Skip to content

Commit

Permalink
Revert "fuchsia: Delete all the legacy code! (flutter#26422)" (flutte…
Browse files Browse the repository at this point in the history
…r#26637)

This reverts commit 58a4669.
  • Loading branch information
arbreng authored Jun 8, 2021
1 parent ff1003a commit 2e09b87
Show file tree
Hide file tree
Showing 71 changed files with 3,053 additions and 47 deletions.
8 changes: 8 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ config("config") {

defines = []

# This define is transitional and will be removed after the embedder API
# transition is complete.
#
# TODO(bugs.fuchsia.dev/54041): Remove when no longer necessary.
if (is_fuchsia && flutter_enable_legacy_fuchsia_embedder) {
defines += [ "LEGACY_FUCHSIA_EMBEDDER" ]
}

if (is_debug) {
defines += [ "FLUTTER_ENABLE_DIFF_CONTEXT" ]
}
Expand Down
11 changes: 11 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ FILE: ../../../flutter/flow/layers/backdrop_filter_layer.cc
FILE: ../../../flutter/flow/layers/backdrop_filter_layer.h
FILE: ../../../flutter/flow/layers/backdrop_filter_layer_unittests.cc
FILE: ../../../flutter/flow/layers/checkerboard_layertree_unittests.cc
FILE: ../../../flutter/flow/layers/child_scene_layer.cc
FILE: ../../../flutter/flow/layers/child_scene_layer.h
FILE: ../../../flutter/flow/layers/clip_path_layer.cc
FILE: ../../../flutter/flow/layers/clip_path_layer.h
FILE: ../../../flutter/flow/layers/clip_path_layer_unittests.cc
Expand All @@ -67,6 +69,7 @@ FILE: ../../../flutter/flow/layers/color_filter_layer_unittests.cc
FILE: ../../../flutter/flow/layers/container_layer.cc
FILE: ../../../flutter/flow/layers/container_layer.h
FILE: ../../../flutter/flow/layers/container_layer_unittests.cc
FILE: ../../../flutter/flow/layers/fuchsia_layer_unittests.cc
FILE: ../../../flutter/flow/layers/image_filter_layer.cc
FILE: ../../../flutter/flow/layers/image_filter_layer.h
FILE: ../../../flutter/flow/layers/image_filter_layer_unittests.cc
Expand Down Expand Up @@ -115,6 +118,8 @@ FILE: ../../../flutter/flow/raster_cache_unittests.cc
FILE: ../../../flutter/flow/rtree.cc
FILE: ../../../flutter/flow/rtree.h
FILE: ../../../flutter/flow/rtree_unittests.cc
FILE: ../../../flutter/flow/scene_update_context.cc
FILE: ../../../flutter/flow/scene_update_context.h
FILE: ../../../flutter/flow/skia_gpu_object.cc
FILE: ../../../flutter/flow/skia_gpu_object.h
FILE: ../../../flutter/flow/skia_gpu_object_unittests.cc
Expand All @@ -123,6 +128,8 @@ FILE: ../../../flutter/flow/surface.h
FILE: ../../../flutter/flow/surface_frame.cc
FILE: ../../../flutter/flow/surface_frame.h
FILE: ../../../flutter/flow/texture_unittests.cc
FILE: ../../../flutter/flow/view_holder.cc
FILE: ../../../flutter/flow/view_holder.h
FILE: ../../../flutter/flutter_frontend_server/bin/starter.dart
FILE: ../../../flutter/flutter_frontend_server/lib/server.dart
FILE: ../../../flutter/fml/ascii_trie.cc
Expand Down Expand Up @@ -309,6 +316,8 @@ FILE: ../../../flutter/lib/ui/compositing/scene.h
FILE: ../../../flutter/lib/ui/compositing/scene_builder.cc
FILE: ../../../flutter/lib/ui/compositing/scene_builder.h
FILE: ../../../flutter/lib/ui/compositing/scene_builder_unittests.cc
FILE: ../../../flutter/lib/ui/compositing/scene_host.cc
FILE: ../../../flutter/lib/ui/compositing/scene_host.h
FILE: ../../../flutter/lib/ui/dart_runtime_hooks.cc
FILE: ../../../flutter/lib/ui/dart_runtime_hooks.h
FILE: ../../../flutter/lib/ui/dart_ui.cc
Expand Down Expand Up @@ -1331,6 +1340,8 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/accessibility_bridge_unitt
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_unittest.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/compositor_context.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/compositor_context.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/default_session_connection.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/default_session_connection.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/engine.cc
Expand Down
3 changes: 3 additions & 0 deletions common/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ declare_args() {

# Whether to use the Skia text shaper module for all text rendering
flutter_always_use_skshaper = false

# Whether to use the legacy embedder when building for Fuchsia.
flutter_enable_legacy_fuchsia_embedder = true
}

# feature_defines_list ---------------------------------------------------------
Expand Down
24 changes: 24 additions & 0 deletions flow/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ source_set("flow") {
"//flutter/fml",
"//third_party/skia",
]

if (is_fuchsia && flutter_enable_legacy_fuchsia_embedder) {
sources += [
"layers/child_scene_layer.cc",
"layers/child_scene_layer.h",
"scene_update_context.cc",
"scene_update_context.h",
"view_holder.cc",
"view_holder.h",
]

public_deps = [
"$fuchsia_sdk_root/fidl:fuchsia.ui.app",
"$fuchsia_sdk_root/fidl:fuchsia.ui.gfx",
"$fuchsia_sdk_root/fidl:fuchsia.ui.views",
"$fuchsia_sdk_root/pkg:scenic_cpp",
]
}
}

if (enable_unittests) {
Expand Down Expand Up @@ -176,5 +194,11 @@ if (enable_unittests) {
# Required for M_PI and others.
defines += [ "_USE_MATH_DEFINES" ]
}

if (is_fuchsia && flutter_enable_legacy_fuchsia_embedder) {
sources += [ "layers/fuchsia_layer_unittests.cc" ]

deps += [ "//build/fuchsia/pkg:sys_cpp_testing" ]
}
}
}
3 changes: 2 additions & 1 deletion flow/layers/backdrop_filter_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ TEST_F(BackdropFilterLayerTest, PaintingEmptyLayerDies) {
parent->Preroll(preroll_context(), SkMatrix());
EXPECT_EQ(layer->paint_bounds(), kEmptyRect);
EXPECT_FALSE(layer->needs_painting(paint_context()));
EXPECT_FALSE(layer->needs_system_composite());

EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
"needs_painting\\(context\\)");
Expand Down Expand Up @@ -262,7 +263,7 @@ TEST_F(BackdropFilterLayerTest, Readback) {

// BDF with no filter blocks child with readback
auto mock_layer =
std::make_shared<MockLayer>(SkPath(), SkPaint(), false, true);
std::make_shared<MockLayer>(SkPath(), SkPaint(), false, false, true);
layer2->Add(mock_layer);
preroll_context()->surface_needs_readback = false;
layer2->Preroll(preroll_context(), initial_transform);
Expand Down
10 changes: 10 additions & 0 deletions flow/layers/checkerboard_layertree_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,12 @@ TEST_F(CheckerBoardLayerTest, PhysicalSaveLayerNotCheckBoard) {
PhysicalShapeLayer::ComputeShadowBounds(layer_path.getBounds(),
initial_elevation, 1.0f));
EXPECT_TRUE(layer->needs_painting(paint_context()));
EXPECT_FALSE(layer->needs_system_composite());
EXPECT_EQ(layer->elevation(), initial_elevation);

// The Fuchsia system compositor handles all elevated PhysicalShapeLayers and
// their shadows , so we do not use the direct |Paint()| path there.
#if !defined(LEGACY_FUCHSIA_EMBEDDER)
const SkRect paint_bounds = SkRect::MakeXYWH(0, 0, 8, 8);
const SkPaint clip_paint;
SkPaint layer_paint;
Expand All @@ -319,6 +323,7 @@ TEST_F(CheckerBoardLayerTest, PhysicalSaveLayerNotCheckBoard) {
MockCanvas::DrawCall{2, MockCanvas::DrawPaint{layer_paint}},
MockCanvas::DrawCall{2, MockCanvas::RestoreData{1}},
MockCanvas::DrawCall{1, MockCanvas::RestoreData{0}}}));
#endif
}

TEST_F(CheckerBoardLayerTest, PhysicalSaveLayerCheckBoard) {
Expand All @@ -336,8 +341,12 @@ TEST_F(CheckerBoardLayerTest, PhysicalSaveLayerCheckBoard) {
PhysicalShapeLayer::ComputeShadowBounds(layer_path.getBounds(),
initial_elevation, 1.0f));
EXPECT_TRUE(layer->needs_painting(paint_context()));
EXPECT_FALSE(layer->needs_system_composite());
EXPECT_EQ(layer->elevation(), initial_elevation);

// The Fuchsia system compositor handles all elevated PhysicalShapeLayers and
// their shadows , so we do not use the direct |Paint()| path there.
#if !defined(LEGACY_FUCHSIA_EMBEDDER)
const SkRect paint_bounds = SkRect::MakeXYWH(0, 0, 8, 8);
const SkPaint clip_paint;
SkPaint layer_paint;
Expand All @@ -358,6 +367,7 @@ TEST_F(CheckerBoardLayerTest, PhysicalSaveLayerCheckBoard) {
MockCanvas::DrawCall{2, MockCanvas::DrawPaint{layer_paint}},
MockCanvas::DrawCall{2, MockCanvas::RestoreData{1}},
MockCanvas::DrawCall{1, MockCanvas::RestoreData{0}}}));
#endif
}

