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.rs 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_Divergent extends android.renderscript.Script.FieldBase { 34 static public class Item { 35 36 int i; 37 Allocation a; 38 int j; 39 40 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.I32(rs), "i"); 51 if (sIs64Bit) { 52 eb.add(Element.U32(rs), "#rs_padding_1"); 53 } 54 55 eb.add(Element.ALLOCATION(rs), "a"); 56 eb.add(Element.I32(rs), "j"); 57 if (sIs64Bit) { 58 eb.add(Element.U32(rs), "#rs_padding_2"); 59 } 60 61 return eb.create(); 62 } 63 64 private ScriptField_Divergent(RenderScript rs) { 65 mItemArray = null; 66 mIOBuffer = null; 67 mElement = createElement(rs); 68 } 69 70 public ScriptField_Divergent(RenderScript rs, int count) { 71 mItemArray = null; 72 mIOBuffer = null; 73 mElement = createElement(rs); 74 init(rs, count); 75 } 76 77 public ScriptField_Divergent(RenderScript rs, int count, int usages) { 78 mItemArray = null; 79 mIOBuffer = null; 80 mElement = createElement(rs); 81 init(rs, count, usages); 82 } 83 84 public static ScriptField_Divergent create1D(RenderScript rs, int dimX, int usages) { 85 ScriptField_Divergent obj = new ScriptField_Divergent(rs); 86 obj.mAllocation = Allocation.createSized(rs, obj.mElement, dimX, usages); 87 return obj; 88 } 89 90 public static ScriptField_Divergent create1D(RenderScript rs, int dimX) { 91 return create1D(rs, dimX, Allocation.USAGE_SCRIPT); 92 } 93 94 public static ScriptField_Divergent create2D(RenderScript rs, int dimX, int dimY) { 95 return create2D(rs, dimX, dimY, Allocation.USAGE_SCRIPT); 96 } 97 98 public static ScriptField_Divergent create2D(RenderScript rs, int dimX, int dimY, int usages) { 99 ScriptField_Divergent obj = new ScriptField_Divergent(rs); 100 Type.Builder b = new Type.Builder(rs, obj.mElement); 101 b.setX(dimX); 102 b.setY(dimY); 103 Type t = b.create(); 104 obj.mAllocation = Allocation.createTyped(rs, t, usages); 105 return obj; 106 } 107 108 public static Type.Builder createTypeBuilder(RenderScript rs) { 109 Element e = createElement(rs); 110 return new Type.Builder(rs, e); 111 } 112 113 public static ScriptField_Divergent createCustom(RenderScript rs, Type.Builder tb, int usages) { 114 ScriptField_Divergent obj = new ScriptField_Divergent(rs); 115 Type t = tb.create(); 116 if (t.getElement() != obj.mElement) { 117 throw new RSIllegalArgumentException("Type.Builder did not match expected element type."); 118 } 119 obj.mAllocation = Allocation.createTyped(rs, t, usages); 120 return obj; 121 } 122 123 private void copyToArrayLocal(Item i, FieldPacker fp) { 124 fp.addI32(i.i); 125 fp.skip(sIs64Bit ? 4 : 0); 126 fp.addObj(i.a); 127 fp.addI32(i.j); 128 fp.skip(sIs64Bit ? 4 : 0); 129 } 130 131 private void copyToArray(Item i, int index) { 132 if (mIOBuffer == null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */); 133 mIOBuffer.reset(index * mElement.getBytesSize()); 134 copyToArrayLocal(i, mIOBuffer); 135 } 136 137 public synchronized void set(Item i, int index, boolean copyNow) { 138 if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */]; 139 mItemArray[index] = i; 140 if (copyNow) { 141 copyToArray(i, index); 142 FieldPacker fp = new FieldPacker(mElement.getBytesSize()); 143 copyToArrayLocal(i, fp); 144 mAllocation.setFromFieldPacker(index, fp); 145 } 146 147 } 148 149 public synchronized Item get(int index) { 150 if (mItemArray == null) return null; 151 return mItemArray[index]; 152 } 153 154 public synchronized void set_i(int index, int v, boolean copyNow) { 155 if (mIOBuffer == null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */); 156 if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */]; 157 if (mItemArray[index] == null) mItemArray[index] = new Item(); 158 mItemArray[index].i = v; 159 if (copyNow) { 160 mIOBuffer.reset(index * mElement.getBytesSize()); 161 mIOBuffer.addI32(v); 162 FieldPacker fp = new FieldPacker(4); 163 fp.addI32(v); 164 mAllocation.setFromFieldPacker(index, 0, fp); 165 } 166 167 } 168 169 public synchronized void set_a(int index, Allocation v, boolean copyNow) { 170 if (mIOBuffer == null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */); 171 if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */]; 172 if (mItemArray[index] == null) mItemArray[index] = new Item(); 173 mItemArray[index].a = v; 174 if (copyNow) { 175 mIOBuffer.reset(index * mElement.getBytesSize() + (sIs64Bit ? 8 : 4)); 176 mIOBuffer.addObj(v); 177 FieldPacker fp = new FieldPacker(sIs64Bit ? 32 : 4); 178 fp.addObj(v); 179 mAllocation.setFromFieldPacker(index, sIs64Bit ? 2 : 1, fp); 180 } 181 182 } 183 184 public synchronized void set_j(int index, int v, boolean copyNow) { 185 if (mIOBuffer == null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */); 186 if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */]; 187 if (mItemArray[index] == null) mItemArray[index] = new Item(); 188 mItemArray[index].j = v; 189 if (copyNow) { 190 mIOBuffer.reset(index * mElement.getBytesSize() + (sIs64Bit ? 40 : 8)); 191 mIOBuffer.addI32(v); 192 FieldPacker fp = new FieldPacker(4); 193 fp.addI32(v); 194 mAllocation.setFromFieldPacker(index, sIs64Bit ? 3 : 2, fp); 195 } 196 197 } 198 199 public synchronized int get_i(int index) { 200 if (mItemArray == null) return 0; 201 return mItemArray[index].i; 202 } 203 204 public synchronized Allocation get_a(int index) { 205 if (mItemArray == null) return null; 206 return mItemArray[index].a; 207 } 208 209 public synchronized int get_j(int index) { 210 if (mItemArray == null) return 0; 211 return mItemArray[index].j; 212 } 213 214 public synchronized void copyAll() { 215 for (int ct = 0; ct < mItemArray.length; ct++) copyToArray(mItemArray[ct], ct); 216 mAllocation.setFromFieldPacker(0, mIOBuffer); 217 } 218 219 public synchronized void resize(int newSize) { 220 if (mItemArray != null) { 221 int oldSize = mItemArray.length; 222 int copySize = Math.min(oldSize, newSize); 223 if (newSize == oldSize) return; 224 Item ni[] = new Item[newSize]; 225 System.arraycopy(mItemArray, 0, ni, 0, copySize); 226 mItemArray = ni; 227 } 228 229 mAllocation.resize(newSize); 230 if (mIOBuffer != null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */); 231 } 232 233 private static boolean sIs64Bit; 234 235 static { 236 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 237 sIs64Bit = Process.is64Bit(); 238 } 239 240 else { 241 try { 242 Field f = RenderScript.class.getDeclaredField("sPointerSize"); 243 f.setAccessible(true); 244 sIs64Bit = (f.getInt(null) == 8); 245 } 246 247 catch (Throwable e) { 248 sIs64Bit = false; 249 } 250 251 } 252 253 } 254 255} 256 257