• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "rs_core.rsh"
2 #include "rs_graphics.rsh"
3 #include "rs_structs.h"
4 
5 // Opaque Allocation type operations
6 extern uint32_t __attribute__((overloadable))
rsAllocationGetDimX(rs_allocation a)7     rsAllocationGetDimX(rs_allocation a) {
8     Allocation_t *alloc = (Allocation_t *)a.p;
9     return alloc->mHal.state.dimensionX;
10 }
11 
12 extern uint32_t __attribute__((overloadable))
rsAllocationGetDimY(rs_allocation a)13         rsAllocationGetDimY(rs_allocation a) {
14     Allocation_t *alloc = (Allocation_t *)a.p;
15     return alloc->mHal.state.dimensionY;
16 }
17 
18 extern uint32_t __attribute__((overloadable))
rsAllocationGetDimZ(rs_allocation a)19         rsAllocationGetDimZ(rs_allocation a) {
20     Allocation_t *alloc = (Allocation_t *)a.p;
21     return alloc->mHal.state.dimensionZ;
22 }
23 
24 extern uint32_t __attribute__((overloadable))
rsAllocationGetDimLOD(rs_allocation a)25         rsAllocationGetDimLOD(rs_allocation a) {
26     Allocation_t *alloc = (Allocation_t *)a.p;
27     return alloc->mHal.state.hasMipmaps;
28 }
29 
30 extern uint32_t __attribute__((overloadable))
rsAllocationGetDimFaces(rs_allocation a)31         rsAllocationGetDimFaces(rs_allocation a) {
32     Allocation_t *alloc = (Allocation_t *)a.p;
33     return alloc->mHal.state.hasFaces;
34 }
35 
36 extern const void * __attribute__((overloadable))
rsGetElementAt(rs_allocation a,uint32_t x)37         rsGetElementAt(rs_allocation a, uint32_t x) {
38     Allocation_t *alloc = (Allocation_t *)a.p;
39     const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.mallocPtr;
40     const uint32_t eSize = alloc->mHal.state.elementSizeBytes;
41     return &p[eSize * x];
42 }
43 
44 extern const void * __attribute__((overloadable))
rsGetElementAt(rs_allocation a,uint32_t x,uint32_t y)45         rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y) {
46     Allocation_t *alloc = (Allocation_t *)a.p;
47     const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.mallocPtr;
48     const uint32_t eSize = alloc->mHal.state.elementSizeBytes;
49     const uint32_t stride = alloc->mHal.drvState.stride;
50     return &p[(eSize * x) + (y * stride)];
51 }
52 
53 extern const void * __attribute__((overloadable))
rsGetElementAt(rs_allocation a,uint32_t x,uint32_t y,uint32_t z)54         rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y, uint32_t z) {
55     Allocation_t *alloc = (Allocation_t *)a.p;
56     const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.mallocPtr;
57     const uint32_t eSize = alloc->mHal.state.elementSizeBytes;
58     const uint32_t stride = alloc->mHal.drvState.stride;
59     const uint32_t dimY = alloc->mHal.state.dimensionY;
60     return &p[(eSize * x) + (y * stride) + (z * stride * dimY)];
61 }
62 
63 extern rs_element __attribute__((overloadable))
rsAllocationGetElement(rs_allocation a)64         rsAllocationGetElement(rs_allocation a) {
65     Allocation_t *alloc = (Allocation_t *)a.p;
66     if (alloc == NULL) {
67         rs_element nullElem = {0};
68         return nullElem;
69     }
70     Type_t *type = (Type_t *)alloc->mHal.state.type;
71     rs_element returnElem = {type->mHal.state.element};
72     return returnElem;
73 }
74