From 6694c1b3cd22d2269af3cd563d2a018d850ead20 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 19 Oct 2020 14:53:38 -0700 Subject: [PATCH] Fix the initialization of AndroidSurfaceFactoryImpl Fixes https://github.com/flutter/flutter/issues/68446 --- .../platform/android/platform_view_android.cc | 20 ++++++++++--------- .../platform/android/platform_view_android.h | 6 ++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/shell/platform/android/platform_view_android.cc b/shell/platform/android/platform_view_android.cc index 0fc9af5c59b51..8ebac2aa929b9 100644 --- a/shell/platform/android/platform_view_android.cc +++ b/shell/platform/android/platform_view_android.cc @@ -30,13 +30,16 @@ namespace flutter { AndroidSurfaceFactoryImpl::AndroidSurfaceFactoryImpl( std::shared_ptr context, - std::shared_ptr jni_facade, - std::weak_ptr external_view_embedder) - : android_context_(context), jni_facade_(jni_facade), - external_view_embedder_(external_view_embedder) {} + std::shared_ptr jni_facade) + : android_context_(context), jni_facade_(jni_facade) {} AndroidSurfaceFactoryImpl::~AndroidSurfaceFactoryImpl() = default; +void AndroidSurfaceFactoryImpl::SetExternalViewEmbedder( + std::shared_ptr external_view_embedder) { + external_view_embedder_ = external_view_embedder; +} + std::unique_ptr AndroidSurfaceFactoryImpl::CreateSurface() { std::shared_ptr external_view_embedder = external_view_embedder_.lock(); @@ -84,12 +87,11 @@ PlatformViewAndroid::PlatformViewAndroid( FML_CHECK(android_context && android_context->IsValid()) << "Could not create an Android context."; - external_view_embedder_ = - std::make_shared(android_context, jni_facade, - surface_factory_); surface_factory_ = - std::make_shared(android_context, jni_facade, - external_view_embedder_); + std::make_shared(android_context, jni_facade); + external_view_embedder_ = std::make_shared( + android_context, jni_facade, surface_factory_); + surface_factory_->SetExternalViewEmbedder(external_view_embedder_); android_surface_ = surface_factory_->CreateSurface(); FML_CHECK(android_surface_ && android_surface_->IsValid()) diff --git a/shell/platform/android/platform_view_android.h b/shell/platform/android/platform_view_android.h index 2ae51464df3c2..b1bf8194976f5 100644 --- a/shell/platform/android/platform_view_android.h +++ b/shell/platform/android/platform_view_android.h @@ -25,13 +25,15 @@ namespace flutter { class AndroidSurfaceFactoryImpl : public AndroidSurfaceFactory { public: AndroidSurfaceFactoryImpl(std::shared_ptr context, - std::shared_ptr jni_facade, - std::weak_ptr external_view_embedder); + std::shared_ptr jni_facade); ~AndroidSurfaceFactoryImpl() override; std::unique_ptr CreateSurface() override; + void SetExternalViewEmbedder( + std::shared_ptr external_view_embedder); + private: std::shared_ptr android_context_; std::shared_ptr jni_facade_;