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_InnerOne extends android.renderscript.Script.FieldBase {
31    static public class Item {
32
33        int x;
34        int y;
35        float f;
36
37        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.I32(rs), "x");
48        eb.add(Element.I32(rs), "y");
49        eb.add(Element.F32(rs), "f");
50        return eb.create();
51    }
52
53    private  ScriptField_InnerOne(RenderScript rs) {
54        mItemArray = null;
55        mIOBuffer = null;
56        mElement = createElement(rs);
57    }
58
59    public  ScriptField_InnerOne(RenderScript rs, int count) {
60        mItemArray = null;
61        mIOBuffer = null;
62        mElement = createElement(rs);
63        init(rs, count);
64    }
65
66    public  ScriptField_InnerOne(RenderScript rs, int count, int usages) {
67        mItemArray = null;
68        mIOBuffer = null;
69        mElement = createElement(rs);
70        init(rs, count, usages);
71    }
72
73    public static ScriptField_InnerOne create1D(RenderScript rs, int dimX, int usages) {
74        ScriptField_InnerOne obj = new ScriptField_InnerOne(rs);
75        obj.mAllocation = Allocation.createSized(rs, obj.mElement, dimX, usages);
76        return obj;
77    }
78
79    public static ScriptField_InnerOne create1D(RenderScript rs, int dimX) {
80        return create1D(rs, dimX, Allocation.USAGE_SCRIPT);
81    }
82
83    public static ScriptField_InnerOne create2D(RenderScript rs, int dimX, int dimY) {
84        return create2D(rs, dimX, dimY, Allocation.USAGE_SCRIPT);
85    }
86
87    public static ScriptField_InnerOne create2D(RenderScript rs, int dimX, int dimY, int usages) {
88        ScriptField_InnerOne obj = new ScriptField_InnerOne(rs);
89        Type.Builder b = new Type.Builder(rs, obj.mElement);
90        b.setX(dimX);
91        b.setY(dimY);
92        Type t = b.create();
93        obj.mAllocation = Allocation.createTyped(rs, t, usages);
94        return obj;
95    }
96
97    public static Type.Builder createTypeBuilder(RenderScript rs) {
98        Element e = createElement(rs);
99        return new Type.Builder(rs, e);
100    }
101
102    public static ScriptField_InnerOne createCustom(RenderScript rs, Type.Builder tb, int usages) {
103        ScriptField_InnerOne obj = new ScriptField_InnerOne(rs);
104        Type t = tb.create();
105        if (t.getElement() != obj.mElement) {
106            throw new RSIllegalArgumentException("Type.Builder did not match expected element type.");
107        }
108        obj.mAllocation = Allocation.createTyped(rs, t, usages);
109        return obj;
110    }
111
112    private void copyToArrayLocal(Item i, FieldPacker fp) {
113        fp.addI32(i.x);
114        fp.addI32(i.y);
115        fp.addF32(i.f);
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_x(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].x = 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_y(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].y = 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 void set_f(int index, float v, boolean copyNow) {
172        if (mIOBuffer == null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */);
173        if (mItemArray == null) mItemArray = new Item[getType().getX() /* count */];
174        if (mItemArray[index] == null) mItemArray[index] = new Item();
175        mItemArray[index].f = v;
176        if (copyNow)  {
177            mIOBuffer.reset(index * mElement.getBytesSize() + 8);
178            mIOBuffer.addF32(v);
179            FieldPacker fp = new FieldPacker(4);
180            fp.addF32(v);
181            mAllocation.setFromFieldPacker(index, 2, fp);
182        }
183
184    }
185
186    public synchronized int get_x(int index) {
187        if (mItemArray == null) return 0;
188        return mItemArray[index].x;
189    }
190
191    public synchronized int get_y(int index) {
192        if (mItemArray == null) return 0;
193        return mItemArray[index].y;
194    }
195
196    public synchronized float get_f(int index) {
197        if (mItemArray == null) return 0;
198        return mItemArray[index].f;
199    }
200
201    public synchronized void copyAll() {
202        for (int ct = 0; ct < mItemArray.length; ct++) copyToArray(mItemArray[ct], ct);
203        mAllocation.setFromFieldPacker(0, mIOBuffer);
204    }
205
206    public synchronized void resize(int newSize) {
207        if (mItemArray != null)  {
208            int oldSize = mItemArray.length;
209            int copySize = Math.min(oldSize, newSize);
210            if (newSize == oldSize) return;
211            Item ni[] = new Item[newSize];
212            System.arraycopy(mItemArray, 0, ni, 0, copySize);
213            mItemArray = ni;
214        }
215
216        mAllocation.resize(newSize);
217        if (mIOBuffer != null) mIOBuffer = new FieldPacker(mElement.getBytesSize() * getType().getX()/* count */);
218    }
219
220}
221
222