Skip to content

Commit b09bab9

Browse files
committed
@
fix(screen-adapter): debounce resize handler to prevent black flicker on web The window resize event listener in _registerEvent() was calling _resizeFrame() synchronously on every resize event. During continuous window dragging, this triggered dozens of swapchain/backbuffer reallocations per second, each producing a blank (black) frame. This change debounces the resize handler using the same EVENT_TIMEOUT (200ms) and setTimeout pattern already used by the orientation change handler. It also adds the handleResizeEvent guard to the DPR matchMedia listener, which was previously bypassing it. Fixes: #19182 @
1 parent ab66819 commit b09bab9

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

pal/screen-adapter/src/web/screen-adapter.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class ScreenAdapter extends EventTarget {
183183
private _onFullscreenError?: () => void;
184184
// We need to set timeout to handle screen event.
185185
private _orientationChangeTimeoutId = -1;
186+
private _resizeTimeoutId = -1;
186187
private _cachedFrameSize = new Size(0, 0); // cache before enter fullscreen.
187188
private _exactFitScreen = false;
188189
private _isHeadlessMode = false;
@@ -381,13 +382,22 @@ class ScreenAdapter extends EventTarget {
381382
if (!this.handleResizeEvent) {
382383
return;
383384
}
384-
this._resizeFrame();
385+
if (this._resizeTimeoutId !== -1) {
386+
clearTimeout(this._resizeTimeoutId);
387+
}
388+
this._resizeTimeoutId = setTimeout((): void => {
389+
this._resizeFrame();
390+
this._resizeTimeoutId = -1;
391+
}, EVENT_TIMEOUT);
385392
});
386393
if (typeof window.matchMedia === 'function') {
387394
const updateDPRChangeListener = (): void => {
388395
const dpr = window.devicePixelRatio;
389396
// NOTE: some browsers especially on iPhone doesn't support MediaQueryList
390397
window.matchMedia(`(resolution: ${dpr}dppx)`)?.addEventListener?.('change', (): void => {
398+
if (!this.handleResizeEvent) {
399+
return;
400+
}
391401
this.emit('window-resize', this.windowSize.width, this.windowSize.height);
392402
updateDPRChangeListener();
393403
}, { once: true });

0 commit comments

Comments
 (0)