Title: [204517] trunk
- Revision
- 204517
- Author
- [email protected]
- Date
- 2016-08-16 12:08:58 -0700 (Tue, 16 Aug 2016)
Log Message
ctx.drawImage should clip source rect if it is outside the source image
https://bugs.webkit.org/show_bug.cgi?id=160804
Reviewed by Simon Fraser.
Source/WebCore:
According to the specification [1]"
"When the source rectangle is outside the source image, the source rectangle
must be clipped to the source image and the destination rectangle must be
clipped in the same proportion."
Firefox and Chrome behave according to the specification. This patch aligns
our behavior.
[1] https://html.spec.whatwg.org/multipage/scripting.html#dom-context-2d-drawimage
Test: fast/canvas/drawImage-srcRect-clipping.html
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawImage):
LayoutTests:
Add layout test coverage.
* fast/canvas/drawImage-srcRect-clipping-expected.html: Added.
* fast/canvas/drawImage-srcRect-clipping.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (204516 => 204517)
--- trunk/LayoutTests/ChangeLog 2016-08-16 19:04:06 UTC (rev 204516)
+++ trunk/LayoutTests/ChangeLog 2016-08-16 19:08:58 UTC (rev 204517)
@@ -1,3 +1,15 @@
+2016-08-16 Chris Dumez <[email protected]>
+
+ ctx.drawImage should clip source rect if it is outside the source image
+ https://bugs.webkit.org/show_bug.cgi?id=160804
+
+ Reviewed by Simon Fraser.
+
+ Add layout test coverage.
+
+ * fast/canvas/drawImage-srcRect-clipping-expected.html: Added.
+ * fast/canvas/drawImage-srcRect-clipping.html: Added.
+
2016-08-16 George Ruan <[email protected]>
⛱ : Implement parsing of Media Constraints for getUserMedia algorithm in Media Capture and Streaming Spec
Added: trunk/LayoutTests/fast/canvas/drawImage-srcRect-clipping-expected.html (0 => 204517)
--- trunk/LayoutTests/fast/canvas/drawImage-srcRect-clipping-expected.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/drawImage-srcRect-clipping-expected.html 2016-08-16 19:08:58 UTC (rev 204517)
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>Tests that the source rect is clipped when outside the image rect.</p>
+<canvas id='target' width='100px' height='100px;'></canvas>
+<script>
+if (window.testRunner)
+ testRunner.waitUntilDone();
+
+var image = new Image();
+
+image._onload_ = function () {
+ target.getContext('2d').drawImage(image, 50, 50, 50, 50, 0, 0, 50, 50);
+ if (window.testRunner)
+ testRunner.notifyDone();
+};
+
+image.src = '';
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/fast/canvas/drawImage-srcRect-clipping.html (0 => 204517)
--- trunk/LayoutTests/fast/canvas/drawImage-srcRect-clipping.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/drawImage-srcRect-clipping.html 2016-08-16 19:08:58 UTC (rev 204517)
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>Tests that the source rect is clipped when outside the image rect.</p>
+<canvas id='target' width='100px' height='100px'></canvas>
+<script>
+if (window.testRunner)
+ testRunner.waitUntilDone();
+
+var image = new Image();
+
+image._onload_ = function () {
+ target.getContext('2d').drawImage(image, 50, 50, 100, 100, 0, 0, 100, 100);
+ if (window.testRunner)
+ testRunner.notifyDone();
+};
+
+image.src = '';
+</script>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (204516 => 204517)
--- trunk/Source/WebCore/ChangeLog 2016-08-16 19:04:06 UTC (rev 204516)
+++ trunk/Source/WebCore/ChangeLog 2016-08-16 19:08:58 UTC (rev 204517)
@@ -1,3 +1,25 @@
+2016-08-16 Chris Dumez <[email protected]>
+
+ ctx.drawImage should clip source rect if it is outside the source image
+ https://bugs.webkit.org/show_bug.cgi?id=160804
+
+ Reviewed by Simon Fraser.
+
+ According to the specification [1]"
+ "When the source rectangle is outside the source image, the source rectangle
+ must be clipped to the source image and the destination rectangle must be
+ clipped in the same proportion."
+
+ Firefox and Chrome behave according to the specification. This patch aligns
+ our behavior.
+
+ [1] https://html.spec.whatwg.org/multipage/scripting.html#dom-context-2d-drawimage
+
+ Test: fast/canvas/drawImage-srcRect-clipping.html
+
+ * html/canvas/CanvasRenderingContext2D.cpp:
+ (WebCore::CanvasRenderingContext2D::drawImage):
+
2016-08-16 George Ruan <[email protected]>
⛱ : Implement parsing of Media Constraints for getUserMedia algorithm in Media Capture and Streaming Spec
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (204516 => 204517)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2016-08-16 19:04:06 UTC (rev 204516)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2016-08-16 19:08:58 UTC (rev 204517)
@@ -1390,9 +1390,21 @@
ec = INDEX_SIZE_ERR;
return;
}
- if (!imageRect.contains(normalizedSrcRect))
+
+ // When the source rectangle is outside the source image, the source rectangle must be clipped
+ // to the source image and the destination rectangle must be clipped in the same proportion.
+ FloatRect originalNormalizedSrcRect = normalizedSrcRect;
+ normalizedSrcRect.intersect(imageRect);
+ if (normalizedSrcRect.isEmpty())
return;
+ if (normalizedSrcRect != originalNormalizedSrcRect) {
+ normalizedDstRect.setWidth(normalizedDstRect.width() * normalizedSrcRect.width() / originalNormalizedSrcRect.width());
+ normalizedDstRect.setHeight(normalizedDstRect.height() * normalizedSrcRect.height() / originalNormalizedSrcRect.height());
+ if (normalizedDstRect.isEmpty())
+ return;
+ }
+
GraphicsContext* c = drawingContext();
if (!c)
return;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes