rsComponent.cpp revision fb6b614bcea88a587a7ea4530be45ff0ffa0210e
1d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams/*
2d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams * Copyright (C) 2009 The Android Open Source Project
3d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams *
4d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams * Licensed under the Apache License, Version 2.0 (the "License");
5d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams * you may not use this file except in compliance with the License.
6d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams * You may obtain a copy of the License at
7d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams *
8d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams *      http://www.apache.org/licenses/LICENSE-2.0
9d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams *
10d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams * Unless required by applicable law or agreed to in writing, software
11d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams * distributed under the License is distributed on an "AS IS" BASIS,
12d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams * See the License for the specific language governing permissions and
14d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams * limitations under the License.
15d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams */
16d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
17d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams#include "rsComponent.h"
18d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
19fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk#ifndef ANDROID_RS_BUILD_FOR_HOST
20d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams#include <GLES/gl.h>
21fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk#else
22fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk#include <OpenGL/gl.h>
23fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk#endif
24d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
25d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Samsusing namespace android;
26d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Samsusing namespace android::renderscript;
27d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
28d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason SamsComponent::Component()
29d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams{
30d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    set(RS_TYPE_NONE, RS_KIND_USER, false, 1);
31d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams}
32d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
33d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason SamsComponent::~Component()
34d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams{
35d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams}
36d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
37d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Samsvoid Component::set(RsDataType dt, RsDataKind dk, bool norm, uint32_t vecSize)
38d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams{
39d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    mType = dt;
40d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    mKind = dk;
41d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    mNormalized = norm;
42d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    mVectorSize = vecSize;
43d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    rsAssert(vecSize <= 4);
44d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
45d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    mBits = 0;
46d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    mTypeBits = 0;
47d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    mIsFloat = false;
48d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    mIsSigned = false;
49d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    mIsPixel = false;
50d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
51d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    switch(mKind) {
52d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_KIND_PIXEL_L:
53d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_KIND_PIXEL_A:
54d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mIsPixel = true;
55d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mVectorSize == 1);
56d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mNormalized == true);
57d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
58d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_KIND_PIXEL_LA:
59d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mIsPixel = true;
60d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mVectorSize == 2);
61d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mNormalized == true);
62d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
63d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_KIND_PIXEL_RGB:
64d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mIsPixel = true;
65d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mVectorSize == 3);
66d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mNormalized == true);
67d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
68d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_KIND_PIXEL_RGBA:
69d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mIsPixel = true;
70d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mVectorSize == 4);
71d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mNormalized == true);
72d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
73d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    default:
74d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
75d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    }
76d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
77d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    switch(mType) {
78d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_NONE:
79d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        return;
80d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_UNSIGNED_5_6_5:
81d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mVectorSize = 3;
82d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mBits = 16;
83d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mNormalized = true;
84d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mKind == RS_KIND_PIXEL_RGB);
85d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        return;
86d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_UNSIGNED_5_5_5_1:
87d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mVectorSize = 4;
88d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mBits = 16;
89d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mNormalized = true;
90d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mKind == RS_KIND_PIXEL_RGBA);
91d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        return;
92d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_UNSIGNED_4_4_4_4:
93d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mVectorSize = 4;
94d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mBits = 16;
95d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mNormalized = true;
96d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mKind == RS_KIND_PIXEL_RGBA);
97d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        return;
98d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_ELEMENT:
99d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_TYPE:
100d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_ALLOCATION:
101d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_SAMPLER:
102d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_SCRIPT:
103d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_MESH:
104d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_PROGRAM_FRAGMENT:
105d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_PROGRAM_VERTEX:
106d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_PROGRAM_RASTER:
107d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_PROGRAM_STORE:
108d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mVectorSize == 1);
109d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mNormalized == false);
110d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        rsAssert(mKind == RS_KIND_USER);
111d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mBits = 32;
112d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mTypeBits = 32;
113d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        return;
114d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
115d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_FLOAT_16:
116d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mTypeBits = 16;
117d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mIsFloat = true;
118d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
119d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_FLOAT_32:
120d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mTypeBits = 32;
121d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mIsFloat = true;
122d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
123d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_FLOAT_64:
124d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mTypeBits = 64;
125d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mIsFloat = true;
126d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
127d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_SIGNED_8:
128d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mTypeBits = 8;
129d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mIsSigned = true;
130d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
131d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_SIGNED_16:
132d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mTypeBits = 16;
133d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mIsSigned = true;
134d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
135d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_SIGNED_32:
136d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mTypeBits = 32;
137d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mIsSigned = true;
138d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
139d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_SIGNED_64:
140d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mTypeBits = 64;
141d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mIsSigned = true;
142d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
143d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_UNSIGNED_8:
144d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mTypeBits = 8;
145d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
146d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_UNSIGNED_16:
147d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mTypeBits = 16;
148d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
149d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_UNSIGNED_32:
150d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mTypeBits = 32;
151d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
152d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_UNSIGNED_64:
153d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        mTypeBits = 64;
154d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        break;
155d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    }
156d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
157d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    mBits = mTypeBits * mVectorSize;
158d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams}
159d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
160d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
161d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
162d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
163d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Samsuint32_t Component::getGLType() const
164d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams{
165d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    switch (mType) {
166d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_UNSIGNED_5_6_5:    return GL_UNSIGNED_SHORT_5_6_5;
167d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_UNSIGNED_5_5_5_1:  return GL_UNSIGNED_SHORT_5_5_5_1;
168d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_UNSIGNED_4_4_4_4:  return GL_UNSIGNED_SHORT_4_4_4_4;
169d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
170d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    //case RS_TYPE_FLOAT_16:      return GL_HALF_FLOAT;
171d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_FLOAT_32:      return GL_FLOAT;
172d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_UNSIGNED_8:    return GL_UNSIGNED_BYTE;
173d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_UNSIGNED_16:   return GL_UNSIGNED_SHORT;
174d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_SIGNED_8:      return GL_BYTE;
175d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_TYPE_SIGNED_16:     return GL_SHORT;
176d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    default:    break;
177d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    }
178d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
179d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    return 0;
180d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams}
181d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
182d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Samsuint32_t Component::getGLFormat() const
183d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams{
184d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    switch (mKind) {
185d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_KIND_PIXEL_L: return GL_LUMINANCE;
186d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_KIND_PIXEL_A: return GL_ALPHA;
187d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_KIND_PIXEL_LA: return GL_LUMINANCE_ALPHA;
188d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_KIND_PIXEL_RGB: return GL_RGB;
189d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    case RS_KIND_PIXEL_RGBA: return GL_RGBA;
190d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    default: break;
191d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    }
192d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    return 0;
193d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams}
194d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
195d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Samsstatic const char * gCTypeStrings[] = {
196d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,
197d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"F16",
198d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "float",
199d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "double",
200d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "char",
201d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "short",
202d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "int",
203d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"S64",
204d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "char",//U8",
205d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "short",//U16",
206d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "int",//U32",
207d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"U64",
208d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"UP_565",
209d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"UP_5551",
210d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"UP_4444",
211d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"ELEMENT",
212d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"TYPE",
213d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"ALLOCATION",
214d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"SAMPLER",
215d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"SCRIPT",
216d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"MESH",
217d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"PROGRAM_FRAGMENT",
218d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"PROGRAM_VERTEX",
219d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"PROGRAM_RASTER",
220d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"PROGRAM_STORE",
221d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams};
222d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
223d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Samsstatic const char * gCVecTypeStrings[] = {
224d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,
225d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"F16",
226d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "vecF32",
227d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "vecF64",
228d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "vecI8",
229d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "vecI16",
230d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "vecI32",
231d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"S64",
232d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "vecU8",//U8",
233d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "vecU16",//U16",
234d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "vecU32",//U32",
235d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"U64",
236d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"UP_565",
237d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"UP_5551",
238d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"UP_4444",
239d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"ELEMENT",
240d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"TYPE",
241d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"ALLOCATION",
242d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"SAMPLER",
243d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"SCRIPT",
244d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"MESH",
245d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"PROGRAM_FRAGMENT",
246d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"PROGRAM_VERTEX",
247d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"PROGRAM_RASTER",
248d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    0,//"PROGRAM_STORE",
249d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams};
250d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
251d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason SamsString8 Component::getCType() const
252d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams{
253d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    char buf[64];
254d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    if (mVectorSize == 1) {
255d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        return String8(gCTypeStrings[mType]);
256d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    }
257d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
258d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    // Yuck, acc WAR
259d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    // Appears to have problems packing chars
260d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    if (mVectorSize == 4 && mType == RS_TYPE_UNSIGNED_8) {
261d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams        return String8("int");
262d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    }
263d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
264d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
265d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    String8 s(gCVecTypeStrings[mType]);
266d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    sprintf(buf, "_%i_t", mVectorSize);
267d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    s.append(buf);
268d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    return s;
269d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams}
270d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
271b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason SamsString8 Component::getGLSLType() const
272b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams{
273b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams    if (mType == RS_TYPE_SIGNED_32) {
274b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams        switch(mVectorSize) {
275b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams        case 1: return String8("int");
276b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams        case 2: return String8("ivec2");
277b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams        case 3: return String8("ivec3");
278b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams        case 4: return String8("ivec4");
279b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams        }
280b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams    }
281b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams    if (mType == RS_TYPE_FLOAT_32) {
282b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams        switch(mVectorSize) {
283b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams        case 1: return String8("float");
284b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams        case 2: return String8("vec2");
285b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams        case 3: return String8("vec3");
286b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams        case 4: return String8("vec4");
287b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams        }
288b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams    }
289b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams    return String8();
290b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams}
291b4d3568f68b1ae97e2a82061cccf220f8e93cd94Jason Sams
292d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Samsstatic const char * gTypeStrings[] = {
293d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "NONE",
294d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "F16",
295d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "F32",
296d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "F64",
297d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "S8",
298d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "S16",
299d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "S32",
300d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "S64",
301d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "U8",
302d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "U16",
303d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "U32",
304d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "U64",
305d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "UP_565",
306d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "UP_5551",
307d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "UP_4444",
308d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "ELEMENT",
309d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "TYPE",
310d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "ALLOCATION",
311d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "SAMPLER",
312d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "SCRIPT",
313d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "MESH",
314d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "PROGRAM_FRAGMENT",
315d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "PROGRAM_VERTEX",
316d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "PROGRAM_RASTER",
317d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "PROGRAM_STORE",
318d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams};
319d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
320d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Samsstatic const char * gKindStrings[] = {
321d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "USER",
322d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "COLOR",
323d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "POSITION",
324d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "TEXTURE",
325d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "NORMAL",
326d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "INDEX",
327d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "POINT_SIZE",
328d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "PIXEL_L",
329d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "PIXEL_A",
330d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "PIXEL_LA",
331d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "PIXEL_RGB",
332d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    "PIXEL_RGBA",
333d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams};
334d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
335d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Samsvoid Component::dumpLOGV(const char *prefix) const
336d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams{
337d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams    LOGV("%s   Component: %s, %s, vectorSize=%i, bits=%i",
338d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams         prefix, gTypeStrings[mType], gKindStrings[mKind], mVectorSize, mBits);
339d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams}
340d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
341fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchoukvoid Component::serialize(OStream *stream) const
342fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk{
343fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    stream->addU8((uint8_t)mType);
344fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    stream->addU8((uint8_t)mKind);
345fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    stream->addU8((uint8_t)(mNormalized ? 1 : 0));
346fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    stream->addU32(mVectorSize);
347fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk}
348fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk
349fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchoukvoid Component::loadFromStream(IStream *stream)
350fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk{
351fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    mType = (RsDataType)stream->loadU8();
352fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    mKind = (RsDataKind)stream->loadU8();
353fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    uint8_t temp = stream->loadU8();
354fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    mNormalized = temp != 0;
355fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    mVectorSize = stream->loadU32();
356fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk
357fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    set(mType, mKind, mNormalized, mVectorSize);
358fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk}
359fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk
360fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk
361fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk
362d01d970cf5973aa5186cc02c80fb2c143a69b0b1Jason Sams
363