Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ FILE: ../../../flutter/display_list/display_list_ops.h
FILE: ../../../flutter/display_list/display_list_paint.cc
FILE: ../../../flutter/display_list/display_list_paint.h
FILE: ../../../flutter/display_list/display_list_paint_unittests.cc
FILE: ../../../flutter/display_list/display_list_path_effect.cc
FILE: ../../../flutter/display_list/display_list_path_effect.h
FILE: ../../../flutter/display_list/display_list_path_effect_unittests.cc
FILE: ../../../flutter/display_list/display_list_test_utils.cc
FILE: ../../../flutter/display_list/display_list_test_utils.h
FILE: ../../../flutter/display_list/display_list_tile_mode.h
Expand Down
3 changes: 3 additions & 0 deletions display_list/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ source_set("display_list") {
"display_list_ops.h",
"display_list_paint.cc",
"display_list_paint.h",
"display_list_path_effect.cc",
"display_list_path_effect.h",
"display_list_tile_mode.h",
"display_list_utils.cc",
"display_list_utils.h",
Expand Down Expand Up @@ -94,6 +96,7 @@ if (enable_unittests) {
"display_list_image_filter_unittests.cc",
"display_list_mask_filter_unittests.cc",
"display_list_paint_unittests.cc",
"display_list_path_effect_unittests.cc",
"display_list_unittests.cc",
"display_list_vertices_unittests.cc",
]
Expand Down
4 changes: 3 additions & 1 deletion display_list/display_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ namespace flutter {
\
V(SetBlender) \
V(ClearBlender) \
V(SetPathEffect) \
\
V(SetSkPathEffect) \
V(SetPodPathEffect) \
V(ClearPathEffect) \
\
V(ClearColorFilter) \
Expand Down
26 changes: 21 additions & 5 deletions display_list/display_list_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,25 @@ void DisplayListBuilder::onSetColorFilter(const DlColorFilter* filter) {
}
UpdateCurrentOpacityCompatibility();
}
void DisplayListBuilder::onSetPathEffect(sk_sp<SkPathEffect> effect) {
(current_path_effect_ = effect) //
? Push<SetPathEffectOp>(0, 0, std::move(effect))
: Push<ClearPathEffectOp>(0, 0);
void DisplayListBuilder::onSetPathEffect(const DlPathEffect* effect) {
if (effect == nullptr) {
current_.setPathEffect(nullptr);
Push<ClearPathEffectOp>(0, 0);
} else {
current_.setPathEffect(effect->shared());
switch (effect->type()) {
case DlPathEffectType::kDash: {
const DlDashPathEffect* dash_effect = effect->asDash();
void* pod = Push<SetPodPathEffectOp>(dash_effect->size(), 0);
new (pod) DlDashPathEffect(dash_effect);
break;
}
case DlPathEffectType::kUnknown: {
Push<SetSkPathEffectOp>(0, 0, effect->skia_object());
break;
}
}
}
}
void DisplayListBuilder::onSetMaskFilter(const DlMaskFilter* filter) {
if (filter == nullptr) {
Expand Down Expand Up @@ -389,7 +404,8 @@ void DisplayListBuilder::setAttributesFromPaint(
setImageFilter(DlImageFilter::From(paint.getImageFilter()).get());
}
if (flags.applies_path_effect()) {
setPathEffect(sk_ref_sp(paint.getPathEffect()));
SkPathEffect* path_effect = paint.getPathEffect();
setPathEffect(DlPathEffect::From(path_effect).get());
}
if (flags.applies_mask_filter()) {
SkMaskFilter* mask_filter = paint.getMaskFilter();
Expand Down
14 changes: 8 additions & 6 deletions display_list/display_list_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "flutter/display_list/display_list_flags.h"
#include "flutter/display_list/display_list_image.h"
#include "flutter/display_list/display_list_paint.h"
#include "flutter/display_list/display_list_path_effect.h"
#include "flutter/display_list/types.h"
#include "flutter/fml/macros.h"

Expand Down Expand Up @@ -102,9 +103,9 @@ class DisplayListBuilder final : public virtual Dispatcher,
onSetColorFilter(filter);
}
}
void setPathEffect(sk_sp<SkPathEffect> effect) override {
if (current_path_effect_ != effect) {
onSetPathEffect(std::move(effect));
void setPathEffect(const DlPathEffect* effect) override {
if (NotEquals(current_.getPathEffect(), effect)) {
onSetPathEffect(effect);
}
}
void setMaskFilter(const DlMaskFilter* filter) override {
Expand Down Expand Up @@ -139,7 +140,9 @@ class DisplayListBuilder final : public virtual Dispatcher,
return current_blender_ ? current_blender_
: SkBlender::Mode(ToSk(current_.getBlendMode()));
}
sk_sp<SkPathEffect> getPathEffect() const { return current_path_effect_; }
std::shared_ptr<const DlPathEffect> getPathEffect() const {
return current_.getPathEffect();
}
std::shared_ptr<const DlMaskFilter> getMaskFilter() const {
return current_.getMaskFilter();
}
Expand Down Expand Up @@ -453,14 +456,13 @@ class DisplayListBuilder final : public virtual Dispatcher,
void onSetColorSource(const DlColorSource* source);
void onSetImageFilter(const DlImageFilter* filter);
void onSetColorFilter(const DlColorFilter* filter);
void onSetPathEffect(sk_sp<SkPathEffect> effect);
void onSetPathEffect(const DlPathEffect* effect);
void onSetMaskFilter(const DlMaskFilter* filter);
void onSetMaskBlurFilter(SkBlurStyle style, SkScalar sigma);

DlPaint current_;
// If |current_blender_| is set then ignore |current_.getBlendMode()|
sk_sp<SkBlender> current_blender_;
sk_sp<SkPathEffect> current_path_effect_;
};

} // namespace flutter
Expand Down
31 changes: 14 additions & 17 deletions display_list/display_list_canvas_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,12 @@ class TestParameters {
NotEquals(ref_attr.getColorSource(), attr.getColorSource())) {
return false;
}

DisplayListSpecialGeometryFlags geo_flags =
flags_.WithPathEffect(attr.getPathEffect());
flags_.WithPathEffect(attr.getPathEffect().get());
if (flags_.applies_path_effect() && //
ref_attr.getPathEffect() != attr.getPathEffect()) {
SkPathEffect::DashInfo info;
if (attr.getPathEffect()->asADash(&info) !=
SkPathEffect::kDash_DashType) {
if (attr.getPathEffect()->asDash() == nullptr) {
return false;
}
if (!ignores_dashes()) {
Expand Down Expand Up @@ -484,8 +483,10 @@ class TestParameters {
adjust =
half_width * paint.getStrokeMiter() + tolerance.discrete_offset();
}
auto paint_effect = paint.refPathEffect();

DisplayListSpecialGeometryFlags geo_flags =
flags_.WithPathEffect(paint.refPathEffect());
flags_.WithPathEffect(DlPathEffect::From(paint.refPathEffect()).get());
if (paint.getStrokeCap() == SkPaint::kButt_Cap &&
!geo_flags.butt_cap_becomes_square()) {
adjust = std::max(adjust, half_width);
Expand Down Expand Up @@ -1254,7 +1255,7 @@ class CanvasCompareTester {
[=](DisplayListBuilder& b) {
b.setStrokeWidth(5.0);
b.setStrokeMiter(3.0);
b.setPathEffect(effect);
b.setPathEffect(DlPathEffect::From(effect).get());
}));
}
EXPECT_TRUE(testP.is_draw_text_blob() || effect->unique())
Expand Down Expand Up @@ -1283,7 +1284,7 @@ class CanvasCompareTester {
[=](DisplayListBuilder& b) {
b.setStrokeWidth(5.0);
b.setStrokeMiter(2.5);
b.setPathEffect(effect);
b.setPathEffect(DlPathEffect::From(effect).get());
}));
}
EXPECT_TRUE(testP.is_draw_text_blob() || effect->unique())
Expand Down Expand Up @@ -1503,7 +1504,7 @@ class CanvasCompareTester {
{
const SkScalar TestDashes1[] = {29.0, 2.0};
const SkScalar TestDashes2[] = {17.0, 1.5};
sk_sp<SkPathEffect> effect = SkDashPathEffect::Make(TestDashes1, 2, 0.0f);
auto effect = DlDashPathEffect::Make(TestDashes1, 2, 0.0f);
{
RenderWith(testP, stroke_base_env, tolerance,
CaseParameters(
Expand All @@ -1513,19 +1514,17 @@ class CanvasCompareTester {
p.setStyle(SkPaint::kStroke_Style);
// Provide some non-trivial stroke size to get dashed
p.setStrokeWidth(5.0);
p.setPathEffect(effect);
p.setPathEffect(effect->skia_object());
},
[=](DisplayListBuilder& b) {
// Need stroke style to see dashing properly
b.setStyle(DlDrawStyle::kStroke);
// Provide some non-trivial stroke size to get dashed
b.setStrokeWidth(5.0);
b.setPathEffect(effect);
b.setPathEffect(effect.get());
}));
}
EXPECT_TRUE(testP.is_draw_text_blob() || effect->unique())
<< "PathEffect == Dash-29-2 Cleanup";
effect = SkDashPathEffect::Make(TestDashes2, 2, 0.0f);
effect = DlDashPathEffect::Make(TestDashes2, 2, 0.0f);
{
RenderWith(testP, stroke_base_env, tolerance,
CaseParameters(
Expand All @@ -1535,18 +1534,16 @@ class CanvasCompareTester {
p.setStyle(SkPaint::kStroke_Style);
// Provide some non-trivial stroke size to get dashed
p.setStrokeWidth(5.0);
p.setPathEffect(effect);
p.setPathEffect(effect->skia_object());
},
[=](DisplayListBuilder& b) {
// Need stroke style to see dashing properly
b.setStyle(DlDrawStyle::kStroke);
// Provide some non-trivial stroke size to get dashed
b.setStrokeWidth(5.0);
b.setPathEffect(effect);
b.setPathEffect(effect.get());
}));
}
EXPECT_TRUE(testP.is_draw_text_blob() || effect->unique())
<< "PathEffect == Dash-17-1.5 Cleanup";
}
}

Expand Down
2 changes: 1 addition & 1 deletion display_list/display_list_complexity_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ComplexityCalculatorHelper
void setColorSource(const DlColorSource* source) override {}
void setImageFilter(const DlImageFilter* filter) override {}
void setColorFilter(const DlColorFilter* filter) override {}
void setPathEffect(sk_sp<SkPathEffect> effect) override {}
void setPathEffect(const DlPathEffect* effect) override {}
void setMaskFilter(const DlMaskFilter* filter) override {}

void save() override {}
Expand Down
3 changes: 2 additions & 1 deletion display_list/display_list_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "flutter/display_list/display_list_image_filter.h"
#include "flutter/display_list/display_list_mask_filter.h"
#include "flutter/display_list/display_list_paint.h"
#include "flutter/display_list/display_list_path_effect.h"
#include "flutter/display_list/display_list_vertices.h"

namespace flutter {
Expand Down Expand Up @@ -52,7 +53,7 @@ class Dispatcher {
virtual void setInvertColors(bool invert) = 0;
virtual void setBlendMode(DlBlendMode mode) = 0;
virtual void setBlender(sk_sp<SkBlender> blender) = 0;
virtual void setPathEffect(sk_sp<SkPathEffect> effect) = 0;
virtual void setPathEffect(const DlPathEffect* effect) = 0;
virtual void setMaskFilter(const DlMaskFilter* filter) = 0;
virtual void setImageFilter(const DlImageFilter* filter) = 0;

Expand Down
23 changes: 21 additions & 2 deletions display_list/display_list_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,28 @@
// found in the LICENSE file.

#include "flutter/display_list/display_list_flags.h"

#include "flutter/display_list/display_list_path_effect.h"
namespace flutter {

// Just exists to ensure that the header can be cleanly imported.
const DisplayListSpecialGeometryFlags DisplayListAttributeFlags::WithPathEffect(
const DlPathEffect* effect) const {
if (is_geometric() && effect) {
if (effect->asDash()) {
// A dash effect has a very simple impact. It cannot introduce any
// miter joins that weren't already present in the original path
// and it does not grow the bounds of the path, but it can add
// end caps to areas that might not have had them before so all
// we need to do is to indicate the potential for diagonal
// end caps and move on.
return special_flags_.with(kMayHaveCaps_ | kMayHaveDiagonalCaps_);
} else {
// An arbitrary path effect can introduce joins at an arbitrary
// angle and may change the geometry of the end caps
return special_flags_.with(kMayHaveCaps_ | kMayHaveDiagonalCaps_ |
kMayHaveJoins_ | kMayHaveAcuteJoins_);
}
}
return special_flags_;
}

} // namespace flutter
22 changes: 2 additions & 20 deletions display_list/display_list_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace flutter {

class DlPathEffect;
/// The base class for the classes that maintain a list of
/// attributes that might be important for a number of operations
/// including which rendering attributes need to be set before
Expand Down Expand Up @@ -159,26 +160,7 @@ class DisplayListSpecialGeometryFlags : DisplayListFlagsBase {
class DisplayListAttributeFlags : DisplayListFlagsBase {
public:
const DisplayListSpecialGeometryFlags WithPathEffect(
sk_sp<SkPathEffect> effect) const {
if (is_geometric() && effect) {
SkPathEffect::DashInfo info;
if (effect->asADash(&info) == SkPathEffect::kDash_DashType) {
// A dash effect has a very simple impact. It cannot introduce any
// miter joins that weren't already present in the original path
// and it does not grow the bounds of the path, but it can add
// end caps to areas that might not have had them before so all
// we need to do is to indicate the potential for diagonal
// end caps and move on.
return special_flags_.with(kMayHaveCaps_ | kMayHaveDiagonalCaps_);
} else {
// An arbitrary path effect can introduce joins at an arbitrary
// angle and may change the geometry of the end caps
return special_flags_.with(kMayHaveCaps_ | kMayHaveDiagonalCaps_ |
kMayHaveJoins_ | kMayHaveAcuteJoins_);
}
}
return special_flags_;
}
const DlPathEffect* effect) const;

bool ignores_paint() const { return has_any(kIgnoresPaint_); }

Expand Down
2 changes: 1 addition & 1 deletion display_list/display_list_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ struct SetBlendModeOp final : DLOp {
} \
};
DEFINE_SET_CLEAR_SKREF_OP(Blender, blender)
DEFINE_SET_CLEAR_SKREF_OP(PathEffect, effect)
#undef DEFINE_SET_CLEAR_SKREF_OP

// Clear: 4 byte header + unused 4 byte payload uses 8 bytes
Expand Down Expand Up @@ -224,6 +223,7 @@ DEFINE_SET_CLEAR_DLATTR_OP(ColorFilter, ColorFilter, filter)
DEFINE_SET_CLEAR_DLATTR_OP(ImageFilter, ImageFilter, filter)
DEFINE_SET_CLEAR_DLATTR_OP(MaskFilter, MaskFilter, filter)
DEFINE_SET_CLEAR_DLATTR_OP(ColorSource, Shader, source)
DEFINE_SET_CLEAR_DLATTR_OP(PathEffect, PathEffect, effect)
#undef DEFINE_SET_CLEAR_DLATTR_OP

// 4 byte header + 80 bytes for the embedded DlImageColorSource
Expand Down
13 changes: 12 additions & 1 deletion display_list/display_list_paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#ifndef FLUTTER_DISPLAY_LIST_DISPLAY_LIST_PAINT_H_
#define FLUTTER_DISPLAY_LIST_DISPLAY_LIST_PAINT_H_

#include <memory>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

#include "flutter/display_list/display_list_blend_mode.h"
#include "flutter/display_list/display_list_color.h"
#include "flutter/display_list/display_list_color_filter.h"
#include "flutter/display_list/display_list_color_source.h"
#include "flutter/display_list/display_list_image_filter.h"
#include "flutter/display_list/display_list_mask_filter.h"
#include "flutter/display_list/display_list_path_effect.h"

namespace flutter {

Expand Down Expand Up @@ -199,6 +201,15 @@ class DlPaint {
return *this;
}

std::shared_ptr<const DlPathEffect> getPathEffect() const {
return pathEffect_;
}
const DlPathEffect* getPathEffectPtr() const { return pathEffect_.get(); }
DlPaint& setPathEffect(std::shared_ptr<DlPathEffect> pathEffect) {
pathEffect_ = pathEffect;
return *this;
}

bool operator==(DlPaint const& other) const;
bool operator!=(DlPaint const& other) const { return !(*this == other); }

Expand Down Expand Up @@ -236,8 +247,8 @@ class DlPaint {
std::shared_ptr<const DlColorFilter> colorFilter_;
std::shared_ptr<const DlImageFilter> imageFilter_;
std::shared_ptr<const DlMaskFilter> maskFilter_;
std::shared_ptr<const DlPathEffect> pathEffect_;
// missing (as compared to SkPaint):
// DlPathEffect - waiting for https://github.com/flutter/engine/pull/32159
// DlBlender - not planning on using that object in a pure DisplayList world
};

Expand Down
Loading