From ff423fe7c9b536bdd430b9b9aa8af41124b2ba42 Mon Sep 17 00:00:00 2001 From: Dave Vasilevsky Date: Wed, 24 Apr 2013 02:07:20 -0400 Subject: [PATCH] SDL: Let driver_base be reused in a different video mode Split init() into one-time initialization, and adaptation to a new video mode. --- BasiliskII/src/SDL/video_sdl.cpp | 41 ++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/BasiliskII/src/SDL/video_sdl.cpp b/BasiliskII/src/SDL/video_sdl.cpp index edcade66..82fd9fe7 100644 --- a/BasiliskII/src/SDL/video_sdl.cpp +++ b/BasiliskII/src/SDL/video_sdl.cpp @@ -600,9 +600,12 @@ static void migrate_screen_prefs(void) class driver_base { public: driver_base(SDL_monitor_desc &m); - void init(); ~driver_base(); + void init(); // One-time init + void set_video_mode(int flags); + void adapt_to_video_mode(); + void update_palette(void); void suspend(void) {} void resume(void) {} @@ -641,25 +644,26 @@ driver_base::driver_base(SDL_monitor_desc &m) the_buffer_copy = NULL; } -void driver_base::init() +void driver_base::set_video_mode(int flags) { int aligned_height = (VIDEO_MODE_Y + 15) & ~15; int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH); - int width = VIDEO_MODE_X, height = VIDEO_MODE_Y; - - ADBSetRelMouseMode(mouse_grabbed); - - // Create surface - int flags = SDL_HWSURFACE; - if (display_type == DISPLAY_SCREEN) - flags |= SDL_FULLSCREEN; - if ((s = SDL_SetVideoMode(width, height, depth, flags)) == NULL) + if ((s = SDL_SetVideoMode(VIDEO_MODE_X, VIDEO_MODE_Y, depth, + SDL_HWSURFACE | flags)) == NULL) return; +#ifdef ENABLE_VOSF + the_host_buffer = (uint8 *)s->pixels; +#endif +} + +void driver_base::init() +{ + set_video_mode(display_type == DISPLAY_SCREEN ? SDL_FULLSCREEN : 0); + int aligned_height = (VIDEO_MODE_Y + 15) & ~15; #ifdef ENABLE_VOSF use_vosf = true; // Allocate memory for frame buffer (SIZE is extended to page-boundary) - the_host_buffer = (uint8 *)s->pixels; the_buffer_size = page_extend((aligned_height + 2) * s->pitch); the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size); the_buffer_copy = (uint8 *)malloc(the_buffer_size); @@ -689,10 +693,19 @@ void driver_base::init() D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); } + // Set frame buffer base + set_mac_frame_buffer(monitor, VIDEO_MODE_DEPTH, true); + + adapt_to_video_mode(); +} + +void driver_base::adapt_to_video_mode() { + ADBSetRelMouseMode(false); + // Init blitting routines SDL_PixelFormat *f = s->format; VisualFormat visualFormat; - visualFormat.depth = depth; + visualFormat.depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH); visualFormat.Rmask = f->Rmask; visualFormat.Gmask = f->Gmask; visualFormat.Bmask = f->Bmask; @@ -703,8 +716,6 @@ void driver_base::init() for (int i=0; i<256; i++) ExpandMap[i] = SDL_MapRGB(f, i, i, i); - // Set frame buffer base - set_mac_frame_buffer(monitor, VIDEO_MODE_DEPTH, true); bool hardware_cursor = false; #ifdef SHEEPSHAVER