Commit af9d0863 authored by jl@opera.com's avatar jl@opera.com

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
parent 5ef2826e
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.
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.
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
<!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>
...@@ -12,10 +12,10 @@ PASS context.createPattern(green1x1, 'null') threw exception SyntaxError: Failed ...@@ -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, '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(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(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': No function was found that matched the signature provided.. 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': No function was found that matched the signature provided.. 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': No function was found that matched the signature provided.. 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 context.createPattern(green1x1, '') did not throw an exception
PASS getPixel(1,1) is [0,128,0,255] PASS getPixel(1,1) is [0,128,0,255]
PASS getPixel(98,1) is [0,128,0,255] PASS getPixel(98,1) is [0,128,0,255]
......
...@@ -3,12 +3,12 @@ This test checks behavior of Canvas::drawImage with a broken source image. ...@@ -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". 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) 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': 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': 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': 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': Not a valid union member..
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) 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': 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': 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': 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': 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) 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) 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.. 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..
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "core/frame/ImageBitmap.h" #include "core/frame/ImageBitmap.h"
#include "SkPixelRef.h" // FIXME: qualify this skia header file. #include "SkPixelRef.h" // FIXME: qualify this skia header file.
#include "bindings/core/v8/UnionTypesCore.h"
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/fetch/ImageResource.h" #include "core/fetch/ImageResource.h"
#include "core/fetch/MemoryCache.h" #include "core/fetch/MemoryCache.h"
...@@ -39,6 +40,7 @@ ...@@ -39,6 +40,7 @@
#include "core/fetch/ResourcePtr.h" #include "core/fetch/ResourcePtr.h"
#include "core/html/HTMLCanvasElement.h" #include "core/html/HTMLCanvasElement.h"
#include "core/html/HTMLImageElement.h" #include "core/html/HTMLImageElement.h"
#include "core/html/HTMLVideoElement.h"
#include "core/html/canvas/CanvasRenderingContext2D.h" #include "core/html/canvas/CanvasRenderingContext2D.h"
#include "platform/graphics/BitmapImage.h" #include "platform/graphics/BitmapImage.h"
#include "platform/graphics/skia/NativeImageSkia.h" #include "platform/graphics/skia/NativeImageSkia.h"
...@@ -207,7 +209,9 @@ TEST_F(ImageBitmapTest, ImageResourceLifetime) ...@@ -207,7 +209,9 @@ TEST_F(ImageBitmapTest, ImageResourceLifetime)
} }
CanvasRenderingContext* context = canvasElement->getContext("2d"); CanvasRenderingContext* context = canvasElement->getContext("2d");
TrackExceptionState exceptionState; TrackExceptionState exceptionState;
toCanvasRenderingContext2D(context)->drawImage(imageBitmapDerived.get(), 0, 0, exceptionState); CanvasImageSourceUnion imageSource;
imageSource.setImageBitmap(imageBitmapDerived);
toCanvasRenderingContext2D(context)->drawImage(imageSource, 0, 0, exceptionState);
} }
} // namespace } // namespace
...@@ -1483,25 +1483,42 @@ static inline void clipRectsToImageRect(const FloatRect& imageRect, FloatRect* s ...@@ -1483,25 +1483,42 @@ static inline void clipRectsToImageRect(const FloatRect& imageRect, FloatRect* s
dstRect->move(offset); 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(); CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
FloatSize destRectSize = imageSource->defaultDestinationSize(); FloatSize sourceRectSize = imageSourceInternal->sourceSize();
drawImageInternal(imageSource, 0, 0, sourceRectSize.width(), sourceRectSize.height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState); 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) float x, float y, float width, float height, ExceptionState& exceptionState)
{ {
FloatSize sourceRectSize = imageSource->sourceSize(); CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
drawImageInternal(imageSource, 0, 0, sourceRectSize.width(), sourceRectSize.height(), x, y, width, height, exceptionState); 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 sx, float sy, float sw, float sh,
float dx, float dy, float dw, float dh, ExceptionState& exceptionState) 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) static void drawVideo(GraphicsContext* c, CanvasImageSource* imageSource, FloatRect srcRect, FloatRect dstRect)
...@@ -1683,7 +1700,7 @@ PassRefPtrWillBeRawPtr<CanvasGradient> CanvasRenderingContext2D::createRadialGra ...@@ -1683,7 +1700,7 @@ PassRefPtrWillBeRawPtr<CanvasGradient> CanvasRenderingContext2D::createRadialGra
return gradient.release(); return gradient.release();
} }
PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(CanvasImageSource* imageSource, PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(const CanvasImageSourceUnion& imageSource,
const String& repetitionType, ExceptionState& exceptionState) const String& repetitionType, ExceptionState& exceptionState)
{ {
Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetitionType, exceptionState); Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetitionType, exceptionState);
...@@ -1691,13 +1708,14 @@ PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(Ca ...@@ -1691,13 +1708,14 @@ PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(Ca
return nullptr; return nullptr;
SourceImageStatus status; SourceImageStatus status;
RefPtr<Image> imageForRendering = imageSource->getSourceImageForCanvas(CopySourceImageIfVolatile, &status); CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanvas(CopySourceImageIfVolatile, &status);
switch (status) { switch (status) {
case NormalSourceImageStatus: case NormalSourceImageStatus:
break; break;
case ZeroSizeCanvasSourceImageStatus: 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; return nullptr;
case UndecodableSourceImageStatus: case UndecodableSourceImageStatus:
exceptionState.throwDOMException(InvalidStateError, "Source image is in the 'broken' state."); exceptionState.throwDOMException(InvalidStateError, "Source image is in the 'broken' state.");
...@@ -1714,7 +1732,7 @@ PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(Ca ...@@ -1714,7 +1732,7 @@ PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(Ca
} }
ASSERT(imageForRendering); ASSERT(imageForRendering);
bool originClean = !wouldTaintOrigin(imageSource); bool originClean = !wouldTaintOrigin(imageSourceInternal);
return CanvasPattern::create(imageForRendering.release(), repeatMode, originClean); return CanvasPattern::create(imageForRendering.release(), repeatMode, originClean);
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#define CanvasRenderingContext2D_h #define CanvasRenderingContext2D_h
#include "bindings/core/v8/ScriptWrappable.h" #include "bindings/core/v8/ScriptWrappable.h"
#include "bindings/core/v8/UnionTypesCore.h"
#include "core/css/CSSFontSelectorClient.h" #include "core/css/CSSFontSelectorClient.h"
#include "core/html/canvas/Canvas2DContextAttributes.h" #include "core/html/canvas/Canvas2DContextAttributes.h"
#include "core/html/canvas/CanvasPathMethods.h" #include "core/html/canvas/CanvasPathMethods.h"
...@@ -64,6 +65,8 @@ class HTMLVideoElement; ...@@ -64,6 +65,8 @@ class HTMLVideoElement;
class ImageData; class ImageData;
class TextMetrics; class TextMetrics;
typedef HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrImageBitmap CanvasImageSourceUnion;
typedef WillBeHeapHashMap<String, RefPtrWillBeMember<MutableStylePropertySet>> MutableStylePropertyMap; typedef WillBeHeapHashMap<String, RefPtrWillBeMember<MutableStylePropertySet>> MutableStylePropertyMap;
class CanvasRenderingContext2D final: public CanvasRenderingContext, public ScriptWrappable, public CanvasPathMethods { class CanvasRenderingContext2D final: public CanvasRenderingContext, public ScriptWrappable, public CanvasPathMethods {
...@@ -180,9 +183,9 @@ public: ...@@ -180,9 +183,9 @@ public:
void clearShadow(); void clearShadow();
void drawImage(CanvasImageSource*, float x, float y, ExceptionState&); void drawImage(const CanvasImageSourceUnion&, float x, float y, ExceptionState&);
void drawImage(CanvasImageSource*, float x, float y, float width, float height, ExceptionState&); void drawImage(const CanvasImageSourceUnion&, 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 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, 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()); float dx = 0, float dy = 0, float dw = 0, float dh = 0, const String& compositeOperation = emptyString());
...@@ -193,7 +196,7 @@ public: ...@@ -193,7 +196,7 @@ public:
PassRefPtrWillBeRawPtr<CanvasGradient> createLinearGradient(float x0, float y0, float x1, float y1); 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<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(PassRefPtrWillBeRawPtr<ImageData>) const;
PassRefPtrWillBeRawPtr<ImageData> createImageData(float width, float height, ExceptionState&) const; PassRefPtrWillBeRawPtr<ImageData> createImageData(float width, float height, ExceptionState&) const;
......
...@@ -26,14 +26,11 @@ ...@@ -26,14 +26,11 @@
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#canvasrenderingcontext2d // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#canvasrenderingcontext2d
// FIXME: float => double throughout // FIXME: float => double throughout
// FIXME: Use union type in drawImage and createPattern once supported:
// http://crbug.com/372891
typedef (HTMLImageElement or typedef (HTMLImageElement or
HTMLVideoElement or HTMLVideoElement or
HTMLCanvasElement // or HTMLCanvasElement or
// CanvasRenderingContext2D or // CanvasRenderingContext2D or
// ImageBitmap ImageBitmap) CanvasImageSource;
) CanvasImageSource;
enum CanvasFillRule { "nonzero", "evenodd" }; enum CanvasFillRule { "nonzero", "evenodd" };
...@@ -71,9 +68,7 @@ enum CanvasFillRule { "nonzero", "evenodd" }; ...@@ -71,9 +68,7 @@ enum CanvasFillRule { "nonzero", "evenodd" };
[Custom] attribute object fillStyle; // (default black) [Custom] attribute object fillStyle; // (default black)
CanvasGradient createLinearGradient(float x0, float y0, float x1, float y1); 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] CanvasGradient createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1);
[RaisesException] CanvasPattern createPattern(HTMLCanvasElement canvas, DOMString? repetitionType); [RaisesException] CanvasPattern createPattern(CanvasImageSource image, DOMString? repetitionType);
[RaisesException] CanvasPattern createPattern(HTMLImageElement image, DOMString? repetitionType);
[RaisesException] CanvasPattern createPattern(HTMLVideoElement image, DOMString? repetitionType);
// shadows // shadows
attribute unrestricted float shadowOffsetX; attribute unrestricted float shadowOffsetX;
...@@ -110,18 +105,9 @@ enum CanvasFillRule { "nonzero", "evenodd" }; ...@@ -110,18 +105,9 @@ enum CanvasFillRule { "nonzero", "evenodd" };
TextMetrics measureText(DOMString text); TextMetrics measureText(DOMString text);
// drawing images // drawing images
[RaisesException] void drawImage(HTMLImageElement image, unrestricted float x, unrestricted float y); [RaisesException] void drawImage(CanvasImageSource 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(CanvasImageSource 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(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);
[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);
// hit regions // hit regions
[RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void addHitRegion(optional HitRegionOptions options); [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void addHitRegion(optional HitRegionOptions options);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment