Add public API for @hidden Bitmap#createAshmemBitmap
Bug: 150395371
Test: I442cd0c7a849e4c6a2fe7ba21b25a6e44417bbf5
The system needs to move off of @hidden Bitmap APIs so Bitmap can move
to a mainline module. It is valuable to provide a public way for clients
to create a Bitmap backed by ashmem, and the method's usage level is
HIGH. As I understand it, ashmem is being deprecated, so make the new
name more general: #asShared(). This method calls createAshmemBitmap(),
which must continue to exist for now due to the greylist. Add a
maxTargetSdk and publicAlternatives to move clients to the new method.
Mark asShared as @NonNull. It should only fail due to a failure to
allocate the shared memory. Throw a RunTimeException in this (rare)
case.
Add a (private) native method to check whether the Bitmap is already
backed by ashmem so it can skip the copy as necessary.
Remove outdated comments in both createAshmemBitmap methods regarding
SRGB. The new Bitmap will have the same ColorSpace as the original.
Remove the Config param from DisplayContent#screenshotLocked. It is only
ever called with ARGB_8888, which matches the ScreenshotGraphicBuffer
it is copied from. This means Bitmap#createAshmemBitmap(Config) does not
need a public version. It may need to continue to exist due to
@UnsupportedAppUsage.
Change-Id: I359187a5c70b5e241c7f5879d50fde2a7449c818
diff --git a/libs/hwui/jni/Bitmap.cpp b/libs/hwui/jni/Bitmap.cpp
index f42b249..c4865e3 100755
--- a/libs/hwui/jni/Bitmap.cpp
+++ b/libs/hwui/jni/Bitmap.cpp
@@ -1216,6 +1216,14 @@
return bitmapHolder->bitmap().isImmutable() ? JNI_TRUE : JNI_FALSE;
}
+static jboolean Bitmap_isBackedByAshmem(CRITICAL_JNI_PARAMS_COMMA jlong bitmapHandle) {
+ LocalScopedBitmap bitmapHolder(bitmapHandle);
+ if (!bitmapHolder.valid()) return JNI_FALSE;
+
+ return bitmapHolder->bitmap().pixelStorageType() == PixelStorageType::Ashmem ? JNI_TRUE
+ : JNI_FALSE;
+}
+
static void Bitmap_setImmutable(JNIEnv* env, jobject, jlong bitmapHandle) {
LocalScopedBitmap bitmapHolder(bitmapHandle);
if (!bitmapHolder.valid()) return;
@@ -1282,7 +1290,8 @@
{ "nativeSetImmutable", "(J)V", (void*)Bitmap_setImmutable},
// ------------ @CriticalNative ----------------
- { "nativeIsImmutable", "(J)Z", (void*)Bitmap_isImmutable}
+ { "nativeIsImmutable", "(J)Z", (void*)Bitmap_isImmutable},
+ { "nativeIsBackedByAshmem", "(J)Z", (void*)Bitmap_isBackedByAshmem}
};