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