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