Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ FILE: ../../../flutter/shell/common/canvas_spy.h
FILE: ../../../flutter/shell/common/canvas_spy_unittests.cc
FILE: ../../../flutter/shell/common/engine.cc
FILE: ../../../flutter/shell/common/engine.h
FILE: ../../../flutter/shell/common/engine_unittests.cc
FILE: ../../../flutter/shell/common/fixtures/shell_test.dart
FILE: ../../../flutter/shell/common/fixtures/shelltest_screenshot.png
FILE: ../../../flutter/shell/common/input_events_unittests.cc
Expand Down
4 changes: 4 additions & 0 deletions runtime/runtime_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

namespace flutter {

RuntimeController::RuntimeController(RuntimeDelegate& client,
TaskRunners p_task_runners)
: client_(client), vm_(nullptr), task_runners_(p_task_runners) {}

RuntimeController::RuntimeController(
RuntimeDelegate& p_client,
DartVM* p_vm,
Expand Down
10 changes: 7 additions & 3 deletions runtime/runtime_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Window;
/// used by the engine to copy the currently accumulated window state so it can
/// be referenced by the new runtime controller.
///
class RuntimeController final : public PlatformConfigurationClient {
class RuntimeController : public PlatformConfigurationClient {
public:
//----------------------------------------------------------------------------
/// @brief Creates a new instance of a runtime controller. This is
Expand Down Expand Up @@ -340,7 +340,7 @@ class RuntimeController final : public PlatformConfigurationClient {
///
/// @return True if root isolate running, False otherwise.
///
bool IsRootIsolateRunning() const;
virtual bool IsRootIsolateRunning() const;

//----------------------------------------------------------------------------
/// @brief Dispatch the specified platform message to running root
Expand All @@ -351,7 +351,7 @@ class RuntimeController final : public PlatformConfigurationClient {
/// @return If the message was dispatched to the running root isolate.
/// This may fail is an isolate is not running.
///
bool DispatchPlatformMessage(fml::RefPtr<PlatformMessage> message);
virtual bool DispatchPlatformMessage(fml::RefPtr<PlatformMessage> message);

//----------------------------------------------------------------------------
/// @brief Dispatch the specified pointer data message to the running
Expand Down Expand Up @@ -440,6 +440,10 @@ class RuntimeController final : public PlatformConfigurationClient {
///
std::pair<bool, uint32_t> GetRootIsolateReturnCode();

protected:
/// Constructor for Mocks.
RuntimeController(RuntimeDelegate& client, TaskRunners p_task_runners);

private:
struct Locale {
Locale(std::string language_code_,
Expand Down
2 changes: 2 additions & 0 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ if (enable_unittests) {
sources = [
"animator_unittests.cc",
"canvas_spy_unittests.cc",
"engine_unittests.cc",
"input_events_unittests.cc",
"persistent_cache_unittests.cc",
"pipeline_unittests.cc",
Expand All @@ -268,6 +269,7 @@ if (enable_unittests) {
deps = [
"//flutter/assets",
"//flutter/shell/version",
"//third_party/googletest:gmock",
]

public_deps_legacy_and_next = [ ":shell_test_fixture_sources" ]
Expand Down
44 changes: 29 additions & 15 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ static constexpr char kLocalizationChannel[] = "flutter/localization";
static constexpr char kSettingsChannel[] = "flutter/settings";
static constexpr char kIsolateChannel[] = "flutter/isolate";

Engine::Engine(
Delegate& delegate,
const PointerDataDispatcherMaker& dispatcher_maker,
std::shared_ptr<fml::ConcurrentTaskRunner> image_decoder_task_runner,
TaskRunners task_runners,
Settings settings,
std::unique_ptr<Animator> animator,
fml::WeakPtr<IOManager> io_manager,
std::unique_ptr<RuntimeController> runtime_controller)
: delegate_(delegate),
settings_(std::move(settings)),
animator_(std::move(animator)),
runtime_controller_(std::move(runtime_controller)),
activity_running_(true),
have_surface_(false),
image_decoder_(task_runners, image_decoder_task_runner, io_manager),
task_runners_(std::move(task_runners)),
weak_factory_(this) {
pointer_data_dispatcher_ = dispatcher_maker(*this);
}

Engine::Engine(Delegate& delegate,
const PointerDataDispatcherMaker& dispatcher_maker,
DartVM& vm,
Expand All @@ -46,19 +67,14 @@ Engine::Engine(Delegate& delegate,
fml::WeakPtr<IOManager> io_manager,
fml::RefPtr<SkiaUnrefQueue> unref_queue,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate)
: delegate_(delegate),
settings_(std::move(settings)),
animator_(std::move(animator)),
activity_running_(true),
have_surface_(false),
image_decoder_(task_runners,
vm.GetConcurrentWorkerTaskRunner(),
io_manager),
task_runners_(std::move(task_runners)),
weak_factory_(this) {
// Runtime controller is initialized here because it takes a reference to this
// object as its delegate. The delegate may be called in the constructor and
// we want to be fully initilazed by that point.
: Engine(delegate,
dispatcher_maker,
vm.GetConcurrentWorkerTaskRunner(),
task_runners,
settings,
std::move(animator),
io_manager,
nullptr) {
runtime_controller_ = std::make_unique<RuntimeController>(
*this, // runtime delegate
&vm, // VM
Expand All @@ -76,8 +92,6 @@ Engine::Engine(Delegate& delegate,
settings_.isolate_shutdown_callback, // isolate shutdown callback
settings_.persistent_isolate_data // persistent isolate data
);

pointer_data_dispatcher_ = dispatcher_maker(*this);
}

Engine::~Engine() = default;
Expand Down
20 changes: 20 additions & 0 deletions shell/common/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,20 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
const std::vector<std::string>& supported_locale_data) = 0;
};

//----------------------------------------------------------------------------
/// @brief Creates an instance of the engine with a supplied
/// `RuntimeController`. Use the other constructor except for
/// tests.
///
Engine(Delegate& delegate,
const PointerDataDispatcherMaker& dispatcher_maker,
std::shared_ptr<fml::ConcurrentTaskRunner> image_decoder_task_runner,
TaskRunners task_runners,
Settings settings,
std::unique_ptr<Animator> animator,
fml::WeakPtr<IOManager> io_manager,
std::unique_ptr<RuntimeController> runtime_controller);

//----------------------------------------------------------------------------
/// @brief Creates an instance of the engine. This is done by the Shell
/// on the UI task runner.
Expand Down Expand Up @@ -756,6 +770,12 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
///
const std::string& GetLastEntrypointLibrary() const;

//----------------------------------------------------------------------------
/// @brief Getter for the initial route. This can be set with a platform
/// message.
///
const std::string& InitialRoute() const { return initial_route_; }

private:
Engine::Delegate& delegate_;
const Settings settings_;
Expand Down
Loading