Index: LayoutTests/fast/canvas/canvas-createImageBitmap-recursive.html |
diff --git a/LayoutTests/fast/canvas/canvas-createImageBitmap-recursive.html b/LayoutTests/fast/canvas/canvas-createImageBitmap-recursive.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..eb99552b27b4ba102a078079a1957d570496f529 |
--- /dev/null |
+++ b/LayoutTests/fast/canvas/canvas-createImageBitmap-recursive.html |
@@ -0,0 +1,152 @@ |
+<html> |
+<head> |
+<script src="../js/resources/js-test-pre.js"></script> |
+</head> |
+<body> |
+<script> |
+description("Ensure correct behavior of drawImage with ImageBitmaps constructed from ImageBitmaps that are constructed from both images (not pinned to memory) and context (pinned to memory)."); |
+ |
+window.jsTestIsAsync = true; |
+ |
+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 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"); |
+} |
+function clearContext(context) { |
+ context.clearRect(0, 0, 500, 500); |
+} |
+ |
+var image; |
+ |
+var imageWidth = 200; |
+var imageHeight = 200; |
+ |
+var aCanvas = document.createElement("canvas"); |
+aCanvas.width = imageWidth; |
+aCanvas.height = imageHeight; |
+var aCtx = aCanvas.getContext("2d"); |
+aCtx.fillStyle = 'rgb(0, 255, 0)'; |
+aCtx.fillRect(0, 0, 200, 200); |
+ |
+var canvas = document.createElement("canvas"); |
+canvas.setAttribute("width", "500"); |
+canvas.setAttribute("height", "500"); |
+var ctx = canvas.getContext("2d"); |
+ |
+image = new Image(); |
+image.onload = imageLoaded; |
+image.src = aCanvas.toDataURL(); |
+ |
+var imageLoaded = false; |
+ |
+function imageLoaded() { |
+ createImageBitmap(image, imageBitmapLoadedCallback, -100, -100, 200, 200); |
+ imageLoaded = true; |
+} |
+ |
+var i; |
+ |
+function imageBitmapLoadedCallback(imageBitmap) { |
+ i = 0; |
+ bitmap = imageBitmap; |
+ check(i); |
+} |
+ |
+function imageBitmapLoadedCallback2(imageBitmap) { |
+ ++i; |
+ bitmap = imageBitmap; |
+ check(i); |
+} |
+ |
+function check(num) { |
+ switch(num) { |
+ case 0: |
+ createImageBitmap(bitmap, checkCallback(100, 100, 100, 100)); |
+ break; |
+ case 1: |
+ createImageBitmap(bitmap, checkCallback(200, 200, 100, 100), -100, -100, 300, 300); |
+ break; |
+ case 2: |
+ createImageBitmap(bitmap, checkCallback(0, 0, 100, 100), 100, 100, 200, 200); |
+ break; |
+ case 3: |
+ createImageBitmap(aCtx, imageBitmapLoadedCallback2, 100, 100, 200, 200); |
+ break; |
+ case 4: |
+ createImageBitmap(bitmap, checkCallback(0, 0, 100, 100)); |
+ break; |
+ case 5: |
+ createImageBitmap(bitmap, checkCallback(150, 100, 100, 100), -150, -100, 350, 400); |
+ break; |
+ case 6: |
+ createImageBitmap(bitmap, checkCallback(0, 0, 50, 50), 50, 50, 100, 100); |
+ break; |
+ default: |
+ finishJSTest(); |
+ break; |
+ } |
+} |
+ |
+function shouldBeFilled(x, y, w, h) { |
+ shouldBeGreen(x+5, y+5); |
+ shouldBeGreen(x+w-5, y+h-5); |
+ shouldBeGreen(x+w/2, y+h/2); |
+ shouldBeClear(x-5, y-5); |
+ shouldBeClear(x+w+5, y+h+5); |
+} |
+ |
+function checkCallback(x, y, w, h) { |
+ // x, y, w, h are the expected location of the green square |
+ var x1 = x; |
+ var y1 = y; |
+ var w1 = w; |
+ var h1 = h; |
+ return function(imageBitmap) { |
+ clearContext(ctx); |
+ ctx.drawImage(imageBitmap, 0, 0); |
+ shouldBeFilled(x1, y1, w1, h1); |
+ |
+ clearContext(ctx); |
+ ctx.drawImage(imageBitmap, 100, 100, 400, 400); |
+ // scale up w and h as necessary |
+ var w2 = w1 * 400.0 / imageBitmap.width; |
+ var h2 = h1 * 400.0 / imageBitmap.height; |
+ // x and y are transformed |
+ var x2 = x1 * w2 / w1 + 100; |
+ var y2 = y1 * h2 / h1 + 100; |
+ shouldBeFilled(x2, y2, w2, h2); |
+ |
+ clearContext(ctx); |
+ ctx.drawImage(imageBitmap, 0, 0, 500, 500); |
+ // scale up w and h as necessary |
+ var w3 = w1 * 500.0 / imageBitmap.width; |
+ var h3 = h1 * 500.0 / imageBitmap.height; |
+ // x and y are transformed |
+ var x3 = x1 * w3 / w1; |
+ var y3 = y1 * h3 / h1; |
+ shouldBeFilled(x3, y3, w3, h3); |
+ |
+ clearContext(ctx); |
+ ctx.drawImage(imageBitmap, x1, y1, w1, h1, 0, 0, 500, 500); |
+ shouldBeFilled(0, 0, 500, 500); |
+ |
+ ++i; |
+ check(i); |
+ } |
+} |
+ |
+</script> |
+<script src="../js/resources/js-test-post.js"></script> |
+</body> |
+</html> |