Title: [148681] trunk
Revision
148681
Author
mrobin...@webkit.org
Date
2013-04-18 09:20:09 -0700 (Thu, 18 Apr 2013)

Log Message

[GTK] fast/canvas/DrawImageSinglePixelStretch.html fails
https://bugs.webkit.org/show_bug.cgi?id=58309

Reviewed by Alejandro G. Castro.

Source/WebCore:

No new tests. This patch unskips a test.

Prevent sampling outside source boundaries, by creating subsurfaces from source surfaces.
This also requires careful handling of negative and floating source rectangles.

* platform/graphics/cairo/PlatformContextCairo.cpp:
(WebCore::PlatformContextCairo::drawSurfaceToContext): Use a subsurface to prevent sampling
outside rectangle boundaries.

LayoutTests:

* platform/gtk/TestExpectations: Unskip a test which is now passing.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (148680 => 148681)


--- trunk/LayoutTests/ChangeLog	2013-04-18 16:14:58 UTC (rev 148680)
+++ trunk/LayoutTests/ChangeLog	2013-04-18 16:20:09 UTC (rev 148681)
@@ -1,3 +1,12 @@
+2013-04-18  Martin Robinson  <mrobin...@igalia.com>
+
+        [GTK] fast/canvas/DrawImageSinglePixelStretch.html fails
+        https://bugs.webkit.org/show_bug.cgi?id=58309
+
+        Reviewed by Alejandro G. Castro.
+
+        * platform/gtk/TestExpectations: Unskip a test which is now passing.
+
 2013-04-18  Eric Carlson  <eric.carl...@apple.com>
 
         Flaky Test: media/track/track-mode.html

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (148680 => 148681)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2013-04-18 16:14:58 UTC (rev 148680)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2013-04-18 16:20:09 UTC (rev 148681)
@@ -1065,8 +1065,6 @@
 # testRunner.overridePreference("WebKitDefaultFontSize"...) does not take into account screen DPI
 webkit.org/b/57160 fast/harness/override-preferences-2.html [ Failure ]
 
-webkit.org/b/58309 fast/canvas/DrawImageSinglePixelStretch.html [ Failure ]
-
 # Expose title direction in WebKit API
 webkit.org/b/58845 fast/dom/title-directionality.html [ Failure ]
 webkit.org/b/58845 fast/dom/title-directionality-removeChild.html [ Failure ]

Modified: trunk/Source/WebCore/ChangeLog (148680 => 148681)


--- trunk/Source/WebCore/ChangeLog	2013-04-18 16:14:58 UTC (rev 148680)
+++ trunk/Source/WebCore/ChangeLog	2013-04-18 16:20:09 UTC (rev 148681)
@@ -1,3 +1,19 @@
+2013-04-18  Martin Robinson  <mrobin...@igalia.com>
+
+        [GTK] fast/canvas/DrawImageSinglePixelStretch.html fails
+        https://bugs.webkit.org/show_bug.cgi?id=58309
+
+        Reviewed by Alejandro G. Castro.
+
+        No new tests. This patch unskips a test.
+
+        Prevent sampling outside source boundaries, by creating subsurfaces from source surfaces.
+        This also requires careful handling of negative and floating source rectangles.
+
+        * platform/graphics/cairo/PlatformContextCairo.cpp:
+        (WebCore::PlatformContextCairo::drawSurfaceToContext): Use a subsurface to prevent sampling
+        outside rectangle boundaries.
+
 2013-04-18  Jonathan Feldstein  <jfeldst...@blackberry.com>
 
         [BlackBerry] Improper initialization of ANGLEResources (resubmission)

Modified: trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp (148680 => 148681)


--- trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp	2013-04-18 16:14:58 UTC (rev 148680)
+++ trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp	2013-04-18 16:20:09 UTC (rev 148681)
@@ -154,13 +154,29 @@
         cairo_fill(cr);
 }
 
-void PlatformContextCairo::drawSurfaceToContext(cairo_surface_t* surface, const FloatRect& destRect, const FloatRect& srcRect, GraphicsContext* context)
+void PlatformContextCairo::drawSurfaceToContext(cairo_surface_t* surface, const FloatRect& destRect, const FloatRect& originalSrcRect, GraphicsContext* context)
 {
-    // If we're drawing a sub portion of the image or scaling then create
-    // a pattern transformation on the image and draw the transformed pattern.
-    // Test using example site at http://www.meyerweb.com/eric/css/edge/complexspiral/demo.html
-    RefPtr<cairo_pattern_t> pattern = adoptRef(cairo_pattern_create_for_surface(surface));
+    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()));
+    }
+
+    // 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
+    RefPtr<cairo_surface_t> subsurface = adoptRef(cairo_surface_create_for_rectangle(
+        surface, expandedSrcRect.x(), expandedSrcRect.y(), expandedSrcRect.width(), expandedSrcRect.height()));
+    RefPtr<cairo_pattern_t> pattern = adoptRef(cairo_pattern_create_for_surface(subsurface.get()));
+
     ASSERT(m_state);
     switch (m_state->m_imageInterpolationQuality) {
     case InterpolationNone:
@@ -177,9 +193,15 @@
     }
     cairo_pattern_set_extend(pattern.get(), CAIRO_EXTEND_PAD);
 
-    float scaleX = srcRect.width() / destRect.width();
-    float scaleY = srcRect.height() / destRect.height();
-    cairo_matrix_t matrix = { scaleX, 0, 0, scaleY, srcRect.x(), srcRect.y() };
+    // 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());
+    float leftPadding = static_cast<float>(expandedSrcRect.x()) - floorf(srcRect.x());
+    float topPadding = static_cast<float>(expandedSrcRect.y()) - floorf(srcRect.y());
+    cairo_matrix_t matrix = { scaleX, 0, 0, scaleY, leftPadding, topPadding };
     cairo_pattern_set_matrix(pattern.get(), &matrix);
 
     ShadowBlur& shadow = context->platformContext()->shadowBlur();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to