blob: 3334159d15169168f12e6e1d49ceb243ad015fb6 [file] [log] [blame]
Jason Samsa5597fc2009-07-08 18:01:53 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_RS_FILE_A3D_H
18#define ANDROID_RS_FILE_A3D_H
19
Jason Samsa5597fc2009-07-08 18:01:53 -070020#include "rsMesh.h"
21
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070022#include "rsStream.h"
Jason Samsa5597fc2009-07-08 18:01:53 -070023#include <stdio.h>
Miao Wang82e135c2017-02-27 23:35:35 -080024#include <vector>
Jason Samsa5597fc2009-07-08 18:01:53 -070025
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070026#define A3D_MAGIC_KEY "Android3D_ff"
27
Jason Samsa5597fc2009-07-08 18:01:53 -070028// ---------------------------------------------------------------------------
29namespace android {
Jason Samsa6ab26a2012-03-28 17:44:21 -070030 class Asset;
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070031
Jason Samsa5597fc2009-07-08 18:01:53 -070032namespace renderscript {
33
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080034class FileA3D : public ObjectBase {
Jason Samsa5597fc2009-07-08 18:01:53 -070035public:
Chih-Hung Hsieh10ab8bb2016-07-01 12:20:20 -070036 explicit FileA3D(Context *rsc);
Jason Samsa5597fc2009-07-08 18:01:53 -070037 ~FileA3D();
38
39 uint32_t mMajorVersion;
40 uint32_t mMinorVersion;
41 uint64_t mIndexOffset;
42 uint64_t mStringTableOffset;
43 bool mUse64BitOffsets;
44
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070045 class A3DIndexEntry {
Jason Sams48ecf6a2013-07-09 15:35:29 -070046 const char *mObjectName;
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070047 RsA3DClassID mType;
Jason Samsa5597fc2009-07-08 18:01:53 -070048 uint64_t mOffset;
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070049 uint64_t mLength;
50 ObjectBase *mRsObj;
51 public:
52 friend class FileA3D;
Jason Sams48ecf6a2013-07-09 15:35:29 -070053 const char *getObjectName() const {
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070054 return mObjectName;
55 }
56 RsA3DClassID getType() const {
57 return mType;
58 }
Jason Sams48ecf6a2013-07-09 15:35:29 -070059
60 ~A3DIndexEntry();
Jason Samsa5597fc2009-07-08 18:01:53 -070061 };
62
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070063 bool load(FILE *f);
Alex Sakhartchouk5224a272011-01-07 11:12:08 -080064 bool load(Asset *asset);
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070065 bool load(const void *data, size_t length);
66
67 size_t getNumIndexEntries() const;
68 const A3DIndexEntry* getIndexEntry(size_t index) const;
69 ObjectBase *initializeFromEntry(size_t index);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070070
Jason Samse3150cf2012-07-24 18:10:20 -070071 void appendToFile(Context *rsc, ObjectBase *obj);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070072 bool writeFile(const char *filename);
Jason Samsa5597fc2009-07-08 18:01:53 -070073
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070074 // Currently files do not get serialized,
75 // but we need to inherit from ObjectBase for ref tracking
Jason Samse3150cf2012-07-24 18:10:20 -070076 virtual void serialize(Context *rsc, OStream *stream) const {
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070077 }
78 virtual RsA3DClassID getClassId() const {
79 return RS_A3D_CLASS_ID_UNKNOWN;
80 }
81
Jason Samsa5597fc2009-07-08 18:01:53 -070082protected:
Jason Samsa5597fc2009-07-08 18:01:53 -070083
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070084 void parseHeader(IStream *headerStream);
85
Jason Samsa5597fc2009-07-08 18:01:53 -070086 const uint8_t * mData;
87 void * mAlloc;
88 uint64_t mDataSize;
Jason Samsa5597fc2009-07-08 18:01:53 -070089
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070090 OStream *mWriteStream;
Miao Wang82e135c2017-02-27 23:35:35 -080091 std::vector<A3DIndexEntry*> mWriteIndex;
Jason Samsa5597fc2009-07-08 18:01:53 -070092
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070093 IStream *mReadStream;
Miao Wang82e135c2017-02-27 23:35:35 -080094 std::vector<A3DIndexEntry*> mIndex;
Jason Samsa5597fc2009-07-08 18:01:53 -070095};
96
97
Rahul Chaudhry7974fc02017-02-09 12:33:28 -080098} // namespace renderscript
99} // namespace android
Jason Samsa5597fc2009-07-08 18:01:53 -0700100#endif //ANDROID_RS_FILE_A3D_H
Yang Nib8353c52015-02-14 18:00:59 -0800101
102