--- SheepShaver/src/Unix/video_x.cpp 2004/05/16 15:48:25 1.23 +++ SheepShaver/src/Unix/video_x.cpp 2005/03/28 09:05:28 1.39 @@ -1,7 +1,7 @@ /* * video_x.cpp - Video/graphics emulation, X11 specific stuff * - * SheepShaver (C) 1997-2004 Marc Hellwig and Christian Bauer + * SheepShaver (C) 1997-2005 Marc Hellwig and Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,6 +18,15 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* + * NOTES: + * The Ctrl key works like a qualifier for special actions: + * Ctrl-Tab = suspend DGA mode + * Ctrl-Esc = emergency quit + * Ctrl-F1 = mount floppy + * Ctrl-F5 = grab mouse (in windowed mode) + */ + #include "sysdeps.h" #include @@ -31,6 +40,11 @@ #include +#ifdef ENABLE_FBDEV_DGA +# include +# include +#endif + #ifdef ENABLE_XF86_DGA # include #endif @@ -46,6 +60,7 @@ #include "about_window.h" #include "video.h" #include "video_defs.h" +#include "video_blit.h" #define DEBUG 0 #include "debug.h" @@ -65,6 +80,7 @@ static int16 mouse_wheel_mode; static int16 mouse_wheel_lines; static bool redraw_thread_active = false; // Flag: Redraw thread installed static pthread_attr_t redraw_thread_attr; // Redraw thread attributes +static volatile bool redraw_thread_cancel; // Flag: Cancel Redraw thread static pthread_t redraw_thread; // Redraw thread static bool local_X11; // Flag: X server running on local machine? @@ -82,6 +98,7 @@ static const bool use_vosf = false; // static bool palette_changed = false; // Flag: Palette changed, redraw thread must update palette static bool ctrl_down = false; // Flag: Ctrl key pressed +static bool caps_on = false; // Flag: Caps Lock on static bool quit_full_screen = false; // Flag: DGA close requested from redraw thread static volatile bool quit_full_screen_ack = false; // Acknowledge for quit_full_screen static bool emerg_quit = false; // Flag: Ctrl-Esc pressed, emergency quit requested from MacOS thread @@ -99,12 +116,14 @@ static int depth; // Depth of Mac static Window rootwin, the_win; // Root window and our window static int num_depths = 0; // Number of available X depths static int *avail_depths = NULL; // List of available X depths +static VisualFormat visualFormat; static XVisualInfo visualInfo; static Visual *vis; static int color_class; static int rshift, rloss, gshift, gloss, bshift, bloss; // Pixel format of DirectColor/TrueColor modes static Colormap cmap[2]; // Two colormaps (DGA) for 8-bit mode static XColor x_palette[256]; // Color palette to be used as CLUT and gamma table +static int orig_accel_numer, orig_accel_denom, orig_threshold; // Original mouse acceleration static XColor black, white; static unsigned long black_pixel, white_pixel; @@ -127,8 +146,17 @@ static uint8 *the_buffer_copy = NULL; / static uint32 the_buffer_size; // Size of allocated the_buffer // Variables for DGA mode +static bool is_fbdev_dga_mode = false; // Flag: Use FBDev DGA mode? static int current_dga_cmap; +#ifdef ENABLE_FBDEV_DGA +static int fb_dev_fd = -1; // Handle to fb device name +static struct fb_fix_screeninfo fb_finfo; // Fixed info +static struct fb_var_screeninfo fb_vinfo; // Variable info +static struct fb_var_screeninfo fb_orig_vinfo; // Variable info to restore later +static struct fb_cmap fb_oldcmap; // Colormap to restore later +#endif + #ifdef ENABLE_XF86_VIDMODE // Variables for XF86 VidMode support static XF86VidModeModeInfo **x_video_modes; // Array of all available modes @@ -149,6 +177,20 @@ static pthread_mutex_t x_palette_lock = #define UNLOCK_PALETTE #endif +// Mutex to protect frame buffer +#ifdef HAVE_SPINLOCKS +static spinlock_t frame_buffer_lock = SPIN_LOCK_UNLOCKED; +#define LOCK_FRAME_BUFFER spin_lock(&frame_buffer_lock) +#define UNLOCK_FRAME_BUFFER spin_unlock(&frame_buffer_lock) +#elif defined(HAVE_PTHREADS) +static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER; +#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 + // Prototypes static void *redraw_func(void *arg); @@ -360,6 +402,36 @@ static bool find_visual_for_depth(int de * Open display (window or fullscreen) */ +// 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 = "SheepShaver"; + hints->res_class = "SheepShaver"; + XSetClassHint(x_display, w, hints); + XFree(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(hints); + } +} + // Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget) static Atom WM_DELETE_WINDOW = (Atom)0; static void set_window_delete_protocol(Window w) @@ -385,6 +457,18 @@ static void wait_unmapped(Window w) } while ((e.type != UnmapNotify) || (e.xmap.event != w)); } +// Disable mouse acceleration +static void disable_mouse_accel(void) +{ + XChangePointerControl(x_display, True, False, 1, 1, 0); +} + +// Restore mouse acceleration to original value +static void restore_mouse_accel(void) +{ + XChangePointerControl(x_display, True, True, orig_accel_numer, orig_accel_denom, orig_threshold); +} + // Trap SHM errors static bool shm_error = false; static int (*old_error_handler)(Display *, XErrorEvent *); @@ -417,8 +501,11 @@ static bool open_window(int width, int h the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | CWBackingStore | CWColormap, &wattr); - // Set window name - XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); + // 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); @@ -499,7 +586,7 @@ static bool open_window(int width, int h the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line); D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); #endif - screen_base = (uint32)the_buffer; + screen_base = Host2MacAddr(the_buffer); // Create GC the_gc = XCreateGC(x_display, the_win, 0, 0); @@ -538,7 +625,7 @@ static bool open_window(int width, int h native_byte_order = (XImageByteOrder(x_display) == LSBFirst); #endif #ifdef ENABLE_VOSF - Screen_blitter_init(&visualInfo, native_byte_order, depth); + Screen_blitter_init(visualFormat, native_byte_order, depth); #endif // Set bytes per row @@ -546,9 +633,127 @@ static bool open_window(int width, int h return true; } +// Open FBDev display +static bool open_fbdev(int width, int height) +{ +#ifdef ENABLE_FBDEV_DGA + if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo) != 0) { + D(bug("[fbdev] Can't get FSCREENINFO: %s\n", strerror(errno))); + return false; + } + D(bug("[fbdev] Device ID: %s\n", fb_finfo.id)); + D(bug("[fbdev] smem_start: %p [%d bytes]\n", fb_finfo.smem_start, fb_finfo.smem_len)); + int fb_type = fb_finfo.type; + const char *fb_type_str = NULL; + switch (fb_type) { + case FB_TYPE_PACKED_PIXELS: fb_type_str = "Packed Pixels"; break; + case FB_TYPE_PLANES: fb_type_str = "Non interleaved planes"; break; + case FB_TYPE_INTERLEAVED_PLANES: fb_type_str = "Interleaved planes"; break; + case FB_TYPE_TEXT: fb_type_str = "Text/attributes"; break; + case FB_TYPE_VGA_PLANES: fb_type_str = "EGA/VGA planes"; break; + default: fb_type_str = ""; break; + } + D(bug("[fbdev] type: %s\n", fb_type_str)); + int fb_visual = fb_finfo.visual; + const char *fb_visual_str; + switch (fb_visual) { + case FB_VISUAL_MONO01: fb_visual_str = "Monochrome 1=Black 0=White"; break; + case FB_VISUAL_MONO10: fb_visual_str = "Monochrome 1=While 0=Black"; break; + case FB_VISUAL_TRUECOLOR: fb_visual_str = "True color"; break; + case FB_VISUAL_PSEUDOCOLOR: fb_visual_str = "Pseudo color (like atari)"; break; + case FB_VISUAL_DIRECTCOLOR: fb_visual_str = "Direct color"; break; + case FB_VISUAL_STATIC_PSEUDOCOLOR: fb_visual_str = "Pseudo color readonly"; break; + default: fb_visual_str = ""; break; + } + D(bug("[fbdev] visual: %s\n", fb_visual_str)); + + if (fb_type != FB_TYPE_PACKED_PIXELS) { + D(bug("[fbdev] type %s not supported\n", fb_type_str)); + return false; + } + + // Map frame buffer + the_buffer = (uint8 *)mmap(NULL, fb_finfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb_dev_fd, 0); + if (the_buffer == MAP_FAILED) { + D(bug("[fbdev] Can't mmap /dev/fb0: %s\n", strerror(errno))); + return false; + } + + // Set absolute mouse mode + ADBSetRelMouseMode(false); + + // Create window + XSetWindowAttributes wattr; + wattr.event_mask = eventmask = dga_eventmask; + wattr.override_redirect = True; + wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); + the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, + InputOutput, vis, CWEventMask | CWOverrideRedirect | + (color_class == DirectColor ? CWColormap : 0), &wattr); + + // Show window + XMapRaised(x_display, the_win); + wait_mapped(the_win); + + // Grab mouse and keyboard + XGrabKeyboard(x_display, the_win, True, + GrabModeAsync, GrabModeAsync, CurrentTime); + XGrabPointer(x_display, the_win, True, + PointerMotionMask | ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, None, CurrentTime); + disable_mouse_accel(); + + // Create no_cursor + mac_cursor = XCreatePixmapCursor(x_display, + XCreatePixmap(x_display, the_win, 1, 1, 1), + XCreatePixmap(x_display, the_win, 1, 1, 1), + &black, &white, 0, 0); + XDefineCursor(x_display, the_win, mac_cursor); + + // Init blitting routines + int bytes_per_row = TrivialBytesPerRow((width + 7) & ~7, DepthModeForPixelDepth(depth)); +#if ENABLE_VOSF + bool native_byte_order; +#ifdef WORDS_BIGENDIAN + native_byte_order = (XImageByteOrder(x_display) == MSBFirst); +#else + native_byte_order = (XImageByteOrder(x_display) == LSBFirst); +#endif +#if REAL_ADDRESSING || DIRECT_ADDRESSING + // Screen_blitter_init() returns TRUE if VOSF is mandatory + // i.e. the framebuffer update function is not Blit_Copy_Raw + use_vosf = Screen_blitter_init(visualFormat, native_byte_order, depth); + + if (use_vosf) { + // Allocate memory for frame buffer (SIZE is extended to page-boundary) + the_host_buffer = the_buffer; + the_buffer_size = page_extend((height + 2) * bytes_per_row); + the_buffer_copy = (uint8 *)malloc(the_buffer_size); + the_buffer = (uint8 *)vm_acquire(the_buffer_size); + D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); + } +#else + use_vosf = false; +#endif +#endif + + // Set frame buffer base + D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); + screen_base = Host2MacAddr(the_buffer); + VModes[cur_mode].viRowBytes = bytes_per_row; + return true; +#else + ErrorAlert("SheepShaver has been compiled with DGA support disabled."); + return false; +#endif +} + // Open DGA display (!! should use X11 VidMode extensions to set mode) static bool open_dga(int width, int height) { + if (is_fbdev_dga_mode) + return false; + #ifdef ENABLE_XF86_DGA // Set relative mouse mode ADBSetRelMouseMode(true); @@ -612,7 +817,7 @@ static bool open_dga(int width, int heig #if REAL_ADDRESSING || DIRECT_ADDRESSING // Screen_blitter_init() returns TRUE if VOSF is mandatory // i.e. the framebuffer update function is not Blit_Copy_Raw - use_vosf = Screen_blitter_init(&visualInfo, native_byte_order, depth); + use_vosf = Screen_blitter_init(visualFormat, native_byte_order, depth); if (use_vosf) { // Allocate memory for frame buffer (SIZE is extended to page-boundary) @@ -629,7 +834,7 @@ static bool open_dga(int width, int heig // Set frame buffer base D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); - screen_base = (uint32)the_buffer; + screen_base = Host2MacAddr(the_buffer); VModes[cur_mode].viRowBytes = bytes_per_row; return true; #else @@ -643,12 +848,21 @@ static bool open_display(void) D(bug("open_display()\n")); const VideoInfo &mode = VModes[cur_mode]; + // Get original mouse acceleration + XGetPointerControl(x_display, &orig_accel_numer, &orig_accel_denom, &orig_threshold); + // Find best available X visual if (!find_visual_for_depth(mode.viAppleMode)) { ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); return false; } + // Build up visualFormat structure + visualFormat.depth = visualInfo.depth; + visualFormat.Rmask = visualInfo.red_mask; + visualFormat.Gmask = visualInfo.green_mask; + visualFormat.Bmask = visualInfo.blue_mask; + // Create color maps if (color_class == PseudoColor || color_class == DirectColor) { cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); @@ -717,8 +931,17 @@ static bool open_display(void) depth = depth_of_video_mode(mode.viAppleMode); bool display_open = false; - if (display_type == DIS_SCREEN) + if (display_type == DIS_SCREEN) { display_open = open_dga(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); +#ifdef ENABLE_FBDEV_DGA + // Try to fallback to FBDev DGA mode + if (!display_open) { + is_fbdev_dga_mode = true; + display_open = open_fbdev(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); + } +#endif + + } else if (display_type == DIS_WINDOW) display_open = open_window(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); @@ -767,9 +990,36 @@ static void close_window(void) XSync(x_display, false); } +// Close FBDev mode +static void close_fbdev(void) +{ +#ifdef ENABLE_FBDEV_DGA + XUngrabPointer(x_display, CurrentTime); + XUngrabKeyboard(x_display, CurrentTime); + + uint8 *fb_base; + if (!use_vosf) { + // don't free() the screen buffer in driver_base dtor + fb_base = the_buffer; + the_buffer = NULL; + } +#ifdef ENABLE_VOSF + else { + // don't free() the screen buffer in driver_base dtor + fb_base = the_host_buffer; + the_host_buffer = NULL; + } +#endif + munmap(fb_base, fb_finfo.smem_len); +#endif +} + // Close DGA mode static void close_dga(void) { + if (is_fbdev_dga_mode) + return; + #ifdef ENABLE_XF86_DGA XF86DGADirectVideo(x_display, screen, 0); XUngrabPointer(x_display, CurrentTime); @@ -795,8 +1045,12 @@ static void close_dga(void) static void close_display(void) { - if (display_type == DIS_SCREEN) - close_dga(); + if (display_type == DIS_SCREEN) { + if (is_fbdev_dga_mode) + close_fbdev(); + else + close_dga(); + } else if (display_type == DIS_WINDOW) close_window(); @@ -851,6 +1105,9 @@ static void close_display(void) } } #endif + + // Restore mouse acceleration + restore_mouse_accel(); } @@ -882,6 +1139,10 @@ static void keycode_init(void) // Search for server vendor string, then read keycodes const char *vendor = ServerVendor(x_display); + // Force use of MacX mappings on MacOS X with Apple's X server + int dummy; + if (XQueryExtension(x_display, "Apple-DRI", &dummy, &dummy, &dummy)) + vendor = "MacX"; bool vendor_found = false; char line[256]; while (fgets(line, 255, f)) { @@ -956,47 +1217,56 @@ static int find_mode(int apple_mode, int return -1; } +// Add custom video mode +static void add_custom_mode(VideoInfo *&p, int type, uint32 x, uint32 y, int apple_mode, int apple_id) +{ + p->viType = type; + p->viXsize = x; + p->viYsize = y; + p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); + p->viAppleMode = apple_mode; + p->viAppleID = apple_id; + p++; +} + // Add mode to list of supported modes static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type) { if (allow & test) { - p->viType = type; + uint32 x = 0, y = 0; switch (apple_id) { case APPLE_W_640x480: case APPLE_640x480: - p->viXsize = 640; - p->viYsize = 480; + x = 640; + y = 480; break; case APPLE_W_800x600: case APPLE_800x600: - p->viXsize = 800; - p->viYsize = 600; + x = 800; + y = 600; break; case APPLE_1024x768: - p->viXsize = 1024; - p->viYsize = 768; + x = 1024; + y = 768; break; case APPLE_1152x768: - p->viXsize = 1152; - p->viYsize = 768; + x = 1152; + y = 768; break; case APPLE_1152x900: - p->viXsize = 1152; - p->viYsize = 900; + x = 1152; + y = 900; break; case APPLE_1280x1024: - p->viXsize = 1280; - p->viYsize = 1024; + x = 1280; + y = 1024; break; case APPLE_1600x1200: - p->viXsize = 1600; - p->viYsize = 1200; + x = 1600; + y = 1200; break; } - p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); - p->viAppleMode = apple_mode; - p->viAppleID = apple_id; - p++; + add_custom_mode(p, type, x, y, apple_mode, apple_id); } } @@ -1065,10 +1335,16 @@ bool VideoInit(void) #ifdef ENABLE_XF86_DGA // DGA available? int event_base, error_base; + is_fbdev_dga_mode = false; if (local_X11 && XF86DGAQueryExtension(x_display, &event_base, &error_base)) { int dga_flags = 0; XF86DGAQueryDirectVideo(x_display, screen, &dga_flags); has_dga = dga_flags & XF86DGADirectPresent; +#if defined(__linux__) + // Check r/w permission on /dev/mem for DGA mode to work + if (has_dga && access("/dev/mem", R_OK | W_OK) != 0) + has_dga = false; +#endif } else has_dga = false; #endif @@ -1081,6 +1357,27 @@ bool VideoInit(void) XF86VidModeGetAllModeLines(x_display, screen, &num_x_video_modes, &x_video_modes); #endif +#ifdef ENABLE_FBDEV_DGA + // FBDev available? + bool has_fbdev_dga = false; + if (local_X11) { + if ((fb_dev_fd = open("/dev/fb0", O_RDWR)) > 0) { + if (ioctl(fb_dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo) != 0) + close(fb_dev_fd); + else { + has_fbdev_dga = true; + if (!has_dga) { + // Fallback to FBDev DGA mode if XF86 DGA is not possible + has_dga = true; + is_fbdev_dga_mode = true; + } + fb_orig_vinfo = fb_vinfo; + D(bug("Frame buffer device initial resolution: %dx%dx%d\n", fb_vinfo.xres, fb_vinfo.yres, fb_vinfo.bits_per_pixel)); + } + } + } +#endif + // Find black and white colors XParseColor(x_display, DefaultColormap(x_display, screen), "rgb:00/00/00", &black); XAllocColor(x_display, DefaultColormap(x_display, screen), &black); @@ -1106,20 +1403,68 @@ bool VideoInit(void) break; } + // Get screen mode from preferences + const char *mode_str = PrefsFindString("screen"); + int default_width = 640, default_height = 480; + if (mode_str) { + display_type = DIS_INVALID; + if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) + display_type = DIS_WINDOW; +#ifdef ENABLE_XF86_DGA + else if (has_dga && sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2) + display_type = DIS_SCREEN; +#endif +#ifdef ENABLE_FBDEV_DGA + else if (has_fbdev_dga && sscanf(mode_str, "fbdev/%d/%d", &default_width, &default_height) == 2) { + is_fbdev_dga_mode = true; + display_type = DIS_SCREEN; + } +#endif + if (display_type == DIS_INVALID) { + D(bug("Invalid screen mode specified, defaulting to old modes selection\n")); + mode_str = NULL; + } + else { + if (default_width <= 0) + default_width = DisplayWidth(x_display, screen); + else if (default_width > DisplayWidth(x_display, screen)) + default_width = DisplayWidth(x_display, screen); + if (default_height <= 0) + default_height = DisplayHeight(x_display, screen); + else if (default_height > DisplayHeight(x_display, screen)) + default_height = DisplayHeight(x_display, screen); + } + } + // Construct video mode table uint32 window_modes = PrefsFindInt32("windowmodes"); uint32 screen_modes = PrefsFindInt32("screenmodes"); if (!has_dga) screen_modes = 0; - if (window_modes == 0 && screen_modes == 0) + if (mode_str) + window_modes = screen_modes = 0; + else if (window_modes == 0 && screen_modes == 0) window_modes |= 3; // Allow at least 640x480 and 800x600 window modes VideoInfo *p = VModes; - for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) - if (find_visual_for_depth(d)) - add_window_modes(p, window_modes, d); - - if (has_vidmode) { + if (mode_str) { + if (display_type == DIS_WINDOW) { + for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) { + if (find_visual_for_depth(d)) { + if (default_width > 640 && default_height > 480) + add_mode(p, 3, 1, d, APPLE_W_640x480, DIS_WINDOW); + if (default_width > 800 && default_height > 600) + add_mode(p, 3, 2, d, APPLE_W_800x600, DIS_WINDOW); + add_custom_mode(p, display_type, default_width, default_height, d, APPLE_CUSTOM); + } + } + } else + add_custom_mode(p, display_type, default_width, default_height, default_mode, APPLE_CUSTOM); + } else if (window_modes) { + for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) + if (find_visual_for_depth(d)) + add_window_modes(p, window_modes, d); + } else if (has_vidmode) { if (has_mode(640, 480)) add_mode(p, screen_modes, 1, default_mode, APPLE_640x480, DIS_SCREEN); if (has_mode(800, 600)) @@ -1160,9 +1505,18 @@ bool VideoInit(void) int apple_id = find_apple_resolution(screen_width, screen_height); if (apple_id != -1) cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN); + } else if (has_dga && mode_str) + cur_mode = find_mode(default_mode, APPLE_CUSTOM, DIS_SCREEN); + + if (cur_mode == -1) { + // pick up first windowed mode available + for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { + if (p->viType == DIS_WINDOW && p->viAppleMode == default_mode) { + cur_mode = p - VModes; + break; + } + } } - if (cur_mode == -1) - cur_mode = find_mode(default_mode, APPLE_W_640x480, DIS_WINDOW); assert(cur_mode != -1); #if DEBUG @@ -1182,9 +1536,14 @@ bool VideoInit(void) XSetErrorHandler(ignore_errors); #endif + // Lock down frame buffer + XSync(x_display, false); + LOCK_FRAME_BUFFER; + // Start periodic thread XSync(x_display, false); Set_pthread_attr(&redraw_thread_attr, 0); + redraw_thread_cancel = false; redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0); D(bug("Redraw thread installed (%ld)\n", redraw_thread)); return true; @@ -1199,11 +1558,17 @@ void VideoExit(void) { // Stop redraw thread if (redraw_thread_active) { + redraw_thread_cancel = true; pthread_cancel(redraw_thread); pthread_join(redraw_thread, NULL); redraw_thread_active = false; } + // Unlock frame buffer + UNLOCK_FRAME_BUFFER; + XSync(x_display, false); + D(bug(" frame buffer unlocked\n")); + #ifdef ENABLE_VOSF if (use_vosf) { // Deinitialize VOSF @@ -1218,6 +1583,14 @@ void VideoExit(void) XFlush(x_display); XSync(x_display, false); } + +#ifdef ENABLE_FBDEV_DGA + // Close framebuffer device + if (fb_dev_fd >= 0) { + close(fb_dev_fd); + fb_dev_fd = -1; + } +#endif } @@ -1225,9 +1598,6 @@ void VideoExit(void) * Suspend/resume emulator */ -extern void PauseEmulator(void); -extern void ResumeEmulator(void); - static void suspend_emul(void) { if (display_type == DIS_SCREEN) { @@ -1235,39 +1605,41 @@ static void suspend_emul(void) ADBKeyUp(0x36); ctrl_down = false; - // Pause MacOS thread - PauseEmulator(); - emul_suspended = true; + // Lock frame buffer (this will stop the MacOS thread) + LOCK_FRAME_BUFFER; // Save frame buffer fb_save = malloc(VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); if (fb_save) - memcpy(fb_save, (void *)screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); + Mac2Host_memcpy(fb_save, screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); // Close full screen display +#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) #ifdef ENABLE_XF86_DGA - XF86DGADirectVideo(x_display, screen, 0); + if (!is_fbdev_dga_mode) + XF86DGADirectVideo(x_display, screen, 0); +#endif XUngrabPointer(x_display, CurrentTime); XUngrabKeyboard(x_display, CurrentTime); #endif + restore_mouse_accel(); + XUnmapWindow(x_display, the_win); + wait_unmapped(the_win); XSync(x_display, false); // Open "suspend" window XSetWindowAttributes wattr; wattr.event_mask = KeyPressMask; - wattr.background_pixel = black_pixel; - wattr.border_pixel = black_pixel; + wattr.background_pixel = (vis == DefaultVisual(x_display, screen) ? black_pixel : 0); wattr.backing_store = Always; - wattr.backing_planes = xdepth; - wattr.colormap = DefaultColormap(x_display, screen); - XSync(x_display, false); + wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); + 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 | CWBackingStore | CWColormap, &wattr); + set_window_name(suspend_win, STR_SUSPEND_WINDOW_TITLE); + set_window_focus(suspend_win); + XMapWindow(x_display, suspend_win); + emul_suspended = true; } } @@ -1278,11 +1650,18 @@ static void resume_emul(void) XSync(x_display, false); // Reopen full screen display - XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime); - XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); + XMapRaised(x_display, the_win); + wait_mapped(the_win); + XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); + Window w = is_fbdev_dga_mode ? the_win : rootwin; + XGrabKeyboard(x_display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime); + XGrabPointer(x_display, w, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); + disable_mouse_accel(); #ifdef ENABLE_XF86_DGA - XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); - XF86DGASetViewPort(x_display, screen, 0, 0); + if (!is_fbdev_dga_mode) { + XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); + XF86DGASetViewPort(x_display, screen, 0, 0); + } #endif XSync(x_display, false); @@ -1304,16 +1683,14 @@ static void resume_emul(void) // Don't copy fb_save to the temporary frame buffer in VOSF mode if (!use_vosf) #endif - memcpy((void *)screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); + Host2Mac_memcpy(screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); free(fb_save); fb_save = NULL; } - if (depth == 8) - palette_changed = true; - // Resume MacOS thread + // Unlock frame buffer (and continue MacOS thread) + UNLOCK_FRAME_BUFFER; emul_suspended = false; - ResumeEmulator(); } @@ -1477,16 +1854,17 @@ static int kc_decode(KeySym ks) return -1; } -static int event2keycode(XKeyEvent &ev) +static int event2keycode(XKeyEvent &ev, bool key_down) { KeySym ks; - int as; int i = 0; do { ks = XLookupKeysym(&ev, i++); - as = kc_decode(ks); - if (as != -1) + int as = kc_decode(ks); + if (as >= 0) + return as; + if (as == -2) return as; } while (ks != NoSymbol); @@ -1561,12 +1939,24 @@ static void handle_events(void) // Keyboard case KeyPress: { - int code = event2keycode(event.xkey); - if (use_keycodes && code != -1) - code = keycode_table[event.xkey.keycode & 0xff]; - if (code != -1) { + int code = -1; + if (use_keycodes) { + if (event2keycode(event.xkey, true) != -2) // This is called to process the hotkeys + code = keycode_table[event.xkey.keycode & 0xff]; + } else + code = event2keycode(event.xkey, true); + if (code >= 0) { if (!emul_suspended) { - ADBKeyDown(code); + if (code == 0x39) { // Caps Lock pressed + if (caps_on) { + ADBKeyUp(code); + caps_on = false; + } else { + ADBKeyDown(code); + caps_on = true; + } + } else + ADBKeyDown(code); if (code == 0x36) ctrl_down = true; } else { @@ -1577,10 +1967,13 @@ static void handle_events(void) break; } case KeyRelease: { - int code = event2keycode(event.xkey); - if (use_keycodes && code != 1) - code = keycode_table[event.xkey.keycode & 0xff]; - if (code != -1) { + int code = -1; + if (use_keycodes) { + if (event2keycode(event.xkey, false) != -2) // This is called to process the hotkeys + code = keycode_table[event.xkey.keycode & 0xff]; + } else + code = event2keycode(event.xkey, false); + if (code >= 0 && code != 0x39) { // Don't propagate Caps Lock releases ADBKeyUp(code); if (code == 0x36) ctrl_down = false; @@ -1613,6 +2006,11 @@ void VideoVBL(void) if (emerg_quit) QuitEmulator(); + // Temporarily give up frame buffer lock (this is the point where + // we are suspended when the user presses Ctrl-Tab) + UNLOCK_FRAME_BUFFER; + LOCK_FRAME_BUFFER; + // Execute video VBL if (private_data != NULL && private_data->interruptsEnabled) VSLDoInterruptService(private_data->vslServiceID); @@ -1620,371 +2018,6 @@ void VideoVBL(void) /* - * Install graphics acceleration - */ - -// Rectangle inversion -template< int bpp > -static inline void do_invrect(uint8 *dest, uint32 length) -{ -#define INVERT_1(PTR, OFS) ((uint8 *)(PTR))[OFS] = ~((uint8 *)(PTR))[OFS] -#define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS] -#define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS] -#define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS] - -#ifndef UNALIGNED_PROFITABLE - // Align on 16-bit boundaries - if (bpp < 16 && (((uintptr)dest) & 1)) { - INVERT_1(dest, 0); - dest += 1; length -= 1; - } - - // Align on 32-bit boundaries - if (bpp < 32 && (((uintptr)dest) & 2)) { - INVERT_2(dest, 0); - dest += 2; length -= 2; - } -#endif - - // Invert 8-byte words - if (length >= 8) { - const int r = (length / 8) % 8; - dest += r * 8; - - int n = ((length / 8) + 7) / 8; - switch (r) { - case 0: do { - dest += 64; - INVERT_8(dest, -8); - case 7: INVERT_8(dest, -7); - case 6: INVERT_8(dest, -6); - case 5: INVERT_8(dest, -5); - case 4: INVERT_8(dest, -4); - case 3: INVERT_8(dest, -3); - case 2: INVERT_8(dest, -2); - case 1: INVERT_8(dest, -1); - } while (--n > 0); - } - } - - // 32-bit cell to invert? - if (length & 4) { - INVERT_4(dest, 0); - if (bpp <= 16) - dest += 4; - } - - // 16-bit cell to invert? - if (bpp <= 16 && (length & 2)) { - INVERT_2(dest, 0); - if (bpp <= 8) - dest += 2; - } - - // 8-bit cell to invert? - if (bpp <= 8 && (length & 1)) - INVERT_1(dest, 0); - -#undef INVERT_1 -#undef INVERT_2 -#undef INVERT_4 -#undef INVERT_8 -} - -void NQD_invrect(uint32 p) -{ - D(bug("accl_invrect %08x\n", p)); - - // Get inversion parameters - int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); - int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); - int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); - int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); - D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); - D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes))); - - //!!?? pen_mode == 14 - - // And perform the inversion - const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); - const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); - uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); - width *= bpp; - switch (bpp) { - case 1: - for (int i = 0; i < height; i++) { - do_invrect<8>(dest, width); - dest += dest_row_bytes; - } - break; - case 2: - for (int i = 0; i < height; i++) { - do_invrect<16>(dest, width); - dest += dest_row_bytes; - } - break; - case 4: - for (int i = 0; i < height; i++) { - do_invrect<32>(dest, width); - dest += dest_row_bytes; - } - break; - } -} - -// Rectangle filling -template< int bpp > -static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length) -{ -#define FILL_1(PTR, OFS, VAL) ((uint8 *)(PTR))[OFS] = (VAL) -#define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL) -#define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL) -#define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL) - -#ifndef UNALIGNED_PROFITABLE - // Align on 16-bit boundaries - if (bpp < 16 && (((uintptr)dest) & 1)) { - FILL_1(dest, 0, color); - dest += 1; length -= 1; - } - - // Align on 32-bit boundaries - if (bpp < 32 && (((uintptr)dest) & 2)) { - FILL_2(dest, 0, color); - dest += 2; length -= 2; - } -#endif - - // Fill 8-byte words - if (length >= 8) { - const uint64 c = (((uint64)color) << 32) | color; - const int r = (length / 8) % 8; - dest += r * 8; - - int n = ((length / 8) + 7) / 8; - switch (r) { - case 0: do { - dest += 64; - FILL_8(dest, -8, c); - case 7: FILL_8(dest, -7, c); - case 6: FILL_8(dest, -6, c); - case 5: FILL_8(dest, -5, c); - case 4: FILL_8(dest, -4, c); - case 3: FILL_8(dest, -3, c); - case 2: FILL_8(dest, -2, c); - case 1: FILL_8(dest, -1, c); - } while (--n > 0); - } - } - - // 32-bit cell to fill? - if (length & 4) { - FILL_4(dest, 0, color); - if (bpp <= 16) - dest += 4; - } - - // 16-bit cell to fill? - if (bpp <= 16 && (length & 2)) { - FILL_2(dest, 0, color); - if (bpp <= 8) - dest += 2; - } - - // 8-bit cell to fill? - if (bpp <= 8 && (length & 1)) - FILL_1(dest, 0, color); - -#undef FILL_1 -#undef FILL_2 -#undef FILL_4 -#undef FILL_8 -} - -void NQD_fillrect(uint32 p) -{ - D(bug("accl_fillrect %08x\n", p)); - - // Get filling parameters - int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); - int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); - int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); - int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); - uint32 color = ReadMacInt32(p + acclPenMode) == 8 ? ReadMacInt32(p + acclForePen) : ReadMacInt32(p + acclBackPen); - D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); - D(bug(" width %d, height %d\n", width, height)); - D(bug(" bytes_per_row %d color %08x\n", (int32)ReadMacInt32(p + acclDestRowBytes), color)); - - // And perform the fill - const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); - const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); - uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); - width *= bpp; - switch (bpp) { - case 1: - for (int i = 0; i < height; i++) { - memset(dest, color, width); - dest += dest_row_bytes; - } - break; - case 2: - for (int i = 0; i < height; i++) { - do_fillrect<16>(dest, color, width); - dest += dest_row_bytes; - } - break; - case 4: - for (int i = 0; i < height; i++) { - do_fillrect<32>(dest, color, width); - dest += dest_row_bytes; - } - break; - } -} - -bool NQD_fillrect_hook(uint32 p) -{ - D(bug("accl_fillrect_hook %08x\n", p)); - - // Check if we can accelerate this fillrect - if (ReadMacInt32(p + 0x284) != 0 && ReadMacInt32(p + acclDestPixelSize) >= 8) { - const int transfer_mode = ReadMacInt32(p + acclTransferMode); - if (transfer_mode == 8) { - // Fill - WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_FILLRECT)); - return true; - } - else if (transfer_mode == 10) { - // Invert - WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_INVRECT)); - return true; - } - } - return false; -} - -// Rectangle blitting -// TODO: optimize for VOSF and target pixmap == screen -void NQD_bitblt(uint32 p) -{ - D(bug("accl_bitblt %08x\n", p)); - - // Get blitting parameters - int16 src_X = (int16)ReadMacInt16(p + acclSrcRect + 2) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 2); - int16 src_Y = (int16)ReadMacInt16(p + acclSrcRect + 0) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 0); - int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); - int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); - int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); - int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); - D(bug(" src addr %08x, dest addr %08x\n", ReadMacInt32(p + acclSrcBaseAddr), ReadMacInt32(p + acclDestBaseAddr))); - D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y)); - D(bug(" width %d, height %d\n", width, height)); - - // And perform the blit - const int bpp = bytes_per_pixel(ReadMacInt32(p + acclSrcPixelSize)); - width *= bpp; - if ((int32)ReadMacInt32(p + acclSrcRowBytes) > 0) { - const int src_row_bytes = (int32)ReadMacInt32(p + acclSrcRowBytes); - const int dst_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); - uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + (src_Y * src_row_bytes) + (src_X * bpp)); - uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dst_row_bytes) + (dest_X * bpp)); - for (int i = 0; i < height; i++) { - memmove(dst, src, width); - src += src_row_bytes; - dst += dst_row_bytes; - } - } - else { - const int src_row_bytes = -(int32)ReadMacInt32(p + acclSrcRowBytes); - const int dst_row_bytes = -(int32)ReadMacInt32(p + acclDestRowBytes); - uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp)); - uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp)); - for (int i = height - 1; i >= 0; i--) { - memmove(dst, src, width); - src -= src_row_bytes; - dst -= dst_row_bytes; - } - } -} - -/* - BitBlt transfer modes: - 0 : srcCopy - 1 : srcOr - 2 : srcXor - 3 : srcBic - 4 : notSrcCopy - 5 : notSrcOr - 6 : notSrcXor - 7 : notSrcBic - 32 : blend - 33 : addPin - 34 : addOver - 35 : subPin - 36 : transparent - 37 : adMax - 38 : subOver - 39 : adMin - 50 : hilite -*/ - -bool NQD_bitblt_hook(uint32 p) -{ - D(bug("accl_draw_hook %08x\n", p)); - - // Check if we can accelerate this bitblt - if (ReadMacInt32(p + 0x018) + ReadMacInt32(p + 0x128) == 0 && - ReadMacInt32(p + 0x130) == 0 && - ReadMacInt32(p + acclSrcPixelSize) >= 8 && - ReadMacInt32(p + acclSrcPixelSize) == ReadMacInt32(p + acclDestPixelSize) && - (ReadMacInt32(p + acclSrcRowBytes) ^ ReadMacInt32(p + acclDestRowBytes)) >= 0 && // same sign? - ReadMacInt32(p + acclTransferMode) == 0 && // srcCopy? - ReadMacInt32(p + 0x15c) > 0) { - - // Yes, set function pointer - WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_BITBLT)); - return true; - } - return false; -} - -// Wait for graphics operation to finish -bool NQD_sync_hook(uint32 arg) -{ - D(bug("accl_sync_hook %08x\n", arg)); - return true; -} - -void VideoInstallAccel(void) -{ - // Temporary hack until it's fixed for e.g. little-endian & 64-bit platforms -#ifndef __powerpc__ - return; -#endif - - // Install acceleration hooks - if (PrefsFindBool("gfxaccel")) { - D(bug("Video: Installing acceleration hooks\n")); - uint32 base; - - SheepVar bitblt_hook_info(sizeof(accl_hook_info)); - base = bitblt_hook_info.addr(); - WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK)); - WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); - WriteMacInt32(base + 8, ACCL_BITBLT); - NQDMisc(6, bitblt_hook_info.ptr()); - - SheepVar fillrect_hook_info(sizeof(accl_hook_info)); - base = fillrect_hook_info.addr(); - WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK)); - WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); - WriteMacInt32(base + 8, ACCL_FILLRECT); - NQDMisc(6, fillrect_hook_info.ptr()); - } -} - - -/* * Change video mode */ @@ -2257,7 +2290,7 @@ static void handle_palette_changes(void) } #ifdef ENABLE_XF86_DGA - if (display_type == DIS_SCREEN) { + if (display_type == DIS_SCREEN && !is_fbdev_dga_mode) { current_dga_cmap ^= 1; if (!IsDirectMode(mode) && cmap[current_dga_cmap]) XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); @@ -2276,7 +2309,7 @@ static void *redraw_func(void *arg) int64 ticks = 0; uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; - for (;;) { + while (!redraw_thread_cancel) { // Pause if requested (during video mode switches) while (thread_stop_req) @@ -2302,8 +2335,11 @@ static void *redraw_func(void *arg) quit_full_screen = false; if (display_type == DIS_SCREEN) { XDisplayLock(); +#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) #ifdef ENABLE_XF86_DGA - XF86DGADirectVideo(x_display, screen, 0); + if (is_fbdev_dga_mode) + XF86DGADirectVideo(x_display, screen, 0); +#endif XUngrabPointer(x_display, CurrentTime); XUngrabKeyboard(x_display, CurrentTime); XUnmapWindow(x_display, the_win); @@ -2343,8 +2379,12 @@ static void *redraw_func(void *arg) // Set new cursor image if it was changed if (hw_mac_cursor_accl && cursor_changed) { cursor_changed = false; - memcpy(cursor_image->data, MacCursor + 4, 32); - memcpy(cursor_mask_image->data, MacCursor + 36, 32); + uint8 *x_data = (uint8 *)cursor_image->data; + uint8 *x_mask = (uint8 *)cursor_mask_image->data; + for (int i = 0; i < 32; i++) { + x_mask[i] = MacCursor[4 + i] | MacCursor[36 + i]; + x_data[i] = MacCursor[4 + i]; + } XDisplayLock(); XFreeCursor(x_display, mac_cursor); XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16);