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 @@ -799,6 +799,17 @@ public void onDisplayOverlaySurface(int id, int x, int y, int width, int height)
}
platformViewsController.onDisplayOverlaySurface(id, x, y, width, height);
}

@SuppressWarnings("unused")
@UiThread
public void onBeginFrame() {
ensureRunningOnMainThread();
if (platformViewsController == null) {
throw new RuntimeException(
"platformViewsController must be set before attempting to begin the frame");
}
platformViewsController.onBeginFrame();
}
// ----- End Engine Lifecycle Support ----

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

public void onBeginFrame() {
// TODO: Implement this method. https://github.com/flutter/flutter/issues/58288
}
}
7 changes: 7 additions & 0 deletions shell/platform/android/jni/platform_view_android_jni.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ class PlatformViewAndroidJNI {
int y,
int width,
int height) = 0;
//----------------------------------------------------------------------------
/// @brief Initiates a frame if using hybrid composition.
///
///
/// @note Must be called from the platform thread.
///
virtual void FlutterViewBeginFrame() = 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 @@ -80,6 +80,8 @@ static jmethodID g_on_first_frame_method = nullptr;

static jmethodID g_on_engine_restart_method = nullptr;

static jmethodID g_on_begin_frame_method = nullptr;

static jmethodID g_attach_to_gl_context_method = nullptr;

static jmethodID g_update_tex_image_method = nullptr;
Expand Down Expand Up @@ -718,6 +720,14 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
return false;
}

g_on_begin_frame_method =
env->GetMethodID(g_flutter_jni_class->obj(), "onBeginFrame", "()V");

if (g_on_begin_frame_method == nullptr) {
FML_LOG(ERROR) << "Could not locate onBeginFrame method";
return false;
}

g_on_display_overlay_surface_method = env->GetMethodID(
g_flutter_jni_class->obj(), "onDisplayOverlaySurface", "(IIIII)V");

Expand Down Expand Up @@ -1034,4 +1044,17 @@ void PlatformViewAndroidJNIImpl::FlutterViewDisplayOverlaySurface(
FML_CHECK(CheckException(env));
}

void PlatformViewAndroidJNIImpl::FlutterViewBeginFrame() {
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_begin_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 @@ -62,6 +62,8 @@ class PlatformViewAndroidJNIImpl final : public PlatformViewAndroidJNI {
int width,
int height) override;

void FlutterViewBeginFrame() 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 @@ -81,4 +81,19 @@ public void onDisplayOverlaySurface__callsPlatformViewsController() {
verify(platformViewsController, times(1))
.onDisplayOverlaySurface(/*id=*/ 1, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, /*height=*/ 200);
}

@Test
public void onBeginFrame__callsPlatformViewsController() {
PlatformViewsController platformViewsController = mock(PlatformViewsController.class);

// --- Test Setup ---
FlutterJNI flutterJNI = new FlutterJNI();
flutterJNI.setPlatformViewsController(platformViewsController);

// --- Execute Test ---
flutterJNI.onBeginFrame();

// --- Verify Results ---
verify(platformViewsController, times(1)).onBeginFrame();
}
}