Bug 1243415 - Make use of capture.js in chrome scope. r=automatedtester

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

--HG--
extra : rebase_source : 3d177eeac4935660f43727a20445a39fe78a2c45
This commit is contained in:
Henrik Skupin 2016-12-09 20:47:21 +01:00
Родитель de9d9c65b4
Коммит 685e8274c6
2 изменённых файлов: 13 добавлений и 27 удалений

Просмотреть файл

@ -91,12 +91,20 @@ capture.viewport = function (win, highlights=[]) {
* has been painted on. * has been painted on.
*/ */
capture.canvas = function (win, left, top, width, height, highlights=[]) { capture.canvas = function (win, left, top, width, height, highlights=[]) {
let scale = win.devicePixelRatio;
let canvas = win.document.createElementNS(XHTML_NS, "canvas"); let canvas = win.document.createElementNS(XHTML_NS, "canvas");
canvas.width = width; canvas.width = width * scale;
canvas.height = height; canvas.height = height * scale;
let ctx = canvas.getContext(CONTEXT_2D); let ctx = canvas.getContext(CONTEXT_2D);
ctx.drawWindow(win, left, top, width, height, BG_COLOUR); let flags = ctx.DRAWWINDOW_DRAW_CARET |
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); ctx = capture.highlight_(ctx, highlights, top, left);
return canvas; return canvas;

Просмотреть файл

@ -2404,30 +2404,8 @@ GeckoDriver.prototype.takeScreenshot = function (cmd, resp) {
switch (this.context) { switch (this.context) {
case Context.CHROME: case Context.CHROME:
let win = this.getCurrentWindow(); let canvas = capture.viewport(this.getCurrentWindow());
let canvas = win.document.createElementNS("http://www.w3.org/1999/xhtml", "canvas"); resp.body.value = capture.toBase64(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;
break; break;
case Context.CONTENT: case Context.CONTENT: