aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/SkGlyphCache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/SkGlyphCache.cpp')
-rw-r--r--src/core/SkGlyphCache.cpp98
1 files changed, 41 insertions, 57 deletions
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 56a2680..9f0dfba 100644
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -1,22 +1,14 @@
-/* libs/graphics/sgl/SkGlyphCache.cpp
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
+
+/*
+ * 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 "SkGlyphCache.h"
-#include "SkFontHost.h"
+#include "SkGraphics.h"
#include "SkPaint.h"
#include "SkTemplates.h"
@@ -24,6 +16,8 @@
//#define USE_CACHE_HASH
//#define RECORD_HASH_EFFICIENCY
+bool gSkSuppressFontCachePurgeSpew;
+
///////////////////////////////////////////////////////////////////////////////
#ifdef RECORD_HASH_EFFICIENCY
@@ -121,13 +115,6 @@ unsigned SkGlyphCache::getGlyphCount() {
return fScalerContext->getGlyphCount();
}
-#ifdef ANDROID
-unsigned SkGlyphCache::getBaseGlyphCount(SkUnichar charCode) {
- SkScalerContext* ctx = fScalerContext->charToScalerContext(charCode);
- return ctx->getBaseGlyphCount();
-}
-#endif
-
///////////////////////////////////////////////////////////////////////////////
const SkGlyph& SkGlyphCache::getUnicharAdvance(SkUnichar charCode) {
@@ -308,6 +295,10 @@ const void* SkGlyphCache::findImage(const SkGlyph& glyph) {
// check that alloc() actually succeeded
if (glyph.fImage) {
fScalerContext->getImage(glyph);
+ // TODO: the scaler may have changed the maskformat during
+ // getImage (e.g. from AA or LCD to BW) which means we may have
+ // overallocated the buffer. Check if the new computedImageSize
+ // is smaller, and if so, strink the alloc size in fImageAlloc.
fMemoryUsed += size;
}
}
@@ -396,11 +387,6 @@ void SkGlyphCache::invokeAndRemoveAuxProcs() {
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-#include "SkGlobals.h"
-#include "SkThread.h"
-
-#define SkGlyphCache_GlobalsTag SkSetFourByteTag('g', 'l', 'f', 'c')
-
#ifdef USE_CACHE_HASH
#define HASH_BITCOUNT 6
#define HASH_COUNT (1 << HASH_BITCOUNT)
@@ -420,8 +406,18 @@ void SkGlyphCache::invokeAndRemoveAuxProcs() {
}
#endif
-class SkGlyphCache_Globals : public SkGlobals::Rec {
+#include "SkThread.h"
+
+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;
@@ -436,28 +432,15 @@ public:
#endif
};
-#ifdef SK_USE_RUNTIME_GLOBALS
- static SkGlobals::Rec* create_globals() {
- SkGlyphCache_Globals* rec = SkNEW(SkGlyphCache_Globals);
- rec->fHead = NULL;
- rec->fTotalMemoryUsed = 0;
-#ifdef USE_CACHE_HASH
- memset(rec->fHash, 0, sizeof(rec->fHash));
-#endif
- return rec;
- }
-
- #define FIND_GC_GLOBALS() *(SkGlyphCache_Globals*)SkGlobals::Find(SkGlyphCache_GlobalsTag, create_globals)
- #define GET_GC_GLOBALS() *(SkGlyphCache_Globals*)SkGlobals::Get(SkGlyphCache_GlobalsTag)
-#else
- static SkGlyphCache_Globals gGCGlobals;
- #define FIND_GC_GLOBALS() gGCGlobals
- #define GET_GC_GLOBALS() gGCGlobals
-#endif
+static SkGlyphCache_Globals& getGlobals() {
+ // we leak this, so we don't incur any shutdown cost of the destructor
+ static SkGlyphCache_Globals* gGlobals = new SkGlyphCache_Globals;
+ return *gGlobals;
+}
void SkGlyphCache::VisitAllCaches(bool (*proc)(SkGlyphCache*, void*),
void* context) {
- SkGlyphCache_Globals& globals = FIND_GC_GLOBALS();
+ SkGlyphCache_Globals& globals = getGlobals();
SkAutoMutexAcquire ac(globals.fMutex);
SkGlyphCache* cache;
@@ -483,7 +466,7 @@ SkGlyphCache* SkGlyphCache::VisitCache(const SkDescriptor* desc,
void* context) {
SkASSERT(desc);
- SkGlyphCache_Globals& globals = FIND_GC_GLOBALS();
+ SkGlyphCache_Globals& globals = getGlobals();
SkAutoMutexAcquire ac(globals.fMutex);
SkGlyphCache* cache;
bool insideMutex = true;
@@ -545,7 +528,7 @@ void SkGlyphCache::AttachCache(SkGlyphCache* cache) {
SkASSERT(cache);
SkASSERT(cache->fNext == NULL);
- SkGlyphCache_Globals& globals = GET_GC_GLOBALS();
+ SkGlyphCache_Globals& globals = getGlobals();
SkAutoMutexAcquire ac(globals.fMutex);
globals.validate();
@@ -554,9 +537,10 @@ void SkGlyphCache::AttachCache(SkGlyphCache* cache) {
// if we have a fixed budget for our cache, do a purge here
{
size_t allocated = globals.fTotalMemoryUsed + cache->fMemoryUsed;
- size_t amountToFree = SkFontHost::ShouldPurgeFontCache(allocated);
- if (amountToFree)
- (void)InternalFreeCache(&globals, amountToFree);
+ size_t budgeted = SkGraphics::GetFontCacheLimit();
+ if (allocated > budgeted) {
+ (void)InternalFreeCache(&globals, allocated - budgeted);
+ }
}
cache->attachToHead(&globals.fHead);
@@ -572,7 +556,7 @@ void SkGlyphCache::AttachCache(SkGlyphCache* cache) {
}
size_t SkGlyphCache::GetCacheUsed() {
- SkGlyphCache_Globals& globals = FIND_GC_GLOBALS();
+ SkGlyphCache_Globals& globals = getGlobals();
SkAutoMutexAcquire ac(globals.fMutex);
return SkGlyphCache::ComputeMemoryUsed(globals.fHead);
@@ -582,7 +566,7 @@ bool SkGlyphCache::SetCacheUsed(size_t bytesUsed) {
size_t curr = SkGlyphCache::GetCacheUsed();
if (curr > bytesUsed) {
- SkGlyphCache_Globals& globals = FIND_GC_GLOBALS();
+ SkGlyphCache_Globals& globals = getGlobals();
SkAutoMutexAcquire ac(globals.fMutex);
return InternalFreeCache(&globals, curr - bytesUsed) > 0;
@@ -656,7 +640,7 @@ size_t SkGlyphCache::InternalFreeCache(SkGlyphCache_Globals* globals,
globals->validate();
#ifdef SPEW_PURGE_STATUS
- if (count) {
+ if (count && !gSkSuppressFontCachePurgeSpew) {
SkDebugf("purging %dK from font cache [%d entries]\n",
(int)(bytesFreed >> 10), count);
}