Skip to content

Commit

Permalink
Break the reference cycle between the surface factory and the externa…
Browse files Browse the repository at this point in the history
…l view embedder (flutter#21918)

See flutter#68315
  • Loading branch information
jason-simmons committed Oct 16, 2020
1 parent 5bd7260 commit 787b9c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
32 changes: 15 additions & 17 deletions shell/platform/android/platform_view_android.cc
Expand Up @@ -30,31 +30,28 @@ namespace flutter {

AndroidSurfaceFactoryImpl::AndroidSurfaceFactoryImpl(
std::shared_ptr<AndroidContext> context,
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
android_context_ = context;
jni_facade_ = jni_facade;
}
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
std::weak_ptr<AndroidExternalViewEmbedder> external_view_embedder)
: android_context_(context), jni_facade_(jni_facade),
external_view_embedder_(external_view_embedder) {}

AndroidSurfaceFactoryImpl::~AndroidSurfaceFactoryImpl() = default;

void AndroidSurfaceFactoryImpl::SetExternalViewEmbedder(
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder) {
external_view_embedder_ = external_view_embedder;
}

std::unique_ptr<AndroidSurface> AndroidSurfaceFactoryImpl::CreateSurface() {
FML_CHECK(external_view_embedder_);
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder =
external_view_embedder_.lock();
FML_CHECK(external_view_embedder);
switch (android_context_->RenderingApi()) {
case AndroidRenderingAPI::kSoftware:
return std::make_unique<AndroidSurfaceSoftware>(
android_context_, jni_facade_, external_view_embedder_);
android_context_, jni_facade_, external_view_embedder);
case AndroidRenderingAPI::kOpenGLES:
return std::make_unique<AndroidSurfaceGL>(android_context_, jni_facade_,
external_view_embedder_);
external_view_embedder);
case AndroidRenderingAPI::kVulkan:
#if SHELL_ENABLE_VULKAN
return std::make_unique<AndroidSurfaceVulkan>(
android_context_, jni_facade_, external_view_embedder_);
android_context_, jni_facade_, external_view_embedder);
#endif // SHELL_ENABLE_VULKAN
default:
return nullptr;
Expand Down Expand Up @@ -87,11 +84,12 @@ PlatformViewAndroid::PlatformViewAndroid(
FML_CHECK(android_context && android_context->IsValid())
<< "Could not create an Android context.";

external_view_embedder_ =
std::make_shared<AndroidExternalViewEmbedder>(android_context, jni_facade,
surface_factory_);
surface_factory_ =
std::make_shared<AndroidSurfaceFactoryImpl>(android_context, jni_facade);
surface_factory_->SetExternalViewEmbedder(
std::make_shared<AndroidExternalViewEmbedder>(android_context, jni_facade,
surface_factory_));
std::make_shared<AndroidSurfaceFactoryImpl>(android_context, jni_facade,
external_view_embedder_);

android_surface_ = surface_factory_->CreateSurface();
FML_CHECK(android_surface_ && android_surface_->IsValid())
Expand Down
10 changes: 4 additions & 6 deletions shell/platform/android/platform_view_android.h
Expand Up @@ -25,20 +25,17 @@ namespace flutter {
class AndroidSurfaceFactoryImpl : public AndroidSurfaceFactory {
public:
AndroidSurfaceFactoryImpl(std::shared_ptr<AndroidContext> context,
std::shared_ptr<PlatformViewAndroidJNI> jni_facade);
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
std::weak_ptr<AndroidExternalViewEmbedder> external_view_embedder);

~AndroidSurfaceFactoryImpl() override;

std::unique_ptr<AndroidSurface> CreateSurface() override;

void SetExternalViewEmbedder(
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder);

private:
std::shared_ptr<AndroidContext> android_context_;
std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder_;

std::weak_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
};

class PlatformViewAndroid final : public PlatformView {
Expand Down Expand Up @@ -99,6 +96,7 @@ class PlatformViewAndroid final : public PlatformView {

private:
const std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
std::shared_ptr<AndroidExternalViewEmbedder> external_view_embedder_;
std::shared_ptr<AndroidSurfaceFactoryImpl> surface_factory_;

PlatformViewAndroidDelegate platform_view_android_delegate_;
Expand Down

0 comments on commit 787b9c5

Please sign in to comment.