aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/drm/atomic.c17
-rw-r--r--backend/drm/backend.c10
-rw-r--r--backend/drm/drm.c69
-rw-r--r--backend/drm/legacy.c10
-rw-r--r--backend/drm/util.c19
5 files changed, 91 insertions, 34 deletions
diff --git a/backend/drm/atomic.c b/backend/drm/atomic.c
index 90acac25..5c064ac7 100644
--- a/backend/drm/atomic.c
+++ b/backend/drm/atomic.c
@@ -200,14 +200,14 @@ static bool atomic_crtc_move_cursor(struct wlr_drm_backend *drm,
}
static bool atomic_crtc_set_gamma(struct wlr_drm_backend *drm,
- struct wlr_drm_crtc *crtc, uint16_t *r, uint16_t *g, uint16_t *b,
- uint32_t size) {
+ struct wlr_drm_crtc *crtc, size_t size,
+ uint16_t *r, uint16_t *g, uint16_t *b) {
// Fallback to legacy gamma interface when gamma properties are not available
// (can happen on older intel gpu's that support gamma but not degamma)
// TEMP: This is broken on AMDGPU. Always fallback to legacy until they get
// it fixed. Ref https://bugs.freedesktop.org/show_bug.cgi?id=107459
if (crtc->props.gamma_lut == 0 || true) {
- return legacy_iface.crtc_set_gamma(drm, crtc, r, g, b, size);
+ return legacy_iface.crtc_set_gamma(drm, crtc, size, r, g, b);
}
struct drm_color_lut *gamma = malloc(size * sizeof(struct drm_color_lut));
@@ -216,7 +216,7 @@ static bool atomic_crtc_set_gamma(struct wlr_drm_backend *drm,
return false;
}
- for (uint32_t i = 0; i < size; i++) {
+ for (size_t i = 0; i < size; i++) {
gamma[i].red = r[i];
gamma[i].green = g[i];
gamma[i].blue = b[i];
@@ -240,21 +240,20 @@ static bool atomic_crtc_set_gamma(struct wlr_drm_backend *drm,
return atomic_end(drm->fd, &atom);
}
-static uint32_t atomic_crtc_get_gamma_size(struct wlr_drm_backend *drm,
+static size_t atomic_crtc_get_gamma_size(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc) {
- uint64_t gamma_lut_size;
-
if (crtc->props.gamma_lut_size == 0) {
return legacy_iface.crtc_get_gamma_size(drm, crtc);
}
+ uint64_t gamma_lut_size;
if (!get_drm_prop(drm->fd, crtc->id, crtc->props.gamma_lut_size,
- &gamma_lut_size)) {
+ &gamma_lut_size)) {
wlr_log(WLR_ERROR, "Unable to get gamma lut size");
return 0;
}
- return (uint32_t)gamma_lut_size;
+ return (size_t)gamma_lut_size;
}
const struct wlr_drm_interface atomic_iface = {
diff --git a/backend/drm/backend.c b/backend/drm/backend.c
index 40f17bb7..b298365e 100644
--- a/backend/drm/backend.c
+++ b/backend/drm/backend.c
@@ -101,6 +101,16 @@ static void session_signal(struct wl_listener *listener, void *data) {
(plane && plane->cursor_enabled) ? plane->cursor_bo : NULL);
drm->iface->crtc_move_cursor(drm, conn->crtc, conn->cursor_x,
conn->cursor_y);
+
+ if (conn->crtc->gamma_table != NULL) {
+ size_t size = conn->crtc->gamma_table_size;
+ uint16_t *r = conn->crtc->gamma_table;
+ uint16_t *g = conn->crtc->gamma_table + size;
+ uint16_t *b = conn->crtc->gamma_table + 2 * size;
+ drm->iface->crtc_set_gamma(drm, conn->crtc, size, r, g, b);
+ } else {
+ set_drm_connector_gamma(&conn->output, 0, NULL, NULL, NULL);
+ }
}
} else {
wlr_log(WLR_INFO, "DRM fd paused");
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index 8e7c421d..fa9a95ae 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -193,6 +193,7 @@ void finish_drm_resources(struct wlr_drm_backend *drm) {
if (crtc->gamma_lut) {
drmModeDestroyPropertyBlob(drm->fd, crtc->gamma_lut);
}
+ free(crtc->gamma_table);
}
for (size_t i = 0; i < drm->num_planes; ++i) {
struct wlr_drm_plane *plane = &drm->planes[i];
@@ -251,7 +252,7 @@ static bool drm_connector_swap_buffers(struct wlr_output *output,
return true;
}
-static void fill_empty_gamma_table(uint32_t size,
+static void fill_empty_gamma_table(size_t size,
uint16_t *r, uint16_t *g, uint16_t *b) {
for (uint32_t i = 0; i < size; ++i) {
uint16_t val = (uint32_t)0xffff * i / (size - 1);
@@ -259,7 +260,7 @@ static void fill_empty_gamma_table(uint32_t size,
}
}
-static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) {
+static size_t drm_connector_get_gamma_size(struct wlr_output *output) {
struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
@@ -270,8 +271,8 @@ static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) {
return 0;
}
-static bool drm_connector_set_gamma(struct wlr_output *output,
- uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) {
+bool set_drm_connector_gamma(struct wlr_output *output, size_t size,
+ const uint16_t *r, const uint16_t *g, const uint16_t *b) {
struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
@@ -279,25 +280,42 @@ static bool drm_connector_set_gamma(struct wlr_output *output,
return false;
}
- uint16_t *reset_table = NULL;
+ bool reset = false;
if (size == 0) {
+ reset = true;
size = drm_connector_get_gamma_size(output);
- reset_table = malloc(3 * size * sizeof(uint16_t));
- if (reset_table == NULL) {
- wlr_log(WLR_ERROR, "Failed to allocate gamma table");
+ if (size == 0) {
return false;
}
- r = reset_table;
- g = reset_table + size;
- b = reset_table + 2 * size;
- fill_empty_gamma_table(size, r, g, b);
}
- bool ok = drm->iface->crtc_set_gamma(drm, conn->crtc, r, g, b, size);
+ uint16_t *gamma_table = malloc(3 * size * sizeof(uint16_t));
+ if (gamma_table == NULL) {
+ wlr_log(WLR_ERROR, "Failed to allocate gamma table");
+ return false;
+ }
+ uint16_t *_r = gamma_table;
+ uint16_t *_g = gamma_table + size;
+ uint16_t *_b = gamma_table + 2 * size;
+
+ if (reset) {
+ fill_empty_gamma_table(size, _r, _g, _b);
+ } else {
+ memcpy(_r, r, size * sizeof(uint16_t));
+ memcpy(_g, g, size * sizeof(uint16_t));
+ memcpy(_b, b, size * sizeof(uint16_t));
+ }
+
+ bool ok = drm->iface->crtc_set_gamma(drm, conn->crtc, size, _r, _g, _b);
if (ok) {
wlr_output_update_needs_swap(output);
+
+ free(conn->crtc->gamma_table);
+ conn->crtc->gamma_table = gamma_table;
+ conn->crtc->gamma_table_size = size;
+ } else {
+ free(gamma_table);
}
- free(reset_table);
return ok;
}
@@ -709,6 +727,7 @@ static bool drm_connector_move_cursor(struct wlr_output *output,
static void drm_connector_destroy(struct wlr_output *output) {
struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
drm_connector_cleanup(conn);
+ drmModeFreeCrtc(conn->old_crtc);
wl_event_source_remove(conn->retry_pageflip);
wl_list_remove(&conn->link);
free(conn);
@@ -723,7 +742,7 @@ static const struct wlr_output_impl output_impl = {
.destroy = drm_connector_destroy,
.make_current = drm_connector_make_current,
.swap_buffers = drm_connector_swap_buffers,
- .set_gamma = drm_connector_set_gamma,
+ .set_gamma = set_drm_connector_gamma,
.get_gamma_size = drm_connector_get_gamma_size,
.export_dmabuf = drm_connector_export_dmabuf,
};
@@ -758,6 +777,8 @@ static void dealloc_crtc(struct wlr_drm_connector *conn) {
wlr_log(WLR_DEBUG, "De-allocating CRTC %zu for output '%s'",
conn->crtc - drm->crtcs, conn->output.name);
+ set_drm_connector_gamma(&conn->output, 0, NULL, NULL, NULL);
+
for (size_t type = 0; type < 3; ++type) {
struct wlr_drm_plane *plane = conn->crtc->planes[type];
if (plane == NULL) {
@@ -1088,10 +1109,11 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
wlr_log(WLR_INFO, "'%s' disappeared", conn->output.name);
drm_connector_cleanup(conn);
- drmModeFreeCrtc(conn->old_crtc);
- wl_event_source_remove(conn->retry_pageflip);
- wl_list_remove(&conn->link);
- free(conn);
+ if (conn->pageflip_pending) {
+ conn->state = WLR_DRM_CONN_DISAPPEARED;
+ } else {
+ wlr_output_destroy(&conn->output);
+ }
}
bool changed_outputs[wl_list_length(&drm->outputs)];
@@ -1133,6 +1155,12 @@ static void page_flip_handler(int fd, unsigned seq,
get_drm_backend_from_backend(conn->output.backend);
conn->pageflip_pending = false;
+
+ if (conn->state == WLR_DRM_CONN_DISAPPEARED) {
+ wlr_output_destroy(&conn->output);
+ return;
+ }
+
if (conn->state != WLR_DRM_CONN_CONNECTED || conn->crtc == NULL) {
return;
}
@@ -1193,7 +1221,6 @@ void restore_drm_outputs(struct wlr_drm_backend *drm) {
drmModeSetCrtc(drm->fd, crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y,
&conn->id, 1, &crtc->mode);
- drmModeFreeCrtc(crtc);
}
}
@@ -1248,6 +1275,8 @@ static void drm_connector_cleanup(struct wlr_drm_connector *conn) {
break;
case WLR_DRM_CONN_DISCONNECTED:
break;
+ case WLR_DRM_CONN_DISAPPEARED:
+ return; // don't change state
}
conn->state = WLR_DRM_CONN_DISCONNECTED;
diff --git a/backend/drm/legacy.c b/backend/drm/legacy.c
index c205e167..182c7a95 100644
--- a/backend/drm/legacy.c
+++ b/backend/drm/legacy.c
@@ -63,14 +63,14 @@ bool legacy_crtc_move_cursor(struct wlr_drm_backend *drm,
}
bool legacy_crtc_set_gamma(struct wlr_drm_backend *drm,
- struct wlr_drm_crtc *crtc, uint16_t *r, uint16_t *g, uint16_t *b,
- uint32_t size) {
- return !drmModeCrtcSetGamma(drm->fd, crtc->id, size, r, g, b);
+ struct wlr_drm_crtc *crtc, size_t size,
+ uint16_t *r, uint16_t *g, uint16_t *b) {
+ return !drmModeCrtcSetGamma(drm->fd, crtc->id, (uint32_t)size, r, g, b);
}
-uint32_t legacy_crtc_get_gamma_size(struct wlr_drm_backend *drm,
+size_t legacy_crtc_get_gamma_size(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc) {
- return crtc->legacy_crtc->gamma_size;
+ return (size_t)crtc->legacy_crtc->gamma_size;
}
const struct wlr_drm_interface legacy_iface = {
diff --git a/backend/drm/util.c b/backend/drm/util.c
index f9637c33..6b2c0981 100644
--- a/backend/drm/util.c
+++ b/backend/drm/util.c
@@ -32,21 +32,30 @@ static const char *get_manufacturer(uint16_t id) {
case ID('A', 'A', 'A'): return "Avolites Ltd";
case ID('A', 'C', 'I'): return "Ancor Communications Inc";
case ID('A', 'C', 'R'): return "Acer Technologies";
+ case ID('A', 'D', 'A'): return "Addi-Data GmbH";
case ID('A', 'P', 'P'): return "Apple Computer Inc";
+ case ID('A', 'S', 'K'): return "Ask A/S";
+ case ID('A', 'V', 'T'): return "Avtek (Electronics) Pty Ltd";
case ID('B', 'N', 'O'): return "Bang & Olufsen";
case ID('C', 'M', 'N'): return "Chimei Innolux Corporation";
case ID('C', 'M', 'O'): return "Chi Mei Optoelectronics corp.";
case ID('C', 'R', 'O'): return "Extraordinary Technologies PTY Limited";
case ID('D', 'E', 'L'): return "Dell Inc.";
+ case ID('D', 'G', 'C'): return "Data General Corporation";
case ID('D', 'O', 'N'): return "DENON, Ltd.";
case ID('E', 'N', 'C'): return "Eizo Nanao Corporation";
case ID('E', 'P', 'H'): return "Epiphan Systems Inc.";
+ case ID('E', 'X', 'P'): return "Data Export Corporation";
+ case ID('F', 'N', 'I'): return "Funai Electric Co., Ltd.";
case ID('F', 'U', 'S'): return "Fujitsu Siemens Computers GmbH";
case ID('G', 'S', 'M'): return "Goldstar Company Ltd";
case ID('H', 'I', 'Q'): return "Kaohsiung Opto Electronics Americas, Inc.";
case ID('H', 'S', 'D'): return "HannStar Display Corp";
+ case ID('H', 'T', 'C'): return "Hitachi Ltd";
case ID('H', 'W', 'P'): return "Hewlett Packard";
case ID('I', 'N', 'T'): return "Interphase Corporation";
+ case ID('I', 'N', 'X'): return "Communications Supply Corporation (A division of WESCO)";
+ case ID('I', 'T', 'E'): return "Integrated Tech Express Inc";
case ID('I', 'V', 'M'): return "Iiyama North America";
case ID('L', 'E', 'N'): return "Lenovo Group Limited";
case ID('M', 'A', 'X'): return "Rogen Tech Distribution Inc";
@@ -55,6 +64,7 @@ static const char *get_manufacturer(uint16_t id) {
case ID('M', 'T', 'C'): return "Mars-Tech Corporation";
case ID('M', 'T', 'X'): return "Matrox";
case ID('N', 'E', 'C'): return "NEC Corporation";
+ case ID('N', 'E', 'X'): return "Nexgen Mediatech Inc.";
case ID('O', 'N', 'K'): return "ONKYO Corporation";
case ID('O', 'R', 'N'): return "ORION ELECTRIC CO., LTD.";
case ID('O', 'T', 'M'): return "Optoma Corporation";
@@ -63,15 +73,24 @@ static const char *get_manufacturer(uint16_t id) {
case ID('P', 'I', 'O'): return "Pioneer Electronic Corporation";
case ID('P', 'N', 'R'): return "Planar Systems, Inc.";
case ID('Q', 'D', 'S'): return "Quanta Display Inc.";
+ case ID('R', 'A', 'T'): return "Rent-A-Tech";
+ case ID('R', 'E', 'N'): return "Renesas Technology Corp.";
case ID('S', 'A', 'M'): return "Samsung Electric Company";
+ case ID('S', 'A', 'N'): return "Sanyo Electric Co., Ltd.";
case ID('S', 'E', 'C'): return "Seiko Epson Corporation";
case ID('S', 'H', 'P'): return "Sharp Corporation";
case ID('S', 'I', 'I'): return "Silicon Image, Inc.";
case ID('S', 'N', 'Y'): return "Sony";
+ case ID('S', 'T', 'D'): return "STD Computer Inc";
+ case ID('S', 'V', 'S'): return "SVSI";
+ case ID('S', 'Y', 'N'): return "Synaptics Inc";
+ case ID('T', 'C', 'L'): return "Technical Concepts Ltd";
case ID('T', 'O', 'P'): return "Orion Communications Co., Ltd.";
case ID('T', 'S', 'B'): return "Toshiba America Info Systems Inc";
case ID('T', 'S', 'T'): return "Transtream Inc";
case ID('U', 'N', 'K'): return "Unknown";
+ case ID('V', 'E', 'S'): return "Vestel Elektronik Sanayi ve Ticaret A. S.";
+ case ID('V', 'I', 'T'): return "Visitech AS";
case ID('V', 'I', 'Z'): return "VIZIO, Inc";
case ID('V', 'S', 'C'): return "ViewSonic Corporation";
case ID('Y', 'M', 'H'): return "Yamaha Corporation";