mirror of
https://github.com/libretro/hatari.git
synced 2025-02-17 06:37:30 +00:00
Consolidate the code around SDL_SetVideoMode in a separate function.
SDL_SetVideoMode will be gone with libSDL2. Let's merge the two code paths that use SDL_SetVideoMode into a separate function, so that it can be replaced easier at a later point in time.
This commit is contained in:
parent
74cd79ee2a
commit
95c14b52b3
@ -50,7 +50,6 @@ const char HostScreen_fileid[] = "Hatari hostscreen.c : " __DATE__ " " __TIME__;
|
||||
|
||||
|
||||
/* TODO: put these hostscreen globals to some struct */
|
||||
static Uint32 sdl_videoparams;
|
||||
static SDL_Rect hs_rect;
|
||||
static int hs_width_req, hs_height_req, hs_bpp;
|
||||
static bool doUpdate; // the HW surface is available -> the SDL need not to update the surface after ->pixel access
|
||||
@ -89,10 +88,6 @@ void HostScreen_UnInit(void)
|
||||
|
||||
void HostScreen_toggleFullScreen(void)
|
||||
{
|
||||
sdl_videoparams ^= SDL_FULLSCREEN;
|
||||
Dprintf(("Fullscreen = %s, width = %d, height = %d, bpp = %d\n",
|
||||
sdl_videoparams&SDL_FULLSCREEN?"true":"false", hs_width_req, hs_height_req, hs_bpp));
|
||||
|
||||
HostScreen_setWindowSize(hs_width_req, hs_height_req, hs_bpp);
|
||||
/* force screen redraw */
|
||||
HostScreen_update1(NULL, true);
|
||||
@ -187,9 +182,7 @@ void HostScreen_setWindowSize(int width, int height, int bpp)
|
||||
hs_rect.w = screenwidth;
|
||||
hs_rect.h = screenheight - sbarheight;
|
||||
|
||||
if (sdlscrn && (!bpp || sdlscrn->format->BitsPerPixel == bpp) &&
|
||||
sdlscrn->w == (signed)screenwidth && sdlscrn->h == (signed)screenheight &&
|
||||
(sdlscrn->flags&SDL_FULLSCREEN) == (sdl_videoparams&SDL_FULLSCREEN))
|
||||
if (!Screen_SetSDLVideoSize(screenwidth, screenheight, bpp))
|
||||
{
|
||||
/* same host screen size despite Atari resolution change,
|
||||
* -> no time consuming host video mode change needed
|
||||
@ -213,28 +206,6 @@ void HostScreen_setWindowSize(int width, int height, int bpp)
|
||||
return;
|
||||
}
|
||||
|
||||
if (bInFullScreen) {
|
||||
/* un-embed the Hatari WM window for fullscreen */
|
||||
Control_ReparentWindow(screenwidth, screenheight, bInFullScreen);
|
||||
|
||||
sdl_videoparams = SDL_SWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN;
|
||||
} else {
|
||||
sdl_videoparams = SDL_SWSURFACE|SDL_HWPALETTE;
|
||||
}
|
||||
#ifdef _MUDFLAP
|
||||
if (sdlscrn) {
|
||||
__mf_unregister(sdlscrn->pixels, sdlscrn->pitch*sdlscrn->h, __MF_TYPE_GUESS);
|
||||
}
|
||||
#endif
|
||||
sdlscrn = SDL_SetVideoMode(screenwidth, screenheight, bpp, sdl_videoparams);
|
||||
#ifdef _MUDFLAP
|
||||
__mf_register(sdlscrn->pixels, sdlscrn->pitch*sdlscrn->h, __MF_TYPE_GUESS, "SDL pixels");
|
||||
#endif
|
||||
if (!bInFullScreen) {
|
||||
/* re-embed the new Hatari SDL window */
|
||||
Control_ReparentWindow(screenwidth, screenheight, bInFullScreen);
|
||||
}
|
||||
|
||||
// In case surface format changed, update SDL palette & remap the native palette
|
||||
HostScreen_updatePalette(256);
|
||||
HostScreen_remapPalette();
|
||||
|
@ -103,6 +103,7 @@ extern void Screen_EnterFullScreen(void);
|
||||
extern void Screen_ReturnFromFullScreen(void);
|
||||
extern void Screen_ModeChanged(void);
|
||||
extern bool Screen_Draw(void);
|
||||
extern bool Screen_SetSDLVideoSize(int width, int height, int bitdepth);
|
||||
|
||||
extern bool bTTSampleHold; /* TT special video mode */
|
||||
|
||||
|
172
src/screen.c
172
src/screen.c
@ -336,6 +336,84 @@ static void Screen_SetSTScreenOffsets(void)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the SDL video mode.
|
||||
* @return true if mode has been changed, false if change was not necessary
|
||||
*/
|
||||
bool Screen_SetSDLVideoSize(int width, int height, int bitdepth)
|
||||
{
|
||||
Uint32 sdlVideoFlags;
|
||||
|
||||
/* SDL Video attributes: */
|
||||
if (bInFullScreen)
|
||||
{
|
||||
sdlVideoFlags = SDL_HWSURFACE|SDL_FULLSCREEN/*|SDL_DOUBLEBUF*/;
|
||||
/* SDL_DOUBLEBUF helps avoiding tearing and can be faster on suitable HW,
|
||||
* but it doesn't work with partial screen updates done by the ST screen
|
||||
* update code or the Hatari GUI, so double buffering is disabled. */
|
||||
}
|
||||
else
|
||||
{
|
||||
sdlVideoFlags = SDL_SWSURFACE;
|
||||
}
|
||||
if (bitdepth <= 8)
|
||||
{
|
||||
sdlVideoFlags |= SDL_HWPALETTE;
|
||||
}
|
||||
|
||||
/* Check if we really have to change the video mode: */
|
||||
if (sdlscrn != NULL && sdlscrn->w == width && sdlscrn->h == height
|
||||
&& sdlscrn->format->BitsPerPixel == bitdepth
|
||||
&& (sdlscrn->flags&SDL_FULLSCREEN) == (sdlVideoFlags&SDL_FULLSCREEN))
|
||||
return false;
|
||||
|
||||
#ifdef _MUDFLAP
|
||||
if (sdlscrn)
|
||||
{
|
||||
__mf_unregister(sdlscrn->pixels, sdlscrn->pitch*sdlscrn->h, __MF_TYPE_GUESS);
|
||||
}
|
||||
#endif
|
||||
if (bInFullScreen)
|
||||
{
|
||||
/* unhide the Hatari WM window for fullscreen */
|
||||
Control_ReparentWindow(width, height, bInFullScreen);
|
||||
}
|
||||
|
||||
/* Set new video mode */
|
||||
DEBUGPRINT(("SDL screen request: %d x %d @ %d (%s)\n", width, h, bitdepth, bInFullScreen?"fullscreen":"windowed"));
|
||||
sdlscrn = SDL_SetVideoMode(width, height, bitdepth, sdlVideoFlags);
|
||||
DEBUGPRINT(("SDL screen granted: %d x %d @ %d\n", sdlscrn->w, sdlscrn->h, sdlscrn->format->BitsPerPixel));
|
||||
|
||||
/* By default ConfigureParams.Screen.nForceBpp and therefore
|
||||
* BitCount is zero which means "SDL color depth autodetection".
|
||||
* In this case the SDL_SetVideoMode() call might return
|
||||
* a 24 bpp resolution
|
||||
*/
|
||||
if (sdlscrn && sdlscrn->format->BitsPerPixel == 24)
|
||||
{
|
||||
fprintf(stderr, "Unsupported color depth 24, trying 32 bpp instead...\n");
|
||||
sdlscrn = SDL_SetVideoMode(width, height, 32, sdlVideoFlags);
|
||||
}
|
||||
|
||||
/* Exit if we can not open a screen */
|
||||
if (!sdlscrn)
|
||||
{
|
||||
fprintf(stderr, "Could not set video mode:\n %s\n", SDL_GetError() );
|
||||
SDL_Quit();
|
||||
exit(-2);
|
||||
}
|
||||
#ifdef _MUDFLAP
|
||||
__mf_register(sdlscrn->pixels, sdlscrn->pitch*sdlscrn->h, __MF_TYPE_GUESS, "SDL pixels");
|
||||
#endif
|
||||
|
||||
if (!bInFullScreen)
|
||||
{
|
||||
/* re-embed the new Hatari SDL window */
|
||||
Control_ReparentWindow(width, height, bInFullScreen);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/**
|
||||
@ -344,7 +422,6 @@ static void Screen_SetSTScreenOffsets(void)
|
||||
static void Screen_SetResolution(void)
|
||||
{
|
||||
int Width, Height, nZoom, SBarHeight, BitCount, maxW, maxH;
|
||||
Uint32 sdlVideoFlags;
|
||||
bool bDoubleLowRes = false;
|
||||
|
||||
/* Bits per pixel */
|
||||
@ -427,93 +504,30 @@ static void Screen_SetResolution(void)
|
||||
DEBUGPRINT(("\t= %d x %d (+ statusbar)\n", Width, Height));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Screen_SetSTScreenOffsets();
|
||||
Height += Statusbar_SetHeight(Width, Height);
|
||||
|
||||
PCScreenOffsetX = PCScreenOffsetY = 0;
|
||||
|
||||
/* SDL Video attributes: */
|
||||
if (bInFullScreen)
|
||||
/* Video attributes: */
|
||||
if (bInFullScreen && ConfigureParams.Screen.bKeepResolutionST)
|
||||
{
|
||||
if (ConfigureParams.Screen.bKeepResolutionST)
|
||||
{
|
||||
/* use desktop resolution */
|
||||
Resolution_GetDesktopSize(&maxW, &maxH);
|
||||
SBarHeight = Statusbar_GetHeightForSize(maxW, maxH);
|
||||
/* re-calculate statusbar height for this resolution */
|
||||
Statusbar_SetHeight(maxW, maxH-SBarHeight);
|
||||
/* center Atari screen to resolution */
|
||||
PCScreenOffsetY = (maxH - Height)/2;
|
||||
PCScreenOffsetX = (maxW - Width)/2;
|
||||
/* and select desktop resolution */
|
||||
Height = maxH;
|
||||
Width = maxW;
|
||||
}
|
||||
sdlVideoFlags = SDL_HWSURFACE|SDL_FULLSCREEN/*|SDL_DOUBLEBUF*/;
|
||||
/* SDL_DOUBLEBUF helps avoiding tearing and can be faster on suitable HW,
|
||||
* but it doesn't work with partial screen updates done by the ST screen
|
||||
* update code or the Hatari GUI, so double buffering is disabled.
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
sdlVideoFlags = SDL_SWSURFACE;
|
||||
}
|
||||
if (BitCount <= 8)
|
||||
{
|
||||
sdlVideoFlags |= SDL_HWPALETTE;
|
||||
/* use desktop resolution */
|
||||
Resolution_GetDesktopSize(&maxW, &maxH);
|
||||
SBarHeight = Statusbar_GetHeightForSize(maxW, maxH);
|
||||
/* re-calculate statusbar height for this resolution */
|
||||
Statusbar_SetHeight(maxW, maxH-SBarHeight);
|
||||
/* center Atari screen to resolution */
|
||||
PCScreenOffsetY = (maxH - Height)/2;
|
||||
PCScreenOffsetX = (maxW - Width)/2;
|
||||
/* and select desktop resolution */
|
||||
Height = maxH;
|
||||
Width = maxW;
|
||||
}
|
||||
|
||||
/* Check if we really have to change the video mode: */
|
||||
if (!sdlscrn || sdlscrn->w != Width || sdlscrn->h != Height
|
||||
|| (BitCount && sdlscrn->format->BitsPerPixel != BitCount)
|
||||
|| (sdlscrn->flags&SDL_FULLSCREEN) != (sdlVideoFlags&SDL_FULLSCREEN))
|
||||
if (Screen_SetSDLVideoSize(Width, Height, BitCount))
|
||||
{
|
||||
#ifdef _MUDFLAP
|
||||
if (sdlscrn) {
|
||||
__mf_unregister(sdlscrn->pixels, sdlscrn->pitch*sdlscrn->h, __MF_TYPE_GUESS);
|
||||
}
|
||||
#endif
|
||||
if (bInFullScreen)
|
||||
{
|
||||
/* unhide the Hatari WM window for fullscreen */
|
||||
Control_ReparentWindow(Width, Height, bInFullScreen);
|
||||
}
|
||||
|
||||
/* Set new video mode */
|
||||
DEBUGPRINT(("SDL screen request: %d x %d @ %d (%s)\n", Width, Height, BitCount, bInFullScreen?"fullscreen":"windowed"));
|
||||
sdlscrn = SDL_SetVideoMode(Width, Height, BitCount, sdlVideoFlags);
|
||||
DEBUGPRINT(("SDL screen granted: %d x %d @ %d\n", sdlscrn->w, sdlscrn->h, sdlscrn->format->BitsPerPixel));
|
||||
|
||||
/* By default ConfigureParams.Screen.nForceBpp and therefore
|
||||
* BitCount is zero which means "SDL color depth autodetection".
|
||||
* In this case the SDL_SetVideoMode() call might return
|
||||
* a 24 bpp resolution
|
||||
*/
|
||||
if (sdlscrn && sdlscrn->format->BitsPerPixel == 24)
|
||||
{
|
||||
fprintf(stderr, "Unsupported color depth 24, trying 32 bpp instead...\n");
|
||||
sdlscrn = SDL_SetVideoMode(Width, Height, 32, sdlVideoFlags);
|
||||
}
|
||||
|
||||
/* Exit if we can not open a screen */
|
||||
if (!sdlscrn)
|
||||
{
|
||||
fprintf(stderr, "Could not set video mode:\n %s\n", SDL_GetError() );
|
||||
SDL_Quit();
|
||||
exit(-2);
|
||||
}
|
||||
#ifdef _MUDFLAP
|
||||
__mf_register(sdlscrn->pixels, sdlscrn->pitch*sdlscrn->h, __MF_TYPE_GUESS, "SDL pixels");
|
||||
#endif
|
||||
|
||||
if (!bInFullScreen)
|
||||
{
|
||||
/* re-embed the new Hatari SDL window */
|
||||
Control_ReparentWindow(Width, Height, bInFullScreen);
|
||||
}
|
||||
|
||||
/* Re-init screen palette: */
|
||||
if (sdlscrn->format->BitsPerPixel == 8)
|
||||
Screen_Handle8BitPalettes(); /* Initialize new 8 bit palette */
|
||||
|
Loading…
x
Reference in New Issue
Block a user