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