From d90570816bd6f6f0a3f666ba8413ad2f320aa0fe Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Thu, 4 May 2023 09:56:02 -0700 Subject: [PATCH 1/3] [Impeller][WIP] Use new SkParagraph APIs for stroked text --- impeller/display_list/dl_dispatcher.cc | 20 ++++++++++++++++--- .../backends/skia/text_frame_skia.cc | 11 ++++++++++ .../backends/skia/text_frame_skia.h | 3 +++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/impeller/display_list/dl_dispatcher.cc b/impeller/display_list/dl_dispatcher.cc index 157efbaee69a7..e3a9581cf2887 100644 --- a/impeller/display_list/dl_dispatcher.cc +++ b/impeller/display_list/dl_dispatcher.cc @@ -1088,9 +1088,23 @@ void DlDispatcher::drawTextBlob(const sk_sp blob, SkScalar x, SkScalar y) { Scalar scale = canvas_.GetCurrentTransformation().GetMaxBasisLength(); - canvas_.DrawTextFrame(TextFrameFromTextBlob(blob, scale), // - impeller::Point{x, y}, // - paint_ // + auto text_frame = TextFrameFromTextBlob(blob, scale); + if (paint_.style == Paint::Style::kStroke) { + auto path = PathDataFromTextBlob(blob); + auto bounds = text_frame.GetBounds(); + if (!bounds.has_value()) { + return; + } + canvas_.Save(); + canvas_.Translate({x + bounds->origin.x, y + bounds->origin.y, 0.0}); + canvas_.DrawPath(path, paint_); + canvas_.Restore(); + return; + } + + canvas_.DrawTextFrame(text_frame, // + impeller::Point{x, y}, // + paint_ // ); } diff --git a/impeller/typographer/backends/skia/text_frame_skia.cc b/impeller/typographer/backends/skia/text_frame_skia.cc index e451695dc8b6d..fd0dc2b15a5b3 100644 --- a/impeller/typographer/backends/skia/text_frame_skia.cc +++ b/impeller/typographer/backends/skia/text_frame_skia.cc @@ -7,11 +7,13 @@ #include #include "flutter/fml/logging.h" +#include "impeller/display_list/skia_conversions.h" #include "impeller/typographer/backends/skia/typeface_skia.h" #include "include/core/SkFontTypes.h" #include "include/core/SkRect.h" #include "third_party/skia/include/core/SkFont.h" #include "third_party/skia/include/core/SkFontMetrics.h" +#include "third_party/skia/modules/skparagraph/include/Paragraph.h" #include "third_party/skia/src/core/SkStrikeSpec.h" // nogncheck #include "third_party/skia/src/core/SkTextBlobPriv.h" // nogncheck @@ -38,6 +40,15 @@ static Rect ToRect(const SkRect& rect) { return Rect::MakeLTRB(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); } +Path PathDataFromTextBlob(const sk_sp& blob) { + if (!blob) { + return {}; + } + + return skia_conversions::ToPath( + skia::textlayout::Paragraph::getPaths(blob.get())); +} + TextFrame TextFrameFromTextBlob(const sk_sp& blob, Scalar scale) { if (!blob) { return {}; diff --git a/impeller/typographer/backends/skia/text_frame_skia.h b/impeller/typographer/backends/skia/text_frame_skia.h index 80d6c33921fa3..ba2ecd16e65e5 100644 --- a/impeller/typographer/backends/skia/text_frame_skia.h +++ b/impeller/typographer/backends/skia/text_frame_skia.h @@ -5,11 +5,14 @@ #pragma once #include "flutter/fml/macros.h" +#include "impeller/geometry/path.h" #include "impeller/typographer/text_frame.h" #include "third_party/skia/include/core/SkTextBlob.h" namespace impeller { +Path PathDataFromTextBlob(const sk_sp& blob); + TextFrame TextFrameFromTextBlob(const sk_sp& blob, Scalar scale = 1.0f); From 8a3a5226cb81a2cd6628741cfc9ef5465b41ea31 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 10 Jul 2023 19:49:58 -0700 Subject: [PATCH 2/3] update --- impeller/display_list/BUILD.gn | 1 + impeller/display_list/dl_dispatcher.cc | 3 +-- impeller/display_list/skia_conversions.cc | 9 +++++++++ impeller/display_list/skia_conversions.h | 3 +++ impeller/typographer/backends/skia/text_frame_skia.cc | 11 ----------- impeller/typographer/backends/skia/text_frame_skia.h | 2 -- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/impeller/display_list/BUILD.gn b/impeller/display_list/BUILD.gn index a69f63806c685..1b7f13e5d3d05 100644 --- a/impeller/display_list/BUILD.gn +++ b/impeller/display_list/BUILD.gn @@ -15,6 +15,7 @@ impeller_component("skia_conversions") { "../geometry", "//flutter/fml", "//third_party/skia", + "//third_party/skia/modules/skparagraph", ] } diff --git a/impeller/display_list/dl_dispatcher.cc b/impeller/display_list/dl_dispatcher.cc index 87a0bd554f6e8..6e0bc4c92b924 100644 --- a/impeller/display_list/dl_dispatcher.cc +++ b/impeller/display_list/dl_dispatcher.cc @@ -1107,7 +1107,7 @@ void DlDispatcher::drawTextBlob(const sk_sp blob, Scalar scale = canvas_.GetCurrentTransformation().GetMaxBasisLengthXY(); const auto text_frame = TextFrameFromTextBlob(blob, scale); if (paint_.style == Paint::Style::kStroke) { - auto path = PathDataFromTextBlob(blob); + auto path = skia_conversions::PathDataFromTextBlob(blob); auto bounds = text_frame.GetBounds(); if (!bounds.has_value()) { return; @@ -1119,7 +1119,6 @@ void DlDispatcher::drawTextBlob(const sk_sp blob, return; } - Scalar scale = canvas_.GetCurrentTransformation().GetMaxBasisLengthXY(); canvas_.DrawTextFrame(text_frame, // impeller::Point{x, y}, // paint_ // diff --git a/impeller/display_list/skia_conversions.cc b/impeller/display_list/skia_conversions.cc index d7af98f61484f..29f9ad4eed8ae 100644 --- a/impeller/display_list/skia_conversions.cc +++ b/impeller/display_list/skia_conversions.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "impeller/display_list/skia_conversions.h" +#include "third_party/skia/modules/skparagraph/include/Paragraph.h" namespace impeller { namespace skia_conversions { @@ -159,6 +160,14 @@ std::vector ToRSXForms(const SkRSXform xform[], int count) { return result; } +Path PathDataFromTextBlob(const sk_sp& blob) { + if (!blob) { + return {}; + } + + return ToPath(skia::textlayout::Paragraph::GetPath(blob.get())); +} + std::optional ToPixelFormat(SkColorType type) { switch (type) { case kRGBA_8888_SkColorType: diff --git a/impeller/display_list/skia_conversions.h b/impeller/display_list/skia_conversions.h index 5f1524674240d..9406c6d272f62 100644 --- a/impeller/display_list/skia_conversions.h +++ b/impeller/display_list/skia_conversions.h @@ -16,6 +16,7 @@ #include "third_party/skia/include/core/SkPoint.h" #include "third_party/skia/include/core/SkRRect.h" #include "third_party/skia/include/core/SkRSXform.h" +#include "third_party/skia/include/core/SkTextBlob.h" namespace impeller { namespace skia_conversions { @@ -40,6 +41,8 @@ Path ToPath(const SkPath& path); Path ToPath(const SkRRect& rrect); +Path PathDataFromTextBlob(const sk_sp& blob); + std::optional ToPixelFormat(SkColorType type); } // namespace skia_conversions diff --git a/impeller/typographer/backends/skia/text_frame_skia.cc b/impeller/typographer/backends/skia/text_frame_skia.cc index fd0dc2b15a5b3..e451695dc8b6d 100644 --- a/impeller/typographer/backends/skia/text_frame_skia.cc +++ b/impeller/typographer/backends/skia/text_frame_skia.cc @@ -7,13 +7,11 @@ #include #include "flutter/fml/logging.h" -#include "impeller/display_list/skia_conversions.h" #include "impeller/typographer/backends/skia/typeface_skia.h" #include "include/core/SkFontTypes.h" #include "include/core/SkRect.h" #include "third_party/skia/include/core/SkFont.h" #include "third_party/skia/include/core/SkFontMetrics.h" -#include "third_party/skia/modules/skparagraph/include/Paragraph.h" #include "third_party/skia/src/core/SkStrikeSpec.h" // nogncheck #include "third_party/skia/src/core/SkTextBlobPriv.h" // nogncheck @@ -40,15 +38,6 @@ static Rect ToRect(const SkRect& rect) { return Rect::MakeLTRB(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); } -Path PathDataFromTextBlob(const sk_sp& blob) { - if (!blob) { - return {}; - } - - return skia_conversions::ToPath( - skia::textlayout::Paragraph::getPaths(blob.get())); -} - TextFrame TextFrameFromTextBlob(const sk_sp& blob, Scalar scale) { if (!blob) { return {}; diff --git a/impeller/typographer/backends/skia/text_frame_skia.h b/impeller/typographer/backends/skia/text_frame_skia.h index ba2ecd16e65e5..b43051cacf6ee 100644 --- a/impeller/typographer/backends/skia/text_frame_skia.h +++ b/impeller/typographer/backends/skia/text_frame_skia.h @@ -11,8 +11,6 @@ namespace impeller { -Path PathDataFromTextBlob(const sk_sp& blob); - TextFrame TextFrameFromTextBlob(const sk_sp& blob, Scalar scale = 1.0f); From ef553198b24f16430d12fae0a62c9388e10846d2 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Tue, 11 Jul 2023 17:09:21 -0700 Subject: [PATCH 3/3] add test --- impeller/display_list/dl_unittests.cc | 13 +++++++++++++ .../typographer/backends/skia/text_frame_skia.h | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/impeller/display_list/dl_unittests.cc b/impeller/display_list/dl_unittests.cc index b5ce5c4c9a420..05a0b5d9b072b 100644 --- a/impeller/display_list/dl_unittests.cc +++ b/impeller/display_list/dl_unittests.cc @@ -447,6 +447,19 @@ TEST_P(DisplayListTest, CanDrawWithMaskBlur) { ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); } +TEST_P(DisplayListTest, CanDrawStrokedText) { + flutter::DisplayListBuilder builder; + flutter::DlPaint paint; + + paint.setDrawStyle(flutter::DlDrawStyle::kStroke); + paint.setColor(flutter::DlColor::kRed()); + builder.DrawTextBlob( + SkTextBlob::MakeFromString("stoked about stroked text", CreateTestFont()), + 250, 250, paint); + + ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); +} + TEST_P(DisplayListTest, IgnoreMaskFilterWhenSavingLayer) { auto texture = CreateTextureForFixture("embarcadero.jpg"); flutter::DisplayListBuilder builder; diff --git a/impeller/typographer/backends/skia/text_frame_skia.h b/impeller/typographer/backends/skia/text_frame_skia.h index 7d55e51c30774..a12b0f5ec60fa 100644 --- a/impeller/typographer/backends/skia/text_frame_skia.h +++ b/impeller/typographer/backends/skia/text_frame_skia.h @@ -5,7 +5,6 @@ #pragma once #include "flutter/fml/macros.h" -#include "impeller/geometry/path.h" #include "impeller/typographer/text_frame.h" #include "third_party/skia/include/core/SkTextBlob.h"