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.22 by gbeauche, 2005-11-29T23:20:31Z vs.
Revision 1.36 by asvitkine, 2008-06-25T02:52:52Z

# Line 1 | Line 1
1   /*
2   *  video_sdl.cpp - Video/graphics emulation, SDL specific stuff
3   *
4 < *  Basilisk II (C) 1997-2005 Christian Bauer
4 > *  Basilisk II (C) 1997-2008 Christian Bauer
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 27 | Line 27
27   *      Ctrl-F5 = grab mouse (in windowed mode)
28   *
29   *  FIXMEs and TODOs:
30 + *  - Windows requires an extra mouse event to update the actual cursor image?
31   *  - Ctr-Tab for suspend/resume but how? SDL does not support that for non-Linux
32   *  - Ctrl-Fn doesn't generate SDL_KEYDOWN events (SDL bug?)
33   *  - Mouse acceleration, there is no API in SDL yet for that
34   *  - Force relative mode in Grab mode even if SDL provides absolute coordinates?
34 *  - Fullscreen mode
35   *  - Gamma tables support is likely to be broken here
36   *  - Events processing is bound to the general emulation thread as SDL requires
37   *    to PumpEvents() within the same thread as the one that called SetVideoMode().
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()?
39   *  - Backport hw cursor acceleration to Basilisk II?
40   *  - Factor out code
41   */
# Line 49 | Line 48
48   #include <errno.h>
49   #include <vector>
50  
51 + #ifdef WIN32
52 + #include <malloc.h> /* alloca() */
53 + #endif
54 +
55   #include "cpu_emulation.h"
56   #include "main.h"
57   #include "adb.h"
# Line 133 | Line 136 | static SDL_Cursor *sdl_cursor;                                         // C
136   static volatile bool cursor_changed = false;            // Flag: cursor changed, redraw_func must update the cursor
137   static SDL_Color sdl_palette[256];                                      // Color palette to be used as CLUT and gamma table
138   static bool sdl_palette_changed = false;                        // Flag: Palette changed, redraw thread must set new colors
139 < static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK;
139 > static const int sdl_eventmask = SDL_MOUSEEVENTMASK | SDL_KEYEVENTMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK | SDL_ACTIVEEVENTMASK;
140  
141   // Mutex to protect SDL events
142   static SDL_mutex *sdl_events_lock = NULL;
# Line 194 | Line 197 | extern void SysMountFirstFloppy(void);
197  
198   static void *vm_acquire_framebuffer(uint32 size)
199   {
200 <        return vm_acquire(size);
200 >        // always try to reallocate framebuffer at the same address
201 >        static void *fb = VM_MAP_FAILED;
202 >        if (fb != VM_MAP_FAILED) {
203 >                if (vm_acquire_fixed(fb, size) < 0) {
204 > #ifndef SHEEPSHAVER
205 >                        printf("FATAL: Could not reallocate framebuffer at previous address\n");
206 > #endif
207 >                        fb = VM_MAP_FAILED;
208 >                }
209 >        }
210 >        if (fb == VM_MAP_FAILED)
211 >                fb = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT);
212 >        return fb;
213   }
214  
215   static inline void vm_release_framebuffer(void *fb, uint32 size)
# Line 204 | Line 219 | static inline void vm_release_framebuffe
219  
220  
221   /*
222 + *  Windows message handler
223 + */
224 +
225 + #ifdef WIN32
226 + #include <dbt.h>
227 + static WNDPROC sdl_window_proc = NULL;                          // Window proc used by SDL
228 +
229 + extern void SysMediaArrived(void);
230 + extern void SysMediaRemoved(void);
231 + extern HWND GetMainWindowHandle(void);
232 +
233 + static LRESULT CALLBACK windows_message_handler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
234 + {
235 +        switch (msg) {
236 +        case WM_DEVICECHANGE:
237 +                if (wParam == DBT_DEVICEREMOVECOMPLETE) {
238 +                        DEV_BROADCAST_HDR *p = (DEV_BROADCAST_HDR *)lParam;
239 +                        if (p->dbch_devicetype == DBT_DEVTYP_VOLUME)
240 +                                SysMediaRemoved();
241 +                }
242 +                else if (wParam == DBT_DEVICEARRIVAL) {
243 +                        DEV_BROADCAST_HDR *p = (DEV_BROADCAST_HDR *)lParam;
244 +                        if (p->dbch_devicetype == DBT_DEVTYP_VOLUME)
245 +                                SysMediaArrived();
246 +                }
247 +                return 0;
248 +
249 +        default:
250 +                if (sdl_window_proc)
251 +                        return CallWindowProc(sdl_window_proc, hwnd, msg, wParam, lParam);
252 +        }
253 +
254 +        return DefWindowProc(hwnd, msg, wParam, lParam);
255 + }
256 + #endif
257 +
258 +
259 + /*
260   *  SheepShaver glue
261   */
262  
# Line 248 | Line 301 | static vector<monitor_desc *> VideoMonit
301   // Find Apple mode matching best specified dimensions
302   static int find_apple_resolution(int xsize, int ysize)
303   {
304 <        int apple_id;
305 <        if (xsize < 800)
306 <                apple_id = APPLE_640x480;
307 <        else if (xsize < 1024)
308 <                apple_id = APPLE_800x600;
309 <        else if (xsize < 1152)
310 <                apple_id = APPLE_1024x768;
311 <        else if (xsize < 1280) {
312 <                if (ysize < 900)
313 <                        apple_id = APPLE_1152x768;
314 <                else
315 <                        apple_id = APPLE_1152x900;
316 <        }
317 <        else if (xsize < 1600)
318 <                apple_id = APPLE_1280x1024;
266 <        else
267 <                apple_id = APPLE_1600x1200;
268 <        return apple_id;
269 < }
270 <
271 < // Set parameters to specified Apple mode
272 < static void set_apple_resolution(int apple_id, int &xsize, int &ysize)
273 < {
274 <        switch (apple_id) {
275 <        case APPLE_640x480:
276 <                xsize = 640;
277 <                ysize = 480;
278 <                break;
279 <        case APPLE_800x600:
280 <                xsize = 800;
281 <                ysize = 600;
282 <                break;
283 <        case APPLE_1024x768:
284 <                xsize = 1024;
285 <                ysize = 768;
286 <                break;
287 <        case APPLE_1152x768:
288 <                xsize = 1152;
289 <                ysize = 768;
290 <                break;
291 <        case APPLE_1152x900:
292 <                xsize = 1152;
293 <                ysize = 900;
294 <                break;
295 <        case APPLE_1280x1024:
296 <                xsize = 1280;
297 <                ysize = 1024;
298 <                break;
299 <        case APPLE_1600x1200:
300 <                xsize = 1600;
301 <                ysize = 1200;
302 <                break;
303 <        default:
304 <                abort();
305 <        }
306 < }
307 <
308 < // Match Apple mode matching best specified dimensions
309 < static int match_apple_resolution(int &xsize, int &ysize)
310 < {
311 <        int apple_id = find_apple_resolution(xsize, ysize);
312 <        set_apple_resolution(apple_id, xsize, ysize);
313 <        return apple_id;
304 >        if (xsize == 640 && ysize == 480)
305 >                return APPLE_640x480;
306 >        if (xsize == 800 && ysize == 600)
307 >                return APPLE_800x600;
308 >        if (xsize == 1024 && ysize == 768)
309 >                return APPLE_1024x768;
310 >        if (xsize == 1152 && ysize == 768)
311 >                return APPLE_1152x768;
312 >        if (xsize == 1152 && ysize == 900)
313 >                return APPLE_1152x900;
314 >        if (xsize == 1280 && ysize == 1024)
315 >                return APPLE_1280x1024;
316 >        if (xsize == 1600 && ysize == 1200)
317 >                return APPLE_1600x1200;
318 >        return APPLE_CUSTOM;
319   }
320  
321   // Display error alert
# Line 417 | Line 422 | static int sdl_depth_of_video_depth(int
422          return (video_depth <= VIDEO_DEPTH_8BIT) ? 8 : mac_depth_of_video_depth(video_depth);
423   }
424  
425 + // Get screen dimensions
426 + static void sdl_display_dimensions(int &width, int &height)
427 + {
428 +        static int max_width, max_height;
429 +        if (max_width == 0 && max_height == 0) {
430 +                max_width = 640 ; max_height = 480;
431 +                SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
432 +                if (modes && modes != (SDL_Rect **)-1) {
433 +                        // It turns out that on some implementations, and contrary to the documentation,
434 +                        // the returned list is not sorted from largest to smallest (e.g. Windows)
435 +                        for (int i = 0; modes[i] != NULL; i++) {
436 +                                const int w = modes[i]->w;
437 +                                const int h = modes[i]->h;
438 +                                if (w > max_width && h > max_height) {
439 +                                        max_width = w;
440 +                                        max_height = h;
441 +                                }
442 +                        }
443 +                }
444 +        }
445 +        width = max_width;
446 +        height = max_height;
447 + }
448 +
449 + static inline int sdl_display_width(void)
450 + {
451 +        int width, height;
452 +        sdl_display_dimensions(width, height);
453 +        return width;
454 + }
455 +
456 + static inline int sdl_display_height(void)
457 + {
458 +        int width, height;
459 +        sdl_display_dimensions(width, height);
460 +        return height;
461 + }
462 +
463   // Check wether specified mode is available
464 < static bool has_mode(int type, int width, int height)
464 > static bool has_mode(int type, int width, int height, int depth)
465   {
466   #ifdef SHEEPSHAVER
467 <        // Filter out Classic resolutiosn
467 >        // Filter out Classic resolutions
468          if (width == 512 && height == 384)
469                  return false;
470 + #endif
471  
472 <        // "screen" prefs items always succeeds
473 <        if (PrefsFindString("screen"))
474 <                return true;
431 <
432 <        // Read window & screen modes prefs
433 <        static uint32 window_modes = 0;
434 <        static uint32 screen_modes = 0;
435 <        if (window_modes == 0 || screen_modes == 0) {
436 <                window_modes = PrefsFindInt32("windowmodes");
437 <                screen_modes = PrefsFindInt32("screenmodes");
438 <                if (window_modes == 0 || screen_modes == 0)
439 <                        window_modes |= 3;                      // Allow at least 640x480 and 800x600 window modes
440 <        }
441 <
442 <        int test_modes;
443 <        switch (type) {
444 <        case DISPLAY_WINDOW:
445 <                test_modes = window_modes;
446 <                break;
447 <        case DISPLAY_SCREEN:
448 <                test_modes = screen_modes;
449 <                break;
450 <        default:
451 <                test_modes = 0;
452 <                break;
453 <        }
472 >        // Filter out out-of-bounds resolutions
473 >        if (width > sdl_display_width() || height > sdl_display_height())
474 >                return false;
475  
476 <        int apple_mask;
477 <        switch (find_apple_resolution(width, height)) {
478 <        case APPLE_640x480:             apple_mask = 0x01; break;
479 <        case APPLE_800x600:             apple_mask = 0x02; break;
459 <        case APPLE_1024x768:    apple_mask = 0x04; break;
460 <        case APPLE_1152x768:    apple_mask = 0x40; break;
461 <        case APPLE_1152x900:    apple_mask = 0x08; break;
462 <        case APPLE_1280x1024:   apple_mask = 0x10; break;
463 <        case APPLE_1600x1200:   apple_mask = 0x20; break;
464 <        default:                                apple_mask = 0x00; break;
465 <        }
466 <        return (test_modes & apple_mask);
467 < #endif
468 <        return true;
476 >        // Rely on SDL capabilities
477 >        return SDL_VideoModeOK(width, height,
478 >                                                   sdl_depth_of_video_depth(depth),
479 >                                                   SDL_HWSURFACE | (type == DISPLAY_SCREEN ? SDL_FULLSCREEN : 0));
480   }
481  
482   // Add mode to list of supported modes
483   static void add_mode(int type, int width, int height, int resolution_id, int bytes_per_row, int depth)
484   {
485          // Filter out unsupported modes
486 <        if (!has_mode(type, width, height))
486 >        if (!has_mode(type, width, height, depth))
487                  return;
488  
489          // Fill in VideoMode entry
490          VIDEO_MODE mode;
491   #ifdef SHEEPSHAVER
492 <        // Recalculate dimensions to fit Apple modes
482 <        resolution_id = match_apple_resolution(width, height);
492 >        resolution_id = find_apple_resolution(width, height);
493          mode.viType = type;
494   #endif
495          VIDEO_MODE_X = width;
# Line 490 | Line 500 | static void add_mode(int type, int width
500          VideoModes.push_back(mode);
501   }
502  
493 // Add standard list of windowed modes for given color depth
494 static void add_window_modes(int depth)
495 {
496        video_depth vdepth = (video_depth)depth;
497        add_mode(DISPLAY_WINDOW, 512, 384, 0x80, TrivialBytesPerRow(512, vdepth), depth);
498        add_mode(DISPLAY_WINDOW, 640, 480, 0x81, TrivialBytesPerRow(640, vdepth), depth);
499        add_mode(DISPLAY_WINDOW, 800, 600, 0x82, TrivialBytesPerRow(800, vdepth), depth);
500        add_mode(DISPLAY_WINDOW, 1024, 768, 0x83, TrivialBytesPerRow(1024, vdepth), depth);
501        add_mode(DISPLAY_WINDOW, 1152, 870, 0x84, TrivialBytesPerRow(1152, vdepth), depth);
502        add_mode(DISPLAY_WINDOW, 1280, 1024, 0x85, TrivialBytesPerRow(1280, vdepth), depth);
503        add_mode(DISPLAY_WINDOW, 1600, 1200, 0x86, TrivialBytesPerRow(1600, vdepth), depth);
504 }
505
503   // Set Mac frame layout and base address (uses the_buffer/MacFrameBaseMac)
504   static void set_mac_frame_buffer(SDL_monitor_desc &monitor, int depth, bool native_byte_order)
505   {
# Line 546 | Line 543 | static SDL_GrabMode set_grab_mode(SDL_Gr
543          return (vi && vi->wm_available ? SDL_WM_GrabInput(mode) : SDL_GRAB_OFF);
544   }
545  
546 + // Migrate preferences items (XXX to be handled in MigratePrefs())
547 + static void migrate_screen_prefs(void)
548 + {
549 + #ifdef SHEEPSHAVER
550 +        // Look-up priorities are: "screen", "screenmodes", "windowmodes".
551 +        if (PrefsFindString("screen"))
552 +                return;
553 +
554 +        uint32 window_modes = PrefsFindInt32("windowmodes");
555 +        uint32 screen_modes = PrefsFindInt32("screenmodes");
556 +        int width = 0, height = 0;
557 +        if (screen_modes) {
558 +                static const struct {
559 +                        int id;
560 +                        int width;
561 +                        int height;
562 +                }
563 +                modes[] = {
564 +                        {  1,    640,    480 },
565 +                        {  2,    800,    600 },
566 +                        {  4,   1024,    768 },
567 +                        { 64,   1152,    768 },
568 +                        {  8,   1152,    900 },
569 +                        { 16,   1280,   1024 },
570 +                        { 32,   1600,   1200 },
571 +                        { 0, }
572 +                };
573 +                for (int i = 0; modes[i].id != 0; i++) {
574 +                        if (screen_modes & modes[i].id) {
575 +                                if (width < modes[i].width && height < modes[i].height) {
576 +                                        width = modes[i].width;
577 +                                        height = modes[i].height;
578 +                                }
579 +                        }
580 +                }
581 +        } else {
582 +                if (window_modes & 1)
583 +                        width = 640, height = 480;
584 +                if (window_modes & 2)
585 +                        width = 800, height = 600;
586 +        }
587 +        if (width && height) {
588 +                char str[32];
589 +                sprintf(str, "%s/%d/%d", screen_modes ? "dga" : "win", width, height);
590 +                PrefsReplaceString("screen", str);
591 +        }
592 + #endif
593 + }
594 +
595  
596   /*
597   *  Display "driver" classes
# Line 685 | Line 731 | void driver_base::restore_mouse_accel(vo
731   *  Windowed display driver
732   */
733  
734 + static bool SDL_display_opened = false;
735 +
736   // Open display
737   driver_window::driver_window(SDL_monitor_desc &m)
738          : driver_base(m), mouse_grabbed(false)
# Line 696 | Line 744 | driver_window::driver_window(SDL_monitor
744          // Set absolute mouse mode
745          ADBSetRelMouseMode(mouse_grabbed);
746  
747 +        // This is ugly:
748 +        // If we're switching resolutions (ie, not setting it for the first time),
749 +        // there's a bug in SDL where the SDL_Surface created will not be properly
750 +        // setup. The solution is to SDL_QuitSubSystem(SDL_INIT_VIDEO) before calling
751 +        // SDL_SetVideoMode for the second time (SDL_SetVideoMode will call SDL_Init()
752 +        // and all will be well). Without this, the video becomes corrupted (at least
753 +        // on Mac OS X), after the resolution switch.
754 +        if (SDL_display_opened)
755 +                SDL_QuitSubSystem(SDL_INIT_VIDEO);
756 +
757          // Create surface
758          int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH);
759          if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL)
760                  return;
761  
762 +        SDL_display_opened = true;
763 +
764   #ifdef ENABLE_VOSF
765          use_vosf = true;
766          // Allocate memory for frame buffer (SIZE is extended to page-boundary)
# Line 1025 | Line 1085 | bool SDL_monitor_desc::video_open(void)
1085                  return false;
1086          }
1087  
1088 + #ifdef WIN32
1089 +        // Chain in a new message handler for WM_DEVICECHANGE
1090 +        HWND the_window = GetMainWindowHandle();
1091 +        sdl_window_proc = (WNDPROC)GetWindowLongPtr(the_window, GWLP_WNDPROC);
1092 +        SetWindowLongPtr(the_window, GWLP_WNDPROC, (LONG_PTR)windows_message_handler);
1093 + #endif
1094 +
1095          // Initialize VideoRefresh function
1096          VideoRefreshInit();
1097  
# Line 1078 | Line 1145 | bool VideoInit(bool classic)
1145          mouse_wheel_lines = PrefsFindInt32("mousewheellines");
1146  
1147          // Get screen mode from preferences
1148 +        migrate_screen_prefs();
1149          const char *mode_str = NULL;
1150          if (classic_mode)
1151                  mode_str = "win/512/342";
# Line 1101 | Line 1169 | bool VideoInit(bool classic)
1169                  else if (sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2)
1170                          display_type = DISPLAY_SCREEN;
1171          }
1104        int max_width = 640, max_height = 480;
1105        SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
1106        if (modes && modes != (SDL_Rect **)-1) {
1107                // It turns out that on some implementations, and contrary to the documentation,
1108                // the returned list is not sorted from largest to smallest (e.g. Windows)
1109                for (int i = 0; modes[i] != NULL; i++) {
1110                        const int w = modes[i]->w;
1111                        const int h = modes[i]->h;
1112                        if (w > max_width && h > max_height) {
1113                                max_width = w;
1114                                max_height = h;
1115                        }
1116                }
1117                if (default_width > max_width)
1118                        default_width = max_width;
1119                if (default_height > max_height)
1120                        default_height = max_height;
1121        }
1172          if (default_width <= 0)
1173 <                default_width = max_width;
1173 >                default_width = sdl_display_width();
1174 >        else if (default_width > sdl_display_width())
1175 >                default_width = sdl_display_width();
1176          if (default_height <= 0)
1177 <                default_height = max_height;
1177 >                default_height = sdl_display_height();
1178 >        else if (default_height > sdl_display_height())
1179 >                default_height = sdl_display_height();
1180  
1181          // Mac screen depth follows X depth
1182          screen_depth = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
# Line 1142 | Line 1196 | bool VideoInit(bool classic)
1196                  break;
1197          }
1198  
1199 +        // Initialize list of video modes to try
1200 +        struct {
1201 +                int w;
1202 +                int h;
1203 +                int resolution_id;
1204 +        }
1205 +        video_modes[] = {
1206 +                {   -1,   -1, 0x80 },
1207 +                {  512,  384, 0x80 },
1208 +                {  640,  480, 0x81 },
1209 +                {  800,  600, 0x82 },
1210 +                { 1024,  768, 0x83 },
1211 +                { 1152,  870, 0x84 },
1212 +                { 1280, 1024, 0x85 },
1213 +                { 1600, 1200, 0x86 },
1214 +                { 0, }
1215 +        };
1216 +        video_modes[0].w = default_width;
1217 +        video_modes[0].h = default_height;
1218 +
1219          // Construct list of supported modes
1220          if (display_type == DISPLAY_WINDOW) {
1221                  if (classic)
1222                          add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT);
1223                  else {
1224 <                        for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) {
1225 <                                int bpp = sdl_depth_of_video_depth(d);
1226 <                                if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE))
1227 <                                        add_window_modes(video_depth(d));
1224 >                        for (int i = 0; video_modes[i].w != 0; i++) {
1225 >                                const int w = video_modes[i].w;
1226 >                                const int h = video_modes[i].h;
1227 >                                if (i > 0 && (w >= default_width || h >= default_height))
1228 >                                        continue;
1229 >                                for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++)
1230 >                                        add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)d), d);
1231                          }
1232                  }
1233          } else if (display_type == DISPLAY_SCREEN) {
1157                struct {
1158                        int w;
1159                        int h;
1160                        int resolution_id;
1161                }
1162                video_modes[] = {
1163                        {   -1,   -1, 0x80 },
1164                        {  640,  480, 0x81 },
1165                        {  800,  600, 0x82 },
1166                        { 1024,  768, 0x83 },
1167                        { 1152,  870, 0x84 },
1168                        { 1280, 1024, 0x85 },
1169                        { 1600, 1200, 0x86 },
1170                        { 0, }
1171                };
1172                video_modes[0].w = default_width;
1173                video_modes[0].h = default_height;
1174
1234                  for (int i = 0; video_modes[i].w != 0; i++) {
1235                          const int w = video_modes[i].w;
1236                          const int h = video_modes[i].h;
1237                          if (i > 0 && (w >= default_width || h >= default_height))
1238                                  continue;
1239 +                        if (w == 512 && h == 384)
1240 +                                continue;
1241   #ifdef ENABLE_VOSF
1242 <                        for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) {
1243 <                                int bpp = sdl_depth_of_video_depth(d);
1183 <                                if (SDL_VideoModeOK(w, h, bpp, SDL_HWSURFACE | SDL_FULLSCREEN))
1184 <                                        add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)d), d);
1185 <                        }
1242 >                        for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++)
1243 >                                add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)d), d);
1244   #else
1245                          add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)default_depth), default_depth);
1246   #endif
# Line 1259 | Line 1317 | void SDL_monitor_desc::video_close(void)
1317   {
1318          D(bug("video_close()\n"));
1319  
1320 + #ifdef WIN32
1321 +        // Remove message handler for WM_DEVICECHANGE
1322 +        HWND the_window = GetMainWindowHandle();
1323 +        SetWindowLongPtr(the_window, GWLP_WNDPROC, (LONG_PTR)sdl_window_proc);
1324 + #endif
1325 +
1326          // Stop redraw thread
1327   #ifndef USE_CPU_EMUL_SERVICES
1328          if (redraw_thread_active) {
# Line 1479 | Line 1543 | void SDL_monitor_desc::switch_to_current
1543   #ifdef SHEEPSHAVER
1544   bool video_can_change_cursor(void)
1545   {
1546 <        return (display_type == DISPLAY_WINDOW);
1546 >        static char driver[] = "Quartz?";
1547 >        static int quartzok = -1;
1548 >
1549 >        if (display_type != DISPLAY_WINDOW)
1550 >                return false;
1551 >
1552 >        if (quartzok < 0) {
1553 >                if (SDL_VideoDriverName(driver, sizeof driver) == NULL || strncmp(driver, "Quartz", sizeof driver))
1554 >                        quartzok = true;
1555 >                else {
1556 >                        // Quartz driver bug prevents cursor changing in SDL 1.2.11 and later
1557 >                        const SDL_version *vp = SDL_Linked_Version();
1558 >                        quartzok = SDL_VERSIONNUM(vp->major, vp->minor, vp->patch) <= SDL_VERSIONNUM(1, 2, 10);
1559 >                }
1560 >        }
1561 >
1562 >        return quartzok;
1563   }
1564   #endif
1565  
# Line 1794 | Line 1874 | static void handle_events(void)
1874                                  ADBKeyDown(0x7f);       // Power key
1875                                  ADBKeyUp(0x7f);
1876                                  break;
1877 +
1878 +                        // Application activate/deactivate; consume the event but otherwise ignore it
1879 +                        case SDL_ACTIVEEVENT:
1880 +                                break;
1881                          }
1882                  }
1883          }
# Line 1949 | Line 2033 | static void update_display_static(driver
2033          }
2034   }
2035  
2036 + // Static display update (fixed frame rate, bounding boxes based)
2037 + // XXX use NQD bounding boxes to help detect dirty areas?
2038 + static void update_display_static_bbox(driver_window *drv)
2039 + {
2040 +        const VIDEO_MODE &mode = drv->mode;
2041 +
2042 +        // Allocate bounding boxes for SDL_UpdateRects()
2043 +        const int N_PIXELS = 64;
2044 +        const int n_x_boxes = (VIDEO_MODE_X + N_PIXELS - 1) / N_PIXELS;
2045 +        const int n_y_boxes = (VIDEO_MODE_Y + N_PIXELS - 1) / N_PIXELS;
2046 +        SDL_Rect *boxes = (SDL_Rect *)alloca(sizeof(SDL_Rect) * n_x_boxes * n_y_boxes);
2047 +        int nr_boxes = 0;
2048 +
2049 +        // Lock surface, if required
2050 +        if (SDL_MUSTLOCK(drv->s))
2051 +                SDL_LockSurface(drv->s);
2052 +
2053 +        // Update the surface from Mac screen
2054 +        const int bytes_per_row = VIDEO_MODE_ROW_BYTES;
2055 +        const int bytes_per_pixel = bytes_per_row / VIDEO_MODE_X;
2056 +        int x, y;
2057 +        for (y = 0; y < VIDEO_MODE_Y; y += N_PIXELS) {
2058 +                int h = N_PIXELS;
2059 +                if (h > VIDEO_MODE_Y - y)
2060 +                        h = VIDEO_MODE_Y - y;
2061 +                for (x = 0; x < VIDEO_MODE_X; x += N_PIXELS) {
2062 +                        int w = N_PIXELS;
2063 +                        if (w > VIDEO_MODE_X - x)
2064 +                                w = VIDEO_MODE_X - x;
2065 +                        const int xs = w * bytes_per_pixel;
2066 +                        const int xb = x * bytes_per_pixel;
2067 +                        bool dirty = false;
2068 +                        for (int j = y; j < (y + h); j++) {
2069 +                                const int yb = j * bytes_per_row;
2070 +                                if (memcmp(&the_buffer[yb + xb], &the_buffer_copy[yb + xb], xs) != 0) {
2071 +                                        memcpy(&the_buffer_copy[yb + xb], &the_buffer[yb + xb], xs);
2072 +                                        Screen_blit((uint8 *)drv->s->pixels + yb + xb, the_buffer + yb + xb, xs);
2073 +                                        dirty = true;
2074 +                                }
2075 +                        }
2076 +                        if (dirty) {
2077 +                                boxes[nr_boxes].x = x;
2078 +                                boxes[nr_boxes].y = y;
2079 +                                boxes[nr_boxes].w = w;
2080 +                                boxes[nr_boxes].h = h;
2081 +                                nr_boxes++;
2082 +                        }
2083 +                }
2084 +        }
2085 +
2086 +        // Unlock surface, if required
2087 +        if (SDL_MUSTLOCK(drv->s))
2088 +                SDL_UnlockSurface(drv->s);
2089 +
2090 +        // Refresh display
2091 +        if (nr_boxes)
2092 +                SDL_UpdateRects(drv->s, nr_boxes, boxes);
2093 + }
2094 +
2095  
2096   // We suggest the compiler to inline the next two functions so that it
2097   // may specialise the code according to the current screen depth and
# Line 2043 | Line 2186 | static void video_refresh_window_static(
2186          static int tick_counter = 0;
2187          if (++tick_counter >= frame_skip) {
2188                  tick_counter = 0;
2189 <                update_display_static(static_cast<driver_window *>(drv));
2189 >                const VIDEO_MODE &mode = drv->mode;
2190 >                if ((int)VIDEO_MODE_DEPTH >= VIDEO_DEPTH_8BIT)
2191 >                        update_display_static_bbox(static_cast<driver_window *>(drv));
2192 >                else
2193 >                        update_display_static(static_cast<driver_window *>(drv));
2194          }
2195   }
2196  
# Line 2088 | Line 2235 | static inline void do_video_refresh(void
2235                  LOCK_EVENTS;
2236                  SDL_FreeCursor(sdl_cursor);
2237                  sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]);
2238 <                if (sdl_cursor)
2238 >                if (sdl_cursor) {
2239 >                        SDL_ShowCursor(private_data == NULL || private_data->cursorVisible);
2240                          SDL_SetCursor(sdl_cursor);
2241 + #ifdef WIN32
2242 +                        // XXX Windows apparently needs an extra mouse event to
2243 +                        // make the new cursor image visible
2244 +                        int visible = SDL_ShowCursor(-1);
2245 +                        if (visible) {
2246 +                                int x, y;
2247 +                                SDL_GetMouseState(&x, &y);
2248 +                                SDL_WarpMouse(x, y);
2249 +                        }
2250 + #endif
2251 +                }
2252                  UNLOCK_EVENTS;
2253          }
2254   #endif
# Line 2148 | Line 2307 | static int redraw_func(void *arg)
2307          return 0;
2308   }
2309   #endif
2310 +
2311 +
2312 + /*
2313 + *  Record dirty area from NQD
2314 + */
2315 +
2316 + #ifdef SHEEPSHAVER
2317 + void video_set_dirty_area(int x, int y, int w, int h)
2318 + {
2319 +        const VIDEO_MODE &mode = drv->mode;
2320 +        const int screen_width = VIDEO_MODE_X;
2321 +        const int screen_height = VIDEO_MODE_Y;
2322 +        const int bytes_per_row = VIDEO_MODE_ROW_BYTES;
2323 +
2324 + #ifdef ENABLE_VOSF
2325 +        if (use_vosf) {
2326 +                vosf_set_dirty_area(x, y, w, h, screen_width, screen_height, bytes_per_row);
2327 +                return;
2328 +        }
2329 + #endif
2330 +
2331 +        // XXX handle dirty bounding boxes for non-VOSF modes
2332 + }
2333 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines