forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_node.h
83 lines (64 loc) · 2.73 KB
/
export_node.h
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
// 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_FLOW_EXPORT_NODE_H_
#define FLUTTER_FLOW_EXPORT_NODE_H_
#include <memory>
#include <zx/eventpair.h>
#include "dart-pkg/zircon/sdk_ext/handle.h"
#include "flutter/flow/scene_update_context.h"
#include "flutter/fml/build_config.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/memory/ref_counted.h"
#include "lib/ui/scenic/cpp/resources.h"
#include "third_party/flutter/fml/task_runner.h"
#include "third_party/skia/include/core/SkPoint.h"
namespace flow {
// Wrapper class for ExportNode to use on UI Thread. When ExportNodeHolder is
// destroyed, a task is posted on the Rasterizer thread to dispose the resources
// held by the ExportNode.
class ExportNodeHolder : public fml::RefCountedThreadSafe<ExportNodeHolder> {
public:
ExportNodeHolder(fml::RefPtr<fml::TaskRunner> gpu_task_runner,
fml::RefPtr<zircon::dart::Handle> export_token_handle);
~ExportNodeHolder();
// Calls Bind() on the wrapped ExportNode.
void Bind(SceneUpdateContext& context,
scenic::ContainerNode& container,
const SkPoint& offset,
bool hit_testable);
ExportNode* export_node() { return export_node_.get(); }
private:
fml::RefPtr<fml::TaskRunner> gpu_task_runner_;
std::unique_ptr<ExportNode> export_node_;
FML_FRIEND_MAKE_REF_COUNTED(ExportNodeHolder);
FML_FRIEND_REF_COUNTED_THREAD_SAFE(ExportNodeHolder);
FML_DISALLOW_COPY_AND_ASSIGN(ExportNodeHolder);
};
// Represents a node which is being exported from the session.
// This object is created on the UI thread but the entity node it contains
// must be created and destroyed by the rasterizer thread.
class ExportNode {
public:
ExportNode(fml::RefPtr<zircon::dart::Handle> export_token_handle);
~ExportNode();
// Binds the export token to the entity node and adds it as a child of
// the specified container. Must be called on the Rasterizer thread.
void Bind(SceneUpdateContext& context,
scenic::ContainerNode& container,
const SkPoint& offset,
bool hit_testable);
private:
friend class SceneUpdateContext;
friend class ExportNodeHolder;
// Cleans up resources held and removes this ExportNode from
// SceneUpdateContext. Must be called on the Rasterizer thread.
void Dispose(bool remove_from_scene_update_context);
// Member variables can only be read or modified on Rasterizer thread.
SceneUpdateContext* scene_update_context_ = nullptr;
zx::eventpair export_token_;
std::unique_ptr<scenic::EntityNode> node_;
FML_DISALLOW_COPY_AND_ASSIGN(ExportNode);
};
} // namespace flow
#endif // FLUTTER_FLOW_EXPORT_NODE_H_