Skip to content

Commit 8a4abd3

Browse files
author
@iDoMeteor
authored
Merge pull request DisplayLink#1 from onetr1ck/wip/color-mgmt-followups
evdi: colour management follow-ups (damage, cursor, color_props)
2 parents 8a229d8 + c9a3145 commit 8a4abd3

8 files changed

Lines changed: 123 additions & 23 deletions

File tree

‎module/evdi_color.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,18 @@ void evdi_color_transform_init(struct evdi_color_transform *color)
105105
memset(&color->data, 0, sizeof(color->data));
106106
}
107107

108-
void evdi_color_transform_update(struct evdi_color_transform *color,
109-
struct drm_crtc_state *crtc_state)
108+
bool evdi_color_transform_update(struct evdi_color_transform *color,
109+
struct drm_crtc_state *crtc_state)
110110
{
111111
if (!crtc_state->color_mgmt_changed)
112-
return;
112+
return false;
113113

114114
mutex_lock(&color->lock);
115115
evdi_color_update_gamma(&color->data, crtc_state);
116116
evdi_color_update_ctm(&color->data, crtc_state);
117117
color->data.active = color->data.has_gamma || color->data.has_ctm;
118118
mutex_unlock(&color->lock);
119+
return true;
119120
}
120121

121122
bool evdi_color_transform_snapshot(struct evdi_color_transform *color,

‎module/evdi_color.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ struct evdi_color_transform {
4141

4242
void evdi_color_transform_init(struct evdi_color_transform *color);
4343

44-
/* Recomputes the LUT/CTM from crtc_state; cheap no-op unless
45-
* crtc_state->color_mgmt_changed is set (i.e. on actual property writes).
44+
/* Recomputes the LUT/CTM from crtc_state. Returns true when colour
45+
* properties actually changed (caller should mark the scanout dirty so
46+
* clients re-grab). No-op when !color_mgmt_changed.
4647
*/
47-
void evdi_color_transform_update(struct evdi_color_transform *color,
48-
struct drm_crtc_state *crtc_state);
48+
bool evdi_color_transform_update(struct evdi_color_transform *color,
49+
struct drm_crtc_state *crtc_state);
4950

5051
/* Copies the current transform out under lock. Returns whether it's a
5152
* no-op identity transform, letting the caller skip apply_row() entirely.

‎module/evdi_cursor.c‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <drm/drm_crtc_helper.h>
3030

3131
#include "evdi_cursor.h"
32+
#include "evdi_color.h"
3233
#include "evdi_drm_drv.h"
3334

3435
/*
@@ -176,24 +177,53 @@ static inline uint32_t blend_alpha(const uint32_t pixel_val32,
176177
static int evdi_cursor_compose_pixel(char __user *buffer,
177178
int const cursor_value,
178179
int const fb_value,
179-
int cmd_offset)
180+
int cmd_offset,
181+
const struct evdi_color_data *color,
182+
bool swap_rb)
180183
{
181-
int const composed_value = blend_alpha(fb_value, cursor_value);
184+
uint32_t composed_value = blend_alpha(fb_value, cursor_value);
185+
186+
/*
187+
* Primary scanout is already colour-managed in copy_primary_pixels, but
188+
* this path re-blends from the untinted GEM and would undo that under
189+
* the cursor. Apply the same transform to the composed ARGB pixel so
190+
* Night Light matches the desktop (alpha left untouched).
191+
*/
192+
if (color && color->active) {
193+
u8 px[4];
194+
195+
px[0] = composed_value & 0xff;
196+
px[1] = (composed_value >> 8) & 0xff;
197+
px[2] = (composed_value >> 16) & 0xff;
198+
px[3] = (composed_value >> 24) & 0xff;
199+
evdi_color_transform_apply_row(color, px, 1, swap_rb);
200+
composed_value = (uint32_t)px[0]
201+
| ((uint32_t)px[1] << 8)
202+
| ((uint32_t)px[2] << 16)
203+
| ((uint32_t)px[3] << 24);
204+
}
182205

183206
return copy_to_user(buffer + cmd_offset, &composed_value, 4);
184207
}
185208

209+
static bool evdi_cursor_format_swaps_rb(uint32_t format)
210+
{
211+
return format == DRM_FORMAT_XBGR8888 || format == DRM_FORMAT_ABGR8888;
212+
}
213+
186214
int evdi_cursor_compose_and_copy(struct evdi_cursor *cursor,
187215
struct evdi_framebuffer *efb,
188216
char __user *buffer,
189-
int buf_byte_stride)
217+
int buf_byte_stride,
218+
const struct evdi_color_data *color)
190219
{
191220
int x, y;
192221
struct drm_framebuffer *fb = &efb->base;
193222
const int h_cursor_w = cursor->width >> 1;
194223
const int h_cursor_h = cursor->height >> 1;
195224
uint32_t *cursor_buffer = NULL;
196225
uint32_t bytespp = 0;
226+
const bool swap_rb = evdi_cursor_format_swaps_rb(cursor->pixel_format);
197227

198228
if (!cursor->enabled)
199229
return 0;
@@ -248,7 +278,9 @@ int evdi_cursor_compose_and_copy(struct evdi_cursor *cursor,
248278
if (evdi_cursor_compose_pixel(buffer,
249279
curs_val,
250280
fb_value,
251-
cmd_offset)) {
281+
cmd_offset,
282+
color,
283+
swap_rb)) {
252284
EVDI_ERROR("Failed to compose cursor pixel\n");
253285
return -EFAULT;
254286
}

‎module/evdi_cursor.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
struct evdi_cursor;
3232
struct evdi_framebuffer;
3333
struct evdi_gem_object;
34+
struct evdi_color_data;
3435

3536
int evdi_cursor_init(struct evdi_cursor **cursor);
3637
void evdi_cursor_free(struct evdi_cursor *cursor);
@@ -57,5 +58,6 @@ struct evdi_gem_object *evdi_cursor_gem(struct evdi_cursor *cursor);
5758
int evdi_cursor_compose_and_copy(struct evdi_cursor *cursor,
5859
struct evdi_framebuffer *efb,
5960
char __user *buffer,
60-
int buf_byte_stride);
61+
int buf_byte_stride,
62+
const struct evdi_color_data *color);
6163
#endif

