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

Unified Diff: src/core/SkTypeface.cpp

Issue 1334523002: Revert of Port uses of SkLazyPtr to SkOncePtr. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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/SkPathRef.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 e6a9b4d66cd0f71988cb24e8eb840022ca9316d3..3ed2565ee23715cd1e16c75ad701a0e26c6fd3bc 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -9,9 +9,9 @@
#include "SkEndian.h"
#include "SkFontDescriptor.h"
#include "SkFontMgr.h"
+#include "SkLazyPtr.h"
#include "SkMutex.h"
#include "SkOTTable_OS_2.h"
-#include "SkOncePtr.h"
#include "SkStream.h"
#include "SkTypeface.h"
@@ -73,22 +73,33 @@
}
};
+namespace {
+
SK_DECLARE_STATIC_MUTEX(gCreateDefaultMutex);
-SK_DECLARE_STATIC_ONCE_PTR(SkTypeface, defaults[4]);
+
+// As a template arguments, these must have external linkage.
+SkTypeface* sk_create_default_typeface(int style) {
+ // 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, style);
+ return t ? t : SkEmptyTypeface::Create();
+}
+
+void sk_unref_typeface(SkTypeface* ptr) { SkSafeUnref(ptr); }
+
+} // namespace
+
+SK_DECLARE_STATIC_LAZY_PTR_ARRAY(SkTypeface, defaults, 4,
+ sk_create_default_typeface, sk_unref_typeface);
SkTypeface* SkTypeface::GetDefaultTypeface(Style style) {
SkASSERT((int)style < 4);
- 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, style);
- return t ? t : SkEmptyTypeface::Create();
- });
+ return defaults[style];
}
SkTypeface* SkTypeface::RefDefault(Style style) {
@@ -314,14 +325,22 @@
#include "SkDescriptor.h"
#include "SkPaint.h"
+struct SkTypeface::BoundsComputer {
+ const SkTypeface& fTypeface;
+
+ BoundsComputer(const SkTypeface& tf) : fTypeface(tf) {}
+
+ SkRect* operator()() const {
+ SkRect* rect = new SkRect;
+ if (!fTypeface.onComputeBounds(rect)) {
+ rect->setEmpty();
+ }
+ return rect;
+ }
+};
+
SkRect SkTypeface::getBounds() const {
- return *fLazyBounds.get([&] {
- SkRect* rect = new SkRect;
- if (!this->onComputeBounds(rect)) {
- rect->setEmpty();
- }
- return rect;
- });
+ return *fLazyBounds.get(BoundsComputer(*this));
}
bool SkTypeface::onComputeBounds(SkRect* bounds) const {
« no previous file with comments | « src/core/SkPathRef.cpp ('k') | src/core/SkXfermode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698