| 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 { |
| 23 | boolean mIsRoot; |
| 24 | |
| 25 | Script(int id, RenderScript rs) { |
| 26 | super(rs); |
| 27 | mID = id; |
| 28 | } |
| 29 | |
| 30 | public void destroy() { |
| Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 31 | if(mDestroyed) { |
| 32 | throw new IllegalStateException("Object already destroyed."); |
| 33 | } |
| 34 | mDestroyed = true; |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 35 | mRS.nScriptDestroy(mID); |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 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) { |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 43 | mRS.nScriptSetClearColor(mID, r, g, b, a); |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | public void setClearDepth(float d) { |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 47 | mRS.nScriptSetClearDepth(mID, d); |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | public void setClearStencil(int stencil) { |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 51 | mRS.nScriptSetClearStencil(mID, stencil); |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 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 | } |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 61 | |
| 62 | public static class Builder { |
| 63 | RenderScript mRS; |
| 64 | boolean mIsRoot = false; |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 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() { |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 75 | mRS.nScriptCSetRoot(mIsRoot); |
| 76 | } |
| 77 | |
| 78 | void transferObject(Script s) { |
| 79 | s.mIsRoot = mIsRoot; |
| 80 | } |
| 81 | |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 82 | public void setRoot(boolean r) { |
| 83 | mIsRoot = r; |
| 84 | } |
| 85 | |
| 86 | } |
| 87 | |
| 88 | } |
| 89 | |