summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/2d.composite.globalAlpha.fillPath.html
blob: 1eafc6af5b34a0942468adf02d8c933676d776ba (plain)
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
 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<!-- Test based on that found at
     http://http://philip.html5.org/tests/canvas/suite/tests/index.2d.composite.globalAlpha.html
  -->
<html>
<head>
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<canvas id="canvas" width="100" height="100"></canvas>
<script>

function assertPixelApprox(ctx, x,y, r,g,b,a, pos, colour, tolerance)
{
    var imgdata = ctx.getImageData(x, y, 1, 1);
    var diff = Math.max(Math.abs(r-imgdata.data[0]), Math.abs(g-imgdata.data[1]), Math.abs(b-imgdata.data[2]), Math.abs(a-imgdata.data[3]));
    shouldBeFalse((diff > tolerance).toString());
}

description("The test to ensure correct sync behaviour with globalAlpha and fillPath() in accelerated-2d-canvas mode.");
var ctx = document.getElementById('canvas').getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 100);
ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations
ctx.beginPath();
ctx.fillStyle = '#f00';
ctx.rect(0, 0, 100, 100);
ctx.fill();
assertPixelApprox(ctx, 50,25, 2,253,0,255, "50,25", "2,253,0,255", 2);

</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>