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 /** 28 * Every row in an RS allocation is guaranteed to be aligned by this amount, and 29 * every row in a user-backed allocation must be aligned by this amount. 30 */ 31 #define RS_CPU_ALLOCATION_ALIGNMENT 16 32 33 namespace android { 34 namespace RSC { 35 36 typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText); 37 typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen); 38 39 class RS; 40 class BaseObj; 41 class Element; 42 class Type; 43 class Allocation; 44 class Script; 45 class ScriptC; 46 class Sampler; 47 48 /** 49 * Possible error codes used by RenderScript. Once a status other than RS_SUCCESS 50 * is returned, the RenderScript context is considered dead and cannot perform any 51 * additional work. 52 */ 53 enum RSError { 54 RS_SUCCESS = 0, ///< No error 55 RS_ERROR_INVALID_PARAMETER = 1, ///< An invalid parameter was passed to a function 56 RS_ERROR_RUNTIME_ERROR = 2, ///< The RenderScript driver returned an error; this is 57 ///< often indicative of a kernel that crashed 58 RS_ERROR_INVALID_ELEMENT = 3, ///< An invalid Element was passed to a function 59 RS_ERROR_MAX = 9999 60 61 }; 62 63 /** 64 * YUV formats supported by the RenderScript API. 65 */ 66 enum RSYuvFormat { 67 RS_YUV_NONE = 0, ///< No YUV data 68 RS_YUV_YV12 = 1, ///< YUV data in YV12 format 69 RS_YUV_NV21 = 2, ///< YUV data in NV21 format 70 RS_YUV_MAX = 3 71 }; 72 73 /** 74 * Flags that can control RenderScript behavior on a per-context level. 75 */ 76 enum RSInitFlags { 77 RS_INIT_SYNCHRONOUS = 1, ///< All RenderScript calls will be synchronous. May reduce latency. 78 RS_INIT_LOW_LATENCY = 2, ///< Prefer low latency devices over potentially higher throughput devices. 79 RS_INIT_MAX = 4 80 }; 81 82 /** 83 * The RenderScript context. This class controls initialization, resource management, and teardown. 84 */ 85 class RS : public android::RSC::LightRefBase<RS> { 86 87 public: 88 RS(); 89 virtual ~RS(); 90 91 /** 92 * Initializes a RenderScript context. A context must be initialized before it can be used. 93 * @param[in] flags Optional flags for this context. 94 * @return true on success 95 */ 96 bool init(uint32_t flags = 0); 97 98 /** 99 * Sets the error handler function for this context. This error handler is 100 * called whenever an error is set. 101 * 102 * @param[in] func Error handler function 103 */ 104 void setErrorHandler(ErrorHandlerFunc_t func); 105 106 /** 107 * Returns the current error handler function for this context. 108 * 109 * @return pointer to current error handler function or NULL if not set 110 */ 111 ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; } 112 113 /** 114 * Sets the message handler function for this context. This message handler 115 * is called whenever a message is sent from a RenderScript kernel. 116 * 117 * @param[in] func Message handler function 118 */ 119 void setMessageHandler(MessageHandlerFunc_t func); 120 121 /** 122 * Returns the current message handler function for this context. 123 * 124 * @return pointer to current message handler function or NULL if not set 125 */ 126 MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; } 127 128 /** 129 * Returns current status for the context. 130 * 131 * @return current error 132 */ 133 RSError getError(); 134 135 /** 136 * Waits for any currently running asynchronous operations to finish. This 137 * should only be used for performance testing and timing. 138 */ 139 void finish(); 140 141 RsContext getContext() { return mContext; } 142 void throwError(RSError error, const char *errMsg); 143 144 static dispatchTable* dispatch; 145 146 private: 147 static bool usingNative; 148 static bool initDispatch(int targetApi); 149 150 bool init(int targetApi, uint32_t flags); 151 static void * threadProc(void *); 152 153 static bool gInitialized; 154 static pthread_mutex_t gInitMutex; 155 156 pthread_t mMessageThreadId; 157 pid_t mNativeMessageThreadId; 158 bool mMessageRun; 159 160 RsDevice mDev; 161 RsContext mContext; 162 RSError mCurrentError; 163 164 ErrorHandlerFunc_t mErrorFunc; 165 MessageHandlerFunc_t mMessageFunc; 166 bool mInit; 167 168 struct { 169 sp<const Element> U8; 170 sp<const Element> U8_2; 171 sp<const Element> U8_3; 172 sp<const Element> U8_4; 173 sp<const Element> I8; 174 sp<const Element> I8_2; 175 sp<const Element> I8_3; 176 sp<const Element> I8_4; 177 sp<const Element> U16; 178 sp<const Element> U16_2; 179 sp<const Element> U16_3; 180 sp<const Element> U16_4; 181 sp<const Element> I16; 182 sp<const Element> I16_2; 183 sp<const Element> I16_3; 184 sp<const Element> I16_4; 185 sp<const Element> U32; 186 sp<const Element> U32_2; 187 sp<const Element> U32_3; 188 sp<const Element> U32_4; 189 sp<const Element> I32; 190 sp<const Element> I32_2; 191 sp<const Element> I32_3; 192 sp<const Element> I32_4; 193 sp<const Element> U64; 194 sp<const Element> U64_2; 195 sp<const Element> U64_3; 196 sp<const Element> U64_4; 197 sp<const Element> I64; 198 sp<const Element> I64_2; 199 sp<const Element> I64_3; 200 sp<const Element> I64_4; 201 sp<const Element> F32; 202 sp<const Element> F32_2; 203 sp<const Element> F32_3; 204 sp<const Element> F32_4; 205 sp<const Element> F64; 206 sp<const Element> F64_2; 207 sp<const Element> F64_3; 208 sp<const Element> F64_4; 209 sp<const Element> BOOLEAN; 210 211 sp<const Element> ELEMENT; 212 sp<const Element> TYPE; 213 sp<const Element> ALLOCATION; 214 sp<const Element> SAMPLER; 215 sp<const Element> SCRIPT; 216 sp<const Element> MESH; 217 sp<const Element> PROGRAM_FRAGMENT; 218 sp<const Element> PROGRAM_VERTEX; 219 sp<const Element> PROGRAM_RASTER; 220 sp<const Element> PROGRAM_STORE; 221 222 sp<const Element> A_8; 223 sp<const Element> RGB_565; 224 sp<const Element> RGB_888; 225 sp<const Element> RGBA_5551; 226 sp<const Element> RGBA_4444; 227 sp<const Element> RGBA_8888; 228 229 sp<const Element> YUV; 230 231 sp<const Element> MATRIX_4X4; 232 sp<const Element> MATRIX_3X3; 233 sp<const Element> MATRIX_2X2; 234 } mElements; 235 236 struct { 237 sp<const Sampler> CLAMP_NEAREST; 238 sp<const Sampler> CLAMP_LINEAR; 239 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR; 240 sp<const Sampler> WRAP_NEAREST; 241 sp<const Sampler> WRAP_LINEAR; 242 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR; 243 sp<const Sampler> MIRRORED_REPEAT_NEAREST; 244 sp<const Sampler> MIRRORED_REPEAT_LINEAR; 245 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR; 246 } mSamplers; 247 friend class Sampler; 248 friend class Element; 249 }; 250 251 /** 252 * Base class for all RenderScript objects. Not for direct use by developers. 253 */ 254 class BaseObj : public android::RSC::LightRefBase<BaseObj> { 255 public: 256 void * getID() const; 257 virtual ~BaseObj(); 258 virtual void updateFromNative(); 259 virtual bool equals(sp<const BaseObj> obj); 260 261 protected: 262 void *mID; 263 RS* mRS; 264 std::string mName; 265 266 BaseObj(void *id, sp<RS> rs); 267 void checkValid(); 268 269 static void * getObjID(sp<const BaseObj> o); 270 271 }; 272 273 /** 274 * This class provides the primary method through which data is passed to and 275 * from RenderScript kernels. An Allocation provides the backing store for a 276 * given Type. 277 * 278 * An Allocation also contains a set of usage flags that denote how the 279 * Allocation could be used. For example, an Allocation may have usage flags 280 * specifying that it can be used from a script as well as input to a 281 * Sampler. A developer must synchronize across these different usages using 282 * syncAll(int) in order to ensure that different users of the Allocation have 283 * a consistent view of memory. For example, in the case where an Allocation is 284 * used as the output of one kernel and as Sampler input in a later kernel, a 285 * developer must call syncAll(RS_ALLOCATION_USAGE_SCRIPT) prior to launching the 286 * second kernel to ensure correctness. 287 */ 288 class Allocation : public BaseObj { 289 protected: 290 sp<const Type> mType; 291 uint32_t mUsage; 292 sp<Allocation> mAdaptedAllocation; 293 294 bool mConstrainedLOD; 295 bool mConstrainedFace; 296 bool mConstrainedY; 297 bool mConstrainedZ; 298 bool mReadAllowed; 299 bool mWriteAllowed; 300 uint32_t mSelectedY; 301 uint32_t mSelectedZ; 302 uint32_t mSelectedLOD; 303 RsAllocationCubemapFace mSelectedFace; 304 305 uint32_t mCurrentDimX; 306 uint32_t mCurrentDimY; 307 uint32_t mCurrentDimZ; 308 uint32_t mCurrentCount; 309 310 void * getIDSafe() const; 311 void updateCacheInfo(sp<const Type> t); 312 313 Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage); 314 315 void validateIsInt32(); 316 void validateIsInt16(); 317 void validateIsInt8(); 318 void validateIsFloat32(); 319 void validateIsObject(); 320 321 virtual void updateFromNative(); 322 323 void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h); 324 void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff, 325 uint32_t w, uint32_t h, uint32_t d); 326 327 public: 328 329 /** 330 * Return Type for the allocation. 331 * @return pointer to underlying Type 332 */ 333 sp<const Type> getType() const { 334 return mType; 335 } 336 337 /** 338 * Propagate changes from one usage of the Allocation to other usages of the Allocation. 339 * @param[in] srcLocation source location with changes to propagate elsewhere 340 */ 341 void syncAll(RsAllocationUsageType srcLocation); 342 void ioSendOutput(); 343 void ioGetInput(); 344 345 /** 346 * Generate a mipmap chain. This is only valid if the Type of the Allocation 347 * includes mipmaps. This function will generate a complete set of mipmaps 348 * from the top level LOD and place them into the script memory space. If 349 * the Allocation is also using other memory spaces, a call to 350 * syncAll(Allocation.USAGE_SCRIPT) is required. 351 */ 352 void generateMipmaps(); 353 354 /** 355 * Copy an array into part of this Allocation. 356 * @param[in] off offset of first Element to be overwritten 357 * @param[in] count number of Elements to copy 358 * @param[in] data array from which to copy 359 */ 360 void copy1DRangeFrom(uint32_t off, size_t count, const void *data); 361 362 /** 363 * Copy part of an Allocation into part of this Allocation. 364 * @param[in] off offset of first Element to be overwritten 365 * @param[in] count number of Elements to copy 366 * @param[in] data Allocation from which to copy 367 * @param[in] dataOff offset of first Element in data to copy 368 */ 369 void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff); 370 371 /** 372 * Copy an array into part of this Allocation. 373 * @param[in] off offset of first Element to be overwritten 374 * @param[in] count number of Elements to copy 375 * @param[in] data array from which to copy 376 */ 377 void copy1DRangeTo(uint32_t off, size_t count, void *data); 378 379 /** 380 * Copy entire array to an Allocation. 381 * @param[in] data array from which to copy 382 */ 383 void copy1DFrom(const void* data); 384 385 /** 386 * Copy entire Allocation to an array. 387 * @param[in] data destination array 388 */ 389 void copy1DTo(void* data); 390 391 /** 392 * Copy from an array into a rectangular region in this Allocation. The 393 * array is assumed to be tightly packed. 394 * @param[in] xoff X offset of region to update in this Allocation 395 * @param[in] yoff Y offset of region to update in this Allocation 396 * @param[in] w Width of region to update 397 * @param[in] h Height of region to update 398 * @param[in] data Array from which to copy 399 */ 400 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, 401 const void *data); 402 403 /** 404 * Copy from this Allocation into a rectangular region in an array. The 405 * array is assumed to be tightly packed. 406 * @param[in] xoff X offset of region to copy from this Allocation 407 * @param[in] yoff Y offset of region to copy from this Allocation 408 * @param[in] w Width of region to update 409 * @param[in] h Height of region to update 410 * @param[in] data destination array 411 */ 412 void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, 413 void *data); 414 415 /** 416 * Copy from an Allocation into a rectangular region in this Allocation. 417 * @param[in] xoff X offset of region to update in this Allocation 418 * @param[in] yoff Y offset of region to update in this Allocation 419 * @param[in] w Width of region to update 420 * @param[in] h Height of region to update 421 * @param[in] data Allocation from which to copy 422 * @param[in] dataXoff X offset of region to copy from in data 423 * @param[in] dataYoff Y offset of region to copy from in data 424 */ 425 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, 426 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff); 427 428 /** 429 * Copy from a strided array into a rectangular region in this Allocation. 430 * @param[in] xoff X offset of region to update in this Allocation 431 * @param[in] yoff Y offset of region to update in this Allocation 432 * @param[in] w Width of region to update 433 * @param[in] h Height of region to update 434 * @param[in] data array from which to copy 435 * @param[in] stride stride of data in bytes 436 */ 437 void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, 438 const void *data, size_t stride); 439 440 /** 441 * Copy from a strided array into this Allocation. 442 * @param[in] data array from which to copy 443 * @param[in] stride stride of data in bytes 444 */ 445 void copy2DStridedFrom(const void *data, size_t stride); 446 447 /** 448 * Copy from a rectangular region in this Allocation into a strided array. 449 * @param[in] xoff X offset of region to update in this Allocation 450 * @param[in] yoff Y offset of region to update in this Allocation 451 * @param[in] w Width of region to update 452 * @param[in] h Height of region to update 453 * @param[in] data destination array 454 * @param[in] stride stride of data in bytes 455 */ 456 void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, 457 void *data, size_t stride); 458 459 /** 460 * Copy this Allocation into a strided array. 461 * @param[in] data destination array 462 * @param[in] stride stride of data in bytes 463 */ 464 void copy2DStridedTo(void *data, size_t stride); 465 466 467 /** 468 * Copy from an array into a 3D region in this Allocation. The 469 * array is assumed to be tightly packed. 470 * @param[in] xoff X offset of region to update in this Allocation 471 * @param[in] yoff Y offset of region to update in this Allocation 472 * @param[in] zoff Z offset of region to update in this Allocation 473 * @param[in] w Width of region to update 474 * @param[in] h Height of region to update 475 * @param[in] d Depth of region to update 476 * @param[in] data Array from which to copy 477 */ 478 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w, 479 uint32_t h, uint32_t d, const void* data); 480 481 /** 482 * Copy from an Allocation into a 3D region in this Allocation. 483 * @param[in] xoff X offset of region to update in this Allocation 484 * @param[in] yoff Y offset of region to update in this Allocation 485 * @param[in] zoff Z offset of region to update in this Allocation 486 * @param[in] w Width of region to update 487 * @param[in] h Height of region to update 488 * @param[in] d Depth of region to update 489 * @param[in] data Allocation from which to copy 490 * @param[in] dataXoff X offset of region in data to copy from 491 * @param[in] dataYoff Y offset of region in data to copy from 492 * @param[in] dataZoff Z offset of region in data to copy from 493 */ 494 void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, 495 uint32_t w, uint32_t h, uint32_t d, 496 sp<const Allocation> data, 497 uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff); 498 499 /** 500 * Creates an Allocation for use by scripts with a given Type. 501 * @param[in] rs Context to which the Allocation will belong 502 * @param[in] type Type of the Allocation 503 * @param[in] mips desired mipmap behavior for the Allocation 504 * @param[in] usage usage for the Allocation 505 * @return new Allocation 506 */ 507 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, 508 RsAllocationMipmapControl mips, uint32_t usage); 509 510 /** 511 * Creates an Allocation for use by scripts with a given Type and a backing pointer. For use 512 * with RS_ALLOCATION_USAGE_SHARED. 513 * @param[in] rs Context to which the Allocation will belong 514 * @param[in] type Type of the Allocation 515 * @param[in] mips desired mipmap behavior for the Allocation 516 * @param[in] usage usage for the Allocation 517 * @param[in] pointer existing backing store to use for this Allocation if possible 518 * @return new Allocation 519 */ 520 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, 521 RsAllocationMipmapControl mips, uint32_t usage, void * pointer); 522 523 /** 524 * Creates an Allocation for use by scripts with a given Type with no mipmaps. 525 * @param[in] rs Context to which the Allocation will belong 526 * @param[in] type Type of the Allocation 527 * @param[in] usage usage for the Allocation 528 * @return new Allocation 529 */ 530 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type, 531 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); 532 /** 533 * Creates an Allocation with a specified number of given elements. 534 * @param[in] rs Context to which the Allocation will belong 535 * @param[in] e Element used in the Allocation 536 * @param[in] count Number of elements of the Allocation 537 * @param[in] usage usage for the Allocation 538 * @return new Allocation 539 */ 540 static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count, 541 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); 542 543 /** 544 * Creates a 2D Allocation with a specified number of given elements. 545 * @param[in] rs Context to which the Allocation will belong 546 * @param[in] e Element used in the Allocation 547 * @param[in] x Width in Elements of the Allocation 548 * @param[in] y Height of the Allocation 549 * @param[in] usage usage for the Allocation 550 * @return new Allocation 551 */ 552 static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e, 553 size_t x, size_t y, 554 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT); 555 556 557 }; 558 559 /** 560 * An Element represents one item within an Allocation. An Element is roughly 561 * equivalent to a C type in a RenderScript kernel. Elements may be basic 562 * or complex. Some basic elements are: 563 564 * - A single float value (equivalent to a float in a kernel) 565 * - A four-element float vector (equivalent to a float4 in a kernel) 566 * - An unsigned 32-bit integer (equivalent to an unsigned int in a kernel) 567 * - A single signed 8-bit integer (equivalent to a char in a kernel) 568 569 * Basic Elements are comprised of a Element.DataType and a 570 * Element.DataKind. The DataType encodes C type information of an Element, 571 * while the DataKind encodes how that Element should be interpreted by a 572 * Sampler. Note that Allocation objects with DataKind USER cannot be used as 573 * input for a Sampler. In general, Allocation objects that are intended for 574 * use with a Sampler should use bitmap-derived Elements such as 575 * Element::RGBA_8888. 576 */ 577 578 579 class Element : public BaseObj { 580 public: 581 bool isComplex(); 582 583 /** 584 * Elements could be simple, such as an int or a float, or a structure with 585 * multiple sub-elements, such as a collection of floats, float2, 586 * float4. This function returns zero for simple elements or the number of 587 * sub-elements otherwise. 588 * @return number of sub-elements 589 */ 590 size_t getSubElementCount() { 591 return mVisibleElementMap.size(); 592 } 593 594 /** 595 * For complex Elements, this returns the sub-element at a given index. 596 * @param[in] index index of sub-element 597 * @return sub-element 598 */ 599 sp<const Element> getSubElement(uint32_t index); 600 601 /** 602 * For complex Elements, this returns the name of the sub-element at a given 603 * index. 604 * @param[in] index index of sub-element 605 * @return name of sub-element 606 */ 607 const char * getSubElementName(uint32_t index); 608 609 /** 610 * For complex Elements, this returns the size of the sub-element at a given 611 * index. 612 * @param[in] index index of sub-element 613 * @return size of sub-element 614 */ 615 size_t getSubElementArraySize(uint32_t index); 616 617 /** 618 * Returns the location of a sub-element within a complex Element. 619 * @param[in] index index of sub-element 620 * @return offset in bytes 621 */ 622 uint32_t getSubElementOffsetBytes(uint32_t index); 623 624 /** 625 * Returns the data type used for the Element. 626 * @return data type 627 */ 628 RsDataType getDataType() const { 629 return mType; 630 } 631 632 /** 633 * Returns the data kind used for the Element. 634 * @return data kind 635 */ 636 RsDataKind getDataKind() const { 637 return mKind; 638 } 639 640 /** 641 * Returns the size in bytes of the Element. 642 * @return size in bytes 643 */ 644 size_t getSizeBytes() const { 645 return mSizeBytes; 646 } 647 648 /** 649 * Returns the number of vector components for this Element. 650 * @return number of vector components 651 */ 652 uint32_t getVectorSize() const { 653 return mVectorSize; 654 } 655 656 /** 657 * Utility function for returning an Element containing a single bool. 658 * @param[in] rs RenderScript context 659 * @return Element 660 */ 661 static sp<const Element> BOOLEAN(sp<RS> rs); 662 /** 663 * Utility function for returning an Element containing a single unsigned char. 664 * @param[in] rs RenderScript context 665 * @return Element 666 */ 667 static sp<const Element> U8(sp<RS> rs); 668 /** 669 * Utility function for returning an Element containing a single signed char. 670 * @param[in] rs RenderScript context 671 * @return Element 672 */ 673 static sp<const Element> I8(sp<RS> rs); 674 /** 675 * Utility function for returning an Element containing a single unsigned short. 676 * @param[in] rs RenderScript context 677 * @return Element 678 */ 679 static sp<const Element> U16(sp<RS> rs); 680 /** 681 * Utility function for returning an Element containing a single signed short. 682 * @param[in] rs RenderScript context 683 * @return Element 684 */ 685 static sp<const Element> I16(sp<RS> rs); 686 /** 687 * Utility function for returning an Element containing a single unsigned int. 688 * @param[in] rs RenderScript context 689 * @return Element 690 */ 691 static sp<const Element> U32(sp<RS> rs); 692 /** 693 * Utility function for returning an Element containing a single signed int. 694 * @param[in] rs RenderScript context 695 * @return Element 696 */ 697 static sp<const Element> I32(sp<RS> rs); 698 /** 699 * Utility function for returning an Element containing a single unsigned long long. 700 * @param[in] rs RenderScript context 701 * @return Element 702 */ 703 static sp<const Element> U64(sp<RS> rs); 704 /** 705 * Utility function for returning an Element containing a single signed long long. 706 * @param[in] rs RenderScript context 707 * @return Element 708 */ 709 static sp<const Element> I64(sp<RS> rs); 710 /** 711 * Utility function for returning an Element containing a single float. 712 * @param[in] rs RenderScript context 713 * @return Element 714 */ 715 static sp<const Element> F32(sp<RS> rs); 716 /** 717 * Utility function for returning an Element containing a single double. 718 * @param[in] rs RenderScript context 719 * @return Element 720 */ 721 static sp<const Element> F64(sp<RS> rs); 722 /** 723 * Utility function for returning an Element containing a single Element. 724 * @param[in] rs RenderScript context 725 * @return Element 726 */ 727 static sp<const Element> ELEMENT(sp<RS> rs); 728 /** 729 * Utility function for returning an Element containing a single Type. 730 * @param[in] rs RenderScript context 731 * @return Element 732 */ 733 static sp<const Element> TYPE(sp<RS> rs); 734 /** 735 * Utility function for returning an Element containing a single Allocation. 736 * @param[in] rs RenderScript context 737 * @return Element 738 */ 739 static sp<const Element> ALLOCATION(sp<RS> rs); 740 /** 741 * Utility function for returning an Element containing a single Sampler. 742 * @param[in] rs RenderScript context 743 * @return Element 744 */ 745 static sp<const Element> SAMPLER(sp<RS> rs); 746 /** 747 * Utility function for returning an Element containing a single Script. 748 * @param[in] rs RenderScript context 749 * @return Element 750 */ 751 static sp<const Element> SCRIPT(sp<RS> rs); 752 /** 753 * Utility function for returning an Element containing an ALPHA_8 pixel. 754 * @param[in] rs RenderScript context 755 * @return Element 756 */ 757 static sp<const Element> A_8(sp<RS> rs); 758 /** 759 * Utility function for returning an Element containing an RGB_565 pixel. 760 * @param[in] rs RenderScript context 761 * @return Element 762 */ 763 static sp<const Element> RGB_565(sp<RS> rs); 764 /** 765 * Utility function for returning an Element containing an RGB_888 pixel. 766 * @param[in] rs RenderScript context 767 * @return Element 768 */ 769 static sp<const Element> RGB_888(sp<RS> rs); 770 /** 771 * Utility function for returning an Element containing an RGBA_5551 pixel. 772 * @param[in] rs RenderScript context 773 * @return Element 774 */ 775 static sp<const Element> RGBA_5551(sp<RS> rs); 776 /** 777 * Utility function for returning an Element containing an RGBA_4444 pixel. 778 * @param[in] rs RenderScript context 779 * @return Element 780 */ 781 static sp<const Element> RGBA_4444(sp<RS> rs); 782 /** 783 * Utility function for returning an Element containing an RGBA_8888 pixel. 784 * @param[in] rs RenderScript context 785 * @return Element 786 */ 787 static sp<const Element> RGBA_8888(sp<RS> rs); 788 789 /** 790 * Utility function for returning an Element containing a float2. 791 * @param[in] rs RenderScript context 792 * @return Element 793 */ 794 static sp<const Element> F32_2(sp<RS> rs); 795 /** 796 * Utility function for returning an Element containing a float3. 797 * @param[in] rs RenderScript context 798 * @return Element 799 */ 800 static sp<const Element> F32_3(sp<RS> rs); 801 /** 802 * Utility function for returning an Element containing a float4. 803 * @param[in] rs RenderScript context 804 * @return Element 805 */ 806 static sp<const Element> F32_4(sp<RS> rs); 807 /** 808 * Utility function for returning an Element containing a double2. 809 * @param[in] rs RenderScript context 810 * @return Element 811 */ 812 static sp<const Element> F64_2(sp<RS> rs); 813 /** 814 * Utility function for returning an Element containing a double3. 815 * @param[in] rs RenderScript context 816 * @return Element 817 */ 818 static sp<const Element> F64_3(sp<RS> rs); 819 /** 820 * Utility function for returning an Element containing a double4. 821 * @param[in] rs RenderScript context 822 * @return Element 823 */ 824 static sp<const Element> F64_4(sp<RS> rs); 825 /** 826 * Utility function for returning an Element containing a uchar2. 827 * @param[in] rs RenderScript context 828 * @return Element 829 */ 830 static sp<const Element> U8_2(sp<RS> rs); 831 /** 832 * Utility function for returning an Element containing a uchar3. 833 * @param[in] rs RenderScript context 834 * @return Element 835 */ 836 static sp<const Element> U8_3(sp<RS> rs); 837 /** 838 * Utility function for returning an Element containing a uchar4. 839 * @param[in] rs RenderScript context 840 * @return Element 841 */ 842 static sp<const Element> U8_4(sp<RS> rs); 843 /** 844 * Utility function for returning an Element containing a char2. 845 * @param[in] rs RenderScript context 846 * @return Element 847 */ 848 static sp<const Element> I8_2(sp<RS> rs); 849 /** 850 * Utility function for returning an Element containing a char3. 851 * @param[in] rs RenderScript context 852 * @return Element 853 */ 854 static sp<const Element> I8_3(sp<RS> rs); 855 /** 856 * Utility function for returning an Element containing a char4. 857 * @param[in] rs RenderScript context 858 * @return Element 859 */ 860 static sp<const Element> I8_4(sp<RS> rs); 861 /** 862 * Utility function for returning an Element containing a ushort2. 863 * @param[in] rs RenderScript context 864 * @return Element 865 */ 866 static sp<const Element> U16_2(sp<RS> rs); 867 /** 868 * Utility function for returning an Element containing a ushort3. 869 * @param[in] rs RenderScript context 870 * @return Element 871 */ 872 static sp<const Element> U16_3(sp<RS> rs); 873 /** 874 * Utility function for returning an Element containing a ushort4. 875 * @param[in] rs RenderScript context 876 * @return Element 877 */ 878 static sp<const Element> U16_4(sp<RS> rs); 879 /** 880 * Utility function for returning an Element containing a short2. 881 * @param[in] rs RenderScript context 882 * @return Element 883 */ 884 static sp<const Element> I16_2(sp<RS> rs); 885 /** 886 * Utility function for returning an Element containing a short3. 887 * @param[in] rs RenderScript context 888 * @return Element 889 */ 890 static sp<const Element> I16_3(sp<RS> rs); 891 /** 892 * Utility function for returning an Element containing a short4. 893 * @param[in] rs RenderScript context 894 * @return Element 895 */ 896 static sp<const Element> I16_4(sp<RS> rs); 897 /** 898 * Utility function for returning an Element containing a uint2. 899 * @param[in] rs RenderScript context 900 * @return Element 901 */ 902 static sp<const Element> U32_2(sp<RS> rs); 903 /** 904 * Utility function for returning an Element containing a uint3. 905 * @param[in] rs RenderScript context 906 * @return Element 907 */ 908 static sp<const Element> U32_3(sp<RS> rs); 909 /** 910 * Utility function for returning an Element containing a uint4. 911 * @param[in] rs RenderScript context 912 * @return Element 913 */ 914 static sp<const Element> U32_4(sp<RS> rs); 915 /** 916 * Utility function for returning an Element containing an int2. 917 * @param[in] rs RenderScript context 918 * @return Element 919 */ 920 static sp<const Element> I32_2(sp<RS> rs); 921 /** 922 * Utility function for returning an Element containing an int3. 923 * @param[in] rs RenderScript context 924 * @return Element 925 */ 926 static sp<const Element> I32_3(sp<RS> rs); 927 /** 928 * Utility function for returning an Element containing an int4. 929 * @param[in] rs RenderScript context 930 * @return Element 931 */ 932 static sp<const Element> I32_4(sp<RS> rs); 933 /** 934 * Utility function for returning an Element containing a ulong2. 935 * @param[in] rs RenderScript context 936 * @return Element 937 */ 938 static sp<const Element> U64_2(sp<RS> rs); 939 /** 940 * Utility function for returning an Element containing a ulong3. 941 * @param[in] rs RenderScript context 942 * @return Element 943 */ 944 static sp<const Element> U64_3(sp<RS> rs); 945 /** 946 * Utility function for returning an Element containing a ulong4. 947 * @param[in] rs RenderScript context 948 * @return Element 949 */ 950 static sp<const Element> U64_4(sp<RS> rs); 951 /** 952 * Utility function for returning an Element containing a long2. 953 * @param[in] rs RenderScript context 954 * @return Element 955 */ 956 static sp<const Element> I64_2(sp<RS> rs); 957 /** 958 * Utility function for returning an Element containing a long3. 959 * @param[in] rs RenderScript context 960 * @return Element 961 */ 962 static sp<const Element> I64_3(sp<RS> rs); 963 /** 964 * Utility function for returning an Element containing a long4. 965 * @param[in] rs RenderScript context 966 * @return Element 967 */ 968 static sp<const Element> I64_4(sp<RS> rs); 969 /** 970 * Utility function for returning an Element containing a YUV pixel. 971 * @param[in] rs RenderScript context 972 * @return Element 973 */ 974 static sp<const Element> YUV(sp<RS> rs); 975 /** 976 * Utility function for returning an Element containing an rs_matrix_4x4. 977 * @param[in] rs RenderScript context 978 * @return Element 979 */ 980 static sp<const Element> MATRIX_4X4(sp<RS> rs); 981 /** 982 * Utility function for returning an Element containing an rs_matrix_3x3. 983 * @param[in] rs RenderScript context 984 * @return Element 985 */ 986 static sp<const Element> MATRIX_3X3(sp<RS> rs); 987 /** 988 * Utility function for returning an Element containing an rs_matrix_2x2. 989 * @param[in] rs RenderScript context 990 * @return Element 991 */ 992 static sp<const Element> MATRIX_2X2(sp<RS> rs); 993 994 void updateFromNative(); 995 996 /** 997 * Create an Element with a given DataType. 998 * @param[in] rs RenderScript context 999 * @param[in] dt data type 1000 * @return Element 1001 */ 1002 static sp<const Element> createUser(sp<RS> rs, RsDataType dt); 1003 /** 1004 * Create a vector Element with the given DataType 1005 * @param[in] rs RenderScript 1006 * @param[in] dt DataType 1007 * @param[in] size vector size 1008 * @return Element 1009 */ 1010 static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size); 1011 /** 1012 * Create an Element with a given DataType and DataKind. 1013 * @param[in] rs RenderScript context 1014 * @param[in] dt DataType 1015 * @param[in] dk DataKind 1016 * @return Element 1017 */ 1018 static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk); 1019 1020 /** 1021 * Returns true if the Element can interoperate with this Element. 1022 * @param[in] e Element to compare 1023 * @return true if Elements can interoperate 1024 */ 1025 bool isCompatible(sp<const Element>e) const; 1026 1027 /** 1028 * Builder class for producing complex elements with matching field and name 1029 * pairs. The builder starts empty. The order in which elements are added is 1030 * retained for the layout in memory. 1031 */ 1032 class Builder { 1033 private: 1034 RS* mRS; 1035 std::vector<sp<Element> > mElements; 1036 std::vector<std::string> mElementNames; 1037 std::vector<uint32_t> mArraySizes; 1038 bool mSkipPadding; 1039 1040 public: 1041 Builder(sp<RS> rs); 1042 ~Builder(); 1043 void add(sp<Element> e, std::string &name, uint32_t arraySize = 1); 1044 sp<const Element> create(); 1045 }; 1046 1047 protected: 1048 Element(void *id, sp<RS> rs, 1049 std::vector<sp<Element> > &elements, 1050 std::vector<std::string> &elementNames, 1051 std::vector<uint32_t> &arraySizes); 1052 Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size); 1053 Element(sp<RS> rs); 1054 virtual ~Element(); 1055 1056 private: 1057 void updateVisibleSubElements(); 1058 1059 std::vector<sp<Element> > mElements; 1060 std::vector<std::string> mElementNames; 1061 std::vector<uint32_t> mArraySizes; 1062 std::vector<uint32_t> mVisibleElementMap; 1063 std::vector<uint32_t> mOffsetInBytes; 1064 1065 RsDataType mType; 1066 RsDataKind mKind; 1067 bool mNormalized; 1068 size_t mSizeBytes; 1069 size_t mVectorSize; 1070 }; 1071 1072 class FieldPacker { 1073 protected: 1074 unsigned char* mData; 1075 size_t mPos; 1076 size_t mLen; 1077 1078 public: 1079 FieldPacker(size_t len) 1080 : mPos(0), mLen(len) { 1081 mData = new unsigned char[len]; 1082 } 1083 1084 virtual ~FieldPacker() { 1085 delete [] mData; 1086 } 1087 1088 void align(size_t v) { 1089 if ((v & (v - 1)) != 0) { 1090 // ALOGE("Non-power-of-two alignment: %zu", v); 1091 return; 1092 } 1093 1094 while ((mPos & (v - 1)) != 0) { 1095 mData[mPos++] = 0; 1096 } 1097 } 1098 1099 void reset() { 1100 mPos = 0; 1101 } 1102 1103 void reset(size_t i) { 1104 if (i >= mLen) { 1105 // ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen); 1106 return; 1107 } 1108 mPos = i; 1109 } 1110 1111 void skip(size_t i) { 1112 size_t res = mPos + i; 1113 if (res > mLen) { 1114 // ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen); 1115 return; 1116 } 1117 mPos = res; 1118 } 1119 1120 void* getData() const { 1121 return mData; 1122 } 1123 1124 size_t getLength() const { 1125 return mLen; 1126 } 1127 1128 template <typename T> 1129 void add(T t) { 1130 align(sizeof(t)); 1131 if (mPos + sizeof(t) <= mLen) { 1132 memcpy(&mData[mPos], &t, sizeof(t)); 1133 mPos += sizeof(t); 1134 } 1135 } 1136 1137 /* 1138 void add(rs_matrix4x4 m) { 1139 for (size_t i = 0; i < 16; i++) { 1140 add(m.m[i]); 1141 } 1142 } 1143 1144 void add(rs_matrix3x3 m) { 1145 for (size_t i = 0; i < 9; i++) { 1146 add(m.m[i]); 1147 } 1148 } 1149 1150 void add(rs_matrix2x2 m) { 1151 for (size_t i = 0; i < 4; i++) { 1152 add(m.m[i]); 1153 } 1154 } 1155 */ 1156 1157 void add(sp<BaseObj> obj) { 1158 if (obj != NULL) { 1159 add((uint32_t) (uintptr_t) obj->getID()); 1160 } else { 1161 add((uint32_t) 0); 1162 } 1163 } 1164 }; 1165 1166 /** 1167 * A Type describes the Element and dimensions used for an Allocation or a 1168 * parallel operation. 1169 * 1170 * A Type always includes an Element and an X dimension. A Type may be 1171 * multidimensional, up to three dimensions. A nonzero value in the Y or Z 1172 * dimensions indicates that the dimension is present. Note that a Type with 1173 * only a given X dimension and a Type with the same X dimension but Y = 1 are 1174 * not equivalent. 1175 * 1176 * A Type also supports inclusion of level of detail (LOD) or cube map 1177 * faces. LOD and cube map faces are booleans to indicate present or not 1178 * present. 1179 * 1180 * A Type also supports YUV format information to support an Allocation in a YUV 1181 * format. The YUV formats supported are YV12 and NV21. 1182 */ 1183 class Type : public BaseObj { 1184 protected: 1185 friend class Allocation; 1186 1187 uint32_t mDimX; 1188 uint32_t mDimY; 1189 uint32_t mDimZ; 1190 RSYuvFormat mYuvFormat; 1191 bool mDimMipmaps; 1192 bool mDimFaces; 1193 size_t mElementCount; 1194 sp<const Element> mElement; 1195 1196 Type(void *id, sp<RS> rs); 1197 1198 void calcElementCount(); 1199 virtual void updateFromNative(); 1200 1201 public: 1202 1203 /** 1204 * Returns the YUV format. 1205 * @return YUV format of the Allocation 1206 */ 1207 RSYuvFormat getYuvFormat() const { 1208 return mYuvFormat; 1209 } 1210 1211 /** 1212 * Returns the Element of the Allocation. 1213 * @return YUV format of the Allocation 1214 */ 1215 sp<const Element> getElement() const { 1216 return mElement; 1217 } 1218 1219 /** 1220 * Returns the X dimension of the Allocation. 1221 * @return X dimension of the allocation 1222 */ 1223 uint32_t getX() const { 1224 return mDimX; 1225 } 1226 1227 /** 1228 * Returns the Y dimension of the Allocation. 1229 * @return Y dimension of the allocation 1230 */ 1231 uint32_t getY() const { 1232 return mDimY; 1233 } 1234 1235 /** 1236 * Returns the Z dimension of the Allocation. 1237 * @return Z dimension of the allocation 1238 */ 1239 uint32_t getZ() const { 1240 return mDimZ; 1241 } 1242 1243 /** 1244 * Returns true if the Allocation has mipmaps. 1245 * @return true if the Allocation has mipmaps 1246 */ 1247 bool hasMipmaps() const { 1248 return mDimMipmaps; 1249 } 1250 1251 /** 1252 * Returns true if the Allocation is a cube map 1253 * @return true if the Allocation is a cube map 1254 */ 1255 bool hasFaces() const { 1256 return mDimFaces; 1257 } 1258 1259 /** 1260 * Returns number of accessible Elements in the Allocation 1261 * @return number of accessible Elements in the Allocation 1262 */ 1263 size_t getCount() const { 1264 return mElementCount; 1265 } 1266 1267 /** 1268 * Returns size in bytes of all Elements in the Allocation 1269 * @return size in bytes of all Elements in the Allocation 1270 */ 1271 size_t getSizeBytes() const { 1272 return mElementCount * mElement->getSizeBytes(); 1273 } 1274 1275 /** 1276 * Creates a new Type with the given Element and dimensions. 1277 * @param[in] rs RenderScript context 1278 * @param[in] e Element 1279 * @param[in] dimX X dimension 1280 * @param[in] dimY Y dimension 1281 * @param[in] dimZ Z dimension 1282 * @return new Type 1283 */ 1284 static sp<const Type> create(sp<RS> rs, sp<const Element> e, uint32_t dimX, uint32_t dimY, uint32_t dimZ); 1285 1286 class Builder { 1287 protected: 1288 RS* mRS; 1289 uint32_t mDimX; 1290 uint32_t mDimY; 1291 uint32_t mDimZ; 1292 RSYuvFormat mYuvFormat; 1293 bool mDimMipmaps; 1294 bool mDimFaces; 1295 sp<const Element> mElement; 1296 1297 public: 1298 Builder(sp<RS> rs, sp<const Element> e); 1299 1300 void setX(uint32_t value); 1301 void setY(uint32_t value); 1302 void setZ(uint32_t value); 1303 void setYuvFormat(RSYuvFormat format); 1304 void setMipmaps(bool value); 1305 void setFaces(bool value); 1306 sp<const Type> create(); 1307 }; 1308 1309 }; 1310 1311 /** 1312 * The parent class for all executable Scripts. This should not be used by applications. 1313 */ 1314 class Script : public BaseObj { 1315 private: 1316 1317 protected: 1318 Script(void *id, sp<RS> rs); 1319 void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out, 1320 const void *v, size_t) const; 1321 void bindAllocation(sp<Allocation> va, uint32_t slot) const; 1322 void setVar(uint32_t index, const void *, size_t len) const; 1323 void setVar(uint32_t index, sp<const BaseObj> o) const; 1324 void invoke(uint32_t slot, const void *v, size_t len) const; 1325 1326 1327 void invoke(uint32_t slot) const { 1328 invoke(slot, NULL, 0); 1329 } 1330 void setVar(uint32_t index, float v) const { 1331 setVar(index, &v, sizeof(v)); 1332 } 1333 void setVar(uint32_t index, double v) const { 1334 setVar(index, &v, sizeof(v)); 1335 } 1336 void setVar(uint32_t index, int32_t v) const { 1337 setVar(index, &v, sizeof(v)); 1338 } 1339 void setVar(uint32_t index, int64_t v) const { 1340 setVar(index, &v, sizeof(v)); 1341 } 1342 void setVar(uint32_t index, bool v) const { 1343 setVar(index, &v, sizeof(v)); 1344 } 1345 1346 public: 1347 class FieldBase { 1348 protected: 1349 sp<const Element> mElement; 1350 sp<Allocation> mAllocation; 1351 1352 void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0); 1353 1354 public: 1355 sp<const Element> getElement() { 1356 return mElement; 1357 } 1358 1359 sp<const Type> getType() { 1360 return mAllocation->getType(); 1361 } 1362 1363 sp<const Allocation> getAllocation() { 1364 return mAllocation; 1365 } 1366 1367 //void updateAllocation(); 1368 }; 1369 }; 1370 1371 /** 1372 * The parent class for all user-defined scripts. This is intended to be used by auto-generated code only. 1373 */ 1374 class ScriptC : public Script { 1375 protected: 1376 ScriptC(sp<RS> rs, 1377 const void *codeTxt, size_t codeLength, 1378 const char *cachedName, size_t cachedNameLength, 1379 const char *cacheDir, size_t cacheDirLength); 1380 1381 }; 1382 1383 /** 1384 * The parent class for all script intrinsics. Intrinsics provide highly optimized implementations of 1385 * basic functions. This is not intended to be used directly. 1386 */ 1387 class ScriptIntrinsic : public Script { 1388 protected: 1389 sp<const Element> mElement; 1390 ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e); 1391 virtual ~ScriptIntrinsic(); 1392 }; 1393 1394 /** 1395 * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The incoming 1396 * r,g,b values are use as normalized x,y,z coordinates into a 3D 1397 * allocation. The 8 nearest values are sampled and linearly interpolated. The 1398 * result is placed in the output. 1399 */ 1400 class ScriptIntrinsic3DLUT : public ScriptIntrinsic { 1401 private: 1402 ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e); 1403 public: 1404 /** 1405 * Supported Element types are U8_4. Default lookup table is identity. 1406 * @param[in] rs RenderScript context 1407 * @param[in] e Element 1408 * @return new ScriptIntrinsic 1409 */ 1410 static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e); 1411 1412 /** 1413 * Launch the intrinsic. 1414 * @param[in] ain input Allocation 1415 * @param[in] aout output Allocation 1416 */ 1417 void forEach(sp<Allocation> ain, sp<Allocation> aout); 1418 1419 /** 1420 * Sets the lookup table. The lookup table must use the same Element as the 1421 * intrinsic. 1422 * @param[in] lut new lookup table 1423 */ 1424 void setLUT(sp<Allocation> lut); 1425 }; 1426 1427 /** 1428 * Intrinsic kernel for blending two Allocations. 1429 */ 1430 class ScriptIntrinsicBlend : public ScriptIntrinsic { 1431 private: 1432 ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e); 1433 public: 1434 /** 1435 * Supported Element types are U8_4. 1436 * @param[in] rs RenderScript context 1437 * @param[in] e Element 1438 * @return new ScriptIntrinsicBlend 1439 */ 1440 static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e); 1441 /** 1442 * sets dst = {0, 0, 0, 0} 1443 * @param[in] in input Allocation 1444 * @param[in] out output Allocation 1445 */ 1446 void forEachClear(sp<Allocation> in, sp<Allocation> out); 1447 /** 1448 * Sets dst = src 1449 * @param[in] in input Allocation 1450 * @param[in] out output Allocation 1451 */ 1452 void forEachSrc(sp<Allocation> in, sp<Allocation> out); 1453 /** 1454 * Sets dst = dst (NOP) 1455 * @param[in] in input Allocation 1456 * @param[in] out output Allocation 1457 */ 1458 void forEachDst(sp<Allocation> in, sp<Allocation> out); 1459 /** 1460 * Sets dst = src + dst * (1.0 - src.a) 1461 * @param[in] in input Allocation 1462 * @param[in] out output Allocation 1463 */ 1464 void forEachSrcOver(sp<Allocation> in, sp<Allocation> out); 1465 /** 1466 * Sets dst = dst + src * (1.0 - dst.a) 1467 * @param[in] in input Allocation 1468 * @param[in] out output Allocation 1469 */ 1470 void forEachDstOver(sp<Allocation> in, sp<Allocation> out); 1471 /** 1472 * Sets dst = src * dst.a 1473 * @param[in] in input Allocation 1474 * @param[in] out output Allocation 1475 */ 1476 void forEachSrcIn(sp<Allocation> in, sp<Allocation> out); 1477 /** 1478 * Sets dst = dst * src.a 1479 * @param[in] in input Allocation 1480 * @param[in] out output Allocation 1481 */ 1482 void forEachDstIn(sp<Allocation> in, sp<Allocation> out); 1483 /** 1484 * Sets dst = src * (1.0 - dst.a) 1485 * @param[in] in input Allocation 1486 * @param[in] out output Allocation 1487 */ 1488 void forEachSrcOut(sp<Allocation> in, sp<Allocation> out); 1489 /** 1490 * Sets dst = dst * (1.0 - src.a) 1491 * @param[in] in input Allocation 1492 * @param[in] out output Allocation 1493 */ 1494 void forEachDstOut(sp<Allocation> in, sp<Allocation> out); 1495 /** 1496 * Sets dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb 1497 * @param[in] in input Allocation 1498 * @param[in] out output Allocation 1499 */ 1500 void forEachSrcAtop(sp<Allocation> in, sp<Allocation> out); 1501 /** 1502 * Sets dst.rgb = dst.rgb * src.a + (1.0 - dst.a) * src.rgb 1503 * @param[in] in input Allocation 1504 * @param[in] out output Allocation 1505 */ 1506 void forEachDstAtop(sp<Allocation> in, sp<Allocation> out); 1507 /** 1508 * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a} 1509 * @param[in] in input Allocation 1510 * @param[in] out output Allocation 1511 */ 1512 void forEachXor(sp<Allocation> in, sp<Allocation> out); 1513 /** 1514 * Sets dst = src * dst 1515 * @param[in] in input Allocation 1516 * @param[in] out output Allocation 1517 */ 1518 void forEachMultiply(sp<Allocation> in, sp<Allocation> out); 1519 /** 1520 * Sets dst = min(src + dst, 1.0) 1521 * @param[in] in input Allocation 1522 * @param[in] out output Allocation 1523 */ 1524 void forEachAdd(sp<Allocation> in, sp<Allocation> out); 1525 /** 1526 * Sets dst = max(dst - src, 0.0) 1527 * @param[in] in input Allocation 1528 * @param[in] out output Allocation 1529 */ 1530 void forEachSubtract(sp<Allocation> in, sp<Allocation> out); 1531 }; 1532 1533 /** 1534 * Intrinsic Gausian blur filter. Applies a Gaussian blur of the specified 1535 * radius to all elements of an Allocation. 1536 */ 1537 class ScriptIntrinsicBlur : public ScriptIntrinsic { 1538 private: 1539 ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e); 1540 public: 1541 /** 1542 * Supported Element types are U8 and U8_4. 1543 * @param[in] rs RenderScript context 1544 * @param[in] e Element 1545 * @return new ScriptIntrinsicBlur 1546 */ 1547 static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e); 1548 /** 1549 * Sets the input of the blur. 1550 * @param[in] in input Allocation 1551 */ 1552 void setInput(sp<Allocation> in); 1553 /** 1554 * Runs the intrinsic. 1555 * @param[in] output Allocation 1556 */ 1557 void forEach(sp<Allocation> out); 1558 /** 1559 * Sets the radius of the blur. The supported range is 0 < radius <= 25. 1560 * @param[in] radius radius of the blur 1561 */ 1562 void setRadius(float radius); 1563 }; 1564 1565 /** 1566 * Intrinsic for applying a color matrix to allocations. This has the 1567 * same effect as loading each element and converting it to a 1568 * F32_N, multiplying the result by the 4x4 color matrix 1569 * as performed by rsMatrixMultiply() and writing it to the output 1570 * after conversion back to U8_N or F32_N. 1571 */ 1572 class ScriptIntrinsicColorMatrix : public ScriptIntrinsic { 1573 private: 1574 ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e); 1575 public: 1576 /** 1577 * Creates a new intrinsic. 1578 * @param[in] rs RenderScript context 1579 * @return new ScriptIntrinsicColorMatrix 1580 */ 1581 static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs); 1582 /** 1583 * Applies the color matrix. Supported types are U8 and F32 with 1584 * vector lengths between 1 and 4. 1585 * @param[in] in input Allocation 1586 * @param[out] out output Allocation 1587 */ 1588 void forEach(sp<Allocation> in, sp<Allocation> out); 1589 /** 1590 * Set the value to be added after the color matrix has been 1591 * applied. The default value is {0, 0, 0, 0}. 1592 * @param[in] add float[4] of values 1593 */ 1594 void setAdd(float* add); 1595 1596 /** 1597 * Set the color matrix which will be applied to each cell of the 1598 * image. The alpha channel will be copied. 1599 * 1600 * @param[in] m float[9] of values 1601 */ 1602 void setColorMatrix3(float* m); 1603 /** 1604 * Set the color matrix which will be applied to each cell of the 1605 * image. 1606 * 1607 * @param[in] m float[16] of values 1608 */ 1609 void setColorMatrix4(float* m); 1610 /** 1611 * Set a color matrix to convert from RGB to luminance. The alpha 1612 * channel will be a copy. 1613 */ 1614 void setGreyscale(); 1615 /** 1616 * Set the matrix to convert from RGB to YUV with a direct copy of 1617 * the 4th channel. 1618 */ 1619 void setRGBtoYUV(); 1620 /** 1621 * Set the matrix to convert from YUV to RGB with a direct copy of 1622 * the 4th channel. 1623 */ 1624 void setYUVtoRGB(); 1625 }; 1626 1627 /** 1628 * Intrinsic for applying a 3x3 convolve to an allocation. 1629 */ 1630 class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic { 1631 private: 1632 ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e); 1633 public: 1634 /** 1635 * Supported types U8 and F32 with vector lengths between 1 and 1636 * 4. The default convolution kernel is the identity. 1637 * @param[in] rs RenderScript context 1638 * @param[in] e Element 1639 * @return new ScriptIntrinsicConvolve3x3 1640 */ 1641 static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e); 1642 /** 1643 * Sets input for intrinsic. 1644 * @param[in] in input Allocation 1645 */ 1646 void setInput(sp<Allocation> in); 1647 /** 1648 * Launches the intrinsic. 1649 * @param[in] out output Allocation 1650 */ 1651 void forEach(sp<Allocation> out); 1652 /** 1653 * Sets convolution kernel. 1654 * @param[in] v float[9] of values 1655 */ 1656 void setCoefficients(float* v); 1657 }; 1658 1659 /** 1660 * Intrinsic for applying a 5x5 convolve to an allocation. 1661 */ 1662 class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic { 1663 private: 1664 ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e); 1665 public: 1666 /** 1667 * Supported types U8 and F32 with vector lengths between 1 and 1668 * 4. The default convolution kernel is the identity. 1669 * @param[in] rs RenderScript context 1670 * @param[in] e Element 1671 * @return new ScriptIntrinsicConvolve5x5 1672 */ 1673 static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e); 1674 /** 1675 * Sets input for intrinsic. 1676 * @param[in] in input Allocation 1677 */ 1678 void setInput(sp<Allocation> in); 1679 /** 1680 * Launches the intrinsic. 1681 * @param[in] out output Allocation 1682 */ 1683 void forEach(sp<Allocation> out); 1684 /** 1685 * Sets convolution kernel. 1686 * @param[in] v float[25] of values 1687 */ 1688 void setCoefficients(float* v); 1689 }; 1690 1691 /** 1692 * Intrinsic for computing a histogram. 1693 */ 1694 class ScriptIntrinsicHistogram : public ScriptIntrinsic { 1695 private: 1696 ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e); 1697 sp<Allocation> mOut; 1698 public: 1699 /** 1700 * Create an intrinsic for calculating the histogram of an uchar 1701 * or uchar4 image. 1702 * 1703 * Supported elements types are U8_4, U8_3, U8_2, and U8. 1704 * 1705 * @param[in] rs The RenderScript context 1706 * @param[in] e Element type for inputs 1707 * 1708 * @return ScriptIntrinsicHistogram 1709 */ 1710 static sp<ScriptIntrinsicHistogram> create(sp<RS> rs); 1711 /** 1712 * Set the output of the histogram. 32 bit integer types are 1713 * supported. 1714 * 1715 * @param[in] aout The output allocation 1716 */ 1717 void setOutput(sp<Allocation> aout); 1718 /** 1719 * Set the coefficients used for the dot product calculation. The 1720 * default is {0.299f, 0.587f, 0.114f, 0.f}. 1721 * 1722 * Coefficients must be >= 0 and sum to 1.0 or less. 1723 * 1724 * @param[in] r Red coefficient 1725 * @param[in] g Green coefficient 1726 * @param[in] b Blue coefficient 1727 * @param[in] a Alpha coefficient 1728 */ 1729 void setDotCoefficients(float r, float g, float b, float a); 1730 /** 1731 * Process an input buffer and place the histogram into the output 1732 * allocation. The output allocation may be a narrower vector size 1733 * than the input. In this case the vector size of the output is 1734 * used to determine how many of the input channels are used in 1735 * the computation. This is useful if you have an RGBA input 1736 * buffer but only want the histogram for RGB. 1737 * 1738 * 1D and 2D input allocations are supported. 1739 * 1740 * @param[in] ain The input image 1741 */ 1742 void forEach(sp<Allocation> ain); 1743 /** 1744 * Process an input buffer and place the histogram into the output 1745 * allocation. The dot product of the input channel and the 1746 * coefficients from 'setDotCoefficients' are used to calculate 1747 * the output values. 1748 * 1749 * 1D and 2D input allocations are supported. 1750 * 1751 * @param ain The input image 1752 */ 1753 void forEach_dot(sp<Allocation> ain); 1754 }; 1755 1756 /** 1757 * Intrinsic for applying a per-channel lookup table. Each channel of 1758 * the input has an independant lookup table. The tables are 256 1759 * entries in size and can cover the full value range of U8_4. 1760 **/ 1761 class ScriptIntrinsicLUT : public ScriptIntrinsic { 1762 private: 1763 sp<Allocation> LUT; 1764 bool mDirty; 1765 unsigned char mCache[1024]; 1766 void setTable(unsigned int offset, unsigned char base, unsigned int length, unsigned char* lutValues); 1767 ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e); 1768 1769 public: 1770 /** 1771 * Supported elements types are U8_4. 1772 * 1773 * The defaults tables are identity. 1774 * 1775 * @param[in] rs The RenderScript context 1776 * @param[in] e Element type for intputs and outputs 1777 * 1778 * @return ScriptIntrinsicLUT 1779 */ 1780 static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e); 1781 /** 1782 * Invoke the kernel and apply the lookup to each cell of ain and 1783 * copy to aout. 1784 * 1785 * @param[in] ain Input allocation 1786 * @param[in] aout Output allocation 1787 */ 1788 void forEach(sp<Allocation> ain, sp<Allocation> aout); 1789 /** 1790 * Sets entries in LUT for the red channel. 1791 * @param[in] base base of region to update 1792 * @param[in] length length of region to update 1793 * @param[in] lutValues LUT values to use 1794 */ 1795 void setRed(unsigned char base, unsigned int length, unsigned char* lutValues); 1796 /** 1797 * Sets entries in LUT for the green channel. 1798 * @param[in] base base of region to update 1799 * @param[in] length length of region to update 1800 * @param[in] lutValues LUT values to use 1801 */ 1802 void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues); 1803 /** 1804 * Sets entries in LUT for the blue channel. 1805 * @param[in] base base of region to update 1806 * @param[in] length length of region to update 1807 * @param[in] lutValues LUT values to use 1808 */ 1809 void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues); 1810 /** 1811 * Sets entries in LUT for the alpha channel. 1812 * @param[in] base base of region to update 1813 * @param[in] length length of region to update 1814 * @param[in] lutValues LUT values to use 1815 */ 1816 void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues); 1817 virtual ~ScriptIntrinsicLUT(); 1818 }; 1819 1820 /** 1821 * Intrinsic for converting an Android YUV buffer to RGB. 1822 * 1823 * The input allocation should be supplied in a supported YUV format 1824 * as a YUV element Allocation. The output is RGBA; the alpha channel 1825 * will be set to 255. 1826 */ 1827 class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic { 1828 private: 1829 ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e); 1830 public: 1831 /** 1832 * Create an intrinsic for converting YUV to RGB. 1833 * 1834 * Supported elements types are U8_4. 1835 * 1836 * @param[in] rs The RenderScript context 1837 * @param[in] e Element type for output 1838 * 1839 * @return ScriptIntrinsicYuvToRGB 1840 */ 1841 static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e); 1842 /** 1843 * Set the input YUV allocation. 1844 * 1845 * @param[in] ain The input allocation. 1846 */ 1847 void setInput(sp<Allocation> in); 1848 1849 /** 1850 * Convert the image to RGB. 1851 * 1852 * @param[in] aout Output allocation. Must match creation element 1853 * type. 1854 */ 1855 void forEach(sp<Allocation> out); 1856 1857 }; 1858 1859 /** 1860 * Sampler object that defines how Allocations can be read as textures 1861 * within a kernel. Samplers are used in conjunction with the rsSample 1862 * runtime function to return values from normalized coordinates. 1863 * 1864 * Any Allocation used with a Sampler must have been created with 1865 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; using a Sampler on an 1866 * Allocation that was not created with 1867 * RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE is undefined. 1868 **/ 1869 class Sampler : public BaseObj { 1870 private: 1871 Sampler(sp<RS> rs, void* id); 1872 RsSamplerValue mMin; 1873 RsSamplerValue mMag; 1874 RsSamplerValue mWrapS; 1875 RsSamplerValue mWrapT; 1876 RsSamplerValue mWrapR; 1877 float mAniso; 1878 1879 public: 1880 /** 1881 * Creates a non-standard Sampler. 1882 * @param[in] rs RenderScript context 1883 * @param[in] min minification 1884 * @param[in] mag magnification 1885 * @param[in] wrapS S wrapping mode 1886 * @param[in] wrapT T wrapping mode 1887 * @param[in] anisotropy anisotropy setting 1888 */ 1889 static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy); 1890 1891 /** 1892 * @return minification setting for the sampler 1893 */ 1894 RsSamplerValue getMinification(); 1895 /** 1896 * @return magnification setting for the sampler 1897 */ 1898 RsSamplerValue getMagnification(); 1899 /** 1900 * @return S wrapping mode for the sampler 1901 */ 1902 RsSamplerValue getWrapS(); 1903 /** 1904 * @return T wrapping mode for the sampler 1905 */ 1906 RsSamplerValue getWrapT(); 1907 /** 1908 * @return anisotropy setting for the sampler 1909 */ 1910 float getAnisotropy(); 1911 1912 /** 1913 * Retrieve a sampler with min and mag set to nearest and wrap modes set to 1914 * clamp. 1915 * 1916 * @param rs Context to which the sampler will belong. 1917 * 1918 * @return Sampler 1919 */ 1920 sp<const Sampler> CLAMP_NEAREST(sp<RS> rs); 1921 /** 1922 * Retrieve a sampler with min and mag set to linear and wrap modes set to 1923 * clamp. 1924 * 1925 * @param rs Context to which the sampler will belong. 1926 * 1927 * @return Sampler 1928 */ 1929 sp<const Sampler> CLAMP_LINEAR(sp<RS> rs); 1930 /** 1931 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and 1932 * wrap modes set to clamp. 1933 * 1934 * @param rs Context to which the sampler will belong. 1935 * 1936 * @return Sampler 1937 */ 1938 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs); 1939 /** 1940 * Retrieve a sampler with min and mag set to nearest and wrap modes set to 1941 * wrap. 1942 * 1943 * @param rs Context to which the sampler will belong. 1944 * 1945 * @return Sampler 1946 */ 1947 sp<const Sampler> WRAP_NEAREST(sp<RS> rs); 1948 /** 1949 * Retrieve a sampler with min and mag set to linear and wrap modes set to 1950 * wrap. 1951 * 1952 * @param rs Context to which the sampler will belong. 1953 * 1954 * @return Sampler 1955 */ 1956 sp<const Sampler> WRAP_LINEAR(sp<RS> rs); 1957 /** 1958 * Retrieve a sampler with mag set to linear, min linear mipmap linear, and 1959 * wrap modes set to wrap. 1960 * 1961 * @param rs Context to which the sampler will belong. 1962 * 1963 * @return Sampler 1964 */ 1965 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs); 1966 /** 1967 * Retrieve a sampler with min and mag set to nearest and wrap modes set to 1968 * mirrored repeat. 1969 * 1970 * @param rs Context to which the sampler will belong. 1971 * 1972 * @return Sampler 1973 */ 1974 sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs); 1975 /** 1976 * Retrieve a sampler with min and mag set to linear and wrap modes set to 1977 * mirrored repeat. 1978 * 1979 * @param rs Context to which the sampler will belong. 1980 * 1981 * @return Sampler 1982 */ 1983 sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs); 1984 /** 1985 * Retrieve a sampler with min and mag set to linear and wrap modes set to 1986 * mirrored repeat. 1987 * 1988 * @param rs Context to which the sampler will belong. 1989 * 1990 * @return Sampler 1991 */ 1992 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs); 1993 1994 }; 1995 1996 class Byte2 { 1997 public: 1998 int8_t x, y; 1999 2000 Byte2(int8_t initX, int8_t initY) 2001 : x(initX), y(initY) {} 2002 Byte2() : x(0), y(0) {} 2003 }; 2004 2005 class Byte3 { 2006 public: 2007 int8_t x, y, z; 2008 2009 Byte3(int8_t initX, int8_t initY, int8_t initZ) 2010 : x(initX), y(initY), z(initZ) {} 2011 Byte3() : x(0), y(0), z(0) {} 2012 }; 2013 2014 class Byte4 { 2015 public: 2016 int8_t x, y, z, w; 2017 2018 Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW) 2019 : x(initX), y(initY), z(initZ), w(initW) {} 2020 Byte4() : x(0), y(0), z(0), w(0) {} 2021 }; 2022 2023 class UByte2 { 2024 public: 2025 uint8_t x, y; 2026 2027 UByte2(uint8_t initX, uint8_t initY) 2028 : x(initX), y(initY) {} 2029 UByte2() : x(0), y(0) {} 2030 }; 2031 2032 class UByte3 { 2033 public: 2034 uint8_t x, y, z; 2035 2036 UByte3(uint8_t initX, uint8_t initY, uint8_t initZ) 2037 : x(initX), y(initY), z(initZ) {} 2038 UByte3() : x(0), y(0), z(0) {} 2039 }; 2040 2041 class UByte4 { 2042 public: 2043 uint8_t x, y, z, w; 2044 2045 UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW) 2046 : x(initX), y(initY), z(initZ), w(initW) {} 2047 UByte4() : x(0), y(0), z(0), w(0) {} 2048 }; 2049 2050 class Short2 { 2051 public: 2052 short x, y; 2053 2054 Short2(short initX, short initY) 2055 : x(initX), y(initY) {} 2056 Short2() : x(0), y(0) {} 2057 }; 2058 2059 class Short3 { 2060 public: 2061 short x, y, z; 2062 2063 Short3(short initX, short initY, short initZ) 2064 : x(initX), y(initY), z(initZ) {} 2065 Short3() : x(0), y(0), z(0) {} 2066 }; 2067 2068 class Short4 { 2069 public: 2070 short x, y, z, w; 2071 2072 Short4(short initX, short initY, short initZ, short initW) 2073 : x(initX), y(initY), z(initZ), w(initW) {} 2074 Short4() : x(0), y(0), z(0), w(0) {} 2075 }; 2076 2077 class UShort2 { 2078 public: 2079 uint16_t x, y; 2080 2081 UShort2(uint16_t initX, uint16_t initY) 2082 : x(initX), y(initY) {} 2083 UShort2() : x(0), y(0) {} 2084 }; 2085 2086 class UShort3 { 2087 public: 2088 uint16_t x, y, z; 2089 2090 UShort3(uint16_t initX, uint16_t initY, uint16_t initZ) 2091 : x(initX), y(initY), z(initZ) {} 2092 UShort3() : x(0), y(0), z(0) {} 2093 }; 2094 2095 class UShort4 { 2096 public: 2097 uint16_t x, y, z, w; 2098 2099 UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW) 2100 : x(initX), y(initY), z(initZ), w(initW) {} 2101 UShort4() : x(0), y(0), z(0), w(0) {} 2102 }; 2103 2104 class Int2 { 2105 public: 2106 int x, y; 2107 2108 Int2(int initX, int initY) 2109 : x(initX), y(initY) {} 2110 Int2() : x(0), y(0) {} 2111 }; 2112 2113 class Int3 { 2114 public: 2115 int x, y, z; 2116 2117 Int3(int initX, int initY, int initZ) 2118 : x(initX), y(initY), z(initZ) {} 2119 Int3() : x(0), y(0), z(0) {} 2120 }; 2121 2122 class Int4 { 2123 public: 2124 int x, y, z, w; 2125 2126 Int4(int initX, int initY, int initZ, int initW) 2127 : x(initX), y(initY), z(initZ), w(initW) {} 2128 Int4() : x(0), y(0), z(0), w(0) {} 2129 }; 2130 2131 class UInt2 { 2132 public: 2133 uint32_t x, y; 2134 2135 UInt2(uint32_t initX, uint32_t initY) 2136 : x(initX), y(initY) {} 2137 UInt2() : x(0), y(0) {} 2138 }; 2139 2140 class UInt3 { 2141 public: 2142 uint32_t x, y, z; 2143 2144 UInt3(uint32_t initX, uint32_t initY, uint32_t initZ) 2145 : x(initX), y(initY), z(initZ) {} 2146 UInt3() : x(0), y(0), z(0) {} 2147 }; 2148 2149 class UInt4 { 2150 public: 2151 uint32_t x, y, z, w; 2152 2153 UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW) 2154 : x(initX), y(initY), z(initZ), w(initW) {} 2155 UInt4() : x(0), y(0), z(0), w(0) {} 2156 }; 2157 2158 class Long2 { 2159 public: 2160 int64_t x, y; 2161 2162 Long2(int64_t initX, int64_t initY) 2163 : x(initX), y(initY) {} 2164 Long2() : x(0), y(0) {} 2165 }; 2166 2167 class Long3 { 2168 public: 2169 int64_t x, y, z; 2170 2171 Long3(int64_t initX, int64_t initY, int64_t initZ) 2172 : x(initX), y(initY), z(initZ) {} 2173 Long3() : x(0), y(0), z(0) {} 2174 }; 2175 2176 class Long4 { 2177 public: 2178 int64_t x, y, z, w; 2179 2180 Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW) 2181 : x(initX), y(initY), z(initZ), w(initW) {} 2182 Long4() : x(0), y(0), z(0), w(0) {} 2183 }; 2184 2185 class ULong2 { 2186 public: 2187 uint64_t x, y; 2188 2189 ULong2(uint64_t initX, uint64_t initY) 2190 : x(initX), y(initY) {} 2191 ULong2() : x(0), y(0) {} 2192 }; 2193 2194 class ULong3 { 2195 public: 2196 uint64_t x, y, z; 2197 2198 ULong3(uint64_t initX, uint64_t initY, uint64_t initZ) 2199 : x(initX), y(initY), z(initZ) {} 2200 ULong3() : x(0), y(0), z(0) {} 2201 }; 2202 2203 class ULong4 { 2204 public: 2205 uint64_t x, y, z, w; 2206 2207 ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW) 2208 : x(initX), y(initY), z(initZ), w(initW) {} 2209 ULong4() : x(0), y(0), z(0), w(0) {} 2210 }; 2211 2212 class Float2 { 2213 public: 2214 float x, y; 2215 2216 Float2(float initX, float initY) 2217 : x(initX), y(initY) {} 2218 Float2() : x(0), y(0) {} 2219 }; 2220 2221 class Float3 { 2222 public: 2223 float x, y, z; 2224 2225 Float3(float initX, float initY, float initZ) 2226 : x(initX), y(initY), z(initZ) {} 2227 Float3() : x(0.f), y(0.f), z(0.f) {} 2228 }; 2229 2230 class Float4 { 2231 public: 2232 float x, y, z, w; 2233 2234 Float4(float initX, float initY, float initZ, float initW) 2235 : x(initX), y(initY), z(initZ), w(initW) {} 2236 Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {} 2237 }; 2238 2239 class Double2 { 2240 public: 2241 double x, y; 2242 2243 Double2(double initX, double initY) 2244 : x(initX), y(initY) {} 2245 Double2() : x(0), y(0) {} 2246 }; 2247 2248 class Double3 { 2249 public: 2250 double x, y, z; 2251 2252 Double3(double initX, double initY, double initZ) 2253 : x(initX), y(initY), z(initZ) {} 2254 Double3() : x(0), y(0), z(0) {} 2255 }; 2256 2257 class Double4 { 2258 public: 2259 double x, y, z, w; 2260 2261 Double4(double initX, double initY, double initZ, double initW) 2262 : x(initX), y(initY), z(initZ), w(initW) {} 2263 Double4() : x(0), y(0), z(0), w(0) {} 2264 }; 2265 2266 } 2267 2268 } 2269 2270 #endif 2271