Skip to content

Commit eef71e3

Browse files
committed
Fixed odd red and blue screenshot artifacts
1 parent 468f00b commit eef71e3

2 files changed

Lines changed: 67 additions & 14 deletions

File tree

Ports/JavaScriptPort/STATUS.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Current State
1818
- New patch (not yet CI-validated in this document revision): worker-side fallback screenshot path now waits for a host-side UI-settle barrier before ready-callback dispatch and before canvas capture, to avoid pre-paint frame capture.
1919
- Note: a short-lived `forceShow()` experiment in `BaseTest.registerReadyCallback` was reverted because it caused re-entrant callback loops and prevented `CN1SS:SUITE:FINISHED`.
2020
- New patch (not yet CI-validated in this document revision): host screenshot capture now tracks the real draw target canvas and includes off-DOM canvases reachable via host refs.
21+
- New patch (not yet CI-validated in this document revision): screenshot candidate selection now prioritizes near-screen-sized canvases to prevent tiny offscreen buffers from being selected (fixes unexpected `120x80`/`4x4` outputs).
2122

2223
What Was Fixed In This Pass
2324
---------------------------
@@ -111,6 +112,19 @@ What Was Fixed In This Pass
111112
- Motivation:
112113
- Current logs show active drawing calls while DOM-canvas snapshots remain static/white; this addresses likely off-DOM/back-buffer capture misses.
113114

115+
10. Added large-canvas gating for screenshot candidate selection.
116+
- File:
117+
- `vm/ByteCodeTranslator/src/javascript/browser_bridge.js`
118+
- Changes:
119+
- Evaluate all candidate canvases, compute max area, and prefer candidates with area >= 45% of max (with floor at 65536).
120+
- Only fall back to tiny-canvas pool if no large candidates exist.
121+
- Added diagnostics:
122+
- `PARPAR:DIAG:SCREENSHOT_START:canvasConsidered=...`
123+
- `PARPAR:DIAG:SCREENSHOT_START:canvasLargeCount=...`
124+
- `PARPAR:DIAG:SCREENSHOT_START:canvasMinLargeArea=...`
125+
- Motivation:
126+
- Latest artifacts showed mixed dimensions (`120x80`, `4x4`) and colored tiny captures, indicating offscreen utility buffers were being selected.
127+
114128
Known Failing Symptoms (Latest CI Logs/Artifacts)
115129
-------------------------------------------------
116130

@@ -135,7 +149,9 @@ Priority Next Steps
135149
1. Validate CI output after UI-settle barrier:
136150
- Expect non-identical PNG hashes for distinct tests.
137151
- Confirm `settleChanged`, `canvasSig`, and `canvasSource` diagnostics vary across tests.
138-
2. If white-frame reuse persists, capture and compare per-test `settleSig`/`canvasSig`/`canvasSource` to identify whether paint is not happening or capture target is still wrong.
152+
2. Validate size normalization after large-canvas gating:
153+
- Expect screenshot dimensions to remain consistent at app target size (no `120x80`/`4x4` non-bootstrap outputs).
154+
3. If white-frame reuse persists, capture and compare per-test `settleSig`/`canvasSig`/`canvasSource` to identify whether paint is not happening or capture target is still wrong.
139155
3. Fix per-test null receiver/init path (`__classDef` null) at first failing stack, not via broad fallbacks.
140156
4. Fix missing `Button.initLaf(UIManager)` symbol resolution in worker runtime path.
141157
5. Fix worker-mode orientation lock path so DOM access is host-bridge mediated (no direct `document` access in worker).

vm/ByteCodeTranslator/src/javascript/browser_bridge.js

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,8 @@
505505
if (!candidates.length) {
506506
return null;
507507
}
508-
var best = null;
509-
var bestArea = -1;
510-
var bestScore = -1;
511-
var bestIndex = -1;
512-
var bestSource = 'none';
513-
var bestSignature = 'none';
508+
var evaluated = [];
509+
var maxArea = -1;
514510
for (var i = 0; i < candidates.length; i++) {
515511
var c = candidates[i].canvas;
516512
if (!c || (includeDataUrl && typeof c.toDataURL !== 'function')) {
@@ -522,20 +518,58 @@
522518
var scoreMeta = canvasContentScore(c);
523519
var score = scoreMeta && scoreMeta.score != null ? (scoreMeta.score | 0) : -1;
524520
var signature = scoreMeta && scoreMeta.signature ? String(scoreMeta.signature) : 'none';
525-
if (score > bestScore || (score === bestScore && area > bestArea)) {
526-
bestScore = score;
527-
bestArea = area;
528-
best = c;
529-
bestIndex = i;
530-
bestSource = candidates[i].source || 'unknown';
531-
bestSignature = signature;
521+
evaluated.push({
522+
canvas: c,
523+
index: i,
524+
source: candidates[i].source || 'unknown',
525+
area: area,
526+
score: score,
527+
signature: signature,
528+
width: w,
529+
height: h
530+
});
531+
if (area > maxArea) {
532+
maxArea = area;
533+
}
534+
}
535+
if (!evaluated.length) {
536+
return null;
537+
}
538+
var minLargeArea = Math.max(65536, Math.floor(maxArea * 0.45));
539+
var pool = [];
540+
for (var p = 0; p < evaluated.length; p++) {
541+
if (evaluated[p].area >= minLargeArea) {
542+
pool.push(evaluated[p]);
543+
}
544+
}
545+
if (!pool.length) {
546+
pool = evaluated;
547+
}
548+
var best = null;
549+
var bestArea = -1;
550+
var bestScore = -1;
551+
var bestIndex = -1;
552+
var bestSource = 'none';
553+
var bestSignature = 'none';
554+
for (var j = 0; j < pool.length; j++) {
555+
var pick = pool[j];
556+
if (pick.score > bestScore || (pick.score === bestScore && pick.area > bestArea)) {
557+
bestScore = pick.score;
558+
bestArea = pick.area;
559+
best = pick.canvas;
560+
bestIndex = pick.index;
561+
bestSource = pick.source;
562+
bestSignature = pick.signature;
532563
}
533564
}
534565
if (!best) {
535566
return null;
536567
}
537568
var out = {
538569
canvasCount: candidates.length,
570+
canvasConsidered: evaluated.length,
571+
canvasLargeCount: pool.length,
572+
canvasMinLargeArea: minLargeArea,
539573
canvasPick: bestIndex,
540574
canvasArea: bestArea,
541575
canvasScore: bestScore,
@@ -677,6 +711,9 @@
677711
}
678712
global.__cn1LastScreenshotSignature = result.canvasSignature || '';
679713
diag('SCREENSHOT_START', 'canvasCount', result.canvasCount);
714+
diag('SCREENSHOT_START', 'canvasConsidered', result.canvasConsidered | 0);
715+
diag('SCREENSHOT_START', 'canvasLargeCount', result.canvasLargeCount | 0);
716+
diag('SCREENSHOT_START', 'canvasMinLargeArea', result.canvasMinLargeArea | 0);
680717
diag('SCREENSHOT_START', 'canvasPick', result.canvasPick);
681718
diag('SCREENSHOT_START', 'canvasArea', result.canvasArea);
682719
diag('SCREENSHOT_START', 'canvasScore', result.canvasScore);

0 commit comments

Comments
 (0)