#endif
Expand Down
33 changes: 33 additions & 0 deletions flow/layers/child_scene_layer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.

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

namespace flutter {

ChildSceneLayer::ChildSceneLayer(zx_koid_t layer_id,
const SkPoint& offset,
const SkSize& size,
bool hit_testable)
: layer_id_(layer_id),
offset_(offset),
size_(size),
hit_testable_(hit_testable) {}

void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
TRACE_EVENT0("flutter", "ChildSceneLayer::Preroll");

context->child_scene_layer_exists_below = true;
CheckForChildLayerBelow(context);
}

void ChildSceneLayer::Paint(PaintContext& context) const {}

void ChildSceneLayer::UpdateScene(std::shared_ptr<SceneUpdateContext> context) {
TRACE_EVENT0("flutter", "ChildSceneLayer::UpdateScene");
FML_DCHECK(needs_system_composite());
context->UpdateView(layer_id_, offset_, size_, hit_testable_);
}

} // namespace flutter
42 changes: 42 additions & 0 deletions flow/layers/child_scene_layer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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_LAYERS_CHILD_SCENE_LAYER_H_
#define FLUTTER_FLOW_LAYERS_CHILD_SCENE_LAYER_H_

#include "flutter/flow/layers/layer.h"
#include "flutter/flow/scene_update_context.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkPoint.h"
#include "third_party/skia/include/core/SkSize.h"

namespace flutter {

// Layer that represents an embedded child.
class ChildSceneLayer : public Layer {
public:
ChildSceneLayer(zx_koid_t layer_id,
const SkPoint& offset,
const SkSize& size,
bool hit_testable);
~ChildSceneLayer() override = default;

void Preroll(PrerollContext* context, const SkMatrix& matrix) override;

void Paint(PaintContext& context) const override;

void UpdateScene(std::shared_ptr<SceneUpdateContext> context) override;

private:
zx_koid_t layer_id_ = ZX_KOID_INVALID;
SkPoint offset_;
SkSize size_;
bool hit_testable_ = true;

FML_DISALLOW_COPY_AND_ASSIGN(ChildSceneLayer);
};

} // namespace flutter

#endif // FLUTTER_FLOW_LAYERS_CHILD_SCENE_LAYER_H_
17 changes: 17 additions & 0 deletions flow/layers/clip_path_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "flutter/flow/layers/clip_path_layer.h"
#include "flutter/flow/paint_utils.h"

#if defined(LEGACY_FUCHSIA_EMBEDDER)
#include "lib/ui/scenic/cpp/commands.h"
#endif

namespace flutter {

ClipPathLayer::ClipPathLayer(const SkPath& clip_path, Clip clip_behavior)
Expand Down Expand Up @@ -54,6 +58,19 @@ void ClipPathLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
context->cull_rect = previous_cull_rect;
}

#if defined(LEGACY_FUCHSIA_EMBEDDER)

void ClipPathLayer::UpdateScene(std::shared_ptr<SceneUpdateContext> context) {
TRACE_EVENT0("flutter", "ClipPathLayer::UpdateScene");
FML_DCHECK(needs_system_composite());

// TODO(liyuqian): respect clip_behavior_
SceneUpdateContext::Clip clip(context, clip_path_.getBounds());
UpdateSceneChildren(context);
}

#endif

