rsType.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. #ifndef ANDROID_STRUCTURED_TYPE_H
  17. #define ANDROID_STRUCTURED_TYPE_H
  18. #include "rsElement.h"
  19. #include <vector>
  20. // ---------------------------------------------------------------------------
  21. namespace android {
  22. namespace renderscript {
  23. /*****************************************************************************
  24. * CAUTION
  25. *
  26. * Any layout changes for this class may require a corresponding change to be
  27. * made to frameworks/rs/driver/runtime/rs_structs.h, which contains
  28. * a partial copy of the information below.
  29. *
  30. *****************************************************************************/
  31. class Type : public ObjectBase {
  32. public:
  33. const static uint32_t mMaxArrays = 4;
  34. struct Hal {
  35. mutable void *drv;
  36. struct State {
  37. const Element * element;
  38. // Size of the structure in the various dimensions. A missing Dimension is
  39. // specified as a 0 and not a 1.
  40. uint32_t dimX;
  41. uint32_t dimY;
  42. uint32_t dimZ;
  43. uint32_t *lodDimX;
  44. uint32_t *lodDimY;
  45. uint32_t *lodDimZ;
  46. uint32_t *arrays;
  47. uint32_t lodCount;
  48. uint32_t dimYuv;
  49. uint32_t arrayCount;
  50. bool faces;
  51. };
  52. State state;
  53. };
  54. Hal mHal;
  55. void operator delete(void* ptr);
  56. Type * createTex2D(const Element *, size_t w, size_t h, bool mip);
  57. size_t getCellCount() const {return mCellCount;}
  58. size_t getElementSizeBytes() const {return mElement->getSizeBytes();}
  59. size_t getPackedSizeBytes() const {return mCellCount * mElement->getSizeBytes();}
  60. const Element * getElement() const {return mElement.get();}
  61. uint32_t getDimX() const {return mHal.state.dimX;}
  62. uint32_t getDimY() const {return mHal.state.dimY;}
  63. uint32_t getDimZ() const {return mHal.state.dimZ;}
  64. bool getDimLOD() const {return mDimLOD;}
  65. bool getDimFaces() const {return mHal.state.faces;}
  66. uint32_t getDimYuv() const {return mHal.state.dimYuv;}
  67. uint32_t getArray(uint32_t idx) const {
  68. if (idx < mHal.state.arrayCount) {
  69. return mHal.state.arrays[idx];
  70. }
  71. return 0;
  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. uint32_t getLODCount() const {return mHal.state.lodCount;}
  86. bool getIsNp2() const;
  87. void clear();
  88. void compute();
  89. void dumpLOGV(const char *prefix) const;
  90. virtual void serialize(Context *rsc, OStream *stream) const;
  91. virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; }
  92. static Type *createFromStream(Context *rsc, IStream *stream);
  93. ObjectBaseRef<Type> cloneAndResize1D(Context *rsc, uint32_t dimX) const;
  94. ObjectBaseRef<Type> cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const;
  95. static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e,
  96. const RsTypeCreateParams *params, size_t len);
  97. static Type* getType(Context *rsc, const Element *e,
  98. const RsTypeCreateParams *params, size_t len) {
  99. ObjectBaseRef<Type> type = getTypeRef(rsc, e, params, len);
  100. type->incUserRef();
  101. return type.get();
  102. }
  103. static ObjectBaseRef<Type> getTypeRef(Context *rsc, const Element *e, uint32_t dimX, uint32_t dimY = 0) {
  104. RsTypeCreateParams p;
  105. memset(&p, 0, sizeof(p));
  106. p.dimX = dimX;
  107. p.dimY = dimY;
  108. return getTypeRef(rsc, e, &p, sizeof(p));
  109. }
  110. void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
  111. void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const;
  112. virtual void callUpdateCacheObject(const Context *rsc, void *dstObj) const;
  113. protected:
  114. void makeLODTable();
  115. bool mDimLOD;
  116. // Internal structure from most to least significant.
  117. // * Array dimensions
  118. // * Faces
  119. // * Mipmaps
  120. // * xyz
  121. ObjectBaseRef<const Element> mElement;
  122. // count of mipmap levels, 0 indicates no mipmapping
  123. size_t mCellCount;
  124. protected:
  125. virtual void preDestroy() const;
  126. virtual ~Type();
  127. private:
  128. explicit Type(Context *);
  129. Type(const Type &);
  130. };
  131. class TypeState {
  132. public:
  133. TypeState();
  134. ~TypeState();
  135. // Cache of all existing types.
  136. std::vector<Type *> mTypes;
  137. };
  138. } // namespace renderscript
  139. } // namespace android
  140. #endif //ANDROID_STRUCTURED_TYPE