--- previous/src/resolution.c 2018/04/24 19:25:10 1.1 +++ previous/src/resolution.c 2018/04/24 19:25:33 1.1.1.2 @@ -22,6 +22,48 @@ const char Resolution_fileid[] = "Hatari #define Dprintf(a) #endif +static int DesktopWidth, DesktopHeight; + +/** + * Initilizes resolution settings (gets current desktop + * resolution, sets max Falcon/TT Videl zooming resolution). + */ +void Resolution_Init(void) +{ + /* Needs to be called after SDL video and configuration + * initialization, but before Hatari Screen init is called + * for the first time! + */ + const SDL_VideoInfo* info = SDL_GetVideoInfo(); + if (info->current_w >= 640 && info->current_h >= 400) { + DesktopWidth = info->current_w; + DesktopHeight = info->current_h; + } else { + /* target 800x600 screen with statusbar out of screen */ + DesktopWidth = 320; + DesktopHeight = 200; + fprintf(stderr, "WARNING: invalid desktop size %dx%d, defaulting to %dx%d!\n", + info->current_w, info->current_h, DesktopWidth, DesktopHeight); + } + /* if user hasn't set own max zoom size, use desktop size */ + if (!(ConfigureParams.Screen.nMaxWidth && + ConfigureParams.Screen.nMaxHeight)) { + ConfigureParams.Screen.nMaxWidth = DesktopWidth; + ConfigureParams.Screen.nMaxHeight = DesktopHeight; + } + Dprintf(("Desktop resolution: %dx%d\n",DesktopWidth, DesktopHeight)); + Dprintf(("Configured Max res: %dx%d\n",ConfigureParams.Screen.nMaxWidth,ConfigureParams.Screen.nMaxHeight)); +} + +/** + * Get current desktop resolution + */ +void Resolution_GetDesktopSize(int *width, int *height) +{ + *width = DesktopWidth; + *height = DesktopHeight; +} + /** * Select best resolution from given SDL video modes. @@ -43,7 +85,7 @@ static bool Resolution_Select(SDL_Rect * *height = modes[i]->h; } } - Dprintf(("hostscreen: largest found video mode: %dx%d\n",*width,*height)); + Dprintf(("resolution: largest found video mode: %dx%d\n",*width,*height)); return true; } @@ -63,7 +105,7 @@ static bool Resolution_Select(SDL_Rect * } *width = bestw; *height = besth; - Dprintf(("hostscreen: video mode found: %dx%d\n",*width,*height)); + Dprintf(("resolution: video mode found: %dx%d\n",*width,*height)); return true; #undef TOO_LARGE } @@ -81,22 +123,29 @@ void Resolution_Search(int *width, int * Uint32 modeflags; /* Search in available modes the best suited */ - Dprintf(("hostscreen: video mode asked: %dx%dx%d\n", + Dprintf(("resolution: video mode asked: %dx%dx%d\n", *width, *height, *bpp)); /* Read available video modes */ modeflags = 0 /*SDL_HWSURFACE | SDL_HWPALETTE*/; - if (bInFullScreen) + if (bInFullScreen) { + /* resolution change not allowed? */ + if (ConfigureParams.Screen.bKeepResolution) { + Dprintf(("resolution: limit to desktop size\n")); + Resolution_GetDesktopSize(width, height); + return; + } modeflags |= SDL_FULLSCREEN; - + } + /*--- Search a video mode with asked bpp ---*/ if (*bpp != 0) { pixelformat.BitsPerPixel = *bpp; modes = SDL_ListModes(&pixelformat, modeflags); if ((modes != (SDL_Rect **) 0) && (modes != (SDL_Rect **) -1)) { - Dprintf(("hostscreen: searching a good video mode (any bpp)\n")); + Dprintf(("resolution: searching a good video mode (any bpp)\n")); if (Resolution_Select(modes, width, height)) { - Dprintf(("hostscreen: video mode selected: %dx%dx%d\n", + Dprintf(("resolution: video mode selected: %dx%dx%d\n", *width, *height, *bpp)); return; } @@ -106,9 +155,9 @@ void Resolution_Search(int *width, int * /*--- Search a video mode with any bpp ---*/ modes = SDL_ListModes(NULL, modeflags); if ((modes != (SDL_Rect **) 0) && (modes != (SDL_Rect **) -1)) { - Dprintf(("hostscreen: searching a good video mode\n")); + Dprintf(("resolution: searching a good video mode\n")); if (Resolution_Select(modes, width, height)) { - Dprintf(("hostscreen: video mode selected: %dx%dx%d\n", + Dprintf(("resolution: video mode selected: %dx%dx%d\n", *width, *height, *bpp)); return; } @@ -120,28 +169,37 @@ void Resolution_Search(int *width, int * if (modes == (SDL_Rect **) -1) { /* Any mode available */ - Dprintf(("hostscreen: All resolutions available.\n")); + Dprintf(("resolution: All resolutions available.\n")); } - Dprintf(("hostscreen: video mode selected: %dx%dx%d\n", + Dprintf(("resolution: video mode selected: %dx%dx%d\n", *width, *height, *bpp)); } /** - * Set given width & height arguments to maximum size in the configuration, - * or if that's too large for the requested bit depth, to the largest - * available video mode size. + * Set given width & height arguments to maximum size allowed in the + * configuration, or if that's too large for the requested bit depth, + * to the largest available video mode size. */ void Resolution_GetLimits(int *width, int *height, int *bpp) { *width = *height = 0; /* constrain max size to what HW/SDL offers */ + Dprintf(("resolution: request limits for: %dx%dx%d\n", *width, *height, *bpp)); Resolution_Search(width, height, bpp); - if (!(*width && *width) || + + if (bInFullScreen && ConfigureParams.Screen.bKeepResolution) { + /* resolution change not allowed */ + Dprintf(("resolution: limit to desktop size\n")); + Resolution_GetDesktopSize(width, height); + return; + } + if (!(*width && *height) || + (ConfigureParams.Screen.nMaxWidth < *width && ConfigureParams.Screen.nMaxHeight < *height)) { - /* already within it, use user provided value */ + Dprintf(("resolution: limit to user configured max\n")); *width = ConfigureParams.Screen.nMaxWidth; *height = ConfigureParams.Screen.nMaxHeight; }