| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 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 | |
| 17 | package android.renderscript; |
| 18 | |
| 19 | /** |
| 20 | * @hide |
| 21 | **/ |
| 22 | public class Script extends BaseObj { |
| Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 23 | public static final int MAX_SLOT = 16; |
| 24 | |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 25 | boolean mIsRoot; |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 26 | Type[] mTypes; |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 27 | boolean[] mWritable; |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 28 | |
| 29 | Script(int id, RenderScript rs) { |
| 30 | super(rs); |
| 31 | mID = id; |
| 32 | } |
| 33 | |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 34 | public void bindAllocation(Allocation va, int slot) { |
| 35 | mRS.nScriptBindAllocation(mID, va.mID, slot); |
| 36 | } |
| 37 | |
| 38 | public void setClearColor(float r, float g, float b, float a) { |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 39 | mRS.nScriptSetClearColor(mID, r, g, b, a); |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | public void setClearDepth(float d) { |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 43 | mRS.nScriptSetClearDepth(mID, d); |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | public void setClearStencil(int stencil) { |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 47 | mRS.nScriptSetClearStencil(mID, stencil); |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 50 | public void setTimeZone(String timeZone) { |
| 51 | try { |
| 52 | mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8")); |
| 53 | } catch (java.io.UnsupportedEncodingException e) { |
| 54 | throw new RuntimeException(e); |
| 55 | } |
| 56 | } |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 57 | |
| 58 | public static class Builder { |
| 59 | RenderScript mRS; |
| 60 | boolean mIsRoot = false; |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 61 | Type[] mTypes; |
| Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 62 | String[] mNames; |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 63 | boolean[] mWritable; |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 64 | |
| 65 | Builder(RenderScript rs) { |
| 66 | mRS = rs; |
| Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 67 | mTypes = new Type[MAX_SLOT]; |
| 68 | mNames = new String[MAX_SLOT]; |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 69 | mWritable = new boolean[MAX_SLOT]; |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 72 | public void setType(Type t, int slot) { |
| 73 | mTypes[slot] = t; |
| 74 | mNames[slot] = null; |
| 75 | } |
| 76 | |
| 77 | public void setType(Type t, String name, int slot) { |
| 78 | mTypes[slot] = t; |
| 79 | mNames[slot] = name; |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 82 | public void setType(boolean writable, int slot) { |
| 83 | mWritable[slot] = writable; |
| 84 | } |
| 85 | |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 86 | void transferCreate() { |
| Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 87 | mRS.nScriptSetRoot(mIsRoot); |
| 88 | for(int ct=0; ct < mTypes.length; ct++) { |
| 89 | if(mTypes[ct] != null) { |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 90 | mRS.nScriptSetType(mTypes[ct].mID, mWritable[ct], mNames[ct], ct); |
| Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 91 | } |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 92 | } |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void transferObject(Script s) { |
| 96 | s.mIsRoot = mIsRoot; |
| Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 97 | s.mTypes = mTypes; |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 100 | public void setRoot(boolean r) { |
| 101 | mIsRoot = r; |
| 102 | } |
| 103 | |
| 104 | } |
| 105 | |
| 106 | } |
| 107 | |