Skip to content

Commit 167d393

Browse files
misyltoadadamdmoss
authored andcommitted
DRMBackend: Read the EDID's modes for dynamic refresh rate modes by default
Should supercede ValveSoftware#1627 and allow this feature on some handhelds that just expose modes in the EDID. (cherry picked from commit d52460d)
1 parent 54e7a49 commit 167d393

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/Backends/DRMBackend.cpp

+31-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ gamescope::ConVar<bool> cv_drm_debug_disable_color_range( "drm_debug_disable_col
7272
gamescope::ConVar<bool> cv_drm_debug_disable_explicit_sync( "drm_debug_disable_explicit_sync", false, "Force disable explicit sync on the DRM backend." );
7373
gamescope::ConVar<bool> cv_drm_debug_disable_in_fence_fd( "drm_debug_disable_in_fence_fd", false, "Force disable IN_FENCE_FD being set to avoid over-synchronization on the DRM backend." );
7474

75+
gamescope::ConVar<bool> cv_drm_allow_dynamic_modes_for_external_display( "drm_allow_dynamic_modes_for_external_display", false, "Allow dynamic mode/refresh rate switching for external displays." );
7576

7677
int HackyDRMPresent( const FrameInfo_t *pFrameInfo, bool bAsync );
7778

@@ -2184,6 +2185,8 @@ namespace gamescope
21842185
bool bHasKnownColorimetry = false;
21852186
bool bHasKnownHDRInfo = false;
21862187

2188+
m_Mutable.ValidDynamicRefreshRates.clear();
2189+
m_Mutable.fnDynamicModeGenerator = nullptr;
21872190
{
21882191
CScriptScopedLock script;
21892192

@@ -2197,8 +2200,6 @@ namespace gamescope
21972200
(int)oKnownDisplay->first.size(), oKnownDisplay->first.data(),
21982201
(int)psvPrettyName.size(), psvPrettyName.data() );
21992202

2200-
m_Mutable.fnDynamicModeGenerator = nullptr;
2201-
m_Mutable.ValidDynamicRefreshRates.clear();
22022203

22032204
sol::optional<sol::table> otDynamicRefreshRates = tTable["dynamic_refresh_rates"];
22042205
sol::optional<sol::function> ofnDynamicModegen = tTable["dynamic_modegen"];
@@ -2285,6 +2286,34 @@ namespace gamescope
22852286
bHasKnownHDRInfo = true;
22862287
}
22872288
}
2289+
else
2290+
{
2291+
// Unknown display, see if there are any other refresh rates in the EDID we can get.
2292+
if ( GetScreenType() == GAMESCOPE_SCREEN_TYPE_INTERNAL || cv_drm_allow_dynamic_modes_for_external_display )
2293+
{
2294+
const drmModeModeInfo *pPreferredMode = find_mode( m_pConnector.get(), 0, 0, 0 );
2295+
2296+
if ( pPreferredMode )
2297+
{
2298+
// See if the EDID has any modes for us.
2299+
for (int i = 0; i < m_pConnector->count_modes; i++)
2300+
{
2301+
const drmModeModeInfo *pMode = &m_pConnector->modes[i];
2302+
2303+
if ( pMode->hdisplay != pPreferredMode->hdisplay || pMode->vdisplay != pPreferredMode->vdisplay )
2304+
continue;
2305+
2306+
2307+
if ( !Algorithm::Contains( m_Mutable.ValidDynamicRefreshRates, pMode->vrefresh ) )
2308+
{
2309+
m_Mutable.ValidDynamicRefreshRates.push_back( pMode->vrefresh );
2310+
}
2311+
}
2312+
2313+
std::sort( m_Mutable.ValidDynamicRefreshRates.begin(), m_Mutable.ValidDynamicRefreshRates.end() );
2314+
}
2315+
}
2316+
}
22882317
}
22892318

22902319
if ( !bHasKnownColorimetry )

0 commit comments

Comments
 (0)