ScriptCThunker.java revision 099deb8fb1715e62bcb24513f8e9305ab4f7743a
1/* 2 * Copyright (C) 2013 The Android Open Source Project 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 17package android.support.v8.renderscript; 18 19import android.content.Context; 20import android.content.res.Resources; 21import android.util.Log; 22 23import java.io.File; 24import java.io.IOException; 25import java.io.InputStream; 26import java.util.Map.Entry; 27import java.util.HashMap; 28 29import java.lang.reflect.Field; 30import java.lang.reflect.Modifier; 31 32/** 33 * 34 **/ 35class ScriptCThunker extends android.renderscript.ScriptC { 36 private static final String TAG = "ScriptC"; 37 38 protected ScriptCThunker(RenderScriptThunker rs, Resources resources, int resourceID) { 39 super(rs.mN, resources, resourceID); 40 } 41 42 android.renderscript.Script.KernelID thunkCreateKernelID( 43 int slot, int sig, Element ein, Element eout) { 44 45 android.renderscript.Element nein = null; 46 android.renderscript.Element neout = null; 47 if (ein != null) { 48 nein = ((ElementThunker)ein).mN; 49 } 50 if (eout != null) { 51 neout = ((ElementThunker)eout).mN; 52 } 53 return createKernelID(slot, sig, nein, neout); 54 } 55 56 57 void thunkInvoke(int slot) { 58 invoke(slot); 59 } 60 61 void thunkBindAllocation(Allocation va, int slot) { 62 android.renderscript.Allocation nva = null; 63 if (va != null) { 64 nva = ((AllocationThunker)va).mN; 65 } 66 bindAllocation(nva, slot); 67 } 68 69 void thunkSetTimeZone(String timeZone) { 70 setTimeZone(timeZone); 71 } 72 73 void thunkInvoke(int slot, FieldPacker v) { 74 android.renderscript.FieldPacker nfp = 75 new android.renderscript.FieldPacker(v.getData()); 76 invoke(slot, nfp); 77 } 78 79 void thunkForEach(int slot, Allocation ain, Allocation aout, FieldPacker v) { 80 android.renderscript.Allocation nin = null; 81 android.renderscript.Allocation nout = null; 82 android.renderscript.FieldPacker nfp = null; 83 if (ain != null) { 84 nin = ((AllocationThunker)ain).mN; 85 } 86 if (aout != null) { 87 nout = ((AllocationThunker)aout).mN; 88 } 89 if (v != null) { 90 nfp = new android.renderscript.FieldPacker(v.getData()); 91 } 92 forEach(slot, nin, nout, nfp); 93 } 94 95 void thunkForEach(int slot, Allocation ain, Allocation aout, FieldPacker v, 96 android.support.v8.renderscript.Script.LaunchOptions sc) { 97 android.renderscript.Script.LaunchOptions lo = null; 98 if (sc != null) { 99 lo = new android.renderscript.Script.LaunchOptions(); 100 if (sc.getXEnd() > 0) lo.setX(sc.getXStart(), sc.getXEnd()); 101 if (sc.getYEnd() > 0) lo.setY(sc.getYStart(), sc.getYEnd()); 102 if (sc.getZEnd() > 0) lo.setZ(sc.getZStart(), sc.getZEnd()); 103 } 104 105 android.renderscript.Allocation nin = null; 106 android.renderscript.Allocation nout = null; 107 android.renderscript.FieldPacker nfp = null; 108 if (ain != null) { 109 nin = ((AllocationThunker)ain).mN; 110 } 111 if (aout != null) { 112 nout = ((AllocationThunker)aout).mN; 113 } 114 if (v != null) { 115 nfp = new android.renderscript.FieldPacker(v.getData()); 116 } 117 forEach(slot, nin, nout, nfp, lo); 118 } 119 120 void thunkSetVar(int index, float v) { 121 setVar(index, v); 122 } 123 void thunkSetVar(int index, double v) { 124 setVar(index, v); 125 } 126 void thunkSetVar(int index, int v) { 127 setVar(index, v); 128 } 129 void thunkSetVar(int index, long v) { 130 setVar(index, v); 131 } 132 void thunkSetVar(int index, boolean v) { 133 setVar(index, v); 134 } 135 136 void thunkSetVar(int index, BaseObj o) { 137 if (o == null) { 138 setVar(index, 0); 139 return; 140 } 141 setVar(index, o.getNObj()); 142 } 143 void thunkSetVar(int index, FieldPacker v) { 144 android.renderscript.FieldPacker nfp = 145 new android.renderscript.FieldPacker(v.getData()); 146 setVar(index, nfp); 147 } 148 149 void thunkSetVar(int index, FieldPacker v, Element e, int[] dims) { 150 android.renderscript.FieldPacker nfp = 151 new android.renderscript.FieldPacker(v.getData()); 152 ElementThunker et = (ElementThunker)e; 153 setVar(index, nfp, et.mN, dims); 154 } 155 156 android.renderscript.Script.FieldID thunkCreateFieldID(int slot, Element e) { 157 ElementThunker et = (ElementThunker) e; 158 return createFieldID(slot, et.getNObj()); 159 } 160 161} 162