From 3eb2feb3267343ee955fd504e01d253822b21b08 Mon Sep 17 00:00:00 2001 From: heke Date: Sun, 25 Apr 2021 14:32:57 +0800 Subject: [PATCH] Use "blur_sigma" instead of "blur_radius" in Shadow. This is a bug-fix. The Skia 'SkMaskFilter::MakeBlur()' interface expects a 'blur_sigma' value but currently we pass it a 'radius'. --- lib/ui/painting.dart | 5 +++-- lib/web_ui/lib/src/ui/painting.dart | 2 +- third_party/txt/src/skia/paragraph_builder_skia.cc | 2 +- third_party/txt/src/skia/paragraph_skia.cc | 2 +- third_party/txt/src/txt/paragraph_txt.cc | 4 ++-- third_party/txt/src/txt/text_shadow.cc | 8 ++++---- third_party/txt/src/txt/text_shadow.h | 4 ++-- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/ui/painting.dart b/lib/ui/painting.dart index c223bf69bb038..42df63d532386 100644 --- a/lib/ui/painting.dart +++ b/lib/ui/painting.dart @@ -5010,7 +5010,7 @@ class Shadow { // See SkBlurMask::ConvertRadiusToSigma(). // 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); } } diff --git a/lib/web_ui/lib/src/ui/painting.dart b/lib/web_ui/lib/src/ui/painting.dart index f8e5d20ff28a0..87201667e2ff6 100644 --- a/lib/web_ui/lib/src/ui/painting.dart +++ b/lib/web_ui/lib/src/ui/painting.dart @@ -614,7 +614,7 @@ class Shadow { // See SkBlurMask::ConvertRadiusToSigma(). // 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); diff --git a/third_party/txt/src/skia/paragraph_builder_skia.cc b/third_party/txt/src/skia/paragraph_builder_skia.cc index a2732b593081a..84799c3838737 100644 --- a/third_party/txt/src/skia/paragraph_builder_skia.cc +++ b/third_party/txt/src/skia/paragraph_builder_skia.cc @@ -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); } diff --git a/third_party/txt/src/skia/paragraph_skia.cc b/third_party/txt/src/skia/paragraph_skia.cc index 3b249f09951a8..798f08087e7fc 100644 --- a/third_party/txt/src/skia/paragraph_skia.cc +++ b/third_party/txt/src/skia/paragraph_skia.cc @@ -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); } diff --git a/third_party/txt/src/txt/paragraph_txt.cc b/third_party/txt/src/txt/paragraph_txt.cc index 46f21abf8f0f2..ec14079fc62a1 100644 --- a/third_party/txt/src/txt/paragraph_txt.cc +++ b/third_party/txt/src/txt/paragraph_txt.cc @@ -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); diff --git a/third_party/txt/src/txt/text_shadow.cc b/third_party/txt/src/txt/text_shadow.cc index f6fb9ffb04e04..9fb0b2d82f731 100644 --- a/third_party/txt/src/txt/text_shadow.cc +++ b/third_party/txt/src/txt/text_shadow.cc @@ -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; diff --git a/third_party/txt/src/txt/text_shadow.h b/third_party/txt/src/txt/text_shadow.h index 7904818668318..5fe61dbde7982 100644 --- a/third_party/txt/src/txt/text_shadow.h +++ b/third_party/txt/src/txt/text_shadow.h @@ -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;