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
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import androidx.annotation.Keep;
import androidx.annotation.NonNull;

@Keep
public class FlutterOverlaySurface {
@NonNull private final Surface surface;

private final long id;

@Keep
public FlutterOverlaySurface(long id, @NonNull Surface surface) {
this.id = id;
this.surface = surface;
Expand Down
29 changes: 15 additions & 14 deletions shell/platform/android/platform_view_android_jni_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ static jmethodID g_on_display_platform_view_method = nullptr;

static jmethodID g_on_display_overlay_surface_method = nullptr;

static jfieldID g_overlay_surface_id_field = nullptr;
static jmethodID g_overlay_surface_id_method = nullptr;

static jfieldID g_overlay_surface_surface_field = nullptr;
static jmethodID g_overlay_surface_surface_method = nullptr;

// Called By Java
static jlong AttachJNI(JNIEnv* env,
Expand Down Expand Up @@ -708,16 +708,17 @@ bool RegisterApi(JNIEnv* env) {
FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface class";
return false;
}
g_overlay_surface_id_field =
env->GetFieldID(overlay_surface_class.obj(), "id", "J");
if (g_overlay_surface_id_field == nullptr) {
FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface.id field";
g_overlay_surface_id_method =
env->GetMethodID(overlay_surface_class.obj(), "getId", "()J");
if (g_overlay_surface_id_method == nullptr) {
FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface#getId() method";
return false;
}
g_overlay_surface_surface_field = env->GetFieldID(
overlay_surface_class.obj(), "surface", "Landroid/view/Surface;");
if (g_overlay_surface_surface_field == nullptr) {
FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface.surface field";
g_overlay_surface_surface_method = env->GetMethodID(
overlay_surface_class.obj(), "getSurface", "()Landroid/view/Surface;");
if (g_overlay_surface_surface_method == nullptr) {
FML_LOG(ERROR)
<< "Could not locate FlutterOverlaySurface#getSurface() method";
return false;
}

Expand Down Expand Up @@ -1147,13 +1148,13 @@ PlatformViewAndroidJNIImpl::FlutterViewCreateOverlaySurface() {
}

jlong overlay_id =
env->GetLongField(overlay.obj(), g_overlay_surface_id_field);
env->CallLongMethod(overlay.obj(), g_overlay_surface_id_method);

fml::jni::ScopedJavaLocalRef<jobject> overlay_surface(
env, env->GetObjectField(overlay.obj(), g_overlay_surface_surface_field));
jobject overlay_surface =
env->CallObjectMethod(overlay.obj(), g_overlay_surface_surface_method);

auto overlay_window = fml::MakeRefCounted<AndroidNativeWindow>(
ANativeWindow_fromSurface(env, overlay_surface.obj()));
ANativeWindow_fromSurface(env, overlay_surface));

return std::make_unique<PlatformViewAndroidJNI::OverlayMetadata>(
overlay_id, std::move(overlay_window));
Expand Down