output: make gamma size a size_t and gamma table const

master
emersion 6 years ago
parent 1dd523c34c
commit 2beb68007e

@ -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, 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, struct wlr_drm_crtc *crtc, size_t size,
uint32_t size) { uint16_t *r, uint16_t *g, uint16_t *b) {
// Fallback to legacy gamma interface when gamma properties are not available // Fallback to legacy gamma interface when gamma properties are not available
// (can happen on older intel gpu's that support gamma but not degamma) // (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 // 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 // it fixed. Ref https://bugs.freedesktop.org/show_bug.cgi?id=107459
if (crtc->props.gamma_lut == 0 || true) { 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)); 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; 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].red = r[i];
gamma[i].green = g[i]; gamma[i].green = g[i];
gamma[i].blue = b[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); 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) { struct wlr_drm_crtc *crtc) {
uint64_t gamma_lut_size;
if (crtc->props.gamma_lut_size == 0) { if (crtc->props.gamma_lut_size == 0) {
return legacy_iface.crtc_get_gamma_size(drm, crtc); 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, 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"); wlr_log(WLR_ERROR, "Unable to get gamma lut size");
return 0; return 0;
} }
return (uint32_t)gamma_lut_size; return (size_t)gamma_lut_size;
} }
const struct wlr_drm_interface atomic_iface = { const struct wlr_drm_interface atomic_iface = {

@ -251,7 +251,7 @@ static bool drm_connector_swap_buffers(struct wlr_output *output,
return true; 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) { uint16_t *r, uint16_t *g, uint16_t *b) {
for (uint32_t i = 0; i < size; ++i) { for (uint32_t i = 0; i < size; ++i) {
uint16_t val = (uint32_t)0xffff * i / (size - 1); uint16_t val = (uint32_t)0xffff * i / (size - 1);
@ -259,7 +259,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_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend); struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
@ -270,8 +270,8 @@ static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) {
return 0; return 0;
} }
static bool drm_connector_set_gamma(struct wlr_output *output, static bool drm_connector_set_gamma(struct wlr_output *output, size_t size,
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) { 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_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend); struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
@ -279,25 +279,37 @@ static bool drm_connector_set_gamma(struct wlr_output *output,
return false; return false;
} }
uint16_t *reset_table = NULL; bool reset = false;
if (size == 0) { if (size == 0) {
reset = true;
size = drm_connector_get_gamma_size(output); size = drm_connector_get_gamma_size(output);
reset_table = malloc(3 * size * sizeof(uint16_t)); if (size == 0) {
if (reset_table == NULL) {
wlr_log(WLR_ERROR, "Failed to allocate gamma table");
return false; 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) { if (ok) {
wlr_output_update_needs_swap(output); wlr_output_update_needs_swap(output);
} }
free(reset_table); free(gamma_table);
return ok; return ok;
} }

@ -63,14 +63,14 @@ bool legacy_crtc_move_cursor(struct wlr_drm_backend *drm,
} }
bool legacy_crtc_set_gamma(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, struct wlr_drm_crtc *crtc, size_t size,
uint32_t size) { uint16_t *r, uint16_t *g, uint16_t *b) {
return !drmModeCrtcSetGamma(drm->fd, crtc->id, size, r, g, 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) { 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 = { const struct wlr_drm_interface legacy_iface = {

@ -28,11 +28,11 @@ struct wlr_drm_interface {
struct wlr_drm_crtc *crtc, int x, int y); struct wlr_drm_crtc *crtc, int x, int y);
// Set the gamma lut on crtc // Set the gamma lut on crtc
bool (*crtc_set_gamma)(struct wlr_drm_backend *drm, bool (*crtc_set_gamma)(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc, uint16_t *r, uint16_t *g, uint16_t *b, struct wlr_drm_crtc *crtc, size_t size,
uint32_t size); uint16_t *r, uint16_t *g, uint16_t *b);
// Get the gamma lut size of a crtc // Get the gamma lut size of a crtc
uint32_t (*crtc_get_gamma_size)(struct wlr_drm_backend *drm, size_t (*crtc_get_gamma_size)(struct wlr_drm_backend *drm,
struct wlr_drm_crtc *crtc); struct wlr_drm_crtc *crtc);
}; };
extern const struct wlr_drm_interface atomic_iface; extern const struct wlr_drm_interface atomic_iface;

@ -28,9 +28,9 @@ struct wlr_output_impl {
void (*destroy)(struct wlr_output *output); void (*destroy)(struct wlr_output *output);
bool (*make_current)(struct wlr_output *output, int *buffer_age); bool (*make_current)(struct wlr_output *output, int *buffer_age);
bool (*swap_buffers)(struct wlr_output *output, pixman_region32_t *damage); bool (*swap_buffers)(struct wlr_output *output, pixman_region32_t *damage);
bool (*set_gamma)(struct wlr_output *output, bool (*set_gamma)(struct wlr_output *output, size_t size,
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); const uint16_t *r, const uint16_t *g, const uint16_t *b);
uint32_t (*get_gamma_size)(struct wlr_output *output); size_t (*get_gamma_size)(struct wlr_output *output);
bool (*export_dmabuf)(struct wlr_output *output, bool (*export_dmabuf)(struct wlr_output *output,
struct wlr_dmabuf_attributes *attribs); struct wlr_dmabuf_attributes *attribs);
}; };

@ -182,7 +182,7 @@ void wlr_output_schedule_frame(struct wlr_output *output);
/** /**
* Returns the maximum length of each gamma ramp, or 0 if unsupported. * Returns the maximum length of each gamma ramp, or 0 if unsupported.
*/ */
uint32_t wlr_output_get_gamma_size(struct wlr_output *output); size_t wlr_output_get_gamma_size(struct wlr_output *output);
/** /**
* Sets the gamma table for this output. `r`, `g` and `b` are gamma ramps for * Sets the gamma table for this output. `r`, `g` and `b` are gamma ramps for
* red, green and blue. `size` is the length of the ramps and must not exceed * red, green and blue. `size` is the length of the ramps and must not exceed
@ -190,8 +190,8 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output);
* *
* Providing zero-sized ramps resets the gamma table. * Providing zero-sized ramps resets the gamma table.
*/ */
bool wlr_output_set_gamma(struct wlr_output *output, bool wlr_output_set_gamma(struct wlr_output *output, size_t size,
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); const uint16_t *r, const uint16_t *g, const uint16_t *b);
bool wlr_output_export_dmabuf(struct wlr_output *output, bool wlr_output_export_dmabuf(struct wlr_output *output,
struct wlr_dmabuf_attributes *attribs); struct wlr_dmabuf_attributes *attribs);
void wlr_output_set_fullscreen_surface(struct wlr_output *output, void wlr_output_set_fullscreen_surface(struct wlr_output *output,

@ -560,15 +560,15 @@ void wlr_output_schedule_frame(struct wlr_output *output) {
wl_event_loop_add_idle(ev, schedule_frame_handle_idle_timer, output); wl_event_loop_add_idle(ev, schedule_frame_handle_idle_timer, output);
} }
bool wlr_output_set_gamma(struct wlr_output *output, uint32_t size, bool wlr_output_set_gamma(struct wlr_output *output, size_t size,
uint16_t *r, uint16_t *g, uint16_t *b) { const uint16_t *r, const uint16_t *g, const uint16_t *b) {
if (!output->impl->set_gamma) { if (!output->impl->set_gamma) {
return false; return false;
} }
return output->impl->set_gamma(output, size, r, g, b); return output->impl->set_gamma(output, size, r, g, b);
} }
uint32_t wlr_output_get_gamma_size(struct wlr_output *output) { size_t wlr_output_get_gamma_size(struct wlr_output *output) {
if (!output->impl->get_gamma_size) { if (!output->impl->get_gamma_size) {
return 0; return 0;
} }

Loading…
Cancel
Save