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

Commit 7cb7003

Browse files
authored
onEndFrame JNI (#18867)
* onEndFrame JNI * beginFrame brief change
1 parent 8c24c41 commit 7cb7003

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,17 @@ public void onBeginFrame() {
810810
}
811811
platformViewsController.onBeginFrame();
812812
}
813+
814+
@SuppressWarnings("unused")
815+
@UiThread
816+
public void onEndFrame() {
817+
ensureRunningOnMainThread();
818+
if (platformViewsController == null) {
819+
throw new RuntimeException(
820+
"platformViewsController must be set before attempting to end the frame");
821+
}
822+
platformViewsController.onEndFrame();
823+
}
813824
// ----- End Engine Lifecycle Support ----
814825

815826
// @SuppressWarnings("unused")

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,4 +545,8 @@ public void onDisplayOverlaySurface(int id, int x, int y, int width, int height)
545545
public void onBeginFrame() {
546546
// TODO: Implement this method. https://github.com/flutter/flutter/issues/58288
547547
}
548+
549+
public void onEndFrame() {
550+
// TODO: Implement this method. https://github.com/flutter/flutter/issues/58288
551+
}
548552
}

shell/platform/android/jni/platform_view_android_jni.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ class PlatformViewAndroidJNI {
137137
/// @note Must be called from the platform thread.
138138
///
139139
virtual void FlutterViewBeginFrame() = 0;
140+
141+
//----------------------------------------------------------------------------
142+
/// @brief Indicates that the current frame ended.
143+
/// It's used to clean up state.
144+
///
145+
/// @note Must be called from the platform thread.
146+
///
147+
virtual void FlutterViewEndFrame() = 0;
140148
};
141149

142150
} // namespace flutter

shell/platform/android/platform_view_android_jni_impl.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ static jmethodID g_on_engine_restart_method = nullptr;
8282

8383
static jmethodID g_on_begin_frame_method = nullptr;
8484

85+
static jmethodID g_on_end_frame_method = nullptr;
86+
8587
static jmethodID g_attach_to_gl_context_method = nullptr;
8688

8789
static jmethodID g_update_tex_image_method = nullptr;
@@ -717,6 +719,14 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
717719
return false;
718720
}
719721

722+
g_on_end_frame_method =
723+
env->GetMethodID(g_flutter_jni_class->obj(), "onEndFrame", "()V");
724+
725+
if (g_on_end_frame_method == nullptr) {
726+
FML_LOG(ERROR) << "Could not locate onEndFrame method";
727+
return false;
728+
}
729+
720730
g_on_display_overlay_surface_method = env->GetMethodID(
721731
g_flutter_jni_class->obj(), "onDisplayOverlaySurface", "(IIIII)V");
722732

@@ -1046,4 +1056,17 @@ void PlatformViewAndroidJNIImpl::FlutterViewBeginFrame() {
10461056
FML_CHECK(CheckException(env));
10471057
}
10481058

1059+
void PlatformViewAndroidJNIImpl::FlutterViewEndFrame() {
1060+
JNIEnv* env = fml::jni::AttachCurrentThread();
1061+
1062+
auto java_object = java_object_.get(env);
1063+
if (java_object.is_null()) {
1064+
return;
1065+
}
1066+
1067+
env->CallVoidMethod(java_object.obj(), g_on_end_frame_method);
1068+
1069+
FML_CHECK(CheckException(env));
1070+
}
1071+
10491072
} // namespace flutter

shell/platform/android/platform_view_android_jni_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class PlatformViewAndroidJNIImpl final : public PlatformViewAndroidJNI {
6464

6565
void FlutterViewBeginFrame() override;
6666

67+
void FlutterViewEndFrame() override;
68+
6769
private:
6870
// Reference to FlutterJNI object.
6971
const fml::jni::JavaObjectWeakGlobalRef java_object_;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,19 @@ public void onBeginFrame__callsPlatformViewsController() {
9696
// --- Verify Results ---
9797
verify(platformViewsController, times(1)).onBeginFrame();
9898
}
99+
100+
@Test
101+
public void onEndFrame__callsPlatformViewsController() {
102+
PlatformViewsController platformViewsController = mock(PlatformViewsController.class);
103+
104+
// --- Test Setup ---
105+
FlutterJNI flutterJNI = new FlutterJNI();
106+
flutterJNI.setPlatformViewsController(platformViewsController);
107+
108+
// --- Execute Test ---
109+
flutterJNI.onEndFrame();
110+
111+
// --- Verify Results ---
112+
verify(platformViewsController, times(1)).onEndFrame();
113+
}
99114
}

0 commit comments

Comments
 (0)