aboutsummaryrefslogtreecommitdiff
path: root/backend/drm/drm.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-08-02 18:48:09 -0400
committerGitHub <noreply@github.com>2018-08-02 18:48:09 -0400
commit1654fc80ebdc4c69d86cbb700ceeb49b8f090c62 (patch)
tree9973c182ff78d3758e9487166ca55dc58d006e86 /backend/drm/drm.c
parent0780d7856a1ec2b6f3bcf2837cd5f697556c531e (diff)
parentc3afe4f42e3ddfbd51500d99416b51aee552b689 (diff)
Merge pull request #1157 from emersion/wlr-gamma-control
Implement wlr-gamma-control-unstable-v1
Diffstat (limited to 'backend/drm/drm.c')
-rw-r--r--backend/drm/drm.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index c4674235..9d030dff 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -228,30 +228,54 @@ static bool drm_connector_swap_buffers(struct wlr_output *output,
return true;
}
-static void drm_connector_set_gamma(struct wlr_output *output,
- uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) {
+static void fill_empty_gamma_table(uint32_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);
+ r[i] = g[i] = b[i] = val;
+ }
+}
+
+static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
- bool ok;
if (conn->crtc) {
- ok = drm->iface->crtc_set_gamma(drm, conn->crtc, r, g, b, size);
- if (ok) {
- wlr_output_update_needs_swap(output);
- }
+ return drm->iface->crtc_get_gamma_size(drm, conn->crtc);
}
+ return 0;
}
-static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) {
+static bool 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;
- if (conn->crtc) {
- return drm->iface->crtc_get_gamma_size(drm, conn->crtc);
+ if (!conn->crtc) {
+ return false;
}
- return 0;
+ uint16_t *reset_table = NULL;
+ if (size == 0) {
+ 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");
+ 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);
+ if (ok) {
+ wlr_output_update_needs_swap(output);
+ }
+ free(reset_table);
+ return ok;
}
static bool drm_connector_export_dmabuf(struct wlr_output *output,