32 |
|
#include <algorithm> |
33 |
|
|
34 |
|
#ifdef ENABLE_XF86_DGA |
35 |
< |
#include <X11/extensions/xf86dga.h> |
35 |
> |
# include <X11/extensions/xf86dga.h> |
36 |
|
#endif |
37 |
|
|
38 |
|
#ifdef ENABLE_XF86_VIDMODE |
46 |
|
#include "about_window.h" |
47 |
|
#include "video.h" |
48 |
|
#include "video_defs.h" |
49 |
+ |
#include "video_blit.h" |
50 |
|
|
51 |
|
#define DEBUG 0 |
52 |
|
#include "debug.h" |
58 |
|
|
59 |
|
// Constants |
60 |
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; |
61 |
+ |
static const bool hw_mac_cursor_accl = true; // Flag: Enable MacOS to X11 copy of cursor? |
62 |
|
|
63 |
|
// Global variables |
64 |
|
static int32 frame_skip; |
65 |
|
static int16 mouse_wheel_mode; |
66 |
|
static int16 mouse_wheel_lines; |
67 |
|
static bool redraw_thread_active = false; // Flag: Redraw thread installed |
68 |
+ |
static pthread_attr_t redraw_thread_attr; // Redraw thread attributes |
69 |
+ |
static volatile bool redraw_thread_cancel; // Flag: Cancel Redraw thread |
70 |
|
static pthread_t redraw_thread; // Redraw thread |
71 |
|
|
72 |
|
static bool local_X11; // Flag: X server running on local machine? |
84 |
|
|
85 |
|
static bool palette_changed = false; // Flag: Palette changed, redraw thread must update palette |
86 |
|
static bool ctrl_down = false; // Flag: Ctrl key pressed |
87 |
+ |
static bool caps_on = false; // Flag: Caps Lock on |
88 |
|
static bool quit_full_screen = false; // Flag: DGA close requested from redraw thread |
89 |
|
static volatile bool quit_full_screen_ack = false; // Acknowledge for quit_full_screen |
90 |
|
static bool emerg_quit = false; // Flag: Ctrl-Esc pressed, emergency quit requested from MacOS thread |
102 |
|
static Window rootwin, the_win; // Root window and our window |
103 |
|
static int num_depths = 0; // Number of available X depths |
104 |
|
static int *avail_depths = NULL; // List of available X depths |
105 |
+ |
static VisualFormat visualFormat; |
106 |
|
static XVisualInfo visualInfo; |
107 |
|
static Visual *vis; |
108 |
|
static int color_class; |
131 |
|
static uint32 the_buffer_size; // Size of allocated the_buffer |
132 |
|
|
133 |
|
// Variables for DGA mode |
128 |
– |
static char *dga_screen_base; |
129 |
– |
static int dga_fb_width; |
134 |
|
static int current_dga_cmap; |
135 |
|
|
136 |
|
#ifdef ENABLE_XF86_VIDMODE |
200 |
|
} |
201 |
|
} |
202 |
|
|
203 |
+ |
// Return bits per pixel for requested depth |
204 |
+ |
static inline int bytes_per_pixel(int depth) |
205 |
+ |
{ |
206 |
+ |
int bpp; |
207 |
+ |
switch (depth) { |
208 |
+ |
case 8: |
209 |
+ |
bpp = 1; |
210 |
+ |
break; |
211 |
+ |
case 15: case 16: |
212 |
+ |
bpp = 2; |
213 |
+ |
break; |
214 |
+ |
case 24: case 32: |
215 |
+ |
bpp = 4; |
216 |
+ |
break; |
217 |
+ |
default: |
218 |
+ |
abort(); |
219 |
+ |
} |
220 |
+ |
return bpp; |
221 |
+ |
} |
222 |
+ |
|
223 |
|
// Map video_mode depth ID to numerical depth value |
224 |
|
static inline int depth_of_video_mode(int mode) |
225 |
|
{ |
226 |
< |
int depth = -1; |
226 |
> |
int depth; |
227 |
|
switch (mode) { |
228 |
|
case APPLE_1_BIT: |
229 |
|
depth = 1; |
364 |
|
* Open display (window or fullscreen) |
365 |
|
*/ |
366 |
|
|
367 |
+ |
// Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget) |
368 |
+ |
static Atom WM_DELETE_WINDOW = (Atom)0; |
369 |
+ |
static void set_window_delete_protocol(Window w) |
370 |
+ |
{ |
371 |
+ |
WM_DELETE_WINDOW = XInternAtom(x_display, "WM_DELETE_WINDOW", false); |
372 |
+ |
XSetWMProtocols(x_display, w, &WM_DELETE_WINDOW, 1); |
373 |
+ |
} |
374 |
+ |
|
375 |
|
// Wait until window is mapped/unmapped |
376 |
< |
void wait_mapped(Window w) |
376 |
> |
static void wait_mapped(Window w) |
377 |
|
{ |
378 |
|
XEvent e; |
379 |
|
do { |
381 |
|
} while ((e.type != MapNotify) || (e.xmap.event != w)); |
382 |
|
} |
383 |
|
|
384 |
< |
void wait_unmapped(Window w) |
384 |
> |
static void wait_unmapped(Window w) |
385 |
|
{ |
386 |
|
XEvent e; |
387 |
|
do { |
424 |
|
// Set window name |
425 |
|
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); |
426 |
|
|
427 |
+ |
// Set delete protocol property |
428 |
+ |
set_window_delete_protocol(the_win); |
429 |
+ |
|
430 |
|
// Make window unresizable |
431 |
|
XSizeHints *hints; |
432 |
|
if ((hints = XAllocSizeHints()) != NULL) { |
503 |
|
the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line); |
504 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); |
505 |
|
#endif |
506 |
< |
screen_base = (uint32)the_buffer; |
506 |
> |
screen_base = Host2MacAddr(the_buffer); |
507 |
|
|
508 |
|
// Create GC |
509 |
|
the_gc = XCreateGC(x_display, the_win, 0, 0); |
510 |
|
XSetState(x_display, the_gc, black_pixel, white_pixel, GXcopy, AllPlanes); |
511 |
|
|
512 |
|
// Create cursor |
513 |
< |
cursor_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 4, 16, 16, 16, 2); |
514 |
< |
cursor_image->byte_order = MSBFirst; |
515 |
< |
cursor_image->bitmap_bit_order = MSBFirst; |
516 |
< |
cursor_mask_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 36, 16, 16, 16, 2); |
517 |
< |
cursor_mask_image->byte_order = MSBFirst; |
518 |
< |
cursor_mask_image->bitmap_bit_order = MSBFirst; |
519 |
< |
cursor_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
520 |
< |
cursor_mask_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
521 |
< |
cursor_gc = XCreateGC(x_display, cursor_map, 0, 0); |
522 |
< |
cursor_mask_gc = XCreateGC(x_display, cursor_mask_map, 0, 0); |
523 |
< |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, 0, 0); |
524 |
< |
cursor_changed = false; |
513 |
> |
if (hw_mac_cursor_accl) { |
514 |
> |
cursor_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 4, 16, 16, 16, 2); |
515 |
> |
cursor_image->byte_order = MSBFirst; |
516 |
> |
cursor_image->bitmap_bit_order = MSBFirst; |
517 |
> |
cursor_mask_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 36, 16, 16, 16, 2); |
518 |
> |
cursor_mask_image->byte_order = MSBFirst; |
519 |
> |
cursor_mask_image->bitmap_bit_order = MSBFirst; |
520 |
> |
cursor_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
521 |
> |
cursor_mask_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
522 |
> |
cursor_gc = XCreateGC(x_display, cursor_map, 0, 0); |
523 |
> |
cursor_mask_gc = XCreateGC(x_display, cursor_mask_map, 0, 0); |
524 |
> |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, 0, 0); |
525 |
> |
cursor_changed = false; |
526 |
> |
} |
527 |
> |
|
528 |
> |
// Create no_cursor |
529 |
> |
else { |
530 |
> |
mac_cursor = XCreatePixmapCursor(x_display, |
531 |
> |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
532 |
> |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
533 |
> |
&black, &white, 0, 0); |
534 |
> |
XDefineCursor(x_display, the_win, mac_cursor); |
535 |
> |
} |
536 |
|
|
537 |
|
// Init blitting routines |
538 |
|
bool native_byte_order; |
542 |
|
native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
543 |
|
#endif |
544 |
|
#ifdef ENABLE_VOSF |
545 |
< |
Screen_blitter_init(&visualInfo, native_byte_order, depth); |
545 |
> |
Screen_blitter_init(visualFormat, native_byte_order, depth); |
546 |
|
#endif |
547 |
|
|
548 |
|
// Set bytes per row |
557 |
|
// Set relative mouse mode |
558 |
|
ADBSetRelMouseMode(true); |
559 |
|
|
560 |
+ |
// Create window |
561 |
+ |
XSetWindowAttributes wattr; |
562 |
+ |
wattr.event_mask = eventmask = dga_eventmask; |
563 |
+ |
wattr.override_redirect = True; |
564 |
+ |
wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); |
565 |
+ |
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
566 |
+ |
InputOutput, vis, CWEventMask | CWOverrideRedirect | |
567 |
+ |
(color_class == DirectColor ? CWColormap : 0), &wattr); |
568 |
+ |
|
569 |
+ |
// Show window |
570 |
+ |
XMapRaised(x_display, the_win); |
571 |
+ |
wait_mapped(the_win); |
572 |
+ |
|
573 |
|
#ifdef ENABLE_XF86_VIDMODE |
574 |
|
// Switch to best mode |
575 |
|
if (has_vidmode) { |
586 |
|
#endif |
587 |
|
|
588 |
|
// Establish direct screen connection |
589 |
+ |
XMoveResizeWindow(x_display, the_win, 0, 0, width, height); |
590 |
+ |
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
591 |
|
XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
592 |
|
XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
593 |
+ |
|
594 |
+ |
int v_width, v_bank, v_size; |
595 |
+ |
XF86DGAGetVideo(x_display, screen, (char **)&the_buffer, &v_width, &v_bank, &v_size); |
596 |
|
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
597 |
|
XF86DGASetViewPort(x_display, screen, 0, 0); |
598 |
|
XF86DGASetVidPage(x_display, screen, 0); |
599 |
|
|
600 |
|
// Set colormap |
601 |
< |
if (depth == 8) |
601 |
> |
if (!IsDirectMode(get_current_mode())) { |
602 |
> |
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); |
603 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
604 |
+ |
} |
605 |
+ |
XSync(x_display, false); |
606 |
|
|
607 |
< |
// Set bytes per row |
608 |
< |
int bytes_per_row = TrivialBytesPerRow((dga_fb_width + 7) & ~7, DepthModeForPixelDepth(depth)); |
542 |
< |
|
607 |
> |
// Init blitting routines |
608 |
> |
int bytes_per_row = TrivialBytesPerRow((v_width + 7) & ~7, DepthModeForPixelDepth(depth)); |
609 |
|
#if ENABLE_VOSF |
610 |
|
bool native_byte_order; |
611 |
|
#ifdef WORDS_BIGENDIAN |
616 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
617 |
|
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
618 |
|
// i.e. the framebuffer update function is not Blit_Copy_Raw |
619 |
< |
use_vosf = Screen_blitter_init(&visualInfo, native_byte_order, depth); |
619 |
> |
use_vosf = Screen_blitter_init(visualFormat, native_byte_order, depth); |
620 |
|
|
621 |
|
if (use_vosf) { |
622 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
624 |
|
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
625 |
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
626 |
|
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
627 |
+ |
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
628 |
|
} |
629 |
|
#else |
630 |
|
use_vosf = false; |
564 |
– |
the_buffer = dga_screen_base; |
631 |
|
#endif |
632 |
|
#endif |
567 |
– |
screen_base = (uint32)the_buffer; |
633 |
|
|
634 |
+ |
// Set frame buffer base |
635 |
+ |
D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); |
636 |
+ |
screen_base = Host2MacAddr(the_buffer); |
637 |
|
VModes[cur_mode].viRowBytes = bytes_per_row; |
570 |
– |
XSync(x_display, false); |
638 |
|
return true; |
639 |
|
#else |
640 |
|
ErrorAlert("SheepShaver has been compiled with DGA support disabled."); |
653 |
|
return false; |
654 |
|
} |
655 |
|
|
656 |
+ |
// Build up visualFormat structure |
657 |
+ |
visualFormat.depth = visualInfo.depth; |
658 |
+ |
visualFormat.Rmask = visualInfo.red_mask; |
659 |
+ |
visualFormat.Gmask = visualInfo.green_mask; |
660 |
+ |
visualFormat.Bmask = visualInfo.blue_mask; |
661 |
+ |
|
662 |
|
// Create color maps |
663 |
|
if (color_class == PseudoColor || color_class == DirectColor) { |
664 |
|
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
773 |
|
if (the_gc) |
774 |
|
XFreeGC(x_display, the_gc); |
775 |
|
|
703 |
– |
// Close window |
704 |
– |
if (the_win) { |
705 |
– |
XUnmapWindow(x_display, the_win); |
706 |
– |
wait_unmapped(the_win); |
707 |
– |
XDestroyWindow(x_display, the_win); |
708 |
– |
} |
709 |
– |
|
776 |
|
XFlush(x_display); |
777 |
|
XSync(x_display, false); |
778 |
|
} |
810 |
|
else if (display_type == DIS_WINDOW) |
811 |
|
close_window(); |
812 |
|
|
813 |
+ |
// Close window |
814 |
+ |
if (the_win) { |
815 |
+ |
XUnmapWindow(x_display, the_win); |
816 |
+ |
wait_unmapped(the_win); |
817 |
+ |
XDestroyWindow(x_display, the_win); |
818 |
+ |
} |
819 |
+ |
|
820 |
|
// Free colormaps |
821 |
|
if (cmap[0]) { |
822 |
|
XFreeColormap(x_display, cmap[0]); |
892 |
|
|
893 |
|
// Search for server vendor string, then read keycodes |
894 |
|
const char *vendor = ServerVendor(x_display); |
895 |
+ |
// Force use of MacX mappings on MacOS X with Apple's X server |
896 |
+ |
int dummy; |
897 |
+ |
if (XQueryExtension(x_display, "Apple-DRI", &dummy, &dummy, &dummy)) |
898 |
+ |
vendor = "MacX"; |
899 |
|
bool vendor_found = false; |
900 |
|
char line[256]; |
901 |
|
while (fgets(line, 255, f)) { |
937 |
|
} |
938 |
|
} |
939 |
|
|
940 |
+ |
// Find Apple mode matching best specified dimensions |
941 |
+ |
static int find_apple_resolution(int xsize, int ysize) |
942 |
+ |
{ |
943 |
+ |
int apple_id; |
944 |
+ |
if (xsize < 800) |
945 |
+ |
apple_id = APPLE_640x480; |
946 |
+ |
else if (xsize < 1024) |
947 |
+ |
apple_id = APPLE_800x600; |
948 |
+ |
else if (xsize < 1152) |
949 |
+ |
apple_id = APPLE_1024x768; |
950 |
+ |
else if (xsize < 1280) { |
951 |
+ |
if (ysize < 900) |
952 |
+ |
apple_id = APPLE_1152x768; |
953 |
+ |
else |
954 |
+ |
apple_id = APPLE_1152x900; |
955 |
+ |
} |
956 |
+ |
else if (xsize < 1600) |
957 |
+ |
apple_id = APPLE_1280x1024; |
958 |
+ |
else |
959 |
+ |
apple_id = APPLE_1600x1200; |
960 |
+ |
return apple_id; |
961 |
+ |
} |
962 |
+ |
|
963 |
+ |
// Find mode in list of supported modes |
964 |
+ |
static int find_mode(int apple_mode, int apple_id, int type) |
965 |
+ |
{ |
966 |
+ |
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
967 |
+ |
if (p->viType == type && p->viAppleID == apple_id && p->viAppleMode == apple_mode) |
968 |
+ |
return p - VModes; |
969 |
+ |
} |
970 |
+ |
return -1; |
971 |
+ |
} |
972 |
+ |
|
973 |
|
// Add mode to list of supported modes |
974 |
|
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type) |
975 |
|
{ |
990 |
|
p->viXsize = 1024; |
991 |
|
p->viYsize = 768; |
992 |
|
break; |
993 |
+ |
case APPLE_1152x768: |
994 |
+ |
p->viXsize = 1152; |
995 |
+ |
p->viYsize = 768; |
996 |
+ |
break; |
997 |
|
case APPLE_1152x900: |
998 |
|
p->viXsize = 1152; |
999 |
|
p->viYsize = 900; |
1140 |
|
add_mode(p, screen_modes, 2, default_mode, APPLE_800x600, DIS_SCREEN); |
1141 |
|
if (has_mode(1024, 768)) |
1142 |
|
add_mode(p, screen_modes, 4, default_mode, APPLE_1024x768, DIS_SCREEN); |
1143 |
+ |
if (has_mode(1152, 768)) |
1144 |
+ |
add_mode(p, screen_modes, 64, default_mode, APPLE_1152x768, DIS_SCREEN); |
1145 |
|
if (has_mode(1152, 900)) |
1146 |
|
add_mode(p, screen_modes, 8, default_mode, APPLE_1152x900, DIS_SCREEN); |
1147 |
|
if (has_mode(1280, 1024)) |
1151 |
|
} else if (screen_modes) { |
1152 |
|
int xsize = DisplayWidth(x_display, screen); |
1153 |
|
int ysize = DisplayHeight(x_display, screen); |
1154 |
< |
int apple_id; |
1039 |
< |
if (xsize < 800) |
1040 |
< |
apple_id = APPLE_640x480; |
1041 |
< |
else if (xsize < 1024) |
1042 |
< |
apple_id = APPLE_800x600; |
1043 |
< |
else if (xsize < 1152) |
1044 |
< |
apple_id = APPLE_1024x768; |
1045 |
< |
else if (xsize < 1280) |
1046 |
< |
apple_id = APPLE_1152x900; |
1047 |
< |
else if (xsize < 1600) |
1048 |
< |
apple_id = APPLE_1280x1024; |
1049 |
< |
else |
1050 |
< |
apple_id = APPLE_1600x1200; |
1154 |
> |
int apple_id = find_apple_resolution(xsize, ysize); |
1155 |
|
p->viType = DIS_SCREEN; |
1156 |
|
p->viRowBytes = 0; |
1157 |
|
p->viXsize = xsize; |
1168 |
|
|
1169 |
|
// Find default mode (window 640x480) |
1170 |
|
cur_mode = -1; |
1171 |
< |
for (p = VModes; p->viType != DIS_INVALID; p++) { |
1172 |
< |
if (p->viType == DIS_WINDOW |
1173 |
< |
&& p->viAppleID == APPLE_W_640x480 |
1174 |
< |
&& p->viAppleMode == default_mode) { |
1175 |
< |
cur_mode = p - VModes; |
1176 |
< |
break; |
1171 |
> |
if (has_dga && screen_modes) { |
1172 |
> |
int screen_width = DisplayWidth(x_display, screen); |
1173 |
> |
int screen_height = DisplayHeight(x_display, screen); |
1174 |
> |
int apple_id = find_apple_resolution(screen_width, screen_height); |
1175 |
> |
if (apple_id != -1) |
1176 |
> |
cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN); |
1177 |
> |
} |
1178 |
> |
if (cur_mode == -1) { |
1179 |
> |
// pick up first windowed mode available |
1180 |
> |
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
1181 |
> |
if (p->viType == DIS_WINDOW && p->viAppleMode == default_mode) { |
1182 |
> |
cur_mode = p - VModes; |
1183 |
> |
break; |
1184 |
> |
} |
1185 |
|
} |
1186 |
|
} |
1187 |
|
assert(cur_mode != -1); |
1194 |
|
} |
1195 |
|
#endif |
1196 |
|
|
1085 |
– |
#ifdef ENABLE_XF86_DGA |
1086 |
– |
if (has_dga && screen_modes) { |
1087 |
– |
int v_bank, v_size; |
1088 |
– |
XF86DGAGetVideo(x_display, screen, &dga_screen_base, &dga_fb_width, &v_bank, &v_size); |
1089 |
– |
D(bug("DGA screen_base %p, v_width %d\n", dga_screen_base, dga_fb_width)); |
1090 |
– |
} |
1091 |
– |
#endif |
1092 |
– |
|
1197 |
|
// Open window/screen |
1198 |
|
if (!open_display()) |
1199 |
|
return false; |
1205 |
|
|
1206 |
|
// Start periodic thread |
1207 |
|
XSync(x_display, false); |
1208 |
< |
redraw_thread_active = (pthread_create(&redraw_thread, NULL, redraw_func, NULL) == 0); |
1208 |
> |
Set_pthread_attr(&redraw_thread_attr, 0); |
1209 |
> |
redraw_thread_cancel = false; |
1210 |
> |
redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0); |
1211 |
|
D(bug("Redraw thread installed (%ld)\n", redraw_thread)); |
1212 |
|
return true; |
1213 |
|
} |
1221 |
|
{ |
1222 |
|
// Stop redraw thread |
1223 |
|
if (redraw_thread_active) { |
1224 |
+ |
redraw_thread_cancel = true; |
1225 |
|
pthread_cancel(redraw_thread); |
1226 |
|
pthread_join(redraw_thread, NULL); |
1227 |
|
redraw_thread_active = false; |
1265 |
|
// Save frame buffer |
1266 |
|
fb_save = malloc(VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1267 |
|
if (fb_save) |
1268 |
< |
memcpy(fb_save, (void *)screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1268 |
> |
Mac2Host_memcpy(fb_save, screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1269 |
|
|
1270 |
|
// Close full screen display |
1271 |
|
#ifdef ENABLE_XF86_DGA |
1327 |
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1328 |
|
if (!use_vosf) |
1329 |
|
#endif |
1330 |
< |
memcpy((void *)screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1330 |
> |
Host2Mac_memcpy(screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1331 |
|
free(fb_save); |
1332 |
|
fb_save = NULL; |
1333 |
|
} |
1500 |
|
return -1; |
1501 |
|
} |
1502 |
|
|
1503 |
< |
static int event2keycode(XKeyEvent &ev) |
1503 |
> |
static int event2keycode(XKeyEvent &ev, bool key_down) |
1504 |
|
{ |
1505 |
|
KeySym ks; |
1399 |
– |
int as; |
1506 |
|
int i = 0; |
1507 |
|
|
1508 |
|
do { |
1509 |
|
ks = XLookupKeysym(&ev, i++); |
1510 |
< |
as = kc_decode(ks); |
1511 |
< |
if (as != -1) |
1510 |
> |
int as = kc_decode(ks); |
1511 |
> |
if (as >= 0) |
1512 |
> |
return as; |
1513 |
> |
if (as == -2) |
1514 |
|
return as; |
1515 |
|
} while (ks != NoSymbol); |
1516 |
|
|
1531 |
|
else if (XCheckTypedEvent(x_display, SelectionClear, &event)) |
1532 |
|
ClipboardSelectionClear(&event.xselectionclear); |
1533 |
|
|
1534 |
+ |
// Window "close" widget clicked |
1535 |
+ |
else if (XCheckTypedEvent(x_display, ClientMessage, &event)) { |
1536 |
+ |
if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW) { |
1537 |
+ |
ADBKeyDown(0x7f); // Power key |
1538 |
+ |
ADBKeyUp(0x7f); |
1539 |
+ |
} |
1540 |
+ |
} |
1541 |
+ |
|
1542 |
|
XDisplayUnlock(); |
1543 |
|
break; |
1544 |
|
} |
1572 |
|
break; |
1573 |
|
} |
1574 |
|
|
1575 |
< |
// Mouse moved |
1575 |
> |
// Mouse entered window |
1576 |
|
case EnterNotify: |
1577 |
< |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1577 |
> |
if (event.xcrossing.mode != NotifyGrab && event.xcrossing.mode != NotifyUngrab) |
1578 |
> |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
1579 |
|
break; |
1580 |
+ |
|
1581 |
+ |
// Mouse moved |
1582 |
|
case MotionNotify: |
1583 |
< |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1583 |
> |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
1584 |
|
break; |
1585 |
|
|
1586 |
|
// Keyboard |
1587 |
|
case KeyPress: { |
1588 |
< |
int code = event2keycode(event.xkey); |
1589 |
< |
if (use_keycodes && code != -1) |
1590 |
< |
code = keycode_table[event.xkey.keycode & 0xff]; |
1591 |
< |
if (code != -1) { |
1588 |
> |
int code = -1; |
1589 |
> |
if (use_keycodes) { |
1590 |
> |
if (event2keycode(event.xkey, true) != -2) // This is called to process the hotkeys |
1591 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1592 |
> |
} else |
1593 |
> |
code = event2keycode(event.xkey, true); |
1594 |
> |
if (code >= 0) { |
1595 |
|
if (!emul_suspended) { |
1596 |
< |
ADBKeyDown(code); |
1596 |
> |
if (code == 0x39) { // Caps Lock pressed |
1597 |
> |
if (caps_on) { |
1598 |
> |
ADBKeyUp(code); |
1599 |
> |
caps_on = false; |
1600 |
> |
} else { |
1601 |
> |
ADBKeyDown(code); |
1602 |
> |
caps_on = true; |
1603 |
> |
} |
1604 |
> |
} else |
1605 |
> |
ADBKeyDown(code); |
1606 |
|
if (code == 0x36) |
1607 |
|
ctrl_down = true; |
1608 |
|
} else { |
1613 |
|
break; |
1614 |
|
} |
1615 |
|
case KeyRelease: { |
1616 |
< |
int code = event2keycode(event.xkey); |
1617 |
< |
if (use_keycodes && code != 1) |
1618 |
< |
code = keycode_table[event.xkey.keycode & 0xff]; |
1619 |
< |
if (code != -1) { |
1616 |
> |
int code = -1; |
1617 |
> |
if (use_keycodes) { |
1618 |
> |
if (event2keycode(event.xkey, false) != -2) // This is called to process the hotkeys |
1619 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1620 |
> |
} else |
1621 |
> |
code = event2keycode(event.xkey, false); |
1622 |
> |
if (code >= 0 && code != 0x39) { // Don't propagate Caps Lock releases |
1623 |
|
ADBKeyUp(code); |
1624 |
|
if (code == 0x36) |
1625 |
|
ctrl_down = false; |
1659 |
|
|
1660 |
|
|
1661 |
|
/* |
1528 |
– |
* Install graphics acceleration |
1529 |
– |
*/ |
1530 |
– |
|
1531 |
– |
#if 0 |
1532 |
– |
// Rectangle blitting |
1533 |
– |
static void accl_bitblt(accl_params *p) |
1534 |
– |
{ |
1535 |
– |
D(bug("accl_bitblt\n")); |
1536 |
– |
|
1537 |
– |
// Get blitting parameters |
1538 |
– |
int16 src_X = p->src_rect[1] - p->src_bounds[1]; |
1539 |
– |
int16 src_Y = p->src_rect[0] - p->src_bounds[0]; |
1540 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1541 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1542 |
– |
int16 width = p->dest_rect[3] - p->dest_rect[1] - 1; |
1543 |
– |
int16 height = p->dest_rect[2] - p->dest_rect[0] - 1; |
1544 |
– |
D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y)); |
1545 |
– |
D(bug(" width %d, height %d\n", width, height)); |
1546 |
– |
|
1547 |
– |
// And perform the blit |
1548 |
– |
bitblt_hook(src_X, src_Y, dest_X, dest_Y, width, height); |
1549 |
– |
} |
1550 |
– |
|
1551 |
– |
static bool accl_bitblt_hook(accl_params *p) |
1552 |
– |
{ |
1553 |
– |
D(bug("accl_draw_hook %p\n", p)); |
1554 |
– |
|
1555 |
– |
// Check if we can accelerate this bitblt |
1556 |
– |
if (p->src_base_addr == screen_base && p->dest_base_addr == screen_base && |
1557 |
– |
display_type == DIS_SCREEN && bitblt_hook != NULL && |
1558 |
– |
((uint32 *)p)[0x18 >> 2] + ((uint32 *)p)[0x128 >> 2] == 0 && |
1559 |
– |
((uint32 *)p)[0x130 >> 2] == 0 && |
1560 |
– |
p->transfer_mode == 0 && |
1561 |
– |
p->src_row_bytes > 0 && ((uint32 *)p)[0x15c >> 2] > 0) { |
1562 |
– |
|
1563 |
– |
// Yes, set function pointer |
1564 |
– |
p->draw_proc = accl_bitblt; |
1565 |
– |
return true; |
1566 |
– |
} |
1567 |
– |
return false; |
1568 |
– |
} |
1569 |
– |
|
1570 |
– |
// Rectangle filling/inversion |
1571 |
– |
static void accl_fillrect8(accl_params *p) |
1572 |
– |
{ |
1573 |
– |
D(bug("accl_fillrect8\n")); |
1574 |
– |
|
1575 |
– |
// Get filling parameters |
1576 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1577 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1578 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1579 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1580 |
– |
uint8 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
1581 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1582 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1583 |
– |
|
1584 |
– |
// And perform the fill |
1585 |
– |
fillrect8_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
1586 |
– |
} |
1587 |
– |
|
1588 |
– |
static void accl_fillrect32(accl_params *p) |
1589 |
– |
{ |
1590 |
– |
D(bug("accl_fillrect32\n")); |
1591 |
– |
|
1592 |
– |
// Get filling parameters |
1593 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1594 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1595 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1596 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1597 |
– |
uint32 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
1598 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1599 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1600 |
– |
|
1601 |
– |
// And perform the fill |
1602 |
– |
fillrect32_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
1603 |
– |
} |
1604 |
– |
|
1605 |
– |
static void accl_invrect(accl_params *p) |
1606 |
– |
{ |
1607 |
– |
D(bug("accl_invrect\n")); |
1608 |
– |
|
1609 |
– |
// Get inversion parameters |
1610 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1611 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1612 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1613 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1614 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1615 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1616 |
– |
|
1617 |
– |
//!!?? pen_mode == 14 |
1618 |
– |
|
1619 |
– |
// And perform the inversion |
1620 |
– |
invrect_hook(dest_X, dest_Y, dest_X_max, dest_Y_max); |
1621 |
– |
} |
1622 |
– |
|
1623 |
– |
static bool accl_fillrect_hook(accl_params *p) |
1624 |
– |
{ |
1625 |
– |
D(bug("accl_fillrect_hook %p\n", p)); |
1626 |
– |
|
1627 |
– |
// Check if we can accelerate this fillrect |
1628 |
– |
if (p->dest_base_addr == screen_base && ((uint32 *)p)[0x284 >> 2] != 0 && display_type == DIS_SCREEN) { |
1629 |
– |
if (p->transfer_mode == 8) { |
1630 |
– |
// Fill |
1631 |
– |
if (p->dest_pixel_size == 8 && fillrect8_hook != NULL) { |
1632 |
– |
p->draw_proc = accl_fillrect8; |
1633 |
– |
return true; |
1634 |
– |
} else if (p->dest_pixel_size == 32 && fillrect32_hook != NULL) { |
1635 |
– |
p->draw_proc = accl_fillrect32; |
1636 |
– |
return true; |
1637 |
– |
} |
1638 |
– |
} else if (p->transfer_mode == 10 && invrect_hook != NULL) { |
1639 |
– |
// Invert |
1640 |
– |
p->draw_proc = accl_invrect; |
1641 |
– |
return true; |
1642 |
– |
} |
1643 |
– |
} |
1644 |
– |
return false; |
1645 |
– |
} |
1646 |
– |
|
1647 |
– |
// Wait for graphics operation to finish |
1648 |
– |
static bool accl_sync_hook(void *arg) |
1649 |
– |
{ |
1650 |
– |
D(bug("accl_sync_hook %p\n", arg)); |
1651 |
– |
if (sync_hook != NULL) |
1652 |
– |
sync_hook(); |
1653 |
– |
return true; |
1654 |
– |
} |
1655 |
– |
|
1656 |
– |
static struct accl_hook_info bitblt_hook_info = {accl_bitblt_hook, accl_sync_hook, ACCL_BITBLT}; |
1657 |
– |
static struct accl_hook_info fillrect_hook_info = {accl_fillrect_hook, accl_sync_hook, ACCL_FILLRECT}; |
1658 |
– |
#endif |
1659 |
– |
|
1660 |
– |
void VideoInstallAccel(void) |
1661 |
– |
{ |
1662 |
– |
// Install acceleration hooks |
1663 |
– |
if (PrefsFindBool("gfxaccel")) { |
1664 |
– |
D(bug("Video: Installing acceleration hooks\n")); |
1665 |
– |
//!! NQDMisc(6, &bitblt_hook_info); |
1666 |
– |
// NQDMisc(6, &fillrect_hook_info); |
1667 |
– |
} |
1668 |
– |
} |
1669 |
– |
|
1670 |
– |
|
1671 |
– |
/* |
1662 |
|
* Change video mode |
1663 |
|
*/ |
1664 |
|
|
1761 |
|
|
1762 |
|
|
1763 |
|
/* |
1764 |
+ |
* Can we set the MacOS cursor image into the window? |
1765 |
+ |
*/ |
1766 |
+ |
|
1767 |
+ |
bool video_can_change_cursor(void) |
1768 |
+ |
{ |
1769 |
+ |
return hw_mac_cursor_accl && (display_type != DIS_SCREEN); |
1770 |
+ |
} |
1771 |
+ |
|
1772 |
+ |
|
1773 |
+ |
/* |
1774 |
|
* Set cursor image for window |
1775 |
|
*/ |
1776 |
|
|
1950 |
|
int64 ticks = 0; |
1951 |
|
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
1952 |
|
|
1953 |
< |
for (;;) { |
1953 |
> |
while (!redraw_thread_cancel) { |
1954 |
|
|
1955 |
|
// Pause if requested (during video mode switches) |
1956 |
|
while (thread_stop_req) |
1980 |
|
XF86DGADirectVideo(x_display, screen, 0); |
1981 |
|
XUngrabPointer(x_display, CurrentTime); |
1982 |
|
XUngrabKeyboard(x_display, CurrentTime); |
1983 |
+ |
XUnmapWindow(x_display, the_win); |
1984 |
+ |
wait_unmapped(the_win); |
1985 |
+ |
XDestroyWindow(x_display, the_win); |
1986 |
|
#endif |
1987 |
|
XSync(x_display, false); |
1988 |
|
XDisplayUnlock(); |
2015 |
|
update_display(); |
2016 |
|
|
2017 |
|
// Set new cursor image if it was changed |
2018 |
< |
if (cursor_changed) { |
2018 |
> |
if (hw_mac_cursor_accl && cursor_changed) { |
2019 |
|
cursor_changed = false; |
2020 |
< |
memcpy(cursor_image->data, MacCursor + 4, 32); |
2021 |
< |
memcpy(cursor_mask_image->data, MacCursor + 36, 32); |
2020 |
> |
uint8 *x_data = (uint8 *)cursor_image->data; |
2021 |
> |
uint8 *x_mask = (uint8 *)cursor_mask_image->data; |
2022 |
> |
for (int i = 0; i < 32; i++) { |
2023 |
> |
x_mask[i] = MacCursor[4 + i] | MacCursor[36 + i]; |
2024 |
> |
x_data[i] = MacCursor[4 + i]; |
2025 |
> |
} |
2026 |
|
XDisplayLock(); |
2027 |
|
XFreeCursor(x_display, mac_cursor); |
2028 |
|
XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16); |