aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkTypeface.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-09-09 09:09:53 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-09-09 09:09:53 -0700
commit6c59d80858f453a426df9b07fdf3a8cc01e0b906 (patch)
tree1fc4c3c03062744c4382a40e608bdb147bebad09 /src/core/SkTypeface.cpp
parent336cda3fc0e01cd80212e0ac133d65b60824868e (diff)
Port uses of SkLazyPtr to SkOncePtr.
This gives SkOncePtr a non-trivial destructor that uses std::default_delete by default. This is overrideable, as seen in SkColorTable. SK_DECLARE_STATIC_ONCE_PTR still just leaves its pointers hanging at EOP. BUG=skia: No public API changes. TBR=reed@google.com Committed: https://skia.googlesource.com/skia/+/a1254acdb344174e761f5061c820559dab64a74c Review URL: https://codereview.chromium.org/1322933005
Diffstat (limited to 'src/core/SkTypeface.cpp')
-rw-r--r--src/core/SkTypeface.cpp53
1 files changed, 17 insertions, 36 deletions
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 3ed2565ee2..e6a9b4d66c 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,33 +73,22 @@ protected:
}
};
-namespace {
-
SK_DECLARE_STATIC_MUTEX(gCreateDefaultMutex);
-
-// 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);
+SK_DECLARE_STATIC_ONCE_PTR(SkTypeface, defaults[4]);
SkTypeface* SkTypeface::GetDefaultTypeface(Style style) {
SkASSERT((int)style < 4);
- return defaults[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, style);
+ return t ? t : SkEmptyTypeface::Create();
+ });
}
SkTypeface* SkTypeface::RefDefault(Style style) {
@@ -325,22 +314,14 @@ bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count,
#include "SkDescriptor.h"
#include "SkPaint.h"
-struct SkTypeface::BoundsComputer {
- const SkTypeface& fTypeface;
-
- BoundsComputer(const SkTypeface& tf) : fTypeface(tf) {}
-
- SkRect* operator()() const {
+SkRect SkTypeface::getBounds() const {
+ return *fLazyBounds.get([&] {
SkRect* rect = new SkRect;
- if (!fTypeface.onComputeBounds(rect)) {
+ if (!this->onComputeBounds(rect)) {
rect->setEmpty();
}
return rect;
- }
-};
-
-SkRect SkTypeface::getBounds() const {
- return *fLazyBounds.get(BoundsComputer(*this));
+ });
}
bool SkTypeface::onComputeBounds(SkRect* bounds) const {