-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsApiFileA3D.cpp
119 lines (98 loc) · 3.32 KB
/
rsApiFileA3D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "rsContext.h"
#include "rsFileA3D.h"
using android::Asset;
using android::renderscript::Context;
using android::renderscript::FileA3D;
using android::renderscript::ObjectBase;
using android::renderscript::rsuCopyString;
RsObjectBase rsaFileA3DGetEntryByIndex(RsContext con, uint32_t index, RsFile file) {
FileA3D *fa3d = static_cast<FileA3D *>(file);
if (!fa3d) {
ALOGE("Can't load entry. No valid file");
return nullptr;
}
ObjectBase *obj = fa3d->initializeFromEntry(index);
//ALOGV("Returning object with name %s", obj->getName());
return obj;
}
void rsaFileA3DGetNumIndexEntries(RsContext con, int32_t *numEntries, RsFile file) {
FileA3D *fa3d = static_cast<FileA3D *>(file);
if (fa3d) {
*numEntries = fa3d->getNumIndexEntries();
} else {
*numEntries = 0;
}
}
void rsaFileA3DGetIndexEntries(RsContext con, RsFileIndexEntry *fileEntries, uint32_t numEntries, RsFile file) {
FileA3D *fa3d = static_cast<FileA3D *>(file);
if (!fa3d) {
ALOGE("Can't load index entries. No valid file");
return;
}
uint32_t numFileEntries = fa3d->getNumIndexEntries();
if (numFileEntries != numEntries || numEntries == 0 || fileEntries == nullptr) {
ALOGE("Can't load index entries. Invalid number requested");
return;
}
for (uint32_t i = 0; i < numFileEntries; i ++) {
const FileA3D::A3DIndexEntry *entry = fa3d->getIndexEntry(i);
fileEntries[i].classID = entry->getType();
fileEntries[i].objectName = rsuCopyString(entry->getObjectName());
}
}
RsFile rsaFileA3DCreateFromMemory(RsContext con, const void *data, uint32_t len) {
if (data == nullptr) {
ALOGE("File load failed. Asset stream is nullptr");
return nullptr;
}
Context *rsc = static_cast<Context *>(con);
FileA3D *fa3d = new FileA3D(rsc);
fa3d->incUserRef();
fa3d->load(data, len);
return fa3d;
}
RsFile rsaFileA3DCreateFromAsset(RsContext con, void *_asset) {
#if !defined(__RS_PDK__)
Context *rsc = static_cast<Context *>(con);
Asset *asset = static_cast<Asset *>(_asset);
FileA3D *fa3d = new FileA3D(rsc);
fa3d->incUserRef();
fa3d->load(asset);
return fa3d;
#else
return nullptr;
#endif
}
RsFile rsaFileA3DCreateFromFile(RsContext con, const char *path) {
if (path == nullptr) {
ALOGE("File load failed. Path is nullptr");
return nullptr;
}
Context *rsc = static_cast<Context *>(con);
FileA3D *fa3d = nullptr;
FILE *f = fopen(path, "rb");
if (f) {
fa3d = new FileA3D(rsc);
fa3d->incUserRef();
fa3d->load(f);
fclose(f);
} else {
ALOGE("Could not open file %s", path);
}
return fa3d;
}