diff --git a/engine/src/flutter/shell/platform/android/android_context_gl.cc b/engine/src/flutter/shell/platform/android/android_context_gl.cc index 1a17a9a8f04..04e8b43d902 100644 --- a/engine/src/flutter/shell/platform/android/android_context_gl.cc +++ b/engine/src/flutter/shell/platform/android/android_context_gl.cc @@ -119,7 +119,7 @@ bool AndroidEGLSurface::IsValid() const { return surface_ != EGL_NO_SURFACE; } -bool AndroidEGLSurface::MakeCurrent() { +bool AndroidEGLSurface::MakeCurrent() const { if (eglMakeCurrent(display_, surface_, surface_, context_) != EGL_TRUE) { FML_LOG(ERROR) << "Could not make the context current"; LogLastEGLError(); @@ -235,7 +235,7 @@ bool AndroidContextGL::IsValid() const { return valid_; } -bool AndroidContextGL::ClearCurrent() { +bool AndroidContextGL::ClearCurrent() const { if (eglGetCurrentContext() != context_) { return true; } diff --git a/engine/src/flutter/shell/platform/android/android_context_gl.h b/engine/src/flutter/shell/platform/android/android_context_gl.h index a0e4f99e814..20710a83722 100644 --- a/engine/src/flutter/shell/platform/android/android_context_gl.h +++ b/engine/src/flutter/shell/platform/android/android_context_gl.h @@ -41,7 +41,7 @@ class AndroidEGLSurface { /// /// @return Whether the surface was made current. /// - bool MakeCurrent(); + bool MakeCurrent() const; //---------------------------------------------------------------------------- /// @brief This only applies to on-screen surfaces such as those created @@ -108,7 +108,7 @@ class AndroidContextGL : public AndroidContext { //---------------------------------------------------------------------------- /// @return Whether the current context was successfully clear. /// - bool ClearCurrent(); + bool ClearCurrent() const; //---------------------------------------------------------------------------- /// @brief Create a new EGLContext using the same EGLConfig. diff --git a/engine/src/flutter/shell/platform/android/android_surface_gl.cc b/engine/src/flutter/shell/platform/android/android_surface_gl.cc index 36720dc501f..8d778957095 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_gl.cc +++ b/engine/src/flutter/shell/platform/android/android_surface_gl.cc @@ -20,17 +20,14 @@ constexpr char kEmulatorRendererPrefix[] = } // anonymous namespace AndroidSurfaceGL::AndroidSurfaceGL( - std::shared_ptr android_context, - std::shared_ptr jni_facade, - std::shared_ptr external_view_embedder) - : external_view_embedder_(external_view_embedder), - android_context_( - std::static_pointer_cast(android_context)), + const AndroidContext& android_context, + std::shared_ptr jni_facade) + : android_context_(static_cast(android_context)), native_window_(nullptr), onscreen_surface_(nullptr), offscreen_surface_(nullptr) { // Acquire the offscreen surface. - offscreen_surface_ = android_context_->CreateOffscreenSurface(); + offscreen_surface_ = android_context_.CreateOffscreenSurface(); if (!offscreen_surface_->IsValid()) { offscreen_surface_ = nullptr; } @@ -42,12 +39,12 @@ void AndroidSurfaceGL::TeardownOnScreenContext() { // When the onscreen surface is destroyed, the context and the surface // instance should be deleted. Issue: // https://github.com/flutter/flutter/issues/64414 - android_context_->ClearCurrent(); + android_context_.ClearCurrent(); onscreen_surface_ = nullptr; } bool AndroidSurfaceGL::IsValid() const { - return offscreen_surface_ && android_context_->IsValid(); + return offscreen_surface_ && android_context_.IsValid(); } std::unique_ptr AndroidSurfaceGL::CreateGPUSurface( @@ -67,12 +64,12 @@ bool AndroidSurfaceGL::OnScreenSurfaceResize(const SkISize& size) { return true; } - android_context_->ClearCurrent(); + android_context_.ClearCurrent(); // Ensure the destructor is called since it destroys the `EGLSurface` before // creating a new onscreen surface. onscreen_surface_ = nullptr; - onscreen_surface_ = android_context_->CreateOnscreenSurface(native_window_); + onscreen_surface_ = android_context_.CreateOnscreenSurface(native_window_); if (!onscreen_surface_->IsValid()) { FML_LOG(ERROR) << "Unable to create EGL window surface on resize."; return false; @@ -88,7 +85,7 @@ bool AndroidSurfaceGL::ResourceContextMakeCurrent() { bool AndroidSurfaceGL::ResourceContextClearCurrent() { FML_DCHECK(IsValid()); - return android_context_->ClearCurrent(); + return android_context_.ClearCurrent(); } bool AndroidSurfaceGL::SetNativeWindow( @@ -100,7 +97,7 @@ bool AndroidSurfaceGL::SetNativeWindow( // creating a new onscreen surface. onscreen_surface_ = nullptr; // Create the onscreen surface. - onscreen_surface_ = android_context_->CreateOnscreenSurface(window); + onscreen_surface_ = android_context_.CreateOnscreenSurface(window); if (!onscreen_surface_->IsValid()) { return false; } @@ -117,7 +114,7 @@ std::unique_ptr AndroidSurfaceGL::GLContextMakeCurrent() { bool AndroidSurfaceGL::GLContextClearCurrent() { FML_DCHECK(IsValid()); - return android_context_->ClearCurrent(); + return android_context_.ClearCurrent(); } bool AndroidSurfaceGL::GLContextPresent(uint32_t fbo_id) { @@ -146,7 +143,7 @@ sk_sp AndroidSurfaceGL::GetGLInterface() const { reinterpret_cast(glGetString(GL_RENDERER)); if (gl_renderer && strncmp(gl_renderer, kEmulatorRendererPrefix, strlen(kEmulatorRendererPrefix)) == 0) { - EGLContext new_context = android_context_->CreateNewContext(); + EGLContext new_context = android_context_.CreateNewContext(); if (new_context != EGL_NO_CONTEXT) { EGLContext old_context = eglGetCurrentContext(); EGLDisplay display = eglGetCurrentDisplay(); diff --git a/engine/src/flutter/shell/platform/android/android_surface_gl.h b/engine/src/flutter/shell/platform/android/android_surface_gl.h index 86c35a8f8f6..1028f3c2b3d 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_gl.h +++ b/engine/src/flutter/shell/platform/android/android_surface_gl.h @@ -13,7 +13,6 @@ #include "flutter/shell/gpu/gpu_surface_gl.h" #include "flutter/shell/platform/android/android_context_gl.h" #include "flutter/shell/platform/android/android_environment_gl.h" -#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h" #include "flutter/shell/platform/android/jni/platform_view_android_jni.h" #include "flutter/shell/platform/android/surface/android_surface.h" @@ -22,10 +21,8 @@ namespace flutter { class AndroidSurfaceGL final : public GPUSurfaceGLDelegate, public AndroidSurface { public: - AndroidSurfaceGL( - std::shared_ptr android_context, - std::shared_ptr jni_facade, - std::shared_ptr external_view_embedder); + AndroidSurfaceGL(const AndroidContext& android_context, + std::shared_ptr jni_facade); ~AndroidSurfaceGL() override; @@ -67,8 +64,7 @@ class AndroidSurfaceGL final : public GPUSurfaceGLDelegate, sk_sp GetGLInterface() const override; private: - const std::shared_ptr external_view_embedder_; - const std::shared_ptr android_context_; + const AndroidContextGL& android_context_; fml::RefPtr native_window_; std::unique_ptr onscreen_surface_; diff --git a/engine/src/flutter/shell/platform/android/android_surface_software.cc b/engine/src/flutter/shell/platform/android/android_surface_software.cc index 7731c11e473..8a84204c214 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_software.cc +++ b/engine/src/flutter/shell/platform/android/android_surface_software.cc @@ -38,10 +38,8 @@ bool GetSkColorType(int32_t buffer_format, } // anonymous namespace AndroidSurfaceSoftware::AndroidSurfaceSoftware( - std::shared_ptr android_context, - std::shared_ptr jni_facade, - std::shared_ptr external_view_embedder) - : external_view_embedder_(external_view_embedder) { + const AndroidContext& android_context, + std::shared_ptr jni_facade) { GetSkColorType(WINDOW_FORMAT_RGBA_8888, &target_color_type_, &target_alpha_type_); } diff --git a/engine/src/flutter/shell/platform/android/android_surface_software.h b/engine/src/flutter/shell/platform/android/android_surface_software.h index 51c4c421dd0..9c3025e1949 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_software.h +++ b/engine/src/flutter/shell/platform/android/android_surface_software.h @@ -9,7 +9,6 @@ #include "flutter/fml/platform/android/jni_weak_ref.h" #include "flutter/fml/platform/android/scoped_java_ref.h" #include "flutter/shell/gpu/gpu_surface_software.h" -#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h" #include "flutter/shell/platform/android/jni/platform_view_android_jni.h" #include "flutter/shell/platform/android/surface/android_surface.h" @@ -18,10 +17,8 @@ namespace flutter { class AndroidSurfaceSoftware final : public AndroidSurface, public GPUSurfaceSoftwareDelegate { public: - AndroidSurfaceSoftware( - std::shared_ptr android_context, - std::shared_ptr jni_facade, - std::shared_ptr external_view_embedder); + AndroidSurfaceSoftware(const AndroidContext& android_context, + std::shared_ptr jni_facade); ~AndroidSurfaceSoftware() override; @@ -54,8 +51,6 @@ class AndroidSurfaceSoftware final : public AndroidSurface, bool PresentBackingStore(sk_sp backing_store) override; private: - const std::shared_ptr external_view_embedder_; - sk_sp sk_surface_; fml::RefPtr native_window_; SkColorType target_color_type_; diff --git a/engine/src/flutter/shell/platform/android/android_surface_vulkan.cc b/engine/src/flutter/shell/platform/android/android_surface_vulkan.cc index dfb710b90fc..ab3e68ca609 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_vulkan.cc +++ b/engine/src/flutter/shell/platform/android/android_surface_vulkan.cc @@ -13,11 +13,9 @@ namespace flutter { AndroidSurfaceVulkan::AndroidSurfaceVulkan( - std::shared_ptr android_context, - std::shared_ptr jni_facade, - std::shared_ptr external_view_embedder) - : external_view_embedder_(external_view_embedder), - proc_table_(fml::MakeRefCounted()) {} + const AndroidContext& android_context, + std::shared_ptr jni_facade) + : proc_table_(fml::MakeRefCounted()) {} AndroidSurfaceVulkan::~AndroidSurfaceVulkan() = default; diff --git a/engine/src/flutter/shell/platform/android/android_surface_vulkan.h b/engine/src/flutter/shell/platform/android/android_surface_vulkan.h index 58632d858b8..cf9c6fa7d04 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_vulkan.h +++ b/engine/src/flutter/shell/platform/android/android_surface_vulkan.h @@ -11,7 +11,6 @@ #include "flutter/fml/macros.h" #include "flutter/shell/gpu/gpu_surface_vulkan_delegate.h" -#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h" #include "flutter/shell/platform/android/jni/platform_view_android_jni.h" #include "flutter/shell/platform/android/surface/android_surface.h" #include "flutter/vulkan/vulkan_window.h" @@ -21,10 +20,8 @@ namespace flutter { class AndroidSurfaceVulkan : public AndroidSurface, public GPUSurfaceVulkanDelegate { public: - AndroidSurfaceVulkan( - std::shared_ptr android_context, - std::shared_ptr jni_facade, - std::shared_ptr external_view_embedder); + AndroidSurfaceVulkan(const AndroidContext& android_context, + std::shared_ptr jni_facade); ~AndroidSurfaceVulkan() override; @@ -54,7 +51,6 @@ class AndroidSurfaceVulkan : public AndroidSurface, fml::RefPtr vk() override; private: - const std::shared_ptr external_view_embedder_; fml::RefPtr proc_table_; fml::RefPtr native_window_; diff --git a/engine/src/flutter/shell/platform/android/context/android_context.h b/engine/src/flutter/shell/platform/android/context/android_context.h index 627cbd81508..e9bdc06b171 100644 --- a/engine/src/flutter/shell/platform/android/context/android_context.h +++ b/engine/src/flutter/shell/platform/android/context/android_context.h @@ -20,7 +20,7 @@ enum class AndroidRenderingAPI { /// class AndroidContext { public: - AndroidContext(AndroidRenderingAPI rendering_api); + explicit AndroidContext(AndroidRenderingAPI rendering_api); ~AndroidContext(); diff --git a/engine/src/flutter/shell/platform/android/external_view_embedder/external_view_embedder.cc b/engine/src/flutter/shell/platform/android/external_view_embedder/external_view_embedder.cc index 6ea00128f51..9e544d6a2e5 100644 --- a/engine/src/flutter/shell/platform/android/external_view_embedder/external_view_embedder.cc +++ b/engine/src/flutter/shell/platform/android/external_view_embedder/external_view_embedder.cc @@ -10,7 +10,7 @@ namespace flutter { AndroidExternalViewEmbedder::AndroidExternalViewEmbedder( - std::shared_ptr android_context, + const AndroidContext& android_context, std::shared_ptr jni_facade, std::shared_ptr surface_factory) : ExternalViewEmbedder(), diff --git a/engine/src/flutter/shell/platform/android/external_view_embedder/external_view_embedder.h b/engine/src/flutter/shell/platform/android/external_view_embedder/external_view_embedder.h index b8cf718a5ad..7398ce490aa 100644 --- a/engine/src/flutter/shell/platform/android/external_view_embedder/external_view_embedder.h +++ b/engine/src/flutter/shell/platform/android/external_view_embedder/external_view_embedder.h @@ -30,7 +30,7 @@ namespace flutter { class AndroidExternalViewEmbedder final : public ExternalViewEmbedder { public: AndroidExternalViewEmbedder( - std::shared_ptr android_context, + const AndroidContext& android_context, std::shared_ptr jni_facade, std::shared_ptr surface_factory); @@ -88,7 +88,7 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder { static const int kDefaultMergedLeaseDuration = 10; // Provides metadata to the Android surfaces. - const std::shared_ptr android_context_; + const AndroidContext& android_context_; // Allows to call methods in Java. const std::shared_ptr jni_facade_; diff --git a/engine/src/flutter/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc b/engine/src/flutter/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc index 54921d2659e..1c161cc953f 100644 --- a/engine/src/flutter/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc +++ b/engine/src/flutter/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc @@ -90,8 +90,9 @@ fml::RefPtr GetThreadMergerFromRasterThread() { TEST(AndroidExternalViewEmbedder, GetCurrentCanvases) { auto jni_mock = std::make_shared(); - auto embedder = - std::make_unique(nullptr, jni_mock, nullptr); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); + auto embedder = std::make_unique( + android_context, jni_mock, nullptr); auto raster_thread_merger = GetThreadMergerFromPlatformThread(); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); @@ -112,8 +113,9 @@ TEST(AndroidExternalViewEmbedder, GetCurrentCanvases) { TEST(AndroidExternalViewEmbedder, GetCurrentCanvases__CompositeOrder) { auto jni_mock = std::make_shared(); - auto embedder = - std::make_unique(nullptr, jni_mock, nullptr); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); + auto embedder = std::make_unique( + android_context, jni_mock, nullptr); auto raster_thread_merger = GetThreadMergerFromPlatformThread(); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); @@ -132,8 +134,9 @@ TEST(AndroidExternalViewEmbedder, GetCurrentCanvases__CompositeOrder) { } TEST(AndroidExternalViewEmbedder, CompositeEmbeddedView) { - auto embedder = - std::make_unique(nullptr, nullptr, nullptr); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); + auto embedder = std::make_unique( + android_context, nullptr, nullptr); ASSERT_EQ(nullptr, embedder->CompositeEmbeddedView(0)); embedder->PrerollCompositeEmbeddedView( @@ -147,8 +150,9 @@ TEST(AndroidExternalViewEmbedder, CompositeEmbeddedView) { } TEST(AndroidExternalViewEmbedder, CancelFrame) { - auto embedder = - std::make_unique(nullptr, nullptr, nullptr); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); + auto embedder = std::make_unique( + android_context, nullptr, nullptr); embedder->PrerollCompositeEmbeddedView( 0, std::make_unique()); @@ -160,8 +164,9 @@ TEST(AndroidExternalViewEmbedder, CancelFrame) { TEST(AndroidExternalViewEmbedder, RasterizerRunsOnPlatformThread) { auto jni_mock = std::make_shared(); - auto embedder = - std::make_unique(nullptr, jni_mock, nullptr); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); + auto embedder = std::make_unique( + android_context, jni_mock, nullptr); auto raster_thread_merger = GetThreadMergerFromPlatformThread(); ASSERT_FALSE(raster_thread_merger->IsMerged()); @@ -191,8 +196,9 @@ TEST(AndroidExternalViewEmbedder, RasterizerRunsOnPlatformThread) { TEST(AndroidExternalViewEmbedder, RasterizerRunsOnRasterizerThread) { auto jni_mock = std::make_shared(); - auto embedder = - std::make_unique(nullptr, jni_mock, nullptr); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); + auto embedder = std::make_unique( + android_context, jni_mock, nullptr); auto raster_thread_merger = GetThreadMergerFromPlatformThread(); ASSERT_FALSE(raster_thread_merger->IsMerged()); @@ -209,8 +215,9 @@ TEST(AndroidExternalViewEmbedder, RasterizerRunsOnRasterizerThread) { TEST(AndroidExternalViewEmbedder, PlatformViewRect) { auto jni_mock = std::make_shared(); - auto embedder = - std::make_unique(nullptr, jni_mock, nullptr); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); + auto embedder = std::make_unique( + android_context, jni_mock, nullptr); auto raster_thread_merger = GetThreadMergerFromPlatformThread(); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); @@ -234,8 +241,9 @@ TEST(AndroidExternalViewEmbedder, PlatformViewRect) { TEST(AndroidExternalViewEmbedder, PlatformViewRect__ChangedParams) { auto jni_mock = std::make_shared(); - auto embedder = - std::make_unique(nullptr, jni_mock, nullptr); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); + auto embedder = std::make_unique( + android_context, jni_mock, nullptr); auto raster_thread_merger = GetThreadMergerFromPlatformThread(); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); @@ -270,8 +278,7 @@ TEST(AndroidExternalViewEmbedder, PlatformViewRect__ChangedParams) { TEST(AndroidExternalViewEmbedder, SubmitFrame) { auto jni_mock = std::make_shared(); - auto android_context = - std::make_shared(AndroidRenderingAPI::kSoftware); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto window = fml::MakeRefCounted(nullptr); auto gr_context = GrDirectContext::MakeMock(nullptr); @@ -470,8 +477,9 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) { TEST(AndroidExternalViewEmbedder, DoesNotCallJNIPlatformThreadOnlyMethods) { auto jni_mock = std::make_shared(); - auto embedder = - std::make_unique(nullptr, jni_mock, nullptr); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); + auto embedder = std::make_unique( + android_context, jni_mock, nullptr); // While on the raster thread, don't make JNI calls as these methods can only // run on the platform thread. @@ -487,8 +495,6 @@ TEST(AndroidExternalViewEmbedder, DoesNotCallJNIPlatformThreadOnlyMethods) { TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) { auto jni_mock = std::make_shared(); - auto android_context = - std::make_shared(AndroidRenderingAPI::kSoftware); auto window = fml::MakeRefCounted(nullptr); auto gr_context = GrDirectContext::MakeMock(nullptr); @@ -516,6 +522,7 @@ TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) { return android_surface_mock; }); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto embedder = std::make_unique( android_context, jni_mock, surface_factory); auto raster_thread_merger = GetThreadMergerFromPlatformThread(); @@ -568,8 +575,7 @@ TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) { TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) { auto jni_mock = std::make_shared(); - auto android_context = - std::make_shared(AndroidRenderingAPI::kSoftware); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto window = fml::MakeRefCounted(nullptr); auto gr_context = GrDirectContext::MakeMock(nullptr); @@ -651,16 +657,17 @@ TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) { TEST(AndroidExternalViewEmbedder, SupportsDynamicThreadMerging) { auto jni_mock = std::make_shared(); - - auto embedder = - std::make_unique(nullptr, jni_mock, nullptr); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); + auto embedder = std::make_unique( + android_context, jni_mock, nullptr); ASSERT_TRUE(embedder->SupportsDynamicThreadMerging()); } TEST(AndroidExternalViewEmbedder, DisableThreadMerger) { auto jni_mock = std::make_shared(); - auto embedder = - std::make_unique(nullptr, jni_mock, nullptr); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); + auto embedder = std::make_unique( + android_context, jni_mock, nullptr); auto raster_thread_merger = GetThreadMergerFromRasterThread(); ASSERT_FALSE(raster_thread_merger->IsMerged()); diff --git a/engine/src/flutter/shell/platform/android/external_view_embedder/surface_pool.cc b/engine/src/flutter/shell/platform/android/external_view_embedder/surface_pool.cc index b07a8d1ec27..a7d5f11806d 100644 --- a/engine/src/flutter/shell/platform/android/external_view_embedder/surface_pool.cc +++ b/engine/src/flutter/shell/platform/android/external_view_embedder/surface_pool.cc @@ -21,7 +21,7 @@ SurfacePool::~SurfacePool() = default; std::shared_ptr SurfacePool::GetLayer( GrDirectContext* gr_context, - std::shared_ptr android_context, + const AndroidContext& android_context, std::shared_ptr jni_facade, std::shared_ptr surface_factory) { // Destroy current layers in the pool if the frame size has changed. diff --git a/engine/src/flutter/shell/platform/android/external_view_embedder/surface_pool.h b/engine/src/flutter/shell/platform/android/external_view_embedder/surface_pool.h index afdb6b6a35b..7f32104589d 100644 --- a/engine/src/flutter/shell/platform/android/external_view_embedder/surface_pool.h +++ b/engine/src/flutter/shell/platform/android/external_view_embedder/surface_pool.h @@ -53,7 +53,7 @@ class SurfacePool { // `available_layer_index_`. std::shared_ptr GetLayer( GrDirectContext* gr_context, - std::shared_ptr android_context, + const AndroidContext& android_context, std::shared_ptr jni_facade, std::shared_ptr surface_factory); diff --git a/engine/src/flutter/shell/platform/android/external_view_embedder/surface_pool_unittests.cc b/engine/src/flutter/shell/platform/android/external_view_embedder/surface_pool_unittests.cc index c313a43eb12..652951f474e 100644 --- a/engine/src/flutter/shell/platform/android/external_view_embedder/surface_pool_unittests.cc +++ b/engine/src/flutter/shell/platform/android/external_view_embedder/surface_pool_unittests.cc @@ -39,8 +39,7 @@ TEST(SurfacePool, GetLayer__AllocateOneLayer) { auto pool = std::make_unique(); auto gr_context = GrDirectContext::MakeMock(nullptr); - auto android_context = - std::make_shared(AndroidRenderingAPI::kSoftware); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto jni_mock = std::make_shared(); auto window = fml::MakeRefCounted(nullptr); @@ -69,8 +68,7 @@ TEST(SurfacePool, GetUnusedLayers) { auto pool = std::make_unique(); auto gr_context = GrDirectContext::MakeMock(nullptr); - auto android_context = - std::make_shared(AndroidRenderingAPI::kSoftware); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto jni_mock = std::make_shared(); auto window = fml::MakeRefCounted(nullptr); @@ -108,8 +106,7 @@ TEST(SurfacePool, GetLayer__Recycle) { ByMove(std::make_unique( 0, window)))); - auto android_context = - std::make_shared(AndroidRenderingAPI::kSoftware); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto gr_context_2 = GrDirectContext::MakeMock(nullptr); auto surface_factory = std::make_shared( @@ -145,8 +142,7 @@ TEST(SurfacePool, GetLayer__AllocateTwoLayers) { auto pool = std::make_unique(); auto gr_context = GrDirectContext::MakeMock(nullptr); - auto android_context = - std::make_shared(AndroidRenderingAPI::kSoftware); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto jni_mock = std::make_shared(); auto window = fml::MakeRefCounted(nullptr); @@ -186,8 +182,7 @@ TEST(SurfacePool, DestroyLayers) { pool->DestroyLayers(jni_mock); auto gr_context = GrDirectContext::MakeMock(nullptr); - auto android_context = - std::make_shared(AndroidRenderingAPI::kSoftware); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto window = fml::MakeRefCounted(nullptr); EXPECT_CALL(*jni_mock, FlutterViewCreateOverlaySurface()) @@ -218,8 +213,7 @@ TEST(SurfacePool, DestroyLayers__frameSizeChanged) { auto jni_mock = std::make_shared(); auto gr_context = GrDirectContext::MakeMock(nullptr); - auto android_context = - std::make_shared(AndroidRenderingAPI::kSoftware); + auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto window = fml::MakeRefCounted(nullptr); diff --git a/engine/src/flutter/shell/platform/android/platform_view_android.cc b/engine/src/flutter/shell/platform/android/platform_view_android.cc index 8612d646519..8b6b27658b6 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android.cc @@ -29,32 +29,23 @@ namespace flutter { AndroidSurfaceFactoryImpl::AndroidSurfaceFactoryImpl( - std::shared_ptr context, + const AndroidContext& context, 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(); - FML_CHECK(external_view_embedder); - switch (android_context_->RenderingApi()) { + switch (android_context_.RenderingApi()) { case AndroidRenderingAPI::kSoftware: - return std::make_unique( - android_context_, jni_facade_, external_view_embedder); + return std::make_unique(android_context_, + jni_facade_); case AndroidRenderingAPI::kOpenGLES: - return std::make_unique(android_context_, jni_facade_, - external_view_embedder); + return std::make_unique(android_context_, jni_facade_); case AndroidRenderingAPI::kVulkan: #if SHELL_ENABLE_VULKAN - return std::make_unique( - android_context_, jni_facade_, external_view_embedder); + return std::make_unique(android_context_, + jni_facade_); #endif // SHELL_ENABLE_VULKAN default: return nullptr; @@ -70,28 +61,24 @@ PlatformViewAndroid::PlatformViewAndroid( : PlatformView(delegate, std::move(task_runners)), jni_facade_(jni_facade), platform_view_android_delegate_(jni_facade) { - std::shared_ptr android_context; if (use_software_rendering) { - android_context = - std::make_shared(AndroidRenderingAPI::kSoftware); + android_context_ = + std::make_unique(AndroidRenderingAPI::kSoftware); } else { #if SHELL_ENABLE_VULKAN - android_context = - std::make_shared(AndroidRenderingAPI::kVulkan); + android_context_ = + std::make_unique(AndroidRenderingAPI::kVulkan); #else // SHELL_ENABLE_VULKAN - android_context = std::make_shared( + android_context_ = std::make_unique( AndroidRenderingAPI::kOpenGLES, fml::MakeRefCounted()); #endif // SHELL_ENABLE_VULKAN } - FML_CHECK(android_context && android_context->IsValid()) + FML_CHECK(android_context_ && android_context_->IsValid()) << "Could not create an Android context."; - surface_factory_ = - 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_); + surface_factory_ = std::make_shared( + *android_context_, jni_facade); android_surface_ = surface_factory_->CreateSurface(); FML_CHECK(android_surface_ && android_surface_->IsValid()) @@ -310,7 +297,8 @@ std::unique_ptr PlatformViewAndroid::CreateRenderingSurface() { // |PlatformView| std::shared_ptr PlatformViewAndroid::CreateExternalViewEmbedder() { - return external_view_embedder_; + return std::make_shared( + *android_context_, jni_facade_, surface_factory_); } // |PlatformView| diff --git a/engine/src/flutter/shell/platform/android/platform_view_android.h b/engine/src/flutter/shell/platform/android/platform_view_android.h index b2500c979b9..a808257ae72 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android.h +++ b/engine/src/flutter/shell/platform/android/platform_view_android.h @@ -15,6 +15,7 @@ #include "flutter/fml/platform/android/scoped_java_ref.h" #include "flutter/lib/ui/window/platform_message.h" #include "flutter/shell/common/platform_view.h" +#include "flutter/shell/platform/android/context/android_context.h" #include "flutter/shell/platform/android/jni/platform_view_android_jni.h" #include "flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate.h" #include "flutter/shell/platform/android/surface/android_native_window.h" @@ -24,18 +25,15 @@ namespace flutter { class AndroidSurfaceFactoryImpl : public AndroidSurfaceFactory { public: - AndroidSurfaceFactoryImpl(std::shared_ptr context, + AndroidSurfaceFactoryImpl(const AndroidContext& context, 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_; + const AndroidContext& android_context_; std::shared_ptr jni_facade_; std::weak_ptr external_view_embedder_; }; @@ -98,7 +96,7 @@ class PlatformViewAndroid final : public PlatformView { private: const std::shared_ptr jni_facade_; - std::shared_ptr external_view_embedder_; + std::unique_ptr android_context_; std::shared_ptr surface_factory_; PlatformViewAndroidDelegate platform_view_android_delegate_;