Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 59294e1

Browse files
committed
onEndFrame JNI
1 parent dbb57f1 commit 59294e1

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
2323
import io.flutter.embedding.engine.renderer.RenderSurface;
2424
import io.flutter.plugin.common.StandardMessageCodec;
25+
import io.flutter.plugin.platform.PlatformViewsController;
2526
import io.flutter.view.AccessibilityBridge;
2627
import io.flutter.view.FlutterCallbackInformation;
2728
import java.nio.ByteBuffer;
@@ -168,6 +169,7 @@ public static native void nativeOnVsync(
168169
@Nullable private Long nativePlatformViewId;
169170
@Nullable private AccessibilityDelegate accessibilityDelegate;
170171
@Nullable private PlatformMessageHandler platformMessageHandler;
172+
@Nullable private PlatformViewsController platformViewsController;
171173

172174
@NonNull
173175
private final Set<EngineLifecycleListener> engineLifecycleListeners = new CopyOnWriteArraySet<>();
@@ -415,6 +417,12 @@ private native void nativeDispatchPointerDataPacket(
415417
long nativePlatformViewId, @NonNull ByteBuffer buffer, int position);
416418
// ------ End Touch Interaction Support ---
417419

420+
@UiThread
421+
public void setPlatformViewsController(@NonNull PlatformViewsController platformViewsController) {
422+
ensureRunningOnMainThread();
423+
this.platformViewsController = platformViewsController;
424+
}
425+
418426
// ------ Start Accessibility Support -----
419427
/**
420428
* Sets the {@link AccessibilityDelegate} for the attached Flutter context.
@@ -780,6 +788,17 @@ private void onPreEngineRestart() {
780788
listener.onPreEngineRestart();
781789
}
782790
}
791+
792+
@SuppressWarnings("unused")
793+
@UiThread
794+
public void onEndFrame() {
795+
ensureRunningOnMainThread();
796+
if (platformViewsController == null) {
797+
throw new RuntimeException(
798+
"platformViewsController must be set before attempting to end the frame");
799+
}
800+
platformViewsController.onEndFrame();
801+
}
783802
// ----- End Engine Lifecycle Support ----
784803

785804
// TODO(mattcarroll): determine if this is nonull or nullable

shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,8 @@ private void flushAllViews() {
533533
}
534534
vdControllers.clear();
535535
}
536+
537+
public void onEndFrame() {
538+
// TODO: Implement this method. https://github.com/flutter/flutter/issues/58288
539+
}
536540
}

shell/platform/android/platform_view_android_jni.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ void FlutterViewOnPreEngineRestart(JNIEnv* env, jobject obj) {
118118
FML_CHECK(CheckException(env));
119119
}
120120

121+
static jmethodID g_on_end_frame_method = nullptr;
122+
void FlutterViewEndFrame(JNIEnv* env, jobject obj) {
123+
env->CallVoidMethod(obj, g_on_end_frame_method);
124+
FML_CHECK(CheckException(env));
125+
}
126+
121127
static jmethodID g_attach_to_gl_context_method = nullptr;
122128
void SurfaceTextureAttachToGLContext(JNIEnv* env, jobject obj, jint textureId) {
123129
env->CallVoidMethod(obj, g_attach_to_gl_context_method, textureId);
@@ -757,6 +763,14 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
757763
return false;
758764
}
759765

766+
g_on_end_frame_method =
767+
env->GetMethodID(g_flutter_jni_class->obj(), "onEndFrame", "()V");
768+
769+
if (g_on_end_frame_method == nullptr) {
770+
FML_LOG(ERROR) << "Could not locate onEndFrame method";
771+
return false;
772+
}
773+
760774
g_attach_to_gl_context_method = env->GetMethodID(
761775
g_surface_texture_class->obj(), "attachToGLContext", "(I)V");
762776

shell/platform/android/test/io/flutter/embedding/engine/FlutterJNITest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package io.flutter.embedding.engine;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.mockito.Mockito.mock;
5+
import static org.mockito.Mockito.times;
6+
import static org.mockito.Mockito.verify;
47

58
import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
9+
import io.flutter.plugin.platform.PlatformViewsController;
610
import java.util.concurrent.atomic.AtomicInteger;
711
import org.junit.Test;
812
import org.junit.runner.RunWith;
@@ -44,4 +48,19 @@ public void onFlutterUiNoLongerDisplayed() {}
4448
// --- Verify Results ---
4549
assertEquals(1, callbackInvocationCount.get());
4650
}
51+
52+
@Test
53+
public void onEndFrame__callsPlatformViewsController() {
54+
PlatformViewsController platformViewsController = mock(PlatformViewsController.class);
55+
56+
// --- Test Setup ---
57+
FlutterJNI flutterJNI = new FlutterJNI();
58+
flutterJNI.setPlatformViewsController(platformViewsController);
59+
60+
// --- Execute Test ---
61+
flutterJNI.onEndFrame();
62+
63+
// --- Verify Results ---
64+
verify(platformViewsController, times(1)).onEndFrame();
65+
}
4766
}

0 commit comments

Comments
 (0)