Skip to content

Commit

Permalink
[Android] Remove the unnecessary parent interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xZOne committed Feb 15, 2024
1 parent 2e1016c commit 2be4658
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,15 @@ final class SurfaceTextureRegistryEntry
scheduleEngineFrame();
};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// The callback relies on being executed on the UI thread (unsynchronised read
// of
// mNativeView
// and also the engine code check for platform thread in
// Shell::OnPlatformViewMarkTextureFrameAvailable),
// so we explicitly pass a Handler for the current thread.
// The callback relies on being executed on the UI thread (unsynchronised read of
// mNativeView and also the engine code check for platform thread in
// Shell::OnPlatformViewMarkTextureFrameAvailable), so we explicitly pass a Handler for the
// current thread.
this.surfaceTexture().setOnFrameAvailableListener(onFrameListener, new Handler());
} else {
// Android documentation states that the listener can be called on an arbitrary
// thread.
// But in practice, versions of Android that predate the newer API will call the
// listener
// on the thread where the SurfaceTexture was constructed.
// Android documentation states that the listener can be called on an arbitrary thread. But
// in practice, versions of Android that predate the newer API will call the listener on the
// thread where the SurfaceTexture was constructed.
this.surfaceTexture().setOnFrameAvailableListener(onFrameListener);
}
}
Expand Down Expand Up @@ -762,15 +758,11 @@ private ImageReader createImageReader33() {
// Allow for double buffering.
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
// 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. 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.
builder.setUsage(HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
Expand Down Expand Up @@ -960,11 +952,10 @@ protected void finalize() throws Throwable {
*/
public void startRenderingToSurface(@NonNull Surface surface, boolean onlySwap) {
if (!onlySwap) {
// Stop rendering to the surface releases the associated native resources, which
// causes a glitch when toggling between rendering to an image view (hybrid
// composition) and
// rendering directly to a Surface or Texture view. For more,
// https://github.com/flutter/flutter/issues/95343
// Stop rendering to the surface releases the associated native resources, which causes a
// glitch when toggling between rendering to an image view (hybrid composition) and rendering
// directly to a Surface or Texture view.
// For more, https://github.com/flutter/flutter/issues/95343
stopRenderingToSurface();
}

Expand Down Expand Up @@ -1015,13 +1006,10 @@ public void stopRenderingToSurface() {
if (surface != null) {
flutterJNI.onSurfaceDestroyed();

// TODO(mattcarroll): the source of truth for this call should be FlutterJNI,
// which is where
// the call to onFlutterUiDisplayed() comes from. However, no such native
// callback exists yet,
// so until the engine and FlutterJNI are configured to call us back when
// rendering stops,
// we will manually monitor that change here.
// TODO(mattcarroll): the source of truth for this call should be FlutterJNI, which is where
// the call to onFlutterUiDisplayed() comes from. However, no such native callback exists yet,
// so until the engine and FlutterJNI are configured to call us back when rendering stops, we
// will manually monitor that change here.
if (isDisplayingFlutterUi) {
flutterUiDisplayListener.onFlutterUiNoLongerDisplayed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,11 @@ protected ImageReader createImageReader33() {
// Allow for double buffering.
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
// 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. 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.
builder.setUsage(HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ public class SurfaceTexturePlatformViewRenderTarget implements PlatformViewRende
@Override
public void onTrimMemory(int level) {
// When a memory pressure warning is received and the level equal {@code
// ComponentCallbacks2.TRIM_MEMORY_COMPLETE}, the Android system releases the
// underlying
// surface. If we continue to use the surface (e.g., call lockHardwareCanvas), a
// crash
// occurs, and we found that this crash appeared on Android10 and above.
// ComponentCallbacks2.TRIM_MEMORY_COMPLETE}, the Android system releases the underlying
// surface. If we continue to use the surface (e.g., call lockHardwareCanvas), a crash
// occurs, and we found that this crash appeared on Android 10 and above.
// See https://github.com/flutter/flutter/issues/103870 for more details.
//
// Here our workaround is to recreate the surface before using it.
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/android/io/flutter/view/TextureRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ interface OnTrimMemoryListener {
}

@Keep
interface ImageConsumer extends TextureEntry {
interface ImageConsumer {
/**
* Retrieve the last Image produced. Drops all previously produced images.
*
Expand All @@ -148,7 +148,7 @@ interface ImageConsumer extends TextureEntry {
}

@Keep
interface GLTextureConsumer extends TextureEntry {
interface GLTextureConsumer {
/**
* Retrieve the last GL texture produced.
*
Expand Down

0 comments on commit 2be4658

Please sign in to comment.