rs_element.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "rs_core.rsh"
  2. #include "rs_structs.h"
  3. /**
  4. * Element
  5. */
  6. extern uint32_t __attribute__((overloadable))
  7. rsElementGetSubElementCount(rs_element e) {
  8. Element_t *element = (Element_t *)e.p;
  9. if (element == NULL) {
  10. return 0;
  11. }
  12. return element->mHal.state.fieldsCount;
  13. }
  14. extern rs_element __attribute__((overloadable))
  15. rsElementGetSubElement(rs_element e, uint32_t index) {
  16. Element_t *element = (Element_t *)e.p;
  17. if (element == NULL || index >= element->mHal.state.fieldsCount) {
  18. rs_element nullElem = RS_NULL_OBJ;
  19. return nullElem;
  20. }
  21. rs_element returnElem = {
  22. element->mHal.state.fields[index]
  23. #ifdef __LP64__
  24. , 0, 0, 0
  25. #endif
  26. };
  27. rs_element rs_retval = RS_NULL_OBJ;
  28. rsSetObject(&rs_retval, returnElem);
  29. return rs_retval;
  30. }
  31. extern uint32_t __attribute__((overloadable))
  32. rsElementGetSubElementNameLength(rs_element e, uint32_t index) {
  33. Element_t *element = (Element_t *)e.p;
  34. if (element == NULL || index >= element->mHal.state.fieldsCount) {
  35. return 0;
  36. }
  37. return element->mHal.state.fieldNameLengths[index];
  38. }
  39. extern uint32_t __attribute__((overloadable))
  40. rsElementGetSubElementName(rs_element e, uint32_t index, char *name, uint32_t nameLength) {
  41. Element_t *element = (Element_t *)e.p;
  42. if (element == NULL || index >= element->mHal.state.fieldsCount ||
  43. nameLength == 0 || name == 0) {
  44. return 0;
  45. }
  46. uint32_t numToCopy = element->mHal.state.fieldNameLengths[index];
  47. if (nameLength < numToCopy) {
  48. numToCopy = nameLength;
  49. }
  50. // Place the null terminator manually, in case of partial string
  51. numToCopy --;
  52. name[numToCopy] = '\0';
  53. const char *nameSource = element->mHal.state.fieldNames[index];
  54. for (uint32_t i = 0; i < numToCopy; i ++) {
  55. name[i] = nameSource[i];
  56. }
  57. return numToCopy;
  58. }
  59. extern uint32_t __attribute__((overloadable))
  60. rsElementGetSubElementArraySize(rs_element e, uint32_t index) {
  61. Element_t *element = (Element_t *)e.p;
  62. if (element == NULL || index >= element->mHal.state.fieldsCount) {
  63. return 0;
  64. }
  65. return element->mHal.state.fieldArraySizes[index];
  66. }
  67. extern uint32_t __attribute__((overloadable))
  68. rsElementGetSubElementOffsetBytes(rs_element e, uint32_t index) {
  69. Element_t *element = (Element_t *)e.p;
  70. if (element == NULL || index >= element->mHal.state.fieldsCount) {
  71. return 0;
  72. }
  73. return element->mHal.state.fieldOffsetBytes[index];
  74. }
  75. extern uint32_t __attribute__((overloadable))
  76. rsElementGetBytesSize(rs_element e) {
  77. Element_t *element = (Element_t *)e.p;
  78. if (element == NULL) {
  79. return 0;
  80. }
  81. return element->mHal.state.elementSizeBytes;
  82. }
  83. extern rs_data_type __attribute__((overloadable))
  84. rsElementGetDataType(rs_element e) {
  85. Element_t *element = (Element_t *)e.p;
  86. if (element == NULL) {
  87. return RS_TYPE_INVALID;
  88. }
  89. return element->mHal.state.dataType;
  90. }
  91. extern rs_data_kind __attribute__((overloadable))
  92. rsElementGetDataKind(rs_element e) {
  93. Element_t *element = (Element_t *)e.p;
  94. if (element == NULL) {
  95. return RS_KIND_INVALID;
  96. }
  97. return element->mHal.state.dataKind;
  98. }
  99. extern uint32_t __attribute__((overloadable))
  100. rsElementGetVectorSize(rs_element e) {
  101. Element_t *element = (Element_t *)e.p;
  102. if (element == NULL) {
  103. return 0;
  104. }
  105. return element->mHal.state.vectorSize;
  106. }