Script.java revision 4d3399337d18ef04116bc8a2e5799274655d0c30
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    public static final int MAX_SLOT = 16;
24
25    boolean mIsRoot;
26    Type[] mTypes;
27    boolean[] mWritable;
28    Invokable[] mInvokables;
29
30    public static class Invokable {
31        RenderScript mRS;
32        Script mScript;
33        int mSlot;
34        String mName;
35
36        Invokable() {
37            mSlot = -1;
38        }
39
40        public void execute() {
41            mRS.nScriptInvoke(mScript.mID, mSlot);
42        }
43    }
44
45    protected void invoke(int slot) {
46        mRS.nScriptInvoke(mID, slot);
47    }
48
49    protected void invokeData(int slot) {
50        mRS.nScriptInvokeData(mID, slot);
51    }
52
53    protected void invokeV(int slot, FieldPacker v) {
54        mRS.nScriptInvokeV(mID, slot, v.getData());
55    }
56
57
58    Script(int id, RenderScript rs) {
59        super(rs);
60        mID = id;
61    }
62
63    public void bindAllocation(Allocation va, int slot) {
64        mRS.validate();
65        if (va != null) {
66            mRS.nScriptBindAllocation(mID, va.mID, slot);
67        } else {
68            mRS.nScriptBindAllocation(mID, 0, slot);
69        }
70    }
71
72    public void setVar(int index, float v) {
73        mRS.nScriptSetVarF(mID, index, v);
74    }
75
76    public void setVar(int index, int v) {
77        mRS.nScriptSetVarI(mID, index, v);
78    }
79
80    public void setVar(int index, FieldPacker v) {
81        mRS.nScriptSetVarV(mID, index, v.getData());
82    }
83
84    public void setClearColor(float r, float g, float b, float a) {
85        mRS.validate();
86        mRS.nScriptSetClearColor(mID, r, g, b, a);
87    }
88
89    public void setClearDepth(float d) {
90        mRS.validate();
91        mRS.nScriptSetClearDepth(mID, d);
92    }
93
94    public void setClearStencil(int stencil) {
95        mRS.validate();
96        mRS.nScriptSetClearStencil(mID, stencil);
97    }
98
99    public void setTimeZone(String timeZone) {
100        mRS.validate();
101        try {
102            mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8"));
103        } catch (java.io.UnsupportedEncodingException e) {
104            throw new RuntimeException(e);
105        }
106    }
107
108    public static class Builder {
109        RenderScript mRS;
110
111        Builder(RenderScript rs) {
112            mRS = rs;
113        }
114    }
115
116
117    public static class FieldBase {
118        protected Element mElement;
119        protected Type mType;
120        protected Allocation mAllocation;
121
122        protected void init(RenderScript rs, int dimx) {
123            mAllocation = Allocation.createSized(rs, mElement, dimx);
124            mType = mAllocation.getType();
125        }
126
127        protected FieldBase() {
128        }
129
130        public Element getElement() {
131            return mElement;
132        }
133
134        public Type getType() {
135            return mType;
136        }
137
138        public Allocation getAllocation() {
139            return mAllocation;
140        }
141
142        //@Override
143        public void updateAllocation() {
144        }
145
146
147        //
148        /*
149        public class ScriptField_UserField
150            extends android.renderscript.Script.FieldBase {
151
152            protected
153
154        }
155
156        */
157
158    }
159}
160
161