diff --git a/lib/ui/ui_dart_state.cc b/lib/ui/ui_dart_state.cc index 33bbd384b8c446d85f974515a7a0d79af0d11e1b..4b0a9b4bbf736d176e065afd6adc90676f40f7b2 100644 --- a/lib/ui/ui_dart_state.cc +++ b/lib/ui/ui_dart_state.cc @@ -18,6 +18,7 @@ UIDartState::UIDartState( TaskObserverAdd add_callback, TaskObserverRemove remove_callback, fml::WeakPtr io_manager, + fml::RefPtr skia_unref_queue, fml::WeakPtr image_decoder, std::string advisory_script_uri, std::string advisory_script_entrypoint, @@ -28,6 +29,7 @@ UIDartState::UIDartState( add_callback_(std::move(add_callback)), remove_callback_(std::move(remove_callback)), io_manager_(std::move(io_manager)), + skia_unref_queue_(std::move(skia_unref_queue)), image_decoder_(std::move(image_decoder)), advisory_script_uri_(std::move(advisory_script_uri)), advisory_script_entrypoint_(std::move(advisory_script_entrypoint)), @@ -83,16 +85,7 @@ fml::WeakPtr UIDartState::GetIOManager() const { } fml::RefPtr UIDartState::GetSkiaUnrefQueue() const { - // TODO(gw280): The WeakPtr here asserts that we are derefing it on the - // same thread as it was created on. As we can't guarantee that currently - // we're being called from the IO thread (construction thread), we need - // to use getUnsafe() here to avoid failing the assertion. - // - // https://github.com/flutter/flutter/issues/42946 - if (!io_manager_.getUnsafe()) { - return nullptr; - } - return io_manager_.getUnsafe()->GetSkiaUnrefQueue(); + return skia_unref_queue_; } void UIDartState::ScheduleMicrotask(Dart_Handle closure) { diff --git a/lib/ui/ui_dart_state.h b/lib/ui/ui_dart_state.h index 186911e4c7c9d0ea315ac1914505f12d62650c8a..0a076ce401088003665587e3478e0d8e5627b089 100644 --- a/lib/ui/ui_dart_state.h +++ b/lib/ui/ui_dart_state.h @@ -77,6 +77,7 @@ class UIDartState : public tonic::DartState { TaskObserverAdd add_callback, TaskObserverRemove remove_callback, fml::WeakPtr io_manager, + fml::RefPtr skia_unref_queue, fml::WeakPtr image_decoder, std::string advisory_script_uri, std::string advisory_script_entrypoint, @@ -99,6 +100,7 @@ class UIDartState : public tonic::DartState { const TaskObserverAdd add_callback_; const TaskObserverRemove remove_callback_; fml::WeakPtr io_manager_; + fml::RefPtr skia_unref_queue_; fml::WeakPtr image_decoder_; const std::string advisory_script_uri_; const std::string advisory_script_entrypoint_; diff --git a/runtime/dart_isolate.cc b/runtime/dart_isolate.cc index 2db8ae2c7cd59674d8096209b4e78cdab930fde0..786c10e214fde10bb8e8e52300ffef4a36c75287 100644 --- a/runtime/dart_isolate.cc +++ b/runtime/dart_isolate.cc @@ -36,6 +36,7 @@ std::weak_ptr DartIsolate::CreateRootIsolate( TaskRunners task_runners, std::unique_ptr window, fml::WeakPtr io_manager, + fml::RefPtr unref_queue, fml::WeakPtr image_decoder, std::string advisory_script_uri, std::string advisory_script_entrypoint, @@ -61,6 +62,7 @@ std::weak_ptr DartIsolate::CreateRootIsolate( std::move(shared_snapshot), // shared snapshot task_runners, // task runners std::move(io_manager), // IO manager + std::move(unref_queue), // Skia unref queue std::move(image_decoder), // Image Decoder advisory_script_uri, // advisory URI advisory_script_entrypoint, // advisory entrypoint @@ -105,6 +107,7 @@ DartIsolate::DartIsolate(const Settings& settings, fml::RefPtr shared_snapshot, TaskRunners task_runners, fml::WeakPtr io_manager, + fml::RefPtr unref_queue, fml::WeakPtr image_decoder, std::string advisory_script_uri, std::string advisory_script_entrypoint, @@ -115,6 +118,7 @@ DartIsolate::DartIsolate(const Settings& settings, settings.task_observer_add, settings.task_observer_remove, std::move(io_manager), + std::move(unref_queue), std::move(image_decoder), advisory_script_uri, advisory_script_entrypoint, @@ -596,6 +600,7 @@ Dart_Isolate DartIsolate::DartCreateAndStartServiceIsolate( null_task_runners, // task runners nullptr, // window {}, // IO Manager + {}, // Skia unref queue {}, // Image Decoder DART_VM_SERVICE_ISOLATE_NAME, // script uri DART_VM_SERVICE_ISOLATE_NAME, // script entrypoint @@ -708,7 +713,8 @@ DartIsolate::CreateDartVMAndEmbedderObjectPair( (*raw_embedder_isolate)->GetSharedSnapshot(), // shared_snapshot null_task_runners, // task_runners fml::WeakPtr{}, // io_manager - fml::WeakPtr{}, // io_manager + fml::RefPtr{}, // unref_queue + fml::WeakPtr{}, // image_decoder advisory_script_uri, // advisory_script_uri advisory_script_entrypoint, // advisory_script_entrypoint (*raw_embedder_isolate)->child_isolate_preparer_, // preparer diff --git a/runtime/dart_isolate.h b/runtime/dart_isolate.h index e7ab9b30243c468bff72fe6e81a7d72d0f24966a..b94f9d299e226e06a319119b266d5ebabd992d26 100644 --- a/runtime/dart_isolate.h +++ b/runtime/dart_isolate.h @@ -156,6 +156,7 @@ class DartIsolate : public UIDartState { /// @param[in] window The weak pointer to the window /// associated with this root isolate. /// @param[in] io_manager The i/o manager. + /// @param[in] unref_queue The Skia unref queue. /// @param[in] image_decoder The image decoder. /// @param[in] advisory_script_uri The advisory script uri. This is /// only used in instrumentation. @@ -196,6 +197,7 @@ class DartIsolate : public UIDartState { TaskRunners task_runners, std::unique_ptr window, fml::WeakPtr io_manager, + fml::RefPtr skia_unref_queue, fml::WeakPtr image_decoder, std::string advisory_script_uri, std::string advisory_script_entrypoint, @@ -441,6 +443,7 @@ class DartIsolate : public UIDartState { fml::RefPtr shared_snapshot, TaskRunners task_runners, fml::WeakPtr io_manager, + fml::RefPtr unref_queue, fml::WeakPtr image_decoder, std::string advisory_script_uri, std::string advisory_script_entrypoint, diff --git a/runtime/dart_isolate_unittests.cc b/runtime/dart_isolate_unittests.cc index 83a140737324bc3922aac454b0dfa38997fb7bb1..25b324666fd79900f17d47d52e722ec72b269046 100644 --- a/runtime/dart_isolate_unittests.cc +++ b/runtime/dart_isolate_unittests.cc @@ -42,6 +42,7 @@ TEST_F(DartIsolateTest, RootIsolateCreationAndShutdown) { std::move(task_runners), // task runners nullptr, // window {}, // io manager + {}, // unref queue {}, // image decoder "main.dart", // advisory uri "main", // advisory entrypoint, @@ -75,6 +76,7 @@ TEST_F(DartIsolateTest, IsolateShutdownCallbackIsInIsolateScope) { std::move(task_runners), // task runners nullptr, // window {}, // io manager + {}, // unref queue {}, // image decoder "main.dart", // advisory uri "main", // advisory entrypoint @@ -185,6 +187,7 @@ static void RunDartCodeInIsolate(DartVMRef& vm_ref, std::move(task_runners), // task runners nullptr, // window {}, // io manager + {}, // unref queue {}, // image decoder "main.dart", // advisory uri "main", // advisory entrypoint diff --git a/runtime/dart_lifecycle_unittests.cc b/runtime/dart_lifecycle_unittests.cc index 7a607b7be26ff3cb59b73eac1cfead4be5c57791..4653738e0d9e46f89d806ab0050440a24e43f4f5 100644 --- a/runtime/dart_lifecycle_unittests.cc +++ b/runtime/dart_lifecycle_unittests.cc @@ -57,6 +57,7 @@ static std::shared_ptr CreateAndRunRootIsolate( runners, // task_runners {}, // window {}, // io_manager + {}, // unref_queue {}, // image_decoder "main.dart", // advisory_script_uri entrypoint.c_str(), // advisory_script_entrypoint diff --git a/runtime/runtime_controller.cc b/runtime/runtime_controller.cc index 61415ec4124c89a420a08d2ea6a13ef34918ab90..7ec4bb550d9ba6b81ffa840dabc2773d6b48eced 100644 --- a/runtime/runtime_controller.cc +++ b/runtime/runtime_controller.cc @@ -21,6 +21,7 @@ RuntimeController::RuntimeController( fml::RefPtr p_shared_snapshot, TaskRunners p_task_runners, fml::WeakPtr p_io_manager, + fml::RefPtr p_unref_queue, fml::WeakPtr p_image_decoder, std::string p_advisory_script_uri, std::string p_advisory_script_entrypoint, @@ -34,6 +35,7 @@ RuntimeController::RuntimeController( std::move(p_shared_snapshot), std::move(p_task_runners), std::move(p_io_manager), + std::move(p_unref_queue), std::move(p_image_decoder), std::move(p_advisory_script_uri), std::move(p_advisory_script_entrypoint), @@ -50,6 +52,7 @@ RuntimeController::RuntimeController( fml::RefPtr p_shared_snapshot, TaskRunners p_task_runners, fml::WeakPtr p_io_manager, + fml::RefPtr p_unref_queue, fml::WeakPtr p_image_decoder, std::string p_advisory_script_uri, std::string p_advisory_script_entrypoint, @@ -64,6 +67,7 @@ RuntimeController::RuntimeController( shared_snapshot_(std::move(p_shared_snapshot)), task_runners_(p_task_runners), io_manager_(p_io_manager), + unref_queue_(p_unref_queue), image_decoder_(p_image_decoder), advisory_script_uri_(p_advisory_script_uri), advisory_script_entrypoint_(p_advisory_script_entrypoint), @@ -82,6 +86,7 @@ RuntimeController::RuntimeController( task_runners_, // std::make_unique(this), // io_manager_, // + unref_queue_, // image_decoder_, // p_advisory_script_uri, // p_advisory_script_entrypoint, // @@ -142,6 +147,7 @@ std::unique_ptr RuntimeController::Clone() const { shared_snapshot_, // task_runners_, // io_manager_, // + unref_queue_, // image_decoder_, // advisory_script_uri_, // advisory_script_entrypoint_, // diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h index 665f0e17dbb59d6ca3aa1c55001b37913a57276a..615873ad648ee1a749efa3abde4fc1e82be4dd10 100644 --- a/runtime/runtime_controller.h +++ b/runtime/runtime_controller.h @@ -35,7 +35,8 @@ class RuntimeController final : public WindowClient { fml::RefPtr shared_snapshot, TaskRunners task_runners, fml::WeakPtr io_manager, - fml::WeakPtr iamge_decoder, + fml::RefPtr unref_queue, + fml::WeakPtr image_decoder, std::string advisory_script_uri, std::string advisory_script_entrypoint, std::function idle_notification_callback, @@ -131,6 +132,7 @@ class RuntimeController final : public WindowClient { fml::RefPtr shared_snapshot_; TaskRunners task_runners_; fml::WeakPtr io_manager_; + fml::RefPtr unref_queue_; fml::WeakPtr image_decoder_; std::string advisory_script_uri_; std::string advisory_script_entrypoint_; @@ -149,6 +151,7 @@ class RuntimeController final : public WindowClient { fml::RefPtr shared_snapshot, TaskRunners task_runners, fml::WeakPtr io_manager, + fml::RefPtr unref_queue, fml::WeakPtr image_decoder, std::string advisory_script_uri, std::string advisory_script_entrypoint, diff --git a/shell/common/engine.cc b/shell/common/engine.cc index fd424a369eeb08a1f7765e0499fa5e59d84e0d61..7345ac2055da893228fcb05082399a2e0ab2ff23 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -43,7 +43,8 @@ Engine::Engine(Delegate& delegate, TaskRunners task_runners, Settings settings, std::unique_ptr animator, - fml::WeakPtr io_manager) + fml::WeakPtr io_manager, + fml::RefPtr unref_queue) : delegate_(delegate), settings_(std::move(settings)), animator_(std::move(animator)), @@ -64,6 +65,7 @@ Engine::Engine(Delegate& delegate, std::move(shared_snapshot), // shared snapshot task_runners_, // task runners std::move(io_manager), // io manager + std::move(unref_queue), // Skia unref queue image_decoder_.GetWeakPtr(), // image decoder settings_.advisory_script_uri, // advisory script uri settings_.advisory_script_entrypoint, // advisory script entrypoint diff --git a/shell/common/engine.h b/shell/common/engine.h index 2e4fd41964bb2ff52a351409fdaedcd56c4ba466..cc9d1bcf68761467bfb581318fa27a99036172a2 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -280,7 +280,8 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { TaskRunners task_runners, Settings settings, std::unique_ptr animator, - fml::WeakPtr io_manager); + fml::WeakPtr io_manager, + fml::RefPtr unref_queue); //---------------------------------------------------------------------------- /// @brief Destroys the engine engine. Called by the shell on the UI task diff --git a/shell/common/shell.cc b/shell/common/shell.cc index bf185a6b366174207e816fb484eceaf82d93fe2c..27afb2da7dd7bade7817e07bde7ab515b32b7cd0 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -89,6 +89,8 @@ std::unique_ptr Shell::CreateShellOnPlatformThread( auto io_manager_future = io_manager_promise.get_future(); std::promise> weak_io_manager_promise; auto weak_io_manager_future = weak_io_manager_promise.get_future(); + std::promise> unref_queue_promise; + auto unref_queue_future = unref_queue_promise.get_future(); auto io_task_runner = shell->GetTaskRunners().GetIOTaskRunner(); // TODO(gw280): The WeakPtr here asserts that we are derefing it on the @@ -101,6 +103,7 @@ std::unique_ptr Shell::CreateShellOnPlatformThread( io_task_runner, [&io_manager_promise, // &weak_io_manager_promise, // + &unref_queue_promise, // platform_view = platform_view->GetWeakPtr(), // io_task_runner // ]() { @@ -108,6 +111,7 @@ std::unique_ptr Shell::CreateShellOnPlatformThread( auto io_manager = std::make_unique( platform_view.getUnsafe()->CreateResourceContext(), io_task_runner); weak_io_manager_promise.set_value(io_manager->GetWeakPtr()); + unref_queue_promise.set_value(io_manager->GetSkiaUnrefQueue()); io_manager_promise.set_value(std::move(io_manager)); }); @@ -126,7 +130,8 @@ std::unique_ptr Shell::CreateShellOnPlatformThread( isolate_snapshot = std::move(isolate_snapshot), // shared_snapshot = std::move(shared_snapshot), // vsync_waiter = std::move(vsync_waiter), // - &weak_io_manager_future // + &weak_io_manager_future, // + &unref_queue_future // ]() mutable { TRACE_EVENT0("flutter", "ShellSetupUISubsystem"); const auto& task_runners = shell->GetTaskRunners(); @@ -137,15 +142,16 @@ std::unique_ptr Shell::CreateShellOnPlatformThread( std::move(vsync_waiter)); engine_promise.set_value(std::make_unique( - *shell, // - dispatcher_maker, // - *shell->GetDartVM(), // - std::move(isolate_snapshot), // - std::move(shared_snapshot), // - task_runners, // - shell->GetSettings(), // - std::move(animator), // - weak_io_manager_future.get() // + *shell, // + dispatcher_maker, // + *shell->GetDartVM(), // + std::move(isolate_snapshot), // + std::move(shared_snapshot), // + task_runners, // + shell->GetSettings(), // + std::move(animator), // + weak_io_manager_future.get(), // + unref_queue_future.get() // )); }));