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

output: Implement adaptive sync option #2058

Merged
merged 3 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
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
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
Loading