void ClipPathLayer::Paint(PaintContext& context) const {
TRACE_EVENT0("flutter", "ClipPathLayer::Paint");
FML_DCHECK(needs_painting(context));
Expand Down
4 changes: 4 additions & 0 deletions flow/layers/clip_path_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class ClipPathLayer : public ContainerLayer {
return clip_behavior_ == Clip::antiAliasWithSaveLayer;
}

#if defined(LEGACY_FUCHSIA_EMBEDDER)
void UpdateScene(std::shared_ptr<SceneUpdateContext> context) override;
#endif

private:
SkPath clip_path_;
Clip clip_behavior_;
Expand Down
2 changes: 1 addition & 1 deletion flow/layers/clip_path_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ TEST_F(ClipPathLayerTest, Readback) {
const Clip save_layer = Clip::antiAliasWithSaveLayer;

std::shared_ptr<MockLayer> nochild;
auto reader = std::make_shared<MockLayer>(path, paint, false, true);
auto reader = std::make_shared<MockLayer>(path, paint, false, false, true);
auto nonreader = std::make_shared<MockLayer>(path, paint);

// No children, no prior readback -> no readback after
Expand Down
13 changes: 13 additions & 0 deletions flow/layers/clip_rect_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ void ClipRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
context->cull_rect = previous_cull_rect;
}

#if defined(LEGACY_FUCHSIA_EMBEDDER)

void ClipRectLayer::UpdateScene(std::shared_ptr<SceneUpdateContext> context) {
TRACE_EVENT0("flutter", "ClipRectLayer::UpdateScene");
FML_DCHECK(needs_system_composite());

// TODO(liyuqian): respect clip_behavior_
SceneUpdateContext::Clip clip(context, clip_rect_);
UpdateSceneChildren(context);
}

#endif

void ClipRectLayer::Paint(PaintContext& context) const {
TRACE_EVENT0("flutter", "ClipRectLayer::Paint");
FML_DCHECK(needs_painting(context));
Expand Down
4 changes: 4 additions & 0 deletions flow/layers/clip_rect_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class ClipRectLayer : public ContainerLayer {
return clip_behavior_ == Clip::antiAliasWithSaveLayer;
}

#if defined(LEGACY_FUCHSIA_EMBEDDER)
void UpdateScene(std::shared_ptr<SceneUpdateContext> context) override;
#endif

private:
SkRect clip_rect_;
Clip clip_behavior_;
Expand Down
2 changes: 1 addition & 1 deletion flow/layers/clip_rect_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ TEST_F(ClipRectLayerTest, Readback) {
const Clip save_layer = Clip::antiAliasWithSaveLayer;

std::shared_ptr<MockLayer> nochild;
auto reader = std::make_shared<MockLayer>(path, paint, false, true);
auto reader = std::make_shared<MockLayer>(path, paint, false, false, true);
auto nonreader = std::make_shared<MockLayer>(path, paint);

// No children, no prior readback -> no readback after
Expand Down
13 changes: 13 additions & 0 deletions flow/layers/clip_rrect_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ void ClipRRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
context->cull_rect = previous_cull_rect;
}

#if defined(LEGACY_FUCHSIA_EMBEDDER)

void ClipRRectLayer::UpdateScene(std::shared_ptr<SceneUpdateContext> context) {
TRACE_EVENT0("flutter", "ClipRRectLayer::UpdateScene");
FML_DCHECK(needs_system_composite());

// TODO(liyuqian): respect clip_behavior_
SceneUpdateContext::Clip clip(context, clip_rrect_.getBounds());
UpdateSceneChildren(context);
}

#endif

void ClipRRectLayer::Paint(PaintContext& context) const {
TRACE_EVENT0("flutter", "ClipRRectLayer::Paint");
FML_DCHECK(needs_painting(context));
Expand Down
4 changes: 4 additions & 0 deletions flow/layers/clip_rrect_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class ClipRRectLayer : public ContainerLayer {
return clip_behavior_ == Clip::antiAliasWithSaveLayer;
}

#if defined(LEGACY_FUCHSIA_EMBEDDER)
void UpdateScene(std::shared_ptr<SceneUpdateContext> context) override;
#endif

private:
SkRRect clip_rrect_;
Clip clip_behavior_;
Expand Down
2 changes: 1 addition & 1 deletion flow/layers/clip_rrect_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ TEST_F(ClipRRectLayerTest, Readback) {
const Clip save_layer = Clip::antiAliasWithSaveLayer;

std::shared_ptr<MockLayer> nochild;
auto reader = std::make_shared<MockLayer>(path, paint, false, true);
auto reader = std::make_shared<MockLayer>(path, paint, false, false, true);
auto nonreader = std::make_shared<MockLayer>(path, paint);

// No children, no prior readback -> no readback after
Expand Down
3 changes: 2 additions & 1 deletion flow/layers/color_filter_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ TEST_F(ColorFilterLayerTest, PaintingEmptyLayerDies) {
layer->Preroll(preroll_context(), SkMatrix());
EXPECT_EQ(layer->paint_bounds(), kEmptyRect);
EXPECT_FALSE(layer->needs_painting(paint_context()));
EXPECT_FALSE(layer->needs_system_composite());

EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
"needs_painting\\(context\\)");
Expand Down Expand Up @@ -206,7 +207,7 @@ TEST_F(ColorFilterLayerTest, Readback) {

// ColorFilterLayer blocks child with readback
auto mock_layer =
std::make_shared<MockLayer>(SkPath(), SkPaint(), false, true);
std::make_shared<MockLayer>(SkPath(), SkPaint(), false, false, true);
layer->Add(mock_layer);
preroll_context()->surface_needs_readback = false;
layer->Preroll(preroll_context(), initial_transform);
Expand Down
Loading

0 comments on commit 2e09b87

Please sign in to comment.