From 1c1448fb0972b46c8ee0c4a7f85eb4782a4d6d8a Mon Sep 17 00:00:00 2001 From: cg021 Date: Sat, 6 Jun 2020 14:30:47 -0500 Subject: [PATCH 1/2] onEndFrame JNI --- .../flutter/embedding/engine/FlutterJNI.java | 19 +++++++++++++++++++ .../platform/PlatformViewsController.java | 4 ++++ .../android/platform_view_android_jni.cc | 14 ++++++++++++++ .../android/platform_view_android_jni.h | 2 ++ .../embedding/engine/FlutterJNITest.java | 19 +++++++++++++++++++ 5 files changed, 58 insertions(+) diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index b0d5ad9ba19e2..c59b1f9d0dc03 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -22,6 +22,7 @@ import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener; import io.flutter.embedding.engine.renderer.RenderSurface; import io.flutter.plugin.common.StandardMessageCodec; +import io.flutter.plugin.platform.PlatformViewsController; import io.flutter.view.AccessibilityBridge; import io.flutter.view.FlutterCallbackInformation; import java.nio.ByteBuffer; @@ -168,6 +169,7 @@ public static native void nativeOnVsync( @Nullable private Long nativePlatformViewId; @Nullable private AccessibilityDelegate accessibilityDelegate; @Nullable private PlatformMessageHandler platformMessageHandler; + @Nullable private PlatformViewsController platformViewsController; @NonNull private final Set engineLifecycleListeners = new CopyOnWriteArraySet<>(); @@ -415,6 +417,12 @@ private native void nativeDispatchPointerDataPacket( long nativePlatformViewId, @NonNull ByteBuffer buffer, int position); // ------ End Touch Interaction Support --- + @UiThread + public void setPlatformViewsController(@NonNull PlatformViewsController platformViewsController) { + ensureRunningOnMainThread(); + this.platformViewsController = platformViewsController; + } + // ------ Start Accessibility Support ----- /** * Sets the {@link AccessibilityDelegate} for the attached Flutter context. @@ -780,6 +788,17 @@ private void onPreEngineRestart() { listener.onPreEngineRestart(); } } + + @SuppressWarnings("unused") + @UiThread + public void onEndFrame() { + ensureRunningOnMainThread(); + if (platformViewsController == null) { + throw new RuntimeException( + "platformViewsController must be set before attempting to end the frame"); + } + platformViewsController.onEndFrame(); + } // ----- End Engine Lifecycle Support ---- // TODO(mattcarroll): determine if this is nonull or nullable diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index bc36210e4c9b7..650df346c797d 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -533,4 +533,8 @@ private void flushAllViews() { } vdControllers.clear(); } + + public void onEndFrame() { + // TODO: Implement this method. https://github.com/flutter/flutter/issues/58288 + } } diff --git a/shell/platform/android/platform_view_android_jni.cc b/shell/platform/android/platform_view_android_jni.cc index 4f6f9258b3e11..1d4400f9c560b 100644 --- a/shell/platform/android/platform_view_android_jni.cc +++ b/shell/platform/android/platform_view_android_jni.cc @@ -118,6 +118,12 @@ void FlutterViewOnPreEngineRestart(JNIEnv* env, jobject obj) { FML_CHECK(CheckException(env)); } +static jmethodID g_on_end_frame_method = nullptr; +void FlutterViewEndFrame(JNIEnv* env, jobject obj) { + env->CallVoidMethod(obj, g_on_end_frame_method); + FML_CHECK(CheckException(env)); +} + static jmethodID g_attach_to_gl_context_method = nullptr; void SurfaceTextureAttachToGLContext(JNIEnv* env, jobject obj, jint textureId) { env->CallVoidMethod(obj, g_attach_to_gl_context_method, textureId); @@ -757,6 +763,14 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { return false; } + g_on_end_frame_method = + env->GetMethodID(g_flutter_jni_class->obj(), "onEndFrame", "()V"); + + if (g_on_end_frame_method == nullptr) { + FML_LOG(ERROR) << "Could not locate onEndFrame method"; + return false; + } + g_attach_to_gl_context_method = env->GetMethodID( g_surface_texture_class->obj(), "attachToGLContext", "(I)V"); diff --git a/shell/platform/android/platform_view_android_jni.h b/shell/platform/android/platform_view_android_jni.h index 07c70b2a45b50..13261d9f46aaf 100644 --- a/shell/platform/android/platform_view_android_jni.h +++ b/shell/platform/android/platform_view_android_jni.h @@ -36,6 +36,8 @@ void FlutterViewOnFirstFrame(JNIEnv* env, jobject obj); void FlutterViewOnPreEngineRestart(JNIEnv* env, jobject obj); +void FlutterViewEndFrame(JNIEnv* env, jobject obj); + void SurfaceTextureAttachToGLContext(JNIEnv* env, jobject obj, jint textureId); void SurfaceTextureUpdateTexImage(JNIEnv* env, jobject obj); diff --git a/shell/platform/android/test/io/flutter/embedding/engine/FlutterJNITest.java b/shell/platform/android/test/io/flutter/embedding/engine/FlutterJNITest.java index 98b8660683837..2248b55ea72bf 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/FlutterJNITest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/FlutterJNITest.java @@ -1,8 +1,12 @@ package io.flutter.embedding.engine; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener; +import io.flutter.plugin.platform.PlatformViewsController; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; import org.junit.runner.RunWith; @@ -44,4 +48,19 @@ public void onFlutterUiNoLongerDisplayed() {} // --- Verify Results --- assertEquals(1, callbackInvocationCount.get()); } + + @Test + public void onEndFrame__callsPlatformViewsController() { + PlatformViewsController platformViewsController = mock(PlatformViewsController.class); + + // --- Test Setup --- + FlutterJNI flutterJNI = new FlutterJNI(); + flutterJNI.setPlatformViewsController(platformViewsController); + + // --- Execute Test --- + flutterJNI.onEndFrame(); + + // --- Verify Results --- + verify(platformViewsController, times(1)).onEndFrame(); + } } From 4071671a74b6255a87beed1ccbc4f996c372eaf9 Mon Sep 17 00:00:00 2001 From: cg021 Date: Fri, 12 Jun 2020 15:35:31 -0500 Subject: [PATCH 2/2] beginFrame brief change --- shell/platform/android/jni/platform_view_android_jni.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/android/jni/platform_view_android_jni.h b/shell/platform/android/jni/platform_view_android_jni.h index 246543f449db3..5d00ef13b1fce 100644 --- a/shell/platform/android/jni/platform_view_android_jni.h +++ b/shell/platform/android/jni/platform_view_android_jni.h @@ -139,8 +139,8 @@ class PlatformViewAndroidJNI { virtual void FlutterViewBeginFrame() = 0; //---------------------------------------------------------------------------- - /// @brief Terminates a frame if using hybrid composition. - /// + /// @brief Indicates that the current frame ended. + /// It's used to clean up state. /// /// @note Must be called from the platform thread. ///