Skip to content

Commit 109f6a9

Browse files
Merge pull request #20890 from calixteman/debugger_mv_checkerboard
(Debugger) Don't draw the checkerboard on the canvas but add it behind
2 parents 0e964c2 + fc286aa commit 109f6a9

4 files changed

Lines changed: 19 additions & 59 deletions

File tree

web/internal/canvas_context_details_view.js

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -62,56 +62,6 @@ const COLOR_CTX_PROPS = new Set(["fillStyle", "shadowColor", "strokeStyle"]);
6262

6363
const MATHML_NS = "http://www.w3.org/1998/Math/MathML";
6464

65-
// Cached media queries used by drawCheckerboard.
66-
const _prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
67-
const _prefersHCM = window.matchMedia("(forced-colors: active)");
68-
69-
/**
70-
* Draw a checkerboard pattern filling the canvas, to reveal transparency.
71-
* Mirrors the pattern used in src/display/editor/stamp.js.
72-
*/
73-
function drawCheckerboard(ctx, width, height) {
74-
const isHCM = _prefersHCM.matches;
75-
const isDark = _prefersDark.matches;
76-
let light, dark;
77-
if (isHCM) {
78-
light = "white";
79-
dark = "black";
80-
} else if (isDark) {
81-
light = "#8f8f9d";
82-
dark = "#42414d";
83-
} else {
84-
light = "white";
85-
dark = "#cfcfd8";
86-
}
87-
const boxDim = 15;
88-
const pattern =
89-
typeof OffscreenCanvas !== "undefined"
90-
? new OffscreenCanvas(boxDim * 2, boxDim * 2)
91-
: Object.assign(document.createElement("canvas"), {
92-
width: boxDim * 2,
93-
height: boxDim * 2,
94-
});
95-
const patternCtx = pattern.getContext("2d");
96-
if (!patternCtx) {
97-
return;
98-
}
99-
patternCtx.fillStyle = light;
100-
patternCtx.fillRect(0, 0, boxDim * 2, boxDim * 2);
101-
patternCtx.fillStyle = dark;
102-
patternCtx.fillRect(0, 0, boxDim, boxDim);
103-
patternCtx.fillRect(boxDim, boxDim, boxDim, boxDim);
104-
ctx.save();
105-
const fillPattern = ctx.createPattern(pattern, "repeat");
106-
if (!fillPattern) {
107-
ctx.restore();
108-
return;
109-
}
110-
ctx.fillStyle = fillPattern;
111-
ctx.fillRect(0, 0, width, height);
112-
ctx.restore();
113-
}
114-
11565
/**
11666
* Tracks and displays the CanvasRenderingContext2D graphics state for all
11767
* contexts created during a stepped render.
@@ -240,12 +190,6 @@ class CanvasContextDetailsView {
240190
return ctx;
241191
}
242192
if (!wrappedCtx) {
243-
if (
244-
globalThis.StepperManager._active !== null &&
245-
args[0]?.alpha !== false
246-
) {
247-
drawCheckerboard(ctx, canvas.width, canvas.height);
248-
}
249193
wrappedCtx = this.wrapContext(ctx, label);
250194
}
251195
return wrappedCtx;

web/internal/debugger.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ <h1>PDF.js — Debugging tools</h1>
6666
</div>
6767
<div id="canvas-scroll">
6868
<div id="canvas-wrapper">
69-
<canvas id="render-canvas"></canvas>
69+
<div class="canvas-checker">
70+
<canvas id="render-canvas"></canvas>
71+
</div>
7072
<canvas id="highlight-canvas" aria-hidden="true"></canvas>
7173
</div>
7274
</div>

web/internal/page_view.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,18 @@
124124
color: var(--muted-color);
125125
font-style: italic;
126126
}
127-
.temp-canvas-wrapper canvas {
127+
.canvas-checker {
128+
display: inline-block;
129+
line-height: 0;
130+
background-image: conic-gradient(
131+
light-dark(#cfcfd8, #42414d) 25%,
132+
light-dark(white, #8f8f9d) 25% 50%,
133+
light-dark(#cfcfd8, #42414d) 50% 75%,
134+
light-dark(white, #8f8f9d) 75%
135+
);
136+
background-size: 30px 30px;
137+
}
138+
.temp-canvas-wrapper .canvas-checker {
128139
border: 1px solid var(--border-subtle-color);
129140
zoom: calc(1 / var(--dpr, 1));
130141
}

web/internal/page_view.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ class PageView {
297297
const labelEl = document.createElement("div");
298298
labelEl.className = "temp-canvas-label";
299299
labelEl.textContent = `${ctxLabel}${width}×${height}`;
300-
wrapper.append(labelEl, canvasAndCtx.canvas);
300+
const checker = document.createElement("div");
301+
checker.className = "canvas-checker";
302+
checker.append(canvasAndCtx.canvas);
303+
wrapper.append(labelEl, checker);
301304
const entry = { canvasAndCtx, wrapper, labelEl };
302305
this.#alive.push(entry);
303306
this.#attachWrapper(entry);

0 commit comments

Comments
 (0)