Skip to content

Commit 12a3747

Browse files
authored
fuchsia: Remove dead code / break dependencies (flutter#19396)
The fuchsia code around metrics and sizing was just sending this information through a side-channel, when the engine already had the information available. So, delete all of it to make future CLs simpler. Additionally, the SceneUpdateContext has many unneccesary dependencies re: metrics and PaintTasks. Break those to make future CLs simpler. Tested: Ran all unittests and ran workstation on Fuchsia BUG: 53062, 53063
1 parent 033dd45 commit 12a3747

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+869
-1829
lines changed

flow/layers/child_scene_layer.cc

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#include "flutter/flow/layers/child_scene_layer.h"
66

7-
#include "flutter/flow/view_holder.h"
8-
97
namespace flutter {
108

119
ChildSceneLayer::ChildSceneLayer(zx_koid_t layer_id,
@@ -19,11 +17,9 @@ ChildSceneLayer::ChildSceneLayer(zx_koid_t layer_id,
1917

2018
void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
2119
TRACE_EVENT0("flutter", "ChildSceneLayer::Preroll");
22-
set_needs_system_composite(true);
23-
24-
CheckForChildLayerBelow(context);
2520

2621
context->child_scene_layer_exists_below = true;
22+
CheckForChildLayerBelow(context);
2723

2824
// An alpha "hole punch" is required if the frame behind us is not opaque.
2925
if (!context->is_opaque) {
@@ -49,15 +45,7 @@ void ChildSceneLayer::Paint(PaintContext& context) const {
4945
void ChildSceneLayer::UpdateScene(SceneUpdateContext& context) {
5046
TRACE_EVENT0("flutter", "ChildSceneLayer::UpdateScene");
5147
FML_DCHECK(needs_system_composite());
52-
53-
Layer::UpdateScene(context);
54-
55-
auto* view_holder = ViewHolder::FromId(layer_id_);
56-
FML_DCHECK(view_holder);
57-
58-
view_holder->UpdateScene(context, offset_, size_,
59-
SkScalarRoundToInt(context.alphaf() * 255),
60-
hit_testable_);
48+
context.UpdateView(layer_id_, offset_, size_, hit_testable_);
6149
}
6250

6351
} // namespace flutter

flow/layers/container_layer.cc

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "flutter/flow/layers/container_layer.h"
66

7+
#include <optional>
8+
79
namespace flutter {
810

911
ContainerLayer::ContainerLayer() {}
@@ -30,6 +32,9 @@ void ContainerLayer::PrerollChildren(PrerollContext* context,
3032
const SkMatrix& child_matrix,
3133
SkRect* child_paint_bounds) {
3234
#if defined(LEGACY_FUCHSIA_EMBEDDER)
35+
// If there is embedded Fuchsia content in the scene (a ChildSceneLayer),
36+
// Layers that appear above the embedded content will be turned into their own
37+
// Scenic layers.
3338
child_layer_exists_below_ = context->child_scene_layer_exists_below;
3439
context->child_scene_layer_exists_below = false;
3540
#endif
@@ -98,63 +103,20 @@ void ContainerLayer::UpdateScene(SceneUpdateContext& context) {
98103
}
99104

100105
void ContainerLayer::UpdateSceneChildren(SceneUpdateContext& context) {
101-
auto update_scene_layers = [&] {
102-
// Paint all of the layers which need to be drawn into the container.
103-
// These may be flattened down to a containing Scenic Frame.
104-
for (auto& layer : layers_) {
105-
if (layer->needs_system_composite()) {
106-
layer->UpdateScene(context);
107-
}
108-
}
109-
};
110-
111106
FML_DCHECK(needs_system_composite());
112107

113-
// If there is embedded Fuchsia content in the scene (a ChildSceneLayer),
114-
// PhysicalShapeLayers that appear above the embedded content will be turned
115-
// into their own Scenic layers.
108+
std::optional<SceneUpdateContext::Frame> frame;
116109
if (child_layer_exists_below_) {
117-
float global_scenic_elevation =
118-
context.GetGlobalElevationForNextScenicLayer();
119-
float local_scenic_elevation =
120-
global_scenic_elevation - context.scenic_elevation();
121-
float z_translation = -local_scenic_elevation;
122-
123-
// Retained rendering: speedup by reusing a retained entity node if
124-
// possible. When an entity node is reused, no paint layer is added to the
125-
// frame so we won't call PhysicalShapeLayer::Paint.
126-
LayerRasterCacheKey key(unique_id(), context.Matrix());
127-
if (context.HasRetainedNode(key)) {
128-
TRACE_EVENT_INSTANT0("flutter", "retained layer cache hit");
129-
scenic::EntityNode* retained_node = context.GetRetainedNode(key);
130-
FML_DCHECK(context.top_entity());
131-
FML_DCHECK(retained_node->session() == context.session());
132-
133-
// Re-adjust the elevation.
134-
retained_node->SetTranslation(0.f, 0.f, z_translation);
135-
136-
context.top_entity()->entity_node().AddChild(*retained_node);
137-
return;
138-
}
139-
140-
TRACE_EVENT_INSTANT0("flutter", "cache miss, creating");
141-
// If we can't find an existing retained surface, create one.
142-
SceneUpdateContext::Frame frame(
110+
frame.emplace(
143111
context, SkRRect::MakeRect(paint_bounds()), SK_ColorTRANSPARENT,
144-
SkScalarRoundToInt(context.alphaf() * 255),
145-
"flutter::PhysicalShapeLayer", z_translation, this);
146-
147-
frame.AddPaintLayer(this);
148-
149-
// Node: UpdateSceneChildren needs to be called here so that |frame| is
150-
// still in scope (and therefore alive) while UpdateSceneChildren is being
151-
// called.
152-
float scenic_elevation = context.scenic_elevation();
153-
context.set_scenic_elevation(scenic_elevation + local_scenic_elevation);
154-
update_scene_layers();
155-
context.set_scenic_elevation(scenic_elevation);
156-
} else {
157-
update_scene_layers();
112+
SkScalarRoundToInt(context.alphaf() * 255), "flutter::ContainerLayer");
113+
frame->AddPaintLayer(this);
114+
}
115+
116+
for (auto& layer : layers_) {
117+
if (layer->needs_system_composite()) {
118+
layer->UpdateScene(context);
119+
}
158120
}
159121
}
160122

flow/layers/fuchsia_layer_unittests.cc

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

241-
class MockSurfaceProducerSurface
242-
: public SceneUpdateContext::SurfaceProducerSurface {
241+
class MockSessionWrapper : public flutter::SessionWrapper {
243242
public:
244-
MockSurfaceProducerSurface(scenic::Session* session, const SkISize& size)
245-
: image_(session, 0, 0, {}), size_(size) {}
243+
MockSessionWrapper(fuchsia::ui::scenic::SessionPtr session_ptr)
244+
: session_(std::move(session_ptr)) {}
245+
~MockSessionWrapper() override = default;
246246

247-
size_t AdvanceAndGetAge() override { return 0; }
248-
249-
bool FlushSessionAcquireAndReleaseEvents() override { return false; }
250-
251-
bool IsValid() const override { return false; }
252-
253-
SkISize GetSize() const override { return size_; }
254-
255-
void SignalWritesFinished(
256-
const std::function<void(void)>& on_writes_committed) override {}
257-
258-
scenic::Image* GetImage() override { return &image_; };
259-
260-
sk_sp<SkSurface> GetSkiaSurface() const override { return nullptr; };
247+
scenic::Session* get() override { return &session_; }
248+
void Present() override { session_.Flush(); }
261249

262250
private:
263-
scenic::Image image_;
264-
SkISize size_;
265-
};
266-
267-
class MockSurfaceProducer : public SceneUpdateContext::SurfaceProducer {
268-
public:
269-
MockSurfaceProducer(scenic::Session* session) : session_(session) {}
270-
std::unique_ptr<SceneUpdateContext::SurfaceProducerSurface> ProduceSurface(
271-
const SkISize& size,
272-
const LayerRasterCacheKey& layer_key,
273-
std::unique_ptr<scenic::EntityNode> entity_node) override {
274-
return std::make_unique<MockSurfaceProducerSurface>(session_, size);
275-
}
276-
277-
// Query a retained entity node (owned by a retained surface) for retained
278-
// rendering.
279-
bool HasRetainedNode(const LayerRasterCacheKey& key) const override {
280-
return false;
281-
}
282-
283-
scenic::EntityNode* GetRetainedNode(const LayerRasterCacheKey& key) override {
284-
return nullptr;
285-
}
286-
287-
void SubmitSurface(std::unique_ptr<SceneUpdateContext::SurfaceProducerSurface>
288-
surface) override {}
289-
290-
private:
291-
scenic::Session* session_;
251+
scenic::Session session_;
292252
};
293253

294254
struct TestContext {
@@ -297,12 +257,11 @@ struct TestContext {
297257
fml::RefPtr<fml::TaskRunner> task_runner;
298258

299259
// Session.
300-
MockSession mock_session;
301260
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener> listener_request;
302-
std::unique_ptr<scenic::Session> session;
261+
MockSession mock_session;
262+
std::unique_ptr<MockSessionWrapper> mock_session_wrapper;
303263

304264
// SceneUpdateContext.
305-
std::unique_ptr<MockSurfaceProducer> mock_surface_producer;
306265
std::unique_ptr<SceneUpdateContext> scene_update_context;
307266

308267
// PrerollContext.
@@ -324,15 +283,13 @@ std::unique_ptr<TestContext> InitTest() {
324283
fuchsia::ui::scenic::SessionListenerPtr listener;
325284
context->listener_request = listener.NewRequest();
326285
context->mock_session.Bind(session_ptr.NewRequest(), std::move(listener));
327-
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));
328288

329289
// Init SceneUpdateContext.
330-
context->mock_surface_producer =
331-
std::make_unique<MockSurfaceProducer>(context->session.get());
332290
context->scene_update_context = std::make_unique<SceneUpdateContext>(
333-
context->session.get(), context->mock_surface_producer.get());
334-
context->scene_update_context->set_metrics(
335-
fidl::MakeOptional(fuchsia::ui::gfx::Metrics{1.f, 1.f, 1.f}));
291+
"fuchsia_layer_unittest", fuchsia::ui::views::ViewToken(),
292+
scenic::ViewRefPair::New(), *(context->mock_session_wrapper));
336293

337294
// Init PrerollContext.
338295
context->preroll_context = std::unique_ptr<PrerollContext>(new PrerollContext{
@@ -348,7 +305,6 @@ std::unique_ptr<TestContext> InitTest() {
348305
context->unused_texture_registry, // texture registry (not
349306
// supported)
350307
false, // checkerboard_offscreen_layers
351-
100.f, // maximum depth allowed for rendering
352308
1.f // ratio between logical and physical
353309
});
354310

@@ -602,7 +558,7 @@ TEST_F(FuchsiaLayerTest, DISABLED_PhysicalShapeLayersAndChildSceneLayers) {
602558
// against the list above.
603559
root->UpdateScene(*(test_context->scene_update_context));
604560

605-
test_context->session->Flush();
561+
test_context->mock_session_wrapper->Present();
606562

607563
// Run loop until idle, so that the Session receives and processes
608564
// its method calls.
@@ -784,7 +740,7 @@ TEST_F(FuchsiaLayerTest, DISABLED_OpacityAndTransformLayer) {
784740
// commands against the list above.
785741
root->UpdateScene(*(test_context->scene_update_context));
786742

787-
test_context->session->Flush();
743+
test_context->mock_session_wrapper->Present();
788744

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

flow/layers/layer.cc

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -58,49 +58,24 @@ Layer::AutoPrerollSaveLayerState::~AutoPrerollSaveLayerState() {
5858
#if defined(LEGACY_FUCHSIA_EMBEDDER)
5959

6060
void Layer::CheckForChildLayerBelow(PrerollContext* context) {
61+
// If there is embedded Fuchsia content in the scene (a ChildSceneLayer),
62+
// PhysicalShapeLayers that appear above the embedded content will be turned
63+
// into their own Scenic layers.
6164
child_layer_exists_below_ = context->child_scene_layer_exists_below;
6265
if (child_layer_exists_below_) {
6366
set_needs_system_composite(true);
6467
}
6568
}
6669

6770
void Layer::UpdateScene(SceneUpdateContext& context) {
68-
// If there is embedded Fuchsia content in the scene (a ChildSceneLayer),
69-
// PhysicalShapeLayers that appear above the embedded content will be turned
70-
// into their own Scenic layers.
71-
if (child_layer_exists_below_) {
72-
float global_scenic_elevation =
73-
context.GetGlobalElevationForNextScenicLayer();
74-
float local_scenic_elevation =
75-
global_scenic_elevation - context.scenic_elevation();
76-
float z_translation = -local_scenic_elevation;
77-
78-
// Retained rendering: speedup by reusing a retained entity node if
79-
// possible. When an entity node is reused, no paint layer is added to the
80-
// frame so we won't call PhysicalShapeLayer::Paint.
81-
LayerRasterCacheKey key(unique_id(), context.Matrix());
82-
if (context.HasRetainedNode(key)) {
83-
TRACE_EVENT_INSTANT0("flutter", "retained layer cache hit");
84-
scenic::EntityNode* retained_node = context.GetRetainedNode(key);
85-
FML_DCHECK(context.top_entity());
86-
FML_DCHECK(retained_node->session() == context.session());
87-
88-
// Re-adjust the elevation.
89-
retained_node->SetTranslation(0.f, 0.f, z_translation);
90-
91-
context.top_entity()->entity_node().AddChild(*retained_node);
92-
return;
93-
}
94-
95-
TRACE_EVENT_INSTANT0("flutter", "cache miss, creating");
96-
// If we can't find an existing retained surface, create one.
97-
SceneUpdateContext::Frame frame(
98-
context, SkRRect::MakeRect(paint_bounds()), SK_ColorTRANSPARENT,
99-
SkScalarRoundToInt(context.alphaf() * 255),
100-
"flutter::PhysicalShapeLayer", z_translation, this);
101-
102-
frame.AddPaintLayer(this);
103-
}
71+
FML_DCHECK(needs_system_composite());
72+
FML_DCHECK(child_layer_exists_below_);
73+
74+
SceneUpdateContext::Frame frame(
75+
context, SkRRect::MakeRect(paint_bounds()), SK_ColorTRANSPARENT,
76+
SkScalarRoundToInt(context.alphaf() * 255), "flutter::Layer");
77+
78+
frame.AddPaintLayer(this);
10479
}
10580

10681
#endif

flow/layers/layer.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,10 @@ struct PrerollContext {
5656
const Stopwatch& ui_time;
5757
TextureRegistry& texture_registry;
5858
const bool checkerboard_offscreen_layers;
59-
60-
// These allow us to make use of the scene metrics during Preroll.
61-
float frame_physical_depth;
62-
float frame_device_pixel_ratio;
59+
const float frame_device_pixel_ratio;
6360

6461
// These allow us to track properties like elevation, opacity, and the
6562
// prescence of a platform view during Preroll.
66-
float total_elevation = 0.0f;
6763
bool has_platform_view = false;
6864
bool is_opaque = true;
6965
#if defined(LEGACY_FUCHSIA_EMBEDDER)
@@ -128,10 +124,7 @@ class Layer {
128124
TextureRegistry& texture_registry;
129125
const RasterCache* raster_cache;
130126
const bool checkerboard_offscreen_layers;
131-
132-
// These allow us to make use of the scene metrics during Paint.
133-
float frame_physical_depth;
134-
float frame_device_pixel_ratio;
127+
const float frame_device_pixel_ratio;
135128
};
136129

137130
// Calls SkCanvas::saveLayer and restores the layer upon destruction. Also

0 commit comments

Comments
 (0)