Skip to content

Commit

Permalink
main: Add --adaptive-sync commandline arg
Browse files Browse the repository at this point in the history
Enables VRR if the display is capable if this flag is set.

Closes: #199
  • Loading branch information
misyltoad committed Nov 8, 2022
1 parent f374689 commit 9898067
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/drm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,11 @@ void load_pnps(void)
fclose(f);
}

bool init_drm(struct drm_t *drm, int width, int height, int refresh)
bool init_drm(struct drm_t *drm, int width, int height, int refresh, bool wants_adaptive_sync)
{
load_pnps();

drm->wants_vrr_enabled = wants_adaptive_sync;
drm->preferred_width = width;
drm->preferred_height = height;
drm->preferred_refresh = refresh;
Expand Down
2 changes: 1 addition & 1 deletion src/drm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ extern enum drm_mode_generation g_drmModeGeneration;
extern enum g_panel_orientation g_drmModeOrientation;
extern uint64_t g_drmEffectiveOrientation;

bool init_drm(struct drm_t *drm, int width, int height, int refresh);
bool init_drm(struct drm_t *drm, int width, int height, int refresh, bool wants_adaptive_sync);
void finish_drm(struct drm_t *drm);
int drm_commit(struct drm_t *drm, const struct FrameInfo_t *frameInfo );
int drm_prepare( struct drm_t *drm, bool async, const struct FrameInfo_t *frameInfo );
Expand Down
7 changes: 6 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#endif

EStreamColorspace g_ForcedNV12ColorSpace = k_EStreamColorspace_Unknown;
static bool s_bInitialWantsVRREnabled = false;

const char *gamescope_optstring = nullptr;

Expand Down Expand Up @@ -60,6 +61,7 @@ const struct option *gamescope_options = (struct option[]){
{ "default-touch-mode", required_argument, nullptr, 0 },
{ "generate-drm-mode", required_argument, nullptr, 0 },
{ "immediate-flips", no_argument, nullptr, 0 },
{ "adaptive-sync", no_argument, nullptr, 0 },

// wlserver options
{ "xwayland-count", required_argument, nullptr, 0 },
Expand Down Expand Up @@ -120,6 +122,7 @@ const char usage[] =
" --default-touch-mode 0: hover, 1: left, 2: right, 3: middle, 4: passthrough\n"
" --generate-drm-mode DRM mode generation algorithm (cvt, fixed)\n"
" --immediate-flips Enable immediate flips, may result in tearing\n"
" --adaptive-sync Enable adaptive sync if available (variable rate refresh)\n"
"\n"
"Debug options:\n"
" --disable-layers disable libliftoff (hardware planes)\n"
Expand Down Expand Up @@ -406,6 +409,8 @@ int main(int argc, char **argv)
g_preferDeviceID = deviceID;
} else if (strcmp(opt_name, "immediate-flips") == 0) {
g_nAsyncFlipsEnabled = 1;
} else if (strcmp(opt_name, "adaptive-sync") == 0) {
s_bInitialWantsVRREnabled = true;
}
break;
case '?':
Expand Down Expand Up @@ -630,6 +635,6 @@ static bool initOutput( int preferredWidth, int preferredHeight, int preferredRe
}
else
{
return init_drm( &g_DRM, preferredWidth, preferredHeight, preferredRefresh );
return init_drm( &g_DRM, preferredWidth, preferredHeight, preferredRefresh, s_bInitialWantsVRREnabled );
}
}

0 comments on commit 9898067

Please sign in to comment.