From 5a541bd5e7adc9fdcc1883558be9218f82a284e0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 16 Dec 2014 23:14:34 -0800 Subject: [PATCH] modesetting: [v2] Don't re-enable the cursor when loading the image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hidden cursors also have their image updated; re-enabling the cursor each time the image is set will cause it to re-appear. * Unifies the code that was in drmmode_load_cursor_argb and drm_mode_show_cursor and moves it to a new drmmode_set_cursor * Add a new boolean, 'cursor_up', to the per-crtc private data to track whether the cursor should be displayed. * Call drmmode_set_cursor from drm_mode_show_cursor and, if the cursor should be displayed, from drm_mode_load_cursor_argb. v2: Call drmModeSetCursor2 when loading a new cursor image if the cursor should be displayed. Signed-off-by: Keith Packard Reviewed-by: Michel Dänzer --- .../drivers/modesetting/drmmode_display.c | 97 ++++++++++--------- .../drivers/modesetting/drmmode_display.h | 1 + 2 files changed, 52 insertions(+), 46 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 13a96dc90..8d9bf8b2e 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -394,60 +394,18 @@ drmmode_set_cursor_position(xf86CrtcPtr crtc, int x, int y) } static void -drmmode_load_cursor_argb(xf86CrtcPtr crtc, CARD32 *image) +drmmode_set_cursor(xf86CrtcPtr crtc) { - modesettingPtr ms = modesettingPTR(crtc->scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - int i; - uint32_t *ptr; - uint32_t handle = drmmode_crtc->cursor_bo->handle; - int ret; - - /* cursor should be mapped already */ - ptr = (uint32_t *) (drmmode_crtc->cursor_bo->ptr); - - for (i = 0; i < ms->cursor_width * ms->cursor_height; i++) - ptr[i] = image[i]; // cpu_to_le32(image[i]); - - ret = - drmModeSetCursor(drmmode_crtc->drmmode->fd, - drmmode_crtc->mode_crtc->crtc_id, handle, - ms->cursor_width, ms->cursor_height); - if (ret) { - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - - cursor_info->MaxWidth = cursor_info->MaxHeight = 0; - drmmode_crtc->drmmode->sw_cursor = TRUE; - /* fallback to swcursor */ - } -} - -static void -drmmode_hide_cursor(xf86CrtcPtr crtc) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - - drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, - ms->cursor_width, ms->cursor_height); - -} - -static void -drmmode_show_cursor(xf86CrtcPtr crtc) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; drmmode_ptr drmmode = drmmode_crtc->drmmode; uint32_t handle = drmmode_crtc->cursor_bo->handle; + modesettingPtr ms = modesettingPTR(crtc->scrn); static Bool use_set_cursor2 = TRUE; + int ret; if (use_set_cursor2) { xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); CursorPtr cursor = xf86_config->cursor; - int ret; ret = drmModeSetCursor2(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, @@ -459,10 +417,57 @@ drmmode_show_cursor(xf86CrtcPtr crtc) return; } - drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, + ret = drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, + ms->cursor_width, ms->cursor_height); + + if (ret) { + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); + xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; + + cursor_info->MaxWidth = cursor_info->MaxHeight = 0; + drmmode_crtc->drmmode->sw_cursor = TRUE; + /* fallback to swcursor */ + } +} + +static void +drmmode_load_cursor_argb(xf86CrtcPtr crtc, CARD32 *image) +{ + modesettingPtr ms = modesettingPTR(crtc->scrn); + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + int i; + uint32_t *ptr; + + /* cursor should be mapped already */ + ptr = (uint32_t *) (drmmode_crtc->cursor_bo->ptr); + + for (i = 0; i < ms->cursor_width * ms->cursor_height; i++) + ptr[i] = image[i]; // cpu_to_le32(image[i]); + + if (drmmode_crtc->cursor_up) + drmmode_set_cursor(crtc); +} + +static void +drmmode_hide_cursor(xf86CrtcPtr crtc) +{ + modesettingPtr ms = modesettingPTR(crtc->scrn); + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + drmmode_ptr drmmode = drmmode_crtc->drmmode; + + drmmode_crtc->cursor_up = FALSE; + drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, ms->cursor_width, ms->cursor_height); } +static void +drmmode_show_cursor(xf86CrtcPtr crtc) +{ + drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; + drmmode_crtc->cursor_up = TRUE; + drmmode_set_cursor(crtc); +} + static void drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t * red, uint16_t * green, uint16_t * blue, int size) diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h index 645081187..0983cf117 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.h +++ b/hw/xfree86/drivers/modesetting/drmmode_display.h @@ -87,6 +87,7 @@ typedef struct { drmModeCrtcPtr mode_crtc; uint32_t vblank_pipe; struct dumb_bo *cursor_bo; + Bool cursor_up; unsigned rotate_fb_id; uint16_t lut_r[256], lut_g[256], lut_b[256]; DamagePtr slave_damage;