setupDefultFontManager correctly clear out cache (flutter/engine#42178)
fixes https://github.com/flutter/flutter/issues/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
This commit is contained in:
8
engine/src/flutter/third_party/txt/BUILD.gn
vendored
8
engine/src/flutter/third_party/txt/BUILD.gn
vendored
@@ -141,11 +141,17 @@ if (enable_unittests) {
|
||||
executable("txt_unittests") {
|
||||
testonly = true
|
||||
|
||||
sources = [ "tests/txt_run_all_unittests.cc" ]
|
||||
sources = [
|
||||
"tests/font_collection_tests.cc",
|
||||
"tests/txt_run_all_unittests.cc",
|
||||
]
|
||||
|
||||
public_configs = [ ":txt_config" ]
|
||||
|
||||
configs += [ ":allow_posix_names" ]
|
||||
|
||||
deps = [
|
||||
":txt",
|
||||
":txt_fixtures",
|
||||
"//flutter/fml",
|
||||
"//flutter/testing:testing_lib",
|
||||
|
||||
@@ -46,6 +46,7 @@ size_t FontCollection::GetFontManagersCount() const {
|
||||
void FontCollection::SetupDefaultFontManager(
|
||||
uint32_t font_initialization_data) {
|
||||
default_font_manager_ = GetDefaultFontManager(font_initialization_data);
|
||||
skt_collection_.reset();
|
||||
}
|
||||
|
||||
void FontCollection::SetDefaultFontManager(sk_sp<SkFontMgr> font_manager) {
|
||||
|
||||
43
engine/src/flutter/third_party/txt/tests/font_collection_tests.cc
vendored
Normal file
43
engine/src/flutter/third_party/txt/tests/font_collection_tests.cc
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2017 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "txt/font_collection.h"
|
||||
|
||||
namespace txt {
|
||||
namespace testing {
|
||||
|
||||
class FontCollectionTests : public ::testing::Test {
|
||||
public:
|
||||
FontCollectionTests() {}
|
||||
|
||||
void SetUp() override {}
|
||||
};
|
||||
|
||||
TEST_F(FontCollectionTests, SettingUpDefaultFontManagerClearsCache) {
|
||||
FontCollection font_collection;
|
||||
sk_sp<skia::textlayout::FontCollection> sk_font_collection =
|
||||
font_collection.CreateSktFontCollection();
|
||||
ASSERT_EQ(sk_font_collection->getFallbackManager().get(), nullptr);
|
||||
font_collection.SetupDefaultFontManager(0);
|
||||
sk_font_collection = font_collection.CreateSktFontCollection();
|
||||
ASSERT_NE(sk_font_collection->getFallbackManager().get(), nullptr);
|
||||
}
|
||||
} // namespace testing
|
||||
} // namespace txt
|
||||
Reference in New Issue
Block a user