diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index c7278d1628..ac1d7935f7 100755 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -32,18 +32,18 @@ FILE: ../../../flutter/common/settings.cc FILE: ../../../flutter/common/settings.h FILE: ../../../flutter/common/task_runners.cc FILE: ../../../flutter/common/task_runners.h +FILE: ../../../flutter/display_list/display_list.cc +FILE: ../../../flutter/display_list/display_list.h +FILE: ../../../flutter/display_list/display_list_canvas.cc +FILE: ../../../flutter/display_list/display_list_canvas.h +FILE: ../../../flutter/display_list/display_list_canvas_unittests.cc +FILE: ../../../flutter/display_list/display_list_unittests.cc +FILE: ../../../flutter/display_list/display_list_utils.cc +FILE: ../../../flutter/display_list/display_list_utils.h FILE: ../../../flutter/flow/compositor_context.cc FILE: ../../../flutter/flow/compositor_context.h FILE: ../../../flutter/flow/diff_context.cc FILE: ../../../flutter/flow/diff_context.h -FILE: ../../../flutter/flow/display_list.cc -FILE: ../../../flutter/flow/display_list.h -FILE: ../../../flutter/flow/display_list_canvas.cc -FILE: ../../../flutter/flow/display_list_canvas.h -FILE: ../../../flutter/flow/display_list_canvas_unittests.cc -FILE: ../../../flutter/flow/display_list_unittests.cc -FILE: ../../../flutter/flow/display_list_utils.cc -FILE: ../../../flutter/flow/display_list_utils.h FILE: ../../../flutter/flow/embedded_view_params_unittests.cc FILE: ../../../flutter/flow/embedded_views.cc FILE: ../../../flutter/flow/embedded_views.h diff --git a/engine/src/flutter/display_list/BUILD.gn b/engine/src/flutter/display_list/BUILD.gn new file mode 100644 index 0000000000..dc9a457e7b --- /dev/null +++ b/engine/src/flutter/display_list/BUILD.gn @@ -0,0 +1,37 @@ +# 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. + +source_set("display_list") { + sources = [ + "display_list.cc", + "display_list.h", + "display_list_canvas.cc", + "display_list_canvas.h", + "display_list_utils.cc", + "display_list_utils.h", + ] + + public_deps = [ + "//flutter/fml", + "//third_party/skia", + ] +} + +# Instead of creating a new test harness for display lists, the flow_unittests +# harness includes these in its own. +source_set("unittests") { + testonly = true + + sources = [ + "display_list_canvas_unittests.cc", + "display_list_unittests.cc", + ] + + deps = [ + "//flutter/testing:testing_lib", + "//third_party/skia", + ] + + public_deps = [ ":display_list" ] +} diff --git a/engine/src/flutter/flow/display_list.cc b/engine/src/flutter/display_list/display_list.cc similarity index 99% rename from engine/src/flutter/flow/display_list.cc rename to engine/src/flutter/display_list/display_list.cc index d9e2248637..b9b6423802 100644 --- a/engine/src/flutter/flow/display_list.cc +++ b/engine/src/flutter/display_list/display_list.cc @@ -4,10 +4,9 @@ #include -#include "flutter/flow/display_list.h" -#include "flutter/flow/display_list_canvas.h" -#include "flutter/flow/display_list_utils.h" - +#include "flutter/display_list/display_list.h" +#include "flutter/display_list/display_list_canvas.h" +#include "flutter/display_list/display_list_utils.h" #include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkRSXform.h" #include "third_party/skia/include/core/SkTextBlob.h" diff --git a/engine/src/flutter/flow/display_list.h b/engine/src/flutter/display_list/display_list.h similarity index 99% rename from engine/src/flutter/flow/display_list.h rename to engine/src/flutter/display_list/display_list.h index 89c3478c23..51015a4e40 100644 --- a/engine/src/flutter/flow/display_list.h +++ b/engine/src/flutter/display_list/display_list.h @@ -7,6 +7,7 @@ #include +#include "flutter/fml/logging.h" #include "third_party/skia/include/core/SkBlender.h" #include "third_party/skia/include/core/SkBlurTypes.h" #include "third_party/skia/include/core/SkCanvas.h" @@ -19,8 +20,6 @@ #include "third_party/skia/include/core/SkShader.h" #include "third_party/skia/include/core/SkVertices.h" -#include "flutter/fml/logging.h" - // The Flutter DisplayList mechanism encapsulates a persistent sequence of // rendering operations. // diff --git a/engine/src/flutter/flow/display_list_canvas.cc b/engine/src/flutter/display_list/display_list_canvas.cc similarity index 89% rename from engine/src/flutter/flow/display_list_canvas.cc rename to engine/src/flutter/display_list/display_list_canvas.cc index eeda70d572..99e0bf20ee 100644 --- a/engine/src/flutter/flow/display_list_canvas.cc +++ b/engine/src/flutter/display_list/display_list_canvas.cc @@ -2,15 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flutter/flow/display_list_canvas.h" - -#include "flutter/flow/layers/physical_shape_layer.h" +#include "flutter/display_list/display_list_canvas.h" +#include "flutter/fml/trace_event.h" #include "third_party/skia/include/core/SkMaskFilter.h" #include "third_party/skia/include/core/SkTextBlob.h" +#include "third_party/skia/include/utils/SkShadowUtils.h" namespace flutter { +const SkScalar kLightHeight = 600; +const SkScalar kLightRadius = 800; + const SkPaint* DisplayListCanvasDispatcher::safe_paint(bool use_attributes) { if (use_attributes) { // The accumulated SkPaint object will already have incorporated @@ -217,13 +220,49 @@ void DisplayListCanvasDispatcher::drawTextBlob(const sk_sp blob, SkScalar y) { canvas_->drawTextBlob(blob, x, y, paint()); } + +SkRect DisplayListCanvasDispatcher::ComputeShadowBounds(const SkPath& path, + float elevation, + SkScalar dpr, + const SkMatrix& ctm) { + SkRect shadow_bounds(path.getBounds()); + SkShadowUtils::GetLocalBounds( + ctm, path, SkPoint3::Make(0, 0, dpr * elevation), + SkPoint3::Make(0, -1, 1), kLightRadius / kLightHeight, + SkShadowFlags::kDirectionalLight_ShadowFlag, &shadow_bounds); + return shadow_bounds; +} + +void DisplayListCanvasDispatcher::DrawShadow(SkCanvas* canvas, + const SkPath& path, + SkColor color, + float elevation, + bool transparentOccluder, + SkScalar dpr) { + const SkScalar kAmbientAlpha = 0.039f; + const SkScalar kSpotAlpha = 0.25f; + + uint32_t flags = transparentOccluder + ? SkShadowFlags::kTransparentOccluder_ShadowFlag + : SkShadowFlags::kNone_ShadowFlag; + flags |= SkShadowFlags::kDirectionalLight_ShadowFlag; + SkColor inAmbient = SkColorSetA(color, kAmbientAlpha * SkColorGetA(color)); + SkColor inSpot = SkColorSetA(color, kSpotAlpha * SkColorGetA(color)); + SkColor ambientColor, spotColor; + SkShadowUtils::ComputeTonalColors(inAmbient, inSpot, &ambientColor, + &spotColor); + SkShadowUtils::DrawShadow(canvas, path, SkPoint3::Make(0, 0, dpr * elevation), + SkPoint3::Make(0, -1, 1), + kLightRadius / kLightHeight, ambientColor, + spotColor, flags); +} + void DisplayListCanvasDispatcher::drawShadow(const SkPath& path, const SkColor color, const SkScalar elevation, bool transparent_occluder, SkScalar dpr) { - flutter::PhysicalShapeLayer::DrawShadow(canvas_, path, color, elevation, - transparent_occluder, dpr); + DrawShadow(canvas_, path, color, elevation, transparent_occluder, dpr); } DisplayListCanvasRecorder::DisplayListCanvasRecorder(const SkRect& bounds) diff --git a/engine/src/flutter/flow/display_list_canvas.h b/engine/src/flutter/display_list/display_list_canvas.h similarity index 94% rename from engine/src/flutter/flow/display_list_canvas.h rename to engine/src/flutter/display_list/display_list_canvas.h index fd813e777a..ea73b377ee 100644 --- a/engine/src/flutter/flow/display_list_canvas.h +++ b/engine/src/flutter/display_list/display_list_canvas.h @@ -5,10 +5,9 @@ #ifndef FLUTTER_FLOW_DISPLAY_LIST_CANVAS_H_ #define FLUTTER_FLOW_DISPLAY_LIST_CANVAS_H_ -#include "flutter/flow/display_list.h" -#include "flutter/flow/display_list_utils.h" +#include "flutter/display_list/display_list.h" +#include "flutter/display_list/display_list_utils.h" #include "flutter/fml/logging.h" - #include "third_party/skia/include/core/SkCanvasVirtualEnforcer.h" #include "third_party/skia/include/utils/SkNoDrawCanvas.h" @@ -117,6 +116,18 @@ class DisplayListCanvasDispatcher : public virtual Dispatcher, bool transparent_occluder, SkScalar dpr) override; + static SkRect ComputeShadowBounds(const SkPath& path, + float elevation, + SkScalar dpr, + const SkMatrix& ctm); + + static void DrawShadow(SkCanvas* canvas, + const SkPath& path, + SkColor color, + float elevation, + bool transparentOccluder, + SkScalar dpr); + private: SkCanvas* canvas_; SkPaint temp_paint_; diff --git a/engine/src/flutter/flow/display_list_canvas_unittests.cc b/engine/src/flutter/display_list/display_list_canvas_unittests.cc similarity index 99% rename from engine/src/flutter/flow/display_list_canvas_unittests.cc rename to engine/src/flutter/display_list/display_list_canvas_unittests.cc index 088bd34e98..5c279034af 100644 --- a/engine/src/flutter/flow/display_list_canvas_unittests.cc +++ b/engine/src/flutter/display_list/display_list_canvas_unittests.cc @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flutter/flow/display_list_canvas.h" -#include "flutter/flow/layers/physical_shape_layer.h" - +#include "flutter/display_list/display_list_canvas.h" +#include "flutter/fml/math.h" +#include "flutter/testing/testing.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkImageInfo.h" #include "third_party/skia/include/core/SkPath.h" @@ -20,10 +20,6 @@ #include "third_party/skia/include/effects/SkGradientShader.h" #include "third_party/skia/include/effects/SkImageFilters.h" -#include - -#include "gtest/gtest.h" - namespace flutter { namespace testing { @@ -1543,8 +1539,10 @@ class CanvasCompareTester { 0, 1, 0, RenderCenterY, // 0, 0, 1, 0, // 0, 0, .001, 1); - m44.preConcat(SkM44::Rotate({1, 0, 0}, M_PI / 60)); // 3 degrees around X - m44.preConcat(SkM44::Rotate({0, 1, 0}, M_PI / 45)); // 4 degrees around Y + m44.preConcat( + SkM44::Rotate({1, 0, 0}, math::kPi / 60)); // 3 degrees around X + m44.preConcat( + SkM44::Rotate({0, 1, 0}, math::kPi / 45)); // 4 degrees around Y m44.preTranslate(-RenderCenterX, -RenderCenterY); RenderWith( testP, env, skewed_tolerance, @@ -3021,8 +3019,8 @@ TEST_F(DisplayListCanvas, DrawShadow) { CanvasCompareTester::RenderAll( // TestParameters( [=](SkCanvas* canvas, const SkPaint& paint) { // - PhysicalShapeLayer::DrawShadow(canvas, path, color, elevation, - false, 1.0); + DisplayListCanvasDispatcher::DrawShadow(canvas, path, color, + elevation, false, 1.0); }, [=](DisplayListBuilder& builder) { // builder.drawShadow(path, color, elevation, false, 1.0); @@ -3048,8 +3046,8 @@ TEST_F(DisplayListCanvas, DrawShadowTransparentOccluder) { CanvasCompareTester::RenderAll( // TestParameters( [=](SkCanvas* canvas, const SkPaint& paint) { // - PhysicalShapeLayer::DrawShadow(canvas, path, color, elevation, true, - 1.0); + DisplayListCanvasDispatcher::DrawShadow(canvas, path, color, + elevation, true, 1.0); }, [=](DisplayListBuilder& builder) { // builder.drawShadow(path, color, elevation, true, 1.0); @@ -3075,8 +3073,8 @@ TEST_F(DisplayListCanvas, DrawShadowDpr) { CanvasCompareTester::RenderAll( // TestParameters( [=](SkCanvas* canvas, const SkPaint& paint) { // - PhysicalShapeLayer::DrawShadow(canvas, path, color, elevation, - false, 1.5); + DisplayListCanvasDispatcher::DrawShadow(canvas, path, color, + elevation, false, 1.5); }, [=](DisplayListBuilder& builder) { // builder.drawShadow(path, color, elevation, false, 1.5); diff --git a/engine/src/flutter/flow/display_list_unittests.cc b/engine/src/flutter/display_list/display_list_unittests.cc similarity index 99% rename from engine/src/flutter/flow/display_list_unittests.cc rename to engine/src/flutter/display_list/display_list_unittests.cc index cb8b7c21c4..3dc53324c2 100644 --- a/engine/src/flutter/flow/display_list_unittests.cc +++ b/engine/src/flutter/display_list/display_list_unittests.cc @@ -2,8 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flutter/flow/display_list_canvas.h" - +#include "flutter/display_list/display_list_canvas.h" +#include "flutter/fml/math.h" +#include "flutter/testing/testing.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkImageInfo.h" #include "third_party/skia/include/core/SkPath.h" @@ -19,10 +20,6 @@ #include "third_party/skia/include/effects/SkGradientShader.h" #include "third_party/skia/include/effects/SkImageFilters.h" -#include - -#include "gtest/gtest.h" - namespace flutter { namespace testing { @@ -1449,7 +1446,7 @@ TEST(DisplayList, SingleOpsMightSupportGroupOpacityWithOrWithoutBlendMode) { SkRRect::MakeRectXY({2, 2, 8, 8}, 2, 2));); RUN_TESTS(builder.drawPath( SkPath().addOval({0, 0, 10, 10}).addOval({5, 5, 15, 15}));); - RUN_TESTS(builder.drawArc({0, 0, 10, 10}, 0, M_PI, true);); + RUN_TESTS(builder.drawArc({0, 0, 10, 10}, 0, math::kPi, true);); RUN_TESTS2(builder.drawPoints(SkCanvas::kPoints_PointMode, TestPointCount, TestPoints); , false); diff --git a/engine/src/flutter/flow/display_list_utils.cc b/engine/src/flutter/display_list/display_list_utils.cc similarity index 99% rename from engine/src/flutter/flow/display_list_utils.cc rename to engine/src/flutter/display_list/display_list_utils.cc index 6fcf72cd27..af7083620f 100644 --- a/engine/src/flutter/flow/display_list_utils.cc +++ b/engine/src/flutter/display_list/display_list_utils.cc @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "flutter/display_list/display_list_utils.h" + #include #include -#include "flutter/flow/display_list_utils.h" -#include "flutter/flow/layers/physical_shape_layer.h" +#include "flutter/display_list/display_list_canvas.h" #include "flutter/fml/logging.h" - #include "third_party/skia/include/core/SkMaskFilter.h" #include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkRSXform.h" @@ -518,8 +518,8 @@ void DisplayListBoundsCalculator::drawShadow(const SkPath& path, const SkScalar elevation, bool transparent_occluder, SkScalar dpr) { - SkRect shadow_bounds = - PhysicalShapeLayer::ComputeShadowBounds(path, elevation, dpr, matrix()); + SkRect shadow_bounds = DisplayListCanvasDispatcher::ComputeShadowBounds( + path, elevation, dpr, matrix()); AccumulateRect(shadow_bounds, kDrawShadowFlags); } diff --git a/engine/src/flutter/flow/display_list_utils.h b/engine/src/flutter/display_list/display_list_utils.h similarity index 99% rename from engine/src/flutter/flow/display_list_utils.h rename to engine/src/flutter/display_list/display_list_utils.h index 434c82dab0..a70b9026b5 100644 --- a/engine/src/flutter/flow/display_list_utils.h +++ b/engine/src/flutter/display_list/display_list_utils.h @@ -7,10 +7,9 @@ #include -#include "flutter/flow/display_list.h" +#include "flutter/display_list/display_list.h" #include "flutter/fml/logging.h" #include "flutter/fml/macros.h" - #include "third_party/skia/include/core/SkMaskFilter.h" // This file contains various utility classes to ease implementing diff --git a/engine/src/flutter/flow/BUILD.gn b/engine/src/flutter/flow/BUILD.gn index 642541ee8d..9312329a31 100644 --- a/engine/src/flutter/flow/BUILD.gn +++ b/engine/src/flutter/flow/BUILD.gn @@ -12,12 +12,6 @@ source_set("flow") { "compositor_context.h", "diff_context.cc", "diff_context.h", - "display_list.cc", - "display_list.h", - "display_list_canvas.cc", - "display_list_canvas.h", - "display_list_utils.cc", - "display_list_utils.h", "embedded_views.cc", "embedded_views.h", "frame_timings.cc", @@ -89,6 +83,8 @@ source_set("flow") { "//flutter/fml", "//third_party/skia", ] + + public_deps = [ "//flutter/display_list" ] } if (enable_unittests) { @@ -125,6 +121,7 @@ if (enable_unittests) { deps = [ ":flow", "//flutter/common/graphics", + "//flutter/display_list:unittests", ] } @@ -132,8 +129,6 @@ if (enable_unittests) { testonly = true sources = [ - "display_list_canvas_unittests.cc", - "display_list_unittests.cc", "embedded_view_params_unittests.cc", "flow_run_all_unittests.cc", "flow_test_utils.cc", diff --git a/engine/src/flutter/flow/layers/checkerboard_layertree_unittests.cc b/engine/src/flutter/flow/layers/checkerboard_layertree_unittests.cc index 24b7db407b..c082066f67 100644 --- a/engine/src/flutter/flow/layers/checkerboard_layertree_unittests.cc +++ b/engine/src/flutter/flow/layers/checkerboard_layertree_unittests.cc @@ -7,6 +7,7 @@ #include "flutter/flow/layers/clip_rrect_layer.h" #include "flutter/flow/layers/physical_shape_layer.h" +#include "flutter/display_list/display_list_canvas.h" #include "flutter/flow/testing/layer_test.h" #include "flutter/flow/testing/mock_layer.h" #include "flutter/fml/macros.h" @@ -294,7 +295,7 @@ TEST_F(CheckerBoardLayerTest, PhysicalSaveLayerNotCheckBoard) { // The Fuchsia system compositor handles all elevated PhysicalShapeLayers and // their shadows , so we do not do any painting there. EXPECT_EQ(layer->paint_bounds(), - PhysicalShapeLayer::ComputeShadowBounds( + DisplayListCanvasDispatcher::ComputeShadowBounds( layer_path, initial_elevation, 1.0f, SkMatrix())); EXPECT_TRUE(layer->needs_painting(paint_context())); EXPECT_EQ(layer->elevation(), initial_elevation); @@ -333,7 +334,7 @@ TEST_F(CheckerBoardLayerTest, PhysicalSaveLayerCheckBoard) { // The Fuchsia system compositor handles all elevated PhysicalShapeLayers and // their shadows , so we do not do any painting there. EXPECT_EQ(layer->paint_bounds(), - PhysicalShapeLayer::ComputeShadowBounds( + DisplayListCanvasDispatcher::ComputeShadowBounds( layer_path, initial_elevation, 1.0f, SkMatrix())); EXPECT_TRUE(layer->needs_painting(paint_context())); EXPECT_EQ(layer->elevation(), initial_elevation); diff --git a/engine/src/flutter/flow/layers/display_list_layer.cc b/engine/src/flutter/flow/layers/display_list_layer.cc index 66f278c772..de3f832f0b 100644 --- a/engine/src/flutter/flow/layers/display_list_layer.cc +++ b/engine/src/flutter/flow/layers/display_list_layer.cc @@ -4,7 +4,7 @@ #include "flutter/flow/layers/display_list_layer.h" -#include "flutter/flow/display_list_canvas.h" +#include "flutter/display_list/display_list_canvas.h" namespace flutter { diff --git a/engine/src/flutter/flow/layers/display_list_layer.h b/engine/src/flutter/flow/layers/display_list_layer.h index cf48fc489f..347077455a 100644 --- a/engine/src/flutter/flow/layers/display_list_layer.h +++ b/engine/src/flutter/flow/layers/display_list_layer.h @@ -5,7 +5,7 @@ #ifndef FLUTTER_FLOW_LAYERS_DISPLAY_LIST_LAYER_H_ #define FLUTTER_FLOW_LAYERS_DISPLAY_LIST_LAYER_H_ -#include "flutter/flow/display_list.h" +#include "flutter/display_list/display_list.h" #include "flutter/flow/layers/layer.h" #include "flutter/flow/skia_gpu_object.h" diff --git a/engine/src/flutter/flow/layers/physical_shape_layer.cc b/engine/src/flutter/flow/layers/physical_shape_layer.cc index 8215f3d6e5..06661898cb 100644 --- a/engine/src/flutter/flow/layers/physical_shape_layer.cc +++ b/engine/src/flutter/flow/layers/physical_shape_layer.cc @@ -4,14 +4,11 @@ #include "flutter/flow/layers/physical_shape_layer.h" +#include "flutter/display_list/display_list_canvas.h" #include "flutter/flow/paint_utils.h" -#include "third_party/skia/include/utils/SkShadowUtils.h" namespace flutter { -const SkScalar kLightHeight = 600; -const SkScalar kLightRadius = 800; - PhysicalShapeLayer::PhysicalShapeLayer(SkColor color, SkColor shadow_color, float elevation, @@ -39,9 +36,9 @@ void PhysicalShapeLayer::Diff(DiffContext* context, const Layer* old_layer) { if (elevation_ == 0) { bounds = path_.getBounds(); } else { - bounds = ComputeShadowBounds(path_, elevation_, - context->frame_device_pixel_ratio(), - context->GetTransform()); + bounds = DisplayListCanvasDispatcher::ComputeShadowBounds( + path_, elevation_, context->frame_device_pixel_ratio(), + context->GetTransform()); } context->AddLayerBounds(bounds); @@ -68,7 +65,7 @@ void PhysicalShapeLayer::Preroll(PrerollContext* context, // We will draw the shadow in Paint(), so add some margin to the paint // bounds to leave space for the shadow. We fill this whole region and clip // children to it so we don't need to join the child paint bounds. - set_paint_bounds(ComputeShadowBounds( + set_paint_bounds(DisplayListCanvasDispatcher::ComputeShadowBounds( path_, elevation_, context->frame_device_pixel_ratio, matrix)); } } @@ -78,8 +75,9 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const { FML_DCHECK(needs_painting(context)); if (elevation_ != 0) { - DrawShadow(context.leaf_nodes_canvas, path_, shadow_color_, elevation_, - SkColorGetA(color_) != 0xff, context.frame_device_pixel_ratio); + DisplayListCanvasDispatcher::DrawShadow( + context.leaf_nodes_canvas, path_, shadow_color_, elevation_, + SkColorGetA(color_) != 0xff, context.frame_device_pixel_ratio); } // Call drawPath without clip if possible for better performance. @@ -126,40 +124,4 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const { } } -SkRect PhysicalShapeLayer::ComputeShadowBounds(const SkPath& path, - float elevation, - SkScalar dpr, - const SkMatrix& ctm) { - SkRect shadow_bounds(path.getBounds()); - SkShadowUtils::GetLocalBounds( - ctm, path, SkPoint3::Make(0, 0, dpr * elevation), - SkPoint3::Make(0, -1, 1), kLightRadius / kLightHeight, - SkShadowFlags::kDirectionalLight_ShadowFlag, &shadow_bounds); - return shadow_bounds; -} - -void PhysicalShapeLayer::DrawShadow(SkCanvas* canvas, - const SkPath& path, - SkColor color, - float elevation, - bool transparentOccluder, - SkScalar dpr) { - const SkScalar kAmbientAlpha = 0.039f; - const SkScalar kSpotAlpha = 0.25f; - - uint32_t flags = transparentOccluder - ? SkShadowFlags::kTransparentOccluder_ShadowFlag - : SkShadowFlags::kNone_ShadowFlag; - flags |= SkShadowFlags::kDirectionalLight_ShadowFlag; - SkColor inAmbient = SkColorSetA(color, kAmbientAlpha * SkColorGetA(color)); - SkColor inSpot = SkColorSetA(color, kSpotAlpha * SkColorGetA(color)); - SkColor ambientColor, spotColor; - SkShadowUtils::ComputeTonalColors(inAmbient, inSpot, &ambientColor, - &spotColor); - SkShadowUtils::DrawShadow(canvas, path, SkPoint3::Make(0, 0, dpr * elevation), - SkPoint3::Make(0, -1, 1), - kLightRadius / kLightHeight, ambientColor, - spotColor, flags); -} - } // namespace flutter diff --git a/engine/src/flutter/flow/layers/physical_shape_layer.h b/engine/src/flutter/flow/layers/physical_shape_layer.h index cbce4eef68..0f2b24b87f 100644 --- a/engine/src/flutter/flow/layers/physical_shape_layer.h +++ b/engine/src/flutter/flow/layers/physical_shape_layer.h @@ -17,17 +17,6 @@ class PhysicalShapeLayer : public ContainerLayer { const SkPath& path, Clip clip_behavior); - static SkRect ComputeShadowBounds(const SkPath& path, - float elevation, - SkScalar dpr, - const SkMatrix& ctm); - static void DrawShadow(SkCanvas* canvas, - const SkPath& path, - SkColor color, - float elevation, - bool transparentOccluder, - SkScalar dpr); - void Diff(DiffContext* context, const Layer* old_layer) override; void Preroll(PrerollContext* context, const SkMatrix& matrix) override; diff --git a/engine/src/flutter/flow/layers/physical_shape_layer_unittests.cc b/engine/src/flutter/flow/layers/physical_shape_layer_unittests.cc index 9a9bafb8f6..133ce35f33 100644 --- a/engine/src/flutter/flow/layers/physical_shape_layer_unittests.cc +++ b/engine/src/flutter/flow/layers/physical_shape_layer_unittests.cc @@ -4,6 +4,7 @@ #include "flutter/flow/layers/physical_shape_layer.h" +#include "flutter/display_list/display_list_canvas.h" #include "flutter/flow/testing/diff_context_test.h" #include "flutter/flow/testing/layer_test.h" #include "flutter/flow/testing/mock_layer.h" @@ -125,7 +126,7 @@ TEST_F(PhysicalShapeLayerTest, ElevationSimple) { // The Fuchsia system compositor handles all elevated PhysicalShapeLayers and // their shadows , so we do not do any painting there. EXPECT_EQ(layer->paint_bounds(), - PhysicalShapeLayer::ComputeShadowBounds( + DisplayListCanvasDispatcher::ComputeShadowBounds( layer_path, initial_elevation, 1.0f, SkMatrix())); EXPECT_TRUE(layer->needs_painting(paint_context())); EXPECT_EQ(layer->elevation(), initial_elevation); @@ -174,7 +175,7 @@ TEST_F(PhysicalShapeLayerTest, ElevationComplex) { // PhysicalShapeLayers and their shadows , so we do not do any painting // there. EXPECT_EQ(layers[i]->paint_bounds(), - (PhysicalShapeLayer::ComputeShadowBounds( + (DisplayListCanvasDispatcher::ComputeShadowBounds( layer_path, initial_elevations[i], 1.0f /* pixel_ratio */, SkMatrix()))); EXPECT_TRUE(layers[i]->needs_painting(paint_context())); @@ -210,14 +211,14 @@ TEST_F(PhysicalShapeLayerTest, ShadowNotDependsCtm) { path.addRect(0, 0, 8, 8).close(); for (SkScalar elevation : elevations) { - SkRect baseline_bounds = PhysicalShapeLayer::ComputeShadowBounds( + SkRect baseline_bounds = DisplayListCanvasDispatcher::ComputeShadowBounds( path, elevation, 1.0f, SkMatrix()); for (SkScalar scale : scales) { for (SkScalar translateX : translates) { for (SkScalar translateY : translates) { SkMatrix ctm; ctm.setScaleTranslate(scale, scale, translateX, translateY); - SkRect bounds = PhysicalShapeLayer::ComputeShadowBounds( + SkRect bounds = DisplayListCanvasDispatcher::ComputeShadowBounds( path, elevation, scale, ctm); EXPECT_FLOAT_EQ(bounds.fLeft, baseline_bounds.fLeft); EXPECT_FLOAT_EQ(bounds.fTop, baseline_bounds.fTop); @@ -274,14 +275,14 @@ TEST_F(PhysicalShapeLayerTest, ShadowNotDependsPathSize) { [=](SkCanvas* canvas) { SkPath path; path.addRect(test_case[0]).close(); - PhysicalShapeLayer::DrawShadow(canvas, path, SK_ColorBLACK, - 1.0f, false, 1.0f); + DisplayListCanvasDispatcher::DrawShadow( + canvas, path, SK_ColorBLACK, 1.0f, false, 1.0f); }, [=](SkCanvas* canvas) { SkPath path; path.addRect(test_case[1]).close(); - PhysicalShapeLayer::DrawShadow(canvas, path, SK_ColorBLACK, - 1.0f, false, 1.0f); + DisplayListCanvasDispatcher::DrawShadow( + canvas, path, SK_ColorBLACK, 1.0f, false, 1.0f); }, SkSize::Make(100, 100)), 0); diff --git a/engine/src/flutter/flow/raster_cache.h b/engine/src/flutter/flow/raster_cache.h index bcc88cbec8..b6206d35a4 100644 --- a/engine/src/flutter/flow/raster_cache.h +++ b/engine/src/flutter/flow/raster_cache.h @@ -8,7 +8,7 @@ #include #include -#include "flutter/flow/display_list.h" +#include "flutter/display_list/display_list.h" #include "flutter/flow/raster_cache_key.h" #include "flutter/fml/macros.h" #include "flutter/fml/memory/weak_ptr.h" diff --git a/engine/src/flutter/flow/raster_cache_unittests.cc b/engine/src/flutter/flow/raster_cache_unittests.cc index e7c48c2730..5428b76604 100644 --- a/engine/src/flutter/flow/raster_cache_unittests.cc +++ b/engine/src/flutter/flow/raster_cache_unittests.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flutter/flow/display_list.h" +#include "flutter/display_list/display_list.h" #include "flutter/flow/raster_cache.h" #include "flutter/flow/testing/mock_raster_cache.h" diff --git a/engine/src/flutter/lib/ui/BUILD.gn b/engine/src/flutter/lib/ui/BUILD.gn index fdb56caa54..22fb82dc0a 100644 --- a/engine/src/flutter/lib/ui/BUILD.gn +++ b/engine/src/flutter/lib/ui/BUILD.gn @@ -138,6 +138,7 @@ source_set("ui") { deps = [ "//flutter/assets", "//flutter/common", + "//flutter/display_list", "//flutter/fml", "//flutter/runtime:test_font", "//flutter/third_party/tonic", diff --git a/engine/src/flutter/lib/ui/painting/canvas.cc b/engine/src/flutter/lib/ui/painting/canvas.cc index 6e31a060ca..adc13a8c9e 100644 --- a/engine/src/flutter/lib/ui/painting/canvas.cc +++ b/engine/src/flutter/lib/ui/painting/canvas.cc @@ -661,7 +661,7 @@ void Canvas::drawShadow(const CanvasPath* path, builder()->drawShadow(path->path(), color, elevation, transparentOccluder, dpr); } else if (canvas_) { - flutter::PhysicalShapeLayer::DrawShadow( + DisplayListCanvasDispatcher::DrawShadow( canvas_, path->path(), color, elevation, transparentOccluder, dpr); } } diff --git a/engine/src/flutter/lib/ui/painting/paint.h b/engine/src/flutter/lib/ui/painting/paint.h index 63943003ef..4f3ea749ee 100644 --- a/engine/src/flutter/lib/ui/painting/paint.h +++ b/engine/src/flutter/lib/ui/painting/paint.h @@ -5,11 +5,10 @@ #ifndef FLUTTER_LIB_UI_PAINTING_PAINT_H_ #define FLUTTER_LIB_UI_PAINTING_PAINT_H_ +#include "flutter/display_list/display_list.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/tonic/converter/dart_converter.h" -#include "flow/display_list.h" - namespace flutter { class Paint { diff --git a/engine/src/flutter/lib/ui/painting/picture.h b/engine/src/flutter/lib/ui/painting/picture.h index 8752cc83bd..046168baac 100644 --- a/engine/src/flutter/lib/ui/painting/picture.h +++ b/engine/src/flutter/lib/ui/painting/picture.h @@ -5,7 +5,7 @@ #ifndef FLUTTER_LIB_UI_PAINTING_PICTURE_H_ #define FLUTTER_LIB_UI_PAINTING_PICTURE_H_ -#include "flutter/flow/display_list.h" +#include "flutter/display_list/display_list.h" #include "flutter/flow/skia_gpu_object.h" #include "flutter/lib/ui/dart_wrapper.h" #include "flutter/lib/ui/painting/image.h" diff --git a/engine/src/flutter/lib/ui/painting/picture_recorder.h b/engine/src/flutter/lib/ui/painting/picture_recorder.h index 7d2303284d..d46f1437bc 100644 --- a/engine/src/flutter/lib/ui/painting/picture_recorder.h +++ b/engine/src/flutter/lib/ui/painting/picture_recorder.h @@ -5,7 +5,7 @@ #ifndef FLUTTER_LIB_UI_PAINTING_PICTURE_RECORDER_H_ #define FLUTTER_LIB_UI_PAINTING_PICTURE_RECORDER_H_ -#include "flutter/flow/display_list_canvas.h" +#include "flutter/display_list/display_list_canvas.h" #include "flutter/lib/ui/dart_wrapper.h" #include "third_party/skia/include/core/SkPictureRecorder.h"