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: Add bit depth property #2112

Merged
merged 2 commits into from
Jan 23, 2024
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
5 changes: 5 additions & 0 deletions metadata/output.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@
<option name="vrr" type="bool">
<default>false</default>
</option>
<option name="depth" type="int">
<default>8</default>
<min>8</min>
<max>10</max>
</option>
</object>
</wayfire>
4 changes: 4 additions & 0 deletions src/api/wayfire/output-layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "wayfire/signal-provider.hpp"
#include "wayfire/util.hpp"

#define RENDER_BIT_DEPTH_DEFAULT 8

namespace wf
{
class output_t;
Expand Down Expand Up @@ -51,6 +53,8 @@ struct output_state_t
double scale = 1.0;
/* Whether or not adaptive sync is enabled */
bool vrr = false;
/* Output format bit depth */
int depth = RENDER_BIT_DEPTH_DEFAULT;

/* Output to take the image from. Valid only if source is mirror */
std::string mirror_from;
Expand Down
63 changes: 61 additions & 2 deletions src/core/output-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <sstream>
#include <cstring>
#include <unordered_set>
#include <drm_fourcc.h>

#include <wayfire/debug.hpp>
#include <wayfire/util/log.hpp>
Expand Down Expand Up @@ -206,6 +207,7 @@ bool output_state_t::operator ==(const output_state_t& other) const
eq &= (transform == other.transform);
eq &= (scale == other.scale);
eq &= (vrr == other.vrr);
eq &= (depth == other.depth);

return eq;
}
Expand All @@ -215,6 +217,25 @@ inline bool is_shutting_down()
return wf::get_core().get_current_state() == compositor_state_t::SHUTDOWN;
}

static const char *get_format_name(uint32_t format)
{
switch (format)
{
case DRM_FORMAT_XRGB2101010:
return "DRM_FORMAT_XRGB2101010";

case DRM_FORMAT_XBGR2101010:
return "DRM_FORMAT_XBGR2101010";

case DRM_FORMAT_XRGB8888:
return "DRM_FORMAT_XRGB8888";

case DRM_FORMAT_INVALID:
default:
return "DRM_FORMAT_INVALID";
}
}

/** Represents a single output in the output layout */
struct output_layout_output_t
{
Expand All @@ -223,6 +244,8 @@ struct output_layout_output_t
bool is_externally_managed = false;
bool is_nested_compositor = false;
bool inhibited = false;
std::map<int, std::vector<uint32_t>> formats_for_depth;
int current_bit_depth = RENDER_BIT_DEPTH_DEFAULT;

std::unique_ptr<wf::output_impl_t> output;
wl_listener_wrapper on_destroy, on_commit;
Expand All @@ -233,6 +256,7 @@ struct output_layout_output_t
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<int> depth_opt;

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

output_layout_output_t(wlr_output *handle)
Expand Down Expand Up @@ -273,6 +298,13 @@ struct output_layout_output_t
});
on_commit.connect(&handle->events.commit);
}

formats_for_depth[8] = {DRM_FORMAT_XRGB8888};
formats_for_depth[10] = {
DRM_FORMAT_XRGB2101010,
DRM_FORMAT_XBGR2101010,
DRM_FORMAT_XRGB8888,
};
}

/**
Expand Down Expand Up @@ -439,7 +471,8 @@ struct output_layout_output_t

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

Expand Down Expand Up @@ -562,7 +595,8 @@ struct output_layout_output_t
if ((handle->current_mode->width == mode.width) &&
(handle->current_mode->height == mode.height) &&
(handle->current_mode->refresh == mode.refresh) &&
((handle->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED) == current_state.vrr))
((handle->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED) == current_state.vrr) &&
(current_bit_depth == current_state.depth))
{
/* Commit the enabling of the output */
wlr_output_commit(handle);
Expand Down Expand Up @@ -603,6 +637,23 @@ struct output_layout_output_t
wlr_output_rollback(handle);
}
}

if (current_state.depth != current_bit_depth)
{
for (auto fmt : formats_for_depth[current_state.depth])
{
wlr_output_set_render_format(handle, fmt);
if (wlr_output_test(handle))
{
wlr_output_commit(handle);
current_bit_depth = current_state.depth;
LOGD("Set output format to ", get_format_name(fmt), " on output ", handle->name);
break;
}

LOGD("Failed to set output format ", get_format_name(fmt), " on output ", handle->name);
}
}
}

/* Mirroring implementation */
Expand Down Expand Up @@ -1000,6 +1051,14 @@ class output_layout_t::impl
state.scale = head->state.scale;
state.transform = head->state.transform;
state.vrr = head->state.adaptive_sync_enabled;
if ((handle->pending.render_format == DRM_FORMAT_XRGB2101010) ||
(handle->pending.render_format == DRM_FORMAT_XBGR2101010))
{
state.depth = 10;
} else
{
state.depth = 8;
}
}

return result;
Expand Down
Loading