2010-04-27 13:50:11 +04:00
|
|
|
/*
|
|
|
|
* qxl local rendering (aka display on sdl/vnc)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* maintained by Gerd Hoffmann <kraxel@redhat.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 or
|
|
|
|
* (at your option) version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:13 +03:00
|
|
|
#include "qemu/osdep.h"
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "qxl.h"
|
2019-08-12 08:23:59 +03:00
|
|
|
#include "sysemu/runstate.h"
|
2013-12-07 18:09:12 +04:00
|
|
|
#include "trace.h"
|
2010-04-27 13:50:11 +04:00
|
|
|
|
2012-02-27 14:05:09 +04:00
|
|
|
static void qxl_blit(PCIQXLDevice *qxl, QXLRect *rect)
|
2010-04-27 13:50:11 +04:00
|
|
|
{
|
2013-03-05 18:24:14 +04:00
|
|
|
DisplaySurface *surface = qemu_console_surface(qxl->vga.con);
|
|
|
|
uint8_t *dst = surface_data(surface);
|
2012-02-25 01:19:29 +04:00
|
|
|
uint8_t *src;
|
2010-04-27 13:50:11 +04:00
|
|
|
int len, i;
|
|
|
|
|
2013-03-05 18:24:14 +04:00
|
|
|
if (is_buffer_shared(surface)) {
|
2012-02-25 01:19:29 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-03-18 16:46:15 +04:00
|
|
|
trace_qxl_render_blit(qxl->guest_primary.qxl_stride,
|
2012-02-25 01:19:29 +04:00
|
|
|
rect->left, rect->right, rect->top, rect->bottom);
|
|
|
|
src = qxl->guest_primary.data;
|
2012-02-27 14:05:09 +04:00
|
|
|
if (qxl->guest_primary.qxl_stride < 0) {
|
|
|
|
/* qxl surface is upside down, walk src scanlines
|
|
|
|
* in reverse order to flip it */
|
|
|
|
src += (qxl->guest_primary.surface.height - rect->top - 1) *
|
|
|
|
qxl->guest_primary.abs_stride;
|
|
|
|
} else {
|
|
|
|
src += rect->top * qxl->guest_primary.abs_stride;
|
|
|
|
}
|
2011-10-21 17:59:07 +04:00
|
|
|
dst += rect->top * qxl->guest_primary.abs_stride;
|
2010-04-27 13:50:11 +04:00
|
|
|
src += rect->left * qxl->guest_primary.bytes_pp;
|
|
|
|
dst += rect->left * qxl->guest_primary.bytes_pp;
|
|
|
|
len = (rect->right - rect->left) * qxl->guest_primary.bytes_pp;
|
|
|
|
|
|
|
|
for (i = rect->top; i < rect->bottom; i++) {
|
|
|
|
memcpy(dst, src, len);
|
2011-10-21 17:59:07 +04:00
|
|
|
dst += qxl->guest_primary.abs_stride;
|
2012-02-27 14:05:09 +04:00
|
|
|
src += qxl->guest_primary.qxl_stride;
|
2010-04-27 13:50:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void qxl_render_resize(PCIQXLDevice *qxl)
|
|
|
|
{
|
|
|
|
QXLSurfaceCreate *sc = &qxl->guest_primary.surface;
|
|
|
|
|
2011-10-21 17:59:07 +04:00
|
|
|
qxl->guest_primary.qxl_stride = sc->stride;
|
|
|
|
qxl->guest_primary.abs_stride = abs(sc->stride);
|
2010-04-27 13:50:11 +04:00
|
|
|
qxl->guest_primary.resized++;
|
|
|
|
switch (sc->format) {
|
|
|
|
case SPICE_SURFACE_FMT_16_555:
|
|
|
|
qxl->guest_primary.bytes_pp = 2;
|
|
|
|
qxl->guest_primary.bits_pp = 15;
|
|
|
|
break;
|
|
|
|
case SPICE_SURFACE_FMT_16_565:
|
|
|
|
qxl->guest_primary.bytes_pp = 2;
|
|
|
|
qxl->guest_primary.bits_pp = 16;
|
|
|
|
break;
|
|
|
|
case SPICE_SURFACE_FMT_32_xRGB:
|
|
|
|
case SPICE_SURFACE_FMT_32_ARGB:
|
|
|
|
qxl->guest_primary.bytes_pp = 4;
|
|
|
|
qxl->guest_primary.bits_pp = 32;
|
|
|
|
break;
|
|
|
|
default:
|
2017-11-09 01:56:31 +03:00
|
|
|
fprintf(stderr, "%s: unhandled format: %x\n", __func__,
|
2010-04-27 13:50:11 +04:00
|
|
|
qxl->guest_primary.surface.format);
|
|
|
|
qxl->guest_primary.bytes_pp = 4;
|
|
|
|
qxl->guest_primary.bits_pp = 32;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-25 01:19:31 +04:00
|
|
|
static void qxl_set_rect_to_surface(PCIQXLDevice *qxl, QXLRect *area)
|
|
|
|
{
|
|
|
|
area->left = 0;
|
|
|
|
area->right = qxl->guest_primary.surface.width;
|
|
|
|
area->top = 0;
|
|
|
|
area->bottom = qxl->guest_primary.surface.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qxl_render_update_area_unlocked(PCIQXLDevice *qxl)
|
2010-04-27 13:50:11 +04:00
|
|
|
{
|
|
|
|
VGACommonState *vga = &qxl->vga;
|
2013-02-28 13:48:02 +04:00
|
|
|
DisplaySurface *surface;
|
2018-09-19 13:30:57 +03:00
|
|
|
int width = qxl->guest_head0_width ?: qxl->guest_primary.surface.width;
|
|
|
|
int height = qxl->guest_head0_height ?: qxl->guest_primary.surface.height;
|
2012-02-25 01:19:31 +04:00
|
|
|
int i;
|
2010-04-27 13:50:11 +04:00
|
|
|
|
|
|
|
if (qxl->guest_primary.resized) {
|
|
|
|
qxl->guest_primary.resized = 0;
|
2013-09-05 23:57:19 +04:00
|
|
|
qxl->guest_primary.data = qxl_phys2virt(qxl,
|
|
|
|
qxl->guest_primary.surface.mem,
|
2022-11-28 23:27:39 +03:00
|
|
|
MEMSLOT_GROUP_GUEST,
|
|
|
|
qxl->guest_primary.abs_stride
|
|
|
|
* height);
|
2013-09-05 23:57:19 +04:00
|
|
|
if (!qxl->guest_primary.data) {
|
2015-08-24 14:20:49 +03:00
|
|
|
goto end;
|
2013-09-05 23:57:19 +04:00
|
|
|
}
|
2012-02-25 01:19:31 +04:00
|
|
|
qxl_set_rect_to_surface(qxl, &qxl->dirty[0]);
|
|
|
|
qxl->num_dirty_rects = 1;
|
2012-03-18 16:46:15 +04:00
|
|
|
trace_qxl_render_guest_primary_resized(
|
2018-09-19 13:30:57 +03:00
|
|
|
width,
|
|
|
|
height,
|
2011-10-21 17:59:07 +04:00
|
|
|
qxl->guest_primary.qxl_stride,
|
2010-04-27 13:50:11 +04:00
|
|
|
qxl->guest_primary.bytes_pp,
|
2012-02-25 01:19:29 +04:00
|
|
|
qxl->guest_primary.bits_pp);
|
|
|
|
if (qxl->guest_primary.qxl_stride > 0) {
|
2014-06-18 13:03:15 +04:00
|
|
|
pixman_format_code_t format =
|
|
|
|
qemu_default_pixman_format(qxl->guest_primary.bits_pp, true);
|
2013-02-28 13:48:02 +04:00
|
|
|
surface = qemu_create_displaysurface_from
|
2018-09-19 13:30:57 +03:00
|
|
|
(width,
|
|
|
|
height,
|
2014-06-18 13:03:15 +04:00
|
|
|
format,
|
2012-12-10 10:41:07 +04:00
|
|
|
qxl->guest_primary.abs_stride,
|
2014-06-18 13:03:15 +04:00
|
|
|
qxl->guest_primary.data);
|
2012-02-25 01:19:29 +04:00
|
|
|
} else {
|
2013-02-28 13:48:02 +04:00
|
|
|
surface = qemu_create_displaysurface
|
2018-09-19 13:30:57 +03:00
|
|
|
(width,
|
|
|
|
height);
|
2012-02-25 01:19:29 +04:00
|
|
|
}
|
2013-03-05 18:24:14 +04:00
|
|
|
dpy_gfx_replace_surface(vga->con, surface);
|
2010-04-27 13:50:11 +04:00
|
|
|
}
|
2013-09-05 23:57:19 +04:00
|
|
|
|
|
|
|
if (!qxl->guest_primary.data) {
|
2015-08-24 14:20:49 +03:00
|
|
|
goto end;
|
2013-09-05 23:57:19 +04:00
|
|
|
}
|
2012-02-25 01:19:31 +04:00
|
|
|
for (i = 0; i < qxl->num_dirty_rects; i++) {
|
|
|
|
if (qemu_spice_rect_is_empty(qxl->dirty+i)) {
|
2010-04-27 13:50:11 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-08-29 11:27:52 +04:00
|
|
|
if (qxl->dirty[i].left < 0 ||
|
|
|
|
qxl->dirty[i].top < 0 ||
|
|
|
|
qxl->dirty[i].left > qxl->dirty[i].right ||
|
2014-06-10 15:51:12 +04:00
|
|
|
qxl->dirty[i].top > qxl->dirty[i].bottom ||
|
2018-09-19 13:30:57 +03:00
|
|
|
qxl->dirty[i].right > width ||
|
|
|
|
qxl->dirty[i].bottom > height) {
|
2014-06-10 15:51:12 +04:00
|
|
|
continue;
|
|
|
|
}
|
2012-02-27 14:05:09 +04:00
|
|
|
qxl_blit(qxl, qxl->dirty+i);
|
2013-03-05 18:24:14 +04:00
|
|
|
dpy_gfx_update(vga->con,
|
2012-09-28 17:02:08 +04:00
|
|
|
qxl->dirty[i].left, qxl->dirty[i].top,
|
|
|
|
qxl->dirty[i].right - qxl->dirty[i].left,
|
|
|
|
qxl->dirty[i].bottom - qxl->dirty[i].top);
|
2010-04-27 13:50:11 +04:00
|
|
|
}
|
2012-02-25 01:19:31 +04:00
|
|
|
qxl->num_dirty_rects = 0;
|
2015-08-24 14:20:49 +03:00
|
|
|
|
|
|
|
end:
|
|
|
|
if (qxl->render_update_cookie_num == 0) {
|
|
|
|
graphic_hw_update_done(qxl->ssd.dcl.con);
|
|
|
|
}
|
2012-02-25 01:19:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* use ssd.lock to protect render_update_cookie_num.
|
|
|
|
* qxl_render_update is called by io thread or vcpu thread, and the completion
|
2015-09-09 00:45:14 +03:00
|
|
|
* callbacks are called by spice_server thread, deferring to bh called from the
|
2012-02-25 01:19:31 +04:00
|
|
|
* io thread.
|
|
|
|
*/
|
|
|
|
void qxl_render_update(PCIQXLDevice *qxl)
|
|
|
|
{
|
|
|
|
QXLCookie *cookie;
|
|
|
|
|
|
|
|
qemu_mutex_lock(&qxl->ssd.lock);
|
|
|
|
|
2018-04-27 14:55:28 +03:00
|
|
|
if (!runstate_is_running() || !qxl->guest_primary.commands ||
|
|
|
|
qxl->mode == QXL_MODE_UNDEFINED) {
|
2012-02-25 01:19:31 +04:00
|
|
|
qxl_render_update_area_unlocked(qxl);
|
|
|
|
qemu_mutex_unlock(&qxl->ssd.lock);
|
2021-02-01 23:14:22 +03:00
|
|
|
graphic_hw_update_done(qxl->ssd.dcl.con);
|
2012-02-25 01:19:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qxl->guest_primary.commands = 0;
|
|
|
|
qxl->render_update_cookie_num++;
|
|
|
|
qemu_mutex_unlock(&qxl->ssd.lock);
|
|
|
|
cookie = qxl_cookie_new(QXL_COOKIE_TYPE_RENDER_UPDATE_AREA,
|
|
|
|
0);
|
|
|
|
qxl_set_rect_to_surface(qxl, &cookie->u.render.area);
|
|
|
|
qxl_spice_update_area(qxl, 0, &cookie->u.render.area, NULL,
|
|
|
|
0, 1 /* clear_dirty_region */, QXL_ASYNC, cookie);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qxl_render_update_area_bh(void *opaque)
|
|
|
|
{
|
|
|
|
PCIQXLDevice *qxl = opaque;
|
|
|
|
|
|
|
|
qemu_mutex_lock(&qxl->ssd.lock);
|
|
|
|
qxl_render_update_area_unlocked(qxl);
|
|
|
|
qemu_mutex_unlock(&qxl->ssd.lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qxl_render_update_area_done(PCIQXLDevice *qxl, QXLCookie *cookie)
|
|
|
|
{
|
|
|
|
qemu_mutex_lock(&qxl->ssd.lock);
|
2012-03-18 16:46:15 +04:00
|
|
|
trace_qxl_render_update_area_done(cookie);
|
2012-02-25 01:19:31 +04:00
|
|
|
qemu_bh_schedule(qxl->update_area_bh);
|
|
|
|
qxl->render_update_cookie_num--;
|
|
|
|
qemu_mutex_unlock(&qxl->ssd.lock);
|
|
|
|
g_free(cookie);
|
2010-04-27 13:50:11 +04:00
|
|
|
}
|
|
|
|
|
2017-08-28 15:39:33 +03:00
|
|
|
static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,
|
|
|
|
QXLDataChunk *chunk, uint32_t group_id)
|
|
|
|
{
|
|
|
|
uint32_t max_chunks = 32;
|
|
|
|
size_t offset = 0;
|
|
|
|
size_t bytes;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
bytes = MIN(size - offset, chunk->data_size);
|
|
|
|
memcpy(dest + offset, chunk->data, bytes);
|
|
|
|
offset += bytes;
|
|
|
|
if (offset == size) {
|
|
|
|
return;
|
|
|
|
}
|
2022-11-28 23:27:39 +03:00
|
|
|
chunk = qxl_phys2virt(qxl, chunk->next_chunk, group_id,
|
|
|
|
sizeof(QXLDataChunk) + chunk->data_size);
|
2017-08-28 15:39:33 +03:00
|
|
|
if (!chunk) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
max_chunks--;
|
|
|
|
if (max_chunks == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor,
|
|
|
|
uint32_t group_id)
|
2010-04-27 13:50:11 +04:00
|
|
|
{
|
|
|
|
QEMUCursor *c;
|
2018-09-03 17:54:47 +03:00
|
|
|
uint8_t *and_mask, *xor_mask;
|
2011-11-09 12:52:55 +04:00
|
|
|
size_t size;
|
2010-04-27 13:50:11 +04:00
|
|
|
|
|
|
|
c = cursor_alloc(cursor->header.width, cursor->header.height);
|
2022-04-07 11:17:12 +03:00
|
|
|
|
|
|
|
if (!c) {
|
|
|
|
qxl_set_guest_bug(qxl, "%s: cursor %ux%u alloc error", __func__,
|
|
|
|
cursor->header.width, cursor->header.height);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-04-27 13:50:11 +04:00
|
|
|
c->hot_x = cursor->header.hot_spot_x;
|
|
|
|
c->hot_y = cursor->header.hot_spot_y;
|
|
|
|
switch (cursor->header.type) {
|
2018-09-03 17:54:47 +03:00
|
|
|
case SPICE_CURSOR_TYPE_MONO:
|
|
|
|
/* Assume that the full cursor is available in a single chunk. */
|
|
|
|
size = 2 * cursor_get_mono_bpl(c) * c->height;
|
|
|
|
if (size != cursor->data_size) {
|
|
|
|
fprintf(stderr, "%s: bad monochrome cursor %ux%u with size %u\n",
|
|
|
|
__func__, c->width, c->height, cursor->data_size);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
and_mask = cursor->chunk.data;
|
|
|
|
xor_mask = and_mask + cursor_get_mono_bpl(c) * c->height;
|
|
|
|
cursor_set_mono(c, 0xffffff, 0x000000, xor_mask, 1, and_mask);
|
|
|
|
if (qxl->debug > 2) {
|
|
|
|
cursor_print_ascii_art(c, "qxl/mono");
|
|
|
|
}
|
|
|
|
break;
|
2010-04-27 13:50:11 +04:00
|
|
|
case SPICE_CURSOR_TYPE_ALPHA:
|
2022-04-07 11:11:06 +03:00
|
|
|
size = sizeof(uint32_t) * c->width * c->height;
|
2017-08-28 15:39:33 +03:00
|
|
|
qxl_unpack_chunks(c->data, size, qxl, &cursor->chunk, group_id);
|
2010-04-27 13:50:11 +04:00
|
|
|
if (qxl->debug > 2) {
|
|
|
|
cursor_print_ascii_art(c, "qxl/alpha");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s: not implemented: type %d\n",
|
2017-11-09 01:56:31 +03:00
|
|
|
__func__, cursor->header.type);
|
2010-04-27 13:50:11 +04:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
cursor_put(c);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* called from spice server thread context only */
|
2012-04-25 13:13:18 +04:00
|
|
|
int qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext)
|
2010-04-27 13:50:11 +04:00
|
|
|
{
|
2022-11-28 23:27:39 +03:00
|
|
|
QXLCursorCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id,
|
|
|
|
sizeof(QXLCursorCmd));
|
2010-04-27 13:50:11 +04:00
|
|
|
QXLCursor *cursor;
|
|
|
|
QEMUCursor *c;
|
|
|
|
|
2012-04-25 13:13:18 +04:00
|
|
|
if (!cmd) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:24:14 +04:00
|
|
|
if (!dpy_cursor_define_supported(qxl->vga.con)) {
|
2012-04-25 13:13:18 +04:00
|
|
|
return 0;
|
2010-04-27 13:50:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (qxl->debug > 1 && cmd->type != QXL_CURSOR_MOVE) {
|
2017-11-09 01:56:31 +03:00
|
|
|
fprintf(stderr, "%s", __func__);
|
2010-04-27 13:50:11 +04:00
|
|
|
qxl_log_cmd_cursor(qxl, cmd, ext->group_id);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
switch (cmd->type) {
|
|
|
|
case QXL_CURSOR_SET:
|
2022-11-28 23:27:39 +03:00
|
|
|
/* First read the QXLCursor to get QXLDataChunk::data_size ... */
|
|
|
|
cursor = qxl_phys2virt(qxl, cmd->u.set.shape, ext->group_id,
|
|
|
|
sizeof(QXLCursor));
|
|
|
|
if (!cursor) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* Then read including the chunked data following QXLCursor. */
|
|
|
|
cursor = qxl_phys2virt(qxl, cmd->u.set.shape, ext->group_id,
|
|
|
|
sizeof(QXLCursor) + cursor->chunk.data_size);
|
2012-04-25 13:13:18 +04:00
|
|
|
if (!cursor) {
|
|
|
|
return 1;
|
|
|
|
}
|
2017-08-28 15:39:33 +03:00
|
|
|
c = qxl_cursor(qxl, cursor, ext->group_id);
|
2010-04-27 13:50:11 +04:00
|
|
|
if (c == NULL) {
|
|
|
|
c = cursor_builtin_left_ptr();
|
|
|
|
}
|
2011-04-27 17:50:32 +04:00
|
|
|
qemu_mutex_lock(&qxl->ssd.lock);
|
|
|
|
if (qxl->ssd.cursor) {
|
|
|
|
cursor_put(qxl->ssd.cursor);
|
|
|
|
}
|
|
|
|
qxl->ssd.cursor = c;
|
|
|
|
qxl->ssd.mouse_x = cmd->u.set.position.x;
|
|
|
|
qxl->ssd.mouse_y = cmd->u.set.position.y;
|
|
|
|
qemu_mutex_unlock(&qxl->ssd.lock);
|
2014-11-04 15:59:59 +03:00
|
|
|
qemu_bh_schedule(qxl->ssd.cursor_bh);
|
2010-04-27 13:50:11 +04:00
|
|
|
break;
|
|
|
|
case QXL_CURSOR_MOVE:
|
2011-04-27 17:50:32 +04:00
|
|
|
qemu_mutex_lock(&qxl->ssd.lock);
|
|
|
|
qxl->ssd.mouse_x = cmd->u.position.x;
|
|
|
|
qxl->ssd.mouse_y = cmd->u.position.y;
|
|
|
|
qemu_mutex_unlock(&qxl->ssd.lock);
|
2014-11-04 15:59:59 +03:00
|
|
|
qemu_bh_schedule(qxl->ssd.cursor_bh);
|
2010-04-27 13:50:11 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-04-25 13:13:18 +04:00
|
|
|
return 0;
|
2010-04-27 13:50:11 +04:00
|
|
|
}
|