blob: bbb68efbd155da4690f05d857effe530aea7d5cb [file] [log] [blame]
Yang Ni85d0cb12016-03-18 15:33:52 -07001/*
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 Hsieh11496ac2016-11-15 15:14:05 -080020using android::Asset;
21using android::renderscript::Context;
22using android::renderscript::FileA3D;
23using android::renderscript::ObjectBase;
24using android::renderscript::rsuCopyString;
Yang Ni85d0cb12016-03-18 15:33:52 -070025
26RsObjectBase 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
40void 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
50void 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
71RsFile 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
85RsFile rsaFileA3DCreateFromAsset(RsContext con, void *_asset) {
Yang Niba5e5912016-12-13 16:58:02 -080086 ALOGE("Calling deprecated %s API", __FUNCTION__);
Yang Ni85d0cb12016-03-18 15:33:52 -070087 return nullptr;
Yang Ni85d0cb12016-03-18 15:33:52 -070088}
89
90RsFile 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 Kralevich95e17022018-12-11 14:35:57 -080099 FILE *f = fopen(path, "rbe");
Yang Ni85d0cb12016-03-18 15:33:52 -0700100 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}