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