• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "rsComponent.h"
18 
19 using namespace android;
20 using namespace android::renderscript;
21 
Component()22 Component::Component() {
23     set(RS_TYPE_NONE, RS_KIND_USER, false, 1);
24 }
25 
~Component()26 Component::~Component() {
27 }
28 
set(RsDataType dt,RsDataKind dk,bool norm,uint32_t vecSize)29 void Component::set(RsDataType dt, RsDataKind dk, bool norm, uint32_t vecSize) {
30     mType = dt;
31     mKind = dk;
32     mNormalized = norm;
33     mVectorSize = vecSize;
34     rsAssert(vecSize <= 4);
35 
36     mBits = 0;
37     mTypeBits = 0;
38     mIsFloat = false;
39     mIsSigned = false;
40     mIsPixel = false;
41 
42     switch (mKind) {
43     case RS_KIND_PIXEL_L:
44     case RS_KIND_PIXEL_A:
45         mIsPixel = true;
46         rsAssert(mVectorSize == 1);
47         rsAssert(mNormalized == true);
48         break;
49     case RS_KIND_PIXEL_LA:
50         mIsPixel = true;
51         rsAssert(mVectorSize == 2);
52         rsAssert(mNormalized == true);
53         break;
54     case RS_KIND_PIXEL_RGB:
55         mIsPixel = true;
56         rsAssert(mVectorSize == 3);
57         rsAssert(mNormalized == true);
58         break;
59     case RS_KIND_PIXEL_RGBA:
60         mIsPixel = true;
61         rsAssert(mVectorSize == 4);
62         rsAssert(mNormalized == true);
63         break;
64     default:
65         break;
66     }
67 
68     switch (mType) {
69     case RS_TYPE_NONE:
70         return;
71     case RS_TYPE_UNSIGNED_5_6_5:
72         mVectorSize = 3;
73         mBits = 16;
74         mNormalized = true;
75         rsAssert(mKind == RS_KIND_PIXEL_RGB);
76         return;
77     case RS_TYPE_UNSIGNED_5_5_5_1:
78         mVectorSize = 4;
79         mBits = 16;
80         mNormalized = true;
81         rsAssert(mKind == RS_KIND_PIXEL_RGBA);
82         return;
83     case RS_TYPE_UNSIGNED_4_4_4_4:
84         mVectorSize = 4;
85         mBits = 16;
86         mNormalized = true;
87         rsAssert(mKind == RS_KIND_PIXEL_RGBA);
88         return;
89 
90     case RS_TYPE_MATRIX_4X4:
91         mTypeBits = 16 * 32;
92         rsAssert(mVectorSize == 1);
93         rsAssert(mNormalized == false);
94         rsAssert(mKind == RS_KIND_USER);
95         break;
96     case RS_TYPE_MATRIX_3X3:
97         mTypeBits = 9 * 32;
98         rsAssert(mVectorSize == 1);
99         rsAssert(mNormalized == false);
100         rsAssert(mKind == RS_KIND_USER);
101         break;
102     case RS_TYPE_MATRIX_2X2:
103         mTypeBits = 4 * 32;
104         rsAssert(mVectorSize == 1);
105         rsAssert(mNormalized == false);
106         rsAssert(mKind == RS_KIND_USER);
107         break;
108 
109     case RS_TYPE_ELEMENT:
110     case RS_TYPE_TYPE:
111     case RS_TYPE_ALLOCATION:
112     case RS_TYPE_SAMPLER:
113     case RS_TYPE_SCRIPT:
114     case RS_TYPE_MESH:
115     case RS_TYPE_PROGRAM_FRAGMENT:
116     case RS_TYPE_PROGRAM_VERTEX:
117     case RS_TYPE_PROGRAM_RASTER:
118     case RS_TYPE_PROGRAM_STORE:
119         rsAssert(mVectorSize == 1);
120         rsAssert(mNormalized == false);
121         rsAssert(mKind == RS_KIND_USER);
122         mBits = 32;
123         mTypeBits = 32;
124         return;
125 
126     case RS_TYPE_FLOAT_16:
127         mTypeBits = 16;
128         mIsFloat = true;
129         break;
130     case RS_TYPE_FLOAT_32:
131         mTypeBits = 32;
132         mIsFloat = true;
133         break;
134     case RS_TYPE_FLOAT_64:
135         mTypeBits = 64;
136         mIsFloat = true;
137         break;
138     case RS_TYPE_SIGNED_8:
139         mTypeBits = 8;
140         mIsSigned = true;
141         break;
142     case RS_TYPE_SIGNED_16:
143         mTypeBits = 16;
144         mIsSigned = true;
145         break;
146     case RS_TYPE_SIGNED_32:
147         mTypeBits = 32;
148         mIsSigned = true;
149         break;
150     case RS_TYPE_SIGNED_64:
151         mTypeBits = 64;
152         mIsSigned = true;
153         break;
154     case RS_TYPE_UNSIGNED_8:
155         mTypeBits = 8;
156         break;
157     case RS_TYPE_UNSIGNED_16:
158         mTypeBits = 16;
159         break;
160     case RS_TYPE_UNSIGNED_32:
161         mTypeBits = 32;
162         break;
163     case RS_TYPE_UNSIGNED_64:
164         mTypeBits = 64;
165         break;
166 
167     case RS_TYPE_BOOLEAN:
168         mTypeBits = 8;
169         break;
170     }
171 
172     mBits = mTypeBits * mVectorSize;
173 }
174 
isReference() const175 bool Component::isReference() const {
176     return (mType >= RS_TYPE_ELEMENT);
177 }
178 
179 static const char * gTypeBasicStrings[] = {
180     "NONE",
181     "F16",
182     "F32",
183     "F64",
184     "S8",
185     "S16",
186     "S32",
187     "S64",
188     "U8",
189     "U16",
190     "U32",
191     "U64",
192     "BOOLEAN",
193     "UP_565",
194     "UP_5551",
195     "UP_4444",
196     "MATRIX_4X4",
197     "MATRIX_3X3",
198     "MATRIX_2X2",
199 };
200 
201 static const char * gTypeObjStrings[] = {
202     "ELEMENT",
203     "TYPE",
204     "ALLOCATION",
205     "SAMPLER",
206     "SCRIPT",
207     "MESH",
208     "PROGRAM_FRAGMENT",
209     "PROGRAM_VERTEX",
210     "PROGRAM_RASTER",
211     "PROGRAM_STORE",
212 };
213 
214 static const char * gKindStrings[] = {
215     "USER",
216     "COLOR",
217     "POSITION",
218     "TEXTURE",
219     "NORMAL",
220     "INDEX",
221     "POINT_SIZE",
222     "PIXEL_L",
223     "PIXEL_A",
224     "PIXEL_LA",
225     "PIXEL_RGB",
226     "PIXEL_RGBA",
227 };
228 
dumpLOGV(const char * prefix) const229 void Component::dumpLOGV(const char *prefix) const {
230     if (mType >= RS_TYPE_ELEMENT) {
231         LOGV("%s   Component: %s, %s, vectorSize=%i, bits=%i",
232              prefix, gTypeObjStrings[mType - RS_TYPE_ELEMENT], gKindStrings[mKind], mVectorSize, mBits);
233     } else {
234         LOGV("%s   Component: %s, %s, vectorSize=%i, bits=%i",
235              prefix, gTypeBasicStrings[mType], gKindStrings[mKind], mVectorSize, mBits);
236     }
237 }
238 
serialize(OStream * stream) const239 void Component::serialize(OStream *stream) const {
240     stream->addU8((uint8_t)mType);
241     stream->addU8((uint8_t)mKind);
242     stream->addU8((uint8_t)(mNormalized ? 1 : 0));
243     stream->addU32(mVectorSize);
244 }
245 
loadFromStream(IStream * stream)246 void Component::loadFromStream(IStream *stream) {
247     mType = (RsDataType)stream->loadU8();
248     mKind = (RsDataKind)stream->loadU8();
249     uint8_t temp = stream->loadU8();
250     mNormalized = temp != 0;
251     mVectorSize = stream->loadU32();
252 
253     set(mType, mKind, mNormalized, mVectorSize);
254 }
255 
256 
257 
258 
259