@@ -2208,112 +2208,9 @@ def make_reftest(self, expected):
22082208 # make sure the pngs used here have no color correction, using e.g.
22092209 # pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB infile outfile
22102210 shutil .copy (expected , 'expected.png' )
2211- create_file ('reftest.js' , '''
2212- // We have some tests that don't perform rendering during `main` so
2213- // the normal process of performing `doReftest` in `postRun` doesn't
2214- // work. These tests can delay the call to `doReftest` by calling
2215- // `reftestBlock` and then calling `reftestUnblock` once they have
2216- // done their rendering.
2217- var reftestBlocked = false;
2218- function reftestBlock() {
2219- reftestBlocked = true;
2220- }
2221- function reftestUnblock() {
2222- reftestBlocked = false;
2223- doReftest();
2224- }
2225- function doReftest() {
2226- if (reftestBlocked) return;
2227- if (doReftest.done) return;
2228- doReftest.done = true;
2229- console.log('doReftest');
2230- var img = new Image();
2231- img.onload = () => {
2232- assert(img.width == Module.canvas.width, `Invalid width: ${Module.canvas.width}, should be ${img.width}`);
2233- assert(img.height == Module.canvas.height, `Invalid height: ${Module.canvas.height}, should be ${img.height}`);
2234-
2235- var canvas = document.createElement('canvas');
2236- canvas.width = img.width;
2237- canvas.height = img.height;
2238- var ctx = canvas.getContext('2d');
2239- ctx.drawImage(img, 0, 0);
2240- var expected = ctx.getImageData(0, 0, img.width, img.height).data;
2241-
2242- var actualUrl = Module.canvas.toDataURL();
2243- var actualImage = new Image();
2244- actualImage.onload = () => {
2245- /*
2246- document.body.appendChild(img); // for comparisons
2247- var div = document.createElement('div');
2248- div.innerHTML = '^=expected, v=actual';
2249- document.body.appendChild(div);
2250- document.body.appendChild(actualImage); // to grab it for creating the test reference
2251- */
2252-
2253- var actualCanvas = document.createElement('canvas');
2254- actualCanvas.width = actualImage.width;
2255- actualCanvas.height = actualImage.height;
2256- var actualCtx = actualCanvas.getContext('2d');
2257- actualCtx.drawImage(actualImage, 0, 0);
2258- var actual = actualCtx.getImageData(0, 0, actualImage.width, actualImage.height).data;
2259-
2260- var total = 0;
2261- var width = img.width;
2262- var height = img.height;
2263- for (var x = 0; x < width; x++) {
2264- for (var y = 0; y < height; y++) {
2265- total += Math.abs(expected[y*width*4 + x*4 + 0] - actual[y*width*4 + x*4 + 0]);
2266- total += Math.abs(expected[y*width*4 + x*4 + 1] - actual[y*width*4 + x*4 + 1]);
2267- total += Math.abs(expected[y*width*4 + x*4 + 2] - actual[y*width*4 + x*4 + 2]);
2268- }
2269- }
2270- // floor, to allow some margin of error for antialiasing
2271- var wrong = Math.floor(total / (img.width*img.height*3));
2272- var rebaseline = %s;
2273- if (wrong || rebaseline) {
2274- // Generate a png of the actual rendered image and send it back
2275- // to the server.
2276- Module.canvas.toBlob((blob) => {
2277- sendFileToServer('actual.png', blob);
2278- reportResultToServer(wrong);
2279- })
2280- } else {
2281- reportResultToServer(wrong);
2282- }
2283- };
2284- actualImage.src = actualUrl;
2285- }
2286- img.src = 'expected.png';
2287- };
2288-
2289- /** @suppress {uselessCode} */
2290- function setupRefTest() {
2291- Module['postRun'] = doReftest;
2292-
2293- if (typeof WebGLClient !== 'undefined') {
2294- // trigger reftest from RAF as well, needed for workers where there is no pre|postRun on the main thread
2295- var realRAF = window.requestAnimationFrame;
2296- /** @suppress{checkTypes} */
2297- window.requestAnimationFrame = (func) => {
2298- return realRAF(() => {
2299- func();
2300- realRAF(doReftest);
2301- });
2302- };
2303-
2304- // trigger reftest from canvas render too, for workers not doing GL
2305- var realWOM = worker.onmessage;
2306- worker.onmessage = (event) => {
2307- realWOM(event);
2308- if (event.data.target === 'canvas' && event.data.op === 'render') {
2309- realRAF(doReftest);
2310- }
2311- };
2312- }
2313- }
2314-
2315- setupRefTest();
2316- ''' % EMTEST_REBASELINE )
2211+ create_file ('reftest.js' , f'''
2212+ const reftestRebaseline = { EMTEST_REBASELINE } ;
2213+ ''' + read_file (test_file ('reftest.js' )))
23172214
23182215 def compile_btest (self , filename , args , reporting = Reporting .FULL ):
23192216 # Inject support code for reporting results. This adds an include a header so testcases can
0 commit comments