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.31 by asvitkine, 2007-01-22T00:32:25Z vs.
Revision 1.42 by asvitkine, 2011-12-28T22:15:10Z

# 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 66 | Line 66
66   #define DEBUG 0
67   #include "debug.h"
68  
69 + #if (defined(__APPLE__) && defined(__MACH__))
70 + extern "C" {
71 +        void NSAutoReleasePool_wrap(void (*fn)(void));
72 + }
73 + #endif
74  
75   // Supported video modes
76   using std::vector;
# Line 136 | Line 141 | static SDL_Cursor *sdl_cursor;                                         // C
141   static volatile bool cursor_changed = false;            // Flag: cursor changed, redraw_func must update the cursor
142   static SDL_Color sdl_palette[256];                                      // Color palette to be used as CLUT and gamma table
143   static bool sdl_palette_changed = false;                        // Flag: Palette changed, redraw thread must set new colors
144 < static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK;
144 > static const int sdl_eventmask = SDL_MOUSEEVENTMASK | SDL_KEYEVENTMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK | SDL_ACTIVEEVENTMASK;
145  
146   // Mutex to protect SDL events
147   static SDL_mutex *sdl_events_lock = NULL;
# Line 197 | Line 202 | extern void SysMountFirstFloppy(void);
202  
203   static void *vm_acquire_framebuffer(uint32 size)
204   {
205 <        return vm_acquire(size);
205 >        // always try to reallocate framebuffer at the same address
206 >        static void *fb = VM_MAP_FAILED;
207 >        if (fb != VM_MAP_FAILED) {
208 >                if (vm_acquire_fixed(fb, size) < 0) {
209 > #ifndef SHEEPSHAVER
210 >                        printf("FATAL: Could not reallocate framebuffer at previous address\n");
211 > #endif
212 >                        fb = VM_MAP_FAILED;
213 >                }
214 >        }
215 >        if (fb == VM_MAP_FAILED)
216 >                fb = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT);
217 >        return fb;
218   }
219  
220   static inline void vm_release_framebuffer(void *fb, uint32 size)
# Line 613 | Line 630 | public:
630   class driver_window;
631   static void update_display_window_vosf(driver_window *drv);
632   static void update_display_dynamic(int ticker, driver_window *drv);
633 < static void update_display_static(driver_window *drv);
633 > static void update_display_static(driver_base *drv);
634  
635   class driver_window : public driver_base {
636          friend void update_display_window_vosf(driver_window *drv);
637          friend void update_display_dynamic(int ticker, driver_window *drv);
638 <        friend void update_display_static(driver_window *drv);
638 >        friend void update_display_static(driver_base *drv);
639  
640   public:
641          driver_window(SDL_monitor_desc &monitor);
# Line 719 | Line 736 | void driver_base::restore_mouse_accel(vo
736   *  Windowed display driver
737   */
738  
739 < static int SDL_display_opened = FALSE;
739 > static bool SDL_display_opened = false;
740  
741   // Open display
742   driver_window::driver_window(SDL_monitor_desc &m)
# Line 735 | Line 752 | driver_window::driver_window(SDL_monitor
752          // This is ugly:
753          // If we're switching resolutions (ie, not setting it for the first time),
754          // there's a bug in SDL where the SDL_Surface created will not be properly
755 <        // setup. The solution is to SDL_Quit() before calling SDL_SetVideoMode for
756 <        // the second time (SDL_SetVideoMode will call SDL_Init() and all will be
757 <        // well). Without this, the video becomes corrupted (at least on Mac OS X),
758 <        // after the resolution switch (for the second and subsequent times).
759 < // EDIT: Ack, this breaks audio!
760 < //      if (SDL_display_opened)
744 < //              SDL_Quit();
755 >        // setup. The solution is to SDL_QuitSubSystem(SDL_INIT_VIDEO) before calling
756 >        // SDL_SetVideoMode for the second time (SDL_SetVideoMode will call SDL_Init()
757 >        // and all will be well). Without this, the video becomes corrupted (at least
758 >        // on Mac OS X), after the resolution switch.
759 >        if (SDL_display_opened)
760 >                SDL_QuitSubSystem(SDL_INIT_VIDEO);
761  
762          // Create surface
763          int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH);
764          if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL)
765                  return;
766  
767 <        SDL_display_opened = TRUE;
767 >        SDL_display_opened = true;
768  
769   #ifdef ENABLE_VOSF
770          use_vosf = true;
# Line 1227 | Line 1243 | bool VideoInit(bool classic)
1243                                  continue;
1244                          if (w == 512 && h == 384)
1245                                  continue;
1230 #ifdef ENABLE_VOSF
1246                          for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++)
1247                                  add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)d), d);
1233 #else
1234                        add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)default_depth), default_depth);
1235 #endif
1248                  }
1249          }
1250  
# Line 1532 | Line 1544 | void SDL_monitor_desc::switch_to_current
1544   #ifdef SHEEPSHAVER
1545   bool video_can_change_cursor(void)
1546   {
1547 <        return (display_type == DISPLAY_WINDOW);
1547 >        static char driver[] = "Quartz?";
1548 >        static int quartzok = -1;
1549 >
1550 >        if (display_type != DISPLAY_WINDOW)
1551 >                return false;
1552 >
1553 >        if (quartzok < 0) {
1554 >                if (SDL_VideoDriverName(driver, sizeof driver) == NULL || strncmp(driver, "Quartz", sizeof driver))
1555 >                        quartzok = true;
1556 >                else {
1557 >                        // Quartz driver bug prevents cursor changing in SDL 1.2.11 and later
1558 >                        const SDL_version *vp = SDL_Linked_Version();
1559 >                        quartzok = SDL_VERSIONNUM(vp->major, vp->minor, vp->patch) <= SDL_VERSIONNUM(1, 2, 10);
1560 >                }
1561 >        }
1562 >
1563 >        return quartzok;
1564   }
1565   #endif
1566  
# Line 1743 | Line 1771 | static void handle_events(void)
1771                          // Mouse button
1772                          case SDL_MOUSEBUTTONDOWN: {
1773                                  unsigned int button = event.button.button;
1774 <                                if (button < 4)
1775 <                                        ADBMouseDown(button - 1);
1774 >                                if (button == SDL_BUTTON_LEFT)
1775 >                                        ADBMouseDown(0);
1776 >                                else if (button == SDL_BUTTON_RIGHT)
1777 >                                        ADBMouseDown(1);
1778 >                                else if (button == SDL_BUTTON_MIDDLE)
1779 >                                        ADBMouseDown(2);
1780                                  else if (button < 6) {  // Wheel mouse
1781                                          if (mouse_wheel_mode == 0) {
1782                                                  int key = (button == 5) ? 0x79 : 0x74;  // Page up/down
# Line 1762 | Line 1794 | static void handle_events(void)
1794                          }
1795                          case SDL_MOUSEBUTTONUP: {
1796                                  unsigned int button = event.button.button;
1797 <                                if (button < 4)
1798 <                                        ADBMouseUp(button - 1);
1797 >                                if (button == SDL_BUTTON_LEFT)
1798 >                                        ADBMouseUp(0);
1799 >                                else if (button == SDL_BUTTON_RIGHT)
1800 >                                        ADBMouseUp(1);
1801 >                                else if (button == SDL_BUTTON_MIDDLE)
1802 >                                        ADBMouseUp(2);
1803                                  break;
1804                          }
1805  
# Line 1847 | Line 1883 | static void handle_events(void)
1883                                  ADBKeyDown(0x7f);       // Power key
1884                                  ADBKeyUp(0x7f);
1885                                  break;
1886 +
1887 +                        // Application activate/deactivate; consume the event but otherwise ignore it
1888 +                        case SDL_ACTIVEEVENT:
1889 +                                break;
1890                          }
1891                  }
1892          }
# Line 1858 | Line 1898 | static void handle_events(void)
1898   */
1899  
1900   // Static display update (fixed frame rate, but incremental)
1901 < static void update_display_static(driver_window *drv)
1901 > static void update_display_static(driver_base *drv)
1902   {
1903          // Incremental update code
1904          int wide = 0, high = 0, x1, x2, y1, y2, i, j;
# Line 1947 | Line 1987 | static void update_display_static(driver
1987  
1988                  } else {
1989                          const int bytes_per_pixel = VIDEO_MODE_ROW_BYTES / VIDEO_MODE_X;
1990 +                        const int dst_bytes_per_row = drv->s->pitch;
1991  
1992                          x1 = VIDEO_MODE_X;
1993                          for (j=y1; j<=y2; j++) {
# Line 1987 | Line 2028 | static void update_display_static(driver
2028                                  // Blit to screen surface
2029                                  for (j=y1; j<=y2; j++) {
2030                                          i = j * bytes_per_row + x1 * bytes_per_pixel;
2031 +                                        int dst_i = j * dst_bytes_per_row + x1 * bytes_per_pixel;
2032                                          memcpy(the_buffer_copy + i, the_buffer + i, bytes_per_pixel * wide);
2033 <                                        Screen_blit((uint8 *)drv->s->pixels + i, the_buffer + i, bytes_per_pixel * wide);
2033 >                                        Screen_blit((uint8 *)drv->s->pixels + dst_i, the_buffer + i, bytes_per_pixel * wide);
2034                                  }
2035  
2036                                  // Unlock surface, if required
# Line 2004 | Line 2046 | static void update_display_static(driver
2046  
2047   // Static display update (fixed frame rate, bounding boxes based)
2048   // XXX use NQD bounding boxes to help detect dirty areas?
2049 < static void update_display_static_bbox(driver_window *drv)
2049 > static void update_display_static_bbox(driver_base *drv)
2050   {
2051          const VIDEO_MODE &mode = drv->mode;
2052  
# Line 2022 | Line 2064 | static void update_display_static_bbox(d
2064          // Update the surface from Mac screen
2065          const int bytes_per_row = VIDEO_MODE_ROW_BYTES;
2066          const int bytes_per_pixel = bytes_per_row / VIDEO_MODE_X;
2067 +        const int dst_bytes_per_row = drv->s->pitch;
2068          int x, y;
2069          for (y = 0; y < VIDEO_MODE_Y; y += N_PIXELS) {
2070                  int h = N_PIXELS;
# Line 2036 | Line 2079 | static void update_display_static_bbox(d
2079                          bool dirty = false;
2080                          for (int j = y; j < (y + h); j++) {
2081                                  const int yb = j * bytes_per_row;
2082 +                                const int dst_yb = j * dst_bytes_per_row;
2083                                  if (memcmp(&the_buffer[yb + xb], &the_buffer_copy[yb + xb], xs) != 0) {
2084                                          memcpy(&the_buffer_copy[yb + xb], &the_buffer[yb + xb], xs);
2085 <                                        Screen_blit((uint8 *)drv->s->pixels + yb + xb, the_buffer + yb + xb, xs);
2085 >                                        Screen_blit((uint8 *)drv->s->pixels + dst_yb + xb, the_buffer + yb + xb, xs);
2086                                          dirty = true;
2087                                  }
2088                          }
# Line 2102 | Line 2146 | static inline void handle_palette_change
2146          UNLOCK_PALETTE;
2147   }
2148  
2149 + static void video_refresh_window_static(void);
2150 +
2151   static void video_refresh_dga(void)
2152   {
2153          // Quit DGA mode if requested
2154          possibly_quit_dga_mode();
2155 +        video_refresh_window_static();
2156   }
2157  
2158   #ifdef ENABLE_VOSF
# Line 2157 | Line 2204 | static void video_refresh_window_static(
2204                  tick_counter = 0;
2205                  const VIDEO_MODE &mode = drv->mode;
2206                  if ((int)VIDEO_MODE_DEPTH >= VIDEO_DEPTH_8BIT)
2207 <                        update_display_static_bbox(static_cast<driver_window *>(drv));
2207 >                        update_display_static_bbox(drv);
2208                  else
2209 <                        update_display_static(static_cast<driver_window *>(drv));
2209 >                        update_display_static(drv);
2210          }
2211   }
2212  
# Line 2195 | Line 2242 | static inline void do_video_refresh(void
2242          handle_events();
2243  
2244          // Update display
2245 + #if (defined(__APPLE__) && defined(__MACH__))
2246 +        // SDL expects an auto-release pool to be present.
2247 +        NSAutoReleasePool_wrap(video_refresh);
2248 + #else
2249          video_refresh();
2250 + #endif
2251  
2252   #ifdef SHEEPSHAVER
2253          // Set new cursor image if it was changed
# Line 2205 | Line 2257 | static inline void do_video_refresh(void
2257                  SDL_FreeCursor(sdl_cursor);
2258                  sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]);
2259                  if (sdl_cursor) {
2260 +                        SDL_ShowCursor(private_data == NULL || private_data->cursorVisible);
2261                          SDL_SetCursor(sdl_cursor);
2262   #ifdef WIN32
2263                          // XXX Windows apparently needs an extra mouse event to
# Line 2284 | Line 2337 | static int redraw_func(void *arg)
2337   #ifdef SHEEPSHAVER
2338   void video_set_dirty_area(int x, int y, int w, int h)
2339   {
2340 + #ifdef ENABLE_VOSF
2341          const VIDEO_MODE &mode = drv->mode;
2342          const int screen_width = VIDEO_MODE_X;
2343          const int screen_height = VIDEO_MODE_Y;
2344          const int bytes_per_row = VIDEO_MODE_ROW_BYTES;
2345  
2292 #ifdef ENABLE_VOSF
2346          if (use_vosf) {
2347                  vosf_set_dirty_area(x, y, w, h, screen_width, screen_height, bytes_per_row);
2348                  return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines