1#include "rs_core.rsh"
2#include "rs_graphics.rsh"
3#include "rs_structs.h"
4
5// Opaque Allocation type operations
6extern uint32_t __attribute__((overloadable))
7    rsAllocationGetDimX(rs_allocation a) {
8    Allocation_t *alloc = (Allocation_t *)a.p;
9    return alloc->mHal.state.dimensionX;
10}
11
12extern uint32_t __attribute__((overloadable))
13        rsAllocationGetDimY(rs_allocation a) {
14    Allocation_t *alloc = (Allocation_t *)a.p;
15    return alloc->mHal.state.dimensionY;
16}
17
18extern uint32_t __attribute__((overloadable))
19        rsAllocationGetDimZ(rs_allocation a) {
20    Allocation_t *alloc = (Allocation_t *)a.p;
21    return alloc->mHal.state.dimensionZ;
22}
23
24extern uint32_t __attribute__((overloadable))
25        rsAllocationGetDimLOD(rs_allocation a) {
26    Allocation_t *alloc = (Allocation_t *)a.p;
27    return alloc->mHal.state.hasMipmaps;
28}
29
30extern uint32_t __attribute__((overloadable))
31        rsAllocationGetDimFaces(rs_allocation a) {
32    Allocation_t *alloc = (Allocation_t *)a.p;
33    return alloc->mHal.state.hasFaces;
34}
35
36extern const void * __attribute__((overloadable))
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
44extern const void * __attribute__((overloadable))
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
53extern const void * __attribute__((overloadable))
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
63extern rs_element __attribute__((overloadable))
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