Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 | |
| 17 | #ifndef ANDROID_STRUCTURED_ELEMENT_H |
| 18 | #define ANDROID_STRUCTURED_ELEMENT_H |
| 19 | |
Chris Wailes | 93d6bc8 | 2014-07-28 16:54:38 -0700 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 22 | #include "rsComponent.h" |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 23 | #include "rsUtils.h" |
Alex Sakhartchouk | e23d239 | 2012-03-09 09:24:39 -0800 | [diff] [blame] | 24 | #include "rsDefines.h" |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 25 | #include "rsObjectBase.h" |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 26 | |
| 27 | // --------------------------------------------------------------------------- |
| 28 | namespace android { |
| 29 | namespace renderscript { |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 30 | /***************************************************************************** |
| 31 | * CAUTION |
| 32 | * |
| 33 | * Any layout changes for this class may require a corresponding change to be |
| 34 | * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains |
| 35 | * a partial copy of the information below. |
| 36 | * |
| 37 | *****************************************************************************/ |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 38 | // An element is a group of Components that occupies one cell in a structure. |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 39 | class Element : public ObjectBase { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 40 | public: |
Alex Sakhartchouk | 253325d | 2011-12-15 09:56:10 -0800 | [diff] [blame] | 41 | struct Hal { |
| 42 | mutable void *drv; |
| 43 | |
| 44 | struct State { |
| 45 | RsDataType dataType; |
| 46 | RsDataKind dataKind; |
| 47 | uint32_t vectorSize; |
| 48 | uint32_t elementSizeBytes; |
| 49 | |
| 50 | // Subelements |
| 51 | const Element **fields; |
| 52 | uint32_t *fieldArraySizes; |
| 53 | const char **fieldNames; |
| 54 | uint32_t *fieldNameLengths; |
| 55 | uint32_t *fieldOffsetBytes; |
| 56 | uint32_t fieldsCount; |
| 57 | }; |
| 58 | State state; |
| 59 | }; |
| 60 | Hal mHal; |
| 61 | |
Tim Murray | 49a8777 | 2014-07-10 10:00:00 -0700 | [diff] [blame] | 62 | void operator delete(void* ptr); |
| 63 | |
Jason Sams | 565ac36 | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 64 | uint32_t getGLType() const; |
| 65 | uint32_t getGLFormat() const; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 66 | |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 67 | size_t getSizeBitsUnpadded() const; |
| 68 | size_t getSizeBytesUnpadded() const { |
| 69 | return (getSizeBitsUnpadded() + 7) >> 3; |
| 70 | } |
| 71 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 72 | size_t getSizeBits() const; |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 73 | size_t getSizeBytes() const { |
| 74 | return (getSizeBits() + 7) >> 3; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 77 | size_t getFieldOffsetBits(uint32_t componentNumber) const { |
| 78 | return mFields[componentNumber].offsetBits; |
| 79 | } |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 80 | size_t getFieldOffsetBytes(uint32_t componentNumber) const { |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 81 | return mFields[componentNumber].offsetBits >> 3; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 84 | size_t getFieldOffsetBytesUnpadded(uint32_t componentNumber) const { |
| 85 | return mFields[componentNumber].offsetBitsUnpadded >> 3; |
| 86 | } |
| 87 | |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 88 | uint32_t getFieldCount() const {return mFieldCount;} |
| 89 | const Element * getField(uint32_t idx) const {return mFields[idx].e.get();} |
Jason Sams | 48ecf6a | 2013-07-09 15:35:29 -0700 | [diff] [blame] | 90 | const char * getFieldName(uint32_t idx) const {return mFields[idx].name;} |
Alex Sakhartchouk | 39f2ef6 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 91 | uint32_t getFieldArraySize(uint32_t idx) const {return mFields[idx].arraySize;} |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 92 | |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 93 | const Component & getComponent() const {return mComponent;} |
| 94 | RsDataType getType() const {return mComponent.getType();} |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 95 | RsDataKind getKind() const {return mComponent.getKind();} |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 96 | uint32_t getBits() const {return mBits;} |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 97 | uint32_t getBitsUnpadded() const {return mBitsUnpadded;} |
Jason Sams | c905efd | 2012-11-26 15:20:18 -0800 | [diff] [blame] | 98 | uint32_t getVectorSize() const {return mComponent.getVectorSize();} |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 99 | |
Jason Sams | e12c1c5 | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 100 | void dumpLOGV(const char *prefix) const; |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 101 | virtual void serialize(Context *rsc, OStream *stream) const; |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 102 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ELEMENT; } |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 103 | static Element *createFromStream(Context *rsc, IStream *stream); |
Jason Sams | e12c1c5 | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 104 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 105 | static ObjectBaseRef<const Element> createRef(Context *rsc, |
| 106 | RsDataType dt, |
| 107 | RsDataKind dk, |
| 108 | bool isNorm, |
| 109 | uint32_t vecSize); |
| 110 | static ObjectBaseRef<const Element> createRef(Context *rsc, size_t count, |
| 111 | const Element **, |
| 112 | const char **, |
| 113 | const size_t * lengths, |
| 114 | const uint32_t *asin); |
| 115 | |
| 116 | static const Element* create(Context *rsc, |
| 117 | RsDataType dt, |
| 118 | RsDataKind dk, |
| 119 | bool isNorm, |
| 120 | uint32_t vecSize) { |
| 121 | ObjectBaseRef<const Element> elem = createRef(rsc, dt, dk, isNorm, vecSize); |
| 122 | elem->incUserRef(); |
| 123 | return elem.get(); |
| 124 | } |
| 125 | static const Element* create(Context *rsc, size_t count, |
| 126 | const Element **ein, |
| 127 | const char **nin, |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 128 | const size_t * lengths = nullptr, |
| 129 | const uint32_t *asin = nullptr) { |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 130 | ObjectBaseRef<const Element> elem = createRef(rsc, count, ein, nin, lengths, asin); |
| 131 | elem->incUserRef(); |
| 132 | return elem.get(); |
| 133 | } |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 134 | |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 135 | void incRefs(const void *) const; |
| 136 | void decRefs(const void *) const; |
Jason Sams | a36c50a | 2014-06-17 12:06:06 -0700 | [diff] [blame] | 137 | virtual void callUpdateCacheObject(const Context *rsc, void *dstObj) const; |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 138 | bool getHasReferences() const {return mHasReference;} |
| 139 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 140 | protected: |
| 141 | // deallocate any components that are part of this element. |
| 142 | void clear(); |
| 143 | |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 144 | typedef struct { |
Jason Sams | 48ecf6a | 2013-07-09 15:35:29 -0700 | [diff] [blame] | 145 | const char *name; |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 146 | ObjectBaseRef<const Element> e; |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 147 | uint32_t offsetBits; |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 148 | uint32_t offsetBitsUnpadded; |
Jason Sams | 46e4554 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 149 | uint32_t arraySize; |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 150 | } ElementField_t; |
| 151 | ElementField_t *mFields; |
| 152 | size_t mFieldCount; |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 153 | bool mHasReference; |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 154 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 155 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 156 | virtual ~Element(); |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 157 | Element(Context *); |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 158 | |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 159 | Component mComponent; |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 160 | uint32_t mBitsUnpadded; |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 161 | uint32_t mBits; |
Alex Sakhartchouk | 54929cc | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 162 | |
| 163 | void compute(); |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 164 | |
| 165 | virtual void preDestroy() const; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | |
| 169 | class ElementState { |
| 170 | public: |
| 171 | ElementState(); |
| 172 | ~ElementState(); |
| 173 | |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 174 | // Cache of all existing elements. |
Chris Wailes | 93d6bc8 | 2014-07-28 16:54:38 -0700 | [diff] [blame] | 175 | std::vector<Element *> mElements; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | |
| 179 | } |
| 180 | } |
| 181 | #endif //ANDROID_STRUCTURED_ELEMENT_H |