1// The size of the golden images (DMs) 2const CANVAS_WIDTH = 600; 3const CANVAS_HEIGHT = 600; 4 5function reportSurface(surface, testname, done) { 6 // In docker, the webgl canvas is blank, but the surface has the pixel 7 // data. So, we copy it out and draw it to a normal canvas to take a picture. 8 // To be consistent across CPU and GPU, we just do it for all configurations 9 // (even though the CPU canvas shows up after flush just fine). 10 let pixels = surface.getCanvas().readPixels(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT); 11 pixels = new Uint8ClampedArray(pixels.buffer); 12 const imageData = new ImageData(pixels, CANVAS_WIDTH, CANVAS_HEIGHT); 13 14 const reportingCanvas = document.getElementById('report'); 15 reportingCanvas.getContext('2d').putImageData(imageData, 0, 0); 16 reportCanvas(reportingCanvas, testname).then(() => { 17 done(); 18 }).catch(reportError(done)); 19} 20 21 22function starPath(CanvasKit, X=128, Y=128, R=116) { 23 let p = new CanvasKit.SkPath(); 24 p.moveTo(X + R, Y); 25 for (let i = 1; i < 8; i++) { 26 let a = 2.6927937 * i; 27 p.lineTo(X + R * Math.cos(a), Y + R * Math.sin(a)); 28 } 29 return p; 30} 31