Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
Jason Sams | bc0ca6b | 2013-02-15 18:13:43 -0800 | [diff] [blame] | 2 | * Copyright (C) 2013 The Android Open Source Project |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 3 | * |
| 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 | // --------------------------------------------------------------------------- |
| 23 | namespace android { |
| 24 | namespace renderscript { |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 25 | /***************************************************************************** |
| 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 Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 33 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 34 | class Type : public ObjectBase { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 35 | public: |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 36 | 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 Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 47 | uint32_t *lodDimX; |
| 48 | uint32_t *lodDimY; |
| 49 | uint32_t *lodDimZ; |
Jason Sams | 61656a7 | 2013-09-03 16:21:18 -0700 | [diff] [blame] | 50 | uint32_t *_unused; |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 51 | uint32_t lodCount; |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 52 | uint32_t dimYuv; |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 53 | bool faces; |
| 54 | }; |
| 55 | State state; |
| 56 | }; |
| 57 | Hal mHal; |
| 58 | |
Tim Murray | 49a8777 | 2014-07-10 10:00:00 -0700 | [diff] [blame] | 59 | void operator delete(void* ptr); |
| 60 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 61 | Type * createTex2D(const Element *, size_t w, size_t h, bool mip); |
| 62 | |
Jason Sams | 61656a7 | 2013-09-03 16:21:18 -0700 | [diff] [blame] | 63 | size_t getCellCount() const {return mCellCount;} |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 64 | size_t getElementSizeBytes() const {return mElement->getSizeBytes();} |
Jason Sams | 61656a7 | 2013-09-03 16:21:18 -0700 | [diff] [blame] | 65 | size_t getPackedSizeBytes() const {return mCellCount * mElement->getSizeBytes();} |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 66 | const Element * getElement() const {return mElement.get();} |
| 67 | |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 68 | uint32_t getDimX() const {return mHal.state.dimX;} |
| 69 | uint32_t getDimY() const {return mHal.state.dimY;} |
| 70 | uint32_t getDimZ() const {return mHal.state.dimZ;} |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 71 | bool getDimLOD() const {return mDimLOD;} |
Alex Sakhartchouk | 50bfc35 | 2011-12-20 12:37:59 -0800 | [diff] [blame] | 72 | bool getDimFaces() const {return mHal.state.faces;} |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 73 | uint32_t getDimYuv() const {return mHal.state.dimYuv;} |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 74 | |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 75 | uint32_t getLODDimX(uint32_t lod) const { |
| 76 | rsAssert(lod < mHal.state.lodCount); |
| 77 | return mHal.state.lodDimX[lod]; |
| 78 | } |
| 79 | uint32_t getLODDimY(uint32_t lod) const { |
| 80 | rsAssert(lod < mHal.state.lodCount); |
| 81 | return mHal.state.lodDimY[lod]; |
| 82 | } |
| 83 | uint32_t getLODDimZ(uint32_t lod) const { |
| 84 | rsAssert(lod < mHal.state.lodCount); |
| 85 | return mHal.state.lodDimZ[lod]; |
| 86 | } |
Jason Sams | bcac934 | 2011-01-13 17:38:18 -0800 | [diff] [blame] | 87 | |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 88 | uint32_t getLODCount() const {return mHal.state.lodCount;} |
Jason Sams | ef21edc | 2010-02-22 15:37:51 -0800 | [diff] [blame] | 89 | bool getIsNp2() const; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 90 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 91 | void clear(); |
| 92 | void compute(); |
| 93 | |
Jason Sams | e12c1c5 | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 94 | void dumpLOGV(const char *prefix) const; |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 95 | virtual void serialize(Context *rsc, OStream *stream) const; |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 96 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; } |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 97 | static Type *createFromStream(Context *rsc, IStream *stream); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 98 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 99 | ObjectBaseRef<Type> cloneAndResize1D(Context *rsc, uint32_t dimX) const; |
| 100 | ObjectBaseRef<Type> cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const; |
Alex Sakhartchouk | 383e5b1 | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 101 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 102 | static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e, |
| 103 | uint32_t dimX, uint32_t dimY, uint32_t dimZ, |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 104 | bool dimLOD, bool dimFaces, uint32_t dimYuv); |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 105 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 106 | static Type* getType(Context *rsc, const Element *e, |
| 107 | uint32_t dimX, uint32_t dimY, uint32_t dimZ, |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 108 | bool dimLOD, bool dimFaces, uint32_t yuv) { |
| 109 | ObjectBaseRef<Type> type = getTypeRef(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces, yuv); |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 110 | type->incUserRef(); |
| 111 | return type.get(); |
| 112 | } |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 113 | |
Stephen Hines | 9f70a4e | 2012-04-02 20:18:48 -0700 | [diff] [blame] | 114 | void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const; |
| 115 | void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const; |
Jason Sams | a36c50a | 2014-06-17 12:06:06 -0700 | [diff] [blame] | 116 | virtual void callUpdateCacheObject(const Context *rsc, void *dstObj) const; |
Stephen Hines | 9f70a4e | 2012-04-02 20:18:48 -0700 | [diff] [blame] | 117 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 118 | protected: |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 119 | void makeLODTable(); |
Alex Sakhartchouk | 246fbee | 2012-03-08 14:52:36 -0800 | [diff] [blame] | 120 | bool mDimLOD; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 121 | |
| 122 | // Internal structure from most to least significant. |
| 123 | // * Array dimensions |
| 124 | // * Faces |
| 125 | // * Mipmaps |
| 126 | // * xyz |
| 127 | |
| 128 | ObjectBaseRef<const Element> mElement; |
| 129 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 130 | // count of mipmap levels, 0 indicates no mipmapping |
| 131 | |
Jason Sams | 61656a7 | 2013-09-03 16:21:18 -0700 | [diff] [blame] | 132 | size_t mCellCount; |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 133 | protected: |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 134 | virtual void preDestroy() const; |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 135 | virtual ~Type(); |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 136 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 137 | private: |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 138 | Type(Context *); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 139 | Type(const Type &); |
| 140 | }; |
| 141 | |
| 142 | |
| 143 | class TypeState { |
| 144 | public: |
| 145 | TypeState(); |
| 146 | ~TypeState(); |
| 147 | |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 148 | // Cache of all existing types. |
| 149 | Vector<Type *> mTypes; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | |
| 153 | } |
| 154 | } |
| 155 | #endif //ANDROID_STRUCTURED_TYPE |