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: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ FILE: ../../../flutter/runtime/runtime_test.cc
FILE: ../../../flutter/runtime/runtime_test.h
FILE: ../../../flutter/runtime/service_protocol.cc
FILE: ../../../flutter/runtime/service_protocol.h
FILE: ../../../flutter/runtime/skia_concurrent_executor.cc
FILE: ../../../flutter/runtime/skia_concurrent_executor.h
FILE: ../../../flutter/runtime/start_up.cc
FILE: ../../../flutter/runtime/start_up.h
FILE: ../../../flutter/runtime/test_font_data.cc
Expand Down
2 changes: 2 additions & 0 deletions runtime/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ source_set("runtime") {
"runtime_delegate.h",
"service_protocol.cc",
"service_protocol.h",
"skia_concurrent_executor.cc",
"skia_concurrent_executor.h",
"start_up.cc",
"start_up.h",
]
Expand Down
12 changes: 12 additions & 0 deletions runtime/dart_vm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "flutter/runtime/ptrace_ios.h"
#include "flutter/runtime/start_up.h"
#include "third_party/dart/runtime/include/bin/dart_io_api.h"
#include "third_party/skia/include/core/SkExecutor.h"
#include "third_party/tonic/converter/dart_converter.h"
#include "third_party/tonic/dart_class_library.h"
#include "third_party/tonic/dart_class_provider.h"
Expand Down Expand Up @@ -255,13 +256,20 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
std::shared_ptr<IsolateNameServer> isolate_name_server)
: settings_(vm_data->GetSettings()),
concurrent_message_loop_(fml::ConcurrentMessageLoop::Create()),
skia_concurrent_executor_(
[runner = concurrent_message_loop_->GetTaskRunner()](
fml::closure work) { runner->PostTask(work); }),
vm_data_(vm_data),
isolate_name_server_(std::move(isolate_name_server)),
service_protocol_(std::make_shared<ServiceProtocol>()) {
TRACE_EVENT0("flutter", "DartVMInitializer");

gVMLaunchCount++;

// Setting the executor is not thread safe but Dart VM initialization is. So
// this call is thread-safe.
SkExecutor::SetDefault(&skia_concurrent_executor_);

FML_DCHECK(vm_data_);
FML_DCHECK(isolate_name_server_);
FML_DCHECK(service_protocol_);
Expand Down Expand Up @@ -425,6 +433,10 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
}

DartVM::~DartVM() {
// Setting the executor is not thread safe but Dart VM shutdown is. So
// this call is thread-safe.
SkExecutor::SetDefault(nullptr);

if (Dart_CurrentIsolate() != nullptr) {
Dart_ExitIsolate();
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/dart_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "flutter/runtime/dart_snapshot.h"
#include "flutter/runtime/dart_vm_data.h"
#include "flutter/runtime/service_protocol.h"
#include "flutter/runtime/skia_concurrent_executor.h"
#include "third_party/dart/runtime/include/dart_api.h"

namespace flutter {
Expand All @@ -47,6 +48,7 @@ class DartVM {
private:
const Settings settings_;
std::shared_ptr<fml::ConcurrentMessageLoop> concurrent_message_loop_;
SkiaConcurrentExecutor skia_concurrent_executor_;
std::shared_ptr<const DartVMData> vm_data_;
const std::shared_ptr<IsolateNameServer> isolate_name_server_;
const std::shared_ptr<ServiceProtocol> service_protocol_;
Expand Down
26 changes: 26 additions & 0 deletions runtime/skia_concurrent_executor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/runtime/skia_concurrent_executor.h"

#include "flutter/fml/trace_event.h"

namespace flutter {

SkiaConcurrentExecutor::SkiaConcurrentExecutor(OnWorkCallback on_work)
: on_work_(on_work) {}

SkiaConcurrentExecutor::~SkiaConcurrentExecutor() = default;

void SkiaConcurrentExecutor::add(fml::closure work) {
if (!work) {
return;
}
on_work_([work]() {
TRACE_EVENT0("flutter", "SkiaExecutor");
work();
});
}

} // namespace flutter
31 changes: 31 additions & 0 deletions runtime/skia_concurrent_executor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_RUNTIME_SKIA_CONCURRENT_EXECUTOR_H_
#define FLUTTER_RUNTIME_SKIA_CONCURRENT_EXECUTOR_H_

#include "flutter/fml/closure.h"
#include "flutter/fml/macros.h"
#include "third_party/skia/include/core/SkExecutor.h"

namespace flutter {

class SkiaConcurrentExecutor : public SkExecutor {
public:
using OnWorkCallback = std::function<void(fml::closure work)>;
SkiaConcurrentExecutor(OnWorkCallback on_work);

~SkiaConcurrentExecutor() override;

void add(fml::closure work) override;

private:
OnWorkCallback on_work_;

FML_DISALLOW_COPY_AND_ASSIGN(SkiaConcurrentExecutor);
};

} // namespace flutter

#endif // FLUTTER_RUNTIME_SKIA_CONCURRENT_EXECUTOR_H_