Diff
Modified: trunk/Source/WebCore/ChangeLog (227291 => 227292)
--- trunk/Source/WebCore/ChangeLog 2018-01-22 14:22:50 UTC (rev 227291)
+++ trunk/Source/WebCore/ChangeLog 2018-01-22 14:23:07 UTC (rev 227292)
@@ -1,3 +1,35 @@
+2018-01-22 Zan Dobersek <zdober...@igalia.com>
+
+ [Cairo] Refactor PlatformContextCairo::drawSurfaceToContext() into a Cairo operation
+ https://bugs.webkit.org/show_bug.cgi?id=181930
+
+ Reviewed by Carlos Garcia Campos.
+
+ Move the PlatformContextCairo::drawSurfaceToContext() code into the
+ Cairo namespace as an operation, renaming it to drawSurface(). Mirroring
+ other operations, the PlatformContextCairo object is now passed through
+ a reference as the first argument to the function, and cairo_t context
+ object is retrieved from that.
+
+ Call sites of the PlatformContextCairo::drawSurfaceToContext() method
+ are adjusted to now call Cairo::drawSurface() and properly pass the
+ PlatformContextCairo object to the function.
+
+ No new tests -- no change in functionality.
+
+ * platform/graphics/cairo/CairoOperations.cpp:
+ (WebCore::Cairo::prepareForStroking): Make this static.
+ (WebCore::Cairo::drawPatternToCairoContext):
+ (WebCore::Cairo::drawNativeImage):
+ (WebCore::Cairo::drawSurface):
+ * platform/graphics/cairo/CairoOperations.h:
+ * platform/graphics/cairo/PlatformContextCairo.cpp:
+ (WebCore::drawPatternToCairoContext): Deleted.
+ (WebCore::PlatformContextCairo::drawSurfaceToContext): Deleted.
+ * platform/graphics/cairo/PlatformContextCairo.h:
+ * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp:
+ (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::paintCurrentFrame):
+
2018-01-22 Manuel Rego Casasnovas <r...@igalia.com>
[css-grid] Spanning Grid item has too much space at the bottom / is too high
Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp (227291 => 227292)
--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp 2018-01-22 14:22:50 UTC (rev 227291)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp 2018-01-22 14:23:07 UTC (rev 227292)
@@ -132,7 +132,7 @@
}
}
-void prepareForStroking(cairo_t* cr, const Cairo::StrokeSource& strokeSource, AlphaPreservation alphaPreservation)
+static void prepareForStroking(cairo_t* cr, const Cairo::StrokeSource& strokeSource, AlphaPreservation alphaPreservation)
{
bool preserveAlpha = alphaPreservation == PreserveAlpha;
@@ -144,6 +144,19 @@
strokeSource.color, preserveAlpha ? strokeSource.globalAlpha : 1);
}
+static void drawPatternToCairoContext(cairo_t* cr, cairo_pattern_t* pattern, const FloatRect& destRect, float alpha)
+{
+ cairo_translate(cr, destRect.x(), destRect.y());
+ cairo_set_source(cr, pattern);
+ cairo_rectangle(cr, 0, 0, destRect.width(), destRect.height());
+
+ if (alpha < 1) {
+ cairo_clip(cr);
+ cairo_paint_with_alpha(cr, alpha);
+ } else
+ cairo_fill(cr);
+}
+
static inline void fillRectWithColor(cairo_t* cr, const FloatRect& rect, const Color& color)
{
if (!color.isVisible() && cairo_get_operator(cr) == CAIRO_OPERATOR_OVER)
@@ -790,7 +803,7 @@
}
}
- platformContext.drawSurfaceToContext(surface, dst, srcRect, imageInterpolationQuality, globalAlpha, shadowState, targetContext);
+ drawSurface(platformContext, surface, dst, srcRect, imageInterpolationQuality, globalAlpha, shadowState, targetContext);
platformContext.restore();
}
@@ -800,6 +813,80 @@
drawPatternToCairoContext(platformContext.cr(), surface, size, tileRect, patternTransform, phase, toCairoOperator(compositeOperator, blendMode), destRect);
}
+void drawSurface(PlatformContextCairo& platformContext, cairo_surface_t* surface, const FloatRect& destRect, const FloatRect& originalSrcRect, InterpolationQuality imageInterpolationQuality, float globalAlpha, const ShadowState& shadowState, GraphicsContext& context)
+{
+ // Avoid invalid cairo matrix with small values.
+ if (std::fabs(destRect.width()) < 0.5f || std::fabs(destRect.height()) < 0.5f)
+ return;
+
+ FloatRect srcRect = originalSrcRect;
+
+ // We need to account for negative source dimensions by flipping the rectangle.
+ if (originalSrcRect.width() < 0) {
+ srcRect.setX(originalSrcRect.x() + originalSrcRect.width());
+ srcRect.setWidth(std::fabs(originalSrcRect.width()));
+ }
+ if (originalSrcRect.height() < 0) {
+ srcRect.setY(originalSrcRect.y() + originalSrcRect.height());
+ srcRect.setHeight(std::fabs(originalSrcRect.height()));
+ }
+
+ RefPtr<cairo_surface_t> patternSurface = surface;
+ float leftPadding = 0;
+ float topPadding = 0;
+ if (srcRect.x() || srcRect.y() || srcRect.size() != cairoSurfaceSize(surface)) {
+ // Cairo subsurfaces don't support floating point boundaries well, so we expand the rectangle.
+ IntRect expandedSrcRect(enclosingIntRect(srcRect));
+
+ // We use a subsurface here so that we don't end up sampling outside the originalSrcRect rectangle.
+ // See https://bugs.webkit.org/show_bug.cgi?id=58309
+ patternSurface = adoptRef(cairo_surface_create_for_rectangle(surface, expandedSrcRect.x(),
+ expandedSrcRect.y(), expandedSrcRect.width(), expandedSrcRect.height()));
+
+ leftPadding = static_cast<float>(expandedSrcRect.x()) - floorf(srcRect.x());
+ topPadding = static_cast<float>(expandedSrcRect.y()) - floorf(srcRect.y());
+ }
+
+ RefPtr<cairo_pattern_t> pattern = adoptRef(cairo_pattern_create_for_surface(patternSurface.get()));
+
+ switch (imageInterpolationQuality) {
+ case InterpolationNone:
+ case InterpolationLow:
+ cairo_pattern_set_filter(pattern.get(), CAIRO_FILTER_FAST);
+ break;
+ case InterpolationMedium:
+ case InterpolationDefault:
+ cairo_pattern_set_filter(pattern.get(), CAIRO_FILTER_GOOD);
+ break;
+ case InterpolationHigh:
+ cairo_pattern_set_filter(pattern.get(), CAIRO_FILTER_BEST);
+ break;
+ }
+ cairo_pattern_set_extend(pattern.get(), CAIRO_EXTEND_PAD);
+
+ // The pattern transformation properly scales the pattern for when the source rectangle is a
+ // different size than the destination rectangle. We also account for any offset we introduced
+ // by expanding floating point source rectangle sizes. It's important to take the absolute value
+ // of the scale since the original width and height might be negative.
+ float scaleX = std::fabs(srcRect.width() / destRect.width());
+ float scaleY = std::fabs(srcRect.height() / destRect.height());
+ cairo_matrix_t matrix = { scaleX, 0, 0, scaleY, leftPadding, topPadding };
+ cairo_pattern_set_matrix(pattern.get(), &matrix);
+
+ ShadowBlur shadow({ shadowState.blur, shadowState.blur }, shadowState.offset, shadowState.color, shadowState.ignoreTransforms);
+ if (shadow.type() != ShadowBlur::NoShadow) {
+ if (GraphicsContext* shadowContext = shadow.beginShadowLayer(context, destRect)) {
+ drawPatternToCairoContext(shadowContext->platformContext()->cr(), pattern.get(), destRect, 1);
+ shadow.endShadowLayer(context);
+ }
+ }
+
+ auto* cr = platformContext.cr();
+ cairo_save(cr);
+ drawPatternToCairoContext(cr, pattern.get(), destRect, globalAlpha);
+ cairo_restore(cr);
+}
+
void drawRect(PlatformContextCairo& platformContext, const FloatRect& rect, float borderThickness, const Color& fillColor, StrokeStyle strokeStyle, const Color& strokeColor)
{
// FIXME: how should borderThickness be used?
Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h (227291 => 227292)
--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h 2018-01-22 14:22:50 UTC (rev 227291)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h 2018-01-22 14:23:07 UTC (rev 227292)
@@ -137,6 +137,7 @@
void drawNativeImage(PlatformContextCairo&, cairo_surface_t*, const FloatRect&, const FloatRect&, CompositeOperator, BlendMode, ImageOrientation, InterpolationQuality, float, const ShadowState&, GraphicsContext&);
void drawPattern(PlatformContextCairo&, cairo_surface_t*, const IntSize&, const FloatRect&, const FloatRect&, const AffineTransform&, const FloatPoint&, CompositeOperator, BlendMode);
+void drawSurface(PlatformContextCairo&, cairo_surface_t*, const FloatRect&, const FloatRect&, InterpolationQuality, float, const ShadowState&, GraphicsContext&);
void drawRect(PlatformContextCairo&, const FloatRect&, float, const Color&, StrokeStyle, const Color&);
void drawLine(PlatformContextCairo&, const FloatPoint&, const FloatPoint&, StrokeStyle, const Color&, float, bool);
Modified: trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp (227291 => 227292)
--- trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp 2018-01-22 14:22:50 UTC (rev 227291)
+++ trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp 2018-01-22 14:23:07 UTC (rev 227292)
@@ -130,93 +130,6 @@
cairo_translate(m_cr.get(), -rect.x(), -rect.y());
}
-static void drawPatternToCairoContext(cairo_t* cr, cairo_pattern_t* pattern, const FloatRect& destRect, float alpha)
-{
- cairo_translate(cr, destRect.x(), destRect.y());
- cairo_set_source(cr, pattern);
- cairo_rectangle(cr, 0, 0, destRect.width(), destRect.height());
-
- if (alpha < 1) {
- cairo_clip(cr);
- cairo_paint_with_alpha(cr, alpha);
- } else
- cairo_fill(cr);
-}
-
-void PlatformContextCairo::drawSurfaceToContext(cairo_surface_t* surface, const FloatRect& destRect, const FloatRect& originalSrcRect, InterpolationQuality imageInterpolationQuality, float globalAlpha, const Cairo::ShadowState& shadowState, GraphicsContext& context)
-{
- // Avoid invalid cairo matrix with small values.
- if (std::fabs(destRect.width()) < 0.5f || std::fabs(destRect.height()) < 0.5f)
- return;
-
- FloatRect srcRect = originalSrcRect;
-
- // We need to account for negative source dimensions by flipping the rectangle.
- if (originalSrcRect.width() < 0) {
- srcRect.setX(originalSrcRect.x() + originalSrcRect.width());
- srcRect.setWidth(std::fabs(originalSrcRect.width()));
- }
- if (originalSrcRect.height() < 0) {
- srcRect.setY(originalSrcRect.y() + originalSrcRect.height());
- srcRect.setHeight(std::fabs(originalSrcRect.height()));
- }
-
- RefPtr<cairo_surface_t> patternSurface = surface;
- float leftPadding = 0;
- float topPadding = 0;
- if (srcRect.x() || srcRect.y() || srcRect.size() != cairoSurfaceSize(surface)) {
- // Cairo subsurfaces don't support floating point boundaries well, so we expand the rectangle.
- IntRect expandedSrcRect(enclosingIntRect(srcRect));
-
- // We use a subsurface here so that we don't end up sampling outside the originalSrcRect rectangle.
- // See https://bugs.webkit.org/show_bug.cgi?id=58309
- patternSurface = adoptRef(cairo_surface_create_for_rectangle(surface, expandedSrcRect.x(),
- expandedSrcRect.y(), expandedSrcRect.width(), expandedSrcRect.height()));
-
- leftPadding = static_cast<float>(expandedSrcRect.x()) - floorf(srcRect.x());
- topPadding = static_cast<float>(expandedSrcRect.y()) - floorf(srcRect.y());
- }
-
- RefPtr<cairo_pattern_t> pattern = adoptRef(cairo_pattern_create_for_surface(patternSurface.get()));
-
- ASSERT(m_state);
- switch (imageInterpolationQuality) {
- case InterpolationNone:
- case InterpolationLow:
- cairo_pattern_set_filter(pattern.get(), CAIRO_FILTER_FAST);
- break;
- case InterpolationMedium:
- case InterpolationDefault:
- cairo_pattern_set_filter(pattern.get(), CAIRO_FILTER_GOOD);
- break;
- case InterpolationHigh:
- cairo_pattern_set_filter(pattern.get(), CAIRO_FILTER_BEST);
- break;
- }
- cairo_pattern_set_extend(pattern.get(), CAIRO_EXTEND_PAD);
-
- // The pattern transformation properly scales the pattern for when the source rectangle is a
- // different size than the destination rectangle. We also account for any offset we introduced
- // by expanding floating point source rectangle sizes. It's important to take the absolute value
- // of the scale since the original width and height might be negative.
- float scaleX = std::fabs(srcRect.width() / destRect.width());
- float scaleY = std::fabs(srcRect.height() / destRect.height());
- cairo_matrix_t matrix = { scaleX, 0, 0, scaleY, leftPadding, topPadding };
- cairo_pattern_set_matrix(pattern.get(), &matrix);
-
- ShadowBlur shadow({ shadowState.blur, shadowState.blur }, shadowState.offset, shadowState.color, shadowState.ignoreTransforms);
- if (shadow.type() != ShadowBlur::NoShadow) {
- if (GraphicsContext* shadowContext = shadow.beginShadowLayer(context, destRect)) {
- drawPatternToCairoContext(shadowContext->platformContext()->cr(), pattern.get(), destRect, 1);
- shadow.endShadowLayer(context);
- }
- }
-
- cairo_save(m_cr.get());
- drawPatternToCairoContext(m_cr.get(), pattern.get(), destRect, globalAlpha);
- cairo_restore(m_cr.get());
-}
-
} // namespace WebCore
#endif // USE(CAIRO)
Modified: trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h (227291 => 227292)
--- trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h 2018-01-22 14:22:50 UTC (rev 227291)
+++ trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h 2018-01-22 14:23:07 UTC (rev 227292)
@@ -66,7 +66,6 @@
void restore();
void pushImageMask(cairo_surface_t*, const FloatRect&);
- WEBCORE_EXPORT void drawSurfaceToContext(cairo_surface_t*, const FloatRect& destRect, const FloatRect& srcRect, InterpolationQuality, float globalAlpha, const Cairo::ShadowState&, GraphicsContext&);
private:
RefPtr<cairo_t> m_cr;
Modified: trunk/Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp (227291 => 227292)
--- trunk/Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp 2018-01-22 14:22:50 UTC (rev 227291)
+++ trunk/Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp 2018-01-22 14:23:07 UTC (rev 227292)
@@ -2973,9 +2973,9 @@
FloatRect srcRect(0, 0, width, height);
if (image) {
- WebCore::PlatformContextCairo* ctxt = context.platformContext();
+ ASSERT(context.hasPlatformContext());
auto& state = context.state();
- ctxt->drawSurfaceToContext(image, destRect, srcRect, state.imageInterpolationQuality, state.alpha, Cairo::ShadowState(state), context);
+ Cairo::drawSurface(*context.platformContext(), image, destRect, srcRect, state.imageInterpolationQuality, state.alpha, Cairo::ShadowState(state), context);
cairo_surface_destroy(image);
}
#else
Modified: trunk/Source/WebKit/ChangeLog (227291 => 227292)
--- trunk/Source/WebKit/ChangeLog 2018-01-22 14:22:50 UTC (rev 227291)
+++ trunk/Source/WebKit/ChangeLog 2018-01-22 14:23:07 UTC (rev 227292)
@@ -1,3 +1,19 @@
+2018-01-22 Zan Dobersek <zdober...@igalia.com>
+
+ [Cairo] Refactor PlatformContextCairo::drawSurfaceToContext() into a Cairo operation
+ https://bugs.webkit.org/show_bug.cgi?id=181930
+
+ Reviewed by Carlos Garcia Campos.
+
+ Call sites of the PlatformContextCairo::drawSurfaceToContext() method
+ are adjusted to now call Cairo::drawSurface() and properly pass the
+ PlatformContextCairo object to the function.
+
+ * Shared/cairo/ShareableBitmapCairo.cpp:
+ (WebKit::ShareableBitmap::paint):
+ * WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp:
+ (WebKit::convertCairoSurfaceToShareableBitmap):
+
2018-01-21 Carlos Garcia Campos <cgar...@igalia.com>
Unreviewed. Fix compile warning.
Modified: trunk/Source/WebKit/Shared/cairo/ShareableBitmapCairo.cpp (227291 => 227292)
--- trunk/Source/WebKit/Shared/cairo/ShareableBitmapCairo.cpp 2018-01-22 14:22:50 UTC (rev 227291)
+++ trunk/Source/WebKit/Shared/cairo/ShareableBitmapCairo.cpp 2018-01-22 14:23:07 UTC (rev 227292)
@@ -75,8 +75,10 @@
FloatRect destRect(dstPoint, srcRect.size());
FloatRect srcRectScaled(srcRect);
srcRectScaled.scale(scaleFactor);
+
+ ASSERT(context.hasPlatformContext());
auto& state = context.state();
- context.platformContext()->drawSurfaceToContext(surface.get(), destRect, srcRectScaled, state.imageInterpolationQuality, state.alpha, Cairo::ShadowState(state), context);
+ Cairo::drawSurface(*context.platformContext(), surface.get(), destRect, srcRectScaled, state.imageInterpolationQuality, state.alpha, Cairo::ShadowState(state), context);
}
RefPtr<cairo_surface_t> ShareableBitmap::createCairoSurface()
Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp (227291 => 227292)
--- trunk/Source/WebKit/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp 2018-01-22 14:22:50 UTC (rev 227291)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp 2018-01-22 14:23:07 UTC (rev 227292)
@@ -54,8 +54,9 @@
RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(imageSize, { });
auto graphicsContext = bitmap->createGraphicsContext();
+ ASSERT(context.hasPlatformContext());
auto& state = graphicsContext->state();
- graphicsContext->platformContext()->drawSurfaceToContext(surface, IntRect(IntPoint(), imageSize), IntRect(IntPoint(), imageSize), state.imageInterpolationQuality, state.alpha, Cairo::ShadowState(state), *graphicsContext);
+ Cairo::drawSurface(*graphicsContext->platformContext(), surface, IntRect(IntPoint(), imageSize), IntRect(IntPoint(), imageSize), state.imageInterpolationQuality, state.alpha, Cairo::ShadowState(state), *graphicsContext);
return bitmap;
}