Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * qxl local rendering (aka display on sdl/vnc) |
| 3 | * |
| 4 | * Copyright (C) 2010 Red Hat, Inc. |
| 5 | * |
| 6 | * maintained by Gerd Hoffmann <kraxel@redhat.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 or |
| 11 | * (at your option) version 3 of the License. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
Peter Maydell | 47df515 | 2016-01-26 18:17:13 +0000 | [diff] [blame] | 22 | #include "qemu/osdep.h" |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 23 | #include "qxl.h" |
Markus Armbruster | 54d3123 | 2019-08-12 07:23:59 +0200 | [diff] [blame] | 24 | #include "sysemu/runstate.h" |
Stefan Weil | b1829cd | 2013-12-07 15:09:12 +0100 | [diff] [blame] | 25 | #include "trace.h" |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 26 | |
Gerd Hoffmann | e2efc0a | 2012-02-27 11:05:09 +0100 | [diff] [blame] | 27 | static void qxl_blit(PCIQXLDevice *qxl, QXLRect *rect) |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 28 | { |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 29 | DisplaySurface *surface = qemu_console_surface(qxl->vga.con); |
| 30 | uint8_t *dst = surface_data(surface); |
Alon Levy | 4c19ebb | 2012-02-24 23:19:29 +0200 | [diff] [blame] | 31 | uint8_t *src; |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 32 | int len, i; |
| 33 | |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 34 | if (is_buffer_shared(surface)) { |
Alon Levy | 4c19ebb | 2012-02-24 23:19:29 +0200 | [diff] [blame] | 35 | return; |
| 36 | } |
Alon Levy | d53291c | 2012-03-18 13:46:15 +0100 | [diff] [blame] | 37 | trace_qxl_render_blit(qxl->guest_primary.qxl_stride, |
Alon Levy | 4c19ebb | 2012-02-24 23:19:29 +0200 | [diff] [blame] | 38 | rect->left, rect->right, rect->top, rect->bottom); |
| 39 | src = qxl->guest_primary.data; |
Gerd Hoffmann | e2efc0a | 2012-02-27 11:05:09 +0100 | [diff] [blame] | 40 | if (qxl->guest_primary.qxl_stride < 0) { |
| 41 | /* qxl surface is upside down, walk src scanlines |
| 42 | * in reverse order to flip it */ |
| 43 | src += (qxl->guest_primary.surface.height - rect->top - 1) * |
| 44 | qxl->guest_primary.abs_stride; |
| 45 | } else { |
| 46 | src += rect->top * qxl->guest_primary.abs_stride; |
| 47 | } |
Gerd Hoffmann | 0e2487b | 2011-10-21 15:59:07 +0200 | [diff] [blame] | 48 | dst += rect->top * qxl->guest_primary.abs_stride; |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 49 | src += rect->left * qxl->guest_primary.bytes_pp; |
| 50 | dst += rect->left * qxl->guest_primary.bytes_pp; |
| 51 | len = (rect->right - rect->left) * qxl->guest_primary.bytes_pp; |
| 52 | |
| 53 | for (i = rect->top; i < rect->bottom; i++) { |
| 54 | memcpy(dst, src, len); |
Gerd Hoffmann | 0e2487b | 2011-10-21 15:59:07 +0200 | [diff] [blame] | 55 | dst += qxl->guest_primary.abs_stride; |
Gerd Hoffmann | e2efc0a | 2012-02-27 11:05:09 +0100 | [diff] [blame] | 56 | src += qxl->guest_primary.qxl_stride; |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
| 60 | void qxl_render_resize(PCIQXLDevice *qxl) |
| 61 | { |
| 62 | QXLSurfaceCreate *sc = &qxl->guest_primary.surface; |
| 63 | |
Gerd Hoffmann | 0e2487b | 2011-10-21 15:59:07 +0200 | [diff] [blame] | 64 | qxl->guest_primary.qxl_stride = sc->stride; |
| 65 | qxl->guest_primary.abs_stride = abs(sc->stride); |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 66 | qxl->guest_primary.resized++; |
| 67 | switch (sc->format) { |
| 68 | case SPICE_SURFACE_FMT_16_555: |
| 69 | qxl->guest_primary.bytes_pp = 2; |
| 70 | qxl->guest_primary.bits_pp = 15; |
| 71 | break; |
| 72 | case SPICE_SURFACE_FMT_16_565: |
| 73 | qxl->guest_primary.bytes_pp = 2; |
| 74 | qxl->guest_primary.bits_pp = 16; |
| 75 | break; |
| 76 | case SPICE_SURFACE_FMT_32_xRGB: |
| 77 | case SPICE_SURFACE_FMT_32_ARGB: |
| 78 | qxl->guest_primary.bytes_pp = 4; |
| 79 | qxl->guest_primary.bits_pp = 32; |
| 80 | break; |
| 81 | default: |
Alistair Francis | a89f364 | 2017-11-08 14:56:31 -0800 | [diff] [blame] | 82 | fprintf(stderr, "%s: unhandled format: %x\n", __func__, |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 83 | qxl->guest_primary.surface.format); |
| 84 | qxl->guest_primary.bytes_pp = 4; |
| 85 | qxl->guest_primary.bits_pp = 32; |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | |
Alon Levy | 81fb6f1 | 2012-02-24 23:19:31 +0200 | [diff] [blame] | 90 | static void qxl_set_rect_to_surface(PCIQXLDevice *qxl, QXLRect *area) |
| 91 | { |
| 92 | area->left = 0; |
| 93 | area->right = qxl->guest_primary.surface.width; |
| 94 | area->top = 0; |
| 95 | area->bottom = qxl->guest_primary.surface.height; |
| 96 | } |
| 97 | |
| 98 | static void qxl_render_update_area_unlocked(PCIQXLDevice *qxl) |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 99 | { |
| 100 | VGACommonState *vga = &qxl->vga; |
Gerd Hoffmann | da229ef | 2013-02-28 10:48:02 +0100 | [diff] [blame] | 101 | DisplaySurface *surface; |
Gerd Hoffmann | 979f7ef | 2018-09-19 12:30:57 +0200 | [diff] [blame] | 102 | int width = qxl->guest_head0_width ?: qxl->guest_primary.surface.width; |
| 103 | int height = qxl->guest_head0_height ?: qxl->guest_primary.surface.height; |
Alon Levy | 81fb6f1 | 2012-02-24 23:19:31 +0200 | [diff] [blame] | 104 | int i; |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 105 | |
| 106 | if (qxl->guest_primary.resized) { |
| 107 | qxl->guest_primary.resized = 0; |
Gerd Hoffmann | c58c7b9 | 2013-09-05 21:57:19 +0200 | [diff] [blame] | 108 | qxl->guest_primary.data = qxl_phys2virt(qxl, |
| 109 | qxl->guest_primary.surface.mem, |
| 110 | MEMSLOT_GROUP_GUEST); |
| 111 | if (!qxl->guest_primary.data) { |
Marc-André Lureau | 4d63162 | 2015-08-24 13:20:49 +0200 | [diff] [blame] | 112 | goto end; |
Gerd Hoffmann | c58c7b9 | 2013-09-05 21:57:19 +0200 | [diff] [blame] | 113 | } |
Alon Levy | 81fb6f1 | 2012-02-24 23:19:31 +0200 | [diff] [blame] | 114 | qxl_set_rect_to_surface(qxl, &qxl->dirty[0]); |
| 115 | qxl->num_dirty_rects = 1; |
Alon Levy | d53291c | 2012-03-18 13:46:15 +0100 | [diff] [blame] | 116 | trace_qxl_render_guest_primary_resized( |
Gerd Hoffmann | 979f7ef | 2018-09-19 12:30:57 +0200 | [diff] [blame] | 117 | width, |
| 118 | height, |
Gerd Hoffmann | 0e2487b | 2011-10-21 15:59:07 +0200 | [diff] [blame] | 119 | qxl->guest_primary.qxl_stride, |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 120 | qxl->guest_primary.bytes_pp, |
Alon Levy | 4c19ebb | 2012-02-24 23:19:29 +0200 | [diff] [blame] | 121 | qxl->guest_primary.bits_pp); |
Alon Levy | 4c19ebb | 2012-02-24 23:19:29 +0200 | [diff] [blame] | 122 | if (qxl->guest_primary.qxl_stride > 0) { |
Gerd Hoffmann | 30f1e66 | 2014-06-18 11:03:15 +0200 | [diff] [blame] | 123 | pixman_format_code_t format = |
| 124 | qemu_default_pixman_format(qxl->guest_primary.bits_pp, true); |
Gerd Hoffmann | da229ef | 2013-02-28 10:48:02 +0100 | [diff] [blame] | 125 | surface = qemu_create_displaysurface_from |
Gerd Hoffmann | 979f7ef | 2018-09-19 12:30:57 +0200 | [diff] [blame] | 126 | (width, |
| 127 | height, |
Gerd Hoffmann | 30f1e66 | 2014-06-18 11:03:15 +0200 | [diff] [blame] | 128 | format, |
Gerd Hoffmann | 2f464b5 | 2012-12-10 07:41:07 +0100 | [diff] [blame] | 129 | qxl->guest_primary.abs_stride, |
Gerd Hoffmann | 30f1e66 | 2014-06-18 11:03:15 +0200 | [diff] [blame] | 130 | qxl->guest_primary.data); |
Alon Levy | 4c19ebb | 2012-02-24 23:19:29 +0200 | [diff] [blame] | 131 | } else { |
Gerd Hoffmann | da229ef | 2013-02-28 10:48:02 +0100 | [diff] [blame] | 132 | surface = qemu_create_displaysurface |
Gerd Hoffmann | 979f7ef | 2018-09-19 12:30:57 +0200 | [diff] [blame] | 133 | (width, |
| 134 | height); |
Alon Levy | 4c19ebb | 2012-02-24 23:19:29 +0200 | [diff] [blame] | 135 | } |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 136 | dpy_gfx_replace_surface(vga->con, surface); |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 137 | } |
Gerd Hoffmann | c58c7b9 | 2013-09-05 21:57:19 +0200 | [diff] [blame] | 138 | |
| 139 | if (!qxl->guest_primary.data) { |
Marc-André Lureau | 4d63162 | 2015-08-24 13:20:49 +0200 | [diff] [blame] | 140 | goto end; |
Gerd Hoffmann | c58c7b9 | 2013-09-05 21:57:19 +0200 | [diff] [blame] | 141 | } |
Alon Levy | 81fb6f1 | 2012-02-24 23:19:31 +0200 | [diff] [blame] | 142 | for (i = 0; i < qxl->num_dirty_rects; i++) { |
| 143 | if (qemu_spice_rect_is_empty(qxl->dirty+i)) { |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 144 | break; |
| 145 | } |
Gerd Hoffmann | 503b3b3 | 2014-08-29 09:27:52 +0200 | [diff] [blame] | 146 | if (qxl->dirty[i].left < 0 || |
| 147 | qxl->dirty[i].top < 0 || |
| 148 | qxl->dirty[i].left > qxl->dirty[i].right || |
Gerd Hoffmann | 788fbf0 | 2014-06-10 13:51:12 +0200 | [diff] [blame] | 149 | qxl->dirty[i].top > qxl->dirty[i].bottom || |
Gerd Hoffmann | 979f7ef | 2018-09-19 12:30:57 +0200 | [diff] [blame] | 150 | qxl->dirty[i].right > width || |
| 151 | qxl->dirty[i].bottom > height) { |
Gerd Hoffmann | 788fbf0 | 2014-06-10 13:51:12 +0200 | [diff] [blame] | 152 | continue; |
| 153 | } |
Gerd Hoffmann | e2efc0a | 2012-02-27 11:05:09 +0100 | [diff] [blame] | 154 | qxl_blit(qxl, qxl->dirty+i); |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 155 | dpy_gfx_update(vga->con, |
Gerd Hoffmann | a93a4a2 | 2012-09-28 15:02:08 +0200 | [diff] [blame] | 156 | qxl->dirty[i].left, qxl->dirty[i].top, |
| 157 | qxl->dirty[i].right - qxl->dirty[i].left, |
| 158 | qxl->dirty[i].bottom - qxl->dirty[i].top); |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 159 | } |
Alon Levy | 81fb6f1 | 2012-02-24 23:19:31 +0200 | [diff] [blame] | 160 | qxl->num_dirty_rects = 0; |
Marc-André Lureau | 4d63162 | 2015-08-24 13:20:49 +0200 | [diff] [blame] | 161 | |
| 162 | end: |
| 163 | if (qxl->render_update_cookie_num == 0) { |
| 164 | graphic_hw_update_done(qxl->ssd.dcl.con); |
| 165 | } |
Alon Levy | 81fb6f1 | 2012-02-24 23:19:31 +0200 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | /* |
| 169 | * use ssd.lock to protect render_update_cookie_num. |
| 170 | * qxl_render_update is called by io thread or vcpu thread, and the completion |
Veres Lajos | 67cc32e | 2015-09-08 22:45:14 +0100 | [diff] [blame] | 171 | * callbacks are called by spice_server thread, deferring to bh called from the |
Alon Levy | 81fb6f1 | 2012-02-24 23:19:31 +0200 | [diff] [blame] | 172 | * io thread. |
| 173 | */ |
| 174 | void qxl_render_update(PCIQXLDevice *qxl) |
| 175 | { |
| 176 | QXLCookie *cookie; |
| 177 | |
| 178 | qemu_mutex_lock(&qxl->ssd.lock); |
| 179 | |
Gerd Hoffmann | 5bd5c27 | 2018-04-27 13:55:28 +0200 | [diff] [blame] | 180 | if (!runstate_is_running() || !qxl->guest_primary.commands || |
| 181 | qxl->mode == QXL_MODE_UNDEFINED) { |
Alon Levy | 81fb6f1 | 2012-02-24 23:19:31 +0200 | [diff] [blame] | 182 | qxl_render_update_area_unlocked(qxl); |
| 183 | qemu_mutex_unlock(&qxl->ssd.lock); |
Marc-André Lureau | b577ab2 | 2021-02-02 00:14:22 +0400 | [diff] [blame] | 184 | graphic_hw_update_done(qxl->ssd.dcl.con); |
Alon Levy | 81fb6f1 | 2012-02-24 23:19:31 +0200 | [diff] [blame] | 185 | return; |
| 186 | } |
| 187 | |
| 188 | qxl->guest_primary.commands = 0; |
| 189 | qxl->render_update_cookie_num++; |
| 190 | qemu_mutex_unlock(&qxl->ssd.lock); |
| 191 | cookie = qxl_cookie_new(QXL_COOKIE_TYPE_RENDER_UPDATE_AREA, |
| 192 | 0); |
| 193 | qxl_set_rect_to_surface(qxl, &cookie->u.render.area); |
| 194 | qxl_spice_update_area(qxl, 0, &cookie->u.render.area, NULL, |
| 195 | 0, 1 /* clear_dirty_region */, QXL_ASYNC, cookie); |
| 196 | } |
| 197 | |
| 198 | void qxl_render_update_area_bh(void *opaque) |
| 199 | { |
| 200 | PCIQXLDevice *qxl = opaque; |
| 201 | |
| 202 | qemu_mutex_lock(&qxl->ssd.lock); |
| 203 | qxl_render_update_area_unlocked(qxl); |
| 204 | qemu_mutex_unlock(&qxl->ssd.lock); |
| 205 | } |
| 206 | |
| 207 | void qxl_render_update_area_done(PCIQXLDevice *qxl, QXLCookie *cookie) |
| 208 | { |
| 209 | qemu_mutex_lock(&qxl->ssd.lock); |
Alon Levy | d53291c | 2012-03-18 13:46:15 +0100 | [diff] [blame] | 210 | trace_qxl_render_update_area_done(cookie); |
Alon Levy | 81fb6f1 | 2012-02-24 23:19:31 +0200 | [diff] [blame] | 211 | qemu_bh_schedule(qxl->update_area_bh); |
| 212 | qxl->render_update_cookie_num--; |
| 213 | qemu_mutex_unlock(&qxl->ssd.lock); |
| 214 | g_free(cookie); |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 215 | } |
| 216 | |
Gerd Hoffmann | b21330b | 2017-08-28 14:39:33 +0200 | [diff] [blame] | 217 | static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl, |
| 218 | QXLDataChunk *chunk, uint32_t group_id) |
| 219 | { |
| 220 | uint32_t max_chunks = 32; |
| 221 | size_t offset = 0; |
| 222 | size_t bytes; |
| 223 | |
| 224 | for (;;) { |
| 225 | bytes = MIN(size - offset, chunk->data_size); |
| 226 | memcpy(dest + offset, chunk->data, bytes); |
| 227 | offset += bytes; |
| 228 | if (offset == size) { |
| 229 | return; |
| 230 | } |
| 231 | chunk = qxl_phys2virt(qxl, chunk->next_chunk, group_id); |
| 232 | if (!chunk) { |
| 233 | return; |
| 234 | } |
| 235 | max_chunks--; |
| 236 | if (max_chunks == 0) { |
| 237 | return; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor, |
| 243 | uint32_t group_id) |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 244 | { |
| 245 | QEMUCursor *c; |
Peter Wu | 36ffc12 | 2018-09-03 16:54:47 +0200 | [diff] [blame] | 246 | uint8_t *and_mask, *xor_mask; |
Markus Armbruster | 66d3f19 | 2011-11-09 09:52:55 +0100 | [diff] [blame] | 247 | size_t size; |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 248 | |
| 249 | c = cursor_alloc(cursor->header.width, cursor->header.height); |
| 250 | c->hot_x = cursor->header.hot_spot_x; |
| 251 | c->hot_y = cursor->header.hot_spot_y; |
| 252 | switch (cursor->header.type) { |
Peter Wu | 36ffc12 | 2018-09-03 16:54:47 +0200 | [diff] [blame] | 253 | case SPICE_CURSOR_TYPE_MONO: |
| 254 | /* Assume that the full cursor is available in a single chunk. */ |
| 255 | size = 2 * cursor_get_mono_bpl(c) * c->height; |
| 256 | if (size != cursor->data_size) { |
| 257 | fprintf(stderr, "%s: bad monochrome cursor %ux%u with size %u\n", |
| 258 | __func__, c->width, c->height, cursor->data_size); |
| 259 | goto fail; |
| 260 | } |
| 261 | and_mask = cursor->chunk.data; |
| 262 | xor_mask = and_mask + cursor_get_mono_bpl(c) * c->height; |
| 263 | cursor_set_mono(c, 0xffffff, 0x000000, xor_mask, 1, and_mask); |
| 264 | if (qxl->debug > 2) { |
| 265 | cursor_print_ascii_art(c, "qxl/mono"); |
| 266 | } |
| 267 | break; |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 268 | case SPICE_CURSOR_TYPE_ALPHA: |
Gerd Hoffmann | bfc1012 | 2013-06-03 10:36:54 +0200 | [diff] [blame] | 269 | size = sizeof(uint32_t) * cursor->header.width * cursor->header.height; |
Gerd Hoffmann | b21330b | 2017-08-28 14:39:33 +0200 | [diff] [blame] | 270 | qxl_unpack_chunks(c->data, size, qxl, &cursor->chunk, group_id); |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 271 | if (qxl->debug > 2) { |
| 272 | cursor_print_ascii_art(c, "qxl/alpha"); |
| 273 | } |
| 274 | break; |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 275 | default: |
| 276 | fprintf(stderr, "%s: not implemented: type %d\n", |
Alistair Francis | a89f364 | 2017-11-08 14:56:31 -0800 | [diff] [blame] | 277 | __func__, cursor->header.type); |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 278 | goto fail; |
| 279 | } |
| 280 | return c; |
| 281 | |
| 282 | fail: |
| 283 | cursor_put(c); |
| 284 | return NULL; |
| 285 | } |
| 286 | |
| 287 | |
| 288 | /* called from spice server thread context only */ |
Alon Levy | fae2afb | 2012-04-25 12:13:18 +0300 | [diff] [blame] | 289 | int qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext) |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 290 | { |
| 291 | QXLCursorCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id); |
| 292 | QXLCursor *cursor; |
| 293 | QEMUCursor *c; |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 294 | |
Alon Levy | fae2afb | 2012-04-25 12:13:18 +0300 | [diff] [blame] | 295 | if (!cmd) { |
| 296 | return 1; |
| 297 | } |
| 298 | |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 299 | if (!dpy_cursor_define_supported(qxl->vga.con)) { |
Alon Levy | fae2afb | 2012-04-25 12:13:18 +0300 | [diff] [blame] | 300 | return 0; |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | if (qxl->debug > 1 && cmd->type != QXL_CURSOR_MOVE) { |
Alistair Francis | a89f364 | 2017-11-08 14:56:31 -0800 | [diff] [blame] | 304 | fprintf(stderr, "%s", __func__); |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 305 | qxl_log_cmd_cursor(qxl, cmd, ext->group_id); |
| 306 | fprintf(stderr, "\n"); |
| 307 | } |
| 308 | switch (cmd->type) { |
| 309 | case QXL_CURSOR_SET: |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 310 | cursor = qxl_phys2virt(qxl, cmd->u.set.shape, ext->group_id); |
Alon Levy | fae2afb | 2012-04-25 12:13:18 +0300 | [diff] [blame] | 311 | if (!cursor) { |
| 312 | return 1; |
| 313 | } |
Gerd Hoffmann | b21330b | 2017-08-28 14:39:33 +0200 | [diff] [blame] | 314 | c = qxl_cursor(qxl, cursor, ext->group_id); |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 315 | if (c == NULL) { |
| 316 | c = cursor_builtin_left_ptr(); |
| 317 | } |
Gerd Hoffmann | 0753609 | 2011-04-27 15:50:32 +0200 | [diff] [blame] | 318 | qemu_mutex_lock(&qxl->ssd.lock); |
| 319 | if (qxl->ssd.cursor) { |
| 320 | cursor_put(qxl->ssd.cursor); |
| 321 | } |
| 322 | qxl->ssd.cursor = c; |
| 323 | qxl->ssd.mouse_x = cmd->u.set.position.x; |
| 324 | qxl->ssd.mouse_y = cmd->u.set.position.y; |
| 325 | qemu_mutex_unlock(&qxl->ssd.lock); |
Gerd Hoffmann | 0b2824e | 2014-11-04 13:59:59 +0100 | [diff] [blame] | 326 | qemu_bh_schedule(qxl->ssd.cursor_bh); |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 327 | break; |
| 328 | case QXL_CURSOR_MOVE: |
Gerd Hoffmann | 0753609 | 2011-04-27 15:50:32 +0200 | [diff] [blame] | 329 | qemu_mutex_lock(&qxl->ssd.lock); |
| 330 | qxl->ssd.mouse_x = cmd->u.position.x; |
| 331 | qxl->ssd.mouse_y = cmd->u.position.y; |
| 332 | qemu_mutex_unlock(&qxl->ssd.lock); |
Gerd Hoffmann | 0b2824e | 2014-11-04 13:59:59 +0100 | [diff] [blame] | 333 | qemu_bh_schedule(qxl->ssd.cursor_bh); |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 334 | break; |
| 335 | } |
Alon Levy | fae2afb | 2012-04-25 12:13:18 +0300 | [diff] [blame] | 336 | return 0; |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 337 | } |