Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 8ce8181

Browse files
committed
Re-enable HardwareBuffer backed Platform Views on Android >= 29
1 parent 78c1ad2 commit 8ce8181

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class ImageReaderPlatformViewRenderTarget implements PlatformViewRenderTa
1919
private int bufferWidth = 0;
2020
private int bufferHeight = 0;
2121
private static final String TAG = "ImageReaderPlatformViewRenderTarget";
22+
private static final int MAX_IMAGES = 3;
2223

2324
private void closeReader() {
2425
if (this.reader != null) {
@@ -39,7 +40,7 @@ public void onImageAvailable(ImageReader reader) {
3940
try {
4041
image = reader.acquireLatestImage();
4142
} catch (IllegalStateException e) {
42-
Log.e(TAG, "New image available that could not be acquired: " + e.toString());
43+
Log.e(TAG, "New image available but it could not be acquired: " + e.toString());
4344
}
4445
if (image == null) {
4546
return;
@@ -52,7 +53,7 @@ public void onImageAvailable(ImageReader reader) {
5253
protected ImageReader createImageReader33() {
5354
final ImageReader.Builder builder = new ImageReader.Builder(bufferWidth, bufferHeight);
5455
// Allow for double buffering.
55-
builder.setMaxImages(3);
56+
builder.setMaxImages(MAX_IMAGES);
5657
// Use PRIVATE image format so that we can support video decoding.
5758
// TODO(johnmccutchan): Should we always use PRIVATE here? It may impact our
5859
// ability to read back texture data. If we don't always want to use it, how do
@@ -78,7 +79,7 @@ protected ImageReader createImageReader29() {
7879
bufferWidth,
7980
bufferHeight,
8081
ImageFormat.PRIVATE,
81-
3,
82+
MAX_IMAGES,
8283
HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
8384
reader.setOnImageAvailableListener(this.onImageAvailableListener, onImageAvailableHandler);
8485
return reader;

shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
147147
// Whether software rendering is used.
148148
private boolean usesSoftwareRendering = false;
149149

150-
private static boolean enableHardwareBufferRenderingTarget = false;
150+
private static boolean enableHardwareBufferRenderingTarget = true;
151151

152152
private final PlatformViewsChannel.PlatformViewsHandler channelHandler =
153153
new PlatformViewsChannel.PlatformViewsHandler() {

0 commit comments

Comments
 (0)