Script.java revision 96ed4cfa62dd09aafb3f9da01e047661b4fe3c95
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 invoke(int slot, FieldPacker v) {
50        if (v != null) {
51            mRS.nScriptInvokeV(mID, slot, v.getData());
52        } else {
53            mRS.nScriptInvoke(mID, slot);
54        }
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 setTimeZone(String timeZone) {
85        mRS.validate();
86        try {
87            mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8"));
88        } catch (java.io.UnsupportedEncodingException e) {
89            throw new RuntimeException(e);
90        }
91    }
92
93    public static class Builder {
94        RenderScript mRS;
95
96        Builder(RenderScript rs) {
97            mRS = rs;
98        }
99    }
100
101
102    public static class FieldBase {
103        protected Element mElement;
104        protected Type mType;
105        protected Allocation mAllocation;
106
107        protected void init(RenderScript rs, int dimx) {
108            mAllocation = Allocation.createSized(rs, mElement, dimx);
109            mType = mAllocation.getType();
110        }
111
112        protected FieldBase() {
113        }
114
115        public Element getElement() {
116            return mElement;
117        }
118
119        public Type getType() {
120            return mType;
121        }
122
123        public Allocation getAllocation() {
124            return mAllocation;
125        }
126
127        //@Override
128        public void updateAllocation() {
129        }
130
131
132        //
133        /*
134        public class ScriptField_UserField
135            extends android.renderscript.Script.FieldBase {
136
137            protected
138
139        }
140
141        */
142
143    }
144}
145
146