Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WaylandBackend: Fix scale equation and unscale libdecor frame commit #1630

Merged
Merged
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
31 changes: 22 additions & 9 deletions src/Backends/WaylandBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

#include "drm_include.h"

#define WL_FRACTIONAL_SCALE_DENOMINATOR 120

extern int g_nPreferredOutputWidth;
extern int g_nPreferredOutputHeight;
extern bool g_bForceHDR10OutputDebug;
Expand All @@ -63,6 +65,13 @@ auto CallWithAllButLast(Func pFunc, Args&&... args)
return Forwarder(std::forward_as_tuple(args...), std::make_index_sequence<sizeof...(Args) - 1>());
}

static inline uint32_t WaylandScaleToPhysical( uint32_t pValue, uint32_t pFactor ) {
return pValue * pFactor / WL_FRACTIONAL_SCALE_DENOMINATOR;
}
static inline uint32_t WaylandScaleToLogical( uint32_t pValue, uint32_t pFactor ) {
return div_roundup( pValue * WL_FRACTIONAL_SCALE_DENOMINATOR, pFactor );
}

#define WAYLAND_NULL() []<typename... Args> ( void *pData, Args... args ) { }
#define WAYLAND_USERDATA_TO_THIS(type, name) []<typename... Args> ( void *pData, Args... args ) { type *pThing = (type *)pData; pThing->name( std::forward<Args>(args)... ); }

Expand Down Expand Up @@ -1016,14 +1025,15 @@ namespace gamescope
wl_fixed_from_double( oState->flSrcHeight ) );
wp_viewport_set_destination(
m_pViewport,
oState->nDstWidth * 120 / uScale,
oState->nDstHeight * 120 / uScale);
WaylandScaleToLogical( oState->nDstWidth, uScale ),
WaylandScaleToLogical( oState->nDstHeight, uScale ) );

if ( m_pSubsurface )
{
wl_subsurface_set_position(
m_pSubsurface,
oState->nDestX * 120 / uScale,
oState->nDestY * 120 / uScale );
WaylandScaleToLogical( oState->nDestX, uScale ),
WaylandScaleToLogical( oState->nDestY, uScale ) );
}
// The x/y here does nothing? Why? What is it for...
// Use the subsurface set_position thing instead.
Expand All @@ -1041,7 +1051,10 @@ namespace gamescope

void CWaylandPlane::CommitLibDecor( libdecor_configuration *pConfiguration )
{
libdecor_state *pState = libdecor_state_new( g_nOutputWidth, g_nOutputHeight );
int32_t uScale = GetScale();
libdecor_state *pState = libdecor_state_new(
WaylandScaleToLogical( g_nOutputWidth, uScale ),
WaylandScaleToLogical( g_nOutputHeight, uScale ) );
libdecor_frame_commit( m_pFrame, pState, pConfiguration );
libdecor_state_free( pState );
}
Expand Down Expand Up @@ -1148,11 +1161,11 @@ namespace gamescope
int nWidth, nHeight;
if ( !libdecor_configuration_get_content_size( pConfiguration, m_pFrame, &nWidth, &nHeight ) )
{
nWidth = g_nOutputWidth * 120 / uScale;
nHeight = g_nOutputHeight * 120 / uScale;
nWidth = WaylandScaleToLogical( g_nOutputWidth, uScale );
nHeight = WaylandScaleToLogical( g_nOutputHeight, uScale );
}
g_nOutputWidth = nWidth * uScale / 120;
g_nOutputHeight = nHeight * uScale / 120;
g_nOutputWidth = WaylandScaleToPhysical( nWidth, uScale );
g_nOutputHeight = WaylandScaleToPhysical( nHeight, uScale );

CommitLibDecor( pConfiguration );

Expand Down