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.18 by gbeauche, 2005-03-20T23:43:17Z vs.
Revision 1.19 by gbeauche, 2005-06-06T21:20:28Z

# Line 21 | Line 21
21   /*
22   *  NOTES:
23   *    The Ctrl key works like a qualifier for special actions:
24 < *      Ctrl-Tab = suspend DGA mode
24 > *      Ctrl-Tab = suspend DGA mode (TODO)
25   *      Ctrl-Esc = emergency quit
26   *      Ctrl-F1 = mount floppy
27   *      Ctrl-F5 = grab mouse (in windowed mode)
28   *
29   *  FIXMEs and TODOs:
30 + *  - Ctr-Tab for suspend/resume but how? SDL does not support that for non-Linux
31   *  - Ctrl-Fn doesn't generate SDL_KEYDOWN events (SDL bug?)
32   *  - Mouse acceleration, there is no API in SDL yet for that
33   *  - Force relative mode in Grab mode even if SDL provides absolute coordinates?
# Line 37 | Line 38
38   *    Besides, there can't seem to be a way to call SetVideoMode() from a child thread.
39   *  - Refresh performance is still slow. Use SDL_CreateRGBSurface()?
40   *  - Backport hw cursor acceleration to Basilisk II?
41 + *  - Factor out code
42   */
43  
44   #include "sysdeps.h"
# Line 392 | Line 394 | static int sdl_depth_of_video_depth(int
394   // Check wether specified mode is available
395   static bool has_mode(int type, int width, int height)
396   {
395        // FIXME: no fullscreen support yet
396        if (type == DISPLAY_SCREEN)
397                return false;
398
397   #ifdef SHEEPSHAVER
398          // Filter out Classic resolutiosn
399          if (width == 512 && height == 384)
400                  return false;
401  
402 <        // Read window modes prefs
402 >        // "screen" prefs items always succeeds
403 >        if (PrefsFindString("screen"))
404 >                return true;
405 >
406 >        // Read window & screen modes prefs
407          static uint32 window_modes = 0;
408          static uint32 screen_modes = 0;
409          if (window_modes == 0 || screen_modes == 0) {
# Line 411 | Line 413 | static bool has_mode(int type, int width
413                          window_modes |= 3;                      // Allow at least 640x480 and 800x600 window modes
414          }
415  
416 <        if (type == DISPLAY_WINDOW) {
417 <                int apple_mask, apple_id = find_apple_resolution(width, height);
418 <                switch (apple_id) {
419 <                case APPLE_640x480:             apple_mask = 0x01; break;
420 <                case APPLE_800x600:             apple_mask = 0x02; break;
421 <                case APPLE_1024x768:    apple_mask = 0x04; break;
422 <                case APPLE_1152x768:    apple_mask = 0x40; break;
423 <                case APPLE_1152x900:    apple_mask = 0x08; break;
424 <                case APPLE_1280x1024:   apple_mask = 0x10; break;
425 <                case APPLE_1600x1200:   apple_mask = 0x20; break;
426 <                default:                                apple_mask = 0x00; break;
425 <                }
426 <                return (window_modes & apple_mask);
416 >        int test_modes;
417 >        switch (type) {
418 >        case DISPLAY_WINDOW:
419 >                test_modes = window_modes;
420 >                break;
421 >        case DISPLAY_SCREEN:
422 >                test_modes = screen_modes;
423 >                break;
424 >        default:
425 >                test_modes = 0;
426 >                break;
427          }
428 < #else
429 <        return true;
428 >
429 >        int apple_mask;
430 >        switch (find_apple_resolution(width, height)) {
431 >        case APPLE_640x480:             apple_mask = 0x01; break;
432 >        case APPLE_800x600:             apple_mask = 0x02; break;
433 >        case APPLE_1024x768:    apple_mask = 0x04; break;
434 >        case APPLE_1152x768:    apple_mask = 0x40; break;
435 >        case APPLE_1152x900:    apple_mask = 0x08; break;
436 >        case APPLE_1280x1024:   apple_mask = 0x10; break;
437 >        case APPLE_1600x1200:   apple_mask = 0x20; break;
438 >        default:                                apple_mask = 0x00; break;
439 >        }
440 >        return (test_modes & apple_mask);
441   #endif
442 <        return false;
442 >        return true;
443   }
444  
445   // Add mode to list of supported modes
# Line 505 | Line 516 | static void set_window_name(int name)
516   // Set mouse grab mode
517   static SDL_GrabMode set_grab_mode(SDL_GrabMode mode)
518   {
519 <        const SDL_VideoInfo *vi =SDL_GetVideoInfo();
519 >        const SDL_VideoInfo *vi = SDL_GetVideoInfo();
520          return (vi && vi->wm_available ? SDL_WM_GrabInput(mode) : SDL_GRAB_OFF);
521   }
522  
# Line 564 | Line 575 | private:
575          int mouse_last_x, mouse_last_y; // Last mouse position (for relative mode)
576   };
577  
578 + class driver_fullscreen : public driver_base {
579 + public:
580 +        driver_fullscreen(SDL_monitor_desc &monitor);
581 +        ~driver_fullscreen();
582 + };
583 +
584   static driver_base *drv = NULL; // Pointer to currently used driver object
585  
586   #ifdef ENABLE_VOSF
# Line 779 | Line 796 | void driver_window::mouse_moved(int x, i
796          ADBMouseMoved(x, y);
797   }
798  
799 +
800 + /*
801 + *  Full-screen display driver
802 + */
803 +
804 + // Open display
805 + driver_fullscreen::driver_fullscreen(SDL_monitor_desc &m)
806 +        : driver_base(m)
807 + {
808 +        int width = VIDEO_MODE_X, height = VIDEO_MODE_Y;
809 +        int aligned_width = (width + 15) & ~15;
810 +        int aligned_height = (height + 15) & ~15;
811 +
812 +        // Set absolute mouse mode
813 +        ADBSetRelMouseMode(false);
814 +
815 +        // Create surface
816 +        int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH);
817 +        if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE | SDL_FULLSCREEN)) == NULL)
818 +                return;
819 +
820 + #ifdef ENABLE_VOSF
821 +        use_vosf = true;
822 +        // Allocate memory for frame buffer (SIZE is extended to page-boundary)
823 +        the_host_buffer = (uint8 *)s->pixels;
824 +        the_buffer_size = page_extend((aligned_height + 2) * s->pitch);
825 +        the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size);
826 +        the_buffer_copy = (uint8 *)malloc(the_buffer_size);
827 +        D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
828 +
829 +        // Check whether we can initialize the VOSF subsystem and it's profitable
830 +        if (!video_vosf_init(m)) {
831 +                WarningAlert(STR_VOSF_INIT_ERR);
832 +                use_vosf = false;
833 +        }
834 +        else if (!video_vosf_profitable()) {
835 +                video_vosf_exit();
836 +                printf("VOSF acceleration is not profitable on this platform, disabling it\n");
837 +                use_vosf = false;
838 +        }
839 +        if (!use_vosf) {
840 +                free(the_buffer_copy);
841 +                vm_release(the_buffer, the_buffer_size);
842 +                the_host_buffer = NULL;
843 +        }
844 + #endif
845 +        if (!use_vosf) {
846 +                // Allocate memory for frame buffer
847 +                the_buffer_size = (aligned_height + 2) * s->pitch;
848 +                the_buffer_copy = (uint8 *)calloc(1, the_buffer_size);
849 +                the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size);
850 +                D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
851 +        }
852 +        
853 +        // Hide cursor
854 +        SDL_ShowCursor(0);
855 +
856 +        // Init blitting routines
857 +        SDL_PixelFormat *f = s->format;
858 +        VisualFormat visualFormat;
859 +        visualFormat.depth = depth;
860 +        visualFormat.Rmask = f->Rmask;
861 +        visualFormat.Gmask = f->Gmask;
862 +        visualFormat.Bmask = f->Bmask;
863 +        Screen_blitter_init(visualFormat, true, mac_depth_of_video_depth(VIDEO_MODE_DEPTH));
864 +
865 +        // Load gray ramp to 8->16/32 expand map
866 +        if (!IsDirectMode(mode))
867 +                for (int i=0; i<256; i++)
868 +                        ExpandMap[i] = SDL_MapRGB(f, i, i, i);
869 +
870 +        // Set frame buffer base
871 +        set_mac_frame_buffer(monitor, VIDEO_MODE_DEPTH, true);
872 +
873 +        // Everything went well
874 +        init_ok = true;
875 + }
876 +
877 + // Close display
878 + driver_fullscreen::~driver_fullscreen()
879 + {
880 + #ifdef ENABLE_VOSF
881 +        if (use_vosf)
882 +                the_host_buffer = NULL; // don't free() in driver_base dtor
883 + #endif
884 +        if (s)
885 +                SDL_FreeSurface(s);
886 +
887 +        // Show cursor
888 +        SDL_ShowCursor(1);
889 + }
890 +
891 +
892   /*
893   *  Initialization
894   */
# Line 877 | Line 987 | bool SDL_monitor_desc::video_open(void)
987          case DISPLAY_WINDOW:
988                  drv = new(std::nothrow) driver_window(*this);
989                  break;
990 +        case DISPLAY_SCREEN:
991 +                drv = new(std::nothrow) driver_fullscreen(*this);
992 +                break;
993          }
994          if (drv == NULL)
995                  return false;
# Line 934 | Line 1047 | bool VideoInit(bool classic)
1047  
1048          // Get screen mode from preferences
1049          const char *mode_str = NULL;
937 #ifndef SHEEPSHAVER
1050          if (classic_mode)
1051                  mode_str = "win/512/342";
1052          else
1053                  mode_str = PrefsFindString("screen");
942 #endif
1054  
1055          // Determine display type and default dimensions
1056          int default_width, default_height;
# Line 955 | Line 1066 | bool VideoInit(bool classic)
1066          if (mode_str) {
1067                  if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2)
1068                          display_type = DISPLAY_WINDOW;
1069 +                else if (sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2)
1070 +                        display_type = DISPLAY_SCREEN;
1071          }
1072          int max_width = 640, max_height = 480;
1073          SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
# Line 1008 | Line 1121 | bool VideoInit(bool classic)
1121                                          add_window_modes(video_depth(d));
1122                          }
1123                  }
1124 <        } else
1125 <                add_mode(display_type, default_width, default_height, 0x80, TrivialBytesPerRow(default_width, (video_depth)default_depth), default_depth);
1124 >        } else if (display_type == DISPLAY_SCREEN) {
1125 >                struct {
1126 >                        int w;
1127 >                        int h;
1128 >                        int resolution_id;
1129 >                }
1130 >                video_modes[] = {
1131 >                        {   -1,   -1, 0x80 },
1132 >                        {  640,  480, 0x81 },
1133 >                        {  800,  600, 0x82 },
1134 >                        { 1024,  768, 0x83 },
1135 >                        { 1152,  870, 0x84 },
1136 >                        { 1280, 1024, 0x85 },
1137 >                        { 1600, 1200, 0x86 },
1138 >                        { 0, }
1139 >                };
1140 >                video_modes[0].w = default_width;
1141 >                video_modes[0].h = default_height;
1142 >
1143 >                for (int i = 0; video_modes[i].w != 0; i++) {
1144 >                        const int w = video_modes[i].w;
1145 >                        const int h = video_modes[i].h;
1146 >                        if (i > 0 && (w >= default_width || h >= default_height))
1147 >                                continue;
1148 > #ifdef ENABLE_VOSF
1149 >                        for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) {
1150 >                                int bpp = sdl_depth_of_video_depth(d);
1151 >                                if (SDL_VideoModeOK(w, h, bpp, SDL_HWSURFACE | SDL_FULLSCREEN))
1152 >                                        add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)d), d);
1153 >                        }
1154 > #else
1155 >                        add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)default_depth), default_depth);
1156 > #endif
1157 >                }
1158 >        }
1159 >
1160          if (VideoModes.empty()) {
1161                  ErrorAlert(STR_NO_XVISUAL_ERR);
1162                  return false;
# Line 1429 | Line 1576 | static int kc_decode(SDL_keysym const &
1576          case SDLK_LMETA: return 0x3a;
1577          case SDLK_RMETA: return 0x3a;
1578   #endif
1579 +        case SDLK_LSUPER: return 0x3a; // "Windows" key
1580 +        case SDLK_RSUPER: return 0x3a;
1581          case SDLK_MENU: return 0x32;
1582          case SDLK_CAPSLOCK: return 0x39;
1583          case SDLK_NUMLOCK: return 0x47;
# Line 1822 | Line 1971 | static void video_refresh_dga_vosf(void)
1971                  tick_counter = 0;
1972                  if (mainBuffer.dirty) {
1973                          LOCK_VOSF;
1974 <                        update_display_dga_vosf();
1974 >                        update_display_dga_vosf(static_cast<driver_fullscreen *>(drv));
1975                          UNLOCK_VOSF;
1976                  }
1977          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines