diff --git a/testing/marionette/capture.js b/testing/marionette/capture.js index 4930bf5277fb..e71faa47f194 100644 --- a/testing/marionette/capture.js +++ b/testing/marionette/capture.js @@ -91,12 +91,22 @@ capture.viewport = function (win, highlights=[]) { * has been painted on. */ capture.canvas = function (win, left, top, width, height, highlights=[]) { + let scale = win.devicePixelRatio; + let canvas = win.document.createElementNS(XHTML_NS, "canvas"); - canvas.width = width; - canvas.height = height; + canvas.width = width * scale; + canvas.height = height * scale; let ctx = canvas.getContext(CONTEXT_2D); - ctx.drawWindow(win, left, top, width, height, BG_COLOUR); + let flags = ctx.DRAWWINDOW_DRAW_CARET; + // Disabled in bug 1243415 for webplatform-test failures due to out of view elements. + // Needs https://github.com/w3c/web-platform-tests/issues/4383 fixed. + // ctx.DRAWWINDOW_DRAW_VIEW; + // Bug 1009762 - Crash in [@ mozilla::gl::ReadPixelsIntoDataSurface] + // ctx.DRAWWINDOW_USE_WIDGET_LAYERS; + + ctx.scale(scale, scale); + ctx.drawWindow(win, left, top, width, height, BG_COLOUR, flags); ctx = capture.highlight_(ctx, highlights, top, left); return canvas; diff --git a/testing/marionette/driver.js b/testing/marionette/driver.js index be2feaa2390c..c78dadb14b19 100644 --- a/testing/marionette/driver.js +++ b/testing/marionette/driver.js @@ -2409,30 +2409,8 @@ GeckoDriver.prototype.takeScreenshot = function (cmd, resp) { switch (this.context) { case Context.CHROME: - let win = this.getCurrentWindow(); - let canvas = win.document.createElementNS("http://www.w3.org/1999/xhtml", "canvas"); - let doc = win.document.documentElement; - let docRect = doc.getBoundingClientRect(); - let width = docRect.width; - let height = docRect.height; - - // Convert width and height from CSS pixels (potentially fractional) - // to device pixels (integer). - let scale = win.devicePixelRatio; - canvas.setAttribute("width", Math.round(width * scale)); - canvas.setAttribute("height", Math.round(height * scale)); - - // Bug 1075168: CanvasRenderingContext2D image is distorted when using - // certain flags in chrome context. - let flags = context.DRAWWINDOW_DRAW_VIEW | - context.DRAWWINDOW_USE_WIDGET_LAYERS; - - let context = canvas.getContext("2d"); - context.scale(scale, scale); - context.drawWindow(win, 0, 0, width, height, "rgb(255,255,255)", flags); - let dataUrl = canvas.toDataURL("image/png", ""); - let data = dataUrl.substring(dataUrl.indexOf(",") + 1); - resp.body.value = data; + let canvas = capture.viewport(this.getCurrentWindow()); + resp.body.value = capture.toBase64(canvas); break; case Context.CONTENT: