577 |
|
use_vosf = true; |
578 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
579 |
|
the_host_buffer = the_buffer_copy; |
580 |
< |
the_buffer_size = page_extend((aligned_height + 2) * (the_host_buffer_row_bytes = img->bytes_per_line)); |
580 |
> |
the_buffer_size = page_extend((aligned_height + 2) * img->bytes_per_line); |
581 |
|
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
582 |
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
583 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
633 |
|
return true; |
634 |
|
} |
635 |
|
|
636 |
< |
// Open FBDev display |
637 |
< |
static bool open_fbdev(int width, int height) |
636 |
> |
// Open FBDev DGA display |
637 |
> |
static bool open_fbdev_dga(int width, int height) |
638 |
|
{ |
639 |
|
#ifdef ENABLE_FBDEV_DGA |
640 |
+ |
#ifdef ENABLE_XF86_VIDMODE |
641 |
+ |
// Switch to best mode |
642 |
+ |
if (has_vidmode) { |
643 |
+ |
int best = -1; |
644 |
+ |
for (int i = 0; i < num_x_video_modes; i++) { |
645 |
+ |
if (x_video_modes[i]->hdisplay == width && x_video_modes[i]->vdisplay == height) { |
646 |
+ |
best = i; |
647 |
+ |
break; |
648 |
+ |
} |
649 |
+ |
}; |
650 |
+ |
assert(best != -1); |
651 |
+ |
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[best]); |
652 |
+ |
XF86VidModeSetViewPort(x_display, screen, 0, 0); |
653 |
+ |
D(bug("[fbdev] VideoMode %d: %d x %d @ %d\n", best, |
654 |
+ |
x_video_modes[best]->hdisplay, x_video_modes[best]->vdisplay, |
655 |
+ |
1000 * x_video_modes[best]->dotclock / (x_video_modes[best]->htotal * x_video_modes[best]->vtotal))); |
656 |
+ |
} |
657 |
+ |
#endif |
658 |
+ |
|
659 |
|
if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo) != 0) { |
660 |
|
D(bug("[fbdev] Can't get FSCREENINFO: %s\n", strerror(errno))); |
661 |
|
return false; |
725 |
|
GrabModeAsync, GrabModeAsync, CurrentTime); |
726 |
|
XGrabPointer(x_display, the_win, True, |
727 |
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask, |
728 |
< |
GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
728 |
> |
GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime); |
729 |
|
disable_mouse_accel(); |
730 |
|
|
731 |
|
// Create no_cursor |
736 |
|
XDefineCursor(x_display, the_win, mac_cursor); |
737 |
|
|
738 |
|
// Init blitting routines |
739 |
+ |
int bytes_per_row = TrivialBytesPerRow((width + 7) & ~7, DepthModeForPixelDepth(depth)); |
740 |
|
#if ENABLE_VOSF |
741 |
|
// Extract current screen color masks (we are in True Color mode) |
742 |
|
VisualFormat visualFormat; |
763 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
764 |
|
use_vosf = true; |
765 |
|
the_host_buffer = the_buffer; |
766 |
< |
the_host_buffer_row_bytes = TrivialBytesPerRow((width + 7) & ~7, DepthModeForPixelDepth(visualFormat.depth)); |
747 |
< |
the_buffer_size = page_extend((height + 2) * the_host_buffer_row_bytes); |
766 |
> |
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
767 |
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
768 |
|
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
769 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
772 |
|
// Set frame buffer base |
773 |
|
D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); |
774 |
|
screen_base = Host2MacAddr(the_buffer); |
775 |
< |
VModes[cur_mode].viRowBytes = TrivialBytesPerRow((width + 7) & ~7, DepthModeForPixelDepth(depth)); |
775 |
> |
VModes[cur_mode].viRowBytes = bytes_per_row; |
776 |
|
return true; |
777 |
|
#else |
778 |
|
ErrorAlert("SheepShaver has been compiled with DGA support disabled."); |
780 |
|
#endif |
781 |
|
} |
782 |
|
|
783 |
< |
// Open DGA display (!! should use X11 VidMode extensions to set mode) |
784 |
< |
static bool open_dga(int width, int height) |
783 |
> |
// Open XF86 DGA display (!! should use X11 VidMode extensions to set mode) |
784 |
> |
static bool open_xf86_dga(int width, int height) |
785 |
|
{ |
786 |
|
if (is_fbdev_dga_mode) |
787 |
|
return false; |
854 |
|
if (use_vosf) { |
855 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
856 |
|
the_host_buffer = the_buffer; |
857 |
< |
the_buffer_size = page_extend((height + 2) * (the_host_buffer_row_bytes = bytes_per_row)); |
857 |
> |
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
858 |
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
859 |
|
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
860 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
875 |
|
#endif |
876 |
|
} |
877 |
|
|
878 |
+ |
// Open DGA display |
879 |
+ |
static bool open_dga(int width, int height) |
880 |
+ |
{ |
881 |
+ |
bool display_open; |
882 |
+ |
|
883 |
+ |
display_open = open_xf86_dga(width, height); |
884 |
+ |
#ifdef ENABLE_FBDEV_DGA |
885 |
+ |
// Try to fallback to FBDev DGA mode |
886 |
+ |
if (!display_open) { |
887 |
+ |
is_fbdev_dga_mode = true; |
888 |
+ |
display_open = open_fbdev_dga(width, height); |
889 |
+ |
} |
890 |
+ |
#endif |
891 |
+ |
|
892 |
+ |
// Common DGA display initialization |
893 |
+ |
if (display_open) { |
894 |
+ |
|
895 |
+ |
// Fake image to get display bounds in the refresh function |
896 |
+ |
if ((img = (XImage *)malloc(sizeof(*img))) == NULL) |
897 |
+ |
return false; |
898 |
+ |
img->width = DisplayWidth(x_display, screen); |
899 |
+ |
img->height = DisplayHeight(x_display, screen); |
900 |
+ |
img->depth = is_fbdev_dga_mode ? xdepth : depth; |
901 |
+ |
img->bytes_per_line = TrivialBytesPerRow(img->width, DepthModeForPixelDepth(img->depth)); |
902 |
+ |
} |
903 |
+ |
|
904 |
+ |
return display_open; |
905 |
+ |
} |
906 |
+ |
|
907 |
|
static bool open_display(void) |
908 |
|
{ |
909 |
|
D(bug("open_display()\n")); |
992 |
|
display_type = mode.viType; |
993 |
|
depth = depth_of_video_mode(mode.viAppleMode); |
994 |
|
|
995 |
< |
bool display_open = false; |
996 |
< |
if (display_type == DIS_SCREEN) { |
995 |
> |
bool display_open; |
996 |
> |
switch (display_type) { |
997 |
> |
case DIS_SCREEN: |
998 |
|
display_open = open_dga(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
999 |
< |
#ifdef ENABLE_FBDEV_DGA |
1000 |
< |
// Try to fallback to FBDev DGA mode |
952 |
< |
if (!display_open) { |
953 |
< |
is_fbdev_dga_mode = true; |
954 |
< |
display_open = open_fbdev(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
955 |
< |
} |
956 |
< |
#endif |
957 |
< |
|
958 |
< |
} |
959 |
< |
else if (display_type == DIS_WINDOW) |
999 |
> |
break; |
1000 |
> |
case DIS_WINDOW: |
1001 |
|
display_open = open_window(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
1002 |
+ |
break; |
1003 |
+ |
default: |
1004 |
+ |
display_open = false; |
1005 |
+ |
break; |
1006 |
+ |
} |
1007 |
|
|
1008 |
|
#ifdef ENABLE_VOSF |
1009 |
|
if (use_vosf) { |
1057 |
|
} |
1058 |
|
|
1059 |
|
// Close FBDev mode |
1060 |
< |
static void close_fbdev(void) |
1060 |
> |
static void close_fbdev_dga(void) |
1061 |
|
{ |
1062 |
|
#ifdef ENABLE_FBDEV_DGA |
1017 |
– |
XUngrabPointer(x_display, CurrentTime); |
1018 |
– |
XUngrabKeyboard(x_display, CurrentTime); |
1019 |
– |
|
1063 |
|
uint8 *fb_base; |
1064 |
< |
if (!use_vosf) { |
1022 |
< |
// don't free() the screen buffer in driver_base dtor |
1064 |
> |
if (!use_vosf) |
1065 |
|
fb_base = the_buffer; |
1024 |
– |
the_buffer = NULL; |
1025 |
– |
} |
1066 |
|
#ifdef ENABLE_VOSF |
1067 |
< |
else { |
1028 |
< |
// don't free() the screen buffer in driver_base dtor |
1067 |
> |
else |
1068 |
|
fb_base = the_host_buffer; |
1030 |
– |
the_host_buffer = NULL; |
1031 |
– |
} |
1069 |
|
#endif |
1070 |
|
munmap(fb_base, fb_finfo.smem_len); |
1071 |
|
#endif |
1072 |
|
} |
1073 |
|
|
1074 |
+ |
// Close XF86 DGA mode |
1075 |
+ |
static void close_xf86_dga(void) |
1076 |
+ |
{ |
1077 |
+ |
#ifdef ENABLE_XF86_DGA |
1078 |
+ |
XF86DGADirectVideo(x_display, screen, 0); |
1079 |
+ |
#endif |
1080 |
+ |
} |
1081 |
+ |
|
1082 |
|
// Close DGA mode |
1083 |
|
static void close_dga(void) |
1084 |
|
{ |
1085 |
|
if (is_fbdev_dga_mode) |
1086 |
< |
return; |
1086 |
> |
close_fbdev_dga(); |
1087 |
> |
else |
1088 |
> |
close_xf86_dga(); |
1089 |
|
|
1043 |
– |
#ifdef ENABLE_XF86_DGA |
1044 |
– |
XF86DGADirectVideo(x_display, screen, 0); |
1090 |
|
XUngrabPointer(x_display, CurrentTime); |
1091 |
|
XUngrabKeyboard(x_display, CurrentTime); |
1047 |
– |
#endif |
1092 |
|
|
1093 |
|
#ifdef ENABLE_XF86_VIDMODE |
1094 |
|
if (has_vidmode) |
1095 |
|
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[0]); |
1096 |
|
#endif |
1097 |
|
|
1098 |
+ |
// Release fake image (it's not a normal XImage!) |
1099 |
+ |
free(img); |
1100 |
+ |
img = NULL; |
1101 |
+ |
|
1102 |
|
if (!use_vosf) { |
1103 |
|
// don't free() the screen buffer in driver_base dtor |
1104 |
|
the_buffer = NULL; |
1113 |
|
|
1114 |
|
static void close_display(void) |
1115 |
|
{ |
1116 |
< |
if (display_type == DIS_SCREEN) { |
1117 |
< |
if (is_fbdev_dga_mode) |
1070 |
< |
close_fbdev(); |
1071 |
< |
else |
1072 |
< |
close_dga(); |
1073 |
< |
} |
1116 |
> |
if (display_type == DIS_SCREEN) |
1117 |
> |
close_dga(); |
1118 |
|
else if (display_type == DIS_WINDOW) |
1119 |
|
close_window(); |
1120 |
|
|
1344 |
|
static bool has_mode(int x, int y) |
1345 |
|
{ |
1346 |
|
#ifdef ENABLE_XF86_VIDMODE |
1347 |
< |
for (int i=0; i<num_x_video_modes; i++) |
1348 |
< |
if (x_video_modes[i]->hdisplay >= x && x_video_modes[i]->vdisplay >= y) |
1349 |
< |
return true; |
1350 |
< |
return false; |
1351 |
< |
#else |
1352 |
< |
return DisplayWidth(x_display, screen) >= x && DisplayHeight(x_display, screen) >= y; |
1347 |
> |
if (has_vidmode) { |
1348 |
> |
for (int i=0; i<num_x_video_modes; i++) |
1349 |
> |
if (x_video_modes[i]->hdisplay == x && x_video_modes[i]->vdisplay == y) |
1350 |
> |
return true; |
1351 |
> |
return false; |
1352 |
> |
} |
1353 |
|
#endif |
1354 |
+ |
return DisplayWidth(x_display, screen) >= x && DisplayHeight(x_display, screen) >= y; |
1355 |
|
} |
1356 |
|
|
1357 |
|
bool VideoInit(void) |
1418 |
|
// VidMode available? |
1419 |
|
int vm_event_base, vm_error_base; |
1420 |
|
has_vidmode = XF86VidModeQueryExtension(x_display, &vm_event_base, &vm_error_base); |
1421 |
< |
if (has_vidmode) |
1421 |
> |
if (has_vidmode) { |
1422 |
> |
int vm_major_version, vm_minor_version; |
1423 |
> |
XF86VidModeQueryVersion(x_display, &vm_major_version, &vm_minor_version); |
1424 |
> |
D(bug("VidMode extension %d.%d available\n", vm_major_version, vm_minor_version)); |
1425 |
|
XF86VidModeGetAllModeLines(x_display, screen, &num_x_video_modes, &x_video_modes); |
1426 |
+ |
} |
1427 |
|
#endif |
1428 |
|
|
1429 |
|
#ifdef ENABLE_FBDEV_DGA |
1535 |
|
#endif |
1536 |
|
} else |
1537 |
|
add_custom_mode(p, display_type, default_width, default_height, default_mode, APPLE_CUSTOM); |
1538 |
+ |
|
1539 |
+ |
// Add extra VidMode capable modes |
1540 |
+ |
if (display_type == DIS_SCREEN) { |
1541 |
+ |
struct { |
1542 |
+ |
int w; |
1543 |
+ |
int h; |
1544 |
+ |
int apple_id; |
1545 |
+ |
} |
1546 |
+ |
video_modes[] = { |
1547 |
+ |
{ 640, 480, APPLE_640x480 }, |
1548 |
+ |
{ 800, 600, APPLE_800x600 }, |
1549 |
+ |
{ 1024, 768, APPLE_1024x768 }, |
1550 |
+ |
{ 1152, 768, APPLE_1152x768 }, |
1551 |
+ |
{ 1152, 900, APPLE_1152x900 }, |
1552 |
+ |
{ 1280, 1024, APPLE_1280x1024 }, |
1553 |
+ |
{ 1600, 1200, APPLE_1600x1200 }, |
1554 |
+ |
{ 0, } |
1555 |
+ |
}; |
1556 |
+ |
|
1557 |
+ |
for (int i = 0; video_modes[i].w != 0; i++) { |
1558 |
+ |
const int w = video_modes[i].w; |
1559 |
+ |
const int h = video_modes[i].h; |
1560 |
+ |
if (w >= default_width || h >= default_height) |
1561 |
+ |
continue; |
1562 |
+ |
if (has_mode(w, h)) { |
1563 |
+ |
#ifdef ENABLE_VOSF |
1564 |
+ |
if (is_fbdev_dga_mode) { |
1565 |
+ |
for (unsigned int d = APPLE_1_BIT; d <= default_mode; d++) |
1566 |
+ |
if (find_visual_for_depth(d)) |
1567 |
+ |
add_custom_mode(p, display_type, w, h, d, video_modes[i].apple_id); |
1568 |
+ |
} else |
1569 |
+ |
#endif |
1570 |
+ |
add_custom_mode(p, display_type, w, h, default_mode, video_modes[i].apple_id); |
1571 |
+ |
} |
1572 |
+ |
} |
1573 |
+ |
} |
1574 |
|
} else if (window_modes) { |
1575 |
|
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) |
1576 |
|
if (find_visual_for_depth(d)) |
1766 |
|
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
1767 |
|
Window w = is_fbdev_dga_mode ? the_win : rootwin; |
1768 |
|
XGrabKeyboard(x_display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
1769 |
< |
XGrabPointer(x_display, w, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
1769 |
> |
XGrabPointer(x_display, w, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, is_fbdev_dga_mode ? w : None, None, CurrentTime); |
1770 |
|
disable_mouse_accel(); |
1771 |
|
#ifdef ENABLE_XF86_DGA |
1772 |
|
if (!is_fbdev_dga_mode) { |
2451 |
|
XDisplayLock(); |
2452 |
|
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) |
2453 |
|
#ifdef ENABLE_XF86_DGA |
2454 |
< |
if (is_fbdev_dga_mode) |
2454 |
> |
if (!is_fbdev_dga_mode) |
2455 |
|
XF86DGADirectVideo(x_display, screen, 0); |
2456 |
|
#endif |
2457 |
|
XUngrabPointer(x_display, CurrentTime); |