From 83ad9dfa79374cae8551072527816d2015a98dbe Mon Sep 17 00:00:00 2001 From: The412Banner Date: Sat, 19 Sep 2026 17:19:19 -0400 Subject: [PATCH] Re-arm frame generation when the presenting window changes Opening the Steam menu over a fullscreen game and closing it again left the game as a strip in a corner with an engine on. gamescope forwards a fullscreen game's own buffers straight through and hands over its composited output while the menu is up; each is a different window to the compositor, and the engine's ring and history straddled the switch. The compositor already reports every change of presenting window, so the engine is disarmed on it and re-armed against the new one, as it is across a Surface resize. --- .../java/com/steamdeck/launcher/SessionActivity.kt | 3 +++ .../java/com/steamdeck/launcher/session/PerfHud.kt | 13 ++++++++++++- .../steamdeck/launcher/wayland/CompositorHost.kt | 13 +++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt index 37a33ad8ed..fdba4801d3 100644 --- a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt @@ -104,6 +104,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { loading = LoadingState(this) hud = PerfHud(this) + hud.onPresentingWindowChanged = { + if (FrameGen.engine(this) != FrameGen.ENGINE_OFF) CompositorHost.rearmFrameGen { applyFrameGen() } + } // A session that has already drawn is past its milestones; do not cover its picture. if (SessionState.running && SessionState.firstFrameSeen) { loading.visible = false diff --git a/app/src/main/java/com/steamdeck/launcher/session/PerfHud.kt b/app/src/main/java/com/steamdeck/launcher/session/PerfHud.kt index 864da2354f..5256f836cf 100644 --- a/app/src/main/java/com/steamdeck/launcher/session/PerfHud.kt +++ b/app/src/main/java/com/steamdeck/launcher/session/PerfHud.kt @@ -38,8 +38,19 @@ class PerfHud(context: Context) { get() = SessionPrefs.hudEnabled(context) && !File(Environment.getExternalStorageDirectory(), "Download/steamdeck-no-hud").exists() + /** Told, on the main thread, when the window presenting frames changes. */ + var onPresentingWindowChanged: (() -> Unit)? = null + private var lastWindow: String? = null + private val listener = object : WaylandCompositor.GameListener { - override fun onGameSurface(window: String?, gpuName: String?) {} + override fun onGameSurface(window: String?, gpuName: String?) { + // gamescope forwards a fullscreen game's own buffers straight through and its composited + // output when the Steam menu is up; each is a different window here. Compositor thread. + if (window != null && window != lastWindow) { + lastWindow = window + handler.post { onPresentingWindowChanged?.invoke() } + } + } override fun onGameFrame() { frames.incrementAndGet() } } diff --git a/app/src/main/java/com/steamdeck/launcher/wayland/CompositorHost.kt b/app/src/main/java/com/steamdeck/launcher/wayland/CompositorHost.kt index e5c73c1e6b..4cc47698ce 100644 --- a/app/src/main/java/com/steamdeck/launcher/wayland/CompositorHost.kt +++ b/app/src/main/java/com/steamdeck/launcher/wayland/CompositorHost.kt @@ -70,6 +70,19 @@ object CompositorHost { android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(rearm, 600) } + /** + * The window the guest presents through has changed (the Steam menu opening or closing over a + * fullscreen game swaps gamescope between forwarding the game's own buffers and its composited + * output). The engine's ring and history straddle that switch and come back wrong-sized — a + * game shown as a strip in a corner — so it is disarmed and re-armed against the new window. + */ + fun rearmFrameGen(rearm: () -> Unit) { + if (!started) return + WaylandCompositor.nativeSetFrameGenArmed(false, 0) + WaylandCompositor.nativeLog("screen", "presenting window changed: frame generation re-armed") + android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(rearm, 600) + } + /** * The activity is going away. The compositor keeps running with nothing to present into — * the guest carries on, and its next frames land on the Surface the next activity brings.