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 : cd399eb3ee012516b218b9d1a5fd26422ebc9be0
This commit is contained in:
Henrik Skupin 2016-12-28 14:13:31 +01:00
Родитель 468d519037
Коммит 260407fb18
2 изменённых файлов: 15 добавлений и 27 удалений

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

@ -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;

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

@ -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: