Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE HTML> | 1 <script src="../../resources/testharness.js"></script> |
| 2 <html> | 2 <script src="../../resources/testharnessreport.js"></script> |
| 3 <body> | 3 <script type="text/javascript" src="canvas-blending-helpers.js"></script> |
| 4 <script src="../../resources/js-test.js"></script> | 4 <script> |
| 5 <script type="text/javascript" src="canvas-blending-helpers.js"></script> | 5 test(function(t) { |
| 6 <script type="text/javascript"> | 6 var context; |
| 7 function actualColor(x, y) { | |
| 8 return context.getImageData(x, y, 1, 1).data; | |
| 9 } | |
| 7 | 10 |
| 8 description("Series of tests to ensure correct results on applying diffe rent blend modes when drawing with clipped regions."); | 11 function checkBlendModeResult(i, context, sigma) { |
| 12 var expectedColor = blendColors([129 / 255, 1, 129 / 255, 1], [1, 129 / 255, 129 / 255, 1], i); | |
| 13 var ac = actualColor(0, 0); | |
| 14 assert_approx_equals(ac[0], 0, sigma); | |
| 15 assert_approx_equals(ac[1], 0, sigma); | |
| 16 assert_approx_equals(ac[2], 0, sigma); | |
| 17 assert_approx_equals(ac[3], 0, sigma); | |
| 9 | 18 |
| 10 var context; | 19 ac = actualColor(5, 5); |
| 11 function actualColor(x, y) { | 20 assert_approx_equals(ac[0], expectedColor[0], sigma); |
| 12 return context.getImageData(x, y, 1, 1).data; | 21 assert_approx_equals(ac[1], expectedColor[1], sigma); |
| 22 assert_approx_equals(ac[2], expectedColor[2], sigma); | |
| 23 assert_approx_equals(ac[3], expectedColor[3], sigma); | |
| 24 } | |
| 25 | |
| 26 function runTest() { | |
|
Justin Novosad
2017/02/08 16:52:33
Nit: the nested function is not necessary
zakerinasab
2017/02/08 19:04:10
Done.
| |
| 27 var canvas = document.createElement("canvas"); | |
| 28 var sigma = 5; | |
| 29 canvas.width = 10; | |
| 30 canvas.height = 10; | |
| 31 context = canvas.getContext("2d"); | |
| 32 | |
| 33 for (var i = 0; i < blendModes.length; ++i) { | |
|
Justin Novosad
2017/02/08 16:52:33
Nit: this test could be unrolled with generate_tes
zakerinasab
2017/02/08 19:04:10
It can be done only if we put the each blend mode
| |
| 34 context.clearRect(0, 0, 10, 10); | |
| 35 context.save(); | |
| 36 context.beginPath(); | |
| 37 context.moveTo(3, 3); | |
| 38 context.lineTo(3, 7); | |
| 39 context.lineTo(7, 7); | |
| 40 context.lineTo(7, 3); | |
| 41 context.lineTo(3, 3); | |
| 42 context.clip(); | |
| 43 | |
| 44 drawBackdropColorInContext(context); | |
| 45 context.globalCompositeOperation = blendModes[i]; | |
| 46 drawSourceColorInContext(context); | |
| 47 checkBlendModeResult(i, context, sigma); | |
| 48 context.restore(); | |
| 13 } | 49 } |
| 50 } | |
| 51 runTest(); | |
| 52 }, 'Series of tests to ensure correct results on applying different blend modes when drawing with clipped regions.'); | |
| 53 </script> | |
| 14 | 54 |
| 15 function checkBlendModeResult(i, context, sigma) { | |
| 16 var expectedColor = blendColors([129 / 255, 1, 129 / 255, 1], [1, 12 9 / 255, 129 / 255, 1], i); | |
| 17 var ac = "actualColor(0, 0)"; | |
| 18 shouldBeCloseTo(ac + "[0]", 0, sigma); | |
| 19 shouldBeCloseTo(ac + "[1]", 0, sigma); | |
| 20 shouldBeCloseTo(ac + "[2]", 0, sigma); | |
| 21 shouldBeCloseTo(ac + "[3]", 0, sigma); | |
| 22 | |
| 23 ac = "actualColor(5, 5)"; | |
| 24 shouldBeCloseTo(ac + "[0]", expectedColor[0], sigma); | |
| 25 shouldBeCloseTo(ac + "[1]", expectedColor[1], sigma); | |
| 26 shouldBeCloseTo(ac + "[2]", expectedColor[2], sigma); | |
| 27 shouldBeCloseTo(ac + "[3]", expectedColor[3], sigma); | |
| 28 } | |
| 29 | |
| 30 function runTest() { | |
| 31 var canvas = document.createElement("canvas"); | |
| 32 var sigma = 5; | |
| 33 canvas.width = 10; | |
| 34 canvas.height = 10; | |
| 35 context = canvas.getContext("2d"); | |
| 36 | |
| 37 for (var i = 0; i < blendModes.length; ++i) { | |
| 38 debug("Testing blend mode " + blendModes[i]); | |
| 39 | |
| 40 context.clearRect(0, 0, 10, 10); | |
| 41 context.save(); | |
| 42 context.beginPath(); | |
| 43 context.moveTo(3, 3); | |
| 44 context.lineTo(3, 7); | |
| 45 context.lineTo(7, 7); | |
| 46 context.lineTo(7, 3); | |
| 47 context.lineTo(3, 3); | |
| 48 context.clip(); | |
| 49 | |
| 50 drawBackdropColorInContext(context); | |
| 51 context.globalCompositeOperation = blendModes[i]; | |
| 52 drawSourceColorInContext(context); | |
| 53 checkBlendModeResult(i, context, sigma); | |
| 54 context.restore(); | |
| 55 debug(''); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 runTest(); | |
| 60 </script> | 55 </script> |
| 61 </body> | 56 </body> |
| 62 </html> | 57 </html> |
| OLD | NEW |