Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 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 { |
| 25 | |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 26 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 27 | class Type : public ObjectBase { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 28 | public: |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 29 | Type * createTex2D(const Element *, size_t w, size_t h, bool mip); |
| 30 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 31 | size_t getOffsetForFace(uint32_t face) const; |
| 32 | |
| 33 | size_t getSizeBytes() const {return mTotalSizeBytes;} |
| 34 | size_t getElementSizeBytes() const {return mElement->getSizeBytes();} |
| 35 | const Element * getElement() const {return mElement.get();} |
| 36 | |
| 37 | uint32_t getDimX() const {return mDimX;} |
| 38 | uint32_t getDimY() const {return mDimY;} |
| 39 | uint32_t getDimZ() const {return mDimZ;} |
| 40 | uint32_t getDimLOD() const {return mDimLOD;} |
| 41 | bool getDimFaces() const {return mFaces;} |
| 42 | |
| 43 | uint32_t getLODDimX(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mX;} |
| 44 | uint32_t getLODDimY(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mY;} |
| 45 | uint32_t getLODDimZ(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mZ;} |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 46 | |
Jason Sams | bcac934 | 2011-01-13 17:38:18 -0800 | [diff] [blame] | 47 | uint32_t getLODOffset(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mOffset;} |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 48 | uint32_t getLODOffset(uint32_t lod, uint32_t x) const; |
| 49 | uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const; |
| 50 | uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) const; |
| 51 | |
Jason Sams | bcac934 | 2011-01-13 17:38:18 -0800 | [diff] [blame] | 52 | uint32_t getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face, uint32_t x, uint32_t y) const; |
| 53 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 54 | uint32_t getLODCount() const {return mLODCount;} |
Jason Sams | ef21edc | 2010-02-22 15:37:51 -0800 | [diff] [blame] | 55 | bool getIsNp2() const; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 56 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 57 | void clear(); |
| 58 | void compute(); |
| 59 | |
Jason Sams | e12c1c5 | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 60 | void dumpLOGV(const char *prefix) const; |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 61 | virtual void serialize(OStream *stream) const; |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 62 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; } |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 63 | static Type *createFromStream(Context *rsc, IStream *stream); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 64 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 65 | ObjectBaseRef<Type> cloneAndResize1D(Context *rsc, uint32_t dimX) const; |
| 66 | ObjectBaseRef<Type> cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const; |
Alex Sakhartchouk | 383e5b1 | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 67 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 68 | static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e, |
| 69 | uint32_t dimX, uint32_t dimY, uint32_t dimZ, |
| 70 | bool dimLOD, bool dimFaces); |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 71 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 72 | static Type* getType(Context *rsc, const Element *e, |
| 73 | uint32_t dimX, uint32_t dimY, uint32_t dimZ, |
| 74 | bool dimLOD, bool dimFaces) { |
| 75 | ObjectBaseRef<Type> type = getTypeRef(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces); |
| 76 | type->incUserRef(); |
| 77 | return type.get(); |
| 78 | } |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 79 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 80 | protected: |
| 81 | struct LOD { |
| 82 | size_t mX; |
| 83 | size_t mY; |
| 84 | size_t mZ; |
| 85 | size_t mOffset; |
| 86 | }; |
| 87 | |
| 88 | void makeLODTable(); |
| 89 | |
| 90 | // Internal structure from most to least significant. |
| 91 | // * Array dimensions |
| 92 | // * Faces |
| 93 | // * Mipmaps |
| 94 | // * xyz |
| 95 | |
| 96 | ObjectBaseRef<const Element> mElement; |
| 97 | |
| 98 | // Size of the structure in the various dimensions. A missing Dimension is |
| 99 | // specified as a 0 and not a 1. |
| 100 | size_t mDimX; |
| 101 | size_t mDimY; |
| 102 | size_t mDimZ; |
| 103 | bool mDimLOD; |
| 104 | bool mFaces; |
| 105 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 106 | // count of mipmap levels, 0 indicates no mipmapping |
| 107 | |
| 108 | size_t mMipChainSizeBytes; |
| 109 | size_t mTotalSizeBytes; |
| 110 | LOD *mLODs; |
| 111 | uint32_t mLODCount; |
| 112 | |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 113 | protected: |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 114 | virtual void preDestroy() const; |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 115 | virtual ~Type(); |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 116 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 117 | private: |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 118 | Type(Context *); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 119 | Type(const Type &); |
| 120 | }; |
| 121 | |
| 122 | |
| 123 | class TypeState { |
| 124 | public: |
| 125 | TypeState(); |
| 126 | ~TypeState(); |
| 127 | |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 128 | // Cache of all existing types. |
| 129 | Vector<Type *> mTypes; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | |
| 133 | } |
| 134 | } |
| 135 | #endif //ANDROID_STRUCTURED_TYPE |