rsElement.h revision d01d970cf5973aa5186cc02c80fb2c143a69b0b1
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// --------------------------------------------------------------------------- 25namespace android { 26namespace renderscript { 27 28 29// An element is a group of Components that occupies one cell in a structure. 30class Element : public ObjectBase 31{ 32public: 33 ~Element(); 34 35 36 //void setComponent(uint32_t idx, Component *c); 37 38 uint32_t getGLType() const; 39 uint32_t getGLFormat() const; 40 41 42 size_t getSizeBits() const; 43 size_t getSizeBytes() const { 44 return (getSizeBits() + 7) >> 3; 45 } 46 47 size_t getFieldOffsetBits(uint32_t componentNumber) const; 48 size_t getFieldOffsetBytes(uint32_t componentNumber) const { 49 return (getFieldOffsetBits(componentNumber) + 7) >> 3; 50 } 51 52 uint32_t getFieldCount() const {return mFieldCount;} 53 const Element * getField(uint32_t idx) const {return mFields[idx].e.get();} 54 const char * getFieldName(uint32_t idx) const {return mFields[idx].name.string();} 55 56 const Component & getComponent() const {return mComponent;} 57 RsDataType getType() const {return mComponent.getType();} 58 //bool getIsNormalized() const {return mIsNormalized;} 59 RsDataKind getKind() const {return mComponent.getKind();} 60 uint32_t getBits() const {return mBits;} 61 //uint32_t getGLType() const; 62 63 String8 getCType(uint32_t indent=0) const; 64 String8 getCStructBody(uint32_t indent=0) const; 65 66 void dumpLOGV(const char *prefix) const; 67 68 static Element * create(Context *rsc, RsDataType dt, RsDataKind dk, 69 bool isNorm, uint32_t vecSize); 70 static Element * create(Context *rsc, size_t count, const Element **, 71 const char **, const size_t * lengths); 72 73protected: 74 // deallocate any components that are part of this element. 75 void clear(); 76 77 typedef struct { 78 String8 name; 79 ObjectBaseRef<const Element> e; 80 } ElementField_t; 81 ElementField_t *mFields; 82 size_t mFieldCount; 83 84 85 Element(Context *); 86 87 Component mComponent; 88 uint32_t mBits; 89}; 90 91 92class ElementState { 93public: 94 ElementState(); 95 ~ElementState(); 96 97 Vector<Element *> mBuildList; 98 Vector<String8> mNames; 99}; 100 101 102} 103} 104#endif //ANDROID_STRUCTURED_ELEMENT_H 105