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.