Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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_RSCPPSTRUCTS_H |
| 18 | #define ANDROID_RSCPPSTRUCTS_H |
| 19 | |
| 20 | #include <utils/String8.h> |
| 21 | #include <utils/Vector.h> |
| 22 | #include "utils/RefBase.h" |
| 23 | |
| 24 | #include <rs.h> |
| 25 | |
| 26 | namespace android { |
Tim Murray | 9eb7f4b | 2012-11-16 14:02:18 -0800 | [diff] [blame] | 27 | namespace RSC { |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 28 | |
| 29 | typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText); |
| 30 | typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen); |
| 31 | |
| 32 | class RS; |
| 33 | class BaseObj; |
| 34 | class Element; |
| 35 | class Type; |
| 36 | class Allocation; |
| 37 | class Script; |
| 38 | class ScriptC; |
| 39 | |
| 40 | class RS : public android::LightRefBase<RS> { |
| 41 | |
| 42 | public: |
| 43 | RS(); |
| 44 | virtual ~RS(); |
| 45 | |
Tim Murray | 4d252d6 | 2012-11-29 14:37:59 -0800 | [diff] [blame] | 46 | bool init(bool forceCpu = false, bool synchronous = false); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 47 | |
| 48 | void setErrorHandler(ErrorHandlerFunc_t func); |
| 49 | ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; } |
| 50 | |
| 51 | void setMessageHandler(MessageHandlerFunc_t func); |
| 52 | MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; } |
| 53 | |
| 54 | void throwError(const char *err) const; |
| 55 | |
| 56 | RsContext getContext() { return mContext; } |
| 57 | |
Tim Murray | baca6c3 | 2012-11-14 16:51:46 -0800 | [diff] [blame] | 58 | void finish(); |
| 59 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 60 | private: |
Tim Murray | 4d252d6 | 2012-11-29 14:37:59 -0800 | [diff] [blame] | 61 | bool init(int targetApi, bool forceCpu, bool synchronous); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 62 | static void * threadProc(void *); |
| 63 | |
| 64 | static bool gInitialized; |
| 65 | static pthread_mutex_t gInitMutex; |
| 66 | |
| 67 | pthread_t mMessageThreadId; |
| 68 | pid_t mNativeMessageThreadId; |
| 69 | bool mMessageRun; |
| 70 | |
| 71 | RsDevice mDev; |
| 72 | RsContext mContext; |
| 73 | |
| 74 | ErrorHandlerFunc_t mErrorFunc; |
| 75 | MessageHandlerFunc_t mMessageFunc; |
| 76 | |
| 77 | struct { |
| 78 | Element *U8; |
| 79 | Element *I8; |
| 80 | Element *U16; |
| 81 | Element *I16; |
| 82 | Element *U32; |
| 83 | Element *I32; |
| 84 | Element *U64; |
| 85 | Element *I64; |
| 86 | Element *F32; |
| 87 | Element *F64; |
| 88 | Element *BOOLEAN; |
| 89 | |
| 90 | Element *ELEMENT; |
| 91 | Element *TYPE; |
| 92 | Element *ALLOCATION; |
| 93 | Element *SAMPLER; |
| 94 | Element *SCRIPT; |
| 95 | Element *MESH; |
| 96 | Element *PROGRAM_FRAGMENT; |
| 97 | Element *PROGRAM_VERTEX; |
| 98 | Element *PROGRAM_RASTER; |
| 99 | Element *PROGRAM_STORE; |
| 100 | |
| 101 | Element *A_8; |
| 102 | Element *RGB_565; |
| 103 | Element *RGB_888; |
| 104 | Element *RGBA_5551; |
| 105 | Element *RGBA_4444; |
| 106 | Element *RGBA_8888; |
| 107 | |
| 108 | Element *FLOAT_2; |
| 109 | Element *FLOAT_3; |
| 110 | Element *FLOAT_4; |
| 111 | |
| 112 | Element *DOUBLE_2; |
| 113 | Element *DOUBLE_3; |
| 114 | Element *DOUBLE_4; |
| 115 | |
| 116 | Element *UCHAR_2; |
| 117 | Element *UCHAR_3; |
| 118 | Element *UCHAR_4; |
| 119 | |
| 120 | Element *CHAR_2; |
| 121 | Element *CHAR_3; |
| 122 | Element *CHAR_4; |
| 123 | |
| 124 | Element *USHORT_2; |
| 125 | Element *USHORT_3; |
| 126 | Element *USHORT_4; |
| 127 | |
| 128 | Element *SHORT_2; |
| 129 | Element *SHORT_3; |
| 130 | Element *SHORT_4; |
| 131 | |
| 132 | Element *UINT_2; |
| 133 | Element *UINT_3; |
| 134 | Element *UINT_4; |
| 135 | |
| 136 | Element *INT_2; |
| 137 | Element *INT_3; |
| 138 | Element *INT_4; |
| 139 | |
| 140 | Element *ULONG_2; |
| 141 | Element *ULONG_3; |
| 142 | Element *ULONG_4; |
| 143 | |
| 144 | Element *LONG_2; |
| 145 | Element *LONG_3; |
| 146 | Element *LONG_4; |
| 147 | |
| 148 | Element *MATRIX_4X4; |
| 149 | Element *MATRIX_3X3; |
| 150 | Element *MATRIX_2X2; |
| 151 | } mElements; |
| 152 | |
| 153 | }; |
| 154 | |
| 155 | class BaseObj : public android::LightRefBase<BaseObj> { |
| 156 | protected: |
| 157 | void *mID; |
| 158 | sp<RS> mRS; |
| 159 | String8 mName; |
| 160 | |
| 161 | BaseObj(void *id, sp<RS> rs); |
| 162 | void checkValid(); |
| 163 | |
| 164 | static void * getObjID(sp<const BaseObj> o); |
| 165 | |
| 166 | public: |
| 167 | |
| 168 | void * getID() const; |
| 169 | virtual ~BaseObj(); |
| 170 | virtual void updateFromNative(); |
| 171 | virtual bool equals(const BaseObj *obj); |
| 172 | }; |
| 173 | |
| 174 | |
| 175 | class Allocation : public BaseObj { |
| 176 | protected: |
| 177 | android::sp<const Type> mType; |
| 178 | uint32_t mUsage; |
| 179 | android::sp<Allocation> mAdaptedAllocation; |
| 180 | |
| 181 | bool mConstrainedLOD; |
| 182 | bool mConstrainedFace; |
| 183 | bool mConstrainedY; |
| 184 | bool mConstrainedZ; |
| 185 | bool mReadAllowed; |
| 186 | bool mWriteAllowed; |
| 187 | uint32_t mSelectedY; |
| 188 | uint32_t mSelectedZ; |
| 189 | uint32_t mSelectedLOD; |
| 190 | RsAllocationCubemapFace mSelectedFace; |
| 191 | |
| 192 | uint32_t mCurrentDimX; |
| 193 | uint32_t mCurrentDimY; |
| 194 | uint32_t mCurrentDimZ; |
| 195 | uint32_t mCurrentCount; |
| 196 | |
| 197 | void * getIDSafe() const; |
| 198 | void updateCacheInfo(sp<const Type> t); |
| 199 | |
| 200 | Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage); |
| 201 | |
| 202 | void validateIsInt32(); |
| 203 | void validateIsInt16(); |
| 204 | void validateIsInt8(); |
| 205 | void validateIsFloat32(); |
| 206 | void validateIsObject(); |
| 207 | |
| 208 | virtual void updateFromNative(); |
| 209 | |
| 210 | void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h); |
| 211 | |
| 212 | public: |
| 213 | android::sp<const Type> getType() { |
| 214 | return mType; |
| 215 | } |
| 216 | |
| 217 | void syncAll(RsAllocationUsageType srcLocation); |
| 218 | void ioSendOutput(); |
| 219 | void ioGetInput(); |
| 220 | |
| 221 | void generateMipmaps(); |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 222 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 223 | void copy1DRangeFrom(uint32_t off, size_t count, const void *data); |
Tim Murray | a4cbc2b | 2012-11-14 17:18:08 -0800 | [diff] [blame] | 224 | void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 225 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 226 | void copy1DRangeTo(uint32_t off, size_t count, void *data); |
| 227 | |
| 228 | void copy1DFrom(const void* data); |
| 229 | void copy1DTo(void* data); |
Tim Murray | a4cbc2b | 2012-11-14 17:18:08 -0800 | [diff] [blame] | 230 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 231 | void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 232 | const void *data); |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 233 | |
| 234 | void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 235 | void *data); |
| 236 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 237 | void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 238 | sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 239 | |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 240 | void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 241 | const void *data, size_t stride); |
| 242 | void copy2DStridedFrom(const void *data, size_t stride); |
| 243 | |
| 244 | void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 245 | void *data, size_t stride); |
| 246 | void copy2DStridedTo(void *data, size_t stride); |
| 247 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 248 | void resize(int dimX); |
| 249 | void resize(int dimX, int dimY); |
| 250 | |
| 251 | static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, |
| 252 | RsAllocationMipmapControl mips, uint32_t usage); |
| 253 | static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, |
| 254 | RsAllocationMipmapControl mips, uint32_t usage, void * pointer); |
| 255 | |
| 256 | static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, |
| 257 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
| 258 | static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count, |
| 259 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
Tim Murray | 684726c | 2012-11-14 11:57:42 -0800 | [diff] [blame] | 260 | static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e, |
| 261 | size_t x, size_t y, |
| 262 | uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); |
| 263 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 264 | |
| 265 | }; |
| 266 | |
| 267 | class Element : public BaseObj { |
| 268 | public: |
| 269 | bool isComplex(); |
| 270 | size_t getSubElementCount() { |
| 271 | return mVisibleElementMap.size(); |
| 272 | } |
| 273 | |
| 274 | sp<const Element> getSubElement(uint32_t index); |
| 275 | const char * getSubElementName(uint32_t index); |
| 276 | size_t getSubElementArraySize(uint32_t index); |
| 277 | uint32_t getSubElementOffsetBytes(uint32_t index); |
| 278 | RsDataType getDataType() const { |
| 279 | return mType; |
| 280 | } |
| 281 | |
| 282 | RsDataKind getDataKind() const { |
| 283 | return mKind; |
| 284 | } |
| 285 | |
| 286 | size_t getSizeBytes() const { |
| 287 | return mSizeBytes; |
| 288 | } |
| 289 | |
| 290 | static sp<const Element> BOOLEAN(sp<RS> rs); |
| 291 | static sp<const Element> U8(sp<RS> rs); |
| 292 | static sp<const Element> I8(sp<RS> rs); |
| 293 | static sp<const Element> U16(sp<RS> rs); |
| 294 | static sp<const Element> I16(sp<RS> rs); |
| 295 | static sp<const Element> U32(sp<RS> rs); |
| 296 | static sp<const Element> I32(sp<RS> rs); |
| 297 | static sp<const Element> U64(sp<RS> rs); |
| 298 | static sp<const Element> I64(sp<RS> rs); |
| 299 | static sp<const Element> F32(sp<RS> rs); |
| 300 | static sp<const Element> F64(sp<RS> rs); |
| 301 | static sp<const Element> ELEMENT(sp<RS> rs); |
| 302 | static sp<const Element> TYPE(sp<RS> rs); |
| 303 | static sp<const Element> ALLOCATION(sp<RS> rs); |
| 304 | static sp<const Element> SAMPLER(sp<RS> rs); |
| 305 | static sp<const Element> SCRIPT(sp<RS> rs); |
| 306 | static sp<const Element> MESH(sp<RS> rs); |
| 307 | static sp<const Element> PROGRAM_FRAGMENT(sp<RS> rs); |
| 308 | static sp<const Element> PROGRAM_VERTEX(sp<RS> rs); |
| 309 | static sp<const Element> PROGRAM_RASTER(sp<RS> rs); |
| 310 | static sp<const Element> PROGRAM_STORE(sp<RS> rs); |
| 311 | |
| 312 | static sp<const Element> A_8(sp<RS> rs); |
| 313 | static sp<const Element> RGB_565(sp<RS> rs); |
| 314 | static sp<const Element> RGB_888(sp<RS> rs); |
| 315 | static sp<const Element> RGBA_5551(sp<RS> rs); |
| 316 | static sp<const Element> RGBA_4444(sp<RS> rs); |
| 317 | static sp<const Element> RGBA_8888(sp<RS> rs); |
| 318 | |
| 319 | static sp<const Element> F32_2(sp<RS> rs); |
| 320 | static sp<const Element> F32_3(sp<RS> rs); |
| 321 | static sp<const Element> F32_4(sp<RS> rs); |
| 322 | static sp<const Element> F64_2(sp<RS> rs); |
| 323 | static sp<const Element> F64_3(sp<RS> rs); |
| 324 | static sp<const Element> F64_4(sp<RS> rs); |
| 325 | static sp<const Element> U8_2(sp<RS> rs); |
| 326 | static sp<const Element> U8_3(sp<RS> rs); |
| 327 | static sp<const Element> U8_4(sp<RS> rs); |
| 328 | static sp<const Element> I8_2(sp<RS> rs); |
| 329 | static sp<const Element> I8_3(sp<RS> rs); |
| 330 | static sp<const Element> I8_4(sp<RS> rs); |
| 331 | static sp<const Element> U16_2(sp<RS> rs); |
| 332 | static sp<const Element> U16_3(sp<RS> rs); |
| 333 | static sp<const Element> U16_4(sp<RS> rs); |
| 334 | static sp<const Element> I16_2(sp<RS> rs); |
| 335 | static sp<const Element> I16_3(sp<RS> rs); |
| 336 | static sp<const Element> I16_4(sp<RS> rs); |
| 337 | static sp<const Element> U32_2(sp<RS> rs); |
| 338 | static sp<const Element> U32_3(sp<RS> rs); |
| 339 | static sp<const Element> U32_4(sp<RS> rs); |
| 340 | static sp<const Element> I32_2(sp<RS> rs); |
| 341 | static sp<const Element> I32_3(sp<RS> rs); |
| 342 | static sp<const Element> I32_4(sp<RS> rs); |
| 343 | static sp<const Element> U64_2(sp<RS> rs); |
| 344 | static sp<const Element> U64_3(sp<RS> rs); |
| 345 | static sp<const Element> U64_4(sp<RS> rs); |
| 346 | static sp<const Element> I64_2(sp<RS> rs); |
| 347 | static sp<const Element> I64_3(sp<RS> rs); |
| 348 | static sp<const Element> I64_4(sp<RS> rs); |
| 349 | static sp<const Element> MATRIX_4X4(sp<RS> rs); |
| 350 | static sp<const Element> MATRIX_3X3(sp<RS> rs); |
| 351 | static sp<const Element> MATRIX_2X2(sp<RS> rs); |
| 352 | |
| 353 | Element(void *id, sp<RS> rs, |
| 354 | android::Vector<sp<Element> > &elements, |
| 355 | android::Vector<android::String8> &elementNames, |
| 356 | android::Vector<uint32_t> &arraySizes); |
| 357 | Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size); |
| 358 | Element(sp<RS> rs); |
| 359 | virtual ~Element(); |
| 360 | |
| 361 | void updateFromNative(); |
| 362 | static sp<const Element> createUser(sp<RS> rs, RsDataType dt); |
| 363 | static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size); |
| 364 | static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk); |
| 365 | bool isCompatible(sp<const Element>e); |
| 366 | |
| 367 | class Builder { |
| 368 | private: |
| 369 | sp<RS> mRS; |
| 370 | android::Vector<sp<Element> > mElements; |
| 371 | android::Vector<android::String8> mElementNames; |
| 372 | android::Vector<uint32_t> mArraySizes; |
| 373 | bool mSkipPadding; |
| 374 | |
| 375 | public: |
| 376 | Builder(sp<RS> rs); |
| 377 | ~Builder(); |
| 378 | void add(sp<Element>, android::String8 &name, uint32_t arraySize = 1); |
| 379 | sp<const Element> create(); |
| 380 | }; |
| 381 | |
| 382 | private: |
| 383 | void updateVisibleSubElements(); |
| 384 | |
| 385 | android::Vector<sp</*const*/ Element> > mElements; |
| 386 | android::Vector<android::String8> mElementNames; |
| 387 | android::Vector<uint32_t> mArraySizes; |
| 388 | android::Vector<uint32_t> mVisibleElementMap; |
| 389 | android::Vector<uint32_t> mOffsetInBytes; |
| 390 | |
| 391 | RsDataType mType; |
| 392 | RsDataKind mKind; |
| 393 | bool mNormalized; |
| 394 | size_t mSizeBytes; |
| 395 | size_t mVectorSize; |
| 396 | }; |
| 397 | |
Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 398 | class FieldPacker { |
| 399 | protected: |
| 400 | unsigned char* mData; |
| 401 | size_t mPos; |
| 402 | size_t mLen; |
| 403 | |
| 404 | public: |
| 405 | FieldPacker(size_t len) |
| 406 | : mPos(0), |
| 407 | mLen(len) { |
| 408 | mData = new unsigned char[len]; |
| 409 | } |
| 410 | |
| 411 | virtual ~FieldPacker() { |
| 412 | delete [] mData; |
| 413 | } |
| 414 | |
| 415 | void align(size_t v) { |
| 416 | if ((v & (v - 1)) != 0) { |
| 417 | ALOGE("Non-power-of-two alignment: %zu", v); |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | while ((mPos & (v - 1)) != 0) { |
| 422 | mData[mPos++] = 0; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | void reset() { |
| 427 | mPos = 0; |
| 428 | } |
| 429 | |
| 430 | void reset(size_t i) { |
| 431 | if (i >= mLen) { |
| 432 | ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen); |
| 433 | return; |
| 434 | } |
| 435 | mPos = i; |
| 436 | } |
| 437 | |
| 438 | void skip(size_t i) { |
| 439 | size_t res = mPos + i; |
| 440 | if (res > mLen) { |
| 441 | ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen); |
| 442 | return; |
| 443 | } |
| 444 | mPos = res; |
| 445 | } |
| 446 | |
| 447 | void* getData() const { |
| 448 | return mData; |
| 449 | } |
| 450 | |
| 451 | size_t getLength() const { |
| 452 | return mLen; |
| 453 | } |
| 454 | |
| 455 | template <typename T> |
| 456 | void add(T t) { |
| 457 | align(sizeof(t)); |
| 458 | if (mPos + sizeof(t) <= mLen) { |
| 459 | memcpy(&mData[mPos], &t, sizeof(t)); |
| 460 | mPos += sizeof(t); |
| 461 | } |
| 462 | } |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 463 | |
| 464 | /* |
| 465 | void add(rs_matrix4x4 m) { |
| 466 | for (size_t i = 0; i < 16; i++) { |
| 467 | add(m.m[i]); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | void add(rs_matrix3x3 m) { |
| 472 | for (size_t i = 0; i < 9; i++) { |
| 473 | add(m.m[i]); |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | void add(rs_matrix2x2 m) { |
| 478 | for (size_t i = 0; i < 4; i++) { |
| 479 | add(m.m[i]); |
| 480 | } |
| 481 | } |
| 482 | */ |
| 483 | |
| 484 | void add(BaseObj* obj) { |
| 485 | if (obj != NULL) { |
| 486 | add((uint32_t) (uintptr_t) obj->getID()); |
| 487 | } else { |
| 488 | add((uint32_t) 0); |
| 489 | } |
| 490 | } |
Stephen Hines | 2c7206e | 2012-11-14 19:47:01 -0800 | [diff] [blame] | 491 | }; |
| 492 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 493 | class Type : public BaseObj { |
| 494 | protected: |
| 495 | friend class Allocation; |
| 496 | |
| 497 | uint32_t mDimX; |
| 498 | uint32_t mDimY; |
| 499 | uint32_t mDimZ; |
| 500 | bool mDimMipmaps; |
| 501 | bool mDimFaces; |
| 502 | size_t mElementCount; |
| 503 | sp<const Element> mElement; |
| 504 | |
| 505 | void calcElementCount(); |
| 506 | virtual void updateFromNative(); |
| 507 | |
| 508 | public: |
| 509 | |
| 510 | sp<const Element> getElement() const { |
| 511 | return mElement; |
| 512 | } |
| 513 | |
| 514 | uint32_t getX() const { |
| 515 | return mDimX; |
| 516 | } |
| 517 | |
| 518 | uint32_t getY() const { |
| 519 | return mDimY; |
| 520 | } |
| 521 | |
| 522 | uint32_t getZ() const { |
| 523 | return mDimZ; |
| 524 | } |
| 525 | |
| 526 | bool hasMipmaps() const { |
| 527 | return mDimMipmaps; |
| 528 | } |
| 529 | |
| 530 | bool hasFaces() const { |
| 531 | return mDimFaces; |
| 532 | } |
| 533 | |
| 534 | size_t getCount() const { |
| 535 | return mElementCount; |
| 536 | } |
| 537 | |
| 538 | size_t getSizeBytes() const { |
| 539 | return mElementCount * mElement->getSizeBytes(); |
| 540 | } |
| 541 | |
| 542 | Type(void *id, sp<RS> rs); |
| 543 | |
| 544 | |
| 545 | class Builder { |
| 546 | protected: |
| 547 | sp<RS> mRS; |
| 548 | uint32_t mDimX; |
| 549 | uint32_t mDimY; |
| 550 | uint32_t mDimZ; |
| 551 | bool mDimMipmaps; |
| 552 | bool mDimFaces; |
| 553 | sp<const Element> mElement; |
| 554 | |
| 555 | public: |
| 556 | Builder(sp<RS> rs, sp<const Element> e); |
| 557 | |
| 558 | void setX(uint32_t value); |
| 559 | void setY(int value); |
| 560 | void setMipmaps(bool value); |
| 561 | void setFaces(bool value); |
| 562 | sp<const Type> create(); |
| 563 | }; |
| 564 | |
| 565 | }; |
| 566 | |
| 567 | class Script : public BaseObj { |
| 568 | private: |
| 569 | |
| 570 | protected: |
| 571 | Script(void *id, sp<RS> rs); |
| 572 | void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out, |
| 573 | const void *v, size_t) const; |
| 574 | void bindAllocation(sp<Allocation> va, uint32_t slot) const; |
| 575 | void setVar(uint32_t index, const void *, size_t len) const; |
| 576 | void setVar(uint32_t index, sp<const BaseObj> o) const; |
| 577 | void invoke(uint32_t slot, const void *v, size_t len) const; |
| 578 | |
| 579 | |
| 580 | void invoke(uint32_t slot) const { |
| 581 | invoke(slot, NULL, 0); |
| 582 | } |
| 583 | void setVar(uint32_t index, float v) const { |
| 584 | setVar(index, &v, sizeof(v)); |
| 585 | } |
| 586 | void setVar(uint32_t index, double v) const { |
| 587 | setVar(index, &v, sizeof(v)); |
| 588 | } |
| 589 | void setVar(uint32_t index, int32_t v) const { |
| 590 | setVar(index, &v, sizeof(v)); |
| 591 | } |
| 592 | void setVar(uint32_t index, int64_t v) const { |
| 593 | setVar(index, &v, sizeof(v)); |
| 594 | } |
| 595 | void setVar(uint32_t index, bool v) const { |
| 596 | setVar(index, &v, sizeof(v)); |
| 597 | } |
| 598 | |
| 599 | public: |
| 600 | class FieldBase { |
| 601 | protected: |
| 602 | sp<const Element> mElement; |
| 603 | sp<Allocation> mAllocation; |
| 604 | |
| 605 | void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0); |
| 606 | |
| 607 | public: |
| 608 | sp<const Element> getElement() { |
| 609 | return mElement; |
| 610 | } |
| 611 | |
| 612 | sp<const Type> getType() { |
| 613 | return mAllocation->getType(); |
| 614 | } |
| 615 | |
| 616 | sp<const Allocation> getAllocation() { |
| 617 | return mAllocation; |
| 618 | } |
| 619 | |
| 620 | //void updateAllocation(); |
| 621 | }; |
| 622 | }; |
| 623 | |
| 624 | class ScriptC : public Script { |
| 625 | protected: |
| 626 | ScriptC(sp<RS> rs, |
| 627 | const void *codeTxt, size_t codeLength, |
| 628 | const char *cachedName, size_t cachedNameLength, |
| 629 | const char *cacheDir, size_t cacheDirLength); |
| 630 | |
| 631 | }; |
| 632 | |
Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 633 | class ScriptIntrinsic : public Script { |
| 634 | protected: |
Tim Murray | 3cd44af | 2012-11-14 11:25:27 -0800 | [diff] [blame] | 635 | ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e); |
Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 636 | }; |
| 637 | |
| 638 | class ScriptIntrinsicBlend : public ScriptIntrinsic { |
| 639 | public: |
Tim Murray | 3cd44af | 2012-11-14 11:25:27 -0800 | [diff] [blame] | 640 | ScriptIntrinsicBlend(sp<RS> rs, sp <const Element> e); |
Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 641 | void blendClear(sp<Allocation> in, sp<Allocation> out); |
| 642 | void blendSrc(sp<Allocation> in, sp<Allocation> out); |
| 643 | void blendDst(sp<Allocation> in, sp<Allocation> out); |
| 644 | void blendSrcOver(sp<Allocation> in, sp<Allocation> out); |
| 645 | void blendDstOver(sp<Allocation> in, sp<Allocation> out); |
| 646 | void blendSrcIn(sp<Allocation> in, sp<Allocation> out); |
| 647 | void blendDstIn(sp<Allocation> in, sp<Allocation> out); |
| 648 | void blendSrcOut(sp<Allocation> in, sp<Allocation> out); |
| 649 | void blendDstOut(sp<Allocation> in, sp<Allocation> out); |
| 650 | void blendSrcAtop(sp<Allocation> in, sp<Allocation> out); |
| 651 | void blendDstAtop(sp<Allocation> in, sp<Allocation> out); |
| 652 | void blendXor(sp<Allocation> in, sp<Allocation> out); |
| 653 | void blendMultiply(sp<Allocation> in, sp<Allocation> out); |
| 654 | void blendAdd(sp<Allocation> in, sp<Allocation> out); |
| 655 | void blendSubtract(sp<Allocation> in, sp<Allocation> out); |
| 656 | }; |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 657 | |
Tim Murray | 8f1e60c | 2012-11-13 12:25:11 -0800 | [diff] [blame] | 658 | class ScriptIntrinsicBlur : public ScriptIntrinsic { |
| 659 | public: |
Tim Murray | 3cd44af | 2012-11-14 11:25:27 -0800 | [diff] [blame] | 660 | ScriptIntrinsicBlur(sp<RS> rs, sp <const Element> e); |
Tim Murray | 8f1e60c | 2012-11-13 12:25:11 -0800 | [diff] [blame] | 661 | void blur(sp<Allocation> in, sp<Allocation> out); |
| 662 | void setRadius(float radius); |
| 663 | }; |
| 664 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 665 | } |
Tim Murray | 7f0d568 | 2012-11-08 16:35:24 -0800 | [diff] [blame] | 666 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | #endif |