Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2011 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 #define M_PI        3.14159265358979323846264338327950288f   /* pi */
     45 
     46 #include "stdbool.h"
     47 /**
     48  * 8 bit integer type
     49  */
     50 typedef char int8_t;
     51 /**
     52  * 16 bit integer type
     53  */
     54 typedef short int16_t;
     55 /**
     56  * 32 bit integer type
     57  */
     58 typedef int int32_t;
     59 /**
     60  * 64 bit integer type
     61  */
     62 typedef long long int64_t;
     63 /**
     64  * 8 bit unsigned integer type
     65  */
     66 typedef unsigned char uint8_t;
     67 /**
     68  * 16 bit unsigned integer type
     69  */
     70 typedef unsigned short uint16_t;
     71 /**
     72  * 32 bit unsigned integer type
     73  */
     74 typedef unsigned int uint32_t;
     75 /**
     76  * 64 bit unsigned integer type
     77  */
     78 typedef unsigned long long uint64_t;
     79 /**
     80  * 8 bit unsigned integer type
     81  */
     82 typedef uint8_t uchar;
     83 /**
     84  * 16 bit unsigned integer type
     85  */
     86 typedef uint16_t ushort;
     87 /**
     88  * 32 bit unsigned integer type
     89  */
     90 typedef uint32_t uint;
     91 /**
     92  * Typedef for unsigned long (use for 64-bit unsigned integers)
     93  */
     94 typedef uint64_t ulong;
     95 /**
     96  * Typedef for unsigned int
     97  */
     98 typedef uint32_t size_t;
     99 /**
    100  * Typedef for int (use for 32-bit integers)
    101  */
    102 typedef int32_t ssize_t;
    103 
    104 /**
    105  * \brief Opaque handle to a Renderscript element.
    106  *
    107  * See: android.renderscript.Element
    108  */
    109 typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_element;
    110 /**
    111  * \brief Opaque handle to a Renderscript type.
    112  *
    113  * See: android.renderscript.Type
    114  */
    115 typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_type;
    116 /**
    117  * \brief Opaque handle to a Renderscript allocation.
    118  *
    119  * See: android.renderscript.Allocation
    120  */
    121 typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_allocation;
    122 /**
    123  * \brief Opaque handle to a Renderscript sampler object.
    124  *
    125  * See: android.renderscript.Sampler
    126  */
    127 typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_sampler;
    128 /**
    129  * \brief Opaque handle to a Renderscript script object.
    130  *
    131  * See: android.renderscript.ScriptC
    132  */
    133 typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_script;
    134 /**
    135  * \brief Opaque handle to a Renderscript mesh object.
    136  *
    137  * See: android.renderscript.Mesh
    138  */
    139 typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_mesh;
    140 /**
    141  * \brief Opaque handle to a Renderscript ProgramFragment object.
    142  *
    143  * See: android.renderscript.ProgramFragment
    144  */
    145 typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_fragment;
    146 /**
    147  * \brief Opaque handle to a Renderscript ProgramVertex object.
    148  *
    149  * See: android.renderscript.ProgramVertex
    150  */
    151 typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_vertex;
    152 /**
    153  * \brief Opaque handle to a Renderscript ProgramRaster object.
    154  *
    155  * See: android.renderscript.ProgramRaster
    156  */
    157 typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_raster;
    158 /**
    159  * \brief Opaque handle to a Renderscript ProgramStore object.
    160  *
    161  * See: android.renderscript.ProgramStore
    162  */
    163 typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_store;
    164 /**
    165  * \brief Opaque handle to a Renderscript font object.
    166  *
    167  * See: android.renderscript.Font
    168  */
    169 typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_font;
    170 
    171 /**
    172  * Vector version of the basic float type.
    173  * Provides two float fields packed into a single 64 bit field with 64 bit
    174  * alignment.
    175  */
    176 typedef float float2 __attribute__((ext_vector_type(2)));
    177 /**
    178  * Vector version of the basic float type. Provides three float fields packed
    179  * into a single 128 bit field with 128 bit alignment.
    180  */
    181 typedef float float3 __attribute__((ext_vector_type(3)));
    182 /**
    183  * Vector version of the basic float type.
    184  * Provides four float fields packed into a single 128 bit field with 128 bit
    185  * alignment.
    186  */
    187 typedef float float4 __attribute__((ext_vector_type(4)));
    188 
    189 /**
    190  * Vector version of the basic double type. Provides two double fields packed
    191  * into a single 128 bit field with 128 bit alignment.
    192  */
    193 typedef double double2 __attribute__((ext_vector_type(2)));
    194 /**
    195  * Vector version of the basic double type. Provides three double fields packed
    196  * into a single 256 bit field with 256 bit alignment.
    197  */
    198 typedef double double3 __attribute__((ext_vector_type(3)));
    199 /**
    200  * Vector version of the basic double type. Provides four double fields packed
    201  * into a single 256 bit field with 256 bit alignment.
    202  */
    203 typedef double double4 __attribute__((ext_vector_type(4)));
    204 
    205 /**
    206  * Vector version of the basic uchar type. Provides two uchar fields packed
    207  * into a single 16 bit field with 16 bit alignment.
    208  */
    209 typedef uchar uchar2 __attribute__((ext_vector_type(2)));
    210 /**
    211  * Vector version of the basic uchar type. Provides three uchar fields packed
    212  * into a single 32 bit field with 32 bit alignment.
    213  */
    214 typedef uchar uchar3 __attribute__((ext_vector_type(3)));
    215 /**
    216  * Vector version of the basic uchar type. Provides four uchar fields packed
    217  * into a single 32 bit field with 32 bit alignment.
    218  */
    219 typedef uchar uchar4 __attribute__((ext_vector_type(4)));
    220 
    221 /**
    222  * Vector version of the basic ushort type. Provides two ushort fields packed
    223  * into a single 32 bit field with 32 bit alignment.
    224  */
    225 typedef ushort ushort2 __attribute__((ext_vector_type(2)));
    226 /**
    227  * Vector version of the basic ushort type. Provides three ushort fields packed
    228  * into a single 64 bit field with 64 bit alignment.
    229  */
    230 typedef ushort ushort3 __attribute__((ext_vector_type(3)));
    231 /**
    232  * Vector version of the basic ushort type. Provides four ushort fields packed
    233  * into a single 64 bit field with 64 bit alignment.
    234  */
    235 typedef ushort ushort4 __attribute__((ext_vector_type(4)));
    236 
    237 /**
    238  * Vector version of the basic uint type. Provides two uint fields packed into a
    239  * single 64 bit field with 64 bit alignment.
    240  */
    241 typedef uint uint2 __attribute__((ext_vector_type(2)));
    242 /**
    243  * Vector version of the basic uint type. Provides three uint fields packed into
    244  * a single 128 bit field with 128 bit alignment.
    245  */
    246 typedef uint uint3 __attribute__((ext_vector_type(3)));
    247 /**
    248  * Vector version of the basic uint type. Provides four uint fields packed into
    249  * a single 128 bit field with 128 bit alignment.
    250  */
    251 typedef uint uint4 __attribute__((ext_vector_type(4)));
    252 
    253 /**
    254  * Vector version of the basic ulong type. Provides two ulong fields packed into
    255  * a single 128 bit field with 128 bit alignment.
    256  */
    257 typedef ulong ulong2 __attribute__((ext_vector_type(2)));
    258 /**
    259  * Vector version of the basic ulong type. Provides three ulong fields packed
    260  * into a single 256 bit field with 256 bit alignment.
    261  */
    262 typedef ulong ulong3 __attribute__((ext_vector_type(3)));
    263 /**
    264  * Vector version of the basic ulong type. Provides four ulong fields packed
    265  * into a single 256 bit field with 256 bit alignment.
    266  */
    267 typedef ulong ulong4 __attribute__((ext_vector_type(4)));
    268 
    269 /**
    270  * Vector version of the basic char type. Provides two char fields packed into a
    271  * single 16 bit field with 16 bit alignment.
    272  */
    273 typedef char char2 __attribute__((ext_vector_type(2)));
    274 /**
    275  * Vector version of the basic char type. Provides three char fields packed into
    276  * a single 32 bit field with 32 bit alignment.
    277  */
    278 typedef char char3 __attribute__((ext_vector_type(3)));
    279 /**
    280  * Vector version of the basic char type. Provides four char fields packed into
    281  * a single 32 bit field with 32 bit alignment.
    282  */
    283 typedef char char4 __attribute__((ext_vector_type(4)));
    284 
    285 /**
    286  * Vector version of the basic short type. Provides two short fields packed into
    287  * a single 32 bit field with 32 bit alignment.
    288  */
    289 typedef short short2 __attribute__((ext_vector_type(2)));
    290 /**
    291  * Vector version of the basic short type. Provides three short fields packed
    292  * into a single 64 bit field with 64 bit alignment.
    293  */
    294 typedef short short3 __attribute__((ext_vector_type(3)));
    295 /**
    296  * Vector version of the basic short type. Provides four short fields packed
    297  * into a single 64 bit field with 64 bit alignment.
    298  */
    299 typedef short short4 __attribute__((ext_vector_type(4)));
    300 
    301 /**
    302  * Vector version of the basic int type. Provides two int fields packed into a
    303  * single 64 bit field with 64 bit alignment.
    304  */
    305 typedef int int2 __attribute__((ext_vector_type(2)));
    306 /**
    307  * Vector version of the basic int type. Provides three int fields packed into a
    308  * single 128 bit field with 128 bit alignment.
    309  */
    310 typedef int int3 __attribute__((ext_vector_type(3)));
    311 /**
    312  * Vector version of the basic int type. Provides two four fields packed into a
    313  * single 128 bit field with 128 bit alignment.
    314  */
    315 typedef int int4 __attribute__((ext_vector_type(4)));
    316 
    317 /**
    318  * Vector version of the basic long type. Provides two long fields packed into a
    319  * single 128 bit field with 128 bit alignment.
    320  */
    321 typedef long long2 __attribute__((ext_vector_type(2)));
    322 /**
    323  * Vector version of the basic long type. Provides three long fields packed into
    324  * a single 256 bit field with 256 bit alignment.
    325  */
    326 typedef long long3 __attribute__((ext_vector_type(3)));
    327 /**
    328  * Vector version of the basic long type. Provides four long fields packed into
    329  * a single 256 bit field with 256 bit alignment.
    330  */
    331 typedef long long4 __attribute__((ext_vector_type(4)));
    332 
    333 /**
    334  * \brief 4x4 float matrix
    335  *
    336  * Native holder for RS matrix.  Elements are stored in the array at the
    337  * location [row*4 + col]
    338  */
    339 typedef struct {
    340     float m[16];
    341 } rs_matrix4x4;
    342 /**
    343  * \brief 3x3 float matrix
    344  *
    345  * Native holder for RS matrix.  Elements are stored in the array at the
    346  * location [row*3 + col]
    347  */
    348 typedef struct {
    349     float m[9];
    350 } rs_matrix3x3;
    351 /**
    352  * \brief 2x2 float matrix
    353  *
    354  * Native holder for RS matrix.  Elements are stored in the array at the
    355  * location [row*2 + col]
    356  */
    357 typedef struct {
    358     float m[4];
    359 } rs_matrix2x2;
    360 
    361 /**
    362  * quaternion type for use with the quaternion functions
    363  */
    364 typedef float4 rs_quaternion;
    365 
    366 #define RS_PACKED __attribute__((packed, aligned(4)))
    367 #define NULL ((const void *)0)
    368 
    369 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
    370 
    371 /**
    372  * \brief Enum for selecting cube map faces
    373  */
    374 typedef enum {
    375     RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X = 0,
    376     RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_X = 1,
    377     RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Y = 2,
    378     RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Y = 3,
    379     RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Z = 4,
    380     RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Z = 5
    381 } rs_allocation_cubemap_face;
    382 
    383 /**
    384  * \brief Bitfield to specify the usage types for an allocation.
    385  *
    386  * These values are ORed together to specify which usages or memory spaces are
    387  * relevant to an allocation or an operation on an allocation.
    388  */
    389 typedef enum {
    390     RS_ALLOCATION_USAGE_SCRIPT = 0x0001,
    391     RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002,
    392     RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004,
    393     RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008,
    394     RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010
    395 } rs_allocation_usage_type;
    396 
    397 #endif //defined(RS_VERSION) && (RS_VERSION >= 14)
    398 
    399 #endif
    400