blob: 1d136b4068d6dbd2c57b3f27341cc0069b989fb6 [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;
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080047 uint32_t *lodDimX;
48 uint32_t *lodDimY;
49 uint32_t *lodDimZ;
50 uint32_t *lodOffset;
51 uint32_t lodCount;
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080052 bool faces;
53 };
54 State state;
55 };
56 Hal mHal;
57
Jason Sams326e0dd2009-05-22 14:03:28 -070058 Type * createTex2D(const Element *, size_t w, size_t h, bool mip);
59
Jason Sams326e0dd2009-05-22 14:03:28 -070060 size_t getOffsetForFace(uint32_t face) const;
61
62 size_t getSizeBytes() const {return mTotalSizeBytes;}
63 size_t getElementSizeBytes() const {return mElement->getSizeBytes();}
64 const Element * getElement() const {return mElement.get();}
65
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080066 uint32_t getDimX() const {return mHal.state.dimX;}
67 uint32_t getDimY() const {return mHal.state.dimY;}
68 uint32_t getDimZ() const {return mHal.state.dimZ;}
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080069 bool getDimLOD() const {return mDimLOD;}
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080070 bool getDimFaces() const {return mHal.state.faces;}
Jason Sams326e0dd2009-05-22 14:03:28 -070071
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080072 uint32_t getLODDimX(uint32_t lod) const {
73 rsAssert(lod < mHal.state.lodCount);
74 return mHal.state.lodDimX[lod];
75 }
76 uint32_t getLODDimY(uint32_t lod) const {
77 rsAssert(lod < mHal.state.lodCount);
78 return mHal.state.lodDimY[lod];
79 }
80 uint32_t getLODDimZ(uint32_t lod) const {
81 rsAssert(lod < mHal.state.lodCount);
82 return mHal.state.lodDimZ[lod];
83 }
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080084 uint32_t getLODOffset(uint32_t lod) const {
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080085 rsAssert(lod < mHal.state.lodCount);
86 return mHal.state.lodOffset[lod];
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080087 }
Jason Sams326e0dd2009-05-22 14:03:28 -070088 uint32_t getLODOffset(uint32_t lod, uint32_t x) const;
89 uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const;
90 uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) const;
91
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080092 uint32_t getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face,
93 uint32_t x, uint32_t y) const;
Jason Samsbcac9342011-01-13 17:38:18 -080094
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080095 uint32_t getLODCount() const {return mHal.state.lodCount;}
Jason Samsef21edc2010-02-22 15:37:51 -080096 bool getIsNp2() const;
Jason Sams326e0dd2009-05-22 14:03:28 -070097
Jason Sams326e0dd2009-05-22 14:03:28 -070098 void clear();
99 void compute();
100
Jason Samse12c1c52009-09-27 17:50:38 -0700101 void dumpLOGV(const char *prefix) const;
Jason Samse3150cf2012-07-24 18:10:20 -0700102 virtual void serialize(Context *rsc, OStream *stream) const;
Alex Sakhartchoukb825f672010-06-04 10:06:50 -0700103 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700104 static Type *createFromStream(Context *rsc, IStream *stream);
Jason Sams326e0dd2009-05-22 14:03:28 -0700105
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700106 ObjectBaseRef<Type> cloneAndResize1D(Context *rsc, uint32_t dimX) const;
107 ObjectBaseRef<Type> cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const;
Alex Sakhartchouk383e5b12010-09-23 16:16:33 -0700108
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700109 static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e,
110 uint32_t dimX, uint32_t dimY, uint32_t dimZ,
111 bool dimLOD, bool dimFaces);
Jason Sams96abf812010-10-05 13:32:49 -0700112
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700113 static Type* getType(Context *rsc, const Element *e,
114 uint32_t dimX, uint32_t dimY, uint32_t dimZ,
115 bool dimLOD, bool dimFaces) {
116 ObjectBaseRef<Type> type = getTypeRef(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces);
117 type->incUserRef();
118 return type.get();
119 }
Jason Samsf0c1df42010-10-26 13:09:17 -0700120
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700121 void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
122 void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
123
Jason Sams326e0dd2009-05-22 14:03:28 -0700124protected:
Jason Sams326e0dd2009-05-22 14:03:28 -0700125 void makeLODTable();
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -0800126 bool mDimLOD;
Jason Sams326e0dd2009-05-22 14:03:28 -0700127
128 // Internal structure from most to least significant.
129 // * Array dimensions
130 // * Faces
131 // * Mipmaps
132 // * xyz
133
134 ObjectBaseRef<const Element> mElement;
135
Jason Sams326e0dd2009-05-22 14:03:28 -0700136 // count of mipmap levels, 0 indicates no mipmapping
137
138 size_t mMipChainSizeBytes;
139 size_t mTotalSizeBytes;
Jason Sams225afd32010-10-21 14:06:55 -0700140protected:
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700141 virtual void preDestroy() const;
Jason Samsf0c1df42010-10-26 13:09:17 -0700142 virtual ~Type();
Jason Sams225afd32010-10-21 14:06:55 -0700143
Jason Sams326e0dd2009-05-22 14:03:28 -0700144private:
Jason Samsf0c1df42010-10-26 13:09:17 -0700145 Type(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -0700146 Type(const Type &);
147};
148
149
150class TypeState {
151public:
152 TypeState();
153 ~TypeState();
154
Jason Sams81549542010-02-17 15:38:10 -0800155 // Cache of all existing types.
156 Vector<Type *> mTypes;
Jason Sams326e0dd2009-05-22 14:03:28 -0700157};
158
159
160}
161}
162#endif //ANDROID_STRUCTURED_TYPE