forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_node.cc
80 lines (61 loc) · 2.29 KB
/
export_node.cc
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
// 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/flow/export_node.h"
#include "flutter/fml/thread_local.h"
namespace {
using ExportNodeBindings =
std::unordered_map<zx_koid_t, std::unique_ptr<flutter::ExportNode>>;
FML_THREAD_LOCAL fml::ThreadLocalUniquePtr<ExportNodeBindings>
tls_export_node_bindings;
} // namespace
namespace flutter {
ExportNode::ExportNode(zx::eventpair export_token)
: pending_export_token_(std::move(export_token)) {
FML_DCHECK(pending_export_token_);
}
void ExportNode::Create(zx_koid_t id, zx::eventpair export_token) {
// This GPU thread contains at least 1 ViewHolder. Initialize the per-thread
// bindings.
if (tls_export_node_bindings.get() == nullptr) {
tls_export_node_bindings.reset(new ExportNodeBindings());
}
auto* bindings = tls_export_node_bindings.get();
FML_DCHECK(bindings);
FML_DCHECK(bindings->find(id) == bindings->end());
auto export_node =
std::unique_ptr<ExportNode>(new ExportNode(std::move(export_token)));
bindings->emplace(id, std::move(export_node));
}
void ExportNode::Destroy(zx_koid_t id) {
auto* bindings = tls_export_node_bindings.get();
FML_DCHECK(bindings);
bindings->erase(id);
}
ExportNode* ExportNode::FromId(zx_koid_t id) {
auto* bindings = tls_export_node_bindings.get();
if (!bindings) {
return nullptr;
}
auto binding = bindings->find(id);
if (binding == bindings->end()) {
return nullptr;
}
return binding->second.get();
}
void ExportNode::UpdateScene(SceneUpdateContext& context,
const SkPoint& offset,
const SkSize& size,
bool hit_testable) {
if (pending_export_token_) {
export_node_ = std::make_unique<scenic::EntityNode>(context.session());
export_node_->Export(std::move(pending_export_token_));
}
FML_DCHECK(export_node_);
context.top_entity()->entity_node().AddChild(*export_node_);
export_node_->SetTranslation(offset.x(), offset.y(), -0.1f);
export_node_->SetHitTestBehavior(
hit_testable ? fuchsia::ui::gfx::HitTestBehavior::kDefault
: fuchsia::ui::gfx::HitTestBehavior::kSuppress);
}
} // namespace flutter