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