‎module/evdi_modeset.c‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,18 @@ static void evdi_crtc_atomic_flush(
8989
(crtc_state->mode_changed || evdi_painter_needs_full_modeset(evdi->painter));
9090
bool notify_dpms = crtc_state->active_changed || evdi_painter_needs_full_modeset(evdi->painter);
9191

92-
evdi_color_transform_update(&evdi->color, crtc_state);
92+
/*
93+
* Colour is applied only on GRABPIX of dirty rects. When the compositor
94+
* changes GAMMA_LUT/CTM without repainting, force a full-frame dirty so
95+
* DisplayLinkManager re-grabs and the new transform is visible.
96+
*/
97+
if (evdi_color_transform_update(&evdi->color, crtc_state)) {
98+
struct drm_clip_rect full =
99+
evdi_painter_framebuffer_size(evdi->painter);
100+
101+
if (full.x2 > full.x1 && full.y2 > full.y1)
102+
evdi_painter_mark_dirty(evdi, &full);
103+
}
93104

94105
if (notify_mode_changed)
95106
evdi_painter_mode_changed_notify(evdi, &crtc_state->adjusted_mode);
@@ -508,14 +519,23 @@ static int evdi_crtc_init(struct drm_device *dev)
508519
drm_crtc_helper_add(crtc, &evdi_helper_funcs);
509520

510521
/*
511-
* evdi has no hardware gamma/CTM block to program; the properties
512-
* registered here are applied in software to the raw framebuffer
513-
* bytes in evdi_painter.c's copy_primary_pixels()/_on_xe(), since
514-
* that's the only place the driver has direct access to pixel data
515-
* before it's handed to userspace.
522+
* Software colour management (see evdi_color.c). Which properties are
523+
* advertised is selected by the color_props module parameter so a
524+
* compositor can be steered to GAMMA_LUT or CTM for testing.
516525
*/
517-
drm_mode_crtc_set_gamma_size(crtc, EVDI_GAMMA_LUT_SIZE);
518-
drm_crtc_enable_color_mgmt(crtc, 0, true, EVDI_GAMMA_LUT_SIZE);
526+
{
527+
const bool has_gamma = evdi_color_props_has_gamma();
528+
const bool has_ctm = evdi_color_props_has_ctm();
529+
const uint gamma_size = has_gamma ? EVDI_GAMMA_LUT_SIZE : 0;
530+
531+
if (has_gamma)
532+
drm_mode_crtc_set_gamma_size(crtc, EVDI_GAMMA_LUT_SIZE);
533+
if (has_gamma || has_ctm)
534+
drm_crtc_enable_color_mgmt(crtc, 0, has_ctm, gamma_size);
535+
EVDI_INFO("color_props=%s (gamma=%d ctm=%d)\n",
536+
evdi_color_props ? evdi_color_props : "both",
537+
has_gamma, has_ctm);
538+
}
519539

520540
return 0;
521541
}

