Home | History | Annotate | Download | only in rs
      1 /*
      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 "rsMesh.h"
     21 
     22 #include "rsStream.h"
     23 #include <stdio.h>
     24 #include <vector>
     25 
     26 #define A3D_MAGIC_KEY "Android3D_ff"
     27 
     28 // ---------------------------------------------------------------------------
     29 namespace android {
     30     class Asset;
     31 
     32 namespace renderscript {
     33 
     34 class FileA3D : public ObjectBase {
     35 public:
     36     explicit FileA3D(Context *rsc);
     37     ~FileA3D();
     38 
     39     uint32_t mMajorVersion;
     40     uint32_t mMinorVersion;
     41     uint64_t mIndexOffset;
     42     uint64_t mStringTableOffset;
     43     bool mUse64BitOffsets;
     44 
     45     class A3DIndexEntry {
     46         const char *mObjectName;
     47         RsA3DClassID mType;
     48         uint64_t mOffset;
     49         uint64_t mLength;
     50         ObjectBase *mRsObj;
     51     public:
     52         friend class FileA3D;
     53         const char *getObjectName() const {
     54             return mObjectName;
     55         }
     56         RsA3DClassID getType() const {
     57             return mType;
     58         }
     59 
     60         ~A3DIndexEntry();
     61     };
     62 
     63     bool load(FILE *f);
     64     bool load(Asset *asset);
     65     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);
     70 
     71     void appendToFile(Context *rsc, ObjectBase *obj);
     72     bool writeFile(const char *filename);
     73 
     74     // Currently files do not get serialized,
     75     // but we need to inherit from ObjectBase for ref tracking
     76     virtual void serialize(Context *rsc, OStream *stream) const {
     77     }
     78     virtual RsA3DClassID getClassId() const {
     79         return RS_A3D_CLASS_ID_UNKNOWN;
     80     }
     81 
     82 protected:
     83 
     84     void parseHeader(IStream *headerStream);
     85 
     86     const uint8_t * mData;
     87     void * mAlloc;
     88     uint64_t mDataSize;
     89 
     90     OStream *mWriteStream;
     91     std::vector<A3DIndexEntry*> mWriteIndex;
     92 
     93     IStream *mReadStream;
     94     std::vector<A3DIndexEntry*> mIndex;
     95 };
     96 
     97 
     98 } // namespace renderscript
     99 } // namespace android
    100 #endif //ANDROID_RS_FILE_A3D_H
    101 
    102 
    103