ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/SDL/video_sdl.cpp
(Generate patch)

Comparing BasiliskII/src/SDL/video_sdl.cpp (file contents):
Revision 1.23 by gbeauche, 2006-03-28T07:01:19Z vs.
Revision 1.24 by gbeauche, 2006-05-09T21:41:02Z

# Line 286 | Line 286 | static vector<monitor_desc *> VideoMonit
286   // Find Apple mode matching best specified dimensions
287   static int find_apple_resolution(int xsize, int ysize)
288   {
289 <        int apple_id;
290 <        if (xsize < 800)
291 <                apple_id = APPLE_640x480;
292 <        else if (xsize < 1024)
293 <                apple_id = APPLE_800x600;
294 <        else if (xsize < 1152)
295 <                apple_id = APPLE_1024x768;
296 <        else if (xsize < 1280) {
297 <                if (ysize < 900)
298 <                        apple_id = APPLE_1152x768;
299 <                else
300 <                        apple_id = APPLE_1152x900;
301 <        }
302 <        else if (xsize < 1600)
303 <                apple_id = APPLE_1280x1024;
304 <        else
305 <                apple_id = APPLE_1600x1200;
306 <        return apple_id;
307 < }
308 <
309 < // Set parameters to specified Apple mode
310 < static void set_apple_resolution(int apple_id, int &xsize, int &ysize)
311 < {
312 <        switch (apple_id) {
313 <        case APPLE_640x480:
314 <                xsize = 640;
315 <                ysize = 480;
316 <                break;
317 <        case APPLE_800x600:
318 <                xsize = 800;
319 <                ysize = 600;
320 <                break;
321 <        case APPLE_1024x768:
322 <                xsize = 1024;
323 <                ysize = 768;
324 <                break;
325 <        case APPLE_1152x768:
326 <                xsize = 1152;
327 <                ysize = 768;
328 <                break;
329 <        case APPLE_1152x900:
330 <                xsize = 1152;
331 <                ysize = 900;
332 <                break;
333 <        case APPLE_1280x1024:
334 <                xsize = 1280;
335 <                ysize = 1024;
336 <                break;
337 <        case APPLE_1600x1200:
338 <                xsize = 1600;
339 <                ysize = 1200;
340 <                break;
341 <        default:
342 <                abort();
343 <        }
344 < }
345 <
346 < // Match Apple mode matching best specified dimensions
347 < static int match_apple_resolution(int &xsize, int &ysize)
348 < {
349 <        int apple_id = find_apple_resolution(xsize, ysize);
350 <        set_apple_resolution(apple_id, xsize, ysize);
351 <        return apple_id;
289 >        if (xsize == 640 && ysize == 480)
290 >                return APPLE_640x480;
291 >        if (xsize == 800 && ysize == 600)
292 >                return APPLE_800x600;
293 >        if (xsize == 1024 && ysize == 768)
294 >                return APPLE_1024x768;
295 >        if (xsize == 1152 && ysize == 768)
296 >                return APPLE_1152x768;
297 >        if (xsize == 1152 && ysize == 900)
298 >                return APPLE_1152x900;
299 >        if (xsize == 1280 && ysize == 1024)
300 >                return APPLE_1280x1024;
301 >        if (xsize == 1600 && ysize == 1200)
302 >                return APPLE_1600x1200;
303 >        return APPLE_CUSTOM;
304   }
305  
306   // Display error alert
# Line 455 | Line 407 | static int sdl_depth_of_video_depth(int
407          return (video_depth <= VIDEO_DEPTH_8BIT) ? 8 : mac_depth_of_video_depth(video_depth);
408   }
409  
410 + // Get screen dimensions
411 + static void sdl_display_dimensions(int &width, int &height)
412 + {
413 +        static int max_width, max_height;
414 +        if (max_width == 0 && max_height == 0) {
415 +                max_width = 640 ; max_height = 480;
416 +                SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
417 +                if (modes && modes != (SDL_Rect **)-1) {
418 +                        // It turns out that on some implementations, and contrary to the documentation,
419 +                        // the returned list is not sorted from largest to smallest (e.g. Windows)
420 +                        for (int i = 0; modes[i] != NULL; i++) {
421 +                                const int w = modes[i]->w;
422 +                                const int h = modes[i]->h;
423 +                                if (w > max_width && h > max_height) {
424 +                                        max_width = w;
425 +                                        max_height = h;
426 +                                }
427 +                        }
428 +                }
429 +        }
430 +        width = max_width;
431 +        height = max_height;
432 + }
433 +
434 + static inline int sdl_display_width(void)
435 + {
436 +        int width, height;
437 +        sdl_display_dimensions(width, height);
438 +        return width;
439 + }
440 +
441 + static inline int sdl_display_height(void)
442 + {
443 +        int width, height;
444 +        sdl_display_dimensions(width, height);
445 +        return height;
446 + }
447 +
448   // Check wether specified mode is available
449 < static bool has_mode(int type, int width, int height)
449 > static bool has_mode(int type, int width, int height, int depth)
450   {
451   #ifdef SHEEPSHAVER
452 <        // Filter out Classic resolutiosn
452 >        // Filter out Classic resolutions
453          if (width == 512 && height == 384)
454                  return false;
455 + #endif
456  
457 <        // "screen" prefs items always succeeds
458 <        if (PrefsFindString("screen"))
459 <                return true;
469 <
470 <        // Read window & screen modes prefs
471 <        static uint32 window_modes = 0;
472 <        static uint32 screen_modes = 0;
473 <        if (window_modes == 0 || screen_modes == 0) {
474 <                window_modes = PrefsFindInt32("windowmodes");
475 <                screen_modes = PrefsFindInt32("screenmodes");
476 <                if (window_modes == 0 || screen_modes == 0)
477 <                        window_modes |= 3;                      // Allow at least 640x480 and 800x600 window modes
478 <        }
479 <
480 <        int test_modes;
481 <        switch (type) {
482 <        case DISPLAY_WINDOW:
483 <                test_modes = window_modes;
484 <                break;
485 <        case DISPLAY_SCREEN:
486 <                test_modes = screen_modes;
487 <                break;
488 <        default:
489 <                test_modes = 0;
490 <                break;
491 <        }
457 >        // Filter out out-of-bounds resolutions
458 >        if (width > sdl_display_width() || height > sdl_display_height())
459 >                return false;
460  
461 <        int apple_mask;
462 <        switch (find_apple_resolution(width, height)) {
463 <        case APPLE_640x480:             apple_mask = 0x01; break;
464 <        case APPLE_800x600:             apple_mask = 0x02; break;
497 <        case APPLE_1024x768:    apple_mask = 0x04; break;
498 <        case APPLE_1152x768:    apple_mask = 0x40; break;
499 <        case APPLE_1152x900:    apple_mask = 0x08; break;
500 <        case APPLE_1280x1024:   apple_mask = 0x10; break;
501 <        case APPLE_1600x1200:   apple_mask = 0x20; break;
502 <        default:                                apple_mask = 0x00; break;
503 <        }
504 <        return (test_modes & apple_mask);
505 < #endif
506 <        return true;
461 >        // Rely on SDL capabilities
462 >        return SDL_VideoModeOK(width, height,
463 >                                                   sdl_depth_of_video_depth(depth),
464 >                                                   SDL_HWSURFACE | (type == DISPLAY_SCREEN ? SDL_FULLSCREEN : 0));
465   }
466  
467   // Add mode to list of supported modes
468   static void add_mode(int type, int width, int height, int resolution_id, int bytes_per_row, int depth)
469   {
470          // Filter out unsupported modes
471 <        if (!has_mode(type, width, height))
471 >        if (!has_mode(type, width, height, depth))
472                  return;
473  
474          // Fill in VideoMode entry
475          VIDEO_MODE mode;
476   #ifdef SHEEPSHAVER
477 <        // Recalculate dimensions to fit Apple modes
520 <        resolution_id = match_apple_resolution(width, height);
477 >        resolution_id = find_apple_resolution(width, height);
478          mode.viType = type;
479   #endif
480          VIDEO_MODE_X = width;
# Line 528 | Line 485 | static void add_mode(int type, int width
485          VideoModes.push_back(mode);
486   }
487  
531 // Add standard list of windowed modes for given color depth
532 static void add_window_modes(int depth)
533 {
534        video_depth vdepth = (video_depth)depth;
535        add_mode(DISPLAY_WINDOW, 512, 384, 0x80, TrivialBytesPerRow(512, vdepth), depth);
536        add_mode(DISPLAY_WINDOW, 640, 480, 0x81, TrivialBytesPerRow(640, vdepth), depth);
537        add_mode(DISPLAY_WINDOW, 800, 600, 0x82, TrivialBytesPerRow(800, vdepth), depth);
538        add_mode(DISPLAY_WINDOW, 1024, 768, 0x83, TrivialBytesPerRow(1024, vdepth), depth);
539        add_mode(DISPLAY_WINDOW, 1152, 870, 0x84, TrivialBytesPerRow(1152, vdepth), depth);
540        add_mode(DISPLAY_WINDOW, 1280, 1024, 0x85, TrivialBytesPerRow(1280, vdepth), depth);
541        add_mode(DISPLAY_WINDOW, 1600, 1200, 0x86, TrivialBytesPerRow(1600, vdepth), depth);
542 }
543
488   // Set Mac frame layout and base address (uses the_buffer/MacFrameBaseMac)
489   static void set_mac_frame_buffer(SDL_monitor_desc &monitor, int depth, bool native_byte_order)
490   {
# Line 584 | Line 528 | static SDL_GrabMode set_grab_mode(SDL_Gr
528          return (vi && vi->wm_available ? SDL_WM_GrabInput(mode) : SDL_GRAB_OFF);
529   }
530  
531 + // Migrate preferences items (XXX to be handled in MigratePrefs())
532 + static void migrate_screen_prefs(void)
533 + {
534 + #ifdef SHEEPSHAVER
535 +        // Look-up priorities are: "screen", "screenmodes", "windowmodes".
536 +        if (PrefsFindString("screen"))
537 +                return;
538 +
539 +        uint32 window_modes = PrefsFindInt32("windowmodes");
540 +        uint32 screen_modes = PrefsFindInt32("screenmodes");
541 +        int width = 0, height = 0;
542 +        if (screen_modes) {
543 +                static const struct {
544 +                        int id;
545 +                        int width;
546 +                        int height;
547 +                }
548 +                modes[] = {
549 +                        {  1,    640,    480 },
550 +                        {  2,    800,    600 },
551 +                        {  4,   1024,    768 },
552 +                        { 64,   1152,    768 },
553 +                        {  8,   1152,    900 },
554 +                        { 16,   1280,   1024 },
555 +                        { 32,   1600,   1200 },
556 +                        { 0, }
557 +                };
558 +                for (int i = 0; modes[i].id != 0; i++) {
559 +                        if (screen_modes & modes[i].id) {
560 +                                if (width < modes[i].width && height < modes[i].height) {
561 +                                        width = modes[i].width;
562 +                                        height = modes[i].height;
563 +                                }
564 +                        }
565 +                }
566 +        } else {
567 +                if (window_modes & 1)
568 +                        width = 640, height = 480;
569 +                if (window_modes & 2)
570 +                        width = 800, height = 600;
571 +        }
572 +        if (width && height) {
573 +                char str[32];
574 +                sprintf(str, "%s/%d/%d", screen_modes ? "dga" : "win", width, height);
575 +                PrefsReplaceString("screen", str);
576 +        }
577 + #endif
578 + }
579 +
580  
581   /*
582   *  Display "driver" classes
# Line 1123 | Line 1116 | bool VideoInit(bool classic)
1116          mouse_wheel_lines = PrefsFindInt32("mousewheellines");
1117  
1118          // Get screen mode from preferences
1119 +        migrate_screen_prefs();
1120          const char *mode_str = NULL;
1121          if (classic_mode)
1122                  mode_str = "win/512/342";
# Line 1146 | Line 1140 | bool VideoInit(bool classic)
1140                  else if (sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2)
1141                          display_type = DISPLAY_SCREEN;
1142          }
1149        int max_width = 640, max_height = 480;
1150        SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
1151        if (modes && modes != (SDL_Rect **)-1) {
1152                // It turns out that on some implementations, and contrary to the documentation,
1153                // the returned list is not sorted from largest to smallest (e.g. Windows)
1154                for (int i = 0; modes[i] != NULL; i++) {
1155                        const int w = modes[i]->w;
1156                        const int h = modes[i]->h;
1157                        if (w > max_width && h > max_height) {
1158                                max_width = w;
1159                                max_height = h;
1160                        }
1161                }
1162                if (default_width > max_width)
1163                        default_width = max_width;
1164                if (default_height > max_height)
1165                        default_height = max_height;
1166        }
1143          if (default_width <= 0)
1144 <                default_width = max_width;
1144 >                default_width = sdl_display_width();
1145 >        else if (default_width > sdl_display_width())
1146 >                default_width = sdl_display_width();
1147          if (default_height <= 0)
1148 <                default_height = max_height;
1148 >                default_height = sdl_display_height();
1149 >        else if (default_height > sdl_display_height())
1150 >                default_height = sdl_display_height();
1151  
1152          // Mac screen depth follows X depth
1153          screen_depth = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
# Line 1187 | Line 1167 | bool VideoInit(bool classic)
1167                  break;
1168          }
1169  
1170 +        // Initialize list of video modes to try
1171 +        struct {
1172 +                int w;
1173 +                int h;
1174 +                int resolution_id;
1175 +        }
1176 +        video_modes[] = {
1177 +                {   -1,   -1, 0x80 },
1178 +                {  512,  384, 0x80 },
1179 +                {  640,  480, 0x81 },
1180 +                {  800,  600, 0x82 },
1181 +                { 1024,  768, 0x83 },
1182 +                { 1152,  870, 0x84 },
1183 +                { 1280, 1024, 0x85 },
1184 +                { 1600, 1200, 0x86 },
1185 +                { 0, }
1186 +        };
1187 +        video_modes[0].w = default_width;
1188 +        video_modes[0].h = default_height;
1189 +
1190          // Construct list of supported modes
1191          if (display_type == DISPLAY_WINDOW) {
1192                  if (classic)
1193                          add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT);
1194                  else {
1195 <                        for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) {
1196 <                                int bpp = sdl_depth_of_video_depth(d);
1197 <                                if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE))
1198 <                                        add_window_modes(video_depth(d));
1195 >                        for (int i = 0; video_modes[i].w != 0; i++) {
1196 >                                const int w = video_modes[i].w;
1197 >                                const int h = video_modes[i].h;
1198 >                                if (i > 0 && (w >= default_width || h >= default_height))
1199 >                                        continue;
1200 >                                for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++)
1201 >                                        add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)d), d);
1202                          }
1203                  }
1204          } else if (display_type == DISPLAY_SCREEN) {
1202                struct {
1203                        int w;
1204                        int h;
1205                        int resolution_id;
1206                }
1207                video_modes[] = {
1208                        {   -1,   -1, 0x80 },
1209                        {  640,  480, 0x81 },
1210                        {  800,  600, 0x82 },
1211                        { 1024,  768, 0x83 },
1212                        { 1152,  870, 0x84 },
1213                        { 1280, 1024, 0x85 },
1214                        { 1600, 1200, 0x86 },
1215                        { 0, }
1216                };
1217                video_modes[0].w = default_width;
1218                video_modes[0].h = default_height;
1219
1205                  for (int i = 0; video_modes[i].w != 0; i++) {
1206                          const int w = video_modes[i].w;
1207                          const int h = video_modes[i].h;
1208                          if (i > 0 && (w >= default_width || h >= default_height))
1209                                  continue;
1210 +                        if (w == 512 && h == 384)
1211 +                                continue;
1212   #ifdef ENABLE_VOSF
1213 <                        for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) {
1214 <                                int bpp = sdl_depth_of_video_depth(d);
1228 <                                if (SDL_VideoModeOK(w, h, bpp, SDL_HWSURFACE | SDL_FULLSCREEN))
1229 <                                        add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)d), d);
1230 <                        }
1213 >                        for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++)
1214 >                                add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)d), d);
1215   #else
1216                          add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)default_depth), default_depth);
1217   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines