Bug 1812202 - Reduce the max capture dimension by 1px. r=niklas

* Captures at exactly the max dimension (32767) result in a fully transparent image.
* Import these dimensions to use in tests so we have a single source of truth
* Update the same constant in the extension

Differential Revision: https://phabricator.services.mozilla.com/D190221
This commit is contained in:
Sam Foster 2023-10-06 22:37:16 +00:00
Родитель 40cc2b8b8f
Коммит f66a0aefaa
4 изменённых файлов: 12 добавлений и 11 удалений

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

@ -27,8 +27,8 @@ const PanelOffsetY = -8;
// The max dimension for a canvas is defined https://searchfox.org/mozilla-central/rev/f40d29a11f2eb4685256b59934e637012ea6fb78/gfx/cairo/cairo/src/cairo-image-surface.c#62.
// The max number of pixels for a canvas is 124925329 or 11177 x 11177.
// We have to limit screenshots to these dimensions otherwise it will cause an error.
const MAX_CAPTURE_DIMENSION = 32767;
const MAX_CAPTURE_AREA = 124925329;
export const MAX_CAPTURE_DIMENSION = 32766;
export const MAX_CAPTURE_AREA = 124925329;
export class ScreenshotsComponentParent extends JSWindowActorParent {
async receiveMessage(message) {
@ -517,8 +517,8 @@ export var ScreenshotsUtils = {
},
/**
* The max one dimesion for a canvas is 32767 and the max canvas area is
* 124925329. If the width or height is greater than 32767 we will crop the
* The max dimension of any side of a canvas is 32767 and the max canvas area is
* 124925329. If the width or height is greater or equal to 32766 we will crop the
* screenshot to the max width. If the area is still too large for the canvas
* we will adjust the height so we can successfully capture the screenshot.
* @param {Object} rect The dimensions of the screenshot. The rect will be

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

@ -39,11 +39,11 @@ add_task(async function test_screenshot_too_large_cropped() {
ScreenshotsUtils.cropScreenshotRectIfNeeded(rect);
is(rect.width, MAX_CAPTURE_DIMENSION, "The width is 32767");
is(rect.width, MAX_CAPTURE_DIMENSION, "The width is 32766");
is(
rect.height,
Math.floor(MAX_CAPTURE_AREA / MAX_CAPTURE_DIMENSION),
"The height is 124925329 / 32767"
"The height is 124925329 / 32766"
);
rect.width = 40000;
@ -54,7 +54,7 @@ add_task(async function test_screenshot_too_large_cropped() {
is(
rect.width,
MAX_CAPTURE_DIMENSION,
"The width was cropped to the max capture dimension (32767)."
"The width was cropped to the max capture dimension (32766)."
);
rect.width = 1;
@ -65,7 +65,7 @@ add_task(async function test_screenshot_too_large_cropped() {
is(
rect.height,
MAX_CAPTURE_DIMENSION,
"The height was cropped to the max capture dimension (32767)."
"The height was cropped to the max capture dimension (32766)."
);
rect.width = 12345;

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

@ -19,8 +19,9 @@ const TEST_PAGE = TEST_ROOT + "test-page.html";
const SHORT_TEST_PAGE = TEST_ROOT + "short-test-page.html";
const LARGE_TEST_PAGE = TEST_ROOT + "large-test-page.html";
const MAX_CAPTURE_DIMENSION = 32767;
const MAX_CAPTURE_AREA = 124925329;
const { MAX_CAPTURE_DIMENSION, MAX_CAPTURE_AREA } = ChromeUtils.importESModule(
"resource:///modules/ScreenshotsUtils.sys.mjs"
);
const gScreenshotUISelectors = {
panelButtons: "#screenshotsPagePanel",

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

@ -8,7 +8,7 @@
this.takeshot = (function () {
const exports = {};
const MAX_CANVAS_DIMENSION = 32767;
const MAX_CANVAS_DIMENSION = 32766;
communication.register(
"screenshotPage",