blob: 632a459069a56a7323e683df61e22821475e58c7 [file] [log] [blame]
Jason Sams69f0d312009-08-03 18:11:17 -07001/*
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 {
Jason Samsfbf0b9e2009-08-13 12:59:04 -070023 public static final int MAX_SLOT = 16;
24
Jason Sams69f0d312009-08-03 18:11:17 -070025 boolean mIsRoot;
Jason Sams43ee06852009-08-12 17:54:11 -070026 Type[] mTypes;
Jason Sams334ea0c2009-08-17 13:56:09 -070027 boolean[] mWritable;
Jason Samsbe2e8412009-09-16 15:04:38 -070028 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.mID, mSlot);
42 }
43 }
Jason Sams69f0d312009-08-03 18:11:17 -070044
Jason Sams2d71bc72010-03-26 16:06:43 -070045 protected void invoke(int slot) {
46 mRS.nScriptInvoke(mID, slot);
47 }
48
Jason Sams4d339932010-05-11 14:03:58 -070049 protected void invokeData(int slot) {
50 mRS.nScriptInvokeData(mID, slot);
51 }
52
53 protected void invokeV(int slot, FieldPacker v) {
54 mRS.nScriptInvokeV(mID, slot, v.getData());
55 }
56
57
Jason Sams69f0d312009-08-03 18:11:17 -070058 Script(int id, RenderScript rs) {
59 super(rs);
60 mID = id;
61 }
62
Jason Sams69f0d312009-08-03 18:11:17 -070063 public void bindAllocation(Allocation va, int slot) {
Jason Sams771bebb2009-12-07 12:40:12 -080064 mRS.validate();
Jason Sams4d339932010-05-11 14:03:58 -070065 if (va != null) {
66 mRS.nScriptBindAllocation(mID, va.mID, slot);
67 } else {
68 mRS.nScriptBindAllocation(mID, 0, slot);
69 }
70 }
71
72 public void setVar(int index, float v) {
73 mRS.nScriptSetVarF(mID, index, v);
74 }
75
76 public void setVar(int index, int v) {
77 mRS.nScriptSetVarI(mID, index, v);
78 }
79
80 public void setVar(int index, FieldPacker v) {
81 mRS.nScriptSetVarV(mID, index, v.getData());
Jason Sams69f0d312009-08-03 18:11:17 -070082 }
83
84 public void setClearColor(float r, float g, float b, float a) {
Jason Sams771bebb2009-12-07 12:40:12 -080085 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -070086 mRS.nScriptSetClearColor(mID, r, g, b, a);
Jason Sams69f0d312009-08-03 18:11:17 -070087 }
88
89 public void setClearDepth(float d) {
Jason Sams771bebb2009-12-07 12:40:12 -080090 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -070091 mRS.nScriptSetClearDepth(mID, d);
Jason Sams69f0d312009-08-03 18:11:17 -070092 }
93
94 public void setClearStencil(int stencil) {
Jason Sams771bebb2009-12-07 12:40:12 -080095 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -070096 mRS.nScriptSetClearStencil(mID, stencil);
Jason Sams69f0d312009-08-03 18:11:17 -070097 }
98
Jason Sams22534172009-08-04 16:58:20 -070099 public void setTimeZone(String timeZone) {
Jason Sams771bebb2009-12-07 12:40:12 -0800100 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -0700101 try {
102 mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8"));
103 } catch (java.io.UnsupportedEncodingException e) {
104 throw new RuntimeException(e);
105 }
106 }
Jason Sams69f0d312009-08-03 18:11:17 -0700107
108 public static class Builder {
109 RenderScript mRS;
Jason Sams69f0d312009-08-03 18:11:17 -0700110
111 Builder(RenderScript rs) {
112 mRS = rs;
113 }
Jason Sams69f0d312009-08-03 18:11:17 -0700114 }
115
Jason Sams2d71bc72010-03-26 16:06:43 -0700116
117 public static class FieldBase {
118 protected Element mElement;
119 protected Type mType;
120 protected Allocation mAllocation;
121
122 protected void init(RenderScript rs, int dimx) {
123 mAllocation = Allocation.createSized(rs, mElement, dimx);
124 mType = mAllocation.getType();
125 }
126
127 protected FieldBase() {
128 }
129
130 public Element getElement() {
131 return mElement;
132 }
133
134 public Type getType() {
135 return mType;
136 }
137
138 public Allocation getAllocation() {
139 return mAllocation;
140 }
141
142 //@Override
143 public void updateAllocation() {
144 }
145
146
147 //
148 /*
149 public class ScriptField_UserField
150 extends android.renderscript.Script.FieldBase {
151
152 protected
153
154 }
155
156 */
157
158 }
Jason Sams69f0d312009-08-03 18:11:17 -0700159}
160