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