rsElement.h revision 4815c0d121310cfcd6a8aba4eab77a9910af53ac
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    RsDataType getType() const {return mType;}
57    bool getIsNormalized() const {return mIsNormalized;}
58    RsDataKind getKind() const {return mKind;}
59    uint32_t getBits() const {return mBits;}
60    //uint32_t getGLType() const;
61    const char * getCType() const;
62
63    void dumpLOGV(const char *prefix) const;
64
65
66    static Element * create(Context *rsc, RsDataKind dk, RsDataType dt,
67                            bool isNorm, size_t bits);
68    static Element * create(Context *rsc, Element **, const char **,
69                            const size_t * lengths, size_t count);
70
71protected:
72    // deallocate any components that are part of this element.
73    void clear();
74
75    typedef struct {
76        String8 name;
77        ObjectBaseRef<Element> e;
78    } ElementField_t;
79    ElementField_t *mFields;
80    size_t mFieldCount;
81
82
83    Element(Context *);
84
85
86    RsDataType mType;
87    bool mIsNormalized;
88    RsDataKind mKind;
89    uint32_t mBits;
90    //String8 mName;
91};
92
93
94class ElementState {
95public:
96    ElementState();
97    ~ElementState();
98
99    Vector<Element *> mBuildList;
100    Vector<String8> mNames;
101};
102
103
104}
105}
106#endif //ANDROID_STRUCTURED_ELEMENT_H
107