blob: d2bc96b70b3c6b67f0f96d82e2beee18c3e50649 [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
Jason Samsbc0ca6b2013-02-15 18:13:43 -08002 * Copyright (C) 2013 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;
Stephen Hines86087f22012-10-19 19:16:51 -070050 uint32_t *lodOffset;
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080051 uint32_t lodCount;
Jason Samsa572aca2013-01-09 11:52:26 -080052 uint32_t dimYuv;
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080053 bool faces;
54 };
55 State state;
56 };
57 Hal mHal;
58
Jason Sams326e0dd2009-05-22 14:03:28 -070059 Type * createTex2D(const Element *, size_t w, size_t h, bool mip);
60
Stephen Hines86087f22012-10-19 19:16:51 -070061 size_t getOffsetForFace(uint32_t face) const;
62
Jason Sams326e0dd2009-05-22 14:03:28 -070063 size_t getSizeBytes() const {return mTotalSizeBytes;}
64 size_t getElementSizeBytes() const {return mElement->getSizeBytes();}
65 const Element * getElement() const {return mElement.get();}
66
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080067 uint32_t getDimX() const {return mHal.state.dimX;}
68 uint32_t getDimY() const {return mHal.state.dimY;}
69 uint32_t getDimZ() const {return mHal.state.dimZ;}
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080070 bool getDimLOD() const {return mDimLOD;}
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080071 bool getDimFaces() const {return mHal.state.faces;}
Jason Samsa572aca2013-01-09 11:52:26 -080072 uint32_t getDimYuv() const {return mHal.state.dimYuv;}
Jason Sams326e0dd2009-05-22 14:03:28 -070073
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080074 uint32_t getLODDimX(uint32_t lod) const {
75 rsAssert(lod < mHal.state.lodCount);
76 return mHal.state.lodDimX[lod];
77 }
78 uint32_t getLODDimY(uint32_t lod) const {
79 rsAssert(lod < mHal.state.lodCount);
80 return mHal.state.lodDimY[lod];
81 }
82 uint32_t getLODDimZ(uint32_t lod) const {
83 rsAssert(lod < mHal.state.lodCount);
84 return mHal.state.lodDimZ[lod];
85 }
Stephen Hines86087f22012-10-19 19:16:51 -070086 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;
Jason Samsbcac9342011-01-13 17:38:18 -080096
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080097 uint32_t getLODCount() const {return mHal.state.lodCount;}
Jason Samsef21edc2010-02-22 15:37:51 -080098 bool getIsNp2() const;
Jason Sams326e0dd2009-05-22 14:03:28 -070099
Jason Sams326e0dd2009-05-22 14:03:28 -0700100 void clear();
101 void compute();
102
Jason Samse12c1c52009-09-27 17:50:38 -0700103 void dumpLOGV(const char *prefix) const;
Jason Samse3150cf2012-07-24 18:10:20 -0700104 virtual void serialize(Context *rsc, OStream *stream) const;
Alex Sakhartchoukb825f672010-06-04 10:06:50 -0700105 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700106 static Type *createFromStream(Context *rsc, IStream *stream);
Jason Sams326e0dd2009-05-22 14:03:28 -0700107
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700108 ObjectBaseRef<Type> cloneAndResize1D(Context *rsc, uint32_t dimX) const;
109 ObjectBaseRef<Type> cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const;
Alex Sakhartchouk383e5b12010-09-23 16:16:33 -0700110
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700111 static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e,
112 uint32_t dimX, uint32_t dimY, uint32_t dimZ,
Jason Samsa572aca2013-01-09 11:52:26 -0800113 bool dimLOD, bool dimFaces, uint32_t dimYuv);
Jason Sams96abf812010-10-05 13:32:49 -0700114
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700115 static Type* getType(Context *rsc, const Element *e,
116 uint32_t dimX, uint32_t dimY, uint32_t dimZ,
Jason Samsa572aca2013-01-09 11:52:26 -0800117 bool dimLOD, bool dimFaces, uint32_t yuv) {
118 ObjectBaseRef<Type> type = getTypeRef(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces, yuv);
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700119 type->incUserRef();
120 return type.get();
121 }
Jason Samsf0c1df42010-10-26 13:09:17 -0700122
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700123 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
Jason Sams326e0dd2009-05-22 14:03:28 -0700126protected:
Jason Sams326e0dd2009-05-22 14:03:28 -0700127 void makeLODTable();
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -0800128 bool mDimLOD;
Jason Sams326e0dd2009-05-22 14:03:28 -0700129
130 // Internal structure from most to least significant.
131 // * Array dimensions
132 // * Faces
133 // * Mipmaps
134 // * xyz
135
136 ObjectBaseRef<const Element> mElement;
137
Jason Sams326e0dd2009-05-22 14:03:28 -0700138 // count of mipmap levels, 0 indicates no mipmapping
139
140 size_t mMipChainSizeBytes;
141 size_t mTotalSizeBytes;
Jason Sams225afd32010-10-21 14:06:55 -0700142protected:
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700143 virtual void preDestroy() const;
Jason Samsf0c1df42010-10-26 13:09:17 -0700144 virtual ~Type();
Jason Sams225afd32010-10-21 14:06:55 -0700145
Jason Sams326e0dd2009-05-22 14:03:28 -0700146private:
Jason Samsf0c1df42010-10-26 13:09:17 -0700147 Type(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -0700148 Type(const Type &);
149};
150
151
152class TypeState {
153public:
154 TypeState();
155 ~TypeState();
156
Jason Sams81549542010-02-17 15:38:10 -0800157 // Cache of all existing types.
158 Vector<Type *> mTypes;
Jason Sams326e0dd2009-05-22 14:03:28 -0700159};
160
161
162}
163}
164#endif //ANDROID_STRUCTURED_TYPE