Expose Bitmap#getHardwareBuffer
Bug: 148155907
Bug: 150395371
Test: I652101b6a4b3d9de4e77a316ba0436ce466f3620
Bitmap already has a method to create a Bitmap from a HardwareBuffer,
and the NDK allows doing the reverse. This updates the SDK to allow
retrieving the HardwareBuffer, too.
Update the docs to match wrapHardwareBuffer regarding modifications.
Throw an Exception if called on a non-HARDWARE Bitmap, which is
friendlier than the crash that previously happened on the hidden API
(and the one it replaced).
Change-Id: I408cff708efa76f89e0c4c6dae16f19166ffe74d
diff --git a/libs/hwui/jni/Bitmap.cpp b/libs/hwui/jni/Bitmap.cpp
index 084bdaa..f42b249 100755
--- a/libs/hwui/jni/Bitmap.cpp
+++ b/libs/hwui/jni/Bitmap.cpp
@@ -1196,13 +1196,16 @@
static jobject Bitmap_getHardwareBuffer(JNIEnv* env, jobject, jlong bitmapPtr) {
#ifdef __ANDROID__ // Layoutlib does not support graphic buffer
LocalScopedBitmap bitmapHandle(bitmapPtr);
- LOG_ALWAYS_FATAL_IF(!bitmapHandle->isHardware(),
+ if (!bitmapHandle->isHardware()) {
+ jniThrowException(env, "java/lang/IllegalStateException",
"Hardware config is only supported config in Bitmap_getHardwareBuffer");
+ return nullptr;
+ }
Bitmap& bitmap = bitmapHandle->bitmap();
return AHardwareBuffer_toHardwareBuffer(env, bitmap.hardwareBuffer());
#else
- return NULL;
+ return nullptr;
#endif
}