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

Commit fe8a503

Browse files
committed
fix conflicts
1 parent 3ba1c4e commit fe8a503

File tree

7 files changed

+188
-3
lines changed

7 files changed

+188
-3
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,39 @@ public void onDisplayOverlaySurface(int id, int x, int y, int width, int height)
799799
}
800800
platformViewsController.onDisplayOverlaySurface(id, x, y, width, height);
801801
}
802+
803+
@SuppressWarnings("unused")
804+
@UiThread
805+
public void onBeginFrame() {
806+
ensureRunningOnMainThread();
807+
if (platformViewsController == null) {
808+
throw new RuntimeException(
809+
"platformViewsController must be set before attempting to begin the frame");
810+
}
811+
platformViewsController.onBeginFrame();
812+
}
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+
}
824+
825+
@SuppressWarnings("unused")
826+
@UiThread
827+
public FlutterOverlaySurface createOverlaySurface() {
828+
ensureRunningOnMainThread();
829+
if (platformViewsController == null) {
830+
throw new RuntimeException(
831+
"platformViewsController must be set before attempting to position an overlay surface");
832+
}
833+
platformViewsController.onDisplayOverlaySurface(id, x, y, width, height);
834+
}
802835
// ----- End Engine Lifecycle Support ----
803836

804837
// @SuppressWarnings("unused")

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
import android.view.Surface;
88

99
public class FlutterOverlaySurface {
10+
// @NonNull
1011
private final Surface surface;
12+
1113
private final long id;
1214

15+
// @Keep
1316
public FlutterOverlaySurface(long id, Surface surface) {
1417
this.id = id;
1518
this.surface = surface;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import androidx.annotation.NonNull;
1818
import androidx.annotation.UiThread;
1919
import androidx.annotation.VisibleForTesting;
20+
import io.flutter.embedding.engine.FlutterOverlaySurface;
2021
import io.flutter.embedding.engine.dart.DartExecutor;
2122
import io.flutter.embedding.engine.systemchannels.PlatformViewsChannel;
22-
import io.flutter.embedding.engine.FlutterOverlaySurface;
2323
import io.flutter.plugin.editing.TextInputPlugin;
2424
import io.flutter.view.AccessibilityBridge;
2525
import io.flutter.view.TextureRegistry;
@@ -555,4 +555,4 @@ public FlutterOverlaySurface createOverlaySurface() {
555555
// TODO: Implement this method. https://github.com/flutter/flutter/issues/58288
556556
return null;
557557
}
558-
}
558+
}

shell/platform/android/jni/platform_view_android_jni.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,30 @@ class PlatformViewAndroidJNI {
130130
int y,
131131
int width,
132132
int height) = 0;
133+
134+
//----------------------------------------------------------------------------
135+
/// @brief Initiates a frame if using hybrid composition.
136+
///
137+
///
138+
/// @note Must be called from the platform thread.
139+
///
140+
virtual void FlutterViewBeginFrame() = 0;
141+
142+
//----------------------------------------------------------------------------
143+
/// @brief Indicates that the current frame ended.
144+
/// It's used to clean up state.
145+
///
146+
/// @note Must be called from the platform thread.
147+
///
148+
virtual void FlutterViewEndFrame() = 0;
149+
150+
//----------------------------------------------------------------------------
151+
/// @brief Indicates that the current frame ended.
152+
/// It's used to clean up state.
153+
///
154+
/// @note Must be called from the platform thread.
155+
///
156+
virtual FlutterOverlaySurface FlutterViewCreateOverlaySurface() = 0;
133157
};
134158

135159
} // namespace flutter

shell/platform/android/platform_view_android_jni_impl.cc

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ std::unique_ptr<AndroidFlutterOverlaySurface> FlutterViewCreateOverlaySurface(
100100
ANativeWindow_fromSurface(env, surface)));
101101
}
102102

103+
static jmethodID g_on_begin_frame_method = nullptr;
104+
105+
static jmethodID g_on_end_frame_method = nullptr;
106+
107+
static jmethodID g_create_overlay_surface_method = nullptr;
108+
109+
static jmethodID g_flutter_overlay_layer_get_id_method = nullptr;
110+
111+
static jmethodID g_flutter_overlay_layer_get_surface_method = nullptr;
112+
103113
static jmethodID g_attach_to_gl_context_method = nullptr;
104114

105115
static jmethodID g_update_tex_image_method = nullptr;
@@ -746,6 +756,30 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
746756
return false;
747757
}
748758

