1 /* 2 * Copyright (C) 2012 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_ELEMENT_H__ 18 #define __ANDROID_ELEMENT_H__ 19 20 #include <rs.h> 21 #include "RenderScript.h" 22 #include "BaseObj.h" 23 24 namespace android { 25 namespace renderscriptCpp { 26 27 class Element : public BaseObj { 28 public: 29 /** 30 * Return if a element is too complex for use as a data source for a Mesh or 31 * a Program. 32 * 33 * @return boolean 34 */ 35 bool isComplex(); 36 37 /** 38 * @hide 39 * @return number of sub-elements in this element 40 */ getSubElementCount()41 size_t getSubElementCount() { 42 return mVisibleElementMap.size(); 43 } 44 45 /** 46 * @hide 47 * @param index index of the sub-element to return 48 * @return sub-element in this element at given index 49 */ 50 sp<const Element> getSubElement(uint32_t index); 51 52 /** 53 * @hide 54 * @param index index of the sub-element 55 * @return sub-element in this element at given index 56 */ 57 const char * getSubElementName(uint32_t index); 58 59 /** 60 * @hide 61 * @param index index of the sub-element 62 * @return array size of sub-element in this element at given index 63 */ 64 size_t getSubElementArraySize(uint32_t index); 65 66 /** 67 * @hide 68 * @param index index of the sub-element 69 * @return offset in bytes of sub-element in this element at given index 70 */ 71 uint32_t getSubElementOffsetBytes(uint32_t index); 72 73 /** 74 * @hide 75 * @return element data type 76 */ getDataType()77 RsDataType getDataType() const { 78 return mType; 79 } 80 81 /** 82 * @hide 83 * @return element data kind 84 */ getDataKind()85 RsDataKind getDataKind() const { 86 return mKind; 87 } 88 getSizeBytes()89 size_t getSizeBytes() const { 90 return mSizeBytes; 91 } 92 93 94 static sp<const Element> BOOLEAN(RenderScript *rs); 95 static sp<const Element> U8(RenderScript *rs); 96 static sp<const Element> I8(RenderScript *rs); 97 static sp<const Element> U16(RenderScript *rs); 98 static sp<const Element> I16(RenderScript *rs); 99 static sp<const Element> U32(RenderScript *rs); 100 static sp<const Element> I32(RenderScript *rs); 101 static sp<const Element> U64(RenderScript *rs); 102 static sp<const Element> I64(RenderScript *rs); 103 static sp<const Element> F32(RenderScript *rs); 104 static sp<const Element> F64(RenderScript *rs); 105 static sp<const Element> ELEMENT(RenderScript *rs); 106 static sp<const Element> TYPE(RenderScript *rs); 107 static sp<const Element> ALLOCATION(RenderScript *rs); 108 static sp<const Element> SAMPLER(RenderScript *rs); 109 static sp<const Element> SCRIPT(RenderScript *rs); 110 static sp<const Element> MESH(RenderScript *rs); 111 static sp<const Element> PROGRAM_FRAGMENT(RenderScript *rs); 112 static sp<const Element> PROGRAM_VERTEX(RenderScript *rs); 113 static sp<const Element> PROGRAM_RASTER(RenderScript *rs); 114 static sp<const Element> PROGRAM_STORE(RenderScript *rs); 115 116 static sp<const Element> A_8(RenderScript *rs); 117 static sp<const Element> RGB_565(RenderScript *rs); 118 static sp<const Element> RGB_888(RenderScript *rs); 119 static sp<const Element> RGBA_5551(RenderScript *rs); 120 static sp<const Element> RGBA_4444(RenderScript *rs); 121 static sp<const Element> RGBA_8888(RenderScript *rs); 122 123 static sp<const Element> F32_2(RenderScript *rs); 124 static sp<const Element> F32_3(RenderScript *rs); 125 static sp<const Element> F32_4(RenderScript *rs); 126 static sp<const Element> F64_2(RenderScript *rs); 127 static sp<const Element> F64_3(RenderScript *rs); 128 static sp<const Element> F64_4(RenderScript *rs); 129 static sp<const Element> U8_2(RenderScript *rs); 130 static sp<const Element> U8_3(RenderScript *rs); 131 static sp<const Element> U8_4(RenderScript *rs); 132 static sp<const Element> I8_2(RenderScript *rs); 133 static sp<const Element> I8_3(RenderScript *rs); 134 static sp<const Element> I8_4(RenderScript *rs); 135 static sp<const Element> U16_2(RenderScript *rs); 136 static sp<const Element> U16_3(RenderScript *rs); 137 static sp<const Element> U16_4(RenderScript *rs); 138 static sp<const Element> I16_2(RenderScript *rs); 139 static sp<const Element> I16_3(RenderScript *rs); 140 static sp<const Element> I16_4(RenderScript *rs); 141 static sp<const Element> U32_2(RenderScript *rs); 142 static sp<const Element> U32_3(RenderScript *rs); 143 static sp<const Element> U32_4(RenderScript *rs); 144 static sp<const Element> I32_2(RenderScript *rs); 145 static sp<const Element> I32_3(RenderScript *rs); 146 static sp<const Element> I32_4(RenderScript *rs); 147 static sp<const Element> U64_2(RenderScript *rs); 148 static sp<const Element> U64_3(RenderScript *rs); 149 static sp<const Element> U64_4(RenderScript *rs); 150 static sp<const Element> I64_2(RenderScript *rs); 151 static sp<const Element> I64_3(RenderScript *rs); 152 static sp<const Element> I64_4(RenderScript *rs); 153 static sp<const Element> MATRIX_4X4(RenderScript *rs); 154 static sp<const Element> MATRIX_3X3(RenderScript *rs); 155 static sp<const Element> MATRIX_2X2(RenderScript *rs); 156 157 Element(void *id, RenderScript *rs, 158 android::Vector<sp</*const*/ Element> > &elements, 159 android::Vector<android::String8> &elementNames, 160 android::Vector<uint32_t> &arraySizes); 161 Element(void *id, RenderScript *rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size); 162 Element(RenderScript *rs); 163 virtual ~Element(); 164 165 void updateFromNative(); 166 static sp<const Element> createUser(RenderScript *rs, RsDataType dt); 167 static sp<const Element> createVector(RenderScript *rs, RsDataType dt, uint32_t size); 168 static sp<const Element> createPixel(RenderScript *rs, RsDataType dt, RsDataKind dk); 169 bool isCompatible(sp<const Element>e); 170 171 class Builder { 172 private: 173 RenderScript *mRS; 174 android::Vector<sp</*const*/ Element> > mElements; 175 android::Vector<android::String8> mElementNames; 176 android::Vector<uint32_t> mArraySizes; 177 bool mSkipPadding; 178 179 public: 180 Builder(RenderScript *rs); 181 ~Builder(); 182 void add(sp</*const*/ Element>, android::String8 &name, uint32_t arraySize = 1); 183 sp<const Element> create(); 184 }; 185 186 private: 187 void updateVisibleSubElements(); 188 189 android::Vector<sp</*const*/ Element> > mElements; 190 android::Vector<android::String8> mElementNames; 191 android::Vector<uint32_t> mArraySizes; 192 android::Vector<uint32_t> mVisibleElementMap; 193 android::Vector<uint32_t> mOffsetInBytes; 194 195 RsDataType mType; 196 RsDataKind mKind; 197 bool mNormalized; 198 size_t mSizeBytes; 199 size_t mVectorSize; 200 }; 201 202 } 203 } 204 #endif 205