--- BasiliskII/src/Unix/video_x.cpp 2000/09/25 21:49:19 1.20 +++ BasiliskII/src/Unix/video_x.cpp 2000/11/30 16:09:03 1.31 @@ -53,7 +53,6 @@ #endif #ifdef ENABLE_VOSF -# include // log() # include # include # include @@ -123,13 +122,19 @@ static Colormap cmap[2]; // Two co static XColor black, white; static unsigned long black_pixel, white_pixel; static int eventmask; -static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask; -static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; +static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask | StructureNotifyMask; +static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask; +static Atom WM_DELETE_WINDOW = (Atom)0; static XColor palette[256]; // Color palette for 8-bit mode static bool palette_changed = false; // Flag: Palette changed, redraw thread must set new colors #ifdef HAVE_PTHREADS static pthread_mutex_t palette_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect palette +#define LOCK_PALETTE pthread_mutex_lock(&palette_lock) +#define UNLOCK_PALETTE pthread_mutex_unlock(&palette_lock) +#else +#define LOCK_PALETTE +#define UNLOCK_PALETTE #endif // Variables for window mode @@ -150,6 +155,11 @@ static Window suspend_win; // "Sus static void *fb_save = NULL; // Saved frame buffer for suspend #ifdef HAVE_PTHREADS static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer +#define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock); +#define UNLOCK_FRAME_BUFFER pthread_mutex_unlock(&frame_buffer_lock); +#else +#define LOCK_FRAME_BUFFER +#define UNLOCK_FRAME_BUFFER #endif // Variables for fbdev DGA mode @@ -169,12 +179,10 @@ static const bool use_vosf = false; #endif #ifdef ENABLE_VOSF -static uint8 * the_host_buffer; // Host frame buffer in VOSF mode +// Variables for Video on SEGV support (taken from the Win32 port) +static uint8 *the_host_buffer; // Host frame buffer in VOSF mode static uint32 the_buffer_size; // Size of allocated the_buffer -#endif -#ifdef ENABLE_VOSF -// Variables for Video on SEGV support (taken from the Win32 port) struct ScreenPageInfo { int top, bottom; // Mapping between this virtual page and Mac scanlines }; @@ -216,9 +224,25 @@ static bool Screen_fault_handler_init(); static struct sigaction vosf_sa; #ifdef HAVE_PTHREADS -static pthread_mutex_t Screen_draw_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) +static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) +#define LOCK_VOSF pthread_mutex_lock(&vosf_lock); +#define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock); +#else +#define LOCK_VOSF +#define UNLOCK_VOSF #endif +static int log_base_2(uint32 x) +{ + uint32 mask = 0x80000000; + int l = 31; + while (l >= 0 && (x & mask) == 0) { + mask >>= 1; + l--; + } + return l; +} + #endif // VideoRefresh function @@ -227,7 +251,7 @@ static void (*video_refresh)(void); // Prototypes static void *redraw_func(void *arg); -static int event2keycode(XKeyEvent *ev); +static int event2keycode(XKeyEvent &ev); // From main_unix.cpp @@ -297,6 +321,60 @@ void set_video_monitor(int width, int he VideoMonitor.bytes_per_row = bytes_per_row; } +// Set window name and class +static void set_window_name(Window w, int name) +{ + const char *str = GetString(name); + XStoreName(x_display, w, str); + XSetIconName(x_display, w, str); + + XClassHint *hints; + hints = XAllocClassHint(); + if (hints) { + hints->res_name = "BasiliskII"; + hints->res_class = "BasiliskII"; + XSetClassHint(x_display, w, hints); + XFree((char *)hints); + } +} + +// Set window input focus flag +static void set_window_focus(Window w) +{ + XWMHints *hints = XAllocWMHints(); + if (hints) { + hints->input = True; + hints->initial_state = NormalState; + hints->flags = InputHint | StateHint; + XSetWMHints(x_display, w, hints); + XFree((char *)hints); + } +} + +// Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget) +static void set_window_delete_protocol(Window w) +{ + WM_DELETE_WINDOW = XInternAtom(x_display, "WM_DELETE_WINDOW", false); + XSetWMProtocols(x_display, w, &WM_DELETE_WINDOW, 1); +} + +// Wait until window is mapped/unmapped +void wait_mapped(Window w) +{ + XEvent e; + do { + XMaskEvent(x_display, StructureNotifyMask, &e); + } while ((e.type != MapNotify) || (e.xmap.event != w)); +} + +void wait_unmapped(Window w) +{ + XEvent e; + do { + XMaskEvent(x_display, StructureNotifyMask, &e); + } while ((e.type != UnmapNotify) || (e.xmap.event != w)); +} + // Trap SHM errors static bool shm_error = false; static int (*old_error_handler)(Display *, XErrorEvent *); @@ -326,38 +404,38 @@ static bool init_window(int width, int h XSetWindowAttributes wattr; wattr.event_mask = eventmask = win_eventmask; wattr.background_pixel = black_pixel; - wattr.border_pixel = black_pixel; - wattr.backing_store = NotUseful; - wattr.save_under = false; - wattr.backing_planes = xdepth; + wattr.colormap = cmap[0]; - XSync(x_display, false); the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, - InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | - CWBackingStore | CWBackingPlanes, &wattr); - XSync(x_display, false); - XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); - XMapRaised(x_display, the_win); - XSync(x_display, false); + InputOutput, vis, CWEventMask | CWBackPixel | (depth == 8 ? CWColormap : 0), &wattr); - // Set colormap - if (depth == 8) { - XSetWindowColormap(x_display, the_win, cmap[0]); - XSetWMColormapWindows(x_display, the_win, &the_win, 1); - } + // Set window name/class + set_window_name(the_win, STR_WINDOW_TITLE); + + // Indicate that we want keyboard input + set_window_focus(the_win); + + // Set delete protocol property + set_window_delete_protocol(the_win); // Make window unresizable - XSizeHints *hints; - if ((hints = XAllocSizeHints()) != NULL) { - hints->min_width = width; - hints->max_width = width; - hints->min_height = height; - hints->max_height = height; - hints->flags = PMinSize | PMaxSize; - XSetWMNormalHints(x_display, the_win, hints); - XFree((char *)hints); + { + XSizeHints *hints = XAllocSizeHints(); + if (hints) { + hints->min_width = width; + hints->max_width = width; + hints->min_height = height; + hints->max_height = height; + hints->flags = PMinSize | PMaxSize; + XSetWMNormalHints(x_display, the_win, hints); + XFree((char *)hints); + } } + // Show window + XMapWindow(x_display, the_win); + wait_mapped(the_win); + // Try to create and attach SHM image have_shm = false; if (depth != 1 && local_X11 && XShmQueryExtension(x_display)) { @@ -440,9 +518,9 @@ static bool init_window(int width, int h // Set VideoMonitor bool native_byte_order; #ifdef WORDS_BIGENDIAN - native_byte_order = (img->bitmap_bit_order == MSBFirst); + native_byte_order = (XImageByteOrder(x_display) == MSBFirst); #else - native_byte_order = (img->bitmap_bit_order == LSBFirst); + native_byte_order = (XImageByteOrder(x_display) == LSBFirst); #endif #ifdef ENABLE_VOSF do_update_framebuffer = GET_FBCOPY_FUNC(depth, native_byte_order, DISPLAY_WINDOW); @@ -529,21 +607,26 @@ static bool init_fbdev_dga(char *in_fb_n // Create window XSetWindowAttributes wattr; - wattr.override_redirect = True; - wattr.backing_store = NotUseful; - wattr.background_pixel = white_pixel; - wattr.border_pixel = black_pixel; - wattr.event_mask = eventmask = dga_eventmask; + wattr.event_mask = eventmask = dga_eventmask; + wattr.background_pixel = white_pixel; + wattr.override_redirect = True; + wattr.colormap = cmap[0]; - XSync(x_display, false); the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, InputOutput, vis, - CWEventMask|CWBackPixel|CWBorderPixel|CWOverrideRedirect|CWBackingStore, + CWEventMask | CWBackPixel | CWOverrideRedirect | (depth == 8 ? CWColormap : 0), &wattr); - XSync(x_display, false); + + // Set window name/class + set_window_name(the_win, STR_WINDOW_TITLE); + + // Indicate that we want keyboard input + set_window_focus(the_win); + + // Show window XMapRaised(x_display, the_win); - XSync(x_display, false); + wait_mapped(the_win); // Grab mouse and keyboard XGrabKeyboard(x_display, the_win, True, @@ -552,12 +635,6 @@ static bool init_fbdev_dga(char *in_fb_n PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime); - // Set colormap - if (depth == 8) { - XSetWindowColormap(x_display, the_win, cmap[0]); - XSetWMColormapWindows(x_display, the_win, &the_win, 1); - } - // Set VideoMonitor int bytes_per_row = width; switch (depth) { @@ -583,6 +660,7 @@ static bool init_fbdev_dga(char *in_fb_n } } +#if ENABLE_VOSF #if REAL_ADDRESSING || DIRECT_ADDRESSING // If the blit function is null, i.e. just a copy of the buffer, // we first try to avoid the allocation of a temporary frame buffer @@ -599,9 +677,10 @@ static bool init_fbdev_dga(char *in_fb_n the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); memset(the_buffer, 0, the_buffer_size); } -#elif ENABLE_VOSF +#else use_vosf = false; #endif +#endif set_video_monitor(width, height, bytes_per_row, true); #if REAL_ADDRESSING || DIRECT_ADDRESSING @@ -635,22 +714,27 @@ static bool init_xf86_dga(int width, int } XF86VidModeSwitchToMode(x_display, screen, x_video_modes[best]); XF86VidModeSetViewPort(x_display, screen, 0, 0); + XSync(x_display, false); } #endif // Create window XSetWindowAttributes wattr; wattr.event_mask = eventmask = dga_eventmask; - wattr.border_pixel = black_pixel; wattr.override_redirect = True; - XSync(x_display, false); the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, - InputOutput, vis, CWEventMask | CWBorderPixel | CWOverrideRedirect, &wattr); - XSync(x_display, false); - XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); + InputOutput, vis, CWEventMask | CWOverrideRedirect, &wattr); + + // Set window name/class + set_window_name(the_win, STR_WINDOW_TITLE); + + // Indicate that we want keyboard input + set_window_focus(the_win); + + // Show window XMapRaised(x_display, the_win); - XSync(x_display, false); + wait_mapped(the_win); // Establish direct screen connection XMoveResizeWindow(x_display, the_win, 0, 0, width, height); @@ -667,9 +751,9 @@ static bool init_xf86_dga(int width, int // Set colormap if (depth == 8) { XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); - XSetWMColormapWindows(x_display, the_win, &the_win, 1); XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); } + XSync(x_display, false); // Set VideoMonitor int bytes_per_row = (v_width + 7) & ~7; @@ -703,7 +787,7 @@ static bool init_xf86_dga(int width, int the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); memset(the_buffer, 0, the_buffer_size); } -#elif ENABLE_VOSF +#elif defined(ENABLE_VOSF) // The UAE memory handlers will already handle color conversion, if needed. use_vosf = false; #endif @@ -802,7 +886,7 @@ bool VideoInitBuffer() mainBuffer.pageSize = page_size; mainBuffer.pageCount = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize; - mainBuffer.pageBits = int( log(mainBuffer.pageSize) / log(2.0) ); + mainBuffer.pageBits = log_base_2(mainBuffer.pageSize); if (mainBuffer.dirtyPages != 0) free(mainBuffer.dirtyPages); @@ -1008,10 +1092,8 @@ bool VideoInit(bool classic) break; } -#ifdef HAVE_PTHREADS // Lock down frame buffer - pthread_mutex_lock(&frame_buffer_lock); -#endif + LOCK_FRAME_BUFFER; #if !REAL_ADDRESSING && !DIRECT_ADDRESSING // Set variables for UAE memory mapping @@ -1076,10 +1158,8 @@ void VideoExit(void) } #endif -#ifdef HAVE_PTHREADS // Unlock frame buffer - pthread_mutex_unlock(&frame_buffer_lock); -#endif + UNLOCK_FRAME_BUFFER; // Close window and server connection if (x_display != NULL) { @@ -1182,12 +1262,10 @@ void VideoInterrupt(void) if (emerg_quit) QuitEmulator(); -#ifdef HAVE_PTHREADS // Temporarily give up frame buffer lock (this is the point where // we are suspended when the user presses Ctrl-Tab) - pthread_mutex_unlock(&frame_buffer_lock); - pthread_mutex_lock(&frame_buffer_lock); -#endif + UNLOCK_FRAME_BUFFER; + LOCK_FRAME_BUFFER; } @@ -1197,9 +1275,7 @@ void VideoInterrupt(void) void video_set_palette(uint8 *pal) { -#ifdef HAVE_PTHREDS - pthread_mutex_lock(&palette_lock); -#endif + LOCK_PALETTE; // Convert colors to XColor array for (int i=0; i<256; i++) { @@ -1213,9 +1289,7 @@ void video_set_palette(uint8 *pal) // Tell redraw thread to change palette palette_changed = true; -#ifdef HAVE_PTHREADS - pthread_mutex_unlock(&palette_lock); -#endif + UNLOCK_PALETTE; } @@ -1231,10 +1305,8 @@ static void suspend_emul(void) ADBKeyUp(0x36); ctrl_down = false; -#ifdef HAVE_PTHREADS // Lock frame buffer (this will stop the MacOS thread) - pthread_mutex_lock(&frame_buffer_lock); -#endif + LOCK_FRAME_BUFFER; // Save frame buffer fb_save = malloc(VideoMonitor.y * VideoMonitor.bytes_per_row); @@ -1248,25 +1320,18 @@ static void suspend_emul(void) XUngrabPointer(x_display, CurrentTime); XUngrabKeyboard(x_display, CurrentTime); XUnmapWindow(x_display, the_win); - XSync(x_display, false); + wait_unmapped(the_win); // Open "suspend" window XSetWindowAttributes wattr; wattr.event_mask = KeyPressMask; wattr.background_pixel = black_pixel; - wattr.border_pixel = black_pixel; - wattr.backing_store = Always; - wattr.backing_planes = xdepth; - wattr.colormap = DefaultColormap(x_display, screen); - XSync(x_display, false); suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth, - InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | - CWBackingStore | CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr); - XSync(x_display, false); - XStoreName(x_display, suspend_win, GetString(STR_SUSPEND_WINDOW_TITLE)); - XMapRaised(x_display, suspend_win); - XSync(x_display, false); + InputOutput, vis, CWEventMask | CWBackPixel, &wattr); + set_window_name(suspend_win, STR_SUSPEND_WINDOW_TITLE); + set_window_focus(suspend_win); + XMapWindow(x_display, suspend_win); emul_suspended = true; } } @@ -1279,8 +1344,8 @@ static void resume_emul(void) // Reopen full screen display XMapRaised(x_display, the_win); + wait_mapped(the_win); XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); - XSync(x_display, false); XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime); XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); #ifdef ENABLE_XF86_DGA @@ -1288,27 +1353,26 @@ static void resume_emul(void) XF86DGASetViewPort(x_display, screen, 0, 0); #endif XSync(x_display, false); - + + // the_buffer already contains the data to restore. i.e. since a temporary + // frame buffer is used when VOSF is actually used, fb_save is therefore + // not necessary. +#ifdef ENABLE_VOSF + if (use_vosf) { + LOCK_VOSF; + PFLAG_SET_ALL; + UNLOCK_VOSF; + memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); + } +#endif + // Restore frame buffer if (fb_save) { -#if REAL_ADDRESSING || DIRECT_ADDRESSING - if (use_vosf) - mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ|PROT_WRITE); +#ifdef ENABLE_VOSF + // Don't copy fb_save to the temporary frame buffer in VOSF mode + if (!use_vosf) #endif memcpy(the_buffer, fb_save, VideoMonitor.y * VideoMonitor.bytes_per_row); -#if REAL_ADDRESSING || DIRECT_ADDRESSING - if (use_vosf) { - mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ); - do_update_framebuffer(the_host_buffer, the_buffer, VideoMonitor.x * VideoMonitor.bytes_per_row); -#ifdef HAVE_PTHREADS - pthread_mutex_lock(&Screen_draw_lock); -#endif - PFLAG_CLEAR_ALL; -#ifdef HAVE_PTHREADS - pthread_mutex_unlock(&Screen_draw_lock); -#endif - } -#endif free(fb_save); fb_save = NULL; } @@ -1318,11 +1382,9 @@ static void resume_emul(void) XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); #endif -#ifdef HAVE_PTHREADS // Unlock frame buffer (and continue MacOS thread) - pthread_mutex_unlock(&frame_buffer_lock); + UNLOCK_FRAME_BUFFER; emul_suspended = false; -#endif } #endif @@ -1476,14 +1538,14 @@ static int kc_decode(KeySym ks) return -1; } -static int event2keycode(XKeyEvent *ev) +static int event2keycode(XKeyEvent &ev) { KeySym ks; int as; int i = 0; do { - ks = XLookupKeysym(ev, i++); + ks = XLookupKeysym(&ev, i++); as = kc_decode(ks); if (as != -1) return as; @@ -1499,15 +1561,14 @@ static int event2keycode(XKeyEvent *ev) static void handle_events(void) { - XEvent event; - for (;;) { - if (!XCheckMaskEvent(x_display, eventmask, &event)) - break; + while (XPending(x_display)) { + XEvent event; + XNextEvent(x_display, &event); switch (event.type) { // Mouse button case ButtonPress: { - unsigned int button = ((XButtonEvent *)&event)->button; + unsigned int button = event.xbutton.button; if (button < 4) ADBMouseDown(button - 1); else if (button < 6) { // Wheel mouse @@ -1526,7 +1587,7 @@ static void handle_events(void) break; } case ButtonRelease: { - unsigned int button = ((XButtonEvent *)&event)->button; + unsigned int button = event.xbutton.button; if (button < 4) ADBMouseUp(button - 1); break; @@ -1534,20 +1595,18 @@ static void handle_events(void) // Mouse moved case EnterNotify: - ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); - break; case MotionNotify: - ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); + ADBMouseMoved(event.xmotion.x, event.xmotion.y); break; // Keyboard case KeyPress: { int code; if (use_keycodes) { - event2keycode((XKeyEvent *)&event); // This is called to process the hotkeys - code = keycode_table[((XKeyEvent *)&event)->keycode & 0xff]; + event2keycode(event.xkey); // This is called to process the hotkeys + code = keycode_table[event.xkey.keycode & 0xff]; } else - code = event2keycode((XKeyEvent *)&event); + code = event2keycode(event.xkey); if (code != -1) { if (!emul_suspended) { if (code == 0x39) { // Caps Lock pressed @@ -1574,10 +1633,10 @@ static void handle_events(void) case KeyRelease: { int code; if (use_keycodes) { - event2keycode((XKeyEvent *)&event); // This is called to process the hotkeys - code = keycode_table[((XKeyEvent *)&event)->keycode & 0xff]; + event2keycode(event.xkey); // This is called to process the hotkeys + code = keycode_table[event.xkey.keycode & 0xff]; } else - code = event2keycode((XKeyEvent *)&event); + code = event2keycode(event.xkey); if (code != -1 && code != 0x39) { // Don't propagate Caps Lock releases ADBKeyUp(code); if (code == 0x36) @@ -1589,24 +1648,31 @@ static void handle_events(void) // Hidden parts exposed, force complete refresh of window case Expose: if (display_type == DISPLAY_WINDOW) { +#ifdef ENABLE_VOSF + if (use_vosf) { // VOSF refresh + LOCK_VOSF; + PFLAG_SET_ALL; + UNLOCK_VOSF; + memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); + } + else +#endif if (frame_skip == 0) { // Dynamic refresh int x1, y1; for (y1=0; y1<16; y1++) for (x1=0; x1<16; x1++) updt_box[x1][y1] = true; nr_boxes = 16 * 16; - } else { -#ifdef ENABLE_VOSF -#ifdef HAVE_PTHREADS - pthread_mutex_lock(&Screen_draw_lock); -#endif - PFLAG_SET_ALL; -#ifdef HAVE_PTHREADS - pthread_mutex_unlock(&Screen_draw_lock); -#endif -#endif + } else // Static refresh memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); - } + } + break; + + // Window "close" widget clicked + case ClientMessage: + if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW) { + ADBKeyDown(0x7f); // Power key + ADBKeyUp(0x7f); } break; } @@ -1737,7 +1803,7 @@ static void update_display_static(void) // Check for first column from left and first column from right that have changed if (high) { if (depth == 1) { - x1 = VideoMonitor.x; + x1 = VideoMonitor.x - 1; for (j=y1; j<=y2; j++) { p = &the_buffer[j * bytes_per_row]; p2 = &the_buffer_copy[j * bytes_per_row]; @@ -1758,12 +1824,12 @@ static void update_display_static(void) for (i=(VideoMonitor.x>>3); i>(x2>>3); i--) { p--; p2--; if (*p != *p2) { - x2 = i << 3; + x2 = (i << 3) + 7; break; } } } - wide = x2 - x1; + wide = x2 - x1 + 1; // Update copy of the_buffer if (high && wide) { @@ -1865,14 +1931,14 @@ static inline void possibly_quit_dga_mod static inline void handle_palette_changes(int depth, int display_type) { -#ifdef HAVE_PTHREADS - pthread_mutex_lock(&palette_lock); -#endif + LOCK_PALETTE; + if (palette_changed) { palette_changed = false; if (depth == 8) { XStoreColors(x_display, cmap[0], palette, 256); XStoreColors(x_display, cmap[1], palette, 256); + XSync(x_display, false); #ifdef ENABLE_XF86_DGA if (display_type == DISPLAY_DGA) { @@ -1882,9 +1948,8 @@ static inline void handle_palette_change #endif } } -#ifdef HAVE_PTHREADS - pthread_mutex_unlock(&palette_lock); -#endif + + UNLOCK_PALETTE; } static void video_refresh_dga(void) @@ -1899,6 +1964,7 @@ static void video_refresh_dga(void) handle_palette_changes(depth, DISPLAY_DGA); } +#ifdef ENABLE_VOSF #if REAL_ADDRESSING || DIRECT_ADDRESSING static void video_refresh_dga_vosf(void) { @@ -1915,18 +1981,13 @@ static void video_refresh_dga_vosf(void) static int tick_counter = 0; if (++tick_counter >= frame_skip) { tick_counter = 0; -#ifdef HAVE_PTHREADS - pthread_mutex_lock(&Screen_draw_lock); -#endif + LOCK_VOSF; update_display_dga_vosf(); -#ifdef HAVE_PTHREADS - pthread_mutex_unlock(&Screen_draw_lock); -#endif + UNLOCK_VOSF; } } #endif -#ifdef ENABLE_VOSF static void video_refresh_window_vosf(void) { // Quit DGA mode if requested @@ -1942,16 +2003,12 @@ static void video_refresh_window_vosf(vo static int tick_counter = 0; if (++tick_counter >= frame_skip) { tick_counter = 0; -#ifdef HAVE_PTHREADS - pthread_mutex_lock(&Screen_draw_lock); -#endif + LOCK_VOSF; update_display_window_vosf(); -#ifdef HAVE_PTHREADS - pthread_mutex_unlock(&Screen_draw_lock); -#endif + UNLOCK_VOSF; } } -#endif +#endif // def ENABLE_VOSF static void video_refresh_window_static(void) { @@ -1992,7 +2049,7 @@ void VideoRefreshInit(void) { // TODO: set up specialised 8bpp VideoRefresh handlers ? if (display_type == DISPLAY_DGA) { -#if REAL_ADDRESSING || DIRECT_ADDRESSING +#if ENABLE_VOSF && (REAL_ADDRESSING || DIRECT_ADDRESSING) if (use_vosf) video_refresh = video_refresh_dga_vosf; else @@ -2018,64 +2075,6 @@ void VideoRefresh(void) video_refresh(); } -#if 0 -void VideoRefresh(void) -{ -#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) - // Quit DGA mode if requested - if (quit_full_screen) { - quit_full_screen = false; - if (display_type == DISPLAY_DGA) { -#ifdef ENABLE_XF86_DGA - XF86DGADirectVideo(x_display, screen, 0); -#endif - XUngrabPointer(x_display, CurrentTime); - XUngrabKeyboard(x_display, CurrentTime); - XUnmapWindow(x_display, the_win); - XSync(x_display, false); - } - } -#endif - - // Handle X events - handle_events(); - - // Handle palette changes -#ifdef HAVE_PTHREADS - pthread_mutex_lock(&palette_lock); -#endif - if (palette_changed) { - palette_changed = false; - if (depth == 8) { - XStoreColors(x_display, cmap[0], palette, 256); - XStoreColors(x_display, cmap[1], palette, 256); - -#ifdef ENABLE_XF86_DGA - if (display_type == DISPLAY_DGA) { - current_dga_cmap ^= 1; - XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); - } -#endif - } - } -#ifdef HAVE_PTHREADS - pthread_mutex_unlock(&palette_lock); -#endif - - // In window mode, update display - static int tick_counter = 0; - if (display_type == DISPLAY_WINDOW) { - tick_counter++; - if (frame_skip == 0) - update_display_dynamic(tick_counter); - else if (tick_counter >= frame_skip) { - tick_counter = 0; - update_display_static(); - } - } -} -#endif - #ifdef HAVE_PTHREADS static void *redraw_func(void *arg) { @@ -2083,7 +2082,6 @@ static void *redraw_func(void *arg) int64 ticks = 0; uint64 next = GetTicks_usec(); while (!redraw_thread_cancel) { -// VideoRefresh(); video_refresh(); next += 16667; int64 delay = next - GetTicks_usec();