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