Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b18778c

Browse files
authored
setupDefultFontManager correctly clear out cache (#42178)
fixes flutter/flutter#123483 Not entirely sure if this really fix the flake as I can't reproduce locally. My guess to the flake is that the setDefaultfontmgr should only be called once during the life time of the app. The setDefaultfontmgr can be remove at the call site, since it is already called during setup [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 983910f commit b18778c

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

third_party/txt/BUILD.gn

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,17 @@ if (enable_unittests) {
141141
executable("txt_unittests") {
142142
testonly = true
143143

144-
sources = [ "tests/txt_run_all_unittests.cc" ]
144+
sources = [
145+
"tests/font_collection_tests.cc",
146+
"tests/txt_run_all_unittests.cc",
147+
]
148+
149+
public_configs = [ ":txt_config" ]
145150

146151
configs += [ ":allow_posix_names" ]
147152

148153
deps = [
154+
":txt",
149155
":txt_fixtures",
150156
"//flutter/fml",
151157
"//flutter/testing:testing_lib",

third_party/txt/src/txt/font_collection.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ size_t FontCollection::GetFontManagersCount() const {
4646
void FontCollection::SetupDefaultFontManager(
4747
uint32_t font_initialization_data) {
4848
default_font_manager_ = GetDefaultFontManager(font_initialization_data);
49+
skt_collection_.reset();
4950
}
5051

5152
void FontCollection::SetDefaultFontManager(sk_sp<SkFontMgr> font_manager) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2017 Google, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "gtest/gtest.h"
18+
19+
#include <sstream>
20+
21+
#include "txt/font_collection.h"
22+
23+
namespace txt {
24+
namespace testing {
25+
26+
class FontCollectionTests : public ::testing::Test {
27+
public:
28+
FontCollectionTests() {}
29+
30+
void SetUp() override {}
31+
};
32+
33+
TEST_F(FontCollectionTests, SettingUpDefaultFontManagerClearsCache) {
34+
FontCollection font_collection;
35+
sk_sp<skia::textlayout::FontCollection> sk_font_collection =
36+
font_collection.CreateSktFontCollection();
37+
ASSERT_EQ(sk_font_collection->getFallbackManager().get(), nullptr);
38+
font_collection.SetupDefaultFontManager(0);
39+
sk_font_collection = font_collection.CreateSktFontCollection();
40+
ASSERT_NE(sk_font_collection->getFallbackManager().get(), nullptr);
41+
}
42+
} // namespace testing
43+
} // namespace txt

0 commit comments

Comments
 (0)