From 1c0e8655dcefad632a8c0d93a94ca271070f38de Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Fri, 8 Sep 2017 23:43:01 +0000 Subject: [PATCH] for non-OSX hosts, make GNU Autotools revert to using SDL 1.x, if SDL 2.x can't be found --- BasiliskII/src/CrossPlatform/video_vosf.h | 15 ++++++++----- BasiliskII/src/SDL/audio_sdl.cpp | 10 ++++++++- BasiliskII/src/SDL/video_sdl.cpp | 10 +++++++++ BasiliskII/src/SDL/video_sdl2.cpp | 14 ++++++++++-- BasiliskII/src/Unix/configure.ac | 27 +++++++++++++++++------ 5 files changed, 60 insertions(+), 16 deletions(-) diff --git a/BasiliskII/src/CrossPlatform/video_vosf.h b/BasiliskII/src/CrossPlatform/video_vosf.h index fc89e125..f99b44bf 100644 --- a/BasiliskII/src/CrossPlatform/video_vosf.h +++ b/BasiliskII/src/CrossPlatform/video_vosf.h @@ -30,6 +30,12 @@ #include "util_windows.h" #endif +// Import SDL-backend-specific functions +#ifdef USE_SDL_VIDEO +extern void update_sdl_video(SDL_Surface *screen, Sint32 x, Sint32 y, Sint32 w, Sint32 h); +extern void update_sdl_video(SDL_Surface *screen, int numrects, SDL_Rect *rects); +#endif + // Glue for SDL and X11 support #ifdef TEST_VOSF_PERFORMANCE #define MONITOR_INIT /* nothing */ @@ -514,8 +520,7 @@ static void update_display_window_vosf(VIDEO_DRV_WIN_INIT) VIDEO_DRV_UNLOCK_PIXELS; #ifdef USE_SDL_VIDEO - //SDL_UpdateRect(drv->s, 0, y1, VIDEO_MODE_X, height); - update_sdl_video(); + update_sdl_video(drv->s, 0, y1, VIDEO_MODE_X, height); #else if (VIDEO_DRV_HAVE_SHM) XShmPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height, 0); @@ -559,8 +564,7 @@ static void update_display_dga_vosf(VIDEO_DRV_DGA_INIT) i2 += scr_bytes_per_row; } #ifdef USE_SDL_VIDEO - //SDL_UpdateRect(drv->s, 0, 0, VIDEO_MODE_X, VIDEO_MODE_Y); - update_sdl_video(); + update_sdl_video(drv->s, 0, 0, VIDEO_MODE_X, VIDEO_MODE_Y); #endif VIDEO_DRV_UNLOCK_PIXELS; return; @@ -666,8 +670,7 @@ static void update_display_dga_vosf(VIDEO_DRV_DGA_INIT) #endif } #ifdef USE_SDL_VIDEO - //SDL_UpdateRects(drv->s, bbi, bb); - update_sdl_video(); + update_sdl_video(drv->s, bbi, bb); #endif VIDEO_DRV_UNLOCK_PIXELS; } diff --git a/BasiliskII/src/SDL/audio_sdl.cpp b/BasiliskII/src/SDL/audio_sdl.cpp index 130afe6b..6bff36c3 100644 --- a/BasiliskII/src/SDL/audio_sdl.cpp +++ b/BasiliskII/src/SDL/audio_sdl.cpp @@ -28,6 +28,7 @@ #include #include +#include #define DEBUG 0 #include "debug.h" @@ -87,7 +88,7 @@ static bool open_sdl_audio(void) } SDL_AudioSpec audio_spec; - SDL_zero(audio_spec); + memset(&audio_spec, 0, sizeof(audio_spec)); audio_spec.freq = audio_sample_rates[audio_sample_rate_index] >> 16; audio_spec.format = (audio_sample_sizes[audio_sample_size_index] == 8) ? AUDIO_U8 : AUDIO_S16MSB; audio_spec.channels = audio_channel_counts[audio_channel_count_index]; @@ -101,18 +102,25 @@ static bool open_sdl_audio(void) return false; } +#if SDL_VERSION_ATLEAST(2,0,0) // HACK: workaround a bug in SDL pre-2.0.6 (reported via https://bugzilla.libsdl.org/show_bug.cgi?id=3710 ) // whereby SDL does not update audio_spec.size if (audio_spec.size == 0) { audio_spec.size = (SDL_AUDIO_BITSIZE(audio_spec.format) / 8) * audio_spec.channels * audio_spec.samples; } +#endif #if defined(BINCUE) OpenAudio_bincue(audio_spec.freq, audio_spec.format, audio_spec.channels, audio_spec.silence); #endif +#if SDL_VERSION_ATLEAST(2,0,0) const char * driver_name = SDL_GetCurrentAudioDriver(); +#else + char driver_name[32]; + SDL_AudioDriverName(driver_name, sizeof(driver_name) - 1); +#endif printf("Using SDL/%s audio output\n", driver_name ? driver_name : ""); silence_byte = audio_spec.silence; SDL_PauseAudio(0); diff --git a/BasiliskII/src/SDL/video_sdl.cpp b/BasiliskII/src/SDL/video_sdl.cpp index c0090d23..03e4c5b7 100644 --- a/BasiliskII/src/SDL/video_sdl.cpp +++ b/BasiliskII/src/SDL/video_sdl.cpp @@ -587,6 +587,16 @@ static void migrate_screen_prefs(void) #endif } +void update_sdl_video(SDL_Surface *screen, Sint32 x, Sint32 y, Sint32 w, Sint32 h) +{ + SDL_UpdateRect(screen, x, y, w, h); +} + +void update_sdl_video(SDL_Surface *screen, int numrects, SDL_Rect *rects) +{ + SDL_UpdateRects(screen, numrects, rects); +} + /* * Display "driver" classes diff --git a/BasiliskII/src/SDL/video_sdl2.cpp b/BasiliskII/src/SDL/video_sdl2.cpp index aa57ff6a..d597101c 100755 --- a/BasiliskII/src/SDL/video_sdl2.cpp +++ b/BasiliskII/src/SDL/video_sdl2.cpp @@ -883,7 +883,18 @@ static int update_sdl_video() return 0; } -static int update_sdl_video(SDL_Surface *s, int x, int y, int w, int h) +void update_sdl_video(SDL_Surface *s, Sint32 x, Sint32 y, Sint32 w, Sint32 h) +{ + // HACK, dludwig@pobox.com: for now, just update the whole screen, via + // VideoInterrupt(), which gets called on the main thread. + // + // TODO: make sure SDL_Renderer resources get displayed, if and when + // MacsBug is running (and VideoInterrupt() might not get called) + // + // TODO: cache rects to update, then use rects in present_sdl_video() +} + +void update_sdl_video(SDL_Surface *s, int numrects, SDL_Rect *rects) { // HACK, dludwig@pobox.com: for now, just update the whole screen, via // VideoInterrupt(), which gets called on the main thread. @@ -892,7 +903,6 @@ static int update_sdl_video(SDL_Surface *s, int x, int y, int w, int h) // MacsBug is running (and VideoInterrupt() might not get called) // // TODO: cache rects to update, then use rects in present_sdl_video() - return 0; } void driver_base::set_video_mode(int flags) diff --git a/BasiliskII/src/Unix/configure.ac b/BasiliskII/src/Unix/configure.ac index d9f54b13..d1f90841 100755 --- a/BasiliskII/src/Unix/configure.ac +++ b/BasiliskII/src/Unix/configure.ac @@ -300,13 +300,26 @@ if [[ "x$WANT_SDL" = "xyes" ]]; then ac_cv_framework_SDL=no fi if [[ "x$ac_cv_framework_SDL" = "xno" ]]; then - PKG_CHECK_MODULES([sdl2], [sdl2 >= 2.0], [ - CFLAGS="$CFLAGS $sdl2_CFLAGS" - CXXFLAGS="$CXXFLAGS $sdl2_CFLAGS" - LIBS="$LIBS $sdl2_LIBS" - ], [ - WANT_SDL=no - ]) + WANT_SDL_VERSION_MAJOR=2 + if [[ "x$WANT_SDL_VERSION_MAJOR" = "x2" ]]; then + PKG_CHECK_MODULES([sdl2], [sdl2 >= 2.0], [ + CFLAGS="$CFLAGS $sdl2_CFLAGS" + CXXFLAGS="$CXXFLAGS $sdl2_CFLAGS" + LIBS="$LIBS $sdl2_LIBS" + ], [ + WANT_SDL_VERSION_MAJOR=1 + ]) + fi + if [[ "x$WANT_SDL_VERSION_MAJOR" = "x1" ]]; then + PKG_CHECK_MODULES([sdl], [sdl >= 1.2], [ + CFLAGS="$CFLAGS $sdl_CFLAGS" + CXXFLAGS="$CXXFLAGS $sdl_CFLAGS" + LIBS="$LIBS $sdl_LIBS" + ], [ + WANT_SDL=no + WANT_SDL_VERSION_MAJOR= + ]) + fi fi SDL_SUPPORT=`echo "$SDL_SUPPORT" | sed -e "s/^ //"` else