Skip to content

Commit

Permalink
SDL: Let driver_base be reused in a different video mode
Browse files Browse the repository at this point in the history
Split init() into one-time initialization, and adaptation to a new video mode.
  • Loading branch information
vasi committed Apr 24, 2013
1 parent e9c913c commit ff423fe
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions BasiliskII/src/SDL/video_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit ff423fe

Please sign in to comment.