sdl: add support for high resolution window icon

Modern desktop environments can render icons at very large sizes,
especially with high DPI screens. Providing a 32x32 pixel bitmap is
nowhere near sufficient anymore.

When displayed in GNOME shell the QEMU icon looks awful, having been
scaled up to at least x4 its base size. This is compounded by the fact
that the BMP file doesn't do transparency, so while we've removed white
pixels, we still have anti-aliased nearly-white pixels which make the
logo look appalling on black backgrounds.

Loading a high resolution PNG icon addresses both problems, but requires
use of the extra SDL2_image library.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-id: 20190110120047.25369-4-berrange@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2019-01-10 12:00:47 +00:00 committed by Gerd Hoffmann
parent 67ea954682
commit a442fe2f2b
3 changed files with 58 additions and 6 deletions

43
configure vendored
View File

@ -346,6 +346,7 @@ fdt=""
netmap="no" netmap="no"
sdl="" sdl=""
sdlabi="" sdlabi=""
sdl_image=""
virtfs="" virtfs=""
mpath="" mpath=""
vnc="yes" vnc="yes"
@ -1042,6 +1043,10 @@ for opt do
;; ;;
--with-sdlabi=*) sdlabi="$optarg" --with-sdlabi=*) sdlabi="$optarg"
;; ;;
--disable-sdl-image) sdl_image="no"
;;
--enable-sdl-image) sdl_image="yes"
;;
--disable-qom-cast-debug) qom_cast_debug="no" --disable-qom-cast-debug) qom_cast_debug="no"
;; ;;
--enable-qom-cast-debug) qom_cast_debug="yes" --enable-qom-cast-debug) qom_cast_debug="yes"
@ -1704,6 +1709,7 @@ disabled with --disable-FEATURE, default is enabled if available:
gcrypt libgcrypt cryptography support gcrypt libgcrypt cryptography support
sdl SDL UI sdl SDL UI
--with-sdlabi select preferred SDL ABI 1.2 or 2.0 --with-sdlabi select preferred SDL ABI 1.2 or 2.0
sdl_image SDL Image support for icons
gtk gtk UI gtk gtk UI
vte vte support for the gtk UI vte vte support for the gtk UI
curses curses UI curses curses UI
@ -3002,10 +3008,43 @@ EOF
fi # sdl compile test fi # sdl compile test
} }
sdl_image_probe ()
{
if test "$sdl_image" != "no" ; then
if $pkg_config SDL2_image --exists; then
if test "$static" = "yes"; then
sdl_image_libs=$($pkg_config SDL2_image --libs --static 2>/dev/null)
else
sdl_image_libs=$($pkg_config SDL2_image --libs 2>/dev/null)
fi
sdl_image_cflags=$($pkg_config SDL2_image --cflags 2>/dev/null)
sdl_image=yes
sdl_cflags="$sdl_cflags $sdl_image_cflags"
sdl_libs="$sdl_libs $sdl_image_libs"
else
if test "$sdl_image" = "yes" ; then
feature_not_found "sdl_image" "Install SDL Image devel"
else
sdl_image=no
fi
fi
fi
}
if test "$sdl" != "no" ; then if test "$sdl" != "no" ; then
sdl_probe sdl_probe
fi fi
if test "$sdl" = "yes" ; then
sdl_image_probe
else
if test "$sdl_image" = "yes"; then
echo "warning: SDL Image requested, but SDL is not available, disabling"
fi
sdl_image=no
fi
if test "$sdl" = "yes" ; then if test "$sdl" = "yes" ; then
cat > $TMPC <<EOF cat > $TMPC <<EOF
#include <SDL.h> #include <SDL.h>
@ -6029,6 +6068,7 @@ if test "$darwin" = "yes" ; then
echo "Cocoa support $cocoa" echo "Cocoa support $cocoa"
fi fi
echo "SDL support $sdl $(echo_version $sdl $sdlversion)" echo "SDL support $sdl $(echo_version $sdl $sdlversion)"
echo "SDL image support $sdl_image"
echo "GTK support $gtk $(echo_version $gtk $gtk_version)" echo "GTK support $gtk $(echo_version $gtk $gtk_version)"
echo "GTK GL support $gtk_gl" echo "GTK GL support $gtk_gl"
echo "VTE support $vte $(echo_version $vte $vteversion)" echo "VTE support $vte $(echo_version $vte $vteversion)"
@ -6368,6 +6408,9 @@ if test "$sdl" = "yes" ; then
echo "CONFIG_SDLABI=$sdlabi" >> $config_host_mak echo "CONFIG_SDLABI=$sdlabi" >> $config_host_mak
echo "SDL_CFLAGS=$sdl_cflags" >> $config_host_mak echo "SDL_CFLAGS=$sdl_cflags" >> $config_host_mak
echo "SDL_LIBS=$sdl_libs" >> $config_host_mak echo "SDL_LIBS=$sdl_libs" >> $config_host_mak
if test "$sdl_image" = "yes" ; then
echo "CONFIG_SDL_IMAGE=y" >> $config_host_mak
fi
fi fi
if test "$cocoa" = "yes" ; then if test "$cocoa" = "yes" ; then
echo "CONFIG_COCOA=y" >> $config_host_mak echo "CONFIG_COCOA=y" >> $config_host_mak

View File

@ -6,6 +6,9 @@
#include <SDL.h> #include <SDL.h>
#include <SDL_syswm.h> #include <SDL_syswm.h>
#ifdef CONFIG_SDL_IMAGE
# include <SDL_image.h>
#endif
#ifdef CONFIG_OPENGL #ifdef CONFIG_OPENGL
# include "ui/egl-helpers.h" # include "ui/egl-helpers.h"

View File

@ -764,6 +764,7 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
uint8_t data = 0; uint8_t data = 0;
int i; int i;
SDL_SysWMinfo info; SDL_SysWMinfo info;
SDL_Surface *icon = NULL;
assert(o->type == DISPLAY_TYPE_SDL); assert(o->type == DISPLAY_TYPE_SDL);
@ -835,13 +836,18 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
#endif #endif
} }
#ifdef CONFIG_SDL_IMAGE
icon = IMG_Load(CONFIG_QEMU_ICONDIR "/hicolor/128x128/apps/qemu.png");
#else
/* Load a 32x32x4 image. White pixels are transparent. */ /* Load a 32x32x4 image. White pixels are transparent. */
SDL_Surface *image = SDL_LoadBMP(CONFIG_QEMU_ICONDIR icon = SDL_LoadBMP(CONFIG_QEMU_ICONDIR "/hicolor/32x32/apps/qemu.bmp");
"/hicolor/32x32/apps/qemu.bmp"); if (icon) {
if (image) { uint32_t colorkey = SDL_MapRGB(icon->format, 255, 255, 255);
uint32_t colorkey = SDL_MapRGB(image->format, 255, 255, 255); SDL_SetColorKey(icon, SDL_TRUE, colorkey);
SDL_SetColorKey(image, SDL_TRUE, colorkey); }
SDL_SetWindowIcon(sdl2_console[0].real_window, image); #endif
if (icon) {
SDL_SetWindowIcon(sdl2_console[0].real_window, icon);
} }
gui_grab = 0; gui_grab = 0;