Changeset 102816 in webkit


Ignore:
Timestamp:
Dec 14, 2011 1:21:38 PM (12 years ago)
Author:
reed@google.com
Message:

[skia] cache typeface in FontPlatformData
https://bugs.webkit.org/show_bug.cgi?id=74415

Reviewed by Stephen White.

No new tests. Existing tests apply, this is just an optimization
to avoid looking up the typeface on each drawText call.

  • platform/graphics/chromium/FontChromiumWin.cpp:

(WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::drawGlyphs):
(WebCore::Font::drawGlyphs):

  • platform/graphics/chromium/FontPlatformDataChromiumWin.cpp:

(WebCore::createTypefaceFromHFont):
(WebCore::FontPlatformData::FontPlatformData):
(WebCore::FontPlatformData::operator=):
(WebCore::FontPlatformData::~FontPlatformData):

  • platform/graphics/chromium/FontPlatformDataChromiumWin.h:

(WebCore::FontPlatformData::typeface):
(WebCore::FontPlatformData::lfQuality):
(WebCore::FontPlatformData::hash):
(WebCore::FontPlatformData::operator==):

  • platform/graphics/skia/SkiaFontWin.cpp:

(WebCore::setupPaintForFont):
(WebCore::paintSkiaText):

  • platform/graphics/skia/SkiaFontWin.h:
Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r102815 r102816  
     12011-12-14  Mike Reed  <reed@google.com>
     2
     3        [skia] cache typeface in FontPlatformData
     4        https://bugs.webkit.org/show_bug.cgi?id=74415
     5
     6        Reviewed by Stephen White.
     7
     8        No new tests. Existing tests apply, this is just an optimization
     9        to avoid looking up the typeface on each drawText call.
     10
     11        * platform/graphics/chromium/FontChromiumWin.cpp:
     12        (WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::drawGlyphs):
     13        (WebCore::Font::drawGlyphs):
     14        * platform/graphics/chromium/FontPlatformDataChromiumWin.cpp:
     15        (WebCore::createTypefaceFromHFont):
     16        (WebCore::FontPlatformData::FontPlatformData):
     17        (WebCore::FontPlatformData::operator=):
     18        (WebCore::FontPlatformData::~FontPlatformData):
     19        * platform/graphics/chromium/FontPlatformDataChromiumWin.h:
     20        (WebCore::FontPlatformData::typeface):
     21        (WebCore::FontPlatformData::lfQuality):
     22        (WebCore::FontPlatformData::hash):
     23        (WebCore::FontPlatformData::operator==):
     24        * platform/graphics/skia/SkiaFontWin.cpp:
     25        (WebCore::setupPaintForFont):
     26        (WebCore::paintSkiaText):
     27        * platform/graphics/skia/SkiaFontWin.h:
     28
    1292011-12-14  Simon Fraser  <simon.fraser@apple.com>
    230
  • trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp

    r98692 r102816  
    266266        SkPoint origin = m_point;
    267267        origin.fX += SkFloatToScalar(startAdvance);
    268         paintSkiaText(m_graphicsContext, m_font->platformData().hfont(),
     268        paintSkiaText(m_graphicsContext, m_font->platformData(),
    269269                      numGlyphs, glyphs, advances, 0, &origin);
    270270        return true;
     
    394394    if (!alpha && graphicsContext->platformContext()->getStrokeStyle() == NoStroke && !graphicsContext->hasShadow())
    395395        return;
    396 
    397     HFONT hfont = font->platformData().hfont();
    398396
    399397    // We draw the glyphs in chunks to avoid having to do a heap allocation for
     
    437435        SkPoint origin = point;
    438436        origin.fX += SkFloatToScalar(horizontalOffset - point.x() - currentWidth);
    439         paintSkiaText(graphicsContext, hfont, curLen, &glyphs[0], &advances[0], 0, &origin);
     437        paintSkiaText(graphicsContext, font->platformData(), curLen, &glyphs[0], &advances[0], 0, &origin);
    440438    }
    441439}
  • trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp

    r95901 r102816  
    3838
    3939#include "PlatformSupport.h"
     40#include "SkTypeface_win.h"
    4041#include "SkiaFontWin.h"
    4142#include "StdLibExtras.h"
    4243
    4344namespace WebCore {
     45
     46static SkTypeface* createTypefaceFromHFont(HFONT hfont, uint8_t* lfQuality)
     47{
     48    LOGFONT info;
     49    GetObject(hfont, sizeof(info), &info);
     50    *lfQuality = info.lfQuality;
     51    return SkCreateTypefaceFromLOGFONT(info);
     52}
    4453
    4554FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
     
    4857    , m_scriptCache(0)
    4958    , m_scriptFontProperties(0)
     59    , m_typeface(0)
     60    , m_lfQuality(DEFAULT_QUALITY)
    5061{
    5162}
     
    5667    , m_scriptCache(0)
    5768    , m_scriptFontProperties(0)
     69    , m_typeface(0)
     70    , m_lfQuality(DEFAULT_QUALITY)
    5871{
    5972}
     
    6477    , m_scriptCache(0)
    6578    , m_scriptFontProperties(0)
     79    , m_typeface(createTypefaceFromHFont(font, &m_lfQuality))
    6680{
    6781}
     
    7387    , m_scriptCache(0)
    7488    , m_scriptFontProperties(0)
     89    , m_typeface(0)
     90    , m_lfQuality(DEFAULT_QUALITY)
    7591{
    7692}
     
    8197    , m_scriptCache(0)
    8298    , m_scriptFontProperties(0)
     99    , m_typeface(data.m_typeface)
     100    , m_lfQuality(data.m_lfQuality)
    83101{
     102    SkSafeRef(m_typeface);
    84103}
    85104
     
    89108        m_font = data.m_font;
    90109        m_size = data.m_size;
     110        SkRefCnt_SafeAssign(m_typeface, data.m_typeface);
     111        m_lfQuality = data.m_lfQuality;
    91112
    92113        // The following fields will get re-computed if necessary.
     
    102123FontPlatformData::~FontPlatformData()
    103124{
     125    SkSafeUnref(m_typeface);
     126
    104127    ScriptFreeCache(&m_scriptCache);
    105128    m_scriptCache = 0;
  • trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h

    r95901 r102816  
    3636
    3737#include "FontOrientation.h"
     38#include "SkTypeface.h"
    3839#include <wtf/Forward.h>
    3940#include <wtf/PassRefPtr.h>
     
    7071    HFONT hfont() const { return m_font ? m_font->hfont() : 0; }
    7172    float size() const { return m_size; }
     73    SkTypeface* typeface() const { return m_typeface; }
     74    uint8_t lfQuality() const { return m_lfQuality; }
    7275
    7376    FontOrientation orientation() const { return Horizontal; } // FIXME: Implement.
     
    7578
    7679    unsigned hash() const
    77     { 
     80    {
    7881        return m_font ? m_font->hash() : NULL;
    7982    }
     
    130133    float m_size;  // Point size of the font in pixels.
    131134
     135    SkTypeface* m_typeface; // cached from m_font
     136    uint8_t m_lfQuality; // cached from m_font
     137
    132138    mutable SCRIPT_CACHE m_scriptCache;
    133139    mutable SCRIPT_FONTPROPERTIES* m_scriptFontProperties;
  • trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.cpp

    r98692 r102816  
    3333
    3434#include "AffineTransform.h"
     35#include "Gradient.h"
     36#include "Pattern.h"
    3537#include "PlatformContextSkia.h"
    3638#include "PlatformSupport.h"
    37 #include "Gradient.h"
    38 #include "Pattern.h"
     39#include "SimpleFontData.h"
    3940#include "SkCanvas.h"
    4041#include "SkDevice.h"
     
    4243#include "SkShader.h"
    4344#include "SkTemplates.h"
    44 #include "SkTypeface_win.h"
    4545
    4646namespace WebCore {
     
    180180}
    181181
    182 static void setupPaintForFont(HFONT hfont, SkPaint* paint, PlatformContextSkia* pcs)
    183 {
    184     //  FIXME:
    185     //  Much of this logic could also happen in
    186     //  FontCustomPlatformData::fontPlatformData and be cached,
    187     //  allowing us to avoid talking to GDI at this point.
    188     //
    189     LOGFONT info;
    190     GetObject(hfont, sizeof(info), &info);
    191     int size = info.lfHeight;
    192     if (size < 0)
    193         size = -size; // We don't let GDI dpi-scale us (see SkFontHost_win.cpp).
    194     paint->setTextSize(SkIntToScalar(size));
    195 
    196     SkTypeface* face = SkCreateTypefaceFromLOGFONT(info);
    197     paint->setTypeface(face);
    198     SkSafeUnref(face);
     182static void setupPaintForFont(SkPaint* paint, const FontPlatformData& font, PlatformContextSkia* pcs)
     183{
     184    paint->setTextSize(SkFloatToScalar(font.size()));
     185    paint->setTypeface(font.typeface());
    199186
    200187    // turn lfQuality into text flags
    201188    uint32_t textFlags;
    202     switch (info.lfQuality) {
     189    switch (font.lfQuality()) {
    203190    case NONANTIALIASED_QUALITY:
    204191        textFlags = 0;
     
    229216
    230217void paintSkiaText(GraphicsContext* context,
    231                    HFONT hfont,
     218                   const FontPlatformData& font,
    232219                   int numGlyphs,
    233220                   const WORD* glyphs,
     
    241228    // Ensure font load for printing, because PDF device needs it.
    242229    if (canvas->getTopDevice()->getDeviceCapabilities() & SkDevice::kVector_Capability)
    243         PlatformSupport::ensureFontLoaded(hfont);
     230        PlatformSupport::ensureFontLoaded(font.hfont());
    244231
    245232    // Filling (if necessary). This is the common case.
     
    247234    platformContext->setupPaintForFilling(&paint);
    248235    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
    249     setupPaintForFont(hfont, &paint, platformContext);
     236    setupPaintForFont(&paint, font, platformContext);
    250237
    251238    bool didFill = false;
     
    264251        platformContext->setupPaintForStroking(&paint, 0, 0);
    265252        paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
    266         setupPaintForFont(hfont, &paint, platformContext);
     253        setupPaintForFont(&paint, font, platformContext);
    267254
    268255        if (didFill) {
     
    283270}
    284271
     272void paintSkiaText(GraphicsContext* context,
     273                   HFONT hfont,
     274                   int numGlyphs,
     275                   const WORD* glyphs,
     276                   const int* advances,
     277                   const GOFFSET* offsets,
     278                   const SkPoint* origin)
     279{
     280    LOGFONT info;
     281    GetObject(hfont, sizeof(info), &info);
     282    float size = info.lfHeight;
     283    if (size < 0)
     284        size = -size;
     285
     286    FontPlatformData font(hfont, size);
     287    paintSkiaText(context, font, numGlyphs, glyphs, advances, offsets, origin);
     288}
     289
    285290}  // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.h

    r97573 r102816  
    3939namespace WebCore {
    4040
     41class FontPlatformData;
    4142class GraphicsContext;
    4243class PlatformContextSkia;
     
    7374// per glyph offset (such as returned by ScriptPlace Windows API function).
    7475void paintSkiaText(GraphicsContext*,
     76                   const FontPlatformData&,
     77                   int numGlyphs,
     78                   const WORD* glyphs,
     79                   const int* advances,
     80                   const GOFFSET* offsets,
     81                   const SkPoint* origin);
     82
     83// Convenience call for clients that don't cache the typeface or size
     84void paintSkiaText(GraphicsContext*,
    7585                   HFONT,
    7686                   int numGlyphs,
Note: See TracChangeset for help on using the changeset viewer.