Home | History | Annotate | Download | only in rs
      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 // ---------------------------------------------------------------------------
     23 namespace android {
     24 namespace 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 
     34 class Type : public ObjectBase {
     35 public:
     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 
    115 protected:
    116     void makeLODTable();
    117     bool mDimLOD;
    118 
    119     // Internal structure from most to least significant.
    120     // * Array dimensions
    121     // * Faces
    122     // * Mipmaps
    123     // * xyz
    124 
    125     ObjectBaseRef<const Element> mElement;
    126 
    127     // count of mipmap levels, 0 indicates no mipmapping
    128 
    129     size_t mCellCount;
    130 protected:
    131     virtual void preDestroy() const;
    132     virtual ~Type();
    133 
    134 private:
    135     Type(Context *);
    136     Type(const Type &);
    137 };
    138 
    139 
    140 class TypeState {
    141 public:
    142     TypeState();
    143     ~TypeState();
    144 
    145     // Cache of all existing types.
    146     Vector<Type *> mTypes;
    147 };
    148 
    149 
    150 }
    151 }
    152 #endif //ANDROID_STRUCTURED_TYPE
    153