From 72c674cc1c0ad09b20ff5c6ebf61d676675765b6 Mon Sep 17 00:00:00 2001 From: John McCutchan Date: Thu, 21 Sep 2023 14:40:31 -0700 Subject: [PATCH] Re-enable HardwareBuffer backed Platform Views on Android >= 29 (flutter/engine#46071) --- .../platform/ImageReaderPlatformViewRenderTarget.java | 7 ++++--- .../flutter/plugin/platform/PlatformViewsController.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java index 937b00c6ae..4ba58fce13 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java +++ b/engine/src/flutter/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 class ImageReaderPlatformViewRenderTarget implements PlatformViewRenderTa 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 class ImageReaderPlatformViewRenderTarget implements PlatformViewRenderTa 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 @@ public class ImageReaderPlatformViewRenderTarget implements PlatformViewRenderTa bufferWidth, bufferHeight, ImageFormat.PRIVATE, - 3, + MAX_IMAGES, HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE); reader.setOnImageAvailableListener(this.onImageAvailableListener, onImageAvailableHandler); return reader; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index b5559a3a9e..0e7ad70aee 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/engine/src/flutter/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() {