Title: [193592] branches/safari-601-branch/Source/WebCore

Diff

Modified: branches/safari-601-branch/Source/WebCore/ChangeLog (193591 => 193592)


--- branches/safari-601-branch/Source/WebCore/ChangeLog	2015-12-06 21:59:06 UTC (rev 193591)
+++ branches/safari-601-branch/Source/WebCore/ChangeLog	2015-12-06 22:03:21 UTC (rev 193592)
@@ -1,3 +1,35 @@
+2015-12-06  Babak Shafiei  <bshaf...@apple.com>
+
+        Merge r188114.
+
+    2015-08-06  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+            CSSSegmentedFontFace::fontRanges() does not handle duplicate fonts correctly
+            https://bugs.webkit.org/show_bug.cgi?id=147765
+
+            Reviewed by Filip Pizlo.
+
+            CSSSegmentedFontFace::fontRanges() was trying to hash on FontDescriptors by
+            picking a few specific pieces of data out of the FontDescriptor, computing
+            a hash on it, and using that unsigned as a key in a HashMap. This has two
+            problems: it doesn't handle equality correctly, as hash collisions cannot
+            depend on an equality operator to dedup, and it doesn't hash on all the
+            members of a FontDescription.
+
+            Instead, this HashMap should use FontDescriptionKey, which represents a
+            FontDescription, and is designed exactly for the purpose of being used as a
+            key in a HashMap.
+
+            No new tests because there is no behavior change (because a problem occurs
+            when two different FontDescriptions hash to the same value, which is rare).
+
+            * css/CSSSegmentedFontFace.cpp:
+            (WebCore::CSSSegmentedFontFace::fontRanges):
+            * css/CSSSegmentedFontFace.h:
+            * platform/graphics/FontCache.h:
+            (WebCore::FontDescriptionKeyHash::hash):
+            (WebCore::FontDescriptionKeyHash::equal):
+
 2015-12-06  Matthew Hanson  <matthew_han...@apple.com>
 
         Merge r190895. rdar://problem/23769817

Modified: branches/safari-601-branch/Source/WebCore/css/CSSSegmentedFontFace.cpp (193591 => 193592)


--- branches/safari-601-branch/Source/WebCore/css/CSSSegmentedFontFace.cpp	2015-12-06 21:59:06 UTC (rev 193591)
+++ branches/safari-601-branch/Source/WebCore/css/CSSSegmentedFontFace.cpp	2015-12-06 22:03:21 UTC (rev 193592)
@@ -31,6 +31,7 @@
 #include "CSSFontSelector.h"
 #include "Document.h"
 #include "Font.h"
+#include "FontCache.h"
 #include "FontDescription.h"
 #include "RuntimeEnabledFeatures.h"
 
@@ -113,17 +114,11 @@
         return FontRanges();
 
     FontTraitsMask desiredTraitsMask = fontDescription.traitsMask();
-    // FIXME: Unify this function with FontDescriptionFontDataCacheKey in FontCache.h (Or just use the regular FontCache instead of this)
-    unsigned hashKey = ((fontDescription.computedPixelSize() + 1) << (FontTraitsMaskWidth + FontWidthVariantWidth + FontSynthesisWidth + 1))
-        | (fontDescription.fontSynthesis() << (FontTraitsMaskWidth + FontWidthVariantWidth + 1))
-        | ((fontDescription.orientation() == Vertical ? 1 : 0) << (FontTraitsMaskWidth + FontWidthVariantWidth))
-        | fontDescription.widthVariant() << FontTraitsMaskWidth
-        | desiredTraitsMask;
 
-    auto addResult = m_descriptionToRangesMap.add(hashKey, FontRanges());
+    auto addResult = m_descriptionToRangesMap.add(FontDescriptionFontDataCacheKey(fontDescription), FontRanges()); 
     auto& fontRanges = addResult.iterator->value;
 
-    if (addResult.isNewEntry) {
+    if (true /*addResult.isNewEntry*/) {
         for (auto& face : m_fontFaces) {
             if (!face->isValid())
                 continue;

Modified: branches/safari-601-branch/Source/WebCore/css/CSSSegmentedFontFace.h (193591 => 193592)


--- branches/safari-601-branch/Source/WebCore/css/CSSSegmentedFontFace.h	2015-12-06 21:59:06 UTC (rev 193591)
+++ branches/safari-601-branch/Source/WebCore/css/CSSSegmentedFontFace.h	2015-12-06 22:03:21 UTC (rev 193592)
@@ -26,6 +26,7 @@
 #ifndef CSSSegmentedFontFace_h
 #define CSSSegmentedFontFace_h
 
+#include "FontCache.h"
 #include "FontRanges.h"
 #include <wtf/HashMap.h>
 #include <wtf/PassRefPtr.h>
@@ -73,7 +74,7 @@
 #endif
 
     CSSFontSelector* m_fontSelector;
-    HashMap<unsigned, FontRanges> m_descriptionToRangesMap;
+    HashMap<FontDescriptionFontDataCacheKey, FontRanges, FontDescriptionKeyHash, WTF::SimpleClassHashTraits<FontDescriptionFontDataCacheKey>> m_descriptionToRangesMap; 
     Vector<RefPtr<CSSFontFace>, 1> m_fontFaces;
 #if ENABLE(FONT_LOAD_EVENTS)
     Vector<RefPtr<LoadFontCallback>> m_callbacks;

Modified: branches/safari-601-branch/Source/WebCore/platform/graphics/FontCache.h (193591 => 193592)


--- branches/safari-601-branch/Source/WebCore/platform/graphics/FontCache.h	2015-12-06 21:59:06 UTC (rev 193591)
+++ branches/safari-601-branch/Source/WebCore/platform/graphics/FontCache.h	2015-12-06 22:03:21 UTC (rev 193592)
@@ -139,6 +139,20 @@
     FontFeatureSettings m_featureSettings;
 };
 
+struct FontDescriptionKeyHash {
+    static unsigned hash(const FontDescriptionFontDataCacheKey& key)
+    {
+        return key.computeHash();
+    }
+
+    static bool equal(const FontDescriptionFontDataCacheKey& a, const FontDescriptionFontDataCacheKey& b)
+    {
+        return a == b;
+    }
+
+    static const bool safeToCompareToEmptyOrDeleted = true;
+};
+
 class FontCache {
     friend class WTF::NeverDestroyed<FontCache>;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to