Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7fa36ce

Browse files
committed
Pass as mapping
1 parent df5c029 commit 7fa36ce

18 files changed

+182
-55
lines changed

runtime/dart_isolate.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,14 @@ fml::RefPtr<fml::TaskRunner> DartIsolate::GetMessageHandlingTaskRunner() const {
334334
return message_handling_task_runner_;
335335
}
336336

337-
bool DartIsolate::LoadLoadingUnit(intptr_t loading_unit_id,
338-
const uint8_t* snapshot_data,
339-
const uint8_t* snapshot_instructions) {
337+
bool DartIsolate::LoadLoadingUnit(
338+
intptr_t loading_unit_id,
339+
std::unique_ptr<fml::Mapping> snapshot_data,
340+
std::unique_ptr<fml::Mapping> snapshot_instructions) {
340341
tonic::DartState::Scope scope(this);
341-
Dart_Handle result = Dart_DeferredLoadComplete(loading_unit_id, snapshot_data,
342-
snapshot_instructions);
342+
Dart_Handle result =
343+
Dart_DeferredLoadComplete(loading_unit_id, snapshot_data->GetMapping(),
344+
snapshot_instructions->GetMapping());
343345
if (tonic::LogIfError(result)) {
344346
result =
345347
Dart_DeferredLoadCompleteError(loading_unit_id, Dart_GetError(result),

runtime/dart_isolate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ class DartIsolate : public UIDartState {
385385
fml::RefPtr<fml::TaskRunner> GetMessageHandlingTaskRunner() const;
386386

387387
bool LoadLoadingUnit(intptr_t loading_unit_id,
388-
const uint8_t* snapshot_data,
389-
const uint8_t* snapshot_instructions);
388+
std::unique_ptr<fml::Mapping> snapshot_data,
389+
std::unique_ptr<fml::Mapping> snapshot_instructions);
390390

391391
void LoadLoadingUnitFailure(intptr_t loading_unit_id,
392392
const std::string error_message,

runtime/dart_isolate_unittests.cc

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111
#include "flutter/runtime/dart_vm.h"
1212
#include "flutter/runtime/dart_vm_lifecycle.h"
1313
#include "flutter/runtime/isolate_configuration.h"
14+
// #include "flutter/runtime/runtime_controller.h"
1415
#include "flutter/testing/dart_isolate_runner.h"
1516
#include "flutter/testing/fixture_test.h"
1617
#include "flutter/testing/testing.h"
1718
#include "third_party/tonic/converter/dart_converter.h"
1819
#include "third_party/tonic/scopes/dart_isolate_scope.h"
1920

21+
// #include "flutter/lib/ui/window/platform_configuration.h"
22+
#include "gmock/gmock.h"
23+
2024
namespace flutter {
2125
namespace testing {
2226

@@ -34,6 +38,114 @@ class DartIsolateTest : public FixtureTest {
3438
FML_DISALLOW_COPY_AND_ASSIGN(DartIsolateTest);
3539
};
3640

41+
// class MockPlatformConfigurationClient : public PlatformConfigurationClient {
42+
// public:
43+
// // virtual std::string DefaultRouteName();
44+
// // virtual void ScheduleFrame();
45+
// // virtual void Render(Scene* scene);
46+
// // virtual void UpdateSemantics(SemanticsUpdate* update);
47+
// // virtual void HandlePlatformMessage(fml::RefPtr<PlatformMessage>
48+
// message);
49+
// // virtual FontCollection& GetFontCollection();
50+
// // virtual void UpdateIsolateDescription(const std::string isolate_name,
51+
// // int64_t isolate_port); virtual void SetNeedsReportTimings(bool value);
52+
// // virtual std::shared_ptr<const fml::Mapping> GetPersistentIsolateData();
53+
// // virtual std::unique_ptr<std::vector<std::string>>
54+
// // ComputePlatformResolvedLocale(const std::vector<std::string>&
55+
// // supported_locale_data); virtual void RequestDartDeferredLibrary(intptr_t
56+
// // loading_unit_id);
57+
// MOCK_METHOD0(DefaultRouteName, std::string());
58+
// MOCK_METHOD1(ScheduleFrame, void(bool));
59+
// MOCK_METHOD1(Render, void(std::unique_ptr<flutter::LayerTree>));
60+
// MOCK_METHOD2(UpdateSemantics,
61+
// void(SemanticsNodeUpdates, CustomAccessibilityActionUpdates));
62+
// MOCK_METHOD1(HandlePlatformMessage, void(fml::RefPtr<PlatformMessage>));
63+
// MOCK_METHOD0(GetFontCollection, FontCollection&());
64+
// MOCK_METHOD0(OnRootIsolateCreated, void());
65+
// MOCK_METHOD2(UpdateIsolateDescription, void(const std::string, int64_t));
66+
// MOCK_METHOD1(SetNeedsReportTimings, void(bool));
67+
// MOCK_METHOD1(ComputePlatformResolvedLocale,
68+
// std::unique_ptr<std::vector<std::string>>(
69+
// const std::vector<std::string>&));
70+
// MOCK_METHOD1(RequestDartDeferredLibrary, void(intptr_t));
71+
// }
72+
73+
// class MockRuntimeDelegate : public RuntimeDelegate {
74+
// public:
75+
// MOCK_METHOD0(DefaultRouteName, std::string());
76+
// MOCK_METHOD1(ScheduleFrame, void(bool));
77+
// MOCK_METHOD1(Render, void(std::unique_ptr<flutter::LayerTree>));
78+
// MOCK_METHOD2(UpdateSemantics,
79+
// void(SemanticsNodeUpdates, CustomAccessibilityActionUpdates));
80+
// MOCK_METHOD1(HandlePlatformMessage, void(fml::RefPtr<PlatformMessage>));
81+
// MOCK_METHOD0(GetFontCollection, FontCollection&());
82+
// MOCK_METHOD0(OnRootIsolateCreated, void());
83+
// MOCK_METHOD2(UpdateIsolateDescription, void(const std::string, int64_t));
84+
// MOCK_METHOD1(SetNeedsReportTimings, void(bool));
85+
// MOCK_METHOD1(ComputePlatformResolvedLocale,
86+
// std::unique_ptr<std::vector<std::string>>(
87+
// const std::vector<std::string>&));
88+
// MOCK_METHOD1(RequestDartDeferredLibrary, void(intptr_t));
89+
// };
90+
91+
// // class MockRuntimeController : public RuntimeController {
92+
// // public:
93+
// // MockRuntimeController(RuntimeDelegate& client, TaskRunners
94+
// p_task_runners)
95+
// // : RuntimeController(client, p_task_runners) {}
96+
// // MOCK_METHOD0(IsRootIsolateRunning, bool());
97+
// // MOCK_METHOD1(DispatchPlatformMessage,
98+
// bool(fml::RefPtr<PlatformMessage>));
99+
// // };
100+
101+
// TEST_F(DartIsolateTest, DartDeferredLoadPassesValue) {
102+
// ASSERT_FALSE(DartVMRef::IsInstanceRunning());
103+
// auto settings = CreateSettingsForFixture();
104+
// auto vm_ref = DartVMRef::Create(settings);
105+
// ASSERT_TRUE(vm_ref);
106+
// auto vm_data = vm_ref.GetVMData();
107+
// ASSERT_TRUE(vm_data);
108+
// TaskRunners task_runners(GetCurrentTestName(), //
109+
// GetCurrentTaskRunner(), //
110+
// GetCurrentTaskRunner(), //
111+
// GetCurrentTaskRunner(), //
112+
// GetCurrentTaskRunner() //
113+
// );
114+
// auto isolate_configuration =
115+
// IsolateConfiguration::InferFromSettings(settings);
116+
// std::unique_ptr<MockPlatformConfigurationClient> client =
117+
// std::make_unique<MockPlatformConfigurationClient>();
118+
// auto weak_isolate = DartIsolate::CreateRunningRootIsolate(
119+
// vm_data->GetSettings(), // settings
120+
// vm_data->GetIsolateSnapshot(), // isolate snapshot
121+
// std::move(task_runners), // task runners
122+
// std::move(client), // window
123+
// {}, // snapshot delegate
124+
// {}, // hint freed delegate
125+
// {}, // io manager
126+
// {}, // unref queue
127+
// {}, // image decoder
128+
// "main.dart", // advisory uri
129+
// "main", // advisory entrypoint
130+
// DartIsolate::Flags{}, // flags
131+
// settings.isolate_create_callback, // isolate create callback
132+
// settings.isolate_shutdown_callback, // isolate shutdown callback
133+
// "main", // dart entrypoint
134+
// std::nullopt, // dart entrypoint library
135+
// std::move(isolate_configuration) // isolate configuration
136+
// );
137+
// auto root_isolate = weak_isolate.lock();
138+
// ASSERT_TRUE(root_isolate);
139+
// ASSERT_EQ(root_isolate->GetPhase(), DartIsolate::Phase::Running);
140+
// size_t destruction_callback_count = 0;
141+
// root_isolate->AddIsolateShutdownCallback([&destruction_callback_count]() {
142+
// ASSERT_NE(Dart_CurrentIsolate(), nullptr);
143+
// destruction_callback_count++;
144+
// });
145+
// ASSERT_TRUE(root_isolate->Shutdown());
146+
// ASSERT_EQ(destruction_callback_count, 1u);
147+
// }
148+
37149
TEST_F(DartIsolateTest, RootIsolateCreationAndShutdown) {
38150
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
39151
auto settings = CreateSettingsForFixture();

runtime/runtime_controller.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,11 @@ std::optional<uint32_t> RuntimeController::GetRootIsolateReturnCode() {
419419

420420
void RuntimeController::LoadDartDeferredLibrary(
421421
intptr_t loading_unit_id,
422-
const uint8_t* snapshot_data,
423-
const uint8_t* snapshot_instructions) {
424-
root_isolate_.lock()->LoadLoadingUnit(loading_unit_id, snapshot_data,
425-
snapshot_instructions);
422+
std::unique_ptr<fml::Mapping> snapshot_data,
423+
std::unique_ptr<fml::Mapping> snapshot_instructions) {
424+
root_isolate_.lock()->LoadLoadingUnit(loading_unit_id,
425+
std::move(snapshot_data),
426+
std::move(snapshot_instructions));
426427
}
427428

428429
void RuntimeController::RequestDartDeferredLibrary(intptr_t loading_unit_id) {

runtime/runtime_controller.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "flutter/common/task_runners.h"
1212
#include "flutter/flow/layers/layer_tree.h"
1313
#include "flutter/fml/macros.h"
14+
#include "flutter/fml/mapping.h"
1415
#include "flutter/lib/ui/io_manager.h"
1516
#include "flutter/lib/ui/text/font_collection.h"
1617
#include "flutter/lib/ui/ui_dart_state.h"
@@ -501,9 +502,10 @@ class RuntimeController : public PlatformConfigurationClient {
501502
/// @param[in] snapshot_data Dart snapshot instructions of the loading
502503
/// unit's shared library.
503504
///
504-
void LoadDartDeferredLibrary(intptr_t loading_unit_id,
505-
const uint8_t* snapshot_data,
506-
const uint8_t* snapshot_instructions);
505+
void LoadDartDeferredLibrary(
506+
intptr_t loading_unit_id,
507+
std::unique_ptr<fml::Mapping> snapshot_data,
508+
std::unique_ptr<fml::Mapping> snapshot_instructions);
507509

508510
// |PlatformConfigurationClient|
509511
//--------------------------------------------------------------------------

shell/common/engine.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,12 +512,14 @@ void Engine::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
512512
return delegate_.RequestDartDeferredLibrary(loading_unit_id);
513513
}
514514

515-
void Engine::LoadDartDeferredLibrary(intptr_t loading_unit_id,
516-
const uint8_t* snapshot_data,
517-
const uint8_t* snapshot_instructions) {
515+
void Engine::LoadDartDeferredLibrary(
516+
intptr_t loading_unit_id,
517+
std::unique_ptr<fml::Mapping> snapshot_data,
518+
std::unique_ptr<fml::Mapping> snapshot_instructions) {
518519
if (runtime_controller_->IsRootIsolateRunning()) {
519-
runtime_controller_->LoadDartDeferredLibrary(loading_unit_id, snapshot_data,
520-
snapshot_instructions);
520+
runtime_controller_->LoadDartDeferredLibrary(
521+
loading_unit_id, std::move(snapshot_data),
522+
std::move(snapshot_instructions));
521523
}
522524
}
523525

shell/common/engine.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "flutter/assets/asset_manager.h"
1212
#include "flutter/common/task_runners.h"
1313
#include "flutter/fml/macros.h"
14+
#include "flutter/fml/mapping.h"
1415
#include "flutter/fml/memory/weak_ptr.h"
1516
#include "flutter/lib/ui/hint_freed_delegate.h"
1617
#include "flutter/lib/ui/painting/image_decoder.h"
@@ -810,9 +811,10 @@ class Engine final : public RuntimeDelegate,
810811
/// @param[in] snapshot_data Dart snapshot instructions of the loading
811812
/// unit's shared library.
812813
///
813-
void LoadDartDeferredLibrary(intptr_t loading_unit_id,
814-
const uint8_t* snapshot_data,
815-
const uint8_t* snapshot_instructions);
814+
void LoadDartDeferredLibrary(
815+
intptr_t loading_unit_id,
816+
std::unique_ptr<fml::Mapping> snapshot_data,
817+
std::unique_ptr<fml::Mapping> snapshot_instructions);
816818

817819
private:
818820
Engine::Delegate& delegate_;

shell/common/platform_view.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ void PlatformView::RequestDartDeferredLibrary(intptr_t loading_unit_id) {}
163163

164164
void PlatformView::LoadDartDeferredLibrary(
165165
intptr_t loading_unit_id,
166-
const uint8_t* snapshot_data,
167-
const uint8_t* snapshot_instructions) {}
166+
std::unique_ptr<fml::Mapping> snapshot_data,
167+
std::unique_ptr<fml::Mapping> snapshot_instructions) {}
168168

169169
void PlatformView::UpdateAssetManager(
170170
std::shared_ptr<AssetManager> asset_manager) {}

shell/common/platform_view.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "flutter/common/task_runners.h"
1313
#include "flutter/flow/surface.h"
1414
#include "flutter/fml/macros.h"
15+
#include "flutter/fml/mapping.h"
1516
#include "flutter/fml/memory/weak_ptr.h"
1617
#include "flutter/lib/ui/semantics/custom_accessibility_action.h"
1718
#include "flutter/lib/ui/semantics/semantics_node.h"
@@ -235,8 +236,8 @@ class PlatformView {
235236
///
236237
virtual void LoadDartDeferredLibrary(
237238
intptr_t loading_unit_id,
238-
const uint8_t* snapshot_data,
239-
const uint8_t* snapshot_instructions) = 0;
239+
std::unique_ptr<fml::Mapping> snapshot_data,
240+
std::unique_ptr<fml::Mapping> snapshot_instructions) = 0;
240241

241242
// TODO(garyq): Implement a proper asset_resolver replacement instead of
242243
// overwriting the entire asset manager.
@@ -645,9 +646,10 @@ class PlatformView {
645646
/// @param[in] snapshot_data Dart snapshot instructions of the loading
646647
/// unit's shared library.
647648
///
648-
virtual void LoadDartDeferredLibrary(intptr_t loading_unit_id,
649-
const uint8_t* snapshot_data,
650-
const uint8_t* snapshot_instructions);
649+
virtual void LoadDartDeferredLibrary(
650+
intptr_t loading_unit_id,
651+
std::unique_ptr<fml::Mapping> snapshot_data,
652+
std::unique_ptr<fml::Mapping> snapshot_instructions);
651653

652654
// TODO(garyq): Implement a proper asset_resolver replacement instead of
653655
// overwriting the entire asset manager.

shell/common/shell.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,11 +1185,12 @@ std::unique_ptr<std::vector<std::string>> Shell::ComputePlatformResolvedLocale(
11851185
return platform_view_->ComputePlatformResolvedLocales(supported_locale_data);
11861186
}
11871187

1188-
void Shell::LoadDartDeferredLibrary(intptr_t loading_unit_id,
1189-
const uint8_t* snapshot_data,
1190-
const uint8_t* snapshot_instructions) {
1191-
engine_->LoadDartDeferredLibrary(loading_unit_id, snapshot_data,
1192-
snapshot_instructions);
1188+
void Shell::LoadDartDeferredLibrary(
1189+
intptr_t loading_unit_id,
1190+
std::unique_ptr<fml::Mapping> snapshot_data,
1191+
std::unique_ptr<fml::Mapping> snapshot_instructions) {
1192+
engine_->LoadDartDeferredLibrary(loading_unit_id, std::move(snapshot_data),
1193+
std::move(snapshot_instructions));
11931194
}
11941195

11951196
void Shell::UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) {

0 commit comments

Comments
 (0)