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 1 commit
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
Prev Previous commit
Next Next commit
Complete the DlPathEffect Object
  • Loading branch information
JsouLiang committed May 9, 2022
commit 9ae187694b9cd2b2daf86f23aaaf675443820036
2 changes: 2 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
50 changes: 45 additions & 5 deletions display_list/display_list_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,49 @@ 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_path_effect_ = nullptr;
Push<ClearPathEffectOp>(0, 0);
} else {
current_path_effect_ = effect->shared();
switch (current_path_effect_->type()) {
case DlPathEffectType::kCorner: {
const DlCornerPathEffect* corner_effect = effect->asCorner();
void* pod = Push<SetPodPathEffectOp>(corner_effect->size(), 0);
new (pod) DlCornerPathEffect(corner_effect);
break;
}
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::kDiscrete: {
const DlDiscretePathEffect* discrete_effect = effect->asDiscrete();
void* pod = Push<SetPodPathEffectOp>(discrete_effect->size(), 0);
new (pod) DlDiscretePathEffect(discrete_effect);
break;
}
case DlPathEffectType::kSumPathEffect: {
const DlSumPathEffect* sum_effect = effect->asSum();
void* pod = Push<SetPodPathEffectOp>(sum_effect->size(), 0);
new (pod) DlSumPathEffect(sum_effect);
break;
}
case DlPathEffectType::kComposePathEffect: {
const DlComposePathEffect* compose_effect = effect->asCompose();
void* pod = Push<SetPodPathEffectOp>(compose_effect->size(), 0);
new (pod) DlComposePathEffect(compose_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 +428,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
13 changes: 8 additions & 5 deletions display_list/display_list_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef FLUTTER_DISPLAY_LIST_DISPLAY_LIST_BUILDER_H_
#define FLUTTER_DISPLAY_LIST_DISPLAY_LIST_BUILDER_H_

#include <memory>
#include "flutter/display_list/display_list.h"
#include "flutter/display_list/display_list_blend_mode.h"
#include "flutter/display_list/display_list_comparable.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_path_effect_, 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_path_effect_;
}
std::shared_ptr<const DlMaskFilter> getMaskFilter() const {
return current_.getMaskFilter();
}
Expand Down Expand Up @@ -453,7 +456,7 @@ 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);

Expand Down
44 changes: 25 additions & 19 deletions display_list/display_list_canvas_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <memory>
#include "flutter/display_list/display_list.h"
#include "flutter/display_list/display_list_canvas_dispatcher.h"
#include "flutter/display_list/display_list_canvas_recorder.h"
Expand Down Expand Up @@ -387,13 +388,13 @@ class TestParameters {
NotEquals(ref_attr.getColorSource(), attr.getColorSource())) {
return false;
}
auto skia_path_effect = attr.getPathEffect()->skia_object();
DisplayListSpecialGeometryFlags geo_flags =
flags_.WithPathEffect(attr.getPathEffect());
flags_.WithPathEffect(skia_path_effect);
if (flags_.applies_path_effect() && //
ref_attr.getPathEffect() != attr.getPathEffect()) {
SkPathEffect::DashInfo info;
if (attr.getPathEffect()->asADash(&info) !=
SkPathEffect::kDash_DashType) {
if (skia_path_effect->asADash(&info) != SkPathEffect::kDash_DashType) {
return false;
}
if (!ignores_dashes()) {
Expand Down Expand Up @@ -1230,7 +1231,9 @@ class CanvasCompareTester {
}

{
sk_sp<SkPathEffect> effect = SkDiscretePathEffect::Make(3, 5);
std::shared_ptr<DlDiscretePathEffect> effect =
DlDiscretePathEffect::Make(3, 5);
auto skia_effect = effect->skia_object();
{
// Discrete path effects need a stroke width for drawPointsAsPoints
// to do something realistic
Expand All @@ -1249,17 +1252,18 @@ class CanvasCompareTester {
[=](SkCanvas*, SkPaint& p) {
p.setStrokeWidth(5.0);
p.setStrokeMiter(3.0);
p.setPathEffect(effect);
p.setPathEffect(skia_effect);
},
[=](DisplayListBuilder& b) {
b.setStrokeWidth(5.0);
b.setStrokeMiter(3.0);
b.setPathEffect(effect);
b.setPathEffect(effect.get());
}));
}
EXPECT_TRUE(testP.is_draw_text_blob() || effect->unique())
EXPECT_TRUE(testP.is_draw_text_blob() || skia_effect->unique())
<< "PathEffect == Discrete-3-5 Cleanup";
effect = SkDiscretePathEffect::Make(2, 3);
effect = DlDiscretePathEffect::Make(2, 3);
skia_effect = effect->skia_object();
{
// Discrete path effects need a stroke width for drawPointsAsPoints
// to do something realistic
Expand All @@ -1278,15 +1282,15 @@ class CanvasCompareTester {
[=](SkCanvas*, SkPaint& p) {
p.setStrokeWidth(5.0);
p.setStrokeMiter(2.5);
p.setPathEffect(effect);
p.setPathEffect(skia_effect);
},
[=](DisplayListBuilder& b) {
b.setStrokeWidth(5.0);
b.setStrokeMiter(2.5);
b.setPathEffect(effect);
b.setPathEffect(effect.get());
}));
}
EXPECT_TRUE(testP.is_draw_text_blob() || effect->unique())
EXPECT_TRUE(testP.is_draw_text_blob() || skia_effect->unique())
<< "PathEffect == Discrete-2-3 Cleanup";
}

Expand Down Expand Up @@ -1503,7 +1507,8 @@ 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);
auto skia_effect = effect->skia_object();
{
RenderWith(testP, stroke_base_env, tolerance,
CaseParameters(
Expand All @@ -1513,19 +1518,20 @@ 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(skia_effect);
},
[=](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())
EXPECT_TRUE(testP.is_draw_text_blob() || skia_effect->unique())
<< "PathEffect == Dash-29-2 Cleanup";
effect = SkDashPathEffect::Make(TestDashes2, 2, 0.0f);
effect = DlDashPathEffect::Make(TestDashes2, 2, 0.0f);
skia_effect = effect->skia_object();
{
RenderWith(testP, stroke_base_env, tolerance,
CaseParameters(
Expand All @@ -1535,17 +1541,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(skia_effect);
},
[=](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())
EXPECT_TRUE(testP.is_draw_text_blob() || skia_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 @@ -14,6 +14,7 @@
#include "flutter/display_list/display_list_mask_filter.h"
#include "flutter/display_list/display_list_paint.h"
#include "flutter/display_list/display_list_vertices.h"
#include "flutter/display_list/display_list_path_effect.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
3 changes: 2 additions & 1 deletion display_list/display_list_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ struct SetBlendModeOp final : DLOp {
} \
};
DEFINE_SET_CLEAR_SKREF_OP(Blender, blender)
DEFINE_SET_CLEAR_SKREF_OP(PathEffect, effect)
DEFINE_SET_CLEAR_SKREF_OP(ImageFilter, filter)
#undef DEFINE_SET_CLEAR_SKREF_OP

// Clear: 4 byte header + unused 4 byte payload uses 8 bytes
Expand Down Expand Up @@ -224,6 +224,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
16 changes: 14 additions & 2 deletions display_list/display_list_path_effect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@

namespace flutter {

std::shared_ptr<DlPathEffect> DlPathEffect::From(SkPathEffect* sk_path_effect) {
if (sk_path_effect == nullptr) {
return nullptr;
}
// There are no inspection methods for SkPathEffect so we cannot break
// the Skia filter down into a specific subclass (i.e. DlSumPathEffect or
// DlComposePathEffect).
return std::make_shared<DlUnknownPathEffect>(sk_ref_sp(sk_path_effect));
}

std::shared_ptr<DlPathEffect> DlPathEffect::MakeSum(
std::shared_ptr<DlPathEffect> first,
std::shared_ptr<DlPathEffect> second) {
return std::make_shared<DlSumPathEffect>(first, second);
return std::make_shared<DlSumPathEffect>(first->skia_object(),
second->skia_object());
}

std::shared_ptr<DlPathEffect> DlPathEffect::MakeCompose(
std::shared_ptr<DlPathEffect> outer,
std::shared_ptr<DlPathEffect> inner) {
return std::make_shared<DlComposePathEffect>(outer, inner);
return std::make_shared<DlComposePathEffect>(outer->skia_object(),
inner->skia_object());
}

} // namespace flutter
Loading