Skip to content

Commit

Permalink
steamcompmgr, etc: {g_nNestedWidth, g_nNestedHeight} -> g_ivNestedRes…
Browse files Browse the repository at this point in the history
…olution

color_helpers: enable using structured bindings w/ glm::vec
  • Loading branch information
sharkautarch committed Sep 6, 2024
1 parent 761b73f commit 2a1ae84
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Backends/OpenVRBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Backends/WaylandBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
53 changes: 53 additions & 0 deletions src/color_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,59 @@
#include <glm/vec3.hpp> // glm::vec3
#include <glm/mat3x3.hpp> // glm::mat3
#include <glm/gtx/component_wise.hpp>
/////////////////////////////////////////////////////////
// Stuff for using structured bindings with glm::vec: //
/////////////////////////////////////////////////////////
namespace std
{
#define MK_TUPLE_SIZE(size, type) \
template<> \
struct tuple_size< ::glm::vec<size, type, glm::defaultp> > : \
std::integral_constant<size_t, size> { }

# define MK_TUPLE_ELEMENT(size) \
template<std::size_t I, class T> \
struct tuple_element<I, ::glm::vec<size, T, glm::defaultp>> : std::type_identity<T> \
{ \
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 )
Expand Down
18 changes: 8 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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() )
{
Expand Down
4 changes: 2 additions & 2 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ extern const char *gamescope_optstring;
extern const struct option *gamescope_options;

extern std::atomic< bool > g_bRun;
#include <glm/fwd.hpp>

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;
Expand Down
4 changes: 2 additions & 2 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +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 nestedResolution = glm::vec2 { g_ivNestedResolution };
auto outputRatio = (glm::vec2)currentOutputResolution / nestedResolution;

glm::vec2 ratios = nestedResolution / sourceDimensions;
Expand Down Expand Up @@ -7411,7 +7411,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 );
Expand Down
10 changes: 5 additions & 5 deletions src/wlserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -2080,16 +2080,16 @@ struct wlr_surface *wlserver_surface_to_override_surface( struct wlr_surface *pS
return pSurface;
}

std::pair<int, int> 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();
Expand Down

0 comments on commit 2a1ae84

Please sign in to comment.