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

Revert "Reenable HardwareBuffer backed Android Platform Views on SDK … #45973

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions shell/platform/android/hardware_buffer_external_texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ void HardwareBufferExternalTexture::Paint(PaintContext& context,
flutter::DlCanvas::SrcRectConstraint::kStrict // enforce edges
);
} else {
FML_LOG(WARNING)
<< "No DlImage available for HardwareBufferExternalTexture to paint.";
FML_LOG(WARNING) << "No DlImage available.";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ public void run() {

@Keep
final class ImageTextureRegistryEntry implements TextureRegistry.ImageTextureEntry {
private static final String TAG = "ImageTextureRegistryEntry";
private final long id;
private boolean released;
private Image image;
Expand Down Expand Up @@ -371,10 +370,8 @@ public void pushImage(Image image) {
if (toClose != null) {
toClose.close();
}
if (image != null) {
// Mark that we have a new frame available.
markTextureFrameAvailable(id);
}
// Mark that we have a new frame available.
markTextureFrameAvailable(id);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,31 @@
import android.view.Surface;
import io.flutter.view.TextureRegistry.ImageTextureEntry;

@TargetApi(29)
@TargetApi(26)
public class ImageReaderPlatformViewRenderTarget implements PlatformViewRenderTarget {
private ImageTextureEntry textureEntry;
private boolean mustRecreateImageReader = false;
private ImageReader reader;
private int bufferWidth = 0;
private int bufferHeight = 0;
private static final String TAG = "ImageReaderPlatformViewRenderTarget";

private void closeReader() {
if (this.reader != null) {
// Push a null image, forcing the texture entry to close any cached images.
textureEntry.pushImage(null);
// Close the reader, which also closes any produced images.
this.reader.close();
this.reader = null;
}
}

private void recreateImageReaderIfNeeded() {
if (!mustRecreateImageReader) {
return;
}
mustRecreateImageReader = false;
closeReader();
this.reader = createImageReader();
}

private final Handler onImageAvailableHandler = new Handler();
private final ImageReader.OnImageAvailableListener onImageAvailableListener =
new ImageReader.OnImageAvailableListener() {
Expand All @@ -48,12 +55,9 @@ protected ImageReader createImageReader33() {
// Allow for double buffering.
builder.setMaxImages(3);
// 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 we
// decide when to use it or not? Perhaps PlatformViews can indicate if they may contain
// DRM'd content.
// I need to investigate how PRIVATE impacts our ability to take screenshots or capture
// the output of Flutter application.
// 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 we decide when
// to use it or not? Perhaps PlatformViews can indicate if they may contain DRM'd content.
builder.setImageFormat(ImageFormat.PRIVATE);
// Hint that consumed images will only be read by GPU.
builder.setUsage(HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
Expand All @@ -64,31 +68,29 @@ protected ImageReader createImageReader33() {

@TargetApi(29)
protected ImageReader createImageReader29() {
final ImageReader reader =
ImageReader.newInstance(
bufferWidth,
bufferHeight,
ImageFormat.PRIVATE,
2,
HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
reader.setOnImageAvailableListener(this.onImageAvailableListener, onImageAvailableHandler);
return reader;
return ImageReader.newInstance(
bufferWidth, bufferHeight, ImageFormat.PRIVATE, 2, HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
}

@TargetApi(26)
protected ImageReader createImageReader26() {
return ImageReader.newInstance(bufferWidth, bufferHeight, ImageFormat.PRIVATE, 2);
}

protected ImageReader createImageReader() {
if (Build.VERSION.SDK_INT >= 33) {
return createImageReader33();
} else if (Build.VERSION.SDK_INT >= 29) {
return createImageReader29();
} else {
return createImageReader26();
}
throw new UnsupportedOperationException(
"ImageReaderPlatformViewRenderTarget requires API version 29+");
}

public ImageReaderPlatformViewRenderTarget(ImageTextureEntry textureEntry) {
if (Build.VERSION.SDK_INT < 29) {
if (Build.VERSION.SDK_INT < 26) {
throw new UnsupportedOperationException(
"ImageReaderPlatformViewRenderTarget requires API version 29+");
"ImageReaderPlatformViewRenderTarget requires API version 26+");
}
this.textureEntry = textureEntry;
}
Expand Down Expand Up @@ -125,16 +127,17 @@ public long getId() {
}

public void release() {
closeReader();
// textureEntry has a finalizer attached.
textureEntry = null;
closeReader();
}

public boolean isReleased() {
return this.textureEntry == null;
}

public Surface getSurface() {
recreateImageReaderIfNeeded();
return this.reader.getSurface();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,8 @@ private void unlockInputConnection(@NonNull VirtualDisplayController controller)

private static PlatformViewRenderTarget makePlatformViewRenderTarget(
TextureRegistry textureRegistry) {
if (Build.VERSION.SDK_INT >= 29) {
// TODO(johnmccutchan): Enable ImageReaderPlatformViewRenderTarget for public use.
if (false) {
final TextureRegistry.ImageTextureEntry textureEntry = textureRegistry.createImageTexture();
return new ImageReaderPlatformViewRenderTarget(textureEntry);
}
Expand Down
3 changes: 1 addition & 2 deletions shell/platform/android/surface_texture_external_texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ void SurfaceTextureExternalTexture::Paint(PaintContext& context,
context.canvas->DrawImage(dl_image_, {0, 0}, sampling, context.paint);
}
} else {
FML_LOG(WARNING)
<< "No DlImage available for SurfaceTextureExternalTexture to paint.";
FML_LOG(WARNING) << "No DlImage available.";
}
}

Expand Down