From bd6e1285dacb9923685f5739df20c27416f8f445 Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Thu, 2 Nov 2023 12:29:07 -0700 Subject: [PATCH] Only pixel copy if view is hardwell accell Summary: You can only use pixel copy if the view is drawn by the hardware, this sort of makes sense as there is no hardware buffer to copy from. we were falling back but there was a lot of noise in the logs Reviewed By: lblasa Differential Revision: D50853427 fbshipit-source-id: 9365a3d566a05de9082afb8bc2915922c624fd88 --- .../plugins/uidebugger/core/Snapshot.kt | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/Snapshot.kt b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/Snapshot.kt index 3e003bc41..fb38f0130 100644 --- a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/Snapshot.kt +++ b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/Snapshot.kt @@ -55,17 +55,22 @@ class ModernPixelCopySnapshotter( override suspend fun takeSnapshot(view: View): BitmapPool.ReusableBitmap? { - return SnapshotCommon.doSnapshotWithErrorHandling(bitmapPool, view, fallback) { reusableBitmap - -> - suspendCoroutine { continuation -> - // Since android U this api is actually async - val request = - PixelCopy.Request.Builder.ofWindow(view) - .setDestinationBitmap(reusableBitmap.bitmap) - .build() - PixelCopy.request( - request, { handler.post(it) }, { continuation.resume(it.status == PixelCopy.SUCCESS) }) + return if (view.isHardwareAccelerated) { + SnapshotCommon.doSnapshotWithErrorHandling(bitmapPool, view, fallback) { reusableBitmap -> + suspendCoroutine { continuation -> + // Since android U this api is actually async + val request = + PixelCopy.Request.Builder.ofWindow(view) + .setDestinationBitmap(reusableBitmap.bitmap) + .build() + PixelCopy.request( + request, + { handler.post(it) }, + { continuation.resume(it.status == PixelCopy.SUCCESS) }) + } } + } else { + fallback.takeSnapshot(view) } } } @@ -85,8 +90,12 @@ class PixelCopySnapshotter( override suspend fun takeSnapshot(view: View): BitmapPool.ReusableBitmap? { - return SnapshotCommon.doSnapshotWithErrorHandling(bitmapPool, view, fallback) { - tryCopyViaActivityWindow(view, it) || tryCopyViaInternalSurface(view, it) + return if (view.isHardwareAccelerated) { + SnapshotCommon.doSnapshotWithErrorHandling(bitmapPool, view, fallback) { + tryCopyViaActivityWindow(view, it) || tryCopyViaInternalSurface(view, it) + } + } else { + fallback.takeSnapshot(view) } }