From 0a703c2cc670b9dc7111a89d2b4109e4e5fd6076 Mon Sep 17 00:00:00 2001 From: sharkautarch <128002472+sharkautarch@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:12:29 -0400 Subject: [PATCH] steamcompmgr, etc: {g_nNestedWidth, g_nNestedHeight} -> g_ivNestedResolution color_helpers: enable using structured bindings w/ glm::vec --- src/Backends/OpenVRBackend.cpp | 2 +- src/Backends/WaylandBackend.cpp | 2 +- src/color_helpers.h | 53 +++++++++++++++++++++++++++++++++ src/main.cpp | 18 +++++------ src/main.hpp | 4 +-- src/steamcompmgr.cpp | 5 ++-- src/wlserver.cpp | 10 +++---- 7 files changed, 72 insertions(+), 22 deletions(-) diff --git a/src/Backends/OpenVRBackend.cpp b/src/Backends/OpenVRBackend.cpp index c4de4aca83..54722778ca 100644 --- a/src/Backends/OpenVRBackend.cpp +++ b/src/Backends/OpenVRBackend.cpp @@ -250,7 +250,7 @@ namespace gamescope bool UpdateEdid() { - m_FakeEdid = GenerateSimpleEdid( g_nNestedWidth, g_nNestedHeight ); + m_FakeEdid = GenerateSimpleEdid( g_ivNestedResolution.x, g_ivNestedResolution.y ); return true; } diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp index 6498f3b491..49535e16e9 100644 --- a/src/Backends/WaylandBackend.cpp +++ b/src/Backends/WaylandBackend.cpp @@ -811,7 +811,7 @@ namespace gamescope bool CWaylandConnector::UpdateEdid() { - m_FakeEdid = GenerateSimpleEdid( g_nNestedWidth, g_nNestedHeight ); + m_FakeEdid = GenerateSimpleEdid( g_ivNestedResolution.x, g_ivNestedResolution.y ); return true; } diff --git a/src/color_helpers.h b/src/color_helpers.h index 66213e1594..f3827fcdde 100644 --- a/src/color_helpers.h +++ b/src/color_helpers.h @@ -11,6 +11,59 @@ #include // glm::vec3 #include // glm::mat3 #include +///////////////////////////////////////////////////////// +// Stuff for using structured bindings with glm::vec: // +///////////////////////////////////////////////////////// +namespace std +{ +#define MK_TUPLE_SIZE(size, type) \ + template<> \ + struct tuple_size< ::glm::vec > : \ + std::integral_constant { } + +# define MK_TUPLE_ELEMENT(size) \ + template \ + struct tuple_element> : std::type_identity \ + { \ + using type = T; \ + } + + MK_TUPLE_SIZE(2, int); + MK_TUPLE_SIZE(2, float); + MK_TUPLE_SIZE(2, unsigned); + + MK_TUPLE_SIZE(3, int); + MK_TUPLE_SIZE(3, float); + MK_TUPLE_SIZE(3, unsigned); + + MK_TUPLE_SIZE(4, int); + MK_TUPLE_SIZE(4, float); + MK_TUPLE_SIZE(4, unsigned); + + MK_TUPLE_ELEMENT(2); + MK_TUPLE_ELEMENT(3); + MK_TUPLE_ELEMENT(4); +} + +namespace glm { +# define INSTANTIATE(qualifier) \ + template< std::size_t I > \ + auto qualifier \ + get( auto qualifier v ) noexcept { \ + if constexpr (I == 0) return v.x; \ + if constexpr (I == 1) return v.y; \ + if constexpr (I == 2) return v.z; \ + if constexpr (I == 3) return v.w; \ + } + + INSTANTIATE(&) + INSTANTIATE(const&) + INSTANTIATE(&&) + INSTANTIATE(const&&) +} +///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// + // Color utils inline int quantize( float fVal, float fMaxVal ) diff --git a/src/main.cpp b/src/main.cpp index ca4001249f..05d8db9e8a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -269,8 +269,7 @@ const char usage[] = std::atomic< bool > g_bRun{true}; -int g_nNestedWidth = 0; -int g_nNestedHeight = 0; +glm::ivec2 g_ivNestedResolution {}; int g_nNestedRefresh = 0; int g_nNestedUnfocusedRefresh = 0; int g_nNestedDisplayIndex = 0; @@ -678,10 +677,10 @@ int main(int argc, char **argv) const char *opt_name; switch (o) { case 'w': - g_nNestedWidth = atoi( optarg ); + g_ivNestedResolution.x = atoi( optarg ); break; case 'h': - g_nNestedHeight = atoi( optarg ); + g_ivNestedResolution.y = atoi( optarg ); break; case 'r': g_nNestedRefresh = gamescope::ConvertHztomHz( atoi( optarg ) ); @@ -918,18 +917,17 @@ int main(int argc, char **argv) } } - if ( g_nNestedHeight == 0 ) + if ( g_ivNestedResolution.y == 0 ) { - if ( g_nNestedWidth != 0 ) + if ( g_ivNestedResolution.x != 0 ) { fprintf( stderr, "Cannot specify -w without -h\n" ); return 1; } - g_nNestedWidth = g_nOutputWidth; - g_nNestedHeight = g_nOutputHeight; + g_ivNestedResolution = glm::ivec2 { g_nOutputWidth, g_nOutputHeight }; } - if ( g_nNestedWidth == 0 ) - g_nNestedWidth = g_nNestedHeight * 16 / 9; + if ( g_ivNestedResolution.x == 0 ) + g_ivNestedResolution.x = g_ivNestedResolution.y * 16 / 9; if ( !wlserver_init() ) { diff --git a/src/main.hpp b/src/main.hpp index 2e6fb833af..e2d62baada 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -8,9 +8,9 @@ extern const char *gamescope_optstring; extern const struct option *gamescope_options; extern std::atomic< bool > g_bRun; +#include -extern int g_nNestedWidth; -extern int g_nNestedHeight; +extern glm::ivec2 g_ivNestedResolution; extern int g_nNestedRefresh; // mHz extern int g_nNestedUnfocusedRefresh; // mHz extern int g_nNestedDisplayIndex; diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index ef9a73fc59..dc28e212f7 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -1272,8 +1272,7 @@ window_is_fullscreen( steamcompmgr_win_t *w ) glm::vec2 calc_scale_factor_scaler(float sourceWidth, float sourceHeight) { auto sourceDimensions = glm::vec2 {sourceWidth, sourceHeight}; - auto nestedResolution = glm::vec2 { (float) g_nNestedWidth, (float) g_nNestedHeight }; - auto outputRatio = (glm::vec2)currentOutputResolution / nestedResolution; + auto outputRatio = (glm::vec2)currentOutputResolution / g_ivNestedResolution; glm::vec2 ratios = nestedResolution / sourceDimensions; @@ -7411,7 +7410,7 @@ steamcompmgr_main(int argc, char **argv) { if ( steamMode && g_nXWaylandCount > 1 ) { - g_nNestedHeight = ( g_nNestedWidth * g_nOutputHeight ) / g_nOutputWidth; + g_ivNestedResolution.y = ( g_ivNestedResolution.x * g_nOutputHeight ) / g_nOutputWidth; wlserver_lock(); // Update only Steam, the root ctx, with the new output size for now wlserver_set_xwayland_server_mode( 0, g_nOutputWidth, g_nOutputHeight, g_nOutputRefresh ); diff --git a/src/wlserver.cpp b/src/wlserver.cpp index e822627424..dfb7d9ab76 100644 --- a/src/wlserver.cpp +++ b/src/wlserver.cpp @@ -222,7 +222,7 @@ void xwayland_surface_commit(struct wlr_surface *wlr_surface) { wlr_xdg_surface_schedule_configure( wlserver_xdg_surface_info->xdg_surface ); if ( wlserver_xdg_surface_info->layer_surface ) - wlr_layer_surface_v1_configure( wlserver_xdg_surface_info->layer_surface, g_nNestedWidth, g_nNestedHeight ); + wlr_layer_surface_v1_configure( wlserver_xdg_surface_info->layer_surface, g_ivNestedResolution.x, g_ivNestedResolution.y ); wlserver_xdg_surface_info->bDoneConfigure = true; } @@ -1511,7 +1511,7 @@ gamescope_xwayland_server_t::gamescope_xwayland_server_t(wl_display *display) } wlr_output_state_set_enabled(output_state, true); - wlr_output_state_set_custom_mode(output_state, g_nNestedWidth, g_nNestedHeight, refresh); + wlr_output_state_set_custom_mode(output_state, g_ivNestedResolution.x, g_ivNestedResolution.y, refresh); if (!wlr_output_commit_state(output, output_state)) { wl_log.errorf("Failed to commit headless output"); @@ -2080,16 +2080,16 @@ struct wlr_surface *wlserver_surface_to_override_surface( struct wlr_surface *pS return pSurface; } -std::pair wlserver_get_surface_extent( struct wlr_surface *pSurface ) +glm::ivec2 wlserver_get_surface_extent( struct wlr_surface *pSurface ) { assert( wlserver_is_lock_held() ); pSurface = wlserver_surface_to_override_surface( pSurface ); if ( !pSurface ) - return std::make_pair( g_nNestedWidth, g_nNestedHeight ); + return g_ivNestedResolution; - return std::make_pair( pSurface->current.width, pSurface->current.height ); + return glm::ivec2( pSurface->current.width, pSurface->current.height ); } bool ShouldDrawCursor();