Jason Sams | d19f10d | 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 | |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 20 | #include "rsComponent.h" |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 21 | #include "rsUtils.h" |
| 22 | #include "rsObjectBase.h" |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 23 | |
| 24 | // --------------------------------------------------------------------------- |
| 25 | namespace android { |
| 26 | namespace renderscript { |
| 27 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 28 | // An element is a group of Components that occupies one cell in a structure. |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 29 | class Element : public ObjectBase { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 30 | public: |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 31 | class Builder { |
| 32 | public: |
Alex Sakhartchouk | a8bb921 | 2011-08-19 09:43:18 -0700 | [diff] [blame] | 33 | Builder(); |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 34 | void add(const Element *e, const char *nameStr, uint32_t arraySize); |
| 35 | ObjectBaseRef<const Element> create(Context *rsc); |
| 36 | private: |
| 37 | Vector<ObjectBaseRef<const Element> > mBuilderElementRefs; |
| 38 | Vector<const Element *> mBuilderElements; |
| 39 | Vector<const char*> mBuilderNameStrings; |
| 40 | Vector<size_t> mBuilderNameLengths; |
| 41 | Vector<uint32_t> mBuilderArrays; |
| 42 | }; |
Jason Sams | e2ae85f | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 43 | uint32_t getGLType() const; |
| 44 | uint32_t getGLFormat() const; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 45 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 46 | size_t getSizeBits() const; |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 47 | size_t getSizeBytes() const { |
| 48 | return (getSizeBits() + 7) >> 3; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 51 | size_t getFieldOffsetBits(uint32_t componentNumber) const { |
| 52 | return mFields[componentNumber].offsetBits; |
| 53 | } |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 54 | size_t getFieldOffsetBytes(uint32_t componentNumber) const { |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 55 | return mFields[componentNumber].offsetBits >> 3; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 58 | uint32_t getFieldCount() const {return mFieldCount;} |
| 59 | const Element * getField(uint32_t idx) const {return mFields[idx].e.get();} |
| 60 | const char * getFieldName(uint32_t idx) const {return mFields[idx].name.string();} |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 61 | uint32_t getFieldArraySize(uint32_t idx) const {return mFields[idx].arraySize;} |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 62 | |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 63 | const Component & getComponent() const {return mComponent;} |
| 64 | RsDataType getType() const {return mComponent.getType();} |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 65 | RsDataKind getKind() const {return mComponent.getKind();} |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 66 | uint32_t getBits() const {return mBits;} |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 67 | |
Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 68 | void dumpLOGV(const char *prefix) const; |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 69 | virtual void serialize(OStream *stream) const; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 70 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ELEMENT; } |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 71 | static Element *createFromStream(Context *rsc, IStream *stream); |
Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 72 | |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 73 | static ObjectBaseRef<const Element> createRef(Context *rsc, |
| 74 | RsDataType dt, |
| 75 | RsDataKind dk, |
| 76 | bool isNorm, |
| 77 | uint32_t vecSize); |
| 78 | static ObjectBaseRef<const Element> createRef(Context *rsc, size_t count, |
| 79 | const Element **, |
| 80 | const char **, |
| 81 | const size_t * lengths, |
| 82 | const uint32_t *asin); |
| 83 | |
| 84 | static const Element* create(Context *rsc, |
| 85 | RsDataType dt, |
| 86 | RsDataKind dk, |
| 87 | bool isNorm, |
| 88 | uint32_t vecSize) { |
| 89 | ObjectBaseRef<const Element> elem = createRef(rsc, dt, dk, isNorm, vecSize); |
| 90 | elem->incUserRef(); |
| 91 | return elem.get(); |
| 92 | } |
| 93 | static const Element* create(Context *rsc, size_t count, |
| 94 | const Element **ein, |
| 95 | const char **nin, |
| 96 | const size_t * lengths, |
| 97 | const uint32_t *asin) { |
| 98 | ObjectBaseRef<const Element> elem = createRef(rsc, count, ein, nin, lengths, asin); |
| 99 | elem->incUserRef(); |
| 100 | return elem.get(); |
| 101 | } |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 102 | |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 103 | void incRefs(const void *) const; |
| 104 | void decRefs(const void *) const; |
| 105 | bool getHasReferences() const {return mHasReference;} |
| 106 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 107 | protected: |
| 108 | // deallocate any components that are part of this element. |
| 109 | void clear(); |
| 110 | |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 111 | typedef struct { |
| 112 | String8 name; |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 113 | ObjectBaseRef<const Element> e; |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 114 | uint32_t offsetBits; |
Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 115 | uint32_t arraySize; |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 116 | } ElementField_t; |
| 117 | ElementField_t *mFields; |
| 118 | size_t mFieldCount; |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 119 | bool mHasReference; |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 120 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 121 | |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 122 | virtual ~Element(); |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 123 | Element(Context *); |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 124 | |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 125 | Component mComponent; |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 126 | uint32_t mBits; |
Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 127 | |
| 128 | void compute(); |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 129 | |
| 130 | virtual void preDestroy() const; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | |
| 134 | class ElementState { |
| 135 | public: |
| 136 | ElementState(); |
| 137 | ~ElementState(); |
| 138 | |
Jason Sams | e4c487a | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 139 | // Cache of all existing elements. |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 140 | Vector<Element *> mElements; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | |
| 144 | } |
| 145 | } |
| 146 | #endif //ANDROID_STRUCTURED_ELEMENT_H |