aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/SkGlyphCache.cpp
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2012-01-18 08:56:56 -0500
committerDerek Sollenberger <derek@android.com>2012-02-06 14:14:40 -0500
commit1cab2921ab279367f8206cdadc9259d12e603548 (patch)
tree2852f9dc2481f639122e18fc7831ae6ca43d6d5a /src/core/SkGlyphCache.cpp
parentd7176fd5571bc9878d3cdac8696eaa35ec170d9d (diff)
downloadexternal_skia-1cab2921ab279367f8206cdadc9259d12e603548.zip
external_skia-1cab2921ab279367f8206cdadc9259d12e603548.tar.gz
external_skia-1cab2921ab279367f8206cdadc9259d12e603548.tar.bz2
Skia merge (revision 3022)
This CL has companion changes to account for API updates in... (1) frameworks/base (2) external/webkit Change-Id: Ibb989e76e8bd24313849f9631dbef42cdef9eb7d
Diffstat (limited to 'src/core/SkGlyphCache.cpp')
-rw-r--r--src/core/SkGlyphCache.cpp91
1 files changed, 41 insertions, 50 deletions
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index ad790e8..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
@@ -301,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;
}
}
@@ -389,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)
@@ -413,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;
@@ -429,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;
@@ -476,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;
@@ -538,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();
@@ -547,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);
@@ -565,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);
@@ -575,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;
@@ -649,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);
}