forked from youtube/chrobalt_sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas-putImageData.html
41 lines (36 loc) · 1.61 KB
/
canvas-putImageData.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!-- Test for https://bugs.webkit.org/show_bug.cgi?id=46319 -->
<head>
<script src="resources/text-based-repaint.js"></script>
</head>
<body>
<canvas id="canvas" width="100" height="100"></canvas>
<script>
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d', {willReadFrequently: true});
// prepare imagedata
ctx.fillStyle = "rgb(255, 0, 0)"; ctx.fillRect(0, 0, 100, 100); // red background
ctx.fillStyle = "rgb(0, 255, 0)"; ctx.fillRect(10, 10, 10, 10); // inset green square
var imageDataGreen = ctx.getImageData(10, 10, 10, 10);
var imageDataRedWithInsetGreen = ctx.getImageData(0, 0, 30, 30);
// clear canvas to dark green
ctx.fillStyle = "rgb(0, 128, 0)";
ctx.fillRect(0, 0, 100, 100);
// fill target locations with dark red
ctx.fillStyle = "rgb(128, 0, 0)";
ctx.fillRect(0, 0, 10, 10);
ctx.fillRect(40, 40, 10, 10);
ctx.fillRect(80, 80, 10, 10);
window.testIsAsync = true;
function repaintTest()
{
// patch up red squares with putImageData
ctx.putImageData(imageDataGreen, 0, 0);
ctx.putImageData(imageDataGreen, 40, 40);
ctx.putImageData(imageDataRedWithInsetGreen, 70, 70, 10, 10, 10, 10);
// Because canvas invalidations are processed at the end of the current task,
// the repaint test has to end in a subsequent task in order to capture the repaint.
setTimeout(finishRepaintTest, 0);
}
window.onload = runRepaintAndPixelTest;
</script>
</body>