blob: 26dacfc7852510b80ff40e3a5a9b52343b4b20ca [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;
Jason Sams61656a72013-09-03 16:21:18 -070050 uint32_t *_unused;
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
Jason Sams61656a72013-09-03 16:21:18 -070061 size_t getCellCount() const {return mCellCount;}
Jason Sams326e0dd2009-05-22 14:03:28 -070062 size_t getElementSizeBytes() const {return mElement->getSizeBytes();}
Jason Sams61656a72013-09-03 16:21:18 -070063 size_t getPackedSizeBytes() const {return mCellCount * mElement->getSizeBytes();}
Jason Sams326e0dd2009-05-22 14:03:28 -070064 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 Samsa572aca2013-01-09 11:52:26 -080071 uint32_t getDimYuv() const {return mHal.state.dimYuv;}
Jason Sams326e0dd2009-05-22 14:03:28 -070072
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080073 uint32_t getLODDimX(uint32_t lod) const {
74 rsAssert(lod < mHal.state.lodCount);
75 return mHal.state.lodDimX[lod];
76 }
77 uint32_t getLODDimY(uint32_t lod) const {
78 rsAssert(lod < mHal.state.lodCount);
79 return mHal.state.lodDimY[lod];
80 }
81 uint32_t getLODDimZ(uint32_t lod) const {
82 rsAssert(lod < mHal.state.lodCount);
83 return mHal.state.lodDimZ[lod];
84 }
Jason Samsbcac9342011-01-13 17:38:18 -080085
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080086 uint32_t getLODCount() const {return mHal.state.lodCount;}
Jason Samsef21edc2010-02-22 15:37:51 -080087 bool getIsNp2() const;
Jason Sams326e0dd2009-05-22 14:03:28 -070088
Jason Sams326e0dd2009-05-22 14:03:28 -070089 void clear();
90 void compute();
91
Jason Samse12c1c52009-09-27 17:50:38 -070092 void dumpLOGV(const char *prefix) const;
Jason Samse3150cf2012-07-24 18:10:20 -070093 virtual void serialize(Context *rsc, OStream *stream) const;
Alex Sakhartchoukb825f672010-06-04 10:06:50 -070094 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070095 static Type *createFromStream(Context *rsc, IStream *stream);
Jason Sams326e0dd2009-05-22 14:03:28 -070096
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070097 ObjectBaseRef<Type> cloneAndResize1D(Context *rsc, uint32_t dimX) const;
98 ObjectBaseRef<Type> cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const;
Alex Sakhartchouk383e5b12010-09-23 16:16:33 -070099
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700100 static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e,
101 uint32_t dimX, uint32_t dimY, uint32_t dimZ,
Jason Samsa572aca2013-01-09 11:52:26 -0800102 bool dimLOD, bool dimFaces, uint32_t dimYuv);
Jason Sams96abf812010-10-05 13:32:49 -0700103
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700104 static Type* getType(Context *rsc, const Element *e,
105 uint32_t dimX, uint32_t dimY, uint32_t dimZ,
Jason Samsa572aca2013-01-09 11:52:26 -0800106 bool dimLOD, bool dimFaces, uint32_t yuv) {
107 ObjectBaseRef<Type> type = getTypeRef(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces, yuv);
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700108 type->incUserRef();
109 return type.get();
110 }
Jason Samsf0c1df42010-10-26 13:09:17 -0700111
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700112 void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
113 void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
114
Jason Sams326e0dd2009-05-22 14:03:28 -0700115protected:
Jason Sams326e0dd2009-05-22 14:03:28 -0700116 void makeLODTable();
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -0800117 bool mDimLOD;
Jason Sams326e0dd2009-05-22 14:03:28 -0700118
119 // Internal structure from most to least significant.
120 // * Array dimensions
121 // * Faces
122 // * Mipmaps
123 // * xyz
124
125 ObjectBaseRef<const Element> mElement;
126
Jason Sams326e0dd2009-05-22 14:03:28 -0700127 // count of mipmap levels, 0 indicates no mipmapping
128
Jason Sams61656a72013-09-03 16:21:18 -0700129 size_t mCellCount;
Jason Sams225afd32010-10-21 14:06:55 -0700130protected:
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700131 virtual void preDestroy() const;
Jason Samsf0c1df42010-10-26 13:09:17 -0700132 virtual ~Type();
Jason Sams225afd32010-10-21 14:06:55 -0700133
Jason Sams326e0dd2009-05-22 14:03:28 -0700134private:
Jason Samsf0c1df42010-10-26 13:09:17 -0700135 Type(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -0700136 Type(const Type &);
137};
138
139
140class TypeState {
141public:
142 TypeState();
143 ~TypeState();
144
Jason Sams81549542010-02-17 15:38:10 -0800145 // Cache of all existing types.
146 Vector<Type *> mTypes;
Jason Sams326e0dd2009-05-22 14:03:28 -0700147};
148
149
150}
151}
152#endif //ANDROID_STRUCTURED_TYPE