Title: [103262] trunk/Source/WebCore
Revision
103262
Author
r...@google.com
Date
2011-12-19 13:40:00 -0800 (Mon, 19 Dec 2011)

Log 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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (103261 => 103262)


--- trunk/Source/WebCore/ChangeLog	2011-12-19 21:28:51 UTC (rev 103261)
+++ trunk/Source/WebCore/ChangeLog	2011-12-19 21:40:00 UTC (rev 103262)
@@ -1,3 +1,29 @@
+2011-12-19  Mike Reed  <r...@google.com>
+
+        [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:
+
 2011-12-04  Robert Hogan  <rob...@webkit.org>
 
         CSS 2.1 failure: border-conflict-element-*

Modified: trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp (103261 => 103262)


--- trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp	2011-12-19 21:28:51 UTC (rev 103261)
+++ trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp	2011-12-19 21:40:00 UTC (rev 103262)
@@ -265,7 +265,7 @@
     if (!m_useGDI) {
         SkPoint origin = m_point;
         origin.fX += SkFloatToScalar(startAdvance);
-        paintSkiaText(m_graphicsContext, m_font->platformData().hfont(),
+        paintSkiaText(m_graphicsContext, m_font->platformData(),
                       numGlyphs, glyphs, advances, 0, &origin);
         return true;
     }
@@ -394,8 +394,6 @@
     if (!alpha && graphicsContext->platformContext()->getStrokeStyle() == NoStroke && !graphicsContext->hasShadow())
         return;
 
-    HFONT hfont = font->platformData().hfont();
-
     // We draw the glyphs in chunks to avoid having to do a heap allocation for
     // the arrays of characters and advances.
     const int kMaxBufferLength = 256;
@@ -436,7 +434,7 @@
 
         SkPoint origin = point;
         origin.fX += SkFloatToScalar(horizontalOffset - point.x() - currentWidth);
-        paintSkiaText(graphicsContext, hfont, curLen, &glyphs[0], &advances[0], 0, &origin);
+        paintSkiaText(graphicsContext, font->platformData(), curLen, &glyphs[0], &advances[0], 0, &origin);
     }
 }
 #else

Modified: trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp (103261 => 103262)


--- trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp	2011-12-19 21:28:51 UTC (rev 103261)
+++ trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp	2011-12-19 21:40:00 UTC (rev 103262)
@@ -37,16 +37,34 @@
 #include <mlang.h>
 
 #include "PlatformSupport.h"
