summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjl@opera.com <jl@opera.com>2014-11-12 21:55:39 +0000
committerjl@opera.com <jl@opera.com>2014-11-12 21:55:39 +0000
commitaf9d086381a49219002d6cfddb0a19a08659149d (patch)
tree90137be24ba1a1633f1b8d731d0b6add488a5497
parent5ef2826ef900fa0ed6289a3c7242e54f387b5351 (diff)
downloadchromium_src-af9d086381a49219002d6cfddb0a19a08659149d.zip
chromium_src-af9d086381a49219002d6cfddb0a19a08659149d.tar.gz
chromium_src-af9d086381a49219002d6cfddb0a19a08659149d.tar.bz2
Use CanvasImageSource union type instead of overloading
In CanvasRenderingContext2D.idl, use the already defined union type CanvasImageSource for the argument to drawImage() and createPattern(), instead of having one overload of each per union member type. This reduces the number of overloads for drawImage() from 12 to 3 and thus greatly reduces the amount of generated bindings code for it. BUG=430337 Review URL: https://codereview.chromium.org/703783004 git-svn-id: svn://svn.chromium.org/blink/trunk@185247 bbb929c8-8fbe-4397-9dbb-9b2b20218538
-rw-r--r--third_party/WebKit/LayoutTests/canvas/philip/tests/2d.pattern.image.string-expected.txt2
-rw-r--r--third_party/WebKit/LayoutTests/canvas/philip/tests/2d.pattern.image.undefined-expected.txt2
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-createPattern-expected.txt269
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-createPattern.html189
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-behaviour-expected.txt8
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/drawImage-with-broken-image-expected.txt12
-rw-r--r--third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp6
-rw-r--r--third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp44
-rw-r--r--third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.h11
-rw-r--r--third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.idl26
10 files changed, 519 insertions, 50 deletions
diff --git a/third_party/WebKit/LayoutTests/canvas/philip/tests/2d.pattern.image.string-expected.txt b/third_party/WebKit/LayoutTests/canvas/philip/tests/2d.pattern.image.string-expected.txt
index 8a74311..ca03c3c 100644
--- a/third_party/WebKit/LayoutTests/canvas/philip/tests/2d.pattern.image.string-expected.txt
+++ b/third_party/WebKit/LayoutTests/canvas/philip/tests/2d.pattern.image.string-expected.txt
@@ -1 +1 @@
-Failed assertion: expected exception of type TYPE_MISMATCH_ERR, got: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': No function was found that matched the signature provided.
+Failed assertion: expected exception of type TYPE_MISMATCH_ERR, got: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': Not a valid union member.
diff --git a/third_party/WebKit/LayoutTests/canvas/philip/tests/2d.pattern.image.undefined-expected.txt b/third_party/WebKit/LayoutTests/canvas/philip/tests/2d.pattern.image.undefined-expected.txt
index 8a74311..ca03c3c 100644
--- a/third_party/WebKit/LayoutTests/canvas/philip/tests/2d.pattern.image.undefined-expected.txt
+++ b/third_party/WebKit/LayoutTests/canvas/philip/tests/2d.pattern.image.undefined-expected.txt
@@ -1 +1 @@
-Failed assertion: expected exception of type TYPE_MISMATCH_ERR, got: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': No function was found that matched the signature provided.
+Failed assertion: expected exception of type TYPE_MISMATCH_ERR, got: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': Not a valid union member.
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-createPattern-expected.txt b/third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-createPattern-expected.txt
new file mode 100644
index 0000000..33c0374
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-createPattern-expected.txt
@@ -0,0 +1,269 @@
+Ensure correct behavior of createPattern with ImageBitmaps.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testBitmap.width is imageWidth
+PASS testBitmap.height is imageHeight
+PASS testBitmap.width is imageWidth
+PASS testBitmap.height is imageHeight
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 255 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 255 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 255 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 255 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 255 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 255 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 255 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 255 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 255 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 255 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 255 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 255 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 255 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 255 is true
+PASS d[3] == 255 is true
+PASS d[0] == 255 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 255 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 255 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 255 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 255 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 255 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 255 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS d[0] == 0 is true
+PASS d[1] == 0 is true
+PASS d[2] == 0 is true
+PASS d[3] == 0 is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-createPattern.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-createPattern.html
new file mode 100644
index 0000000..1ab2ba7
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-createPattern.html
@@ -0,0 +1,189 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+</head>
+<body>
+<script>
+
+description("Ensure correct behavior of createPattern with ImageBitmaps.");
+window.jsTestIsAsync = true;
+
+function jsWrapperClass(node)
+{
+ // returns the ClassName of node
+ if (!node)
+ return "[null]";
+ var string = Object.prototype.toString.apply(node);
+
+ // string will be of the form [object ClassName]
+ return string.substr(8, string.length - 9);
+}
+
+function shouldBeType(expression, className)
+{
+ shouldBe("jsWrapperClass(" + expression + ")", "'" + className + "'");
+}
+
+function shouldNotBeCalled() {
+ testFailed("createImageBitmap promise rejected.");
+ finishJSTest();
+}
+
+function shouldBeRed(x, y) {
+ d = ctx.getImageData(x, y, 1, 1).data;
+ shouldBeTrue("d[0] == 255");
+ shouldBeTrue("d[1] == 0");
+ shouldBeTrue("d[2] == 0");
+ shouldBeTrue("d[3] == 255");
+}
+
+function shouldBeGreen(x, y) {
+ d = ctx.getImageData(x, y, 1, 1).data;
+ shouldBeTrue("d[0] == 0");
+ shouldBeTrue("d[1] == 255");
+ shouldBeTrue("d[2] == 0");
+ shouldBeTrue("d[3] == 255");
+}
+
+function shouldBeBlue(x, y) {
+ d = ctx.getImageData(x, y, 1, 1).data;
+ shouldBeTrue("d[0] == 0");
+ shouldBeTrue("d[1] == 0");
+ shouldBeTrue("d[2] == 255");
+ shouldBeTrue("d[3] == 255");
+}
+
+function shouldBeBlack(x, y) {
+ d = ctx.getImageData(x, y, 1, 1).data;
+ shouldBeTrue("d[0] == 0");
+ shouldBeTrue("d[1] == 0");
+ shouldBeTrue("d[2] == 0");
+ shouldBeTrue("d[3] == 255");
+}
+
+function shouldBeClear(x, y) {
+ // should be transparent black pixels
+ d = ctx.getImageData(x, y, 1, 1).data;
+ shouldBeTrue("d[0] == 0");
+ shouldBeTrue("d[1] == 0");
+ shouldBeTrue("d[2] == 0");
+ shouldBeTrue("d[3] == 0");
+}
+
+var checks = { red: shouldBeRed,
+ green: shouldBeGreen,
+ blue: shouldBeBlue,
+ black: shouldBeBlack,
+ clear: shouldBeClear };
+
+function checkQuad(x, y, top_left, top_right, bottom_left, bottom_right) {
+ checks[top_left](x, y);
+ checks[top_right](x + 1, y);
+ checks[bottom_left](x, y + 1);
+ checks[bottom_right](x + 1, y + 1);
+}
+
+function drawPattern(ctx) {
+ // Draw a four-color pattern
+ ctx.beginPath();
+ ctx.fillStyle = "rgb(255, 0, 0)";
+ ctx.fillRect(0, 0, 10, 10);
+ ctx.fillStyle = "rgb(0, 255, 0)";
+ ctx.fillRect(10, 0, 10, 10);
+ ctx.fillStyle = "rgb(0, 0, 255)";
+ ctx.fillRect(0, 10, 10, 10);
+ ctx.fillStyle = "rgb(0, 0, 0)";
+ ctx.fillRect(10, 10, 10, 10);
+}
+
+function clearContext(context) {
+ context.clearRect(0, 0, 50, 50);
+}
+
+var bitmap;
+var image;
+var testBitmap; // this is an ImageBitmap that is uncropped. We use this to test createImageBitmap(testBitmap)
+var d; // image.imageData
+var elements;
+
+var imageWidth = 20;
+var imageHeight = 20;
+
+// Draw to an auxillary canvas.
+var aCanvas = document.createElement("canvas");
+aCanvas.width = imageWidth;
+aCanvas.height = imageHeight;
+var aCtx = aCanvas.getContext("2d");
+drawPattern(aCtx);
+
+var canvas = document.createElement("canvas");
+canvas.setAttribute("width", "50");
+canvas.setAttribute("height", "50");
+var ctx = canvas.getContext("2d");
+
+image = new Image();
+image.onload = imageLoaded;
+image.src = aCanvas.toDataURL();
+
+var imageLoaded = false;
+var imageBitmapLoaded = false;
+
+function imageLoaded() {
+ createImageBitmap(image).then(imageBitmapLoadedCallback, shouldNotBeCalled);
+ d = aCtx.getImageData(0, 0, 20, 20);
+ imageLoaded = true;
+ loaded();
+}
+
+function imageBitmapLoadedCallback(imageBitmap) {
+ testBitmap = imageBitmap;
+
+ shouldBe("testBitmap.width", "imageWidth");
+ shouldBe("testBitmap.height", "imageHeight");
+
+ // width and height are readonly
+ testBitmap.width = 42;
+ testBitmap.height = 42;
+ shouldBe("testBitmap.width", "imageWidth");
+ shouldBe("testBitmap.height", "imageHeight");
+
+ imageBitmapLoaded = true;
+ loaded();
+}
+
+function loaded() {
+ if (imageLoaded && imageBitmapLoaded) {
+ ctx.fillStyle = ctx.createPattern(testBitmap, "repeat");
+ ctx.fillRect(10, 10, 30, 30);
+
+ // Check each pixel quad at each corner. The filled pattern
+ // is 3x3 squares of different colors, so there are four rows
+ // of four corners.
+
+ checkQuad(9, 9, "clear", "clear", "clear", "black");
+ checkQuad(19, 9, "clear", "clear", "black", "blue");
+ checkQuad(29, 9, "clear", "clear", "blue", "black");
+ checkQuad(39, 9, "clear", "clear", "black", "clear");
+
+ checkQuad(9, 19, "clear", "black", "clear", "green");
+ checkQuad(19, 19, "black", "blue", "green", "red");
+ checkQuad(29, 19, "blue", "black", "red", "green");
+ checkQuad(39, 19, "black", "clear", "green", "clear");
+
+ checkQuad(9, 29, "clear", "green", "clear", "black");
+ checkQuad(19, 29, "green", "red", "black", "blue");
+ checkQuad(29, 29, "red", "green", "blue", "black");
+ checkQuad(39, 29, "green", "clear", "black", "clear");
+
+ checkQuad(9, 39, "clear", "black", "clear", "clear");
+ checkQuad(19, 39, "black", "blue", "clear", "clear");
+ checkQuad(29, 39, "blue", "black", "clear", "clear");
+ checkQuad(39, 39, "black", "clear", "clear", "clear");
+
+ finishJSTest();
+ }
+}
+</script>
+</body>
+</html>
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-behaviour-expected.txt b/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-behaviour-expected.txt
index 77e0c8a..77780fe 100644
--- a/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-behaviour-expected.txt
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-behaviour-expected.txt
@@ -12,10 +12,10 @@ PASS context.createPattern(green1x1, 'null') threw exception SyntaxError: Failed
PASS context.createPattern(green1x1, undefined) threw exception SyntaxError: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': The provided type ('undefined') is not one of 'repeat', 'no-repeat', 'repeat-x', or 'repeat-y'..
PASS context.createPattern(green1x1, 'undefined') threw exception SyntaxError: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': The provided type ('undefined') is not one of 'repeat', 'no-repeat', 'repeat-x', or 'repeat-y'..
PASS context.createPattern(green1x1, {toString:function(){ return null;}}) threw exception SyntaxError: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': The provided type ('null') is not one of 'repeat', 'no-repeat', 'repeat-x', or 'repeat-y'..
-PASS context.createPattern(null, '') threw exception TypeError: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
-PASS context.createPattern(undefined, '') threw exception TypeError: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
-PASS context.createPattern({}, '') threw exception TypeError: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
-PASS context.createPattern([], '') threw exception TypeError: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
+PASS context.createPattern(null, '') threw exception TypeError: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': Not a valid union member..
+PASS context.createPattern(undefined, '') threw exception TypeError: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': Not a valid union member..
+PASS context.createPattern({}, '') threw exception TypeError: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': Not a valid union member..
+PASS context.createPattern([], '') threw exception TypeError: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': Not a valid union member..
PASS context.createPattern(green1x1, '') did not throw an exception
PASS getPixel(1,1) is [0,128,0,255]
PASS getPixel(98,1) is [0,128,0,255]
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/drawImage-with-broken-image-expected.txt b/third_party/WebKit/LayoutTests/fast/canvas/drawImage-with-broken-image-expected.txt
index 91ce0fe..4afe142 100644
--- a/third_party/WebKit/LayoutTests/fast/canvas/drawImage-with-broken-image-expected.txt
+++ b/third_party/WebKit/LayoutTests/fast/canvas/drawImage-with-broken-image-expected.txt
@@ -3,12 +3,12 @@ This test checks behavior of Canvas::drawImage with a broken source image.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-PASS ctx.drawImage(null, 0, 0) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
-PASS ctx.drawImage(null, 0, 0, 20, 20) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
-PASS ctx.drawImage(null, 0, 0, 20, 20, 0, 0, 20, 20) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
-PASS ctx.drawImage(undefined, 0, 0) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
-PASS ctx.drawImage(undefined, 0, 0, 20, 20) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
-PASS ctx.drawImage(undefined, 0, 0, 20, 20, 0, 0, 20, 20) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': No function was found that matched the signature provided..
+PASS ctx.drawImage(null, 0, 0) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': Not a valid union member..
+PASS ctx.drawImage(null, 0, 0, 20, 20) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': Not a valid union member..
+PASS ctx.drawImage(null, 0, 0, 20, 20, 0, 0, 20, 20) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': Not a valid union member..
+PASS ctx.drawImage(undefined, 0, 0) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': Not a valid union member..
+PASS ctx.drawImage(undefined, 0, 0, 20, 20) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': Not a valid union member..
+PASS ctx.drawImage(undefined, 0, 0, 20, 20, 0, 0, 20, 20) threw exception TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': Not a valid union member..
PASS ctx.drawImage(invalidImage, 0, 0) threw exception InvalidStateError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state..
PASS ctx.drawImage(invalidImage, 0, 0, 20, 20) threw exception InvalidStateError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state..
PASS ctx.drawImage(invalidImage, 0, 0, 20, 20, 0, 0, 20, 20) threw exception InvalidStateError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state..
diff --git a/third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp b/third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp
index d9e08db..064c9ef 100644
--- a/third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp
+++ b/third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp
@@ -32,6 +32,7 @@
#include "core/frame/ImageBitmap.h"
#include "SkPixelRef.h" // FIXME: qualify this skia header file.
+#include "bindings/core/v8/UnionTypesCore.h"
#include "core/dom/Document.h"
#include "core/fetch/ImageResource.h"
#include "core/fetch/MemoryCache.h"
@@ -39,6 +40,7 @@
#include "core/fetch/ResourcePtr.h"
#include "core/html/HTMLCanvasElement.h"
#include "core/html/HTMLImageElement.h"
+#include "core/html/HTMLVideoElement.h"
#include "core/html/canvas/CanvasRenderingContext2D.h"
#include "platform/graphics/BitmapImage.h"
#include "platform/graphics/skia/NativeImageSkia.h"
@@ -207,7 +209,9 @@ TEST_F(ImageBitmapTest, ImageResourceLifetime)
}
CanvasRenderingContext* context = canvasElement->getContext("2d");
TrackExceptionState exceptionState;
- toCanvasRenderingContext2D(context)->drawImage(imageBitmapDerived.get(), 0, 0, exceptionState);
+ CanvasImageSourceUnion imageSource;
+ imageSource.setImageBitmap(imageBitmapDerived);
+ toCanvasRenderingContext2D(context)->drawImage(imageSource, 0, 0, exceptionState);
}
} // namespace
diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp
index 41540be..32d0d66 100644
--- a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp
+++ b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp
@@ -1483,25 +1483,42 @@ static inline void clipRectsToImageRect(const FloatRect& imageRect, FloatRect* s
dstRect->move(offset);
}
-void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, float x, float y, ExceptionState& exceptionState)
+static inline CanvasImageSource* toImageSourceInternal(const CanvasImageSourceUnion& value)
+{
+ if (value.isHTMLImageElement())
+ return value.getAsHTMLImageElement().get();
+ if (value.isHTMLVideoElement())
+ return value.getAsHTMLVideoElement().get();
+ if (value.isHTMLCanvasElement())
+ return value.getAsHTMLCanvasElement().get();
+ if (value.isImageBitmap())
+ return value.getAsImageBitmap().get();
+ ASSERT_NOT_REACHED();
+ return nullptr;
+}
+
+void CanvasRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource, float x, float y, ExceptionState& exceptionState)
{
- FloatSize sourceRectSize = imageSource->sourceSize();
- FloatSize destRectSize = imageSource->defaultDestinationSize();
- drawImageInternal(imageSource, 0, 0, sourceRectSize.width(), sourceRectSize.height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState);
+ CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
+ FloatSize sourceRectSize = imageSourceInternal->sourceSize();
+ FloatSize destRectSize = imageSourceInternal->defaultDestinationSize();
+ drawImageInternal(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize.height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState);
}
-void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource,
+void CanvasRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource,
float x, float y, float width, float height, ExceptionState& exceptionState)
{
- FloatSize sourceRectSize = imageSource->sourceSize();
- drawImageInternal(imageSource, 0, 0, sourceRectSize.width(), sourceRectSize.height(), x, y, width, height, exceptionState);
+ CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
+ FloatSize sourceRectSize = imageSourceInternal->sourceSize();
+ drawImageInternal(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize.height(), x, y, width, height, exceptionState);
}
-void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource,
+void CanvasRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource,
float sx, float sy, float sw, float sh,
float dx, float dy, float dw, float dh, ExceptionState& exceptionState)
{
- drawImageInternal(imageSource, sx, sy, sw, sh, dx, dy, dw, dh, exceptionState);
+ CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
+ drawImageInternal(imageSourceInternal, sx, sy, sw, sh, dx, dy, dw, dh, exceptionState);
}
static void drawVideo(GraphicsContext* c, CanvasImageSource* imageSource, FloatRect srcRect, FloatRect dstRect)
@@ -1683,7 +1700,7 @@ PassRefPtrWillBeRawPtr<CanvasGradient> CanvasRenderingContext2D::createRadialGra
return gradient.release();
}
-PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(CanvasImageSource* imageSource,
+PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(const CanvasImageSourceUnion& imageSource,
const String& repetitionType, ExceptionState& exceptionState)
{
Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetitionType, exceptionState);
@@ -1691,13 +1708,14 @@ PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(Ca
return nullptr;
SourceImageStatus status;
- RefPtr<Image> imageForRendering = imageSource->getSourceImageForCanvas(CopySourceImageIfVolatile, &status);
+ CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
+ RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanvas(CopySourceImageIfVolatile, &status);
switch (status) {
case NormalSourceImageStatus:
break;
case ZeroSizeCanvasSourceImageStatus:
- exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSource->sourceSize().width() ? "height" : "width"));
+ exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSourceInternal->sourceSize().width() ? "height" : "width"));
return nullptr;
case UndecodableSourceImageStatus:
exceptionState.throwDOMException(InvalidStateError, "Source image is in the 'broken' state.");
@@ -1714,7 +1732,7 @@ PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(Ca
}
ASSERT(imageForRendering);
- bool originClean = !wouldTaintOrigin(imageSource);
+ bool originClean = !wouldTaintOrigin(imageSourceInternal);
return CanvasPattern::create(imageForRendering.release(), repeatMode, originClean);
}
diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.h b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.h
index 7119a69..88a564a 100644
--- a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.h
+++ b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.h
@@ -27,6 +27,7 @@
#define CanvasRenderingContext2D_h
#include "bindings/core/v8/ScriptWrappable.h"
+#include "bindings/core/v8/UnionTypesCore.h"
#include "core/css/CSSFontSelectorClient.h"
#include "core/html/canvas/Canvas2DContextAttributes.h"
#include "core/html/canvas/CanvasPathMethods.h"
@@ -64,6 +65,8 @@ class HTMLVideoElement;
class ImageData;
class TextMetrics;
+typedef HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrImageBitmap CanvasImageSourceUnion;
+
typedef WillBeHeapHashMap<String, RefPtrWillBeMember<MutableStylePropertySet>> MutableStylePropertyMap;
class CanvasRenderingContext2D final: public CanvasRenderingContext, public ScriptWrappable, public CanvasPathMethods {
@@ -180,9 +183,9 @@ public:
void clearShadow();
- void drawImage(CanvasImageSource*, float x, float y, ExceptionState&);
- void drawImage(CanvasImageSource*, float x, float y, float width, float height, ExceptionState&);
- void drawImage(CanvasImageSource*, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh, ExceptionState&);
+ void drawImage(const CanvasImageSourceUnion&, float x, float y, ExceptionState&);
+ void drawImage(const CanvasImageSourceUnion&, float x, float y, float width, float height, ExceptionState&);
+ void drawImage(const CanvasImageSourceUnion&, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh, ExceptionState&);
void drawImageFromRect(HTMLImageElement*, float sx = 0, float sy = 0, float sw = 0, float sh = 0,
float dx = 0, float dy = 0, float dw = 0, float dh = 0, const String& compositeOperation = emptyString());
@@ -193,7 +196,7 @@ public:
PassRefPtrWillBeRawPtr<CanvasGradient> createLinearGradient(float x0, float y0, float x1, float y1);
PassRefPtrWillBeRawPtr<CanvasGradient> createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1, ExceptionState&);
- PassRefPtrWillBeRawPtr<CanvasPattern> createPattern(CanvasImageSource*, const String& repetitionType, ExceptionState&);
+ PassRefPtrWillBeRawPtr<CanvasPattern> createPattern(const CanvasImageSourceUnion&, const String& repetitionType, ExceptionState&);
PassRefPtrWillBeRawPtr<ImageData> createImageData(PassRefPtrWillBeRawPtr<ImageData>) const;
PassRefPtrWillBeRawPtr<ImageData> createImageData(float width, float height, ExceptionState&) const;
diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.idl b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.idl
index 198cf3a..1faf6e7 100644
--- a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.idl
+++ b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.idl
@@ -26,14 +26,11 @@
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#canvasrenderingcontext2d
// FIXME: float => double throughout
-// FIXME: Use union type in drawImage and createPattern once supported:
-// http://crbug.com/372891
typedef (HTMLImageElement or
HTMLVideoElement or
- HTMLCanvasElement // or
+ HTMLCanvasElement or
// CanvasRenderingContext2D or
- // ImageBitmap
- ) CanvasImageSource;
+ ImageBitmap) CanvasImageSource;
enum CanvasFillRule { "nonzero", "evenodd" };
@@ -71,9 +68,7 @@ enum CanvasFillRule { "nonzero", "evenodd" };
[Custom] attribute object fillStyle; // (default black)
CanvasGradient createLinearGradient(float x0, float y0, float x1, float y1);
[RaisesException] CanvasGradient createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1);
- [RaisesException] CanvasPattern createPattern(HTMLCanvasElement canvas, DOMString? repetitionType);
- [RaisesException] CanvasPattern createPattern(HTMLImageElement image, DOMString? repetitionType);
- [RaisesException] CanvasPattern createPattern(HTMLVideoElement image, DOMString? repetitionType);
+ [RaisesException] CanvasPattern createPattern(CanvasImageSource image, DOMString? repetitionType);
// shadows
attribute unrestricted float shadowOffsetX;
@@ -110,18 +105,9 @@ enum CanvasFillRule { "nonzero", "evenodd" };
TextMetrics measureText(DOMString text);
// drawing images
- [RaisesException] void drawImage(HTMLImageElement image, unrestricted float x, unrestricted float y);
- [RaisesException] void drawImage(HTMLImageElement image, unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
- [RaisesException] void drawImage(HTMLImageElement image, unrestricted float sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
- [RaisesException] void drawImage(HTMLCanvasElement canvas, unrestricted float x, unrestricted float y);
- [RaisesException] void drawImage(HTMLCanvasElement canvas, unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
- [RaisesException] void drawImage(HTMLCanvasElement canvas, unrestricted float sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
- [RaisesException] void drawImage(HTMLVideoElement video, unrestricted float x, unrestricted float y);
- [RaisesException] void drawImage(HTMLVideoElement video, unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
- [RaisesException] void drawImage(HTMLVideoElement video, unrestricted float sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
- [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void drawImage(ImageBitmap imageBitmap, unrestricted float x, unrestricted float y);
- [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void drawImage(ImageBitmap imageBitmap, unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
- [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void drawImage(ImageBitmap imageBitmap, unrestricted float sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
+ [RaisesException] void drawImage(CanvasImageSource image, unrestricted float x, unrestricted float y);
+ [RaisesException] void drawImage(CanvasImageSource image, unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
+ [RaisesException] void drawImage(CanvasImageSource image, unrestricted float sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
// hit regions
[RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void addHitRegion(optional HitRegionOptions options);