Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,17 @@ public void onBeginFrame() {
}
platformViewsController.onBeginFrame();
}

@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 ----

// @SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,4 +545,8 @@ public void onDisplayOverlaySurface(int id, int x, int y, int width, int height)
public void onBeginFrame() {
// TODO: Implement this method. https://github.com/flutter/flutter/issues/58288
}

public void onEndFrame() {
// TODO: Implement this method. https://github.com/flutter/flutter/issues/58288
}
}
8 changes: 8 additions & 0 deletions shell/platform/android/jni/platform_view_android_jni.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ class PlatformViewAndroidJNI {
/// @note Must be called from the platform thread.
///
virtual void FlutterViewBeginFrame() = 0;

//----------------------------------------------------------------------------
/// @brief Indicates that the current frame ended.
/// It's used to clean up state.
///
/// @note Must be called from the platform thread.
///
virtual void FlutterViewEndFrame() = 0;
};

} // namespace flutter
Expand Down
23 changes: 23 additions & 0 deletions shell/platform/android/platform_view_android_jni_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ static jmethodID g_on_engine_restart_method = nullptr;

static jmethodID g_on_begin_frame_method = nullptr;

static jmethodID g_on_end_frame_method = nullptr;

static jmethodID g_attach_to_gl_context_method = nullptr;

static jmethodID g_update_tex_image_method = nullptr;
Expand Down Expand Up @@ -728,6 +730,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_on_display_overlay_surface_method = env->GetMethodID(
g_flutter_jni_class->obj(), "onDisplayOverlaySurface", "(IIIII)V");

Expand Down Expand Up @@ -1057,4 +1067,17 @@ void PlatformViewAndroidJNIImpl::FlutterViewBeginFrame() {
FML_CHECK(CheckException(env));
}

void PlatformViewAndroidJNIImpl::FlutterViewEndFrame() {
JNIEnv* env = fml::jni::AttachCurrentThread();

auto java_object = java_object_.get(env);
if (java_object.is_null()) {
return;
}

env->CallVoidMethod(java_object.obj(), g_on_end_frame_method);

FML_CHECK(CheckException(env));
}

} // namespace flutter
2 changes: 2 additions & 0 deletions shell/platform/android/platform_view_android_jni_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class PlatformViewAndroidJNIImpl final : public PlatformViewAndroidJNI {

void FlutterViewBeginFrame() override;

void FlutterViewEndFrame() override;

private:
// Reference to FlutterJNI object.
const fml::jni::JavaObjectWeakGlobalRef java_object_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,19 @@ public void onBeginFrame__callsPlatformViewsController() {
// --- Verify Results ---
verify(platformViewsController, times(1)).onBeginFrame();
}

@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();
}
}