sync DisplayAllocator interface
Hi all,
this simple patch sync's the DisplayAllocator interface with upstream qemu. The only non trivial change, is the new ability for sdl to support the DisplayAllocator interface, hence improving performances (avoid a memcpy) when the guest is in text mode or uses a color depth of 8bpp or 24bpp (no DisplayState surface sharing allowed).
Signed-off-by Stefano Stabellini <[email protected]>
---
console.c +9 -10
@@ -1033,8 +1033,7 @@ void console_select(unsigned int index)DisplayState *ds = s->ds; active_console = s;if (ds_get_bits_per_pixel (s->ds)) { - ds->surface =qemu_resize_displaysurface (ds, s->g_width, - s->g_height,32 ,4 * s->g_width); + ds->surface =qemu_resize_displaysurface (ds, s->g_width, s->g_height); }else { s->ds->surface->width = s->width; s->ds->surface->height = s->height;
@@ -1243,7 +1242,7 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update, ds = (DisplayState *)qemu_mallocz (sizeof (DisplayState)); ds->allocator = &default_allocator; - ds->surface =qemu_create_displaysurface (ds,640 ,480 ,32 ,640 *4 ); + ds->surface =qemu_create_displaysurface (ds,640 ,480 ); s =new_console (ds,GRAPHIC_CONSOLE );if (s ==NULL ) {
@@ -1395,7 +1394,7 @@ void qemu_console_resize(DisplayState *ds, int width, int height) s->g_width = width; s->g_height = height;if (is_graphic_console ()) { - ds->surface =qemu_resize_displaysurface (ds, width, height,32 ,4 * width); + ds->surface =qemu_resize_displaysurface (ds, width, height);dpy_resize (ds); } }
@@ -1518,14 +1517,14 @@ PixelFormat qemu_default_pixelformat(int bpp)return pf; } -DisplaySurface *defaultallocator_create_displaysurface (int width,int height,int bpp,int linesize) +DisplaySurface *defaultallocator_create_displaysurface (int width,int height) {DisplaySurface *surface = (DisplaySurface *)qemu_mallocz (sizeof (DisplaySurface)); surface->width = width; surface->height = height; - surface->linesize = linesize; - surface->pf =qemu_default_pixelformat (bpp); + surface->linesize = width *4 ; + surface->pf =qemu_default_pixelformat (32 );#ifdef WORDS_BIGENDIAN surface->flags =QEMU_ALLOCATED_FLAG |QEMU_BIG_ENDIAN_FLAG ;#else
@@ -1537,12 +1536,12 @@ DisplaySurface* defaultallocator_create_displaysurface(int width, int height, in }DisplaySurface *defaultallocator_resize_displaysurface (DisplaySurface *surface, -int width,int height,int bpp,int linesize) +int width,int height) { surface->width = width; surface->height = height; - surface->linesize = linesize; - surface->pf =qemu_default_pixelformat (bpp); + surface->linesize = width *4 ; + surface->pf =qemu_default_pixelformat (32 );if (surface->flags &QEMU_ALLOCATED_FLAG ) surface->data = (uint8_t *)qemu_realloc (surface->data, surface->linesize * surface->height);else
console.h +16 -10
@@ -108,9 +108,8 @@ struct DisplayChangeListener { };struct DisplayAllocator { -DisplaySurface * (*create_displaysurface)(int width,int height,int bpp,int linesize); -DisplaySurface * (*resize_displaysurface)(DisplaySurface *surface, -int width,int height,int bpp,int linesize); +DisplaySurface * (*create_displaysurface)(int width,int height); +DisplaySurface * (*resize_displaysurface)(DisplaySurface *surface,int width,int height);void (*free_displaysurface)(DisplaySurface *surface); };
@@ -138,19 +137,18 @@ PixelFormat qemu_default_pixelformat(int bpp);extern struct DisplayAllocator default_allocator;DisplayAllocator *register_displayallocator (DisplayState *ds,DisplayAllocator *da); -DisplaySurface *defaultallocator_create_displaysurface (int width,int height,int bpp,int linesize); -DisplaySurface *defaultallocator_resize_displaysurface (DisplaySurface *surface, -int width,int height,int bpp,int linesize); +DisplaySurface *defaultallocator_create_displaysurface (int width,int height); +DisplaySurface *defaultallocator_resize_displaysurface (DisplaySurface *surface,int width,int height);void defaultallocator_free_displaysurface (DisplaySurface *surface); -static inline DisplaySurface *qemu_create_displaysurface (DisplayState *ds,int width,int height,int bpp,int linesize) +static inline DisplaySurface *qemu_create_displaysurface (DisplayState *ds,int width,int height) { -return ds->allocator->create_displaysurface (width, height, bpp, linesize); +return ds->allocator->create_displaysurface (width, height); } -static inline DisplaySurface *qemu_resize_displaysurface (DisplayState *ds,int width,int height,int bpp,int linesize) +static inline DisplaySurface *qemu_resize_displaysurface (DisplayState *ds,int width,int height) { -return ds->allocator->resize_displaysurface (ds->surface, width, height, bpp, linesize); +return ds->allocator->resize_displaysurface (ds->surface, width, height); }static inline void qemu_free_displaysurface (DisplayState *ds)
@@ -158,6 +156,14 @@ static inline void qemu_free_displaysurface(DisplayState *ds) ds->allocator->free_displaysurface (ds->surface); } +static inline int is_surface_bgr (DisplaySurface *surface) +{ +if (surface->pf.bits_per_pixel ==32 && surface->pf.rshift ==0 ) +return 1 ; +else +return 0 ; +} +static inline int is_buffer_shared (DisplaySurface *surface) {return (!(surface->flags &QEMU_ALLOCATED_FLAG ));
hw/vga.c +6 -2
@@ -1173,7 +1173,10 @@ static inline int get_depth_index(DisplayState *s)case 16 :return 2 ;case 32 : -return 3 ; +if (is_surface_bgr (s->surface)) +return 4 ; +else +return 3 ; } }
@@ -2794,7 +2797,8 @@ static void vga_screen_dump(void *opaque, const char *filename) dcl.dpy_resize = vga_save_dpy_resize; dcl.dpy_refresh = vga_save_dpy_refresh;register_displaychangelistener (ds, &dcl); - ds->surface =qemu_create_displaysurface (ds, w, h,32 ,4 * w); + ds->allocator = &default_allocator; + ds->surface =qemu_create_displaysurface (ds, w, h); s->ds = ds; s->graphic_mode =-1 ;
hw/xenfb.c +1 -3
@@ -744,9 +744,7 @@ static void xenfb_update(void *opaque)break ;default :/* we must convert stuff */ -qemu_resize_displaysurface (xenfb->c.ds, - xenfb->width, xenfb->height, - xenfb->depth, xenfb->row_stride); +qemu_resize_displaysurface (xenfb->c.ds, xenfb->width, xenfb->height);break ; }dpy_resize (xenfb->c.ds);
sdl.c +124 -13
181 lines not on this page · raw message
vl.c +1 -1
@@ -2922,7 +2922,7 @@ static void dumb_display_init(void)exit (1 ); } ds->allocator = &default_allocator; - ds->surface =qemu_create_displaysurface (ds,640 ,480 ,32 ,640 *4 ); + ds->surface =qemu_create_displaysurface (ds,640 ,480 );register_displaystate (ds); }
xenfbfront.c +7 -7
@@ -216,7 +216,7 @@ static void kbdfront_thread(void *p) } -static DisplaySurface *xenfb_create_displaysurface (int width,int height,int bpp,int linesize) +static DisplaySurface *xenfb_create_displaysurface (int width,int height) {DisplaySurface *surface = (DisplaySurface *)qemu_mallocz (sizeof (DisplaySurface));if (surface ==NULL ) {
@@ -226,8 +226,8 @@ static DisplaySurface* xenfb_create_displaysurface(int width, int height, int bp surface->width = width; surface->height = height; - surface->linesize = linesize; - surface->pf =qemu_default_pixelformat (bpp); + surface->linesize = width *4 ; + surface->pf =qemu_default_pixelformat (32 );#ifdef WORDS_BIGENDIAN surface->flags =QEMU_ALLOCATED_FLAG |QEMU_BIG_ENDIAN_FLAG ;#else
@@ -239,12 +239,12 @@ static DisplaySurface* xenfb_create_displaysurface(int width, int height, int bp }static DisplaySurface *xenfb_resize_displaysurface (DisplaySurface *surface, -int width,int height,int bpp,int linesize) +int width,int height) { surface->width = width; surface->height = height; - surface->linesize = linesize; - surface->pf =qemu_default_pixelformat (bpp); + surface->linesize = width *4 ; + surface->pf =qemu_default_pixelformat (32 );#ifdef WORDS_BIGENDIAN surface->flags =QEMU_ALLOCATED_FLAG |QEMU_BIG_ENDIAN_FLAG ;#else
@@ -282,7 +282,7 @@ static void xenfb_pv_display_allocator(void)/* Touch the pages before sharing them */ memset (xs->nonshared_vram,0xff , vga_ram_size); - ds =xenfb_create_displaysurface (ds_get_width (xs->ds),ds_get_height (xs->ds),ds_get_bits_per_pixel (xs->ds),ds_get_linesize (xs->ds)); + ds =xenfb_create_displaysurface (ds_get_width (xs->ds),ds_get_height (xs->ds));defaultallocator_free_displaysurface (xs->ds->surface); xs->ds->surface = ds; }