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