Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed some problems with switching to/from fullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
antifinidictor committed Aug 17, 2011
1 parent e1d0eb8 commit fcf01b4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/SDL_compat.c
Expand Up @@ -848,7 +848,7 @@ SDL_WM_ToggleFullScreen(SDL_Surface * surface)
/* Copy the old bits out */
length = SDL_PublicSurface->w * SDL_PublicSurface->format->BytesPerPixel;
pixels = SDL_malloc(SDL_PublicSurface->h * length);
if (pixels) {
if (pixels && SDL_PublicSurface->pixels) {
src = (Uint8*)SDL_PublicSurface->pixels;
dst = (Uint8*)pixels;
for (row = 0; row < SDL_PublicSurface->h; ++row) {
Expand Down
5 changes: 4 additions & 1 deletion src/video/bwindow/SDL_BWin.h
Expand Up @@ -98,8 +98,10 @@ class SDL_BWin:public BDirectWindow
#if SDL_VIDEO_OPENGL
if (_SDL_GLView) {
_SDL_GLView->UnlockGL();
RemoveChild(_SDL_GLView); /* Why was this outside the if
statement before? */
}
RemoveChild(_SDL_GLView);

#endif
Unlock();
#if SDL_VIDEO_OPENGL
Expand Down Expand Up @@ -129,6 +131,7 @@ class SDL_BWin:public BDirectWindow
gl_flags);
}
AddChild(_SDL_GLView);
_SDL_GLView->EnableDirectMode(true);
_SDL_GLView->LockGL(); /* "New" GLViews are created */
Unlock();
return (_SDL_GLView);
Expand Down
66 changes: 51 additions & 15 deletions src/video/bwindow/SDL_bmodes.cc
Expand Up @@ -32,12 +32,12 @@
extern "C" {
#endif

#if 1
/* This wrapper is here so that the driverdata can be freed */
typedef struct SDL_DisplayModeData {
display_mode *bmode;
};


#endif

static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
return ((SDL_BWin*)(window->driverdata));
Expand All @@ -47,6 +47,13 @@ static inline SDL_BApp *_GetBeApp() {
return ((SDL_BApp*)be_app);
}

static inline display_mode * _ExtractBMode(SDL_DisplayMode *mode) {
#if 0
return (display_mode*)(mode->driverdata);
#else
return ((SDL_DisplayModeData*)mode->driverdata)->bmode;
#endif
}

/* Copied from haiku/trunk/src/preferences/screen/ScreenMode.cpp */
static float get_refresh_rate(display_mode &mode) {
Expand Down Expand Up @@ -114,9 +121,14 @@ static inline void BE_BDisplayModeToSdlDisplayMode(display_mode *bmode,
mode->w = bmode->virtual_width;
mode->h = bmode->virtual_height;
mode->refresh_rate = (int)get_refresh_rate(*bmode);
#if 1
SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1, sizeof(SDL_DisplayModeData));
data->bmode = bmode;

mode->driverdata = data;
#else
mode->driverdata = bmode;
#endif

/* Set the format */
int32 bpp = ColorSpaceToBitsPerPixel(bmode->space);
Expand All @@ -127,35 +139,35 @@ static inline void BE_BDisplayModeToSdlDisplayMode(display_mode *bmode,
void BE_AddDisplay(BScreen *screen) {
SDL_VideoDisplay display;
SDL_DisplayMode *mode = (SDL_DisplayMode*)SDL_calloc(1, sizeof(SDL_DisplayMode));
display_mode bmode;
screen->GetMode(&bmode);
display_mode *bmode = (display_mode*)SDL_calloc(1, sizeof(display_mode));
screen->GetMode(bmode);

BE_BDisplayModeToSdlDisplayMode(&bmode, mode);
BE_BDisplayModeToSdlDisplayMode(bmode, mode);

SDL_zero(display);
display.desktop_mode = *mode;
display.current_mode = *mode;

SDL_AddVideoDisplay(&display);
}

int BE_InitModes(_THIS) {
BScreen screen;

/* Save the current display mode */
display_mode *prevMode;
screen.GetMode(prevMode);
_GetBeApp()->SetPrevMode(prevMode);
// display_mode *prevMode;
// screen.GetMode(prevMode);
// _GetBeApp()->SetPrevMode(prevMode);

/* Only one possible video display right now */
BE_AddDisplay(&screen);
}

int BE_QuitModes(_THIS) {
/* printf(__FILE__": %d; Begin quit\n", __LINE__);*/
/* Restore the previous video mode */
BScreen screen;
display_mode *savedMode = _GetBeApp()->GetPrevMode();
screen.SetMode(savedMode);
// display_mode *savedMode = _GetBeApp()->GetPrevMode();
// screen.SetMode(savedMode);
return 0;
}

Expand Down Expand Up @@ -197,13 +209,37 @@ void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display) {
int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){
/* Get the current screen */
BScreen bscreen;

if(!bscreen.IsValid()) {
printf(__FILE__": %d - ERROR: BAD SCREEN\n", __LINE__);
}

/* Set the mode using the driver data */
display_mode *bmode = ((SDL_DisplayModeData*)mode->driverdata)->bmode;
if(bscreen.SetMode(bmode) == B_OK) {
display_mode *bmode = _ExtractBMode(mode);

status_t s;
if((s = bscreen.SetMode(bmode)) == B_OK) {
return 0; /* No error */
}

printf(__FILE__": %d - ERROR: FAILED TO CHANGE VIDEO MODE; s = %i, status = B_BAD_VALUE? %i\n", __LINE__, s, s == B_BAD_VALUE);
display_mode *bmode_list;
uint32 count;
bscreen.GetModeList(&bmode_list, &count);
s = bscreen.ProposeMode(bmode, &bmode_list[count - 1], &bmode_list[0]);
switch(s) {
case B_OK:
printf(__FILE__": %d - B_OK\n", __LINE__);
break;
case B_BAD_VALUE:
printf(__FILE__": %d - B_BAD_VALUE\n", __LINE__);
break;
case B_ERROR:
printf(__FILE__": %d - B_ERROR\n", __LINE__);
break;
default:
printf(__FILE__": %d - (unknown error code)\n", __LINE__);
break;
}
free(bmode_list);
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/video/bwindow/SDL_bwindow.cc
Expand Up @@ -51,7 +51,7 @@ int _InitWindow(_THIS, SDL_Window *window) {
if(window->flags & SDL_WINDOW_OPENGL) {
}
if(!(window->flags & SDL_WINDOW_RESIZABLE)) {
flags |= B_NOT_RESIZABLE;
flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE;
}
if(window->flags & SDL_WINDOW_BORDERLESS) {
}
Expand Down

0 comments on commit fcf01b4

Please sign in to comment.