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 all commits
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
9 changes: 8 additions & 1 deletion ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,10 @@ FILE: ../../../flutter/third_party/txt/src/minikin/SparseBitSet.cpp
FILE: ../../../flutter/third_party/txt/src/minikin/SparseBitSet.h
FILE: ../../../flutter/third_party/txt/src/minikin/WordBreaker.cpp
FILE: ../../../flutter/third_party/txt/src/minikin/WordBreaker.h
FILE: ../../../flutter/third_party/txt/src/skia/paragraph_builder_skia.cc
FILE: ../../../flutter/third_party/txt/src/skia/paragraph_builder_skia.h
FILE: ../../../flutter/third_party/txt/src/skia/paragraph_skia.cc
FILE: ../../../flutter/third_party/txt/src/skia/paragraph_skia.h
FILE: ../../../flutter/third_party/txt/src/txt/asset_font_manager.cc
FILE: ../../../flutter/third_party/txt/src/txt/asset_font_manager.h
FILE: ../../../flutter/third_party/txt/src/txt/font_asset_provider.cc
Expand All @@ -1083,12 +1087,15 @@ FILE: ../../../flutter/third_party/txt/src/txt/font_style.h
FILE: ../../../flutter/third_party/txt/src/txt/font_weight.h
FILE: ../../../flutter/third_party/txt/src/txt/paint_record.cc
FILE: ../../../flutter/third_party/txt/src/txt/paint_record.h
FILE: ../../../flutter/third_party/txt/src/txt/paragraph.cc
FILE: ../../../flutter/third_party/txt/src/txt/paragraph.h
FILE: ../../../flutter/third_party/txt/src/txt/paragraph_builder.cc
FILE: ../../../flutter/third_party/txt/src/txt/paragraph_builder.h
FILE: ../../../flutter/third_party/txt/src/txt/paragraph_builder_txt.cc
FILE: ../../../flutter/third_party/txt/src/txt/paragraph_builder_txt.h
FILE: ../../../flutter/third_party/txt/src/txt/paragraph_style.cc
FILE: ../../../flutter/third_party/txt/src/txt/paragraph_style.h
FILE: ../../../flutter/third_party/txt/src/txt/paragraph_txt.cc
FILE: ../../../flutter/third_party/txt/src/txt/paragraph_txt.h
FILE: ../../../flutter/third_party/txt/src/txt/placeholder_run.cc
FILE: ../../../flutter/third_party/txt/src/txt/placeholder_run.h
FILE: ../../../flutter/third_party/txt/src/txt/styled_runs.cc
Expand Down
3 changes: 3 additions & 0 deletions common/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ if (target_cpu == "arm" || target_cpu == "arm64") {
declare_args() {
# The runtime mode ("debug", "profile", or "release")
flutter_runtime_mode = "debug"

# Whether to use the Skia text shaper module
flutter_enable_skshaper = false
}

# feature_defines_list ---------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# found in the LICENSE file.

import("//build/fuchsia/sdk.gni")
import("$flutter_root/common/config.gni")
import("$flutter_root/testing/testing.gni")

source_set("ui") {
Expand Down Expand Up @@ -126,6 +127,10 @@ source_set("ui") {
"$flutter_root/third_party/txt",
]

if (flutter_enable_skshaper) {
defines = [ "FLUTTER_ENABLE_SKSHAPER" ]
}

if (is_fuchsia) {
sources += [
"compositing/scene_host.cc",
Expand Down
13 changes: 10 additions & 3 deletions lib/ui/text/paragraph_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,16 @@ ParagraphBuilder::ParagraphBuilder(

FontCollection& font_collection =
UIDartState::Current()->window()->client()->GetFontCollection();
m_paragraphBuilder = std::make_unique<txt::ParagraphBuilder>(
style, font_collection.GetFontCollection());
} // namespace flutter

#if FLUTTER_ENABLE_SKSHAPER
#define FLUTTER_PARAGRAPH_BUILDER txt::ParagraphBuilder::CreateSkiaBuilder
#else
#define FLUTTER_PARAGRAPH_BUILDER txt::ParagraphBuilder::CreateTxtBuilder
#endif

m_paragraphBuilder =
FLUTTER_PARAGRAPH_BUILDER(style, font_collection.GetFontCollection());
}

ParagraphBuilder::~ParagraphBuilder() = default;

Expand Down
21 changes: 20 additions & 1 deletion third_party/txt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import("$flutter_root/common/config.gni")

declare_args() {
flutter_use_fontconfig = false
}
Expand All @@ -30,6 +32,9 @@ source_set("txt") {
if (flutter_use_fontconfig) {
defines += [ "FLUTTER_USE_FONTCONFIG" ]
}
if (flutter_enable_skshaper) {
defines += [ "FLUTTER_ENABLE_SKSHAPER" ]
}

sources = [
"src/log/log.cc",
Expand Down Expand Up @@ -84,12 +89,15 @@ source_set("txt") {
"src/txt/font_weight.h",
"src/txt/paint_record.cc",
"src/txt/paint_record.h",
"src/txt/paragraph.cc",
"src/txt/paragraph.h",
"src/txt/paragraph_builder.cc",
"src/txt/paragraph_builder.h",
"src/txt/paragraph_builder_txt.cc",
"src/txt/paragraph_builder_txt.h",
"src/txt/paragraph_style.cc",
"src/txt/paragraph_style.h",
"src/txt/paragraph_txt.cc",
"src/txt/paragraph_txt.h",
"src/txt/placeholder_run.cc",
"src/txt/placeholder_run.h",
"src/txt/platform.h",
Expand Down Expand Up @@ -130,6 +138,17 @@ source_set("txt") {
deps += [ "//third_party/fontconfig" ]
}

if (flutter_enable_skshaper) {
sources += [
"src/skia/paragraph_builder_skia.cc",
"src/skia/paragraph_builder_skia.h",
"src/skia/paragraph_skia.cc",
"src/skia/paragraph_skia.h",
]

deps += [ "//third_party/skia/modules/skparagraph" ]
}

if (is_mac || is_ios) {
sources += [ "src/txt/platform_mac.mm" ]
deps += [ "$flutter_root/fml" ]
Expand Down
56 changes: 28 additions & 28 deletions third_party/txt/benchmarks/paragraph_benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "txt/font_style.h"
#include "txt/font_weight.h"
#include "txt/paragraph.h"
#include "txt/paragraph_builder.h"
#include "txt/paragraph_builder_txt.h"

namespace txt {

Expand All @@ -45,15 +45,15 @@ static void BM_ParagraphShortLayout(benchmark::State& state) {
txt::TextStyle text_style;
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.color = SK_ColorBLACK;
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());

builder.PushStyle(text_style);
builder.AddText(u16_text);
builder.Pop();
auto paragraph = builder.Build();
auto paragraph = BuildParagraph(builder);
while (state.KeepRunning()) {
paragraph->SetDirty();
paragraph->Layout(300, true);
paragraph->Layout(300);
}
}
BENCHMARK(BM_ParagraphShortLayout);
Expand Down Expand Up @@ -87,15 +87,15 @@ static void BM_ParagraphLongLayout(benchmark::State& state) {
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.color = SK_ColorBLACK;

txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());

builder.PushStyle(text_style);
builder.AddText(u16_text);
builder.Pop();
auto paragraph = builder.Build();
auto paragraph = BuildParagraph(builder);
while (state.KeepRunning()) {
paragraph->SetDirty();
paragraph->Layout(300, true);
paragraph->Layout(300);
}
}
BENCHMARK(BM_ParagraphLongLayout);
Expand Down Expand Up @@ -130,15 +130,15 @@ static void BM_ParagraphJustifyLayout(benchmark::State& state) {
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.color = SK_ColorBLACK;

txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());

builder.PushStyle(text_style);
builder.AddText(u16_text);
builder.Pop();
auto paragraph = builder.Build();
auto paragraph = BuildParagraph(builder);
while (state.KeepRunning()) {
paragraph->SetDirty();
paragraph->Layout(300, true);
paragraph->Layout(300);
}
}
BENCHMARK(BM_ParagraphJustifyLayout);
Expand All @@ -154,15 +154,15 @@ static void BM_ParagraphManyStylesLayout(benchmark::State& state) {
txt::TextStyle text_style;
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.color = SK_ColorBLACK;
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
for (int i = 0; i < 1000; ++i) {
builder.PushStyle(text_style);
builder.AddText(u16_text);
}
auto paragraph = builder.Build();
auto paragraph = BuildParagraph(builder);
while (state.KeepRunning()) {
paragraph->SetDirty();
paragraph->Layout(300, true);
paragraph->Layout(300);
}
}
BENCHMARK(BM_ParagraphManyStylesLayout);
Expand All @@ -181,15 +181,15 @@ static void BM_ParagraphTextBigO(benchmark::State& state) {
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.color = SK_ColorBLACK;

txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());

builder.PushStyle(text_style);
builder.AddText(u16_text);
builder.Pop();
auto paragraph = builder.Build();
auto paragraph = BuildParagraph(builder);
while (state.KeepRunning()) {
paragraph->SetDirty();
paragraph->Layout(300, true);
paragraph->Layout(300);
}
state.SetComplexityN(state.range(0));
}
Expand All @@ -210,16 +210,16 @@ static void BM_ParagraphStylesBigO(benchmark::State& state) {
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.color = SK_ColorBLACK;

txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());

for (int i = 0; i < state.range(0); ++i) {
builder.PushStyle(text_style);
builder.AddText(u16_text);
}
auto paragraph = builder.Build();
auto paragraph = BuildParagraph(builder);
while (state.KeepRunning()) {
paragraph->SetDirty();
paragraph->Layout(300, true);
paragraph->Layout(300);
}
state.SetComplexityN(state.range(0));
}
Expand All @@ -239,11 +239,11 @@ static void BM_ParagraphPaintSimple(benchmark::State& state) {
txt::TextStyle text_style;
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.color = SK_ColorBLACK;
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
builder.PushStyle(text_style);
builder.AddText(u16_text);
auto paragraph = builder.Build();
paragraph->Layout(300, true);
auto paragraph = BuildParagraph(builder);
paragraph->Layout(300);

std::unique_ptr<SkBitmap> bitmap = std::make_unique<SkBitmap>();
bitmap->allocN32Pixels(1000, 1000);
Expand Down Expand Up @@ -286,11 +286,11 @@ static void BM_ParagraphPaintLarge(benchmark::State& state) {
txt::TextStyle text_style;
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.color = SK_ColorBLACK;
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
builder.PushStyle(text_style);
builder.AddText(u16_text);
auto paragraph = builder.Build();
paragraph->Layout(300, true);
auto paragraph = BuildParagraph(builder);
paragraph->Layout(300);

std::unique_ptr<SkBitmap> bitmap = std::make_unique<SkBitmap>();
bitmap->allocN32Pixels(1000, 1000);
Expand Down Expand Up @@ -322,7 +322,7 @@ static void BM_ParagraphPaintDecoration(benchmark::State& state) {
text_style.decoration_style = TextDecorationStyle(kSolid);
text_style.color = SK_ColorBLACK;

txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());

builder.PushStyle(text_style);
builder.AddText(u16_text);
Expand All @@ -335,8 +335,8 @@ static void BM_ParagraphPaintDecoration(benchmark::State& state) {
builder.PushStyle(text_style);
builder.AddText(u16_text);

auto paragraph = builder.Build();
paragraph->Layout(300, true);
auto paragraph = BuildParagraph(builder);
paragraph->Layout(300);

std::unique_ptr<SkBitmap> bitmap = std::make_unique<SkBitmap>();
bitmap->allocN32Pixels(1000, 1000);
Expand Down
20 changes: 10 additions & 10 deletions third_party/txt/benchmarks/paragraph_builder_benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
#include "txt/font_style.h"
#include "txt/font_weight.h"
#include "txt/paragraph.h"
#include "txt/paragraph_builder.h"
#include "txt/paragraph_builder_txt.h"

namespace txt {

static void BM_ParagraphBuilderConstruction(benchmark::State& state) {
txt::ParagraphStyle paragraph_style;
auto font_collection = GetTestFontCollection();
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style, font_collection);
txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
}
}
BENCHMARK(BM_ParagraphBuilderConstruction);
Expand All @@ -43,15 +43,15 @@ static void BM_ParagraphBuilderPushStyle(benchmark::State& state) {
text_style.color = SK_ColorBLACK;
auto font_collection = GetTestFontCollection();
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style, font_collection);
txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
builder.PushStyle(text_style);
}
}
BENCHMARK(BM_ParagraphBuilderPushStyle);

static void BM_ParagraphBuilderPushPop(benchmark::State& state) {
txt::ParagraphStyle paragraph_style;
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());

txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
Expand All @@ -70,7 +70,7 @@ static void BM_ParagraphBuilderAddTextString(benchmark::State& state) {
txt::ParagraphStyle paragraph_style;

while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style, font_collection);
txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
builder.AddText(text);
}
}
Expand All @@ -82,7 +82,7 @@ static void BM_ParagraphBuilderAddTextChar(benchmark::State& state) {
txt::ParagraphStyle paragraph_style;
auto font_collection = GetTestFontCollection();
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style, font_collection);
txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
builder.AddText(text);
}
}
Expand All @@ -97,7 +97,7 @@ static void BM_ParagraphBuilderAddTextU16stringShort(benchmark::State& state) {
txt::ParagraphStyle paragraph_style;
auto font_collection = GetTestFontCollection();
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style, font_collection);
txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
builder.AddText(u16_text);
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ static void BM_ParagraphBuilderAddTextU16stringLong(benchmark::State& state) {
txt::ParagraphStyle paragraph_style;

while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style, font_collection);
txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
builder.AddText(u16_text);
}
}
Expand All @@ -150,7 +150,7 @@ static void BM_ParagraphBuilderShortParagraphConstruct(
text_style.color = SK_ColorBLACK;
auto font_collection = GetTestFontCollection();
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style, font_collection);
txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
builder.PushStyle(text_style);
builder.AddText(u16_text);
builder.Pop();
Expand Down Expand Up @@ -188,7 +188,7 @@ static void BM_ParagraphBuilderLongParagraphConstruct(benchmark::State& state) {
text_style.color = SK_ColorBLACK;
auto font_collection = GetTestFontCollection();
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style, font_collection);
txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
builder.PushStyle(text_style);
builder.AddText(u16_text);
builder.Pop();
Expand Down
Loading