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