blob: 3878156a21911564f00c5fba23ee5421151c8606 [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 {
Alex Sakhartchouk4a43e3e2011-12-28 13:47:05 -080025/*****************************************************************************
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 *****************************************************************************/
Jason Samse5ffb872009-08-09 17:01:55 -070033
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080034class Type : public ObjectBase {
Jason Sams326e0dd2009-05-22 14:03:28 -070035public:
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080036 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 bool dimLOD;
48 bool faces;
49 };
50 State state;
51 };
52 Hal mHal;
53
Jason Sams326e0dd2009-05-22 14:03:28 -070054 Type * createTex2D(const Element *, size_t w, size_t h, bool mip);
55
Jason Sams326e0dd2009-05-22 14:03:28 -070056 size_t getOffsetForFace(uint32_t face) const;
57
58 size_t getSizeBytes() const {return mTotalSizeBytes;}
59 size_t getElementSizeBytes() const {return mElement->getSizeBytes();}
60 const Element * getElement() const {return mElement.get();}
61
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080062 uint32_t getDimX() const {return mHal.state.dimX;}
63 uint32_t getDimY() const {return mHal.state.dimY;}
64 uint32_t getDimZ() const {return mHal.state.dimZ;}
65 uint32_t getDimLOD() const {return mHal.state.dimLOD;}
66 bool getDimFaces() const {return mHal.state.faces;}
Jason Sams326e0dd2009-05-22 14:03:28 -070067
68 uint32_t getLODDimX(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mX;}
69 uint32_t getLODDimY(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mY;}
70 uint32_t getLODDimZ(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mZ;}
Jason Sams326e0dd2009-05-22 14:03:28 -070071
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080072 uint32_t getLODOffset(uint32_t lod) const {
73 rsAssert(lod < mLODCount); return mLODs[lod].mOffset;
74 }
Jason Sams326e0dd2009-05-22 14:03:28 -070075 uint32_t getLODOffset(uint32_t lod, uint32_t x) const;
76 uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const;
77 uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) const;
78
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080079 uint32_t getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face,
80 uint32_t x, uint32_t y) const;
Jason Samsbcac9342011-01-13 17:38:18 -080081
Jason Sams326e0dd2009-05-22 14:03:28 -070082 uint32_t getLODCount() const {return mLODCount;}
Jason Samsef21edc2010-02-22 15:37:51 -080083 bool getIsNp2() const;
Jason Sams326e0dd2009-05-22 14:03:28 -070084
Jason Sams326e0dd2009-05-22 14:03:28 -070085 void clear();
86 void compute();
87
Jason Samse12c1c52009-09-27 17:50:38 -070088 void dumpLOGV(const char *prefix) const;
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070089 virtual void serialize(OStream *stream) const;
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070090 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070091 static Type *createFromStream(Context *rsc, IStream *stream);
Jason Sams326e0dd2009-05-22 14:03:28 -070092
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070093 ObjectBaseRef<Type> cloneAndResize1D(Context *rsc, uint32_t dimX) const;
94 ObjectBaseRef<Type> cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const;
Alex Sakhartchouk383e5b12010-09-23 16:16:33 -070095
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070096 static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e,
97 uint32_t dimX, uint32_t dimY, uint32_t dimZ,
98 bool dimLOD, bool dimFaces);
Jason Sams96abf812010-10-05 13:32:49 -070099
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700100 static Type* getType(Context *rsc, const Element *e,
101 uint32_t dimX, uint32_t dimY, uint32_t dimZ,
102 bool dimLOD, bool dimFaces) {
103 ObjectBaseRef<Type> type = getTypeRef(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces);
104 type->incUserRef();
105 return type.get();
106 }
Jason Samsf0c1df42010-10-26 13:09:17 -0700107
Jason Sams326e0dd2009-05-22 14:03:28 -0700108protected:
109 struct LOD {
110 size_t mX;
111 size_t mY;
112 size_t mZ;
113 size_t mOffset;
114 };
115
116 void makeLODTable();
117
118 // Internal structure from most to least significant.
119 // * Array dimensions
120 // * Faces
121 // * Mipmaps
122 // * xyz
123
124 ObjectBaseRef<const Element> mElement;
125
Jason Sams326e0dd2009-05-22 14:03:28 -0700126 // count of mipmap levels, 0 indicates no mipmapping
127
128 size_t mMipChainSizeBytes;
129 size_t mTotalSizeBytes;
130 LOD *mLODs;
131 uint32_t mLODCount;
132
Jason Sams225afd32010-10-21 14:06:55 -0700133protected:
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700134 virtual void preDestroy() const;
Jason Samsf0c1df42010-10-26 13:09:17 -0700135 virtual ~Type();
Jason Sams225afd32010-10-21 14:06:55 -0700136
Jason Sams326e0dd2009-05-22 14:03:28 -0700137private:
Jason Samsf0c1df42010-10-26 13:09:17 -0700138 Type(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -0700139 Type(const Type &);
140};
141
142
143class TypeState {
144public:
145 TypeState();
146 ~TypeState();
147
Jason Sams81549542010-02-17 15:38:10 -0800148 // Cache of all existing types.
149 Vector<Type *> mTypes;
Jason Sams326e0dd2009-05-22 14:03:28 -0700150};
151
152
153}
154}
155#endif //ANDROID_STRUCTURED_TYPE