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