From 8d744a5fbeff9424e839780d13106ef7cc0219c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= <26625149+0xZOne@users.noreply.github.com> Date: Fri, 16 Feb 2024 05:49:54 +0800 Subject: [PATCH] [Android] Remove the unnecessary parent interface. (flutter/engine#50677) `ImageConsumer` and `GLTextureConsumer` should not inherit from `TextureEntry`. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../engine/renderer/FlutterRenderer.java | 52 +++++++------------ .../ImageReaderPlatformViewRenderTarget.java | 14 ++--- ...urfaceTexturePlatformViewRenderTarget.java | 8 ++- .../io/flutter/view/TextureRegistry.java | 4 +- 4 files changed, 30 insertions(+), 48 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java index 62b365a150..a5bc96401f 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java @@ -302,19 +302,15 @@ public class FlutterRenderer implements TextureRegistry { 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); } } @@ -762,15 +758,11 @@ public class FlutterRenderer implements TextureRegistry { // 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); @@ -960,11 +952,10 @@ public class FlutterRenderer implements TextureRegistry { */ 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(); } @@ -1015,13 +1006,10 @@ public class FlutterRenderer implements TextureRegistry { 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(); } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java index 5853689fc2..9a89d54507 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java @@ -54,15 +54,11 @@ public class ImageReaderPlatformViewRenderTarget implements PlatformViewRenderTa // 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); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/SurfaceTexturePlatformViewRenderTarget.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/SurfaceTexturePlatformViewRenderTarget.java index 4b474b0b01..f629daa26c 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/SurfaceTexturePlatformViewRenderTarget.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/SurfaceTexturePlatformViewRenderTarget.java @@ -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. diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/TextureRegistry.java b/engine/src/flutter/shell/platform/android/io/flutter/view/TextureRegistry.java index 2f8e2b3234..a8b5a52d0e 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/TextureRegistry.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/TextureRegistry.java @@ -135,7 +135,7 @@ public interface TextureRegistry { } @Keep - interface ImageConsumer extends TextureEntry { + interface ImageConsumer { /** * Retrieve the last Image produced. Drops all previously produced images. * @@ -148,7 +148,7 @@ public interface TextureRegistry { } @Keep - interface GLTextureConsumer extends TextureEntry { + interface GLTextureConsumer { /** * Retrieve the last GL texture produced. *