1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/context/context-attribute-preserve-drawing-buffer.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,113 @@ 1.4 +<!-- 1.5 +Copyright (C) 2012 Opera Software ASA. All rights reserved. 1.6 + 1.7 +Redistribution and use in source and binary forms, with or without 1.8 +modification, are permitted provided that the following conditions 1.9 +are met: 1.10 +1. Redistributions of source code must retain the above copyright 1.11 + notice, this list of conditions and the following disclaimer. 1.12 +2. Redistributions in binary form must reproduce the above copyright 1.13 + notice, this list of conditions and the following disclaimer in the 1.14 + documentation and/or other materials provided with the distribution. 1.15 + 1.16 +THIS SOFTWARE IS PROVIDED BY OPERA SOFTWARE ASA. ''AS IS'' AND ANY 1.17 +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.18 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.19 +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 1.20 +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.21 +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.22 +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.23 +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 1.24 +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.25 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.26 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.27 + --> 1.28 +<!DOCTYPE html> 1.29 +<html> 1.30 + <head> 1.31 + <meta charset="utf-8"> 1.32 + <link rel="stylesheet" href="../../resources/js-test-style.css"/> 1.33 + <script src="../../resources/js-test-pre.js"></script> 1.34 + <script src="../resources/webgl-test.js"></script> 1.35 + <style> 1.36 + canvas { 1.37 + width:50px; 1.38 + height:50px; 1.39 + } 1.40 + .square { 1.41 + display:inline-block; 1.42 + width:50px; 1.43 + height:50px; 1.44 + background-color:red; 1.45 + } 1.46 + </style> 1.47 + <script> 1.48 + function checkResult(ctx1, ctx2, preserve) { 1.49 + var imgData1 = ctx1.getImageData(0,0,1,1); 1.50 + var imgData2 = ctx2.getImageData(0,0,1,1); 1.51 + var correct1 = [255,0,0,255]; 1.52 + var correct2 = preserve ? [255,0,0,255] : [0,0,0,255]; 1.53 + var ok1 = true; 1.54 + var ok2 = true; 1.55 + for (var p = 0; p < 4; ++p) { 1.56 + if (imgData1.data[p] != correct1[p]) 1.57 + ok1 = false; 1.58 + if (imgData2.data[p] != correct2[p]) 1.59 + ok2 = false; 1.60 + } 1.61 + if (ok1 && ok2) 1.62 + testPassed('Rendered ok with preserveDrawingBuffer ' + preserve +'.'); 1.63 + else 1.64 + testFailed('Did not render ok with preserveDrawingBuffer ' + preserve + '.'); 1.65 + if (preserve) { 1.66 + debug('<br /><span class="pass">TEST COMPLETE</span>'); 1.67 + notifyFinishedToHarness() 1.68 + } else { 1.69 + runTest(true); 1.70 + } 1.71 + } 1.72 + 1.73 + function runTest(preserve) { 1.74 + var c1 = document.getElementById('c' + (preserve * 3 + 1)); 1.75 + var c2 = document.getElementById('c' + (preserve * 3 + 2)); 1.76 + var c3 = document.getElementById('c' + (preserve * 3 + 3)); 1.77 + var ctx1 = c1.getContext('2d'); 1.78 + var ctx2 = c2.getContext('2d'); 1.79 + var gl = c3.getContext('experimental-webgl', { alpha:false, preserveDrawingBuffer:preserve }); 1.80 + gl.clearColor(1, 0, 0, 1); 1.81 + gl.clear(gl.COLOR_BUFFER_BIT); 1.82 + ctx1.drawImage(c3, 0, 0); 1.83 + setTimeout(function() { ctx2.drawImage(c3, 0, 0); checkResult(ctx1, ctx2, preserve); }, 100); 1.84 + 1.85 + } 1.86 + </script> 1.87 + </head> 1.88 + <body> 1.89 + <div> 1.90 + <canvas id='c1'></canvas> 1.91 + <canvas id='c2'></canvas> 1.92 + <canvas id='c3'></canvas> 1.93 + <span>should look as right pattern</span> 1.94 + <div class='square'></div> 1.95 + <div class='square' style='background-color:black'></div> 1.96 + <div class='square'></div> 1.97 + </div> 1.98 + <div> 1.99 + <canvas id='c4'></canvas> 1.100 + <canvas id='c5'></canvas> 1.101 + <canvas id='c6'></canvas> 1.102 + <span>should look as right pattern</span> 1.103 + <div class='square'></div> 1.104 + <div class='square'></div> 1.105 + <div class='square'></div> 1.106 + </div> 1.107 + <div id="description"></div> 1.108 + <div id="console"></div> 1.109 + <script> 1.110 + description('Verify that preserveDrawingBuffer attribute is honored.'); 1.111 + runTest(false); 1.112 + successfullyParsed = true; 1.113 + shouldBeTrue("successfullyParsed"); 1.114 + </script> 1.115 + </body> 1.116 +</html>