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.19 by gbeauche, 2005-06-06T21:20:28Z vs.
Revision 1.22 by gbeauche, 2005-11-29T23:20:31Z

# Line 101 | Line 101 | static uint8 *the_buffer_copy = NULL;
101   static uint32 the_buffer_size;                                          // Size of allocated the_buffer
102  
103   static bool redraw_thread_active = false;                       // Flag: Redraw thread installed
104 + #ifndef USE_CPU_EMUL_SERVICES
105   static volatile bool redraw_thread_cancel;                      // Flag: Cancel Redraw thread
106   static SDL_Thread *redraw_thread = NULL;                        // Redraw thread
107 + #ifdef SHEEPSHAVER
108   static volatile bool thread_stop_req = false;
109   static volatile bool thread_stop_ack = false;           // Acknowledge for thread_stop_req
110 + #endif
111 + #endif
112  
113   #ifdef ENABLE_VOSF
114   static bool use_vosf = false;                                           // Flag: VOSF enabled
# Line 131 | Line 135 | static SDL_Color sdl_palette[256];                                     /
135   static bool sdl_palette_changed = false;                        // Flag: Palette changed, redraw thread must set new colors
136   static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK;
137  
138 + // Mutex to protect SDL events
139 + static SDL_mutex *sdl_events_lock = NULL;
140 + #define LOCK_EVENTS SDL_LockMutex(sdl_events_lock)
141 + #define UNLOCK_EVENTS SDL_UnlockMutex(sdl_events_lock)
142 +
143   // Mutex to protect palette
144   static SDL_mutex *sdl_palette_lock = NULL;
145   #define LOCK_PALETTE SDL_LockMutex(sdl_palette_lock)
# Line 154 | Line 163 | extern void SysMountFirstFloppy(void);
163  
164  
165   /*
166 + *  SDL surface locking glue
167 + */
168 +
169 + #ifdef ENABLE_VOSF
170 + #define SDL_VIDEO_LOCK_VOSF_SURFACE(SURFACE) do {                               \
171 +        if ((SURFACE)->flags & (SDL_HWSURFACE | SDL_FULLSCREEN))        \
172 +                the_host_buffer = (uint8 *)(SURFACE)->pixels;                   \
173 + } while (0)
174 + #else
175 + #define SDL_VIDEO_LOCK_VOSF_SURFACE(SURFACE)
176 + #endif
177 +
178 + #define SDL_VIDEO_LOCK_SURFACE(SURFACE) do {    \
179 +        if (SDL_MUSTLOCK(SURFACE)) {                            \
180 +                SDL_LockSurface(SURFACE);                               \
181 +                SDL_VIDEO_LOCK_VOSF_SURFACE(SURFACE);   \
182 +        }                                                                                       \
183 + } while (0)
184 +
185 + #define SDL_VIDEO_UNLOCK_SURFACE(SURFACE) do {  \
186 +        if (SDL_MUSTLOCK(SURFACE))                                      \
187 +                SDL_UnlockSurface(SURFACE);                             \
188 + } while (0)
189 +
190 +
191 + /*
192   *  Framebuffer allocation routines
193   */
194  
195   static void *vm_acquire_framebuffer(uint32 size)
196   {
162 #ifdef SHEEPSHAVER
163 #ifdef DIRECT_ADDRESSING_HACK
164        const uint32 FRAME_BUFFER_BASE = 0x61000000;
165        uint8 *fb = Mac2HostAddr(FRAME_BUFFER_BASE);
166        if (vm_acquire_fixed(fb, size) < 0)
167                fb = VM_MAP_FAILED;
168        return fb;
169 #endif
170 #endif
197          return vm_acquire(size);
198   }
199  
# Line 1006 | Line 1032 | bool SDL_monitor_desc::video_open(void)
1032          LOCK_FRAME_BUFFER;
1033  
1034          // Start redraw/input thread
1035 + #ifndef USE_CPU_EMUL_SERVICES
1036          redraw_thread_cancel = false;
1037          redraw_thread_active = ((redraw_thread = SDL_CreateThread(redraw_func, NULL)) != NULL);
1038          if (!redraw_thread_active) {
1039                  printf("FATAL: cannot create redraw thread\n");
1040                  return false;
1041          }
1042 + #else
1043 +        redraw_thread_active = true;
1044 + #endif
1045          return true;
1046   }
1047  
# Line 1032 | Line 1062 | bool VideoInit(bool classic)
1062   #endif
1063  
1064          // Create Mutexes
1065 +        if ((sdl_events_lock = SDL_CreateMutex()) == NULL)
1066 +                return false;
1067          if ((sdl_palette_lock = SDL_CreateMutex()) == NULL)
1068                  return false;
1069          if ((frame_buffer_lock = SDL_CreateMutex()) == NULL)
# Line 1228 | Line 1260 | void SDL_monitor_desc::video_close(void)
1260          D(bug("video_close()\n"));
1261  
1262          // Stop redraw thread
1263 + #ifndef USE_CPU_EMUL_SERVICES
1264          if (redraw_thread_active) {
1265                  redraw_thread_cancel = true;
1266                  SDL_WaitThread(redraw_thread, NULL);
1267          }
1268 + #endif
1269          redraw_thread_active = false;
1270  
1271          // Unlock frame buffer
# Line 1255 | Line 1289 | void VideoExit(void)
1289                  SDL_DestroyMutex(frame_buffer_lock);
1290          if (sdl_palette_lock)
1291                  SDL_DestroyMutex(sdl_palette_lock);
1292 +        if (sdl_events_lock)
1293 +                SDL_DestroyMutex(sdl_events_lock);
1294   }
1295  
1296  
# Line 1424 | Line 1460 | int16 video_mode_change(VidLocals *csSav
1460   void SDL_monitor_desc::switch_to_current_mode(void)
1461   {
1462          // Close and reopen display
1463 +        LOCK_EVENTS;
1464          video_close();
1465          video_open();
1466 +        UNLOCK_EVENTS;
1467  
1468          if (drv == NULL) {
1469                  ErrorAlert(STR_OPEN_WINDOW_ERR);
# Line 2035 | Line 2073 | static void VideoRefreshInit(void)
2073          }
2074   }
2075  
2076 + static inline void do_video_refresh(void)
2077 + {
2078 +        // Handle SDL events
2079 +        handle_events();
2080 +
2081 +        // Update display
2082 +        video_refresh();
2083 +
2084 + #ifdef SHEEPSHAVER
2085 +        // Set new cursor image if it was changed
2086 +        if (cursor_changed && sdl_cursor) {
2087 +                cursor_changed = false;
2088 +                LOCK_EVENTS;
2089 +                SDL_FreeCursor(sdl_cursor);
2090 +                sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]);
2091 +                if (sdl_cursor)
2092 +                        SDL_SetCursor(sdl_cursor);
2093 +                UNLOCK_EVENTS;
2094 +        }
2095 + #endif
2096 +
2097 +        // Set new palette if it was changed
2098 +        handle_palette_changes();
2099 + }
2100 +
2101 + // This function is called on non-threaded platforms from a timer interrupt
2102 + void VideoRefresh(void)
2103 + {
2104 +        // We need to check redraw_thread_active to inhibit refreshed during
2105 +        // mode changes on non-threaded platforms
2106 +        if (!redraw_thread_active)
2107 +                return;
2108 +
2109 +        // Process pending events and update display
2110 +        do_video_refresh();
2111 + }
2112 +
2113   const int VIDEO_REFRESH_HZ = 60;
2114   const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ;
2115  
2116 + #ifndef USE_CPU_EMUL_SERVICES
2117   static int redraw_func(void *arg)
2118   {
2119          uint64 start = GetTicks_usec();
# Line 2063 | Line 2139 | static int redraw_func(void *arg)
2139                  }
2140   #endif
2141  
2142 <                // Handle SDL events
2143 <                handle_events();
2068 <
2069 <                // Refresh display
2070 <                video_refresh();
2071 <
2072 < #ifdef SHEEPSHAVER
2073 <                // Set new cursor image if it was changed
2074 <                if (cursor_changed && sdl_cursor) {
2075 <                        cursor_changed = false;
2076 <                        SDL_FreeCursor(sdl_cursor);
2077 <                        sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]);
2078 <                        if (sdl_cursor)
2079 <                                SDL_SetCursor(sdl_cursor);
2080 <                }
2081 < #endif
2082 <
2083 <                // Set new palette if it was changed
2084 <                handle_palette_changes();
2142 >                // Process pending events and update display
2143 >                do_video_refresh();
2144          }
2145  
2146          uint64 end = GetTicks_usec();
2147          D(bug("%lld refreshes in %lld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start)));
2148          return 0;
2149   }
2150 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines