Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
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
2 changes: 2 additions & 0 deletions display_list/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ if (enable_unittests) {
":display_list_fixtures",
"//flutter/display_list/testing:display_list_testing",
"//flutter/testing",
"//flutter/third_party/txt:txt",
]

if (!defined(defines)) {
Expand Down Expand Up @@ -222,6 +223,7 @@ source_set("display_list_benchmarks_source") {
"//flutter/fml",
"//flutter/testing:skia",
"//flutter/testing:testing_lib",
"//flutter/third_party/txt:txt",
"//third_party/dart/runtime:libdart_jit", # for tracing
"//third_party/skia",
]
Expand Down
3 changes: 2 additions & 1 deletion display_list/benchmarking/dl_benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/GrRecordingContext.h"
#include "third_party/skia/include/gpu/GrTypes.h"
#include "third_party/txt/src/txt/platform.h"

namespace flutter {
namespace testing {
Expand Down Expand Up @@ -1203,7 +1204,7 @@ void BM_DrawTextBlob(benchmark::State& state,

for (size_t i = 0; i < draw_calls; i++) {
character[0] = 'A' + (i % 26);
auto blob = SkTextBlob::MakeFromString(character, SkFont());
auto blob = SkTextBlob::MakeFromString(character, txt::DefaultFont());
builder.DrawTextBlob(blob, 50.0f, 50.0f, paint);
}

Expand Down
3 changes: 2 additions & 1 deletion display_list/benchmarking/dl_complexity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/txt/src/txt/platform.h"

namespace flutter {
namespace testing {
Expand Down Expand Up @@ -306,7 +307,7 @@ TEST(DisplayListComplexity, DrawVertices) {

TEST(DisplayListComplexity, DrawTextBlob) {
auto text_blob = SkTextBlob::MakeFromString(
"The quick brown fox jumps over the lazy dog.", SkFont());
"The quick brown fox jumps over the lazy dog.", txt::DefaultFont());

DisplayListBuilder builder;
builder.DrawTextBlob(text_blob, 0.0f, 0.0f, DlPaint());
Expand Down
1 change: 1 addition & 0 deletions display_list/testing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ source_set("display_list_testing") {

deps = [
"//flutter/testing:testing_lib",
"//flutter/third_party/txt:txt",
"//third_party/skia",
]

Expand Down
5 changes: 3 additions & 2 deletions display_list/testing/dl_test_snippets.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "third_party/skia/include/effects/SkDashPathEffect.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "third_party/skia/include/effects/SkImageFilters.h"
#include "third_party/txt/src/txt/platform.h"

namespace flutter {
namespace testing {
Expand Down Expand Up @@ -223,8 +224,8 @@ static sk_sp<DisplayList> TestDisplayList2 =
MakeTestDisplayList(25, 25, SK_ColorBLUE);

static sk_sp<SkTextBlob> MakeTextBlob(std::string string) {
return SkTextBlob::MakeFromText(string.c_str(), string.size(), SkFont(),
SkTextEncoding::kUTF8);
return SkTextBlob::MakeFromText(string.c_str(), string.size(),
txt::DefaultFont(), SkTextEncoding::kUTF8);
}
static sk_sp<SkTextBlob> TestBlob1 = MakeTextBlob("TestBlob1");
static sk_sp<SkTextBlob> TestBlob2 = MakeTextBlob("TestBlob2");
Expand Down
1 change: 1 addition & 0 deletions third_party/txt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ source_set("txt") {
"src/txt/placeholder_run.cc",
"src/txt/placeholder_run.h",
"src/txt/platform.h",
"src/txt/platform_common.cc",
"src/txt/run_metrics.h",
"src/txt/test_font_manager.cc",
"src/txt/test_font_manager.h",
Expand Down
4 changes: 4 additions & 0 deletions third_party/txt/src/txt/platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

#include "txt/platform.h"

#include "fml/logging.h"

namespace txt {

std::vector<std::string> GetDefaultFontFamilies() {
return {"Arial"};
}

sk_sp<SkFontMgr> GetDefaultFontManager(uint32_t font_initialization_data) {
// TODO(b/305780908) Replace this with a singleton that depends on which
// platform we are on and which SkFontMgr was compiled in.
return SkFontMgr::RefDefault();
}

Expand Down
7 changes: 7 additions & 0 deletions third_party/txt/src/txt/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@
#include <vector>

#include "flutter/fml/macros.h"
#include "third_party/skia/include/core/SkFont.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#include "third_party/skia/include/core/SkRefCnt.h"

namespace txt {

std::vector<std::string> GetDefaultFontFamilies();

// Returns the platform specific SkFontMgr, which is a singleton.
sk_sp<SkFontMgr> GetDefaultFontManager(uint32_t font_initialization_data);

// Returns a font using a default typeface returned by a platform-specific
// SkFontMgr. It may be different on different platforms.
SkFont DefaultFont();

} // namespace txt

#endif // TXT_PLATFORM_H_
41 changes: 41 additions & 0 deletions third_party/txt/src/txt/platform_common.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "txt/platform.h"

#include "fml/logging.h"
#include "third_party/skia/include/core/SkFont.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#include "third_party/skia/include/core/SkFontStyle.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkTypeface.h"

namespace txt {

static sk_sp<SkTypeface> MakeTypefaceFromName(const char* name,
SkFontStyle style) {
sk_sp<SkFontMgr> fm = GetDefaultFontManager(0);
FML_CHECK(fm);
sk_sp<SkTypeface> face = fm->legacyMakeTypeface(name, style);
return face;
}

static sk_sp<SkTypeface> DefaultTypeface() {
sk_sp<SkTypeface> face = MakeTypefaceFromName(nullptr, SkFontStyle());
if (face) {
return face;
}
// Due to how SkTypeface::MakeDefault() used to work, many callers of this
// depend on the returned SkTypeface being non-null.
// TODO(kjlubick) replace this with SkTypeface::MakeEmpty()
face = SkTypeface::MakeDefault();
FML_CHECK(face);
return face;
}

SkFont DefaultFont() {
return SkFont(DefaultTypeface());
}

} // namespace txt