rsElement.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright (C) 2009 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_ELEMENT_H
  17. #define ANDROID_STRUCTURED_ELEMENT_H
  18. #include "rsComponent.h"
  19. #include "rsUtils.h"
  20. #include "rsInternalDefines.h"
  21. #include "rsObjectBase.h"
  22. #include <vector>
  23. // ---------------------------------------------------------------------------
  24. namespace android {
  25. namespace renderscript {
  26. /*****************************************************************************
  27. * CAUTION
  28. *
  29. * Any layout changes for this class may require a corresponding change to be
  30. * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains
  31. * a partial copy of the information below.
  32. *
  33. *****************************************************************************/
  34. // An element is a group of Components that occupies one cell in a structure.
  35. class Element : public ObjectBase {
  36. public:
  37. struct Hal {
  38. mutable void *drv;
  39. struct State {
  40. RsDataType dataType;
  41. RsDataKind dataKind;
  42. uint32_t vectorSize;
  43. uint32_t elementSizeBytes;
  44. // Subelements
  45. const Element **fields;
  46. uint32_t *fieldArraySizes;
  47. const char **fieldNames;
  48. uint32_t *fieldNameLengths;
  49. uint32_t *fieldOffsetBytes;
  50. uint32_t fieldsCount;
  51. };
  52. State state;
  53. };
  54. Hal mHal;
  55. void operator delete(void* ptr);
  56. uint32_t getGLType() const;
  57. uint32_t getGLFormat() const;
  58. size_t getSizeBitsUnpadded() const;
  59. size_t getSizeBytesUnpadded() const {
  60. return (getSizeBitsUnpadded() + 7) >> 3;
  61. }
  62. size_t getSizeBits() const;
  63. size_t getSizeBytes() const {
  64. return (getSizeBits() + 7) >> 3;
  65. }
  66. size_t getFieldOffsetBits(uint32_t componentNumber) const {
  67. return mFields[componentNumber].offsetBits;
  68. }
  69. size_t getFieldOffsetBytes(uint32_t componentNumber) const {
  70. return mFields[componentNumber].offsetBits >> 3;
  71. }
  72. size_t getFieldOffsetBytesUnpadded(uint32_t componentNumber) const {
  73. return mFields[componentNumber].offsetBitsUnpadded >> 3;
  74. }
  75. uint32_t getFieldCount() const {return mFieldCount;}
  76. const Element * getField(uint32_t idx) const {return mFields[idx].e.get();}
  77. const char * getFieldName(uint32_t idx) const {return mFields[idx].name;}
  78. uint32_t getFieldArraySize(uint32_t idx) const {return mFields[idx].arraySize;}
  79. const Component & getComponent() const {return mComponent;}
  80. RsDataType getType() const {return mComponent.getType();}
  81. RsDataKind getKind() const {return mComponent.getKind();}
  82. uint32_t getBits() const {return mBits;}
  83. uint32_t getBitsUnpadded() const {return mBitsUnpadded;}
  84. uint32_t getVectorSize() const {return mComponent.getVectorSize();}
  85. void dumpLOGV(const char *prefix) const;
  86. virtual void serialize(Context *rsc, OStream *stream) const;
  87. virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ELEMENT; }
  88. static Element *createFromStream(Context *rsc, IStream *stream);
  89. static ObjectBaseRef<const Element> createRef(Context *rsc,
  90. RsDataType dt,
  91. RsDataKind dk,
  92. bool isNorm,
  93. uint32_t vecSize);
  94. static ObjectBaseRef<const Element> createRef(Context *rsc, size_t count,
  95. const Element **,
  96. const char **,
  97. const size_t * lengths,
  98. const uint32_t *asin);
  99. static const Element* create(Context *rsc,
  100. RsDataType dt,
  101. RsDataKind dk,
  102. bool isNorm,
  103. uint32_t vecSize) {
  104. ObjectBaseRef<const Element> elem = createRef(rsc, dt, dk, isNorm, vecSize);
  105. elem->incUserRef();
  106. return elem.get();
  107. }
  108. static const Element* create(Context *rsc, size_t count,
  109. const Element **ein,
  110. const char **nin,
  111. const size_t * lengths = nullptr,
  112. const uint32_t *asin = nullptr) {
  113. ObjectBaseRef<const Element> elem = createRef(rsc, count, ein, nin, lengths, asin);
  114. elem->incUserRef();
  115. return elem.get();
  116. }
  117. void incRefs(const void *) const;
  118. void decRefs(const void *) const;
  119. virtual void callUpdateCacheObject(const Context *rsc, void *dstObj) const;
  120. bool getHasReferences() const {return mHasReference;}
  121. protected:
  122. // deallocate any components that are part of this element.
  123. void clear();
  124. typedef struct {
  125. const char *name;
  126. ObjectBaseRef<const Element> e;
  127. uint32_t offsetBits;
  128. uint32_t offsetBitsUnpadded;
  129. uint32_t arraySize;
  130. } ElementField_t;
  131. ElementField_t *mFields;
  132. size_t mFieldCount;
  133. bool mHasReference;
  134. virtual ~Element();
  135. explicit Element(Context *);
  136. Component mComponent;
  137. uint32_t mBitsUnpadded;
  138. uint32_t mBits;
  139. void compute();
  140. virtual void preDestroy() const;
  141. };
  142. class ElementState {
  143. public:
  144. ElementState();
  145. ~ElementState();
  146. // Cache of all existing elements.
  147. std::vector<Element *> mElements;
  148. };
  149. } // namespace renderscript
  150. } // namespace android
  151. #endif //ANDROID_STRUCTURED_ELEMENT_H