Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Unified Diff: LayoutTests/fast/canvas/canvas-createImageBitmap-recursive.html

Issue 19393004: Allow eviction of ImageBitmaps that are created from ImageElements. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Decrease canvas size for recursive test. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8b4f3679739296e5467bb60a24e5068405484a3f
--- /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, 50, 50);
+}
+
+var image;
+
+var imageWidth = 20;
+var imageHeight = 20;
+
+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, 20, 20);
+
+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;
+
+function imageLoaded() {
+ createImageBitmap(image, imageBitmapLoadedCallback, -10, -10, 20, 20);
+ 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(10, 10, 10, 10));
+ break;
+ case 1:
+ createImageBitmap(bitmap, checkCallback(20, 20, 10, 10), -10, -10, 30, 30);
+ break;
+ case 2:
+ createImageBitmap(bitmap, checkCallback(0, 0, 10, 10), 10, 10, 20, 20);
+ break;
+ case 3:
+ createImageBitmap(aCtx, imageBitmapLoadedCallback2, 10, 10, 20, 20);
+ break;
+ case 4:
+ createImageBitmap(bitmap, checkCallback(0, 0, 10, 10));
+ break;
+ case 5:
+ createImageBitmap(bitmap, checkCallback(15, 10, 10, 10), -15, -10, 35, 40);
+ break;
+ case 6:
+ createImageBitmap(bitmap, checkCallback(0, 0, 5, 5), 5, 5, 10, 10);
+ break;
+ default:
+ finishJSTest();
+ break;
+ }
+}
+
+function shouldBeFilled(x, y, w, h) {
+ shouldBeGreen(x+2, y+2);
+ shouldBeGreen(x+w-2, y+h-2);
+ shouldBeGreen(x+w/2, y+h/2);
+ shouldBeClear(x-2, y-2);
+ shouldBeClear(x+w+2, y+h+2);
+}
+
+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, 10, 10, 40, 40);
+ // scale up w and h as necessary
+ var w2 = w1 * 40.0 / imageBitmap.width;
+ var h2 = h1 * 40.0 / imageBitmap.height;
+ // x and y are transformed
+ var x2 = x1 * w2 / w1 + 10;
+ var y2 = y1 * h2 / h1 + 10;
+ shouldBeFilled(x2, y2, w2, h2);
+
+ clearContext(ctx);
+ ctx.drawImage(imageBitmap, 0, 0, 50, 50);
+ // scale up w and h as necessary
+ var w3 = w1 * 50.0 / imageBitmap.width;
+ var h3 = h1 * 50.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, 50, 50);
+ shouldBeFilled(0, 0, 50, 50);
+
+ ++i;
+ check(i);
+ }
+}
+
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698