Skip to content

Commit 1278ce2

Browse files
committed
Revert "Reenable HardwareBuffer backed Android Platform Views on SDK >= 29 (flutter#44790)"
This reverts commit d259a52.
1 parent 4107ee0 commit 1278ce2

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

shell/platform/android/hardware_buffer_external_texture.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ void HardwareBufferExternalTexture::Paint(PaintContext& context,
3939
flutter::DlCanvas::SrcRectConstraint::kStrict // enforce edges
4040
);
4141
} else {
42-
FML_LOG(WARNING)
43-
<< "No DlImage available for HardwareBufferExternalTexture to paint.";
42+
FML_LOG(WARNING) << "No DlImage available.";
4443
}
4544
}
4645

shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ public void run() {
336336

337337
@Keep
338338
final class ImageTextureRegistryEntry implements TextureRegistry.ImageTextureEntry {
339-
private static final String TAG = "ImageTextureRegistryEntry";
340339
private final long id;
341340
private boolean released;
342341
private Image image;
@@ -371,10 +370,8 @@ public void pushImage(Image image) {
371370
if (toClose != null) {
372371
toClose.close();
373372
}
374-
if (image != null) {
375-
// Mark that we have a new frame available.
376-
markTextureFrameAvailable(id);
377-
}
373+
// Mark that we have a new frame available.
374+
markTextureFrameAvailable(id);
378375
}
379376

380377
@Override

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

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,31 @@
1111
import android.view.Surface;
1212
import io.flutter.view.TextureRegistry.ImageTextureEntry;
1313

14-
@TargetApi(29)
14+
@TargetApi(26)
1515
public class ImageReaderPlatformViewRenderTarget implements PlatformViewRenderTarget {
1616
private ImageTextureEntry textureEntry;
17+
private boolean mustRecreateImageReader = false;
1718
private ImageReader reader;
1819
private int bufferWidth = 0;
1920
private int bufferHeight = 0;
2021
private static final String TAG = "ImageReaderPlatformViewRenderTarget";
2122

2223
private void closeReader() {
2324
if (this.reader != null) {
24-
// Push a null image, forcing the texture entry to close any cached images.
25-
textureEntry.pushImage(null);
26-
// Close the reader, which also closes any produced images.
2725
this.reader.close();
2826
this.reader = null;
2927
}
3028
}
3129

30+
private void recreateImageReaderIfNeeded() {
31+
if (!mustRecreateImageReader) {
32+
return;
33+
}
34+
mustRecreateImageReader = false;
35+
closeReader();
36+
this.reader = createImageReader();
37+
}
38+
3239
private final Handler onImageAvailableHandler = new Handler();
3340
private final ImageReader.OnImageAvailableListener onImageAvailableListener =
3441
new ImageReader.OnImageAvailableListener() {
@@ -48,12 +55,9 @@ protected ImageReader createImageReader33() {
4855
// Allow for double buffering.
4956
builder.setMaxImages(3);
5057
// Use PRIVATE image format so that we can support video decoding.
51-
// TODO(johnmccutchan): Should we always use PRIVATE here? It may impact our
52-
// ability to read back texture data. If we don't always want to use it, how do we
53-
// decide when to use it or not? Perhaps PlatformViews can indicate if they may contain
54-
// DRM'd content.
55-
// I need to investigate how PRIVATE impacts our ability to take screenshots or capture
56-
// the output of Flutter application.
58+
// TODO(johnmccutchan): Should we always use PRIVATE here? It may impact our ability
59+
// to read back texture data. If we don't always want to use it, how do we decide when
60+
// to use it or not? Perhaps PlatformViews can indicate if they may contain DRM'd content.
5761
builder.setImageFormat(ImageFormat.PRIVATE);
5862
// Hint that consumed images will only be read by GPU.
5963
builder.setUsage(HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
@@ -64,31 +68,29 @@ protected ImageReader createImageReader33() {
6468

6569
@TargetApi(29)
6670
protected ImageReader createImageReader29() {
67-
final ImageReader reader =
68-
ImageReader.newInstance(
69-
bufferWidth,
70-
bufferHeight,
71-
ImageFormat.PRIVATE,
72-
2,
73-
HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
74-
reader.setOnImageAvailableListener(this.onImageAvailableListener, onImageAvailableHandler);
75-
return reader;
71+
return ImageReader.newInstance(
72+
bufferWidth, bufferHeight, ImageFormat.PRIVATE, 2, HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
73+
}
74+
75+
@TargetApi(26)
76+
protected ImageReader createImageReader26() {
77+
return ImageReader.newInstance(bufferWidth, bufferHeight, ImageFormat.PRIVATE, 2);
7678
}
7779

7880
protected ImageReader createImageReader() {
7981
if (Build.VERSION.SDK_INT >= 33) {
8082
return createImageReader33();
8183
} else if (Build.VERSION.SDK_INT >= 29) {
8284
return createImageReader29();
85+
} else {
86+
return createImageReader26();
8387
}
84-
throw new UnsupportedOperationException(
85-
"ImageReaderPlatformViewRenderTarget requires API version 29+");
8688
}
8789

8890
public ImageReaderPlatformViewRenderTarget(ImageTextureEntry textureEntry) {
89-
if (Build.VERSION.SDK_INT < 29) {
91+
if (Build.VERSION.SDK_INT < 26) {
9092
throw new UnsupportedOperationException(
91-
"ImageReaderPlatformViewRenderTarget requires API version 29+");
93+
"ImageReaderPlatformViewRenderTarget requires API version 26+");
9294
}
9395
this.textureEntry = textureEntry;
9496
}
@@ -125,16 +127,17 @@ public long getId() {
125127
}
126128

127129
public void release() {
128-
closeReader();
129130
// textureEntry has a finalizer attached.
130131
textureEntry = null;
132+
closeReader();
131133
}
132134

133135
public boolean isReleased() {
134136
return this.textureEntry == null;
135137
}
136138

137139
public Surface getSurface() {
140+
recreateImageReaderIfNeeded();
138141
return this.reader.getSurface();
139142
}
140143
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,8 @@ private void unlockInputConnection(@NonNull VirtualDisplayController controller)
968968

969969
private static PlatformViewRenderTarget makePlatformViewRenderTarget(
970970
TextureRegistry textureRegistry) {
971-
if (Build.VERSION.SDK_INT >= 29) {
971+
// TODO(johnmccutchan): Enable ImageReaderPlatformViewRenderTarget for public use.
972+
if (false) {
972973
final TextureRegistry.ImageTextureEntry textureEntry = textureRegistry.createImageTexture();
973974
return new ImageReaderPlatformViewRenderTarget(textureEntry);
974975
}

shell/platform/android/surface_texture_external_texture.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ void SurfaceTextureExternalTexture::Paint(PaintContext& context,
7878
context.canvas->DrawImage(dl_image_, {0, 0}, sampling, context.paint);
7979
}
8080
} else {
81-
FML_LOG(WARNING)
82-
<< "No DlImage available for SurfaceTextureExternalTexture to paint.";
81+
FML_LOG(WARNING) << "No DlImage available.";
8382
}
8483
}
8584

0 commit comments

Comments
 (0)