aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-11-08 13:48:32 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-11-08 13:48:32 +0000
commit77407ca019ca1bb98dd65f940be825d38719e983 (patch)
tree50a62c68e649ef2fbf4032006eef19d01387976e /src/core
parentca08edd7a88d4691f0ec762fe7c8dee96ef0052b (diff)
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
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkGlyphCache.cpp9
-rw-r--r--src/core/SkGraphics.cpp40
2 files changed, 37 insertions, 12 deletions
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 6cdc993dd8..937ac225b2 100644
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -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);
diff --git a/src/core/SkGraphics.cpp b/src/core/SkGraphics.cpp
index 2da0856d86..5e8e549624 100644
--- a/src/core/SkGraphics.cpp
+++ b/src/core/SkGraphics.cpp
@@ -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;
- }
- if (minor) {
- *minor = SKIA_VERSION_MINOR;
+#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 (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);
}
}