Update NDK methods for HARDWARE Bitmaps
Bug: 135133301
Test: I2c1e58c41e49c72fb4bdbc64989da103885d34bf
_getInfo now sets a bit in AndroidBitmapInfo.flags to indicate whether
the Bitmap has Config.HARDWARE.
For a HARDWARE Bitmap, its AHardwareBuffer can now be retrieved with
AndroidBitmap_getHardwareBuffer. Call AHardwareBuffer_acquire on the
buffer so it will not be deleted while the client is using it.
Change-Id: I9240c1928c1478053ecf7c252443a33dbd6fd6db
diff --git a/native/graphics/jni/bitmap.cpp b/native/graphics/jni/bitmap.cpp
index ea8a521..4f21ccb 100644
--- a/native/graphics/jni/bitmap.cpp
+++ b/native/graphics/jni/bitmap.cpp
@@ -76,6 +76,21 @@
return ANDROID_BITMAP_RESULT_SUCCESS;
}
+int AndroidBitmap_getHardwareBuffer(JNIEnv* env, jobject jbitmap, AHardwareBuffer** outBuffer) {
+ if (NULL == env || NULL == jbitmap || NULL == outBuffer) {
+ return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
+ }
+
+ android::graphics::Bitmap bitmap(env, jbitmap);
+
+ if (!bitmap.isValid()) {
+ return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
+ }
+
+ *outBuffer = bitmap.getHardwareBuffer();
+ return *outBuffer == NULL ? ANDROID_BITMAP_RESULT_BAD_PARAMETER : ANDROID_BITMAP_RESULT_SUCCESS;
+}
+
int AndroidBitmap_compress(const AndroidBitmapInfo* info,
int32_t dataSpace,
const void* pixels,
diff --git a/native/graphics/jni/libjnigraphics.map.txt b/native/graphics/jni/libjnigraphics.map.txt
index 6843e7a..2e6c966 100644
--- a/native/graphics/jni/libjnigraphics.map.txt
+++ b/native/graphics/jni/libjnigraphics.map.txt
@@ -22,6 +22,7 @@
AndroidBitmap_lockPixels;
AndroidBitmap_unlockPixels;
AndroidBitmap_compress; # introduced=30
+ AndroidBitmap_getHardwareBuffer; #introduced=30
local:
*;
};