Diff
Modified: trunk/Source/WebCore/ChangeLog (102815 => 102816)
--- trunk/Source/WebCore/ChangeLog 2011-12-14 21:16:07 UTC (rev 102815)
+++ trunk/Source/WebCore/ChangeLog 2011-12-14 21:21:38 UTC (rev 102816)
@@ -1,3 +1,31 @@
+2011-12-14 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. 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:
+
2011-12-14 Simon Fraser <simon.fra...@apple.com>
Make -webkit-filter animatable
Modified: trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp (102815 => 102816)
--- trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp 2011-12-14 21:16:07 UTC (rev 102815)
+++ trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp 2011-12-14 21:21:38 UTC (rev 102816)
@@ -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 (102815 => 102816)
--- trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp 2011-12-14 21:16:07 UTC (rev 102815)
+++ trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp 2011-12-14 21:21:38 UTC (rev 102816)
@@ -37,16 +37,27 @@
#include <mlang.h>
#include "PlatformSupport.h"
+#include "SkTypeface_win.h"
#include "SkiaFontWin.h"
#include "StdLibExtras.h"
namespace WebCore {
+static SkTypeface* createTypefaceFromHFont(HFONT hfont, uint8_t* lfQuality)
+{
+ LOGFONT info;
+ GetObject(hfont, sizeof(info), &info);
+ *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 +66,8 @@
, m_size(0)
, m_scriptCache(0)
, m_scriptFontProperties(0)
+ , m_typeface(0)
+ , m_lfQuality(DEFAULT_QUALITY)
{
}
@@ -63,6 +76,7 @@
, m_size(size)
, m_scriptCache(0)
, m_scriptFontProperties(0)
+ , m_typeface(createTypefaceFromHFont(font, &m_lfQuality))
{
}
@@ -72,6 +86,8 @@
, m_size(size)
, m_scriptCache(0)
, m_scriptFontProperties(0)
+ , m_typeface(0)
+ , m_lfQuality(DEFAULT_QUALITY)
{
}
@@ -80,7 +96,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 +107,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 +122,8 @@
FontPlatformData::~FontPlatformData()
{
+ SkSafeUnref(m_typeface);
+
ScriptFreeCache(&m_scriptCache);
m_scriptCache = 0;
Modified: trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h (102815 => 102816)
--- trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h 2011-12-14 21:16:07 UTC (rev 102815)
+++ trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h 2011-12-14 21:21:38 UTC (rev 102816)
@@ -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>
@@ -69,12 +70,14 @@
HFONT hfont() const { return m_font ? m_font->hfont() : 0; }
float size() const { return m_size; }
+ SkTypeface* typeface() const { return m_typeface; }
+ uint8_t 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 +132,9 @@
RefPtr<RefCountedHFONT> m_font;
float m_size; // Point size of the font in pixels.
+ SkTypeface* m_typeface; // cached from m_font
+ uint8_t 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 (102815 => 102816)
--- trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.cpp 2011-12-14 21:16:07 UTC (rev 102815)
+++ trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.cpp 2011-12-14 21:21:38 UTC (rev 102816)
@@ -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,14 @@
return gFlags;
}
-static void setupPaintForFont(HFONT hfont, SkPaint* paint, PlatformContextSkia* pcs)
+static void setupPaintForFont(SkPaint* paint, const FontPlatformData& font, PlatformContextSkia* pcs)
{
- // 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));
+ paint->setTextSize(SkFloatToScalar(font.size()));
+ paint->setTypeface(font.typeface());
- SkTypeface* face = SkCreateTypefaceFromLOGFONT(info);
- paint->setTypeface(face);
- SkSafeUnref(face);
-
// turn lfQuality into text flags
uint32_t textFlags;
- switch (info.lfQuality) {
+ switch (font.lfQuality()) {
case NONANTIALIASED_QUALITY:
textFlags = 0;
break;
@@ -228,7 +215,7 @@
}
void paintSkiaText(GraphicsContext* context,
- HFONT hfont,
+ const FontPlatformData& font,
int numGlyphs,
const WORD* glyphs,
const int* advances,
@@ -240,13 +227,13 @@
TextDrawingModeFlags textMode = platformContext->getTextDrawingMode();
// Ensure font load for printing, because PDF device needs it.
if (canvas->getTopDevice()->getDeviceCapabilities() & SkDevice::kVector_Capability)
- PlatformSupport::ensureFontLoaded(hfont);
+ PlatformSupport::ensureFontLoaded(font.hfont());
// Filling (if necessary). This is the common case.
SkPaint paint;
platformContext->setupPaintForFilling(&paint);
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- setupPaintForFont(hfont, &paint, platformContext);
+ setupPaintForFont(&paint, font, platformContext);
bool didFill = false;
@@ -263,7 +250,7 @@
paint.reset();
platformContext->setupPaintForStroking(&paint, 0, 0);
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- setupPaintForFont(hfont, &paint, platformContext);
+ setupPaintForFont(&paint, font, platformContext);
if (didFill) {
// If there is a shadow and we filled above, there will already be
@@ -282,4 +269,22 @@
}
}
+void paintSkiaText(GraphicsContext* context,
+ HFONT hfont,
+ int numGlyphs,
+ const WORD* glyphs,
+ const int* advances,
+ const GOFFSET* offsets,
+ const SkPoint* origin)
+{
+ LOGFONT info;
+ GetObject(hfont, sizeof(info), &info);
+ float size = info.lfHeight;
+ if (size < 0)
+ size = -size;
+
+ FontPlatformData font(hfont, size);
+ paintSkiaText(context, font, numGlyphs, glyphs, advances, offsets, origin);
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.h (102815 => 102816)
--- trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.h 2011-12-14 21:16:07 UTC (rev 102815)
+++ trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.h 2011-12-14 21:21:38 UTC (rev 102816)
@@ -38,6 +38,7 @@
namespace WebCore {
+class FontPlatformData;
class GraphicsContext;
class PlatformContextSkia;
@@ -72,6 +73,15 @@
// 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);
+
+// Convenience call for clients that don't cache the typeface or size
+void paintSkiaText(GraphicsContext*,
HFONT,
int numGlyphs,
const WORD* glyphs,