Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Unified Diff: src/core/SkTypeface.cpp

Issue 1945293004: Revert of SkOncePtr -> SkOnce (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkTaskGroup.cpp ('k') | src/core/SkXfermode.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkTypeface.cpp
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 75bb05c2b13cbfac283b36281850603e0206f3c0..3830c46c7af2e5c608310ab9f098ff862ccc0e00 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -11,7 +11,7 @@
#include "SkFontMgr.h"
#include "SkMutex.h"
#include "SkOTTable_OS_2.h"
-#include "SkOnce.h"
+#include "SkOncePtr.h"
#include "SkStream.h"
#include "SkTypeface.h"
@@ -79,23 +79,21 @@
}
SK_DECLARE_STATIC_MUTEX(gCreateDefaultMutex);
+SK_DECLARE_STATIC_ONCE_PTR(SkTypeface, defaults[4]);
SkTypeface* SkTypeface::GetDefaultTypeface(Style style) {
- static SkOnce once[4];
- static SkTypeface* defaults[4];
-
SkASSERT((int)style < 4);
- once[style]([style] {
+ return defaults[style].get([=]{
// It is not safe to call FontConfigTypeface::LegacyCreateTypeface concurrently.
// To be safe, we serialize here with a mutex so only one call to
// CreateTypeface is happening at any given time.
// TODO(bungeman, mtklein): This is sad. Make our fontconfig code safe?
SkAutoMutexAcquire lock(&gCreateDefaultMutex);
+
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
SkTypeface* t = fm->legacyCreateTypeface(nullptr, SkFontStyle::FromOldStyle(style));
- defaults[style] = t ? t : SkEmptyTypeface::Create();
+ return t ? t : SkEmptyTypeface::Create();
});
- return defaults[style];
}
SkTypeface* SkTypeface::RefDefault(Style style) {
« no previous file with comments | « src/core/SkTaskGroup.cpp ('k') | src/core/SkXfermode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698