[6336] DisplayState interface change (Stefano Stabellini)
Revision: 6336
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6336 Author: aliguori Date: 2009-01-15 22:14:11 +0000 (Thu, 15 Jan 2009)
Log Message:
-----------
DisplayState interface change (Stefano Stabellini)
This patch changes the DisplayState interface adding support for multiple frontends at the same time (sdl and vnc) and implements most of the benefit of the shared_buf patch without the added complexity.
Currently DisplayState is managed by sdl (or vnc) and sdl (or vnc) is also responsible for allocating the data and setting the depth. Vga.c (or another backend) will do any necessary conversion.
The idea is to change it so that is vga.c (or another backend) together with console.c that fully manage the DisplayState interface allocating data and setting the depth (either 16 or 32 bit, if the guest uses a different resolution or is in text mode, vga.c (or another backend) is in charge of doing the conversion seamlessly).
The other idea is that DisplayState supports *multiple* frontends like sdl and vnc; each of them can register some callbacks to be called when a display event occurs.
The interesting changes are:
- the new structures and related functions in console.h and console.c
in particular the following functions are very helpful to manage a DisplaySurface:
qemu_create_displaysurfaceqemu_resize_displaysurfaceqemu_create_displaysurface_fromqemu_free_displaysurface
- console_select and qemu_console_resize in console.c this two functions manage multiple consoles on a single host display
- moving code around in hw/vga.c
as for the shared_buf patch this is necessary to be able to handle a dynamic DisplaySurface bpp
- changes to vga_draw_graphic in hw/vga.c
this is the place where the DisplaySurface buffer is shared with the videoram, when possible;
Compared to the last version the only changes are:
- do not remove support to dpy_copy in cirrus_vga
- change the name of the displaysurface handling functions
Modified Paths:
--------------
trunk/console.c
trunk/console.h
trunk/curses.c
trunk/hw/cirrus_vga.c
trunk/hw/nseries.c
trunk/hw/palm.c
trunk/hw/vga.c
trunk/hw/vga_int.h
trunk/qemu-common.h
trunk/sdl.c
trunk/vl.c
trunk/vnc.c
Modified: trunk/console.c
===================================================================
console.c +144 -27
@@ -1044,12 +1044,15 @@if (index >=MAX_CONSOLES )return ; + active_console->g_width =ds_get_width (active_console->ds); + active_console->g_height =ds_get_height (active_console->ds); s = consoles[index];if (s) { +DisplayState *ds = s->ds; active_console = s; -if (s->console_type !=TEXT_CONSOLE && s->g_width && s->g_height - && (s->g_width !=ds_get_width (s->ds) || s->g_height !=ds_get_height (s->ds))) -dpy_resize (s->ds, s->g_width, s->g_height); + ds->surface =qemu_resize_displaysurface (ds->surface, s->g_width, + s->g_height,32 ,4 * s->g_width); +dpy_resize (s->ds);vga_hw_invalidate (); } }
@@ -1157,16 +1160,6 @@static void text_console_invalidate (void *opaque) {TextConsole *s = (TextConsole *) opaque; - -if (s->g_width !=ds_get_width (s->ds) || s->g_height !=ds_get_height (s->ds)) { -if (s->console_type ==TEXT_CONSOLE_FIXED_SIZE ) -dpy_resize (s->ds, s->g_width, s->g_height); -else { - s->g_width =ds_get_width (s->ds); - s->g_height =ds_get_height (s->ds); -text_console_resize (s); - } - }console_refresh (s); }
@@ -1346,13 +1339,12 @@void qemu_console_resize (QEMUConsole *console,int width,int height) { -if (console->g_width != width || console->g_height != height - || !ds_get_data (console->ds)) { - console->g_width = width; - console->g_height = height; -if (active_console == console) { -dpy_resize (console->ds, width, height); - } + console->g_width = width; + console->g_height = height; +if (active_console == console) { +DisplayState *ds = console->ds; + ds->surface =qemu_resize_displaysurface (ds->surface, width, height,32 ,4 * width); +dpy_resize (console->ds); } }
@@ -1360,12 +1352,137 @@ int dst_x, int dst_y, int w, int h) { if (active_console == console) { - if (console->ds->dpy_copy) - console->ds->dpy_copy(console->ds, - src_x, src_y, dst_x, dst_y, w, h); - else { -/* TODO */ - console->ds->dpy_update (console->ds, dst_x, dst_y, w, h); - } + dpy_copy(console->ds, src_x, src_y, dst_x, dst_y, w, h); } } + +static PixelFormat qemu_default_pixelformat (int bpp) +{ +PixelFormat pf; + +memset (&pf,0x00 ,sizeof (PixelFormat)); + + pf.bits_per_pixel = bpp; + pf.bytes_per_pixel = bpp /8 ; + pf.depth = bpp ==32 ?24 : bpp; + +switch (bpp) { +case 8 : + pf.rmask =0x000000E0 ; + pf.gmask =0x0000001C ; + pf.bmask =0x00000003 ; + pf.rmax =7 ; + pf.gmax =7 ; + pf.bmax =3 ; + pf.rshift =5 ; + pf.gshift =2 ; + pf.bshift =0 ; +break ; +case 16 : + pf.rmask =0x0000F800 ; + pf.gmask =0x000007E0 ; + pf.bmask =0x0000001F ; + pf.rmax =31 ; + pf.gmax =63 ; + pf.bmax =31 ; + pf.rshift =11 ; + pf.gshift =5 ; + pf.bshift =0 ; +break ; +case 24 : +case 32 : + pf.rmask =0x00FF0000 ; + pf.gmask =0x0000FF00 ; + pf.bmask =0x000000FF ; + pf.rmax =255 ; + pf.gmax =255 ; + pf.bmax =255 ; + pf.rshift =16 ; + pf.gshift =8 ; + pf.bshift =0 ; +break ; +default : +break ; + } +return pf; +} + +DisplaySurface *qemu_create_displaysurface (int width,int height,int bpp,int linesize) +{ +DisplaySurface *surface = (DisplaySurface *)qemu_mallocz (sizeof (DisplaySurface)); +if (surface ==NULL ) { +fprintf (stderr,"qemu_create_displaysurface: malloc failed\n" ); +exit (1 ); + } + + surface->width = width; + surface->height = height; + surface->linesize = linesize; + surface->pf =qemu_default_pixelformat (bpp); +#ifdef WORDS_BIGENDIAN + surface->flags =QEMU_ALLOCATED_FLAG |QEMU_BIG_ENDIAN_FLAG ; +#else + surface->flags =QEMU_ALLOCATED_FLAG ; +#endif + surface->data = (uint8_t *)qemu_mallocz (surface->linesize * surface->height); +if (surface->data ==NULL ) { +fprintf (stderr,"qemu_create_displaysurface: malloc failed\n" ); +exit (1 ); + } + +return surface; +} + +DisplaySurface *qemu_resize_displaysurface (DisplaySurface *surface, +int width,int height,int bpp,int linesize) +{ + surface->width = width; + surface->height = height; + surface->linesize = linesize; + surface->pf =qemu_default_pixelformat (bpp); +if (surface->flags &QEMU_ALLOCATED_FLAG ) + surface->data = (uint8_t *)qemu_realloc (surface->data, surface->linesize * surface->height); +else + surface->data = (uint8_t *)qemu_malloc (surface->linesize * surface->height); +if (surface->data ==NULL ) { +fprintf (stderr,"qemu_resize_displaysurface: malloc failed\n" ); +exit (1 ); + } +#ifdef WORDS_BIGENDIAN + surface->flags =QEMU_ALLOCATED_FLAG |QEMU_BIG_ENDIAN_FLAG ; +#else + surface->flags =QEMU_ALLOCATED_FLAG ; +#endif + +return surface; +} + +DisplaySurface *qemu_create_displaysurface_from (int width,int height,int bpp, +int linesize,uint8_t *data) +{ +DisplaySurface *surface = (DisplaySurface *)qemu_mallocz (sizeof (DisplaySurface)); +if (surface ==NULL ) { +fprintf (stderr,"qemu_create_displaysurface_from: malloc failed\n" ); +exit (1 ); + } + + surface->width = width; + surface->height = height; + surface->linesize = linesize; + surface->pf =qemu_default_pixelformat (bpp); +#ifdef WORDS_BIGENDIAN + surface->flags =QEMU_BIG_ENDIAN_FLAG ; +#endif + surface->data = data; + +return surface; +} + +void qemu_free_displaysurface (DisplaySurface *surface) +{ +if (surface ==NULL ) +return ; +if (surface->flags &QEMU_ALLOCATED_FLAG ) +qemu_free (surface->data); +qemu_free (surface); +}
Modified: trunk/console.h
===================================================================
console.h +114 -21
189 lines not on this page · raw message
Modified: trunk/curses.c
===================================================================
curses.c +20 -18
@@ -97,13 +97,13 @@ } } -static void curses_resize (DisplayState *ds,int w,int h) +static void curses_resize (DisplayState *ds) { -if (w == gwidth && h == gheight) +if (ds_get_width (ds) == gwidth &&ds_get_height (ds) == gheight)return ; - gwidth = w; - gheight = h; + gwidth =ds_get_width (ds); + gheight =ds_get_height (ds);curses_calc_pad (); }
@@ -169,8 +169,8 @@clear ();refresh ();curses_calc_pad (); - ds->width =FONT_WIDTH * width; - ds->height =FONT_HEIGHT * height; + ds->surface->width =FONT_WIDTH * width; + ds->surface->height =FONT_HEIGHT * height;vga_hw_invalidate (); invalidate =0 ; }
@@ -197,8 +197,8 @@refresh ();curses_calc_pad ();curses_update (ds,0 ,0 , width, height); - ds->width =FONT_WIDTH * width; - ds->height =FONT_HEIGHT * height; + ds->surface->width =FONT_WIDTH * width; + ds->surface->height =FONT_HEIGHT * height; continue; }#endif
@@ -338,6 +338,7 @@void curses_display_init (DisplayState *ds,int full_screen) { +DisplayChangeListener *dcl;#ifndef _WIN32if (!isatty (1 )) {fprintf (stderr,"We need a terminal output\n" );
@@ -357,18 +358,19 @@#endif #endif - ds->data = (void *) screen; - ds->linesize =0 ; - ds->depth =0 ; - ds->width =640 ; - ds->height =400 ; - ds->dpy_update = curses_update; - ds->dpy_resize = curses_resize; - ds->dpy_refresh = curses_refresh; - ds->dpy_text_cursor = curses_cursor_position; + dcl = (DisplayChangeListener *)qemu_mallocz (sizeof (DisplayChangeListener)); +if (!dcl) +exit (1 ); + dcl->dpy_update = curses_update; + dcl->dpy_resize = curses_resize; + dcl->dpy_refresh = curses_refresh; + dcl->dpy_text_cursor = curses_cursor_position; +register_displaychangelistener (ds, dcl); +qemu_free_displaysurface (ds->surface); + ds->surface =qemu_create_displaysurface_from (80 ,25 ,0 ,0 , (uint8_t *) screen); invalidate =1 ;/* Standard VGA initial text mode dimensions */ -curses_resize (ds,80 ,25 ); +curses_resize (ds); }
Modified: trunk/hw/cirrus_vga.c
===================================================================
hw/cirrus_vga.c +3 -16
@@ -793,23 +793,10 @@if (BLTUNSAFE (s))return 0 ; -if (s->ds->dpy_copy) { -cirrus_do_copy (s, s->cirrus_blt_dstaddr - s->start_addr, - s->cirrus_blt_srcaddr - s->start_addr, - s->cirrus_blt_width, s->cirrus_blt_height); - }else { - (*s->cirrus_rop) (s, s->vram_ptr + - (s->cirrus_blt_dstaddr & s->cirrus_addr_mask), - s->vram_ptr + - (s->cirrus_blt_srcaddr & s->cirrus_addr_mask), - s->cirrus_blt_dstpitch, s->cirrus_blt_srcpitch, - s->cirrus_blt_width, s->cirrus_blt_height); +cirrus_do_copy (s, s->cirrus_blt_dstaddr - s->start_addr, + s->cirrus_blt_srcaddr - s->start_addr, + s->cirrus_blt_width, s->cirrus_blt_height); -cirrus_invalidate_region (s, s->cirrus_blt_dstaddr, - s->cirrus_blt_dstpitch, s->cirrus_blt_width, - s->cirrus_blt_height); - } -return 1 ; }
Modified: trunk/hw/nseries.c
===================================================================
hw/nseries.c +2 -1
@@ -1360,7 +1360,8 @@/* FIXME: We shouldn't really be doing this here. The LCD controller will set the size once configured, so this just sets an initial size until the guest activates the display. */ -dpy_resize (ds,800 ,480 ); + ds->surface =qemu_resize_displaysurface (ds->surface,800 ,480 ,32 ,4 *800 ); +dpy_resize (ds); }static struct arm_boot_info n800_binfo = {
Modified: trunk/hw/palm.c
===================================================================
hw/palm.c +2 -1
@@ -277,7 +277,8 @@/* FIXME: We shouldn't really be doing this here. The LCD controller will set the size once configured, so this just sets an initial size until the guest activates the display. */ -dpy_resize (ds,320 ,320 ); + ds->surface =qemu_resize_displaysurface (ds->surface,320 ,320 ,32 ,4 *320 ); +dpy_resize (ds); }QEMUMachine palmte_machine = {
Modified: trunk/hw/vga.c
===================================================================
hw/vga.c +69 -32
205 lines not on this page · raw message
Modified: trunk/hw/vga_int.h
===================================================================
hw/vga_int.h +2 -0
@@ -154,9 +154,11 @@uint32_t line_compare; \uint32_t start_addr; \uint32_t plane_updated; \ +uint32_t last_line_offset; \uint8_t last_cw, last_ch; \uint32_t last_width, last_height;/* in chars or pixels */ \uint32_t last_scr_width, last_scr_height;/* in pixels */ \ +uint32_t last_depth;/* in bits */ \uint8_t cursor_start, cursor_end; \uint32_t cursor_offset; \ unsigned int (*rgb_to_pixel)(unsigned int r, \
Modified: trunk/qemu-common.h
===================================================================
qemu-common.h +3 -0
@@ -166,6 +166,9 @@typedef struct AudioState AudioState ;typedef struct BlockDriverState BlockDriverState ;typedef struct DisplayState DisplayState ; +typedef struct DisplayChangeListener DisplayChangeListener ; +typedef struct DisplaySurface DisplaySurface ; +typedef struct PixelFormat PixelFormat ;typedef struct TextConsole TextConsole ;typedef TextConsole QEMUConsole ;typedef struct CharDriverState CharDriverState ;
Modified: trunk/sdl.c
===================================================================
sdl.c +49 -37
155 lines not on this page · raw message
Modified: trunk/vl.c
===================================================================
vl.c +55 -32
167 lines not on this page · raw message
Modified: trunk/vnc.c
===================================================================
vnc.c +34 -73
225 lines not on this page · raw message
This patch completely breaks the cocoa front end. The cocoa end either needs to be re-written. I will see what I can do, however, I am not skilled in writing such code.
Quoted 74 lines · Anthony Liguori
Revision: 6336
http://svn.sv.gnu.org/viewvc/? view=rev&root=qemu&revision=6336 Author: aliguori Date: 2009-01-15 22:14:11 +0000 (Thu, 15 Jan 2009)Log Message:
-----------
DisplayState interface change (Stefano Stabellini)This patch changes the DisplayState interface adding support for multiple frontends at the same time (sdl and vnc) and implements most of the benefit of the
shared_bufpatch without the added complexity.Currently DisplayState is managed by sdl (or vnc) and sdl (or vnc) is also responsible for allocating the data and setting the depth.
Vga.c(or another backend) will do any necessary conversion.The idea is to change it so that is
vga.c(or another backend) together withconsole.cthat fully manage the DisplayState interface allocating data and setting the depth (either 16 or 32 bit, if the guest uses a different resolution or is in text mode,vga.c(or another backend) is in charge of doing the conversion seamlessly).The other idea is that DisplayState supports *multiple* frontends like sdl and vnc; each of them can register some callbacks to be called when a display event occurs.
The interesting changes are:
- the new structures and related functions in
console.handconsole.cin particular the following functions are very helpful to manage a DisplaySurface:
qemu_create_displaysurfaceqemu_resize_displaysurfaceqemu_create_displaysurface_fromqemu_free_displaysurface-
console_selectandqemu_console_resizeinconsole.cthis two functions manage multiple consoles on a single host display- moving code around in
hw/vga.c
as for theshared_bufpatch this is necessary to be able to handle a dynamic DisplaySurface bpp- changes to
vga_draw_graphicinhw/vga.c
this is the place where the DisplaySurface buffer is shared with the videoram, when possible;Compared to the last version the only changes are:
- do not remove support to
dpy_copyincirrus_vga
- change the name of the displaysurface handling functionsSigned-off-by Stefano Stabellini <[email protected]>Signed-off-by Anthony Liguori <[email protected]>Modified Paths:
--------------
trunk/console.c
trunk/console.h
trunk/curses.c
trunk/hw/cirrus_vga.c
trunk/hw/nseries.c
trunk/hw/palm.c
trunk/hw/vga.c
trunk/hw/vga_int.h
trunk/qemu-common.h
trunk/sdl.c
trunk/vl.c
trunk/vnc.c
Quoted 4 lines · C.W. Betts
This patch completely breaks the cocoa front end. The cocoa end either needs to be re-written. I will see what I can do, however, I am not skilled in writing such code.
On Jan 15, 2009, at 3:14 PM, Anthony Liguori wrote:
It is a known problem, I wrote a patch to show what changes have to be made to cocoa to use the new interface, we also spoke about it recently again and Anthony and\or Andreas said they would fix it.
So it is just temporary, hold on help is on its way :)
Quoted 2 lines · C.W. Betts
This patch completely breaks the cocoa front end. The cocoa end either needs to be re-written. I will see what I can do, however, I am not skilled in writing such code. On Jan 15, 2009, at 3:14 PM, Anthony Liguori wrote:
Why do we have a cocoa front end?
SDL seems to be available for OS X[1]. It's virtual impossible to maintain since it's an API for a proprietary OS that only works on special hardware. It's also Objective C?
[1] http://www.libsdl.org/faq.php?action=listentries&category=7
Regards,
Anthony Liguori
Quoted 5 lines · Anthony Liguori
Quoted 4 lines · C.W. Betts
This patch completely breaks the cocoa front end. The cocoa end either needs to be re-written. I will see what I can do, however, I am not skilled in writing such code.
On Jan 15, 2009, at 3:14 PM, Anthony Liguori wrote:
Quoted 8 lines
Why do we have a cocoa front end?
SDL seems to be available for OS X[1]. It's virtual impossible to maintain since it's an API for a proprietary OS that only works on special hardware. It's also Objective C?
[1] http://www.libsdl.org/faq.php?action=listentries&category=7
I thought the same thing more than once but I have never dared to say it :)
Quoted 9 lines · Stefano Stabellini
Quoted 7 lines · Anthony Liguori
Quoted 4 lines · C.W. Betts
This patch completely breaks the cocoa front end. The cocoa end either needs to be re-written. I will see what I can do, however, I am not skilled in writing such code.
On Jan 15, 2009, at 3:14 PM, Anthony Liguori wrote:Why do we have a cocoa front end?
Quoted 10 lines
Quoted 6 lines
SDL seems to be available for OS X[1]. It's virtual impossible to maintain since it's an API for a proprietary OS that only works on special hardware. It's also Objective C?
[1] http://www.libsdl.org/faq.php?action=listentries&category=7
I thought the same thing more than once but I have never dared to say it :)
I don't know, but I do know that it isn't installed by default. Also, SDL isn't available on 64-bit Applications on OS X (It uses a deprecated API)
Quoted 5 lines · Anthony Liguori
Revision: 6336
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6336 Author: aliguori Date: 2009-01-15 22:14:11 +0000 (Thu, 15 Jan 2009)
Quoted 7 lines
Log Message:
-----------
DisplayState interface change (Stefano Stabellini)This patch changes the DisplayState interface adding support for multiple frontends at the same time (sdl and vnc) and implements most of the benefit of the
shared_bufpatch without the added complexity.
This breaks truecolor display for both sdl and vnc on big-endian hosts.
Signature · 1 line
mailto:[email protected]
Quoted 4 lines · malc
This breaks truecolor display for both sdl and vnc on big-endian hosts.
I hope that "breaks" in this case means "the colors are wrong".
I think I just need to change console.c:qemu_default_pixelformat to correctly handle big-endian hosts, the fix should be simple but it will be really difficult for me to test.
Quoted 9 lines · Stefano Stabellini
Quoted 4 lines · malc
This breaks truecolor display for both sdl and vnc on big-endian hosts.
I hope that "breaks" in this case means "the colors are wrong".
Yes.
Quoted 4 lines
I think I just need to change console.c:qemu_default_pixelformat to correctly handle big-endian hosts, the fix should be simple but it will be really difficult for me to test.
If it will help any, following brings the colors back to normal for vnc:
vnc.c +1 -1
@@ -1283,7 +1283,7 @@ static void set_pixel_format(VncState *vs, vs->clientds.pf.bits_per_pixel = bits_per_pixel; vs->clientds.pf.bytes_per_pixel = bits_per_pixel /8 ; vs->clientds.pf.depth = bits_per_pixel ==32 ?24 : bits_per_pixel; - vs->clientds.flags = big_endian_flag ?QEMU_BIG_ENDIAN_FLAG :0x00 ; + vs->clientds.flags =0 ;set_pixel_conversion (vs);
P.S. In console.c you have this:
if (surface->flags & QEMU_ALLOCATED_FLAG)
surface->data = (uint8_t*) qemu_realloc(surface->data, surface->linesize * surface->height);
else
surface->data = (uint8_t*) qemu_malloc(surface->linesize * surface->height);
Why? Have reservations that qemu_realloc might break the realloc contract
(of being the same as malloc in case of NULL ptr)? Also the casts are unnecessary.Signature · 1 line
mailto:[email protected]