Cache support for OpenTypeVerticalData
authoryosin@chromium.org <yosin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Aug 2012 01:26:52 +0000 (01:26 +0000)
committeryosin@chromium.org <yosin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Aug 2012 01:26:52 +0000 (01:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=81332

Patch by Koji Ishii <kojiishi@gmail.com> 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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@124397 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.pri
Source/WebCore/platform/graphics/FontCache.cpp
Source/WebCore/platform/graphics/FontCache.h
Source/WebCore/platform/graphics/SimpleFontData.h
Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.h

index 811712d..bac348b 100644 (file)
@@ -50,6 +50,7 @@ SET(WebCore_INCLUDE_DIRECTORIES
     "${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"
index ae49dbf..17c37be 100644 (file)
@@ -1,3 +1,37 @@
+2012-08-01  Koji Ishii  <kojiishi@gmail.com>
+
+        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  <jamesr@chromium.org>
 
         [chromium] Move compositor HUD font atlas initialization code out of compositor core
index 958645c..4b46743 100644 (file)
@@ -3418,6 +3418,7 @@ webcore_sources += \
        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 \
index 45aeecf..6b7ea37 100644 (file)
@@ -2097,6 +2097,7 @@ HEADERS += \
     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 \
index 513d261..c0a6335 100644 (file)
@@ -57,6 +57,7 @@ INCLUDEPATH += \
     $$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 \
index 47f251c..b46263a 100644 (file)
 #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 @@ static const AtomicString& alternateFamilyName(const AtomicString& familyName)
     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 @@ FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& fo
     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 @@ void FontCache::purgeInactiveFontData(int count)
             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;
 }
 
index c71e41f..858db21 100644 (file)
@@ -49,6 +49,7 @@ class FontPlatformData;
 class FontData;
 class FontDescription;
 class FontSelector;
+class OpenTypeVerticalData;
 class SimpleFontData;
 
 class FontCache {
@@ -104,6 +105,11 @@ public:
     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();
index 425cf73..3452d00 100644 (file)
@@ -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 @@ public:
     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;
index f073957..34ccee0 100644 (file)
@@ -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 @@ private:
     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