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

Commit 639e2c6

Browse files
JNI glue for calling PlatformViewsController.createOverlaySurface (#19221)
1 parent 5b1b59a commit 639e2c6

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

shell/platform/android/platform_view_android_jni_impl.cc

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ static jmethodID g_on_display_platform_view_method = nullptr;
102102

103103
static jmethodID g_on_display_overlay_surface_method = nullptr;
104104

105+
static jfieldID g_overlay_surface_id_field = nullptr;
106+
107+
static jfieldID g_overlay_surface_surface_field = nullptr;
108+
105109
// Called By Java
106110
static jlong AttachJNI(JNIEnv* env,
107111
jclass clazz,
@@ -698,6 +702,25 @@ bool RegisterApi(JNIEnv* env) {
698702
return false;
699703
}
700704

705+
fml::jni::ScopedJavaLocalRef<jclass> overlay_surface_class(
706+
env, env->FindClass("io/flutter/embedding/engine/FlutterOverlaySurface"));
707+
if (overlay_surface_class.is_null()) {
708+
FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface class";
709+
return false;
710+
}
711+
g_overlay_surface_id_field =
712+
env->GetFieldID(overlay_surface_class.obj(), "id", "J");
713+
if (g_overlay_surface_id_field == nullptr) {
714+
FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface.id field";
715+
return false;
716+
}
717+
g_overlay_surface_surface_field = env->GetFieldID(
718+
overlay_surface_class.obj(), "surface", "Landroid/view/Surface;");
719+
if (g_overlay_surface_surface_field == nullptr) {
720+
FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface.surface field";
721+
return false;
722+
}
723+
701724
return true;
702725
}
703726

@@ -1113,12 +1136,27 @@ PlatformViewAndroidJNIImpl::FlutterViewCreateOverlaySurface() {
11131136
return nullptr;
11141137
}
11151138

1116-
env->CallVoidMethod(java_object.obj(), g_create_overlay_surface_method);
1117-
1139+
fml::jni::ScopedJavaLocalRef<jobject> overlay(
1140+
env, env->CallObjectMethod(java_object.obj(),
1141+
g_create_overlay_surface_method));
11181142
FML_CHECK(CheckException(env));
1119-
// TODO(egarciad): Wire this up.
1120-
// https://github.com/flutter/flutter/issues/55270
1121-
return std::make_unique<PlatformViewAndroidJNI::OverlayMetadata>(0, nullptr);
1143+
1144+
if (overlay.is_null()) {
1145+
return std::make_unique<PlatformViewAndroidJNI::OverlayMetadata>(0,
1146+
nullptr);
1147+
}
1148+
1149+
jlong overlay_id =
1150+
env->GetLongField(overlay.obj(), g_overlay_surface_id_field);
1151+
1152+
fml::jni::ScopedJavaLocalRef<jobject> overlay_surface(
1153+
env, env->GetObjectField(overlay.obj(), g_overlay_surface_surface_field));
1154+
1155+
auto overlay_window = fml::MakeRefCounted<AndroidNativeWindow>(
1156+
ANativeWindow_fromSurface(env, overlay_surface.obj()));
1157+
1158+
return std::make_unique<PlatformViewAndroidJNI::OverlayMetadata>(
1159+
overlay_id, std::move(overlay_window));
11221160
}
11231161

11241162
std::unique_ptr<std::vector<std::string>>

0 commit comments

Comments
 (0)