blob: c907869d88a56b6af3b1eab785f52967e5d31abd [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
Miao Wang82e135c2017-02-27 23:35:35 -080022#include <vector>
23
Jason Sams326e0dd2009-05-22 14:03:28 -070024// ---------------------------------------------------------------------------
25namespace android {
26namespace renderscript {
Alex Sakhartchouk4a43e3e2011-12-28 13:47:05 -080027/*****************************************************************************
28 * CAUTION
29 *
30 * Any layout changes for this class may require a corresponding change to be
Jason Samsc7968a02014-11-11 16:24:36 -080031 * made to frameworks/rs/driver/runtime/rs_structs.h, which contains
Alex Sakhartchouk4a43e3e2011-12-28 13:47:05 -080032 * a partial copy of the information below.
33 *
34 *****************************************************************************/
Jason Samse5ffb872009-08-09 17:01:55 -070035
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080036class Type : public ObjectBase {
Jason Sams326e0dd2009-05-22 14:03:28 -070037public:
Jason Samsc7968a02014-11-11 16:24:36 -080038 const static uint32_t mMaxArrays = 4;
39
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080040 struct Hal {
41 mutable void *drv;
42
43 struct State {
44 const Element * element;
45
46 // Size of the structure in the various dimensions. A missing Dimension is
47 // specified as a 0 and not a 1.
48 uint32_t dimX;
49 uint32_t dimY;
50 uint32_t dimZ;
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080051 uint32_t *lodDimX;
52 uint32_t *lodDimY;
53 uint32_t *lodDimZ;
Jason Samsc7968a02014-11-11 16:24:36 -080054 uint32_t *arrays;
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080055 uint32_t lodCount;
Jason Samsa572aca2013-01-09 11:52:26 -080056 uint32_t dimYuv;
Jason Samsc7968a02014-11-11 16:24:36 -080057 uint32_t arrayCount;
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080058 bool faces;
59 };
60 State state;
61 };
62 Hal mHal;
63
Tim Murray49a87772014-07-10 10:00:00 -070064 void operator delete(void* ptr);
65
Jason Sams326e0dd2009-05-22 14:03:28 -070066 Type * createTex2D(const Element *, size_t w, size_t h, bool mip);
67
Jason Sams61656a72013-09-03 16:21:18 -070068 size_t getCellCount() const {return mCellCount;}
Jason Sams326e0dd2009-05-22 14:03:28 -070069 size_t getElementSizeBytes() const {return mElement->getSizeBytes();}
Jason Sams61656a72013-09-03 16:21:18 -070070 size_t getPackedSizeBytes() const {return mCellCount * mElement->getSizeBytes();}
Jason Sams326e0dd2009-05-22 14:03:28 -070071 const Element * getElement() const {return mElement.get();}
72
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080073 uint32_t getDimX() const {return mHal.state.dimX;}
74 uint32_t getDimY() const {return mHal.state.dimY;}
75 uint32_t getDimZ() const {return mHal.state.dimZ;}
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080076 bool getDimLOD() const {return mDimLOD;}
Alex Sakhartchouk50bfc352011-12-20 12:37:59 -080077 bool getDimFaces() const {return mHal.state.faces;}
Jason Samsa572aca2013-01-09 11:52:26 -080078 uint32_t getDimYuv() const {return mHal.state.dimYuv;}
Jason Samsc7968a02014-11-11 16:24:36 -080079 uint32_t getArray(uint32_t idx) const {
80 if (idx < mHal.state.arrayCount) {
81 return mHal.state.arrays[idx];
82 }
83 return 0;
84 }
Jason Sams326e0dd2009-05-22 14:03:28 -070085
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080086 uint32_t getLODDimX(uint32_t lod) const {
87 rsAssert(lod < mHal.state.lodCount);
88 return mHal.state.lodDimX[lod];
89 }
90 uint32_t getLODDimY(uint32_t lod) const {
91 rsAssert(lod < mHal.state.lodCount);
92 return mHal.state.lodDimY[lod];
93 }
94 uint32_t getLODDimZ(uint32_t lod) const {
95 rsAssert(lod < mHal.state.lodCount);
96 return mHal.state.lodDimZ[lod];
97 }
Jason Samsbcac9342011-01-13 17:38:18 -080098
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -080099 uint32_t getLODCount() const {return mHal.state.lodCount;}
Jason Samsef21edc2010-02-22 15:37:51 -0800100 bool getIsNp2() const;
Jason Sams326e0dd2009-05-22 14:03:28 -0700101
Jason Sams326e0dd2009-05-22 14:03:28 -0700102 void clear();
103 void compute();
104
Jason Samse12c1c52009-09-27 17:50:38 -0700105 void dumpLOGV(const char *prefix) const;
Jason Samse3150cf2012-07-24 18:10:20 -0700106 virtual void serialize(Context *rsc, OStream *stream) const;
Alex Sakhartchoukb825f672010-06-04 10:06:50 -0700107 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700108 static Type *createFromStream(Context *rsc, IStream *stream);
Jason Sams326e0dd2009-05-22 14:03:28 -0700109
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700110 ObjectBaseRef<Type> cloneAndResize1D(Context *rsc, uint32_t dimX) const;
111 ObjectBaseRef<Type> cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const;
Alex Sakhartchouk383e5b12010-09-23 16:16:33 -0700112
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700113 static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e,
Jason Samsc7968a02014-11-11 16:24:36 -0800114 const RsTypeCreateParams *params, size_t len);
Jason Sams96abf812010-10-05 13:32:49 -0700115
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700116 static Type* getType(Context *rsc, const Element *e,
Yang Ni79c51de2016-03-08 21:01:45 +0000117 const RsTypeCreateParams *params, size_t len) {
Jason Samsc7968a02014-11-11 16:24:36 -0800118 ObjectBaseRef<Type> type = getTypeRef(rsc, e, params, len);
Yang Ni79c51de2016-03-08 21:01:45 +0000119 type->incUserRef();
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700120 return type.get();
121 }
Jason Samsf0c1df42010-10-26 13:09:17 -0700122
Jason Samsc7968a02014-11-11 16:24:36 -0800123 static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e, uint32_t dimX, uint32_t dimY = 0) {
124 RsTypeCreateParams p;
125 memset(&p, 0, sizeof(p));
126 p.dimX = dimX;
127 p.dimY = dimY;
128 return getTypeRef(rsc, e, &p, sizeof(p));
129 }
130
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700131 void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
132 void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
Jason Samsa36c50a2014-06-17 12:06:06 -0700133 virtual void callUpdateCacheObject(const Context *rsc, void *dstObj) const;
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700134
Jason Sams326e0dd2009-05-22 14:03:28 -0700135protected:
Jason Sams326e0dd2009-05-22 14:03:28 -0700136 void makeLODTable();
Alex Sakhartchouk246fbee2012-03-08 14:52:36 -0800137 bool mDimLOD;
Jason Sams326e0dd2009-05-22 14:03:28 -0700138
139 // Internal structure from most to least significant.
140 // * Array dimensions
141 // * Faces
142 // * Mipmaps
143 // * xyz
144
145 ObjectBaseRef<const Element> mElement;
146
Jason Sams326e0dd2009-05-22 14:03:28 -0700147 // count of mipmap levels, 0 indicates no mipmapping
148
Jason Sams61656a72013-09-03 16:21:18 -0700149 size_t mCellCount;
Jason Sams225afd32010-10-21 14:06:55 -0700150protected:
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700151 virtual void preDestroy() const;
Jason Samsf0c1df42010-10-26 13:09:17 -0700152 virtual ~Type();
Jason Sams225afd32010-10-21 14:06:55 -0700153
Jason Sams326e0dd2009-05-22 14:03:28 -0700154private:
Chih-Hung Hsieh10ab8bb2016-07-01 12:20:20 -0700155 explicit Type(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -0700156 Type(const Type &);
157};
158
159
160class TypeState {
161public:
162 TypeState();
163 ~TypeState();
164
Jason Sams81549542010-02-17 15:38:10 -0800165 // Cache of all existing types.
Miao Wang82e135c2017-02-27 23:35:35 -0800166 std::vector<Type *> mTypes;
Jason Sams326e0dd2009-05-22 14:03:28 -0700167};
168
169
Rahul Chaudhry7974fc02017-02-09 12:33:28 -0800170} // namespace renderscript
171} // namespace android
Jason Sams326e0dd2009-05-22 14:03:28 -0700172#endif //ANDROID_STRUCTURED_TYPE