зеркало из https://github.com/mozilla/moz-skia.git
add SetFlags for command line control
http://codereview.appspot.com/5416047/ M include/core/SkGraphics.h M src/core/SkGraphics.cpp git-svn-id: http://skia.googlecode.com/svn/trunk@2727 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
f788feb3f1
Коммит
54c782c968
|
@ -45,6 +45,16 @@ public:
|
|||
* draws to be recreated, since they will no longer be in the cache.
|
||||
*/
|
||||
static void PurgeFontCache();
|
||||
|
||||
/**
|
||||
* Applications with command line options may pass optional state, such
|
||||
* as cache sizes, here, for instance:
|
||||
* font-cache-limit=12345678
|
||||
*
|
||||
* The flags format is name=value[;name=value...] with no spaces.
|
||||
* This format is subject to change.
|
||||
*/
|
||||
static void SetFlags(const char* flags);
|
||||
|
||||
private:
|
||||
/** This is automatically called by SkGraphics::Init(), and must be
|
||||
|
|
|
@ -157,3 +157,50 @@ void SkGraphics::PurgeFontCache() {
|
|||
SkGlyphCache::SetCacheUsed(0);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const char kFontCacheLimitStr[] = "font-cache-limit";
|
||||
static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
|
||||
|
||||
static const struct {
|
||||
const char* fStr;
|
||||
size_t fLen;
|
||||
size_t (*fFunc)(size_t);
|
||||
} gFlags[] = {
|
||||
{kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit}
|
||||
};
|
||||
|
||||
/* flags are of the form param; or param=value; */
|
||||
void SkGraphics::SetFlags(const char* flags) {
|
||||
if (!flags) {
|
||||
return;
|
||||
}
|
||||
const char* nextSemi;
|
||||
do {
|
||||
size_t len = strlen(flags);
|
||||
const char* paramEnd = flags + len;
|
||||
const char* nextEqual = strchr(flags, '=');
|
||||
if (nextEqual && paramEnd > nextEqual) {
|
||||
paramEnd = nextEqual;
|
||||
}
|
||||
nextSemi = strchr(flags, ';');
|
||||
if (nextSemi && paramEnd > nextSemi) {
|
||||
paramEnd = nextSemi;
|
||||
}
|
||||
size_t paramLen = paramEnd - flags;
|
||||
for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) {
|
||||
if (paramLen != gFlags[i].fLen) {
|
||||
continue;
|
||||
}
|
||||
if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) {
|
||||
size_t val = 0;
|
||||
if (nextEqual) {
|
||||
val = (size_t) atoi(nextEqual + 1);
|
||||
}
|
||||
(gFlags[i].fFunc)(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
flags = nextSemi + 1;
|
||||
} while (nextSemi);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче