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:
parent
ca08edd7a8
commit
77407ca019
@ -105,6 +105,12 @@
|
|||||||
*/
|
*/
|
||||||
//#define SkDebugf(...) MyFunction(__VA_ARGS__)
|
//#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.
|
/* If defined, use CoreText instead of ATSUI on OS X.
|
||||||
*/
|
*/
|
||||||
//#define SK_USE_MAC_CORE_TEXT
|
//#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
|
/** Return SkScalerContext gamma flag, or 0, based on the paint that will be
|
||||||
used to draw something with antialiasing.
|
used to draw something with antialiasing.
|
||||||
*/
|
*/
|
||||||
|
@ -17,21 +17,42 @@ public:
|
|||||||
static void Init();
|
static void Init();
|
||||||
static void Term();
|
static void Term();
|
||||||
|
|
||||||
/** Return the (approximate) number of bytes used by the font cache.
|
/**
|
||||||
*/
|
* Return the version numbers for the library. If the parameter is not
|
||||||
static size_t GetFontCacheUsed();
|
* null, it is set to the version number.
|
||||||
|
|
||||||
/** 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.
|
|
||||||
*/
|
*/
|
||||||
static void GetVersion(int32_t* major, int32_t* minor, int32_t* patch);
|
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:
|
private:
|
||||||
/** This is automatically called by SkGraphics::Init(), and must be
|
/** This is automatically called by SkGraphics::Init(), and must be
|
||||||
implemented by the host OS. This allows the host OS to register a callback
|
implemented by the host OS. This allows the host OS to register a callback
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "SkGlyphCache.h"
|
#include "SkGlyphCache.h"
|
||||||
#include "SkFontHost.h"
|
#include "SkGraphics.h"
|
||||||
#include "SkPaint.h"
|
#include "SkPaint.h"
|
||||||
#include "SkTemplates.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
|
// if we have a fixed budget for our cache, do a purge here
|
||||||
{
|
{
|
||||||
size_t allocated = globals.fTotalMemoryUsed + cache->fMemoryUsed;
|
size_t allocated = globals.fTotalMemoryUsed + cache->fMemoryUsed;
|
||||||
size_t amountToFree = SkFontHost::ShouldPurgeFontCache(allocated);
|
size_t budgeted = SkGraphics::GetFontCacheLimit();
|
||||||
if (amountToFree)
|
if (allocated > budgeted) {
|
||||||
(void)InternalFreeCache(&globals, amountToFree);
|
(void)InternalFreeCache(&globals, allocated - budgeted);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cache->attachToHead(&globals.fHead);
|
cache->attachToHead(&globals.fHead);
|
||||||
|
@ -29,6 +29,18 @@
|
|||||||
#include "SkUtils.h"
|
#include "SkUtils.h"
|
||||||
#include "SkXfermode.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) }
|
#define typesizeline(type) { #type , sizeof(type) }
|
||||||
|
|
||||||
#ifdef BUILD_EMBOSS_TABLE
|
#ifdef BUILD_EMBOSS_TABLE
|
||||||
@ -124,15 +136,27 @@ bool SkGraphics::SetFontCacheUsed(size_t usageInBytes) {
|
|||||||
return SkGlyphCache::SetCacheUsed(usageInBytes);
|
return SkGlyphCache::SetCacheUsed(usageInBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) {
|
#ifndef SK_DEFAULT_FONT_CACHE_LIMIT
|
||||||
if (major) {
|
#define SK_DEFAULT_FONT_CACHE_LIMIT (1024 * 1024)
|
||||||
*major = SKIA_VERSION_MAJOR;
|
#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) {
|
gFontCacheLimit = bytes;
|
||||||
*minor = SKIA_VERSION_MINOR;
|
|
||||||
}
|
// trigger a purge if the new size is smaller that our currently used amount
|
||||||
if (patch) {
|
if (bytes < GetFontCacheUsed()) {
|
||||||
*patch = SKIA_VERSION_PATCH;
|
SetFontCacheUsed(bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,8 +324,3 @@ SkScalerContext* SkFontHost::CreateFallbackScalerContext(
|
|||||||
return SkFontHost::CreateScalerContext(desc);
|
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 "FontHostConfiguration_android.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define FONT_CACHE_MEMORY_BUDGET (768 * 1024)
|
|
||||||
|
|
||||||
#ifndef SK_FONT_FILE_PREFIX
|
#ifndef SK_FONT_FILE_PREFIX
|
||||||
#define SK_FONT_FILE_PREFIX "/fonts/"
|
#define SK_FONT_FILE_PREFIX "/fonts/"
|
||||||
#endif
|
#endif
|
||||||
@ -763,12 +761,3 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
|
|||||||
return face;
|
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 std::map<uint32_t, SkTypeface *> global_fc_typefaces;
|
||||||
static unsigned global_fc_map_next_id = 0;
|
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)
|
static unsigned UniqueIdToFileId(unsigned uniqueid)
|
||||||
{
|
{
|
||||||
return uniqueid >> 8;
|
return uniqueid >> 8;
|
||||||
@ -361,12 +358,3 @@ SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
|
|||||||
return 0;
|
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 "SkTSearch.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define FONT_CACHE_MEMORY_BUDGET (1 * 1024 * 1024)
|
|
||||||
|
|
||||||
#ifndef SK_FONT_FILE_PREFIX
|
#ifndef SK_FONT_FILE_PREFIX
|
||||||
#define SK_FONT_FILE_PREFIX "/usr/share/fonts/truetype/msttcorefonts/"
|
#define SK_FONT_FILE_PREFIX "/usr/share/fonts/truetype/msttcorefonts/"
|
||||||
#endif
|
#endif
|
||||||
@ -600,12 +598,3 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
|
|||||||
return face;
|
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 "SkPaint.h"
|
||||||
#include "SkPoint.h"
|
#include "SkPoint.h"
|
||||||
|
|
||||||
// Give 1MB font cache budget
|
|
||||||
#define FONT_CACHE_MEMORY_BUDGET (1024 * 1024)
|
|
||||||
|
|
||||||
const char* gDefaultfont = "Arial"; // hard code for now
|
const char* gDefaultfont = "Arial"; // hard code for now
|
||||||
static SkMutex gFTMutex;
|
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) {
|
int SkFontHost::ComputeGammaFlag(const SkPaint& paint) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,6 @@ static unsigned CGRGBPixel_getAlpha(CGRGBPixel pixel) {
|
|||||||
|
|
||||||
using namespace skia_advanced_typeface_metrics_utils;
|
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";
|
static const char FONT_DEFAULT_NAME[] = "Lucida Sans";
|
||||||
|
|
||||||
// see Source/WebKit/chromium/base/mac/mac_util.mm DarwinMajorVersionInternal
|
// 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"
|
#include "SkColorFilter.h"
|
||||||
|
|
||||||
static bool justAColor(const SkPaint& paint, SkColor* color) {
|
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) {
|
int SkFontHost::ComputeGammaFlag(const SkPaint& paint) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
#include "SkTSearch.h"
|
#include "SkTSearch.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define FONT_CACHE_MEMORY_BUDGET (768 * 1024)
|
|
||||||
|
|
||||||
#ifdef SK_BUILD_FOR_MAC
|
#ifdef SK_BUILD_FOR_MAC
|
||||||
#define SK_FONT_FILE_PREFIX "/Library/Fonts/"
|
#define SK_FONT_FILE_PREFIX "/Library/Fonts/"
|
||||||
#else
|
#else
|
||||||
@ -653,12 +651,3 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
|
|||||||
return face;
|
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 const uint16_t BUFFERSIZE = (16384 - 32);
|
||||||
static uint8_t glyphbuf[BUFFERSIZE];
|
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,
|
* 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
|
* 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);
|
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[]) {
|
SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
|
||||||
printf("SkFontHost::CreateTypefaceFromFile unimplemented");
|
printf("SkFontHost::CreateTypefaceFromFile unimplemented");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user