rsType.h revision b99ed44dcffcc268958e86a7bdba2c683d729cf6
1/* 2 * Copyright (C) 2011 The Android Open Source Project 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// --------------------------------------------------------------------------- 23namespace android { 24namespace renderscript { 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 *****************************************************************************/ 33 34class Type : public ObjectBase { 35public: 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; 47 uint32_t *lodDimX; 48 uint32_t *lodDimY; 49 uint32_t *lodDimZ; 50 uint32_t lodCount; 51 bool faces; 52 }; 53 State state; 54 }; 55 Hal mHal; 56 57 Type * createTex2D(const Element *, size_t w, size_t h, bool mip); 58 59 size_t getSizeBytes() const {return mTotalSizeBytes;} 60 size_t getElementSizeBytes() const {return mElement->getSizeBytes();} 61 const Element * getElement() const {return mElement.get();} 62 63 uint32_t getDimX() const {return mHal.state.dimX;} 64 uint32_t getDimY() const {return mHal.state.dimY;} 65 uint32_t getDimZ() const {return mHal.state.dimZ;} 66 bool getDimLOD() const {return mDimLOD;} 67 bool getDimFaces() const {return mHal.state.faces;} 68 69 uint32_t getLODDimX(uint32_t lod) const { 70 rsAssert(lod < mHal.state.lodCount); 71 return mHal.state.lodDimX[lod]; 72 } 73 uint32_t getLODDimY(uint32_t lod) const { 74 rsAssert(lod < mHal.state.lodCount); 75 return mHal.state.lodDimY[lod]; 76 } 77 uint32_t getLODDimZ(uint32_t lod) const { 78 rsAssert(lod < mHal.state.lodCount); 79 return mHal.state.lodDimZ[lod]; 80 } 81 82 uint32_t getLODCount() const {return mHal.state.lodCount;} 83 bool getIsNp2() const; 84 85 void clear(); 86 void compute(); 87 88 void dumpLOGV(const char *prefix) const; 89 virtual void serialize(Context *rsc, OStream *stream) const; 90 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; } 91 static Type *createFromStream(Context *rsc, IStream *stream); 92 93 ObjectBaseRef<Type> cloneAndResize1D(Context *rsc, uint32_t dimX) const; 94 ObjectBaseRef<Type> cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const; 95 96 static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e, 97 uint32_t dimX, uint32_t dimY, uint32_t dimZ, 98 bool dimLOD, bool dimFaces); 99 100 static Type* getType(Context *rsc, const Element *e, 101 uint32_t dimX, uint32_t dimY, uint32_t dimZ, 102 bool dimLOD, bool dimFaces) { 103 ObjectBaseRef<Type> type = getTypeRef(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces); 104 type->incUserRef(); 105 return type.get(); 106 } 107 108 void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const; 109 void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const; 110 111protected: 112 void makeLODTable(); 113 bool mDimLOD; 114 115 // Internal structure from most to least significant. 116 // * Array dimensions 117 // * Faces 118 // * Mipmaps 119 // * xyz 120 121 ObjectBaseRef<const Element> mElement; 122 123 // count of mipmap levels, 0 indicates no mipmapping 124 125 // Sizes are packed size, not including any padding. 126 // i.e. cell counts. 127 size_t mMipChainSizeBytes; 128 size_t mTotalSizeBytes; 129protected: 130 virtual void preDestroy() const; 131 virtual ~Type(); 132 133private: 134 Type(Context *); 135 Type(const Type &); 136}; 137 138 139class TypeState { 140public: 141 TypeState(); 142 ~TypeState(); 143 144 // Cache of all existing types. 145 Vector<Type *> mTypes; 146}; 147 148 149} 150} 151#endif //ANDROID_STRUCTURED_TYPE 152