diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-04-18 23:07:08 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-04-18 23:07:08 +0000 |
commit | f7b310edf2098a82bbac3af61b06cb4eb4726635 (patch) | |
tree | 7719cfa78b77359036ab330e1ffe1b11f324cf4b | |
parent | e41861c58a22f85da2d17f28cfaa0b0fa655704d (diff) | |
parent | b67f9c4a19d87a49501765ffdc1cfca1457c003d (diff) | |
download | minikin-f7b310edf2098a82bbac3af61b06cb4eb4726635.tar.gz |
Snap for 7293377 from b67f9c4a19d87a49501765ffdc1cfca1457c003d to sc-release
Change-Id: Ia19e840ceb49da803797da4bbacbdd44db897c49
-rw-r--r-- | include/minikin/SystemFonts.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/minikin/SystemFonts.h b/include/minikin/SystemFonts.h index 686f32e..616997d 100644 --- a/include/minikin/SystemFonts.h +++ b/include/minikin/SystemFonts.h @@ -43,6 +43,18 @@ public: return getInstance().registerDefaultInternal(fc); } + using FontMapDeleter = std::function<void()>; + + static void addFontMap(std::shared_ptr<FontCollection>&& collections) { + return getInstance().addFontMapInternal(std::move(collections)); + } + + // This obtains a mutex inside, so do not call this method inside callback. + static void getFontMap( + std::function<void(const std::vector<std::shared_ptr<FontCollection>>&)> func) { + return getInstance().getFontMapInternal(func); + } + protected: // Visible for testing purposes. SystemFonts() {} @@ -60,11 +72,24 @@ protected: mDefaultFallback = fc; } + void addFontMapInternal(std::shared_ptr<FontCollection>&& collections) { + std::lock_guard<std::mutex> lock(mMutex); + mCollections.emplace_back(std::move(collections)); + } + + void getFontMapInternal( + std::function<void(const std::vector<std::shared_ptr<FontCollection>>&)> func) { + std::lock_guard<std::mutex> lock(mMutex); + func(mCollections); + } + private: static SystemFonts& getInstance(); std::map<std::string, std::shared_ptr<FontCollection>> mSystemFallbacks GUARDED_BY(mMutex); std::shared_ptr<FontCollection> mDefaultFallback GUARDED_BY(mMutex); + std::vector<std::shared_ptr<FontCollection>> mCollections GUARDED_BY(mMutex); + std::mutex mMutex; }; |