aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Vanlaer <vincent.vanlaer@skynet.be>2018-02-01 20:27:35 +0100
committerVincent Vanlaer <vincent.vanlaer@skynet.be>2018-02-09 17:29:04 +0100
commitcc1229e75e0c0c2cf5ae6d67bc7411c2631deb86 (patch)
tree528e569385d110464518fd1ecb47e1d88a13da55
parent34489dca16ef9e7fd05c161b8b4f2fd5ce5e4ef0 (diff)
Add atomic gamma setting
-rw-r--r--backend/drm/atomic.c32
-rw-r--r--backend/drm/drm.c5
-rw-r--r--backend/drm/legacy.c8
-rw-r--r--backend/drm/properties.c1
-rw-r--r--include/backend/drm/drm.h5
-rw-r--r--include/backend/drm/iface.h4
-rw-r--r--include/backend/drm/properties.h3
7 files changed, 55 insertions, 3 deletions
diff --git a/backend/drm/atomic.c b/backend/drm/atomic.c
index 54024d86..a8003492 100644
--- a/backend/drm/atomic.c
+++ b/backend/drm/atomic.c
@@ -1,3 +1,4 @@
+#include <stdlib.h>
#include <gbm.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
@@ -195,9 +196,40 @@ static bool atomic_crtc_move_cursor(struct wlr_drm_backend *drm,
return atomic_end(drm->fd, &atom);
}
+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 drm_color_lut *gamma = calloc(sizeof(struct drm_color_lut), size);
+
+ for (uint32_t i = 0; i < size; i++) {
+ gamma[i].red = r[i];
+ gamma[i].green = g[i];
+ gamma[i].blue = b[i];
+ }
+
+ if (crtc->gamma_lut != 0) {
+ drmModeDestroyPropertyBlob(drm->fd, crtc->gamma_lut);
+ }
+
+ if (drmModeCreatePropertyBlob(drm->fd, gamma,
+ sizeof(struct drm_color_lut) * size, &crtc->gamma_lut)) {
+ wlr_log_errno(L_ERROR, "Unable to create property blob");
+ return false;
+ }
+
+ free(gamma);
+
+ struct atomic atom;
+
+ atomic_begin(crtc, &atom);
+ atomic_add(&atom, crtc->id, crtc->props.gamma_lut, crtc->gamma_lut);
+ return atomic_end(drm->fd, &atom);
+}
+
const struct wlr_drm_interface atomic_iface = {
.conn_enable = atomic_conn_enable,
.crtc_pageflip = atomic_crtc_pageflip,
.crtc_set_cursor = atomic_crtc_set_cursor,
.crtc_move_cursor = atomic_crtc_move_cursor,
+ .crtc_set_gamma = atomic_crtc_set_gamma,
};
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index 08ced783..abcfcf8a 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -169,6 +169,9 @@ void wlr_drm_resources_free(struct wlr_drm_backend *drm) {
if (crtc->mode_id) {
drmModeDestroyPropertyBlob(drm->fd, crtc->mode_id);
}
+ if (crtc->gamma_lut) {
+ drmModeDestroyPropertyBlob(drm->fd, crtc->gamma_lut);
+ }
}
for (size_t i = 0; i < drm->num_planes; ++i) {
struct wlr_drm_plane *plane = &drm->planes[i];
@@ -227,7 +230,7 @@ static void wlr_drm_connector_set_gamma(struct wlr_output *output,
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
- drmModeCrtcSetGamma(drm->fd, conn->crtc->id, size, r, g, b);
+ drm->iface->crtc_set_gamma(drm, conn->crtc, r, g, b, size);
}
static uint32_t wlr_drm_connector_get_gamma_size(struct wlr_output *output) {
diff --git a/backend/drm/legacy.c b/backend/drm/legacy.c
index 61140cec..46911905 100644
--- a/backend/drm/legacy.c
+++ b/backend/drm/legacy.c
@@ -59,9 +59,17 @@ bool legacy_crtc_move_cursor(struct wlr_drm_backend *drm,
return !drmModeMoveCursor(drm->fd, crtc->id, x, y);
}
+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);
+}
+
+
const struct wlr_drm_interface legacy_iface = {
.conn_enable = legacy_conn_enable,
.crtc_pageflip = legacy_crtc_pageflip,
.crtc_set_cursor = legacy_crtc_set_cursor,
.crtc_move_cursor = legacy_crtc_move_cursor,
+ .crtc_set_gamma = legacy_crtc_set_gamma,
};
diff --git a/backend/drm/properties.c b/backend/drm/properties.c
index 5bec3243..c3efa96e 100644
--- a/backend/drm/properties.c
+++ b/backend/drm/properties.c
@@ -28,6 +28,7 @@ static const struct prop_info connector_info[] = {
static const struct prop_info crtc_info[] = {
#define INDEX(name) (offsetof(union wlr_drm_crtc_props, name) / sizeof(uint32_t))
{ "ACTIVE", INDEX(active) },
+ { "GAMMA_LUT", INDEX(gamma_lut) },
{ "MODE_ID", INDEX(mode_id) },
{ "rotation", INDEX(rotation) },
{ "scaling mode", INDEX(scaling_mode) },
diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h
index af472ede..782764c8 100644
--- a/include/backend/drm/drm.h
+++ b/include/backend/drm/drm.h
@@ -39,7 +39,10 @@ struct wlr_drm_plane {
struct wlr_drm_crtc {
uint32_t id;
- uint32_t mode_id; // atomic modesetting only
+
+ // Atomic modesetting only
+ uint32_t mode_id;
+ uint32_t gamma_lut;
drmModeAtomicReq *atomic;
union {
diff --git a/include/backend/drm/iface.h b/include/backend/drm/iface.h
index 4a5d2e9d..228b313a 100644
--- a/include/backend/drm/iface.h
+++ b/include/backend/drm/iface.h
@@ -27,6 +27,10 @@ struct wlr_drm_interface {
// Move the cursor on crtc
bool (*crtc_move_cursor)(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc, int x, int y);
+ // Set the gamma lut on crtc
+ bool (*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);
};
extern const struct wlr_drm_interface atomic_iface;
diff --git a/include/backend/drm/properties.h b/include/backend/drm/properties.h
index 7de386ea..119d24c3 100644
--- a/include/backend/drm/properties.h
+++ b/include/backend/drm/properties.h
@@ -32,8 +32,9 @@ union wlr_drm_crtc_props {
uint32_t active;
uint32_t mode_id;
+ uint32_t gamma_lut;
};
- uint32_t props[4];
+ uint32_t props[5];
};
union wlr_drm_plane_props {