rsCppStructs.h revision eeaf7142d7e06efb3e0ddc7ef542884ab1d527dc
1/* 2 * Copyright (C) 2013 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 "rsDefines.h" 21#include "util/RefBase.h" 22#include "rsDispatch.h" 23 24#include <vector> 25#include <string> 26 27// Every row in an RS allocation is guaranteed to be aligned by this amount 28// Every row in a user-backed allocation must be aligned by this amount 29#define RS_CPU_ALLOCATION_ALIGNMENT 16 30 31namespace android { 32namespace RSC { 33 34typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText); 35typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen); 36 37class RS; 38class BaseObj; 39class Element; 40class Type; 41class Allocation; 42class Script; 43class ScriptC; 44class Sampler; 45 46 enum RSError { 47 RS_SUCCESS = 0, 48 RS_ERROR_INVALID_PARAMETER = 1, 49 RS_ERROR_RUNTIME_ERROR = 2, 50 RS_ERROR_INVALID_ELEMENT = 3, 51 RS_ERROR_MAX = 9999 52 53 }; 54 55 enum RSYuvFormat { 56 RS_YUV_NONE = 0, 57 RS_YUV_YV12 = 1, 58 RS_YUV_NV21 = 2, 59 RS_YUV_MAX = 3 60 }; 61 62 class RS : public android::RSC::LightRefBase<RS> { 63 64 public: 65 RS(); 66 virtual ~RS(); 67 68 bool init(bool forceCpu = false, bool synchronous = false); 69 70 void setErrorHandler(ErrorHandlerFunc_t func); 71 ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; } 72 73 void setMessageHandler(MessageHandlerFunc_t func); 74 MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; } 75 76 void throwError(RSError error, const char *errMsg); 77 RSError getError(); 78 79 RsContext getContext() { return mContext; } 80 81 void finish(); 82 83 static dispatchTable* dispatch; 84 85 private: 86 static bool usingNative; 87 static bool initDispatch(int targetApi); 88 89 bool init(int targetApi, bool forceCpu, bool synchronous); 90 static void * threadProc(void *); 91 92 static bool gInitialized; 93 static pthread_mutex_t gInitMutex; 94 95 pthread_t mMessageThreadId; 96 pid_t mNativeMessageThreadId; 97 bool mMessageRun; 98 99 RsDevice mDev; 100 RsContext mContext; 101 RSError mCurrentError; 102 103 ErrorHandlerFunc_t mErrorFunc; 104 MessageHandlerFunc_t mMessageFunc; 105 bool mInit; 106 107 struct { 108 sp<const Element> U8; 109 sp<const Element> U8_2; 110 sp<const Element> U8_3; 111 sp<const Element> U8_4; 112 sp<const Element> I8; 113 sp<const Element> I8_2; 114 sp<const Element> I8_3; 115 sp<const Element> I8_4; 116 sp<const Element> U16; 117 sp<const Element> U16_2; 118 sp<const Element> U16_3; 119 sp<const Element> U16_4; 120 sp<const Element> I16; 121 sp<const Element> I16_2; 122 sp<const Element> I16_3; 123 sp<const Element> I16_4; 124 sp<const Element> U32; 125 sp<const Element> U32_2; 126 sp<const Element> U32_3; 127 sp<const Element> U32_4; 128 sp<const Element> I32; 129 sp<const Element> I32_2; 130 sp<const Element> I32_3; 131 sp<const Element> I32_4; 132 sp<const Element> U64; 133 sp<const Element> U64_2; 134 sp<const Element> U64_3; 135 sp<const Element> U64_4; 136 sp<const Element> I64; 137 sp<const Element> I64_2; 138 sp<const Element> I64_3; 139 sp<const Element> I64_4; 140 sp<const Element> F32; 141 sp<const Element> F32_2; 142 sp<const Element> F32_3; 143 sp<const Element> F32_4; 144 sp<const Element> F64; 145 sp<const Element> F64_2; 146 sp<const Element> F64_3; 147 sp<const Element> F64_4; 148 sp<const Element> BOOLEAN; 149 150 sp<const Element> ELEMENT; 151 sp<const Element> TYPE; 152 sp<const Element> ALLOCATION; 153 sp<const Element> SAMPLER; 154 sp<const Element> SCRIPT; 155 sp<const Element> MESH; 156 sp<const Element> PROGRAM_FRAGMENT; 157 sp<const Element> PROGRAM_VERTEX; 158 sp<const Element> PROGRAM_RASTER; 159 sp<const Element> PROGRAM_STORE; 160 161 sp<const Element> A_8; 162 sp<const Element> RGB_565; 163 sp<const Element> RGB_888; 164 sp<const Element> RGBA_5551; 165 sp<const Element> RGBA_4444; 166 sp<const Element> RGBA_8888; 167 168 sp<const Element> YUV; 169 170 sp<const Element> MATRIX_4X4; 171 sp<const Element> MATRIX_3X3; 172 sp<const Element> MATRIX_2X2; 173 } mElements; 174 175 struct { 176 sp<const Sampler> CLAMP_NEAREST; 177 sp<const Sampler> CLAMP_LINEAR; 178 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR; 179 sp<const Sampler> WRAP_NEAREST; 180 sp<const Sampler> WRAP_LINEAR; 181 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR; 182 sp<const Sampler> MIRRORED_REPEAT_NEAREST; 183 sp<const Sampler> MIRRORED_REPEAT_LINEAR; 184 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR; 185 } mSamplers; 186 friend class Sampler; 187 friend class Element; 188}; 189 190class BaseObj : public android::RSC::LightRefBase<BaseObj> { 191public: 192 void * getID() const; 193 virtual ~BaseObj(); 194 virtual void updateFromNative(); 195 virtual bool equals(sp<const BaseObj> obj); 196 197protected: 198 void *mID; 199 sp<RS> mRS; 200 std::string mName; 201 202 BaseObj(void *id, sp<RS> rs); 203 void checkValid(); 204 205 static void * getObjID(sp<const BaseObj> o); 206 207}; 208 209 210class Allocation : public BaseObj { 211protected: 212 sp<const Type> mType; 213 uint32_t mUsage; 214 sp<Allocation> mAdaptedAllocation; 215 216 bool mConstrainedLOD; 217 bool mConstrainedFace; 218 bool mConstrainedY; 219 bool mConstrainedZ; 220 bool mReadAllowed; 221 bool mWriteAllowed; 222 uint32_t mSelectedY; 223 uint32_t mSelectedZ; 224 uint32_t mSelectedLOD; 225 RsAllocationCubemapFace mSelectedFace; 226 227 uint32_t mCurrentDimX; 228 uint32_t mCurrentDimY; 229 uint32_t mCurrentDimZ; 230 uint32_t mCurrentCount; 231 232 void * getIDSafe() const; 233 void updateCacheInfo(sp<const Type> t); 234 235 Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage); 236 237 void validateIsInt32(); 238 void validateIsInt16(); 239 void validateIsInt8(); 240 void validateIsFloat32(); 241 void validateIsObject(); 242 243 virtual void updateFromNative(); 244 245 void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h); 246 void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff, 247 uint32_t w, uint32_t h, uint32_t d); 248 249public: 250 sp<const Type> getType() const { 251 return mType; 252 } 253 254 void syncAll(RsAllocationUsageType srcLocation); 255 void ioSendOutput(); 256 void ioGetInput(); 257 258 void generateMipmaps(); 259 260 void copy1DRangeFrom(uint32_t off, size_t count, const void *data); 261 void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff); 262 263 void copy1DRangeTo(uint32_t off, size_t count, void *data); 264 265 void copy1DFrom(const void* data); 266 void copy1DTo(void* data); 267 268 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, 269 const void *data); 270 271 void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, 272 void *data); 273 274 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, 275 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff); 276 277 void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, 278 const void *data, size_t stride); 279 void copy2DStridedFrom(const void *data, size_t stride); 280 281 void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, 282 void *data, size_t stride); 283 void copy2DStridedTo(void *data, size_t stride); 284 285 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w, 286 uint32_t h, uint32_t d, const void* data); 287 288 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, 289 uint32_t w, uint32_t h, uint32_t d, 290 sp<const Allocation> data, 291 uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff); 292 293 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, 294 RsAllocationMipmapControl mips, uint32_t usage); 295 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, 296 RsAllocationMipmapControl mips, uint32_t usage, void * pointer); 297 298 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, 299 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); 300 static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count, 301 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); 302 static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e, 303 size_t x, size_t y, 304 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); 305 306 307}; 308 309class Element : public BaseObj { 310public: 311 bool isComplex(); 312 size_t getSubElementCount() { 313 return mVisibleElementMap.size(); 314 } 315 316 sp<const Element> getSubElement(uint32_t index); 317 const char * getSubElementName(uint32_t index); 318 size_t getSubElementArraySize(uint32_t index); 319 uint32_t getSubElementOffsetBytes(uint32_t index); 320 RsDataType getDataType() const { 321 return mType; 322 } 323 324 RsDataKind getDataKind() const { 325 return mKind; 326 } 327 328 size_t getSizeBytes() const { 329 return mSizeBytes; 330 } 331 332 uint32_t getVectorSize() const { 333 return mVectorSize; 334 } 335 336 static sp<const Element> BOOLEAN(sp<RS> rs); 337 static sp<const Element> U8(sp<RS> rs); 338 static sp<const Element> I8(sp<RS> rs); 339 static sp<const Element> U16(sp<RS> rs); 340 static sp<const Element> I16(sp<RS> rs); 341 static sp<const Element> U32(sp<RS> rs); 342 static sp<const Element> I32(sp<RS> rs); 343 static sp<const Element> U64(sp<RS> rs); 344 static sp<const Element> I64(sp<RS> rs); 345 static sp<const Element> F32(sp<RS> rs); 346 static sp<const Element> F64(sp<RS> rs); 347 static sp<const Element> ELEMENT(sp<RS> rs); 348 static sp<const Element> TYPE(sp<RS> rs); 349 static sp<const Element> ALLOCATION(sp<RS> rs); 350 static sp<const Element> SAMPLER(sp<RS> rs); 351 static sp<const Element> SCRIPT(sp<RS> rs); 352 static sp<const Element> MESH(sp<RS> rs); 353 static sp<const Element> PROGRAM_FRAGMENT(sp<RS> rs); 354 static sp<const Element> PROGRAM_VERTEX(sp<RS> rs); 355 static sp<const Element> PROGRAM_RASTER(sp<RS> rs); 356 static sp<const Element> PROGRAM_STORE(sp<RS> rs); 357 358 static sp<const Element> A_8(sp<RS> rs); 359 static sp<const Element> RGB_565(sp<RS> rs); 360 static sp<const Element> RGB_888(sp<RS> rs); 361 static sp<const Element> RGBA_5551(sp<RS> rs); 362 static sp<const Element> RGBA_4444(sp<RS> rs); 363 static sp<const Element> RGBA_8888(sp<RS> rs); 364 365 static sp<const Element> F32_2(sp<RS> rs); 366 static sp<const Element> F32_3(sp<RS> rs); 367 static sp<const Element> F32_4(sp<RS> rs); 368 static sp<const Element> F64_2(sp<RS> rs); 369 static sp<const Element> F64_3(sp<RS> rs); 370 static sp<const Element> F64_4(sp<RS> rs); 371 static sp<const Element> U8_2(sp<RS> rs); 372 static sp<const Element> U8_3(sp<RS> rs); 373 static sp<const Element> U8_4(sp<RS> rs); 374 static sp<const Element> I8_2(sp<RS> rs); 375 static sp<const Element> I8_3(sp<RS> rs); 376 static sp<const Element> I8_4(sp<RS> rs); 377 static sp<const Element> U16_2(sp<RS> rs); 378 static sp<const Element> U16_3(sp<RS> rs); 379 static sp<const Element> U16_4(sp<RS> rs); 380 static sp<const Element> I16_2(sp<RS> rs); 381 static sp<const Element> I16_3(sp<RS> rs); 382 static sp<const Element> I16_4(sp<RS> rs); 383 static sp<const Element> U32_2(sp<RS> rs); 384 static sp<const Element> U32_3(sp<RS> rs); 385 static sp<const Element> U32_4(sp<RS> rs); 386 static sp<const Element> I32_2(sp<RS> rs); 387 static sp<const Element> I32_3(sp<RS> rs); 388 static sp<const Element> I32_4(sp<RS> rs); 389 static sp<const Element> U64_2(sp<RS> rs); 390 static sp<const Element> U64_3(sp<RS> rs); 391 static sp<const Element> U64_4(sp<RS> rs); 392 static sp<const Element> I64_2(sp<RS> rs); 393 static sp<const Element> I64_3(sp<RS> rs); 394 static sp<const Element> I64_4(sp<RS> rs); 395 static sp<const Element> YUV(sp<RS> rs); 396 static sp<const Element> MATRIX_4X4(sp<RS> rs); 397 static sp<const Element> MATRIX_3X3(sp<RS> rs); 398 static sp<const Element> MATRIX_2X2(sp<RS> rs); 399 400 void updateFromNative(); 401 static sp<const Element> createUser(sp<RS> rs, RsDataType dt); 402 static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size); 403 static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk); 404 bool isCompatible(sp<const Element>e) const; 405 406 class Builder { 407 private: 408 sp<RS> mRS; 409 std::vector<sp<Element> > mElements; 410 std::vector<std::string> mElementNames; 411 std::vector<uint32_t> mArraySizes; 412 bool mSkipPadding; 413 414 public: 415 Builder(sp<RS> rs); 416 ~Builder(); 417 void add(sp<Element> e, std::string &name, uint32_t arraySize = 1); 418 sp<const Element> create(); 419 }; 420 421protected: 422 Element(void *id, sp<RS> rs, 423 std::vector<sp<Element> > &elements, 424 std::vector<std::string> &elementNames, 425 std::vector<uint32_t> &arraySizes); 426 Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size); 427 Element(sp<RS> rs); 428 virtual ~Element(); 429 430private: 431 void updateVisibleSubElements(); 432 433 std::vector<sp<Element> > mElements; 434 std::vector<std::string> mElementNames; 435 std::vector<uint32_t> mArraySizes; 436 std::vector<uint32_t> mVisibleElementMap; 437 std::vector<uint32_t> mOffsetInBytes; 438 439 RsDataType mType; 440 RsDataKind mKind; 441 bool mNormalized; 442 size_t mSizeBytes; 443 size_t mVectorSize; 444}; 445 446class FieldPacker { 447protected: 448 unsigned char* mData; 449 size_t mPos; 450 size_t mLen; 451 452public: 453 FieldPacker(size_t len) 454 : mPos(0), mLen(len) { 455 mData = new unsigned char[len]; 456 } 457 458 virtual ~FieldPacker() { 459 delete [] mData; 460 } 461 462 void align(size_t v) { 463 if ((v & (v - 1)) != 0) { 464 // ALOGE("Non-power-of-two alignment: %zu", v); 465 return; 466 } 467 468 while ((mPos & (v - 1)) != 0) { 469 mData[mPos++] = 0; 470 } 471 } 472 473 void reset() { 474 mPos = 0; 475 } 476 477 void reset(size_t i) { 478 if (i >= mLen) { 479 // ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen); 480 return; 481 } 482 mPos = i; 483 } 484 485 void skip(size_t i) { 486 size_t res = mPos + i; 487 if (res > mLen) { 488 // ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen); 489 return; 490 } 491 mPos = res; 492 } 493 494 void* getData() const { 495 return mData; 496 } 497 498 size_t getLength() const { 499 return mLen; 500 } 501 502 template <typename T> 503 void add(T t) { 504 align(sizeof(t)); 505 if (mPos + sizeof(t) <= mLen) { 506 memcpy(&mData[mPos], &t, sizeof(t)); 507 mPos += sizeof(t); 508 } 509 } 510 511 /* 512 void add(rs_matrix4x4 m) { 513 for (size_t i = 0; i < 16; i++) { 514 add(m.m[i]); 515 } 516 } 517 518 void add(rs_matrix3x3 m) { 519 for (size_t i = 0; i < 9; i++) { 520 add(m.m[i]); 521 } 522 } 523 524 void add(rs_matrix2x2 m) { 525 for (size_t i = 0; i < 4; i++) { 526 add(m.m[i]); 527 } 528 } 529 */ 530 531 void add(sp<BaseObj> obj) { 532 if (obj != NULL) { 533 add((uint32_t) (uintptr_t) obj->getID()); 534 } else { 535 add((uint32_t) 0); 536 } 537 } 538}; 539 540 541class Type : public BaseObj { 542protected: 543 friend class Allocation; 544 545 uint32_t mDimX; 546 uint32_t mDimY; 547 uint32_t mDimZ; 548 RSYuvFormat mYuvFormat; 549 bool mDimMipmaps; 550 bool mDimFaces; 551 size_t mElementCount; 552 sp<const Element> mElement; 553 554 Type(void *id, sp<RS> rs); 555 556 void calcElementCount(); 557 virtual void updateFromNative(); 558 559public: 560 561 RSYuvFormat getYuvFormat() const { 562 return mYuvFormat; 563 } 564 565 sp<const Element> getElement() const { 566 return mElement; 567 } 568 569 uint32_t getX() const { 570 return mDimX; 571 } 572 573 uint32_t getY() const { 574 return mDimY; 575 } 576 577 uint32_t getZ() const { 578 return mDimZ; 579 } 580 581 bool hasMipmaps() const { 582 return mDimMipmaps; 583 } 584 585 bool hasFaces() const { 586 return mDimFaces; 587 } 588 589 size_t getCount() const { 590 return mElementCount; 591 } 592 593 size_t getSizeBytes() const { 594 return mElementCount * mElement->getSizeBytes(); 595 } 596 597 static sp<const Type> create(sp<RS> rs, sp<const Element> e, uint32_t dimX, uint32_t dimY, uint32_t dimZ); 598 599 class Builder { 600 protected: 601 sp<RS> mRS; 602 uint32_t mDimX; 603 uint32_t mDimY; 604 uint32_t mDimZ; 605 RSYuvFormat mYuvFormat; 606 bool mDimMipmaps; 607 bool mDimFaces; 608 sp<const Element> mElement; 609 610 public: 611 Builder(sp<RS> rs, sp<const Element> e); 612 613 void setX(uint32_t value); 614 void setY(uint32_t value); 615 void setZ(uint32_t value); 616 void setYuvFormat(RSYuvFormat format); 617 void setMipmaps(bool value); 618 void setFaces(bool value); 619 sp<const Type> create(); 620 }; 621 622}; 623 624class Script : public BaseObj { 625private: 626 627protected: 628 Script(void *id, sp<RS> rs); 629 void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out, 630 const void *v, size_t) const; 631 void bindAllocation(sp<Allocation> va, uint32_t slot) const; 632 void setVar(uint32_t index, const void *, size_t len) const; 633 void setVar(uint32_t index, sp<const BaseObj> o) const; 634 void invoke(uint32_t slot, const void *v, size_t len) const; 635 636 637 void invoke(uint32_t slot) const { 638 invoke(slot, NULL, 0); 639 } 640 void setVar(uint32_t index, float v) const { 641 setVar(index, &v, sizeof(v)); 642 } 643 void setVar(uint32_t index, double v) const { 644 setVar(index, &v, sizeof(v)); 645 } 646 void setVar(uint32_t index, int32_t v) const { 647 setVar(index, &v, sizeof(v)); 648 } 649 void setVar(uint32_t index, int64_t v) const { 650 setVar(index, &v, sizeof(v)); 651 } 652 void setVar(uint32_t index, bool v) const { 653 setVar(index, &v, sizeof(v)); 654 } 655 656public: 657 class FieldBase { 658 protected: 659 sp<const Element> mElement; 660 sp<Allocation> mAllocation; 661 662 void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0); 663 664 public: 665 sp<const Element> getElement() { 666 return mElement; 667 } 668 669 sp<const Type> getType() { 670 return mAllocation->getType(); 671 } 672 673 sp<const Allocation> getAllocation() { 674 return mAllocation; 675 } 676 677 //void updateAllocation(); 678 }; 679}; 680 681class ScriptC : public Script { 682protected: 683 ScriptC(sp<RS> rs, 684 const void *codeTxt, size_t codeLength, 685 const char *cachedName, size_t cachedNameLength, 686 const char *cacheDir, size_t cacheDirLength); 687 688}; 689 690class ScriptIntrinsic : public Script { 691 protected: 692 sp<const Element> mElement; 693 ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e); 694 virtual ~ScriptIntrinsic(); 695}; 696 697class ScriptIntrinsic3DLUT : public ScriptIntrinsic { 698 private: 699 ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e); 700 public: 701 static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e); 702 void forEach(sp<Allocation> ain, sp<Allocation> aout); 703 void setLUT(sp<Allocation> lut); 704}; 705 706class ScriptIntrinsicBlend : public ScriptIntrinsic { 707 private: 708 ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e); 709 public: 710 static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e); 711 void blendClear(sp<Allocation> in, sp<Allocation> out); 712 void blendSrc(sp<Allocation> in, sp<Allocation> out); 713 void blendDst(sp<Allocation> in, sp<Allocation> out); 714 void blendSrcOver(sp<Allocation> in, sp<Allocation> out); 715 void blendDstOver(sp<Allocation> in, sp<Allocation> out); 716 void blendSrcIn(sp<Allocation> in, sp<Allocation> out); 717 void blendDstIn(sp<Allocation> in, sp<Allocation> out); 718 void blendSrcOut(sp<Allocation> in, sp<Allocation> out); 719 void blendDstOut(sp<Allocation> in, sp<Allocation> out); 720 void blendSrcAtop(sp<Allocation> in, sp<Allocation> out); 721 void blendDstAtop(sp<Allocation> in, sp<Allocation> out); 722 void blendXor(sp<Allocation> in, sp<Allocation> out); 723 void blendMultiply(sp<Allocation> in, sp<Allocation> out); 724 void blendAdd(sp<Allocation> in, sp<Allocation> out); 725 void blendSubtract(sp<Allocation> in, sp<Allocation> out); 726}; 727 728class ScriptIntrinsicBlur : public ScriptIntrinsic { 729 private: 730 ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e); 731 public: 732 static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e); 733 void setInput(sp<Allocation> in); 734 void forEach(sp<Allocation> out); 735 void setRadius(float radius); 736}; 737 738class ScriptIntrinsicColorMatrix : public ScriptIntrinsic { 739 private: 740 ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e); 741 public: 742 static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs); 743 void forEach(sp<Allocation> in, sp<Allocation> out); 744 void setAdd(float* add); 745 void setColorMatrix3(float* m); 746 void setColorMatrix4(float* m); 747 void setGreyscale(); 748 void setRGBtoYUV(); 749 void setYUVtoRGB(); 750}; 751 752class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic { 753 private: 754 ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e); 755 public: 756 static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e); 757 void setInput(sp<Allocation> in); 758 void forEach(sp<Allocation> out); 759 void setCoefficients(float* v); 760}; 761 762class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic { 763 private: 764 ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e); 765 public: 766 static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e); 767 void setInput(sp<Allocation> in); 768 void forEach(sp<Allocation> out); 769 void setCoefficients(float* v); 770}; 771 772class ScriptIntrinsicHistogram : public ScriptIntrinsic { 773 private: 774 ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e); 775 sp<Allocation> mOut; 776 public: 777 static sp<ScriptIntrinsicHistogram> create(sp<RS> rs); 778 void setOutput(sp<Allocation> aout); 779 void setDotCoefficients(float r, float g, float b, float a); 780 void forEach(sp<Allocation> ain); 781 void forEach_dot(sp<Allocation> ain); 782}; 783 784class ScriptIntrinsicLUT : public ScriptIntrinsic { 785 private: 786 sp<Allocation> LUT; 787 bool mDirty; 788 unsigned char mCache[1024]; 789 void setTable(unsigned int offset, unsigned char base, unsigned int length, unsigned char* lutValues); 790 ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e); 791 792 public: 793 static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e); 794 void forEach(sp<Allocation> ain, sp<Allocation> aout); 795 void setRed(unsigned char base, unsigned int length, unsigned char* lutValues); 796 void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues); 797 void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues); 798 void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues); 799 virtual ~ScriptIntrinsicLUT(); 800}; 801 802class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic { 803 private: 804 ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e); 805 public: 806 static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e); 807 void setInput(sp<Allocation> in); 808 void forEach(sp<Allocation> out); 809 810}; 811 812 813 class Sampler : public BaseObj { 814 private: 815 Sampler(sp<RS> rs, void* id); 816 RsSamplerValue mMin; 817 RsSamplerValue mMag; 818 RsSamplerValue mWrapS; 819 RsSamplerValue mWrapT; 820 RsSamplerValue mWrapR; 821 float mAniso; 822 823 public: 824 static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy); 825 826 RsSamplerValue getMinification(); 827 RsSamplerValue getMagnification(); 828 RsSamplerValue getWrapS(); 829 RsSamplerValue getWrapT(); 830 float getAnisotropy(); 831 832 sp<const Sampler> CLAMP_NEAREST(sp<RS> rs); 833 sp<const Sampler> CLAMP_LINEAR(sp<RS> rs); 834 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs); 835 sp<const Sampler> WRAP_NEAREST(sp<RS> rs); 836 sp<const Sampler> WRAP_LINEAR(sp<RS> rs); 837 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs); 838 sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs); 839 sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs); 840 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs); 841 842}; 843 844class Byte2 { 845 public: 846 int8_t x, y; 847 848 Byte2(int8_t initX, int8_t initY) 849 : x(initX), y(initY) {} 850 Byte2() : x(0), y(0) {} 851}; 852 853class Byte3 { 854 public: 855 int8_t x, y, z; 856 857 Byte3(int8_t initX, int8_t initY, int8_t initZ) 858 : x(initX), y(initY), z(initZ) {} 859 Byte3() : x(0), y(0), z(0) {} 860}; 861 862class Byte4 { 863 public: 864 int8_t x, y, z, w; 865 866 Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW) 867 : x(initX), y(initY), z(initZ), w(initW) {} 868 Byte4() : x(0), y(0), z(0), w(0) {} 869}; 870 871class UByte2 { 872 public: 873 uint8_t x, y; 874 875 UByte2(uint8_t initX, uint8_t initY) 876 : x(initX), y(initY) {} 877 UByte2() : x(0), y(0) {} 878}; 879 880class UByte3 { 881 public: 882 uint8_t x, y, z; 883 884 UByte3(uint8_t initX, uint8_t initY, uint8_t initZ) 885 : x(initX), y(initY), z(initZ) {} 886 UByte3() : x(0), y(0), z(0) {} 887}; 888 889class UByte4 { 890 public: 891 uint8_t x, y, z, w; 892 893 UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW) 894 : x(initX), y(initY), z(initZ), w(initW) {} 895 UByte4() : x(0), y(0), z(0), w(0) {} 896}; 897 898class Short2 { 899 public: 900 short x, y; 901 902 Short2(short initX, short initY) 903 : x(initX), y(initY) {} 904 Short2() : x(0), y(0) {} 905}; 906 907class Short3 { 908 public: 909 short x, y, z; 910 911 Short3(short initX, short initY, short initZ) 912 : x(initX), y(initY), z(initZ) {} 913 Short3() : x(0), y(0), z(0) {} 914}; 915 916class Short4 { 917 public: 918 short x, y, z, w; 919 920 Short4(short initX, short initY, short initZ, short initW) 921 : x(initX), y(initY), z(initZ), w(initW) {} 922 Short4() : x(0), y(0), z(0), w(0) {} 923}; 924 925class UShort2 { 926 public: 927 uint16_t x, y; 928 929 UShort2(uint16_t initX, uint16_t initY) 930 : x(initX), y(initY) {} 931 UShort2() : x(0), y(0) {} 932}; 933 934class UShort3 { 935 public: 936 uint16_t x, y, z; 937 938 UShort3(uint16_t initX, uint16_t initY, uint16_t initZ) 939 : x(initX), y(initY), z(initZ) {} 940 UShort3() : x(0), y(0), z(0) {} 941}; 942 943class UShort4 { 944 public: 945 uint16_t x, y, z, w; 946 947 UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW) 948 : x(initX), y(initY), z(initZ), w(initW) {} 949 UShort4() : x(0), y(0), z(0), w(0) {} 950}; 951 952class Int2 { 953 public: 954 int x, y; 955 956 Int2(int initX, int initY) 957 : x(initX), y(initY) {} 958 Int2() : x(0), y(0) {} 959}; 960 961class Int3 { 962 public: 963 int x, y, z; 964 965 Int3(int initX, int initY, int initZ) 966 : x(initX), y(initY), z(initZ) {} 967 Int3() : x(0), y(0), z(0) {} 968}; 969 970class Int4 { 971 public: 972 int x, y, z, w; 973 974 Int4(int initX, int initY, int initZ, int initW) 975 : x(initX), y(initY), z(initZ), w(initW) {} 976 Int4() : x(0), y(0), z(0), w(0) {} 977}; 978 979class UInt2 { 980 public: 981 uint32_t x, y; 982 983 UInt2(uint32_t initX, uint32_t initY) 984 : x(initX), y(initY) {} 985 UInt2() : x(0), y(0) {} 986}; 987 988class UInt3 { 989 public: 990 uint32_t x, y, z; 991 992 UInt3(uint32_t initX, uint32_t initY, uint32_t initZ) 993 : x(initX), y(initY), z(initZ) {} 994 UInt3() : x(0), y(0), z(0) {} 995}; 996 997class UInt4 { 998 public: 999 uint32_t x, y, z, w; 1000 1001 UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW) 1002 : x(initX), y(initY), z(initZ), w(initW) {} 1003 UInt4() : x(0), y(0), z(0), w(0) {} 1004}; 1005 1006class Long2 { 1007 public: 1008 int64_t x, y; 1009 1010 Long2(int64_t initX, int64_t initY) 1011 : x(initX), y(initY) {} 1012 Long2() : x(0), y(0) {} 1013}; 1014 1015class Long3 { 1016 public: 1017 int64_t x, y, z; 1018 1019 Long3(int64_t initX, int64_t initY, int64_t initZ) 1020 : x(initX), y(initY), z(initZ) {} 1021 Long3() : x(0), y(0), z(0) {} 1022}; 1023 1024class Long4 { 1025 public: 1026 int64_t x, y, z, w; 1027 1028 Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW) 1029 : x(initX), y(initY), z(initZ), w(initW) {} 1030 Long4() : x(0), y(0), z(0), w(0) {} 1031}; 1032 1033class ULong2 { 1034 public: 1035 uint64_t x, y; 1036 1037 ULong2(uint64_t initX, uint64_t initY) 1038 : x(initX), y(initY) {} 1039 ULong2() : x(0), y(0) {} 1040}; 1041 1042class ULong3 { 1043 public: 1044 uint64_t x, y, z; 1045 1046 ULong3(uint64_t initX, uint64_t initY, uint64_t initZ) 1047 : x(initX), y(initY), z(initZ) {} 1048 ULong3() : x(0), y(0), z(0) {} 1049}; 1050 1051class ULong4 { 1052 public: 1053 uint64_t x, y, z, w; 1054 1055 ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW) 1056 : x(initX), y(initY), z(initZ), w(initW) {} 1057 ULong4() : x(0), y(0), z(0), w(0) {} 1058}; 1059 1060class Float2 { 1061 public: 1062 float x, y; 1063 1064 Float2(float initX, float initY) 1065 : x(initX), y(initY) {} 1066 Float2() : x(0), y(0) {} 1067}; 1068 1069class Float3 { 1070 public: 1071 float x, y, z; 1072 1073 Float3(float initX, float initY, float initZ) 1074 : x(initX), y(initY), z(initZ) {} 1075 Float3() : x(0.f), y(0.f), z(0.f) {} 1076}; 1077 1078class Float4 { 1079 public: 1080 float x, y, z, w; 1081 1082 Float4(float initX, float initY, float initZ, float initW) 1083 : x(initX), y(initY), z(initZ), w(initW) {} 1084 Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {} 1085}; 1086 1087class Double2 { 1088 public: 1089 double x, y; 1090 1091 Double2(double initX, double initY) 1092 : x(initX), y(initY) {} 1093 Double2() : x(0), y(0) {} 1094}; 1095 1096class Double3 { 1097 public: 1098 double x, y, z; 1099 1100 Double3(double initX, double initY, double initZ) 1101 : x(initX), y(initY), z(initZ) {} 1102 Double3() : x(0), y(0), z(0) {} 1103}; 1104 1105class Double4 { 1106 public: 1107 double x, y, z, w; 1108 1109 Double4(double initX, double initY, double initZ, double initW) 1110 : x(initX), y(initY), z(initZ), w(initW) {} 1111 Double4() : x(0), y(0), z(0), w(0) {} 1112}; 1113 1114} 1115 1116} 1117 1118#endif 1119