blob: 5d3f99343443ec9f2de66de215a5a52b72043804 [file] [log] [blame]
Stephen Hines05f25d22011-08-09 14:21:04 -07001#include "rs_core.rsh"
Alex Sakhartchouk5681ee62011-10-15 09:55:24 -07002#include "rs_graphics.rsh"
Stephen Hinesd4740c52011-08-08 15:04:52 -07003/*****************************************************************************
4 * CAUTION
5 *
6 * The following structure layout provides a more efficient way to access
7 * internal members of the C++ class Allocation owned by librs. Unfortunately,
8 * since this class has virtual members, we can't simply use offsetof() or any
9 * other compiler trickery to dynamically get the appropriate values at
10 * build-time. This layout may need to be updated whenever
11 * frameworks/base/libs/rs/rsAllocation.h is modified.
12 *
13 * Having the layout information available in this file allows us to
14 * accelerate functionality like rsAllocationGetDimX(). Without this
15 * information, we would not be able to inline the bitcode, thus resulting in
16 * potential runtime performance penalties for tight loops operating on
17 * allocations.
18 *
19 *****************************************************************************/
Alex Sakhartchouk26301b42011-12-20 14:50:14 -080020typedef enum {
21 RS_ALLOCATION_MIPMAP_NONE = 0,
22 RS_ALLOCATION_MIPMAP_FULL = 1,
23 RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE = 2
24} rs_allocation_mipmap_control;
25
Stephen Hinesd4740c52011-08-08 15:04:52 -070026typedef struct Allocation {
Alex Sakhartchouk26301b42011-12-20 14:50:14 -080027 char __pad[28];
Alex Sakhartchouk5681ee62011-10-15 09:55:24 -070028 struct {
Alex Sakhartchouk26301b42011-12-20 14:50:14 -080029 void * drv;
Alex Sakhartchouk5681ee62011-10-15 09:55:24 -070030 struct {
Alex Sakhartchouk26301b42011-12-20 14:50:14 -080031 const void *type;
32 uint32_t usageFlags;
33 rs_allocation_mipmap_control mipmapControl;
Stephen Hinesd4740c52011-08-08 15:04:52 -070034 uint32_t dimensionX;
35 uint32_t dimensionY;
36 uint32_t dimensionZ;
37 uint32_t elementSizeBytes;
38 bool hasMipmaps;
39 bool hasFaces;
40 bool hasReferences;
Jason Samsdcf7fec2011-12-09 16:13:43 -080041 void * usrPtr;
Jason Samsa0b6c062012-02-10 13:25:54 -080042 int32_t surfaceTextureID;
Jason Sams8c504fb2012-02-15 12:07:16 -080043 void * wndSurface;
Stephen Hinesd4740c52011-08-08 15:04:52 -070044 } state;
45
46 struct DrvState {
47 void * mallocPtr;
48 } drvState;
49 } mHal;
50} Allocation_t;
51
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -080052/*****************************************************************************
53 * CAUTION
54 *
55 * The following structure layout provides a more efficient way to access
56 * internal members of the C++ class ProgramStore owned by librs. Unfortunately,
57 * since this class has virtual members, we can't simply use offsetof() or any
58 * other compiler trickery to dynamically get the appropriate values at
59 * build-time. This layout may need to be updated whenever
60 * frameworks/base/libs/rs/rsProgramStore.h is modified.
61 *
62 * Having the layout information available in this file allows us to
63 * accelerate functionality like rsgProgramStoreGetDepthFunc(). Without this
64 * information, we would not be able to inline the bitcode, thus resulting in
65 * potential runtime performance penalties for tight loops operating on
Alex Sakhartchouk26301b42011-12-20 14:50:14 -080066 * program store.
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -080067 *
68 *****************************************************************************/
69typedef struct ProgramStore {
70 char __pad[36];
71 struct {
72 struct {
73 bool ditherEnable;
74 bool colorRWriteEnable;
75 bool colorGWriteEnable;
76 bool colorBWriteEnable;
77 bool colorAWriteEnable;
78 rs_blend_src_func blendSrc;
79 rs_blend_dst_func blendDst;
80 bool depthWriteEnable;
81 rs_depth_func depthFunc;
82 } state;
83 } mHal;
84} ProgramStore_t;
85
86/*****************************************************************************
87 * CAUTION
88 *
89 * The following structure layout provides a more efficient way to access
90 * internal members of the C++ class ProgramRaster owned by librs. Unfortunately,
91 * since this class has virtual members, we can't simply use offsetof() or any
92 * other compiler trickery to dynamically get the appropriate values at
93 * build-time. This layout may need to be updated whenever
94 * frameworks/base/libs/rs/rsProgramRaster.h is modified.
95 *
96 * Having the layout information available in this file allows us to
97 * accelerate functionality like rsgProgramRasterGetCullMode(). Without this
98 * information, we would not be able to inline the bitcode, thus resulting in
99 * potential runtime performance penalties for tight loops operating on
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800100 * program raster.
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800101 *
102 *****************************************************************************/
103typedef struct ProgramRaster {
104 char __pad[36];
105 struct {
106 struct {
107 bool pointSprite;
108 rs_cull_mode cull;
109 } state;
110 } mHal;
111} ProgramRaster_t;
112
113/*****************************************************************************
114 * CAUTION
115 *
116 * The following structure layout provides a more efficient way to access
117 * internal members of the C++ class Sampler owned by librs. Unfortunately,
118 * since this class has virtual members, we can't simply use offsetof() or any
119 * other compiler trickery to dynamically get the appropriate values at
120 * build-time. This layout may need to be updated whenever
121 * frameworks/base/libs/rs/rsSampler.h is modified.
122 *
123 * Having the layout information available in this file allows us to
124 * accelerate functionality like rsgProgramRasterGetMagFilter(). Without this
125 * information, we would not be able to inline the bitcode, thus resulting in
126 * potential runtime performance penalties for tight loops operating on
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800127 * samplers.
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800128 *
129 *****************************************************************************/
130typedef struct Sampler {
131 char __pad[32];
132 struct {
133 struct {
134 rs_sampler_value magFilter;
135 rs_sampler_value minFilter;
136 rs_sampler_value wrapS;
137 rs_sampler_value wrapT;
138 rs_sampler_value wrapR;
139 float aniso;
140 } state;
141 } mHal;
142} Sampler_t;
143
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800144/*****************************************************************************
145 * CAUTION
146 *
147 * The following structure layout provides a more efficient way to access
148 * internal members of the C++ class Element owned by librs. Unfortunately,
149 * since this class has virtual members, we can't simply use offsetof() or any
150 * other compiler trickery to dynamically get the appropriate values at
151 * build-time. This layout may need to be updated whenever
152 * frameworks/base/libs/rs/rsElement.h is modified.
153 *
154 * Having the layout information available in this file allows us to
155 * accelerate functionality like rsElementGetSubElementCount(). Without this
156 * information, we would not be able to inline the bitcode, thus resulting in
157 * potential runtime performance penalties for tight loops operating on
158 * elements.
159 *
160 *****************************************************************************/
161typedef struct Element {
162 char __pad[28];
163 struct {
164 void *drv;
165 struct {
166 rs_data_type dataType;
167 rs_data_kind dataKind;
168 uint32_t vectorSize;
169 uint32_t elementSizeBytes;
170
171 // Subelements
172 const void **fields;
173 uint32_t *fieldArraySizes;
174 const char **fieldNames;
175 uint32_t *fieldNameLengths;
176 uint32_t *fieldOffsetBytes;
177 uint32_t fieldsCount;
178 } state;
179 } mHal;
180} Element_t;
181
182/*****************************************************************************
183 * CAUTION
184 *
185 * The following structure layout provides a more efficient way to access
186 * internal members of the C++ class Type owned by librs. Unfortunately,
187 * since this class has virtual members, we can't simply use offsetof() or any
188 * other compiler trickery to dynamically get the appropriate values at
189 * build-time. This layout may need to be updated whenever
190 * frameworks/base/libs/rs/rsType.h is modified.
191 *
192 * Having the layout information available in this file allows us to
193 * accelerate functionality like rsAllocationGetElement(). Without this
194 * information, we would not be able to inline the bitcode, thus resulting in
195 * potential runtime performance penalties for tight loops operating on
196 * types.
197 *
198 *****************************************************************************/
199typedef struct Type {
200 char __pad[28];
201 struct {
202 void *drv;
203 struct {
204 const void * element;
205 uint32_t dimX;
206 uint32_t dimY;
207 uint32_t dimZ;
208 bool dimLOD;
209 bool faces;
210 } state;
211 } mHal;
212} Type_t;
213
214/*****************************************************************************
215 * CAUTION
216 *
217 * The following structure layout provides a more efficient way to access
218 * internal members of the C++ class Mesh owned by librs. Unfortunately,
219 * since this class has virtual members, we can't simply use offsetof() or any
220 * other compiler trickery to dynamically get the appropriate values at
221 * build-time. This layout may need to be updated whenever
222 * frameworks/base/libs/rs/rsMesh.h is modified.
223 *
224 * Having the layout information available in this file allows us to
225 * accelerate functionality like rsMeshGetVertexAllocationCount(). Without this
226 * information, we would not be able to inline the bitcode, thus resulting in
227 * potential runtime performance penalties for tight loops operating on
228 * meshes.
229 *
230 *****************************************************************************/
231typedef struct Mesh {
232 char __pad[28];
233 struct {
234 void *drv;
235 struct {
236 void **vertexBuffers;
237 uint32_t vertexBuffersCount;
238
239 // indexBuffers[i] could be NULL, in which case only primitives[i] is used
240 void **indexBuffers;
241 uint32_t indexBuffersCount;
242 rs_primitive *primitives;
243 uint32_t primitivesCount;
244 } state;
245 } mHal;
246} Mesh_t;
247
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800248
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800249/* Declaration of 4 basic functions in libRS */
250extern void __attribute__((overloadable))
251 rsDebug(const char *, float, float);
252extern void __attribute__((overloadable))
253 rsDebug(const char *, float, float, float);
254extern void __attribute__((overloadable))
255 rsDebug(const char *, float, float, float, float);
Shih-wei Liaof9728b92011-01-17 18:04:33 -0800256extern float4 __attribute__((overloadable)) convert_float4(uchar4 c);
257
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800258/* Implementation of Core Runtime */
259
260extern void __attribute__((overloadable)) rsDebug(const char *s, float2 v) {
261 rsDebug(s, v.x, v.y);
262}
263
264extern void __attribute__((overloadable)) rsDebug(const char *s, float3 v) {
265 rsDebug(s, v.x, v.y, v.z);
266}
267
268extern void __attribute__((overloadable)) rsDebug(const char *s, float4 v) {
269 rsDebug(s, v.x, v.y, v.z, v.w);
270}
271
Jason Samsf7ab3772012-02-29 15:59:43 -0800272/*
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800273extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b)
274{
275 uchar4 c;
Jason Sams9d3f8a72011-10-13 17:20:04 -0700276 c.x = (uchar)(r * 255.f + 0.5f);
277 c.y = (uchar)(g * 255.f + 0.5f);
278 c.z = (uchar)(b * 255.f + 0.5f);
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800279 c.w = 255;
280 return c;
281}
282
283extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b, float a)
284{
285 uchar4 c;
Jason Sams9d3f8a72011-10-13 17:20:04 -0700286 c.x = (uchar)(r * 255.f + 0.5f);
287 c.y = (uchar)(g * 255.f + 0.5f);
288 c.z = (uchar)(b * 255.f + 0.5f);
289 c.w = (uchar)(a * 255.f + 0.5f);
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800290 return c;
291}
292
293extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float3 color)
294{
295 color *= 255.f;
Jason Sams9d3f8a72011-10-13 17:20:04 -0700296 color += 0.5f;
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800297 uchar4 c = {color.x, color.y, color.z, 255};
298 return c;
299}
300
301extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float4 color)
302{
303 color *= 255.f;
Jason Sams9d3f8a72011-10-13 17:20:04 -0700304 color += 0.5f;
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800305 uchar4 c = {color.x, color.y, color.z, color.w};
306 return c;
307}
Jason Samsf7ab3772012-02-29 15:59:43 -0800308*/
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800309
310extern float4 rsUnpackColor8888(uchar4 c)
311{
Jason Sams9d3f8a72011-10-13 17:20:04 -0700312 float4 ret = (float4)0.003921569f;
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800313 ret *= convert_float4(c);
314 return ret;
315}
316
317/////////////////////////////////////////////////////
318// Matrix ops
319/////////////////////////////////////////////////////
320
321extern void __attribute__((overloadable))
322rsMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v) {
323 m->m[row * 4 + col] = v;
324}
325
326extern float __attribute__((overloadable))
327rsMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col) {
328 return m->m[row * 4 + col];
329}
330
331extern void __attribute__((overloadable))
332rsMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v) {
333 m->m[row * 3 + col] = v;
334}
335
336extern float __attribute__((overloadable))
337rsMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col) {
338 return m->m[row * 3 + col];
339}
340
341extern void __attribute__((overloadable))
342rsMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v) {
343 m->m[row * 2 + col] = v;
344}
345
346extern float __attribute__((overloadable))
347rsMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col) {
348 return m->m[row * 2 + col];
349}
350
Jason Sams5bc951c2012-02-27 19:32:15 -0800351/*
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800352extern float4 __attribute__((overloadable))
Jason Samsf9931b82011-07-26 17:28:38 -0700353rsMatrixMultiply(const rs_matrix4x4 *m, float4 in) {
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800354 float4 ret;
355 ret.x = (m->m[0] * in.x) + (m->m[4] * in.y) + (m->m[8] * in.z) + (m->m[12] * in.w);
356 ret.y = (m->m[1] * in.x) + (m->m[5] * in.y) + (m->m[9] * in.z) + (m->m[13] * in.w);
357 ret.z = (m->m[2] * in.x) + (m->m[6] * in.y) + (m->m[10] * in.z) + (m->m[14] * in.w);
358 ret.w = (m->m[3] * in.x) + (m->m[7] * in.y) + (m->m[11] * in.z) + (m->m[15] * in.w);
359 return ret;
360}
Jason Samsf9931b82011-07-26 17:28:38 -0700361extern float4 __attribute__((overloadable))
362rsMatrixMultiply(rs_matrix4x4 *m, float4 in) {
363 return rsMatrixMultiply((const rs_matrix4x4 *)m, in);
364}
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800365
366extern float4 __attribute__((overloadable))
Jason Samsf9931b82011-07-26 17:28:38 -0700367rsMatrixMultiply(const rs_matrix4x4 *m, float3 in) {
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800368 float4 ret;
369 ret.x = (m->m[0] * in.x) + (m->m[4] * in.y) + (m->m[8] * in.z) + m->m[12];
370 ret.y = (m->m[1] * in.x) + (m->m[5] * in.y) + (m->m[9] * in.z) + m->m[13];
371 ret.z = (m->m[2] * in.x) + (m->m[6] * in.y) + (m->m[10] * in.z) + m->m[14];
372 ret.w = (m->m[3] * in.x) + (m->m[7] * in.y) + (m->m[11] * in.z) + m->m[15];
373 return ret;
374}
Jason Samsf9931b82011-07-26 17:28:38 -0700375extern float4 __attribute__((overloadable))
376rsMatrixMultiply(rs_matrix4x4 *m, float3 in) {
377 return rsMatrixMultiply((const rs_matrix4x4 *)m, in);
378}
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800379
380extern float4 __attribute__((overloadable))
Jason Samsf9931b82011-07-26 17:28:38 -0700381rsMatrixMultiply(const rs_matrix4x4 *m, float2 in) {
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800382 float4 ret;
383 ret.x = (m->m[0] * in.x) + (m->m[4] * in.y) + m->m[12];
384 ret.y = (m->m[1] * in.x) + (m->m[5] * in.y) + m->m[13];
385 ret.z = (m->m[2] * in.x) + (m->m[6] * in.y) + m->m[14];
386 ret.w = (m->m[3] * in.x) + (m->m[7] * in.y) + m->m[15];
387 return ret;
388}
Jason Samsf9931b82011-07-26 17:28:38 -0700389extern float4 __attribute__((overloadable))
390rsMatrixMultiply(rs_matrix4x4 *m, float2 in) {
391 return rsMatrixMultiply((const rs_matrix4x4 *)m, in);
392}
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800393
394extern float3 __attribute__((overloadable))
Jason Samsf9931b82011-07-26 17:28:38 -0700395rsMatrixMultiply(const rs_matrix3x3 *m, float3 in) {
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800396 float3 ret;
397 ret.x = (m->m[0] * in.x) + (m->m[3] * in.y) + (m->m[6] * in.z);
398 ret.y = (m->m[1] * in.x) + (m->m[4] * in.y) + (m->m[7] * in.z);
399 ret.z = (m->m[2] * in.x) + (m->m[5] * in.y) + (m->m[8] * in.z);
400 return ret;
401}
Jason Samsf9931b82011-07-26 17:28:38 -0700402extern float3 __attribute__((overloadable))
403rsMatrixMultiply(rs_matrix3x3 *m, float3 in) {
404 return rsMatrixMultiply((const rs_matrix3x3 *)m, in);
405}
406
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800407extern float3 __attribute__((overloadable))
Jason Samsf9931b82011-07-26 17:28:38 -0700408rsMatrixMultiply(const rs_matrix3x3 *m, float2 in) {
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800409 float3 ret;
410 ret.x = (m->m[0] * in.x) + (m->m[3] * in.y);
411 ret.y = (m->m[1] * in.x) + (m->m[4] * in.y);
412 ret.z = (m->m[2] * in.x) + (m->m[5] * in.y);
413 return ret;
414}
Jason Samsf9931b82011-07-26 17:28:38 -0700415extern float3 __attribute__((overloadable))
416rsMatrixMultiply(rs_matrix3x3 *m, float2 in) {
417 return rsMatrixMultiply((const rs_matrix3x3 *)m, in);
418}
Jason Sams5bc951c2012-02-27 19:32:15 -0800419*/
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800420
421extern float2 __attribute__((overloadable))
Jason Samsf9931b82011-07-26 17:28:38 -0700422rsMatrixMultiply(const rs_matrix2x2 *m, float2 in) {
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800423 float2 ret;
424 ret.x = (m->m[0] * in.x) + (m->m[2] * in.y);
425 ret.y = (m->m[1] * in.x) + (m->m[3] * in.y);
426 return ret;
427}
Jason Samsf9931b82011-07-26 17:28:38 -0700428extern float2 __attribute__((overloadable))
429rsMatrixMultiply(rs_matrix2x2 *m, float2 in) {
430 return rsMatrixMultiply((const rs_matrix2x2 *)m, in);
431}
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800432
433/////////////////////////////////////////////////////
434// int ops
435/////////////////////////////////////////////////////
436
Stephen Hines85b860c2012-02-24 20:46:36 -0800437/*extern uint __attribute__((overloadable, always_inline)) rsClamp(uint amount, uint low, uint high) {
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800438 return amount < low ? low : (amount > high ? high : amount);
Stephen Hines85b860c2012-02-24 20:46:36 -0800439}*/
Shih-wei Liao50cdf8f2011-01-26 14:10:25 -0800440extern int __attribute__((overloadable, always_inline)) rsClamp(int amount, int low, int high) {
441 return amount < low ? low : (amount > high ? high : amount);
442}
443extern ushort __attribute__((overloadable, always_inline)) rsClamp(ushort amount, ushort low, ushort high) {
444 return amount < low ? low : (amount > high ? high : amount);
445}
446extern short __attribute__((overloadable, always_inline)) rsClamp(short amount, short low, short high) {
447 return amount < low ? low : (amount > high ? high : amount);
448}
449extern uchar __attribute__((overloadable, always_inline)) rsClamp(uchar amount, uchar low, uchar high) {
450 return amount < low ? low : (amount > high ? high : amount);
451}
452extern char __attribute__((overloadable, always_inline)) rsClamp(char amount, char low, char high) {
453 return amount < low ? low : (amount > high ? high : amount);
454}
Stephen Hinesd4740c52011-08-08 15:04:52 -0700455
456// Opaque Allocation type operations
457extern uint32_t __attribute__((overloadable))
458 rsAllocationGetDimX(rs_allocation a) {
459 Allocation_t *alloc = (Allocation_t *)a.p;
460 return alloc->mHal.state.dimensionX;
461}
462
463extern uint32_t __attribute__((overloadable))
464 rsAllocationGetDimY(rs_allocation a) {
465 Allocation_t *alloc = (Allocation_t *)a.p;
466 return alloc->mHal.state.dimensionY;
467}
468
469extern uint32_t __attribute__((overloadable))
470 rsAllocationGetDimZ(rs_allocation a) {
471 Allocation_t *alloc = (Allocation_t *)a.p;
472 return alloc->mHal.state.dimensionZ;
473}
474
475extern uint32_t __attribute__((overloadable))
476 rsAllocationGetDimLOD(rs_allocation a) {
477 Allocation_t *alloc = (Allocation_t *)a.p;
478 return alloc->mHal.state.hasMipmaps;
479}
480
481extern uint32_t __attribute__((overloadable))
482 rsAllocationGetDimFaces(rs_allocation a) {
483 Allocation_t *alloc = (Allocation_t *)a.p;
484 return alloc->mHal.state.hasFaces;
485}
486
487extern const void * __attribute__((overloadable))
488 rsGetElementAt(rs_allocation a, uint32_t x) {
489 Allocation_t *alloc = (Allocation_t *)a.p;
490 const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.mallocPtr;
491 const uint32_t eSize = alloc->mHal.state.elementSizeBytes;
492 return &p[eSize * x];
493}
494
495extern const void * __attribute__((overloadable))
496 rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y) {
497 Allocation_t *alloc = (Allocation_t *)a.p;
498 const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.mallocPtr;
499 const uint32_t eSize = alloc->mHal.state.elementSizeBytes;
500 const uint32_t dimX = alloc->mHal.state.dimensionX;
501 return &p[eSize * (x + y * dimX)];
502}
503
504extern const void * __attribute__((overloadable))
505 rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y, uint32_t z) {
506 Allocation_t *alloc = (Allocation_t *)a.p;
507 const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.mallocPtr;
508 const uint32_t eSize = alloc->mHal.state.elementSizeBytes;
509 const uint32_t dimX = alloc->mHal.state.dimensionX;
510 const uint32_t dimY = alloc->mHal.state.dimensionY;
511 return &p[eSize * (x + y * dimX + z * dimX * dimY)];
512}
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800513
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800514extern rs_element __attribute__((overloadable))
515 rsAllocationGetElement(rs_allocation a) {
516 Allocation_t *alloc = (Allocation_t *)a.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800517 if (alloc == NULL) {
518 rs_element nullElem = {0};
519 return nullElem;
520 }
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800521 Type_t *type = (Type_t *)alloc->mHal.state.type;
522 rs_element returnElem = {type->mHal.state.element};
523 return returnElem;
524}
525
526/**
527* Program Store
528*/
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800529extern rs_depth_func __attribute__((overloadable))
530 rsgProgramStoreGetDepthFunc(rs_program_store ps) {
531 ProgramStore_t *prog = (ProgramStore_t *)ps.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800532 if (prog == NULL) {
533 return RS_DEPTH_FUNC_INVALID;
534 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800535 return prog->mHal.state.depthFunc;
536}
537
538extern bool __attribute__((overloadable))
539 rsgProgramStoreGetDepthMask(rs_program_store ps) {
540 ProgramStore_t *prog = (ProgramStore_t *)ps.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800541 if (prog == NULL) {
542 return false;
543 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800544 return prog->mHal.state.depthWriteEnable;
545}
546
547extern bool __attribute__((overloadable))
548 rsgProgramStoreGetColorMaskR(rs_program_store ps) {
549 ProgramStore_t *prog = (ProgramStore_t *)ps.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800550 if (prog == NULL) {
551 return false;
552 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800553 return prog->mHal.state.colorRWriteEnable;
554}
555
556extern bool __attribute__((overloadable))
557 rsgProgramStoreGetColorMaskG(rs_program_store ps) {
558 ProgramStore_t *prog = (ProgramStore_t *)ps.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800559 if (prog == NULL) {
560 return false;
561 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800562 return prog->mHal.state.colorGWriteEnable;
563}
564
565extern bool __attribute__((overloadable))
566 rsgProgramStoreGetColorMaskB(rs_program_store ps) {
567 ProgramStore_t *prog = (ProgramStore_t *)ps.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800568 if (prog == NULL) {
569 return false;
570 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800571 return prog->mHal.state.colorBWriteEnable;
572}
573
574extern bool __attribute__((overloadable))
575 rsgProgramStoreGetColorMaskA(rs_program_store ps) {
576 ProgramStore_t *prog = (ProgramStore_t *)ps.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800577 if (prog == NULL) {
578 return false;
579 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800580 return prog->mHal.state.colorAWriteEnable;
581}
582
583extern rs_blend_src_func __attribute__((overloadable))
584 rsgProgramStoreGetBlendSrcFunc(rs_program_store ps) {
585 ProgramStore_t *prog = (ProgramStore_t *)ps.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800586 if (prog == NULL) {
587 return RS_BLEND_SRC_INVALID;
588 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800589 return prog->mHal.state.blendSrc;
590}
591
592extern rs_blend_dst_func __attribute__((overloadable))
593 rsgProgramStoreGetBlendDstFunc(rs_program_store ps) {
594 ProgramStore_t *prog = (ProgramStore_t *)ps.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800595 if (prog == NULL) {
596 return RS_BLEND_DST_INVALID;
597 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800598 return prog->mHal.state.blendDst;
599}
600
601extern bool __attribute__((overloadable))
602 rsgProgramStoreGetDitherEnabled(rs_program_store ps) {
603 ProgramStore_t *prog = (ProgramStore_t *)ps.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800604 if (prog == NULL) {
605 return false;
606 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800607 return prog->mHal.state.ditherEnable;
608}
609
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800610/**
611* Program Raster
612*/
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800613extern bool __attribute__((overloadable))
614 rsgProgramRasterGetPointSpriteEnabled(rs_program_raster pr) {
615 ProgramRaster_t *prog = (ProgramRaster_t *)pr.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800616 if (prog == NULL) {
617 return false;
618 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800619 return prog->mHal.state.pointSprite;
620}
621
622extern rs_cull_mode __attribute__((overloadable))
623 rsgProgramRasterGetCullMode(rs_program_raster pr) {
624 ProgramRaster_t *prog = (ProgramRaster_t *)pr.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800625 if (prog == NULL) {
626 return RS_CULL_INVALID;
627 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800628 return prog->mHal.state.cull;
629}
630
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800631/**
632* Sampler
633*/
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800634extern rs_sampler_value __attribute__((overloadable))
635 rsgSamplerGetMinification(rs_sampler s) {
636 Sampler_t *prog = (Sampler_t *)s.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800637 if (prog == NULL) {
638 return RS_SAMPLER_INVALID;
639 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800640 return prog->mHal.state.minFilter;
641}
642
643extern rs_sampler_value __attribute__((overloadable))
644 rsgSamplerGetMagnification(rs_sampler s) {
645 Sampler_t *prog = (Sampler_t *)s.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800646 if (prog == NULL) {
647 return RS_SAMPLER_INVALID;
648 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800649 return prog->mHal.state.magFilter;
650}
651
652extern rs_sampler_value __attribute__((overloadable))
653 rsgSamplerGetWrapS(rs_sampler s) {
654 Sampler_t *prog = (Sampler_t *)s.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800655 if (prog == NULL) {
656 return RS_SAMPLER_INVALID;
657 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800658 return prog->mHal.state.wrapS;
659}
660
661extern rs_sampler_value __attribute__((overloadable))
662 rsgSamplerGetWrapT(rs_sampler s) {
663 Sampler_t *prog = (Sampler_t *)s.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800664 if (prog == NULL) {
665 return RS_SAMPLER_INVALID;
666 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800667 return prog->mHal.state.wrapT;
668}
669
670extern float __attribute__((overloadable))
671 rsgSamplerGetAnisotropy(rs_sampler s) {
672 Sampler_t *prog = (Sampler_t *)s.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800673 if (prog == NULL) {
674 return 0.0f;
675 }
Alex Sakhartchoukaa08fd62011-11-17 16:01:24 -0800676 return prog->mHal.state.aniso;
677}
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800678
679/**
680* Mesh
681*/
682extern uint32_t __attribute__((overloadable))
683 rsMeshGetVertexAllocationCount(rs_mesh m) {
684 Mesh_t *mesh = (Mesh_t *)m.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800685 if (mesh == NULL) {
686 return 0;
687 }
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800688 return mesh->mHal.state.vertexBuffersCount;
689}
690
691extern uint32_t __attribute__((overloadable))
692 rsMeshGetPrimitiveCount(rs_mesh m) {
693 Mesh_t *mesh = (Mesh_t *)m.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800694 if (mesh == NULL) {
695 return 0;
696 }
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800697 return mesh->mHal.state.primitivesCount;
698}
699
700extern rs_allocation __attribute__((overloadable))
701 rsMeshGetVertexAllocation(rs_mesh m, uint32_t index) {
702 Mesh_t *mesh = (Mesh_t *)m.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800703 if (mesh == NULL || index >= mesh->mHal.state.vertexBuffersCount) {
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800704 rs_allocation nullAlloc = {0};
705 return nullAlloc;
706 }
707 rs_allocation returnAlloc = {mesh->mHal.state.vertexBuffers[index]};
708 return returnAlloc;
709}
710
711extern rs_allocation __attribute__((overloadable))
712 rsMeshGetIndexAllocation(rs_mesh m, uint32_t index) {
713 Mesh_t *mesh = (Mesh_t *)m.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800714 if (mesh == NULL || index >= mesh->mHal.state.primitivesCount) {
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800715 rs_allocation nullAlloc = {0};
716 return nullAlloc;
717 }
718 rs_allocation returnAlloc = {mesh->mHal.state.indexBuffers[index]};
719 return returnAlloc;
720}
721
722extern rs_primitive __attribute__((overloadable))
723 rsMeshGetPrimitive(rs_mesh m, uint32_t index) {
724 Mesh_t *mesh = (Mesh_t *)m.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800725 if (mesh == NULL || index >= mesh->mHal.state.primitivesCount) {
726 return RS_PRIMITIVE_INVALID;
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800727 }
728 return mesh->mHal.state.primitives[index];
729}
730
731/**
732* Element
733*/
734extern uint32_t __attribute__((overloadable))
735 rsElementGetSubElementCount(rs_element e) {
736 Element_t *element = (Element_t *)e.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800737 if (element == NULL) {
738 return 0;
739 }
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800740 return element->mHal.state.fieldsCount;
741}
742
743extern rs_element __attribute__((overloadable))
744 rsElementGetSubElement(rs_element e, uint32_t index) {
745 Element_t *element = (Element_t *)e.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800746 if (element == NULL || index >= element->mHal.state.fieldsCount) {
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800747 rs_element nullElem = {0};
748 return nullElem;
749 }
750 rs_element returnElem = {element->mHal.state.fields[index]};
751 return returnElem;
752}
753
754extern uint32_t __attribute__((overloadable))
755 rsElementGetSubElementNameLength(rs_element e, uint32_t index) {
756 Element_t *element = (Element_t *)e.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800757 if (element == NULL || index >= element->mHal.state.fieldsCount) {
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800758 return 0;
759 }
760 return element->mHal.state.fieldNameLengths[index];
761}
762
763extern uint32_t __attribute__((overloadable))
764 rsElementGetSubElementName(rs_element e, uint32_t index, char *name, uint32_t nameLength) {
765 Element_t *element = (Element_t *)e.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800766 if (element == NULL || index >= element->mHal.state.fieldsCount ||
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800767 nameLength == 0 || name == 0) {
768 return 0;
769 }
770
771 uint32_t numToCopy = element->mHal.state.fieldNameLengths[index];
772 if (nameLength < numToCopy) {
773 numToCopy = nameLength;
774 }
775 // Place the null terminator manually, in case of partial string
776 numToCopy --;
777 name[numToCopy] = '\0';
778 const char *nameSource = element->mHal.state.fieldNames[index];
779 for (uint32_t i = 0; i < numToCopy; i ++) {
780 name[i] = nameSource[i];
781 }
782 return numToCopy;
783}
784
785extern uint32_t __attribute__((overloadable))
786 rsElementGetSubElementArraySize(rs_element e, uint32_t index) {
787 Element_t *element = (Element_t *)e.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800788 if (element == NULL || index >= element->mHal.state.fieldsCount) {
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800789 return 0;
790 }
791 return element->mHal.state.fieldArraySizes[index];
792}
793
794extern uint32_t __attribute__((overloadable))
795 rsElementGetSubElementOffsetBytes(rs_element e, uint32_t index) {
796 Element_t *element = (Element_t *)e.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800797 if (element == NULL || index >= element->mHal.state.fieldsCount) {
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800798 return 0;
799 }
800 return element->mHal.state.fieldOffsetBytes[index];
801}
802
803extern uint32_t __attribute__((overloadable))
804 rsElementGetSizeBytes(rs_element e) {
805 Element_t *element = (Element_t *)e.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800806 if (element == NULL) {
807 return 0;
808 }
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800809 return element->mHal.state.elementSizeBytes;
810}
811
812extern rs_data_type __attribute__((overloadable))
813 rsElementGetDataType(rs_element e) {
814 Element_t *element = (Element_t *)e.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800815 if (element == NULL) {
816 return RS_TYPE_INVALID;
817 }
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800818 return element->mHal.state.dataType;
819}
820
821extern rs_data_kind __attribute__((overloadable))
822 rsElementGetDataKind(rs_element e) {
823 Element_t *element = (Element_t *)e.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800824 if (element == NULL) {
825 return RS_KIND_INVALID;
826 }
Alex Sakhartchouk26301b42011-12-20 14:50:14 -0800827 return element->mHal.state.dataKind;
828}
Alex Sakhartchouka6f221e2011-12-22 14:36:19 -0800829
830extern uint32_t __attribute__((overloadable))
831 rsElementGetVectorSize(rs_element e) {
832 Element_t *element = (Element_t *)e.p;
Alex Sakhartchoukd5364732011-12-29 13:32:05 -0800833 if (element == NULL) {
834 return 0;
835 }
Alex Sakhartchouka6f221e2011-12-22 14:36:19 -0800836 return element->mHal.state.vectorSize;
837}