From 8ce818132eff62eb384d4c3bcdb45593a9715f61 Mon Sep 17 00:00:00 2001 From: John McCutchan Date: Tue, 19 Sep 2023 11:25:15 -0700 Subject: [PATCH] Re-enable HardwareBuffer backed Platform Views on Android >= 29 --- .../platform/ImageReaderPlatformViewRenderTarget.java | 7 ++++--- .../flutter/plugin/platform/PlatformViewsController.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java b/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java index 937b00c6ae899..4ba58fce13b5f 100644 --- a/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java +++ b/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java @@ -19,6 +19,7 @@ public class ImageReaderPlatformViewRenderTarget implements PlatformViewRenderTa private int bufferWidth = 0; private int bufferHeight = 0; private static final String TAG = "ImageReaderPlatformViewRenderTarget"; + private static final int MAX_IMAGES = 3; private void closeReader() { if (this.reader != null) { @@ -39,7 +40,7 @@ public void onImageAvailable(ImageReader reader) { try { image = reader.acquireLatestImage(); } catch (IllegalStateException e) { - Log.e(TAG, "New image available that could not be acquired: " + e.toString()); + Log.e(TAG, "New image available but it could not be acquired: " + e.toString()); } if (image == null) { return; @@ -52,7 +53,7 @@ public void onImageAvailable(ImageReader reader) { protected ImageReader createImageReader33() { final ImageReader.Builder builder = new ImageReader.Builder(bufferWidth, bufferHeight); // Allow for double buffering. - builder.setMaxImages(3); + builder.setMaxImages(MAX_IMAGES); // Use PRIVATE image format so that we can support video decoding. // TODO(johnmccutchan): Should we always use PRIVATE here? It may impact our // ability to read back texture data. If we don't always want to use it, how do @@ -78,7 +79,7 @@ protected ImageReader createImageReader29() { bufferWidth, bufferHeight, ImageFormat.PRIVATE, - 3, + MAX_IMAGES, HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE); reader.setOnImageAvailableListener(this.onImageAvailableListener, onImageAvailableHandler); return reader; diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index b5559a3a9e23a..0e7ad70aee29d 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -147,7 +147,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega // Whether software rendering is used. private boolean usesSoftwareRendering = false; - private static boolean enableHardwareBufferRenderingTarget = false; + private static boolean enableHardwareBufferRenderingTarget = true; private final PlatformViewsChannel.PlatformViewsHandler channelHandler = new PlatformViewsChannel.PlatformViewsHandler() {