1 |
|
/* |
2 |
|
* video_x.cpp - Video/graphics emulation, X11 specific stuff |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2004 Marc Hellwig and Christian Bauer |
4 |
> |
* SheepShaver (C) 1997-2005 Marc Hellwig and Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
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; |
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; |
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 |
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) |
633 |
|
|
634 |
|
// Set frame buffer base |
635 |
|
D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); |
636 |
< |
screen_base = (uint32)the_buffer; |
636 |
> |
screen_base = Host2MacAddr(the_buffer); |
637 |
|
VModes[cur_mode].viRowBytes = bytes_per_row; |
638 |
|
return true; |
639 |
|
#else |
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); |
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)) { |
970 |
|
return -1; |
971 |
|
} |
972 |
|
|
973 |
+ |
// Add custom video mode |
974 |
+ |
static void add_custom_mode(VideoInfo *&p, int type, uint32 x, uint32 y, int apple_mode, int apple_id) |
975 |
+ |
{ |
976 |
+ |
p->viType = type; |
977 |
+ |
p->viXsize = x; |
978 |
+ |
p->viYsize = y; |
979 |
+ |
p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); |
980 |
+ |
p->viAppleMode = apple_mode; |
981 |
+ |
p->viAppleID = apple_id; |
982 |
+ |
p++; |
983 |
+ |
} |
984 |
+ |
|
985 |
|
// Add mode to list of supported modes |
986 |
|
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type) |
987 |
|
{ |
988 |
|
if (allow & test) { |
989 |
< |
p->viType = type; |
989 |
> |
uint32 x = 0, y = 0; |
990 |
|
switch (apple_id) { |
991 |
|
case APPLE_W_640x480: |
992 |
|
case APPLE_640x480: |
993 |
< |
p->viXsize = 640; |
994 |
< |
p->viYsize = 480; |
993 |
> |
x = 640; |
994 |
> |
y = 480; |
995 |
|
break; |
996 |
|
case APPLE_W_800x600: |
997 |
|
case APPLE_800x600: |
998 |
< |
p->viXsize = 800; |
999 |
< |
p->viYsize = 600; |
998 |
> |
x = 800; |
999 |
> |
y = 600; |
1000 |
|
break; |
1001 |
|
case APPLE_1024x768: |
1002 |
< |
p->viXsize = 1024; |
1003 |
< |
p->viYsize = 768; |
1002 |
> |
x = 1024; |
1003 |
> |
y = 768; |
1004 |
|
break; |
1005 |
|
case APPLE_1152x768: |
1006 |
< |
p->viXsize = 1152; |
1007 |
< |
p->viYsize = 768; |
1006 |
> |
x = 1152; |
1007 |
> |
y = 768; |
1008 |
|
break; |
1009 |
|
case APPLE_1152x900: |
1010 |
< |
p->viXsize = 1152; |
1011 |
< |
p->viYsize = 900; |
1010 |
> |
x = 1152; |
1011 |
> |
y = 900; |
1012 |
|
break; |
1013 |
|
case APPLE_1280x1024: |
1014 |
< |
p->viXsize = 1280; |
1015 |
< |
p->viYsize = 1024; |
1014 |
> |
x = 1280; |
1015 |
> |
y = 1024; |
1016 |
|
break; |
1017 |
|
case APPLE_1600x1200: |
1018 |
< |
p->viXsize = 1600; |
1019 |
< |
p->viYsize = 1200; |
1018 |
> |
x = 1600; |
1019 |
> |
y = 1200; |
1020 |
|
break; |
1021 |
|
} |
1022 |
< |
p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); |
985 |
< |
p->viAppleMode = apple_mode; |
986 |
< |
p->viAppleID = apple_id; |
987 |
< |
p++; |
1022 |
> |
add_custom_mode(p, type, x, y, apple_mode, apple_id); |
1023 |
|
} |
1024 |
|
} |
1025 |
|
|
1129 |
|
break; |
1130 |
|
} |
1131 |
|
|
1132 |
+ |
// Get screen mode from preferences |
1133 |
+ |
const char *mode_str = PrefsFindString("screen"); |
1134 |
+ |
int default_width = 640, default_height = 480; |
1135 |
+ |
if (mode_str) { |
1136 |
+ |
display_type = DIS_INVALID; |
1137 |
+ |
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) |
1138 |
+ |
display_type = DIS_WINDOW; |
1139 |
+ |
#ifdef ENABLE_XF86_DGA |
1140 |
+ |
else if (has_dga && sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2) |
1141 |
+ |
display_type = DIS_SCREEN; |
1142 |
+ |
#endif |
1143 |
+ |
if (display_type == DIS_INVALID) { |
1144 |
+ |
D(bug("Invalid screen mode specified, defaulting to old modes selection\n")); |
1145 |
+ |
mode_str = NULL; |
1146 |
+ |
} |
1147 |
+ |
else { |
1148 |
+ |
if (default_width <= 0) |
1149 |
+ |
default_width = DisplayWidth(x_display, screen); |
1150 |
+ |
else if (default_width > DisplayWidth(x_display, screen)) |
1151 |
+ |
default_width = DisplayWidth(x_display, screen); |
1152 |
+ |
if (default_height <= 0) |
1153 |
+ |
default_height = DisplayHeight(x_display, screen); |
1154 |
+ |
else if (default_height > DisplayHeight(x_display, screen)) |
1155 |
+ |
default_height = DisplayHeight(x_display, screen); |
1156 |
+ |
} |
1157 |
+ |
} |
1158 |
+ |
|
1159 |
|
// Construct video mode table |
1160 |
|
uint32 window_modes = PrefsFindInt32("windowmodes"); |
1161 |
|
uint32 screen_modes = PrefsFindInt32("screenmodes"); |
1162 |
|
if (!has_dga) |
1163 |
|
screen_modes = 0; |
1164 |
< |
if (window_modes == 0 && screen_modes == 0) |
1164 |
> |
if (mode_str) |
1165 |
> |
window_modes = screen_modes = 0; |
1166 |
> |
else if (window_modes == 0 && screen_modes == 0) |
1167 |
|
window_modes |= 3; // Allow at least 640x480 and 800x600 window modes |
1168 |
|
|
1169 |
|
VideoInfo *p = VModes; |
1170 |
< |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) |
1171 |
< |
if (find_visual_for_depth(d)) |
1172 |
< |
add_window_modes(p, window_modes, d); |
1173 |
< |
|
1174 |
< |
if (has_vidmode) { |
1170 |
> |
if (mode_str) { |
1171 |
> |
if (display_type == DIS_WINDOW) { |
1172 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) { |
1173 |
> |
if (find_visual_for_depth(d)) { |
1174 |
> |
if (default_width > 640 && default_height > 480) |
1175 |
> |
add_mode(p, 3, 1, d, APPLE_W_640x480, DIS_WINDOW); |
1176 |
> |
if (default_width > 800 && default_height > 600) |
1177 |
> |
add_mode(p, 3, 2, d, APPLE_W_800x600, DIS_WINDOW); |
1178 |
> |
add_custom_mode(p, display_type, default_width, default_height, d, APPLE_CUSTOM); |
1179 |
> |
} |
1180 |
> |
} |
1181 |
> |
} else |
1182 |
> |
add_custom_mode(p, display_type, default_width, default_height, default_mode, APPLE_CUSTOM); |
1183 |
> |
} else if (window_modes) { |
1184 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) |
1185 |
> |
if (find_visual_for_depth(d)) |
1186 |
> |
add_window_modes(p, window_modes, d); |
1187 |
> |
} else if (has_vidmode) { |
1188 |
|
if (has_mode(640, 480)) |
1189 |
|
add_mode(p, screen_modes, 1, default_mode, APPLE_640x480, DIS_SCREEN); |
1190 |
|
if (has_mode(800, 600)) |
1225 |
|
int apple_id = find_apple_resolution(screen_width, screen_height); |
1226 |
|
if (apple_id != -1) |
1227 |
|
cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN); |
1228 |
+ |
} else if (has_dga && mode_str) |
1229 |
+ |
cur_mode = find_mode(default_mode, APPLE_CUSTOM, DIS_SCREEN); |
1230 |
+ |
|
1231 |
+ |
if (cur_mode == -1) { |
1232 |
+ |
// pick up first windowed mode available |
1233 |
+ |
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
1234 |
+ |
if (p->viType == DIS_WINDOW && p->viAppleMode == default_mode) { |
1235 |
+ |
cur_mode = p - VModes; |
1236 |
+ |
break; |
1237 |
+ |
} |
1238 |
+ |
} |
1239 |
|
} |
1152 |
– |
if (cur_mode == -1) |
1153 |
– |
cur_mode = find_mode(default_mode, APPLE_W_640x480, DIS_WINDOW); |
1240 |
|
assert(cur_mode != -1); |
1241 |
|
|
1242 |
|
#if DEBUG |
1259 |
|
// Start periodic thread |
1260 |
|
XSync(x_display, false); |
1261 |
|
Set_pthread_attr(&redraw_thread_attr, 0); |
1262 |
+ |
redraw_thread_cancel = false; |
1263 |
|
redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0); |
1264 |
|
D(bug("Redraw thread installed (%ld)\n", redraw_thread)); |
1265 |
|
return true; |
1274 |
|
{ |
1275 |
|
// Stop redraw thread |
1276 |
|
if (redraw_thread_active) { |
1277 |
+ |
redraw_thread_cancel = true; |
1278 |
|
pthread_cancel(redraw_thread); |
1279 |
|
pthread_join(redraw_thread, NULL); |
1280 |
|
redraw_thread_active = false; |
1318 |
|
// Save frame buffer |
1319 |
|
fb_save = malloc(VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1320 |
|
if (fb_save) |
1321 |
< |
memcpy(fb_save, (void *)screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1321 |
> |
Mac2Host_memcpy(fb_save, screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1322 |
|
|
1323 |
|
// Close full screen display |
1324 |
|
#ifdef ENABLE_XF86_DGA |
1380 |
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1381 |
|
if (!use_vosf) |
1382 |
|
#endif |
1383 |
< |
memcpy((void *)screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1383 |
> |
Host2Mac_memcpy(screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1384 |
|
free(fb_save); |
1385 |
|
fb_save = NULL; |
1386 |
|
} |
1553 |
|
return -1; |
1554 |
|
} |
1555 |
|
|
1556 |
< |
static int event2keycode(XKeyEvent &ev) |
1556 |
> |
static int event2keycode(XKeyEvent &ev, bool key_down) |
1557 |
|
{ |
1558 |
|
KeySym ks; |
1471 |
– |
int as; |
1559 |
|
int i = 0; |
1560 |
|
|
1561 |
|
do { |
1562 |
|
ks = XLookupKeysym(&ev, i++); |
1563 |
< |
as = kc_decode(ks); |
1564 |
< |
if (as != -1) |
1563 |
> |
int as = kc_decode(ks); |
1564 |
> |
if (as >= 0) |
1565 |
> |
return as; |
1566 |
> |
if (as == -2) |
1567 |
|
return as; |
1568 |
|
} while (ks != NoSymbol); |
1569 |
|
|
1638 |
|
|
1639 |
|
// Keyboard |
1640 |
|
case KeyPress: { |
1641 |
< |
int code = event2keycode(event.xkey); |
1642 |
< |
if (use_keycodes && code != -1) |
1643 |
< |
code = keycode_table[event.xkey.keycode & 0xff]; |
1644 |
< |
if (code != -1) { |
1641 |
> |
int code = -1; |
1642 |
> |
if (use_keycodes) { |
1643 |
> |
if (event2keycode(event.xkey, true) != -2) // This is called to process the hotkeys |
1644 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1645 |
> |
} else |
1646 |
> |
code = event2keycode(event.xkey, true); |
1647 |
> |
if (code >= 0) { |
1648 |
|
if (!emul_suspended) { |
1649 |
< |
ADBKeyDown(code); |
1649 |
> |
if (code == 0x39) { // Caps Lock pressed |
1650 |
> |
if (caps_on) { |
1651 |
> |
ADBKeyUp(code); |
1652 |
> |
caps_on = false; |
1653 |
> |
} else { |
1654 |
> |
ADBKeyDown(code); |
1655 |
> |
caps_on = true; |
1656 |
> |
} |
1657 |
> |
} else |
1658 |
> |
ADBKeyDown(code); |
1659 |
|
if (code == 0x36) |
1660 |
|
ctrl_down = true; |
1661 |
|
} else { |
1666 |
|
break; |
1667 |
|
} |
1668 |
|
case KeyRelease: { |
1669 |
< |
int code = event2keycode(event.xkey); |
1670 |
< |
if (use_keycodes && code != 1) |
1671 |
< |
code = keycode_table[event.xkey.keycode & 0xff]; |
1672 |
< |
if (code != -1) { |
1669 |
> |
int code = -1; |
1670 |
> |
if (use_keycodes) { |
1671 |
> |
if (event2keycode(event.xkey, false) != -2) // This is called to process the hotkeys |
1672 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1673 |
> |
} else |
1674 |
> |
code = event2keycode(event.xkey, false); |
1675 |
> |
if (code >= 0 && code != 0x39) { // Don't propagate Caps Lock releases |
1676 |
|
ADBKeyUp(code); |
1677 |
|
if (code == 0x36) |
1678 |
|
ctrl_down = false; |
1712 |
|
|
1713 |
|
|
1714 |
|
/* |
1611 |
– |
* Install graphics acceleration |
1612 |
– |
*/ |
1613 |
– |
|
1614 |
– |
#if 0 |
1615 |
– |
// Rectangle filling/inversion |
1616 |
– |
static void accl_fillrect8(accl_params *p) |
1617 |
– |
{ |
1618 |
– |
D(bug("accl_fillrect8\n")); |
1619 |
– |
|
1620 |
– |
// Get filling parameters |
1621 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1622 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1623 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1624 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1625 |
– |
uint8 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
1626 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1627 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1628 |
– |
|
1629 |
– |
// And perform the fill |
1630 |
– |
fillrect8_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
1631 |
– |
} |
1632 |
– |
|
1633 |
– |
static void accl_fillrect32(accl_params *p) |
1634 |
– |
{ |
1635 |
– |
D(bug("accl_fillrect32\n")); |
1636 |
– |
|
1637 |
– |
// Get filling parameters |
1638 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1639 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1640 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1641 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1642 |
– |
uint32 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
1643 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1644 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1645 |
– |
|
1646 |
– |
// And perform the fill |
1647 |
– |
fillrect32_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
1648 |
– |
} |
1649 |
– |
|
1650 |
– |
static void accl_invrect(accl_params *p) |
1651 |
– |
{ |
1652 |
– |
D(bug("accl_invrect\n")); |
1653 |
– |
|
1654 |
– |
// Get inversion parameters |
1655 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1656 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1657 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1658 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1659 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1660 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1661 |
– |
|
1662 |
– |
//!!?? pen_mode == 14 |
1663 |
– |
|
1664 |
– |
// And perform the inversion |
1665 |
– |
invrect_hook(dest_X, dest_Y, dest_X_max, dest_Y_max); |
1666 |
– |
} |
1667 |
– |
|
1668 |
– |
static bool accl_fillrect_hook(accl_params *p) |
1669 |
– |
{ |
1670 |
– |
D(bug("accl_fillrect_hook %p\n", p)); |
1671 |
– |
|
1672 |
– |
// Check if we can accelerate this fillrect |
1673 |
– |
if (p->dest_base_addr == screen_base && ((uint32 *)p)[0x284 >> 2] != 0 && display_type == DIS_SCREEN) { |
1674 |
– |
if (p->transfer_mode == 8) { |
1675 |
– |
// Fill |
1676 |
– |
if (p->dest_pixel_size == 8 && fillrect8_hook != NULL) { |
1677 |
– |
p->draw_proc = accl_fillrect8; |
1678 |
– |
return true; |
1679 |
– |
} else if (p->dest_pixel_size == 32 && fillrect32_hook != NULL) { |
1680 |
– |
p->draw_proc = accl_fillrect32; |
1681 |
– |
return true; |
1682 |
– |
} |
1683 |
– |
} else if (p->transfer_mode == 10 && invrect_hook != NULL) { |
1684 |
– |
// Invert |
1685 |
– |
p->draw_proc = accl_invrect; |
1686 |
– |
return true; |
1687 |
– |
} |
1688 |
– |
} |
1689 |
– |
return false; |
1690 |
– |
} |
1691 |
– |
|
1692 |
– |
static struct accl_hook_info fillrect_hook_info = {accl_fillrect_hook, accl_sync_hook, ACCL_FILLRECT}; |
1693 |
– |
#endif |
1694 |
– |
|
1695 |
– |
// Rectangle blitting |
1696 |
– |
// TODO: optimize for VOSF and target pixmap == screen |
1697 |
– |
void NQD_bitblt(uint32 arg) |
1698 |
– |
{ |
1699 |
– |
D(bug("accl_bitblt %08x\n", arg)); |
1700 |
– |
accl_params *p = (accl_params *)arg; |
1701 |
– |
|
1702 |
– |
// Get blitting parameters |
1703 |
– |
int16 src_X = p->src_rect[1] - p->src_bounds[1]; |
1704 |
– |
int16 src_Y = p->src_rect[0] - p->src_bounds[0]; |
1705 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1706 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1707 |
– |
int16 width = p->dest_rect[3] - p->dest_rect[1]; |
1708 |
– |
int16 height = p->dest_rect[2] - p->dest_rect[0]; |
1709 |
– |
D(bug(" src addr %08x, dest addr %08x\n", p->src_base_addr, p->dest_base_addr)); |
1710 |
– |
D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y)); |
1711 |
– |
D(bug(" width %d, height %d\n", width, height)); |
1712 |
– |
|
1713 |
– |
// And perform the blit |
1714 |
– |
const int bpp = bytes_per_pixel(p->src_pixel_size); |
1715 |
– |
width *= bpp; |
1716 |
– |
if (p->src_row_bytes > 0) { |
1717 |
– |
const int src_row_bytes = p->src_row_bytes; |
1718 |
– |
const int dst_row_bytes = p->dest_row_bytes; |
1719 |
– |
uint8 *src = (uint8 *)p->src_base_addr + (src_Y * src_row_bytes) + (src_X * bpp); |
1720 |
– |
uint8 *dst = (uint8 *)p->dest_base_addr + (dest_Y * dst_row_bytes) + (dest_X * bpp); |
1721 |
– |
for (int i = 0; i < height; i++) { |
1722 |
– |
memcpy(dst, src, width); |
1723 |
– |
src += src_row_bytes; |
1724 |
– |
dst += dst_row_bytes; |
1725 |
– |
} |
1726 |
– |
} |
1727 |
– |
else { |
1728 |
– |
const int src_row_bytes = -p->src_row_bytes; |
1729 |
– |
const int dst_row_bytes = -p->dest_row_bytes; |
1730 |
– |
uint8 *src = (uint8 *)p->src_base_addr + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp); |
1731 |
– |
uint8 *dst = (uint8 *)p->dest_base_addr + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp); |
1732 |
– |
for (int i = height - 1; i >= 0; i--) { |
1733 |
– |
memcpy(dst, src, width); |
1734 |
– |
src -= src_row_bytes; |
1735 |
– |
dst -= dst_row_bytes; |
1736 |
– |
} |
1737 |
– |
} |
1738 |
– |
} |
1739 |
– |
|
1740 |
– |
bool NQD_bitblt_hook(uint32 arg) |
1741 |
– |
{ |
1742 |
– |
D(bug("accl_draw_hook %08x\n", arg)); |
1743 |
– |
accl_params *p = (accl_params *)arg; |
1744 |
– |
|
1745 |
– |
// Check if we can accelerate this bitblt |
1746 |
– |
if (((uint32 *)p)[0x18 >> 2] + ((uint32 *)p)[0x128 >> 2] == 0 && |
1747 |
– |
((uint32 *)p)[0x130 >> 2] == 0 && |
1748 |
– |
p->src_pixel_size >= 8 && p->src_pixel_size == p->dest_pixel_size && |
1749 |
– |
((p->src_row_bytes ^ p->dest_row_bytes) >> 31) == 0 && |
1750 |
– |
p->transfer_mode == 0 && |
1751 |
– |
((uint32 *)p)[0x15c >> 2] > 0) { |
1752 |
– |
|
1753 |
– |
// Yes, set function pointer |
1754 |
– |
p->draw_proc = NativeTVECT(NATIVE_BITBLT); |
1755 |
– |
return true; |
1756 |
– |
} |
1757 |
– |
return false; |
1758 |
– |
} |
1759 |
– |
|
1760 |
– |
// Wait for graphics operation to finish |
1761 |
– |
bool NQD_sync_hook(uint32 arg) |
1762 |
– |
{ |
1763 |
– |
D(bug("accl_sync_hook %08x\n", arg)); |
1764 |
– |
return true; |
1765 |
– |
} |
1766 |
– |
|
1767 |
– |
void VideoInstallAccel(void) |
1768 |
– |
{ |
1769 |
– |
// Install acceleration hooks |
1770 |
– |
if (PrefsFindBool("gfxaccel")) { |
1771 |
– |
D(bug("Video: Installing acceleration hooks\n")); |
1772 |
– |
uint32 base; |
1773 |
– |
|
1774 |
– |
SheepVar bitblt_hook_info(sizeof(accl_hook_info)); |
1775 |
– |
base = bitblt_hook_info.addr(); |
1776 |
– |
WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK)); |
1777 |
– |
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
1778 |
– |
WriteMacInt32(base + 8, ACCL_BITBLT); |
1779 |
– |
#if defined(__powerpc__) // Temporary hack until it's fixed for e.g. little-endian & 64-bit platforms |
1780 |
– |
NQDMisc(6, bitblt_hook_info.ptr()); |
1781 |
– |
#endif |
1782 |
– |
|
1783 |
– |
// NQDMisc(6, &fillrect_hook_info); |
1784 |
– |
} |
1785 |
– |
} |
1786 |
– |
|
1787 |
– |
|
1788 |
– |
/* |
1715 |
|
* Change video mode |
1716 |
|
*/ |
1717 |
|
|
1814 |
|
|
1815 |
|
|
1816 |
|
/* |
1817 |
+ |
* Can we set the MacOS cursor image into the window? |
1818 |
+ |
*/ |
1819 |
+ |
|
1820 |
+ |
bool video_can_change_cursor(void) |
1821 |
+ |
{ |
1822 |
+ |
return hw_mac_cursor_accl && (display_type != DIS_SCREEN); |
1823 |
+ |
} |
1824 |
+ |
|
1825 |
+ |
|
1826 |
+ |
/* |
1827 |
|
* Set cursor image for window |
1828 |
|
*/ |
1829 |
|
|
2003 |
|
int64 ticks = 0; |
2004 |
|
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
2005 |
|
|
2006 |
< |
for (;;) { |
2006 |
> |
while (!redraw_thread_cancel) { |
2007 |
|
|
2008 |
|
// Pause if requested (during video mode switches) |
2009 |
|
while (thread_stop_req) |
2068 |
|
update_display(); |
2069 |
|
|
2070 |
|
// Set new cursor image if it was changed |
2071 |
< |
if (cursor_changed) { |
2071 |
> |
if (hw_mac_cursor_accl && cursor_changed) { |
2072 |
|
cursor_changed = false; |
2073 |
< |
memcpy(cursor_image->data, MacCursor + 4, 32); |
2074 |
< |
memcpy(cursor_mask_image->data, MacCursor + 36, 32); |
2073 |
> |
uint8 *x_data = (uint8 *)cursor_image->data; |
2074 |
> |
uint8 *x_mask = (uint8 *)cursor_mask_image->data; |
2075 |
> |
for (int i = 0; i < 32; i++) { |
2076 |
> |
x_mask[i] = MacCursor[4 + i] | MacCursor[36 + i]; |
2077 |
> |
x_data[i] = MacCursor[4 + i]; |
2078 |
> |
} |
2079 |
|
XDisplayLock(); |
2080 |
|
XFreeCursor(x_display, mac_cursor); |
2081 |
|
XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16); |