Script.java revision 6f4cf0b8885403ead157ae00fd43cf1282331c23
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 * @hide 21 **/ 22public class Script extends BaseObj { 23 public static final int MAX_SLOT = 16; 24 25 boolean mIsRoot; 26 Type[] mTypes; 27 boolean[] mWritable; 28 Invokable[] mInvokables; 29 30 public static class Invokable { 31 RenderScript mRS; 32 Script mScript; 33 int mSlot; 34 String mName; 35 36 Invokable() { 37 mSlot = -1; 38 } 39 40 public void execute() { 41 mRS.nScriptInvoke(mScript.getID(), mSlot); 42 } 43 } 44 45 protected void invoke(int slot) { 46 mRS.nScriptInvoke(getID(), slot); 47 } 48 49 protected void invoke(int slot, FieldPacker v) { 50 if (v != null) { 51 mRS.nScriptInvokeV(getID(), slot, v.getData()); 52 } else { 53 mRS.nScriptInvoke(getID(), slot); 54 } 55 } 56 57 58 Script(int id, RenderScript rs) { 59 super(id, rs); 60 } 61 62 public void bindAllocation(Allocation va, int slot) { 63 mRS.validate(); 64 if (va != null) { 65 mRS.nScriptBindAllocation(getID(), va.getID(), slot); 66 } else { 67 mRS.nScriptBindAllocation(getID(), 0, slot); 68 } 69 } 70 71 public void setVar(int index, float v) { 72 mRS.nScriptSetVarF(getID(), index, v); 73 } 74 75 public void setVar(int index, double v) { 76 mRS.nScriptSetVarD(getID(), index, v); 77 } 78 79 public void setVar(int index, int v) { 80 mRS.nScriptSetVarI(getID(), index, v); 81 } 82 83 public void setVar(int index, long v) { 84 mRS.nScriptSetVarJ(getID(), index, v); 85 } 86 87 public void setVar(int index, boolean v) { 88 mRS.nScriptSetVarI(getID(), index, v ? 1 : 0); 89 } 90 91 public void setVar(int index, BaseObj o) { 92 mRS.nScriptSetVarObj(getID(), index, (o == null) ? 0 : o.getID()); 93 } 94 95 public void setVar(int index, FieldPacker v) { 96 mRS.nScriptSetVarV(getID(), index, v.getData()); 97 } 98 99 public void setTimeZone(String timeZone) { 100 mRS.validate(); 101 try { 102 mRS.nScriptSetTimeZone(getID(), timeZone.getBytes("UTF-8")); 103 } catch (java.io.UnsupportedEncodingException e) { 104 throw new RuntimeException(e); 105 } 106 } 107 108 public static class Builder { 109 RenderScript mRS; 110 111 Builder(RenderScript rs) { 112 mRS = rs; 113 } 114 } 115 116 117 public static class FieldBase { 118 protected Element mElement; 119 protected Allocation mAllocation; 120 121 protected void init(RenderScript rs, int dimx) { 122 mAllocation = Allocation.createSized(rs, mElement, dimx); 123 } 124 125 protected FieldBase() { 126 } 127 128 public Element getElement() { 129 return mElement; 130 } 131 132 public Type getType() { 133 return mAllocation.getType(); 134 } 135 136 public Allocation getAllocation() { 137 return mAllocation; 138 } 139 140 //@Override 141 public void updateAllocation() { 142 } 143 } 144} 145 146