• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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 // ---------------------------------------------------------------------------
23 namespace android {
24 namespace renderscript {
25 /*****************************************************************************
26  * CAUTION
27  *
28  * Any layout changes for this class may require a corresponding change to be
29  * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains
30  * a partial copy of the information below.
31  *
32  *****************************************************************************/
33 
34 class Type : public ObjectBase {
35 public:
36     struct Hal {
37         mutable void *drv;
38 
39         struct State {
40             const Element * element;
41 
42             // Size of the structure in the various dimensions.  A missing Dimension is
43             // specified as a 0 and not a 1.
44             uint32_t dimX;
45             uint32_t dimY;
46             uint32_t dimZ;
47             uint32_t *lodDimX;
48             uint32_t *lodDimY;
49             uint32_t *lodDimZ;
50             uint32_t *lodOffset;
51             uint32_t lodCount;
52             uint32_t dimYuv;
53             bool faces;
54         };
55         State state;
56     };
57     Hal mHal;
58 
59     Type * createTex2D(const Element *, size_t w, size_t h, bool mip);
60 
61     size_t getOffsetForFace(uint32_t face) const;
62 
getSizeBytes()63     size_t getSizeBytes() const {return mTotalSizeBytes;}
getElementSizeBytes()64     size_t getElementSizeBytes() const {return mElement->getSizeBytes();}
getElement()65     const Element * getElement() const {return mElement.get();}
66 
getDimX()67     uint32_t getDimX() const {return mHal.state.dimX;}
getDimY()68     uint32_t getDimY() const {return mHal.state.dimY;}
getDimZ()69     uint32_t getDimZ() const {return mHal.state.dimZ;}
getDimLOD()70     bool getDimLOD() const {return mDimLOD;}
getDimFaces()71     bool getDimFaces() const {return mHal.state.faces;}
getDimYuv()72     uint32_t getDimYuv() const {return mHal.state.dimYuv;}
73 
getLODDimX(uint32_t lod)74     uint32_t getLODDimX(uint32_t lod) const {
75         rsAssert(lod < mHal.state.lodCount);
76         return mHal.state.lodDimX[lod];
77     }
getLODDimY(uint32_t lod)78     uint32_t getLODDimY(uint32_t lod) const {
79         rsAssert(lod < mHal.state.lodCount);
80         return mHal.state.lodDimY[lod];
81     }
getLODDimZ(uint32_t lod)82     uint32_t getLODDimZ(uint32_t lod) const {
83         rsAssert(lod < mHal.state.lodCount);
84         return mHal.state.lodDimZ[lod];
85     }
getLODOffset(uint32_t lod)86     uint32_t getLODOffset(uint32_t lod) const {
87         rsAssert(lod < mHal.state.lodCount);
88         return mHal.state.lodOffset[lod];
89     }
90     uint32_t getLODOffset(uint32_t lod, uint32_t x) const;
91     uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const;
92     uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) const;
93 
94     uint32_t getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face,
95                               uint32_t x, uint32_t y) const;
96 
getLODCount()97     uint32_t getLODCount() const {return mHal.state.lodCount;}
98     bool getIsNp2() const;
99 
100     void clear();
101     void compute();
102 
103     void dumpLOGV(const char *prefix) const;
104     virtual void serialize(Context *rsc, OStream *stream) const;
getClassId()105     virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; }
106     static Type *createFromStream(Context *rsc, IStream *stream);
107 
108     ObjectBaseRef<Type> cloneAndResize1D(Context *rsc, uint32_t dimX) const;
109     ObjectBaseRef<Type> cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const;
110 
111     static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e,
112                                           uint32_t dimX, uint32_t dimY, uint32_t dimZ,
113                                           bool dimLOD, bool dimFaces, uint32_t dimYuv);
114 
getType(Context * rsc,const Element * e,uint32_t dimX,uint32_t dimY,uint32_t dimZ,bool dimLOD,bool dimFaces,uint32_t yuv)115     static Type* getType(Context *rsc, const Element *e,
116                          uint32_t dimX, uint32_t dimY, uint32_t dimZ,
117                          bool dimLOD, bool dimFaces, uint32_t yuv) {
118         ObjectBaseRef<Type> type = getTypeRef(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces, yuv);
119         type->incUserRef();
120         return type.get();
121     }
122 
123     void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
124     void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
125 
126 protected:
127     void makeLODTable();
128     bool mDimLOD;
129 
130     // Internal structure from most to least significant.
131     // * Array dimensions
132     // * Faces
133     // * Mipmaps
134     // * xyz
135 
136     ObjectBaseRef<const Element> mElement;
137 
138     // count of mipmap levels, 0 indicates no mipmapping
139 
140     size_t mMipChainSizeBytes;
141     size_t mTotalSizeBytes;
142 protected:
143     virtual void preDestroy() const;
144     virtual ~Type();
145 
146 private:
147     Type(Context *);
148     Type(const Type &);
149 };
150 
151 
152 class TypeState {
153 public:
154     TypeState();
155     ~TypeState();
156 
157     // Cache of all existing types.
158     Vector<Type *> mTypes;
159 };
160 
161 
162 }
163 }
164 #endif //ANDROID_STRUCTURED_TYPE
165