Use "blur_sigma" instead of "blur_radius" in Shadow. (flutter/engine#25760)

This commit is contained in:
heke123
2021-05-01 05:34:02 +08:00
committed by GitHub
parent c2341da13f
commit c59ffe8b9a
7 changed files with 14 additions and 13 deletions

View File

@@ -5010,7 +5010,7 @@ class Shadow {
// See SkBlurMask::ConvertRadiusToSigma().
// <https://github.com/google/skia/blob/bb5b77db51d2e149ee66db284903572a5aac09be/src/effects/SkBlurMask.cpp#L23>
static double convertRadiusToSigma(double radius) {
return radius * 0.57735 + 0.5;
return radius > 0 ? radius * 0.57735 + 0.5 : 0;
}
/// The [blurRadius] in sigmas instead of logical pixels.
@@ -5147,8 +5147,9 @@ class Shadow {
shadowsData.setFloat32(_kYOffset + shadowOffset,
shadow.offset.dy, _kFakeHostEndian);
final double blurSigma = Shadow.convertRadiusToSigma(shadow.blurRadius);
shadowsData.setFloat32(_kBlurOffset + shadowOffset,
shadow.blurRadius, _kFakeHostEndian);
blurSigma, _kFakeHostEndian);
}
}

View File

@@ -614,7 +614,7 @@ class Shadow {
// See SkBlurMask::ConvertRadiusToSigma().
// <https://github.com/google/skia/blob/bb5b77db51d2e149ee66db284903572a5aac09be/src/effects/SkBlurMask.cpp#L23>
static double convertRadiusToSigma(double radius) {
return radius * 0.57735 + 0.5;
return radius > 0 ? radius * 0.57735 + 0.5 : 0;
}
double get blurSigma => convertRadiusToSigma(blurRadius);

View File

@@ -126,7 +126,7 @@ skt::TextStyle TxtToSkia(const TextStyle& txt) {
for (const txt::TextShadow& txt_shadow : txt.text_shadows) {
skt::TextShadow shadow;
shadow.fOffset = txt_shadow.offset;
shadow.fBlurSigma = txt_shadow.blur_radius;
shadow.fBlurSigma = txt_shadow.blur_sigma;
shadow.fColor = txt_shadow.color;
skia.addShadow(shadow);
}

View File

@@ -75,7 +75,7 @@ TextStyle SkiaToTxt(const skt::TextStyle& skia) {
for (const skt::TextShadow& skia_shadow : skia.getShadows()) {
txt::TextShadow shadow;
shadow.offset = skia_shadow.fOffset;
shadow.blur_radius = skia_shadow.fBlurSigma;
shadow.blur_sigma = skia_shadow.fBlurSigma;
shadow.color = skia_shadow.fColor;
txt.text_shadows.emplace_back(shadow);
}

View File

@@ -1650,9 +1650,9 @@ void ParagraphTxt::PaintShadow(SkCanvas* canvas,
SkPaint paint;
paint.setColor(text_shadow.color);
if (text_shadow.blur_radius != 0.0) {
if (text_shadow.blur_sigma > 0.5) {
paint.setMaskFilter(SkMaskFilter::MakeBlur(
kNormal_SkBlurStyle, text_shadow.blur_radius, false));
kNormal_SkBlurStyle, text_shadow.blur_sigma, false));
}
canvas->drawTextBlob(record.text(), offset.x() + text_shadow.offset.x(),
offset.y() + text_shadow.offset.y(), paint);

View File

@@ -20,15 +20,15 @@
namespace txt {
TextShadow::TextShadow() {}
TextShadow::TextShadow(SkColor color, SkPoint offset, double blur_radius)
: color(color), offset(offset), blur_radius(blur_radius) {}
TextShadow::TextShadow(SkColor color, SkPoint offset, double blur_sigma)
: color(color), offset(offset), blur_sigma(blur_sigma) {}
bool TextShadow::operator==(const TextShadow& other) const {
if (color != other.color)
return false;
if (offset != other.offset)
return false;
if (blur_radius != other.blur_radius)
if (blur_sigma != other.blur_sigma)
return false;
return true;
@@ -41,7 +41,7 @@ bool TextShadow::operator!=(const TextShadow& other) const {
bool TextShadow::hasShadow() const {
if (!offset.isZero())
return true;
if (blur_radius != 0.0)
if (blur_sigma > 0.5)
return true;
return false;

View File

@@ -26,11 +26,11 @@ class TextShadow {
public:
SkColor color = SK_ColorBLACK;
SkPoint offset;
double blur_radius = 0.0;
double blur_sigma = 0.0;
TextShadow();
TextShadow(SkColor color, SkPoint offset, double blur_radius);
TextShadow(SkColor color, SkPoint offset, double blur_sigma);
bool operator==(const TextShadow& other) const;