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 | |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 20 | #include "rsComponent.h" |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 21 | #include "rsUtils.h" |
| 22 | #include "rsObjectBase.h" |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 23 | |
| 24 | // --------------------------------------------------------------------------- |
| 25 | namespace android { |
| 26 | namespace renderscript { |
| 27 | |
| 28 | |
| 29 | // An element is a group of Components that occupies one cell in a structure. |
| 30 | class Element : public ObjectBase |
| 31 | { |
| 32 | public: |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 33 | ~Element(); |
| 34 | |
Jason Sams | 565ac36 | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 35 | uint32_t getGLType() const; |
| 36 | uint32_t getGLFormat() const; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 37 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 38 | size_t getSizeBits() const; |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 39 | size_t getSizeBytes() const { |
| 40 | return (getSizeBits() + 7) >> 3; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 43 | size_t getFieldOffsetBits(uint32_t componentNumber) const { |
| 44 | return mFields[componentNumber].offsetBits; |
| 45 | } |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 46 | size_t getFieldOffsetBytes(uint32_t componentNumber) const { |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 47 | return mFields[componentNumber].offsetBits >> 3; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 50 | uint32_t getFieldCount() const {return mFieldCount;} |
| 51 | const Element * getField(uint32_t idx) const {return mFields[idx].e.get();} |
| 52 | const char * getFieldName(uint32_t idx) const {return mFields[idx].name.string();} |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 53 | |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 54 | const Component & getComponent() const {return mComponent;} |
| 55 | RsDataType getType() const {return mComponent.getType();} |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 56 | RsDataKind getKind() const {return mComponent.getKind();} |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 57 | uint32_t getBits() const {return mBits;} |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 58 | |
Jason Sams | b4d3568 | 2010-01-04 16:52:27 -0800 | [diff] [blame] | 59 | String8 getGLSLType(uint32_t indent=0) const; |
Jason Sams | e12c1c5 | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 60 | |
| 61 | void dumpLOGV(const char *prefix) const; |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 62 | virtual void serialize(OStream *stream) const; |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 63 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ELEMENT; } |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 64 | static Element *createFromStream(Context *rsc, IStream *stream); |
Jason Sams | e12c1c5 | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 65 | |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 66 | static const Element * create(Context *rsc, RsDataType dt, RsDataKind dk, |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 67 | bool isNorm, uint32_t vecSize); |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 68 | static const Element * create(Context *rsc, size_t count, const Element **, |
Jason Sams | 46e4554 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 69 | const char **, const size_t * lengths, const uint32_t *asin); |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 70 | |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 71 | void incRefs(const void *) const; |
| 72 | void decRefs(const void *) const; |
| 73 | bool getHasReferences() const {return mHasReference;} |
| 74 | |
Alex Sakhartchouk | 383e5b1 | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 75 | bool isEqual(const Element *other) const; |
| 76 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 77 | protected: |
| 78 | // deallocate any components that are part of this element. |
| 79 | void clear(); |
| 80 | |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 81 | typedef struct { |
| 82 | String8 name; |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 83 | ObjectBaseRef<const Element> e; |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 84 | uint32_t offsetBits; |
Jason Sams | 46e4554 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 85 | uint32_t arraySize; |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 86 | } ElementField_t; |
| 87 | ElementField_t *mFields; |
| 88 | size_t mFieldCount; |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 89 | bool mHasReference; |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 90 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 91 | |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 92 | Element(Context *); |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 93 | |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 94 | Component mComponent; |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 95 | uint32_t mBits; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | |
| 99 | class ElementState { |
| 100 | public: |
| 101 | ElementState(); |
| 102 | ~ElementState(); |
| 103 | |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 104 | void elementBuilderBegin(); |
| 105 | void elementBuilderAdd(const Element *e, const char *nameStr, uint32_t arraySize); |
| 106 | const Element *elementBuilderCreate(Context *rsc); |
| 107 | |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 108 | // Cache of all existing elements. |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 109 | Vector<Element *> mElements; |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 110 | private: |
| 111 | Vector<const Element *> mBuilderElements; |
| 112 | Vector<const char*> mBuilderNameStrings; |
| 113 | Vector<size_t> mBuilderNameLengths; |
| 114 | Vector<uint32_t> mBuilderArrays; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | |
| 118 | } |
| 119 | } |
| 120 | #endif //ANDROID_STRUCTURED_ELEMENT_H |