diff options
author | Jason Sams <rjsams@android.com> | 2010-03-01 15:31:04 -0800 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2010-03-01 15:31:04 -0800 |
commit | 8a64743f37ed35af7c2204acd18bb3d62d8f66d5 (patch) | |
tree | 13222fdd1021b6af52f78d1d3576b0139b724ee1 /graphics/java | |
parent | c2908e60c9b021fb4bb69acff8d49981dd4dade8 (diff) | |
download | frameworks_base-8a64743f37ed35af7c2204acd18bb3d62d8f66d5.zip frameworks_base-8a64743f37ed35af7c2204acd18bb3d62d8f66d5.tar.gz frameworks_base-8a64743f37ed35af7c2204acd18bb3d62d8f66d5.tar.bz2 |
Add support for linking to a skia bitmap rather than always copying the data from the bitmap.
Diffstat (limited to 'graphics/java')
-rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 46 | ||||
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 1 |
2 files changed, 46 insertions, 1 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 8185404..17c0778 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -32,6 +32,7 @@ import android.util.TypedValue; **/ public class Allocation extends BaseObj { Type mType; + Bitmap mBitmap; Allocation(int id, RenderScript rs, Type t) { super(rs); @@ -262,15 +263,58 @@ public class Allocation extends BaseObj { return new Allocation(id, rs, t); } + static private Element elementFromBitmap(RenderScript rs, Bitmap b) { + final Bitmap.Config bc = b.getConfig(); + if (bc == Bitmap.Config.ALPHA_8) { + return Element.A_8(rs); + } + if (bc == Bitmap.Config.ARGB_4444) { + return Element.RGBA_4444(rs); + } + if (bc == Bitmap.Config.ARGB_8888) { + return Element.RGBA_8888(rs); + } + if (bc == Bitmap.Config.RGB_565) { + return Element.RGB_565(rs); + } + throw new IllegalStateException("Bad bitmap type."); + } + + static private Type typeFromBitmap(RenderScript rs, Bitmap b) { + Element e = elementFromBitmap(rs, b); + Type.Builder tb = new Type.Builder(rs, e); + tb.add(Dimension.X, b.getWidth()); + tb.add(Dimension.Y, b.getHeight()); + return tb.create(); + } + static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) throws IllegalArgumentException { rs.validate(); + Type t = typeFromBitmap(rs, b); + int id = rs.nAllocationCreateFromBitmap(dstFmt.mID, genMips, b); if(id == 0) { throw new IllegalStateException("Load failed."); } - return new Allocation(id, rs, null); + return new Allocation(id, rs, t); + } + + static public Allocation createBitmapRef(RenderScript rs, Bitmap b) + throws IllegalArgumentException { + + rs.validate(); + Type t = typeFromBitmap(rs, b); + + int id = rs.nAllocationCreateBitmapRef(t.getID(), b); + if(id == 0) { + throw new IllegalStateException("Load failed."); + } + + Allocation a = new Allocation(id, rs, t); + a.mBitmap = b; + return a; } static Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 70c97ea..a935243 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -98,6 +98,7 @@ public class RenderScript { native int nAllocationCreateTyped(int type); native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp); + native int nAllocationCreateBitmapRef(int type, Bitmap bmp); native int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp); native int nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream); |