From 6887a43bb702626b8ef017a4e9df8c385439cbc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=A1=E5=98=89=E5=81=A5?= Date: Fri, 20 Sep 2024 17:34:59 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"Add=20call=20to=20Dart=5FNotifyDestro?= =?UTF-8?q?yed=20when=20the=20flutter=20view=20is=20destroyed.=20(#37539)"?= =?UTF-8?q?=20Reason:=20=E5=9C=A8=E5=A4=9A=E4=B8=AAflutterView=E5=A4=8D?= =?UTF-8?q?=E7=94=A8=E5=90=8C=E4=B8=80=E4=B8=AA=E5=BC=95=E6=93=8E=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=EF=BC=8C=E8=AF=A5=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BC=9A=E5=AF=BC=E8=87=B4=E5=BA=94=E7=94=A8=E5=88=87=E6=8D=A2?= =?UTF-8?q?flutterView=E7=9A=84=E6=97=B6=E5=80=99=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E4=B8=A5=E9=87=8D=E7=9A=84=E6=80=A7=E8=83=BD=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E6=AF=94=E5=A6=82=E6=96=B0flutterView=E7=9A=84UI?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E6=97=A0=E6=B3=95=E5=8F=8A=E6=97=B6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=EF=BC=88=E9=97=AA=E7=99=BD=EF=BC=89=E6=88=96=E8=80=85?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=BA=86=E5=89=8D=E4=B8=80=E4=B8=AAflutterVi?= =?UTF-8?q?ew=E7=9A=84=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 1e1a4ab3c993b98fcd9304a88cf9a09abe271a98. Signed-off-by: 蔡嘉健 --- runtime/runtime_controller.cc | 13 ---------- runtime/runtime_controller.h | 11 --------- shell/common/engine.cc | 5 ---- shell/common/engine.h | 7 ------ shell/common/fixtures/shell_test.dart | 7 ------ shell/common/shell.cc | 8 ------- shell/common/shell_unittests.cc | 34 --------------------------- 7 files changed, 85 deletions(-) diff --git a/runtime/runtime_controller.cc b/runtime/runtime_controller.cc index 9870d5e780..357654958e 100644 --- a/runtime/runtime_controller.cc +++ b/runtime/runtime_controller.cc @@ -243,19 +243,6 @@ bool RuntimeController::NotifyIdle(fml::TimeDelta deadline) { return true; } -bool RuntimeController::NotifyDestroyed() { - std::shared_ptr root_isolate = root_isolate_.lock(); - if (!root_isolate) { - return false; - } - - tonic::DartState::Scope scope(root_isolate); - - Dart_NotifyDestroyed(); - - return true; -} - bool RuntimeController::DispatchPlatformMessage( std::unique_ptr message) { if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) { diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h index 3f8fa2dcb3..d4a6ab6c0a 100644 --- a/runtime/runtime_controller.h +++ b/runtime/runtime_controller.h @@ -360,17 +360,6 @@ class RuntimeController : public PlatformConfigurationClient { /// virtual bool NotifyIdle(fml::TimeDelta deadline); - //---------------------------------------------------------------------------- - /// @brief Notify the Dart VM that the attached flutter view has been - /// destroyed. This gives the Dart VM to perform some cleanup - /// activities e.g: perform garbage collection to free up any - /// unused memory. - /// - /// NotifyDestroyed is advisory. The VM may or may not perform any clean up - /// activities. - /// - virtual bool NotifyDestroyed(); - //---------------------------------------------------------------------------- /// @brief Returns if the root isolate is running. The isolate must be /// transitioned to the running phase manually. The isolate can diff --git a/shell/common/engine.cc b/shell/common/engine.cc index bbdf61cac7..88be4b15dc 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -261,11 +261,6 @@ void Engine::NotifyIdle(fml::TimeDelta deadline) { runtime_controller_->NotifyIdle(deadline); } -void Engine::NotifyDestroyed() { - TRACE_EVENT0("flutter", "Engine::NotifyDestroyed"); - runtime_controller_->NotifyDestroyed(); -} - std::optional Engine::GetUIIsolateReturnCode() { return runtime_controller_->GetRootIsolateReturnCode(); } diff --git a/shell/common/engine.h b/shell/common/engine.h index 70402c24a7..e08fc0a20d 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -554,13 +554,6 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { /// void NotifyIdle(fml::TimeDelta deadline); - //---------------------------------------------------------------------------- - /// @brief Notifies the engine that the attached flutter view has been - /// destroyed. - /// This enables the engine to notify the Dart VM so it can do - /// some cleanp activities. - void NotifyDestroyed(); - //---------------------------------------------------------------------------- /// @brief Dart code cannot fully measure the time it takes for a /// specific frame to be rendered. This is because Dart code only diff --git a/shell/common/fixtures/shell_test.dart b/shell/common/fixtures/shell_test.dart index 605e3d951d..9a7c02179f 100644 --- a/shell/common/fixtures/shell_test.dart +++ b/shell/common/fixtures/shell_test.dart @@ -212,11 +212,6 @@ void performanceModeImpactsNotifyIdle() { PlatformDispatcher.instance.requestDartPerformanceMode(DartPerformanceMode.balanced); } -@pragma('vm:entry-point') -void callNotifyDestroyed() { - notifyDestroyed(); -} - @pragma('vm:external-name', 'NotifyMessage') external void notifyMessage(String string); @@ -429,8 +424,6 @@ Future runCallback(IsolateParam param) async { @pragma('vm:entry-point') @pragma('vm:external-name', 'NotifyNativeBool') external void notifyNativeBool(bool value); -@pragma('vm:external-name', 'NotifyDestroyed') -external void notifyDestroyed(); @pragma('vm:entry-point') Future testPluginUtilitiesCallbackHandle() async { diff --git a/shell/common/shell.cc b/shell/common/shell.cc index bdaf8c234d..de1fbb6e19 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -851,14 +851,6 @@ void Shell::OnPlatformViewDestroyed() { // This incorrect assumption can lead to deadlock. rasterizer_->DisableThreadMergerIfNeeded(); - // Notify the Dart VM that the PlatformView has been destroyed and some - // cleanup activity can be done (e.g: garbage collect the Dart heap). - task_runners_.GetUITaskRunner()->PostTask([engine = engine_->GetWeakPtr()]() { - if (engine) { - engine->NotifyDestroyed(); - } - }); - // Note: // This is a synchronous operation because certain platforms depend on // setup/suspension of all activities that may be interacting with the GPU in diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index d850eab688..64504b70ba 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -3979,40 +3979,6 @@ TEST_F(ShellTest, NotifyIdleNotCalledInLatencyMode) { ASSERT_FALSE(DartVMRef::IsInstanceRunning()); } -TEST_F(ShellTest, NotifyDestroyed) { - ASSERT_FALSE(DartVMRef::IsInstanceRunning()); - Settings settings = CreateSettingsForFixture(); - ThreadHost thread_host("io.flutter.test." + GetCurrentTestName() + ".", - ThreadHost::Type::Platform | ThreadHost::UI | - ThreadHost::IO | ThreadHost::RASTER); - auto platform_task_runner = thread_host.platform_thread->GetTaskRunner(); - TaskRunners task_runners("test", thread_host.platform_thread->GetTaskRunner(), - thread_host.raster_thread->GetTaskRunner(), - thread_host.ui_thread->GetTaskRunner(), - thread_host.io_thread->GetTaskRunner()); - auto shell = CreateShell(settings, task_runners); - ASSERT_TRUE(DartVMRef::IsInstanceRunning()); - ASSERT_TRUE(ValidateShell(shell.get())); - - fml::CountDownLatch latch(1); - AddNativeCallback("NotifyDestroyed", CREATE_NATIVE_ENTRY([&](auto args) { - auto runtime_controller = const_cast( - shell->GetEngine()->GetRuntimeController()); - bool success = runtime_controller->NotifyDestroyed(); - EXPECT_TRUE(success); - latch.CountDown(); - })); - - auto configuration = RunConfiguration::InferFromSettings(settings); - configuration.SetEntrypoint("callNotifyDestroyed"); - RunEngine(shell.get(), std::move(configuration)); - - latch.Wait(); - - DestroyShell(std::move(shell), task_runners); - ASSERT_FALSE(DartVMRef::IsInstanceRunning()); -} - } // namespace testing } // namespace flutter -- Gitee