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/** @file rs_types.rsh 18 * 19 * Define the standard RenderScript types 20 * 21 * Integers 22 * 8 bit: char, int8_t 23 * 16 bit: short, int16_t 24 * 32 bit: int, in32_t 25 * 64 bit: long, long long, int64_t 26 * 27 * Unsigned Integers 28 * 8 bit: uchar, uint8_t 29 * 16 bit: ushort, uint16_t 30 * 32 bit: uint, uint32_t 31 * 64 bit: ulong, uint64_t 32 * 33 * Floating point 34 * 32 bit: float 35 * 64 bit: double 36 * 37 * Vectors of length 2, 3, and 4 are supported for all the types above. 38 * 39 */ 40 41#ifndef __RS_TYPES_RSH__ 42#define __RS_TYPES_RSH__ 43 44/* Constants */ 45#define M_E 2.718281828459045235360287471352662498f /* e */ 46#define M_LOG2E 1.442695040888963407359924681001892137f /* log_2 e */ 47#define M_LOG10E 0.434294481903251827651128918916605082f /* log_10 e */ 48#define M_LN2 0.693147180559945309417232121458176568f /* log_e 2 */ 49#define M_LN10 2.302585092994045684017991454684364208f /* log_e 10 */ 50#define M_PI 3.141592653589793238462643383279502884f /* pi */ 51#define M_PI_2 1.570796326794896619231321691639751442f /* pi/2 */ 52#define M_PI_4 0.785398163397448309615660845819875721f /* pi/4 */ 53#define M_1_PI 0.318309886183790671537767526745028724f /* 1/pi */ 54#define M_2_PIl 0.636619772367581343075535053490057448f /* 2/pi */ 55#define M_2_SQRTPI 1.128379167095512573896158903121545172f /* 2/sqrt(pi) */ 56#define M_SQRT2 1.414213562373095048801688724209698079f /* sqrt(2) */ 57#define M_SQRT1_2 0.707106781186547524400844362104849039f /* 1/sqrt(2) */ 58 59#include "stdbool.h" 60/** 61 * 8 bit integer type 62 */ 63typedef char int8_t; 64/** 65 * 16 bit integer type 66 */ 67typedef short int16_t; 68/** 69 * 32 bit integer type 70 */ 71typedef int int32_t; 72/** 73 * 64 bit integer type 74 */ 75#if (defined(RS_VERSION) && (RS_VERSION >= 21)) 76 typedef long int64_t; 77#else 78 typedef long long int64_t; 79#endif 80/** 81 * 8 bit unsigned integer type 82 */ 83typedef unsigned char uint8_t; 84/** 85 * 16 bit unsigned integer type 86 */ 87typedef unsigned short uint16_t; 88/** 89 * 32 bit unsigned integer type 90 */ 91typedef unsigned int uint32_t; 92/** 93 * 64 bit unsigned integer type 94 */ 95#if (defined(RS_VERSION) && (RS_VERSION >= 21)) 96 typedef unsigned long uint64_t; 97#else 98 typedef unsigned long long uint64_t; 99#endif 100/** 101 * 8 bit unsigned integer type 102 */ 103typedef uint8_t uchar; 104/** 105 * 16 bit unsigned integer type 106 */ 107typedef uint16_t ushort; 108/** 109 * 32 bit unsigned integer type 110 */ 111typedef uint32_t uint; 112/** 113 * Typedef for unsigned long (use for 64-bit unsigned integers) 114 */ 115typedef uint64_t ulong; 116/** 117 * Typedef for size_t 118 */ 119#ifndef __LP64__ 120typedef uint32_t size_t; 121typedef int32_t ssize_t; 122#else 123typedef uint64_t size_t; 124typedef int64_t ssize_t; 125#endif 126 127#ifndef __LP64__ 128#define RS_BASE_OBJ typedef struct { const int* const p; } __attribute__((packed, aligned(4))) 129#else 130#define RS_BASE_OBJ typedef struct { const long* const p; const long* const r; const long* const v1; const long* const v2; } 131#endif 132 133/** 134 * \brief Opaque handle to a RenderScript element. 135 * 136 * See: android.renderscript.Element 137 */ 138RS_BASE_OBJ rs_element; 139/** 140 * \brief Opaque handle to a RenderScript type. 141 * 142 * See: android.renderscript.Type 143 */ 144RS_BASE_OBJ rs_type; 145/** 146 * \brief Opaque handle to a RenderScript allocation. 147 * 148 * See: android.renderscript.Allocation 149 */ 150RS_BASE_OBJ rs_allocation; 151/** 152 * \brief Opaque handle to a RenderScript sampler object. 153 * 154 * See: android.renderscript.Sampler 155 */ 156RS_BASE_OBJ rs_sampler; 157/** 158 * \brief Opaque handle to a RenderScript script object. 159 * 160 * See: android.renderscript.ScriptC 161 */ 162RS_BASE_OBJ rs_script; 163 164#ifndef __LP64__ 165/** 166 * \brief Opaque handle to a RenderScript mesh object. 167 * 168 * See: android.renderscript.Mesh 169 */ 170typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_mesh; 171/** 172 * \brief Opaque handle to a RenderScript Path object. 173 * 174 * See: android.renderscript.Path 175 */ 176typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_path; 177/** 178 * \brief Opaque handle to a RenderScript ProgramFragment object. 179 * 180 * See: android.renderscript.ProgramFragment 181 */ 182typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_fragment; 183/** 184 * \brief Opaque handle to a RenderScript ProgramVertex object. 185 * 186 * See: android.renderscript.ProgramVertex 187 */ 188typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_vertex; 189/** 190 * \brief Opaque handle to a RenderScript ProgramRaster object. 191 * 192 * See: android.renderscript.ProgramRaster 193 */ 194typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_raster; 195/** 196 * \brief Opaque handle to a RenderScript ProgramStore object. 197 * 198 * See: android.renderscript.ProgramStore 199 */ 200typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_store; 201/** 202 * \brief Opaque handle to a RenderScript font object. 203 * 204 * See: android.renderscript.Font 205 */ 206typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_font; 207#endif // __LP64__ 208 209/** 210 * Vector version of the basic float type. 211 * Provides two float fields packed into a single 64 bit field with 64 bit 212 * alignment. 213 */ 214typedef float float2 __attribute__((ext_vector_type(2))); 215/** 216 * Vector version of the basic float type. Provides three float fields packed 217 * into a single 128 bit field with 128 bit alignment. 218 */ 219typedef float float3 __attribute__((ext_vector_type(3))); 220/** 221 * Vector version of the basic float type. 222 * Provides four float fields packed into a single 128 bit field with 128 bit 223 * alignment. 224 */ 225typedef float float4 __attribute__((ext_vector_type(4))); 226 227/** 228 * Vector version of the basic double type. Provides two double fields packed 229 * into a single 128 bit field with 128 bit alignment. 230 */ 231typedef double double2 __attribute__((ext_vector_type(2))); 232/** 233 * Vector version of the basic double type. Provides three double fields packed 234 * into a single 256 bit field with 256 bit alignment. 235 */ 236typedef double double3 __attribute__((ext_vector_type(3))); 237/** 238 * Vector version of the basic double type. Provides four double fields packed 239 * into a single 256 bit field with 256 bit alignment. 240 */ 241typedef double double4 __attribute__((ext_vector_type(4))); 242 243/** 244 * Vector version of the basic uchar type. Provides two uchar fields packed 245 * into a single 16 bit field with 16 bit alignment. 246 */ 247typedef uchar uchar2 __attribute__((ext_vector_type(2))); 248/** 249 * Vector version of the basic uchar type. Provides three uchar fields packed 250 * into a single 32 bit field with 32 bit alignment. 251 */ 252typedef uchar uchar3 __attribute__((ext_vector_type(3))); 253/** 254 * Vector version of the basic uchar type. Provides four uchar fields packed 255 * into a single 32 bit field with 32 bit alignment. 256 */ 257typedef uchar uchar4 __attribute__((ext_vector_type(4))); 258 259/** 260 * Vector version of the basic ushort type. Provides two ushort fields packed 261 * into a single 32 bit field with 32 bit alignment. 262 */ 263typedef ushort ushort2 __attribute__((ext_vector_type(2))); 264/** 265 * Vector version of the basic ushort type. Provides three ushort fields packed 266 * into a single 64 bit field with 64 bit alignment. 267 */ 268typedef ushort ushort3 __attribute__((ext_vector_type(3))); 269/** 270 * Vector version of the basic ushort type. Provides four ushort fields packed 271 * into a single 64 bit field with 64 bit alignment. 272 */ 273typedef ushort ushort4 __attribute__((ext_vector_type(4))); 274 275/** 276 * Vector version of the basic uint type. Provides two uint fields packed into a 277 * single 64 bit field with 64 bit alignment. 278 */ 279typedef uint uint2 __attribute__((ext_vector_type(2))); 280/** 281 * Vector version of the basic uint type. Provides three uint fields packed into 282 * a single 128 bit field with 128 bit alignment. 283 */ 284typedef uint uint3 __attribute__((ext_vector_type(3))); 285/** 286 * Vector version of the basic uint type. Provides four uint fields packed into 287 * a single 128 bit field with 128 bit alignment. 288 */ 289typedef uint uint4 __attribute__((ext_vector_type(4))); 290 291/** 292 * Vector version of the basic ulong type. Provides two ulong fields packed into 293 * a single 128 bit field with 128 bit alignment. 294 */ 295typedef ulong ulong2 __attribute__((ext_vector_type(2))); 296/** 297 * Vector version of the basic ulong type. Provides three ulong fields packed 298 * into a single 256 bit field with 256 bit alignment. 299 */ 300typedef ulong ulong3 __attribute__((ext_vector_type(3))); 301/** 302 * Vector version of the basic ulong type. Provides four ulong fields packed 303 * into a single 256 bit field with 256 bit alignment. 304 */ 305typedef ulong ulong4 __attribute__((ext_vector_type(4))); 306 307/** 308 * Vector version of the basic char type. Provides two char fields packed into a 309 * single 16 bit field with 16 bit alignment. 310 */ 311typedef char char2 __attribute__((ext_vector_type(2))); 312/** 313 * Vector version of the basic char type. Provides three char fields packed into 314 * a single 32 bit field with 32 bit alignment. 315 */ 316typedef char char3 __attribute__((ext_vector_type(3))); 317/** 318 * Vector version of the basic char type. Provides four char fields packed into 319 * a single 32 bit field with 32 bit alignment. 320 */ 321typedef char char4 __attribute__((ext_vector_type(4))); 322 323/** 324 * Vector version of the basic short type. Provides two short fields packed into 325 * a single 32 bit field with 32 bit alignment. 326 */ 327typedef short short2 __attribute__((ext_vector_type(2))); 328/** 329 * Vector version of the basic short type. Provides three short fields packed 330 * into a single 64 bit field with 64 bit alignment. 331 */ 332typedef short short3 __attribute__((ext_vector_type(3))); 333/** 334 * Vector version of the basic short type. Provides four short fields packed 335 * into a single 64 bit field with 64 bit alignment. 336 */ 337typedef short short4 __attribute__((ext_vector_type(4))); 338 339/** 340 * Vector version of the basic int type. Provides two int fields packed into a 341 * single 64 bit field with 64 bit alignment. 342 */ 343typedef int int2 __attribute__((ext_vector_type(2))); 344/** 345 * Vector version of the basic int type. Provides three int fields packed into a 346 * single 128 bit field with 128 bit alignment. 347 */ 348typedef int int3 __attribute__((ext_vector_type(3))); 349/** 350 * Vector version of the basic int type. Provides two four fields packed into a 351 * single 128 bit field with 128 bit alignment. 352 */ 353typedef int int4 __attribute__((ext_vector_type(4))); 354 355/** 356 * Vector version of the basic long type. Provides two long fields packed into a 357 * single 128 bit field with 128 bit alignment. 358 */ 359typedef long long2 __attribute__((ext_vector_type(2))); 360/** 361 * Vector version of the basic long type. Provides three long fields packed into 362 * a single 256 bit field with 256 bit alignment. 363 */ 364typedef long long3 __attribute__((ext_vector_type(3))); 365/** 366 * Vector version of the basic long type. Provides four long fields packed into 367 * a single 256 bit field with 256 bit alignment. 368 */ 369typedef long long4 __attribute__((ext_vector_type(4))); 370 371/** 372 * \brief 4x4 float matrix 373 * 374 * Native holder for RS matrix. Elements are stored in the array at the 375 * location [row*4 + col] 376 */ 377typedef struct { 378 float m[16]; 379} rs_matrix4x4; 380/** 381 * \brief 3x3 float matrix 382 * 383 * Native holder for RS matrix. Elements are stored in the array at the 384 * location [row*3 + col] 385 */ 386typedef struct { 387 float m[9]; 388} rs_matrix3x3; 389/** 390 * \brief 2x2 float matrix 391 * 392 * Native holder for RS matrix. Elements are stored in the array at the 393 * location [row*2 + col] 394 */ 395typedef struct { 396 float m[4]; 397} rs_matrix2x2; 398 399/** 400 * quaternion type for use with the quaternion functions 401 */ 402typedef float4 rs_quaternion; 403 404#define RS_PACKED __attribute__((packed, aligned(4))) 405#define NULL ((void *)0) 406 407#if (defined(RS_VERSION) && (RS_VERSION >= 14)) 408 409/** 410 * \brief Enum for selecting cube map faces 411 */ 412typedef enum { 413 RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X = 0, 414 RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_X = 1, 415 RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Y = 2, 416 RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Y = 3, 417 RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Z = 4, 418 RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Z = 5 419} rs_allocation_cubemap_face; 420 421/** 422 * \brief Bitfield to specify the usage types for an allocation. 423 * 424 * These values are ORed together to specify which usages or memory spaces are 425 * relevant to an allocation or an operation on an allocation. 426 */ 427typedef enum { 428 RS_ALLOCATION_USAGE_SCRIPT = 0x0001, 429 RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002, 430 RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004, 431 RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008, 432 RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010 433} rs_allocation_usage_type; 434 435#endif //defined(RS_VERSION) && (RS_VERSION >= 14) 436 437// New API's 438#if (defined(RS_VERSION) && (RS_VERSION >= 16)) 439 440#ifndef __LP64__ 441/** 442 * Describes the way mesh vertex data is interpreted when rendering 443 * 444 **/ 445typedef enum { 446 /** 447 * Vertex data will be rendered as a series of points 448 */ 449 RS_PRIMITIVE_POINT = 0, 450 /** 451 * Vertex pairs will be rendered as lines 452 */ 453 RS_PRIMITIVE_LINE = 1, 454 /** 455 * Vertex data will be rendered as a connected line strip 456 */ 457 RS_PRIMITIVE_LINE_STRIP = 2, 458 /** 459 * Vertices will be rendered as individual triangles 460 */ 461 RS_PRIMITIVE_TRIANGLE = 3, 462 /** 463 * Vertices will be rendered as a connected triangle strip 464 * defined by the first three vertices with each additional 465 * triangle defined by a new vertex 466 */ 467 RS_PRIMITIVE_TRIANGLE_STRIP = 4, 468 /** 469 * Vertices will be rendered as a sequence of triangles that all 470 * share first vertex as the origin 471 */ 472 RS_PRIMITIVE_TRIANGLE_FAN = 5, 473 474 /** 475 * Invalid primitive 476 */ 477 RS_PRIMITIVE_INVALID = 100, 478} rs_primitive; 479#endif // __LP64__ 480 481/** 482 * \brief Enumeration for possible element data types 483 * 484 * DataType represents the basic type information for a basic element. The 485 * naming convention follows. For numeric types it is FLOAT, 486 * SIGNED, or UNSIGNED followed by the _BITS where BITS is the 487 * size of the data. BOOLEAN is a true / false (1,0) 488 * represented in an 8 bit container. The UNSIGNED variants 489 * with multiple bit definitions are for packed graphical data 490 * formats and represent vectors with per vector member sizes 491 * which are treated as a single unit for packing and alignment 492 * purposes. 493 * 494 * MATRIX the three matrix types contain FLOAT_32 elements and are treated 495 * as 32 bits for alignment purposes. 496 * 497 * RS_* objects. 32 bit opaque handles. 498 */ 499typedef enum { 500 RS_TYPE_NONE = 0, 501 RS_TYPE_FLOAT_32 = 2, 502 RS_TYPE_FLOAT_64 = 3, 503 RS_TYPE_SIGNED_8 = 4, 504 RS_TYPE_SIGNED_16 = 5, 505 RS_TYPE_SIGNED_32 = 6, 506 RS_TYPE_SIGNED_64 = 7, 507 RS_TYPE_UNSIGNED_8 = 8, 508 RS_TYPE_UNSIGNED_16 = 9, 509 RS_TYPE_UNSIGNED_32 = 10, 510 RS_TYPE_UNSIGNED_64 = 11, 511 512 RS_TYPE_BOOLEAN = 12, 513 514 RS_TYPE_UNSIGNED_5_6_5 = 13, 515 RS_TYPE_UNSIGNED_5_5_5_1 = 14, 516 RS_TYPE_UNSIGNED_4_4_4_4 = 15, 517 518 RS_TYPE_MATRIX_4X4 = 16, 519 RS_TYPE_MATRIX_3X3 = 17, 520 RS_TYPE_MATRIX_2X2 = 18, 521 522 RS_TYPE_ELEMENT = 1000, 523 RS_TYPE_TYPE = 1001, 524 RS_TYPE_ALLOCATION = 1002, 525 RS_TYPE_SAMPLER = 1003, 526 RS_TYPE_SCRIPT = 1004, 527 RS_TYPE_MESH = 1005, 528 RS_TYPE_PROGRAM_FRAGMENT = 1006, 529 RS_TYPE_PROGRAM_VERTEX = 1007, 530 RS_TYPE_PROGRAM_RASTER = 1008, 531 RS_TYPE_PROGRAM_STORE = 1009, 532 RS_TYPE_FONT = 1010, 533 534 RS_TYPE_INVALID = 10000, 535} rs_data_type; 536 537/** 538 * \brief Enumeration for possible element data kind 539 * 540 * The special interpretation of the data if required. This is primarly 541 * useful for graphical data. USER indicates no special interpretation is 542 * expected. PIXEL is used in conjunction with the standard data types for 543 * representing texture formats. 544 */ 545typedef enum { 546 RS_KIND_USER = 0, 547 548 RS_KIND_PIXEL_L = 7, 549 RS_KIND_PIXEL_A = 8, 550 RS_KIND_PIXEL_LA = 9, 551 RS_KIND_PIXEL_RGB = 10, 552 RS_KIND_PIXEL_RGBA = 11, 553 RS_KIND_PIXEL_DEPTH = 12, 554 RS_KIND_PIXEL_YUV = 13, 555 556 RS_KIND_INVALID = 100, 557} rs_data_kind; 558 559#ifndef __LP64__ 560typedef enum { 561 /** 562 * Always drawn 563 */ 564 RS_DEPTH_FUNC_ALWAYS = 0, 565 /** 566 * Drawn if the incoming depth value is less than that in the 567 * depth buffer 568 */ 569 RS_DEPTH_FUNC_LESS = 1, 570 /** 571 * Drawn if the incoming depth value is less or equal to that in 572 * the depth buffer 573 */ 574 RS_DEPTH_FUNC_LEQUAL = 2, 575 /** 576 * Drawn if the incoming depth value is greater than that in the 577 * depth buffer 578 */ 579 RS_DEPTH_FUNC_GREATER = 3, 580 /** 581 * Drawn if the incoming depth value is greater or equal to that 582 * in the depth buffer 583 */ 584 RS_DEPTH_FUNC_GEQUAL = 4, 585 /** 586 * Drawn if the incoming depth value is equal to that in the 587 * depth buffer 588 */ 589 RS_DEPTH_FUNC_EQUAL = 5, 590 /** 591 * Drawn if the incoming depth value is not equal to that in the 592 * depth buffer 593 */ 594 RS_DEPTH_FUNC_NOTEQUAL = 6, 595 /** 596 * Invalid depth function 597 */ 598 RS_DEPTH_FUNC_INVALID = 100, 599} rs_depth_func; 600 601typedef enum { 602 RS_BLEND_SRC_ZERO = 0, 603 RS_BLEND_SRC_ONE = 1, 604 RS_BLEND_SRC_DST_COLOR = 2, 605 RS_BLEND_SRC_ONE_MINUS_DST_COLOR = 3, 606 RS_BLEND_SRC_SRC_ALPHA = 4, 607 RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA = 5, 608 RS_BLEND_SRC_DST_ALPHA = 6, 609 RS_BLEND_SRC_ONE_MINUS_DST_ALPHA = 7, 610 RS_BLEND_SRC_SRC_ALPHA_SATURATE = 8, 611 612 RS_BLEND_SRC_INVALID = 100, 613} rs_blend_src_func; 614 615typedef enum { 616 RS_BLEND_DST_ZERO = 0, 617 RS_BLEND_DST_ONE = 1, 618 RS_BLEND_DST_SRC_COLOR = 2, 619 RS_BLEND_DST_ONE_MINUS_SRC_COLOR = 3, 620 RS_BLEND_DST_SRC_ALPHA = 4, 621 RS_BLEND_DST_ONE_MINUS_SRC_ALPHA = 5, 622 RS_BLEND_DST_DST_ALPHA = 6, 623 RS_BLEND_DST_ONE_MINUS_DST_ALPHA = 7, 624 625 RS_BLEND_DST_INVALID = 100, 626} rs_blend_dst_func; 627 628typedef enum { 629 RS_CULL_BACK = 0, 630 RS_CULL_FRONT = 1, 631 RS_CULL_NONE = 2, 632 633 RS_CULL_INVALID = 100, 634} rs_cull_mode; 635#endif //__LP64__ 636 637typedef enum { 638 RS_SAMPLER_NEAREST = 0, 639 RS_SAMPLER_LINEAR = 1, 640 RS_SAMPLER_LINEAR_MIP_LINEAR = 2, 641 RS_SAMPLER_WRAP = 3, 642 RS_SAMPLER_CLAMP = 4, 643 RS_SAMPLER_LINEAR_MIP_NEAREST = 5, 644 RS_SAMPLER_MIRRORED_REPEAT = 6, 645 646 RS_SAMPLER_INVALID = 100, 647} rs_sampler_value; 648 649#endif // (defined(RS_VERSION) && (RS_VERSION >= 16)) 650 651#endif // __RS_TYPES_RSH__ 652