Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slideshow: pause mode refresh #10607

Merged
merged 5 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions browser/src/slideshow/SlideShowPresenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class SlideShowPresenter {
_slideShowCanvas: HTMLCanvasElement = null;
_slideShowWindowProxy: ReturnType<typeof window.open> = null;
_windowCloseInterval: ReturnType<typeof setInterval> = null;
_pauseRenderTimer: number = null;
_pauseEnterFunc: () => void;
_slideRenderer: SlideRenderer = null;
_canvasLoader: CanvasLoader | null = null;
private _pauseTimer: PauseTimerGl | PauseTimer2d;
Expand Down Expand Up @@ -392,7 +394,7 @@ class SlideShowPresenter {
overlay.style.right = '0';
overlay.style.left = '0';

overlay.style.opacity = '40%';
overlay.style.opacity = '65%';
overlay.style.backgroundColor = 'black';
overlay.style.color = 'white';

Expand Down Expand Up @@ -422,7 +424,7 @@ class SlideShowPresenter {
</head>
<body>
<div id="root-in-window"></div>
<div id="overlay-in-window" style="display: none">
<div id="overlay-in-window">
<span>${pauseText}</span>
</div>
</body>
Expand Down Expand Up @@ -454,15 +456,47 @@ class SlideShowPresenter {
else return this._slideShowWindowProxy.document;
}

_requestPauseFrame() {
if (!document.hidden) return;

const logRefresh = function () {
console.debug(
'_requestPauseFrame: after onTabSwitch pause was activated',
);
};
requestAnimationFrame(logRefresh);
}

onTabSwitch() {
const windowDocument = this._getProxyDocumentNode().documentElement;

if (document.hidden) this._stylePauseOverlay(windowDocument, true);
else this._stylePauseOverlay(windowDocument, false);

requestAnimationFrame(function ab() {
console.debug('render after onTabSwitch handler');
});
this._requestPauseFrame();
}

enablePauseHandler() {
if (this._cypressSVGPresentationTest) return;

// allow rendering in paused mode in Firefox at least 1 per sec
// Chrome doesn't draw anything when main window is hidden
this._pauseRenderTimer = this._slideShowWindowProxy.setInterval(
this._requestPauseFrame.bind(this),
1000,
);

this._pauseEnterFunc = this.onTabSwitch.bind(this);

document.addEventListener('visibilitychange', this._pauseEnterFunc);
}

disablePauseHandler() {
if (this._cypressSVGPresentationTest) return;

document.removeEventListener('visibilitychange', this._pauseEnterFunc);
this._pauseEnterFunc = undefined;
this._slideShowWindowProxy.clearInterval(this._pauseRenderTimer);
}

_doInWindowPresentation() {
Expand All @@ -488,8 +522,7 @@ class SlideShowPresenter {
return;
}

const deactivateFunc = this.onTabSwitch.bind(this);
document.addEventListener('visibilitychange', deactivateFunc);
this.enablePauseHandler();

this._getProxyDocumentNode().documentElement.innerHTML = htmlContent;
this._getProxyDocumentNode().close();
Expand Down Expand Up @@ -538,7 +571,7 @@ class SlideShowPresenter {
this._windowCloseInterval = setInterval(
function () {
if (slideShowWindow.closed) {
document.removeEventListener('visibilitychange', deactivateFunc);
this.disablePauseHandler();
clearInterval(this._windowCloseInterval);
this._slideShowNavigator.quit();
this._map.uiManager.closeSnackbar();
Expand Down
5 changes: 5 additions & 0 deletions browser/src/slideshow/Transition2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class Transition2d extends TransitionBase {
gl.clear(gl.COLOR_BUFFER_BIT);
}

if (!this.program) {
eszkadev marked this conversation as resolved.
Show resolved Hide resolved
console.error('Transition2d.render: this.program is missing');
return;
}

gl.useProgram(this.program);
gl.bindVertexArray(this.vao);
gl.uniform1f(gl.getUniformLocation(this.program, 'time'), nT);
Expand Down