‎module/evdi_painter.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,15 @@ static int copy_primary_pixels(struct evdi_framebuffer *efb,
299299
static void copy_cursor_pixels(struct evdi_framebuffer *efb,
300300
char __user *buffer,
301301
int buf_byte_stride,
302-
struct evdi_cursor *cursor)
302+
struct evdi_cursor *cursor,
303+
const struct evdi_color_data *color)
303304
{
304305
evdi_cursor_lock(cursor);
305306
if (evdi_cursor_compose_and_copy(cursor,
306307
efb,
307308
buffer,
308-
buf_byte_stride))
309+
buf_byte_stride,
310+
color))
309311
EVDI_ERROR("Failed to blend cursor\n");
310312

311313
evdi_cursor_unlock(cursor);
@@ -1215,7 +1217,8 @@ int evdi_painter_grabpix_ioctl(struct drm_device *drm_dev, void *data,
12151217
copy_cursor_pixels(efb,
12161218
cmd->buffer,
12171219
cmd->buf_byte_stride,
1218-
evdi->cursor);
1220+
evdi->cursor,
1221+
&color);
12191222

12201223
if (import_attach)
12211224
dma_buf_end_cpu_access(import_attach->dmabuf,

‎module/evdi_params.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99

1010
#include <linux/module.h>
1111
#include <linux/moduleparam.h>
12+
#include <linux/string.h>
1213

1314
#include "evdi_params.h"
1415
#include "evdi_debug.h"
1516

1617
unsigned int evdi_loglevel __read_mostly = EVDI_LOGLEVEL_INFO;
1718
unsigned short int evdi_initial_device_count __read_mostly;
19+
char *evdi_color_props __read_mostly = "both";
1820

1921
module_param_named(initial_loglevel, evdi_loglevel, int, 0400);
2022
MODULE_PARM_DESC(initial_loglevel, "Initial log level");
@@ -23,3 +25,27 @@ module_param_named(initial_device_count,
2325
evdi_initial_device_count, ushort, 0644);
2426
MODULE_PARM_DESC(initial_device_count, "Initial DRM device count (default: 0)");
2527

28+
module_param_named(color_props, evdi_color_props, charp, 0644);
29+
MODULE_PARM_DESC(color_props,
30+
"Colour properties to advertise: both, gamma, or ctm (default: both)");
31+
32+
bool evdi_color_props_has_gamma(void)
33+
{
34+
if (!evdi_color_props)
35+
return true;
36+
if (!strcmp(evdi_color_props, "ctm"))
37+
return false;
38+
/* both, gamma, or unknown → offer gamma */
39+
return true;
40+
}
41+
42+
bool evdi_color_props_has_ctm(void)
43+
{
44+
if (!evdi_color_props)
45+
return true;
46+
if (!strcmp(evdi_color_props, "gamma"))
47+
return false;
48+
/* both, ctm, or unknown → offer CTM */
49+
return true;
50+
}
51+

‎module/evdi_params.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,19 @@
1212
extern unsigned int evdi_loglevel;
1313
extern unsigned short int evdi_initial_device_count;
1414

15+
/*
16+
* Which DRM colour properties to advertise (compositors pick Night Light path
17+
* from what is present). Set at module load, e.g.:
18+
* modprobe evdi color_props=ctm
19+
* EVDI_COLOR_PROPS=gamma sudo ./scripts/install.sh
20+
*
21+
* both — GAMMA_LUT + CTM (default; GNOME prefers GAMMA_LUT)
22+
* gamma — GAMMA_LUT only
23+
* ctm — CTM only (useful to force Mutter CTM path)
24+
*/
25+
extern char *evdi_color_props;
26+
27+
bool evdi_color_props_has_gamma(void);
28+
bool evdi_color_props_has_ctm(void);
29+
1530
#endif /* EVDI_PARAMS_H */

0 commit comments

Comments
 (0)