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
2 changes: 1 addition & 1 deletion runtime/runtime_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ class RuntimeController : public PlatformConfigurationClient {
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
const fml::WeakPtr<IOManager>& GetIOManager() const { return io_manager_; }

DartVM* GetDartVM() const { return vm_; }
virtual DartVM* GetDartVM() const { return vm_; }

const fml::RefPtr<const DartSnapshot>& GetIsolateSnapshot() const {
return isolate_snapshot_;
Expand Down
1 change: 1 addition & 0 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ if (enable_unittests) {
"//flutter/common/graphics",
"//flutter/shell/profiling:profiling_unittests",
"//flutter/shell/version",
"//flutter/testing:fixture_test",
"//third_party/googletest:gmock",
]

Expand Down
12 changes: 8 additions & 4 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ Engine::Engine(
Settings settings,
std::unique_ptr<Animator> animator,
fml::WeakPtr<IOManager> io_manager,
const std::shared_ptr<FontCollection>& font_collection,
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),
font_collection_(font_collection),
image_decoder_(task_runners, image_decoder_task_runner, io_manager),
task_runners_(std::move(task_runners)),
weak_factory_(this) {
Expand All @@ -75,6 +77,7 @@ Engine::Engine(Delegate& delegate,
settings,
std::move(animator),
io_manager,
std::make_shared<FontCollection>(),
nullptr) {
runtime_controller_ = std::make_unique<RuntimeController>(
*this, // runtime delegate
Expand Down Expand Up @@ -111,6 +114,7 @@ std::unique_ptr<Engine> Engine::Spawn(
/*settings=*/settings,
/*animator=*/std::move(animator),
/*io_manager=*/runtime_controller_->GetIOManager(),
/*font_collection=*/font_collection_,
/*runtime_controller=*/nullptr);
result->runtime_controller_ = runtime_controller_->Spawn(
*result, // runtime delegate
Expand All @@ -132,7 +136,7 @@ fml::WeakPtr<Engine> Engine::GetWeakPtr() const {

void Engine::SetupDefaultFontManager() {
TRACE_EVENT0("flutter", "Engine::SetupDefaultFontManager");
font_collection_.SetupDefaultFontManager();
font_collection_->SetupDefaultFontManager();
}

std::shared_ptr<AssetManager> Engine::GetAssetManager() {
Expand All @@ -152,10 +156,10 @@ bool Engine::UpdateAssetManager(
}

// Using libTXT as the text engine.
font_collection_.RegisterFonts(asset_manager_);
font_collection_->RegisterFonts(asset_manager_);

if (settings_.use_test_fonts) {
font_collection_.RegisterTestFonts();
font_collection_->RegisterTestFonts();
}

return true;
Expand Down Expand Up @@ -492,7 +496,7 @@ void Engine::SetNeedsReportTimings(bool needs_reporting) {
}

FontCollection& Engine::GetFontCollection() {
return font_collection_;
return *font_collection_;
}

void Engine::DoDispatchPacket(std::unique_ptr<PointerDataPacket> packet,
Expand Down
3 changes: 2 additions & 1 deletion shell/common/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ class Engine final : public RuntimeDelegate,
Settings settings,
std::unique_ptr<Animator> animator,
fml::WeakPtr<IOManager> io_manager,
const std::shared_ptr<FontCollection>& font_collection,
std::unique_ptr<RuntimeController> runtime_controller);

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -888,7 +889,7 @@ class Engine final : public RuntimeDelegate,
std::shared_ptr<AssetManager> asset_manager_;
bool activity_running_;
bool have_surface_;
FontCollection font_collection_;
std::shared_ptr<FontCollection> font_collection_;
ImageDecoder image_decoder_;
TaskRunners task_runners_;
size_t hint_freed_bytes_since_last_idle_ = 0;
Expand Down
36 changes: 35 additions & 1 deletion shell/common/engine_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "flutter/runtime/dart_vm_lifecycle.h"
#include "flutter/shell/common/thread_host.h"
#include "flutter/testing/fixture_test.h"
#include "flutter/testing/testing.h"
#include "gmock/gmock.h"
#include "rapidjson/document.h"
Expand Down Expand Up @@ -67,6 +68,7 @@ class MockRuntimeController : public RuntimeController {
MOCK_METHOD1(DispatchPlatformMessage, bool(fml::RefPtr<PlatformMessage>));
MOCK_METHOD3(LoadDartDeferredLibraryError,
void(intptr_t, const std::string, bool));
MOCK_CONST_METHOD0(GetDartVM, DartVM*());
};

fml::RefPtr<PlatformMessage> MakePlatformMessage(
Expand Down Expand Up @@ -95,7 +97,7 @@ fml::RefPtr<PlatformMessage> MakePlatformMessage(
return message;
}

class EngineTest : public ::testing::Test {
class EngineTest : public testing::FixtureTest {
public:
EngineTest()
: thread_host_("EngineTest",
Expand All @@ -120,6 +122,7 @@ class EngineTest : public ::testing::Test {

protected:
void SetUp() override {
settings_ = CreateSettingsForFixture();
dispatcher_maker_ = [](PointerDataDispatcher::Delegate&) {
return nullptr;
};
Expand Down Expand Up @@ -147,6 +150,7 @@ TEST_F(EngineTest, Create) {
/*settings=*/settings_,
/*animator=*/std::move(animator_),
/*io_manager=*/io_manager_,
/*font_collection=*/std::make_shared<FontCollection>(),
/*runtime_controller=*/std::move(runtime_controller_));
EXPECT_TRUE(engine);
});
Expand All @@ -167,6 +171,7 @@ TEST_F(EngineTest, DispatchPlatformMessageUnknown) {
/*settings=*/settings_,
/*animator=*/std::move(animator_),
/*io_manager=*/io_manager_,
/*font_collection=*/std::make_shared<FontCollection>(),
/*runtime_controller=*/std::move(mock_runtime_controller));

fml::RefPtr<PlatformMessageResponse> response =
Expand All @@ -192,6 +197,7 @@ TEST_F(EngineTest, DispatchPlatformMessageInitialRoute) {
/*settings=*/settings_,
/*animator=*/std::move(animator_),
/*io_manager=*/io_manager_,
/*font_collection=*/std::make_shared<FontCollection>(),
/*runtime_controller=*/std::move(mock_runtime_controller));

fml::RefPtr<PlatformMessageResponse> response =
Expand Down Expand Up @@ -224,6 +230,7 @@ TEST_F(EngineTest, DispatchPlatformMessageInitialRouteIgnored) {
/*settings=*/settings_,
/*animator=*/std::move(animator_),
/*io_manager=*/io_manager_,
/*font_collection=*/std::make_shared<FontCollection>(),
/*runtime_controller=*/std::move(mock_runtime_controller));

fml::RefPtr<PlatformMessageResponse> response =
Expand All @@ -239,6 +246,32 @@ TEST_F(EngineTest, DispatchPlatformMessageInitialRouteIgnored) {
});
}

TEST_F(EngineTest, SpawnSharesFontLibrary) {
PostUITaskSync([this] {
MockRuntimeDelegate client;
auto mock_runtime_controller =
std::make_unique<MockRuntimeController>(client, task_runners_);
auto vm_ref = DartVMRef::Create(settings_);
EXPECT_CALL(*mock_runtime_controller, GetDartVM())
.WillRepeatedly(::testing::Return(vm_ref.get()));
auto engine = std::make_unique<Engine>(
/*delegate=*/delegate_,
/*dispatcher_maker=*/dispatcher_maker_,
/*image_decoder_task_runner=*/image_decoder_task_runner_,
/*task_runners=*/task_runners_,
/*settings=*/settings_,
/*animator=*/std::move(animator_),
/*io_manager=*/io_manager_,
/*font_collection=*/std::make_shared<FontCollection>(),
/*runtime_controller=*/std::move(mock_runtime_controller));

auto spawn =
engine->Spawn(delegate_, dispatcher_maker_, settings_, nullptr);
EXPECT_TRUE(spawn != nullptr);
EXPECT_EQ(&engine->GetFontCollection(), &spawn->GetFontCollection());
});
}

TEST_F(EngineTest, PassesLoadDartDeferredLibraryErrorToRuntime) {
PostUITaskSync([this] {
intptr_t error_id = 123;
Expand All @@ -259,6 +292,7 @@ TEST_F(EngineTest, PassesLoadDartDeferredLibraryErrorToRuntime) {
/*settings=*/settings_,
/*animator=*/std::move(animator_),
/*io_manager=*/io_manager_,
/*font_collection=*/std::make_shared<FontCollection>(),
/*runtime_controller=*/std::move(mock_runtime_controller));

engine->LoadDartDeferredLibraryError(error_id, error_message, true);
Expand Down