未验证 提交 8becf442 编写于 作者: C Chinmay Garde 提交者: GitHub

Wire up a concurrent message loop backed SkExecutor for Skia. (#10788)

Fixes https://github.com/flutter/flutter/issues/37885
上级 9d2a2888
......@@ -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_;
......
// 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
// 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_
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册