Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 1 | /* |
Jason Sams | bc0ca6b | 2013-02-15 18:13:43 -0800 | [diff] [blame] | 2 | * Copyright (C) 2013 The Android Open Source Project |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 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 | |
Chih-Hung Hsieh | 11496ac | 2016-11-15 15:14:05 -0800 | [diff] [blame] | 19 | namespace android { |
| 20 | namespace renderscript { |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 21 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 22 | Component::Component() { |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 23 | set(RS_TYPE_NONE, RS_KIND_USER, false, 1); |
| 24 | } |
| 25 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 26 | Component::~Component() { |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 27 | } |
| 28 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 29 | void Component::set(RsDataType dt, RsDataKind dk, bool norm, uint32_t vecSize) { |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 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 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 42 | switch (mKind) { |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 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; |
Jason Sams | bc0ca6b | 2013-02-15 18:13:43 -0800 | [diff] [blame] | 64 | case RS_KIND_PIXEL_YUV: |
| 65 | mIsPixel = true; |
| 66 | rsAssert(mVectorSize == 1); |
| 67 | rsAssert(mNormalized == true); |
| 68 | break; |
| 69 | |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 70 | default: |
Alex Sakhartchouk | 25a59d0 | 2011-12-29 11:17:38 -0800 | [diff] [blame] | 71 | rsAssert(mKind != RS_KIND_INVALID); |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 72 | break; |
| 73 | } |
| 74 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 75 | switch (mType) { |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 76 | case RS_TYPE_NONE: |
| 77 | return; |
| 78 | case RS_TYPE_UNSIGNED_5_6_5: |
| 79 | mVectorSize = 3; |
| 80 | mBits = 16; |
| 81 | mNormalized = true; |
| 82 | rsAssert(mKind == RS_KIND_PIXEL_RGB); |
| 83 | return; |
| 84 | case RS_TYPE_UNSIGNED_5_5_5_1: |
| 85 | mVectorSize = 4; |
| 86 | mBits = 16; |
| 87 | mNormalized = true; |
| 88 | rsAssert(mKind == RS_KIND_PIXEL_RGBA); |
| 89 | return; |
| 90 | case RS_TYPE_UNSIGNED_4_4_4_4: |
| 91 | mVectorSize = 4; |
| 92 | mBits = 16; |
| 93 | mNormalized = true; |
| 94 | rsAssert(mKind == RS_KIND_PIXEL_RGBA); |
| 95 | return; |
Jason Sams | 39cd317 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 96 | |
| 97 | case RS_TYPE_MATRIX_4X4: |
| 98 | mTypeBits = 16 * 32; |
| 99 | rsAssert(mVectorSize == 1); |
| 100 | rsAssert(mNormalized == false); |
| 101 | rsAssert(mKind == RS_KIND_USER); |
| 102 | break; |
| 103 | case RS_TYPE_MATRIX_3X3: |
| 104 | mTypeBits = 9 * 32; |
| 105 | rsAssert(mVectorSize == 1); |
| 106 | rsAssert(mNormalized == false); |
| 107 | rsAssert(mKind == RS_KIND_USER); |
| 108 | break; |
| 109 | case RS_TYPE_MATRIX_2X2: |
| 110 | mTypeBits = 4 * 32; |
| 111 | rsAssert(mVectorSize == 1); |
| 112 | rsAssert(mNormalized == false); |
| 113 | rsAssert(mKind == RS_KIND_USER); |
| 114 | break; |
| 115 | |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 116 | case RS_TYPE_ELEMENT: |
| 117 | case RS_TYPE_TYPE: |
| 118 | case RS_TYPE_ALLOCATION: |
| 119 | case RS_TYPE_SAMPLER: |
| 120 | case RS_TYPE_SCRIPT: |
| 121 | case RS_TYPE_MESH: |
| 122 | case RS_TYPE_PROGRAM_FRAGMENT: |
| 123 | case RS_TYPE_PROGRAM_VERTEX: |
| 124 | case RS_TYPE_PROGRAM_RASTER: |
| 125 | case RS_TYPE_PROGRAM_STORE: |
Stephen Hines | ae8b795 | 2012-04-11 18:09:54 -0700 | [diff] [blame] | 126 | case RS_TYPE_FONT: |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 127 | rsAssert(mVectorSize == 1); |
| 128 | rsAssert(mNormalized == false); |
| 129 | rsAssert(mKind == RS_KIND_USER); |
Stephen Hines | 7202c92 | 2014-06-25 15:21:47 -0700 | [diff] [blame] | 130 | #ifdef __LP64__ |
| 131 | // Large object pointers on 64-bit targets. |
| 132 | mBits = 256; |
| 133 | mTypeBits = 256; |
| 134 | #else |
| 135 | // Single pointer objects on 32-bit targets. |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 136 | mBits = 32; |
| 137 | mTypeBits = 32; |
Stephen Hines | 7202c92 | 2014-06-25 15:21:47 -0700 | [diff] [blame] | 138 | #endif // __LP64__ |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 139 | return; |
| 140 | |
| 141 | case RS_TYPE_FLOAT_16: |
| 142 | mTypeBits = 16; |
| 143 | mIsFloat = true; |
| 144 | break; |
| 145 | case RS_TYPE_FLOAT_32: |
| 146 | mTypeBits = 32; |
| 147 | mIsFloat = true; |
| 148 | break; |
| 149 | case RS_TYPE_FLOAT_64: |
| 150 | mTypeBits = 64; |
| 151 | mIsFloat = true; |
| 152 | break; |
| 153 | case RS_TYPE_SIGNED_8: |
| 154 | mTypeBits = 8; |
| 155 | mIsSigned = true; |
| 156 | break; |
| 157 | case RS_TYPE_SIGNED_16: |
| 158 | mTypeBits = 16; |
| 159 | mIsSigned = true; |
| 160 | break; |
| 161 | case RS_TYPE_SIGNED_32: |
| 162 | mTypeBits = 32; |
| 163 | mIsSigned = true; |
| 164 | break; |
| 165 | case RS_TYPE_SIGNED_64: |
| 166 | mTypeBits = 64; |
| 167 | mIsSigned = true; |
| 168 | break; |
| 169 | case RS_TYPE_UNSIGNED_8: |
| 170 | mTypeBits = 8; |
| 171 | break; |
| 172 | case RS_TYPE_UNSIGNED_16: |
| 173 | mTypeBits = 16; |
| 174 | break; |
| 175 | case RS_TYPE_UNSIGNED_32: |
| 176 | mTypeBits = 32; |
| 177 | break; |
| 178 | case RS_TYPE_UNSIGNED_64: |
| 179 | mTypeBits = 64; |
| 180 | break; |
Jason Sams | 5e9811f | 2010-06-21 17:42:41 -0700 | [diff] [blame] | 181 | |
| 182 | case RS_TYPE_BOOLEAN: |
| 183 | mTypeBits = 8; |
| 184 | break; |
Alex Sakhartchouk | 25a59d0 | 2011-12-29 11:17:38 -0800 | [diff] [blame] | 185 | default: |
| 186 | rsAssert(mType != RS_TYPE_INVALID); |
Stephen Hines | ae8b795 | 2012-04-11 18:09:54 -0700 | [diff] [blame] | 187 | rsAssert(0); |
Alex Sakhartchouk | 25a59d0 | 2011-12-29 11:17:38 -0800 | [diff] [blame] | 188 | break; |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 191 | mBitsUnpadded = mTypeBits * mVectorSize; |
| 192 | mBits = mTypeBits * rsHigherPow2(mVectorSize); |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 193 | } |
| 194 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 195 | bool Component::isReference() const { |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 196 | return (mType >= RS_TYPE_ELEMENT); |
| 197 | } |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 198 | |
Jason Sams | 39cd317 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 199 | static const char * gTypeBasicStrings[] = { |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 200 | "NONE", |
| 201 | "F16", |
| 202 | "F32", |
| 203 | "F64", |
| 204 | "S8", |
| 205 | "S16", |
| 206 | "S32", |
| 207 | "S64", |
| 208 | "U8", |
| 209 | "U16", |
| 210 | "U32", |
| 211 | "U64", |
Jason Sams | 5e9811f | 2010-06-21 17:42:41 -0700 | [diff] [blame] | 212 | "BOOLEAN", |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 213 | "UP_565", |
| 214 | "UP_5551", |
| 215 | "UP_4444", |
Jason Sams | 39cd317 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 216 | "MATRIX_4X4", |
| 217 | "MATRIX_3X3", |
| 218 | "MATRIX_2X2", |
| 219 | }; |
| 220 | |
| 221 | static const char * gTypeObjStrings[] = { |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 222 | "ELEMENT", |
| 223 | "TYPE", |
| 224 | "ALLOCATION", |
| 225 | "SAMPLER", |
| 226 | "SCRIPT", |
| 227 | "MESH", |
| 228 | "PROGRAM_FRAGMENT", |
| 229 | "PROGRAM_VERTEX", |
| 230 | "PROGRAM_RASTER", |
| 231 | "PROGRAM_STORE", |
| 232 | }; |
| 233 | |
| 234 | static const char * gKindStrings[] = { |
| 235 | "USER", |
| 236 | "COLOR", |
| 237 | "POSITION", |
| 238 | "TEXTURE", |
| 239 | "NORMAL", |
| 240 | "INDEX", |
| 241 | "POINT_SIZE", |
| 242 | "PIXEL_L", |
| 243 | "PIXEL_A", |
| 244 | "PIXEL_LA", |
| 245 | "PIXEL_RGB", |
| 246 | "PIXEL_RGBA", |
| 247 | }; |
| 248 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 249 | void Component::dumpLOGV(const char *prefix) const { |
Jason Sams | 39cd317 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 250 | if (mType >= RS_TYPE_ELEMENT) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 251 | ALOGV("%s Component: %s, %s, vectorSize=%i, bits=%i", |
Jason Sams | 39cd317 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 252 | prefix, gTypeObjStrings[mType - RS_TYPE_ELEMENT], gKindStrings[mKind], mVectorSize, mBits); |
| 253 | } else { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 254 | ALOGV("%s Component: %s, %s, vectorSize=%i, bits=%i", |
Jason Sams | 39cd317 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 255 | prefix, gTypeBasicStrings[mType], gKindStrings[mKind], mVectorSize, mBits); |
| 256 | } |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 259 | void Component::serialize(OStream *stream) const { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 260 | stream->addU8((uint8_t)mType); |
| 261 | stream->addU8((uint8_t)mKind); |
| 262 | stream->addU8((uint8_t)(mNormalized ? 1 : 0)); |
| 263 | stream->addU32(mVectorSize); |
| 264 | } |
| 265 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 266 | void Component::loadFromStream(IStream *stream) { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 267 | mType = (RsDataType)stream->loadU8(); |
| 268 | mKind = (RsDataKind)stream->loadU8(); |
| 269 | uint8_t temp = stream->loadU8(); |
| 270 | mNormalized = temp != 0; |
| 271 | mVectorSize = stream->loadU32(); |
| 272 | |
| 273 | set(mType, mKind, mNormalized, mVectorSize); |
| 274 | } |
| 275 | |
Chih-Hung Hsieh | 11496ac | 2016-11-15 15:14:05 -0800 | [diff] [blame] | 276 | } // namespace renderscript |
| 277 | } // namespace android |