Diff
Modified: trunk/Source/WebCore/ChangeLog (147638 => 147639)
--- trunk/Source/WebCore/ChangeLog 2013-04-04 16:28:43 UTC (rev 147638)
+++ trunk/Source/WebCore/ChangeLog 2013-04-04 16:37:08 UTC (rev 147639)
@@ -1,5 +1,44 @@
2013-04-04 Andreas Kling <[email protected]>
+ Global FontPlatformData cache should use OwnPtr.
+ <http://webkit.org/b/111939>
+
+ Reviewed by Anders Carlsson.
+
+ Let the global FontPlatformData use OwnPtr instead of raw pointers + deleteAllValues().
+
+ * platform/graphics/FontCache.cpp:
+ (WebCore::FontCache::getCachedFontPlatformData):
+ (WebCore::FontCache::purgeInactiveFontData):
+ (WebCore::FontCache::invalidate):
+
+ Tweaked code for OwnPtr. Also made getCachedFontPlatformData() do one hash lookup
+ instead of two.
+
+ * platform/graphics/FontCache.h:
+ * platform/graphics/blackberry/FontCacheBlackBerry.cpp:
+ (WebCore::FontCache::createFontPlatformData):
+ * platform/graphics/chromium/FontCacheAndroid.cpp:
+ (WebCore::FontCache::createFontPlatformData):
+ * platform/graphics/freetype/FontCacheFreeType.cpp:
+ (WebCore::FontCache::createFontPlatformData):
+ * platform/graphics/mac/FontCacheMac.mm:
+ (WebCore::FontCache::createFontPlatformData):
+ * platform/graphics/qt/FontCacheQt.cpp:
+ (WebCore::FontCache::createFontPlatformData):
+ * platform/graphics/skia/FontCacheSkia.cpp:
+ (WebCore::FontCache::createFontPlatformData):
+ * platform/graphics/win/FontCacheWin.cpp:
+ (WebCore::FontCache::createFontPlatformData):
+ * platform/graphics/wince/FontCacheWinCE.cpp:
+ (WebCore::FontCache::createFontPlatformData):
+ * platform/graphics/wx/FontCacheWx.cpp:
+ (WebCore::FontCache::createFontPlatformData):
+
+ FontCache::createFontPlatformData() now returns a PassOwnPtr.
+
+2013-04-04 Andreas Kling <[email protected]>
+
Render images with low-quality scaling while FrameView is being resized.
<http://webkit.org/b/113764>
<rdar://problem/13555154>
Modified: trunk/Source/WebCore/platform/graphics/FontCache.cpp (147638 => 147639)
--- trunk/Source/WebCore/platform/graphics/FontCache.cpp 2013-04-04 16:28:43 UTC (rev 147638)
+++ trunk/Source/WebCore/platform/graphics/FontCache.cpp 2013-04-04 16:37:08 UTC (rev 147639)
@@ -125,7 +125,7 @@
struct FontPlatformDataCacheKeyTraits : WTF::SimpleClassHashTraits<FontPlatformDataCacheKey> { };
-typedef HashMap<FontPlatformDataCacheKey, FontPlatformData*, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits> FontPlatformDataCache;
+typedef HashMap<FontPlatformDataCacheKey, OwnPtr<FontPlatformData>, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits> FontPlatformDataCache;
static FontPlatformDataCache* gFontPlatformDataCache = 0;
@@ -200,29 +200,24 @@
FontPlatformDataCacheKey key(familyName, fontDescription.computedPixelSize(), fontDescription.weight(), fontDescription.italic(),
fontDescription.usePrinterFont(), fontDescription.renderingMode(), fontDescription.orientation(),
fontDescription.widthVariant());
- FontPlatformData* result = 0;
- bool foundResult;
- FontPlatformDataCache::iterator it = gFontPlatformDataCache->find(key);
- if (it == gFontPlatformDataCache->end()) {
- result = createFontPlatformData(fontDescription, familyName);
- gFontPlatformDataCache->set(key, result);
- foundResult = result;
- } else {
- result = it->value;
- foundResult = true;
- }
- if (!foundResult && !checkingAlternateName) {
- // We were unable to find a font. We have a small set of fonts that we alias to other names,
- // e.g., Arial/Helvetica, Courier/Courier New, etc. Try looking up the font under the aliased name.
- const AtomicString& alternateName = alternateFamilyName(familyName);
- if (!alternateName.isEmpty())
- result = getCachedFontPlatformData(fontDescription, alternateName, true);
- if (result)
- gFontPlatformDataCache->set(key, new FontPlatformData(*result)); // Cache the result under the old name.
+ FontPlatformDataCache::AddResult result = gFontPlatformDataCache->add(key, nullptr);
+ if (result.isNewEntry) {
+ result.iterator->value = createFontPlatformData(fontDescription, familyName);
+
+ if (!result.iterator->value && !checkingAlternateName) {
+ // We were unable to find a font. We have a small set of fonts that we alias to other names,
+ // e.g., Arial/Helvetica, Courier/Courier New, etc. Try looking up the font under the aliased name.
+ const AtomicString& alternateName = alternateFamilyName(familyName);
+ if (!alternateName.isEmpty()) {
+ FontPlatformData* fontPlatformDataForAlternateName = getCachedFontPlatformData(fontDescription, alternateName, true);
+ if (fontPlatformDataForAlternateName)
+ result.iterator->value = adoptPtr(new FontPlatformData(*fontPlatformDataForAlternateName));
+ }
+ }
}
- return result;
+ return result.iterator->value.get();
}
#if ENABLE(OPENTYPE_VERTICAL)
@@ -411,7 +406,7 @@
size_t keysToRemoveCount = keysToRemove.size();
for (size_t i = 0; i < keysToRemoveCount; ++i)
- delete gFontPlatformDataCache->take(keysToRemove[i]);
+ gFontPlatformDataCache->remove(keysToRemove[i]);
}
#if ENABLE(OPENTYPE_VERTICAL)
@@ -536,11 +531,8 @@
return;
}
- if (gFontPlatformDataCache) {
- deleteAllValues(*gFontPlatformDataCache);
- delete gFontPlatformDataCache;
- gFontPlatformDataCache = new FontPlatformDataCache;
- }
+ if (gFontPlatformDataCache)
+ gFontPlatformDataCache->clear();
gGeneration++;
Modified: trunk/Source/WebCore/platform/graphics/FontCache.h (147638 => 147639)
--- trunk/Source/WebCore/platform/graphics/FontCache.h 2013-04-04 16:28:43 UTC (rev 147638)
+++ trunk/Source/WebCore/platform/graphics/FontCache.h 2013-04-04 16:37:08 UTC (rev 147639)
@@ -150,7 +150,7 @@
// These methods are implemented by each platform.
PassRefPtr<SimpleFontData> getSimilarFontPlatformData(const Font&);
- FontPlatformData* createFontPlatformData(const FontDescription&, const AtomicString& family);
+ PassOwnPtr<FontPlatformData> createFontPlatformData(const FontDescription&, const AtomicString& family);
PassRefPtr<SimpleFontData> getCachedFontData(const FontPlatformData*, ShouldRetain = Retain);
Modified: trunk/Source/WebCore/platform/graphics/blackberry/FontCacheBlackBerry.cpp (147638 => 147639)
--- trunk/Source/WebCore/platform/graphics/blackberry/FontCacheBlackBerry.cpp 2013-04-04 16:28:43 UTC (rev 147638)
+++ trunk/Source/WebCore/platform/graphics/blackberry/FontCacheBlackBerry.cpp 2013-04-04 16:37:08 UTC (rev 147639)
@@ -147,7 +147,7 @@
FontCache::SimpleFontFamily family;
FontCache::getFontFamilyForCharacters(characters, length, locale.getLanguage(), font.fontDescription(), &family);
if (family.name.isEmpty())
- return 0;
+ return nullptr;
AtomicString atomicFamily(family.name);
// Changes weight and/or italic of given FontDescription depends on
@@ -171,7 +171,7 @@
FontPlatformData* substitutePlatformData = getCachedFontPlatformData(description, atomicFamily, DoNotRetain);
if (!substitutePlatformData)
- return 0;
+ return nullptr;
FontPlatformData platformData = FontPlatformData(*substitutePlatformData);
platformData.setFakeBold(shouldSetFakeBold);
platformData.setFakeItalic(shouldSetFakeItalic);
@@ -269,7 +269,7 @@
}
}
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
{
// The CSS font matching algorithm (http://www.w3.org/TR/css3-fonts/#font-matching-algorithm)
// says that we must find an exact match for font family, slant (italic or oblique can be used)
@@ -277,15 +277,15 @@
FcPattern* pattern = FcPatternCreate();
String familyNameString(getFamilyNameStringFromFontDescriptionAndFamily(fontDescription, family));
if (!FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(familyNameString.utf8().data())))
- return 0;
+ return nullptr;
bool italic = fontDescription.italic();
if (!FcPatternAddInteger(pattern, FC_SLANT, italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN))
- return 0;
+ return nullptr;
if (!FcPatternAddInteger(pattern, FC_WEIGHT, fontWeightToFontconfigWeight(fontDescription.weight())))
- return 0;
+ return nullptr;
if (!FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontDescription.computedPixelSize()))
- return 0;
+ return nullptr;
// The strategy is originally from Skia (src/ports/SkFontHost_fontconfig.cpp):
@@ -303,7 +303,7 @@
FcPattern* resultPattern = FcFontMatch(0, pattern, &fontConfigResult);
FcPatternDestroy(pattern);
if (!resultPattern) // No match.
- return 0;
+ return nullptr;
FcChar8* fontConfigFamilyNameAfterMatching;
FcPatternGetString(resultPattern, FC_FAMILY, 0, &fontConfigFamilyNameAfterMatching);
@@ -316,7 +316,7 @@
&& !(equalIgnoringCase(familyNameString, "sans") || equalIgnoringCase(familyNameString, "sans-serif")
|| equalIgnoringCase(familyNameString, "serif") || equalIgnoringCase(familyNameString, "monospace")
|| equalIgnoringCase(familyNameString, "fantasy") || equalIgnoringCase(familyNameString, "cursive")))
- return 0;
+ return nullptr;
int fontWeight;
FcPatternGetInteger(resultPattern, FC_WEIGHT, 0, &fontWeight);
@@ -335,10 +335,10 @@
memset(name, 0, MAX_FONT_NAME_LEN+1);
// fprintf(stderr, "FS_load_font %s: ", fontFileName);
if (FS_load_font(BlackBerry::Platform::Graphics::getIType(), reinterpret_cast<FILECHAR*>(fontFileName), 0, 0, MAX_FONT_NAME_LEN, name) != SUCCESS)
- return 0;
+ return nullptr;
// fprintf(stderr, " %s\n", name);
- return new FontPlatformData(name, fontDescription.computedSize(), shouldFakeBold, shouldFakeItalic, fontDescription.orientation());
+ return adoptPtr(new FontPlatformData(name, fontDescription.computedSize(), shouldFakeBold, shouldFakeItalic, fontDescription.orientation()));
}
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/chromium/FontCacheAndroid.cpp (147638 => 147639)
--- trunk/Source/WebCore/platform/graphics/chromium/FontCacheAndroid.cpp 2013-04-04 16:28:43 UTC (rev 147638)
+++ trunk/Source/WebCore/platform/graphics/chromium/FontCacheAndroid.cpp 2013-04-04 16:37:08 UTC (rev 147639)
@@ -149,7 +149,7 @@
notImplemented();
}
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
{
const char* name = 0;
CString nameString; // Keeps name valid within scope of this function in case that name is from a family.
@@ -207,7 +207,7 @@
}
SkSafeUnref(typeface);
- return result;
+ return adoptPtr(result);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp (147638 => 147639)
--- trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp 2013-04-04 16:28:43 UTC (rev 147638)
+++ trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp 2013-04-04 16:37:08 UTC (rev 147639)
@@ -169,7 +169,7 @@
}
}
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
{
// The CSS font matching algorithm (http://www.w3.org/TR/css3-fonts/#font-matching-algorithm)
// says that we must find an exact match for font family, slant (italic or oblique can be used)
@@ -177,15 +177,15 @@
RefPtr<FcPattern> pattern = adoptRef(FcPatternCreate());
String familyNameString(getFamilyNameStringFromFontDescriptionAndFamily(fontDescription, family));
if (!FcPatternAddString(pattern.get(), FC_FAMILY, reinterpret_cast<const FcChar8*>(familyNameString.utf8().data())))
- return 0;
+ return nullptr;
bool italic = fontDescription.italic();
if (!FcPatternAddInteger(pattern.get(), FC_SLANT, italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN))
- return 0;
+ return nullptr;
if (!FcPatternAddInteger(pattern.get(), FC_WEIGHT, fontWeightToFontconfigWeight(fontDescription.weight())))
- return 0;
+ return nullptr;
if (!FcPatternAddDouble(pattern.get(), FC_PIXEL_SIZE, fontDescription.computedPixelSize()))
- return 0;
+ return nullptr;
// The strategy is originally from Skia (src/ports/SkFontHost_fontconfig.cpp):
@@ -202,7 +202,7 @@
FcResult fontConfigResult;
RefPtr<FcPattern> resultPattern = adoptRef(FcFontMatch(0, pattern.get(), &fontConfigResult));
if (!resultPattern) // No match.
- return 0;
+ return nullptr;
FcChar8* fontConfigFamilyNameAfterMatching;
FcPatternGetString(resultPattern.get(), FC_FAMILY, 0, &fontConfigFamilyNameAfterMatching);
@@ -215,18 +215,16 @@
&& !(equalIgnoringCase(familyNameString, "sans") || equalIgnoringCase(familyNameString, "sans-serif")
|| equalIgnoringCase(familyNameString, "serif") || equalIgnoringCase(familyNameString, "monospace")
|| equalIgnoringCase(familyNameString, "fantasy") || equalIgnoringCase(familyNameString, "cursive")))
- return 0;
+ return nullptr;
// Verify that this font has an encoding compatible with Fontconfig. Fontconfig currently
// supports three encodings in FcFreeTypeCharIndex: Unicode, Symbol and AppleRoman.
// If this font doesn't have one of these three encodings, don't select it.
- FontPlatformData* platformData = new FontPlatformData(resultPattern.get(), fontDescription);
- if (!platformData->hasCompatibleCharmap()) {
- delete platformData;
- return 0;
- }
+ OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(resultPattern.get(), fontDescription));
+ if (!platformData->hasCompatibleCharmap())
+ return nullptr;
- return platformData;
+ return platformData.release();
}
}
Modified: trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm (147638 => 147639)
--- trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm 2013-04-04 16:28:43 UTC (rev 147638)
+++ trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm 2013-04-04 16:37:08 UTC (rev 147639)
@@ -216,7 +216,7 @@
[WebFontCache getTraits:traitsMasks inFamily:familyName];
}
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
{
NSFontTraitMask traits = fontDescription.italic() ? NSFontItalicTrait : 0;
NSInteger weight = toAppKitFontWeight(fontDescription.weight());
@@ -224,7 +224,7 @@
NSFont *nsFont = [WebFontCache fontWithFamily:family traits:traits weight:weight size:size];
if (!nsFont)
- return 0;
+ return nullptr;
NSFontManager *fontManager = [NSFontManager sharedFontManager];
NSFontTraitMask actualTraits = 0;
@@ -240,8 +240,8 @@
// In that case, we don't want to use the platformData.
OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platformFont, size, fontDescription.usePrinterFont(), syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant()));
if (!platformData->font())
- return 0;
- return platformData.leakPtr();
+ return nullptr;
+ return platformData.release();
}
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/qt/FontCacheQt.cpp (147638 => 147639)
--- trunk/Source/WebCore/platform/graphics/qt/FontCacheQt.cpp 2013-04-04 16:28:43 UTC (rev 147638)
+++ trunk/Source/WebCore/platform/graphics/qt/FontCacheQt.cpp 2013-04-04 16:37:08 UTC (rev 147639)
@@ -88,12 +88,12 @@
{
}
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName)
{
QFontDatabase db;
if (!db.hasFamily(familyName))
- return 0;
- return new FontPlatformData(fontDescription, familyName);
+ return nullptr;
+ return adoptPtr(new FontPlatformData(fontDescription, familyName));
}
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/skia/FontCacheSkia.cpp (147638 => 147639)
--- trunk/Source/WebCore/platform/graphics/skia/FontCacheSkia.cpp 2013-04-04 16:28:43 UTC (rev 147638)
+++ trunk/Source/WebCore/platform/graphics/skia/FontCacheSkia.cpp 2013-04-04 16:37:08 UTC (rev 147639)
@@ -129,8 +129,7 @@
notImplemented();
}
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription,
- const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
{
const char* name = 0;
CString s;
@@ -172,7 +171,7 @@
SkTypeface* tf = SkTypeface::CreateFromName(name, static_cast<SkTypeface::Style>(style));
if (!tf)
- return 0;
+ return nullptr;
FontPlatformData* result =
new FontPlatformData(tf,
@@ -182,7 +181,7 @@
(style & SkTypeface::kItalic) && !tf->isItalic(),
fontDescription.orientation());
tf->unref();
- return result;
+ return adoptPtr(result);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp (147638 => 147639)
--- trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp 2013-04-04 16:28:43 UTC (rev 147638)
+++ trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp 2013-04-04 16:37:08 UTC (rev 147639)
@@ -545,7 +545,7 @@
copyToVector(procData.m_traitsMasks, traitsMasks);
}
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
{
bool isLucidaGrande = false;
static AtomicString lucidaStr("Lucida Grande");
@@ -563,7 +563,7 @@
fontDescription.computedPixelSize() * (useGDI ? 1 : 32), useGDI);
if (!hfont)
- return 0;
+ return nullptr;
if (isLucidaGrande)
useGDI = false; // Never use GDI for Lucida Grande.
@@ -588,10 +588,10 @@
// font.
delete result;
DeleteObject(hfont);
- return 0;
+ return nullptr;
}
- return result;
+ return adoptPtr(result);
}
}
Modified: trunk/Source/WebCore/platform/graphics/wince/FontCacheWinCE.cpp (147638 => 147639)
--- trunk/Source/WebCore/platform/graphics/wince/FontCacheWinCE.cpp 2013-04-04 16:28:43 UTC (rev 147638)
+++ trunk/Source/WebCore/platform/graphics/wince/FontCacheWinCE.cpp 2013-04-04 16:37:08 UTC (rev 147639)
@@ -312,10 +312,9 @@
return getCachedFontData(fontDesc, FontPlatformData::defaultFontFamily(), false, shouldRetain);
}
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
{
- FontPlatformData* result = new FontPlatformData(fontDescription, family);
- return result;
+ return adoptPtr(new FontPlatformData(fontDescription, family));
}
void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigned>& traitsMasks)
Modified: trunk/Source/WebCore/platform/graphics/wx/FontCacheWx.cpp (147638 => 147639)
--- trunk/Source/WebCore/platform/graphics/wx/FontCacheWx.cpp 2013-04-04 16:28:43 UTC (rev 147638)
+++ trunk/Source/WebCore/platform/graphics/wx/FontCacheWx.cpp 2013-04-04 16:37:08 UTC (rev 147639)
@@ -97,14 +97,14 @@
return fallback.release();
}
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
{
// wx will ALWAYS create a valid font, even if the font family we're looking for is not available.
// So we check to make sure the font is the one we're looking for before creating the font.
if (!wxFontEnumerator::IsValidFacename(family.string()))
- return 0;
+ return nullptr;
- return new FontPlatformData(fontDescription,family);
+ return adoptPtr(new FontPlatformData(fontDescription, family));
}
void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigned>& traitsMasks)