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: reflection3264_divergent.rscript 20 */ 21 22package foo; 23 24import android.os.Build; 25import android.os.Process; 26import java.lang.reflect.Field; 27import android.renderscript.*; 28import foo.reflection3264_divergentBitCode; 29 30/** 31 * @hide 32 */ 33public class ScriptField_NonDivergent extends android.renderscript.Script.FieldBase { 34 static public class Item { 35 36 int i; 37 int j; 38 39 Item() { 40 } 41 42 } 43 44 private Item mItemArray[]; 45 private FieldPacker mIOBuffer; 46 private static java.lang.ref.WeakReference<Element> mElementCache = new java.lang.ref.WeakReference<Element>(null); 47 public static Element createElement(RenderScript rs) { 48 Element.Builder eb = new Element.Builder(rs); 49 eb.add(Element.I32(rs), "i"); 50 eb.add(Element.I32(rs), "j"); 51 return eb.create(); 52 } 53 54 private ScriptField_NonDivergent(RenderScript rs) { 55 mItemArray = null; 56 mIOBuffer = null; 57 mElement = createElement(rs); 58 } 59 60 public ScriptField_NonDivergent(RenderScript rs, int count) { 61 mItemArray = null; 62 mIOBuffer = null; 63 mElement = createElement(rs); 64 init(rs, count); 65 } 66 67 public ScriptField_NonDivergent(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_NonDivergent create1D(RenderScript rs, int dimX, int usages) { 75 ScriptField_NonDivergent obj = new ScriptField_NonDivergent(rs); 76 obj.mAllocation = Allocation.createSized(rs, obj.mElement, dimX, usages); 77 return obj; 78 } 79 80 public static ScriptField_NonDivergent create1D(RenderScript rs, int dimX) { 81 return create1D(rs, dimX, Allocation.USAGE_SCRIPT); 82 } 83 84 public static ScriptField_NonDivergent create2D(RenderScript rs, int dimX, int dimY) { 85 return create2D(rs, dimX, dimY, Allocation.USAGE_SCRIPT); 86 } 87 88 public static ScriptField_NonDivergent create2D(RenderScript rs, int dimX, int dimY, int usages) { 89 ScriptField_NonDivergent obj = new ScriptField_NonDivergent(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_NonDivergent createCustom(RenderScript rs, Type.Builder tb, int usages) { 104 ScriptField_NonDivergent obj = new ScriptField_NonDivergent(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.addI32(i.i); 115 fp.addI32(i.j); 116 } 117 118 private void copyToArray(Item i, int index) { 119 if (mIOBuffer == null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */); 120 mIOBuffer.reset(index * mElement.getBytesSize()); 121 copyToArrayLocal(i, mIOBuffer); 122 } 123 124 public synchronized void set(Item i, int index, boolean copyNow) { 125 if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */]; 126 mItemArray[index] = i; 127 if (copyNow) { 128 copyToArray(i, index); 129 FieldPacker fp = new FieldPacker(mElement.getBytesSize()); 130 copyToArrayLocal(i, fp); 131 mAllocation.setFromFieldPacker(index, fp); 132 } 133 134 } 135 136 public synchronized Item get(int index) { 137 if (mItemArray == null) return null; 138 return mItemArray[index]; 139 } 140 141 public synchronized void set_i(int index, int v, boolean copyNow) { 142 if (mIOBuffer == null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */); 143 if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */]; 144 if (mItemArray[index] == null) mItemArray[index] = new Item(); 145 mItemArray[index].i = v; 146 if (copyNow) { 147 mIOBuffer.reset(index * mElement.getBytesSize()); 148 mIOBuffer.addI32(v); 149 FieldPacker fp = new FieldPacker(4); 150 fp.addI32(v); 151 mAllocation.setFromFieldPacker(index, 0, fp); 152 } 153 154 } 155 156 public synchronized void set_j(int index, int v, boolean copyNow) { 157 if (mIOBuffer == null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */); 158 if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */]; 159 if (mItemArray[index] == null) mItemArray[index] = new Item(); 160 mItemArray[index].j = v; 161 if (copyNow) { 162 mIOBuffer.reset(index * mElement.getBytesSize() + 4); 163 mIOBuffer.addI32(v); 164 FieldPacker fp = new FieldPacker(4); 165 fp.addI32(v); 166 mAllocation.setFromFieldPacker(index, 1, fp); 167 } 168 169 } 170 171 public synchronized int get_i(int index) { 172 if (mItemArray == null) return 0; 173 return mItemArray[index].i; 174 } 175 176 public synchronized int get_j(int index) { 177 if (mItemArray == null) return 0; 178 return mItemArray[index].j; 179 } 180 181 public synchronized void copyAll() { 182 for (int ct = 0; ct < mItemArray.length; ct++) copyToArray(mItemArray[ct], ct); 183 mAllocation.setFromFieldPacker(0, mIOBuffer); 184 } 185 186 public synchronized void resize(int newSize) { 187 if (mItemArray != null) { 188 int oldSize = mItemArray.length; 189 int copySize = Math.min(oldSize, newSize); 190 if (newSize == oldSize) return; 191 Item ni[] = new Item[newSize]; 192 System.arraycopy(mItemArray, 0, ni, 0, copySize); 193 mItemArray = ni; 194 } 195 196 mAllocation.resize(newSize); 197 if (mIOBuffer != null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */); 198 } 199 200} 201 202