OLD | NEW |
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
2 <!-- Test based on that found at | 2 <!-- Test based on that found at |
3 http://http://philip.html5.org/tests/canvas/suite/tests/index.2d.composite.
globalAlpha.html | 3 http://http://philip.html5.org/tests/canvas/suite/tests/index.2d.composite.
globalAlpha.html |
4 --> | 4 --> |
5 <html> | 5 <html> |
6 <head> | 6 <head> |
7 <script src="../js/resources/js-test-pre.js"></script> | 7 <script src="../../resources/js-test.js"></script> |
8 </head> | 8 </head> |
9 <body> | 9 <body> |
10 <canvas id="canvas" width="100" height="100"></canvas> | 10 <canvas id="canvas" width="100" height="100"></canvas> |
11 <script> | 11 <script> |
12 | 12 |
13 function assertPixelApprox(ctx, x,y, r,g,b,a, pos, colour, tolerance) | 13 function assertPixelApprox(ctx, x,y, r,g,b,a, pos, colour, tolerance) |
14 { | 14 { |
15 var imgdata = ctx.getImageData(x, y, 1, 1); | 15 var imgdata = ctx.getImageData(x, y, 1, 1); |
16 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])); | 16 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])); |
17 shouldBeFalse((diff > tolerance).toString()); | 17 shouldBeFalse((diff > tolerance).toString()); |
18 } | 18 } |
19 | 19 |
20 description("The test to ensure correct sync behaviour with globalAlpha and fill
Path() in accelerated-2d-canvas mode."); | 20 description("The test to ensure correct sync behaviour with globalAlpha and fill
Path() in accelerated-2d-canvas mode."); |
21 var ctx = document.getElementById('canvas').getContext('2d'); | 21 var ctx = document.getElementById('canvas').getContext('2d'); |
22 | 22 |
23 ctx.fillStyle = '#0f0'; | 23 ctx.fillStyle = '#0f0'; |
24 ctx.fillRect(0, 0, 100, 100); | 24 ctx.fillRect(0, 0, 100, 100); |
25 ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations | 25 ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations |
26 ctx.beginPath(); | 26 ctx.beginPath(); |
27 ctx.fillStyle = '#f00'; | 27 ctx.fillStyle = '#f00'; |
28 ctx.rect(0, 0, 100, 100); | 28 ctx.rect(0, 0, 100, 100); |
29 ctx.fill(); | 29 ctx.fill(); |
30 assertPixelApprox(ctx, 50,25, 2,253,0,255, "50,25", "2,253,0,255", 2); | 30 assertPixelApprox(ctx, 50,25, 2,253,0,255, "50,25", "2,253,0,255", 2); |
31 | 31 |
32 </script> | 32 </script> |
33 </body> | 33 </body> |
34 </html> | 34 </html> |
35 | 35 |
OLD | NEW |