Script.java revision fbf0b9ecda03fbdbd4ebabfd18da09a789686249
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 28 Script(int id, RenderScript rs) { 29 super(rs); 30 mID = id; 31 } 32 33 public void destroy() { 34 if(mDestroyed) { 35 throw new IllegalStateException("Object already destroyed."); 36 } 37 mDestroyed = true; 38 mRS.nScriptDestroy(mID); 39 } 40 41 public void bindAllocation(Allocation va, int slot) { 42 mRS.nScriptBindAllocation(mID, va.mID, slot); 43 } 44 45 public void setClearColor(float r, float g, float b, float a) { 46 mRS.nScriptSetClearColor(mID, r, g, b, a); 47 } 48 49 public void setClearDepth(float d) { 50 mRS.nScriptSetClearDepth(mID, d); 51 } 52 53 public void setClearStencil(int stencil) { 54 mRS.nScriptSetClearStencil(mID, stencil); 55 } 56 57 public void setTimeZone(String timeZone) { 58 try { 59 mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8")); 60 } catch (java.io.UnsupportedEncodingException e) { 61 throw new RuntimeException(e); 62 } 63 } 64 65 public static class Builder { 66 RenderScript mRS; 67 boolean mIsRoot = false; 68 Type[] mTypes; 69 String[] mNames; 70 71 Builder(RenderScript rs) { 72 mRS = rs; 73 mTypes = new Type[MAX_SLOT]; 74 mNames = new String[MAX_SLOT]; 75 } 76 77 public void setType(Type t, int slot) { 78 mTypes[slot] = t; 79 mNames[slot] = null; 80 } 81 82 public void setType(Type t, String name, int slot) { 83 mTypes[slot] = t; 84 mNames[slot] = name; 85 } 86 87 void transferCreate() { 88 mRS.nScriptSetRoot(mIsRoot); 89 for(int ct=0; ct < mTypes.length; ct++) { 90 if(mTypes[ct] != null) { 91 mRS.nScriptSetType(mTypes[ct].mID, mNames[ct], ct); 92 } 93 } 94 } 95 96 void transferObject(Script s) { 97 s.mIsRoot = mIsRoot; 98 s.mTypes = mTypes; 99 } 100 101 public void setRoot(boolean r) { 102 mIsRoot = r; 103 } 104 105 } 106 107} 108 109