forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembedder_engine.cc
More file actions
115 lines (93 loc) · 2.92 KB
/
embedder_engine.cc
File metadata and controls
115 lines (93 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// 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/shell/platform/embedder/embedder_engine.h"
#include "flutter/fml/make_copyable.h"
namespace shell {
EmbedderEngine::EmbedderEngine(
ThreadHost thread_host,
blink::TaskRunners task_runners,
blink::Settings settings,
Shell::CreateCallback<PlatformView> on_create_platform_view,
Shell::CreateCallback<Rasterizer> on_create_rasterizer)
: thread_host_(std::move(thread_host)),
shell_(Shell::Create(std::move(task_runners),
std::move(settings),
on_create_platform_view,
on_create_rasterizer)) {
is_valid_ = shell_ != nullptr;
}
EmbedderEngine::~EmbedderEngine() = default;
bool EmbedderEngine::IsValid() const {
return is_valid_;
}
bool EmbedderEngine::NotifyCreated() {
if (!IsValid()) {
return false;
}
shell_->GetPlatformView()->NotifyCreated();
return true;
}
bool EmbedderEngine::NotifyDestroyed() {
if (!IsValid()) {
return false;
}
shell_->GetPlatformView()->NotifyDestroyed();
return true;
}
bool EmbedderEngine::Run(RunConfiguration run_configuration) {
if (!IsValid()) {
return false;
}
shell_->GetTaskRunners().GetUITaskRunner()->PostTask(
fml::MakeCopyable([engine = shell_->GetEngine(), // engine
config = std::move(run_configuration) // config
]() mutable {
if (engine) {
auto result = engine->Run(std::move(config));
if (result == shell::Engine::RunStatus::Failure) {
FML_LOG(ERROR) << "Could not launch the engine with configuration.";
}
}
}));
return true;
}
bool EmbedderEngine::SetViewportMetrics(blink::ViewportMetrics metrics) {
if (!IsValid()) {
return false;
}
shell_->GetTaskRunners().GetUITaskRunner()->PostTask(
[engine = shell_->GetEngine(), metrics = std::move(metrics)]() {
if (engine) {
engine->SetViewportMetrics(std::move(metrics));
}
});
return true;
}
bool EmbedderEngine::DispatchPointerDataPacket(
std::unique_ptr<blink::PointerDataPacket> packet) {
if (!IsValid() || !packet) {
return false;
}
shell_->GetTaskRunners().GetUITaskRunner()->PostTask(fml::MakeCopyable(
[engine = shell_->GetEngine(), packet = std::move(packet)] {
if (engine) {
engine->DispatchPointerDataPacket(*packet);
}
}));
return true;
}
bool EmbedderEngine::SendPlatformMessage(
fml::RefPtr<blink::PlatformMessage> message) {
if (!IsValid() || !message) {
return false;
}
shell_->GetTaskRunners().GetUITaskRunner()->PostTask(
[engine = shell_->GetEngine(), message] {
if (engine) {
engine->DispatchPlatformMessage(message);
}
});
return true;
}
} // namespace shell