2010-04-27 17:50:11 +08: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-27 02:17:13 +08:00
|
|
|
#include "qemu/osdep.h"
|
2013-03-19 00:36:02 +08:00
|
|
|
#include "qxl.h"
|
2013-12-07 22:09:12 +08:00
|
|
|
#include "trace.h"
|
2010-04-27 17:50:11 +08:00
|
|
|
|
2012-02-27 18:05:09 +08:00
|
|
|
static void qxl_blit(PCIQXLDevice *qxl, QXLRect *rect)
|
2010-04-27 17:50:11 +08:00
|
|
|
{
|
2013-03-05 22:24:14 +08:00
|
|
|
DisplaySurface *surface = qemu_console_surface(qxl->vga.con);
|
|
|
|
uint8_t *dst = surface_data(surface);
|
2012-02-25 05:19:29 +08:00
|
|
|
uint8_t *src;
|
2010-04-27 17:50:11 +08:00
|
|
|
int len, i;
|
|
|
|
|
2013-03-05 22:24:14 +08:00
|
|
|
if (is_buffer_shared(surface)) {
|
2012-02-25 05:19:29 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-03-18 20:46:15 +08:00
|
|
|
trace_qxl_render_blit(qxl->guest_primary.qxl_stride,
|
2012-02-25 05:19:29 +08:00
|
|
|
rect->left, rect->right, rect->top, rect->bottom);
|
|
|
|
src = qxl->guest_primary.data;
|
2012-02-27 18:05:09 +08: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 21:59:07 +08:00
|
|
|
dst += rect->top * qxl->guest_primary.abs_stride;
|
2010-04-27 17:50:11 +08: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 21:59:07 +08:00
|
|
|
dst += qxl->guest_primary.abs_stride;
|
2012-02-27 18:05:09 +08:00
|
|
|
src += qxl->guest_primary.qxl_stride;
|
2010-04-27 17:50:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void qxl_render_resize(PCIQXLDevice *qxl)
|
|
|
|
{
|
|
|
|
QXLSurfaceCreate *sc = &qxl->guest_primary.surface;
|
|
|
|
|
2011-10-21 21:59:07 +08:00
|
|
|
qxl->guest_primary.qxl_stride = sc->stride;
|
|
|
|
qxl->guest_primary.abs_stride = abs(sc->stride);
|
2010-04-27 17:50:11 +08: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:
|
|
|
|
fprintf(stderr, "%s: unhandled format: %x\n", __FUNCTION__,
|
|
|
|
qxl->guest_primary.surface.format);
|
|
|
|
qxl->guest_primary.bytes_pp = 4;
|
|
|
|
qxl->guest_primary.bits_pp = 32;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-25 05:19:31 +08: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 17:50:11 +08:00
|
|
|
{
|
|
|
|
VGACommonState *vga = &qxl->vga;
|
2013-02-28 17:48:02 +08:00
|
|
|
DisplaySurface *surface;
|
2012-02-25 05:19:31 +08:00
|
|
|
int i;
|
2010-04-27 17:50:11 +08:00
|
|
|
|
|
|
|
if (qxl->guest_primary.resized) {
|
|
|
|
qxl->guest_primary.resized = 0;
|
2013-09-06 03:57:19 +08:00
|
|
|
qxl->guest_primary.data = qxl_phys2virt(qxl,
|
|
|
|
qxl->guest_primary.surface.mem,
|
|
|
|
MEMSLOT_GROUP_GUEST);
|
|
|
|
if (!qxl->guest_primary.data) {
|
|
|
|
return;
|
|
|
|
}
|
2012-02-25 05:19:31 +08:00
|
|
|
qxl_set_rect_to_surface(qxl, &qxl->dirty[0]);
|
|
|
|
qxl->num_dirty_rects = 1;
|
2012-03-18 20:46:15 +08:00
|
|
|
trace_qxl_render_guest_primary_resized(
|
2010-04-27 17:50:11 +08:00
|
|
|
qxl->guest_primary.surface.width,
|
|
|
|
qxl->guest_primary.surface.height,
|
2011-10-21 21:59:07 +08:00
|
|
|
qxl->guest_primary.qxl_stride,
|
2010-04-27 17:50:11 +08:00
|
|
|
qxl->guest_primary.bytes_pp,
|
2012-02-25 05:19:29 +08:00
|
|
|
qxl->guest_primary.bits_pp);
|
|
|
|
if (qxl->guest_primary.qxl_stride > 0) {
|
2014-06-18 17:03:15 +08:00
|
|
|
pixman_format_code_t format =
|
|
|
|
qemu_default_pixman_format(qxl->guest_primary.bits_pp, true);
|
2013-02-28 17:48:02 +08:00
|
|
|
surface = qemu_create_displaysurface_from
|
2012-12-10 14:41:07 +08:00
|
|
|
(qxl->guest_primary.surface.width,
|
|
|
|
qxl->guest_primary.surface.height,
|
2014-06-18 17:03:15 +08:00
|
|
|
format,
|
2012-12-10 14:41:07 +08:00
|
|
|
qxl->guest_primary.abs_stride,
|
2014-06-18 17:03:15 +08:00
|
|
|
qxl->guest_primary.data);
|
2012-02-25 05:19:29 +08:00
|
|
|
} else {
|
2013-02-28 17:48:02 +08:00
|
|
|
surface = qemu_create_displaysurface
|
|
|
|
(qxl->guest_primary.surface.width,
|
|
|
|
qxl->guest_primary.surface.height);
|
2012-02-25 05:19:29 +08:00
|
|
|
}
|
2013-03-05 22:24:14 +08:00
|
|
|
dpy_gfx_replace_surface(vga->con, surface);
|
2010-04-27 17:50:11 +08:00
|
|
|
}
|
2013-09-06 03:57:19 +08:00
|
|
|
|
|
|
|
if (!qxl->guest_primary.data) {
|
|
|
|
return;
|
|
|
|
}
|
2012-02-25 05:19:31 +08:00
|
|
|
for (i = 0; i < qxl->num_dirty_rects; i++) {
|
|
|
|
if (qemu_spice_rect_is_empty(qxl->dirty+i)) {
|
2010-04-27 17:50:11 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-08-29 15:27:52 +08:00
|
|
|
if (qxl->dirty[i].left < 0 ||
|
|
|
|
qxl->dirty[i].top < 0 ||
|
|
|
|
qxl->dirty[i].left > qxl->dirty[i].right ||
|
2014-06-10 19:51:12 +08:00
|
|
|
qxl->dirty[i].top > qxl->dirty[i].bottom ||
|
|
|
|
qxl->dirty[i].right > qxl->guest_primary.surface.width ||
|
|
|
|
qxl->dirty[i].bottom > qxl->guest_primary.surface.height) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-02-27 18:05:09 +08:00
|
|
|
qxl_blit(qxl, qxl->dirty+i);
|
2013-03-05 22:24:14 +08:00
|
|
|
dpy_gfx_update(vga->con,
|
2012-09-28 21:02:08 +08: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 17:50:11 +08:00
|
|
|
}
|
2012-02-25 05:19:31 +08:00
|
|
|
qxl->num_dirty_rects = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 05:45:14 +08:00
|
|
|
* callbacks are called by spice_server thread, deferring to bh called from the
|
2012-02-25 05:19:31 +08:00
|
|
|
* io thread.
|
|
|
|
*/
|
|
|
|
void qxl_render_update(PCIQXLDevice *qxl)
|
|
|
|
{
|
|
|
|
QXLCookie *cookie;
|
|
|
|
|
|
|
|
qemu_mutex_lock(&qxl->ssd.lock);
|
|
|
|
|
|
|
|
if (!runstate_is_running() || !qxl->guest_primary.commands) {
|
|
|
|
qxl_render_update_area_unlocked(qxl);
|
|
|
|
qemu_mutex_unlock(&qxl->ssd.lock);
|
|
|
|
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 20:46:15 +08:00
|
|
|
trace_qxl_render_update_area_done(cookie);
|
2012-02-25 05:19:31 +08: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 17:50:11 +08:00
|
|
|
}
|
|
|
|
|
2017-08-28 20:39:33 +08: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;
|
|
|
|
}
|
|
|
|
chunk = qxl_phys2virt(qxl, chunk->next_chunk, group_id);
|
|
|
|
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 17:50:11 +08:00
|
|
|
{
|
|
|
|
QEMUCursor *c;
|
2011-11-09 16:52:55 +08:00
|
|
|
size_t size;
|
2010-04-27 17:50:11 +08:00
|
|
|
|
|
|
|
c = cursor_alloc(cursor->header.width, cursor->header.height);
|
|
|
|
c->hot_x = cursor->header.hot_spot_x;
|
|
|
|
c->hot_y = cursor->header.hot_spot_y;
|
|
|
|
switch (cursor->header.type) {
|
|
|
|
case SPICE_CURSOR_TYPE_ALPHA:
|
2013-06-03 16:36:54 +08:00
|
|
|
size = sizeof(uint32_t) * cursor->header.width * cursor->header.height;
|
2017-08-28 20:39:33 +08:00
|
|
|
qxl_unpack_chunks(c->data, size, qxl, &cursor->chunk, group_id);
|
2010-04-27 17:50:11 +08:00
|
|
|
if (qxl->debug > 2) {
|
|
|
|
cursor_print_ascii_art(c, "qxl/alpha");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s: not implemented: type %d\n",
|
|
|
|
__FUNCTION__, cursor->header.type);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
cursor_put(c);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* called from spice server thread context only */
|
2012-04-25 17:13:18 +08:00
|
|
|
int qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext)
|
2010-04-27 17:50:11 +08:00
|
|
|
{
|
|
|
|
QXLCursorCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id);
|
|
|
|
QXLCursor *cursor;
|
|
|
|
QEMUCursor *c;
|
|
|
|
|
2012-04-25 17:13:18 +08:00
|
|
|
if (!cmd) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-03-05 22:24:14 +08:00
|
|
|
if (!dpy_cursor_define_supported(qxl->vga.con)) {
|
2012-04-25 17:13:18 +08:00
|
|
|
return 0;
|
2010-04-27 17:50:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (qxl->debug > 1 && cmd->type != QXL_CURSOR_MOVE) {
|
|
|
|
fprintf(stderr, "%s", __FUNCTION__);
|
|
|
|
qxl_log_cmd_cursor(qxl, cmd, ext->group_id);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
switch (cmd->type) {
|
|
|
|
case QXL_CURSOR_SET:
|
|
|
|
cursor = qxl_phys2virt(qxl, cmd->u.set.shape, ext->group_id);
|
2012-04-25 17:13:18 +08:00
|
|
|
if (!cursor) {
|
|
|
|
return 1;
|
|
|
|
}
|
2017-08-28 20:39:33 +08:00
|
|
|
c = qxl_cursor(qxl, cursor, ext->group_id);
|
2010-04-27 17:50:11 +08:00
|
|
|
if (c == NULL) {
|
|
|
|
c = cursor_builtin_left_ptr();
|
|
|
|
}
|
2011-04-27 21:50:32 +08: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 20:59:59 +08:00
|
|
|
qemu_bh_schedule(qxl->ssd.cursor_bh);
|
2010-04-27 17:50:11 +08:00
|
|
|
break;
|
|
|
|
case QXL_CURSOR_MOVE:
|
2011-04-27 21:50:32 +08: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 20:59:59 +08:00
|
|
|
qemu_bh_schedule(qxl->ssd.cursor_bh);
|
2010-04-27 17:50:11 +08:00
|
|
|
break;
|
|
|
|
}
|
2012-04-25 17:13:18 +08:00
|
|
|
return 0;
|
2010-04-27 17:50:11 +08:00
|
|
|
}
|