console: stop using PixelFormat

With this patch the qemu console core stops using PixelFormat and pixman
format codes side-by-side, pixman format code is the primary way to
specify the DisplaySurface format:

 * DisplaySurface stops carrying a PixelFormat field.
 * qemu_create_displaysurface_from() expects a pixman format now.

Functions to convert PixelFormat to pixman_format_code_t (and back)
exist for those who still use PixelFormat.   As PixelFormat allows
easy access to masks and shifts it will probably continue to exist.

[ xenfb added by Benjamin Herrenschmidt ]

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Gerd Hoffmann 2014-06-18 11:03:15 +02:00
parent 56bd9ea1a3
commit 30f1e661b6
8 changed files with 42 additions and 45 deletions

View File

@ -116,13 +116,14 @@ static void qxl_render_update_area_unlocked(PCIQXLDevice *qxl)
qxl->guest_primary.bytes_pp, qxl->guest_primary.bytes_pp,
qxl->guest_primary.bits_pp); qxl->guest_primary.bits_pp);
if (qxl->guest_primary.qxl_stride > 0) { if (qxl->guest_primary.qxl_stride > 0) {
pixman_format_code_t format =
qemu_default_pixman_format(qxl->guest_primary.bits_pp, true);
surface = qemu_create_displaysurface_from surface = qemu_create_displaysurface_from
(qxl->guest_primary.surface.width, (qxl->guest_primary.surface.width,
qxl->guest_primary.surface.height, qxl->guest_primary.surface.height,
qxl->guest_primary.bits_pp, format,
qxl->guest_primary.abs_stride, qxl->guest_primary.abs_stride,
qxl->guest_primary.data, qxl->guest_primary.data);
false);
} else { } else {
surface = qemu_create_displaysurface surface = qemu_create_displaysurface
(qxl->guest_primary.surface.width, (qxl->guest_primary.surface.width,

View File

@ -1689,9 +1689,11 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)
height != s->last_height || height != s->last_height ||
s->last_depth != depth) { s->last_depth != depth) {
if (depth == 32 || (depth == 16 && !byteswap)) { if (depth == 32 || (depth == 16 && !byteswap)) {
pixman_format_code_t format =
qemu_default_pixman_format(depth, !byteswap);
surface = qemu_create_displaysurface_from(disp_width, surface = qemu_create_displaysurface_from(disp_width,
height, depth, s->line_offset, height, format, s->line_offset,
s->vram_ptr + (s->start_addr * 4), byteswap); s->vram_ptr + (s->start_addr * 4));
dpy_gfx_replace_surface(s->con, surface); dpy_gfx_replace_surface(s->con, surface);
} else { } else {
qemu_console_resize(s->con, disp_width, height); qemu_console_resize(s->con, disp_width, height);
@ -1707,9 +1709,11 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)
} else if (is_buffer_shared(surface) && } else if (is_buffer_shared(surface) &&
(full_update || surface_data(surface) != s->vram_ptr (full_update || surface_data(surface) != s->vram_ptr
+ (s->start_addr * 4))) { + (s->start_addr * 4))) {
pixman_format_code_t format =
qemu_default_pixman_format(depth, !byteswap);
surface = qemu_create_displaysurface_from(disp_width, surface = qemu_create_displaysurface_from(disp_width,
height, depth, s->line_offset, height, format, s->line_offset,
s->vram_ptr + (s->start_addr * 4), byteswap); s->vram_ptr + (s->start_addr * 4));
dpy_gfx_replace_surface(s->con, surface); dpy_gfx_replace_surface(s->con, surface);
} }

View File

@ -1052,10 +1052,12 @@ static inline void vmsvga_check_size(struct vmsvga_state_s *s)
s->new_height != surface_height(surface) || s->new_height != surface_height(surface) ||
s->new_depth != surface_bits_per_pixel(surface)) { s->new_depth != surface_bits_per_pixel(surface)) {
int stride = (s->new_depth * s->new_width) / 8; int stride = (s->new_depth * s->new_width) / 8;
pixman_format_code_t format =
qemu_default_pixman_format(s->new_depth, true);
trace_vmware_setmode(s->new_width, s->new_height, s->new_depth); trace_vmware_setmode(s->new_width, s->new_height, s->new_depth);
surface = qemu_create_displaysurface_from(s->new_width, s->new_height, surface = qemu_create_displaysurface_from(s->new_width, s->new_height,
s->new_depth, stride, format, stride,
s->vga.vram_ptr, false); s->vga.vram_ptr);
dpy_gfx_replace_surface(s->vga.con, surface); dpy_gfx_replace_surface(s->vga.con, surface);
s->invalidated = 1; s->invalidated = 1;
} }

View File

@ -713,15 +713,17 @@ static void xenfb_update(void *opaque)
/* resize if needed */ /* resize if needed */
if (xenfb->do_resize) { if (xenfb->do_resize) {
pixman_format_code_t format;
xenfb->do_resize = 0; xenfb->do_resize = 0;
switch (xenfb->depth) { switch (xenfb->depth) {
case 16: case 16:
case 32: case 32:
/* console.c supported depth -> buffer can be used directly */ /* console.c supported depth -> buffer can be used directly */
format = qemu_default_pixman_format(xenfb->depth, true);
surface = qemu_create_displaysurface_from surface = qemu_create_displaysurface_from
(xenfb->width, xenfb->height, xenfb->depth, (xenfb->width, xenfb->height, format,
xenfb->row_stride, xenfb->pixels + xenfb->offset, xenfb->row_stride, xenfb->pixels + xenfb->offset);
false);
break; break;
default: default:
/* we must convert stuff */ /* we must convert stuff */

View File

@ -119,8 +119,6 @@ struct DisplaySurface {
pixman_format_code_t format; pixman_format_code_t format;
pixman_image_t *image; pixman_image_t *image;
uint8_t flags; uint8_t flags;
struct PixelFormat pf;
}; };
typedef struct QemuUIInfo { typedef struct QemuUIInfo {
@ -188,9 +186,9 @@ struct DisplayChangeListener {
}; };
DisplayState *init_displaystate(void); DisplayState *init_displaystate(void);
DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp, DisplaySurface *qemu_create_displaysurface_from(int width, int height,
int linesize, uint8_t *data, pixman_format_code_t format,
bool byteswap); int linesize, uint8_t *data);
PixelFormat qemu_different_endianness_pixelformat(int bpp); PixelFormat qemu_different_endianness_pixelformat(int bpp);
PixelFormat qemu_default_pixelformat(int bpp); PixelFormat qemu_default_pixelformat(int bpp);
@ -199,10 +197,12 @@ void qemu_free_displaysurface(DisplaySurface *surface);
static inline int is_surface_bgr(DisplaySurface *surface) static inline int is_surface_bgr(DisplaySurface *surface)
{ {
if (surface->pf.bits_per_pixel == 32 && surface->pf.rshift == 0) if (PIXMAN_FORMAT_BPP(surface->format) == 32 &&
PIXMAN_FORMAT_TYPE(surface->format) == PIXMAN_TYPE_ABGR) {
return 1; return 1;
else } else {
return 0; return 0;
}
} }
static inline int is_buffer_shared(DisplaySurface *surface) static inline int is_buffer_shared(DisplaySurface *surface)

View File

@ -1045,7 +1045,7 @@ console_txt_new(int w, int h) "%dx%d"
console_select(int nr) "%d" console_select(int nr) "%d"
console_refresh(int interval) "interval %d ms" console_refresh(int interval) "interval %d ms"
displaysurface_create(void *display_surface, int w, int h) "surface=%p, %dx%d" displaysurface_create(void *display_surface, int w, int h) "surface=%p, %dx%d"
displaysurface_create_from(void *display_surface, int w, int h, int bpp, int swap) "surface=%p, %dx%d, bpp %d, bswap %d" displaysurface_create_from(void *display_surface, int w, int h, uint32_t format) "surface=%p, %dx%d, format 0x%x"
displaysurface_free(void *display_surface) "surface=%p" displaysurface_free(void *display_surface) "surface=%p"
displaychangelistener_register(void *dcl, const char *name) "%p [ %s ]" displaychangelistener_register(void *dcl, const char *name) "%p [ %s ]"
displaychangelistener_unregister(void *dcl, const char *name) "%p [ %s ]" displaychangelistener_unregister(void *dcl, const char *name) "%p [ %s ]"

View File

@ -1224,22 +1224,18 @@ static QemuConsole *new_console(DisplayState *ds, console_type_t console_type,
return s; return s;
} }
static void qemu_alloc_display(DisplaySurface *surface, int width, int height, static void qemu_alloc_display(DisplaySurface *surface, int width, int height)
int linesize, PixelFormat pf, int newflags)
{ {
surface->pf = pf;
qemu_pixman_image_unref(surface->image); qemu_pixman_image_unref(surface->image);
surface->image = NULL; surface->image = NULL;
surface->format = qemu_pixman_get_format(&pf); surface->format = PIXMAN_x8r8g8b8;
assert(surface->format != 0);
surface->image = pixman_image_create_bits(surface->format, surface->image = pixman_image_create_bits(surface->format,
width, height, width, height,
NULL, linesize); NULL, width * 4);
assert(surface->image != NULL); assert(surface->image != NULL);
surface->flags = newflags | QEMU_ALLOCATED_FLAG; surface->flags = QEMU_ALLOCATED_FLAG;
#ifdef HOST_WORDS_BIGENDIAN #ifdef HOST_WORDS_BIGENDIAN
surface->flags |= QEMU_BIG_ENDIAN_FLAG; surface->flags |= QEMU_BIG_ENDIAN_FLAG;
#endif #endif
@ -1248,29 +1244,20 @@ static void qemu_alloc_display(DisplaySurface *surface, int width, int height,
DisplaySurface *qemu_create_displaysurface(int width, int height) DisplaySurface *qemu_create_displaysurface(int width, int height)
{ {
DisplaySurface *surface = g_new0(DisplaySurface, 1); DisplaySurface *surface = g_new0(DisplaySurface, 1);
int linesize = width * 4;
trace_displaysurface_create(surface, width, height); trace_displaysurface_create(surface, width, height);
qemu_alloc_display(surface, width, height, linesize, qemu_alloc_display(surface, width, height);
qemu_default_pixelformat(32), 0);
return surface; return surface;
} }
DisplaySurface *qemu_create_displaysurface_from(int width, int height, int bpp, DisplaySurface *qemu_create_displaysurface_from(int width, int height,
int linesize, uint8_t *data, pixman_format_code_t format,
bool byteswap) int linesize, uint8_t *data)
{ {
DisplaySurface *surface = g_new0(DisplaySurface, 1); DisplaySurface *surface = g_new0(DisplaySurface, 1);
trace_displaysurface_create_from(surface, width, height, bpp, byteswap); trace_displaysurface_create_from(surface, width, height, format);
if (byteswap) { surface->format = format;
surface->pf = qemu_different_endianness_pixelformat(bpp);
} else {
surface->pf = qemu_default_pixelformat(bpp);
}
surface->format = qemu_pixman_get_format(&surface->pf);
assert(surface->format != 0);
surface->image = pixman_image_create_bits(surface->format, surface->image = pixman_image_create_bits(surface->format,
width, height, width, height,
(void *)data, linesize); (void *)data, linesize);

View File

@ -127,6 +127,7 @@ static void do_sdl_resize(int width, int height, int bpp)
static void sdl_switch(DisplayChangeListener *dcl, static void sdl_switch(DisplayChangeListener *dcl,
DisplaySurface *new_surface) DisplaySurface *new_surface)
{ {
PixelFormat pf = qemu_pixelformat_from_pixman(new_surface->format);
/* temporary hack: allows to call sdl_switch to handle scaling changes */ /* temporary hack: allows to call sdl_switch to handle scaling changes */
if (new_surface) { if (new_surface) {
@ -148,8 +149,8 @@ static void sdl_switch(DisplayChangeListener *dcl,
(surface_data(surface), (surface_data(surface),
surface_width(surface), surface_height(surface), surface_width(surface), surface_height(surface),
surface_bits_per_pixel(surface), surface_stride(surface), surface_bits_per_pixel(surface), surface_stride(surface),
surface->pf.rmask, surface->pf.gmask, pf.rmask, pf.gmask,
surface->pf.bmask, surface->pf.amask); pf.bmask, pf.amask);
} }
/* generic keyboard conversion */ /* generic keyboard conversion */