Skip to content

Commit

Permalink
Tweak based on Jim's suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
matanlurey committed Aug 15, 2023
1 parent a1e1fe7 commit af290e9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion display_list/dl_paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class DlPaint {
// TODO(matanl): Remove this flag when the Skia backend is removed,
// https://github.com/flutter/flutter/issues/112498.
bool isDitherHintForSkBackend() const {
return colorSource_ ? colorSource_->isDitherHintForSkBackend() : false;
return colorSource_ ? colorSource_->isGradient() : false;
}

bool isInvertColors() const { return isInvertColors_; }
Expand Down
9 changes: 3 additions & 6 deletions display_list/effects/dl_color_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,14 @@ class DlColorSource : public DlAttribute<DlColorSource, DlColorSourceType> {
virtual bool isUIThreadSafe() const = 0;

//----------------------------------------------------------------------------
/// @brief If the underlying platform data should have dithering
/// applied to it (if requested), this method returns true.
/// In practice, this is only true for gradients and is only
/// used by the Skia backend.
/// @brief If the underlying platform data represents a gradient.
///
/// TODO(matanl): Remove this flag when the Skia backend is
/// removed, https://github.com/flutter/flutter/issues/112498.
///
/// @return True if the class represents the output of a gradient.
///
virtual bool isDitherHintForSkBackend() const { return false; }
virtual bool isGradient() const { return false; }

// Return a DlColorColorSource pointer to this object iff it is an Color
// type of ColorSource, otherwise return nullptr.
Expand Down Expand Up @@ -300,7 +297,7 @@ class DlGradientColorSourceBase : public DlMatrixColorSourceBase {
return true;
}

bool isDitherHintForSkBackend() const override { return true; }
bool isGradient() const override { return true; }

DlTileMode tile_mode() const { return mode_; }
int stop_count() const { return stop_count_; }
Expand Down
25 changes: 13 additions & 12 deletions display_list/skia/dl_sk_canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ SkPaint ToSk(const DlPaint& paint, bool force_stroke) {
SkPaint sk_paint;

sk_paint.setAntiAlias(paint.isAntiAlias());

// On the Impeller backend, we will only support dithering of *gradients*,
// and it will be enabled by default (without the option to disable it). Until
// Skia support is completely removed, we only want to respect the dither flag
// for gradients (otherwise it will also apply to, for example, images, which
// is not supported in Impeller).
//
// See https://github.com/flutter/flutter/issues/112498.
if (paint.isDitherHintForSkBackend()) {
sk_paint.setDither(paint.isDither());
}

sk_paint.setColor(paint.getColor());
sk_paint.setBlendMode(ToSk(paint.getBlendMode()));
sk_paint.setStyle(force_stroke ? SkPaint::kStroke_Style
Expand All @@ -59,6 +47,19 @@ SkPaint ToSk(const DlPaint& paint, bool force_stroke) {
color_filter = invert_filter;
}
sk_paint.setColorFilter(color_filter);

// On the Impeller backend, we will only support dithering of *gradients*,
// and it will be enabled by default (without the option to disable it). Until
// Skia support is completely removed, we only want to respect the dither flag
// for gradients (otherwise it will also apply to, for example, images, which
// is not supported in Impeller).
//
// See https://github.com/flutter/flutter/issues/112498.
auto color_source = paint.getColorSourcePtr();
if (color_source && color_source->isGradient()) {
sk_paint.setDither(paint.isDither());
}

sk_paint.setMaskFilter(ToSk(paint.getMaskFilterPtr()));
sk_paint.setPathEffect(ToSk(paint.getPathEffectPtr()));

Expand Down

0 comments on commit af290e9

Please sign in to comment.