blob: 11aa13476bff74e7709d9d3b2a2e5a8426d84d5c [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/**
Jason Samsa23d4e72011-01-04 18:59:12 -080020 *
Jason Sams69f0d312009-08-03 18:11:17 -070021 **/
22public class Script extends BaseObj {
Jason Sams67e3d202011-01-09 13:49:01 -080023 /**
Jason Sams67e3d202011-01-09 13:49:01 -080024 * Only intended for use by generated reflected code.
25 *
26 * @param slot
27 */
Jason Sams2d71bc72010-03-26 16:06:43 -070028 protected void invoke(int slot) {
Jason Sams06d69de2010-11-09 17:11:40 -080029 mRS.nScriptInvoke(getID(), slot);
Jason Sams2d71bc72010-03-26 16:06:43 -070030 }
31
Jason Sams67e3d202011-01-09 13:49:01 -080032 /**
Jason Sams67e3d202011-01-09 13:49:01 -080033 * Only intended for use by generated reflected code.
34 *
35 * @param slot
36 * @param v
37 */
Jason Sams96ed4cf2010-06-15 12:15:57 -070038 protected void invoke(int slot, FieldPacker v) {
39 if (v != null) {
Jason Sams06d69de2010-11-09 17:11:40 -080040 mRS.nScriptInvokeV(getID(), slot, v.getData());
Jason Sams96ed4cf2010-06-15 12:15:57 -070041 } else {
Jason Sams06d69de2010-11-09 17:11:40 -080042 mRS.nScriptInvoke(getID(), slot);
Jason Sams96ed4cf2010-06-15 12:15:57 -070043 }
Jason Sams4d339932010-05-11 14:03:58 -070044 }
45
Jason Sams6e494d32011-04-27 16:33:11 -070046 /**
47 * @hide
48 * Only intended for use by generated reflected code.
49 *
50 * @param slot
51 * @param ain
52 * @param aout
53 * @param v
54 */
55 protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v) {
56 if (ain == null && aout == null) {
57 throw new RSIllegalArgumentException(
58 "At least one of ain or aout is required to be non-null.");
59 }
60 int in_id = 0;
61 if (ain != null) {
62 in_id = ain.getID();
63 }
64 int out_id = 0;
65 if (aout != null) {
66 out_id = aout.getID();
67 }
68 byte[] params = null;
69 if (v != null) {
70 params = v.getData();
71 }
72 mRS.nScriptForEach(getID(), slot, in_id, out_id, params);
73 }
74
Jason Sams4d339932010-05-11 14:03:58 -070075
Jason Sams69f0d312009-08-03 18:11:17 -070076 Script(int id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -070077 super(id, rs);
Jason Sams69f0d312009-08-03 18:11:17 -070078 }
79
Jason Sams67e3d202011-01-09 13:49:01 -080080
81 /**
Jason Sams67e3d202011-01-09 13:49:01 -080082 * Only intended for use by generated reflected code.
83 *
84 * @param va
85 * @param slot
86 */
Jason Sams69f0d312009-08-03 18:11:17 -070087 public void bindAllocation(Allocation va, int slot) {
Jason Sams771bebb2009-12-07 12:40:12 -080088 mRS.validate();
Jason Sams4d339932010-05-11 14:03:58 -070089 if (va != null) {
Jason Sams06d69de2010-11-09 17:11:40 -080090 mRS.nScriptBindAllocation(getID(), va.getID(), slot);
Jason Sams4d339932010-05-11 14:03:58 -070091 } else {
Jason Sams06d69de2010-11-09 17:11:40 -080092 mRS.nScriptBindAllocation(getID(), 0, slot);
Jason Sams4d339932010-05-11 14:03:58 -070093 }
94 }
95
Jason Sams67e3d202011-01-09 13:49:01 -080096 /**
Jason Sams67e3d202011-01-09 13:49:01 -080097 * Only intended for use by generated reflected code.
98 *
99 * @param index
100 * @param v
101 */
Jason Sams4d339932010-05-11 14:03:58 -0700102 public void setVar(int index, float v) {
Jason Sams06d69de2010-11-09 17:11:40 -0800103 mRS.nScriptSetVarF(getID(), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700104 }
105
Jason Sams67e3d202011-01-09 13:49:01 -0800106 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800107 * Only intended for use by generated reflected code.
108 *
109 * @param index
110 * @param v
111 */
Stephen Hinesca54ec32010-09-20 17:20:30 -0700112 public void setVar(int index, double v) {
Jason Sams06d69de2010-11-09 17:11:40 -0800113 mRS.nScriptSetVarD(getID(), index, v);
Stephen Hinesca54ec32010-09-20 17:20:30 -0700114 }
115
Jason Sams67e3d202011-01-09 13:49:01 -0800116 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800117 * Only intended for use by generated reflected code.
118 *
119 * @param index
120 * @param v
121 */
Jason Sams4d339932010-05-11 14:03:58 -0700122 public void setVar(int index, int v) {
Jason Sams06d69de2010-11-09 17:11:40 -0800123 mRS.nScriptSetVarI(getID(), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700124 }
125
Jason Sams67e3d202011-01-09 13:49:01 -0800126 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800127 * Only intended for use by generated reflected code.
128 *
129 * @param index
130 * @param v
131 */
Stephen Hines031ec58c2010-10-11 10:54:21 -0700132 public void setVar(int index, long v) {
Jason Sams06d69de2010-11-09 17:11:40 -0800133 mRS.nScriptSetVarJ(getID(), index, v);
Stephen Hines031ec58c2010-10-11 10:54:21 -0700134 }
135
Jason Sams67e3d202011-01-09 13:49:01 -0800136 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800137 * Only intended for use by generated reflected code.
138 *
139 * @param index
140 * @param v
141 */
Jason Sams0b9a22c2010-07-02 15:35:19 -0700142 public void setVar(int index, boolean v) {
Jason Sams06d69de2010-11-09 17:11:40 -0800143 mRS.nScriptSetVarI(getID(), index, v ? 1 : 0);
Jason Sams0b9a22c2010-07-02 15:35:19 -0700144 }
145
Jason Sams67e3d202011-01-09 13:49:01 -0800146 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800147 * Only intended for use by generated reflected code.
148 *
149 * @param index
150 * @param o
151 */
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800152 public void setVar(int index, BaseObj o) {
153 mRS.nScriptSetVarObj(getID(), index, (o == null) ? 0 : o.getID());
154 }
155
Jason Sams67e3d202011-01-09 13:49:01 -0800156 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800157 * Only intended for use by generated reflected code.
158 *
159 * @param index
160 * @param v
161 */
Jason Sams4d339932010-05-11 14:03:58 -0700162 public void setVar(int index, FieldPacker v) {
Jason Sams06d69de2010-11-09 17:11:40 -0800163 mRS.nScriptSetVarV(getID(), index, v.getData());
Jason Sams69f0d312009-08-03 18:11:17 -0700164 }
165
Jason Sams22534172009-08-04 16:58:20 -0700166 public void setTimeZone(String timeZone) {
Jason Sams771bebb2009-12-07 12:40:12 -0800167 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -0700168 try {
Jason Sams06d69de2010-11-09 17:11:40 -0800169 mRS.nScriptSetTimeZone(getID(), timeZone.getBytes("UTF-8"));
Jason Sams22534172009-08-04 16:58:20 -0700170 } catch (java.io.UnsupportedEncodingException e) {
171 throw new RuntimeException(e);
172 }
173 }
Jason Sams69f0d312009-08-03 18:11:17 -0700174
175 public static class Builder {
176 RenderScript mRS;
Jason Sams69f0d312009-08-03 18:11:17 -0700177
178 Builder(RenderScript rs) {
179 mRS = rs;
180 }
Jason Sams69f0d312009-08-03 18:11:17 -0700181 }
182
Jason Sams2d71bc72010-03-26 16:06:43 -0700183
184 public static class FieldBase {
185 protected Element mElement;
Jason Sams2d71bc72010-03-26 16:06:43 -0700186 protected Allocation mAllocation;
187
188 protected void init(RenderScript rs, int dimx) {
Jason Sams5476b452010-12-08 16:14:36 -0800189 mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT);
190 }
191
192 protected void init(RenderScript rs, int dimx, int usages) {
193 mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT | usages);
Jason Sams2d71bc72010-03-26 16:06:43 -0700194 }
195
196 protected FieldBase() {
197 }
198
199 public Element getElement() {
200 return mElement;
201 }
202
203 public Type getType() {
Jason Sams31a7e422010-10-26 13:09:17 -0700204 return mAllocation.getType();
Jason Sams2d71bc72010-03-26 16:06:43 -0700205 }
206
207 public Allocation getAllocation() {
208 return mAllocation;
209 }
210
211 //@Override
212 public void updateAllocation() {
213 }
Jason Sams2d71bc72010-03-26 16:06:43 -0700214 }
Jason Sams69f0d312009-08-03 18:11:17 -0700215}
216