forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene_update_context.h
196 lines (151 loc) · 5.65 KB
/
scene_update_context.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Copyright 2016 The Chromium 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_SCENE_UPDATE_CONTEXT_H_
#define FLUTTER_FLOW_SCENE_UPDATE_CONTEXT_H_
#include <memory>
#include <vector>
#include "flutter/flow/compositor_context.h"
#include "lib/fxl/build_config.h"
#include "lib/fxl/logging.h"
#include "lib/fxl/macros.h"
#include "lib/ui/scenic/client/resources.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkSurface.h"
namespace flow {
class Layer;
class ExportNodeHolder;
class ExportNode;
class SceneUpdateContext {
public:
class SurfaceProducerSurface {
public:
virtual ~SurfaceProducerSurface() = default;
virtual size_t AdvanceAndGetAge() = 0;
virtual bool FlushSessionAcquireAndReleaseEvents() = 0;
virtual bool IsValid() const = 0;
virtual SkISize GetSize() const = 0;
virtual void SignalWritesFinished(
std::function<void(void)> on_writes_committed) = 0;
virtual scenic_lib::Image* GetImage() = 0;
virtual sk_sp<SkSurface> GetSkiaSurface() const = 0;
};
class SurfaceProducer {
public:
virtual ~SurfaceProducer() = default;
virtual std::unique_ptr<SurfaceProducerSurface> ProduceSurface(
const SkISize& size) = 0;
virtual void SubmitSurface(
std::unique_ptr<SurfaceProducerSurface> surface) = 0;
};
class Entity {
public:
Entity(SceneUpdateContext& context);
~Entity();
SceneUpdateContext& context() { return context_; }
scenic_lib::EntityNode& entity_node() { return entity_node_; }
private:
SceneUpdateContext& context_;
Entity* const previous_entity_;
scenic_lib::EntityNode entity_node_;
};
class Clip : public Entity {
public:
Clip(SceneUpdateContext& context,
scenic_lib::Shape& shape,
const SkRect& shape_bounds);
~Clip();
};
class Transform : public Entity {
public:
Transform(SceneUpdateContext& context, const SkMatrix& transform);
Transform(SceneUpdateContext& context,
float scale_x,
float scale_y,
float scale_z);
~Transform();
private:
float const previous_scale_x_;
float const previous_scale_y_;
};
class Frame : public Entity {
public:
Frame(SceneUpdateContext& context,
const SkRRect& rrect,
SkColor color,
float elevation);
~Frame();
void AddPaintedLayer(Layer* layer);
private:
const SkRRect& rrect_;
SkColor const color_;
std::vector<Layer*> paint_layers_;
SkRect paint_bounds_;
};
SceneUpdateContext(scenic_lib::Session* session,
SurfaceProducer* surface_producer);
~SceneUpdateContext();
scenic_lib::Session* session() { return session_; }
bool has_metrics() const { return !!metrics_; }
void set_metrics(scenic::MetricsPtr metrics) {
metrics_ = std::move(metrics);
}
const scenic::MetricsPtr& metrics() const { return metrics_; }
void AddChildScene(ExportNode* export_node,
SkPoint offset,
bool hit_testable);
// Adds reference to |export_node| so we can call export_node->Dispose() in
// our destructor. Caller is responsible for calling RemoveExportNode() before
// |export_node| is destroyed.
void AddExportNode(ExportNode* export_node);
// Removes reference to |export_node|.
void RemoveExportNode(ExportNode* export_node);
// TODO(chinmaygarde): This method must submit the surfaces as soon as paint
// tasks are done. However, given that there is no support currently for
// Vulkan semaphores, we need to submit all the surfaces after an explicit
// CPU wait. Once Vulkan semaphores are available, this method must return
// void and the implementation must submit surfaces on its own as soon as the
// specific canvas operations are done.
FXL_WARN_UNUSED_RESULT
std::vector<std::unique_ptr<SurfaceProducerSurface>> ExecutePaintTasks(
CompositorContext::ScopedFrame& frame);
private:
struct PaintTask {
std::unique_ptr<SurfaceProducerSurface> surface;
SkScalar left;
SkScalar top;
SkScalar scale_x;
SkScalar scale_y;
SkColor background_color;
std::vector<Layer*> layers;
};
void CreateFrame(scenic_lib::EntityNode& entity_node,
const SkRRect& rrect,
SkColor color,
const SkRect& paint_bounds,
std::vector<Layer*> paint_layers);
void SetShapeTextureOrColor(scenic_lib::ShapeNode& shape_node,
SkColor color,
SkScalar scale_x,
SkScalar scale_y,
const SkRect& paint_bounds,
std::vector<Layer*> paint_layers);
void SetShapeColor(scenic_lib::ShapeNode& shape_node, SkColor color);
scenic_lib::Image* GenerateImageIfNeeded(SkColor color,
SkScalar scale_x,
SkScalar scale_y,
const SkRect& paint_bounds,
std::vector<Layer*> paint_layers);
Entity* top_entity_ = nullptr;
float top_scale_x_ = 1.f;
float top_scale_y_ = 1.f;
scenic_lib::Session* const session_;
SurfaceProducer* const surface_producer_;
scenic::MetricsPtr metrics_;
std::vector<PaintTask> paint_tasks_;
// Save ExportNodes so we can dispose them in our destructor.
std::set<ExportNode*> export_nodes_;
FXL_DISALLOW_COPY_AND_ASSIGN(SceneUpdateContext);
};
} // namespace flow
#endif // FLUTTER_FLOW_SCENE_UPDATE_CONTEXT_H_