blob: bc0d9ffdbe46021b7da3e06a7e6f58b629682ca9 [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -07002 * Copyright (C) 2011 The Android Open Source Project
Jason Sams326e0dd2009-05-22 14:03:28 -07003 *
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
Jason Samse5ffb872009-08-09 17:01:55 -070026
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080027class Type : public ObjectBase {
Jason Sams326e0dd2009-05-22 14:03:28 -070028public:
Jason Sams326e0dd2009-05-22 14:03:28 -070029 Type * createTex2D(const Element *, size_t w, size_t h, bool mip);
30
Jason Sams326e0dd2009-05-22 14:03:28 -070031 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;}
Jason Sams326e0dd2009-05-22 14:03:28 -070046
Jason Samsbcac9342011-01-13 17:38:18 -080047 uint32_t getLODOffset(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mOffset;}
Jason Sams326e0dd2009-05-22 14:03:28 -070048 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
Jason Samsbcac9342011-01-13 17:38:18 -080052 uint32_t getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face, uint32_t x, uint32_t y) const;
53
Jason Sams326e0dd2009-05-22 14:03:28 -070054 uint32_t getLODCount() const {return mLODCount;}
Jason Samsef21edc2010-02-22 15:37:51 -080055 bool getIsNp2() const;
Jason Sams326e0dd2009-05-22 14:03:28 -070056
Jason Sams326e0dd2009-05-22 14:03:28 -070057 void clear();
58 void compute();
59
Jason Samse12c1c52009-09-27 17:50:38 -070060 void dumpLOGV(const char *prefix) const;
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070061 virtual void serialize(OStream *stream) const;
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070062 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070063 static Type *createFromStream(Context *rsc, IStream *stream);
Jason Sams326e0dd2009-05-22 14:03:28 -070064
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070065 ObjectBaseRef<Type> cloneAndResize1D(Context *rsc, uint32_t dimX) const;
66 ObjectBaseRef<Type> cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const;
Alex Sakhartchouk383e5b12010-09-23 16:16:33 -070067
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070068 static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e,
69 uint32_t dimX, uint32_t dimY, uint32_t dimZ,
70 bool dimLOD, bool dimFaces);
Jason Sams96abf812010-10-05 13:32:49 -070071
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070072 static Type* getType(Context *rsc, const Element *e,
73 uint32_t dimX, uint32_t dimY, uint32_t dimZ,
74 bool dimLOD, bool dimFaces) {
75 ObjectBaseRef<Type> type = getTypeRef(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces);
76 type->incUserRef();
77 return type.get();
78 }
Jason Samsf0c1df42010-10-26 13:09:17 -070079
Jason Sams326e0dd2009-05-22 14:03:28 -070080protected:
81 struct LOD {
82 size_t mX;
83 size_t mY;
84 size_t mZ;
85 size_t mOffset;
86 };
87
88 void makeLODTable();
89
90 // Internal structure from most to least significant.
91 // * Array dimensions
92 // * Faces
93 // * Mipmaps
94 // * xyz
95
96 ObjectBaseRef<const Element> mElement;
97
98 // Size of the structure in the various dimensions. A missing Dimension is
99 // specified as a 0 and not a 1.
100 size_t mDimX;
101 size_t mDimY;
102 size_t mDimZ;
103 bool mDimLOD;
104 bool mFaces;
105
Jason Sams326e0dd2009-05-22 14:03:28 -0700106 // count of mipmap levels, 0 indicates no mipmapping
107
108 size_t mMipChainSizeBytes;
109 size_t mTotalSizeBytes;
110 LOD *mLODs;
111 uint32_t mLODCount;
112
Jason Sams225afd32010-10-21 14:06:55 -0700113protected:
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700114 virtual void preDestroy() const;
Jason Samsf0c1df42010-10-26 13:09:17 -0700115 virtual ~Type();
Jason Sams225afd32010-10-21 14:06:55 -0700116
Jason Sams326e0dd2009-05-22 14:03:28 -0700117private:
Jason Samsf0c1df42010-10-26 13:09:17 -0700118 Type(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -0700119 Type(const Type &);
120};
121
122
123class TypeState {
124public:
125 TypeState();
126 ~TypeState();
127
Jason Sams81549542010-02-17 15:38:10 -0800128 // Cache of all existing types.
129 Vector<Type *> mTypes;
Jason Sams326e0dd2009-05-22 14:03:28 -0700130};
131
132
133}
134}
135#endif //ANDROID_STRUCTURED_TYPE