aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-31 00:15:22 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-31 00:15:22 +0000
commitf71e8fd0c5d2da9795d00a5b81b716ae585be14a (patch)
treefe05847a2462ba087f532fdd002c076dbdce541b /src/core
parent56f7cca144c539ec01f00d6382fded362ff193a3 (diff)
Revert of Port most uses of SkOnce to SkLazyPtr. (https://codereview.chromium.org/304383005/)
Reason for revert: linux x86-64 release segfault in src/ports/SkFontHost_fontconfig.cpp:107 http://108.170.220.120:10117/builders/Test-Ubuntu12-ShuttleA-GTX660-x86_64-Release/builds/905/steps/RunTests/logs/stdio Original issue's description: > Port most uses of SkOnce to SkLazyPtr. > > BUG=skia: > > Committed: http://code.google.com/p/skia/source/detail?r=15006 > > Committed: http://code.google.com/p/skia/source/detail?r=15014 R=reed@google.com, mtklein@chromium.org TBR=mtklein@chromium.org, reed@google.com NOTREECHECKS=true NOTRY=true BUG=skia: Author: mtklein@google.com Review URL: https://codereview.chromium.org/306063004 git-svn-id: http://skia.googlecode.com/svn/trunk@15015 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkFontHost.cpp17
-rwxr-xr-xsrc/core/SkGlyphCache.cpp18
-rw-r--r--src/core/SkLazyPtr.h2
-rw-r--r--src/core/SkMatrix.cpp40
-rw-r--r--src/core/SkMessageBus.h21
-rw-r--r--src/core/SkPathRef.cpp16
-rw-r--r--src/core/SkTypeface.cpp37
7 files changed, 85 insertions, 66 deletions
diff --git a/src/core/SkFontHost.cpp b/src/core/SkFontHost.cpp
index a16a8c42e0..9e7eeb182d 100644
--- a/src/core/SkFontHost.cpp
+++ b/src/core/SkFontHost.cpp
@@ -6,7 +6,7 @@
*/
#include "SkFontLCDConfig.h"
-#include "SkLazyPtr.h"
+#include "SkOnce.h"
static SkFontLCDConfig::LCDOrientation gLCDOrientation = SkFontLCDConfig::kHorizontal_LCDOrientation;
static SkFontLCDConfig::LCDOrder gLCDOrder = SkFontLCDConfig::kRGB_LCDOrder;
@@ -198,14 +198,19 @@ SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[],
return this->onLegacyCreateTypeface(familyName, styleBits);
}
-SkFontMgr* SkFontMgr::CreateDefault() {
- SkFontMgr* fm = SkFontMgr::Factory();
- return fm ? fm : SkNEW(SkEmptyFontMgr);
+void set_up_default(SkFontMgr** singleton) {
+ *singleton = SkFontMgr::Factory();
+ // we never want to return NULL
+ if (NULL == *singleton) {
+ *singleton = SkNEW(SkEmptyFontMgr);
+ }
}
SkFontMgr* SkFontMgr::RefDefault() {
- SK_DECLARE_STATIC_LAZY_PTR(SkFontMgr, singleton, CreateDefault);
- return SkRef(singleton.get());
+ static SkFontMgr* gFM = NULL;
+ SK_DECLARE_STATIC_ONCE(once);
+ SkOnce(&once, set_up_default, &gFM);
+ return SkRef(gFM);
}
//////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 2ab721aab4..699801d2db 100755
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -11,7 +11,7 @@
#include "SkGlyphCache_Globals.h"
#include "SkDistanceFieldGen.h"
#include "SkGraphics.h"
-#include "SkLazyPtr.h"
+#include "SkOnce.h"
#include "SkPaint.h"
#include "SkPath.h"
#include "SkTemplates.h"
@@ -21,18 +21,18 @@
//#define SPEW_PURGE_STATUS
//#define RECORD_HASH_EFFICIENCY
-namespace {
-
-SkGlyphCache_Globals* create_globals() {
- return SkNEW_ARGS(SkGlyphCache_Globals, (SkGlyphCache_Globals::kYes_UseMutex));
+static void create_globals(SkGlyphCache_Globals** globals) {
+ *globals = SkNEW_ARGS(SkGlyphCache_Globals, (SkGlyphCache_Globals::kYes_UseMutex));
}
-} // namespace
-
// Returns the shared globals
static SkGlyphCache_Globals& getSharedGlobals() {
- SK_DECLARE_STATIC_LAZY_PTR(SkGlyphCache_Globals, globals, create_globals);
- return *globals.get();
+ // we leak this, so we don't incur any shutdown cost of the destructor
+ static SkGlyphCache_Globals* gGlobals = NULL;
+ SK_DECLARE_STATIC_ONCE(once);
+ SkOnce(&once, create_globals, &gGlobals);
+ SkASSERT(NULL != gGlobals);
+ return *gGlobals;
}
// Returns the TLS globals (if set), or the shared globals
diff --git a/src/core/SkLazyPtr.h b/src/core/SkLazyPtr.h
index fa1a14e033..515086876c 100644
--- a/src/core/SkLazyPtr.h
+++ b/src/core/SkLazyPtr.h
@@ -64,6 +64,7 @@
// See FIXME below.
class SkFontConfigInterface;
+class SkTypeface;
namespace Private {
@@ -99,6 +100,7 @@ public:
#ifdef SK_DEBUG
// FIXME: We know we leak refs on some classes. For now, let them leak.
void cleanup(SkFontConfigInterface*) {}
+ void cleanup(SkTypeface*) {}
template <typename U> void cleanup(U* ptr) { Destroy(ptr); }
~SkLazyPtr() {
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index 8778f78f41..40f6e5298d 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -7,7 +7,7 @@
#include "SkMatrix.h"
#include "SkFloatBits.h"
-#include "SkLazyPtr.h"
+#include "SkOnce.h"
#include "SkString.h"
// In a few places, we performed the following
@@ -1558,33 +1558,29 @@ bool SkMatrix::getMinMaxScales(SkScalar scaleFactors[2]) const {
return get_scale_factor<kBoth_MinMaxOrBoth>(this->getType(), fMat, scaleFactors);
}
-namespace {
-
-SkMatrix* create_identity() {
- SkMatrix* m = SkNEW(SkMatrix);
- m->reset();
- return m;
-}
-
-SkMatrix* create_invalid() {
- SkMatrix* m = SkNEW(SkMatrix);
- m->setAll(SK_ScalarMax, SK_ScalarMax, SK_ScalarMax,
- SK_ScalarMax, SK_ScalarMax, SK_ScalarMax,
- SK_ScalarMax, SK_ScalarMax, SK_ScalarMax);
- m->getType(); // Force the type to be computed.
- return m;
+static void reset_identity_matrix(SkMatrix* identity) {
+ identity->reset();
}
-} // namespace
-
const SkMatrix& SkMatrix::I() {
- SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, identity, create_identity);
- return *identity.get();
+ // If you can use C++11 now, you might consider replacing this with a constexpr constructor.
+ static SkMatrix gIdentity;
+ SK_DECLARE_STATIC_ONCE(once);
+ SkOnce(&once, reset_identity_matrix, &gIdentity);
+ return gIdentity;
}
const SkMatrix& SkMatrix::InvalidMatrix() {
- SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, invalid, create_invalid);
- return *invalid.get();
+ static SkMatrix gInvalid;
+ static bool gOnce;
+ if (!gOnce) {
+ gInvalid.setAll(SK_ScalarMax, SK_ScalarMax, SK_ScalarMax,
+ SK_ScalarMax, SK_ScalarMax, SK_ScalarMax,
+ SK_ScalarMax, SK_ScalarMax, SK_ScalarMax);
+ gInvalid.getType(); // force the type to be computed
+ gOnce = true;
+ }
+ return gInvalid;
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkMessageBus.h b/src/core/SkMessageBus.h
index f36c42b4c7..ddeac57ac1 100644
--- a/src/core/SkMessageBus.h
+++ b/src/core/SkMessageBus.h
@@ -8,7 +8,7 @@
#ifndef SkMessageBus_DEFINED
#define SkMessageBus_DEFINED
-#include "SkLazyPtr.h"
+#include "SkOnce.h"
#include "SkTDArray.h"
#include "SkThread.h"
#include "SkTypes.h"
@@ -38,7 +38,7 @@ public:
private:
SkMessageBus();
static SkMessageBus* Get();
- static SkMessageBus* New();
+ static void New(SkMessageBus**);
SkTDArray<Inbox*> fInboxes;
SkMutex fInboxesMutex;
@@ -46,11 +46,14 @@ private:
// This must go in a single .cpp file, not some .h, or we risk creating more than one global
// SkMessageBus per type when using shared libraries.
-#define DECLARE_SKMESSAGEBUS_MESSAGE(Message) \
- template <> \
- SkMessageBus<Message>* SkMessageBus<Message>::Get() { \
- SK_DECLARE_STATIC_LAZY_PTR(SkMessageBus<Message>, bus, New); \
- return bus.get(); \
+#define DECLARE_SKMESSAGEBUS_MESSAGE(Message) \
+ template <> \
+ SkMessageBus<Message>* SkMessageBus<Message>::Get() { \
+ static SkMessageBus<Message>* bus = NULL; \
+ SK_DECLARE_STATIC_ONCE(once); \
+ SkOnce(&once, &New, &bus); \
+ SkASSERT(bus != NULL); \
+ return bus; \
}
// ----------------------- Implementation of SkMessageBus::Inbox -----------------------
@@ -97,8 +100,8 @@ template <typename Message>
SkMessageBus<Message>::SkMessageBus() {}
template <typename Message>
-/*static*/ SkMessageBus<Message>* SkMessageBus<Message>::New() {
- return SkNEW(SkMessageBus<Message>);
+/*static*/ void SkMessageBus<Message>::New(SkMessageBus<Message>** bus) {
+ *bus = new SkMessageBus<Message>();
}
template <typename Message>
diff --git a/src/core/SkPathRef.cpp b/src/core/SkPathRef.cpp
index de7a8f56ae..161eb80419 100644
--- a/src/core/SkPathRef.cpp
+++ b/src/core/SkPathRef.cpp
@@ -6,7 +6,7 @@
*/
#include "SkBuffer.h"
-#include "SkLazyPtr.h"
+#include "SkOnce.h"
#include "SkPath.h"
#include "SkPathRef.h"
@@ -28,16 +28,18 @@ SkPathRef::Editor::Editor(SkAutoTUnref<SkPathRef>* pathRef,
}
//////////////////////////////////////////////////////////////////////////////
+static SkPathRef* gEmptyPathRef = NULL;
+static void cleanup_gEmptyPathRef() { gEmptyPathRef->unref(); }
-SkPathRef* SkPathRef::CreateEmptyImpl() {
- SkPathRef* p = SkNEW(SkPathRef);
- p->computeBounds(); // Preemptively avoid a race to clear fBoundsIsDirty.
- return p;
+void SkPathRef::CreateEmptyImpl(int) {
+ gEmptyPathRef = SkNEW(SkPathRef);
+ gEmptyPathRef->computeBounds(); // Preemptively avoid a race to clear fBoundsIsDirty.
}
SkPathRef* SkPathRef::CreateEmpty() {
- SK_DECLARE_STATIC_LAZY_PTR(SkPathRef, empty, CreateEmptyImpl);
- return SkRef(empty.get());
+ SK_DECLARE_STATIC_ONCE(once);
+ SkOnce(&once, SkPathRef::CreateEmptyImpl, 0, cleanup_gEmptyPathRef);
+ return SkRef(gEmptyPathRef);
}
void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst,
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 6139c1e411..cd3953ba98 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -8,7 +8,7 @@
#include "SkAdvancedTypefaceMetrics.h"
#include "SkFontDescriptor.h"
#include "SkFontHost.h"
-#include "SkLazyPtr.h"
+#include "SkOnce.h"
#include "SkStream.h"
#include "SkTypeface.h"
@@ -74,23 +74,34 @@ protected:
}
};
-SkTypeface* SkTypeface::CreateDefault(int style) {
- SkTypeface* t = SkFontHost::CreateTypeface(NULL, NULL, (Style)style);
- return t ? t : SkEmptyTypeface::Create();
-}
+static SkTypeface* gDefaultTypefaces[] = { NULL, NULL, NULL, NULL };
+static const size_t FONT_STYLE_COUNT = SK_ARRAY_COUNT(gDefaultTypefaces);
+static SkOnceFlag gDefaultTypefaceOnce[FONT_STYLE_COUNT] = {
+ SK_ONCE_INIT, SK_ONCE_INIT, SK_ONCE_INIT, SK_ONCE_INIT
+};
+template <uintmax_t N> struct SkTIsPow2 {
+ static const bool value = (N & (N - 1)) == 0;
+};
+SK_COMPILE_ASSERT(SkTIsPow2<FONT_STYLE_COUNT>::value, FONT_STYLE_COUNT_not_power_of_2);
-void SkTypeface::DeleteDefault(SkTypeface* t) {
- // The SkTypeface returned by SkFontHost::CreateTypeface may _itself_ be a
- // cleverly-shared singleton. This is less than ideal. This means we
- // cannot just assert our ownership and SkDELETE(t) like we'd want to.
- SkSafeUnref(t);
+void SkTypeface::create_default_typeface(Style style) {
+ if (NULL == gDefaultTypefaces[style]) {
+ gDefaultTypefaces[style] = SkFontHost::CreateTypeface(NULL, NULL, style);
+ }
+ if (NULL == gDefaultTypefaces[style]) {
+ // FIXME: Use a singleton for SkEmptyTypeface.
+ gDefaultTypefaces[style] = SkEmptyTypeface::Create();
+ }
}
SkTypeface* SkTypeface::GetDefaultTypeface(Style style) {
- SK_DECLARE_STATIC_LAZY_PTR_ARRAY(SkTypeface, defaults, 4, CreateDefault, DeleteDefault);
+ SkASSERT((size_t)style < FONT_STYLE_COUNT);
+
+ // mask off any other bits to avoid a crash in SK_RELEASE
+ style = (Style)(style & (FONT_STYLE_COUNT - 1));
- SkASSERT((int)style < 4);
- return defaults[style];
+ SkOnce(&gDefaultTypefaceOnce[style], SkTypeface::create_default_typeface, style);
+ return gDefaultTypefaces[style];
}
SkTypeface* SkTypeface::RefDefault(Style style) {