1/* 2 * Copyright (C) 2012 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.renderscript; 18 19 20import java.lang.reflect.Field; 21import java.lang.Class; 22import java.lang.reflect.Method; 23import java.lang.reflect.Constructor; 24 25import android.util.Log; 26 27class RSReflect { 28 Class mElement; 29 Class mElementBuilder; 30 Class mElementDataType; 31 Class mElementDataKind; 32 Method mElement_createUser; 33 Method mElement_createVector; 34 Method mElement_createPixel; 35 Constructor mElementBuilder_constructor; 36 Method mElementBuilder_add; 37 Method mElementBuilder_create; 38 39 Class mType; 40 Class mTypeBuilder; 41 Class mTypeCubemapFace; 42 Constructor mTypeBuilder_constructor; 43 Method mTypeBuilder_setX; 44 Method mTypeBuilder_setY; 45 Method mTypeBuilder_setMipmaps; 46 Method mTypeBuilder_setFaces; 47 48 Class mAllocation; 49 Class mAllocationMipmapControl; 50 Method mAllocation_syncAll; 51 Method mAllocation_copyFrom_O; 52 Method mAllocation_copyFromUnchecked_I; 53 Method mAllocation_copyFromUnchecked_S; 54 Method mAllocation_copyFromUnchecked_B; 55 Method mAllocation_copyFromUnchecked_F; 56 Method mAllocation_copyFrom_I; 57 Method mAllocation_copyFrom_S; 58 Method mAllocation_copyFrom_B; 59 Method mAllocation_copyFrom_F; 60 Method mAllocation_setFromFieldPacker; 61 Method mAllocation_setFromFieldPacker_component; 62 Method mAllocation_generateMipmaps; 63 Method mAllocation_copy1DRangeFromUnchecked; 64 65 66 Class mBaseObj; 67 Class mRenderScript; 68 Class mSampler; 69 Class mScript; 70 Class mScriptC; 71 Class mScriptGroup; 72 73 74 private RSReflect() { 75 } 76 77 private boolean init() { 78 try { 79 Method m[]; 80 81 mElement = Class.forName("android.renderscript.Element"); 82 mElementBuilder = Class.forName("android.renderscript.Element$Builder"); 83 mElementDataType = Class.forName("android.renderscript.Element$DataType"); 84 mElementDataKind = Class.forName("android.renderscript.Element$DataKind"); 85 86 mType = Class.forName("android.renderscript.Type"); 87 mTypeBuilder = Class.forName("android.renderscript.Type$Builder"); 88 mTypeCubemapFace = Class.forName("android.renderscript.Type$CubemapFace"); 89 90 mAllocation = Class.forName("android.renderscript.Allocation"); 91 mBaseObj = Class.forName("android.renderscript.BaseObj"); 92 mRenderScript = Class.forName("android.renderscript.RenderScript"); 93 mSampler = Class.forName("android.renderscript.Sampler"); 94 mScript = Class.forName("android.renderscript.Script"); 95 mScriptC = Class.forName("android.renderscript.ScriptC"); 96 97 mElement_createUser = mElement.getDeclaredMethod("createUser", 98 new Class[] { mRenderScript, mElementDataType }); 99 mElement_createVector = mElement.getDeclaredMethod("createVector", 100 new Class[] { mRenderScript, mElementDataType, Integer.TYPE }); 101 mElement_createPixel = mElement.getDeclaredMethod("createPixel", 102 new Class[] { mRenderScript, mElementDataType, mElementDataKind }); 103 mElementBuilder_constructor = mElementBuilder.getDeclaredConstructor( 104 new Class[] { mRenderScript }); 105 mElementBuilder_add = mElementBuilder.getDeclaredMethod("add", 106 new Class[] { mElement, String.class, Integer.TYPE }); 107 mElementBuilder_create = mElementBuilder.getDeclaredMethod("create", 108 new Class[] {}); 109 110 mTypeBuilder_constructor = mTypeBuilder.getDeclaredConstructor( 111 new Class[] { mRenderScript, mElement }); 112 mTypeBuilder_setX = mTypeBuilder.getDeclaredMethod("setX", 113 new Class[] { Integer.TYPE }); 114 mTypeBuilder_setY = mTypeBuilder.getDeclaredMethod("setY", 115 new Class[] { Integer.TYPE }); 116 mTypeBuilder_setMipmaps = mTypeBuilder.getDeclaredMethod("setMipmaps", 117 new Class[] { Boolean.TYPE }); 118 mTypeBuilder_setFaces = mTypeBuilder.getDeclaredMethod("setFaces", 119 new Class[] { Boolean.TYPE }); 120 121 122 123 124 125 //mScriptGroup = Class.forName("android.renderscript.Element"); 126 127 128 } catch (Throwable e) { 129 android.util.Log.w("RSR", "Using native RS failed. " + e); 130 return false; 131 } 132 return true; 133 } 134 135 static RSReflect create() { 136 android.util.Log.v("RSR", "create"); 137 RSReflect r = new RSReflect(); 138 if (r.init()) { 139 android.util.Log.v("RSR", "create ok"); 140 return r; 141 } 142 android.util.Log.v("RSR", "create fail"); 143 return null; 144 } 145 146 private Method findMethod(Method m[], String name) { 147 for (int ct=0; ct < m.length; ct++) { 148 if (m[ct].getName().equals(name)) { 149 return m[ct]; 150 } 151 } 152 return null; 153 } 154 155 156 //Class c = Class.forName("java.lang.String"); 157 158} 159