blob: 42c58ce13cf7d841cc746ad4d49f68d0df8be53f [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 {
23 boolean mIsRoot;
Jason Sams43ee06852009-08-12 17:54:11 -070024 Type[] mTypes;
Jason Sams69f0d312009-08-03 18:11:17 -070025
26 Script(int id, RenderScript rs) {
27 super(rs);
28 mID = id;
29 }
30
31 public void destroy() {
Jason Sams1bada8c2009-08-09 17:01:55 -070032 if(mDestroyed) {
33 throw new IllegalStateException("Object already destroyed.");
34 }
35 mDestroyed = true;
Jason Sams69f0d312009-08-03 18:11:17 -070036 mRS.nScriptDestroy(mID);
Jason Sams69f0d312009-08-03 18:11:17 -070037 }
38
39 public void bindAllocation(Allocation va, int slot) {
40 mRS.nScriptBindAllocation(mID, va.mID, slot);
41 }
42
43 public void setClearColor(float r, float g, float b, float a) {
Jason Sams22534172009-08-04 16:58:20 -070044 mRS.nScriptSetClearColor(mID, r, g, b, a);
Jason Sams69f0d312009-08-03 18:11:17 -070045 }
46
47 public void setClearDepth(float d) {
Jason Sams22534172009-08-04 16:58:20 -070048 mRS.nScriptSetClearDepth(mID, d);
Jason Sams69f0d312009-08-03 18:11:17 -070049 }
50
51 public void setClearStencil(int stencil) {
Jason Sams22534172009-08-04 16:58:20 -070052 mRS.nScriptSetClearStencil(mID, stencil);
Jason Sams69f0d312009-08-03 18:11:17 -070053 }
54
Jason Sams22534172009-08-04 16:58:20 -070055 public void setTimeZone(String timeZone) {
56 try {
57 mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8"));
58 } catch (java.io.UnsupportedEncodingException e) {
59 throw new RuntimeException(e);
60 }
61 }
Jason Sams69f0d312009-08-03 18:11:17 -070062
63 public static class Builder {
64 RenderScript mRS;
65 boolean mIsRoot = false;
Jason Sams43ee06852009-08-12 17:54:11 -070066 Type[] mTypes;
67 int mTypeCount;
Jason Sams69f0d312009-08-03 18:11:17 -070068
69 Builder(RenderScript rs) {
70 mRS = rs;
Jason Sams43ee06852009-08-12 17:54:11 -070071 mTypes = new Type[4];
72 mTypeCount = 0;
Jason Sams69f0d312009-08-03 18:11:17 -070073 }
74
75 public void addType(Type t) {
Jason Sams43ee06852009-08-12 17:54:11 -070076 if(mTypeCount >= mTypes.length) {
77 Type[] nt = new Type[mTypeCount * 2];
78 for(int ct=0; ct < mTypeCount; ct++) {
79 nt[ct] = mTypes[ct];
80 }
81 mTypes = nt;
82 }
83 mTypes[mTypeCount] = t;
84 mTypeCount++;
Jason Sams69f0d312009-08-03 18:11:17 -070085 }
86
87 void transferCreate() {
Jason Sams69f0d312009-08-03 18:11:17 -070088 mRS.nScriptCSetRoot(mIsRoot);
Jason Sams43ee06852009-08-12 17:54:11 -070089 for(int ct=0; ct < mTypeCount; ct++) {
90 mRS.nScriptCAddType(mTypes[ct].mID);
91 }
Jason Sams69f0d312009-08-03 18:11:17 -070092 }
93
94 void transferObject(Script s) {
95 s.mIsRoot = mIsRoot;
Jason Sams43ee06852009-08-12 17:54:11 -070096 s.mTypes = new Type[mTypeCount];
97 for(int ct=0; ct < mTypeCount; ct++) {
98 s.mTypes[ct] = mTypes[ct];
99 }
Jason Sams69f0d312009-08-03 18:11:17 -0700100 }
101
Jason Sams69f0d312009-08-03 18:11:17 -0700102 public void setRoot(boolean r) {
103 mIsRoot = r;
104 }
105
106 }
107
108}
109