Changeset 124397 in webkit


Ignore:
Timestamp:
Aug 1, 2012 6:26:52 PM (12 years ago)
Author:
yosin@chromium.org
Message:

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

Patch by Koji Ishii <Koji Ishii> 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):

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r124306 r124397  
    5151    "${WEBCORE_DIR}/platform/graphics/harfbuzz"
    5252    "${WEBCORE_DIR}/platform/graphics/harfbuzz/ng"
     53    "${WEBCORE_DIR}/platform/graphics/opentype"
    5354    "${WEBCORE_DIR}/platform/graphics/transforms"
    5455    "${WEBCORE_DIR}/platform/image-decoders"
  • trunk/Source/WebCore/ChangeLog

    r124396 r124397  
     12012-08-01  Koji Ishii  <kojiishi@gmail.com>
     2
     3        Cache support for OpenTypeVerticalData
     4        https://bugs.webkit.org/show_bug.cgi?id=81332
     5
     6        Reviewed by Tony Chang.
     7
     8        This patch adds FontCache to cache OpenTypeVerticalData class
     9        instances that was introduced in bug 81326.
     10
     11        We need one instance of the class per OpenType font file, and we don't
     12        have a class to hold such instances today.
     13
     14        ENABLE_OPENTYPE_VERTICAL isn't enabled for any platforms yet, so this
     15        patch isn't on any code path. Apple Windows port (bug 48459) is going
     16        to use this code, and probably Chromium (51450, 69282) as well.
     17
     18        "FIXME" comment in SimpleFontData.h will be implemented in 48459.
     19
     20        No new tests are required. No behavior changes.
     21
     22        * platform/graphics/FontCache.cpp:
     23        (WebCore::FontCache::getCachedFontPlatformData): Ignore leading "@" on Windows to disable Windows feature for vertical flow.
     24        (WebCore):
     25        (WebCore::FontCache::getVerticalData): Get cached OpenTypeVerticalData from FontPlatformData, or crete one.
     26        (WebCore::FontCache::purgeInactiveFontData): Purge inactive OpenTypeVerticalData.
     27        * platform/graphics/FontCache.h:
     28        (WebCore):
     29        * platform/graphics/SimpleFontData.h:
     30        (SimpleFontData):
     31        (WebCore::SimpleFontData::verticalData): A dummy implementation for purgeInactiveFontData() to work.
     32        * platform/graphics/opentype/OpenTypeVerticalData.h: Added m_inFontCache for mark & sweep.
     33        (OpenTypeVerticalData):
     34
    1352012-08-01  James Robinson  <jamesr@chromium.org>
    236
  • trunk/Source/WebCore/GNUmakefile.list.am

    r124306 r124397  
    34193419        Source/WebCore/platform/graphics/MediaPlayer.h \
    34203420        Source/WebCore/platform/graphics/MediaPlayerPrivate.h \
     3421        Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.h \
    34213422        Source/WebCore/platform/graphics/Path.cpp \
    34223423        Source/WebCore/platform/graphics/Path.h \
  • trunk/Source/WebCore/Target.pri

    r124306 r124397  
    20982098    platform/graphics/IntRect.h \
    20992099    platform/graphics/MediaPlayer.h \
     2100    platform/graphics/opentype/OpenTypeVerticalData.h \
    21002101    platform/graphics/Path.h \
    21012102    platform/graphics/PathTraversalState.h \
  • trunk/Source/WebCore/WebCore.pri

    r123185 r124397  
    5858    $$SOURCE_DIR/platform/graphics/filters/arm \
    5959    $$SOURCE_DIR/platform/graphics/opengl \
     60    $$SOURCE_DIR/platform/graphics/opentype \
    6061    $$SOURCE_DIR/platform/graphics/qt \
    6162    $$SOURCE_DIR/platform/graphics/surfaces \
  • trunk/Source/WebCore/platform/graphics/FontCache.cpp

    r107794 r124397  
    3636#include "FontSelector.h"
    3737#include "GlyphPageTreeNode.h"
     38#include "OpenTypeVerticalData.h"
    3839#include "WebKitFontFamilyNames.h"
    3940#include <wtf/HashMap.h>
    4041#include <wtf/ListHashSet.h>
    4142#include <wtf/StdLibExtras.h>
     43#include <wtf/text/AtomicStringHash.h>
    4244#include <wtf/text/StringHash.h>
    4345
     
    180182}
    181183
    182 FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& fontDescription, 
    183                                                        const AtomicString& familyName,
     184FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& fontDescription,
     185                                                       const AtomicString& passedFamilyName,
    184186                                                       bool checkingAlternateName)
    185187{
     188#if OS(WINDOWS) && ENABLE(OPENTYPE_VERTICAL)
     189    // Leading "@" in the font name enables Windows vertical flow flag for the font.
     190    // Because we do vertical flow by ourselves, we don't want to use the Windows feature.
     191    // IE disregards "@" regardless of the orientatoin, so we follow the behavior.
     192    const AtomicString& familyName = (passedFamilyName.isEmpty() || passedFamilyName[0] != '@') ?
     193        passedFamilyName : AtomicString(passedFamilyName.impl()->substring(1));
     194#else
     195    const AtomicString& familyName = passedFamilyName;
     196#endif
     197
    186198    if (!gFontPlatformDataCache) {
    187199        gFontPlatformDataCache = new FontPlatformDataCache;
     
    217229}
    218230
     231#if ENABLE(OPENTYPE_VERTICAL)
     232typedef HashMap<FontCache::FontFileKey, OwnPtr<OpenTypeVerticalData>> FontVerticalDataCache;
     233
     234FontVerticalDataCache& fontVerticalDataCacheInstance()
     235{
     236    DEFINE_STATIC_LOCAL(FontVerticalDataCache, fontVerticalDataCache, ());
     237    return fontVerticalDataCache;
     238}
     239
     240OpenTypeVerticalData* FontCache::getVerticalData(const FontFileKey& key, const FontPlatformData& platformData)
     241{
     242    FontVerticalDataCache& fontVerticalDataCache = fontVerticalDataCacheInstance();
     243    FontVerticalDataCache::iterator result = fontVerticalDataCache.find(key);
     244    if (result != fontVerticalDataCache.end())
     245        return result.get()->second.get();
     246
     247    OpenTypeVerticalData* verticalData = new OpenTypeVerticalData(platformData);
     248    if (!verticalData->isOpenType()) {
     249        delete verticalData;
     250        verticalData = 0; // Put 0 in cache to mark that this isn't an OpenType font.
     251    }
     252    fontVerticalDataCache.set(key, adoptPtr(verticalData));
     253    return verticalData;
     254}
     255#endif
     256
    219257struct FontDataCacheKeyHash {
    220258    static unsigned hash(const FontPlatformData& platformData)
     
    382420    }
    383421
     422#if ENABLE(OPENTYPE_VERTICAL)
     423    FontVerticalDataCache& fontVerticalDataCache = fontVerticalDataCacheInstance();
     424    if (!fontVerticalDataCache.isEmpty()) {
     425        // Mark & sweep unused verticalData
     426        FontVerticalDataCache::iterator verticalDataEnd = fontVerticalDataCache.end();
     427        for (FontVerticalDataCache::iterator verticalData = fontVerticalDataCache.begin(); verticalData != verticalDataEnd; ++verticalData) {
     428            if (verticalData->second)
     429                verticalData->second->m_inFontCache = false;
     430        }
     431        FontDataCache::iterator fontDataEnd = gFontDataCache->end();
     432        for (FontDataCache::iterator fontData = gFontDataCache->begin(); fontData != fontDataEnd; ++fontData) {
     433            OpenTypeVerticalData* verticalData = const_cast<OpenTypeVerticalData*>(fontData->second.first->verticalData());
     434            if (verticalData)
     435                verticalData->m_inFontCache = true;
     436        }
     437        Vector<FontFileKey> keysToRemove;
     438        keysToRemove.reserveInitialCapacity(fontVerticalDataCache.size());
     439        for (FontVerticalDataCache::iterator verticalData = fontVerticalDataCache.begin(); verticalData != verticalDataEnd; ++verticalData) {
     440            if (!verticalData->second || !verticalData->second->m_inFontCache)
     441                keysToRemove.append(verticalData->first);
     442        }
     443        for (size_t i = 0, count = keysToRemove.size(); i < count; ++i)
     444            fontVerticalDataCache.take(keysToRemove[i]);
     445    }
     446#endif
     447
    384448    isPurging = false;
    385449}
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r123181 r124397  
    5050class FontDescription;
    5151class FontSelector;
     52class OpenTypeVerticalData;
    5253class SimpleFontData;
    5354
     
    105106#endif
    106107
     108#if ENABLE(OPENTYPE_VERTICAL)
     109    typedef AtomicString FontFileKey;
     110    OpenTypeVerticalData* getVerticalData(const FontFileKey&, const FontPlatformData&);
     111#endif
     112
    107113private:
    108114    FontCache();
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.h

    r123181 r124397  
    3232#include "GlyphMetricsMap.h"
    3333#include "GlyphPageTreeNode.h"
     34#if ENABLE(OPENTYPE_VERTICAL)
     35#include "OpenTypeVerticalData.h"
     36#endif
    3437#include "TypesettingFeatures.h"
    3538#include <wtf/OwnPtr.h>
     
    8992
    9093    const FontPlatformData& platformData() const { return m_platformData; }
     94#if ENABLE(OPENTYPE_VERTICAL)
     95    const OpenTypeVerticalData* verticalData() const { return 0; } // FIXME: implement
     96#endif
    9197
    9298    SimpleFontData* smallCapsFontData(const FontDescription&) const;
  • trunk/Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.h

    r122788 r124397  
    2525#ifndef OpenTypeVerticalData_h
    2626#define OpenTypeVerticalData_h
     27
     28#if ENABLE(OPENTYPE_VERTICAL)
    2729
    2830#include "Glyph.h"
     
    5759    int16_t m_defaultVertOriginY;
    5860    HashMap<Glyph, int16_t> m_vertOriginY;
     61
     62    friend class FontCache;
     63    bool m_inFontCache; // for mark & sweep in FontCache::purgeInactiveFontData()
    5964};
    6065
    6166} // namespace WebCore
    6267
     68#endif // ENABLE(OPENTYPE_VERTICAL)
     69
    6370#endif // OpenTypeVerticalData_h
Note: See TracChangeset for help on using the changeset viewer.