Diff
Modified: trunk/Source/WebCore/ChangeLog (224751 => 224752)
--- trunk/Source/WebCore/ChangeLog 2017-11-13 09:55:42 UTC (rev 224751)
+++ trunk/Source/WebCore/ChangeLog 2017-11-13 13:33:07 UTC (rev 224752)
@@ -1,5 +1,33 @@
2017-11-13 Zan Dobersek <[email protected]>
+ [Cairo] Move glyph drawing operations from FontCairo to CairoOperations
+ https://bugs.webkit.org/show_bug.cgi?id=179609
+
+ Reviewed by Carlos Garcia Campos.
+
+ Move operations that perform glyph drawing to the CairoOperations file.
+ This limits operations to only work with a PlatformContextCairo object,
+ along with other required parameters, and will help with future work
+ that will rely on isolated Cairo-specific code.
+
+ Along with moving the drawGlyphs() code, the helper functions are moved
+ and adjusted to work specifically on a PlatformContextCairo object and
+ a const GraphicsContextState reference, only using a GraphicsContext
+ reference for any required shadowed glyph drawing.
+
+ No new tests -- no change in behavior.
+
+ * platform/graphics/cairo/CairoOperations.cpp:
+ (WebCore::Cairo::drawGlyphsToContext):
+ (WebCore::Cairo::drawGlyphsShadow):
+ (WebCore::Cairo::drawGlyphs):
+ * platform/graphics/cairo/FontCairo.cpp:
+ (WebCore::FontCascade::drawGlyphs):
+ (WebCore::drawGlyphsToContext): Deleted.
+ (WebCore::drawGlyphsShadow): Deleted.
+
+2017-11-13 Zan Dobersek <[email protected]>
+
[Cairo] Move focus ring drawing operations from GraphicsContextCairo to CairoOperations
https://bugs.webkit.org/show_bug.cgi?id=179603
Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp (224751 => 224752)
--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp 2017-11-13 09:55:42 UTC (rev 224751)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp 2017-11-13 13:33:07 UTC (rev 224752)
@@ -161,6 +161,54 @@
#endif
}
+static void drawGlyphsToContext(cairo_t* context, cairo_scaled_font_t* scaledFont, double syntheticBoldOffset, const Vector<cairo_glyph_t>& glyphs)
+{
+ cairo_matrix_t originalTransform;
+ if (syntheticBoldOffset)
+ cairo_get_matrix(context, &originalTransform);
+
+ cairo_set_scaled_font(context, scaledFont);
+ cairo_show_glyphs(context, glyphs.data(), glyphs.size());
+
+ if (syntheticBoldOffset) {
+ cairo_translate(context, syntheticBoldOffset, 0);
+ cairo_show_glyphs(context, glyphs.data(), glyphs.size());
+
+ cairo_set_matrix(context, &originalTransform);
+ }
+}
+
+static void drawGlyphsShadow(PlatformContextCairo& platformContext, const GraphicsContextState& state, bool mustUseShadowBlur, const FloatPoint& point, cairo_scaled_font_t* scaledFont, double syntheticBoldOffset, const Vector<cairo_glyph_t>& glyphs, GraphicsContext& targetContext)
+{
+ ShadowBlur& shadow = platformContext.shadowBlur();
+
+ if (!(state.textDrawingMode & TextModeFill) || shadow.type() == ShadowBlur::NoShadow)
+ return;
+
+ if (!mustUseShadowBlur) {
+ // Optimize non-blurry shadows, by just drawing text without the ShadowBlur.
+ cairo_t* context = platformContext.cr();
+ cairo_save(context);
+
+ FloatSize shadowOffset(state.shadowOffset);
+ cairo_translate(context, shadowOffset.width(), shadowOffset.height());
+ setSourceRGBAFromColor(context, state.shadowColor);
+ drawGlyphsToContext(context, scaledFont, syntheticBoldOffset, glyphs);
+
+ cairo_restore(context);
+ return;
+ }
+
+ cairo_text_extents_t extents;
+ cairo_scaled_font_glyph_extents(scaledFont, glyphs.data(), glyphs.size(), &extents);
+ FloatRect fontExtentsRect(point.x() + extents.x_bearing, point.y() + extents.y_bearing, extents.width, extents.height);
+
+ if (GraphicsContext* shadowContext = shadow.beginShadowLayer(targetContext, fontExtentsRect)) {
+ drawGlyphsToContext(shadowContext->platformContext()->cr(), scaledFont, syntheticBoldOffset, glyphs);
+ shadow.endShadowLayer(targetContext);
+ }
+}
+
namespace State {
void setStrokeStyle(PlatformContextCairo& platformContext, StrokeStyle strokeStyle)
@@ -347,6 +395,35 @@
cairo_restore(cr);
}
+void drawGlyphs(PlatformContextCairo& platformContext, const GraphicsContextState& state, bool mustUseShadowBlur, const FloatPoint& point, cairo_scaled_font_t* scaledFont, double syntheticBoldOffset, const Vector<cairo_glyph_t>& glyphs, float xOffset, GraphicsContext& targetContext)
+{
+ drawGlyphsShadow(platformContext, state, mustUseShadowBlur, point, scaledFont, syntheticBoldOffset, glyphs, targetContext);
+
+ cairo_t* cr = platformContext.cr();
+ cairo_save(cr);
+
+ if (state.textDrawingMode & TextModeFill) {
+ platformContext.prepareForFilling(state, PlatformContextCairo::AdjustPatternForGlobalAlpha);
+ drawGlyphsToContext(cr, scaledFont, syntheticBoldOffset, glyphs);
+ }
+
+ // Prevent running into a long computation within cairo. If the stroke width is
+ // twice the size of the width of the text we will not ask cairo to stroke
+ // the text as even one single stroke would cover the full wdth of the text.
+ // See https://bugs.webkit.org/show_bug.cgi?id=33759.
+ if (state.textDrawingMode & TextModeStroke && state.strokeThickness < 2 * xOffset) {
+ platformContext.prepareForStroking(state);
+ cairo_set_line_width(cr, state.strokeThickness);
+
+ // This may disturb the CTM, but we are going to call cairo_restore soon after.
+ cairo_set_scaled_font(cr, scaledFont);
+ cairo_glyph_path(cr, glyphs.data(), glyphs.size());
+ cairo_stroke(cr);
+ }
+
+ cairo_restore(cr);
+}
+
void drawFocusRing(PlatformContextCairo& platformContext, const Path& path, float width, const Color& color)
{
// FIXME: We should draw paths that describe a rectangle with rounded corners
Modified: trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp (224751 => 224752)
--- trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp 2017-11-13 09:55:42 UTC (rev 224751)
+++ trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp 2017-11-13 13:33:07 UTC (rev 224752)
@@ -47,56 +47,6 @@
namespace WebCore {
-static void drawGlyphsToContext(cairo_t* context, const Font& font, const cairo_glyph_t* glyphs, unsigned numGlyphs)
-{
- cairo_matrix_t originalTransform;
- float syntheticBoldOffset = font.syntheticBoldOffset();
- if (syntheticBoldOffset)
- cairo_get_matrix(context, &originalTransform);
-
- cairo_set_scaled_font(context, font.platformData().scaledFont());
- cairo_show_glyphs(context, glyphs, numGlyphs);
-
- if (syntheticBoldOffset) {
- cairo_translate(context, syntheticBoldOffset, 0);
- cairo_show_glyphs(context, glyphs, numGlyphs);
- }
-
- if (syntheticBoldOffset)
- cairo_set_matrix(context, &originalTransform);
-}
-
-static void drawGlyphsShadow(GraphicsContext& graphicsContext, const FloatPoint& point, const Font& font, const cairo_glyph_t* glyphs, unsigned numGlyphs)
-{
- ShadowBlur& shadow = graphicsContext.platformContext()->shadowBlur();
-
- if (!(graphicsContext.textDrawingMode() & TextModeFill) || shadow.type() == ShadowBlur::NoShadow)
- return;
-
- if (!graphicsContext.mustUseShadowBlur()) {
- // Optimize non-blurry shadows, by just drawing text without the ShadowBlur.
- cairo_t* context = graphicsContext.platformContext()->cr();
- cairo_save(context);
-
- FloatSize shadowOffset(graphicsContext.state().shadowOffset);
- cairo_translate(context, shadowOffset.width(), shadowOffset.height());
- setSourceRGBAFromColor(context, graphicsContext.state().shadowColor);
- drawGlyphsToContext(context, font, glyphs, numGlyphs);
-
- cairo_restore(context);
- return;
- }
-
- cairo_text_extents_t extents;
- cairo_scaled_font_glyph_extents(font.platformData().scaledFont(), glyphs, numGlyphs, &extents);
- FloatRect fontExtentsRect(point.x() + extents.x_bearing, point.y() + extents.y_bearing, extents.width, extents.height);
-
- if (GraphicsContext* shadowContext = shadow.beginShadowLayer(graphicsContext, fontExtentsRect)) {
- drawGlyphsToContext(shadowContext->platformContext()->cr(), font, glyphs, numGlyphs);
- shadow.endShadowLayer(graphicsContext);
- }
-}
-
void FontCascade::drawGlyphs(GraphicsContext& context, const Font& font, const GlyphBuffer& glyphBuffer,
unsigned from, unsigned numGlyphs, const FloatPoint& point, FontSmoothingMode)
{
@@ -104,45 +54,24 @@
return;
auto xOffset = point.x();
- Vector<cairo_glyph_t> cairoGlyphs(numGlyphs);
+ Vector<cairo_glyph_t> glyphs(numGlyphs);
{
ASSERT(from + numGlyphs <= glyphBuffer.size());
- auto* glyphs = glyphBuffer.glyphs(from);
+ auto* glyphsData = glyphBuffer.glyphs(from);
auto* advances = glyphBuffer.advances(from);
auto yOffset = point.y();
for (size_t i = 0; i < numGlyphs; ++i) {
- cairoGlyphs[i] = { glyphs[i], xOffset, yOffset };
+ glyphs[i] = { glyphsData[i], xOffset, yOffset };
xOffset += advances[i].width();
}
}
- PlatformContextCairo* platformContext = context.platformContext();
- drawGlyphsShadow(context, point, font, cairoGlyphs.data(), numGlyphs);
+ cairo_scaled_font_t* scaledFont = font.platformData().scaledFont();
+ double syntheticBoldOffset = font.syntheticBoldOffset();
- cairo_t* cr = platformContext->cr();
- cairo_save(cr);
-
- if (context.textDrawingMode() & TextModeFill) {
- platformContext->prepareForFilling(context.state(), PlatformContextCairo::AdjustPatternForGlobalAlpha);
- drawGlyphsToContext(cr, font, cairoGlyphs.data(), numGlyphs);
- }
-
- // Prevent running into a long computation within cairo. If the stroke width is
- // twice the size of the width of the text we will not ask cairo to stroke
- // the text as even one single stroke would cover the full wdth of the text.
- // See https://bugs.webkit.org/show_bug.cgi?id=33759.
- if (context.textDrawingMode() & TextModeStroke && context.strokeThickness() < 2 * xOffset) {
- platformContext->prepareForStroking(context.state());
- cairo_set_line_width(cr, context.strokeThickness());
-
- // This may disturb the CTM, but we are going to call cairo_restore soon after.
- cairo_set_scaled_font(cr, font.platformData().scaledFont());
- cairo_glyph_path(cr, cairoGlyphs.data(), numGlyphs);
- cairo_stroke(cr);
- }
-
- cairo_restore(cr);
+ ASSERT(context.hasPlatformContext());
+ Cairo::drawGlyphs(*context.platformContext(), context.state(), context.mustUseShadowBlur(), point, scaledFont, syntheticBoldOffset, glyphs, xOffset, context);
}
#if ENABLE(CSS3_TEXT_DECORATION_SKIP_INK)