diff --git a/shell/platform/android/external_view_embedder/external_view_embedder.cc b/shell/platform/android/external_view_embedder/external_view_embedder.cc index 84f2ab9378125..0c326eb950b03 100644 --- a/shell/platform/android/external_view_embedder/external_view_embedder.cc +++ b/shell/platform/android/external_view_embedder/external_view_embedder.cc @@ -4,8 +4,6 @@ #include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h" -#include "flutter/fml/synchronization/waitable_event.h" -#include "flutter/fml/task_runner.h" #include "flutter/fml/trace_event.h" #include "flutter/shell/platform/android/surface/android_surface.h" @@ -14,14 +12,12 @@ namespace flutter { AndroidExternalViewEmbedder::AndroidExternalViewEmbedder( const AndroidContext& android_context, std::shared_ptr jni_facade, - std::shared_ptr surface_factory, - TaskRunners task_runners) + std::shared_ptr surface_factory) : ExternalViewEmbedder(), android_context_(android_context), jni_facade_(jni_facade), surface_factory_(surface_factory), - surface_pool_(std::make_unique()), - task_runners_(task_runners) {} + surface_pool_(std::make_unique()) {} // |ExternalViewEmbedder| void AndroidExternalViewEmbedder::PrerollCompositeEmbeddedView( @@ -268,8 +264,8 @@ void AndroidExternalViewEmbedder::BeginFrame( // The surface size changed. Therefore, destroy existing surfaces as // the existing surfaces in the pool can't be recycled. - if (frame_size_ != frame_size) { - DestroySurfaces(); + if (frame_size_ != frame_size && raster_thread_merger->IsOnPlatformThread()) { + surface_pool_->DestroyLayers(jni_facade_); } surface_pool_->SetFrameSize(frame_size); // JNI method must be called on the platform thread. @@ -304,18 +300,7 @@ bool AndroidExternalViewEmbedder::SupportsDynamicThreadMerging() { // |ExternalViewEmbedder| void AndroidExternalViewEmbedder::Teardown() { - DestroySurfaces(); -} - -// |ExternalViewEmbedder| -void AndroidExternalViewEmbedder::DestroySurfaces() { - fml::AutoResetWaitableEvent latch; - fml::TaskRunner::RunNowOrPostTask(task_runners_.GetPlatformTaskRunner(), - [&]() { - surface_pool_->DestroyLayers(jni_facade_); - latch.Signal(); - }); - latch.Wait(); + surface_pool_->DestroyLayers(jni_facade_); } } // namespace flutter diff --git a/shell/platform/android/external_view_embedder/external_view_embedder.h b/shell/platform/android/external_view_embedder/external_view_embedder.h index 2ec13297bb9ad..278d7693e7661 100644 --- a/shell/platform/android/external_view_embedder/external_view_embedder.h +++ b/shell/platform/android/external_view_embedder/external_view_embedder.h @@ -7,7 +7,6 @@ #include -#include "flutter/common/task_runners.h" #include "flutter/flow/embedded_views.h" #include "flutter/flow/rtree.h" #include "flutter/shell/platform/android/context/android_context.h" @@ -33,8 +32,7 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder { AndroidExternalViewEmbedder( const AndroidContext& android_context, std::shared_ptr jni_facade, - std::shared_ptr surface_factory, - TaskRunners task_runners); + std::shared_ptr surface_factory); // |ExternalViewEmbedder| void PrerollCompositeEmbeddedView( @@ -101,9 +99,6 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder { // Holds surfaces. Allows to recycle surfaces or allocate new ones. const std::unique_ptr surface_pool_; - // The task runners. - const TaskRunners task_runners_; - // The size of the root canvas. SkISize frame_size_; @@ -131,11 +126,6 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder { // The number of platform views in the previous frame. int64_t previous_frame_view_count_; - // Destroys the surfaces created from the surface factory. - // This method schedules a task on the platform thread, and waits for - // the task until it completes. - void DestroySurfaces(); - // Resets the state. void Reset(); diff --git a/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc b/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc index 57966440d0d05..c5a3c19701a3f 100644 --- a/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc +++ b/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#define FML_USED_ON_EMBEDDER - #include #include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h" @@ -89,24 +87,12 @@ fml::RefPtr GetThreadMergerFromRasterThread( rasterizer_queue_id); } -TaskRunners GetTaskRunnersForFixture() { - fml::MessageLoop::EnsureInitializedForCurrentThread(); - auto& loop = fml::MessageLoop::GetCurrent(); - return { - "test", - loop.GetTaskRunner(), // platform - loop.GetTaskRunner(), // raster - loop.GetTaskRunner(), // ui - loop.GetTaskRunner() // io - }; -} - TEST(AndroidExternalViewEmbedder, GetCurrentCanvases) { auto jni_mock = std::make_shared(); auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto embedder = std::make_unique( - android_context, jni_mock, nullptr, GetTaskRunnersForFixture()); + android_context, jni_mock, nullptr); fml::Thread rasterizer_thread("rasterizer"); auto raster_thread_merger = GetThreadMergerFromPlatformThread(&rasterizer_thread); @@ -131,7 +117,7 @@ TEST(AndroidExternalViewEmbedder, GetCurrentCanvasesCompositeOrder) { auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto embedder = std::make_unique( - android_context, jni_mock, nullptr, GetTaskRunnersForFixture()); + android_context, jni_mock, nullptr); fml::Thread rasterizer_thread("rasterizer"); auto raster_thread_merger = GetThreadMergerFromPlatformThread(&rasterizer_thread); @@ -154,7 +140,7 @@ TEST(AndroidExternalViewEmbedder, GetCurrentCanvasesCompositeOrder) { TEST(AndroidExternalViewEmbedder, CompositeEmbeddedView) { auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto embedder = std::make_unique( - android_context, nullptr, nullptr, GetTaskRunnersForFixture()); + android_context, nullptr, nullptr); ASSERT_EQ(nullptr, embedder->CompositeEmbeddedView(0)); embedder->PrerollCompositeEmbeddedView( @@ -170,7 +156,7 @@ TEST(AndroidExternalViewEmbedder, CompositeEmbeddedView) { TEST(AndroidExternalViewEmbedder, CancelFrame) { auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto embedder = std::make_unique( - android_context, nullptr, nullptr, GetTaskRunnersForFixture()); + android_context, nullptr, nullptr); embedder->PrerollCompositeEmbeddedView( 0, std::make_unique()); @@ -184,7 +170,7 @@ TEST(AndroidExternalViewEmbedder, RasterizerRunsOnPlatformThread) { auto jni_mock = std::make_shared(); auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto embedder = std::make_unique( - android_context, jni_mock, nullptr, GetTaskRunnersForFixture()); + android_context, jni_mock, nullptr); fml::Thread rasterizer_thread("rasterizer"); auto raster_thread_merger = @@ -218,7 +204,7 @@ TEST(AndroidExternalViewEmbedder, RasterizerRunsOnRasterizerThread) { auto jni_mock = std::make_shared(); auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto embedder = std::make_unique( - android_context, jni_mock, nullptr, GetTaskRunnersForFixture()); + android_context, jni_mock, nullptr); fml::Thread rasterizer_thread("rasterizer"); auto raster_thread_merger = @@ -239,7 +225,7 @@ TEST(AndroidExternalViewEmbedder, PlatformViewRect) { auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto embedder = std::make_unique( - android_context, jni_mock, nullptr, GetTaskRunnersForFixture()); + android_context, jni_mock, nullptr); fml::Thread rasterizer_thread("rasterizer"); auto raster_thread_merger = GetThreadMergerFromPlatformThread(&rasterizer_thread); @@ -267,7 +253,7 @@ TEST(AndroidExternalViewEmbedder, PlatformViewRectChangedParams) { auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto embedder = std::make_unique( - android_context, jni_mock, nullptr, GetTaskRunnersForFixture()); + android_context, jni_mock, nullptr); fml::Thread rasterizer_thread("rasterizer"); auto raster_thread_merger = GetThreadMergerFromPlatformThread(&rasterizer_thread); @@ -342,7 +328,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) { return android_surface_mock; }); auto embedder = std::make_unique( - *android_context, jni_mock, surface_factory, GetTaskRunnersForFixture()); + *android_context, jni_mock, surface_factory); auto raster_thread_merger = GetThreadMergerFromPlatformThread(); @@ -535,7 +521,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFrameOverlayComposition) { return android_surface_mock; }); auto embedder = std::make_unique( - *android_context, jni_mock, surface_factory, GetTaskRunnersForFixture()); + *android_context, jni_mock, surface_factory); auto raster_thread_merger = GetThreadMergerFromPlatformThread(); @@ -637,7 +623,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFramePlatformViewWithoutAnyOverlay) { return android_surface_mock; }); auto embedder = std::make_unique( - *android_context, jni_mock, surface_factory, GetTaskRunnersForFixture()); + *android_context, jni_mock, surface_factory); auto raster_thread_merger = GetThreadMergerFromPlatformThread(); @@ -676,7 +662,7 @@ TEST(AndroidExternalViewEmbedder, DoesNotCallJNIPlatformThreadOnlyMethods) { auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto embedder = std::make_unique( - android_context, jni_mock, nullptr, GetTaskRunnersForFixture()); + 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. @@ -725,7 +711,7 @@ TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) { }); auto embedder = std::make_unique( - *android_context, jni_mock, surface_factory, GetTaskRunnersForFixture()); + *android_context, jni_mock, surface_factory); fml::Thread rasterizer_thread("rasterizer"); auto raster_thread_merger = GetThreadMergerFromPlatformThread(&rasterizer_thread); @@ -812,7 +798,7 @@ TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) { }); auto embedder = std::make_unique( - *android_context, jni_mock, surface_factory, GetTaskRunnersForFixture()); + *android_context, jni_mock, surface_factory); // ------------------ First frame ------------------ // { @@ -857,7 +843,9 @@ TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) { embedder->EndFrame(/*should_resubmit_frame=*/false, raster_thread_merger); } - EXPECT_CALL(*jni_mock, FlutterViewDestroyOverlaySurfaces()).Times(1); + // Changing the frame size from the raster thread does not make JNI calls. + + EXPECT_CALL(*jni_mock, FlutterViewDestroyOverlaySurfaces()).Times(0); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()).Times(0); fml::Thread platform_thread("platform"); @@ -869,7 +857,7 @@ TEST(AndroidExternalViewEmbedder, SupportsDynamicThreadMerging) { auto jni_mock = std::make_shared(); auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto embedder = std::make_unique( - android_context, jni_mock, nullptr, GetTaskRunnersForFixture()); + android_context, jni_mock, nullptr); ASSERT_TRUE(embedder->SupportsDynamicThreadMerging()); } @@ -877,7 +865,7 @@ TEST(AndroidExternalViewEmbedder, DisableThreadMerger) { auto jni_mock = std::make_shared(); auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); auto embedder = std::make_unique( - android_context, jni_mock, nullptr, GetTaskRunnersForFixture()); + android_context, jni_mock, nullptr); fml::Thread platform_thread("platform"); auto raster_thread_merger = GetThreadMergerFromRasterThread(&platform_thread); @@ -933,7 +921,7 @@ TEST(AndroidExternalViewEmbedder, Teardown) { }); auto embedder = std::make_unique( - *android_context, jni_mock, surface_factory, GetTaskRunnersForFixture()); + *android_context, jni_mock, surface_factory); fml::Thread rasterizer_thread("rasterizer"); auto raster_thread_merger = GetThreadMergerFromPlatformThread(&rasterizer_thread); diff --git a/shell/platform/android/platform_view_android.cc b/shell/platform/android/platform_view_android.cc index 97c58de4c3298..c3d4c696628f4 100644 --- a/shell/platform/android/platform_view_android.cc +++ b/shell/platform/android/platform_view_android.cc @@ -14,12 +14,13 @@ #include "flutter/shell/platform/android/android_external_texture_gl.h" #include "flutter/shell/platform/android/android_surface_gl.h" #include "flutter/shell/platform/android/android_surface_software.h" -#include "flutter/shell/platform/android/context/android_context.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/platform_message_response_android.h" #include "flutter/shell/platform/android/surface/android_surface.h" #include "flutter/shell/platform/android/surface/snapshot_surface_producer.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_message_response_android.h" #include "flutter/shell/platform/android/vsync_waiter_android.h" namespace flutter { @@ -254,8 +255,7 @@ std::unique_ptr PlatformViewAndroid::CreateRenderingSurface() { std::shared_ptr PlatformViewAndroid::CreateExternalViewEmbedder() { return std::make_shared( - *android_context_, jni_facade_, surface_factory_, - std::move(task_runners_)); + *android_context_, jni_facade_, surface_factory_); } // |PlatformView|