759+
g_on_begin_frame_method =
760+
env->GetMethodID(g_flutter_jni_class->obj(), "onBeginFrame", "()V");
761+
762+
if (g_on_begin_frame_method == nullptr) {
763+
FML_LOG(ERROR) << "Could not locate onBeginFrame method";
764+
return false;
765+
}
766+
767+
g_on_end_frame_method =
768+
env->GetMethodID(g_flutter_jni_class->obj(), "onEndFrame", "()V");
769+
770+
if (g_on_end_frame_method == nullptr) {
771+
FML_LOG(ERROR) << "Could not locate onEndFrame method";
772+
return false;
773+
}
774+
775+
g_create_overlay_surface_method = env->GetMethodID(
776+
g_flutter_jni_class->obj(), "createOverlaySurface", "()V");
777+
778+
if (g_create_overlay_surface_method == nullptr) {
779+
FML_LOG(ERROR) << "Could not locate createOverlaySurface method";
780+
return false;
781+
}
782+
749783
g_on_display_overlay_surface_method = env->GetMethodID(
750784
g_flutter_jni_class->obj(), "onDisplayOverlaySurface", "(IIIII)V");
751785

@@ -1062,4 +1096,43 @@ void PlatformViewAndroidJNIImpl::FlutterViewDisplayOverlaySurface(
10621096
FML_CHECK(CheckException(env));
10631097
}
10641098

1065-
} // namespace flutter
1099+
void PlatformViewAndroidJNIImpl::FlutterViewBeginFrame() {
1100+
JNIEnv* env = fml::jni::AttachCurrentThread();
1101+
1102+
auto java_object = java_object_.get(env);
1103+
if (java_object.is_null()) {
1104+
return;
1105+
}
1106+
1107+
env->CallVoidMethod(java_object.obj(), g_on_begin_frame_method);
1108+
1109+
FML_CHECK(CheckException(env));
1110+
}
1111+
1112+
void PlatformViewAndroidJNIImpl::FlutterViewEndFrame() {
1113+
JNIEnv* env = fml::jni::AttachCurrentThread();
1114+
1115+
auto java_object = java_object_.get(env);
1116+
if (java_object.is_null()) {
1117+
return;
1118+
}
1119+
1120+
env->CallVoidMethod(java_object.obj(), g_on_end_frame_method);
1121+
1122+
FML_CHECK(CheckException(env));
1123+
}
1124+
1125+
void PlatformViewAndroidJNIImpl::FlutterViewCreateOverlaySurface() {
1126+
JNIEnv* env = fml::jni::AttachCurrentThread();
1127+
1128+
auto java_object = java_object_.get(env);
1129+
if (java_object.is_null()) {
1130+
return;
1131+
}
1132+
1133+
env->CallVoidMethod(java_object.obj(), g_create_overlay_surface_method);
1134+
1135+
FML_CHECK(CheckException(env));
1136+
}
1137+
1138+
} // namespace flutter

shell/platform/android/platform_view_android_jni_impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ class PlatformViewAndroidJNIImpl final : public PlatformViewAndroidJNI {
6262
int width,
6363
int height) override;
6464

65+
void FlutterViewBeginFrame() override;
66+
67+
void FlutterViewEndFrame() override;
68+
69+
void FlutterViewCreateOverlaySurface() override;
70+
6571
private:
6672
// Reference to FlutterJNI object.
6773
const fml::jni::JavaObjectWeakGlobalRef java_object_;

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,50 @@ public void onDisplayOverlaySurface__callsPlatformViewsController() {
8181
verify(platformViewsController, times(1))
8282
.onDisplayOverlaySurface(/*id=*/ 1, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, /*height=*/ 200);
8383
}
84+
85+
@Test
86+
public void onBeginFrame__callsPlatformViewsController() {
87+
PlatformViewsController platformViewsController = mock(PlatformViewsController.class);
88+
89+
// --- Test Setup ---
90+
FlutterJNI flutterJNI = new FlutterJNI();
91+
flutterJNI.setPlatformViewsController(platformViewsController);
92+
93+
// --- Execute Test ---
94+
flutterJNI.onBeginFrame();
95+
96+
// --- Verify Results ---
97+
verify(platformViewsController, times(1)).onBeginFrame();
98+
}
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+
}
114+
115+
@Test
116+
public void createOverlaySurface__callsPlatformViewsController() {
117+
PlatformViewsController platformViewsController = mock(PlatformViewsController.class);
118+
119+
FlutterJNI flutterJNI = new FlutterJNI();
120+
flutterJNI.setPlatformViewsController(platformViewsController);
121+
122+
// --- Execute Test ---
123+
flutterJNI.onDisplayOverlaySurface(
124+
/*id=*/ 1, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, /*height=*/ 200);
125+
126+
// --- Verify Results ---
127+
verify(platformViewsController, times(1))
128+
.onDisplayOverlaySurface(/*id=*/ 1, /*x=*/ 10, /*y=*/ 20, /*width=*/ 100, /*height=*/ 200);
129+
}
84130
}

0 commit comments

Comments
 (0)