Script.java revision 1bada8cd6e4f340de93cff4a2439835fc3b1456c
1/*
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;
24
25    Script(int id, RenderScript rs) {
26        super(rs);
27        mID = id;
28    }
29
30    public void destroy() {
31        if(mDestroyed) {
32            throw new IllegalStateException("Object already destroyed.");
33        }
34        mDestroyed = true;
35        mRS.nScriptDestroy(mID);
36    }
37
38    public void bindAllocation(Allocation va, int slot) {
39        mRS.nScriptBindAllocation(mID, va.mID, slot);
40    }
41
42    public void setClearColor(float r, float g, float b, float a) {
43        mRS.nScriptSetClearColor(mID, r, g, b, a);
44    }
45
46    public void setClearDepth(float d) {
47        mRS.nScriptSetClearDepth(mID, d);
48    }
49
50    public void setClearStencil(int stencil) {
51        mRS.nScriptSetClearStencil(mID, stencil);
52    }
53
54    public void setTimeZone(String timeZone) {
55        try {
56            mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8"));
57        } catch (java.io.UnsupportedEncodingException e) {
58            throw new RuntimeException(e);
59        }
60    }
61
62    public static class Builder {
63        RenderScript mRS;
64        boolean mIsRoot = false;
65
66        Builder(RenderScript rs) {
67            mRS = rs;
68        }
69
70        public void addType(Type t) {
71            mRS.nScriptCAddType(t.mID);
72        }
73
74        void transferCreate() {
75            mRS.nScriptCSetRoot(mIsRoot);
76        }
77
78        void transferObject(Script s) {
79            s.mIsRoot = mIsRoot;
80        }
81
82        public void setRoot(boolean r) {
83            mIsRoot = r;
84        }
85
86    }
87
88}
89
90