Title: [124397] trunk/Source/WebCore
Revision
124397
Author
[email protected]
Date
2012-08-01 18:26:52 -0700 (Wed, 01 Aug 2012)

Log Message

Cache support for OpenTypeVerticalData
https://bugs.webkit.org/show_bug.cgi?id=81332

Patch by Koji Ishii <[email protected]> on 2012-08-01
Reviewed by Tony Chang.

This patch adds FontCache to cache OpenTypeVerticalData class
instances that was introduced in bug 81326.

We need one instance of the class per OpenType font file, and we don't
have a class to hold such instances today.

ENABLE_OPENTYPE_VERTICAL isn't enabled for any platforms yet, so this
patch isn't on any code path. Apple Windows port (bug 48459) is going
to use this code, and probably Chromium (51450, 69282) as well.

"FIXME" comment in SimpleFontData.h will be implemented in 48459.

No new tests are required. No behavior changes.

* platform/graphics/FontCache.cpp:
(WebCore::FontCache::getCachedFontPlatformData): Ignore leading "@" on Windows to disable Windows feature for vertical flow.
(WebCore):
(WebCore::FontCache::getVerticalData): Get cached OpenTypeVerticalData from FontPlatformData, or crete one.
(WebCore::FontCache::purgeInactiveFontData): Purge inactive OpenTypeVerticalData.
* platform/graphics/FontCache.h:
(WebCore):
* platform/graphics/SimpleFontData.h:
(SimpleFontData):
(WebCore::SimpleFontData::verticalData): A dummy implementation for purgeInactiveFontData() to work.
* platform/graphics/opentype/OpenTypeVerticalData.h: Added m_inFontCache for mark & sweep.
(OpenTypeVerticalData):

Modified Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (124396 => 124397)


--- trunk/Source/WebCore/CMakeLists.txt	2012-08-02 01:18:42 UTC (rev 124396)
+++ trunk/Source/WebCore/CMakeLists.txt	2012-08-02 01:26:52 UTC (rev 124397)
@@ -50,6 +50,7 @@
     "${WEBCORE_DIR}/platform/graphics/filters/arm"
     "${WEBCORE_DIR}/platform/graphics/harfbuzz"
     "${WEBCORE_DIR}/platform/graphics/harfbuzz/ng"
+    "${WEBCORE_DIR}/platform/graphics/opentype"
     "${WEBCORE_DIR}/platform/graphics/transforms"
     "${WEBCORE_DIR}/platform/image-decoders"
     "${WEBCORE_DIR}/platform/image-decoders/bmp"

Modified: trunk/Source/WebCore/ChangeLog (124396 => 124397)


--- trunk/Source/WebCore/ChangeLog	2012-08-02 01:18:42 UTC (rev 124396)
+++ trunk/Source/WebCore/ChangeLog	2012-08-02 01:26:52 UTC (rev 124397)
@@ -1,3 +1,37 @@
+2012-08-01  Koji Ishii  <[email protected]>
+
+        Cache support for OpenTypeVerticalData
+        https://bugs.webkit.org/show_bug.cgi?id=81332
+
+        Reviewed by Tony Chang.
+
+        This patch adds FontCache to cache OpenTypeVerticalData class
+        instances that was introduced in bug 81326.
+
+        We need one instance of the class per OpenType font file, and we don't
+        have a class to hold such instances today.
+
+        ENABLE_OPENTYPE_VERTICAL isn't enabled for any platforms yet, so this
+        patch isn't on any code path. Apple Windows port (bug 48459) is going
+        to use this code, and probably Chromium (51450, 69282) as well.
+
+        "FIXME" comment in SimpleFontData.h will be implemented in 48459.
+
+        No new tests are required. No behavior changes.
+
+        * platform/graphics/FontCache.cpp:
+        (WebCore::FontCache::getCachedFontPlatformData): Ignore leading "@" on Windows to disable Windows feature for vertical flow.
+        (WebCore):
+        (WebCore::FontCache::getVerticalData): Get cached OpenTypeVerticalData from FontPlatformData, or crete one.
+        (WebCore::FontCache::purgeInactiveFontData): Purge inactive OpenTypeVerticalData.
+        * platform/graphics/FontCache.h:
+        (WebCore):
+        * platform/graphics/SimpleFontData.h:
+        (SimpleFontData):
+        (WebCore::SimpleFontData::verticalData): A dummy implementation for purgeInactiveFontData() to work.
+        * platform/graphics/opentype/OpenTypeVerticalData.h: Added m_inFontCache for mark & sweep.
+        (OpenTypeVerticalData):
+
 2012-08-01  James Robinson  <[email protected]>
 
         [chromium] Move compositor HUD font atlas initialization code out of compositor core

Modified: trunk/Source/WebCore/GNUmakefile.list.am (124396 => 124397)


--- trunk/Source/WebCore/GNUmakefile.list.am	2012-08-02 01:18:42 UTC (rev 124396)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2012-08-02 01:26:52 UTC (rev 124397)
@@ -3418,6 +3418,7 @@
 	Source/WebCore/platform/graphics/MediaPlayer.cpp \
 	Source/WebCore/platform/graphics/MediaPlayer.h \
 	Source/WebCore/platform/graphics/MediaPlayerPrivate.h \
