Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7134e10

Browse files
committed
Break up SurfaceProducer/SceneUpdateContext/SessionConnection
1 parent 106d4d5 commit 7134e10

14 files changed

+369
-406
lines changed

flow/layers/fuchsia_layer_unittests.cc

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,28 @@ class MockSession : public fuchsia::ui::scenic::testing::Session_TestBase {
238238
fuchsia::ui::scenic::SessionListenerPtr listener_;
239239
};
240240

241+
class MockSessionWrapper : public flutter::SessionWrapper {
242+
public:
243+
MockSessionWrapper(fuchsia::ui::scenic::SessionPtr session_ptr)
244+
: session_(std::move(session_ptr)) {}
245+
~MockSessionWrapper() override = default;
246+
247+
scenic::Session* get() override { return &session_; }
248+
void Present() override { session_.Flush(); }
249+
250+
private:
251+
scenic::Session session_;
252+
};
253+
241254
struct TestContext {
242255
// Message loop.
243256
fml::RefPtr<fml::MessageLoopFuchsia> loop;
244257
fml::RefPtr<fml::TaskRunner> task_runner;
245258

246259
// Session.
247-
MockSession mock_session;
248260
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener> listener_request;
249-
std::unique_ptr<scenic::Session> session;
261+
MockSession mock_session;
262+
std::unique_ptr<MockSessionWrapper> mock_session_wrapper;
250263

251264
// SceneUpdateContext.
252265
std::unique_ptr<SceneUpdateContext> scene_update_context;
@@ -270,11 +283,13 @@ std::unique_ptr<TestContext> InitTest() {
270283
fuchsia::ui::scenic::SessionListenerPtr listener;
271284
context->listener_request = listener.NewRequest();
272285
context->mock_session.Bind(session_ptr.NewRequest(), std::move(listener));
273-
context->session = std::make_unique<scenic::Session>(std::move(session_ptr));
286+
context->mock_session_wrapper =
287+
std::make_unique<MockSessionWrapper>(std::move(session_ptr));
274288

275289
// Init SceneUpdateContext.
276-
context->scene_update_context =
277-
std::make_unique<SceneUpdateContext>(context->session.get());
290+
context->scene_update_context = std::make_unique<SceneUpdateContext>(
291+
"fuchsia_layer_unittest", fuchsia::ui::views::ViewToken(),
292+
scenic::ViewRefPair::New(), *(context->mock_session_wrapper));
278293

279294
// Init PrerollContext.
280295
context->preroll_context = std::unique_ptr<PrerollContext>(new PrerollContext{
@@ -543,7 +558,7 @@ TEST_F(FuchsiaLayerTest, DISABLED_PhysicalShapeLayersAndChildSceneLayers) {
543558
// against the list above.
544559
root->UpdateScene(*(test_context->scene_update_context));
545560

546-
test_context->session->Flush();
561+
test_context->mock_session_wrapper->Present();
547562

548563
// Run loop until idle, so that the Session receives and processes
549564
// its method calls.
@@ -725,7 +740,7 @@ TEST_F(FuchsiaLayerTest, DISABLED_OpacityAndTransformLayer) {
725740
// commands against the list above.
726741
root->UpdateScene(*(test_context->scene_update_context));
727742

728-
test_context->session->Flush();
743+
test_context->mock_session_wrapper->Present();
729744

730745
// Run loop until idle, so that the Session receives and processes
731746
// its method calls.

flow/layers/layer_tree.cc

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,6 @@ bool LayerTree::Preroll(CompositorContext::ScopedFrame& frame,
6060
return context.surface_needs_readback;
6161
}
6262

63-
#if defined(LEGACY_FUCHSIA_EMBEDDER)
64-
void LayerTree::UpdateScene(SceneUpdateContext& context,
65-
scenic::ContainerNode& container) {
66-
TRACE_EVENT0("flutter", "LayerTree::UpdateScene");
67-
68-
const float inv_dpr = 1.0f / device_pixel_ratio_;
69-
SceneUpdateContext::Transform transform(context, inv_dpr, inv_dpr, 1.0f);
70-
71-
SceneUpdateContext::Frame frame(
72-
context,
73-
SkRRect::MakeRect(
74-
SkRect::MakeWH(frame_size_.width(), frame_size_.height())),
75-
SK_ColorTRANSPARENT, SK_AlphaOPAQUE, "flutter::LayerTree");
76-
if (root_layer_->needs_system_composite()) {
77-
root_layer_->UpdateScene(context);
78-
}
79-
if (root_layer_->needs_painting()) {
80-
frame.AddPaintLayer(root_layer_.get());
81-
}
82-
container.AddChild(transform.entity_node());
83-
}
84-
#endif
85-
8663
void LayerTree::Paint(CompositorContext::ScopedFrame& frame,
8764
bool ignore_raster_cache) const {
8865
TRACE_EVENT0("flutter", "LayerTree::Paint");

flow/layers/layer_tree.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ class LayerTree {
3232
bool Preroll(CompositorContext::ScopedFrame& frame,
3333
bool ignore_raster_cache = false);
3434

35-
#if defined(LEGACY_FUCHSIA_EMBEDDER)
36-
void UpdateScene(SceneUpdateContext& context,
37-
scenic::ContainerNode& container);
38-
#endif
39-
4035
void Paint(CompositorContext::ScopedFrame& frame,
4136
bool ignore_raster_cache = false) const;
4237

flow/scene_update_context.cc

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "flutter/flow/scene_update_context.h"
66

7+
#include <lib/ui/scenic/cpp/commands.h>
78
#include <lib/ui/scenic/cpp/view_token_pair.h>
89

910
#include "flutter/flow/layers/layer.h"
@@ -64,28 +65,67 @@ void SetMaterialColor(scenic::Material& material,
6465

6566
} // namespace
6667

67-
SceneUpdateContext::SceneUpdateContext(scenic::Session* session)
68-
: session_(session) {}
68+
SceneUpdateContext::SceneUpdateContext(std::string debug_label,
69+
fuchsia::ui::views::ViewToken view_token,
70+
scenic::ViewRefPair view_ref_pair,
71+
SessionWrapper& session)
72+
: session_(session),
73+
root_view_(session_.get(),
74+
std::move(view_token),
75+
std::move(view_ref_pair.control_ref),
76+
std::move(view_ref_pair.view_ref),
77+
debug_label),
78+
root_node_(session_.get()) {
79+
root_view_.AddChild(root_node_);
80+
root_node_.SetEventMask(fuchsia::ui::gfx::kMetricsEventMask);
81+
82+
session_.Present();
83+
}
84+
85+
std::vector<SceneUpdateContext::PaintTask> SceneUpdateContext::GetPaintTasks() {
86+
std::vector<PaintTask> frame_paint_tasks = std::move(paint_tasks_);
87+
88+
paint_tasks_.clear();
89+
90+
return frame_paint_tasks;
91+
}
6992

70-
void SceneUpdateContext::CreateFrame(scenic::EntityNode entity_node,
93+
void SceneUpdateContext::EnableWireframe(bool enable) {
94+
session_.get()->Enqueue(
95+
scenic::NewSetEnableDebugViewBoundsCmd(root_view_.id(), enable));
96+
}
97+
98+
void SceneUpdateContext::Reset() {
99+
paint_tasks_.clear();
100+
top_entity_ = nullptr;
101+
top_scale_x_ = 1.f;
102+
top_scale_y_ = 1.f;
103+
top_elevation_ = 0.f;
104+
next_elevation_ = 0.f;
105+
alpha_ = 1.f;
106+
107+
// We are going to be sending down a fresh node hierarchy every frame. So just
108+
// enqueue a detach op on the imported root node.
109+
session_.get()->Enqueue(scenic::NewDetachChildrenCmd(root_node_.id()));
110+
}
111+
112+
void SceneUpdateContext::CreateFrame(scenic::EntityNode& entity_node,
71113
const SkRRect& rrect,
72114
SkColor color,
73115
SkAlpha opacity,
74116
const SkRect& paint_bounds,
75117
std::vector<Layer*> paint_layers) {
76-
FML_DCHECK(!rrect.isEmpty());
118+
if (rrect.isEmpty())
119+
return;
77120

78121
// Frames always clip their children.
79122
SkRect shape_bounds = rrect.getBounds();
80123
SetEntityNodeClipPlanes(entity_node, shape_bounds);
81124

82125
// and possibly for its texture.
83126
// TODO(SCN-137): Need to be able to express the radii as vectors.
84-
scenic::ShapeNode shape_node(session());
85-
scenic::Rectangle shape(session_, // session
86-
rrect.width(), // width
87-
rrect.height() // height
88-
);
127+
scenic::ShapeNode shape_node(session_.get());
128+
scenic::Rectangle shape(session_.get(), rrect.width(), rrect.height());
89129
shape_node.SetShape(shape);
90130
shape_node.SetTranslation(shape_bounds.width() * 0.5f + shape_bounds.left(),
91131
shape_bounds.height() * 0.5f + shape_bounds.top(),
@@ -95,7 +135,7 @@ void SceneUpdateContext::CreateFrame(scenic::EntityNode entity_node,
95135
if (paint_bounds.isEmpty() || !paint_bounds.intersects(shape_bounds))
96136
paint_layers.clear();
97137

98-
scenic::Material material(session());
138+
scenic::Material material(session_.get());
99139
shape_node.SetMaterial(material);
100140
entity_node.AddChild(shape_node);
101141

@@ -120,19 +160,6 @@ void SceneUpdateContext::CreateFrame(scenic::EntityNode entity_node,
120160
}
121161
}
122162

123-
std::vector<SceneUpdateContext::PaintTask>
124-
SceneUpdateContext::ResetAndGetPaintTasks() {
125-
std::vector<PaintTask> frame_paint_tasks = std::move(paint_tasks_);
126-
127-
// Reset all internal state.
128-
paint_tasks_.clear();
129-
top_elevation_ = 0.0f;
130-
next_elevation_ = 0.0f;
131-
alpha_ = 1.0f;
132-
133-
return frame_paint_tasks;
134-
}
135-
136163
void SceneUpdateContext::CreateView(int64_t view_id,
137164
bool hit_testable,
138165
bool focusable) {
@@ -163,20 +190,24 @@ void SceneUpdateContext::UpdateView(int64_t view_id,
163190
: view_holder->hit_testable();
164191
view_holder->SetProperties(size.width(), size.height(), 0, 0, 0, 0,
165192
view_holder->focusable());
166-
view_holder->Update(session_, top_entity_->embedder_node(), offset, size,
167-
SkScalarRoundToInt(alphaf() * 255), hit_testable);
193+
view_holder->Update(session_.get(), top_entity_->embedder_node(), offset,
194+
size, SkScalarRoundToInt(alphaf() * 255), hit_testable);
168195
}
169196

170197
SceneUpdateContext::Entity::Entity(SceneUpdateContext& context)
171198
: context_(context),
172199
previous_entity_(context.top_entity_),
173-
entity_node_(context.session()) {
174-
if (previous_entity_)
175-
previous_entity_->embedder_node().AddChild(entity_node_);
200+
entity_node_(context.session_.get()) {
176201
context.top_entity_ = this;
177202
}
178203

179204
SceneUpdateContext::Entity::~Entity() {
205+
if (previous_entity_) {
206+
previous_entity_->embedder_node().AddChild(entity_node_);
207+
} else {
208+
context_.root_node_.AddChild(entity_node_);
209+
}
210+
180211
FML_DCHECK(context_.top_entity_ == this);
181212
context_.top_entity_ = previous_entity_;
182213
}
@@ -245,7 +276,7 @@ SceneUpdateContext::Frame::Frame(SceneUpdateContext& context,
245276
rrect_(rrect),
246277
color_(color),
247278
opacity_(opacity),
248-
opacity_node_(context.session()),
279+
opacity_node_(context.session_.get()),
249280
paint_bounds_(SkRect::MakeEmpty()) {
250281
entity_node().SetLabel(label);
251282
entity_node().SetTranslation(0.f, 0.f,
@@ -262,15 +293,11 @@ SceneUpdateContext::Frame::Frame(SceneUpdateContext& context,
262293
}
263294

264295
SceneUpdateContext::Frame::~Frame() {
265-
context().top_elevation_ = previous_elevation_;
266-
267-
// We don't need a shape if the frame is zero size.
268-
if (rrect_.isEmpty())
269-
return;
270-
271296
// Add a part which represents the frame's geometry for clipping purposes
272-
context().CreateFrame(std::move(entity_node()), rrect_, color_, opacity_,
273-
paint_bounds_, std::move(paint_layers_));
297+
context().CreateFrame(entity_node(), rrect_, color_, opacity_, paint_bounds_,
298+
std::move(paint_layers_));
299+
300+
context().top_elevation_ = previous_elevation_;
274301
}
275302

276303
void SceneUpdateContext::Frame::AddPaintLayer(Layer* layer) {

flow/scene_update_context.h

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
#ifndef FLUTTER_FLOW_SCENE_UPDATE_CONTEXT_H_
66
#define FLUTTER_FLOW_SCENE_UPDATE_CONTEXT_H_
77

8+
#include <fuchsia/ui/views/cpp/fidl.h>
9+
#include <lib/ui/scenic/cpp/resources.h>
10+
#include <lib/ui/scenic/cpp/session.h>
11+
#include <lib/ui/scenic/cpp/view_ref_pair.h>
12+
813
#include <cfloat>
914
#include <memory>
1015
#include <set>
1116
#include <vector>
1217

1318
#include "flutter/flow/embedded_views.h"
14-
#include "flutter/fml/compiler_specific.h"
1519
#include "flutter/fml/logging.h"
1620
#include "flutter/fml/macros.h"
17-
#include "lib/ui/scenic/cpp/resources.h"
1821
#include "third_party/skia/include/core/SkRect.h"
1922
#include "third_party/skia/include/core/SkSurface.h"
2023

@@ -31,6 +34,14 @@ constexpr float kOneMinusEpsilon = 1 - FLT_EPSILON;
3134
// How much layers are separated in Scenic z elevation.
3235
constexpr float kScenicZElevationBetweenLayers = 10.f;
3336

37+
class SessionWrapper {
38+
public:
39+
virtual ~SessionWrapper() {}
40+
41+
virtual scenic::Session* get() = 0;
42+
virtual void Present() = 0;
43+
};
44+
3445
class SceneUpdateContext : public flutter::ExternalViewEmbedder {
3546
public:
3647
class Entity {
@@ -106,18 +117,24 @@ class SceneUpdateContext : public flutter::ExternalViewEmbedder {
106117
std::vector<Layer*> layers;
107118
};
108119

109-
SceneUpdateContext(scenic::Session* session);
120+
SceneUpdateContext(std::string debug_label,
121+
fuchsia::ui::views::ViewToken view_token,
122+
scenic::ViewRefPair view_ref_pair,
123+
SessionWrapper& session);
110124
~SceneUpdateContext() = default;
111125

112-
scenic::Session* session() { return session_; }
113-
Entity* top_entity() { return top_entity_; }
114-
115126
// The cumulative alpha value based on all the parent OpacityLayers.
116127
void set_alphaf(float alpha) { alpha_ = alpha; }
117128
float alphaf() { return alpha_; }
118129

119130
// Returns all `PaintTask`s generated for the current frame.
120-
std::vector<PaintTask> ResetAndGetPaintTasks();
131+
std::vector<PaintTask> GetPaintTasks();
132+
133+
// Enable/disable wireframe rendering around the root view bounds.
134+
void EnableWireframe(bool enable);
135+
136+
// Reset state for a new frame.
137+
void Reset();
121138

122139
// |ExternalViewEmbedder|
123140
SkCanvas* GetRootCanvas() override { return nullptr; }
@@ -155,24 +172,27 @@ class SceneUpdateContext : public flutter::ExternalViewEmbedder {
155172
std::optional<bool> override_hit_testable = std::nullopt);
156173

157174
private:
158-
void CreateFrame(scenic::EntityNode entity_node,
175+
void CreateFrame(scenic::EntityNode& entity_node,
159176
const SkRRect& rrect,
160177
SkColor color,
161178
SkAlpha opacity,
162179
const SkRect& paint_bounds,
163180
std::vector<Layer*> paint_layers);
164181

182+
SessionWrapper& session_;
183+
184+
scenic::View root_view_;
185+
scenic::EntityNode root_node_;
186+
187+
std::vector<PaintTask> paint_tasks_;
188+
165189
Entity* top_entity_ = nullptr;
166190
float top_scale_x_ = 1.f;
167191
float top_scale_y_ = 1.f;
168-
float top_elevation_ = 0.0f;
192+
float top_elevation_ = 0.f;
169193

170-
scenic::Session* const session_;
171-
172-
float alpha_ = 1.0f;
173-
float next_elevation_ = 0.0f;
174-
175-
std::vector<PaintTask> paint_tasks_;
194+
float next_elevation_ = 0.f;
195+
float alpha_ = 1.f;
176196

177197
FML_DISALLOW_COPY_AND_ASSIGN(SceneUpdateContext);
178198
};

shell/platform/fuchsia/flutter/component.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ Application::Application(
365365
// Controls whether category "skia" trace events are enabled.
366366
settings_.trace_skia = true;
367367

368+
settings_.verbose_logging = true;
369+
370+
settings_.advisory_script_uri = debug_label_;
371+
372+
settings_.advisory_script_entrypoint = debug_label_;
373+
368374
settings_.icu_data_path = "";
369375

370376
settings_.assets_dir = application_assets_directory_.get();

0 commit comments

Comments
 (0)