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