Script.java revision 21b4103e42cb0fa004cc4a978f49f63e7668ab0b
1/* 2 * Copyright (C) 2008 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/** 20 * 21 **/ 22public class Script extends BaseObj { 23 /** 24 * Only intended for use by generated reflected code. 25 * 26 * @param slot 27 */ 28 protected void invoke(int slot) { 29 mRS.nScriptInvoke(getID(), slot); 30 } 31 32 /** 33 * Only intended for use by generated reflected code. 34 * 35 * @param slot 36 * @param v 37 */ 38 protected void invoke(int slot, FieldPacker v) { 39 if (v != null) { 40 mRS.nScriptInvokeV(getID(), slot, v.getData()); 41 } else { 42 mRS.nScriptInvoke(getID(), slot); 43 } 44 } 45 46 47 Script(int id, RenderScript rs) { 48 super(id, rs); 49 } 50 51 52 /** 53 * Only intended for use by generated reflected code. 54 * 55 * @param va 56 * @param slot 57 */ 58 public void bindAllocation(Allocation va, int slot) { 59 mRS.validate(); 60 if (va != null) { 61 mRS.nScriptBindAllocation(getID(), va.getID(), slot); 62 } else { 63 mRS.nScriptBindAllocation(getID(), 0, slot); 64 } 65 } 66 67 /** 68 * Only intended for use by generated reflected code. 69 * 70 * @param index 71 * @param v 72 */ 73 public void setVar(int index, float v) { 74 mRS.nScriptSetVarF(getID(), index, v); 75 } 76 77 /** 78 * Only intended for use by generated reflected code. 79 * 80 * @param index 81 * @param v 82 */ 83 public void setVar(int index, double v) { 84 mRS.nScriptSetVarD(getID(), index, v); 85 } 86 87 /** 88 * Only intended for use by generated reflected code. 89 * 90 * @param index 91 * @param v 92 */ 93 public void setVar(int index, int v) { 94 mRS.nScriptSetVarI(getID(), index, v); 95 } 96 97 /** 98 * Only intended for use by generated reflected code. 99 * 100 * @param index 101 * @param v 102 */ 103 public void setVar(int index, long v) { 104 mRS.nScriptSetVarJ(getID(), index, v); 105 } 106 107 /** 108 * Only intended for use by generated reflected code. 109 * 110 * @param index 111 * @param v 112 */ 113 public void setVar(int index, boolean v) { 114 mRS.nScriptSetVarI(getID(), index, v ? 1 : 0); 115 } 116 117 /** 118 * Only intended for use by generated reflected code. 119 * 120 * @param index 121 * @param o 122 */ 123 public void setVar(int index, BaseObj o) { 124 mRS.nScriptSetVarObj(getID(), index, (o == null) ? 0 : o.getID()); 125 } 126 127 /** 128 * Only intended for use by generated reflected code. 129 * 130 * @param index 131 * @param v 132 */ 133 public void setVar(int index, FieldPacker v) { 134 mRS.nScriptSetVarV(getID(), index, v.getData()); 135 } 136 137 public void setTimeZone(String timeZone) { 138 mRS.validate(); 139 try { 140 mRS.nScriptSetTimeZone(getID(), timeZone.getBytes("UTF-8")); 141 } catch (java.io.UnsupportedEncodingException e) { 142 throw new RuntimeException(e); 143 } 144 } 145 146 public static class Builder { 147 RenderScript mRS; 148 149 Builder(RenderScript rs) { 150 mRS = rs; 151 } 152 } 153 154 155 public static class FieldBase { 156 protected Element mElement; 157 protected Allocation mAllocation; 158 159 protected void init(RenderScript rs, int dimx) { 160 mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT); 161 } 162 163 protected void init(RenderScript rs, int dimx, int usages) { 164 mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT | usages); 165 } 166 167 protected FieldBase() { 168 } 169 170 public Element getElement() { 171 return mElement; 172 } 173 174 public Type getType() { 175 return mAllocation.getType(); 176 } 177 178 public Allocation getAllocation() { 179 return mAllocation; 180 } 181 182 //@Override 183 public void updateAllocation() { 184 } 185 } 186} 187 188