1/* 2 * Copyright (C) 2011-2014 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/* 18 * This file is auto-generated. DO NOT MODIFY! 19 * The source Renderscript file: struct_field.rscript 20 */ 21 22package struct_field; 23 24import android.os.Build; 25import android.os.Process; 26import java.lang.reflect.Field; 27import android.renderscript.*; 28import struct_field.struct_fieldBitCode; 29 30/** 31 * @hide 32 */ 33public class ScriptField_InnerTwo extends android.renderscript.Script.FieldBase { 34 static public class Item { 35 36 byte z; 37 ScriptField_InnerOne.Item innerOne; 38 39 Item() { 40 innerOne = new ScriptField_InnerOne.Item(); 41 } 42 43 } 44 45 private Item mItemArray[]; 46 private FieldPacker mIOBuffer; 47 private static java.lang.ref.WeakReference<Element> mElementCache = new java.lang.ref.WeakReference<Element>(null); 48 public static Element createElement(RenderScript rs) { 49 Element.Builder eb = new Element.Builder(rs); 50 eb.add(Element.I8(rs), "z"); 51 eb.add(Element.U16(rs), "#rs_padding_1"); 52 eb.add(Element.U8(rs), "#rs_padding_2"); 53 eb.add(ScriptField_InnerOne.createElement(rs), "innerOne"); 54 return eb.create(); 55 } 56 57 private ScriptField_InnerTwo(RenderScript rs) { 58 mItemArray = null; 59 mIOBuffer = null; 60 mElement = createElement(rs); 61 } 62 63 public ScriptField_InnerTwo(RenderScript rs, int count) { 64 mItemArray = null; 65 mIOBuffer = null; 66 mElement = createElement(rs); 67 init(rs, count); 68 } 69 70 public ScriptField_InnerTwo(RenderScript rs, int count, int usages) { 71 mItemArray = null; 72 mIOBuffer = null; 73 mElement = createElement(rs); 74 init(rs, count, usages); 75 } 76 77 public static ScriptField_InnerTwo create1D(RenderScript rs, int dimX, int usages) { 78 ScriptField_InnerTwo obj = new ScriptField_InnerTwo(rs); 79 obj.mAllocation = Allocation.createSized(rs, obj.mElement, dimX, usages); 80 return obj; 81 } 82 83 public static ScriptField_InnerTwo create1D(RenderScript rs, int dimX) { 84 return create1D(rs, dimX, Allocation.USAGE_SCRIPT); 85 } 86 87 public static ScriptField_InnerTwo create2D(RenderScript rs, int dimX, int dimY) { 88 return create2D(rs, dimX, dimY, Allocation.USAGE_SCRIPT); 89 } 90 91 public static ScriptField_InnerTwo create2D(RenderScript rs, int dimX, int dimY, int usages) { 92 ScriptField_InnerTwo obj = new ScriptField_InnerTwo(rs); 93 Type.Builder b = new Type.Builder(rs, obj.mElement); 94 b.setX(dimX); 95 b.setY(dimY); 96 Type t = b.create(); 97 obj.mAllocation = Allocation.createTyped(rs, t, usages); 98 return obj; 99 } 100 101 public static Type.Builder createTypeBuilder(RenderScript rs) { 102 Element e = createElement(rs); 103 return new Type.Builder(rs, e); 104 } 105 106 public static ScriptField_InnerTwo createCustom(RenderScript rs, Type.Builder tb, int usages) { 107 ScriptField_InnerTwo obj = new ScriptField_InnerTwo(rs); 108 Type t = tb.create(); 109 if (t.getElement() != obj.mElement) { 110 throw new RSIllegalArgumentException("Type.Builder did not match expected element type."); 111 } 112 obj.mAllocation = Allocation.createTyped(rs, t, usages); 113 return obj; 114 } 115 116 private void copyToArrayLocal(Item i, FieldPacker fp) { 117 fp.addI8(i.z); 118 fp.skip(3); 119 fp.addI32(i.innerOne.x); 120 fp.addI32(i.innerOne.y); 121 fp.addF32(i.innerOne.f); 122 } 123 124 private void copyToArray(Item i, int index) { 125 if (mIOBuffer == null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */); 126 mIOBuffer.reset(index * mElement.getBytesSize()); 127 copyToArrayLocal(i, mIOBuffer); 128 } 129 130 public synchronized void set(Item i, int index, boolean copyNow) { 131 if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */]; 132 mItemArray[index] = i; 133 if (copyNow) { 134 copyToArray(i, index); 135 FieldPacker fp = new FieldPacker(mElement.getBytesSize()); 136 copyToArrayLocal(i, fp); 137 mAllocation.setFromFieldPacker(index, fp); 138 } 139 140 } 141 142 public synchronized Item get(int index) { 143 if (mItemArray == null) return null; 144 return mItemArray[index]; 145 } 146 147 public synchronized void set_z(int index, byte v, boolean copyNow) { 148 if (mIOBuffer == null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */); 149 if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */]; 150 if (mItemArray[index] == null) mItemArray[index] = new Item(); 151 mItemArray[index].z = v; 152 if (copyNow) { 153 mIOBuffer.reset(index * mElement.getBytesSize()); 154 mIOBuffer.addI8(v); 155 FieldPacker fp = new FieldPacker(1); 156 fp.addI8(v); 157 mAllocation.setFromFieldPacker(index, 0, fp); 158 } 159 160 } 161 162 public synchronized void set_innerOne(int index, ScriptField_InnerOne.Item v, boolean copyNow) { 163 if (mIOBuffer == null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */); 164 if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */]; 165 if (mItemArray[index] == null) mItemArray[index] = new Item(); 166 mItemArray[index].innerOne = v; 167 if (copyNow) { 168 mIOBuffer.reset(index * mElement.getBytesSize() + 4); 169 mIOBuffer.addI32(v.x); 170 mIOBuffer.addI32(v.y); 171 mIOBuffer.addF32(v.f); 172 FieldPacker fp = new FieldPacker(12); 173 fp.addI32(v.x); 174 fp.addI32(v.y); 175 fp.addF32(v.f); 176 mAllocation.setFromFieldPacker(index, 3, fp); 177 } 178 179 } 180 181 public synchronized byte get_z(int index) { 182 if (mItemArray == null) return 0; 183 return mItemArray[index].z; 184 } 185 186 public synchronized ScriptField_InnerOne.Item get_innerOne(int index) { 187 if (mItemArray == null) return null; 188 return mItemArray[index].innerOne; 189 } 190 191 public synchronized void copyAll() { 192 for (int ct = 0; ct < mItemArray.length; ct++) copyToArray(mItemArray[ct], ct); 193 mAllocation.setFromFieldPacker(0, mIOBuffer); 194 } 195 196 public synchronized void resize(int newSize) { 197 if (mItemArray != null) { 198 int oldSize = mItemArray.length; 199 int copySize = Math.min(oldSize, newSize); 200 if (newSize == oldSize) return; 201 Item ni[] = new Item[newSize]; 202 System.arraycopy(mItemArray, 0, ni, 0, copySize); 203 mItemArray = ni; 204 } 205 206 mAllocation.resize(newSize); 207 if (mIOBuffer != null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */); 208 } 209 210} 211 212