backend/drm: add support for color transforms

This commit is contained in:
Simon Ser 2025-05-24 13:40:05 +02:00 committed by Kenny Levinsen
parent 97f6946c8d
commit f10dd1da1c
3 changed files with 35 additions and 11 deletions

View file

@ -10,6 +10,7 @@
#include "backend/drm/fb.h" #include "backend/drm/fb.h"
#include "backend/drm/iface.h" #include "backend/drm/iface.h"
#include "backend/drm/util.h" #include "backend/drm/util.h"
#include "render/color.h"
static char *atomic_commit_flags_str(uint32_t flags) { static char *atomic_commit_flags_str(uint32_t flags) {
const char *const l[] = { const char *const l[] = {
@ -251,19 +252,25 @@ bool drm_atomic_connector_prepare(struct wlr_drm_connector_state *state, bool mo
} }
uint32_t gamma_lut = crtc->gamma_lut; uint32_t gamma_lut = crtc->gamma_lut;
if (state->base->committed & WLR_OUTPUT_STATE_GAMMA_LUT) { if (state->base->committed & WLR_OUTPUT_STATE_COLOR_TRANSFORM) {
size_t dim = 0;
uint16_t *lut = NULL;
if (state->base->color_transform != NULL) {
struct wlr_color_transform_lut_3x1d *tr =
color_transform_lut_3x1d_from_base(state->base->color_transform);
dim = tr->dim;
lut = tr->lut_3x1d;
}
// Fallback to legacy gamma interface when gamma properties are not // Fallback to legacy gamma interface when gamma properties are not
// available (can happen on older Intel GPUs that support gamma but not // available (can happen on older Intel GPUs that support gamma but not
// degamma). // degamma).
if (crtc->props.gamma_lut == 0) { if (crtc->props.gamma_lut == 0) {
if (!drm_legacy_crtc_set_gamma(drm, crtc, if (!drm_legacy_crtc_set_gamma(drm, crtc, dim, lut)) {
state->base->gamma_lut_size,
state->base->gamma_lut)) {
return false; return false;
} }
} else { } else {
if (!create_gamma_lut_blob(drm, state->base->gamma_lut_size, if (!create_gamma_lut_blob(drm, dim, lut, &gamma_lut)) {
state->base->gamma_lut, &gamma_lut)) {
return false; return false;
} }
} }

View file

@ -24,6 +24,7 @@
#include "backend/drm/fb.h" #include "backend/drm/fb.h"
#include "backend/drm/iface.h" #include "backend/drm/iface.h"
#include "backend/drm/util.h" #include "backend/drm/util.h"
#include "render/color.h"
#include "types/wlr_output.h" #include "types/wlr_output.h"
#include "util/env.h" #include "util/env.h"
#include "config.h" #include "config.h"
@ -37,11 +38,11 @@ static const uint32_t COMMIT_OUTPUT_STATE =
WLR_OUTPUT_STATE_BUFFER | WLR_OUTPUT_STATE_BUFFER |
WLR_OUTPUT_STATE_MODE | WLR_OUTPUT_STATE_MODE |
WLR_OUTPUT_STATE_ENABLED | WLR_OUTPUT_STATE_ENABLED |
WLR_OUTPUT_STATE_GAMMA_LUT |
WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED | WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED |
WLR_OUTPUT_STATE_LAYERS | WLR_OUTPUT_STATE_LAYERS |
WLR_OUTPUT_STATE_WAIT_TIMELINE | WLR_OUTPUT_STATE_WAIT_TIMELINE |
WLR_OUTPUT_STATE_SIGNAL_TIMELINE; WLR_OUTPUT_STATE_SIGNAL_TIMELINE |
WLR_OUTPUT_STATE_COLOR_TRANSFORM;
static const uint32_t SUPPORTED_OUTPUT_STATE = static const uint32_t SUPPORTED_OUTPUT_STATE =
WLR_OUTPUT_STATE_BACKEND_OPTIONAL | COMMIT_OUTPUT_STATE; WLR_OUTPUT_STATE_BACKEND_OPTIONAL | COMMIT_OUTPUT_STATE;
@ -856,6 +857,13 @@ static bool drm_connector_prepare(struct wlr_drm_connector_state *conn_state, bo
} }
} }
if ((state->committed & WLR_OUTPUT_STATE_COLOR_TRANSFORM) && state->color_transform != NULL &&
state->color_transform->type != COLOR_TRANSFORM_LUT_3X1D) {
wlr_drm_conn_log(conn, WLR_DEBUG,
"Only 3x1D LUT color transforms are supported");
return false;
}
if (test_only && conn->backend->mgpu_renderer.wlr_rend) { if (test_only && conn->backend->mgpu_renderer.wlr_rend) {
// If we're running as a secondary GPU, we can't perform an atomic // If we're running as a secondary GPU, we can't perform an atomic
// commit without blitting a buffer. // commit without blitting a buffer.

View file

@ -7,6 +7,7 @@
#include "backend/drm/fb.h" #include "backend/drm/fb.h"
#include "backend/drm/iface.h" #include "backend/drm/iface.h"
#include "backend/drm/util.h" #include "backend/drm/util.h"
#include "render/color.h"
#include "types/wlr_output.h" #include "types/wlr_output.h"
static bool legacy_fb_props_match(struct wlr_drm_fb *fb1, static bool legacy_fb_props_match(struct wlr_drm_fb *fb1,
@ -124,9 +125,17 @@ static bool legacy_crtc_commit(const struct wlr_drm_connector_state *state,
} }
} }
if (state->base->committed & WLR_OUTPUT_STATE_GAMMA_LUT) { if (state->base->committed & WLR_OUTPUT_STATE_COLOR_TRANSFORM) {
if (!drm_legacy_crtc_set_gamma(drm, crtc, size_t dim = 0;
state->base->gamma_lut_size, state->base->gamma_lut)) { uint16_t *lut = NULL;
if (state->base->color_transform != NULL) {
struct wlr_color_transform_lut_3x1d *tr =
color_transform_lut_3x1d_from_base(state->base->color_transform);
dim = tr->dim;
lut = tr->lut_3x1d;
}
if (!drm_legacy_crtc_set_gamma(drm, crtc, dim, lut)) {
return false; return false;
} }
} }