summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjcgregorio@google.com <jcgregorio@google.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538>2014-02-24 22:12:36 +0000
committerjcgregorio@google.com <jcgregorio@google.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538>2014-02-24 22:12:36 +0000
commitae658d99dda0ea37f60d1fa33814b08aedd0716b (patch)
tree57a4d066be5e81d06fbcbe28dc089fb778957707
parentc6f6a302ede5467a8c5e1f02d8763309c152223a (diff)
downloadchromium_src-ae658d99dda0ea37f60d1fa33814b08aedd0716b.zip
chromium_src-ae658d99dda0ea37f60d1fa33814b08aedd0716b.tar.gz
chromium_src-ae658d99dda0ea37f60d1fa33814b08aedd0716b.tar.bz2
Add versions of stroke, fill, and clip to CanvasRenderingContext2D that take a Path parameter.
The spec reference is: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-fill This partially addresses bug 330506. The rest of these functions need to be added to completely close that bug, which I plan to do in a following CL: - drawSystemFocusRing(path, element); - drawCustomFocusRing(path, element); - isPointInPath(path, x, y); - isPointInStroke(path, x, y); - scrollPathIntoView(path); BUG=330506 Review URL: https://codereview.chromium.org/137353004 git-svn-id: svn://svn.chromium.org/blink/trunk@167705 bbb929c8-8fbe-4397-9dbb-9b2b20218538
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip-expected.txt47
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip.html9
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-fill-expected.txt47
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-fill.html9
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-stroke-expected.txt22
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-stroke.html9
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-clip.js72
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-fill.js70
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-stroke.js53
-rw-r--r--third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-path-context-clip-expected.txt47
-rw-r--r--third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-path-context-fill-expected.txt47
-rw-r--r--third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-path-context-stroke-expected.txt22
-rw-r--r--third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp131
-rw-r--r--third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.h7
-rw-r--r--third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.idl13
15 files changed, 559 insertions, 46 deletions
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip-expected.txt b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip-expected.txt
new file mode 100644
index 0000000..48864a4
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip-expected.txt
@@ -0,0 +1,47 @@
+Series of tests to ensure clip() works with path and winding rule parameters.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Testing clip()
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing clip(path)
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing clip("nonzero")
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing clip(path, "nonzero")
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing clip("evenodd")
+PASS pixelDataAtPoint()[0] is within 5 of 255
+PASS pixelDataAtPoint()[1] is within 5 of 0
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing clip(path, "evenodd")
+PASS pixelDataAtPoint()[0] is within 5 of 255
+PASS pixelDataAtPoint()[1] is within 5 of 0
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+PASS ctx.clip(null) threw exception TypeError: Failed to execute 'clip' on 'CanvasRenderingContext2D': parameter 1 ('null') is not a valid enum value..
+PASS ctx.clip(null, null) threw exception TypeError: Failed to execute 'clip' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip.html
new file mode 100644
index 0000000..9ff47f9
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+</head>
+<body>
+<canvas id="canvas" width="200" height="200"></canvas>
+<script src="script-tests/canvas-path-context-clip.js"></script>
+</body>
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-fill-expected.txt b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-fill-expected.txt
new file mode 100644
index 0000000..f89551e
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-fill-expected.txt
@@ -0,0 +1,47 @@
+Series of tests to ensure fill() works with path and winding rule parameters.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Testing fill()
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing fill(path)
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing fill("nonzero")
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing fill(path, "nonzero")
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing fill("evenodd")
+PASS pixelDataAtPoint()[0] is within 5 of 255
+PASS pixelDataAtPoint()[1] is within 5 of 0
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing fill(path, "evenodd")
+PASS pixelDataAtPoint()[0] is within 5 of 255
+PASS pixelDataAtPoint()[1] is within 5 of 0
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+PASS ctx.fill(null) threw exception TypeError: Failed to execute 'fill' on 'CanvasRenderingContext2D': parameter 1 ('null') is not a valid enum value..
+PASS ctx.fill(null, null) threw exception TypeError: Failed to execute 'fill' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-fill.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-fill.html
new file mode 100644
index 0000000..073f1ac
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-fill.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+</head>
+<body>
+<canvas id="canvas" width="200" height="200"></canvas>
+<script src="script-tests/canvas-path-context-fill.js"></script>
+</body>
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-stroke-expected.txt b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-stroke-expected.txt
new file mode 100644
index 0000000..cd71511
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-stroke-expected.txt
@@ -0,0 +1,22 @@
+Series of tests to ensure stroke() works with optional path parameter.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Testing stroke()
+
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+Testing stroke(path)
+
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+PASS ctx.stroke(null) threw exception TypeError: Failed to execute 'stroke' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-stroke.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-stroke.html
new file mode 100644
index 0000000..5f84cb2
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-stroke.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+</head>
+<body>
+<canvas id="canvas" width="200" height="200"></canvas>
+<script src="script-tests/canvas-path-context-stroke.js"></script>
+</body>
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-clip.js b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-clip.js
new file mode 100644
index 0000000..78e0257
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-clip.js
@@ -0,0 +1,72 @@
+description("Series of tests to ensure clip() works with path and winding rule parameters.");
+
+var ctx = document.getElementById('canvas').getContext('2d');
+
+function pixelDataAtPoint() {
+ return ctx.getImageData(50, 50, 1, 1).data;
+}
+
+function checkResult(expectedColors, sigma) {
+ for (var i = 0; i < 4; i++)
+ shouldBeCloseTo("pixelDataAtPoint()[" + i + "]", expectedColors[i], sigma);
+}
+
+function drawRectanglesOn(contextOrPath) {
+ contextOrPath.rect(0, 0, 100, 100);
+ contextOrPath.rect(25, 25, 50, 50);
+}
+
+function formatName(fillRule, path) {
+ return 'clip(' + (path ? 'path' : '') + (fillRule && path ? ', ' : '') +
+ (fillRule ? '"' + fillRule + '"' : '') + ')';
+}
+
+function testClipWith(fillRule, path) {
+ debug('Testing ' + formatName(fillRule, path));
+ ctx.fillStyle = 'rgb(255,0,0)';
+ ctx.beginPath();
+ ctx.fillRect(0, 0, 100, 100);
+ ctx.fillStyle = 'rgb(0,255,0)';
+ if (path) {
+ if (fillRule) {
+ ctx.clip(path, fillRule);
+ } else {
+ ctx.clip(path);
+ }
+ } else {
+ ctx.beginPath();
+ drawRectanglesOn(ctx);
+ if (fillRule) {
+ ctx.clip(fillRule);
+ } else {
+ ctx.clip();
+ }
+ }
+ ctx.beginPath();
+ ctx.fillRect(0, 0, 100, 100);
+ if (fillRule == 'evenodd') {
+ checkResult([255, 0, 0, 255], 5);
+ } else {
+ checkResult([0, 255, 0, 255], 5);
+ }
+ debug('');
+}
+
+// Execute test.
+function prepareTestScenario() {
+ fillRules = [undefined, 'nonzero', 'evenodd'];
+ var path = new Path();
+ drawRectanglesOn(path);
+
+ for (var i = 0; i < fillRules.length; i++) {
+ testClipWith(fillRules[i]);
+ testClipWith(fillRules[i], path);
+ }
+
+ // Test exception cases.
+ shouldThrow("ctx.clip(null)");
+ shouldThrow("ctx.clip(null, null)");
+}
+
+// Run test and allow variation of results.
+prepareTestScenario();
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-fill.js b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-fill.js
new file mode 100644
index 0000000..c394d6b
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-fill.js
@@ -0,0 +1,70 @@
+description("Series of tests to ensure fill() works with path and winding rule parameters.");
+
+var ctx = document.getElementById('canvas').getContext('2d');
+
+function pixelDataAtPoint() {
+ return ctx.getImageData(50, 50, 1, 1).data;
+}
+
+function checkResult(expectedColors, sigma) {
+ for (var i = 0; i < 4; i++)
+ shouldBeCloseTo("pixelDataAtPoint()[" + i + "]", expectedColors[i], sigma);
+}
+
+function drawRectanglesOn(contextOrPath) {
+ contextOrPath.rect(0, 0, 100, 100);
+ contextOrPath.rect(25, 25, 50, 50);
+}
+
+function formatName(fillRule, path) {
+ return 'fill(' + (path ? 'path' : '') + (fillRule && path ? ', ' : '') +
+ (fillRule ? '"' + fillRule + '"' : '') + ')';
+}
+
+function testFillWith(fillRule, path) {
+ debug('Testing ' + formatName(fillRule, path));
+ ctx.fillStyle = 'rgb(255,0,0)';
+ ctx.beginPath();
+ ctx.fillRect(0, 0, 100, 100);
+ ctx.fillStyle = 'rgb(0,255,0)';
+ if (path) {
+ if (fillRule) {
+ ctx.fill(path, fillRule);
+ } else {
+ ctx.fill(path);
+ }
+ } else {
+ ctx.beginPath();
+ drawRectanglesOn(ctx);
+ if (fillRule) {
+ ctx.fill(fillRule);
+ } else {
+ ctx.fill();
+ }
+ }
+ if (fillRule == 'evenodd') {
+ checkResult([255, 0, 0, 255], 5);
+ } else {
+ checkResult([0, 255, 0, 255], 5);
+ }
+ debug('');
+}
+
+// Execute test.
+function prepareTestScenario() {
+ fillRules = [undefined, 'nonzero', 'evenodd'];
+ var path = new Path();
+ drawRectanglesOn(path);
+
+ for (var i = 0; i < fillRules.length; i++) {
+ testFillWith(fillRules[i]);
+ testFillWith(fillRules[i], path);
+ }
+
+ // Test exception cases.
+ shouldThrow("ctx.fill(null)");
+ shouldThrow("ctx.fill(null, null)");
+}
+
+// Run test and allow variation of results.
+prepareTestScenario();
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-stroke.js b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-stroke.js
new file mode 100644
index 0000000..d3f711f
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-stroke.js
@@ -0,0 +1,53 @@
+description("Series of tests to ensure stroke() works with optional path parameter.");
+
+var ctx = document.getElementById('canvas').getContext('2d');
+
+function pixelDataAtPoint() {
+ return ctx.getImageData(75, 75, 1, 1).data;
+}
+
+function checkResult(expectedColors, sigma) {
+ for (var i = 0; i < 4; i++)
+ shouldBeCloseTo("pixelDataAtPoint()[" + i + "]", expectedColors[i], sigma);
+}
+
+function drawRectangleOn(contextOrPath) {
+ contextOrPath.rect(25, 25, 50, 50);
+}
+
+function formatName(path) {
+ return 'stroke(' + (path ? 'path' : '') + ')';
+}
+
+function testStrokeWith(path) {
+ debug('Testing ' + formatName(path));
+ ctx.fillStyle = 'rgb(255,0,0)';
+ ctx.beginPath();
+ ctx.fillRect(0, 0, 100, 100);
+ ctx.strokeStyle = 'rgb(0,255,0)';
+ ctx.lineWidth = 5;
+ if (path) {
+ ctx.stroke(path);
+ } else {
+ ctx.beginPath();
+ drawRectangleOn(ctx);
+ ctx.stroke();
+ }
+ debug('');
+ checkResult([0, 255, 0, 255], 5);
+}
+
+// Execute test.
+function prepareTestScenario() {
+ var path = new Path();
+ drawRectangleOn(path);
+
+ testStrokeWith();
+ testStrokeWith(path);
+
+ // Test exception cases.
+ shouldThrow("ctx.stroke(null)");
+}
+
+// Run test and allow variation of results.
+prepareTestScenario();
diff --git a/third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-path-context-clip-expected.txt b/third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-path-context-clip-expected.txt
new file mode 100644
index 0000000..48864a4
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-path-context-clip-expected.txt
@@ -0,0 +1,47 @@
+Series of tests to ensure clip() works with path and winding rule parameters.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Testing clip()
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing clip(path)
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing clip("nonzero")
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing clip(path, "nonzero")
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing clip("evenodd")
+PASS pixelDataAtPoint()[0] is within 5 of 255
+PASS pixelDataAtPoint()[1] is within 5 of 0
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing clip(path, "evenodd")
+PASS pixelDataAtPoint()[0] is within 5 of 255
+PASS pixelDataAtPoint()[1] is within 5 of 0
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+PASS ctx.clip(null) threw exception TypeError: Failed to execute 'clip' on 'CanvasRenderingContext2D': parameter 1 ('null') is not a valid enum value..
+PASS ctx.clip(null, null) threw exception TypeError: Failed to execute 'clip' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-path-context-fill-expected.txt b/third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-path-context-fill-expected.txt
new file mode 100644
index 0000000..f89551e
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-path-context-fill-expected.txt
@@ -0,0 +1,47 @@
+Series of tests to ensure fill() works with path and winding rule parameters.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Testing fill()
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing fill(path)
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing fill("nonzero")
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing fill(path, "nonzero")
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing fill("evenodd")
+PASS pixelDataAtPoint()[0] is within 5 of 255
+PASS pixelDataAtPoint()[1] is within 5 of 0
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+Testing fill(path, "evenodd")
+PASS pixelDataAtPoint()[0] is within 5 of 255
+PASS pixelDataAtPoint()[1] is within 5 of 0
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+
+PASS ctx.fill(null) threw exception TypeError: Failed to execute 'fill' on 'CanvasRenderingContext2D': parameter 1 ('null') is not a valid enum value..
+PASS ctx.fill(null, null) threw exception TypeError: Failed to execute 'fill' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-path-context-stroke-expected.txt b/third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-path-context-stroke-expected.txt
new file mode 100644
index 0000000..cd71511
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-path-context-stroke-expected.txt
@@ -0,0 +1,22 @@
+Series of tests to ensure stroke() works with optional path parameter.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Testing stroke()
+
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+Testing stroke(path)
+
+PASS pixelDataAtPoint()[0] is within 5 of 0
+PASS pixelDataAtPoint()[1] is within 5 of 255
+PASS pixelDataAtPoint()[2] is within 5 of 0
+PASS pixelDataAtPoint()[3] is within 5 of 255
+PASS ctx.stroke(null) threw exception TypeError: Failed to execute 'stroke' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp
index cd52b29..0c7b113 100644
--- a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp
+++ b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp
@@ -872,86 +872,129 @@ static bool parseWinding(const String& windingRuleString, WindRule& windRule)
return true;
}
-void CanvasRenderingContext2D::fill(const String& windingRuleString)
+void CanvasRenderingContext2D::fillInternal(const Path& path, const String& windingRuleString)
{
+ if (path.isEmpty()) {
+ return;
+ }
GraphicsContext* c = drawingContext();
- if (!c)
+ if (!c) {
return;
- if (!state().m_invertibleCTM)
+ }
+ if (!state().m_invertibleCTM) {
return;
+ }
FloatRect clipBounds;
- if (!drawingContext()->getTransformedClipBounds(&clipBounds))
+ if (!drawingContext()->getTransformedClipBounds(&clipBounds)) {
return;
+ }
// If gradient size is zero, then paint nothing.
Gradient* gradient = c->fillGradient();
- if (gradient && gradient->isZeroSize())
+ if (gradient && gradient->isZeroSize()) {
return;
+ }
- if (!m_path.isEmpty()) {
- WindRule windRule = c->fillRule();
- WindRule newWindRule = RULE_NONZERO;
- if (!parseWinding(windingRuleString, newWindRule))
- return;
- c->setFillRule(newWindRule);
-
- if (isFullCanvasCompositeMode(state().m_globalComposite)) {
- fullCanvasCompositedFill(m_path);
- didDraw(clipBounds);
- } else if (state().m_globalComposite == CompositeCopy) {
- clearCanvas();
- c->fillPath(m_path);
- didDraw(clipBounds);
- } else {
- FloatRect dirtyRect;
- if (computeDirtyRect(m_path.boundingRect(), clipBounds, &dirtyRect)) {
- c->fillPath(m_path);
- didDraw(dirtyRect);
- }
- }
+ WindRule windRule = c->fillRule();
+ WindRule newWindRule = RULE_NONZERO;
+ if (!parseWinding(windingRuleString, newWindRule)) {
+ return;
+ }
+ c->setFillRule(newWindRule);
- c->setFillRule(windRule);
+ if (isFullCanvasCompositeMode(state().m_globalComposite)) {
+ fullCanvasCompositedFill(path);
+ didDraw(clipBounds);
+ } else if (state().m_globalComposite == CompositeCopy) {
+ clearCanvas();
+ c->fillPath(path);
+ didDraw(clipBounds);
+ } else {
+ FloatRect dirtyRect;
+ if (computeDirtyRect(path.boundingRect(), clipBounds, &dirtyRect)) {
+ c->fillPath(path);
+ didDraw(dirtyRect);
+ }
}
+
+ c->setFillRule(windRule);
}
-void CanvasRenderingContext2D::stroke()
+void CanvasRenderingContext2D::fill(const String& windingRuleString)
+{
+ fillInternal(m_path, windingRuleString);
+}
+
+void CanvasRenderingContext2D::fill(DOMPath* domPath, const String& windingRuleString)
+{
+ fillInternal(domPath->path(), windingRuleString);
+}
+
+void CanvasRenderingContext2D::strokeInternal(const Path& path)
{
+ if (path.isEmpty()) {
+ return;
+ }
GraphicsContext* c = drawingContext();
- if (!c)
+ if (!c) {
return;
- if (!state().m_invertibleCTM)
+ }
+ if (!state().m_invertibleCTM) {
return;
+ }
// If gradient size is zero, then paint nothing.
Gradient* gradient = c->strokeGradient();
- if (gradient && gradient->isZeroSize())
+ if (gradient && gradient->isZeroSize()) {
return;
+ }
- if (!m_path.isEmpty()) {
- FloatRect bounds = m_path.boundingRect();
- inflateStrokeRect(bounds);
- FloatRect dirtyRect;
- if (computeDirtyRect(bounds, &dirtyRect)) {
- c->strokePath(m_path);
- didDraw(dirtyRect);
- }
+ FloatRect bounds = path.boundingRect();
+ inflateStrokeRect(bounds);
+ FloatRect dirtyRect;
+ if (computeDirtyRect(bounds, &dirtyRect)) {
+ c->strokePath(path);
+ didDraw(dirtyRect);
}
}
-void CanvasRenderingContext2D::clip(const String& windingRuleString)
+void CanvasRenderingContext2D::stroke()
+{
+ strokeInternal(m_path);
+}
+
+void CanvasRenderingContext2D::stroke(DOMPath* domPath)
+{
+ strokeInternal(domPath->path());
+}
+
+void CanvasRenderingContext2D::clipInternal(const Path& path, const String& windingRuleString)
{
GraphicsContext* c = drawingContext();
- if (!c)
+ if (!c) {
return;
- if (!state().m_invertibleCTM)
+ }
+ if (!state().m_invertibleCTM) {
return;
+ }
WindRule newWindRule = RULE_NONZERO;
- if (!parseWinding(windingRuleString, newWindRule))
+ if (!parseWinding(windingRuleString, newWindRule)) {
return;
+ }
realizeSaves();
- c->canvasClip(m_path, newWindRule);
+ c->canvasClip(path, newWindRule);
+}
+
+void CanvasRenderingContext2D::clip(const String& windingRuleString)
+{
+ clipInternal(m_path, windingRuleString);
+}
+
+void CanvasRenderingContext2D::clip(DOMPath* domPath, const String& windingRuleString)
+{
+ clipInternal(domPath->path(), windingRuleString);
}
bool CanvasRenderingContext2D::isPointInPath(const float x, const float y, const String& windingRuleString)
diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.h b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.h
index 6967fca..8c57a66 100644
--- a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.h
+++ b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.h
@@ -148,8 +148,11 @@ public:
PassRefPtr<DOMPath> currentPath();
void setCurrentPath(DOMPath*);
void fill(const String& winding = "nonzero");
+ void fill(DOMPath*, const String& winding = "nonzero");
void stroke();
+ void stroke(DOMPath*);
void clip(const String& winding = "nonzero");
+ void clip(DOMPath*, const String& winding = "nonzero");
bool isPointInPath(const float x, const float y, const String& winding = "nonzero");
bool isPointInStroke(const float x, const float y);
@@ -302,6 +305,10 @@ private:
void applyStrokePattern();
void applyFillPattern();
+ void fillInternal(const Path&, const String& windingRuleString);
+ void strokeInternal(const Path&);
+ void clipInternal(const Path&, const String& windingRuleString);
+
void drawTextInternal(const String& text, float x, float y, bool fill, float maxWidth = 0, bool useMaxWidth = false);
const Font& accessFont();
diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.idl b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.idl
index 0f0925a..c46a82b 100644
--- a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.idl
+++ b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.idl
@@ -76,9 +76,18 @@ interface CanvasRenderingContext2D : CanvasRenderingContext {
[RaisesException] void arc(float x, float y, float radius, float startAngle, float endAngle, [Default=Undefined] optional boolean anticlockwise);
[RaisesException] void ellipse(float x, float y, float radiusX, float radiusY, float rotation, float startAngle, float endAngle, [Default=Undefined] optional boolean anticlockwise);
- void fill(optional CanvasWindingRule winding);
+ // FIXME: Simplify these using optional CanvasWindingRule once crbug.com/339000 gets fixed.
+ void fill();
+ [RuntimeEnabled=ExperimentalCanvasFeatures] void fill(Path path);
+ void fill(CanvasWindingRule winding);
+ [RuntimeEnabled=ExperimentalCanvasFeatures] void fill(Path path, CanvasWindingRule winding);
void stroke();
- void clip(optional CanvasWindingRule winding);
+ [RuntimeEnabled=ExperimentalCanvasFeatures] void stroke(Path path);
+ // FIXME: Simplify these using optional CanvasWindingRule once crbug.com/339000 gets fixed.
+ void clip();
+ [RuntimeEnabled=ExperimentalCanvasFeatures] void clip(Path path);
+ void clip(CanvasWindingRule winding);
+ [RuntimeEnabled=ExperimentalCanvasFeatures] void clip(Path path, CanvasWindingRule winding);
boolean isPointInPath(float x, float y, optional CanvasWindingRule winding);
boolean isPointInStroke(float x, float y);