Changeset 103262 in webkit


Ignore:
Timestamp:
Dec 19, 2011 1:40:00 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. optimization only, existing tests in play

  • 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):

  • 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

    r103251 r103262  
     12011-12-19  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. optimization only, existing tests in play
     9
     10        * platform/graphics/chromium/FontChromiumWin.cpp:
     11        (WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::drawGlyphs):
     12        (WebCore::Font::drawGlyphs):
     13        * platform/graphics/chromium/FontPlatformDataChromiumWin.cpp:
     14        (WebCore::CreateTypefaceFromHFont):
     15        (WebCore::FontPlatformData::FontPlatformData):
     16        (WebCore::FontPlatformData::operator=):
     17        (WebCore::FontPlatformData::~FontPlatformData):
     18        * platform/graphics/chromium/FontPlatformDataChromiumWin.h:
     19        (WebCore::FontPlatformData::typeface):
     20        (WebCore::FontPlatformData::lfQuality):
     21        (WebCore::FontPlatformData::hash):
     22        * platform/graphics/skia/SkiaFontWin.cpp:
     23        (WebCore::setupPaintForFont):
     24        (WebCore::paintSkiaText):
     25        * platform/graphics/skia/SkiaFontWin.h:
     26
    1272011-12-04  Robert Hogan  <robert@webkit.org>
    228
  • trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp

    r102858 r103262  
    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

    r102858 r103262  
    3838
    3939#include "PlatformSupport.h"
     40#include "SkTypeface_win.h"
    4041#include "SkiaFontWin.h"
    4142#include "StdLibExtras.h"
    4243
    4344namespace WebCore {
     45
     46SkTypeface* CreateTypefaceFromHFont(HFONT hfont, int* size, int* lfQuality)
     47{
     48    LOGFONT info;
     49    GetObject(hfont, sizeof(info), &info);
     50    if (size) {
     51        int height = info.lfHeight;
     52        if (height < 0)
     53            height = -height;
     54        *size = height;
     55    }
     56    if (lfQuality)
     57        *lfQuality = info.lfQuality;
     58    return SkCreateTypefaceFromLOGFONT(info);
     59}
    4460
    4561FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
     
    4864    , m_scriptCache(0)
    4965    , m_scriptFontProperties(0)
     66    , m_typeface(0)
     67    , m_lfQuality(DEFAULT_QUALITY)
    5068{
    5169}
     
    5674    , m_scriptCache(0)
    5775    , m_scriptFontProperties(0)
     76    , m_typeface(0)
     77    , m_lfQuality(DEFAULT_QUALITY)
    5878{
    5979}
     
    6484    , m_scriptCache(0)
    6585    , m_scriptFontProperties(0)
     86    , m_typeface(CreateTypefaceFromHFont(font, 0, &m_lfQuality))
    6687{
    6788}
     
    7394    , m_scriptCache(0)
    7495    , m_scriptFontProperties(0)
     96    , m_typeface(0)
     97    , m_lfQuality(DEFAULT_QUALITY)
    7598{
    7699}
     
    81104    , m_scriptCache(0)
    82105    , m_scriptFontProperties(0)
     106    , m_typeface(data.m_typeface)
     107    , m_lfQuality(data.m_lfQuality)
    83108{
     109    SkSafeRef(m_typeface);
    84110}
    85111
     
    89115        m_font = data.m_font;
    90116        m_size = data.m_size;
     117        SkRefCnt_SafeAssign(m_typeface, data.m_typeface);
     118        m_lfQuality = data.m_lfQuality;
    91119
    92120        // The following fields will get re-computed if necessary.
     
    102130FontPlatformData::~FontPlatformData()
    103131{
     132    SkSafeUnref(m_typeface);
     133
    104134    ScriptFreeCache(&m_scriptCache);
    105135    m_scriptCache = 0;
  • trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h

    r102858 r103262  
    3636
    3737#include "FontOrientation.h"
     38#include "SkTypeface.h"
    3839#include <wtf/Forward.h>
    3940#include <wtf/PassRefPtr.h>
     
    4647
    4748namespace WebCore {
     49
     50// Return a typeface associated with the hfont, and return its size and
     51// lfQuality from the hfont's LOGFONT. The caller is now an owner of the
     52// typeface.
     53SkTypeface* CreateTypefaceFromHFont(HFONT, int* size, int* lfQuality);
    4854
    4955class FontDescription;
     
    5864    FontPlatformData(WTF::HashTableDeletedValueType);
    5965    FontPlatformData();
     66    // This constructor takes ownership of the HFONT
    6067    FontPlatformData(HFONT, float size);
    6168    FontPlatformData(float size, bool bold, bool oblique);
     
    7077    HFONT hfont() const { return m_font ? m_font->hfont() : 0; }
    7178    float size() const { return m_size; }
     79    SkTypeface* typeface() const { return m_typeface; }
     80    int lfQuality() const { return m_lfQuality; }
    7281
    7382    FontOrientation orientation() const { return Horizontal; } // FIXME: Implement.
     
    7584
    7685    unsigned hash() const
    77     { 
     86    {
    7887        return m_font ? m_font->hash() : NULL;
    7988    }
     
    130139    float m_size;  // Point size of the font in pixels.
    131140
     141    SkTypeface* m_typeface; // cached from m_font
     142    int m_lfQuality; // cached from m_font
     143
    132144    mutable SCRIPT_CACHE m_scriptCache;
    133145    mutable SCRIPT_FONTPROPERTIES* m_scriptFontProperties;
  • trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.cpp

    r102858 r103262  
    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);
     182static void setupPaintForFont(SkPaint* paint, PlatformContextSkia* pcs,
     183                              SkTypeface* face, float size, int quality)
     184{
     185    paint->setTextSize(SkFloatToScalar(size));
    197186    paint->setTypeface(face);
    198     SkSafeUnref(face);
    199 
    200     // turn lfQuality into text flags
     187
     188    // turn quality into text flags
    201189    uint32_t textFlags;
    202     switch (info.lfQuality) {
     190    switch (quality) {
    203191    case NONANTIALIASED_QUALITY:
    204192        textFlags = 0;
     
    228216}
    229217
    230 void paintSkiaText(GraphicsContext* context,
    231                    HFONT hfont,
    232                    int numGlyphs,
    233                    const WORD* glyphs,
    234                    const int* advances,
    235                    const GOFFSET* offsets,
    236                    const SkPoint* origin)
     218static void paintSkiaText(GraphicsContext* context, HFONT hfont,
     219                          SkTypeface* face, float size, int quality,
     220                          int numGlyphs,
     221                          const WORD* glyphs,
     222                          const int* advances,
     223                          const GOFFSET* offsets,
     224                          const SkPoint* origin)
    237225{
    238226    PlatformContextSkia* platformContext = context->platformContext();
     
    247235    platformContext->setupPaintForFilling(&paint);
    248236    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
    249     setupPaintForFont(hfont, &paint, platformContext);
     237    setupPaintForFont(&paint, platformContext, face, size, quality);
    250238
    251239    bool didFill = false;
     
    264252        platformContext->setupPaintForStroking(&paint, 0, 0);
    265253        paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
    266         setupPaintForFont(hfont, &paint, platformContext);
     254        setupPaintForFont(&paint, platformContext, face, size, quality);
    267255
    268256        if (didFill) {
     
    283271}
    284272
     273///////////////////////////////////////////////////////////////////////////////////////////
     274
     275void paintSkiaText(GraphicsContext* context,
     276                   const FontPlatformData& data,
     277                   int numGlyphs,
     278                   const WORD* glyphs,
     279                   const int* advances,
     280                   const GOFFSET* offsets,
     281                   const SkPoint* origin)
     282{
     283    paintSkiaText(context, data.hfont(), data.typeface(), data.size(), data.lfQuality(),
     284                  numGlyphs, glyphs, advances, offsets, origin);
     285}
     286
     287void paintSkiaText(GraphicsContext* context,
     288                   HFONT hfont,
     289                   int numGlyphs,
     290                   const WORD* glyphs,
     291                   const int* advances,
     292                   const GOFFSET* offsets,
     293                   const SkPoint* origin)
     294{
     295    int size;
     296    int quality;
     297    SkTypeface* face = CreateTypefaceFromHFont(hfont, &size, &quality);
     298    SkAutoUnref aur(face);
     299
     300    paintSkiaText(context, hfont, face, size, quality, numGlyphs, glyphs, advances, offsets, origin);
     301}
     302
    285303}  // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.h

    r102858 r103262  
    3939namespace WebCore {
    4040
     41class FontPlatformData;
    4142class GraphicsContext;
    4243class PlatformContextSkia;
     
    7071#endif
    7172
    72 // Note that the offsets parameter is optional.  If not NULL it represents a
     73// Note that the offsets parameter is optional. If not null it represents a
    7374// per glyph offset (such as returned by ScriptPlace Windows API function).
     75void 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// Note that the offsets parameter is optional. If not null it represents a
     84// per glyph offset (such as returned by ScriptPlace Windows API function).
     85// Note: this is less efficient than calling the version with FontPlatformData,
     86// as that caches the SkTypeface object.
    7487void paintSkiaText(GraphicsContext*,
    7588                   HFONT,
Note: See TracChangeset for help on using the changeset viewer.