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

Comparing SheepShaver/src/Unix/video_x.cpp (file contents):
Revision 1.37 by gbeauche, 2005-03-27T14:53:04Z vs.
Revision 1.38 by gbeauche, 2005-03-27T19:05:18Z

# Line 18 | Line 18
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  
21 + /*
22 + *  NOTES:
23 + *    The Ctrl key works like a qualifier for special actions:
24 + *      Ctrl-Tab = suspend DGA mode
25 + *      Ctrl-Esc = emergency quit
26 + *      Ctrl-F1 = mount floppy
27 + *      Ctrl-F5 = grab mouse (in windowed mode)
28 + */
29 +
30   #include "sysdeps.h"
31  
32   #include <X11/Xlib.h>
# Line 31 | Line 40
40  
41   #include <algorithm>
42  
43 + #ifdef ENABLE_FBDEV_DGA
44 + # include <linux/fb.h>
45 + # include <sys/ioctl.h>
46 + #endif
47 +
48   #ifdef ENABLE_XF86_DGA
49   # include <X11/extensions/xf86dga.h>
50   #endif
# Line 109 | Line 123 | static int color_class;
123   static int rshift, rloss, gshift, gloss, bshift, bloss; // Pixel format of DirectColor/TrueColor modes
124   static Colormap cmap[2];                                        // Two colormaps (DGA) for 8-bit mode
125   static XColor x_palette[256];                           // Color palette to be used as CLUT and gamma table
126 + static int orig_accel_numer, orig_accel_denom, orig_threshold;  // Original mouse acceleration
127  
128   static XColor black, white;
129   static unsigned long black_pixel, white_pixel;
# Line 131 | Line 146 | static uint8 *the_buffer_copy = NULL;          /
146   static uint32 the_buffer_size;                          // Size of allocated the_buffer
147  
148   // Variables for DGA mode
149 + static bool is_fbdev_dga_mode = false;          // Flag: Use FBDev DGA mode?
150   static int current_dga_cmap;
151  
152 + #ifdef ENABLE_FBDEV_DGA
153 + static int fb_dev_fd = -1;                                              // Handle to fb device name
154 + static struct fb_fix_screeninfo fb_finfo;               // Fixed info
155 + static struct fb_var_screeninfo fb_vinfo;               // Variable info
156 + static struct fb_var_screeninfo fb_orig_vinfo;  // Variable info to restore later
157 + static struct fb_cmap fb_oldcmap;                               // Colormap to restore later
158 + #endif
159 +
160   #ifdef ENABLE_XF86_VIDMODE
161   // Variables for XF86 VidMode support
162   static XF86VidModeModeInfo **x_video_modes;             // Array of all available modes
# Line 153 | Line 177 | static pthread_mutex_t x_palette_lock =
177   #define UNLOCK_PALETTE
178   #endif
179  
180 + // Mutex to protect frame buffer
181 + #ifdef HAVE_SPINLOCKS
182 + static spinlock_t frame_buffer_lock = SPIN_LOCK_UNLOCKED;
183 + #define LOCK_FRAME_BUFFER spin_lock(&frame_buffer_lock)
184 + #define UNLOCK_FRAME_BUFFER spin_unlock(&frame_buffer_lock)
185 + #elif defined(HAVE_PTHREADS)
186 + static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
187 + #define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock);
188 + #define UNLOCK_FRAME_BUFFER pthread_mutex_unlock(&frame_buffer_lock);
189 + #else
190 + #define LOCK_FRAME_BUFFER
191 + #define UNLOCK_FRAME_BUFFER
192 + #endif
193 +
194  
195   // Prototypes
196   static void *redraw_func(void *arg);
# Line 364 | Line 402 | static bool find_visual_for_depth(int de
402   *  Open display (window or fullscreen)
403   */
404  
405 + // Set window name and class
406 + static void set_window_name(Window w, int name)
407 + {
408 +        const char *str = GetString(name);
409 +        XStoreName(x_display, w, str);
410 +        XSetIconName(x_display, w, str);
411 +
412 +        XClassHint *hints;
413 +        hints = XAllocClassHint();
414 +        if (hints) {
415 +                hints->res_name = "SheepShaver";
416 +                hints->res_class = "SheepShaver";
417 +                XSetClassHint(x_display, w, hints);
418 +                XFree(hints);
419 +        }
420 + }
421 +
422 + // Set window input focus flag
423 + static void set_window_focus(Window w)
424 + {
425 +        XWMHints *hints = XAllocWMHints();
426 +        if (hints) {
427 +                hints->input = True;
428 +                hints->initial_state = NormalState;
429 +                hints->flags = InputHint | StateHint;
430 +                XSetWMHints(x_display, w, hints);
431 +                XFree(hints);
432 +        }
433 + }
434 +
435   // Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget)
436   static Atom WM_DELETE_WINDOW = (Atom)0;
437   static void set_window_delete_protocol(Window w)
# Line 389 | Line 457 | static void wait_unmapped(Window w)
457          } while ((e.type != UnmapNotify) || (e.xmap.event != w));
458   }
459  
460 + // Disable mouse acceleration
461 + static void disable_mouse_accel(void)
462 + {
463 +        XChangePointerControl(x_display, True, False, 1, 1, 0);
464 + }
465 +
466 + // Restore mouse acceleration to original value
467 + static void restore_mouse_accel(void)
468 + {
469 +        XChangePointerControl(x_display, True, True, orig_accel_numer, orig_accel_denom, orig_threshold);
470 + }
471 +
472   // Trap SHM errors
473   static bool shm_error = false;
474   static int (*old_error_handler)(Display *, XErrorEvent *);
# Line 421 | Line 501 | static bool open_window(int width, int h
501          the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
502                  InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | CWBackingStore | CWColormap, &wattr);
503  
504 <        // Set window name
505 <        XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE));
504 >        // Set window name/class
505 >        set_window_name(the_win, STR_WINDOW_TITLE);
506 >
507 >        // Indicate that we want keyboard input
508 >        set_window_focus(the_win);
509  
510          // Set delete protocol property
511          set_window_delete_protocol(the_win);
# Line 550 | Line 633 | static bool open_window(int width, int h
633          return true;
634   }
635  
636 + // Open FBDev display
637 + static bool open_fbdev(int width, int height)
638 + {
639 + #ifdef ENABLE_FBDEV_DGA
640 +        if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo) != 0) {
641 +                D(bug("[fbdev] Can't get FSCREENINFO: %s\n", strerror(errno)));
642 +                return false;
643 +        }
644 +        D(bug("[fbdev] Device ID: %s\n", fb_finfo.id));
645 +        D(bug("[fbdev] smem_start: %p [%d bytes]\n", fb_finfo.smem_start, fb_finfo.smem_len));
646 +        int fb_type = fb_finfo.type;
647 +        const char *fb_type_str = NULL;
648 +        switch (fb_type) {
649 +        case FB_TYPE_PACKED_PIXELS:                     fb_type_str = "Packed Pixels";                  break;
650 +        case FB_TYPE_PLANES:                            fb_type_str = "Non interleaved planes"; break;
651 +        case FB_TYPE_INTERLEAVED_PLANES:        fb_type_str = "Interleaved planes";             break;
652 +        case FB_TYPE_TEXT:                                      fb_type_str = "Text/attributes";                break;
653 +        case FB_TYPE_VGA_PLANES:                        fb_type_str = "EGA/VGA planes";                 break;
654 +        default:                                                        fb_type_str = "<unknown>";                              break;
655 +        }
656 +        D(bug("[fbdev] type: %s\n", fb_type_str));
657 +        int fb_visual = fb_finfo.visual;
658 +        const char *fb_visual_str;
659 +        switch (fb_visual) {
660 +        case FB_VISUAL_MONO01:                          fb_visual_str = "Monochrome 1=Black 0=White";   break;
661 +        case FB_VISUAL_MONO10:                          fb_visual_str = "Monochrome 1=While 0=Black";   break;
662 +        case FB_VISUAL_TRUECOLOR:                       fb_visual_str = "True color";                                   break;
663 +        case FB_VISUAL_PSEUDOCOLOR:                     fb_visual_str = "Pseudo color (like atari)";    break;
664 +        case FB_VISUAL_DIRECTCOLOR:                     fb_visual_str = "Direct color";                                 break;
665 +        case FB_VISUAL_STATIC_PSEUDOCOLOR:      fb_visual_str = "Pseudo color readonly";                break;
666 +        default:                                                        fb_visual_str = "<unknown>";                                    break;
667 +        }
668 +        D(bug("[fbdev] visual: %s\n", fb_visual_str));
669 +
670 +        if (fb_type != FB_TYPE_PACKED_PIXELS) {
671 +                D(bug("[fbdev] type %s not supported\n", fb_type_str));
672 +                return false;
673 +        }
674 +        
675 +        // Map frame buffer
676 +        the_buffer = (uint8 *)mmap(NULL, fb_finfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb_dev_fd, 0);
677 +        if (the_buffer == MAP_FAILED) {
678 +                D(bug("[fbdev] Can't mmap /dev/fb0: %s\n", strerror(errno)));
679 +                return false;
680 +        }
681 +
682 +        // Set absolute mouse mode
683 +        ADBSetRelMouseMode(false);
684 +
685 +        // Create window
686 +        XSetWindowAttributes wattr;
687 +        wattr.event_mask = eventmask = dga_eventmask;
688 +        wattr.override_redirect = True;
689 +        wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]);
690 +        the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
691 +                                                        InputOutput, vis, CWEventMask | CWOverrideRedirect |
692 +                                                        (color_class == DirectColor ? CWColormap : 0), &wattr);
693 +
694 +        // Show window
695 +        XMapRaised(x_display, the_win);
696 +        wait_mapped(the_win);
697 +
698 +        // Grab mouse and keyboard
699 +        XGrabKeyboard(x_display, the_win, True,
700 +                                  GrabModeAsync, GrabModeAsync, CurrentTime);
701 +        XGrabPointer(x_display, the_win, True,
702 +                                 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
703 +                                 GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
704 +        disable_mouse_accel();
705 +
706 +        // Create no_cursor
707 +        mac_cursor = XCreatePixmapCursor(x_display,
708 +                                                                         XCreatePixmap(x_display, the_win, 1, 1, 1),
709 +                                                                         XCreatePixmap(x_display, the_win, 1, 1, 1),
710 +                                                                         &black, &white, 0, 0);
711 +        XDefineCursor(x_display, the_win, mac_cursor);
712 +
713 +        // Init blitting routines
714 +        int bytes_per_row = TrivialBytesPerRow((width + 7) & ~7, DepthModeForPixelDepth(depth));
715 + #if ENABLE_VOSF
716 +        bool native_byte_order;
717 + #ifdef WORDS_BIGENDIAN
718 +        native_byte_order = (XImageByteOrder(x_display) == MSBFirst);
719 + #else
720 +        native_byte_order = (XImageByteOrder(x_display) == LSBFirst);
721 + #endif
722 + #if REAL_ADDRESSING || DIRECT_ADDRESSING
723 +        // Screen_blitter_init() returns TRUE if VOSF is mandatory
724 +        // i.e. the framebuffer update function is not Blit_Copy_Raw
725 +        use_vosf = Screen_blitter_init(visualFormat, native_byte_order, depth);
726 +        
727 +        if (use_vosf) {
728 +          // Allocate memory for frame buffer (SIZE is extended to page-boundary)
729 +          the_host_buffer = the_buffer;
730 +          the_buffer_size = page_extend((height + 2) * bytes_per_row);
731 +          the_buffer_copy = (uint8 *)malloc(the_buffer_size);
732 +          the_buffer = (uint8 *)vm_acquire(the_buffer_size);
733 +          D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
734 +        }
735 + #else
736 +        use_vosf = false;
737 + #endif
738 + #endif
739 +
740 +        // Set frame buffer base
741 +        D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf));
742 +        screen_base = Host2MacAddr(the_buffer);
743 +        VModes[cur_mode].viRowBytes = bytes_per_row;
744 +        return true;
745 + #else
746 +        ErrorAlert("SheepShaver has been compiled with DGA support disabled.");
747 +        return false;
748 + #endif
749 + }
750 +
751   // Open DGA display (!! should use X11 VidMode extensions to set mode)
752   static bool open_dga(int width, int height)
753   {
754 +        if (is_fbdev_dga_mode)
755 +                return false;
756 +
757   #ifdef ENABLE_XF86_DGA
758          // Set relative mouse mode
759          ADBSetRelMouseMode(true);
# Line 647 | Line 848 | static bool open_display(void)
848          D(bug("open_display()\n"));
849          const VideoInfo &mode = VModes[cur_mode];
850  
851 +        // Get original mouse acceleration
852 +        XGetPointerControl(x_display, &orig_accel_numer, &orig_accel_denom, &orig_threshold);
853 +
854          // Find best available X visual
855          if (!find_visual_for_depth(mode.viAppleMode)) {
856                  ErrorAlert(GetString(STR_NO_XVISUAL_ERR));
# Line 727 | Line 931 | static bool open_display(void)
931          depth = depth_of_video_mode(mode.viAppleMode);
932  
933          bool display_open = false;
934 <        if (display_type == DIS_SCREEN)
934 >        if (display_type == DIS_SCREEN) {
935                  display_open = open_dga(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize);
936 + #ifdef ENABLE_FBDEV_DGA
937 +                // Try to fallback to FBDev DGA mode
938 +                if (!display_open) {
939 +                        is_fbdev_dga_mode = true;
940 +                        display_open = open_fbdev(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize);
941 +                }
942 + #endif
943 +                
944 +        }
945          else if (display_type == DIS_WINDOW)
946                  display_open = open_window(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize);
947  
# Line 777 | Line 990 | static void close_window(void)
990          XSync(x_display, false);
991   }
992  
993 + // Close FBDev mode
994 + static void close_fbdev(void)
995 + {
996 + #ifdef ENABLE_FBDEV_DGA
997 +        XUngrabPointer(x_display, CurrentTime);
998 +        XUngrabKeyboard(x_display, CurrentTime);
999 +
1000 +        uint8 *fb_base;
1001 +        if (!use_vosf) {
1002 +                // don't free() the screen buffer in driver_base dtor
1003 +                fb_base = the_buffer;
1004 +                the_buffer = NULL;
1005 +        }
1006 + #ifdef ENABLE_VOSF
1007 +        else {
1008 +                // don't free() the screen buffer in driver_base dtor
1009 +                fb_base = the_host_buffer;
1010 +                the_host_buffer = NULL;
1011 +        }
1012 + #endif
1013 +        munmap(fb_base, fb_finfo.smem_len);
1014 + #endif
1015 + }
1016 +
1017   // Close DGA mode
1018   static void close_dga(void)
1019   {
1020 +        if (is_fbdev_dga_mode)
1021 +                return;
1022 +
1023   #ifdef ENABLE_XF86_DGA
1024          XF86DGADirectVideo(x_display, screen, 0);
1025          XUngrabPointer(x_display, CurrentTime);
# Line 805 | Line 1045 | static void close_dga(void)
1045  
1046   static void close_display(void)
1047   {
1048 <        if (display_type == DIS_SCREEN)
1049 <                close_dga();
1048 >        if (display_type == DIS_SCREEN) {
1049 >                if (is_fbdev_dga_mode)
1050 >                        close_fbdev();
1051 >                else
1052 >                        close_dga();
1053 >        }
1054          else if (display_type == DIS_WINDOW)
1055                  close_window();
1056  
# Line 861 | Line 1105 | static void close_display(void)
1105                  }
1106          }
1107   #endif
1108 +
1109 +        // Restore mouse acceleration
1110 +        restore_mouse_accel();
1111   }
1112  
1113  
# Line 1088 | Line 1335 | bool VideoInit(void)
1335   #ifdef ENABLE_XF86_DGA
1336          // DGA available?
1337      int event_base, error_base;
1338 +    is_fbdev_dga_mode = false;
1339      if (local_X11 && XF86DGAQueryExtension(x_display, &event_base, &error_base)) {
1340                  int dga_flags = 0;
1341                  XF86DGAQueryDirectVideo(x_display, screen, &dga_flags);
1342                  has_dga = dga_flags & XF86DGADirectPresent;
1343 + #if defined(__linux__)
1344 +                // Check r/w permission on /dev/mem for DGA mode to work
1345 +                if (has_dga && access("/dev/mem", R_OK | W_OK) != 0)
1346 +                        has_dga = false;
1347 + #endif
1348          } else
1349                  has_dga = false;
1350   #endif
# Line 1104 | Line 1357 | bool VideoInit(void)
1357                  XF86VidModeGetAllModeLines(x_display, screen, &num_x_video_modes, &x_video_modes);
1358   #endif
1359  
1360 + #ifdef ENABLE_FBDEV_DGA
1361 +        // FBDev available?
1362 +        if (!has_dga && local_X11) {
1363 +                if ((fb_dev_fd = open("/dev/fb0", O_RDWR)) > 0) {
1364 +                        if (ioctl(fb_dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo) != 0)
1365 +                                close(fb_dev_fd);
1366 +                        else {
1367 +                                has_dga = true;
1368 +                                is_fbdev_dga_mode = true;
1369 +                                fb_orig_vinfo = fb_vinfo;
1370 +                                D(bug("Frame buffer device initial resolution: %dx%dx%d\n", fb_vinfo.xres, fb_vinfo.yres, fb_vinfo.bits_per_pixel));
1371 +                        }
1372 +                }
1373 +        }
1374 + #endif
1375 +
1376          // Find black and white colors
1377          XParseColor(x_display, DefaultColormap(x_display, screen), "rgb:00/00/00", &black);
1378          XAllocColor(x_display, DefaultColormap(x_display, screen), &black);
# Line 1256 | Line 1525 | bool VideoInit(void)
1525          XSetErrorHandler(ignore_errors);
1526   #endif
1527  
1528 +        // Lock down frame buffer
1529 +        XSync(x_display, false);
1530 +        LOCK_FRAME_BUFFER;
1531 +
1532          // Start periodic thread
1533          XSync(x_display, false);
1534          Set_pthread_attr(&redraw_thread_attr, 0);
# Line 1280 | Line 1553 | void VideoExit(void)
1553                  redraw_thread_active = false;
1554          }
1555  
1556 +        // Unlock frame buffer
1557 +        UNLOCK_FRAME_BUFFER;
1558 +        XSync(x_display, false);
1559 +        D(bug(" frame buffer unlocked\n"));
1560 +
1561   #ifdef ENABLE_VOSF
1562          if (use_vosf) {
1563                  // Deinitialize VOSF
# Line 1294 | Line 1572 | void VideoExit(void)
1572                  XFlush(x_display);
1573                  XSync(x_display, false);
1574          }
1575 +
1576 + #ifdef ENABLE_FBDEV_DGA
1577 +        // Close framebuffer device
1578 +        if (fb_dev_fd >= 0) {
1579 +                close(fb_dev_fd);
1580 +                fb_dev_fd = -1;
1581 +        }
1582 + #endif
1583   }
1584  
1585  
# Line 1301 | Line 1587 | void VideoExit(void)
1587   *  Suspend/resume emulator
1588   */
1589  
1304 extern void PauseEmulator(void);
1305 extern void ResumeEmulator(void);
1306
1590   static void suspend_emul(void)
1591   {
1592          if (display_type == DIS_SCREEN) {
# Line 1311 | Line 1594 | static void suspend_emul(void)
1594                  ADBKeyUp(0x36);
1595                  ctrl_down = false;
1596  
1597 <                // Pause MacOS thread
1598 <                PauseEmulator();
1316 <                emul_suspended = true;
1597 >                // Lock frame buffer (this will stop the MacOS thread)
1598 >                LOCK_FRAME_BUFFER;
1599  
1600                  // Save frame buffer
1601                  fb_save = malloc(VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes);
# Line 1321 | Line 1603 | static void suspend_emul(void)
1603                          Mac2Host_memcpy(fb_save, screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes);
1604  
1605                  // Close full screen display
1606 + #if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA)
1607   #ifdef ENABLE_XF86_DGA
1608 <                XF86DGADirectVideo(x_display, screen, 0);
1608 >                if (!is_fbdev_dga_mode)
1609 >                        XF86DGADirectVideo(x_display, screen, 0);
1610 > #endif
1611                  XUngrabPointer(x_display, CurrentTime);
1612                  XUngrabKeyboard(x_display, CurrentTime);
1613   #endif
1614 +                restore_mouse_accel();
1615 +                XUnmapWindow(x_display, the_win);
1616 +                wait_unmapped(the_win);
1617                  XSync(x_display, false);
1618  
1619                  // Open "suspend" window
1620                  XSetWindowAttributes wattr;
1621                  wattr.event_mask = KeyPressMask;
1622 <                wattr.background_pixel = black_pixel;
1335 <                wattr.border_pixel = black_pixel;
1622 >                wattr.background_pixel = (vis == DefaultVisual(x_display, screen) ? black_pixel : 0);
1623                  wattr.backing_store = Always;
1624 <                wattr.backing_planes = xdepth;
1625 <                wattr.colormap = DefaultColormap(x_display, screen);
1339 <                XSync(x_display, false);
1624 >                wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]);
1625 >
1626                  suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth,
1627 <                        InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel |
1628 <                        CWBackingStore | CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr);
1629 <                XSync(x_display, false);
1630 <                XStoreName(x_display, suspend_win, GetString(STR_SUSPEND_WINDOW_TITLE));
1631 <                XMapRaised(x_display, suspend_win);
1346 <                XSync(x_display, false);
1627 >                                                                        InputOutput, vis, CWEventMask | CWBackPixel | CWBackingStore | CWColormap, &wattr);
1628 >                set_window_name(suspend_win, STR_SUSPEND_WINDOW_TITLE);
1629 >                set_window_focus(suspend_win);
1630 >                XMapWindow(x_display, suspend_win);
1631 >                emul_suspended = true;
1632          }
1633   }
1634  
# Line 1354 | Line 1639 | static void resume_emul(void)
1639          XSync(x_display, false);
1640  
1641          // Reopen full screen display
1642 <        XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime);
1643 <        XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
1642 >        XMapRaised(x_display, the_win);
1643 >        wait_mapped(the_win);
1644 >        XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0);
1645 >        Window w = is_fbdev_dga_mode ? the_win : rootwin;
1646 >        XGrabKeyboard(x_display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime);
1647 >        XGrabPointer(x_display, w, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
1648 >        disable_mouse_accel();
1649   #ifdef ENABLE_XF86_DGA
1650 <        XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse);
1651 <        XF86DGASetViewPort(x_display, screen, 0, 0);
1650 >        if (!is_fbdev_dga_mode) {
1651 >                XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse);
1652 >                XF86DGASetViewPort(x_display, screen, 0, 0);
1653 >        }
1654   #endif
1655          XSync(x_display, false);
1656  
# Line 1387 | Line 1679 | static void resume_emul(void)
1679          if (depth == 8)
1680                  palette_changed = true;
1681  
1682 <        // Resume MacOS thread
1682 >        // Unlock frame buffer (and continue MacOS thread)
1683 >        UNLOCK_FRAME_BUFFER;
1684          emul_suspended = false;
1392        ResumeEmulator();
1685   }
1686  
1687  
# Line 1705 | Line 1997 | void VideoVBL(void)
1997          if (emerg_quit)
1998                  QuitEmulator();
1999  
2000 +        // Temporarily give up frame buffer lock (this is the point where
2001 +        // we are suspended when the user presses Ctrl-Tab)
2002 +        UNLOCK_FRAME_BUFFER;
2003 +        LOCK_FRAME_BUFFER;
2004 +
2005          // Execute video VBL
2006          if (private_data != NULL && private_data->interruptsEnabled)
2007                  VSLDoInterruptService(private_data->vslServiceID);
# Line 1984 | Line 2281 | static void handle_palette_changes(void)
2281                  }
2282  
2283   #ifdef ENABLE_XF86_DGA
2284 <                if (display_type == DIS_SCREEN) {
2284 >                if (display_type == DIS_SCREEN && !is_fbdev_dga_mode) {
2285                          current_dga_cmap ^= 1;
2286                          if (!IsDirectMode(mode) && cmap[current_dga_cmap])
2287                                  XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
# Line 2029 | Line 2326 | static void *redraw_func(void *arg)
2326                                  quit_full_screen = false;
2327                                  if (display_type == DIS_SCREEN) {
2328                                          XDisplayLock();
2329 + #if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA)
2330   #ifdef ENABLE_XF86_DGA
2331 <                                        XF86DGADirectVideo(x_display, screen, 0);
2331 >                                        if (is_fbdev_dga_mode)
2332 >                                                XF86DGADirectVideo(x_display, screen, 0);
2333 > #endif
2334                                          XUngrabPointer(x_display, CurrentTime);
2335                                          XUngrabKeyboard(x_display, CurrentTime);
2336                                          XUnmapWindow(x_display, the_win);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines