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