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

Side by Side 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: Fix drawImage out of bounds src rect. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <html>
2 <head>
3 <script src="../js/resources/js-test-pre.js"></script>
4 </head>
5 <body>
6 <script>
7 description("Ensure correct behavior of drawImage with ImageBitmaps constructed from ImageBitmaps that are constructed from both images (not pinned to memory) a nd context (pinned to memory).");
8
9 window.jsTestIsAsync = true;
10
11 function shouldBeGreen(x, y) {
12 d = ctx.getImageData(x, y, 1, 1).data;
13 shouldBeTrue("d[0] == 0");
14 shouldBeTrue("d[1] == 255");
15 shouldBeTrue("d[2] == 0");
16 shouldBeTrue("d[3] == 255");
17 }
18 function shouldBeClear(x, y) {
19 // should be transparent black pixels
20 d = ctx.getImageData(x, y, 1, 1).data;
21 shouldBeTrue("d[0] == 0");
22 shouldBeTrue("d[1] == 0");
23 shouldBeTrue("d[2] == 0");
24 shouldBeTrue("d[3] == 0");
25 }
26 function clearContext(context) {
27 context.clearRect(0, 0, 500, 500);
28 }
29
30 var image;
31
32 var imageWidth = 200;
33 var imageHeight = 200;
34
35 var aCanvas = document.createElement("canvas");
36 aCanvas.width = imageWidth;
37 aCanvas.height = imageHeight;
38 var aCtx = aCanvas.getContext("2d");
39 aCtx.fillStyle = 'rgb(0, 255, 0)';
40 aCtx.fillRect(0, 0, 200, 200);
41
42 var canvas = document.createElement("canvas");
43 canvas.setAttribute("width", "500");
44 canvas.setAttribute("height", "500");
45 var ctx = canvas.getContext("2d");
46
47 image = new Image();
48 image.onload = imageLoaded;
49 image.src = aCanvas.toDataURL();
50
51 var imageLoaded = false;
52
53 function imageLoaded() {
54 createImageBitmap(image, imageBitmapLoadedCallback, -100, -100, 200, 200);
55 imageLoaded = true;
56 }
57
58 var i;
59
60 function imageBitmapLoadedCallback(imageBitmap) {
61 i = 0;
62 bitmap = imageBitmap;
63 check(i);
64 }
65
66 function imageBitmapLoadedCallback2(imageBitmap) {
67 ++i;
68 bitmap = imageBitmap;
69 check(i);
70 }
71
72 function check(num) {
73 switch(num) {
74 case 0:
75 createImageBitmap(bitmap, checkCallback(100, 100, 100, 100));
76 break;
77 case 1:
78 createImageBitmap(bitmap, checkCallback(200, 200, 100, 100), -100, -100, 300, 300);
79 break;
80 case 2:
81 createImageBitmap(bitmap, checkCallback(0, 0, 100, 100), 100, 100, 200, 200);
82 break;
83 case 3:
84 createImageBitmap(aCtx, imageBitmapLoadedCallback2, 100, 100, 200, 200);
85 break;
86 case 4:
87 createImageBitmap(bitmap, checkCallback(0, 0, 100, 100));
88 break;
89 case 5:
90 createImageBitmap(bitmap, checkCallback(150, 100, 100, 100), -150, -100, 350, 400);
91 break;
92 case 6:
93 createImageBitmap(bitmap, checkCallback(0, 0, 50, 50), 50, 50, 100, 100) ;
94 break;
95 default:
96 finishJSTest();
97 break;
98 }
99 }
100
101 function shouldBeFilled(x, y, w, h) {
102 shouldBeGreen(x+5, y+5);
103 shouldBeGreen(x+w-5, y+h-5);
104 shouldBeGreen(x+w/2, y+h/2);
105 shouldBeClear(x-5, y-5);
106 shouldBeClear(x+w+5, y+h+5);
107 }
108
109 function checkCallback(x, y, w, h) {
110 // x, y, w, h are the expected location of the green square
111 var x1 = x;
112 var y1 = y;
113 var w1 = w;
114 var h1 = h;
115 return function(imageBitmap) {
116 clearContext(ctx);
117 ctx.drawImage(imageBitmap, 0, 0);
118 shouldBeFilled(x1, y1, w1, h1);
119
120 clearContext(ctx);
121 ctx.drawImage(imageBitmap, 100, 100, 400, 400);
122 // scale up w and h as necessary
123 var w2 = w1 * 400.0 / imageBitmap.width;
124 var h2 = h1 * 400.0 / imageBitmap.height;
125 // x and y are transformed
126 var x2 = x1 * w2 / w1 + 100;
127 var y2 = y1 * h2 / h1 + 100;
128 shouldBeFilled(x2, y2, w2, h2);
129
130 clearContext(ctx);
131 ctx.drawImage(imageBitmap, 0, 0, 500, 500);
132 // scale up w and h as necessary
133 var w3 = w1 * 500.0 / imageBitmap.width;
134 var h3 = h1 * 500.0 / imageBitmap.height;
135 // x and y are transformed
136 var x3 = x1 * w3 / w1;
137 var y3 = y1 * h3 / h1;
138 shouldBeFilled(x3, y3, w3, h3);
139
140 clearContext(ctx);
141 ctx.drawImage(imageBitmap, x1, y1, w1, h1, 0, 0, 500, 500);
142 shouldBeFilled(0, 0, 500, 500);
143
144 ++i;
145 check(i);
146 }
147 }
148
149 </script>
150 <script src="../js/resources/js-test-post.js"></script>
151 </body>
152 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698