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.34 by gbeauche, 2004-12-18T18:34:56Z vs.
Revision 1.52 by cebix, 2010-02-21T09:59:52Z

# Line 1 | Line 1
1   /*
2   *  video_x.cpp - Video/graphics emulation, X11 specific stuff
3   *
4 < *  SheepShaver (C) 1997-2004 Marc Hellwig and Christian Bauer
4 > *  SheepShaver (C) Marc Hellwig and 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 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 28 | Line 37
37   #include <sys/shm.h>
38   #include <errno.h>
39   #include <pthread.h>
40 + #include <semaphore.h>
41  
42   #include <algorithm>
43  
44 + #ifdef ENABLE_FBDEV_DGA
45 + # include <linux/fb.h>
46 + # include <sys/ioctl.h>
47 + #endif
48 +
49   #ifdef ENABLE_XF86_DGA
50 < # include <X11/extensions/xf86dga.h>
50 > # include <X11/extensions/Xxf86dga.h>
51   #endif
52  
53   #ifdef ENABLE_XF86_VIDMODE
54   # include <X11/extensions/xf86vmode.h>
55   #endif
56  
57 + #ifdef ENABLE_FBDEV_DGA
58 + # include <sys/mman.h>
59 + #endif
60 +
61   #include "main.h"
62   #include "adb.h"
63   #include "prefs.h"
# Line 69 | Line 88 | static pthread_attr_t redraw_thread_attr
88   static volatile bool redraw_thread_cancel;      // Flag: Cancel Redraw thread
89   static pthread_t redraw_thread;                         // Redraw thread
90  
72 static bool local_X11;                                          // Flag: X server running on local machine?
91   static volatile bool thread_stop_req = false;
92 < static volatile bool thread_stop_ack = false;   // Acknowledge for thread_stop_req
92 > static sem_t thread_stop_ack;
93 > static sem_t thread_resume_req;
94  
95 + static bool local_X11;                                          // Flag: X server running on local machine?
96   static bool has_dga = false;                            // Flag: Video DGA capable
97   static bool has_vidmode = false;                        // Flag: VidMode extension available
98  
# Line 109 | Line 129 | static int color_class;
129   static int rshift, rloss, gshift, gloss, bshift, bloss; // Pixel format of DirectColor/TrueColor modes
130   static Colormap cmap[2];                                        // Two colormaps (DGA) for 8-bit mode
131   static XColor x_palette[256];                           // Color palette to be used as CLUT and gamma table
132 + static int orig_accel_numer, orig_accel_denom, orig_threshold;  // Original mouse acceleration
133  
134   static XColor black, white;
135   static unsigned long black_pixel, white_pixel;
# Line 131 | Line 152 | static uint8 *the_buffer_copy = NULL;          /
152   static uint32 the_buffer_size;                          // Size of allocated the_buffer
153  
154   // Variables for DGA mode
155 + static bool is_fbdev_dga_mode = false;          // Flag: Use FBDev DGA mode?
156   static int current_dga_cmap;
157  
158 + #ifdef ENABLE_FBDEV_DGA
159 + static int fb_dev_fd = -1;                                              // Handle to fb device name
160 + static struct fb_fix_screeninfo fb_finfo;               // Fixed info
161 + static struct fb_var_screeninfo fb_vinfo;               // Variable info
162 + static struct fb_var_screeninfo fb_orig_vinfo;  // Variable info to restore later
163 + static struct fb_cmap fb_oldcmap;                               // Colormap to restore later
164 + #endif
165 +
166   #ifdef ENABLE_XF86_VIDMODE
167   // Variables for XF86 VidMode support
168   static XF86VidModeModeInfo **x_video_modes;             // Array of all available modes
# Line 140 | Line 170 | static int num_x_video_modes;
170   #endif
171  
172   // Mutex to protect palette
173 < #ifdef HAVE_SPINLOCKS
144 < static spinlock_t x_palette_lock = SPIN_LOCK_UNLOCKED;
145 < #define LOCK_PALETTE spin_lock(&x_palette_lock)
146 < #define UNLOCK_PALETTE spin_unlock(&x_palette_lock)
147 < #elif defined(HAVE_PTHREADS)
173 > #if defined(HAVE_PTHREADS)
174   static pthread_mutex_t x_palette_lock = PTHREAD_MUTEX_INITIALIZER;
175   #define LOCK_PALETTE pthread_mutex_lock(&x_palette_lock)
176   #define UNLOCK_PALETTE pthread_mutex_unlock(&x_palette_lock)
177 + #elif defined(HAVE_SPINLOCKS)
178 + static spinlock_t x_palette_lock = SPIN_LOCK_UNLOCKED;
179 + #define LOCK_PALETTE spin_lock(&x_palette_lock)
180 + #define UNLOCK_PALETTE spin_unlock(&x_palette_lock)
181   #else
182   #define LOCK_PALETTE
183   #define UNLOCK_PALETTE
184   #endif
185  
186 + // Mutex to protect frame buffer
187 + #if defined(HAVE_PTHREADS)
188 + static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
189 + #define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock);
190 + #define UNLOCK_FRAME_BUFFER pthread_mutex_unlock(&frame_buffer_lock);
191 + #elif defined(HAVE_SPINLOCKS)
192 + static spinlock_t frame_buffer_lock = SPIN_LOCK_UNLOCKED;
193 + #define LOCK_FRAME_BUFFER spin_lock(&frame_buffer_lock)
194 + #define UNLOCK_FRAME_BUFFER spin_unlock(&frame_buffer_lock)
195 + #else
196 + #define LOCK_FRAME_BUFFER
197 + #define UNLOCK_FRAME_BUFFER
198 + #endif
199 +
200  
201   // Prototypes
202   static void *redraw_func(void *arg);
# Line 364 | Line 408 | static bool find_visual_for_depth(int de
408   *  Open display (window or fullscreen)
409   */
410  
411 + // Set window name and class
412 + static void set_window_name(Window w, int name)
413 + {
414 +        const char *str = GetString(name);
415 +        XStoreName(x_display, w, str);
416 +        XSetIconName(x_display, w, str);
417 +
418 +        XClassHint *hints;
419 +        hints = XAllocClassHint();
420 +        if (hints) {
421 +                hints->res_name = "SheepShaver";
422 +                hints->res_class = "SheepShaver";
423 +                XSetClassHint(x_display, w, hints);
424 +                XFree(hints);
425 +        }
426 + }
427 +
428 + // Set window input focus flag
429 + static void set_window_focus(Window w)
430 + {
431 +        XWMHints *hints = XAllocWMHints();
432 +        if (hints) {
433 +                hints->input = True;
434 +                hints->initial_state = NormalState;
435 +                hints->flags = InputHint | StateHint;
436 +                XSetWMHints(x_display, w, hints);
437 +                XFree(hints);
438 +        }
439 + }
440 +
441   // Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget)
442   static Atom WM_DELETE_WINDOW = (Atom)0;
443   static void set_window_delete_protocol(Window w)
# Line 389 | Line 463 | static void wait_unmapped(Window w)
463          } while ((e.type != UnmapNotify) || (e.xmap.event != w));
464   }
465  
466 + // Disable mouse acceleration
467 + static void disable_mouse_accel(void)
468 + {
469 +        XChangePointerControl(x_display, True, False, 1, 1, 0);
470 + }
471 +
472 + // Restore mouse acceleration to original value
473 + static void restore_mouse_accel(void)
474 + {
475 +        XChangePointerControl(x_display, True, True, orig_accel_numer, orig_accel_denom, orig_threshold);
476 + }
477 +
478   // Trap SHM errors
479   static bool shm_error = false;
480   static int (*old_error_handler)(Display *, XErrorEvent *);
# Line 421 | Line 507 | static bool open_window(int width, int h
507          the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
508                  InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | CWBackingStore | CWColormap, &wattr);
509  
510 <        // Set window name
511 <        XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE));
510 >        // Set window name/class
511 >        set_window_name(the_win, STR_WINDOW_TITLE);
512 >
513 >        // Indicate that we want keyboard input
514 >        set_window_focus(the_win);
515  
516          // Set delete protocol property
517          set_window_delete_protocol(the_win);
# Line 550 | Line 639 | static bool open_window(int width, int h
639          return true;
640   }
641  
642 < // Open DGA display (!! should use X11 VidMode extensions to set mode)
643 < static bool open_dga(int width, int height)
642 > // Open FBDev DGA display
643 > static bool open_fbdev_dga(int width, int height)
644 > {
645 > #ifdef ENABLE_FBDEV_DGA
646 > #ifdef ENABLE_XF86_VIDMODE
647 >        // Switch to best mode
648 >        if (has_vidmode) {
649 >                int best = -1;
650 >                for (int i = 0; i < num_x_video_modes; i++) {
651 >                        if (x_video_modes[i]->hdisplay == width && x_video_modes[i]->vdisplay == height) {
652 >                                best = i;
653 >                                break;
654 >                        }
655 >                };
656 >                assert(best != -1);
657 >                XF86VidModeSwitchToMode(x_display, screen, x_video_modes[best]);
658 >                XF86VidModeSetViewPort(x_display, screen, 0, 0);
659 >                D(bug("[fbdev] VideoMode %d: %d x %d @ %d\n", best,
660 >                          x_video_modes[best]->hdisplay, x_video_modes[best]->vdisplay,
661 >                          1000 * x_video_modes[best]->dotclock / (x_video_modes[best]->htotal * x_video_modes[best]->vtotal)));
662 >        }
663 > #endif
664 >
665 >        if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo) != 0) {
666 >                D(bug("[fbdev] Can't get FSCREENINFO: %s\n", strerror(errno)));
667 >                return false;
668 >        }
669 >        D(bug("[fbdev] Device ID: %s\n", fb_finfo.id));
670 >        D(bug("[fbdev] smem_start: %p [%d bytes]\n", fb_finfo.smem_start, fb_finfo.smem_len));
671 >
672 >        int fb_type = fb_finfo.type;
673 >        const char *fb_type_str = NULL;
674 >        switch (fb_type) {
675 >        case FB_TYPE_PACKED_PIXELS:                     fb_type_str = "Packed Pixels";                  break;
676 >        case FB_TYPE_PLANES:                            fb_type_str = "Non interleaved planes"; break;
677 >        case FB_TYPE_INTERLEAVED_PLANES:        fb_type_str = "Interleaved planes";             break;
678 >        case FB_TYPE_TEXT:                                      fb_type_str = "Text/attributes";                break;
679 >        case FB_TYPE_VGA_PLANES:                        fb_type_str = "EGA/VGA planes";                 break;
680 >        default:                                                        fb_type_str = "<unknown>";                              break;
681 >        }
682 >        D(bug("[fbdev] type: %s\n", fb_type_str));
683 >
684 >        if (fb_type != FB_TYPE_PACKED_PIXELS) {
685 >                D(bug("[fbdev] type '%s' not supported\n", fb_type_str));
686 >                return false;
687 >        }
688 >
689 >        int fb_visual = fb_finfo.visual;
690 >        const char *fb_visual_str;
691 >        switch (fb_visual) {
692 >        case FB_VISUAL_MONO01:                          fb_visual_str = "Monochrome 1=Black 0=White";   break;
693 >        case FB_VISUAL_MONO10:                          fb_visual_str = "Monochrome 1=While 0=Black";   break;
694 >        case FB_VISUAL_TRUECOLOR:                       fb_visual_str = "True color";                                   break;
695 >        case FB_VISUAL_PSEUDOCOLOR:                     fb_visual_str = "Pseudo color (like atari)";    break;
696 >        case FB_VISUAL_DIRECTCOLOR:                     fb_visual_str = "Direct color";                                 break;
697 >        case FB_VISUAL_STATIC_PSEUDOCOLOR:      fb_visual_str = "Pseudo color readonly";                break;
698 >        default:                                                        fb_visual_str = "<unknown>";                                    break;
699 >        }
700 >        D(bug("[fbdev] visual: %s\n", fb_visual_str));
701 >
702 >        if (fb_visual != FB_VISUAL_TRUECOLOR && fb_visual != FB_VISUAL_DIRECTCOLOR) {
703 >                D(bug("[fbdev] visual '%s' not supported\n", fb_visual_str));
704 >                return false;
705 >        }
706 >        
707 >        // Map frame buffer
708 >        the_buffer = (uint8 *)mmap(NULL, fb_finfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb_dev_fd, 0);
709 >        if (the_buffer == MAP_FAILED) {
710 >                D(bug("[fbdev] Can't mmap /dev/fb0: %s\n", strerror(errno)));
711 >                return false;
712 >        }
713 >
714 >        // Set absolute mouse mode
715 >        ADBSetRelMouseMode(false);
716 >
717 >        // Create window
718 >        XSetWindowAttributes wattr;
719 >        wattr.event_mask = eventmask = dga_eventmask;
720 >        wattr.override_redirect = True;
721 >        the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
722 >                                                        InputOutput, DefaultVisual(x_display, screen),
723 >                                                        CWEventMask | CWOverrideRedirect, &wattr);
724 >
725 >        // Show window
726 >        XMapRaised(x_display, the_win);
727 >        wait_mapped(the_win);
728 >
729 >        // Grab mouse and keyboard
730 >        XGrabKeyboard(x_display, the_win, True,
731 >                                  GrabModeAsync, GrabModeAsync, CurrentTime);
732 >        XGrabPointer(x_display, the_win, True,
733 >                                 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
734 >                                 GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime);
735 >        disable_mouse_accel();
736 >
737 >        // Create no_cursor
738 >        mac_cursor = XCreatePixmapCursor(x_display,
739 >                                                                         XCreatePixmap(x_display, the_win, 1, 1, 1),
740 >                                                                         XCreatePixmap(x_display, the_win, 1, 1, 1),
741 >                                                                         &black, &white, 0, 0);
742 >        XDefineCursor(x_display, the_win, mac_cursor);
743 >
744 >        // Init blitting routines
745 >        int bytes_per_row = TrivialBytesPerRow((width + 7) & ~7, DepthModeForPixelDepth(depth));
746 > #if ENABLE_VOSF
747 >        // Extract current screen color masks (we are in True Color mode)
748 >        VisualFormat visualFormat;
749 >        visualFormat.depth = xdepth = DefaultDepth(x_display, screen);
750 >        XMatchVisualInfo(x_display, screen, xdepth, TrueColor, &visualInfo);
751 >        assert(visualFormat.depth == visualInfo.depth);
752 >        visualFormat.Rmask = visualInfo.red_mask;
753 >        visualFormat.Gmask = visualInfo.green_mask;
754 >        visualFormat.Bmask = visualInfo.blue_mask;
755 >        D(bug("[fbdev] %d bpp, (%08x,%08x,%08x)\n",
756 >                  visualFormat.depth,
757 >                  visualFormat.Rmask, visualFormat.Gmask, visualFormat.Bmask));
758 >        D(bug("[fbdev] Mac depth %d bpp\n", depth));
759 >
760 >        // Screen_blitter_init() returns TRUE if VOSF is mandatory
761 >        // i.e. the framebuffer update function is not Blit_Copy_Raw
762 > #ifdef WORDS_BIGENDIAN
763 >        const bool native_byte_order = (XImageByteOrder(x_display) == MSBFirst);
764 > #else
765 >        const bool native_byte_order = (XImageByteOrder(x_display) == LSBFirst);
766 > #endif
767 >        Screen_blitter_init(visualFormat, native_byte_order, depth);
768 >        
769 >        // Allocate memory for frame buffer (SIZE is extended to page-boundary)
770 >        use_vosf = true;
771 >        the_host_buffer = the_buffer;
772 >        the_buffer_size = page_extend((height + 2) * bytes_per_row);
773 >        the_buffer_copy = (uint8 *)malloc(the_buffer_size);
774 >        the_buffer = (uint8 *)vm_acquire(the_buffer_size);
775 >        D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
776 > #endif
777 >
778 >        // Set frame buffer base
779 >        D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf));
780 >        screen_base = Host2MacAddr(the_buffer);
781 >        VModes[cur_mode].viRowBytes = bytes_per_row;
782 >        return true;
783 > #else
784 >        ErrorAlert("SheepShaver has been compiled with DGA support disabled.");
785 >        return false;
786 > #endif
787 > }
788 >
789 > // Open XF86 DGA display (!! should use X11 VidMode extensions to set mode)
790 > static bool open_xf86_dga(int width, int height)
791   {
792 +        if (is_fbdev_dga_mode)
793 +                return false;
794 +
795   #ifdef ENABLE_XF86_DGA
796          // Set relative mouse mode
797          ADBSetRelMouseMode(true);
# Line 642 | Line 881 | static bool open_dga(int width, int heig
881   #endif
882   }
883  
884 + // Open DGA display
885 + static bool open_dga(int width, int height)
886 + {
887 +        bool display_open;
888 +
889 +        display_open = open_xf86_dga(width, height);
890 + #ifdef ENABLE_FBDEV_DGA
891 +        // Try to fallback to FBDev DGA mode
892 +        if (!display_open) {
893 +                is_fbdev_dga_mode = true;
894 +                display_open = open_fbdev_dga(width, height);
895 +        }
896 + #endif
897 +
898 +        // Common DGA display initialization
899 +        if (display_open) {
900 +
901 +                // Fake image to get display bounds in the refresh function
902 +                if ((img = (XImage *)malloc(sizeof(*img))) == NULL)
903 +                        return false;
904 +                img->width = DisplayWidth(x_display, screen);
905 +                img->height = DisplayHeight(x_display, screen);
906 +                img->depth = is_fbdev_dga_mode ? xdepth : depth;
907 +                img->bytes_per_line = TrivialBytesPerRow(img->width, DepthModeForPixelDepth(img->depth));
908 +        }
909 +
910 +        return display_open;
911 + }
912 +
913   static bool open_display(void)
914   {
915          D(bug("open_display()\n"));
916          const VideoInfo &mode = VModes[cur_mode];
917  
918 +        // Get original mouse acceleration
919 +        XGetPointerControl(x_display, &orig_accel_numer, &orig_accel_denom, &orig_threshold);
920 +
921          // Find best available X visual
922          if (!find_visual_for_depth(mode.viAppleMode)) {
923                  ErrorAlert(GetString(STR_NO_XVISUAL_ERR));
# Line 654 | Line 925 | static bool open_display(void)
925          }
926  
927          // Build up visualFormat structure
928 +        visualFormat.fullscreen = (display_type == DIS_SCREEN);
929          visualFormat.depth = visualInfo.depth;
930          visualFormat.Rmask = visualInfo.red_mask;
931          visualFormat.Gmask = visualInfo.green_mask;
# Line 726 | Line 998 | static bool open_display(void)
998          display_type = mode.viType;
999          depth = depth_of_video_mode(mode.viAppleMode);
1000  
1001 <        bool display_open = false;
1002 <        if (display_type == DIS_SCREEN)
1001 >        bool display_open;
1002 >        switch (display_type) {
1003 >        case DIS_SCREEN:
1004                  display_open = open_dga(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize);
1005 <        else if (display_type == DIS_WINDOW)
1005 >                break;
1006 >        case DIS_WINDOW:
1007                  display_open = open_window(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize);
1008 +                break;
1009 +        default:
1010 +                display_open = false;
1011 +                break;
1012 +        }
1013  
1014   #ifdef ENABLE_VOSF
1015          if (use_vosf) {
1016                  // Initialize the VOSF system
1017 +                LOCK_VOSF;
1018                  if (!video_vosf_init()) {
1019                          ErrorAlert(GetString(STR_VOSF_INIT_ERR));
1020 +                        UNLOCK_VOSF;
1021                          return false;
1022                  }
1023 +                UNLOCK_VOSF;
1024          }
1025   #endif
1026 <        
1026 >
1027 >        // Zero screen buffers, viRowBytes is initialized at this stage
1028 >        if (display_open) {
1029 >                memset(the_buffer, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize);
1030 >                memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize);
1031 >        }
1032          return display_open;
1033   }
1034  
# Line 777 | Line 1064 | static void close_window(void)
1064          XSync(x_display, false);
1065   }
1066  
1067 < // Close DGA mode
1068 < static void close_dga(void)
1067 > // Close FBDev mode
1068 > static void close_fbdev_dga(void)
1069 > {
1070 > #ifdef ENABLE_FBDEV_DGA
1071 >        uint8 *fb_base;
1072 >        if (!use_vosf)
1073 >                fb_base = the_buffer;
1074 > #ifdef ENABLE_VOSF
1075 >        else
1076 >                fb_base = the_host_buffer;
1077 > #endif
1078 >        munmap(fb_base, fb_finfo.smem_len);
1079 > #endif
1080 > }
1081 >
1082 > // Close XF86 DGA mode
1083 > static void close_xf86_dga(void)
1084   {
1085   #ifdef ENABLE_XF86_DGA
1086          XF86DGADirectVideo(x_display, screen, 0);
1087 + #endif
1088 + }
1089 +
1090 + // Close DGA mode
1091 + static void close_dga(void)
1092 + {
1093 +        if (is_fbdev_dga_mode)
1094 +                close_fbdev_dga();
1095 +        else
1096 +                close_xf86_dga();
1097 +
1098          XUngrabPointer(x_display, CurrentTime);
1099          XUngrabKeyboard(x_display, CurrentTime);
787 #endif
1100  
1101   #ifdef ENABLE_XF86_VIDMODE
1102          if (has_vidmode)
1103                  XF86VidModeSwitchToMode(x_display, screen, x_video_modes[0]);
1104   #endif
1105  
1106 +        // Release fake image (it's not a normal XImage!)
1107 +        free(img);
1108 +        img = NULL;
1109 +
1110          if (!use_vosf) {
1111                  // don't free() the screen buffer in driver_base dtor
1112                  the_buffer = NULL;
# Line 861 | Line 1177 | static void close_display(void)
1177                  }
1178          }
1179   #endif
1180 +
1181 +        // Restore mouse acceleration
1182 +        restore_mouse_accel();
1183   }
1184  
1185  
# Line 970 | Line 1289 | static int find_mode(int apple_mode, int
1289          return -1;
1290   }
1291  
1292 + // Add custom video mode
1293 + static void add_custom_mode(VideoInfo *&p, int type, uint32 x, uint32 y, int apple_mode, int apple_id)
1294 + {
1295 +        p->viType = type;
1296 +        p->viXsize = x;
1297 +        p->viYsize = y;
1298 +        p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode);
1299 +        p->viAppleMode = apple_mode;
1300 +        p->viAppleID = apple_id;
1301 +        p++;
1302 + }
1303 +
1304   // Add mode to list of supported modes
1305   static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type)
1306   {
1307          if (allow & test) {
1308 <                p->viType = type;
1308 >                uint32 x = 0, y = 0;
1309                  switch (apple_id) {
1310                          case APPLE_W_640x480:
1311                          case APPLE_640x480:
1312 <                                p->viXsize = 640;
1313 <                                p->viYsize = 480;
1312 >                                x = 640;
1313 >                                y = 480;
1314                                  break;
1315                          case APPLE_W_800x600:
1316                          case APPLE_800x600:
1317 <                                p->viXsize = 800;
1318 <                                p->viYsize = 600;
1317 >                                x = 800;
1318 >                                y = 600;
1319                                  break;
1320                          case APPLE_1024x768:
1321 <                                p->viXsize = 1024;
1322 <                                p->viYsize = 768;
1321 >                                x = 1024;
1322 >                                y = 768;
1323                                  break;
1324                          case APPLE_1152x768:
1325 <                                p->viXsize = 1152;
1326 <                                p->viYsize = 768;
1325 >                                x = 1152;
1326 >                                y = 768;
1327                                  break;
1328                          case APPLE_1152x900:
1329 <                                p->viXsize = 1152;
1330 <                                p->viYsize = 900;
1329 >                                x = 1152;
1330 >                                y = 900;
1331                                  break;
1332                          case APPLE_1280x1024:
1333 <                                p->viXsize = 1280;
1334 <                                p->viYsize = 1024;
1333 >                                x = 1280;
1334 >                                y = 1024;
1335                                  break;
1336                          case APPLE_1600x1200:
1337 <                                p->viXsize = 1600;
1338 <                                p->viYsize = 1200;
1337 >                                x = 1600;
1338 >                                y = 1200;
1339                                  break;
1340                  }
1341 <                p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode);
1011 <                p->viAppleMode = apple_mode;
1012 <                p->viAppleID = apple_id;
1013 <                p++;
1341 >                add_custom_mode(p, type, x, y, apple_mode, apple_id);
1342          }
1343   }
1344  
# Line 1024 | Line 1352 | static void add_window_modes(VideoInfo *
1352   static bool has_mode(int x, int y)
1353   {
1354   #ifdef ENABLE_XF86_VIDMODE
1355 <        for (int i=0; i<num_x_video_modes; i++)
1356 <                if (x_video_modes[i]->hdisplay >= x && x_video_modes[i]->vdisplay >= y)
1357 <                        return true;
1358 <        return false;
1359 < #else
1360 <        return DisplayWidth(x_display, screen) >= x && DisplayHeight(x_display, screen) >= y;
1355 >        if (has_vidmode) {
1356 >                for (int i=0; i<num_x_video_modes; i++)
1357 >                        if (x_video_modes[i]->hdisplay == x && x_video_modes[i]->vdisplay == y)
1358 >                                return true;
1359 >                return false;
1360 >        }
1361   #endif
1362 +        return DisplayWidth(x_display, screen) >= x && DisplayHeight(x_display, screen) >= y;
1363   }
1364  
1365   bool VideoInit(void)
# Line 1043 | Line 1372 | bool VideoInit(void)
1372          
1373          // Check if X server runs on local machine
1374          local_X11 = (strncmp(XDisplayName(x_display_name), ":", 1) == 0)
1375 +                 || (strncmp(XDisplayName(x_display_name), "/", 1) == 0)
1376                   || (strncmp(XDisplayName(x_display_name), "unix:", 5) == 0);
1377      
1378          // Init keycode translation
# Line 1079 | Line 1409 | bool VideoInit(void)
1409   #ifdef ENABLE_XF86_DGA
1410          // DGA available?
1411      int event_base, error_base;
1412 +    is_fbdev_dga_mode = false;
1413      if (local_X11 && XF86DGAQueryExtension(x_display, &event_base, &error_base)) {
1414                  int dga_flags = 0;
1415                  XF86DGAQueryDirectVideo(x_display, screen, &dga_flags);
1416                  has_dga = dga_flags & XF86DGADirectPresent;
1417 + #if defined(__linux__)
1418 +                // Check r/w permission on /dev/mem for DGA mode to work
1419 +                if (has_dga && access("/dev/mem", R_OK | W_OK) != 0)
1420 +                        has_dga = false;
1421 + #endif
1422          } else
1423                  has_dga = false;
1424   #endif
# Line 1091 | Line 1427 | bool VideoInit(void)
1427          // VidMode available?
1428          int vm_event_base, vm_error_base;
1429          has_vidmode = XF86VidModeQueryExtension(x_display, &vm_event_base, &vm_error_base);
1430 <        if (has_vidmode)
1430 >        if (has_vidmode) {
1431 >                int vm_major_version, vm_minor_version;
1432 >                XF86VidModeQueryVersion(x_display, &vm_major_version, &vm_minor_version);
1433 >                D(bug("VidMode extension %d.%d available\n", vm_major_version, vm_minor_version));
1434                  XF86VidModeGetAllModeLines(x_display, screen, &num_x_video_modes, &x_video_modes);
1435 +        }
1436 + #endif
1437 +
1438 + #ifdef ENABLE_FBDEV_DGA
1439 +        // FBDev available?
1440 +        bool has_fbdev_dga = false;
1441 +        if (local_X11) {
1442 +                if ((fb_dev_fd = open("/dev/fb0", O_RDWR)) > 0) {
1443 +                        if (ioctl(fb_dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo) != 0)
1444 +                                close(fb_dev_fd);
1445 +                        else {
1446 +                                has_fbdev_dga = true;
1447 +                                if (!has_dga) {
1448 +                                        // Fallback to FBDev DGA mode if XF86 DGA is not possible
1449 +                                        has_dga = true;
1450 +                                        is_fbdev_dga_mode = true;
1451 +                                }
1452 +                                fb_orig_vinfo = fb_vinfo;
1453 +                                D(bug("Frame buffer device initial resolution: %dx%dx%d\n", fb_vinfo.xres, fb_vinfo.yres, fb_vinfo.bits_per_pixel));
1454 +                        }
1455 +                }
1456 +        }
1457   #endif
1458  
1459          // Find black and white colors
# Line 1120 | Line 1481 | bool VideoInit(void)
1481                  break;
1482          }
1483  
1484 +        // Get screen mode from preferences
1485 +        const char *mode_str = PrefsFindString("screen");
1486 +        int default_width = 640, default_height = 480;
1487 +        if (mode_str) {
1488 +                display_type = DIS_INVALID;
1489 +                if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2)
1490 +                        display_type = DIS_WINDOW;
1491 + #ifdef ENABLE_XF86_DGA
1492 +                else if (has_dga && sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2)
1493 +                        display_type = DIS_SCREEN;
1494 + #endif
1495 + #ifdef ENABLE_FBDEV_DGA
1496 +                else if (has_fbdev_dga && sscanf(mode_str, "fbdev/%d/%d", &default_width, &default_height) == 2) {
1497 +                        is_fbdev_dga_mode = true;
1498 +                        display_type = DIS_SCREEN;
1499 +                }
1500 + #endif
1501 +                if (display_type == DIS_INVALID) {
1502 +                        D(bug("Invalid screen mode specified, defaulting to old modes selection\n"));
1503 +                        mode_str = NULL;
1504 +                }
1505 +                else {
1506 +                        if (default_width <= 0)
1507 +                                default_width = DisplayWidth(x_display, screen);
1508 +                        else if (default_width > DisplayWidth(x_display, screen))
1509 +                                default_width = DisplayWidth(x_display, screen);
1510 +                        if (default_height <= 0)
1511 +                                default_height = DisplayHeight(x_display, screen);
1512 +                        else if (default_height > DisplayHeight(x_display, screen))
1513 +                                default_height = DisplayHeight(x_display, screen);
1514 +                }
1515 +        }
1516 +
1517          // Construct video mode table
1518          uint32 window_modes = PrefsFindInt32("windowmodes");
1519          uint32 screen_modes = PrefsFindInt32("screenmodes");
1520          if (!has_dga)
1521                  screen_modes = 0;
1522 <        if (window_modes == 0 && screen_modes == 0)
1522 >        if (mode_str)
1523 >                window_modes = screen_modes = 0;
1524 >        else if (window_modes == 0 && screen_modes == 0)
1525                  window_modes |= 3;      // Allow at least 640x480 and 800x600 window modes
1526  
1527          VideoInfo *p = VModes;
1528 <        for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++)
1529 <                if (find_visual_for_depth(d))
1530 <                        add_window_modes(p, window_modes, d);
1528 >        if (mode_str) {
1529 >                if (display_type == DIS_WINDOW) {
1530 >                        for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) {
1531 >                                if (find_visual_for_depth(d)) {
1532 >                                        if (default_width > 640 && default_height > 480)
1533 >                                                add_mode(p, 3, 1, d, APPLE_W_640x480, DIS_WINDOW);
1534 >                                        if (default_width > 800 && default_height > 600)
1535 >                                                add_mode(p, 3, 2, d, APPLE_W_800x600, DIS_WINDOW);
1536 >                                        add_custom_mode(p, display_type, default_width, default_height, d, APPLE_CUSTOM);
1537 >                                }
1538 >                        }
1539 > #ifdef ENABLE_VOSF
1540 >                } else if (display_type == DIS_SCREEN && is_fbdev_dga_mode) {
1541 >                        for (unsigned int d = APPLE_1_BIT; d <= default_mode; d++)
1542 >                                if (find_visual_for_depth(d))
1543 >                                        add_custom_mode(p, display_type, default_width, default_height, d, APPLE_CUSTOM);
1544 > #endif
1545 >                } else
1546 >                        add_custom_mode(p, display_type, default_width, default_height, default_mode, APPLE_CUSTOM);
1547  
1548 <        if (has_vidmode) {
1548 >                // Add extra VidMode capable modes
1549 >                if (display_type == DIS_SCREEN) {
1550 >                        struct {
1551 >                                int w;
1552 >                                int h;
1553 >                                int apple_id;
1554 >                        }
1555 >                        video_modes[] = {
1556 >                                {  640,  480, APPLE_640x480   },
1557 >                                {  800,  600, APPLE_800x600   },
1558 >                                { 1024,  768, APPLE_1024x768  },
1559 >                                { 1152,  768, APPLE_1152x768  },
1560 >                                { 1152,  900, APPLE_1152x900  },
1561 >                                { 1280, 1024, APPLE_1280x1024 },
1562 >                                { 1600, 1200, APPLE_1600x1200 },
1563 >                                { 0, }
1564 >                        };
1565 >
1566 >                        for (int i = 0; video_modes[i].w != 0; i++) {
1567 >                                const int w = video_modes[i].w;
1568 >                                const int h = video_modes[i].h;
1569 >                                if (w >= default_width || h >= default_height)
1570 >                                        continue;
1571 >                                if (has_mode(w, h)) {
1572 > #ifdef ENABLE_VOSF
1573 >                                        if (is_fbdev_dga_mode) {
1574 >                                                for (unsigned int d = APPLE_1_BIT; d <= default_mode; d++)
1575 >                                                        if (find_visual_for_depth(d))
1576 >                                                                add_custom_mode(p, display_type, w, h, d, video_modes[i].apple_id);
1577 >                                        } else
1578 > #endif
1579 >                                                add_custom_mode(p, display_type, w, h, default_mode, video_modes[i].apple_id);
1580 >                                }
1581 >                        }
1582 >                }
1583 >        } else if (window_modes) {
1584 >                for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++)
1585 >                        if (find_visual_for_depth(d))
1586 >                                add_window_modes(p, window_modes, d);
1587 >        } else if (has_vidmode) {
1588                  if (has_mode(640, 480))
1589                          add_mode(p, screen_modes, 1, default_mode, APPLE_640x480, DIS_SCREEN);
1590                  if (has_mode(800, 600))
# Line 1174 | Line 1625 | bool VideoInit(void)
1625                  int apple_id = find_apple_resolution(screen_width, screen_height);
1626                  if (apple_id != -1)
1627                          cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN);
1628 <        }
1628 >        } else if (has_dga && mode_str)
1629 >                cur_mode = find_mode(default_mode, APPLE_CUSTOM, DIS_SCREEN);
1630 >
1631          if (cur_mode == -1) {
1632                  // pick up first windowed mode available
1633                  for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) {
# Line 1195 | Line 1648 | bool VideoInit(void)
1648   #endif
1649  
1650          // Open window/screen
1651 <        if (!open_display())
1651 >        if (!open_display()) {
1652 >                ErrorAlert(GetString(STR_OPEN_WINDOW_ERR));
1653                  return false;
1654 +        }
1655  
1656   #if 0
1657          // Ignore errors from now on
1658          XSetErrorHandler(ignore_errors);
1659   #endif
1660  
1661 +        // Lock down frame buffer
1662 +        XSync(x_display, false);
1663 +        LOCK_FRAME_BUFFER;
1664 +
1665          // Start periodic thread
1666          XSync(x_display, false);
1667 +        if (sem_init(&thread_stop_ack, 0, 0) < 0)
1668 +                return false;
1669 +        if (sem_init(&thread_resume_req, 0, 0) < 0)
1670 +                return false;
1671          Set_pthread_attr(&redraw_thread_attr, 0);
1672          redraw_thread_cancel = false;
1673          redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0);
# Line 1224 | Line 1687 | void VideoExit(void)
1687                  redraw_thread_cancel = true;
1688                  pthread_cancel(redraw_thread);
1689                  pthread_join(redraw_thread, NULL);
1690 +                sem_destroy(&thread_stop_ack);
1691 +                sem_destroy(&thread_resume_req);
1692                  redraw_thread_active = false;
1693          }
1694  
1695 +        // Unlock frame buffer
1696 +        UNLOCK_FRAME_BUFFER;
1697 +        XSync(x_display, false);
1698 +        D(bug(" frame buffer unlocked\n"));
1699 +
1700   #ifdef ENABLE_VOSF
1701          if (use_vosf) {
1702                  // Deinitialize VOSF
# Line 1241 | Line 1711 | void VideoExit(void)
1711                  XFlush(x_display);
1712                  XSync(x_display, false);
1713          }
1714 +
1715 + #ifdef ENABLE_FBDEV_DGA
1716 +        // Close framebuffer device
1717 +        if (fb_dev_fd >= 0) {
1718 +                close(fb_dev_fd);
1719 +                fb_dev_fd = -1;
1720 +        }
1721 + #endif
1722   }
1723  
1724  
# Line 1248 | Line 1726 | void VideoExit(void)
1726   *  Suspend/resume emulator
1727   */
1728  
1251 extern void PauseEmulator(void);
1252 extern void ResumeEmulator(void);
1253
1729   static void suspend_emul(void)
1730   {
1731          if (display_type == DIS_SCREEN) {
# Line 1258 | Line 1733 | static void suspend_emul(void)
1733                  ADBKeyUp(0x36);
1734                  ctrl_down = false;
1735  
1736 <                // Pause MacOS thread
1737 <                PauseEmulator();
1263 <                emul_suspended = true;
1736 >                // Lock frame buffer (this will stop the MacOS thread)
1737 >                LOCK_FRAME_BUFFER;
1738  
1739                  // Save frame buffer
1740                  fb_save = malloc(VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes);
# Line 1268 | Line 1742 | static void suspend_emul(void)
1742                          Mac2Host_memcpy(fb_save, screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes);
1743  
1744                  // Close full screen display
1745 + #if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA)
1746   #ifdef ENABLE_XF86_DGA
1747 <                XF86DGADirectVideo(x_display, screen, 0);
1747 >                if (!is_fbdev_dga_mode)
1748 >                        XF86DGADirectVideo(x_display, screen, 0);
1749 > #endif
1750                  XUngrabPointer(x_display, CurrentTime);
1751                  XUngrabKeyboard(x_display, CurrentTime);
1752   #endif
1753 +                restore_mouse_accel();
1754 +                XUnmapWindow(x_display, the_win);
1755 +                wait_unmapped(the_win);
1756                  XSync(x_display, false);
1757  
1758                  // Open "suspend" window
1759                  XSetWindowAttributes wattr;
1760                  wattr.event_mask = KeyPressMask;
1761 <                wattr.background_pixel = black_pixel;
1282 <                wattr.border_pixel = black_pixel;
1761 >                wattr.background_pixel = (vis == DefaultVisual(x_display, screen) ? black_pixel : 0);
1762                  wattr.backing_store = Always;
1763 <                wattr.backing_planes = xdepth;
1764 <                wattr.colormap = DefaultColormap(x_display, screen);
1286 <                XSync(x_display, false);
1763 >                wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]);
1764 >
1765                  suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth,
1766 <                        InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel |
1767 <                        CWBackingStore | CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr);
1768 <                XSync(x_display, false);
1769 <                XStoreName(x_display, suspend_win, GetString(STR_SUSPEND_WINDOW_TITLE));
1770 <                XMapRaised(x_display, suspend_win);
1293 <                XSync(x_display, false);
1766 >                                                                        InputOutput, vis, CWEventMask | CWBackPixel | CWBackingStore | CWColormap, &wattr);
1767 >                set_window_name(suspend_win, STR_SUSPEND_WINDOW_TITLE);
1768 >                set_window_focus(suspend_win);
1769 >                XMapWindow(x_display, suspend_win);
1770 >                emul_suspended = true;
1771          }
1772   }
1773  
# Line 1301 | Line 1778 | static void resume_emul(void)
1778          XSync(x_display, false);
1779  
1780          // Reopen full screen display
1781 <        XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime);
1782 <        XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
1781 >        XMapRaised(x_display, the_win);
1782 >        wait_mapped(the_win);
1783 >        XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0);
1784 >        Window w = is_fbdev_dga_mode ? the_win : rootwin;
1785 >        XGrabKeyboard(x_display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime);
1786 >        XGrabPointer(x_display, w, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, is_fbdev_dga_mode ? w : None, None, CurrentTime);
1787 >        disable_mouse_accel();
1788   #ifdef ENABLE_XF86_DGA
1789 <        XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse);
1790 <        XF86DGASetViewPort(x_display, screen, 0, 0);
1789 >        if (!is_fbdev_dga_mode) {
1790 >                XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse);
1791 >                XF86DGASetViewPort(x_display, screen, 0, 0);
1792 >        }
1793   #endif
1794          XSync(x_display, false);
1795  
# Line 1316 | Line 1800 | static void resume_emul(void)
1800          if (use_vosf) {
1801                  LOCK_VOSF;
1802                  PFLAG_SET_ALL;
1319                UNLOCK_VOSF;
1803                  memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize);
1804 +                UNLOCK_VOSF;
1805          }
1806   #endif
1807          
# Line 1331 | Line 1815 | static void resume_emul(void)
1815                  free(fb_save);
1816                  fb_save = NULL;
1817          }
1334        if (depth == 8)
1335                palette_changed = true;
1818  
1819 <        // Resume MacOS thread
1819 >        // Unlock frame buffer (and continue MacOS thread)
1820 >        UNLOCK_FRAME_BUFFER;
1821          emul_suspended = false;
1339        ResumeEmulator();
1822   }
1823  
1824  
# Line 1633 | Line 2115 | static void handle_events(void)
2115                                  if (use_vosf) {                 // VOSF refresh
2116                                          LOCK_VOSF;
2117                                          PFLAG_SET_ALL;
2118 +                                        memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize);
2119                                          UNLOCK_VOSF;
2120                                  }
2121 +                                else
2122   #endif
2123 <                                memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize);
2123 >                                        memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize);
2124                                  break;
2125                  }
2126          }
# Line 1652 | Line 2136 | void VideoVBL(void)
2136          if (emerg_quit)
2137                  QuitEmulator();
2138  
2139 +        // Temporarily give up frame buffer lock (this is the point where
2140 +        // we are suspended when the user presses Ctrl-Tab)
2141 +        UNLOCK_FRAME_BUFFER;
2142 +        LOCK_FRAME_BUFFER;
2143 +
2144          // Execute video VBL
2145          if (private_data != NULL && private_data->interruptsEnabled)
2146                  VSLDoInterruptService(private_data->vslServiceID);
# Line 1677 | Line 2166 | int16 video_mode_change(VidLocals *csSav
2166                          csSave->savePage = ReadMacInt16(ParamPtr + csPage);
2167  
2168                          // Disable interrupts and pause redraw thread
1680                        DisableInterrupt();
1681                        thread_stop_ack = false;
2169                          thread_stop_req = true;
2170 <                        while (!thread_stop_ack) ;
2170 >                        sem_wait(&thread_stop_ack);
2171 >                        thread_stop_req = false;
2172 >                        DisableInterrupt();
2173  
2174                          /* close old display */
2175                          close_display();
# Line 1701 | Line 2190 | int16 video_mode_change(VidLocals *csSav
2190                          csSave->saveMode=VModes[cur_mode].viAppleMode;
2191  
2192                          // Enable interrupts and resume redraw thread
1704                        thread_stop_req = false;
2193                          EnableInterrupt();
2194 +                        sem_post(&thread_resume_req);
2195                          return noErr;
2196                  }
2197          }
# Line 1748 | Line 2237 | void video_set_palette(void)
2237                  // We have to redraw everything because the interpretation of pixel values changed
2238                  LOCK_VOSF;
2239                  PFLAG_SET_ALL;
2240 +                if (display_type == DIS_SCREEN)
2241 +                        PFLAG_SET_VERY_DIRTY;
2242                  UNLOCK_VOSF;
1752                memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize);
2243          }
2244   #endif
2245  
# Line 1931 | Line 2421 | static void handle_palette_changes(void)
2421                  }
2422  
2423   #ifdef ENABLE_XF86_DGA
2424 <                if (display_type == DIS_SCREEN) {
2424 >                if (display_type == DIS_SCREEN && !is_fbdev_dga_mode) {
2425                          current_dga_cmap ^= 1;
2426                          if (!IsDirectMode(mode) && cmap[current_dga_cmap])
2427                                  XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
# Line 1953 | Line 2443 | static void *redraw_func(void *arg)
2443          while (!redraw_thread_cancel) {
2444  
2445                  // Pause if requested (during video mode switches)
2446 <                while (thread_stop_req)
2447 <                        thread_stop_ack = true;
2446 >                if (thread_stop_req) {
2447 >                        sem_post(&thread_stop_ack);
2448 >                        sem_wait(&thread_resume_req);
2449 >                }
2450  
2451                  int64 delay = next - GetTicks_usec();
2452                  if (delay < -VIDEO_REFRESH_DELAY) {
# Line 1976 | Line 2468 | static void *redraw_func(void *arg)
2468                                  quit_full_screen = false;
2469                                  if (display_type == DIS_SCREEN) {
2470                                          XDisplayLock();
2471 + #if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA)
2472   #ifdef ENABLE_XF86_DGA
2473 <                                        XF86DGADirectVideo(x_display, screen, 0);
2473 >                                        if (!is_fbdev_dga_mode)
2474 >                                                XF86DGADirectVideo(x_display, screen, 0);
2475 > #endif
2476                                          XUngrabPointer(x_display, CurrentTime);
2477                                          XUngrabKeyboard(x_display, CurrentTime);
2478                                          XUnmapWindow(x_display, the_win);
# Line 2065 | Line 2560 | static void *redraw_func(void *arg)
2560          }
2561          return NULL;
2562   }
2563 +
2564 +
2565 + /*
2566 + *  Record dirty area from NQD
2567 + */
2568 +
2569 + void video_set_dirty_area(int x, int y, int w, int h)
2570 + {
2571 +        VideoInfo const & mode = VModes[cur_mode];
2572 +        const int screen_width = VIDEO_MODE_X;
2573 +        const int screen_height = VIDEO_MODE_Y;
2574 +        const int bytes_per_row = VIDEO_MODE_ROW_BYTES;
2575 +
2576 + #ifdef ENABLE_VOSF
2577 +        if (use_vosf) {
2578 +                vosf_set_dirty_area(x, y, w, h, screen_width, screen_height, bytes_per_row);
2579 +                return;
2580 +        }
2581 + #endif
2582 +
2583 +        // XXX handle dirty bounding boxes for non-VOSF modes
2584 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines