blob: a402471e39bc2877b2d7108b2b3cf3ddd59e80d4 [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 Sams69f0d312009-08-03 18:11:17 -070028
29 Script(int id, RenderScript rs) {
30 super(rs);
31 mID = id;
32 }
33
Jason Sams69f0d312009-08-03 18:11:17 -070034 public void bindAllocation(Allocation va, int slot) {
35 mRS.nScriptBindAllocation(mID, va.mID, slot);
36 }
37
38 public void setClearColor(float r, float g, float b, float a) {
Jason Sams22534172009-08-04 16:58:20 -070039 mRS.nScriptSetClearColor(mID, r, g, b, a);
Jason Sams69f0d312009-08-03 18:11:17 -070040 }
41
42 public void setClearDepth(float d) {
Jason Sams22534172009-08-04 16:58:20 -070043 mRS.nScriptSetClearDepth(mID, d);
Jason Sams69f0d312009-08-03 18:11:17 -070044 }
45
46 public void setClearStencil(int stencil) {
Jason Sams22534172009-08-04 16:58:20 -070047 mRS.nScriptSetClearStencil(mID, stencil);
Jason Sams69f0d312009-08-03 18:11:17 -070048 }
49
Jason Sams22534172009-08-04 16:58:20 -070050 public void setTimeZone(String timeZone) {
51 try {
52 mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8"));
53 } catch (java.io.UnsupportedEncodingException e) {
54 throw new RuntimeException(e);
55 }
56 }
Jason Sams69f0d312009-08-03 18:11:17 -070057
58 public static class Builder {
59 RenderScript mRS;
60 boolean mIsRoot = false;
Jason Sams43ee06852009-08-12 17:54:11 -070061 Type[] mTypes;
Jason Samsfbf0b9e2009-08-13 12:59:04 -070062 String[] mNames;
Jason Sams334ea0c2009-08-17 13:56:09 -070063 boolean[] mWritable;
Jason Sams69f0d312009-08-03 18:11:17 -070064
65 Builder(RenderScript rs) {
66 mRS = rs;
Jason Samsfbf0b9e2009-08-13 12:59:04 -070067 mTypes = new Type[MAX_SLOT];
68 mNames = new String[MAX_SLOT];
Jason Sams334ea0c2009-08-17 13:56:09 -070069 mWritable = new boolean[MAX_SLOT];
Jason Sams69f0d312009-08-03 18:11:17 -070070 }
71
Jason Samsfbf0b9e2009-08-13 12:59:04 -070072 public void setType(Type t, int slot) {
73 mTypes[slot] = t;
74 mNames[slot] = null;
75 }
76
77 public void setType(Type t, String name, int slot) {
78 mTypes[slot] = t;
79 mNames[slot] = name;
Jason Sams69f0d312009-08-03 18:11:17 -070080 }
81
Jason Sams334ea0c2009-08-17 13:56:09 -070082 public void setType(boolean writable, int slot) {
83 mWritable[slot] = writable;
84 }
85
Jason Sams69f0d312009-08-03 18:11:17 -070086 void transferCreate() {
Jason Samsfbf0b9e2009-08-13 12:59:04 -070087 mRS.nScriptSetRoot(mIsRoot);
88 for(int ct=0; ct < mTypes.length; ct++) {
89 if(mTypes[ct] != null) {
Jason Sams334ea0c2009-08-17 13:56:09 -070090 mRS.nScriptSetType(mTypes[ct].mID, mWritable[ct], mNames[ct], ct);
Jason Samsfbf0b9e2009-08-13 12:59:04 -070091 }
Jason Sams43ee06852009-08-12 17:54:11 -070092 }
Jason Sams69f0d312009-08-03 18:11:17 -070093 }
94
95 void transferObject(Script s) {
96 s.mIsRoot = mIsRoot;
Jason Samsfbf0b9e2009-08-13 12:59:04 -070097 s.mTypes = mTypes;
Jason Sams69f0d312009-08-03 18:11:17 -070098 }
99
Jason Sams69f0d312009-08-03 18:11:17 -0700100 public void setRoot(boolean r) {
101 mIsRoot = r;
102 }
103
104 }
105
106}
107