Skip to content

Commit

Permalink
output: Implement adaptive sync option
Browse files Browse the repository at this point in the history
Enable by setting [output:<NAME>] vrr = true.

Fixes #1009.
  • Loading branch information
soreau committed Dec 8, 2023
1 parent 878c0a9 commit b876cae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions metadata/output.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
<option name="transform" type="string">
<default>normal</default>
</option>
<option name="vrr" type="bool">
<default>false</default>
</option>
</object>
</wayfire>
2 changes: 2 additions & 0 deletions src/api/wayfire/output-layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ struct output_state_t
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
/* The scale of the output */
double scale = 1.0;
/* Whether or not adaptive sync is enabled */
bool vrr = false;

/* Output to take the image from. Valid only if source is mirror */
std::string mirror_from;
Expand Down
28 changes: 28 additions & 0 deletions src/core/output-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ bool output_state_t::operator ==(const output_state_t& other) const
eq &= (mode.refresh == other.mode.refresh);
eq &= (transform == other.transform);
eq &= (scale == other.scale);
eq &= (vrr == other.vrr);

return eq;
}
Expand All @@ -231,6 +232,7 @@ struct output_layout_output_t
wf::option_wrapper_t<wf::output_config::position_t> position_opt;
wf::option_wrapper_t<double> scale_opt;
wf::option_wrapper_t<std::string> transform_opt;
wf::option_wrapper_t<bool> vrr_opt;

wf::option_wrapper_t<bool> use_ext_config{
"workarounds/use_external_output_configuration"};
Expand All @@ -243,6 +245,7 @@ struct output_layout_output_t
position_opt.load_option(name + "/position");
scale_opt.load_option(name + "/scale");
transform_opt.load_option(name + "/transform");
vrr_opt.load_option(name + "/vrr");
}

output_layout_output_t(wlr_output *handle)
Expand Down Expand Up @@ -436,6 +439,7 @@ struct output_layout_output_t

state.scale = scale_opt;
state.transform = get_transform_from_string(transform_opt);
state.vrr = vrr_opt;
return state;
}

Expand Down Expand Up @@ -552,6 +556,30 @@ struct output_layout_output_t
/** Change the output mode */
void apply_mode(const wlr_output_mode& mode)
{
if (!is_nested_compositor)
{
if ((handle->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_DISABLED) && vrr_opt)
{
wlr_output_enable_adaptive_sync(handle, vrr_opt);
wlr_output_commit(handle);
if (handle->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_DISABLED)
{
LOGE("Failed to enable adaptive sync on output: ", handle->name);
wlr_output_enable_adaptive_sync(handle, false);
} else
{
LOGI("Enabled adaptive sync on output: ", handle->name);
}
}

if ((handle->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED) && !vrr_opt)
{
wlr_output_enable_adaptive_sync(handle, false);
wlr_output_commit(handle);
LOGI("Disabled adaptive sync on output: ", handle->name);
}
}

if (handle->current_mode)
{
/* Do not modeset if nothing changed */
Expand Down

0 comments on commit b876cae

Please sign in to comment.