blob: 6ae844661e67375a5b78ad9a7b404c13a3606731 [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
Jason Samsc7968a02014-11-11 16:24:36 -080029 * made to frameworks/rs/driver/runtime/rs_structs.h, which contains
Alex Sakhartchouk4a43e3e2011-12-28 13:47:05 -080030 * 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:
Jason Samsc7968a02014-11-11 16:24:36 -080036 const static uint32_t mMaxArrays = 4;
37
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080038 struct Hal {
39 mutable void *drv;
40
41 struct State {
42 const Element * element;
43
44 // Size of the structure in the various dimensions. A missing Dimension is
45 // specified as a 0 and not a 1.
46 uint32_t dimX;
47 uint32_t dimY;
48 uint32_t dimZ;
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080049 uint32_t *lodDimX;
50 uint32_t *lodDimY;
51 uint32_t *lodDimZ;
Jason Samsc7968a02014-11-11 16:24:36 -080052 uint32_t *arrays;
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080053 uint32_t lodCount;
Jason Samsa572aca2013-01-09 11:52:26 -080054 uint32_t dimYuv;
Jason Samsc7968a02014-11-11 16:24:36 -080055 uint32_t arrayCount;
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080056 bool faces;
57 };
58 State state;
59 };
60 Hal mHal;
61
Tim Murray49a87772014-07-10 10:00:00 -070062 void operator delete(void* ptr);
63
Jason Sams326e0dd2009-05-22 14:03:28 -070064 Type * createTex2D(const Element *, size_t w, size_t h, bool mip);
65
Jason Sams61656a72013-09-03 16:21:18 -070066 size_t getCellCount() const {return mCellCount;}
Jason Sams326e0dd2009-05-22 14:03:28 -070067 size_t getElementSizeBytes() const {return mElement->getSizeBytes();}
Jason Sams61656a72013-09-03 16:21:18 -070068 size_t getPackedSizeBytes() const {return mCellCount * mElement->getSizeBytes();}
Jason Sams326e0dd2009-05-22 14:03:28 -070069 const Element * getElement() const {return mElement.get();}
70
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080071 uint32_t getDimX() const {return mHal.state.dimX;}
72 uint32_t getDimY() const {return mHal.state.dimY;}
73 uint32_t getDimZ() const {return mHal.state.dimZ;}
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080074 bool getDimLOD() const {return mDimLOD;}
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080075 bool getDimFaces() const {return mHal.state.faces;}
Jason Samsa572aca2013-01-09 11:52:26 -080076 uint32_t getDimYuv() const {return mHal.state.dimYuv;}
Jason Samsc7968a02014-11-11 16:24:36 -080077 uint32_t getArray(uint32_t idx) const {
78 if (idx < mHal.state.arrayCount) {
79 return mHal.state.arrays[idx];
80 }
81 return 0;
82 }
Jason Sams326e0dd2009-05-22 14:03:28 -070083
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080084 uint32_t getLODDimX(uint32_t lod) const {
85 rsAssert(lod < mHal.state.lodCount);
86 return mHal.state.lodDimX[lod];
87 }
88 uint32_t getLODDimY(uint32_t lod) const {
89 rsAssert(lod < mHal.state.lodCount);
90 return mHal.state.lodDimY[lod];
91 }
92 uint32_t getLODDimZ(uint32_t lod) const {
93 rsAssert(lod < mHal.state.lodCount);
94 return mHal.state.lodDimZ[lod];
95 }
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,
Jason Samsc7968a02014-11-11 16:24:36 -0800112 const RsTypeCreateParams *params, size_t len);
Jason Sams96abf812010-10-05 13:32:49 -0700113
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700114 static Type* getType(Context *rsc, const Element *e,
Yang Ni79c51de2016-03-08 21:01:45 +0000115 const RsTypeCreateParams *params, size_t len) {
Jason Samsc7968a02014-11-11 16:24:36 -0800116 ObjectBaseRef<Type> type = getTypeRef(rsc, e, params, len);
Yang Ni79c51de2016-03-08 21:01:45 +0000117 type->incUserRef();
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700118 return type.get();
119 }
Jason Samsf0c1df42010-10-26 13:09:17 -0700120
Jason Samsc7968a02014-11-11 16:24:36 -0800121 static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e, uint32_t dimX, uint32_t dimY = 0) {
122 RsTypeCreateParams p;
123 memset(&p, 0, sizeof(p));
124 p.dimX = dimX;
125 p.dimY = dimY;
126 return getTypeRef(rsc, e, &p, sizeof(p));
127 }
128
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700129 void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
130 void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
Jason Samsa36c50a2014-06-17 12:06:06 -0700131 virtual void callUpdateCacheObject(const Context *rsc, void *dstObj) const;
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700132
Jason Sams326e0dd2009-05-22 14:03:28 -0700133protected:
Jason Sams326e0dd2009-05-22 14:03:28 -0700134 void makeLODTable();
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -0800135 bool mDimLOD;
Jason Sams326e0dd2009-05-22 14:03:28 -0700136
137 // Internal structure from most to least significant.
138 // * Array dimensions
139 // * Faces
140 // * Mipmaps
141 // * xyz
142
143 ObjectBaseRef<const Element> mElement;
144
Jason Sams326e0dd2009-05-22 14:03:28 -0700145 // count of mipmap levels, 0 indicates no mipmapping
146
Jason Sams61656a72013-09-03 16:21:18 -0700147 size_t mCellCount;
Jason Sams225afd32010-10-21 14:06:55 -0700148protected:
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700149 virtual void preDestroy() const;
Jason Samsf0c1df42010-10-26 13:09:17 -0700150 virtual ~Type();
Jason Sams225afd32010-10-21 14:06:55 -0700151
Jason Sams326e0dd2009-05-22 14:03:28 -0700152private:
Jason Samsf0c1df42010-10-26 13:09:17 -0700153 Type(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -0700154 Type(const Type &);
155};
156
157
158class TypeState {
159public:
160 TypeState();
161 ~TypeState();
162
Jason Sams81549542010-02-17 15:38:10 -0800163 // Cache of all existing types.
Yang Nib8353c52015-02-14 18:00:59 -0800164 Vector<Type *> mTypes;
Jason Sams326e0dd2009-05-22 14:03:28 -0700165};
166
167
168}
169}
170#endif //ANDROID_STRUCTURED_TYPE