+#include "SkTypeface_win.h"
 #include "SkiaFontWin.h"
 #include "StdLibExtras.h"
 
 namespace WebCore {
 
+SkTypeface* CreateTypefaceFromHFont(HFONT hfont, int* size, int* lfQuality)
+{
+    LOGFONT info;
+    GetObject(hfont, sizeof(info), &info);
+    if (size) {
+        int height = info.lfHeight;
+        if (height < 0)
+            height = -height;
+        *size = height;
+    }
+    if (lfQuality)
+        *lfQuality = info.lfQuality;
+    return SkCreateTypefaceFromLOGFONT(info);
+}
+
 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
     : m_font(hashTableDeletedFontValue())
     , m_size(-1)
     , m_scriptCache(0)
     , m_scriptFontProperties(0)
+    , m_typeface(0)
+    , m_lfQuality(DEFAULT_QUALITY)
 {
 }
 
@@ -55,6 +73,8 @@
     , m_size(0)
     , m_scriptCache(0)
     , m_scriptFontProperties(0)
+    , m_typeface(0)
+    , m_lfQuality(DEFAULT_QUALITY)
 {
 }
 
@@ -63,6 +83,7 @@
     , m_size(size)
     , m_scriptCache(0)
     , m_scriptFontProperties(0)
+    , m_typeface(CreateTypefaceFromHFont(font, 0, &m_lfQuality))
 {
 }
 
@@ -72,6 +93,8 @@
     , m_size(size)
     , m_scriptCache(0)
     , m_scriptFontProperties(0)
+    , m_typeface(0)
+    , m_lfQuality(DEFAULT_QUALITY)
 {
 }
 
@@ -80,7 +103,10 @@
     , m_size(data.m_size)
     , m_scriptCache(0)
     , m_scriptFontProperties(0)
+    , m_typeface(data.m_typeface)
+    , m_lfQuality(data.m_lfQuality)
 {
+    SkSafeRef(m_typeface);
 }
 
 FontPlatformData& FontPlatformData::operator=(const FontPlatformData& data)
@@ -88,6 +114,8 @@
     if (this != &data) {
         m_font = data.m_font;
         m_size = data.m_size;
+        SkRefCnt_SafeAssign(m_typeface, data.m_typeface);
+        m_lfQuality = data.m_lfQuality;
 
         // The following fields will get re-computed if necessary.
         ScriptFreeCache(&m_scriptCache);
@@ -101,6 +129,8 @@
 
 FontPlatformData::~FontPlatformData()
 {
+    SkSafeUnref(m_typeface);
+
     ScriptFreeCache(&m_scriptCache);
     m_scriptCache = 0;
 

Modified: trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h (103261 => 103262)


--- trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h	2011-12-19 21:28:51 UTC (rev 103261)
+++ trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h	2011-12-19 21:40:00 UTC (rev 103262)
@@ -35,6 +35,7 @@
 #include "config.h"
 
 #include "FontOrientation.h"
+#include "SkTypeface.h"
 #include <wtf/Forward.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
@@ -46,6 +47,11 @@
 
 namespace WebCore {
 
+// Return a typeface associated with the hfont, and return its size and
+// lfQuality from the hfont's LOGFONT. The caller is now an owner of the
+// typeface.
+SkTypeface* CreateTypefaceFromHFont(HFONT, int* size, int* lfQuality);
+
 class FontDescription;
 
 class FontPlatformData {
@@ -57,6 +63,7 @@
     // set everything to NULL.
     FontPlatformData(WTF::HashTableDeletedValueType);
     FontPlatformData();
+    // This constructor takes ownership of the HFONT
     FontPlatformData(HFONT, float size);
     FontPlatformData(float size, bool bold, bool oblique);
     FontPlatformData(const FontPlatformData&);
@@ -69,12 +76,14 @@
 
     HFONT hfont() const { return m_font ? m_font->hfont() : 0; }
     float size() const { return m_size; }
+    SkTypeface* typeface() const { return m_typeface; }
+    int lfQuality() const { return m_lfQuality; }
 
     FontOrientation orientation() const { return Horizontal; } // FIXME: Implement.
     void setOrientation(FontOrientation) { } // FIXME: Implement.
 
     unsigned hash() const
-    { 
+    {
         return m_font ? m_font->hash() : NULL;
     }
 
@@ -129,6 +138,9 @@
     RefPtr<RefCountedHFONT> m_font;
     float m_size;  // Point size of the font in pixels.
 
+    SkTypeface* m_typeface; // cached from m_font
+    int m_lfQuality; // cached from m_font
+
     mutable SCRIPT_CACHE m_scriptCache;
     mutable SCRIPT_FONTPROPERTIES* m_scriptFontProperties;
 };

Modified: trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.cpp (103261 => 103262)


--- trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.cpp	2011-12-19 21:28:51 UTC (rev 103261)
+++ trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.cpp	2011-12-19 21:40:00 UTC (rev 103262)
@@ -32,16 +32,16 @@
 #include "SkiaFontWin.h"
 
 #include "AffineTransform.h"
+#include "Gradient.h"
+#include "Pattern.h"
 #include "PlatformContextSkia.h"
 #include "PlatformSupport.h"
-#include "Gradient.h"
-#include "Pattern.h"
+#include "SimpleFontData.h"
 #include "SkCanvas.h"
 #include "SkDevice.h"
 #include "SkPaint.h"
 #include "SkShader.h"
 #include "SkTemplates.h"
-#include "SkTypeface_win.h"
 
 namespace WebCore {
 
@@ -179,27 +179,15 @@
     return gFlags;
 }
 
-static void setupPaintForFont(HFONT hfont, SkPaint* paint, PlatformContextSkia* pcs)
+static void setupPaintForFont(SkPaint* paint, PlatformContextSkia* pcs,
+                              SkTypeface* face, float size, int quality)
 {
-    //  FIXME:
-    //  Much of this logic could also happen in
-    //  FontCustomPlatformData::fontPlatformData and be cached,
-    //  allowing us to avoid talking to GDI at this point.
-    //
-    LOGFONT info;
-    GetObject(hfont, sizeof(info), &info);
-    int size = info.lfHeight;
-    if (size < 0)
-        size = -size; // We don't let GDI dpi-scale us (see SkFontHost_win.cpp).
-    paint->setTextSize(SkIntToScalar(size));
-
-    SkTypeface* face = SkCreateTypefaceFromLOGFONT(info);
+    paint->setTextSize(SkFloatToScalar(size));
     paint->setTypeface(face);
-    SkSafeUnref(face);
 
-    // turn lfQuality into text flags
+    // turn quality into text flags
     uint32_t textFlags;
-    switch (info.lfQuality) {
+    switch (quality) {
     case NONANTIALIASED_QUALITY:
         textFlags = 0;
         break;
@@ -227,13 +215,13 @@
     paint->setFlags(flags);
 }
 
-void paintSkiaText(GraphicsContext* context,
-                   HFONT hfont,
-                   int numGlyphs,
-                   const WORD* glyphs,
-                   const int* advances,
-                   const GOFFSET* offsets,
-                   const SkPoint* origin)
+static void paintSkiaText(GraphicsContext* context, HFONT hfont,
+                          SkTypeface* face, float size, int quality,
+                          int numGlyphs,
+                          const WORD* glyphs,
+                          const int* advances,
+                          const GOFFSET* offsets,
+                          const SkPoint* origin)
 {
     PlatformContextSkia* platformContext = context->platformContext();
     SkCanvas* canvas = platformContext->canvas();
@@ -246,7 +234,7 @@
     SkPaint paint;
     platformContext->setupPaintForFilling(&paint);
     paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
-    setupPaintForFont(hfont, &paint, platformContext);
+    setupPaintForFont(&paint, platformContext, face, size, quality);
 
     bool didFill = false;
 
@@ -263,7 +251,7 @@
         paint.reset();
         platformContext->setupPaintForStroking(&paint, 0, 0);
         paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
-        setupPaintForFont(hfont, &paint, platformContext);
+        setupPaintForFont(&paint, platformContext, face, size, quality);
 
         if (didFill) {
             // If there is a shadow and we filled above, there will already be
@@ -282,4 +270,34 @@
     }
 }
 
+///////////////////////////////////////////////////////////////////////////////////////////
+
+void paintSkiaText(GraphicsContext* context,
+                   const FontPlatformData& data,
+                   int numGlyphs,
+                   const WORD* glyphs,
+                   const int* advances,
+                   const GOFFSET* offsets,
+                   const SkPoint* origin)
+{
+    paintSkiaText(context, data.hfont(), data.typeface(), data.size(), data.lfQuality(),
+                  numGlyphs, glyphs, advances, offsets, origin);
+}
+
+void paintSkiaText(GraphicsContext* context,
+                   HFONT hfont,
+                   int numGlyphs,
+                   const WORD* glyphs,
+                   const int* advances,
+                   const GOFFSET* offsets,
+                   const SkPoint* origin)
+{
+    int size;
+    int quality;
+    SkTypeface* face = CreateTypefaceFromHFont(hfont, &size, &quality);
+    SkAutoUnref aur(face);
+
+    paintSkiaText(context, hfont, face, size, quality, numGlyphs, glyphs, advances, offsets, origin);
+}
+
 }  // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.h (103261 => 103262)


--- trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.h	2011-12-19 21:28:51 UTC (rev 103261)
+++ trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.h	2011-12-19 21:40:00 UTC (rev 103262)
@@ -38,6 +38,7 @@
 
 namespace WebCore {
 
+class FontPlatformData;
 class GraphicsContext;
 class PlatformContextSkia;
 
@@ -69,9 +70,21 @@
 bool windowsCanHandleTextDrawingWithoutShadow(GraphicsContext*);
 #endif
 
-// Note that the offsets parameter is optional.  If not NULL it represents a
+// Note that the offsets parameter is optional. If not null it represents a
 // per glyph offset (such as returned by ScriptPlace Windows API function).
 void paintSkiaText(GraphicsContext*,
+                   const FontPlatformData&,
+                   int numGlyphs,
+                   const WORD* glyphs,
+                   const int* advances,
+                   const GOFFSET* offsets,
+                   const SkPoint* origin);
+
+// Note that the offsets parameter is optional. If not null it represents a
+// per glyph offset (such as returned by ScriptPlace Windows API function).
+// Note: this is less efficient than calling the version with FontPlatformData,
+// as that caches the SkTypeface object.
+void paintSkiaText(GraphicsContext*,
                    HFONT,
                    int numGlyphs,
                    const WORD* glyphs,
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to