Wire up a concurrent message loop backed SkExecutor for Skia. (flutter/engine#10788)
Fixes https://github.com/flutter/flutter/issues/37885
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
|
||||
@@ -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"
|
||||
@@ -255,6 +256,9 @@ 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>()) {
|
||||
@@ -262,6 +266,10 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
|
||||
|
||||
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_);
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
@@ -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_;
|
||||
|
||||
26
engine/src/flutter/runtime/skia_concurrent_executor.cc
Normal file
26
engine/src/flutter/runtime/skia_concurrent_executor.cc
Normal file
@@ -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
engine/src/flutter/runtime/skia_concurrent_executor.h
Normal file
31
engine/src/flutter/runtime/skia_concurrent_executor.h
Normal file
@@ -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_
|
||||
Reference in New Issue
Block a user