blob: 056b5af4c1d519e90c3116561cabe8178d808dd7 [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
20#include "RenderScript.h"
Jason Samsa5597fc2009-07-08 18:01:53 -070021#include "rsMesh.h"
22
23#include <utils/String8.h>
Alex Sakhartchouk5224a272011-01-07 11:12:08 -080024#include <utils/Asset.h>
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070025#include "rsStream.h"
Jason Samsa5597fc2009-07-08 18:01:53 -070026#include <stdio.h>
27
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070028#define A3D_MAGIC_KEY "Android3D_ff"
29
Jason Samsa5597fc2009-07-08 18:01:53 -070030// ---------------------------------------------------------------------------
31namespace android {
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070032
Jason Samsa5597fc2009-07-08 18:01:53 -070033namespace renderscript {
34
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080035class FileA3D : public ObjectBase {
Jason Samsa5597fc2009-07-08 18:01:53 -070036public:
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070037 FileA3D(Context *rsc);
Jason Samsa5597fc2009-07-08 18:01:53 -070038 ~FileA3D();
39
40 uint32_t mMajorVersion;
41 uint32_t mMinorVersion;
42 uint64_t mIndexOffset;
43 uint64_t mStringTableOffset;
44 bool mUse64BitOffsets;
45
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070046 class A3DIndexEntry {
47 String8 mObjectName;
48 RsA3DClassID mType;
Jason Samsa5597fc2009-07-08 18:01:53 -070049 uint64_t mOffset;
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070050 uint64_t mLength;
51 ObjectBase *mRsObj;
52 public:
53 friend class FileA3D;
54 const String8 &getObjectName() const {
55 return mObjectName;
56 }
57 RsA3DClassID getType() const {
58 return mType;
59 }
Jason Samsa5597fc2009-07-08 18:01:53 -070060 };
61
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070062 bool load(FILE *f);
Alex Sakhartchouk5224a272011-01-07 11:12:08 -080063 bool load(Asset *asset);
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070064 bool load(const void *data, size_t length);
65
66 size_t getNumIndexEntries() const;
67 const A3DIndexEntry* getIndexEntry(size_t index) const;
68 ObjectBase *initializeFromEntry(size_t index);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070069
70 void appendToFile(ObjectBase *obj);
71 bool writeFile(const char *filename);
Jason Samsa5597fc2009-07-08 18:01:53 -070072
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070073 // Currently files do not get serialized,
74 // but we need to inherit from ObjectBase for ref tracking
75 virtual void serialize(OStream *stream) const {
76 }
77 virtual RsA3DClassID getClassId() const {
78 return RS_A3D_CLASS_ID_UNKNOWN;
79 }
80
Jason Samsa5597fc2009-07-08 18:01:53 -070081protected:
Jason Samsa5597fc2009-07-08 18:01:53 -070082
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070083 void parseHeader(IStream *headerStream);
84
Jason Samsa5597fc2009-07-08 18:01:53 -070085 const uint8_t * mData;
86 void * mAlloc;
87 uint64_t mDataSize;
Alex Sakhartchouk5224a272011-01-07 11:12:08 -080088 Asset *mAsset;
Jason Samsa5597fc2009-07-08 18:01:53 -070089
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070090 OStream *mWriteStream;
91 Vector<A3DIndexEntry*> mWriteIndex;
Jason Samsa5597fc2009-07-08 18:01:53 -070092
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070093 IStream *mReadStream;
94 Vector<A3DIndexEntry*> mIndex;
Jason Samsa5597fc2009-07-08 18:01:53 -070095};
96
97
98}
99}
100#endif //ANDROID_RS_FILE_A3D_H
101
102