use new PurgeFontCache() api

git-svn-id: http://skia.googlecode.com/svn/trunk@2633 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-11-08 20:03:48 +00:00
parent fe70112985
commit 073c90769e
4 changed files with 18 additions and 29 deletions

View File

@ -37,7 +37,8 @@ protected:
// this is critical - we want to time the creation process, so we
// explicitly flush our cache before each run
SkGraphics::SetFontCacheUsed(0);
SkGraphics::PurgeFontCache();
for (int ps = 9; ps <= 24; ps += 2) {
paint.setTextSize(SkIntToScalar(ps));
canvas->drawText(fText.c_str(), fText.size(),

View File

@ -23,20 +23,6 @@ public:
*/
static void GetVersion(int32_t* major, int32_t* minor, int32_t* patch);
// Font Cache routines
/**
* Return the (approximate) number of bytes used by the font cache.
*/
static size_t GetFontCacheUsed();
/**
* Attempt to purge the font cache until <= the specified amount remains
* in the cache. Specifying 0 will attempt to purge the entire cache.
* Returns true if some amount was purged from the font cache.
*/
static bool SetFontCacheUsed(size_t usageInBytes);
/**
* Return the max number of bytes that should be used by the font cache.
* If the cache needs to allocate more, it will purge previous entries.
@ -53,6 +39,13 @@ public:
*/
static size_t SetFontCacheLimit(size_t bytes);
/**
* For debugging purposes, this will attempt to purge the font cache. It
* does not change the limit, but will cause subsequent font measures and
* draws to be recreated, since they will no longer be in the cache.
*/
static void PurgeFontCache();
private:
/** This is automatically called by SkGraphics::Init(), and must be
implemented by the host OS. This allows the host OS to register a callback

View File

@ -1434,9 +1434,6 @@ bool SampleWindow::onHandleChar(SkUnichar uni) {
}
switch (uni) {
case 'd':
SkGraphics::SetFontCacheUsed(0);
return true;
case 'f':
// only
toggleFPS();

View File

@ -113,6 +113,8 @@ void SkGraphics::Init() {
SkDebugf("SkGraphics: sizeof(%s) = %d\n",
gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf);
}
SkDebugf("SkGraphics: font cache limit %dK\n",
GetFontCacheLimit() >> 10);
#endif
}
@ -123,19 +125,11 @@ void SkGraphics::Init() {
#include "SkTypefaceCache.h"
void SkGraphics::Term() {
SkGraphics::SetFontCacheUsed(0);
SkGlyphCache::SetCacheUsed(0);
SkTypefaceCache::PurgeAll();
SkGlobals::Term();
}
size_t SkGraphics::GetFontCacheUsed() {
return SkGlyphCache::GetCacheUsed();
}
bool SkGraphics::SetFontCacheUsed(size_t usageInBytes) {
return SkGlyphCache::SetCacheUsed(usageInBytes);
}
#ifndef SK_DEFAULT_FONT_CACHE_LIMIT
#define SK_DEFAULT_FONT_CACHE_LIMIT (2 * 1024 * 1024)
#endif
@ -157,9 +151,13 @@ size_t SkGraphics::SetFontCacheLimit(size_t bytes) {
gFontCacheLimit = bytes;
// trigger a purge if the new size is smaller that our currently used amount
if (bytes < GetFontCacheUsed()) {
SetFontCacheUsed(bytes);
if (bytes < SkGlyphCache::GetCacheUsed()) {
SkGlyphCache::SetCacheUsed(bytes);
}
return prev;
}
void SkGraphics::PurgeFontCache() {
SkGlyphCache::SetCacheUsed(0);
}