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 20 #include "rsComponent.h" 21 #include "rsUtils.h" 22 #include "rsObjectBase.h" 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: 33 ~Element(); 34 35 uint32_t getGLType() const; 36 uint32_t getGLFormat() const; 37 38 size_t getSizeBits() const; 39 size_t getSizeBytes() const { 40 return (getSizeBits() + 7) >> 3; 41 } 42 43 size_t getFieldOffsetBits(uint32_t componentNumber) const; 44 size_t getFieldOffsetBytes(uint32_t componentNumber) const { 45 return (getFieldOffsetBits(componentNumber) + 7) >> 3; 46 } 47 48 uint32_t getFieldCount() const {return mFieldCount;} 49 const Element * getField(uint32_t idx) const {return mFields[idx].e.get();} 50 const char * getFieldName(uint32_t idx) const {return mFields[idx].name.string();} 51 52 const Component & getComponent() const {return mComponent;} 53 RsDataType getType() const {return mComponent.getType();} 54 RsDataKind getKind() const {return mComponent.getKind();} 55 uint32_t getBits() const {return mBits;} 56 57 String8 getCType(uint32_t indent=0) const; 58 String8 getCStructBody(uint32_t indent=0) const; 59 String8 getGLSLType(uint32_t indent=0) const; 60 61 void dumpLOGV(const char *prefix) const; 62 63 static const Element * create(Context *rsc, RsDataType dt, RsDataKind dk, 64 bool isNorm, uint32_t vecSize); 65 static const Element * create(Context *rsc, size_t count, const Element **, 66 const char **, const size_t * lengths); 67 68 protected: 69 // deallocate any components that are part of this element. 70 void clear(); 71 72 typedef struct { 73 String8 name; 74 ObjectBaseRef<const Element> e; 75 } ElementField_t; 76 ElementField_t *mFields; 77 size_t mFieldCount; 78 79 80 Element(Context *); 81 82 Component mComponent; 83 uint32_t mBits; 84 }; 85 86 87 class ElementState { 88 public: 89 ElementState(); 90 ~ElementState(); 91 92 // Cache of all existing elements. 93 Vector<const Element *> mElements; 94 }; 95 96 97 } 98 } 99 #endif //ANDROID_STRUCTURED_ELEMENT_H 100