blob: 34498f0764641baf088f2dafc1862277023ac73b [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
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"
Jason Sams433eca32010-01-06 11:57:52 -080021#include "rsVertexArray.h"
Jason Sams326e0dd2009-05-22 14:03:28 -070022
23// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
26
Jason Samse5ffb872009-08-09 17:01:55 -070027
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080028class Type : public ObjectBase {
Jason Sams326e0dd2009-05-22 14:03:28 -070029public:
Jason Sams326e0dd2009-05-22 14:03:28 -070030 Type * createTex2D(const Element *, size_t w, size_t h, bool mip);
31
Jason Sams326e0dd2009-05-22 14:03:28 -070032 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 uint32_t getLODOffset(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mOffset;}
48
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 getLODCount() const {return mLODCount;}
Jason Samsef21edc2010-02-22 15:37:51 -080054 bool getIsNp2() const;
Jason Sams326e0dd2009-05-22 14:03:28 -070055
Jason Sams326e0dd2009-05-22 14:03:28 -070056 void clear();
57 void compute();
58
Jason Samse12c1c52009-09-27 17:50:38 -070059 void dumpLOGV(const char *prefix) const;
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070060 virtual void serialize(OStream *stream) const;
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070061 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070062 static Type *createFromStream(Context *rsc, IStream *stream);
Jason Sams326e0dd2009-05-22 14:03:28 -070063
Alex Sakhartchouk383e5b12010-09-23 16:16:33 -070064 bool isEqual(const Type *other) const;
65
Jason Sams96abf812010-10-05 13:32:49 -070066 Type * cloneAndResize1D(Context *rsc, uint32_t dimX) const;
67 Type * cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const;
68
Jason Samsf0c1df42010-10-26 13:09:17 -070069 static Type * getType(Context *rsc, const Element *e,
70 uint32_t dimX, uint32_t dimY, uint32_t dimZ,
71 bool dimLOD, bool dimFaces);
72
Jason Sams326e0dd2009-05-22 14:03:28 -070073protected:
74 struct LOD {
75 size_t mX;
76 size_t mY;
77 size_t mZ;
78 size_t mOffset;
79 };
80
81 void makeLODTable();
82
83 // Internal structure from most to least significant.
84 // * Array dimensions
85 // * Faces
86 // * Mipmaps
87 // * xyz
88
89 ObjectBaseRef<const Element> mElement;
90
91 // Size of the structure in the various dimensions. A missing Dimension is
92 // specified as a 0 and not a 1.
93 size_t mDimX;
94 size_t mDimY;
95 size_t mDimZ;
96 bool mDimLOD;
97 bool mFaces;
98
Jason Sams326e0dd2009-05-22 14:03:28 -070099 // count of mipmap levels, 0 indicates no mipmapping
100
101 size_t mMipChainSizeBytes;
102 size_t mTotalSizeBytes;
103 LOD *mLODs;
104 uint32_t mLODCount;
105
Jason Sams225afd32010-10-21 14:06:55 -0700106protected:
107 virtual void preDestroy();
Jason Samsf0c1df42010-10-26 13:09:17 -0700108 virtual ~Type();
Jason Sams225afd32010-10-21 14:06:55 -0700109
Jason Sams326e0dd2009-05-22 14:03:28 -0700110private:
Jason Samsf0c1df42010-10-26 13:09:17 -0700111 Type(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -0700112 Type(const Type &);
113};
114
115
116class TypeState {
117public:
118 TypeState();
119 ~TypeState();
120
Jason Sams81549542010-02-17 15:38:10 -0800121 // Cache of all existing types.
122 Vector<Type *> mTypes;
Jason Sams326e0dd2009-05-22 14:03:28 -0700123};
124
125
126}
127}
128#endif //ANDROID_STRUCTURED_TYPE