add api to SkGraphics to get/set font cache limit

add SK_DEFAULT_FONT_CACHE_LIMIT to SkUserConfig, to override our default value



git-svn-id: http://skia.googlecode.com/svn/trunk@2621 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-11-08 13:48:32 +00:00
Родитель ca08edd7a8
Коммит 77407ca019
14 изменённых файлов: 76 добавлений и 114 удалений

Просмотреть файл

@ -105,6 +105,12 @@
*/
//#define SkDebugf(...) MyFunction(__VA_ARGS__)
/*
* To specify a different default font cache limit, define this. If this is
* undefined, skia will use a built-in value.
*/
//#define SK_DEFAULT_FONT_CACHE_LIMIT (1024 * 1024)
/* If defined, use CoreText instead of ATSUI on OS X.
*/
//#define SK_USE_MAC_CORE_TEXT

Просмотреть файл

@ -232,14 +232,6 @@ public:
///////////////////////////////////////////////////////////////////////////
/** Return the number of bytes (approx) that should be purged from the font
cache. The input parameter is the cache's estimate of how much as been
allocated by the cache so far.
To purge (basically) everything, return the input parameter.
To purge nothing, return 0
*/
static size_t ShouldPurgeFontCache(size_t sizeAllocatedSoFar);
/** Return SkScalerContext gamma flag, or 0, based on the paint that will be
used to draw something with antialiasing.
*/

Просмотреть файл

@ -17,21 +17,42 @@ public:
static void Init();
static void Term();
/** 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 version numbers for the library. If the parameter is not
null, it is set to the version number.
/**
* Return the version numbers for the library. If the parameter is not
* null, it is set to the version number.
*/
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.
* This max can be changed by calling SetFontCacheLimit().
*/
static size_t GetFontCacheLimit();
/**
* Specify 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.
*
* This function returns the previous setting, as if GetFontCacheLimit()
* had be called before the new limit was set.
*/
static size_t SetFontCacheLimit(size_t bytes);
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

Просмотреть файл

@ -8,7 +8,7 @@
#include "SkGlyphCache.h"
#include "SkFontHost.h"
#include "SkGraphics.h"
#include "SkPaint.h"
#include "SkTemplates.h"
@ -545,9 +545,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);

Просмотреть файл

@ -29,6 +29,18 @@
#include "SkUtils.h"
#include "SkXfermode.h"
void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) {
if (major) {
*major = SKIA_VERSION_MAJOR;
}
if (minor) {
*minor = SKIA_VERSION_MINOR;
}
if (patch) {
*patch = SKIA_VERSION_PATCH;
}
}
#define typesizeline(type) { #type , sizeof(type) }
#ifdef BUILD_EMBOSS_TABLE
@ -124,15 +136,27 @@ bool SkGraphics::SetFontCacheUsed(size_t usageInBytes) {
return SkGlyphCache::SetCacheUsed(usageInBytes);
}
void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) {
if (major) {
*major = SKIA_VERSION_MAJOR;
#ifndef SK_DEFAULT_FONT_CACHE_LIMIT
#define SK_DEFAULT_FONT_CACHE_LIMIT (1024 * 1024)
#endif
#define SK_MIN_FONT_CACHE_LIMIT (256 * 1024)
static size_t gFontCacheLimit = SK_DEFAULT_FONT_CACHE_LIMIT;
size_t SkGraphics::GetFontCacheLimit() {
return gFontCacheLimit;
}
size_t SkGraphics::SetFontCacheLimit(size_t bytes) {
if (bytes < SK_MIN_FONT_CACHE_LIMIT) {
bytes = SK_MIN_FONT_CACHE_LIMIT;
}
if (minor) {
*minor = SKIA_VERSION_MINOR;
}
if (patch) {
*patch = SKIA_VERSION_PATCH;
gFontCacheLimit = bytes;
// trigger a purge if the new size is smaller that our currently used amount
if (bytes < GetFontCacheUsed()) {
SetFontCacheUsed(bytes);
}
}

Просмотреть файл

@ -324,8 +324,3 @@ SkScalerContext* SkFontHost::CreateFallbackScalerContext(
return SkFontHost::CreateScalerContext(desc);
}
size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar)
{
return 0; // nothing to do (change me if you want to limit the font cache)
}

Просмотреть файл

@ -26,8 +26,6 @@
#include "FontHostConfiguration_android.h"
#include <stdio.h>
#define FONT_CACHE_MEMORY_BUDGET (768 * 1024)
#ifndef SK_FONT_FILE_PREFIX
#define SK_FONT_FILE_PREFIX "/fonts/"
#endif
@ -763,12 +761,3 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
return face;
}
///////////////////////////////////////////////////////////////////////////////
size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar) {
if (sizeAllocatedSoFar > FONT_CACHE_MEMORY_BUDGET)
return sizeAllocatedSoFar - FONT_CACHE_MEMORY_BUDGET;
else
return 0; // nothing to do
}

Просмотреть файл

