Bug 1243415 - Make use of capture.js in chrome scope. r=automatedtester a=test-only
authorHenrik Skupin <mail@hskupin.info>
Wed, 28 Dec 2016 14:13:31 +0100
changeset 353301 daf5f79fa5db751eae51ff64ca163ef018e47909
parent 353300 7a55b008ca3b60579b5b8641ace5baea761b1811
child 353302 a7da8bdcf0f7cb64dc1d84ec6a8c5659aa1d324d
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester, test-only
bugs1243415
milestone52.0a2
Bug 1243415 - Make use of capture.js in chrome scope. r=automatedtester a=test-only The screenshot code in chrome scope is updated to use the generic capture module, which is already used for content scope. By that change the code which captures the canvas makes use of devicePixelRatio now. It means the screenshot will be scaled depending on the screen configuration, eg. on Andoid this mostly 2. MozReview-Commit-ID: EBKmJEKVXPQ
testing/marionette/capture.js
testing/marionette/driver.js
--- a/testing/marionette/capture.js
+++ b/testing/marionette/capture.js
@@ -86,22 +86,32 @@ capture.viewport = function (win, highli
  *     Optional array of nodes, around which a border will be marked to
  *     highlight them in the screenshot.
  *
  * @return {HTMLCanvasElement}
  *     The canvas on which the selection from the window's framebuffer
  *     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;
 };
 
 capture.highlight_ = function (context, highlights, top=0, left=0) {
   if (!highlights) {
     return;
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -2372,40 +2372,18 @@ GeckoDriver.prototype.clearImportedScrip
  *     string.
  */
 GeckoDriver.prototype.takeScreenshot = function (cmd, resp) {
   let {id, highlights, full, hash} = cmd.parameters;
   highlights = highlights || [];
 
   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:
       if (hash) {
         return this.listener.getScreenshotHash(id, full, highlights);
       } else {
         return this.listener.takeScreenshot(id, full, highlights);
       }