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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qxl.h"
|
|
|
|
|
2012-02-27 14:05:09 +04:00
|
|
|
static void qxl_blit(PCIQXLDevice *qxl, QXLRect *rect)
|
2010-04-27 13:50:11 +04:00
|
|
|
{
|
2012-02-25 01:19:29 +04:00
|
|
|
uint8_t *src;
|
|
|
|
uint8_t *dst = qxl->vga.ds->surface->data;
|
2010-04-27 13:50:11 +04:00
|
|
|
int len, i;
|
|
|
|
|
2012-02-27 14:05:09 +04:00
|
|
|
if (is_buffer_shared(qxl->vga.ds->surface)) {
|
2012-02-25 01:19:29 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!qxl->guest_primary.data) {
|
2012-03-18 16:46:15 +04:00
|
|
|
trace_qxl_render_blit_guest_primary_initialized();
|
2012-02-25 01:19:29 +04:00
|
|
|
qxl->guest_primary.data = memory_region_get_ram_ptr(&qxl->vga.vram);
|
|
|
|
}
|
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:
|
|
|
|
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 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;
|
2012-02-25 01:19:31 +04:00
|
|
|
int i;
|
2012-02-25 01:19:29 +04:00
|
|
|
DisplaySurface *surface = vga->ds->surface;
|
2010-04-27 13:50:11 +04:00
|
|
|
|
|
|
|
if (qxl->guest_primary.resized) {
|
|
|
|
qxl->guest_primary.resized = 0;
|
2011-08-08 17:08:57 +04:00
|
|
|
qxl->guest_primary.data = memory_region_get_ram_ptr(&qxl->vga.vram);
|
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(
|
2010-04-27 13:50:11 +04:00
|
|
|
qxl->guest_primary.surface.width,
|
|
|
|
qxl->guest_primary.surface.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 (surface->width != qxl->guest_primary.surface.width ||
|
|
|
|
surface->height != qxl->guest_primary.surface.height) {
|
|
|
|
if (qxl->guest_primary.qxl_stride > 0) {
|
|
|
|
qemu_free_displaysurface(vga->ds);
|
2010-04-27 13:50:11 +04:00
|
|
|
qemu_create_displaysurface_from(qxl->guest_primary.surface.width,
|
|
|
|
qxl->guest_primary.surface.height,
|
|
|
|
qxl->guest_primary.bits_pp,
|
2011-10-21 17:59:07 +04:00
|
|
|
qxl->guest_primary.abs_stride,
|
2012-02-25 01:19:29 +04:00
|
|
|
qxl->guest_primary.data);
|
|
|
|
} else {
|
|
|
|
qemu_resize_displaysurface(vga->ds,
|
|
|
|
qxl->guest_primary.surface.width,
|
|
|
|
qxl->guest_primary.surface.height);
|
|
|
|
}
|
2012-04-18 13:27:00 +04:00
|
|
|
dpy_resize(vga->ds);
|
2010-04-27 13:50:11 +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;
|
|
|
|
}
|
2012-02-27 14:05:09 +04:00
|
|
|
qxl_blit(qxl, qxl->dirty+i);
|
2010-04-27 13:50:11 +04:00
|
|
|
dpy_update(vga->ds,
|
2012-02-25 01:19:31 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* use ssd.lock to protect render_update_cookie_num.
|
|
|
|
* qxl_render_update is called by io thread or vcpu thread, and the completion
|
|
|
|
* callbacks are called by spice_server thread, defering to bh called from the
|
|
|
|
* 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 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
|
|
|
}
|
|
|
|
|
|
|
|
static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor)
|
|
|
|
{
|
|
|
|
QEMUCursor *c;
|
|
|
|
uint8_t *image, *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);
|
|
|
|
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:
|
|
|
|
size = cursor->header.width * cursor->header.height * sizeof(uint32_t);
|
|
|
|
memcpy(c->data, cursor->chunk.data, size);
|
|
|
|
if (qxl->debug > 2) {
|
|
|
|
cursor_print_ascii_art(c, "qxl/alpha");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SPICE_CURSOR_TYPE_MONO:
|
|
|
|
mask = cursor->chunk.data;
|
|
|
|
image = mask + cursor_get_mono_bpl(c) * c->width;
|
|
|
|
cursor_set_mono(c, 0xffffff, 0x000000, image, 1, mask);
|
|
|
|
if (qxl->debug > 2) {
|
|
|
|
cursor_print_ascii_art(c, "qxl/mono");
|
|
|
|
}
|
|
|
|
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 */
|
|
|
|
void qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext)
|
|
|
|
{
|
|
|
|
QXLCursorCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id);
|
|
|
|
QXLCursor *cursor;
|
|
|
|
QEMUCursor *c;
|
|
|
|
|
|
|
|
if (!qxl->ssd.ds->mouse_set || !qxl->ssd.ds->cursor_define) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (cursor->chunk.data_size != cursor->data_size) {
|
|
|
|
fprintf(stderr, "%s: multiple chunks\n", __FUNCTION__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
c = qxl_cursor(qxl, cursor);
|
|
|
|
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);
|
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);
|
2010-04-27 13:50:11 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|