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