From 5a190b19bb2c51dac5c1ddfc78fc0b53a5ff121e Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Tue, 18 Feb 2020 13:52:18 -0500 Subject: Add Bitmap#getHardwareBuffer Bug: 148155907 Bug: 135299581 Test: TODO Hidden for now. We'd like to make it an SDK API eventually (b/148155907). Internal code is currently calling createGraphicBufferHandle. This is not something we plan to expose from the UI rendering module, so add a method to get a HardwareBuffer instead. This is something we were already planning to add. It seems that clients of createGraphicBufferHandle really wanted a Parcelable to pass the HARDWARE Bitmap to another thread. This should satisfy that use case. Change-Id: Id701f7c7eab37830cd7d2cdb929cbe6ba4eca119 --- graphics/java/android/graphics/Bitmap.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'graphics/java') diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 9c2e95fab455..c1e7a360fcc5 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -2243,6 +2243,19 @@ public final class Bitmap implements Parcelable { return nativeCreateGraphicBufferHandle(mNativePtr); } + /** + * @return {@link HardwareBuffer} which is internally used by hardware bitmap + * + * Note: the HardwareBuffer does *not* have an associated {@link ColorSpace}. + * To render this object the same as its rendered with this Bitmap, you + * should also call {@link getColorSpace}. + * + * @hide + */ + public HardwareBuffer getHardwareBuffer() { + return nativeGetHardwareBuffer(mNativePtr); + } + //////////// native methods private static native Bitmap nativeCreate(int[] colors, int offset, @@ -2308,6 +2321,7 @@ public final class Bitmap implements Parcelable { private static native Bitmap nativeWrapHardwareBufferBitmap(HardwareBuffer buffer, long nativeColorSpace); private static native GraphicBuffer nativeCreateGraphicBufferHandle(long nativeBitmap); + private static native HardwareBuffer nativeGetHardwareBuffer(long nativeBitmap); private static native ColorSpace nativeComputeColorSpace(long nativePtr); private static native void nativeSetColorSpace(long nativePtr, long nativeColorSpace); private static native boolean nativeIsSRGB(long nativePtr); -- cgit v1.2.3-59-g8ed1b