Skip to content
Closed
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
17 changes: 17 additions & 0 deletions android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ fixed member mtimes, `--sort=name` order, `uid/gid 0` — so identical inputs
rebuild to byte-identical `.tzst` bytes. The dated filename is a name only; it
does not enter the archive.

## Wine's root desktop: `GAMENATIVE_ROOT_DESKTOP`

The app launches a game either inside Wine's virtual desktop
(`explorer /desktop=shell,WxH`, one top-level X window with the game nested in
it) or on Wine's root desktop (`explorer /desktop=root`, each game window a
managed top-level X window, as upstream gamescope expects). Three patches exist
only for the virtual desktop. The app sets `GAMENATIVE_ROOT_DESKTOP` in
gamescope's environment, and gamescope reads it once at startup:

| value | effect |
|---|---|
| unset, `0` or anything else | virtual desktop: A26, A33 and A48 act as described in their headers |
| `1` | root desktop: A26 leaves upstream's app id (the X window id), A33 never blanks, A48 never sends its bring-to-front request |

Under `1` the uniform app id is gone, so a `gamescope_control` performance-stats
request for that id matches no window.

## Related projects

This tree is only the display server. The pieces it stages but does not build:
Expand Down
30 changes: 25 additions & 5 deletions android/patches/gamescope/0026-A26-uniform-app-id.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
A26 — one uniform app id for every window

GAMENATIVE_ROOT_DESKTOP=1 (wine's root desktop, set by the app) turns the
override off: both sites keep upstream's appID = X window id. The helper
that reads the variable lives here so that A33 and A48 can use it too.
Unset or any other value keeps the uniform id.

diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
index 8eb47a4..cd305bb 100644
--- a/src/steamcompmgr.cpp
+++ b/src/steamcompmgr.cpp
@@ -1547,6 +1547,18 @@
@@ -1547,6 +1547,29 @@ bool steamcompmgr_window_should_refresh_switch( steamcompmgr_win_t *w )
#define SCREEN_SCALE_PROP "STEAM_SCREEN_SCALE"
#define SCREEN_MAGNIFICATION_PROP "STEAM_SCREEN_MAGNIFICATION"

Expand All @@ -15,25 +24,36 @@
+// with no cross-process channel and no file I/O. The app side (GameNative
+// GameNativeDrm.GAMESCOPE_APP_ID) must use the same value.
+static constexpr uint32_t kGameNativeUniformAppId = 1;
+
+// GameNative: GAMENATIVE_ROOT_DESKTOP=1 says the guest runs on wine's root
+// desktop (explorer /desktop=root): every game window is a managed top-level X
+// window, as upstream expects. The patches written for wine's virtual desktop
+// (this uniform app id, A33's blank, A48's bring-to-front) then stand down.
+// Unset or any other value keeps them active. Read once, at startup.
+static const bool g_bGameNativeRootDesktop = []
+{
+ const char *pszRootDesktop = getenv( "GAMENATIVE_ROOT_DESKTOP" );
+ return pszRootDesktop != nullptr && strcmp( pszRootDesktop, "1" ) == 0;
+}();
+
#define TRANSLUCENT 0x00000000
#define OPAQUE 0xffffffff

@@ -5841,7 +5853,7 @@
@@ -5817,7 +5840,7 @@ map_win(xwayland_ctx_t* ctx, Window id, unsigned long sequence)
}
else
{
- w->appID = w->xwayland().id;
+ w->appID = kGameNativeUniformAppId;
+ w->appID = g_bGameNativeRootDesktop ? w->xwayland().id : kGameNativeUniformAppId;
}

if ( w->isSteamLegacyBigPicture )
@@ -6072,7 +6084,7 @@
@@ -6048,7 +6071,7 @@ add_win(xwayland_ctx_t *ctx, Window id, Window prev, unsigned long sequence)
}
else
{
- new_win->appID = id;
+ new_win->appID = kGameNativeUniformAppId;
+ new_win->appID = g_bGameNativeRootDesktop ? id : kGameNativeUniformAppId;
}

