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
This commit is contained in:
Luke De Feo
2023-11-02 12:29:07 -07:00
committed by Facebook GitHub Bot
parent 44b8a39874
commit bd6e1285da

View File

@@ -55,8 +55,8 @@ class ModernPixelCopySnapshotter(
override suspend fun takeSnapshot(view: View): BitmapPool.ReusableBitmap? {
return SnapshotCommon.doSnapshotWithErrorHandling(bitmapPool, view, fallback) { reusableBitmap
->
return if (view.isHardwareAccelerated) {
SnapshotCommon.doSnapshotWithErrorHandling(bitmapPool, view, fallback) { reusableBitmap ->
suspendCoroutine { continuation ->
// Since android U this api is actually async
val request =
@@ -64,9 +64,14 @@ class ModernPixelCopySnapshotter(
.setDestinationBitmap(reusableBitmap.bitmap)
.build()
PixelCopy.request(
request, { handler.post(it) }, { continuation.resume(it.status == PixelCopy.SUCCESS) })
request,
{ handler.post(it) },
{ continuation.resume(it.status == PixelCopy.SUCCESS) })
}
}
} else {
fallback.takeSnapshot(view)
}
}
}
@@ -85,9 +90,13 @@ class PixelCopySnapshotter(
override suspend fun takeSnapshot(view: View): BitmapPool.ReusableBitmap? {
return SnapshotCommon.doSnapshotWithErrorHandling(bitmapPool, view, fallback) {
return if (view.isHardwareAccelerated) {
SnapshotCommon.doSnapshotWithErrorHandling(bitmapPool, view, fallback) {
tryCopyViaActivityWindow(view, it) || tryCopyViaInternalSurface(view, it)
}
} else {
fallback.takeSnapshot(view)
}
}
private suspend fun tryCopyViaActivityWindow(