2 * qxl local rendering (aka display on sdl/vnc)
4 * Copyright (C) 2010 Red Hat, Inc.
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.
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.
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/>.
24 static void qxl_flip(PCIQXLDevice *qxl, QXLRect *rect)
27 uint8_t *dst = qxl->vga.ds->surface->data;
30 if (qxl->guest_primary.qxl_stride > 0) {
33 if (!qxl->guest_primary.data) {
34 dprint(qxl, 1, "%s: initializing guest_primary.data\n", __func__);
35 qxl->guest_primary.data = memory_region_get_ram_ptr(&qxl->vga.vram);
37 dprint(qxl, 1, "%s: stride %d, [%d, %d, %d, %d]\n", __func__,
38 qxl->guest_primary.qxl_stride,
39 rect->left, rect->right, rect->top, rect->bottom);
40 src = qxl->guest_primary.data;
41 src += (qxl->guest_primary.surface.height - rect->top - 1) *
42 qxl->guest_primary.abs_stride;
43 dst += rect->top * qxl->guest_primary.abs_stride;
44 src += rect->left * qxl->guest_primary.bytes_pp;
45 dst += rect->left * qxl->guest_primary.bytes_pp;
46 len = (rect->right - rect->left) * qxl->guest_primary.bytes_pp;
48 for (i = rect->top; i < rect->bottom; i++) {
49 memcpy(dst, src, len);
50 dst += qxl->guest_primary.abs_stride;
51 src -= qxl->guest_primary.abs_stride;
55 void qxl_render_resize(PCIQXLDevice *qxl)
57 QXLSurfaceCreate *sc = &qxl->guest_primary.surface;
59 qxl->guest_primary.qxl_stride = sc->stride;
60 qxl->guest_primary.abs_stride = abs(sc->stride);
61 qxl->guest_primary.resized++;
63 case SPICE_SURFACE_FMT_16_555:
64 qxl->guest_primary.bytes_pp = 2;
65 qxl->guest_primary.bits_pp = 15;
67 case SPICE_SURFACE_FMT_16_565:
68 qxl->guest_primary.bytes_pp = 2;
69 qxl->guest_primary.bits_pp = 16;
71 case SPICE_SURFACE_FMT_32_xRGB:
72 case SPICE_SURFACE_FMT_32_ARGB:
73 qxl->guest_primary.bytes_pp = 4;
74 qxl->guest_primary.bits_pp = 32;
77 fprintf(stderr, "%s: unhandled format: %x\n", __FUNCTION__,
78 qxl->guest_primary.surface.format);
79 qxl->guest_primary.bytes_pp = 4;
80 qxl->guest_primary.bits_pp = 32;
85 void qxl_render_update(PCIQXLDevice *qxl)
87 VGACommonState *vga = &qxl->vga;
88 QXLRect dirty[32], update;
90 DisplaySurface *surface = vga->ds->surface;
92 if (qxl->guest_primary.resized) {
93 qxl->guest_primary.resized = 0;
95 qxl->guest_primary.data = memory_region_get_ram_ptr(&qxl->vga.vram);
96 dprint(qxl, 1, "%s: %dx%d, stride %d, bpp %d, depth %d\n",
98 qxl->guest_primary.surface.width,
99 qxl->guest_primary.surface.height,
100 qxl->guest_primary.qxl_stride,
101 qxl->guest_primary.bytes_pp,
102 qxl->guest_primary.bits_pp);
104 if (surface->width != qxl->guest_primary.surface.width ||
105 surface->height != qxl->guest_primary.surface.height) {
106 dprint(qxl, 1, "%s: resizing displaysurface to guest_primary\n",
108 if (qxl->guest_primary.qxl_stride > 0) {
109 qemu_free_displaysurface(vga->ds);
110 qemu_create_displaysurface_from(qxl->guest_primary.surface.width,
111 qxl->guest_primary.surface.height,
112 qxl->guest_primary.bits_pp,
113 qxl->guest_primary.abs_stride,
114 qxl->guest_primary.data);
116 qemu_resize_displaysurface(vga->ds,
117 qxl->guest_primary.surface.width,
118 qxl->guest_primary.surface.height);
122 update.right = qxl->guest_primary.surface.width;
124 update.bottom = qxl->guest_primary.surface.height;
126 memset(dirty, 0, sizeof(dirty));
127 if (runstate_is_running() && qxl->guest_primary.commands) {
128 qxl->guest_primary.commands = 0;
129 qxl_spice_update_area(qxl, 0, &update,
130 dirty, ARRAY_SIZE(dirty), 1, QXL_SYNC, NULL);
133 memset(dirty, 0, sizeof(dirty));
136 for (i = 0; i < ARRAY_SIZE(dirty); i++) {
137 if (qemu_spice_rect_is_empty(dirty+i)) {
140 qxl_flip(qxl, dirty+i);
142 dirty[i].left, dirty[i].top,
143 dirty[i].right - dirty[i].left,
144 dirty[i].bottom - dirty[i].top);
148 static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor)
151 uint8_t *image, *mask;
154 c = cursor_alloc(cursor->header.width, cursor->header.height);
155 c->hot_x = cursor->header.hot_spot_x;
156 c->hot_y = cursor->header.hot_spot_y;
157 switch (cursor->header.type) {
158 case SPICE_CURSOR_TYPE_ALPHA:
159 size = cursor->header.width * cursor->header.height * sizeof(uint32_t);
160 memcpy(c->data, cursor->chunk.data, size);
161 if (qxl->debug > 2) {
162 cursor_print_ascii_art(c, "qxl/alpha");
165 case SPICE_CURSOR_TYPE_MONO:
166 mask = cursor->chunk.data;
167 image = mask + cursor_get_mono_bpl(c) * c->width;
168 cursor_set_mono(c, 0xffffff, 0x000000, image, 1, mask);
169 if (qxl->debug > 2) {
170 cursor_print_ascii_art(c, "qxl/mono");
174 fprintf(stderr, "%s: not implemented: type %d\n",
175 __FUNCTION__, cursor->header.type);
186 /* called from spice server thread context only */
187 void qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext)
189 QXLCursorCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id);
193 if (!qxl->ssd.ds->mouse_set || !qxl->ssd.ds->cursor_define) {
197 if (qxl->debug > 1 && cmd->type != QXL_CURSOR_MOVE) {
198 fprintf(stderr, "%s", __FUNCTION__);
199 qxl_log_cmd_cursor(qxl, cmd, ext->group_id);
200 fprintf(stderr, "\n");
204 cursor = qxl_phys2virt(qxl, cmd->u.set.shape, ext->group_id);
205 if (cursor->chunk.data_size != cursor->data_size) {
206 fprintf(stderr, "%s: multiple chunks\n", __FUNCTION__);
209 c = qxl_cursor(qxl, cursor);
211 c = cursor_builtin_left_ptr();
213 qemu_mutex_lock(&qxl->ssd.lock);
214 if (qxl->ssd.cursor) {
215 cursor_put(qxl->ssd.cursor);
218 qxl->ssd.mouse_x = cmd->u.set.position.x;
219 qxl->ssd.mouse_y = cmd->u.set.position.y;
220 qemu_mutex_unlock(&qxl->ssd.lock);
222 case QXL_CURSOR_MOVE:
223 qemu_mutex_lock(&qxl->ssd.lock);
224 qxl->ssd.mouse_x = cmd->u.position.x;
225 qxl->ssd.mouse_y = cmd->u.position.y;
226 qemu_mutex_unlock(&qxl->ssd.lock);