Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
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
2 changes: 2 additions & 0 deletions shell/platform/android/hardware_buffer_external_texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ AHardwareBuffer* HardwareBufferExternalTexture::GetLatestHardwareBuffer() {
NDKHelpers::AHardwareBuffer_fromHardwareBuffer(
env, hardware_buffer_java.obj());
if (latest_hardware_buffer == nullptr) {
jni_facade_->HardwareBufferClose(hardware_buffer_java);
jni_facade_->ImageClose(image_java);
return nullptr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,16 @@ public long id() {
}

@Override
@TargetApi(19)
public void release() {
if (released) {
return;
}
released = true;
if (image != null) {
image.close();
image = null;
}
unregisterTexture(id);
}

Expand Down Expand Up @@ -388,12 +393,18 @@ public Image acquireLatestImage() {
}

@Override
@TargetApi(19)
protected void finalize() throws Throwable {
try {
if (released) {
return;
}

if (image != null) {
// Be sure to finalize any cached image.
image.close();
image = null;
}
released = true;
handler.post(new TextureFinalizerRunnable(id, flutterJNI));
} finally {
super.finalize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.Build;
import android.os.Handler;
import android.view.Surface;
import io.flutter.Log;
import io.flutter.view.TextureRegistry.ImageTextureEntry;

@TargetApi(29)
Expand All @@ -34,7 +35,12 @@ private void closeReader() {
new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
final Image image = reader.acquireLatestImage();
Image image = null;
try {
image = reader.acquireLatestImage();
} catch (IllegalStateException e) {
Log.e(TAG, "New image available that could not be acquired: " + e.toString());
}
if (image == null) {
return;
}
Expand All @@ -49,10 +55,13 @@ protected ImageReader createImageReader33() {
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
// 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
// I need to investigate how PRIVATE impacts our ability to take screenshots or
// capture
// the output of Flutter application.
builder.setImageFormat(ImageFormat.PRIVATE);
// Hint that consumed images will only be read by GPU.
Expand All @@ -69,7 +78,7 @@ protected ImageReader createImageReader29() {
bufferWidth,
bufferHeight,
ImageFormat.PRIVATE,
2,
3,
HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
reader.setOnImageAvailableListener(this.onImageAvailableListener, onImageAvailableHandler);
return reader;
Expand Down