blob: 5b9eb5538c9855c6f4a57ad75de0bcc892c90025 [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
34 public void destroy() {
Jason Sams1bada8c2009-08-09 17:01:55 -070035 if(mDestroyed) {
36 throw new IllegalStateException("Object already destroyed.");
37 }
38 mDestroyed = true;
Jason Sams69f0d312009-08-03 18:11:17 -070039 mRS.nScriptDestroy(mID);
Jason Sams69f0d312009-08-03 18:11:17 -070040 }
41
42 public void bindAllocation(Allocation va, int slot) {
43 mRS.nScriptBindAllocation(mID, va.mID, slot);
44 }
45
46 public void setClearColor(float r, float g, float b, float a) {
Jason Sams22534172009-08-04 16:58:20 -070047 mRS.nScriptSetClearColor(mID, r, g, b, a);
Jason Sams69f0d312009-08-03 18:11:17 -070048 }
49
50 public void setClearDepth(float d) {
Jason Sams22534172009-08-04 16:58:20 -070051 mRS.nScriptSetClearDepth(mID, d);
Jason Sams69f0d312009-08-03 18:11:17 -070052 }
53
54 public void setClearStencil(int stencil) {
Jason Sams22534172009-08-04 16:58:20 -070055 mRS.nScriptSetClearStencil(mID, stencil);
Jason Sams69f0d312009-08-03 18:11:17 -070056 }
57
Jason Sams22534172009-08-04 16:58:20 -070058 public void setTimeZone(String timeZone) {
59 try {
60 mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8"));
61 } catch (java.io.UnsupportedEncodingException e) {
62 throw new RuntimeException(e);
63 }
64 }
Jason Sams69f0d312009-08-03 18:11:17 -070065
66 public static class Builder {
67 RenderScript mRS;
68 boolean mIsRoot = false;
Jason Sams43ee06852009-08-12 17:54:11 -070069 Type[] mTypes;
Jason Samsfbf0b9e2009-08-13 12:59:04 -070070 String[] mNames;
Jason Sams334ea0c2009-08-17 13:56:09 -070071 boolean[] mWritable;
Jason Sams69f0d312009-08-03 18:11:17 -070072
73 Builder(RenderScript rs) {
74 mRS = rs;
Jason Samsfbf0b9e2009-08-13 12:59:04 -070075 mTypes = new Type[MAX_SLOT];
76 mNames = new String[MAX_SLOT];
Jason Sams334ea0c2009-08-17 13:56:09 -070077 mWritable = new boolean[MAX_SLOT];
Jason Sams69f0d312009-08-03 18:11:17 -070078 }
79
Jason Samsfbf0b9e2009-08-13 12:59:04 -070080 public void setType(Type t, int slot) {
81 mTypes[slot] = t;
82 mNames[slot] = null;
83 }
84
85 public void setType(Type t, String name, int slot) {
86 mTypes[slot] = t;
87 mNames[slot] = name;
Jason Sams69f0d312009-08-03 18:11:17 -070088 }
89
Jason Sams334ea0c2009-08-17 13:56:09 -070090 public void setType(boolean writable, int slot) {
91 mWritable[slot] = writable;
92 }
93
Jason Sams69f0d312009-08-03 18:11:17 -070094 void transferCreate() {
Jason Samsfbf0b9e2009-08-13 12:59:04 -070095 mRS.nScriptSetRoot(mIsRoot);
96 for(int ct=0; ct < mTypes.length; ct++) {
97 if(mTypes[ct] != null) {
Jason Sams334ea0c2009-08-17 13:56:09 -070098 mRS.nScriptSetType(mTypes[ct].mID, mWritable[ct], mNames[ct], ct);
Jason Samsfbf0b9e2009-08-13 12:59:04 -070099 }
Jason Sams43ee06852009-08-12 17:54:11 -0700100 }
Jason Sams69f0d312009-08-03 18:11:17 -0700101 }
102
103 void transferObject(Script s) {
104 s.mIsRoot = mIsRoot;
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700105 s.mTypes = mTypes;
Jason Sams69f0d312009-08-03 18:11:17 -0700106 }
107
Jason Sams69f0d312009-08-03 18:11:17 -0700108 public void setRoot(boolean r) {
109 mIsRoot = r;
110 }
111
112 }
113
114}
115