Annotation of previous/src/resolution.c, revision 1.1.1.3

1.1       root        1: /*
                      2:   Hatari - resolution.c
                      3: 
                      4:   This file is distributed under the GNU Public License, version 2 or at
                      5:   your option any later version. Read the file gpl.txt for details.
                      6: 
                      7:   SDL resolution limitation and selection routines.
                      8: */
                      9: const char Resolution_fileid[] = "Hatari resolution.c : " __DATE__ " " __TIME__;
                     10: 
                     11: #include <SDL.h>
                     12: #include "main.h"
                     13: #include "configuration.h"
                     14: #include "resolution.h"
                     15: #include "screen.h"
                     16: 
                     17: #define RESOLUTION_DEBUG 0
                     18: 
                     19: #if RESOLUTION_DEBUG
                     20: #define Dprintf(a) printf a
                     21: #else
                     22: #define Dprintf(a)
                     23: #endif
                     24: 
1.1.1.2   root       25: static int DesktopWidth, DesktopHeight;
                     26: 
                     27: /**
                     28:   * Initilizes resolution settings (gets current desktop
                     29:   * resolution, sets max Falcon/TT Videl zooming resolution).
                     30:   */
                     31: void Resolution_Init(void)
                     32: {
                     33:        /* Needs to be called after SDL video and configuration
                     34:         * initialization, but before Hatari Screen init is called
                     35:         * for the first time!
                     36:         */
1.1.1.3 ! root       37:        fprintf(stderr,"FIXME: Resolution init!\n");
        !            38:        DesktopWidth = 800;
        !            39:        DesktopHeight = 600;
        !            40: 
1.1.1.2   root       41:        /* if user hasn't set own max zoom size, use desktop size */
                     42:        if (!(ConfigureParams.Screen.nMaxWidth &&
                     43:              ConfigureParams.Screen.nMaxHeight)) {
                     44:                ConfigureParams.Screen.nMaxWidth = DesktopWidth;
                     45:                ConfigureParams.Screen.nMaxHeight = DesktopHeight;
                     46:        }
                     47:        Dprintf(("Desktop resolution: %dx%d\n",DesktopWidth, DesktopHeight));
                     48:        Dprintf(("Configured Max res: %dx%d\n",ConfigureParams.Screen.nMaxWidth,ConfigureParams.Screen.nMaxHeight));
                     49: }
                     50: 
                     51: /**
                     52:   * Get current desktop resolution
                     53:   */
                     54: void Resolution_GetDesktopSize(int *width, int *height)
                     55: {
                     56:        *width = DesktopWidth;
                     57:        *height = DesktopHeight;
                     58: }
                     59: 
1.1       root       60: 
                     61: /**
                     62:  * Select best resolution from given SDL video modes.
                     63:  * - If width and height are given, select the smallest mode larger
                     64:  *   or equal to requested size
                     65:  * - Otherwise select the largest available mode
                     66:  * return true for success and false if no matching mode was found.
                     67:  */
                     68: static bool Resolution_Select(SDL_Rect **modes, int *width, int *height)
                     69: {
                     70: #define TOO_LARGE 0x7fff
                     71:        int i, bestw, besth;
                     72: 
                     73:        if (!(*width && *height)) {
                     74:                /* search the largest mode (prefer wider ones) */
                     75:                for (i = 0; modes[i]; i++) {
                     76:                        if ((modes[i]->w > *width) && (modes[i]->h >= *height)) {
                     77:                                *width = modes[i]->w;
                     78:                                *height = modes[i]->h;
                     79:                        }
                     80:                }
1.1.1.2   root       81:                Dprintf(("resolution: largest found video mode: %dx%d\n",*width,*height));
1.1       root       82:                return true;
                     83:        }
                     84: 
                     85:        /* Search the smallest mode larger or equal to requested size */
                     86:        bestw = TOO_LARGE;
                     87:        besth = TOO_LARGE;
                     88:        for (i = 0; modes[i]; i++) {
                     89:                if ((modes[i]->w >= *width) && (modes[i]->h >= *height)) {
                     90:                        if ((modes[i]->w < bestw) || (modes[i]->h < besth)) {
                     91:                                bestw = modes[i]->w;
                     92:                                besth = modes[i]->h;
                     93:                        }
                     94:                }
                     95:        }
                     96:        if (bestw == TOO_LARGE || besth == TOO_LARGE) {
                     97:                return false;
                     98:        }
                     99:        *width = bestw;
                    100:        *height = besth;
1.1.1.2   root      101:        Dprintf(("resolution: video mode found: %dx%d\n",*width,*height));
1.1       root      102:        return true;
                    103: #undef TOO_LARGE
                    104: }
                    105: 
                    106: 
                    107: /**
                    108:  * Search video mode size that best suits the given width/height/bpp
                    109:  * constraints and set them into given arguments.  With zeroed arguments,
                    110:  * return largest video mode.
                    111:  */
                    112: void Resolution_Search(int *width, int *height, int *bpp)
                    113: {
1.1.1.3 ! root      114:        fprintf(stderr,"FIXME: Resolution_Search\n");
        !           115:        Resolution_GetDesktopSize(width, height);
1.1       root      116: }
                    117: 
                    118: 
                    119: /**
1.1.1.2   root      120:   * Set given width & height arguments to maximum size allowed in the
                    121:   * configuration, or if that's too large for the requested bit depth,
                    122:   * to the largest available video mode size.
1.1       root      123:  */
                    124: void Resolution_GetLimits(int *width, int *height, int *bpp)
                    125: {
                    126:        *width = *height = 0;
                    127:        /* constrain max size to what HW/SDL offers */
1.1.1.2   root      128:     Dprintf(("resolution: request limits for: %dx%dx%d\n", *width, *height, *bpp));
1.1       root      129:        Resolution_Search(width, height, bpp);
1.1.1.2   root      130: 
                    131:        if (bInFullScreen && ConfigureParams.Screen.bKeepResolution) {
                    132:                /* resolution change not allowed */
                    133:                Dprintf(("resolution: limit to desktop size\n"));
                    134:                Resolution_GetDesktopSize(width, height);
                    135:                return;
                    136:        }
                    137:        if (!(*width && *height) ||
                    138: 
1.1       root      139:            (ConfigureParams.Screen.nMaxWidth < *width &&
                    140:             ConfigureParams.Screen.nMaxHeight < *height)) {
1.1.1.2   root      141:                Dprintf(("resolution: limit to user configured max\n"));
1.1       root      142:                *width = ConfigureParams.Screen.nMaxWidth;
                    143:                *height = ConfigureParams.Screen.nMaxHeight;
                    144:        }
                    145: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.