80 |
|
// Constants |
81 |
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; |
82 |
|
|
83 |
< |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | StructureNotifyMask; |
83 |
> |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask | StructureNotifyMask; |
84 |
|
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask; |
85 |
|
|
86 |
|
|
93 |
|
static bool local_X11; // Flag: X server running on local machine? |
94 |
|
static uint8 *the_buffer = NULL; // Mac frame buffer (where MacOS draws into) |
95 |
|
static uint8 *the_buffer_copy = NULL; // Copy of Mac frame buffer (for refreshed modes) |
96 |
+ |
static uint32 the_buffer_size; // Size of allocated the_buffer |
97 |
|
|
98 |
|
static bool redraw_thread_active = false; // Flag: Redraw thread installed |
99 |
|
#ifdef HAVE_PTHREADS |
213 |
|
// Calculate minimum and maximum supported X depth |
214 |
|
int min_depth = 1, max_depth = 32; |
215 |
|
switch (depth) { |
216 |
< |
case VDEPTH_1BIT: // 1-bit works always |
217 |
< |
min_depth = 1; |
217 |
< |
max_depth = 32; |
216 |
> |
case VDEPTH_1BIT: // 1-bit works always and uses default visual |
217 |
> |
min_depth = max_depth = DefaultDepth(x_display, screen); |
218 |
|
break; |
219 |
|
#ifdef ENABLE_VOSF |
220 |
|
case VDEPTH_2BIT: |
428 |
|
virtual void toggle_mouse_grab(void) {} |
429 |
|
virtual void mouse_moved(int x, int y) { ADBMouseMoved(x, y); } |
430 |
|
|
431 |
+ |
void disable_mouse_accel(void); |
432 |
+ |
void restore_mouse_accel(void); |
433 |
+ |
|
434 |
|
virtual void grab_mouse(void) {} |
435 |
|
virtual void ungrab_mouse(void) {} |
436 |
|
|
437 |
|
public: |
438 |
|
bool init_ok; // Initialization succeeded (we can't use exceptions because of -fomit-frame-pointer) |
439 |
|
Window w; // The window we draw into |
440 |
+ |
|
441 |
+ |
int orig_accel_numer, orig_accel_denom, orig_threshold; // Original mouse acceleration |
442 |
|
}; |
443 |
|
|
444 |
|
class driver_window; |
482 |
|
{ |
483 |
|
the_buffer = NULL; |
484 |
|
the_buffer_copy = NULL; |
485 |
+ |
XGetPointerControl(x_display, &orig_accel_numer, &orig_accel_denom, &orig_threshold); |
486 |
|
} |
487 |
|
|
488 |
|
driver_base::~driver_base() |
489 |
|
{ |
490 |
|
ungrab_mouse(); |
491 |
+ |
restore_mouse_accel(); |
492 |
|
|
493 |
|
if (w) { |
494 |
|
XUnmapWindow(x_display, w); |
516 |
|
free(the_host_buffer); |
517 |
|
the_host_buffer = NULL; |
518 |
|
} |
519 |
< |
if (the_buffer != (uint8 *)VM_MAP_FAILED) { |
520 |
< |
vm_release(the_buffer, the_buffer_size); |
519 |
> |
if (the_buffer) { |
520 |
> |
free(the_buffer); |
521 |
|
the_buffer = NULL; |
522 |
|
} |
523 |
< |
if (the_buffer_copy != (uint8 *)VM_MAP_FAILED) { |
524 |
< |
vm_release(the_buffer_copy, the_buffer_size); |
523 |
> |
if (the_buffer_copy) { |
524 |
> |
free(the_buffer_copy); |
525 |
|
the_buffer_copy = NULL; |
526 |
|
} |
527 |
|
} |
531 |
|
// Palette has changed |
532 |
|
void driver_base::update_palette(void) |
533 |
|
{ |
534 |
< |
if (cmap[0] && cmap[1]) { |
534 |
> |
if (color_class == PseudoColor || color_class == DirectColor) { |
535 |
|
int num = vis->map_entries; |
536 |
|
if (!IsDirectMode(VideoMonitor.mode) && color_class == DirectColor) |
537 |
|
return; // Indexed mode on true color screen, don't set CLUT |
541 |
|
XSync(x_display, false); |
542 |
|
} |
543 |
|
|
544 |
+ |
// Disable mouse acceleration |
545 |
+ |
void driver_base::disable_mouse_accel(void) |
546 |
+ |
{ |
547 |
+ |
XChangePointerControl(x_display, True, False, 1, 1, 0); |
548 |
+ |
} |
549 |
+ |
|
550 |
+ |
// Restore mouse acceleration to original value |
551 |
+ |
void driver_base::restore_mouse_accel(void) |
552 |
+ |
{ |
553 |
+ |
XChangePointerControl(x_display, True, True, orig_accel_numer, orig_accel_denom, orig_threshold); |
554 |
+ |
} |
555 |
+ |
|
556 |
|
|
557 |
|
/* |
558 |
|
* Windowed display driver |
569 |
|
// Set absolute mouse mode |
570 |
|
ADBSetRelMouseMode(mouse_grabbed); |
571 |
|
|
572 |
< |
// Create window |
572 |
> |
// Create window (setting backround_pixel, border_pixel and colormap is |
573 |
> |
// mandatory when using a non-default visual; in 1-bit mode we use the |
574 |
> |
// default visual, so we can also use the default colormap) |
575 |
|
XSetWindowAttributes wattr; |
576 |
|
wattr.event_mask = eventmask = win_eventmask; |
577 |
< |
wattr.background_pixel = black_pixel; |
578 |
< |
wattr.colormap = (mode.depth == VDEPTH_1BIT && color_class == PseudoColor ? DefaultColormap(x_display, screen) : cmap[0]); |
577 |
> |
wattr.background_pixel = (vis == DefaultVisual(x_display, screen) ? black_pixel : 0); |
578 |
> |
wattr.border_pixel = 0; |
579 |
> |
wattr.colormap = (mode.depth == VDEPTH_1BIT ? DefaultColormap(x_display, screen) : cmap[0]); |
580 |
|
w = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
581 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | (color_class == PseudoColor || color_class == DirectColor ? CWColormap : 0), &wattr); |
581 |
> |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | CWColormap, &wattr); |
582 |
|
|
583 |
|
// Set window name/class |
584 |
|
set_window_name(w, STR_WINDOW_TITLE); |
651 |
|
} |
652 |
|
|
653 |
|
#ifdef ENABLE_VOSF |
654 |
+ |
use_vosf = true; |
655 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
656 |
|
the_host_buffer = the_buffer_copy; |
657 |
|
the_buffer_size = page_extend((aligned_height + 2) * img->bytes_per_line); |
705 |
|
the_buffer_copy = NULL; // don't free() in driver_base dtor |
706 |
|
#endif |
707 |
|
} |
708 |
+ |
#ifdef ENABLE_VOSF |
709 |
+ |
if (use_vosf) { |
710 |
+ |
// don't free() memory mapped buffers in driver_base dtor |
711 |
+ |
if (the_buffer != VM_MAP_FAILED) { |
712 |
+ |
vm_release(the_buffer, the_buffer_size); |
713 |
+ |
the_buffer = NULL; |
714 |
+ |
} |
715 |
+ |
if (the_buffer_copy != VM_MAP_FAILED) { |
716 |
+ |
vm_release(the_buffer_copy, the_buffer_size); |
717 |
+ |
the_buffer_copy = NULL; |
718 |
+ |
} |
719 |
+ |
} |
720 |
+ |
#endif |
721 |
|
if (img) |
722 |
|
XDestroyImage(img); |
723 |
|
if (have_shm) { |
749 |
|
Delay_usec(100000); |
750 |
|
} |
751 |
|
if (result == GrabSuccess) { |
716 |
– |
ADBSetRelMouseMode(mouse_grabbed = true); |
752 |
|
XStoreName(x_display, w, GetString(STR_WINDOW_TITLE_GRABBED)); |
753 |
< |
XSync(x_display, false); |
753 |
> |
ADBSetRelMouseMode(mouse_grabbed = true); |
754 |
> |
disable_mouse_accel(); |
755 |
|
} |
756 |
|
} |
757 |
|
|
762 |
|
XUngrabPointer(x_display, CurrentTime); |
763 |
|
XStoreName(x_display, w, GetString(STR_WINDOW_TITLE)); |
764 |
|
ADBSetRelMouseMode(mouse_grabbed = false); |
765 |
+ |
restore_mouse_accel(); |
766 |
|
} |
767 |
|
} |
768 |
|
|
858 |
|
#endif |
859 |
|
XUngrabPointer(x_display, CurrentTime); |
860 |
|
XUngrabKeyboard(x_display, CurrentTime); |
861 |
+ |
restore_mouse_accel(); |
862 |
|
XUnmapWindow(x_display, w); |
863 |
|
wait_unmapped(w); |
864 |
|
|
888 |
|
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
889 |
|
XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
890 |
|
XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
891 |
+ |
disable_mouse_accel(); |
892 |
|
#ifdef ENABLE_XF86_DGA |
893 |
|
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
894 |
|
XF86DGASetViewPort(x_display, screen, 0, 0); |
1035 |
|
XGrabPointer(x_display, w, True, |
1036 |
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask, |
1037 |
|
GrabModeAsync, GrabModeAsync, w, None, CurrentTime); |
1038 |
+ |
disable_mouse_accel(); |
1039 |
|
|
1040 |
|
// Calculate bytes per row |
1041 |
|
int bytes_per_row = TrivialBytesPerRow(mode.x, mode.depth); |
1042 |
|
|
1043 |
|
// Map frame buffer |
1044 |
< |
if ((the_buffer = (uint8 *) mmap(NULL, height * bytes_per_row, PROT_READ | PROT_WRITE, MAP_PRIVATE, fbdev_fd, fb_offset)) == MAP_FAILED) { |
1045 |
< |
if ((the_buffer = (uint8 *) mmap(NULL, height * bytes_per_row, PROT_READ | PROT_WRITE, MAP_SHARED, fbdev_fd, fb_offset)) == MAP_FAILED) { |
1044 |
> |
the_buffer_size = height * bytes_per_row; |
1045 |
> |
if ((the_buffer = (uint8 *) mmap(NULL, the_buffer_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fbdev_fd, fb_offset)) == MAP_FAILED) { |
1046 |
> |
if ((the_buffer = (uint8 *) mmap(NULL, the_buffer_size, PROT_READ | PROT_WRITE, MAP_SHARED, fbdev_fd, fb_offset)) == MAP_FAILED) { |
1047 |
|
char str[256]; |
1048 |
|
sprintf(str, GetString(STR_FBDEV_MMAP_ERR), strerror(errno)); |
1049 |
|
ErrorAlert(str); |
1082 |
|
// Close display |
1083 |
|
driver_fbdev::~driver_fbdev() |
1084 |
|
{ |
1085 |
+ |
if (!use_vosf) { |
1086 |
+ |
if (the_buffer != MAP_FAILED) { |
1087 |
+ |
// don't free() the screen buffer in driver_base dtor |
1088 |
+ |
munmap(the_buffer, the_buffer_size); |
1089 |
+ |
the_buffer = NULL; |
1090 |
+ |
} |
1091 |
+ |
} |
1092 |
+ |
#ifdef ENABLE_VOSF |
1093 |
+ |
else { |
1094 |
+ |
if (the_host_buffer != MAP_FAILED) { |
1095 |
+ |
// don't free() the screen buffer in driver_base dtor |
1096 |
+ |
munmap(the_host_buffer, the_buffer_size); |
1097 |
+ |
the_host_buffer = NULL; |
1098 |
+ |
} |
1099 |
+ |
if (the_buffer_copy != VM_MAP_FAILED) { |
1100 |
+ |
vm_release(the_buffer_copy, the_buffer_size); |
1101 |
+ |
the_buffer_copy = NULL; |
1102 |
+ |
} |
1103 |
+ |
if (the_buffer != VM_MAP_FAILED) { |
1104 |
+ |
vm_release(the_buffer, the_buffer_size); |
1105 |
+ |
the_buffer = NULL; |
1106 |
+ |
} |
1107 |
+ |
} |
1108 |
+ |
#endif |
1109 |
|
} |
1110 |
|
#endif |
1111 |
|
|
1175 |
|
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
1176 |
|
XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
1177 |
|
XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
1178 |
+ |
disable_mouse_accel(); |
1179 |
|
|
1180 |
|
int v_width, v_bank, v_size; |
1181 |
|
XF86DGAGetVideo(x_display, screen, (char **)&the_buffer, &v_width, &v_bank, &v_size); |
1192 |
|
|
1193 |
|
// Init blitting routines |
1194 |
|
int bytes_per_row = TrivialBytesPerRow((v_width + 7) & ~7, mode.depth); |
1195 |
< |
#ifdef VIDEO_VOSF |
1195 |
> |
#if VIDEO_VOSF |
1196 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
1197 |
|
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
1198 |
|
// i.e. the framebuffer update function is not Blit_Copy_Raw |
1223 |
|
driver_xf86dga::~driver_xf86dga() |
1224 |
|
{ |
1225 |
|
XF86DGADirectVideo(x_display, screen, 0); |
1226 |
+ |
if (!use_vosf) { |
1227 |
+ |
// don't free() the screen buffer in driver_base dtor |
1228 |
+ |
the_buffer = NULL; |
1229 |
+ |
} |
1230 |
+ |
#ifdef ENABLE_VOSF |
1231 |
+ |
else { |
1232 |
+ |
// don't free() the screen buffer in driver_base dtor |
1233 |
+ |
the_host_buffer = NULL; |
1234 |
+ |
|
1235 |
+ |
if (the_buffer_copy != VM_MAP_FAILED) { |
1236 |
+ |
vm_release(the_buffer_copy, the_buffer_size); |
1237 |
+ |
the_buffer_copy = NULL; |
1238 |
+ |
} |
1239 |
+ |
if (the_buffer != VM_MAP_FAILED) { |
1240 |
+ |
vm_release(the_buffer, the_buffer_size); |
1241 |
+ |
the_buffer = NULL; |
1242 |
+ |
} |
1243 |
+ |
} |
1244 |
+ |
#endif |
1245 |
|
#ifdef ENABLE_XF86_VIDMODE |
1246 |
|
if (has_vidmode) |
1247 |
|
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[0]); |
1349 |
|
if (color_class == PseudoColor || color_class == DirectColor) { |
1350 |
|
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1351 |
|
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1352 |
+ |
} else { |
1353 |
+ |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocNone); |
1354 |
+ |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocNone); |
1355 |
|
} |
1356 |
|
|
1357 |
|
// Find pixel format of direct modes |
1373 |
|
--bloss; |
1374 |
|
} |
1375 |
|
|
1376 |
< |
// Preset palette pixel values for gamma table |
1376 |
> |
// Preset palette pixel values for CLUT or gamma table |
1377 |
|
if (color_class == DirectColor) { |
1378 |
|
int num = vis->map_entries; |
1379 |
|
for (int i=0; i<num; i++) { |
1380 |
|
int c = (i * 256) / num; |
1381 |
|
palette[i].pixel = map_rgb(c, c, c); |
1382 |
+ |
palette[i].flags = DoRed | DoGreen | DoBlue; |
1383 |
+ |
} |
1384 |
+ |
} else if (color_class == PseudoColor) { |
1385 |
+ |
for (int i=0; i<256; i++) { |
1386 |
+ |
palette[i].pixel = i; |
1387 |
+ |
palette[i].flags = DoRed | DoGreen | DoBlue; |
1388 |
|
} |
1389 |
|
} |
1390 |
|
|
1395 |
|
palette[i].red = c * 0x0101; |
1396 |
|
palette[i].green = c * 0x0101; |
1397 |
|
palette[i].blue = c * 0x0101; |
1304 |
– |
if (color_class == PseudoColor) |
1305 |
– |
palette[i].pixel = i; |
1306 |
– |
palette[i].flags = DoRed | DoGreen | DoBlue; |
1398 |
|
} |
1399 |
< |
if (cmap[0] && cmap[1]) { |
1399 |
> |
if (color_class == PseudoColor || color_class == DirectColor) { |
1400 |
|
XStoreColors(x_display, cmap[0], palette, num); |
1401 |
|
XStoreColors(x_display, cmap[1], palette, num); |
1402 |
|
} |
1403 |
|
|
1404 |
|
#ifdef ENABLE_VOSF |
1405 |
|
// Load gray ramp to 8->16/32 expand map |
1406 |
< |
if (!IsDirectMode(mode) && (color_class == TrueColor || color_class == DirectColor)) |
1406 |
> |
if (!IsDirectMode(mode) && xdepth > 8) |
1407 |
|
for (int i=0; i<256; i++) |
1408 |
|
ExpandMap[i] = map_rgb(i, i, i); |
1409 |
|
#endif |
1434 |
|
|
1435 |
|
#ifdef ENABLE_VOSF |
1436 |
|
if (use_vosf) { |
1437 |
< |
// Initialize the mainBuffer structure |
1438 |
< |
if (!video_init_buffer()) { |
1437 |
> |
// Initialize the VOSF system |
1438 |
> |
if (!video_vosf_init()) { |
1439 |
|
ErrorAlert(STR_VOSF_INIT_ERR); |
1440 |
|
return false; |
1441 |
|
} |
1351 |
– |
|
1352 |
– |
// Initialize the handler for SIGSEGV |
1353 |
– |
if (!sigsegv_install_handler(screen_fault_handler)) { |
1354 |
– |
ErrorAlert("Could not initialize Video on SEGV signals"); |
1355 |
– |
return false; |
1356 |
– |
} |
1442 |
|
} |
1443 |
|
#endif |
1444 |
|
|
1654 |
|
XSync(x_display, false); |
1655 |
|
|
1656 |
|
#ifdef ENABLE_VOSF |
1572 |
– |
// Deinitialize VOSF |
1657 |
|
if (use_vosf) { |
1658 |
< |
if (mainBuffer.pageInfo) { |
1659 |
< |
free(mainBuffer.pageInfo); |
1576 |
< |
mainBuffer.pageInfo = NULL; |
1577 |
< |
} |
1578 |
< |
if (mainBuffer.dirtyPages) { |
1579 |
< |
free(mainBuffer.dirtyPages); |
1580 |
< |
mainBuffer.dirtyPages = NULL; |
1581 |
< |
} |
1658 |
> |
// Deinitialize VOSF |
1659 |
> |
video_vosf_exit(); |
1660 |
|
} |
1661 |
|
#endif |
1662 |
|
|
1754 |
|
p->red = pal[c*3 + 0] * 0x0101; |
1755 |
|
p->green = pal[c*3 + 1] * 0x0101; |
1756 |
|
p->blue = pal[c*3 + 2] * 0x0101; |
1679 |
– |
if (color_class == PseudoColor) |
1680 |
– |
p->pixel = i; |
1681 |
– |
p->flags = DoRed | DoGreen | DoBlue; |
1757 |
|
p++; |
1758 |
|
} |
1759 |
|
|
1760 |
|
#ifdef ENABLE_VOSF |
1761 |
|
// Recalculate pixel color expansion map |
1762 |
< |
if (!IsDirectMode(VideoMonitor.mode) && (color_class == TrueColor || color_class == DirectColor)) { |
1762 |
> |
if (!IsDirectMode(VideoMonitor.mode) && xdepth > 8) { |
1763 |
|
for (int i=0; i<256; i++) { |
1764 |
|
int c = i & (num_in-1); // If there are less than 256 colors, we repeat the first entries (this makes color expansion easier) |
1765 |
|
ExpandMap[i] = map_rgb(pal[c*3+0], pal[c*3+1], pal[c*3+2]); |
1972 |
|
XNextEvent(x_display, &event); |
1973 |
|
|
1974 |
|
switch (event.type) { |
1975 |
+ |
|
1976 |
|
// Mouse button |
1977 |
|
case ButtonPress: { |
1978 |
|
unsigned int button = event.xbutton.button; |
2005 |
|
drv->mouse_moved(event.xmotion.x, event.xmotion.y); |
2006 |
|
break; |
2007 |
|
|
2008 |
+ |
// Mouse entered window |
2009 |
+ |
case EnterNotify: |
2010 |
+ |
if (event.xcrossing.mode != NotifyGrab && event.xcrossing.mode != NotifyUngrab) |
2011 |
+ |
drv->mouse_moved(event.xmotion.x, event.xmotion.y); |
2012 |
+ |
break; |
2013 |
+ |
|
2014 |
|
// Keyboard |
2015 |
|
case KeyPress: { |
2016 |
|
int code = -1; |
2347 |
|
{ |
2348 |
|
// Quit DGA mode if requested |
2349 |
|
possibly_quit_dga_mode(); |
2268 |
– |
|
2269 |
– |
// Handle X events |
2270 |
– |
handle_events(); |
2271 |
– |
|
2272 |
– |
// Handle palette changes |
2273 |
– |
handle_palette_changes(); |
2350 |
|
} |
2351 |
|
|
2352 |
|
#ifdef ENABLE_VOSF |
2356 |
|
// Quit DGA mode if requested |
2357 |
|
possibly_quit_dga_mode(); |
2358 |
|
|
2283 |
– |
// Handle X events |
2284 |
– |
handle_events(); |
2285 |
– |
|
2286 |
– |
// Handle palette changes |
2287 |
– |
handle_palette_changes(); |
2288 |
– |
|
2359 |
|
// Update display (VOSF variant) |
2360 |
|
static int tick_counter = 0; |
2361 |
|
if (++tick_counter >= frame_skip) { |
2374 |
|
// Ungrab mouse if requested |
2375 |
|
possibly_ungrab_mouse(); |
2376 |
|
|
2307 |
– |
// Handle X events |
2308 |
– |
handle_events(); |
2309 |
– |
|
2310 |
– |
// Handle palette changes |
2311 |
– |
handle_palette_changes(); |
2312 |
– |
|
2377 |
|
// Update display (VOSF variant) |
2378 |
|
static int tick_counter = 0; |
2379 |
|
if (++tick_counter >= frame_skip) { |
2393 |
|
// Ungrab mouse if requested |
2394 |
|
possibly_ungrab_mouse(); |
2395 |
|
|
2332 |
– |
// Handle X events |
2333 |
– |
handle_events(); |
2334 |
– |
|
2335 |
– |
// Handle_palette changes |
2336 |
– |
handle_palette_changes(); |
2337 |
– |
|
2396 |
|
// Update display (static variant) |
2397 |
|
static int tick_counter = 0; |
2398 |
|
if (++tick_counter >= frame_skip) { |
2406 |
|
// Ungrab mouse if requested |
2407 |
|
possibly_ungrab_mouse(); |
2408 |
|
|
2351 |
– |
// Handle X events |
2352 |
– |
handle_events(); |
2353 |
– |
|
2354 |
– |
// Handle_palette changes |
2355 |
– |
handle_palette_changes(); |
2356 |
– |
|
2409 |
|
// Update display (dynamic variant) |
2410 |
|
static int tick_counter = 0; |
2411 |
|
tick_counter++; |
2441 |
|
} |
2442 |
|
} |
2443 |
|
|
2444 |
+ |
// This function is called on non-threaded platforms from a timer interrupt |
2445 |
|
void VideoRefresh(void) |
2446 |
|
{ |
2447 |
|
// We need to check redraw_thread_active to inhibit refreshed during |
2448 |
|
// mode changes on non-threaded platforms |
2449 |
< |
if (redraw_thread_active) |
2450 |
< |
video_refresh(); |
2449 |
> |
if (!redraw_thread_active) |
2450 |
> |
return; |
2451 |
> |
|
2452 |
> |
// Handle X events |
2453 |
> |
handle_events(); |
2454 |
> |
|
2455 |
> |
// Handle palette changes |
2456 |
> |
handle_palette_changes(); |
2457 |
> |
|
2458 |
> |
// Update display |
2459 |
> |
video_refresh(); |
2460 |
|
} |
2461 |
|
|
2462 |
+ |
const int VIDEO_REFRESH_HZ = 60; |
2463 |
+ |
const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ; |
2464 |
+ |
|
2465 |
|
#ifdef HAVE_PTHREADS |
2466 |
|
static void *redraw_func(void *arg) |
2467 |
|
{ |
2468 |
+ |
int fd = ConnectionNumber(x_display); |
2469 |
+ |
|
2470 |
|
uint64 start = GetTicks_usec(); |
2471 |
|
int64 ticks = 0; |
2472 |
< |
uint64 next = GetTicks_usec(); |
2472 |
> |
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
2473 |
> |
|
2474 |
|
while (!redraw_thread_cancel) { |
2475 |
< |
video_refresh(); |
2408 |
< |
next += 16667; |
2475 |
> |
|
2476 |
|
int64 delay = next - GetTicks_usec(); |
2477 |
< |
if (delay > 0) |
2478 |
< |
Delay_usec(delay); |
2479 |
< |
else if (delay < -16667) |
2477 |
> |
if (delay < -VIDEO_REFRESH_DELAY) { |
2478 |
> |
|
2479 |
> |
// We are lagging far behind, so we reset the delay mechanism |
2480 |
|
next = GetTicks_usec(); |
2481 |
< |
ticks++; |
2481 |
> |
|
2482 |
> |
} else if (delay <= 0) { |
2483 |
> |
|
2484 |
> |
// Delay expired, refresh display |
2485 |
> |
handle_events(); |
2486 |
> |
handle_palette_changes(); |
2487 |
> |
video_refresh(); |
2488 |
> |
next += VIDEO_REFRESH_DELAY; |
2489 |
> |
ticks++; |
2490 |
> |
|
2491 |
> |
} else { |
2492 |
> |
|
2493 |
> |
// No display refresh pending, check for X events |
2494 |
> |
fd_set readfds; |
2495 |
> |
FD_ZERO(&readfds); |
2496 |
> |
FD_SET(fd, &readfds); |
2497 |
> |
struct timeval timeout; |
2498 |
> |
timeout.tv_sec = 0; |
2499 |
> |
timeout.tv_usec = delay; |
2500 |
> |
if (select(fd+1, &readfds, NULL, NULL, &timeout) > 0) |
2501 |
> |
handle_events(); |
2502 |
> |
} |
2503 |
|
} |
2504 |
+ |
|
2505 |
|
uint64 end = GetTicks_usec(); |
2506 |
< |
// printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, ticks * 1000000 / (end - start)); |
2506 |
> |
D(bug("%Ld refreshes in %Ld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start))); |
2507 |
|
return NULL; |
2508 |
|
} |
2509 |
|
#endif |