Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 1 | /* |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 2 | * Copyright (C) 2008-2012 The Android Open Source Project |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 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 | package android.renderscript; |
| 18 | |
Artur Satayev | 2ebb31c | 2020-01-08 12:24:36 +0000 | [diff] [blame] | 19 | import android.compat.annotation.UnsupportedAppUsage; |
Austin Wang | a63a2c0 | 2019-12-19 06:38:19 +0000 | [diff] [blame] | 20 | import android.content.res.AssetManager; |
| 21 | import android.content.res.Resources; |
| 22 | |
Artur Satayev | 2ebb31c | 2020-01-08 12:24:36 +0000 | [diff] [blame] | 23 | import java.io.File; |
| 24 | import java.io.InputStream; |
| 25 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 26 | /** |
Tim Murray | a908422 | 2013-04-05 22:06:43 +0000 | [diff] [blame] | 27 | * @hide |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 28 | * @deprecated in API 16 |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 29 | * FileA3D allows users to load RenderScript objects from files |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 30 | * or resources stored on disk. It could be used to load items |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 31 | * such as 3D geometry data converted to a RenderScript format from |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 32 | * content creation tools. Currently only meshes are supported |
| 33 | * in FileA3D. |
| 34 | * |
| 35 | * When successfully loaded, FileA3D will contain a list of |
| 36 | * index entries for all the objects stored inside it. |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 37 | * |
| 38 | **/ |
| 39 | public class FileA3D extends BaseObj { |
| 40 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 41 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 42 | * @deprecated in API 16 |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 43 | * Specifies what renderscript object type is contained within |
| 44 | * the FileA3D IndexEntry |
| 45 | **/ |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 46 | public enum EntryType { |
| 47 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 48 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 49 | * @deprecated in API 16 |
Alex Sakhartchouk | ec0d335 | 2011-01-17 15:23:22 -0800 | [diff] [blame] | 50 | * Unknown or or invalid object, nothing will be loaded |
| 51 | **/ |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 52 | UNKNOWN (0), |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 53 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 54 | * @deprecated in API 16 |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 55 | * RenderScript Mesh object |
Alex Sakhartchouk | ec0d335 | 2011-01-17 15:23:22 -0800 | [diff] [blame] | 56 | **/ |
Mathew Inwood | 1532447 | 2018-08-06 11:18:49 +0100 | [diff] [blame] | 57 | @UnsupportedAppUsage |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 58 | MESH (1); |
| 59 | |
| 60 | int mID; |
| 61 | EntryType(int id) { |
| 62 | mID = id; |
| 63 | } |
| 64 | |
| 65 | static EntryType toEntryType(int intID) { |
| 66 | return EntryType.values()[intID]; |
| 67 | } |
| 68 | } |
| 69 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 70 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 71 | * @deprecated in API 16 |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 72 | * IndexEntry contains information about one of the RenderScript |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 73 | * objects inside the file's index. It could be used to query the |
Robert Ly | 11518ac | 2011-02-09 13:57:06 -0800 | [diff] [blame] | 74 | * object's type and also name and load the object itself if |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 75 | * necessary. |
| 76 | */ |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 77 | public static class IndexEntry { |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 78 | RenderScript mRS; |
| 79 | int mIndex; |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 80 | long mID; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 81 | String mName; |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 82 | EntryType mEntryType; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 83 | BaseObj mLoadedObj; |
| 84 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 85 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 86 | * @deprecated in API 16 |
Alex Sakhartchouk | ec0d335 | 2011-01-17 15:23:22 -0800 | [diff] [blame] | 87 | * Returns the name of a renderscript object the index entry |
| 88 | * describes |
| 89 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 90 | * @return name of a renderscript object the index entry |
Alex Sakhartchouk | ec0d335 | 2011-01-17 15:23:22 -0800 | [diff] [blame] | 91 | * describes |
| 92 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 93 | */ |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 94 | public String getName() { |
| 95 | return mName; |
| 96 | } |
| 97 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 98 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 99 | * @deprecated in API 16 |
Alex Sakhartchouk | ec0d335 | 2011-01-17 15:23:22 -0800 | [diff] [blame] | 100 | * Returns the type of a renderscript object the index entry |
| 101 | * describes |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 102 | * @return type of a renderscript object the index entry |
| 103 | * describes |
| 104 | */ |
Mathew Inwood | 1532447 | 2018-08-06 11:18:49 +0100 | [diff] [blame] | 105 | @UnsupportedAppUsage |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 106 | public EntryType getEntryType() { |
| 107 | return mEntryType; |
| 108 | } |
| 109 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 110 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 111 | * @deprecated in API 16 |
Alex Sakhartchouk | ec0d335 | 2011-01-17 15:23:22 -0800 | [diff] [blame] | 112 | * Used to load the object described by the index entry |
| 113 | * @return base renderscript object described by the entry |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 114 | */ |
Mathew Inwood | 1532447 | 2018-08-06 11:18:49 +0100 | [diff] [blame] | 115 | @UnsupportedAppUsage |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 116 | public BaseObj getObject() { |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 117 | mRS.validate(); |
| 118 | BaseObj obj = internalCreate(mRS, this); |
| 119 | return obj; |
| 120 | } |
| 121 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 122 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 123 | * @deprecated in API 16 |
Alex Sakhartchouk | ec0d335 | 2011-01-17 15:23:22 -0800 | [diff] [blame] | 124 | * Used to load the mesh described by the index entry, object |
| 125 | * described by the index entry must be a renderscript mesh |
| 126 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 127 | * @return renderscript mesh object described by the entry |
| 128 | */ |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 129 | public Mesh getMesh() { |
| 130 | return (Mesh)getObject(); |
| 131 | } |
| 132 | |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 133 | static synchronized BaseObj internalCreate(RenderScript rs, IndexEntry entry) { |
| 134 | if(entry.mLoadedObj != null) { |
| 135 | return entry.mLoadedObj; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 138 | // to be purged on cleanup |
| 139 | if(entry.mEntryType == EntryType.UNKNOWN) { |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 140 | return null; |
| 141 | } |
| 142 | |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 143 | long objectID = rs.nFileA3DGetEntryByIndex(entry.mID, entry.mIndex); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 144 | if(objectID == 0) { |
| 145 | return null; |
| 146 | } |
| 147 | |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 148 | switch (entry.mEntryType) { |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 149 | case MESH: |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 150 | entry.mLoadedObj = new Mesh(objectID, rs); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 151 | break; |
Jason Sams | bca8e6d | 2015-03-26 15:29:56 -0700 | [diff] [blame] | 152 | |
| 153 | default: |
| 154 | throw new RSRuntimeException("Unrecognized object type in file."); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 157 | entry.mLoadedObj.updateFromNative(); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 158 | return entry.mLoadedObj; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 161 | IndexEntry(RenderScript rs, int index, long id, String name, EntryType type) { |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 162 | mRS = rs; |
| 163 | mIndex = index; |
| 164 | mID = id; |
| 165 | mName = name; |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 166 | mEntryType = type; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 167 | mLoadedObj = null; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | IndexEntry[] mFileEntries; |
Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 172 | InputStream mInputStream; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 173 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 174 | FileA3D(long id, RenderScript rs, InputStream stream) { |
Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 175 | super(id, rs); |
Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 176 | mInputStream = stream; |
Yang Ni | eb4dd08 | 2016-03-24 09:40:32 -0700 | [diff] [blame] | 177 | guard.open("destroy"); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | private void initEntries() { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 181 | int numFileEntries = mRS.nFileA3DGetNumIndexEntries(getID(mRS)); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 182 | if(numFileEntries <= 0) { |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | mFileEntries = new IndexEntry[numFileEntries]; |
| 187 | int[] ids = new int[numFileEntries]; |
| 188 | String[] names = new String[numFileEntries]; |
| 189 | |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 190 | mRS.nFileA3DGetIndexEntries(getID(mRS), numFileEntries, ids, names); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 191 | |
| 192 | for(int i = 0; i < numFileEntries; i ++) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 193 | mFileEntries[i] = new IndexEntry(mRS, i, getID(mRS), names[i], EntryType.toEntryType(ids[i])); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 197 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 198 | * @deprecated in API 16 |
Alex Sakhartchouk | ec0d335 | 2011-01-17 15:23:22 -0800 | [diff] [blame] | 199 | * Returns the number of objects stored inside the a3d file |
| 200 | * |
| 201 | * @return the number of objects stored inside the a3d file |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 202 | */ |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 203 | public int getIndexEntryCount() { |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 204 | if(mFileEntries == null) { |
| 205 | return 0; |
| 206 | } |
| 207 | return mFileEntries.length; |
| 208 | } |
| 209 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 210 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 211 | * @deprecated in API 16 |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 212 | * Returns an index entry from the list of all objects inside |
| 213 | * FileA3D |
| 214 | * |
| 215 | * @param index number of the entry from the list to return |
Alex Sakhartchouk | ec0d335 | 2011-01-17 15:23:22 -0800 | [diff] [blame] | 216 | * |
| 217 | * @return entry in the a3d file described by the index |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 218 | */ |
Mathew Inwood | 1532447 | 2018-08-06 11:18:49 +0100 | [diff] [blame] | 219 | @UnsupportedAppUsage |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 220 | public IndexEntry getIndexEntry(int index) { |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 221 | if(getIndexEntryCount() == 0 || index < 0 || index >= mFileEntries.length) { |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 222 | return null; |
| 223 | } |
| 224 | return mFileEntries[index]; |
| 225 | } |
| 226 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 227 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 228 | * @deprecated in API 16 |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 229 | * Creates a FileA3D object from an asset stored on disk |
| 230 | * |
| 231 | * @param rs Context to which the object will belong. |
| 232 | * @param mgr asset manager used to load asset |
| 233 | * @param path location of the file to load |
| 234 | * |
Alex Sakhartchouk | ec0d335 | 2011-01-17 15:23:22 -0800 | [diff] [blame] | 235 | * @return a3d file containing renderscript objects |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 236 | */ |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 237 | static public FileA3D createFromAsset(RenderScript rs, AssetManager mgr, String path) { |
| 238 | rs.validate(); |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 239 | long fileId = rs.nFileA3DCreateFromAsset(mgr, path); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 240 | |
| 241 | if(fileId == 0) { |
| 242 | throw new RSRuntimeException("Unable to create a3d file from asset " + path); |
| 243 | } |
| 244 | FileA3D fa3d = new FileA3D(fileId, rs, null); |
| 245 | fa3d.initEntries(); |
| 246 | return fa3d; |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 249 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 250 | * @deprecated in API 16 |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 251 | * Creates a FileA3D object from a file stored on disk |
| 252 | * |
| 253 | * @param rs Context to which the object will belong. |
| 254 | * @param path location of the file to load |
| 255 | * |
Alex Sakhartchouk | ec0d335 | 2011-01-17 15:23:22 -0800 | [diff] [blame] | 256 | * @return a3d file containing renderscript objects |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 257 | */ |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 258 | static public FileA3D createFromFile(RenderScript rs, String path) { |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 259 | long fileId = rs.nFileA3DCreateFromFile(path); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 260 | |
| 261 | if(fileId == 0) { |
| 262 | throw new RSRuntimeException("Unable to create a3d file from " + path); |
| 263 | } |
| 264 | FileA3D fa3d = new FileA3D(fileId, rs, null); |
| 265 | fa3d.initEntries(); |
| 266 | return fa3d; |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 269 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 270 | * @deprecated in API 16 |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 271 | * Creates a FileA3D object from a file stored on disk |
| 272 | * |
| 273 | * @param rs Context to which the object will belong. |
| 274 | * @param path location of the file to load |
| 275 | * |
Alex Sakhartchouk | ec0d335 | 2011-01-17 15:23:22 -0800 | [diff] [blame] | 276 | * @return a3d file containing renderscript objects |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 277 | */ |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 278 | static public FileA3D createFromFile(RenderScript rs, File path) { |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 279 | return createFromFile(rs, path.getAbsolutePath()); |
| 280 | } |
| 281 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 282 | /** |
Jason Sams | 65c80f8 | 2012-05-08 17:30:26 -0700 | [diff] [blame] | 283 | * @deprecated in API 16 |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 284 | * Creates a FileA3D object from an application resource |
| 285 | * |
| 286 | * @param rs Context to which the object will belong. |
| 287 | * @param res resource manager used for loading |
| 288 | * @param id resource to create FileA3D from |
| 289 | * |
Alex Sakhartchouk | ec0d335 | 2011-01-17 15:23:22 -0800 | [diff] [blame] | 290 | * @return a3d file containing renderscript objects |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 291 | */ |
Mathew Inwood | 1532447 | 2018-08-06 11:18:49 +0100 | [diff] [blame] | 292 | @UnsupportedAppUsage |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 293 | static public FileA3D createFromResource(RenderScript rs, Resources res, int id) { |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 294 | |
| 295 | rs.validate(); |
| 296 | InputStream is = null; |
| 297 | try { |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 298 | is = res.openRawResource(id); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 299 | } catch (Exception e) { |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 300 | throw new RSRuntimeException("Unable to open resource " + id); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 303 | long fileId = 0; |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 304 | if (is instanceof AssetManager.AssetInputStream) { |
Ashok Bhat | 0e0c088 | 2014-02-04 14:57:58 +0000 | [diff] [blame] | 305 | long asset = ((AssetManager.AssetInputStream) is).getNativeAsset(); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 306 | fileId = rs.nFileA3DCreateFromAssetStream(asset); |
| 307 | } else { |
| 308 | throw new RSRuntimeException("Unsupported asset stream"); |
| 309 | } |
| 310 | |
| 311 | if(fileId == 0) { |
| 312 | throw new RSRuntimeException("Unable to create a3d file from resource " + id); |
| 313 | } |
| 314 | FileA3D fa3d = new FileA3D(fileId, rs, is); |
| 315 | fa3d.initEntries(); |
| 316 | return fa3d; |
| 317 | |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 318 | } |
| 319 | } |