if ( new_win->isExternalOverlay )
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ desktop does when the game's window goes away, and what a recreate does not do.
The blind's one-shot log line states the stamped id and the newest done commit
id at every transition, so the panel evidence can be tied to the comparison.

GAMENATIVE_ROOT_DESKTOP=1 (wine's root desktop, read in A26) switches the
blank off: there is no virtual desktop window to hide, so neither the
startup/absence blind nor the reaper-end blank is raised, no per-window
state is stamped and no extra frame is painted at shutdown. The log line
states root_desktop= so a session shows which mode it ran in. The blank
texture's output-size extent (rendervulkan.cpp) is not switched; it is not a
blank by itself. Unset or any other value keeps all of the above.

diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
index 54e4efc..f3f914a 100644
--- a/src/rendervulkan.cpp
Expand All @@ -64,10 +72,10 @@ index 54e4efc..f3f914a 100644
return vulkan_create_flat_texture( width, height, 0, 0, 0, 0 );
}
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
index 2dfdd7f..e9ec9a7 100644
index ee14377..65307ae 100644
--- a/src/steamcompmgr.cpp
+++ b/src/steamcompmgr.cpp
@@ -3131,6 +3131,125 @@ gamescope::ConVar<bool> cv_paint_external_overlay_plane{ "paint_external_overlay
@@ -3142,6 +3142,125 @@ gamescope::ConVar<bool> cv_paint_external_overlay_plane{ "paint_external_overlay
gamescope::ConVar<bool> cv_paint_cursor_plane{ "paint_cursor_plane", true };
gamescope::ConVar<bool> cv_paint_mura_plane{ "paint_mura_plane", true };

Expand Down Expand Up @@ -193,24 +201,26 @@ index 2dfdd7f..e9ec9a7 100644
static void
paint_all( global_focus_t *pFocus, bool async )
{
@@ -3170,6 +3289,40 @@ paint_all( global_focus_t *pFocus, bool async )
@@ -3181,6 +3300,42 @@ paint_all( global_focus_t *pFocus, bool async )
// Decide the fit target once so the window planes and the cursor plane agree.
fit = override;

+ // A33: once the reaper has ended the session, wine's desktop window is all
+ // that is left to composite, so the frame is a black plane in place of
+ // every window. This round the same blind is raised earlier -- whenever the
+ // game's window is gone while the session is still alive -- so the desktop
+ // blue is not what the panel is left holding at either transition.
+ bool bSessionBlank = g_bSessionEndBlank || session_game_window_absent( w );
+ // blue is not what the panel is left holding at either transition. On
+ // wine's root desktop there is no desktop window to hide: never blank.
+ bool bSessionBlank = !g_bGameNativeRootDesktop && ( g_bSessionEndBlank || session_game_window_absent( w ) );
+
+ // One-shot stated outcome, raised on every change of the blind's state.
+ static int s_nLastBlankState = -1;
+ if ( ( bSessionBlank ? 1 : 0 ) != s_nLastBlankState )
+ {
+ s_nLastBlankState = bSessionBlank ? 1 : 0;
+ s_SessionBlankLogScope.infof( "blank=%d reaper=%d window=%s override_bound=%d saw_game_window=%d bound_commit=%lu gap_commit=%lu last_done_commit=%lu",
+ s_SessionBlankLogScope.infof( "blank=%d root_desktop=%d reaper=%d window=%s override_bound=%d saw_game_window=%d bound_commit=%lu gap_commit=%lu last_done_commit=%lu",
+ s_nLastBlankState,
+ g_bGameNativeRootDesktop ? 1 : 0,
+ g_bSessionEndBlank ? 1 : 0,
+ w ? "present" : "none",
+ ( w && w->type == steamcompmgr_win_type_t::XWAYLAND && w->xwayland().surface.override_surface != nullptr ) ? 1 : 0,
Expand All @@ -234,7 +244,7 @@ index 2dfdd7f..e9ec9a7 100644
if (++frameCounter == 300)
{
currentFrameRate = 300 * 1000.0f / (currentTime - lastSampledFrameTime);
@@ -3201,7 +3354,11 @@ paint_all( global_focus_t *pFocus, bool async )
@@ -3212,7 +3367,11 @@ paint_all( global_focus_t *pFocus, bool async )
// find the video underlay and put it up first in the scenegraph
if ( cv_paint_primary_plane )
{
Expand All @@ -247,18 +257,20 @@ index 2dfdd7f..e9ec9a7 100644
{
if ( w->isSteamStreamingClient == true )
{
@@ -9464,6 +9621,10 @@ void LaunchNestedChildren( char **ppPrimaryChildArgv )
@@ -9475,6 +9634,12 @@ void LaunchNestedChildren( char **ppPrimaryChildArgv )
gamescope::Process::WaitForChild( nPrimaryChildPid );
s_LaunchLogScope.infof( "Primary child shut down!" );

+ // The reaper has ended the session: the compositor's only remaining
+ // client is wine's desktop window, so hold the output black.
+ g_bSessionEndBlank = true;
+ // client is wine's desktop window, so hold the output black. On
+ // wine's root desktop there is none, and no blank is raised.
+ if ( !g_bGameNativeRootDesktop )
+ g_bSessionEndBlank = true;
+
if ( cv_shutdown_on_primary_child_death )
ShutdownGamescope();
});
@@ -10057,6 +10218,14 @@ steamcompmgr_main(int argc, char **argv)
@@ -10068,6 +10233,14 @@ steamcompmgr_main(int argc, char **argv)

if ( g_bRun == false )
{
Expand All @@ -274,7 +286,7 @@ index 2dfdd7f..e9ec9a7 100644
}

diff --git a/src/steamcompmgr_shared.hpp b/src/steamcompmgr_shared.hpp
index c344d10..c8d8da5 100644
index c344d10..23bd2d4 100644
--- a/src/steamcompmgr_shared.hpp
+++ b/src/steamcompmgr_shared.hpp
@@ -161,6 +161,25 @@ struct steamcompmgr_win_t {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ Verified on the Odin 3: sent at map time the game goes live (pad, keyboard,
continuous XInput polling); sent after the game has hidden its window it
does nothing, so the map event is the only usable trigger.

GAMENATIVE_ROOT_DESKTOP=1 (wine's root desktop, read in A26) switches the
request off: each game window is then a managed top-level window that the
compositor maps and focuses itself, so no nested map sends anything. Unset
or any other value keeps the request.

diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
index 5f4f19c..adafff0 100644
index 65307ae..726f2ef 100644
--- a/src/steamcompmgr.cpp
+++ b/src/steamcompmgr.cpp
@@ -68,6 +68,7 @@
Expand All @@ -35,7 +40,7 @@ index 5f4f19c..adafff0 100644
#include <sys/resource.h>
#include <time.h>
#include <unistd.h>
@@ -5919,6 +5920,46 @@ handle_desktop_window(steamcompmgr_win_t *w)
@@ -5968,6 +5969,49 @@ handle_desktop_window(steamcompmgr_win_t *w)
}
}

Expand Down Expand Up @@ -64,6 +69,9 @@ index 5f4f19c..adafff0 100644
+
+static void gn_activate_nested_app_window( xwayland_ctx_t *ctx, Window window )
+{
+ // Wine's root desktop maps game windows as managed top-level windows.
+ if ( g_bGameNativeRootDesktop )
+ return;
+ XClassHint hint = {};
+ if ( !XGetClassHint( ctx->dpy, window, &hint ) )
+ return;
Expand All @@ -82,7 +90,7 @@ index 5f4f19c..adafff0 100644
static void
map_win(xwayland_ctx_t* ctx, Window id, unsigned long sequence)
{
@@ -8788,6 +8829,8 @@ void xwayland_ctx_t::Dispatch()
@@ -8837,6 +8881,8 @@ void xwayland_ctx_t::Dispatch()

if (w && w->xwayland().id == ev.xmap.window)
map_win(ctx, ev.xmap.window, ev.xmap.serial);
Expand Down
Loading