blob: c46922cb2916558b18b46fa5b525887ddc74b96f [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
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
Jason Sams718cd1f2009-12-23 14:35:29 -080020#include "rsComponent.h"
Jason Sams0011bcf2009-12-15 12:58:36 -080021#include "rsUtils.h"
22#include "rsObjectBase.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070023
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:
Jason Samsd19f10d2009-05-22 14:03:28 -070033 ~Element();
34
35
Jason Sams0011bcf2009-12-15 12:58:36 -080036 //void setComponent(uint32_t idx, Component *c);
Jason Samsd19f10d2009-05-22 14:03:28 -070037
Jason Samse2ae85f2009-06-03 16:04:54 -070038 uint32_t getGLType() const;
39 uint32_t getGLFormat() const;
Jason Samsd19f10d2009-05-22 14:03:28 -070040
41
42 size_t getSizeBits() const;
Jason Sams1bada8c2009-08-09 17:01:55 -070043 size_t getSizeBytes() const {
44 return (getSizeBits() + 7) >> 3;
Jason Samsd19f10d2009-05-22 14:03:28 -070045 }
46
Jason Sams0011bcf2009-12-15 12:58:36 -080047 size_t getFieldOffsetBits(uint32_t componentNumber) const;
48 size_t getFieldOffsetBytes(uint32_t componentNumber) const {
49 return (getFieldOffsetBits(componentNumber) + 7) >> 3;
Jason Samsd19f10d2009-05-22 14:03:28 -070050 }
51
Jason Sams0011bcf2009-12-15 12:58:36 -080052 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();}
Jason Samsd19f10d2009-05-22 14:03:28 -070055
Jason Sams718cd1f2009-12-23 14:35:29 -080056 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();}
Jason Sams0011bcf2009-12-15 12:58:36 -080060 uint32_t getBits() const {return mBits;}
61 //uint32_t getGLType() const;
Jason Sams718cd1f2009-12-23 14:35:29 -080062
63 String8 getCType(uint32_t indent=0) const;
64 String8 getCStructBody(uint32_t indent=0) const;
Jason Sams3c0dfba2009-09-27 17:50:38 -070065
66 void dumpLOGV(const char *prefix) const;
67
Jason Sams718cd1f2009-12-23 14:35:29 -080068 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);
Jason Sams0011bcf2009-12-15 12:58:36 -080072
Jason Samsd19f10d2009-05-22 14:03:28 -070073protected:
74 // deallocate any components that are part of this element.
75 void clear();
76
Jason Sams0011bcf2009-12-15 12:58:36 -080077 typedef struct {
78 String8 name;
Jason Sams718cd1f2009-12-23 14:35:29 -080079 ObjectBaseRef<const Element> e;
Jason Sams0011bcf2009-12-15 12:58:36 -080080 } ElementField_t;
81 ElementField_t *mFields;
82 size_t mFieldCount;
83
Jason Samsd19f10d2009-05-22 14:03:28 -070084
Jason Samsa9e7a052009-09-25 14:51:22 -070085 Element(Context *);
Jason Sams0011bcf2009-12-15 12:58:36 -080086
Jason Sams718cd1f2009-12-23 14:35:29 -080087 Component mComponent;
Jason Sams0011bcf2009-12-15 12:58:36 -080088 uint32_t mBits;
Jason Samsd19f10d2009-05-22 14:03:28 -070089};
90
91
92class ElementState {
93public:
94 ElementState();
95 ~ElementState();
96
Jason Sams0011bcf2009-12-15 12:58:36 -080097 Vector<Element *> mBuildList;
98 Vector<String8> mNames;
Jason Samsd19f10d2009-05-22 14:03:28 -070099};
100
101
102}
103}
104#endif //ANDROID_STRUCTURED_ELEMENT_H