+	Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.h \
 	Source/WebCore/platform/graphics/Path.cpp \
 	Source/WebCore/platform/graphics/Path.h \
 	Source/WebCore/platform/graphics/PathTraversalState.cpp \

Modified: trunk/Source/WebCore/Target.pri (124396 => 124397)


--- trunk/Source/WebCore/Target.pri	2012-08-02 01:18:42 UTC (rev 124396)
+++ trunk/Source/WebCore/Target.pri	2012-08-02 01:26:52 UTC (rev 124397)
@@ -2097,6 +2097,7 @@
     platform/graphics/IntPointHash.h \
     platform/graphics/IntRect.h \
     platform/graphics/MediaPlayer.h \
+    platform/graphics/opentype/OpenTypeVerticalData.h \
     platform/graphics/Path.h \
     platform/graphics/PathTraversalState.h \
     platform/graphics/Pattern.h \

Modified: trunk/Source/WebCore/WebCore.pri (124396 => 124397)


--- trunk/Source/WebCore/WebCore.pri	2012-08-02 01:18:42 UTC (rev 124396)
+++ trunk/Source/WebCore/WebCore.pri	2012-08-02 01:26:52 UTC (rev 124397)
@@ -57,6 +57,7 @@
     $$SOURCE_DIR/platform/graphics/filters \
     $$SOURCE_DIR/platform/graphics/filters/arm \
     $$SOURCE_DIR/platform/graphics/opengl \
+    $$SOURCE_DIR/platform/graphics/opentype \
     $$SOURCE_DIR/platform/graphics/qt \
     $$SOURCE_DIR/platform/graphics/surfaces \
     $$SOURCE_DIR/platform/graphics/texmap \

Modified: trunk/Source/WebCore/platform/graphics/FontCache.cpp (124396 => 124397)


--- trunk/Source/WebCore/platform/graphics/FontCache.cpp	2012-08-02 01:18:42 UTC (rev 124396)
+++ trunk/Source/WebCore/platform/graphics/FontCache.cpp	2012-08-02 01:26:52 UTC (rev 124397)
@@ -35,10 +35,12 @@
 #include "FontPlatformData.h"
 #include "FontSelector.h"
 #include "GlyphPageTreeNode.h"
+#include "OpenTypeVerticalData.h"
 #include "WebKitFontFamilyNames.h"
 #include <wtf/HashMap.h>
 #include <wtf/ListHashSet.h>
 #include <wtf/StdLibExtras.h>
+#include <wtf/text/AtomicStringHash.h>
 #include <wtf/text/StringHash.h>
 
 using namespace WTF;
@@ -179,10 +181,20 @@
     return emptyAtom;
 }
 
-FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& fontDescription, 
-                                                       const AtomicString& familyName,
+FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& fontDescription,
+                                                       const AtomicString& passedFamilyName,
                                                        bool checkingAlternateName)
 {
+#if OS(WINDOWS) && ENABLE(OPENTYPE_VERTICAL)
+    // Leading "@" in the font name enables Windows vertical flow flag for the font.
+    // Because we do vertical flow by ourselves, we don't want to use the Windows feature.
+    // IE disregards "@" regardless of the orientatoin, so we follow the behavior.
+    const AtomicString& familyName = (passedFamilyName.isEmpty() || passedFamilyName[0] != '@') ?
+        passedFamilyName : AtomicString(passedFamilyName.impl()->substring(1));
+#else
+    const AtomicString& familyName = passedFamilyName;
+#endif
+
     if (!gFontPlatformDataCache) {
         gFontPlatformDataCache = new FontPlatformDataCache;
         platformInit();
@@ -216,6 +228,32 @@
     return result;
 }
 
+#if ENABLE(OPENTYPE_VERTICAL)
+typedef HashMap<FontCache::FontFileKey, OwnPtr<OpenTypeVerticalData>> FontVerticalDataCache;
+
+FontVerticalDataCache& fontVerticalDataCacheInstance()
+{
+    DEFINE_STATIC_LOCAL(FontVerticalDataCache, fontVerticalDataCache, ());
+    return fontVerticalDataCache;
+}
+
+OpenTypeVerticalData* FontCache::getVerticalData(const FontFileKey& key, const FontPlatformData& platformData)
+{
+    FontVerticalDataCache& fontVerticalDataCache = fontVerticalDataCacheInstance();
+    FontVerticalDataCache::iterator result = fontVerticalDataCache.find(key);
+    if (result != fontVerticalDataCache.end())
+        return result.get()->second.get();
+
+    OpenTypeVerticalData* verticalData = new OpenTypeVerticalData(platformData);
+    if (!verticalData->isOpenType()) {
+        delete verticalData;
+        verticalData = 0; // Put 0 in cache to mark that this isn't an OpenType font.
+    }
+    fontVerticalDataCache.set(key, adoptPtr(verticalData));
+    return verticalData;
+}
+#endif
+
 struct FontDataCacheKeyHash {
     static unsigned hash(const FontPlatformData& platformData)
     {
@@ -381,6 +419,32 @@
             delete gFontPlatformDataCache->take(keysToRemove[i]);
     }
 
+#if ENABLE(OPENTYPE_VERTICAL)
+    FontVerticalDataCache& fontVerticalDataCache = fontVerticalDataCacheInstance();
+    if (!fontVerticalDataCache.isEmpty()) {
+        // Mark & sweep unused verticalData
+        FontVerticalDataCache::iterator verticalDataEnd = fontVerticalDataCache.end();
+        for (FontVerticalDataCache::iterator verticalData = fontVerticalDataCache.begin(); verticalData != verticalDataEnd; ++verticalData) {
+            if (verticalData->second)
+                verticalData->second->m_inFontCache = false;
+        }
+        FontDataCache::iterator fontDataEnd = gFontDataCache->end();
+        for (FontDataCache::iterator fontData = gFontDataCache->begin(); fontData != fontDataEnd; ++fontData) {
+            OpenTypeVerticalData* verticalData = const_cast<OpenTypeVerticalData*>(fontData->second.first->verticalData());
+            if (verticalData)
+                verticalData->m_inFontCache = true;
+        }
+        Vector<FontFileKey> keysToRemove;
+        keysToRemove.reserveInitialCapacity(fontVerticalDataCache.size());
+        for (FontVerticalDataCache::iterator verticalData = fontVerticalDataCache.begin(); verticalData != verticalDataEnd; ++verticalData) {
+            if (!verticalData->second || !verticalData->second->m_inFontCache)
+                keysToRemove.append(verticalData->first);
+        }
+        for (size_t i = 0, count = keysToRemove.size(); i < count; ++i)
+            fontVerticalDataCache.take(keysToRemove[i]);
+    }
+#endif
+
     isPurging = false;
 }
 

Modified: trunk/Source/WebCore/platform/graphics/FontCache.h (124396 => 124397)


--- trunk/Source/WebCore/platform/graphics/FontCache.h	2012-08-02 01:18:42 UTC (rev 124396)
+++ trunk/Source/WebCore/platform/graphics/FontCache.h	2012-08-02 01:26:52 UTC (rev 124397)
@@ -49,6 +49,7 @@
 class FontData;
 class FontDescription;
 class FontSelector;
+class OpenTypeVerticalData;
 class SimpleFontData;
 
 class FontCache {
@@ -104,6 +105,11 @@
     SimpleFontData* fontDataFromDescriptionAndLogFont(const FontDescription&, ShouldRetain, const LOGFONT& font, wchar_t* outFontFamilyName);
 #endif
 
+#if ENABLE(OPENTYPE_VERTICAL)
+    typedef AtomicString FontFileKey;
+    OpenTypeVerticalData* getVerticalData(const FontFileKey&, const FontPlatformData&);
+#endif
+
 private:
     FontCache();
     ~FontCache();

Modified: trunk/Source/WebCore/platform/graphics/SimpleFontData.h (124396 => 124397)


--- trunk/Source/WebCore/platform/graphics/SimpleFontData.h	2012-08-02 01:18:42 UTC (rev 124396)
+++ trunk/Source/WebCore/platform/graphics/SimpleFontData.h	2012-08-02 01:26:52 UTC (rev 124397)
@@ -31,6 +31,9 @@
 #include "FloatRect.h"
 #include "GlyphMetricsMap.h"
 #include "GlyphPageTreeNode.h"
+#if ENABLE(OPENTYPE_VERTICAL)
+#include "OpenTypeVerticalData.h"
+#endif
 #include "TypesettingFeatures.h"
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
@@ -88,6 +91,9 @@
     virtual ~SimpleFontData();
 
     const FontPlatformData& platformData() const { return m_platformData; }
+#if ENABLE(OPENTYPE_VERTICAL)
+    const OpenTypeVerticalData* verticalData() const { return 0; } // FIXME: implement
+#endif
 
     SimpleFontData* smallCapsFontData(const FontDescription&) const;
     SimpleFontData* emphasisMarkFontData(const FontDescription&) const;

Modified: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.h (124396 => 124397)


--- trunk/Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.h	2012-08-02 01:18:42 UTC (rev 124396)
+++ trunk/Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.h	2012-08-02 01:26:52 UTC (rev 124397)
@@ -25,6 +25,8 @@
 #ifndef OpenTypeVerticalData_h
 #define OpenTypeVerticalData_h
 
+#if ENABLE(OPENTYPE_VERTICAL)
+
 #include "Glyph.h"
 #include <wtf/HashMap.h>
 #include <wtf/Vector.h>
@@ -56,8 +58,13 @@
     Vector<int16_t> m_topSideBearings;
     int16_t m_defaultVertOriginY;
     HashMap<Glyph, int16_t> m_vertOriginY;
+
+    friend class FontCache;
+    bool m_inFontCache; // for mark & sweep in FontCache::purgeInactiveFontData()
 };
 
 } // namespace WebCore
 
+#endif // ENABLE(OPENTYPE_VERTICAL)
+
 #endif // OpenTypeVerticalData_h
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to