@ -44,9 +44,6 @@ static std::map<unsigned, std::string> global_fc_map_inverted;
static std::map<uint32_t, SkTypeface *> global_fc_typefaces;
static unsigned global_fc_map_next_id = 0;
// This is the maximum size of the font cache.
static const unsigned kFontCacheMemoryBudget = 2 * 1024 * 1024; // 2MB
static unsigned UniqueIdToFileId(unsigned uniqueid)
{
return uniqueid >> 8;
@ -361,12 +358,3 @@ SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
return 0;
}
///////////////////////////////////////////////////////////////////////////////
size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar)
{
if (sizeAllocatedSoFar > kFontCacheMemoryBudget)
return sizeAllocatedSoFar - kFontCacheMemoryBudget;
else
return 0; // nothing to do
}

Просмотреть файл

@ -18,8 +18,6 @@
#include "SkTSearch.h"
#include <stdio.h>
#define FONT_CACHE_MEMORY_BUDGET (1 * 1024 * 1024)
#ifndef SK_FONT_FILE_PREFIX
#define SK_FONT_FILE_PREFIX "/usr/share/fonts/truetype/msttcorefonts/"
#endif
@ -600,12 +598,3 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
return face;
}
///////////////////////////////////////////////////////////////////////////////
size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar) {
if (sizeAllocatedSoFar > FONT_CACHE_MEMORY_BUDGET)
return sizeAllocatedSoFar - FONT_CACHE_MEMORY_BUDGET;
else
return 0; // nothing to do
}

Просмотреть файл

@ -15,9 +15,6 @@
#include "SkPaint.h"
#include "SkPoint.h"
// Give 1MB font cache budget
#define FONT_CACHE_MEMORY_BUDGET (1024 * 1024)
const char* gDefaultfont = "Arial"; // hard code for now
static SkMutex gFTMutex;
@ -508,13 +505,6 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
}
}
size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar) {
if (sizeAllocatedSoFar > FONT_CACHE_MEMORY_BUDGET)
return sizeAllocatedSoFar - FONT_CACHE_MEMORY_BUDGET;
else
return 0; // nothing to do
}
int SkFontHost::ComputeGammaFlag(const SkPaint& paint) {
return 0;
}

Просмотреть файл

@ -160,7 +160,6 @@ static unsigned CGRGBPixel_getAlpha(CGRGBPixel pixel) {
using namespace skia_advanced_typeface_metrics_utils;
static const size_t FONT_CACHE_MEMORY_BUDGET = 1024 * 1024;
static const char FONT_DEFAULT_NAME[] = "Lucida Sans";
// see Source/WebKit/chromium/base/mac/mac_util.mm DarwinMajorVersionInternal
@ -1612,13 +1611,6 @@ void SkFontHost::FilterRec(SkScalerContext::Rec* rec) {
///////////////////////////////////////////////////////////////////////////
size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar) {
if (sizeAllocatedSoFar > FONT_CACHE_MEMORY_BUDGET) {
return sizeAllocatedSoFar - FONT_CACHE_MEMORY_BUDGET;
}
return 0;
}
#include "SkColorFilter.h"
static bool justAColor(const SkPaint& paint, SkColor* color) {

Просмотреть файл

@ -81,10 +81,6 @@ SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
///////////////////////////////////////////////////////////////////////////////
size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar) {
return 0; // nothing to do (change me if you want to limit the font cache)
}
int SkFontHost::ComputeGammaFlag(const SkPaint& paint) {
return 0;
}

Просмотреть файл

@ -17,8 +17,6 @@
#include "SkTSearch.h"
#include <stdio.h>
#define FONT_CACHE_MEMORY_BUDGET (768 * 1024)
#ifdef SK_BUILD_FOR_MAC
#define SK_FONT_FILE_PREFIX "/Library/Fonts/"
#else
@ -653,12 +651,3 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
return face;
}
///////////////////////////////////////////////////////////////////////////////
size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar) {
if (sizeAllocatedSoFar > FONT_CACHE_MEMORY_BUDGET)
return sizeAllocatedSoFar - FONT_CACHE_MEMORY_BUDGET;
else
return 0; // nothing to do
}

Просмотреть файл

@ -75,9 +75,6 @@ using namespace skia_advanced_typeface_metrics_utils;
static const uint16_t BUFFERSIZE = (16384 - 32);
static uint8_t glyphbuf[BUFFERSIZE];
// Give 1MB font cache budget
#define FONT_CACHE_MEMORY_BUDGET (1024 * 1024)
/**
* Since LOGFONT wants its textsize as an int, and we support fractional sizes,
* and since we have a cache of LOGFONTs for our tyepfaces, we always set the
@ -1246,13 +1243,6 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
return SkCreateTypefaceFromLOGFONT(lf);
}
size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar) {
if (sizeAllocatedSoFar > FONT_CACHE_MEMORY_BUDGET)
return sizeAllocatedSoFar - FONT_CACHE_MEMORY_BUDGET;
else
return 0; // nothing to do
}
SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
printf("SkFontHost::CreateTypefaceFromFile unimplemented");
return NULL;