ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/video_x.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/video_x.cpp (file contents):
Revision 1.56 by gbeauche, 2001-07-07T09:14:47Z vs.
Revision 1.57 by cebix, 2001-07-09T11:22:00Z

# Line 80 | Line 80 | enum {
80   // Constants
81   const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes";
82  
83 < static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | StructureNotifyMask;
83 > static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask | StructureNotifyMask;
84   static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask;
85  
86  
# Line 429 | Line 429 | public:
429          virtual void toggle_mouse_grab(void) {}
430          virtual void mouse_moved(int x, int y) { ADBMouseMoved(x, y); }
431  
432 +        void disable_mouse_accel(void);
433 +        void restore_mouse_accel(void);
434 +
435          virtual void grab_mouse(void) {}
436          virtual void ungrab_mouse(void) {}
437  
438   public:
439          bool init_ok;   // Initialization succeeded (we can't use exceptions because of -fomit-frame-pointer)
440          Window w;               // The window we draw into
441 +
442 +        int orig_accel_numer, orig_accel_denom, orig_threshold; // Original mouse acceleration
443   };
444  
445   class driver_window;
# Line 478 | Line 483 | driver_base::driver_base()
483   {
484          the_buffer = NULL;
485          the_buffer_copy = NULL;
486 +        XGetPointerControl(x_display, &orig_accel_numer, &orig_accel_denom, &orig_threshold);
487   }
488  
489   driver_base::~driver_base()
490   {
491          ungrab_mouse();
492 +        restore_mouse_accel();
493  
494          if (w) {
495                  XUnmapWindow(x_display, w);
# Line 535 | Line 542 | void driver_base::update_palette(void)
542          XSync(x_display, false);
543   }
544  
545 + // Disable mouse acceleration
546 + void driver_base::disable_mouse_accel(void)
547 + {
548 +        XChangePointerControl(x_display, True, False, 1, 1, 0);
549 + }
550 +
551 + // Restore mouse acceleration to original value
552 + void driver_base::restore_mouse_accel(void)
553 + {
554 +        XChangePointerControl(x_display, True, True, orig_accel_numer, orig_accel_denom, orig_threshold);
555 + }
556 +
557  
558   /*
559   *  Windowed display driver
# Line 728 | Line 747 | void driver_window::grab_mouse(void)
747                  Delay_usec(100000);
748          }
749          if (result == GrabSuccess) {
731                ADBSetRelMouseMode(mouse_grabbed = true);
750                  XStoreName(x_display, w, GetString(STR_WINDOW_TITLE_GRABBED));
751 <                XSync(x_display, false);
751 >                ADBSetRelMouseMode(mouse_grabbed = true);
752 >                disable_mouse_accel();
753          }
754   }
755  
# Line 741 | Line 760 | void driver_window::ungrab_mouse(void)
760                  XUngrabPointer(x_display, CurrentTime);
761                  XStoreName(x_display, w, GetString(STR_WINDOW_TITLE));
762                  ADBSetRelMouseMode(mouse_grabbed = false);
763 +                restore_mouse_accel();
764          }
765   }
766  
# Line 836 | Line 856 | void driver_dga::suspend(void)
856   #endif
857          XUngrabPointer(x_display, CurrentTime);
858          XUngrabKeyboard(x_display, CurrentTime);
859 +        restore_mouse_accel();
860          XUnmapWindow(x_display, w);
861          wait_unmapped(w);
862  
# Line 865 | Line 886 | void driver_dga::resume(void)
886          XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0);
887          XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime);
888          XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
889 +        disable_mouse_accel();
890   #ifdef ENABLE_XF86_DGA
891          XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse);
892          XF86DGASetViewPort(x_display, screen, 0, 0);
# Line 1011 | Line 1033 | driver_fbdev::driver_fbdev(const video_m
1033          XGrabPointer(x_display, w, True,
1034                  PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1035                  GrabModeAsync, GrabModeAsync, w, None, CurrentTime);
1036 +        disable_mouse_accel();
1037          
1038          // Calculate bytes per row
1039          int bytes_per_row = TrivialBytesPerRow(mode.x, mode.depth);
# Line 1150 | Line 1173 | driver_xf86dga::driver_xf86dga(const vid
1173          XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0);
1174          XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime);
1175          XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
1176 +        disable_mouse_accel();
1177  
1178          int v_width, v_bank, v_size;
1179          XF86DGAGetVideo(x_display, screen, (char **)&the_buffer, &v_width, &v_bank, &v_size);
# Line 1344 | Line 1368 | static bool video_open(const video_mode
1368                          --bloss;
1369          }
1370  
1371 <        // Preset palette pixel values for gamma table
1371 >        // Preset palette pixel values for CLUT or gamma table
1372          if (color_class == DirectColor) {
1373                  int num = vis->map_entries;
1374                  for (int i=0; i<num; i++) {
1375                          int c = (i * 256) / num;
1376                          palette[i].pixel = map_rgb(c, c, c);
1377 +                        palette[i].flags = DoRed | DoGreen | DoBlue;
1378 +                }
1379 +        } else if (color_class == PseudoColor) {
1380 +                for (int i=0; i<256; i++) {
1381 +                        palette[i].pixel = i;
1382 +                        palette[i].flags = DoRed | DoGreen | DoBlue;
1383                  }
1384          }
1385  
# Line 1360 | Line 1390 | static bool video_open(const video_mode
1390                  palette[i].red = c * 0x0101;
1391                  palette[i].green = c * 0x0101;
1392                  palette[i].blue = c * 0x0101;
1363                if (color_class == PseudoColor)
1364                        palette[i].pixel = i;
1365                palette[i].flags = DoRed | DoGreen | DoBlue;
1393          }
1394          if (cmap[0] && cmap[1]) {
1395                  XStoreColors(x_display, cmap[0], palette, num);
# Line 1371 | Line 1398 | static bool video_open(const video_mode
1398  
1399   #ifdef ENABLE_VOSF
1400          // Load gray ramp to 8->16/32 expand map
1401 <        if (!IsDirectMode(mode) && (color_class == TrueColor || color_class == DirectColor))
1401 >        if (!IsDirectMode(mode) && xdepth > 8)
1402                  for (int i=0; i<256; i++)
1403                          ExpandMap[i] = map_rgb(i, i, i);
1404   #endif
# Line 1722 | Line 1749 | void video_set_palette(uint8 *pal, int n
1749                  p->red = pal[c*3 + 0] * 0x0101;
1750                  p->green = pal[c*3 + 1] * 0x0101;
1751                  p->blue = pal[c*3 + 2] * 0x0101;
1725                if (color_class == PseudoColor)
1726                        p->pixel = i;
1727                p->flags = DoRed | DoGreen | DoBlue;
1752                  p++;
1753          }
1754  
1755   #ifdef ENABLE_VOSF
1756          // Recalculate pixel color expansion map
1757 <        if (!IsDirectMode(VideoMonitor.mode) && (color_class == TrueColor || color_class == DirectColor)) {
1757 >        if (!IsDirectMode(VideoMonitor.mode) && xdepth > 8) {
1758                  for (int i=0; i<256; i++) {
1759                          int c = i & (num_in-1); // If there are less than 256 colors, we repeat the first entries (this makes color expansion easier)
1760                          ExpandMap[i] = map_rgb(pal[c*3+0], pal[c*3+1], pal[c*3+2]);
# Line 1943 | Line 1967 | static void handle_events(void)
1967                  XNextEvent(x_display, &event);
1968  
1969                  switch (event.type) {
1970 +
1971                          // Mouse button
1972                          case ButtonPress: {
1973                                  unsigned int button = event.xbutton.button;
# Line 1975 | Line 2000 | static void handle_events(void)
2000                                  drv->mouse_moved(event.xmotion.x, event.xmotion.y);
2001                                  break;
2002  
2003 +                        // Mouse entered window
2004 +                        case EnterNotify:
2005 +                                if (event.xcrossing.mode != NotifyGrab && event.xcrossing.mode != NotifyUngrab)
2006 +                                        drv->mouse_moved(event.xmotion.x, event.xmotion.y);
2007 +                                break;
2008 +
2009                          // Keyboard
2010                          case KeyPress: {
2011                                  int code = -1;
# Line 2311 | Line 2342 | static void video_refresh_dga(void)
2342   {
2343          // Quit DGA mode if requested
2344          possibly_quit_dga_mode();
2314        
2315        // Handle X events
2316        handle_events();
2317        
2318        // Handle palette changes
2319        handle_palette_changes();
2345   }
2346  
2347   #ifdef ENABLE_VOSF
# Line 2326 | Line 2351 | static void video_refresh_dga_vosf(void)
2351          // Quit DGA mode if requested
2352          possibly_quit_dga_mode();
2353          
2329        // Handle X events
2330        handle_events();
2331        
2332        // Handle palette changes
2333        handle_palette_changes();
2334        
2354          // Update display (VOSF variant)
2355          static int tick_counter = 0;
2356          if (++tick_counter >= frame_skip) {
# Line 2350 | Line 2369 | static void video_refresh_window_vosf(vo
2369          // Ungrab mouse if requested
2370          possibly_ungrab_mouse();
2371          
2353        // Handle X events
2354        handle_events();
2355        
2356        // Handle palette changes
2357        handle_palette_changes();
2358        
2372          // Update display (VOSF variant)
2373          static int tick_counter = 0;
2374          if (++tick_counter >= frame_skip) {
# Line 2375 | Line 2388 | static void video_refresh_window_static(
2388          // Ungrab mouse if requested
2389          possibly_ungrab_mouse();
2390  
2378        // Handle X events
2379        handle_events();
2380        
2381        // Handle_palette changes
2382        handle_palette_changes();
2383        
2391          // Update display (static variant)
2392          static int tick_counter = 0;
2393          if (++tick_counter >= frame_skip) {
# Line 2394 | Line 2401 | static void video_refresh_window_dynamic
2401          // Ungrab mouse if requested
2402          possibly_ungrab_mouse();
2403  
2397        // Handle X events
2398        handle_events();
2399        
2400        // Handle_palette changes
2401        handle_palette_changes();
2402        
2404          // Update display (dynamic variant)
2405          static int tick_counter = 0;
2406          tick_counter++;
# Line 2435 | Line 2436 | static void VideoRefreshInit(void)
2436          }
2437   }
2438  
2439 + // This function is called on non-threaded platforms from a timer interrupt
2440   void VideoRefresh(void)
2441   {
2442          // We need to check redraw_thread_active to inhibit refreshed during
2443          // mode changes on non-threaded platforms
2444 <        if (redraw_thread_active)
2445 <                video_refresh();
2444 >        if (!redraw_thread_active)
2445 >                return;
2446 >
2447 >        // Handle X events
2448 >        handle_events();
2449 >
2450 >        // Handle palette changes
2451 >        handle_palette_changes();
2452 >
2453 >        // Update display
2454 >        video_refresh();
2455   }
2456  
2457 + const int VIDEO_REFRESH_HZ = 60;
2458 + const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ;
2459 +
2460   #ifdef HAVE_PTHREADS
2461   static void *redraw_func(void *arg)
2462   {
2463 +        int fd = ConnectionNumber(x_display);
2464 +
2465          uint64 start = GetTicks_usec();
2466          int64 ticks = 0;
2467 <        uint64 next = GetTicks_usec();
2467 >        uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY;
2468 >
2469          while (!redraw_thread_cancel) {
2470 <                video_refresh();
2454 <                next += 16667;
2470 >
2471                  int64 delay = next - GetTicks_usec();
2472 <                if (delay > 0)
2473 <                        Delay_usec(delay);
2474 <                else if (delay < -16667)
2472 >                if (delay < -VIDEO_REFRESH_DELAY) {
2473 >
2474 >                        // We are lagging far behind, so we reset the delay mechanism
2475                          next = GetTicks_usec();
2476 <                ticks++;
2476 >
2477 >                } else if (delay <= 0) {
2478 >
2479 >                        // Delay expired, refresh display
2480 >                        handle_events();
2481 >                        handle_palette_changes();
2482 >                        video_refresh();
2483 >                        next += VIDEO_REFRESH_DELAY;
2484 >                        ticks++;
2485 >
2486 >                } else {
2487 >
2488 >                        // No display refresh pending, check for X events
2489 >                        fd_set readfds;
2490 >                        FD_ZERO(&readfds);
2491 >                        FD_SET(fd, &readfds);
2492 >                        struct timeval timeout;
2493 >                        timeout.tv_sec = 0;
2494 >                        timeout.tv_usec = delay;
2495 >                        if (select(fd+1, &readfds, NULL, NULL, &timeout) > 0)
2496 >                                handle_events();
2497 >                }
2498          }
2499 +
2500          uint64 end = GetTicks_usec();
2501 <        // printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, ticks * 1000000 / (end - start));
2501 >        D(bug("%Ld refreshes in %Ld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start)));
2502          return NULL;
2503   }
2504   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines