diff options
author | 2023-10-31 14:58:26 +0000 | |
---|---|---|
committer | 2023-11-01 12:38:12 +0000 | |
commit | 09a77097833a364223c40efab8b28c8e34083fac (patch) | |
tree | 1c222a06c22ce6416036c7ec84bccdc971b5d454 | |
parent | 19c98814b648b9666a7e9a593f449f24ba380207 (diff) |
Avoid default SkFont in tests
Change-Id: I003aa8fcc4de2f6a4e34663a26ebc21d207dcd94
Bug: b/305780908
-rw-r--r-- | libs/hwui/tests/common/TestUtils.cpp | 10 | ||||
-rw-r--r-- | libs/hwui/tests/common/TestUtils.h | 3 | ||||
-rw-r--r-- | libs/hwui/tests/common/scenes/ListViewAnimation.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/tests/common/scenes/StretchyListViewAnimation.cpp | 2 |
4 files changed, 15 insertions, 2 deletions
diff --git a/libs/hwui/tests/common/TestUtils.cpp b/libs/hwui/tests/common/TestUtils.cpp index a4890ede8faa..ad963dd913cf 100644 --- a/libs/hwui/tests/common/TestUtils.cpp +++ b/libs/hwui/tests/common/TestUtils.cpp @@ -19,6 +19,8 @@ #include "DeferredLayerUpdater.h" #include "hwui/Paint.h" +#include <hwui/MinikinSkia.h> +#include <hwui/Typeface.h> #include <minikin/Layout.h> #include <pipeline/skia/SkiaOpenGLPipeline.h> #include <pipeline/skia/SkiaVulkanPipeline.h> @@ -179,5 +181,13 @@ SkRect TestUtils::getLocalClipBounds(const SkCanvas* canvas) { return outlineInLocalCoord; } +SkFont TestUtils::defaultFont() { + const std::shared_ptr<minikin::MinikinFont>& minikinFont = + Typeface::resolveDefault(nullptr)->fFontCollection->getFamilyAt(0)->getFont(0)->baseTypeface(); + SkTypeface* skTypeface = reinterpret_cast<const MinikinFontSkia*>(minikinFont.get())->GetSkTypeface(); + LOG_ALWAYS_FATAL_IF(skTypeface == nullptr); + return SkFont(sk_ref_sp(skTypeface)); +} + } /* namespace uirenderer */ } /* namespace android */ diff --git a/libs/hwui/tests/common/TestUtils.h b/libs/hwui/tests/common/TestUtils.h index ffc664c2e1bc..0ede902b1b95 100644 --- a/libs/hwui/tests/common/TestUtils.h +++ b/libs/hwui/tests/common/TestUtils.h @@ -30,6 +30,7 @@ #include <SkBitmap.h> #include <SkColor.h> +#include <SkFont.h> #include <SkImageInfo.h> #include <SkRefCnt.h> @@ -353,6 +354,8 @@ public: static CallCounts& countsForFunctor(int functor) { return sMockFunctorCounts[functor]; } + static SkFont defaultFont(); + private: static std::unordered_map<int, CallCounts> sMockFunctorCounts; diff --git a/libs/hwui/tests/common/scenes/ListViewAnimation.cpp b/libs/hwui/tests/common/scenes/ListViewAnimation.cpp index 4a5d9468cd88..97d4c8214cde 100644 --- a/libs/hwui/tests/common/scenes/ListViewAnimation.cpp +++ b/libs/hwui/tests/common/scenes/ListViewAnimation.cpp @@ -57,7 +57,7 @@ class ListViewAnimation : public TestListViewSceneBase { 128 * 3; paint.setColor(bgDark ? Color::White : Color::Grey_700); - SkFont font; + SkFont font = TestUtils::defaultFont(); font.setSize(size / 2); char charToShow = 'A' + (rand() % 26); const SkPoint pos = {SkIntToScalar(size / 2), diff --git a/libs/hwui/tests/common/scenes/StretchyListViewAnimation.cpp b/libs/hwui/tests/common/scenes/StretchyListViewAnimation.cpp index bb95490c1d39..159541c11c64 100644 --- a/libs/hwui/tests/common/scenes/StretchyListViewAnimation.cpp +++ b/libs/hwui/tests/common/scenes/StretchyListViewAnimation.cpp @@ -102,7 +102,7 @@ private: 128 * 3; paint.setColor(bgDark ? Color::White : Color::Grey_700); - SkFont font; + SkFont font = TestUtils::defaultFont(); font.setSize(size / 2); char charToShow = 'A' + (rand() % 26); const SkPoint pos = {SkIntToScalar(size / 2), |