Loading graphics/java/android/renderscript/Allocation.java +16 −101 Original line number Diff line number Diff line Loading @@ -40,8 +40,6 @@ public class Allocation extends BaseObj { public static final int USAGE_GRAPHICS_VERTEX = 0x0004; public static final int USAGE_GRAPHICS_CONSTANTS = 0x0008; private static final int USAGE_ALL = 0x000F; public enum CubemapLayout { VERTICAL_FACE_LIST (0), Loading @@ -55,6 +53,7 @@ public class Allocation extends BaseObj { } } public enum MipmapControl { MIPMAP_NONE(0), MIPMAP_FULL(1), Loading @@ -68,7 +67,10 @@ public class Allocation extends BaseObj { Allocation(int id, RenderScript rs, Type t, int usage) { super(id, rs); if (usage > USAGE_ALL) { if ((usage & ~(USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE | USAGE_GRAPHICS_VERTEX | USAGE_GRAPHICS_CONSTANTS)) != 0) { throw new RSIllegalArgumentException("Unknown usage specified."); } mType = t; Loading Loading @@ -160,7 +162,7 @@ public class Allocation extends BaseObj { " not divisible by element size " + eSize + "."); } data1DChecks(xoff, count, data.length, data.length); mRS.nAllocationSubData1D(getID(), xoff, count, data, data.length); mRS.nAllocationData1D(getID(), xoff, 0, count, data, data.length); } Loading @@ -180,7 +182,7 @@ public class Allocation extends BaseObj { " does not match component size " + eSize + "."); } mRS.nAllocationSubElementData1D(getID(), xoff, component_number, data, data.length); mRS.nAllocationElementData1D(getID(), xoff, 0, component_number, data, data.length); } private void data1DChecks(int off, int count, int len, int dataSize) { Loading @@ -203,33 +205,33 @@ public class Allocation extends BaseObj { public void subData1D(int off, int count, int[] d) { int dataSize = mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 4, dataSize); mRS.nAllocationSubData1D(getID(), off, count, d, dataSize); mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize); } public void subData1D(int off, int count, short[] d) { int dataSize = mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 2, dataSize); mRS.nAllocationSubData1D(getID(), off, count, d, dataSize); mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize); } public void subData1D(int off, int count, byte[] d) { int dataSize = mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length, dataSize); mRS.nAllocationSubData1D(getID(), off, count, d, dataSize); mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize); } public void subData1D(int off, int count, float[] d) { int dataSize = mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 4, dataSize); mRS.nAllocationSubData1D(getID(), off, count, d, dataSize); mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize); } public void subData2D(int xoff, int yoff, int w, int h, int[] d) { mRS.validate(); mRS.nAllocationSubData2D(getID(), xoff, yoff, w, h, d, d.length * 4); mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, d, d.length * 4); } public void subData2D(int xoff, int yoff, int w, int h, float[] d) { mRS.validate(); mRS.nAllocationSubData2D(getID(), xoff, yoff, w, h, d, d.length * 4); mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, d, d.length * 4); } public void readData(int[] d) { Loading Loading @@ -266,98 +268,11 @@ public class Allocation extends BaseObj { } */ /* public class Adapter1D extends BaseObj { Adapter1D(int id, RenderScript rs) { super(id, rs); } public void setConstraint(Dimension dim, int value) { mRS.validate(); mRS.nAdapter1DSetConstraint(getID(), dim.mID, value); } public void data(int[] d) { mRS.validate(); mRS.nAdapter1DData(getID(), d); } public void data(float[] d) { mRS.validate(); mRS.nAdapter1DData(getID(), d); } public void subData(int off, int count, int[] d) { mRS.validate(); mRS.nAdapter1DSubData(getID(), off, count, d); } public void subData(int off, int count, float[] d) { mRS.validate(); mRS.nAdapter1DSubData(getID(), off, count, d); } } public Adapter1D createAdapter1D() { mRS.validate(); int id = mRS.nAdapter1DCreate(); if(id == 0) { throw new RSRuntimeException("Adapter creation failed."); } mRS.nAdapter1DBindAllocation(id, getID()); return new Adapter1D(id, mRS); } */ public class Adapter2D extends BaseObj { Adapter2D(int id, RenderScript rs) { super(id, rs); } public void setConstraint(Dimension dim, int value) { mRS.validate(); mRS.nAdapter2DSetConstraint(getID(), dim.mID, value); } public void data(int[] d) { mRS.validate(); mRS.nAdapter2DData(getID(), d); } public void data(float[] d) { mRS.validate(); mRS.nAdapter2DData(getID(), d); } public void subData(int xoff, int yoff, int w, int h, int[] d) { mRS.validate(); mRS.nAdapter2DSubData(getID(), xoff, yoff, w, h, d); } public void subData(int xoff, int yoff, int w, int h, float[] d) { mRS.validate(); mRS.nAdapter2DSubData(getID(), xoff, yoff, w, h, d); } } public Adapter2D createAdapter2D() { mRS.validate(); int id = mRS.nAdapter2DCreate(); if(id == 0) { throw new RSRuntimeException("allocation failed."); } mRS.nAdapter2DBindAllocation(id, getID()); if(id == 0) { throw new RSRuntimeException("Adapter creation failed."); } return new Adapter2D(id, mRS); } // creation private static BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options(); static BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options(); static { mBitmapOptions.inScaled = false; } Loading Loading @@ -400,7 +315,7 @@ public class Allocation extends BaseObj { return createSized(rs, e, count, USAGE_SCRIPT); } static private Element elementFromBitmap(RenderScript rs, Bitmap b) { static Element elementFromBitmap(RenderScript rs, Bitmap b) { final Bitmap.Config bc = b.getConfig(); if (bc == Bitmap.Config.ALPHA_8) { return Element.A_8(rs); Loading @@ -417,7 +332,7 @@ public class Allocation extends BaseObj { throw new RSInvalidStateException("Bad bitmap type: " + bc); } static private Type typeFromBitmap(RenderScript rs, Bitmap b, static Type typeFromBitmap(RenderScript rs, Bitmap b, MipmapControl mip) { Element e = elementFromBitmap(rs, b); Type.Builder tb = new Type.Builder(rs, e); Loading graphics/java/android/renderscript/AllocationAdapter.java 0 → 100644 +213 −0 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.renderscript; import android.content.res.Resources; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.Log; import android.util.TypedValue; /** * @hide * **/ public class AllocationAdapter extends Allocation { private int mSelectedDimX; private int mSelectedDimY; private int mSelectedCount; private Allocation mAlloc; private int mSelectedLOD = 0; private Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITVE_X;; AllocationAdapter(int id, RenderScript rs, Allocation alloc) { super(id, rs, null, alloc.mUsage); Type t = alloc.getType(); mSelectedDimX = t.getX(); mSelectedDimY = t.getY(); mSelectedCount = t.getCount(); } public void copyFrom(BaseObj[] d) { mRS.validate(); if (d.length != mSelectedCount) { throw new RSIllegalArgumentException("Array size mismatch, allocation size = " + mSelectedCount + ", array length = " + d.length); } int i[] = new int[d.length]; for (int ct=0; ct < d.length; ct++) { i[ct] = d[ct].getID(); } subData1D(0, mType.getCount(), i); } void validateBitmap(Bitmap b) { mRS.validate(); if(mSelectedDimX != b.getWidth() || mSelectedDimY != b.getHeight()) { throw new RSIllegalArgumentException("Cannot update allocation from bitmap, sizes mismatch"); } } public void copyFrom(int[] d) { mRS.validate(); subData1D(0, mSelectedCount, d); } public void copyFrom(short[] d) { mRS.validate(); subData1D(0, mSelectedCount, d); } public void copyFrom(byte[] d) { mRS.validate(); subData1D(0, mSelectedCount, d); } public void copyFrom(float[] d) { mRS.validate(); subData1D(0, mSelectedCount, d); } public void copyFrom(Bitmap b) { validateBitmap(b); mRS.nAllocationCopyFromBitmap(getID(), b); } public void copyTo(Bitmap b) { validateBitmap(b); mRS.nAllocationCopyToBitmap(getID(), b); } public void subData(int xoff, FieldPacker fp) { int eSize = mType.mElement.getSizeBytes(); final byte[] data = fp.getData(); int count = data.length / eSize; if ((eSize * count) != data.length) { throw new RSIllegalArgumentException("Field packer length " + data.length + " not divisible by element size " + eSize + "."); } data1DChecks(xoff, count, data.length, data.length); mRS.nAllocationData1D(getID(), xoff, mSelectedLOD, count, data, data.length); } public void subElementData(int xoff, int component_number, FieldPacker fp) { if (component_number >= mType.mElement.mElements.length) { throw new RSIllegalArgumentException("Component_number " + component_number + " out of range."); } if(xoff < 0) { throw new RSIllegalArgumentException("Offset must be >= 0."); } final byte[] data = fp.getData(); int eSize = mType.mElement.mElements[component_number].getSizeBytes(); if (data.length != eSize) { throw new RSIllegalArgumentException("Field packer sizelength " + data.length + " does not match component size " + eSize + "."); } mRS.nAllocationElementData1D(getID(), xoff, mSelectedLOD, component_number, data, data.length); } void data1DChecks(int off, int count, int len, int dataSize) { mRS.validate(); if(off < 0) { throw new RSIllegalArgumentException("Offset must be >= 0."); } if(count < 1) { throw new RSIllegalArgumentException("Count must be >= 1."); } if((off + count) > mSelectedDimX * mSelectedDimY) { throw new RSIllegalArgumentException("Overflow, Available count " + mType.getCount() + ", got " + count + " at offset " + off + "."); } if((len) < dataSize) { throw new RSIllegalArgumentException("Array too small for allocation type."); } } public void subData1D(int off, int count, int[] d) { int dataSize = mAlloc.mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 4, dataSize); mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize); } public void subData1D(int off, int count, short[] d) { int dataSize = mAlloc.mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 2, dataSize); mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize); } public void subData1D(int off, int count, byte[] d) { int dataSize = mAlloc.mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length, dataSize); mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize); } public void subData1D(int off, int count, float[] d) { int dataSize = mAlloc.mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 4, dataSize); mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize); } public void subData2D(int xoff, int yoff, int w, int h, int[] d) { mRS.validate(); mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, d, d.length * 4); } public void subData2D(int xoff, int yoff, int w, int h, float[] d) { mRS.validate(); mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, d, d.length * 4); } public void readData(int[] d) { mRS.validate(); mRS.nAllocationRead(getID(), d); } public void readData(float[] d) { mRS.validate(); mRS.nAllocationRead(getID(), d); } public void setLOD(int lod) { } public void setFace(Type.CubemapFace cf) { } public void setY(int y) { } public void setZ(int z) { } // creation //static public AllocationAdapter create1D(RenderScript rs, Allocation a) { //} static public AllocationAdapter create2D(RenderScript rs, Allocation a) { rs.validate(); AllocationAdapter aa = new AllocationAdapter(0, rs, a); return aa; } } graphics/java/android/renderscript/RenderScript.java +23 −86 Original line number Diff line number Diff line Loading @@ -228,44 +228,38 @@ public class RenderScript { rsnAllocationCopyFromBitmap(mContext, alloc, bmp); } native void rsnAllocationUploadToTexture(int con, int alloc, boolean genMips, int baseMioLevel); synchronized void nAllocationUploadToTexture(int alloc, boolean genMips, int baseMioLevel) { rsnAllocationUploadToTexture(mContext, alloc, genMips, baseMioLevel); } native void rsnAllocationUploadToBufferObject(int con, int alloc); synchronized void nAllocationUploadToBufferObject(int alloc) { rsnAllocationUploadToBufferObject(mContext, alloc); } native void rsnAllocationSubData1D(int con, int id, int off, int count, int[] d, int sizeBytes); synchronized void nAllocationSubData1D(int id, int off, int count, int[] d, int sizeBytes) { rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); native void rsnAllocationData1D(int con, int id, int off, int mip, int count, int[] d, int sizeBytes); synchronized void nAllocationData1D(int id, int off, int mip, int count, int[] d, int sizeBytes) { rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes); } native void rsnAllocationSubData1D(int con, int id, int off, int count, short[] d, int sizeBytes); synchronized void nAllocationSubData1D(int id, int off, int count, short[] d, int sizeBytes) { rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); native void rsnAllocationData1D(int con, int id, int off, int mip, int count, short[] d, int sizeBytes); synchronized void nAllocationData1D(int id, int off, int mip, int count, short[] d, int sizeBytes) { rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes); } native void rsnAllocationSubData1D(int con, int id, int off, int count, byte[] d, int sizeBytes); synchronized void nAllocationSubData1D(int id, int off, int count, byte[] d, int sizeBytes) { rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); native void rsnAllocationData1D(int con, int id, int off, int mip, int count, byte[] d, int sizeBytes); synchronized void nAllocationData1D(int id, int off, int mip, int count, byte[] d, int sizeBytes) { rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes); } native void rsnAllocationSubElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes); synchronized void nAllocationSubElementData1D(int id, int xoff, int compIdx, byte[] d, int sizeBytes) { rsnAllocationSubElementData1D(mContext, id, xoff, compIdx, d, sizeBytes); native void rsnAllocationData1D(int con, int id, int off, int mip, int count, float[] d, int sizeBytes); synchronized void nAllocationData1D(int id, int off, int mip, int count, float[] d, int sizeBytes) { rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes); } native void rsnAllocationSubData1D(int con, int id, int off, int count, float[] d, int sizeBytes); synchronized void nAllocationSubData1D(int id, int off, int count, float[] d, int sizeBytes) { rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); native void rsnAllocationElementData1D(int con, int id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes); synchronized void nAllocationElementData1D(int id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes) { rsnAllocationElementData1D(mContext, id, xoff, mip, compIdx, d, sizeBytes); } native void rsnAllocationSubData2D(int con, int id, int xoff, int yoff, int w, int h, int[] d, int sizeBytes); synchronized void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d, int sizeBytes) { rsnAllocationSubData2D(mContext, id, xoff, yoff, w, h, d, sizeBytes); native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes); synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes) { rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes); } native void rsnAllocationSubData2D(int con, int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes); synchronized void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes) { rsnAllocationSubData2D(mContext, id, xoff, yoff, w, h, d, sizeBytes); native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes); synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes) { rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes); } native void rsnAllocationRead(int con, int id, int[] d); synchronized void nAllocationRead(int id, int[] d) { rsnAllocationRead(mContext, id, d); Loading Loading @@ -310,63 +304,6 @@ public class RenderScript { return rsnFontCreateFromFile(mContext, fileName, size, dpi); } native void rsnAdapter1DBindAllocation(int con, int ad, int alloc); synchronized void nAdapter1DBindAllocation(int ad, int alloc) { rsnAdapter1DBindAllocation(mContext, ad, alloc); } native void rsnAdapter1DSetConstraint(int con, int ad, int dim, int value); synchronized void nAdapter1DSetConstraint(int ad, int dim, int value) { rsnAdapter1DSetConstraint(mContext, ad, dim, value); } native void rsnAdapter1DData(int con, int ad, int[] d); synchronized void nAdapter1DData(int ad, int[] d) { rsnAdapter1DData(mContext, ad, d); } native void rsnAdapter1DData(int con, int ad, float[] d); synchronized void nAdapter1DData(int ad, float[] d) { rsnAdapter1DData(mContext, ad, d); } native void rsnAdapter1DSubData(int con, int ad, int off, int count, int[] d); synchronized void nAdapter1DSubData(int ad, int off, int count, int[] d) { rsnAdapter1DSubData(mContext, ad, off, count, d); } native void rsnAdapter1DSubData(int con, int ad, int off, int count, float[] d); synchronized void nAdapter1DSubData(int ad, int off, int count, float[] d) { rsnAdapter1DSubData(mContext, ad, off, count, d); } native int rsnAdapter1DCreate(int con); synchronized int nAdapter1DCreate() { return rsnAdapter1DCreate(mContext); } native void rsnAdapter2DBindAllocation(int con, int ad, int alloc); synchronized void nAdapter2DBindAllocation(int ad, int alloc) { rsnAdapter2DBindAllocation(mContext, ad, alloc); } native void rsnAdapter2DSetConstraint(int con, int ad, int dim, int value); synchronized void nAdapter2DSetConstraint(int ad, int dim, int value) { rsnAdapter2DSetConstraint(mContext, ad, dim, value); } native void rsnAdapter2DData(int con, int ad, int[] d); synchronized void nAdapter2DData(int ad, int[] d) { rsnAdapter2DData(mContext, ad, d); } native void rsnAdapter2DData(int con, int ad, float[] d); synchronized void nAdapter2DData(int ad, float[] d) { rsnAdapter2DData(mContext, ad, d); } native void rsnAdapter2DSubData(int con, int ad, int xoff, int yoff, int w, int h, int[] d); synchronized void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, int[] d) { rsnAdapter2DSubData(mContext, ad, xoff, yoff, w, h, d); } native void rsnAdapter2DSubData(int con, int ad, int xoff, int yoff, int w, int h, float[] d); synchronized void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, float[] d) { rsnAdapter2DSubData(mContext, ad, xoff, yoff, w, h, d); } native int rsnAdapter2DCreate(int con); synchronized int nAdapter2DCreate() { return rsnAdapter2DCreate(mContext); } native void rsnScriptBindAllocation(int con, int script, int alloc, int slot); synchronized void nScriptBindAllocation(int script, int alloc, int slot) { Loading graphics/java/android/renderscript/Type.java +14 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,20 @@ public class Type extends BaseObj { int mElementCount; Element mElement; public enum CubemapFace { POSITVE_X (0), NEGATIVE_X (1), POSITVE_Y (2), NEGATIVE_Y (3), POSITVE_Z (4), NEGATIVE_Z (5); int mID; CubemapFace(int id) { mID = id; } } /** * Return the element associated with this Type. * Loading graphics/jni/android_renderscript_RenderScript.cpp +33 −192 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
graphics/java/android/renderscript/Allocation.java +16 −101 Original line number Diff line number Diff line Loading @@ -40,8 +40,6 @@ public class Allocation extends BaseObj { public static final int USAGE_GRAPHICS_VERTEX = 0x0004; public static final int USAGE_GRAPHICS_CONSTANTS = 0x0008; private static final int USAGE_ALL = 0x000F; public enum CubemapLayout { VERTICAL_FACE_LIST (0), Loading @@ -55,6 +53,7 @@ public class Allocation extends BaseObj { } } public enum MipmapControl { MIPMAP_NONE(0), MIPMAP_FULL(1), Loading @@ -68,7 +67,10 @@ public class Allocation extends BaseObj { Allocation(int id, RenderScript rs, Type t, int usage) { super(id, rs); if (usage > USAGE_ALL) { if ((usage & ~(USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE | USAGE_GRAPHICS_VERTEX | USAGE_GRAPHICS_CONSTANTS)) != 0) { throw new RSIllegalArgumentException("Unknown usage specified."); } mType = t; Loading Loading @@ -160,7 +162,7 @@ public class Allocation extends BaseObj { " not divisible by element size " + eSize + "."); } data1DChecks(xoff, count, data.length, data.length); mRS.nAllocationSubData1D(getID(), xoff, count, data, data.length); mRS.nAllocationData1D(getID(), xoff, 0, count, data, data.length); } Loading @@ -180,7 +182,7 @@ public class Allocation extends BaseObj { " does not match component size " + eSize + "."); } mRS.nAllocationSubElementData1D(getID(), xoff, component_number, data, data.length); mRS.nAllocationElementData1D(getID(), xoff, 0, component_number, data, data.length); } private void data1DChecks(int off, int count, int len, int dataSize) { Loading @@ -203,33 +205,33 @@ public class Allocation extends BaseObj { public void subData1D(int off, int count, int[] d) { int dataSize = mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 4, dataSize); mRS.nAllocationSubData1D(getID(), off, count, d, dataSize); mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize); } public void subData1D(int off, int count, short[] d) { int dataSize = mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 2, dataSize); mRS.nAllocationSubData1D(getID(), off, count, d, dataSize); mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize); } public void subData1D(int off, int count, byte[] d) { int dataSize = mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length, dataSize); mRS.nAllocationSubData1D(getID(), off, count, d, dataSize); mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize); } public void subData1D(int off, int count, float[] d) { int dataSize = mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 4, dataSize); mRS.nAllocationSubData1D(getID(), off, count, d, dataSize); mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize); } public void subData2D(int xoff, int yoff, int w, int h, int[] d) { mRS.validate(); mRS.nAllocationSubData2D(getID(), xoff, yoff, w, h, d, d.length * 4); mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, d, d.length * 4); } public void subData2D(int xoff, int yoff, int w, int h, float[] d) { mRS.validate(); mRS.nAllocationSubData2D(getID(), xoff, yoff, w, h, d, d.length * 4); mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, d, d.length * 4); } public void readData(int[] d) { Loading Loading @@ -266,98 +268,11 @@ public class Allocation extends BaseObj { } */ /* public class Adapter1D extends BaseObj { Adapter1D(int id, RenderScript rs) { super(id, rs); } public void setConstraint(Dimension dim, int value) { mRS.validate(); mRS.nAdapter1DSetConstraint(getID(), dim.mID, value); } public void data(int[] d) { mRS.validate(); mRS.nAdapter1DData(getID(), d); } public void data(float[] d) { mRS.validate(); mRS.nAdapter1DData(getID(), d); } public void subData(int off, int count, int[] d) { mRS.validate(); mRS.nAdapter1DSubData(getID(), off, count, d); } public void subData(int off, int count, float[] d) { mRS.validate(); mRS.nAdapter1DSubData(getID(), off, count, d); } } public Adapter1D createAdapter1D() { mRS.validate(); int id = mRS.nAdapter1DCreate(); if(id == 0) { throw new RSRuntimeException("Adapter creation failed."); } mRS.nAdapter1DBindAllocation(id, getID()); return new Adapter1D(id, mRS); } */ public class Adapter2D extends BaseObj { Adapter2D(int id, RenderScript rs) { super(id, rs); } public void setConstraint(Dimension dim, int value) { mRS.validate(); mRS.nAdapter2DSetConstraint(getID(), dim.mID, value); } public void data(int[] d) { mRS.validate(); mRS.nAdapter2DData(getID(), d); } public void data(float[] d) { mRS.validate(); mRS.nAdapter2DData(getID(), d); } public void subData(int xoff, int yoff, int w, int h, int[] d) { mRS.validate(); mRS.nAdapter2DSubData(getID(), xoff, yoff, w, h, d); } public void subData(int xoff, int yoff, int w, int h, float[] d) { mRS.validate(); mRS.nAdapter2DSubData(getID(), xoff, yoff, w, h, d); } } public Adapter2D createAdapter2D() { mRS.validate(); int id = mRS.nAdapter2DCreate(); if(id == 0) { throw new RSRuntimeException("allocation failed."); } mRS.nAdapter2DBindAllocation(id, getID()); if(id == 0) { throw new RSRuntimeException("Adapter creation failed."); } return new Adapter2D(id, mRS); } // creation private static BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options(); static BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options(); static { mBitmapOptions.inScaled = false; } Loading Loading @@ -400,7 +315,7 @@ public class Allocation extends BaseObj { return createSized(rs, e, count, USAGE_SCRIPT); } static private Element elementFromBitmap(RenderScript rs, Bitmap b) { static Element elementFromBitmap(RenderScript rs, Bitmap b) { final Bitmap.Config bc = b.getConfig(); if (bc == Bitmap.Config.ALPHA_8) { return Element.A_8(rs); Loading @@ -417,7 +332,7 @@ public class Allocation extends BaseObj { throw new RSInvalidStateException("Bad bitmap type: " + bc); } static private Type typeFromBitmap(RenderScript rs, Bitmap b, static Type typeFromBitmap(RenderScript rs, Bitmap b, MipmapControl mip) { Element e = elementFromBitmap(rs, b); Type.Builder tb = new Type.Builder(rs, e); Loading
graphics/java/android/renderscript/AllocationAdapter.java 0 → 100644 +213 −0 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.renderscript; import android.content.res.Resources; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.Log; import android.util.TypedValue; /** * @hide * **/ public class AllocationAdapter extends Allocation { private int mSelectedDimX; private int mSelectedDimY; private int mSelectedCount; private Allocation mAlloc; private int mSelectedLOD = 0; private Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITVE_X;; AllocationAdapter(int id, RenderScript rs, Allocation alloc) { super(id, rs, null, alloc.mUsage); Type t = alloc.getType(); mSelectedDimX = t.getX(); mSelectedDimY = t.getY(); mSelectedCount = t.getCount(); } public void copyFrom(BaseObj[] d) { mRS.validate(); if (d.length != mSelectedCount) { throw new RSIllegalArgumentException("Array size mismatch, allocation size = " + mSelectedCount + ", array length = " + d.length); } int i[] = new int[d.length]; for (int ct=0; ct < d.length; ct++) { i[ct] = d[ct].getID(); } subData1D(0, mType.getCount(), i); } void validateBitmap(Bitmap b) { mRS.validate(); if(mSelectedDimX != b.getWidth() || mSelectedDimY != b.getHeight()) { throw new RSIllegalArgumentException("Cannot update allocation from bitmap, sizes mismatch"); } } public void copyFrom(int[] d) { mRS.validate(); subData1D(0, mSelectedCount, d); } public void copyFrom(short[] d) { mRS.validate(); subData1D(0, mSelectedCount, d); } public void copyFrom(byte[] d) { mRS.validate(); subData1D(0, mSelectedCount, d); } public void copyFrom(float[] d) { mRS.validate(); subData1D(0, mSelectedCount, d); } public void copyFrom(Bitmap b) { validateBitmap(b); mRS.nAllocationCopyFromBitmap(getID(), b); } public void copyTo(Bitmap b) { validateBitmap(b); mRS.nAllocationCopyToBitmap(getID(), b); } public void subData(int xoff, FieldPacker fp) { int eSize = mType.mElement.getSizeBytes(); final byte[] data = fp.getData(); int count = data.length / eSize; if ((eSize * count) != data.length) { throw new RSIllegalArgumentException("Field packer length " + data.length + " not divisible by element size " + eSize + "."); } data1DChecks(xoff, count, data.length, data.length); mRS.nAllocationData1D(getID(), xoff, mSelectedLOD, count, data, data.length); } public void subElementData(int xoff, int component_number, FieldPacker fp) { if (component_number >= mType.mElement.mElements.length) { throw new RSIllegalArgumentException("Component_number " + component_number + " out of range."); } if(xoff < 0) { throw new RSIllegalArgumentException("Offset must be >= 0."); } final byte[] data = fp.getData(); int eSize = mType.mElement.mElements[component_number].getSizeBytes(); if (data.length != eSize) { throw new RSIllegalArgumentException("Field packer sizelength " + data.length + " does not match component size " + eSize + "."); } mRS.nAllocationElementData1D(getID(), xoff, mSelectedLOD, component_number, data, data.length); } void data1DChecks(int off, int count, int len, int dataSize) { mRS.validate(); if(off < 0) { throw new RSIllegalArgumentException("Offset must be >= 0."); } if(count < 1) { throw new RSIllegalArgumentException("Count must be >= 1."); } if((off + count) > mSelectedDimX * mSelectedDimY) { throw new RSIllegalArgumentException("Overflow, Available count " + mType.getCount() + ", got " + count + " at offset " + off + "."); } if((len) < dataSize) { throw new RSIllegalArgumentException("Array too small for allocation type."); } } public void subData1D(int off, int count, int[] d) { int dataSize = mAlloc.mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 4, dataSize); mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize); } public void subData1D(int off, int count, short[] d) { int dataSize = mAlloc.mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 2, dataSize); mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize); } public void subData1D(int off, int count, byte[] d) { int dataSize = mAlloc.mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length, dataSize); mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize); } public void subData1D(int off, int count, float[] d) { int dataSize = mAlloc.mType.mElement.getSizeBytes() * count; data1DChecks(off, count, d.length * 4, dataSize); mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize); } public void subData2D(int xoff, int yoff, int w, int h, int[] d) { mRS.validate(); mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, d, d.length * 4); } public void subData2D(int xoff, int yoff, int w, int h, float[] d) { mRS.validate(); mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, d, d.length * 4); } public void readData(int[] d) { mRS.validate(); mRS.nAllocationRead(getID(), d); } public void readData(float[] d) { mRS.validate(); mRS.nAllocationRead(getID(), d); } public void setLOD(int lod) { } public void setFace(Type.CubemapFace cf) { } public void setY(int y) { } public void setZ(int z) { } // creation //static public AllocationAdapter create1D(RenderScript rs, Allocation a) { //} static public AllocationAdapter create2D(RenderScript rs, Allocation a) { rs.validate(); AllocationAdapter aa = new AllocationAdapter(0, rs, a); return aa; } }
graphics/java/android/renderscript/RenderScript.java +23 −86 Original line number Diff line number Diff line Loading @@ -228,44 +228,38 @@ public class RenderScript { rsnAllocationCopyFromBitmap(mContext, alloc, bmp); } native void rsnAllocationUploadToTexture(int con, int alloc, boolean genMips, int baseMioLevel); synchronized void nAllocationUploadToTexture(int alloc, boolean genMips, int baseMioLevel) { rsnAllocationUploadToTexture(mContext, alloc, genMips, baseMioLevel); } native void rsnAllocationUploadToBufferObject(int con, int alloc); synchronized void nAllocationUploadToBufferObject(int alloc) { rsnAllocationUploadToBufferObject(mContext, alloc); } native void rsnAllocationSubData1D(int con, int id, int off, int count, int[] d, int sizeBytes); synchronized void nAllocationSubData1D(int id, int off, int count, int[] d, int sizeBytes) { rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); native void rsnAllocationData1D(int con, int id, int off, int mip, int count, int[] d, int sizeBytes); synchronized void nAllocationData1D(int id, int off, int mip, int count, int[] d, int sizeBytes) { rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes); } native void rsnAllocationSubData1D(int con, int id, int off, int count, short[] d, int sizeBytes); synchronized void nAllocationSubData1D(int id, int off, int count, short[] d, int sizeBytes) { rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); native void rsnAllocationData1D(int con, int id, int off, int mip, int count, short[] d, int sizeBytes); synchronized void nAllocationData1D(int id, int off, int mip, int count, short[] d, int sizeBytes) { rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes); } native void rsnAllocationSubData1D(int con, int id, int off, int count, byte[] d, int sizeBytes); synchronized void nAllocationSubData1D(int id, int off, int count, byte[] d, int sizeBytes) { rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); native void rsnAllocationData1D(int con, int id, int off, int mip, int count, byte[] d, int sizeBytes); synchronized void nAllocationData1D(int id, int off, int mip, int count, byte[] d, int sizeBytes) { rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes); } native void rsnAllocationSubElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes); synchronized void nAllocationSubElementData1D(int id, int xoff, int compIdx, byte[] d, int sizeBytes) { rsnAllocationSubElementData1D(mContext, id, xoff, compIdx, d, sizeBytes); native void rsnAllocationData1D(int con, int id, int off, int mip, int count, float[] d, int sizeBytes); synchronized void nAllocationData1D(int id, int off, int mip, int count, float[] d, int sizeBytes) { rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes); } native void rsnAllocationSubData1D(int con, int id, int off, int count, float[] d, int sizeBytes); synchronized void nAllocationSubData1D(int id, int off, int count, float[] d, int sizeBytes) { rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); native void rsnAllocationElementData1D(int con, int id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes); synchronized void nAllocationElementData1D(int id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes) { rsnAllocationElementData1D(mContext, id, xoff, mip, compIdx, d, sizeBytes); } native void rsnAllocationSubData2D(int con, int id, int xoff, int yoff, int w, int h, int[] d, int sizeBytes); synchronized void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d, int sizeBytes) { rsnAllocationSubData2D(mContext, id, xoff, yoff, w, h, d, sizeBytes); native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes); synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes) { rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes); } native void rsnAllocationSubData2D(int con, int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes); synchronized void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes) { rsnAllocationSubData2D(mContext, id, xoff, yoff, w, h, d, sizeBytes); native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes); synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes) { rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes); } native void rsnAllocationRead(int con, int id, int[] d); synchronized void nAllocationRead(int id, int[] d) { rsnAllocationRead(mContext, id, d); Loading Loading @@ -310,63 +304,6 @@ public class RenderScript { return rsnFontCreateFromFile(mContext, fileName, size, dpi); } native void rsnAdapter1DBindAllocation(int con, int ad, int alloc); synchronized void nAdapter1DBindAllocation(int ad, int alloc) { rsnAdapter1DBindAllocation(mContext, ad, alloc); } native void rsnAdapter1DSetConstraint(int con, int ad, int dim, int value); synchronized void nAdapter1DSetConstraint(int ad, int dim, int value) { rsnAdapter1DSetConstraint(mContext, ad, dim, value); } native void rsnAdapter1DData(int con, int ad, int[] d); synchronized void nAdapter1DData(int ad, int[] d) { rsnAdapter1DData(mContext, ad, d); } native void rsnAdapter1DData(int con, int ad, float[] d); synchronized void nAdapter1DData(int ad, float[] d) { rsnAdapter1DData(mContext, ad, d); } native void rsnAdapter1DSubData(int con, int ad, int off, int count, int[] d); synchronized void nAdapter1DSubData(int ad, int off, int count, int[] d) { rsnAdapter1DSubData(mContext, ad, off, count, d); } native void rsnAdapter1DSubData(int con, int ad, int off, int count, float[] d); synchronized void nAdapter1DSubData(int ad, int off, int count, float[] d) { rsnAdapter1DSubData(mContext, ad, off, count, d); } native int rsnAdapter1DCreate(int con); synchronized int nAdapter1DCreate() { return rsnAdapter1DCreate(mContext); } native void rsnAdapter2DBindAllocation(int con, int ad, int alloc); synchronized void nAdapter2DBindAllocation(int ad, int alloc) { rsnAdapter2DBindAllocation(mContext, ad, alloc); } native void rsnAdapter2DSetConstraint(int con, int ad, int dim, int value); synchronized void nAdapter2DSetConstraint(int ad, int dim, int value) { rsnAdapter2DSetConstraint(mContext, ad, dim, value); } native void rsnAdapter2DData(int con, int ad, int[] d); synchronized void nAdapter2DData(int ad, int[] d) { rsnAdapter2DData(mContext, ad, d); } native void rsnAdapter2DData(int con, int ad, float[] d); synchronized void nAdapter2DData(int ad, float[] d) { rsnAdapter2DData(mContext, ad, d); } native void rsnAdapter2DSubData(int con, int ad, int xoff, int yoff, int w, int h, int[] d); synchronized void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, int[] d) { rsnAdapter2DSubData(mContext, ad, xoff, yoff, w, h, d); } native void rsnAdapter2DSubData(int con, int ad, int xoff, int yoff, int w, int h, float[] d); synchronized void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, float[] d) { rsnAdapter2DSubData(mContext, ad, xoff, yoff, w, h, d); } native int rsnAdapter2DCreate(int con); synchronized int nAdapter2DCreate() { return rsnAdapter2DCreate(mContext); } native void rsnScriptBindAllocation(int con, int script, int alloc, int slot); synchronized void nScriptBindAllocation(int script, int alloc, int slot) { Loading
graphics/java/android/renderscript/Type.java +14 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,20 @@ public class Type extends BaseObj { int mElementCount; Element mElement; public enum CubemapFace { POSITVE_X (0), NEGATIVE_X (1), POSITVE_Y (2), NEGATIVE_Y (3), POSITVE_Z (4), NEGATIVE_Z (5); int mID; CubemapFace(int id) { mID = id; } } /** * Return the element associated with this Type. * Loading
graphics/jni/android_renderscript_RenderScript.cpp +33 −192 File changed.Preview size limit exceeded, changes collapsed. Show changes