From 2be4658627b34406d0fc294340c676fe9ed4e0b3 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?= Date: Thu, 15 Feb 2024 11:37:02 +0800 Subject: [PATCH] [Android] Remove the unnecessary parent interface. --- .../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/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java b/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java index 62b365a150ed1..a5bc96401f7f1 100644 --- a/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java +++ b/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java @@ -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); } } @@ -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); @@ -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(); } @@ -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(); } diff --git a/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java b/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java index 5853689fc2fe6..9a89d545072ea 100644 --- a/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java +++ b/shell/platform/android/io/flutter/plugin/platform/ImageReaderPlatformViewRenderTarget.java @@ -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); diff --git a/shell/platform/android/io/flutter/plugin/platform/SurfaceTexturePlatformViewRenderTarget.java b/shell/platform/android/io/flutter/plugin/platform/SurfaceTexturePlatformViewRenderTarget.java index 4b474b0b016ec..f629daa26c425 100644 --- a/shell/platform/android/io/flutter/plugin/platform/SurfaceTexturePlatformViewRenderTarget.java +++ b/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/shell/platform/android/io/flutter/view/TextureRegistry.java b/shell/platform/android/io/flutter/view/TextureRegistry.java index 2f8e2b32349e6..a8b5a52d0e6c5 100644 --- a/shell/platform/android/io/flutter/view/TextureRegistry.java +++ b/shell/platform/android/io/flutter/view/TextureRegistry.java @@ -135,7 +135,7 @@ interface OnTrimMemoryListener { } @Keep - interface ImageConsumer extends TextureEntry { + interface ImageConsumer { /** * Retrieve the last Image produced. Drops all previously produced images. * @@ -148,7 +148,7 @@ interface ImageConsumer extends TextureEntry { } @Keep - interface GLTextureConsumer extends TextureEntry { + interface GLTextureConsumer { /** * Retrieve the last GL texture produced. *