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.1 by gbeauche, 2004-06-23T13:47:20Z vs.
Revision 1.3 by gbeauche, 2004-06-23T22:55:47Z

# Line 32 | Line 32
32   *  - Force relative mode in Grab mode even if SDL provides absolute coordinates?
33   *  - Fullscreen mode
34   *  - Gamma tables support is likely to be broken here
35 + *  - Events processing is bound to the general emulation thread as SDL requires
36 + *    to PumpEvents() within the same thread as the one that called SetVideoMode().
37 + *    Besides, there can't seem to be a way to call SetVideoMode() from a child thread.
38   */
39  
40   #include "sysdeps.h"
# Line 102 | Line 105 | static int keycode_table[256];                                         // X
105   static int screen_depth;                                                        // Depth of current screen
106   static SDL_Color sdl_palette[256];                                      // Color palette to be used as CLUT and gamma table
107   static bool sdl_palette_changed = false;                        // Flag: Palette changed, redraw thread must set new colors
108 + static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK;
109  
110   // Mutex to protect palette
111   static SDL_mutex *sdl_palette_lock = NULL;
# Line 604 | Line 608 | bool SDL_monitor_desc::video_open(void)
608  
609          // Start redraw/input thread
610          redraw_thread_cancel = false;
611 <        redraw_thread_active = (SDL_CreateThread(redraw_func, NULL) != NULL);
611 >        redraw_thread_active = ((redraw_thread = SDL_CreateThread(redraw_func, NULL)) != NULL);
612          if (!redraw_thread_active) {
613                  printf("FATAL: cannot create redraw thread\n");
614                  return false;
# Line 746 | Line 750 | void SDL_monitor_desc::video_close(void)
750          // Stop redraw thread
751          if (redraw_thread_active) {
752                  redraw_thread_cancel = true;
753 < //              SDL_WaitThread(redraw_thread, NULL); doesn't work
750 <                while (redraw_thread_cancel);
753 >                SDL_WaitThread(redraw_thread, NULL);
754          }
755          redraw_thread_active = false;
756  
# Line 799 | Line 802 | void VideoQuitFullScreen(void)
802  
803   void VideoInterrupt(void)
804   {
805 +        // We must fill in the events queue in the same thread that did call SDL_SetVideoMode()
806 +        SDL_PumpEvents();
807 +
808          // Emergency quit requested? Then quit
809          if (emerg_quit)
810                  QuitEmulator();
# Line 1021 | Line 1027 | static int event2keycode(SDL_KeyboardEve
1027  
1028   static void handle_events(void)
1029   {
1030 <        SDL_Event event;
1031 <        while (SDL_PollEvent(&event)) {
1032 <                switch (event.type) {
1030 >        SDL_Event events[10];
1031 >        const int n_max_events = sizeof(events) / sizeof(events[0]);
1032 >        int n_events;
1033 >
1034 >        while ((n_events = SDL_PeepEvents(events, n_max_events, SDL_GETEVENT, sdl_eventmask)) > 0) {
1035 >                for (int i = 0; i < n_events; i++) {
1036 >                        SDL_Event const & event = events[i];
1037 >                        switch (event.type) {
1038  
1039                          // Mouse button
1040                          case SDL_MOUSEBUTTONDOWN: {
# Line 1123 | Line 1134 | static void handle_events(void)
1134                                  ADBKeyDown(0x7f);       // Power key
1135                                  ADBKeyUp(0x7f);
1136                                  break;
1137 +                        }
1138                  }
1139          }
1140   }
# Line 1424 | Line 1436 | static int redraw_func(void *arg)
1436  
1437          uint64 end = GetTicks_usec();
1438          D(bug("%lld refreshes in %lld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start)));
1427        redraw_thread_cancel = false;
1439          return 0;
1440   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines