| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.renderscript; |
| 18 |
|
| 19 |
import android.content.res.Resources; |
| 20 |
|
| 21 |
import java.io.File; |
| 22 |
import java.io.IOException; |
| 23 |
import java.io.InputStream; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
@Deprecated |
| 34 |
public class ScriptC extends Script { |
| 35 |
private static final String TAG = "ScriptC"; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
protected ScriptC(int id, RenderScript rs) { |
| 44 |
super(id, rs); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
protected ScriptC(long id, RenderScript rs) { |
| 54 |
super(id, rs); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
protected ScriptC(RenderScript rs, Resources resources, int resourceID) { |
| 65 |
super(0, rs); |
| 66 |
long id = internalCreate(rs, resources, resourceID); |
| 67 |
if (id == 0) { |
| 68 |
throw new RSRuntimeException("Loading of ScriptC script failed."); |
| 69 |
} |
| 70 |
setID(id); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
protected ScriptC(RenderScript rs, String resName, byte[] bitcode32, byte[] bitcode64) { |
| 79 |
super(0, rs); |
| 80 |
long id = 0; |
| 81 |
if (RenderScript.sPointerSize == 4) { |
| 82 |
id = internalStringCreate(rs, resName, bitcode32); |
| 83 |
} else { |
| 84 |
id = internalStringCreate(rs, resName, bitcode64); |
| 85 |
} |
| 86 |
if (id == 0) { |
| 87 |
throw new RSRuntimeException("Loading of ScriptC script failed."); |
| 88 |
} |
| 89 |
setID(id); |
| 90 |
} |
| 91 |
|
| 92 |
private static synchronized long internalCreate(RenderScript rs, Resources resources, int resourceID) { |
| 93 |
byte[] pgm; |
| 94 |
int pgmLength; |
| 95 |
InputStream is = resources.openRawResource(resourceID); |
| 96 |
try { |
| 97 |
try { |
| 98 |
pgm = new byte[1024]; |
| 99 |
pgmLength = 0; |
| 100 |
while(true) { |
| 101 |
int bytesLeft = pgm.length - pgmLength; |
| 102 |
if (bytesLeft == 0) { |
| 103 |
byte[] buf2 = new byte[pgm.length * 2]; |
| 104 |
System.arraycopy(pgm, 0, buf2, 0, pgm.length); |
| 105 |
pgm = buf2; |
| 106 |
bytesLeft = pgm.length - pgmLength; |
| 107 |
} |
| 108 |
int bytesRead = is.read(pgm, pgmLength, bytesLeft); |
| 109 |
if (bytesRead <= 0) { |
| 110 |
break; |
| 111 |
} |
| 112 |
pgmLength += bytesRead; |
| 113 |
} |
| 114 |
} finally { |
| 115 |
is.close(); |
| 116 |
} |
| 117 |
} catch(IOException e) { |
| 118 |
throw new Resources.NotFoundException(); |
| 119 |
} |
| 120 |
|
| 121 |
String resName = resources.getResourceEntryName(resourceID); |
| 122 |
|
| 123 |
|
| 124 |
return rs.nScriptCCreate(resName, RenderScript.getCachePath(), pgm, pgmLength); |
| 125 |
} |
| 126 |
|
| 127 |
private static synchronized long internalStringCreate(RenderScript rs, String resName, byte[] bitcode) { |
| 128 |
|
| 129 |
return rs.nScriptCCreate(resName, RenderScript.getCachePath(), bitcode, bitcode.length); |
| 130 |
} |
| 131 |
} |