From 721ae5fec5f1fd4f93aa2a361a0ac298e15ce353 Mon Sep 17 00:00:00 2001 From: Riley Andrews Date: Mon, 11 May 2015 16:08:22 -0700 Subject: Add internal bitmap api for creating immutable ashmem backed bitmaps. Bug 21037890 Change-Id: I827e83dd75e301e7d93ead5efdd744f0d8435ae5 --- graphics/java/android/graphics/Bitmap.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'graphics') diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 2d8b0b2..a999b71 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -558,6 +558,22 @@ public final class Bitmap implements Parcelable { } /** + * Creates a new immutable bitmap backed by ashmem which can efficiently + * be passed between processes. + * + * @hide + */ + public Bitmap createAshmemBitmap() { + checkRecycled("Can't copy a recycled bitmap"); + Bitmap b = nativeCopyAshmem(mFinalizer.mNativeBitmap); + if (b != null) { + b.setPremultiplied(mRequestPremultiplied); + b.mDensity = mDensity; + } + return b; + } + + /** * Creates a new bitmap, scaled from an existing bitmap, when possible. If the * specified width and height are the same as the current width and height of * the source bitmap, the source bitmap is returned and no new bitmap is @@ -1636,6 +1652,7 @@ public final class Bitmap implements Parcelable { int nativeConfig, boolean mutable); private static native Bitmap nativeCopy(long nativeSrcBitmap, int nativeConfig, boolean isMutable); + private static native Bitmap nativeCopyAshmem(long nativeSrcBitmap); private static native void nativeDestructor(long nativeBitmap); private static native boolean nativeRecycle(long nativeBitmap); private static native void nativeReconfigure(long nativeBitmap, int width, int height, -- cgit v1.1