blob: 47479d83a5cf4fd2688a1f98c9a137a8567ed731 [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 Sams69f0d312009-08-03 18:11:17 -070027
28 Script(int id, RenderScript rs) {
29 super(rs);
30 mID = id;
31 }
32
33 public void destroy() {
Jason Sams1bada8c2009-08-09 17:01:55 -070034 if(mDestroyed) {
35 throw new IllegalStateException("Object already destroyed.");
36 }
37 mDestroyed = true;
Jason Sams69f0d312009-08-03 18:11:17 -070038 mRS.nScriptDestroy(mID);
Jason Sams69f0d312009-08-03 18:11:17 -070039 }
40
41 public void bindAllocation(Allocation va, int slot) {
42 mRS.nScriptBindAllocation(mID, va.mID, slot);
43 }
44
45 public void setClearColor(float r, float g, float b, float a) {
Jason Sams22534172009-08-04 16:58:20 -070046 mRS.nScriptSetClearColor(mID, r, g, b, a);
Jason Sams69f0d312009-08-03 18:11:17 -070047 }
48
49 public void setClearDepth(float d) {
Jason Sams22534172009-08-04 16:58:20 -070050 mRS.nScriptSetClearDepth(mID, d);
Jason Sams69f0d312009-08-03 18:11:17 -070051 }
52
53 public void setClearStencil(int stencil) {
Jason Sams22534172009-08-04 16:58:20 -070054 mRS.nScriptSetClearStencil(mID, stencil);
Jason Sams69f0d312009-08-03 18:11:17 -070055 }
56
Jason Sams22534172009-08-04 16:58:20 -070057 public void setTimeZone(String timeZone) {
58 try {
59 mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8"));
60 } catch (java.io.UnsupportedEncodingException e) {
61 throw new RuntimeException(e);
62 }
63 }
Jason Sams69f0d312009-08-03 18:11:17 -070064
65 public static class Builder {
66 RenderScript mRS;
67 boolean mIsRoot = false;
Jason Sams43ee06852009-08-12 17:54:11 -070068 Type[] mTypes;
Jason Samsfbf0b9e2009-08-13 12:59:04 -070069 String[] mNames;
Jason Sams69f0d312009-08-03 18:11:17 -070070
71 Builder(RenderScript rs) {
72 mRS = rs;
Jason Samsfbf0b9e2009-08-13 12:59:04 -070073 mTypes = new Type[MAX_SLOT];
74 mNames = new String[MAX_SLOT];
Jason Sams69f0d312009-08-03 18:11:17 -070075 }
76
Jason Samsfbf0b9e2009-08-13 12:59:04 -070077 public void setType(Type t, int slot) {
78 mTypes[slot] = t;
79 mNames[slot] = null;
80 }
81
82 public void setType(Type t, String name, int slot) {
83 mTypes[slot] = t;
84 mNames[slot] = name;
Jason Sams69f0d312009-08-03 18:11:17 -070085 }
86
87 void transferCreate() {
Jason Samsfbf0b9e2009-08-13 12:59:04 -070088 mRS.nScriptSetRoot(mIsRoot);
89 for(int ct=0; ct < mTypes.length; ct++) {
90 if(mTypes[ct] != null) {
91 mRS.nScriptSetType(mTypes[ct].mID, mNames[ct], ct);
92 }
Jason Sams43ee06852009-08-12 17:54:11 -070093 }
Jason Sams69f0d312009-08-03 18:11:17 -070094 }
95
96 void transferObject(Script s) {
97 s.mIsRoot = mIsRoot;
Jason Samsfbf0b9e2009-08-13 12:59:04 -070098 s.mTypes = mTypes;
Jason Sams69f0d312009-08-03 18:11:17 -070099 }
100
Jason Sams69f0d312009-08-03 18:11:17 -0700101 public void setRoot(boolean r) {
102 mIsRoot = r;
103 }
104
105 }
106
107}
108