rsApiFileA3D.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 2016 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. #include "rsContext.h"
  17. #include "rsFileA3D.h"
  18. using android::Asset;
  19. using android::renderscript::Context;
  20. using android::renderscript::FileA3D;
  21. using android::renderscript::ObjectBase;
  22. using android::renderscript::rsuCopyString;
  23. RsObjectBase rsaFileA3DGetEntryByIndex(RsContext con, uint32_t index, RsFile file) {
  24. FileA3D *fa3d = static_cast<FileA3D *>(file);
  25. if (!fa3d) {
  26. ALOGE("Can't load entry. No valid file");
  27. return nullptr;
  28. }
  29. ObjectBase *obj = fa3d->initializeFromEntry(index);
  30. //ALOGV("Returning object with name %s", obj->getName());
  31. return obj;
  32. }
  33. void rsaFileA3DGetNumIndexEntries(RsContext con, int32_t *numEntries, RsFile file) {
  34. FileA3D *fa3d = static_cast<FileA3D *>(file);
  35. if (fa3d) {
  36. *numEntries = fa3d->getNumIndexEntries();
  37. } else {
  38. *numEntries = 0;
  39. }
  40. }
  41. void rsaFileA3DGetIndexEntries(RsContext con, RsFileIndexEntry *fileEntries, uint32_t numEntries, RsFile file) {
  42. FileA3D *fa3d = static_cast<FileA3D *>(file);
  43. if (!fa3d) {
  44. ALOGE("Can't load index entries. No valid file");
  45. return;
  46. }
  47. uint32_t numFileEntries = fa3d->getNumIndexEntries();
  48. if (numFileEntries != numEntries || numEntries == 0 || fileEntries == nullptr) {
  49. ALOGE("Can't load index entries. Invalid number requested");
  50. return;
  51. }
  52. for (uint32_t i = 0; i < numFileEntries; i ++) {
  53. const FileA3D::A3DIndexEntry *entry = fa3d->getIndexEntry(i);
  54. fileEntries[i].classID = entry->getType();
  55. fileEntries[i].objectName = rsuCopyString(entry->getObjectName());
  56. }
  57. }
  58. RsFile rsaFileA3DCreateFromMemory(RsContext con, const void *data, uint32_t len) {
  59. if (data == nullptr) {
  60. ALOGE("File load failed. Asset stream is nullptr");
  61. return nullptr;
  62. }
  63. Context *rsc = static_cast<Context *>(con);
  64. FileA3D *fa3d = new FileA3D(rsc);
  65. fa3d->incUserRef();
  66. fa3d->load(data, len);
  67. return fa3d;
  68. }
  69. RsFile rsaFileA3DCreateFromAsset(RsContext con, void *_asset) {
  70. ALOGE("Calling deprecated %s API", __FUNCTION__);
  71. return nullptr;
  72. }
  73. RsFile rsaFileA3DCreateFromFile(RsContext con, const char *path) {
  74. if (path == nullptr) {
  75. ALOGE("File load failed. Path is nullptr");
  76. return nullptr;
  77. }
  78. Context *rsc = static_cast<Context *>(con);
  79. FileA3D *fa3d = nullptr;
  80. FILE *f = fopen(path, "rbe");
  81. if (f) {
  82. fa3d = new FileA3D(rsc);
  83. fa3d->incUserRef();
  84. fa3d->load(f);
  85. fclose(f);
  86. } else {
  87. ALOGE("Could not open file %s", path);
  88. }
  89. return fa3d;
  90. }