rsType.h revision bcac9340126b4b9fabf2015a2f6a984414d87c21
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_STRUCTURED_TYPE_H
18#define ANDROID_STRUCTURED_TYPE_H
19
20#include "rsElement.h"
21#include "rsVertexArray.h"
22
23// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
26
27
28class Type : public ObjectBase {
29public:
30    Type * createTex2D(const Element *, size_t w, size_t h, bool mip);
31
32    size_t getOffsetForFace(uint32_t face) const;
33
34    size_t getSizeBytes() const {return mTotalSizeBytes;}
35    size_t getElementSizeBytes() const {return mElement->getSizeBytes();}
36    const Element * getElement() const {return mElement.get();}
37
38    uint32_t getDimX() const {return mDimX;}
39    uint32_t getDimY() const {return mDimY;}
40    uint32_t getDimZ() const {return mDimZ;}
41    uint32_t getDimLOD() const {return mDimLOD;}
42    bool getDimFaces() const {return mFaces;}
43
44    uint32_t getLODDimX(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mX;}
45    uint32_t getLODDimY(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mY;}
46    uint32_t getLODDimZ(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mZ;}
47
48    uint32_t getLODOffset(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mOffset;}
49    uint32_t getLODOffset(uint32_t lod, uint32_t x) const;
50    uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const;
51    uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) const;
52
53    uint32_t getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face, uint32_t x, uint32_t y) const;
54
55    uint32_t getLODCount() const {return mLODCount;}
56    bool getIsNp2() const;
57
58    void clear();
59    void compute();
60
61    void dumpLOGV(const char *prefix) const;
62    virtual void serialize(OStream *stream) const;
63    virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; }
64    static Type *createFromStream(Context *rsc, IStream *stream);
65
66    bool isEqual(const Type *other) const;
67
68    Type * cloneAndResize1D(Context *rsc, uint32_t dimX) const;
69    Type * cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const;
70
71    static Type * getType(Context *rsc, const Element *e,
72                      uint32_t dimX, uint32_t dimY, uint32_t dimZ,
73                      bool dimLOD, bool dimFaces);
74
75protected:
76    struct LOD {
77        size_t mX;
78        size_t mY;
79        size_t mZ;
80        size_t mOffset;
81    };
82
83    void makeLODTable();
84
85    // Internal structure from most to least significant.
86    // * Array dimensions
87    // * Faces
88    // * Mipmaps
89    // * xyz
90
91    ObjectBaseRef<const Element> mElement;
92
93    // Size of the structure in the various dimensions.  A missing Dimension is
94    // specified as a 0 and not a 1.
95    size_t mDimX;
96    size_t mDimY;
97    size_t mDimZ;
98    bool mDimLOD;
99    bool mFaces;
100
101    // count of mipmap levels, 0 indicates no mipmapping
102
103    size_t mMipChainSizeBytes;
104    size_t mTotalSizeBytes;
105    LOD *mLODs;
106    uint32_t mLODCount;
107
108protected:
109    virtual void preDestroy();
110    virtual ~Type();
111
112private:
113    Type(Context *);
114    Type(const Type &);
115};
116
117
118class TypeState {
119public:
120    TypeState();
121    ~TypeState();
122
123    // Cache of all existing types.
124    Vector<Type *> mTypes;
125};
126
127
128}
129}
130#endif //ANDROID_STRUCTURED_TYPE
131