/* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __ANDROID_ELEMENT_H__ #define __ANDROID_ELEMENT_H__ #include #include "RenderScript.h" #include "BaseObj.h" namespace android { namespace renderscriptCpp { class Element : public BaseObj { public: /** * Return if a element is too complex for use as a data source for a Mesh or * a Program. * * @return boolean */ bool isComplex(); /** * @hide * @return number of sub-elements in this element */ size_t getSubElementCount() { return mVisibleElementMap.size(); } /** * @hide * @param index index of the sub-element to return * @return sub-element in this element at given index */ sp getSubElement(uint32_t index); /** * @hide * @param index index of the sub-element * @return sub-element in this element at given index */ const char * getSubElementName(uint32_t index); /** * @hide * @param index index of the sub-element * @return array size of sub-element in this element at given index */ size_t getSubElementArraySize(uint32_t index); /** * @hide * @param index index of the sub-element * @return offset in bytes of sub-element in this element at given index */ uint32_t getSubElementOffsetBytes(uint32_t index); /** * @hide * @return element data type */ RsDataType getDataType() const { return mType; } /** * @hide * @return element data kind */ RsDataKind getDataKind() const { return mKind; } size_t getSizeBytes() const { return mSizeBytes; } static sp BOOLEAN(RenderScript *rs); static sp U8(RenderScript *rs); static sp I8(RenderScript *rs); static sp U16(RenderScript *rs); static sp I16(RenderScript *rs); static sp U32(RenderScript *rs); static sp I32(RenderScript *rs); static sp U64(RenderScript *rs); static sp I64(RenderScript *rs); static sp F32(RenderScript *rs); static sp F64(RenderScript *rs); static sp ELEMENT(RenderScript *rs); static sp TYPE(RenderScript *rs); static sp ALLOCATION(RenderScript *rs); static sp SAMPLER(RenderScript *rs); static sp SCRIPT(RenderScript *rs); static sp MESH(RenderScript *rs); static sp PROGRAM_FRAGMENT(RenderScript *rs); static sp PROGRAM_VERTEX(RenderScript *rs); static sp PROGRAM_RASTER(RenderScript *rs); static sp PROGRAM_STORE(RenderScript *rs); static sp A_8(RenderScript *rs); static sp RGB_565(RenderScript *rs); static sp RGB_888(RenderScript *rs); static sp RGBA_5551(RenderScript *rs); static sp RGBA_4444(RenderScript *rs); static sp RGBA_8888(RenderScript *rs); static sp F32_2(RenderScript *rs); static sp F32_3(RenderScript *rs); static sp F32_4(RenderScript *rs); static sp F64_2(RenderScript *rs); static sp F64_3(RenderScript *rs); static sp F64_4(RenderScript *rs); static sp U8_2(RenderScript *rs); static sp U8_3(RenderScript *rs); static sp U8_4(RenderScript *rs); static sp I8_2(RenderScript *rs); static sp I8_3(RenderScript *rs); static sp I8_4(RenderScript *rs); static sp U16_2(RenderScript *rs); static sp U16_3(RenderScript *rs); static sp U16_4(RenderScript *rs); static sp I16_2(RenderScript *rs); static sp I16_3(RenderScript *rs); static sp I16_4(RenderScript *rs); static sp U32_2(RenderScript *rs); static sp U32_3(RenderScript *rs); static sp U32_4(RenderScript *rs); static sp I32_2(RenderScript *rs); static sp I32_3(RenderScript *rs); static sp I32_4(RenderScript *rs); static sp U64_2(RenderScript *rs); static sp U64_3(RenderScript *rs); static sp U64_4(RenderScript *rs); static sp I64_2(RenderScript *rs); static sp I64_3(RenderScript *rs); static sp I64_4(RenderScript *rs); static sp MATRIX_4X4(RenderScript *rs); static sp MATRIX_3X3(RenderScript *rs); static sp MATRIX_2X2(RenderScript *rs); Element(void *id, RenderScript *rs, android::Vector > &elements, android::Vector &elementNames, android::Vector &arraySizes); Element(void *id, RenderScript *rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size); Element(RenderScript *rs); virtual ~Element(); void updateFromNative(); static sp createUser(RenderScript *rs, RsDataType dt); static sp createVector(RenderScript *rs, RsDataType dt, uint32_t size); static sp createPixel(RenderScript *rs, RsDataType dt, RsDataKind dk); bool isCompatible(spe); class Builder { private: RenderScript *mRS; android::Vector > mElements; android::Vector mElementNames; android::Vector mArraySizes; bool mSkipPadding; public: Builder(RenderScript *rs); ~Builder(); void add(sp, android::String8 &name, uint32_t arraySize = 1); sp create(); }; private: void updateVisibleSubElements(); android::Vector > mElements; android::Vector mElementNames; android::Vector mArraySizes; android::Vector mVisibleElementMap; android::Vector mOffsetInBytes; RsDataType mType; RsDataKind mKind; bool mNormalized; size_t mSizeBytes; size_t mVectorSize; }; } } #endif