Skip to content

Commit

Permalink
Allow explicit specification of the isolate snapshot. (flutter#5193)
Browse files Browse the repository at this point in the history
The mobile shells all use the same isolate snapshot. This is also the snapshot used by the service isolate. This works towards a world where the isolate snapshot is no longer a member variable of the DartVM instance. Instead, all snapshots must be specified in the run configuration. For now, the new `Shell::Create` overload will only be used by Fuchsia till I refactor `dart_vm.cc`.

There are no API updates to the mobile shells.
  • Loading branch information
chinmaygarde authored May 8, 2018
1 parent 20b286d commit d97b6d8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
7 changes: 6 additions & 1 deletion runtime/runtime_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ namespace blink {
RuntimeController::RuntimeController(
RuntimeDelegate& p_client,
const DartVM* p_vm,
fxl::RefPtr<DartSnapshot> p_isolate_snapshot,
TaskRunners p_task_runners,
fml::WeakPtr<GrContext> p_resource_context,
fxl::RefPtr<flow::SkiaUnrefQueue> p_unref_queue)
: RuntimeController(p_client,
p_vm,
std::move(p_isolate_snapshot),
std::move(p_task_runners),
std::move(p_resource_context),
std::move(p_unref_queue),
Expand All @@ -34,19 +36,21 @@ RuntimeController::RuntimeController(
RuntimeController::RuntimeController(
RuntimeDelegate& p_client,
const DartVM* p_vm,
fxl::RefPtr<DartSnapshot> p_isolate_snapshot,
TaskRunners p_task_runners,
fml::WeakPtr<GrContext> p_resource_context,
fxl::RefPtr<flow::SkiaUnrefQueue> p_unref_queue,
WindowData p_window_data)
: client_(p_client),
vm_(p_vm),
isolate_snapshot_(std::move(p_isolate_snapshot)),
task_runners_(p_task_runners),
resource_context_(p_resource_context),
unref_queue_(p_unref_queue),
window_data_(std::move(p_window_data)),
root_isolate_(
DartIsolate::CreateRootIsolate(vm_,
vm_->GetIsolateSnapshot(),
isolate_snapshot_,
task_runners_,
std::make_unique<Window>(this),
resource_context_,
Expand Down Expand Up @@ -89,6 +93,7 @@ std::unique_ptr<RuntimeController> RuntimeController::Clone() const {
return std::unique_ptr<RuntimeController>(new RuntimeController(
client_, //
vm_, //
isolate_snapshot_, //
task_runners_, //
resource_context_, //
unref_queue_, //
Expand Down
3 changes: 3 additions & 0 deletions runtime/runtime_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class RuntimeController final : public WindowClient {
public:
RuntimeController(RuntimeDelegate& client,
const DartVM* vm,
fxl::RefPtr<DartSnapshot> isolate_snapshot,
TaskRunners task_runners,
fml::WeakPtr<GrContext> resource_context,
fxl::RefPtr<flow::SkiaUnrefQueue> unref_queue);
Expand Down Expand Up @@ -79,6 +80,7 @@ class RuntimeController final : public WindowClient {

RuntimeDelegate& client_;
const DartVM* vm_;
fxl::RefPtr<DartSnapshot> isolate_snapshot_;
TaskRunners task_runners_;
fml::WeakPtr<GrContext> resource_context_;
fxl::RefPtr<flow::SkiaUnrefQueue> unref_queue_;
Expand All @@ -88,6 +90,7 @@ class RuntimeController final : public WindowClient {

RuntimeController(RuntimeDelegate& client,
const DartVM* vm,
fxl::RefPtr<DartSnapshot> isolate_snapshot,
TaskRunners task_runners,
fml::WeakPtr<GrContext> resource_context,
fxl::RefPtr<flow::SkiaUnrefQueue> unref_queue,
Expand Down
2 changes: 2 additions & 0 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static constexpr char kSettingsChannel[] = "flutter/settings";

Engine::Engine(Delegate& delegate,
const blink::DartVM& vm,
fxl::RefPtr<blink::DartSnapshot> isolate_snapshot,
blink::TaskRunners task_runners,
blink::Settings settings,
std::unique_ptr<Animator> animator,
Expand Down Expand Up @@ -69,6 +70,7 @@ Engine::Engine(Delegate& delegate,
runtime_controller_ = std::make_unique<blink::RuntimeController>(
*this, // runtime delegate
&vm, // VM
std::move(isolate_snapshot), // isolate snapshot
std::move(task_runners), // task runners
std::move(resource_context), // resource context
std::move(unref_queue) // skia unref queue
Expand Down
1 change: 1 addition & 0 deletions shell/common/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Engine final : public blink::RuntimeDelegate {

Engine(Delegate& delegate,
const blink::DartVM& vm,
fxl::RefPtr<blink::DartSnapshot> isolate_snapshot,
blink::TaskRunners task_runners,
blink::Settings settings,
std::unique_ptr<Animator> animator,
Expand Down
38 changes: 33 additions & 5 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace shell {
std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
blink::TaskRunners task_runners,
blink::Settings settings,
fxl::RefPtr<blink::DartSnapshot> isolate_snapshot,
Shell::CreateCallback<PlatformView> on_create_platform_view,
Shell::CreateCallback<Rasterizer> on_create_rasterizer) {
if (!task_runners.IsValid()) {
Expand Down Expand Up @@ -108,6 +109,7 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
fxl::MakeCopyable([&ui_latch, //
&engine, //
shell = shell.get(), //
isolate_snapshot = std::move(isolate_snapshot), //
vsync_waiter = std::move(vsync_waiter), //
resource_context = std::move(resource_context), //
unref_queue = std::move(unref_queue) //
Expand All @@ -121,6 +123,7 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(

engine = std::make_unique<Engine>(*shell, //
shell->GetDartVM(), //
std::move(isolate_snapshot), //
task_runners, //
shell->GetSettings(), //
std::move(animator), //
Expand Down Expand Up @@ -157,6 +160,22 @@ std::unique_ptr<Shell> Shell::Create(
blink::Settings settings,
Shell::CreateCallback<PlatformView> on_create_platform_view,
Shell::CreateCallback<Rasterizer> on_create_rasterizer) {
auto vm = blink::DartVM::ForProcess(settings);
FXL_CHECK(vm) << "Must be able to initialize the VM.";
return Shell::Create(std::move(task_runners), //
std::move(settings), //
vm->GetIsolateSnapshot(), //
std::move(on_create_platform_view), //
std::move(on_create_rasterizer) //
);
}

std::unique_ptr<Shell> Shell::Create(
blink::TaskRunners task_runners,
blink::Settings settings,
fxl::RefPtr<blink::DartSnapshot> isolate_snapshot,
Shell::CreateCallback<PlatformView> on_create_platform_view,
Shell::CreateCallback<Rasterizer> on_create_rasterizer) {
RecordStartupTimestamp();

fxl::LogSettings log_settings;
Expand All @@ -173,11 +192,20 @@ std::unique_ptr<Shell> Shell::Create(
std::unique_ptr<Shell> shell;
fml::TaskRunner::RunNowOrPostTask(
task_runners.GetPlatformTaskRunner(),
[&latch, &shell, task_runners = std::move(task_runners), settings,
on_create_platform_view, on_create_rasterizer]() {
shell = CreateShellOnPlatformThread(std::move(task_runners), settings,
on_create_platform_view,
on_create_rasterizer);
[&latch, //
&shell, //
task_runners = std::move(task_runners), //
settings, //
isolate_snapshot = std::move(isolate_snapshot), //
on_create_platform_view, //
on_create_rasterizer //
]() {
shell = CreateShellOnPlatformThread(std::move(task_runners), //
settings, //
std::move(isolate_snapshot), //
on_create_platform_view, //
on_create_rasterizer //
);
latch.Signal();
});
latch.Wait();
Expand Down
13 changes: 13 additions & 0 deletions shell/common/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,21 @@ class Shell final : public PlatformView::Delegate,
public:
template <class T>
using CreateCallback = std::function<std::unique_ptr<T>(Shell&)>;

// Create a shell with the given task runners and settings. The isolate
// snapshot will be shared with the snapshot of the service isolate.
static std::unique_ptr<Shell> Create(
blink::TaskRunners task_runners,
blink::Settings settings,
CreateCallback<PlatformView> on_create_platform_view,
CreateCallback<Rasterizer> on_create_rasterizer);

// Creates a shell with the given task runners and settings. The isolate
// snapshot is specified upfront.
static std::unique_ptr<Shell> Create(
blink::TaskRunners task_runners,
blink::Settings settings,
fxl::RefPtr<blink::DartSnapshot> isolate_snapshot,
CreateCallback<PlatformView> on_create_platform_view,
CreateCallback<Rasterizer> on_create_rasterizer);

Expand Down Expand Up @@ -92,6 +104,7 @@ class Shell final : public PlatformView::Delegate,
static std::unique_ptr<Shell> CreateShellOnPlatformThread(
blink::TaskRunners task_runners,
blink::Settings settings,
fxl::RefPtr<blink::DartSnapshot> isolate_snapshot,
Shell::CreateCallback<PlatformView> on_create_platform_view,
Shell::CreateCallback<Rasterizer> on_create_rasterizer);

Expand Down

0 comments on commit d97b6d8

Please sign in to comment.