Yang Ni | 85d0cb1 | 2016-03-18 15:33:52 -0700 | [diff] [blame] | 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 | |
| 17 | #include "rsContext.h" |
| 18 | #include "rsFileA3D.h" |
| 19 | |
Chih-Hung Hsieh | 11496ac | 2016-11-15 15:14:05 -0800 | [diff] [blame] | 20 | using android::Asset; |
| 21 | using android::renderscript::Context; |
| 22 | using android::renderscript::FileA3D; |
| 23 | using android::renderscript::ObjectBase; |
| 24 | using android::renderscript::rsuCopyString; |
Yang Ni | 85d0cb1 | 2016-03-18 15:33:52 -0700 | [diff] [blame] | 25 | |
| 26 | RsObjectBase rsaFileA3DGetEntryByIndex(RsContext con, uint32_t index, RsFile file) { |
| 27 | FileA3D *fa3d = static_cast<FileA3D *>(file); |
| 28 | if (!fa3d) { |
| 29 | ALOGE("Can't load entry. No valid file"); |
| 30 | return nullptr; |
| 31 | } |
| 32 | |
| 33 | ObjectBase *obj = fa3d->initializeFromEntry(index); |
| 34 | //ALOGV("Returning object with name %s", obj->getName()); |
| 35 | |
| 36 | return obj; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | void rsaFileA3DGetNumIndexEntries(RsContext con, int32_t *numEntries, RsFile file) { |
| 41 | FileA3D *fa3d = static_cast<FileA3D *>(file); |
| 42 | |
| 43 | if (fa3d) { |
| 44 | *numEntries = fa3d->getNumIndexEntries(); |
| 45 | } else { |
| 46 | *numEntries = 0; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void rsaFileA3DGetIndexEntries(RsContext con, RsFileIndexEntry *fileEntries, uint32_t numEntries, RsFile file) { |
| 51 | FileA3D *fa3d = static_cast<FileA3D *>(file); |
| 52 | |
| 53 | if (!fa3d) { |
| 54 | ALOGE("Can't load index entries. No valid file"); |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | uint32_t numFileEntries = fa3d->getNumIndexEntries(); |
| 59 | if (numFileEntries != numEntries || numEntries == 0 || fileEntries == nullptr) { |
| 60 | ALOGE("Can't load index entries. Invalid number requested"); |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | for (uint32_t i = 0; i < numFileEntries; i ++) { |
| 65 | const FileA3D::A3DIndexEntry *entry = fa3d->getIndexEntry(i); |
| 66 | fileEntries[i].classID = entry->getType(); |
| 67 | fileEntries[i].objectName = rsuCopyString(entry->getObjectName()); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | RsFile rsaFileA3DCreateFromMemory(RsContext con, const void *data, uint32_t len) { |
| 72 | if (data == nullptr) { |
| 73 | ALOGE("File load failed. Asset stream is nullptr"); |
| 74 | return nullptr; |
| 75 | } |
| 76 | |
| 77 | Context *rsc = static_cast<Context *>(con); |
| 78 | FileA3D *fa3d = new FileA3D(rsc); |
| 79 | fa3d->incUserRef(); |
| 80 | |
| 81 | fa3d->load(data, len); |
| 82 | return fa3d; |
| 83 | } |
| 84 | |
| 85 | RsFile rsaFileA3DCreateFromAsset(RsContext con, void *_asset) { |
Yang Ni | ba5e591 | 2016-12-13 16:58:02 -0800 | [diff] [blame] | 86 | ALOGE("Calling deprecated %s API", __FUNCTION__); |
Yang Ni | 85d0cb1 | 2016-03-18 15:33:52 -0700 | [diff] [blame] | 87 | return nullptr; |
Yang Ni | 85d0cb1 | 2016-03-18 15:33:52 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | RsFile rsaFileA3DCreateFromFile(RsContext con, const char *path) { |
| 91 | if (path == nullptr) { |
| 92 | ALOGE("File load failed. Path is nullptr"); |
| 93 | return nullptr; |
| 94 | } |
| 95 | |
| 96 | Context *rsc = static_cast<Context *>(con); |
| 97 | FileA3D *fa3d = nullptr; |
| 98 | |
Nick Kralevich | 95e1702 | 2018-12-11 14:35:57 -0800 | [diff] [blame] | 99 | FILE *f = fopen(path, "rbe"); |
Yang Ni | 85d0cb1 | 2016-03-18 15:33:52 -0700 | [diff] [blame] | 100 | if (f) { |
| 101 | fa3d = new FileA3D(rsc); |
| 102 | fa3d->incUserRef(); |
| 103 | fa3d->load(f); |
| 104 | fclose(f); |
| 105 | } else { |
| 106 | ALOGE("Could not open file %s", path); |
| 107 | } |
| 108 | |
| 109 | return fa3d; |
| 110 | } |