mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-11-03 09:01:40 -05:00 
			
		
		
		
	backend/drm: allow to pass empty gamma ramp to reset it
This commit is contained in:
		
							parent
							
								
									e21563ec76
								
							
						
					
					
						commit
						2ebecb6727
					
				
					 2 changed files with 38 additions and 12 deletions
				
			
		| 
						 | 
					@ -228,19 +228,12 @@ static bool drm_connector_swap_buffers(struct wlr_output *output,
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool drm_connector_set_gamma(struct wlr_output *output,
 | 
					static void fill_empty_gamma_table(uint32_t size,
 | 
				
			||||||
		uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) {
 | 
							uint16_t *r, uint16_t *g, uint16_t *b) {
 | 
				
			||||||
	struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
 | 
						for (uint32_t i = 0; i < size; ++i) {
 | 
				
			||||||
	struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
 | 
							uint16_t val = (uint32_t)0xffff * (uint32_t)i / (uint32_t)(size - 1);
 | 
				
			||||||
 | 
							r[i] = g[i] = b[i] = val;
 | 
				
			||||||
	bool ok = false;
 | 
					 | 
				
			||||||
	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 ok;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) {
 | 
					static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) {
 | 
				
			||||||
| 
						 | 
					@ -254,6 +247,37 @@ 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,
 | 
				
			||||||
 | 
							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 false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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,
 | 
					static bool drm_connector_export_dmabuf(struct wlr_output *output,
 | 
				
			||||||
		struct wlr_dmabuf_attributes *attribs) {
 | 
							struct wlr_dmabuf_attributes *attribs) {
 | 
				
			||||||
	struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
 | 
						struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -182,6 +182,8 @@ uint32_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
 | 
				
			||||||
 * the value returned by `wlr_output_get_gamma_size`.
 | 
					 * the value returned by `wlr_output_get_gamma_size`.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * 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,
 | 
				
			||||||
	uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b);
 | 
						uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue