diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkGlobals.cpp | 84 | ||||
-rw-r--r-- | src/core/SkGlyphCache.cpp | 8 | ||||
-rw-r--r-- | src/core/SkGraphics.cpp | 4 | ||||
-rw-r--r-- | src/ports/SkGlobals_global.cpp | 20 | ||||
-rw-r--r-- | src/views/SkEvent.cpp | 57 | ||||
-rw-r--r-- | src/views/SkEventSink.cpp | 67 |
6 files changed, 63 insertions, 177 deletions
diff --git a/src/core/SkGlobals.cpp b/src/core/SkGlobals.cpp deleted file mode 100644 index e385734bb5..0000000000 --- a/src/core/SkGlobals.cpp +++ /dev/null @@ -1,84 +0,0 @@ - -/* - * Copyright 2006 The Android Open Source Project - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - - -#include "SkGlobals.h" -#include "SkThread.h" - -SkGlobals::Rec::~Rec() -{ -} - -SkGlobals::Rec* SkGlobals::Find(uint32_t tag, Rec* (*create_proc)()) -{ - SkGlobals::BootStrap& bootstrap = SkGlobals::GetBootStrap(); - - Rec* rec = bootstrap.fHead; - while (rec) - { - if (rec->fTag == tag) - return rec; - rec = rec->fNext; - } - - if (create_proc == NULL) // no create proc, just return not found - return NULL; - - // if we get here, we may need to create one. First grab the mutex, and - // search again, creating one if its not found the 2nd time. - - bootstrap.fMutex.acquire(); - - // search again, now that we have the mutex. Odds are it won't be there, but we check again - // just in case it was added by another thread before we grabbed the mutex - - Rec*& head = bootstrap.fHead; - rec = head; - while (rec) - { - if (rec->fTag == tag) - break; - rec = rec->fNext; - } - - if (rec == NULL && (rec = create_proc()) != NULL) - { - rec->fTag = tag; - rec->fNext = head; - bootstrap.fHead = rec; - } - - bootstrap.fMutex.release(); - return rec; -} - -void SkGlobals::Init() -{ -} - -void SkGlobals::Term() -{ - SkGlobals::BootStrap& bootstrap = SkGlobals::GetBootStrap(); - - bootstrap.fMutex.acquire(); - - Rec*& head = bootstrap.fHead; - Rec* rec = head; - - while (rec) - { - Rec* next = rec->fNext; - SkDELETE(rec); - rec = next; - } - - bootstrap.fHead = NULL; - bootstrap.fMutex.release(); -} - - diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp index e2bed06a6a..c3725a6d55 100644 --- a/src/core/SkGlyphCache.cpp +++ b/src/core/SkGlyphCache.cpp @@ -410,6 +410,14 @@ void SkGlyphCache::invokeAndRemoveAuxProcs() { class SkGlyphCache_Globals { public: + SkGlyphCache_Globals() { + fHead = NULL; + fTotalMemoryUsed = 0; +#ifdef USE_CACHE_HASH + sk_bzero(fHash, sizeof(fHash)); +#endif + } + SkMutex fMutex; SkGlyphCache* fHead; size_t fTotalMemoryUsed; diff --git a/src/core/SkGraphics.cpp b/src/core/SkGraphics.cpp index 542a1997ab..a69ac370fd 100644 --- a/src/core/SkGraphics.cpp +++ b/src/core/SkGraphics.cpp @@ -14,7 +14,6 @@ #include "SkCanvas.h" #include "SkFloat.h" #include "SkGeometry.h" -#include "SkGlobals.h" #include "SkMath.h" #include "SkMatrix.h" #include "SkPath.h" @@ -52,8 +51,6 @@ void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) { #endif void SkGraphics::Init() { - SkGlobals::Init(); - #ifdef BUILD_EMBOSS_TABLE SkEmbossMask_BuildTable(); #endif @@ -127,7 +124,6 @@ void SkGraphics::Init() { void SkGraphics::Term() { SkGlyphCache::SetCacheUsed(0); SkTypefaceCache::PurgeAll(); - SkGlobals::Term(); } #ifndef SK_DEFAULT_FONT_CACHE_LIMIT diff --git a/src/ports/SkGlobals_global.cpp b/src/ports/SkGlobals_global.cpp deleted file mode 100644 index bf8e159a8a..0000000000 --- a/src/ports/SkGlobals_global.cpp +++ /dev/null @@ -1,20 +0,0 @@ - -/* - * Copyright 2006 The Android Open Source Project - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - - -#include "SkGlobals.h" -#include "SkThread.h" - -static SkGlobals::BootStrap gBootStrap; - -SkGlobals::BootStrap& SkGlobals::GetBootStrap() -{ - return gBootStrap; -} - - diff --git a/src/views/SkEvent.cpp b/src/views/SkEvent.cpp index c7ac638ce8..82f237958b 100644 --- a/src/views/SkEvent.cpp +++ b/src/views/SkEvent.cpp @@ -265,28 +265,28 @@ void SkEvent::inflate(const SkDOM& dom, const SkDOM::Node* node) #define EVENT_LOGN(s, n) #endif -#include "SkGlobals.h" #include "SkThread.h" #include "SkTime.h" -#define SK_Event_GlobalsTag SkSetFourByteTag('e', 'v', 'n', 't') - -class SkEvent_Globals : public SkGlobals::Rec { +class SkEvent_Globals { public: + SkEvent_Globals() { + fEventQHead = NULL; + fEventQTail = NULL; + fDelayQHead = NULL; + SkDEBUGCODE(fEventCounter = 0;) + } + SkMutex fEventMutex; SkEvent* fEventQHead, *fEventQTail; SkEvent* fDelayQHead; SkDEBUGCODE(int fEventCounter;) }; -static SkGlobals::Rec* create_globals() -{ - SkEvent_Globals* rec = new SkEvent_Globals; - rec->fEventQHead = NULL; - rec->fEventQTail = NULL; - rec->fDelayQHead = NULL; - SkDEBUGCODE(rec->fEventCounter = 0;) - return rec; +static SkEvent_Globals& getGlobals() { + // leak this, so we don't incure any shutdown perf hit + static SkEvent_Globals* gGlobals = new SkEvent_Globals; + return *gGlobals; } /////////////////////////////////////////////////////////////////////////////// @@ -302,7 +302,7 @@ void SkEvent::postDelay(SkMSec delay) { return; } - SkEvent_Globals& globals = *(SkEvent_Globals*)SkGlobals::Find(SK_Event_GlobalsTag, create_globals); + SkEvent_Globals& globals = getGlobals(); globals.fEventMutex.acquire(); bool wasEmpty = SkEvent::Enqueue(this); @@ -320,7 +320,7 @@ void SkEvent::postTime(SkMSec time) { return; } - SkEvent_Globals& globals = *(SkEvent_Globals*)SkGlobals::Find(SK_Event_GlobalsTag, create_globals); + SkEvent_Globals& globals = getGlobals(); globals.fEventMutex.acquire(); SkMSec queueDelay = SkEvent::EnqueueTime(this, time); @@ -333,7 +333,7 @@ void SkEvent::postTime(SkMSec time) { } bool SkEvent::Enqueue(SkEvent* evt) { - SkEvent_Globals& globals = *(SkEvent_Globals*)SkGlobals::Find(SK_Event_GlobalsTag, create_globals); + SkEvent_Globals& globals = getGlobals(); // gEventMutex acquired by caller SkASSERT(evt); @@ -353,7 +353,7 @@ bool SkEvent::Enqueue(SkEvent* evt) { } SkEvent* SkEvent::Dequeue() { - SkEvent_Globals& globals = *(SkEvent_Globals*)SkGlobals::Find(SK_Event_GlobalsTag, create_globals); + SkEvent_Globals& globals = getGlobals(); globals.fEventMutex.acquire(); SkEvent* evt = globals.fEventQHead; @@ -371,7 +371,7 @@ SkEvent* SkEvent::Dequeue() { } bool SkEvent::QHasEvents() { - SkEvent_Globals& globals = *(SkEvent_Globals*)SkGlobals::Find(SK_Event_GlobalsTag, create_globals); + SkEvent_Globals& globals = getGlobals(); // this is not thread accurate, need a semaphore for that return globals.fEventQHead != NULL; @@ -382,7 +382,7 @@ bool SkEvent::QHasEvents() { #endif SkMSec SkEvent::EnqueueTime(SkEvent* evt, SkMSec time) { - SkEvent_Globals& globals = *(SkEvent_Globals*)SkGlobals::Find(SK_Event_GlobalsTag, create_globals); + SkEvent_Globals& globals = getGlobals(); // gEventMutex acquired by caller SkEvent* curr = globals.fDelayQHead; @@ -431,7 +431,7 @@ bool SkEvent::ProcessEvent() { void SkEvent::ServiceQueueTimer() { - SkEvent_Globals& globals = *(SkEvent_Globals*)SkGlobals::Find(SK_Event_GlobalsTag, create_globals); + SkEvent_Globals& globals = getGlobals(); globals.fEventMutex.acquire(); @@ -471,7 +471,7 @@ void SkEvent::ServiceQueueTimer() } int SkEvent::CountEventsOnQueue() { - SkEvent_Globals& globals = *(SkEvent_Globals*)SkGlobals::Find(SK_Event_GlobalsTag, create_globals); + SkEvent_Globals& globals = getGlobals(); globals.fEventMutex.acquire(); int count = 0; @@ -485,27 +485,22 @@ int SkEvent::CountEventsOnQueue() { return count; } -//////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// -void SkEvent::Init() -{ -} +void SkEvent::Init() {} -void SkEvent::Term() -{ - SkEvent_Globals& globals = *(SkEvent_Globals*)SkGlobals::Find(SK_Event_GlobalsTag, create_globals); +void SkEvent::Term() { + SkEvent_Globals& globals = getGlobals(); SkEvent* evt = globals.fEventQHead; - while (evt) - { + while (evt) { SkEvent* next = evt->fNextEvent; delete evt; evt = next; } evt = globals.fDelayQHead; - while (evt) - { + while (evt) { SkEvent* next = evt->fNextEvent; delete evt; evt = next; diff --git a/src/views/SkEventSink.cpp b/src/views/SkEventSink.cpp index 9d3482af2a..0b01669a61 100644 --- a/src/views/SkEventSink.cpp +++ b/src/views/SkEventSink.cpp @@ -11,30 +11,29 @@ #include "SkTagList.h" #include "SkThread.h" -#include "SkGlobals.h" #include "SkThread.h" #include "SkTime.h" -#define SK_EventSink_GlobalsTag SkSetFourByteTag('e', 'v', 's', 'k') - -class SkEventSink_Globals : public SkGlobals::Rec { +class SkEventSink_Globals { public: + SkEventSink_Globals() { + fNextSinkID = 0; + fSinkHead = NULL; + } + SkMutex fSinkMutex; SkEventSinkID fNextSinkID; SkEventSink* fSinkHead; }; -static SkGlobals::Rec* create_globals() -{ - SkEventSink_Globals* rec = new SkEventSink_Globals; - rec->fNextSinkID = 0; - rec->fSinkHead = NULL; - return rec; +static SkEventSink_Globals& getGlobals() { + // leak this, so we don't incur any shutdown perf hit + static SkEventSink_Globals* gGlobals = new SkEventSink_Globals; + return *gGlobals; } -SkEventSink::SkEventSink() : fTagHead(NULL) -{ - SkEventSink_Globals& globals = *(SkEventSink_Globals*)SkGlobals::Find(SK_EventSink_GlobalsTag, create_globals); +SkEventSink::SkEventSink() : fTagHead(NULL) { + SkEventSink_Globals& globals = getGlobals(); globals.fSinkMutex.acquire(); @@ -45,9 +44,8 @@ SkEventSink::SkEventSink() : fTagHead(NULL) globals.fSinkMutex.release(); } -SkEventSink::~SkEventSink() -{ - SkEventSink_Globals& globals = *(SkEventSink_Globals*)SkGlobals::Find(SK_EventSink_GlobalsTag, create_globals); +SkEventSink::~SkEventSink() { + SkEventSink_Globals& globals = getGlobals(); if (fTagHead) SkTagList::DeleteAll(fTagHead); @@ -57,15 +55,14 @@ SkEventSink::~SkEventSink() SkEventSink* sink = globals.fSinkHead; SkEventSink* prev = NULL; - for (;;) - { + for (;;) { SkEventSink* next = sink->fNextSink; - if (sink == this) - { - if (prev) + if (sink == this) { + if (prev) { prev->fNextSink = next; - else + } else { globals.fSinkHead = next; + } break; } prev = sink; @@ -74,36 +71,30 @@ SkEventSink::~SkEventSink() globals.fSinkMutex.release(); } -bool SkEventSink::doEvent(const SkEvent& evt) -{ +bool SkEventSink::doEvent(const SkEvent& evt) { return this->onEvent(evt); } -bool SkEventSink::doQuery(SkEvent* evt) -{ +bool SkEventSink::doQuery(SkEvent* evt) { SkASSERT(evt); return this->onQuery(evt); } -bool SkEventSink::onEvent(const SkEvent&) -{ +bool SkEventSink::onEvent(const SkEvent&) { return false; } -bool SkEventSink::onQuery(SkEvent*) -{ +bool SkEventSink::onQuery(SkEvent*) { return false; } /////////////////////////////////////////////////////////////////////////////// -SkTagList* SkEventSink::findTagList(U8CPU tag) const -{ +SkTagList* SkEventSink::findTagList(U8CPU tag) const { return fTagHead ? SkTagList::Find(fTagHead, tag) : NULL; } -void SkEventSink::addTagList(SkTagList* rec) -{ +void SkEventSink::addTagList(SkTagList* rec) { SkASSERT(rec); SkASSERT(fTagHead == NULL || SkTagList::Find(fTagHead, rec->fTag) == NULL); @@ -111,10 +102,10 @@ void SkEventSink::addTagList(SkTagList* rec) fTagHead = rec; } -void SkEventSink::removeTagList(U8CPU tag) -{ - if (fTagHead) +void SkEventSink::removeTagList(U8CPU tag) { + if (fTagHead) { SkTagList::DeleteTag(&fTagHead, tag); + } } /////////////////////////////////////////////////////////////////////////////// @@ -247,7 +238,7 @@ SkEventSink* SkEventSink::FindSink(SkEventSinkID sinkID) if (sinkID == 0) return 0; - SkEventSink_Globals& globals = *(SkEventSink_Globals*)SkGlobals::Find(SK_EventSink_GlobalsTag, create_globals); + SkEventSink_Globals& globals = getGlobals(); SkAutoMutexAcquire ac(globals.fSinkMutex); SkEventSink* sink = globals.fSinkHead; |