Bug 901845 - add a pref to specify the length limit of words in word caches. r=jfkthame

This commit is contained in:
John Daggett 2013-09-11 10:36:57 +09:00
parent 7adfee67b5
commit 31eb11a789
5 changed files with 43 additions and 6 deletions

View File

@ -3242,6 +3242,8 @@ gfxFont::SplitAndInitTextRun(gfxContext *aContext,
}
InitWordCache();
uint32_t wordCacheCharLimit =
gfxPlatform::GetPlatform()->WordCacheCharLimit();
// the only flags we care about for ShapedWord construction/caching
uint32_t flags = aTextRun->GetFlags();
@ -3279,9 +3281,9 @@ gfxFont::SplitAndInitTextRun(gfxContext *aContext,
// We've decided to break here (i.e. we're at the end of a "word");
// shape the word and add it to the textrun.
// For words longer than gfxShapedWord::kMaxLength, we don't use the
// For words longer than the limit, we don't use the
// font's word cache but just shape directly into the textrun.
if (length > gfxShapedWord::kMaxLength) {
if (length > wordCacheCharLimit) {
bool ok = ShapeFragmentWithoutWordCache(aContext,
text + wordStart,
aRunStart + wordStart,

View File

@ -2467,8 +2467,6 @@ protected:
class gfxShapedWord : public gfxShapedText
{
public:
static const uint32_t kMaxLength = 32;
// Create a ShapedWord that can hold glyphs for aLength characters,
// with mCharacterGlyphs sized appropriately.
//
@ -2482,7 +2480,8 @@ public:
int32_t aRunScript,
int32_t aAppUnitsPerDevUnit,
uint32_t aFlags) {
NS_ASSERTION(aLength <= kMaxLength, "excessive length for gfxShapedWord!");
NS_ASSERTION(aLength <= gfxPlatform::GetPlatform()->WordCacheCharLimit(),
"excessive length for gfxShapedWord!");
// Compute size needed including the mCharacterGlyphs array
// and a copy of the original text
@ -2503,7 +2502,8 @@ public:
int32_t aRunScript,
int32_t aAppUnitsPerDevUnit,
uint32_t aFlags) {
NS_ASSERTION(aLength <= kMaxLength, "excessive length for gfxShapedWord!");
NS_ASSERTION(aLength <= gfxPlatform::GetPlatform()->WordCacheCharLimit(),
"excessive length for gfxShapedWord!");
// In the 16-bit version of Create, if the TEXT_IS_8BIT flag is set,
// then we convert the text to an 8-bit version and call the 8-bit

View File

@ -150,6 +150,8 @@ SRGBOverrideObserver::Observe(nsISupports *aSubject,
#define GFX_PREF_OPENTYPE_SVG "gfx.font_rendering.opentype_svg.enabled"
#define GFX_PREF_WORD_CACHE_CHARLIMIT "gfx.font_rendering.wordcache.charlimit"
#define GFX_PREF_GRAPHITE_SHAPING "gfx.font_rendering.graphite.enabled"
#define BIDI_NUMERAL_PREF "bidi.numeral"
@ -257,6 +259,7 @@ gfxPlatform::gfxPlatform()
mAllowDownloadableFonts = UNINITIALIZED_VALUE;
mFallbackUsesCmaps = UNINITIALIZED_VALUE;
mWordCacheCharLimit = UNINITIALIZED_VALUE;
mGraphiteShapingEnabled = UNINITIALIZED_VALUE;
mOpenTypeSVGEnabled = UNINITIALIZED_VALUE;
mBidiNumeralOption = UNINITIALIZED_VALUE;
@ -963,6 +966,20 @@ gfxPlatform::OpenTypeSVGEnabled()
return mOpenTypeSVGEnabled > 0;
}
uint32_t
gfxPlatform::WordCacheCharLimit()
{
if (mWordCacheCharLimit == UNINITIALIZED_VALUE) {
mWordCacheCharLimit =
Preferences::GetInt(GFX_PREF_WORD_CACHE_CHARLIMIT, 32);
if (mWordCacheCharLimit < 0) {
mWordCacheCharLimit = 32;
}
}
return uint32_t(mWordCacheCharLimit);
}
bool
gfxPlatform::UseGraphiteShaping()
{
@ -1770,6 +1787,13 @@ gfxPlatform::FontsPrefsChanged(const char *aPref)
mAllowDownloadableFonts = UNINITIALIZED_VALUE;
} else if (!strcmp(GFX_PREF_FALLBACK_USE_CMAPS, aPref)) {
mFallbackUsesCmaps = UNINITIALIZED_VALUE;
} else if (!strcmp(GFX_PREF_WORD_CACHE_CHARLIMIT, aPref)) {
mWordCacheCharLimit = UNINITIALIZED_VALUE;
gfxFontCache *fontCache = gfxFontCache::GetCache();
if (fontCache) {
fontCache->AgeAllGenerations();
fontCache->FlushShapedWordCaches();
}
} else if (!strcmp(GFX_PREF_GRAPHITE_SHAPING, aPref)) {
mGraphiteShapingEnabled = UNINITIALIZED_VALUE;
gfxFontCache *fontCache = gfxFontCache::GetCache();

View File

@ -403,6 +403,11 @@ public:
*/
bool OpenTypeSVGEnabled();
/**
* Max character length of words in the word cache
*/
uint32_t WordCacheCharLimit();
/**
* Whether to use the SIL Graphite rendering engine
* (for fonts that include Graphite tables)
@ -672,6 +677,9 @@ protected:
// which scripts should be shaped with harfbuzz
int32_t mUseHarfBuzzScripts;
// max character limit for words in word cache
int32_t mWordCacheCharLimit;
private:
/**
* Start up Thebes.

View File

@ -292,6 +292,9 @@ pref("gfx.font_loader.interval", 50); // run every 50 ms
// whether to always search all font cmaps during system font fallback
pref("gfx.font_rendering.fallback.always_use_cmaps", false);
// cache shaped word results
pref("gfx.font_rendering.wordcache.charlimit", 32);
pref("gfx.font_rendering.graphite.enabled", true);
// Check intl/unicharutil/util/nsUnicodeProperties.h for definitions of script bits