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

Commit 47c1c61

Browse files
authored
Revert "fuchsia: Remove dead code / break dependencies (#19396)" (#20302)
This reverts commit 12a3747.
1 parent f55b95a commit 47c1c61

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

+1829
-869
lines changed

flow/layers/child_scene_layer.cc

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

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

7+
#include "flutter/flow/view_holder.h"
8+
79
namespace flutter {
810

911
ChildSceneLayer::ChildSceneLayer(zx_koid_t layer_id,
@@ -17,10 +19,12 @@ ChildSceneLayer::ChildSceneLayer(zx_koid_t layer_id,
1719

1820
void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
1921
TRACE_EVENT0("flutter", "ChildSceneLayer::Preroll");
22+
set_needs_system_composite(true);
2023

21-
context->child_scene_layer_exists_below = true;
2224
CheckForChildLayerBelow(context);
2325

26+
context->child_scene_layer_exists_below = true;
27+
2428
// An alpha "hole punch" is required if the frame behind us is not opaque.
2529
if (!context->is_opaque) {
2630
set_paint_bounds(
@@ -45,7 +49,15 @@ void ChildSceneLayer::Paint(PaintContext& context) const {
4549
void ChildSceneLayer::UpdateScene(SceneUpdateContext& context) {
4650
TRACE_EVENT0("flutter", "ChildSceneLayer::UpdateScene");
4751
FML_DCHECK(needs_system_composite());
48-
context.UpdateView(layer_id_, offset_, size_, hit_testable_);
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_);
4961
}
5062

5163
} // namespace flutter

flow/layers/container_layer.cc

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

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

7-
#include <optional>
8-
97
namespace flutter {
108

119
ContainerLayer::ContainerLayer() {}
@@ -32,9 +30,6 @@ void ContainerLayer::PrerollChildren(PrerollContext* context,
3230
const SkMatrix& child_matrix,
3331
SkRect* child_paint_bounds) {
3432
#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.
3833
child_layer_exists_below_ = context->child_scene_layer_exists_below;
3934
context->child_scene_layer_exists_below = false;
4035
#endif
@@ -103,20 +98,63 @@ void ContainerLayer::UpdateScene(SceneUpdateContext& context) {
10398
}
10499

105100
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+
106111
FML_DCHECK(needs_system_composite());
107112

108-
std::optional<SceneUpdateContext::Frame> frame;
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.
109116
if (child_layer_exists_below_) {
110-
frame.emplace(
111-
context, SkRRect::MakeRect(paint_bounds()), SK_ColorTRANSPARENT,
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);
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;
119138
}
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(
143+
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();
120158
}
121159
}
122160

flow/layers/fuchsia_layer_unittests.cc

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

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

247-
scenic::Session* get() override { return &session_; }
248-
void Present() override { session_.Flush(); }
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; };
249261

250262
private:
251-
scenic::Session session_;
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_;
252292
};
253293

254294
struct TestContext {
@@ -257,11 +297,12 @@ struct TestContext {
257297
fml::RefPtr<fml::TaskRunner> task_runner;
258298

259299
// Session.
260-
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener> listener_request;
261300
MockSession mock_session;
262-
std::unique_ptr<MockSessionWrapper> mock_session_wrapper;
301+
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener> listener_request;
302+
std::unique_ptr<scenic::Session> session;
263303

264304
// SceneUpdateContext.
305+
std::unique_ptr<MockSurfaceProducer> mock_surface_producer;
265306
std::unique_ptr<SceneUpdateContext> scene_update_context;
266307

267308
// PrerollContext.
@@ -283,13 +324,15 @@ std::unique_ptr<TestContext> InitTest() {
283324
fuchsia::ui::scenic::SessionListenerPtr listener;
284325
context->listener_request = listener.NewRequest();
285326
context->mock_session.Bind(session_ptr.NewRequest(), std::move(listener));
286-
context->mock_session_wrapper =
287-
std::make_unique<MockSessionWrapper>(std::move(session_ptr));
327+
context->session = std::make_unique<scenic::Session>(std::move(session_ptr));
288328

289329
// Init SceneUpdateContext.
330+
context->mock_surface_producer =
331+
std::make_unique<MockSurfaceProducer>(context->session.get());
290332
context->scene_update_context = std::make_unique<SceneUpdateContext>(
291-
"fuchsia_layer_unittest", fuchsia::ui::views::ViewToken(),
292-
scenic::ViewRefPair::New(), *(context->mock_session_wrapper));
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}));
293336

294337
// Init PrerollContext.
295338
context->preroll_context = std::unique_ptr<PrerollContext>(new PrerollContext{
@@ -305,6 +348,7 @@ std::unique_ptr<TestContext> InitTest() {
305348
context->unused_texture_registry, // texture registry (not
306349
// supported)
307350
false, // checkerboard_offscreen_layers
351+
100.f, // maximum depth allowed for rendering
308352
1.f // ratio between logical and physical
309353
});
310354

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

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

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

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

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

flow/layers/layer.cc

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,49 @@ 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.
6461
child_layer_exists_below_ = context->child_scene_layer_exists_below;
6562
if (child_layer_exists_below_) {
6663
set_needs_system_composite(true);
6764
}
6865
}
6966

7067
void Layer::UpdateScene(SceneUpdateContext& context) {
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);
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+
}
79104
}
80105

81106
#endif

flow/layers/layer.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ struct PrerollContext {
5656
const Stopwatch& ui_time;
5757
TextureRegistry& texture_registry;
5858
const bool checkerboard_offscreen_layers;
59-
const float frame_device_pixel_ratio;
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;
6063

6164
// These allow us to track properties like elevation, opacity, and the
6265
// prescence of a platform view during Preroll.
66+
float total_elevation = 0.0f;
6367
bool has_platform_view = false;
6468
bool is_opaque = true;
6569
#if defined(LEGACY_FUCHSIA_EMBEDDER)
@@ -124,7 +128,10 @@ class Layer {
124128
TextureRegistry& texture_registry;
125129
const RasterCache* raster_cache;
126130
const bool checkerboard_offscreen_layers;
127-
const float frame_device_pixel_ratio;
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;
128135
};
129136

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

0 commit comments

Comments
 (0)