fix(hdr): handle translation-only matrices for clip rect support

The previous isIdentity check only caught matrix(1,0,0,1,0,0). Elements
with layout translation (e.g. right-half split at left:960px reporting
matrix(1,0,0,1,960,0)) still routed through the affine path where clip
rects are not applied.

Fix: check for translation-only matrices (scale=1, rotation=0, any tx/ty)
and route those through the region blit path. el.x/el.y from
getBoundingClientRect already include the translation, so the region path
handles positioning correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Vance Ingalls
2026-04-27 21:46:06 -07:00
co-authored by Claude Opus 4.6
parent 67d1f7195c
commit cc89d0aae2
@@ -578,22 +578,22 @@ function blitHdrVideoLayer(
clipped = true;
}
// Detect identity matrix — route through the region path (which supports
// clip rects) instead of the affine path. Chrome reports a viewport matrix
// for all HDR elements, including untransformed ones inside overflow:hidden
// wrappers. An identity matrix means no visual transform is applied.
const isIdentity = !!(
// Detect translation-only matrix (no scale/rotation) — route through the
// region path which supports clip rects. Chrome reports a viewport matrix
// for all HDR elements, even untransformed ones or those with only layout
// translation (e.g. `left: 960px` → `matrix(1,0,0,1,960,0)`). The region
// blit handles translation via el.x/el.y, so we only need the affine path
// for actual scale/rotation transforms.
const isTranslationOnly = !!(
viewportMatrix &&
viewportMatrix.length >= 6 &&
Math.abs(viewportMatrix[0]! - 1) < 0.001 &&
Math.abs(viewportMatrix[1]!) < 0.001 &&
Math.abs(viewportMatrix[2]!) < 0.001 &&
Math.abs(viewportMatrix[3]! - 1) < 0.001 &&
Math.abs(viewportMatrix[4]!) < 0.001 &&
Math.abs(viewportMatrix[5]!) < 0.001
Math.abs(viewportMatrix[3]! - 1) < 0.001
);
if (viewportMatrix && !isIdentity) {
if (viewportMatrix && !isTranslationOnly) {
if (clipped && log) {
log.debug(
`HDR clip rect on affine-transformed element ${el.id} — clip not applied (affine scissor not yet supported)`,