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