Skip to content

Commit

Permalink
output: Implement adaptive sync option (#2058)
Browse files Browse the repository at this point in the history
* output: Implement adaptive sync option

Enable by setting [output:<NAME>] vrr = true, or using a client like wlr-randr.

Fixes #1009.

* output-layout: remove duplicate VRR check

* use rollback instead of manually resetting state

---------
  • Loading branch information
soreau authored Dec 26, 2023
1 parent ab9955c commit 641981d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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
24 changes: 23 additions & 1 deletion 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 @@ -557,7 +561,8 @@ struct output_layout_output_t
/* Do not modeset if nothing changed */
if ((handle->current_mode->width == mode.width) &&
(handle->current_mode->height == mode.height) &&
(handle->current_mode->refresh == mode.refresh))
(handle->current_mode->refresh == mode.refresh) &&
((handle->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED) == current_state.vrr))
{
/* Commit the enabling of the output */
wlr_output_commit(handle);
Expand All @@ -582,6 +587,22 @@ struct output_layout_output_t
}

wlr_output_commit(handle);

const bool adaptive_sync_enabled = (handle->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED);

if (adaptive_sync_enabled != current_state.vrr)
{
wlr_output_enable_adaptive_sync(handle, current_state.vrr);
if (wlr_output_test(handle))
{
wlr_output_commit(handle);
LOGD("Changed adaptive sync on output: ", handle->name, " to ", current_state.vrr);
} else
{
LOGE("Failed to change adaptive sync on output: ", handle->name);
wlr_output_rollback(handle);
}
}
}

/* Mirroring implementation */
Expand Down Expand Up @@ -978,6 +999,7 @@ class output_layout_t::impl
state.position = {head->state.x, head->state.y};
state.scale = head->state.scale;
state.transform = head->state.transform;
state.vrr = head->state.adaptive_sync_enabled;
}

return result;
Expand Down

0 comments on commit 641981d

Please sign in to comment.