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-2008 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 |
18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
*/ |
20 |
|
|
21 |
+ |
/* |
22 |
+ |
* NOTES: |
23 |
+ |
* The Ctrl key works like a qualifier for special actions: |
24 |
+ |
* Ctrl-Tab = suspend DGA mode |
25 |
+ |
* Ctrl-Esc = emergency quit |
26 |
+ |
* Ctrl-F1 = mount floppy |
27 |
+ |
* Ctrl-F5 = grab mouse (in windowed mode) |
28 |
+ |
*/ |
29 |
+ |
|
30 |
|
#include "sysdeps.h" |
31 |
|
|
32 |
|
#include <X11/Xlib.h> |
37 |
|
#include <sys/shm.h> |
38 |
|
#include <errno.h> |
39 |
|
#include <pthread.h> |
40 |
+ |
#include <semaphore.h> |
41 |
|
|
42 |
|
#include <algorithm> |
43 |
|
|
44 |
+ |
#ifdef ENABLE_FBDEV_DGA |
45 |
+ |
# include <linux/fb.h> |
46 |
+ |
# include <sys/ioctl.h> |
47 |
+ |
#endif |
48 |
+ |
|
49 |
|
#ifdef ENABLE_XF86_DGA |
50 |
|
# include <X11/extensions/xf86dga.h> |
51 |
|
#endif |
54 |
|
# include <X11/extensions/xf86vmode.h> |
55 |
|
#endif |
56 |
|
|
57 |
+ |
#ifdef ENABLE_FBDEV_DGA |
58 |
+ |
# include <sys/mman.h> |
59 |
+ |
#endif |
60 |
+ |
|
61 |
|
#include "main.h" |
62 |
|
#include "adb.h" |
63 |
|
#include "prefs.h" |
65 |
|
#include "about_window.h" |
66 |
|
#include "video.h" |
67 |
|
#include "video_defs.h" |
68 |
+ |
#include "video_blit.h" |
69 |
|
|
70 |
|
#define DEBUG 0 |
71 |
|
#include "debug.h" |
77 |
|
|
78 |
|
// Constants |
79 |
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; |
80 |
+ |
static const bool hw_mac_cursor_accl = true; // Flag: Enable MacOS to X11 copy of cursor? |
81 |
|
|
82 |
|
// Global variables |
83 |
|
static int32 frame_skip; |
85 |
|
static int16 mouse_wheel_lines; |
86 |
|
static bool redraw_thread_active = false; // Flag: Redraw thread installed |
87 |
|
static pthread_attr_t redraw_thread_attr; // Redraw thread attributes |
88 |
+ |
static volatile bool redraw_thread_cancel; // Flag: Cancel Redraw thread |
89 |
|
static pthread_t redraw_thread; // Redraw thread |
90 |
|
|
69 |
– |
static bool local_X11; // Flag: X server running on local machine? |
91 |
|
static volatile bool thread_stop_req = false; |
92 |
< |
static volatile bool thread_stop_ack = false; // Acknowledge for thread_stop_req |
92 |
> |
static sem_t thread_stop_ack; |
93 |
> |
static sem_t thread_resume_req; |
94 |
|
|
95 |
+ |
static bool local_X11; // Flag: X server running on local machine? |
96 |
|
static bool has_dga = false; // Flag: Video DGA capable |
97 |
|
static bool has_vidmode = false; // Flag: VidMode extension available |
98 |
|
|
104 |
|
|
105 |
|
static bool palette_changed = false; // Flag: Palette changed, redraw thread must update palette |
106 |
|
static bool ctrl_down = false; // Flag: Ctrl key pressed |
107 |
+ |
static bool caps_on = false; // Flag: Caps Lock on |
108 |
|
static bool quit_full_screen = false; // Flag: DGA close requested from redraw thread |
109 |
|
static volatile bool quit_full_screen_ack = false; // Acknowledge for quit_full_screen |
110 |
|
static bool emerg_quit = false; // Flag: Ctrl-Esc pressed, emergency quit requested from MacOS thread |
122 |
|
static Window rootwin, the_win; // Root window and our window |
123 |
|
static int num_depths = 0; // Number of available X depths |
124 |
|
static int *avail_depths = NULL; // List of available X depths |
125 |
+ |
static VisualFormat visualFormat; |
126 |
|
static XVisualInfo visualInfo; |
127 |
|
static Visual *vis; |
128 |
|
static int color_class; |
129 |
|
static int rshift, rloss, gshift, gloss, bshift, bloss; // Pixel format of DirectColor/TrueColor modes |
130 |
|
static Colormap cmap[2]; // Two colormaps (DGA) for 8-bit mode |
131 |
|
static XColor x_palette[256]; // Color palette to be used as CLUT and gamma table |
132 |
+ |
static int orig_accel_numer, orig_accel_denom, orig_threshold; // Original mouse acceleration |
133 |
|
|
134 |
|
static XColor black, white; |
135 |
|
static unsigned long black_pixel, white_pixel; |
152 |
|
static uint32 the_buffer_size; // Size of allocated the_buffer |
153 |
|
|
154 |
|
// Variables for DGA mode |
155 |
+ |
static bool is_fbdev_dga_mode = false; // Flag: Use FBDev DGA mode? |
156 |
|
static int current_dga_cmap; |
157 |
|
|
158 |
+ |
#ifdef ENABLE_FBDEV_DGA |
159 |
+ |
static int fb_dev_fd = -1; // Handle to fb device name |
160 |
+ |
static struct fb_fix_screeninfo fb_finfo; // Fixed info |
161 |
+ |
static struct fb_var_screeninfo fb_vinfo; // Variable info |
162 |
+ |
static struct fb_var_screeninfo fb_orig_vinfo; // Variable info to restore later |
163 |
+ |
static struct fb_cmap fb_oldcmap; // Colormap to restore later |
164 |
+ |
#endif |
165 |
+ |
|
166 |
|
#ifdef ENABLE_XF86_VIDMODE |
167 |
|
// Variables for XF86 VidMode support |
168 |
|
static XF86VidModeModeInfo **x_video_modes; // Array of all available modes |
170 |
|
#endif |
171 |
|
|
172 |
|
// Mutex to protect palette |
173 |
< |
#ifdef HAVE_SPINLOCKS |
139 |
< |
static spinlock_t x_palette_lock = SPIN_LOCK_UNLOCKED; |
140 |
< |
#define LOCK_PALETTE spin_lock(&x_palette_lock) |
141 |
< |
#define UNLOCK_PALETTE spin_unlock(&x_palette_lock) |
142 |
< |
#elif defined(HAVE_PTHREADS) |
173 |
> |
#if defined(HAVE_PTHREADS) |
174 |
|
static pthread_mutex_t x_palette_lock = PTHREAD_MUTEX_INITIALIZER; |
175 |
|
#define LOCK_PALETTE pthread_mutex_lock(&x_palette_lock) |
176 |
|
#define UNLOCK_PALETTE pthread_mutex_unlock(&x_palette_lock) |
177 |
+ |
#elif defined(HAVE_SPINLOCKS) |
178 |
+ |
static spinlock_t x_palette_lock = SPIN_LOCK_UNLOCKED; |
179 |
+ |
#define LOCK_PALETTE spin_lock(&x_palette_lock) |
180 |
+ |
#define UNLOCK_PALETTE spin_unlock(&x_palette_lock) |
181 |
|
#else |
182 |
|
#define LOCK_PALETTE |
183 |
|
#define UNLOCK_PALETTE |
184 |
|
#endif |
185 |
|
|
186 |
+ |
// Mutex to protect frame buffer |
187 |
+ |
#if defined(HAVE_PTHREADS) |
188 |
+ |
static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER; |
189 |
+ |
#define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock); |
190 |
+ |
#define UNLOCK_FRAME_BUFFER pthread_mutex_unlock(&frame_buffer_lock); |
191 |
+ |
#elif defined(HAVE_SPINLOCKS) |
192 |
+ |
static spinlock_t frame_buffer_lock = SPIN_LOCK_UNLOCKED; |
193 |
+ |
#define LOCK_FRAME_BUFFER spin_lock(&frame_buffer_lock) |
194 |
+ |
#define UNLOCK_FRAME_BUFFER spin_unlock(&frame_buffer_lock) |
195 |
+ |
#else |
196 |
+ |
#define LOCK_FRAME_BUFFER |
197 |
+ |
#define UNLOCK_FRAME_BUFFER |
198 |
+ |
#endif |
199 |
+ |
|
200 |
|
|
201 |
|
// Prototypes |
202 |
|
static void *redraw_func(void *arg); |
408 |
|
* Open display (window or fullscreen) |
409 |
|
*/ |
410 |
|
|
411 |
+ |
// Set window name and class |
412 |
+ |
static void set_window_name(Window w, int name) |
413 |
+ |
{ |
414 |
+ |
const char *str = GetString(name); |
415 |
+ |
XStoreName(x_display, w, str); |
416 |
+ |
XSetIconName(x_display, w, str); |
417 |
+ |
|
418 |
+ |
XClassHint *hints; |
419 |
+ |
hints = XAllocClassHint(); |
420 |
+ |
if (hints) { |
421 |
+ |
hints->res_name = "SheepShaver"; |
422 |
+ |
hints->res_class = "SheepShaver"; |
423 |
+ |
XSetClassHint(x_display, w, hints); |
424 |
+ |
XFree(hints); |
425 |
+ |
} |
426 |
+ |
} |
427 |
+ |
|
428 |
+ |
// Set window input focus flag |
429 |
+ |
static void set_window_focus(Window w) |
430 |
+ |
{ |
431 |
+ |
XWMHints *hints = XAllocWMHints(); |
432 |
+ |
if (hints) { |
433 |
+ |
hints->input = True; |
434 |
+ |
hints->initial_state = NormalState; |
435 |
+ |
hints->flags = InputHint | StateHint; |
436 |
+ |
XSetWMHints(x_display, w, hints); |
437 |
+ |
XFree(hints); |
438 |
+ |
} |
439 |
+ |
} |
440 |
+ |
|
441 |
|
// Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget) |
442 |
|
static Atom WM_DELETE_WINDOW = (Atom)0; |
443 |
|
static void set_window_delete_protocol(Window w) |
463 |
|
} while ((e.type != UnmapNotify) || (e.xmap.event != w)); |
464 |
|
} |
465 |
|
|
466 |
+ |
// Disable mouse acceleration |
467 |
+ |
static void disable_mouse_accel(void) |
468 |
+ |
{ |
469 |
+ |
XChangePointerControl(x_display, True, False, 1, 1, 0); |
470 |
+ |
} |
471 |
+ |
|
472 |
+ |
// Restore mouse acceleration to original value |
473 |
+ |
static void restore_mouse_accel(void) |
474 |
+ |
{ |
475 |
+ |
XChangePointerControl(x_display, True, True, orig_accel_numer, orig_accel_denom, orig_threshold); |
476 |
+ |
} |
477 |
+ |
|
478 |
|
// Trap SHM errors |
479 |
|
static bool shm_error = false; |
480 |
|
static int (*old_error_handler)(Display *, XErrorEvent *); |
507 |
|
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
508 |
|
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | CWBackingStore | CWColormap, &wattr); |
509 |
|
|
510 |
< |
// Set window name |
511 |
< |
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); |
510 |
> |
// Set window name/class |
511 |
> |
set_window_name(the_win, STR_WINDOW_TITLE); |
512 |
> |
|
513 |
> |
// Indicate that we want keyboard input |
514 |
> |
set_window_focus(the_win); |
515 |
|
|
516 |
|
// Set delete protocol property |
517 |
|
set_window_delete_protocol(the_win); |
592 |
|
the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line); |
593 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); |
594 |
|
#endif |
595 |
< |
screen_base = (uint32)the_buffer; |
595 |
> |
screen_base = Host2MacAddr(the_buffer); |
596 |
|
|
597 |
|
// Create GC |
598 |
|
the_gc = XCreateGC(x_display, the_win, 0, 0); |
599 |
|
XSetState(x_display, the_gc, black_pixel, white_pixel, GXcopy, AllPlanes); |
600 |
|
|
601 |
|
// Create cursor |
602 |
< |
cursor_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 4, 16, 16, 16, 2); |
603 |
< |
cursor_image->byte_order = MSBFirst; |
604 |
< |
cursor_image->bitmap_bit_order = MSBFirst; |
605 |
< |
cursor_mask_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 36, 16, 16, 16, 2); |
606 |
< |
cursor_mask_image->byte_order = MSBFirst; |
607 |
< |
cursor_mask_image->bitmap_bit_order = MSBFirst; |
608 |
< |
cursor_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
609 |
< |
cursor_mask_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
610 |
< |
cursor_gc = XCreateGC(x_display, cursor_map, 0, 0); |
611 |
< |
cursor_mask_gc = XCreateGC(x_display, cursor_mask_map, 0, 0); |
612 |
< |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, 0, 0); |
613 |
< |
cursor_changed = false; |
602 |
> |
if (hw_mac_cursor_accl) { |
603 |
> |
cursor_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 4, 16, 16, 16, 2); |
604 |
> |
cursor_image->byte_order = MSBFirst; |
605 |
> |
cursor_image->bitmap_bit_order = MSBFirst; |
606 |
> |
cursor_mask_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 36, 16, 16, 16, 2); |
607 |
> |
cursor_mask_image->byte_order = MSBFirst; |
608 |
> |
cursor_mask_image->bitmap_bit_order = MSBFirst; |
609 |
> |
cursor_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
610 |
> |
cursor_mask_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
611 |
> |
cursor_gc = XCreateGC(x_display, cursor_map, 0, 0); |
612 |
> |
cursor_mask_gc = XCreateGC(x_display, cursor_mask_map, 0, 0); |
613 |
> |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, 0, 0); |
614 |
> |
cursor_changed = false; |
615 |
> |
} |
616 |
> |
|
617 |
> |
// Create no_cursor |
618 |
> |
else { |
619 |
> |
mac_cursor = XCreatePixmapCursor(x_display, |
620 |
> |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
621 |
> |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
622 |
> |
&black, &white, 0, 0); |
623 |
> |
XDefineCursor(x_display, the_win, mac_cursor); |
624 |
> |
} |
625 |
|
|
626 |
|
// Init blitting routines |
627 |
|
bool native_byte_order; |
631 |
|
native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
632 |
|
#endif |
633 |
|
#ifdef ENABLE_VOSF |
634 |
< |
Screen_blitter_init(&visualInfo, native_byte_order, depth); |
634 |
> |
Screen_blitter_init(visualFormat, native_byte_order, depth); |
635 |
|
#endif |
636 |
|
|
637 |
|
// Set bytes per row |
639 |
|
return true; |
640 |
|
} |
641 |
|
|
642 |
< |
// Open DGA display (!! should use X11 VidMode extensions to set mode) |
643 |
< |
static bool open_dga(int width, int height) |
642 |
> |
// Open FBDev DGA display |
643 |
> |
static bool open_fbdev_dga(int width, int height) |
644 |
|
{ |
645 |
+ |
#ifdef ENABLE_FBDEV_DGA |
646 |
+ |
#ifdef ENABLE_XF86_VIDMODE |
647 |
+ |
// Switch to best mode |
648 |
+ |
if (has_vidmode) { |
649 |
+ |
int best = -1; |
650 |
+ |
for (int i = 0; i < num_x_video_modes; i++) { |
651 |
+ |
if (x_video_modes[i]->hdisplay == width && x_video_modes[i]->vdisplay == height) { |
652 |
+ |
best = i; |
653 |
+ |
break; |
654 |
+ |
} |
655 |
+ |
}; |
656 |
+ |
assert(best != -1); |
657 |
+ |
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[best]); |
658 |
+ |
XF86VidModeSetViewPort(x_display, screen, 0, 0); |
659 |
+ |
D(bug("[fbdev] VideoMode %d: %d x %d @ %d\n", best, |
660 |
+ |
x_video_modes[best]->hdisplay, x_video_modes[best]->vdisplay, |
661 |
+ |
1000 * x_video_modes[best]->dotclock / (x_video_modes[best]->htotal * x_video_modes[best]->vtotal))); |
662 |
+ |
} |
663 |
+ |
#endif |
664 |
+ |
|
665 |
+ |
if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo) != 0) { |
666 |
+ |
D(bug("[fbdev] Can't get FSCREENINFO: %s\n", strerror(errno))); |
667 |
+ |
return false; |
668 |
+ |
} |
669 |
+ |
D(bug("[fbdev] Device ID: %s\n", fb_finfo.id)); |
670 |
+ |
D(bug("[fbdev] smem_start: %p [%d bytes]\n", fb_finfo.smem_start, fb_finfo.smem_len)); |
671 |
+ |
|
672 |
+ |
int fb_type = fb_finfo.type; |
673 |
+ |
const char *fb_type_str = NULL; |
674 |
+ |
switch (fb_type) { |
675 |
+ |
case FB_TYPE_PACKED_PIXELS: fb_type_str = "Packed Pixels"; break; |
676 |
+ |
case FB_TYPE_PLANES: fb_type_str = "Non interleaved planes"; break; |
677 |
+ |
case FB_TYPE_INTERLEAVED_PLANES: fb_type_str = "Interleaved planes"; break; |
678 |
+ |
case FB_TYPE_TEXT: fb_type_str = "Text/attributes"; break; |
679 |
+ |
case FB_TYPE_VGA_PLANES: fb_type_str = "EGA/VGA planes"; break; |
680 |
+ |
default: fb_type_str = "<unknown>"; break; |
681 |
+ |
} |
682 |
+ |
D(bug("[fbdev] type: %s\n", fb_type_str)); |
683 |
+ |
|
684 |
+ |
if (fb_type != FB_TYPE_PACKED_PIXELS) { |
685 |
+ |
D(bug("[fbdev] type '%s' not supported\n", fb_type_str)); |
686 |
+ |
return false; |
687 |
+ |
} |
688 |
+ |
|
689 |
+ |
int fb_visual = fb_finfo.visual; |
690 |
+ |
const char *fb_visual_str; |
691 |
+ |
switch (fb_visual) { |
692 |
+ |
case FB_VISUAL_MONO01: fb_visual_str = "Monochrome 1=Black 0=White"; break; |
693 |
+ |
case FB_VISUAL_MONO10: fb_visual_str = "Monochrome 1=While 0=Black"; break; |
694 |
+ |
case FB_VISUAL_TRUECOLOR: fb_visual_str = "True color"; break; |
695 |
+ |
case FB_VISUAL_PSEUDOCOLOR: fb_visual_str = "Pseudo color (like atari)"; break; |
696 |
+ |
case FB_VISUAL_DIRECTCOLOR: fb_visual_str = "Direct color"; break; |
697 |
+ |
case FB_VISUAL_STATIC_PSEUDOCOLOR: fb_visual_str = "Pseudo color readonly"; break; |
698 |
+ |
default: fb_visual_str = "<unknown>"; break; |
699 |
+ |
} |
700 |
+ |
D(bug("[fbdev] visual: %s\n", fb_visual_str)); |
701 |
+ |
|
702 |
+ |
if (fb_visual != FB_VISUAL_TRUECOLOR && fb_visual != FB_VISUAL_DIRECTCOLOR) { |
703 |
+ |
D(bug("[fbdev] visual '%s' not supported\n", fb_visual_str)); |
704 |
+ |
return false; |
705 |
+ |
} |
706 |
+ |
|
707 |
+ |
// Map frame buffer |
708 |
+ |
the_buffer = (uint8 *)mmap(NULL, fb_finfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb_dev_fd, 0); |
709 |
+ |
if (the_buffer == MAP_FAILED) { |
710 |
+ |
D(bug("[fbdev] Can't mmap /dev/fb0: %s\n", strerror(errno))); |
711 |
+ |
return false; |
712 |
+ |
} |
713 |
+ |
|
714 |
+ |
// Set absolute mouse mode |
715 |
+ |
ADBSetRelMouseMode(false); |
716 |
+ |
|
717 |
+ |
// Create window |
718 |
+ |
XSetWindowAttributes wattr; |
719 |
+ |
wattr.event_mask = eventmask = dga_eventmask; |
720 |
+ |
wattr.override_redirect = True; |
721 |
+ |
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
722 |
+ |
InputOutput, DefaultVisual(x_display, screen), |
723 |
+ |
CWEventMask | CWOverrideRedirect, &wattr); |
724 |
+ |
|
725 |
+ |
// Show window |
726 |
+ |
XMapRaised(x_display, the_win); |
727 |
+ |
wait_mapped(the_win); |
728 |
+ |
|
729 |
+ |
// Grab mouse and keyboard |
730 |
+ |
XGrabKeyboard(x_display, the_win, True, |
731 |
+ |
GrabModeAsync, GrabModeAsync, CurrentTime); |
732 |
+ |
XGrabPointer(x_display, the_win, True, |
733 |
+ |
PointerMotionMask | ButtonPressMask | ButtonReleaseMask, |
734 |
+ |
GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime); |
735 |
+ |
disable_mouse_accel(); |
736 |
+ |
|
737 |
+ |
// Create no_cursor |
738 |
+ |
mac_cursor = XCreatePixmapCursor(x_display, |
739 |
+ |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
740 |
+ |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
741 |
+ |
&black, &white, 0, 0); |
742 |
+ |
XDefineCursor(x_display, the_win, mac_cursor); |
743 |
+ |
|
744 |
+ |
// Init blitting routines |
745 |
+ |
int bytes_per_row = TrivialBytesPerRow((width + 7) & ~7, DepthModeForPixelDepth(depth)); |
746 |
+ |
#if ENABLE_VOSF |
747 |
+ |
// Extract current screen color masks (we are in True Color mode) |
748 |
+ |
VisualFormat visualFormat; |
749 |
+ |
visualFormat.depth = xdepth = DefaultDepth(x_display, screen); |
750 |
+ |
XMatchVisualInfo(x_display, screen, xdepth, TrueColor, &visualInfo); |
751 |
+ |
assert(visualFormat.depth == visualInfo.depth); |
752 |
+ |
visualFormat.Rmask = visualInfo.red_mask; |
753 |
+ |
visualFormat.Gmask = visualInfo.green_mask; |
754 |
+ |
visualFormat.Bmask = visualInfo.blue_mask; |
755 |
+ |
D(bug("[fbdev] %d bpp, (%08x,%08x,%08x)\n", |
756 |
+ |
visualFormat.depth, |
757 |
+ |
visualFormat.Rmask, visualFormat.Gmask, visualFormat.Bmask)); |
758 |
+ |
D(bug("[fbdev] Mac depth %d bpp\n", depth)); |
759 |
+ |
|
760 |
+ |
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
761 |
+ |
// i.e. the framebuffer update function is not Blit_Copy_Raw |
762 |
+ |
#ifdef WORDS_BIGENDIAN |
763 |
+ |
const bool native_byte_order = (XImageByteOrder(x_display) == MSBFirst); |
764 |
+ |
#else |
765 |
+ |
const bool native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
766 |
+ |
#endif |
767 |
+ |
Screen_blitter_init(visualFormat, native_byte_order, depth); |
768 |
+ |
|
769 |
+ |
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
770 |
+ |
use_vosf = true; |
771 |
+ |
the_host_buffer = the_buffer; |
772 |
+ |
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
773 |
+ |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
774 |
+ |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
775 |
+ |
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
776 |
+ |
#endif |
777 |
+ |
|
778 |
+ |
// Set frame buffer base |
779 |
+ |
D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); |
780 |
+ |
screen_base = Host2MacAddr(the_buffer); |
781 |
+ |
VModes[cur_mode].viRowBytes = bytes_per_row; |
782 |
+ |
return true; |
783 |
+ |
#else |
784 |
+ |
ErrorAlert("SheepShaver has been compiled with DGA support disabled."); |
785 |
+ |
return false; |
786 |
+ |
#endif |
787 |
+ |
} |
788 |
+ |
|
789 |
+ |
// Open XF86 DGA display (!! should use X11 VidMode extensions to set mode) |
790 |
+ |
static bool open_xf86_dga(int width, int height) |
791 |
+ |
{ |
792 |
+ |
if (is_fbdev_dga_mode) |
793 |
+ |
return false; |
794 |
+ |
|
795 |
|
#ifdef ENABLE_XF86_DGA |
796 |
|
// Set relative mouse mode |
797 |
|
ADBSetRelMouseMode(true); |
855 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
856 |
|
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
857 |
|
// i.e. the framebuffer update function is not Blit_Copy_Raw |
858 |
< |
use_vosf = Screen_blitter_init(&visualInfo, native_byte_order, depth); |
858 |
> |
use_vosf = Screen_blitter_init(visualFormat, native_byte_order, depth); |
859 |
|
|
860 |
|
if (use_vosf) { |
861 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
872 |
|
|
873 |
|
// Set frame buffer base |
874 |
|
D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); |
875 |
< |
screen_base = (uint32)the_buffer; |
875 |
> |
screen_base = Host2MacAddr(the_buffer); |
876 |
|
VModes[cur_mode].viRowBytes = bytes_per_row; |
877 |
|
return true; |
878 |
|
#else |
881 |
|
#endif |
882 |
|
} |
883 |
|
|
884 |
+ |
// Open DGA display |
885 |
+ |
static bool open_dga(int width, int height) |
886 |
+ |
{ |
887 |
+ |
bool display_open; |
888 |
+ |
|
889 |
+ |
display_open = open_xf86_dga(width, height); |
890 |
+ |
#ifdef ENABLE_FBDEV_DGA |
891 |
+ |
// Try to fallback to FBDev DGA mode |
892 |
+ |
if (!display_open) { |
893 |
+ |
is_fbdev_dga_mode = true; |
894 |
+ |
display_open = open_fbdev_dga(width, height); |
895 |
+ |
} |
896 |
+ |
#endif |
897 |
+ |
|
898 |
+ |
// Common DGA display initialization |
899 |
+ |
if (display_open) { |
900 |
+ |
|
901 |
+ |
// Fake image to get display bounds in the refresh function |
902 |
+ |
if ((img = (XImage *)malloc(sizeof(*img))) == NULL) |
903 |
+ |
return false; |
904 |
+ |
img->width = DisplayWidth(x_display, screen); |
905 |
+ |
img->height = DisplayHeight(x_display, screen); |
906 |
+ |
img->depth = is_fbdev_dga_mode ? xdepth : depth; |
907 |
+ |
img->bytes_per_line = TrivialBytesPerRow(img->width, DepthModeForPixelDepth(img->depth)); |
908 |
+ |
} |
909 |
+ |
|
910 |
+ |
return display_open; |
911 |
+ |
} |
912 |
+ |
|
913 |
|
static bool open_display(void) |
914 |
|
{ |
915 |
|
D(bug("open_display()\n")); |
916 |
|
const VideoInfo &mode = VModes[cur_mode]; |
917 |
|
|
918 |
+ |
// Get original mouse acceleration |
919 |
+ |
XGetPointerControl(x_display, &orig_accel_numer, &orig_accel_denom, &orig_threshold); |
920 |
+ |
|
921 |
|
// Find best available X visual |
922 |
|
if (!find_visual_for_depth(mode.viAppleMode)) { |
923 |
|
ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); |
924 |
|
return false; |
925 |
|
} |
926 |
|
|
927 |
+ |
// Build up visualFormat structure |
928 |
+ |
visualFormat.fullscreen = (display_type == DIS_SCREEN); |
929 |
+ |
visualFormat.depth = visualInfo.depth; |
930 |
+ |
visualFormat.Rmask = visualInfo.red_mask; |
931 |
+ |
visualFormat.Gmask = visualInfo.green_mask; |
932 |
+ |
visualFormat.Bmask = visualInfo.blue_mask; |
933 |
+ |
|
934 |
|
// Create color maps |
935 |
|
if (color_class == PseudoColor || color_class == DirectColor) { |
936 |
|
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
998 |
|
display_type = mode.viType; |
999 |
|
depth = depth_of_video_mode(mode.viAppleMode); |
1000 |
|
|
1001 |
< |
bool display_open = false; |
1002 |
< |
if (display_type == DIS_SCREEN) |
1001 |
> |
bool display_open; |
1002 |
> |
switch (display_type) { |
1003 |
> |
case DIS_SCREEN: |
1004 |
|
display_open = open_dga(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
1005 |
< |
else if (display_type == DIS_WINDOW) |
1005 |
> |
break; |
1006 |
> |
case DIS_WINDOW: |
1007 |
|
display_open = open_window(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
1008 |
+ |
break; |
1009 |
+ |
default: |
1010 |
+ |
display_open = false; |
1011 |
+ |
break; |
1012 |
+ |
} |
1013 |
|
|
1014 |
|
#ifdef ENABLE_VOSF |
1015 |
|
if (use_vosf) { |
1016 |
|
// Initialize the VOSF system |
1017 |
+ |
LOCK_VOSF; |
1018 |
|
if (!video_vosf_init()) { |
1019 |
|
ErrorAlert(GetString(STR_VOSF_INIT_ERR)); |
1020 |
+ |
UNLOCK_VOSF; |
1021 |
|
return false; |
1022 |
|
} |
1023 |
+ |
UNLOCK_VOSF; |
1024 |
|
} |
1025 |
|
#endif |
1026 |
< |
|
1026 |
> |
|
1027 |
> |
// Zero screen buffers, viRowBytes is initialized at this stage |
1028 |
> |
if (display_open) { |
1029 |
> |
memset(the_buffer, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
1030 |
> |
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
1031 |
> |
} |
1032 |
|
return display_open; |
1033 |
|
} |
1034 |
|
|
1064 |
|
XSync(x_display, false); |
1065 |
|
} |
1066 |
|
|
1067 |
< |
// Close DGA mode |
1068 |
< |
static void close_dga(void) |
1067 |
> |
// Close FBDev mode |
1068 |
> |
static void close_fbdev_dga(void) |
1069 |
> |
{ |
1070 |
> |
#ifdef ENABLE_FBDEV_DGA |
1071 |
> |
uint8 *fb_base; |
1072 |
> |
if (!use_vosf) |
1073 |
> |
fb_base = the_buffer; |
1074 |
> |
#ifdef ENABLE_VOSF |
1075 |
> |
else |
1076 |
> |
fb_base = the_host_buffer; |
1077 |
> |
#endif |
1078 |
> |
munmap(fb_base, fb_finfo.smem_len); |
1079 |
> |
#endif |
1080 |
> |
} |
1081 |
> |
|
1082 |
> |
// Close XF86 DGA mode |
1083 |
> |
static void close_xf86_dga(void) |
1084 |
|
{ |
1085 |
|
#ifdef ENABLE_XF86_DGA |
1086 |
|
XF86DGADirectVideo(x_display, screen, 0); |
1087 |
+ |
#endif |
1088 |
+ |
} |
1089 |
+ |
|
1090 |
+ |
// Close DGA mode |
1091 |
+ |
static void close_dga(void) |
1092 |
+ |
{ |
1093 |
+ |
if (is_fbdev_dga_mode) |
1094 |
+ |
close_fbdev_dga(); |
1095 |
+ |
else |
1096 |
+ |
close_xf86_dga(); |
1097 |
+ |
|
1098 |
|
XUngrabPointer(x_display, CurrentTime); |
1099 |
|
XUngrabKeyboard(x_display, CurrentTime); |
765 |
– |
#endif |
1100 |
|
|
1101 |
|
#ifdef ENABLE_XF86_VIDMODE |
1102 |
|
if (has_vidmode) |
1103 |
|
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[0]); |
1104 |
|
#endif |
1105 |
|
|
1106 |
+ |
// Release fake image (it's not a normal XImage!) |
1107 |
+ |
free(img); |
1108 |
+ |
img = NULL; |
1109 |
+ |
|
1110 |
|
if (!use_vosf) { |
1111 |
|
// don't free() the screen buffer in driver_base dtor |
1112 |
|
the_buffer = NULL; |
1177 |
|
} |
1178 |
|
} |
1179 |
|
#endif |
1180 |
+ |
|
1181 |
+ |
// Restore mouse acceleration |
1182 |
+ |
restore_mouse_accel(); |
1183 |
|
} |
1184 |
|
|
1185 |
|
|
1211 |
|
|
1212 |
|
// Search for server vendor string, then read keycodes |
1213 |
|
const char *vendor = ServerVendor(x_display); |
1214 |
+ |
// Force use of MacX mappings on MacOS X with Apple's X server |
1215 |
+ |
int dummy; |
1216 |
+ |
if (XQueryExtension(x_display, "Apple-DRI", &dummy, &dummy, &dummy)) |
1217 |
+ |
vendor = "MacX"; |
1218 |
|
bool vendor_found = false; |
1219 |
|
char line[256]; |
1220 |
|
while (fgets(line, 255, f)) { |
1289 |
|
return -1; |
1290 |
|
} |
1291 |
|
|
1292 |
+ |
// Add custom video mode |
1293 |
+ |
static void add_custom_mode(VideoInfo *&p, int type, uint32 x, uint32 y, int apple_mode, int apple_id) |
1294 |
+ |
{ |
1295 |
+ |
p->viType = type; |
1296 |
+ |
p->viXsize = x; |
1297 |
+ |
p->viYsize = y; |
1298 |
+ |
p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); |
1299 |
+ |
p->viAppleMode = apple_mode; |
1300 |
+ |
p->viAppleID = apple_id; |
1301 |
+ |
p++; |
1302 |
+ |
} |
1303 |
+ |
|
1304 |
|
// Add mode to list of supported modes |
1305 |
|
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type) |
1306 |
|
{ |
1307 |
|
if (allow & test) { |
1308 |
< |
p->viType = type; |
1308 |
> |
uint32 x = 0, y = 0; |
1309 |
|
switch (apple_id) { |
1310 |
|
case APPLE_W_640x480: |
1311 |
|
case APPLE_640x480: |
1312 |
< |
p->viXsize = 640; |
1313 |
< |
p->viYsize = 480; |
1312 |
> |
x = 640; |
1313 |
> |
y = 480; |
1314 |
|
break; |
1315 |
|
case APPLE_W_800x600: |
1316 |
|
case APPLE_800x600: |
1317 |
< |
p->viXsize = 800; |
1318 |
< |
p->viYsize = 600; |
1317 |
> |
x = 800; |
1318 |
> |
y = 600; |
1319 |
|
break; |
1320 |
|
case APPLE_1024x768: |
1321 |
< |
p->viXsize = 1024; |
1322 |
< |
p->viYsize = 768; |
1321 |
> |
x = 1024; |
1322 |
> |
y = 768; |
1323 |
|
break; |
1324 |
|
case APPLE_1152x768: |
1325 |
< |
p->viXsize = 1152; |
1326 |
< |
p->viYsize = 768; |
1325 |
> |
x = 1152; |
1326 |
> |
y = 768; |
1327 |
|
break; |
1328 |
|
case APPLE_1152x900: |
1329 |
< |
p->viXsize = 1152; |
1330 |
< |
p->viYsize = 900; |
1329 |
> |
x = 1152; |
1330 |
> |
y = 900; |
1331 |
|
break; |
1332 |
|
case APPLE_1280x1024: |
1333 |
< |
p->viXsize = 1280; |
1334 |
< |
p->viYsize = 1024; |
1333 |
> |
x = 1280; |
1334 |
> |
y = 1024; |
1335 |
|
break; |
1336 |
|
case APPLE_1600x1200: |
1337 |
< |
p->viXsize = 1600; |
1338 |
< |
p->viYsize = 1200; |
1337 |
> |
x = 1600; |
1338 |
> |
y = 1200; |
1339 |
|
break; |
1340 |
|
} |
1341 |
< |
p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); |
985 |
< |
p->viAppleMode = apple_mode; |
986 |
< |
p->viAppleID = apple_id; |
987 |
< |
p++; |
1341 |
> |
add_custom_mode(p, type, x, y, apple_mode, apple_id); |
1342 |
|
} |
1343 |
|
} |
1344 |
|
|
1352 |
|
static bool has_mode(int x, int y) |
1353 |
|
{ |
1354 |
|
#ifdef ENABLE_XF86_VIDMODE |
1355 |
< |
for (int i=0; i<num_x_video_modes; i++) |
1356 |
< |
if (x_video_modes[i]->hdisplay >= x && x_video_modes[i]->vdisplay >= y) |
1357 |
< |
return true; |
1358 |
< |
return false; |
1359 |
< |
#else |
1360 |
< |
return DisplayWidth(x_display, screen) >= x && DisplayHeight(x_display, screen) >= y; |
1355 |
> |
if (has_vidmode) { |
1356 |
> |
for (int i=0; i<num_x_video_modes; i++) |
1357 |
> |
if (x_video_modes[i]->hdisplay == x && x_video_modes[i]->vdisplay == y) |
1358 |
> |
return true; |
1359 |
> |
return false; |
1360 |
> |
} |
1361 |
|
#endif |
1362 |
+ |
return DisplayWidth(x_display, screen) >= x && DisplayHeight(x_display, screen) >= y; |
1363 |
|
} |
1364 |
|
|
1365 |
|
bool VideoInit(void) |
1408 |
|
#ifdef ENABLE_XF86_DGA |
1409 |
|
// DGA available? |
1410 |
|
int event_base, error_base; |
1411 |
+ |
is_fbdev_dga_mode = false; |
1412 |
|
if (local_X11 && XF86DGAQueryExtension(x_display, &event_base, &error_base)) { |
1413 |
|
int dga_flags = 0; |
1414 |
|
XF86DGAQueryDirectVideo(x_display, screen, &dga_flags); |
1415 |
|
has_dga = dga_flags & XF86DGADirectPresent; |
1416 |
+ |
#if defined(__linux__) |
1417 |
+ |
// Check r/w permission on /dev/mem for DGA mode to work |
1418 |
+ |
if (has_dga && access("/dev/mem", R_OK | W_OK) != 0) |
1419 |
+ |
has_dga = false; |
1420 |
+ |
#endif |
1421 |
|
} else |
1422 |
|
has_dga = false; |
1423 |
|
#endif |
1426 |
|
// VidMode available? |
1427 |
|
int vm_event_base, vm_error_base; |
1428 |
|
has_vidmode = XF86VidModeQueryExtension(x_display, &vm_event_base, &vm_error_base); |
1429 |
< |
if (has_vidmode) |
1429 |
> |
if (has_vidmode) { |
1430 |
> |
int vm_major_version, vm_minor_version; |
1431 |
> |
XF86VidModeQueryVersion(x_display, &vm_major_version, &vm_minor_version); |
1432 |
> |
D(bug("VidMode extension %d.%d available\n", vm_major_version, vm_minor_version)); |
1433 |
|
XF86VidModeGetAllModeLines(x_display, screen, &num_x_video_modes, &x_video_modes); |
1434 |
+ |
} |
1435 |
+ |
#endif |
1436 |
+ |
|
1437 |
+ |
#ifdef ENABLE_FBDEV_DGA |
1438 |
+ |
// FBDev available? |
1439 |
+ |
bool has_fbdev_dga = false; |
1440 |
+ |
if (local_X11) { |
1441 |
+ |
if ((fb_dev_fd = open("/dev/fb0", O_RDWR)) > 0) { |
1442 |
+ |
if (ioctl(fb_dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo) != 0) |
1443 |
+ |
close(fb_dev_fd); |
1444 |
+ |
else { |
1445 |
+ |
has_fbdev_dga = true; |
1446 |
+ |
if (!has_dga) { |
1447 |
+ |
// Fallback to FBDev DGA mode if XF86 DGA is not possible |
1448 |
+ |
has_dga = true; |
1449 |
+ |
is_fbdev_dga_mode = true; |
1450 |
+ |
} |
1451 |
+ |
fb_orig_vinfo = fb_vinfo; |
1452 |
+ |
D(bug("Frame buffer device initial resolution: %dx%dx%d\n", fb_vinfo.xres, fb_vinfo.yres, fb_vinfo.bits_per_pixel)); |
1453 |
+ |
} |
1454 |
+ |
} |
1455 |
+ |
} |
1456 |
|
#endif |
1457 |
|
|
1458 |
|
// Find black and white colors |
1480 |
|
break; |
1481 |
|
} |
1482 |
|
|
1483 |
+ |
// Get screen mode from preferences |
1484 |
+ |
const char *mode_str = PrefsFindString("screen"); |
1485 |
+ |
int default_width = 640, default_height = 480; |
1486 |
+ |
if (mode_str) { |
1487 |
+ |
display_type = DIS_INVALID; |
1488 |
+ |
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) |
1489 |
+ |
display_type = DIS_WINDOW; |
1490 |
+ |
#ifdef ENABLE_XF86_DGA |
1491 |
+ |
else if (has_dga && sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2) |
1492 |
+ |
display_type = DIS_SCREEN; |
1493 |
+ |
#endif |
1494 |
+ |
#ifdef ENABLE_FBDEV_DGA |
1495 |
+ |
else if (has_fbdev_dga && sscanf(mode_str, "fbdev/%d/%d", &default_width, &default_height) == 2) { |
1496 |
+ |
is_fbdev_dga_mode = true; |
1497 |
+ |
display_type = DIS_SCREEN; |
1498 |
+ |
} |
1499 |
+ |
#endif |
1500 |
+ |
if (display_type == DIS_INVALID) { |
1501 |
+ |
D(bug("Invalid screen mode specified, defaulting to old modes selection\n")); |
1502 |
+ |
mode_str = NULL; |
1503 |
+ |
} |
1504 |
+ |
else { |
1505 |
+ |
if (default_width <= 0) |
1506 |
+ |
default_width = DisplayWidth(x_display, screen); |
1507 |
+ |
else if (default_width > DisplayWidth(x_display, screen)) |
1508 |
+ |
default_width = DisplayWidth(x_display, screen); |
1509 |
+ |
if (default_height <= 0) |
1510 |
+ |
default_height = DisplayHeight(x_display, screen); |
1511 |
+ |
else if (default_height > DisplayHeight(x_display, screen)) |
1512 |
+ |
default_height = DisplayHeight(x_display, screen); |
1513 |
+ |
} |
1514 |
+ |
} |
1515 |
+ |
|
1516 |
|
// Construct video mode table |
1517 |
|
uint32 window_modes = PrefsFindInt32("windowmodes"); |
1518 |
|
uint32 screen_modes = PrefsFindInt32("screenmodes"); |
1519 |
|
if (!has_dga) |
1520 |
|
screen_modes = 0; |
1521 |
< |
if (window_modes == 0 && screen_modes == 0) |
1521 |
> |
if (mode_str) |
1522 |
> |
window_modes = screen_modes = 0; |
1523 |
> |
else if (window_modes == 0 && screen_modes == 0) |
1524 |
|
window_modes |= 3; // Allow at least 640x480 and 800x600 window modes |
1525 |
|
|
1526 |
|
VideoInfo *p = VModes; |
1527 |
< |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) |
1528 |
< |
if (find_visual_for_depth(d)) |
1529 |
< |
add_window_modes(p, window_modes, d); |
1527 |
> |
if (mode_str) { |
1528 |
> |
if (display_type == DIS_WINDOW) { |
1529 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) { |
1530 |
> |
if (find_visual_for_depth(d)) { |
1531 |
> |
if (default_width > 640 && default_height > 480) |
1532 |
> |
add_mode(p, 3, 1, d, APPLE_W_640x480, DIS_WINDOW); |
1533 |
> |
if (default_width > 800 && default_height > 600) |
1534 |
> |
add_mode(p, 3, 2, d, APPLE_W_800x600, DIS_WINDOW); |
1535 |
> |
add_custom_mode(p, display_type, default_width, default_height, d, APPLE_CUSTOM); |
1536 |
> |
} |
1537 |
> |
} |
1538 |
> |
#ifdef ENABLE_VOSF |
1539 |
> |
} else if (display_type == DIS_SCREEN && is_fbdev_dga_mode) { |
1540 |
> |
for (unsigned int d = APPLE_1_BIT; d <= default_mode; d++) |
1541 |
> |
if (find_visual_for_depth(d)) |
1542 |
> |
add_custom_mode(p, display_type, default_width, default_height, d, APPLE_CUSTOM); |
1543 |
> |
#endif |
1544 |
> |
} else |
1545 |
> |
add_custom_mode(p, display_type, default_width, default_height, default_mode, APPLE_CUSTOM); |
1546 |
|
|
1547 |
< |
if (has_vidmode) { |
1547 |
> |
// Add extra VidMode capable modes |
1548 |
> |
if (display_type == DIS_SCREEN) { |
1549 |
> |
struct { |
1550 |
> |
int w; |
1551 |
> |
int h; |
1552 |
> |
int apple_id; |
1553 |
> |
} |
1554 |
> |
video_modes[] = { |
1555 |
> |
{ 640, 480, APPLE_640x480 }, |
1556 |
> |
{ 800, 600, APPLE_800x600 }, |
1557 |
> |
{ 1024, 768, APPLE_1024x768 }, |
1558 |
> |
{ 1152, 768, APPLE_1152x768 }, |
1559 |
> |
{ 1152, 900, APPLE_1152x900 }, |
1560 |
> |
{ 1280, 1024, APPLE_1280x1024 }, |
1561 |
> |
{ 1600, 1200, APPLE_1600x1200 }, |
1562 |
> |
{ 0, } |
1563 |
> |
}; |
1564 |
> |
|
1565 |
> |
for (int i = 0; video_modes[i].w != 0; i++) { |
1566 |
> |
const int w = video_modes[i].w; |
1567 |
> |
const int h = video_modes[i].h; |
1568 |
> |
if (w >= default_width || h >= default_height) |
1569 |
> |
continue; |
1570 |
> |
if (has_mode(w, h)) { |
1571 |
> |
#ifdef ENABLE_VOSF |
1572 |
> |
if (is_fbdev_dga_mode) { |
1573 |
> |
for (unsigned int d = APPLE_1_BIT; d <= default_mode; d++) |
1574 |
> |
if (find_visual_for_depth(d)) |
1575 |
> |
add_custom_mode(p, display_type, w, h, d, video_modes[i].apple_id); |
1576 |
> |
} else |
1577 |
> |
#endif |
1578 |
> |
add_custom_mode(p, display_type, w, h, default_mode, video_modes[i].apple_id); |
1579 |
> |
} |
1580 |
> |
} |
1581 |
> |
} |
1582 |
> |
} else if (window_modes) { |
1583 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) |
1584 |
> |
if (find_visual_for_depth(d)) |
1585 |
> |
add_window_modes(p, window_modes, d); |
1586 |
> |
} else if (has_vidmode) { |
1587 |
|
if (has_mode(640, 480)) |
1588 |
|
add_mode(p, screen_modes, 1, default_mode, APPLE_640x480, DIS_SCREEN); |
1589 |
|
if (has_mode(800, 600)) |
1624 |
|
int apple_id = find_apple_resolution(screen_width, screen_height); |
1625 |
|
if (apple_id != -1) |
1626 |
|
cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN); |
1627 |
+ |
} else if (has_dga && mode_str) |
1628 |
+ |
cur_mode = find_mode(default_mode, APPLE_CUSTOM, DIS_SCREEN); |
1629 |
+ |
|
1630 |
+ |
if (cur_mode == -1) { |
1631 |
+ |
// pick up first windowed mode available |
1632 |
+ |
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
1633 |
+ |
if (p->viType == DIS_WINDOW && p->viAppleMode == default_mode) { |
1634 |
+ |
cur_mode = p - VModes; |
1635 |
+ |
break; |
1636 |
+ |
} |
1637 |
+ |
} |
1638 |
|
} |
1152 |
– |
if (cur_mode == -1) |
1153 |
– |
cur_mode = find_mode(default_mode, APPLE_W_640x480, DIS_WINDOW); |
1639 |
|
assert(cur_mode != -1); |
1640 |
|
|
1641 |
|
#if DEBUG |
1647 |
|
#endif |
1648 |
|
|
1649 |
|
// Open window/screen |
1650 |
< |
if (!open_display()) |
1650 |
> |
if (!open_display()) { |
1651 |
> |
ErrorAlert(GetString(STR_OPEN_WINDOW_ERR)); |
1652 |
|
return false; |
1653 |
+ |
} |
1654 |
|
|
1655 |
|
#if 0 |
1656 |
|
// Ignore errors from now on |
1657 |
|
XSetErrorHandler(ignore_errors); |
1658 |
|
#endif |
1659 |
|
|
1660 |
+ |
// Lock down frame buffer |
1661 |
+ |
XSync(x_display, false); |
1662 |
+ |
LOCK_FRAME_BUFFER; |
1663 |
+ |
|
1664 |
|
// Start periodic thread |
1665 |
|
XSync(x_display, false); |
1666 |
+ |
if (sem_init(&thread_stop_ack, 0, 0) < 0) |
1667 |
+ |
return false; |
1668 |
+ |
if (sem_init(&thread_resume_req, 0, 0) < 0) |
1669 |
+ |
return false; |
1670 |
|
Set_pthread_attr(&redraw_thread_attr, 0); |
1671 |
+ |
redraw_thread_cancel = false; |
1672 |
|
redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0); |
1673 |
|
D(bug("Redraw thread installed (%ld)\n", redraw_thread)); |
1674 |
|
return true; |
1683 |
|
{ |
1684 |
|
// Stop redraw thread |
1685 |
|
if (redraw_thread_active) { |
1686 |
+ |
redraw_thread_cancel = true; |
1687 |
|
pthread_cancel(redraw_thread); |
1688 |
|
pthread_join(redraw_thread, NULL); |
1689 |
+ |
sem_destroy(&thread_stop_ack); |
1690 |
+ |
sem_destroy(&thread_resume_req); |
1691 |
|
redraw_thread_active = false; |
1692 |
|
} |
1693 |
|
|
1694 |
+ |
// Unlock frame buffer |
1695 |
+ |
UNLOCK_FRAME_BUFFER; |
1696 |
+ |
XSync(x_display, false); |
1697 |
+ |
D(bug(" frame buffer unlocked\n")); |
1698 |
+ |
|
1699 |
|
#ifdef ENABLE_VOSF |
1700 |
|
if (use_vosf) { |
1701 |
|
// Deinitialize VOSF |
1710 |
|
XFlush(x_display); |
1711 |
|
XSync(x_display, false); |
1712 |
|
} |
1713 |
+ |
|
1714 |
+ |
#ifdef ENABLE_FBDEV_DGA |
1715 |
+ |
// Close framebuffer device |
1716 |
+ |
if (fb_dev_fd >= 0) { |
1717 |
+ |
close(fb_dev_fd); |
1718 |
+ |
fb_dev_fd = -1; |
1719 |
+ |
} |
1720 |
+ |
#endif |
1721 |
|
} |
1722 |
|
|
1723 |
|
|
1725 |
|
* Suspend/resume emulator |
1726 |
|
*/ |
1727 |
|
|
1216 |
– |
extern void PauseEmulator(void); |
1217 |
– |
extern void ResumeEmulator(void); |
1218 |
– |
|
1728 |
|
static void suspend_emul(void) |
1729 |
|
{ |
1730 |
|
if (display_type == DIS_SCREEN) { |
1732 |
|
ADBKeyUp(0x36); |
1733 |
|
ctrl_down = false; |
1734 |
|
|
1735 |
< |
// Pause MacOS thread |
1736 |
< |
PauseEmulator(); |
1228 |
< |
emul_suspended = true; |
1735 |
> |
// Lock frame buffer (this will stop the MacOS thread) |
1736 |
> |
LOCK_FRAME_BUFFER; |
1737 |
|
|
1738 |
|
// Save frame buffer |
1739 |
|
fb_save = malloc(VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1740 |
|
if (fb_save) |
1741 |
< |
memcpy(fb_save, (void *)screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1741 |
> |
Mac2Host_memcpy(fb_save, screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1742 |
|
|
1743 |
|
// Close full screen display |
1744 |
+ |
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) |
1745 |
|
#ifdef ENABLE_XF86_DGA |
1746 |
< |
XF86DGADirectVideo(x_display, screen, 0); |
1746 |
> |
if (!is_fbdev_dga_mode) |
1747 |
> |
XF86DGADirectVideo(x_display, screen, 0); |
1748 |
> |
#endif |
1749 |
|
XUngrabPointer(x_display, CurrentTime); |
1750 |
|
XUngrabKeyboard(x_display, CurrentTime); |
1751 |
|
#endif |
1752 |
+ |
restore_mouse_accel(); |
1753 |
+ |
XUnmapWindow(x_display, the_win); |
1754 |
+ |
wait_unmapped(the_win); |
1755 |
|
XSync(x_display, false); |
1756 |
|
|
1757 |
|
// Open "suspend" window |
1758 |
|
XSetWindowAttributes wattr; |
1759 |
|
wattr.event_mask = KeyPressMask; |
1760 |
< |
wattr.background_pixel = black_pixel; |
1247 |
< |
wattr.border_pixel = black_pixel; |
1760 |
> |
wattr.background_pixel = (vis == DefaultVisual(x_display, screen) ? black_pixel : 0); |
1761 |
|
wattr.backing_store = Always; |
1762 |
< |
wattr.backing_planes = xdepth; |
1763 |
< |
wattr.colormap = DefaultColormap(x_display, screen); |
1251 |
< |
XSync(x_display, false); |
1762 |
> |
wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); |
1763 |
> |
|
1764 |
|
suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth, |
1765 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | |
1766 |
< |
CWBackingStore | CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr); |
1767 |
< |
XSync(x_display, false); |
1768 |
< |
XStoreName(x_display, suspend_win, GetString(STR_SUSPEND_WINDOW_TITLE)); |
1769 |
< |
XMapRaised(x_display, suspend_win); |
1258 |
< |
XSync(x_display, false); |
1765 |
> |
InputOutput, vis, CWEventMask | CWBackPixel | CWBackingStore | CWColormap, &wattr); |
1766 |
> |
set_window_name(suspend_win, STR_SUSPEND_WINDOW_TITLE); |
1767 |
> |
set_window_focus(suspend_win); |
1768 |
> |
XMapWindow(x_display, suspend_win); |
1769 |
> |
emul_suspended = true; |
1770 |
|
} |
1771 |
|
} |
1772 |
|
|
1777 |
|
XSync(x_display, false); |
1778 |
|
|
1779 |
|
// Reopen full screen display |
1780 |
< |
XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime); |
1781 |
< |
XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
1780 |
> |
XMapRaised(x_display, the_win); |
1781 |
> |
wait_mapped(the_win); |
1782 |
> |
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
1783 |
> |
Window w = is_fbdev_dga_mode ? the_win : rootwin; |
1784 |
> |
XGrabKeyboard(x_display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
1785 |
> |
XGrabPointer(x_display, w, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, is_fbdev_dga_mode ? w : None, None, CurrentTime); |
1786 |
> |
disable_mouse_accel(); |
1787 |
|
#ifdef ENABLE_XF86_DGA |
1788 |
< |
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
1789 |
< |
XF86DGASetViewPort(x_display, screen, 0, 0); |
1788 |
> |
if (!is_fbdev_dga_mode) { |
1789 |
> |
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
1790 |
> |
XF86DGASetViewPort(x_display, screen, 0, 0); |
1791 |
> |
} |
1792 |
|
#endif |
1793 |
|
XSync(x_display, false); |
1794 |
|
|
1799 |
|
if (use_vosf) { |
1800 |
|
LOCK_VOSF; |
1801 |
|
PFLAG_SET_ALL; |
1284 |
– |
UNLOCK_VOSF; |
1802 |
|
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
1803 |
+ |
UNLOCK_VOSF; |
1804 |
|
} |
1805 |
|
#endif |
1806 |
|
|
1810 |
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1811 |
|
if (!use_vosf) |
1812 |
|
#endif |
1813 |
< |
memcpy((void *)screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1813 |
> |
Host2Mac_memcpy(screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1814 |
|
free(fb_save); |
1815 |
|
fb_save = NULL; |
1816 |
|
} |
1299 |
– |
if (depth == 8) |
1300 |
– |
palette_changed = true; |
1817 |
|
|
1818 |
< |
// Resume MacOS thread |
1818 |
> |
// Unlock frame buffer (and continue MacOS thread) |
1819 |
> |
UNLOCK_FRAME_BUFFER; |
1820 |
|
emul_suspended = false; |
1304 |
– |
ResumeEmulator(); |
1821 |
|
} |
1822 |
|
|
1823 |
|
|
1981 |
|
return -1; |
1982 |
|
} |
1983 |
|
|
1984 |
< |
static int event2keycode(XKeyEvent &ev) |
1984 |
> |
static int event2keycode(XKeyEvent &ev, bool key_down) |
1985 |
|
{ |
1986 |
|
KeySym ks; |
1471 |
– |
int as; |
1987 |
|
int i = 0; |
1988 |
|
|
1989 |
|
do { |
1990 |
|
ks = XLookupKeysym(&ev, i++); |
1991 |
< |
as = kc_decode(ks); |
1992 |
< |
if (as != -1) |
1991 |
> |
int as = kc_decode(ks); |
1992 |
> |
if (as >= 0) |
1993 |
> |
return as; |
1994 |
> |
if (as == -2) |
1995 |
|
return as; |
1996 |
|
} while (ks != NoSymbol); |
1997 |
|
|
2066 |
|
|
2067 |
|
// Keyboard |
2068 |
|
case KeyPress: { |
2069 |
< |
int code = event2keycode(event.xkey); |
2070 |
< |
if (use_keycodes && code != -1) |
2071 |
< |
code = keycode_table[event.xkey.keycode & 0xff]; |
2072 |
< |
if (code != -1) { |
2069 |
> |
int code = -1; |
2070 |
> |
if (use_keycodes) { |
2071 |
> |
if (event2keycode(event.xkey, true) != -2) // This is called to process the hotkeys |
2072 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
2073 |
> |
} else |
2074 |
> |
code = event2keycode(event.xkey, true); |
2075 |
> |
if (code >= 0) { |
2076 |
|
if (!emul_suspended) { |
2077 |
< |
ADBKeyDown(code); |
2077 |
> |
if (code == 0x39) { // Caps Lock pressed |
2078 |
> |
if (caps_on) { |
2079 |
> |
ADBKeyUp(code); |
2080 |
> |
caps_on = false; |
2081 |
> |
} else { |
2082 |
> |
ADBKeyDown(code); |
2083 |
> |
caps_on = true; |
2084 |
> |
} |
2085 |
> |
} else |
2086 |
> |
ADBKeyDown(code); |
2087 |
|
if (code == 0x36) |
2088 |
|
ctrl_down = true; |
2089 |
|
} else { |
2094 |
|
break; |
2095 |
|
} |
2096 |
|
case KeyRelease: { |
2097 |
< |
int code = event2keycode(event.xkey); |
2098 |
< |
if (use_keycodes && code != 1) |
2099 |
< |
code = keycode_table[event.xkey.keycode & 0xff]; |
2100 |
< |
if (code != -1) { |
2097 |
> |
int code = -1; |
2098 |
> |
if (use_keycodes) { |
2099 |
> |
if (event2keycode(event.xkey, false) != -2) // This is called to process the hotkeys |
2100 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
2101 |
> |
} else |
2102 |
> |
code = event2keycode(event.xkey, false); |
2103 |
> |
if (code >= 0 && code != 0x39) { // Don't propagate Caps Lock releases |
2104 |
|
ADBKeyUp(code); |
2105 |
|
if (code == 0x36) |
2106 |
|
ctrl_down = false; |
2114 |
|
if (use_vosf) { // VOSF refresh |
2115 |
|
LOCK_VOSF; |
2116 |
|
PFLAG_SET_ALL; |
2117 |
+ |
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
2118 |
|
UNLOCK_VOSF; |
2119 |
|
} |
2120 |
+ |
else |
2121 |
|
#endif |
2122 |
< |
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
2122 |
> |
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
2123 |
|
break; |
2124 |
|
} |
2125 |
|
} |
2135 |
|
if (emerg_quit) |
2136 |
|
QuitEmulator(); |
2137 |
|
|
2138 |
+ |
// Temporarily give up frame buffer lock (this is the point where |
2139 |
+ |
// we are suspended when the user presses Ctrl-Tab) |
2140 |
+ |
UNLOCK_FRAME_BUFFER; |
2141 |
+ |
LOCK_FRAME_BUFFER; |
2142 |
+ |
|
2143 |
|
// Execute video VBL |
2144 |
|
if (private_data != NULL && private_data->interruptsEnabled) |
2145 |
|
VSLDoInterruptService(private_data->vslServiceID); |
2147 |
|
|
2148 |
|
|
2149 |
|
/* |
1611 |
– |
* Install graphics acceleration |
1612 |
– |
*/ |
1613 |
– |
|
1614 |
– |
// Rectangle inversion |
1615 |
– |
template< int bpp > |
1616 |
– |
static inline void do_invrect(uint8 *dest, uint32 length) |
1617 |
– |
{ |
1618 |
– |
#define INVERT_1(PTR, OFS) ((uint8 *)(PTR))[OFS] = ~((uint8 *)(PTR))[OFS] |
1619 |
– |
#define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS] |
1620 |
– |
#define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS] |
1621 |
– |
#define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS] |
1622 |
– |
|
1623 |
– |
#ifndef UNALIGNED_PROFITABLE |
1624 |
– |
// Align on 16-bit boundaries |
1625 |
– |
if (bpp < 16 && (((uintptr)dest) & 1)) { |
1626 |
– |
INVERT_1(dest, 0); |
1627 |
– |
dest += 1; length -= 1; |
1628 |
– |
} |
1629 |
– |
|
1630 |
– |
// Align on 32-bit boundaries |
1631 |
– |
if (bpp < 32 && (((uintptr)dest) & 2)) { |
1632 |
– |
INVERT_2(dest, 0); |
1633 |
– |
dest += 2; length -= 2; |
1634 |
– |
} |
1635 |
– |
#endif |
1636 |
– |
|
1637 |
– |
// Invert 8-byte words |
1638 |
– |
if (length >= 8) { |
1639 |
– |
const int r = (length / 8) % 8; |
1640 |
– |
dest += r * 8; |
1641 |
– |
|
1642 |
– |
int n = ((length / 8) + 7) / 8; |
1643 |
– |
switch (r) { |
1644 |
– |
case 0: do { |
1645 |
– |
dest += 64; |
1646 |
– |
INVERT_8(dest, -8); |
1647 |
– |
case 7: INVERT_8(dest, -7); |
1648 |
– |
case 6: INVERT_8(dest, -6); |
1649 |
– |
case 5: INVERT_8(dest, -5); |
1650 |
– |
case 4: INVERT_8(dest, -4); |
1651 |
– |
case 3: INVERT_8(dest, -3); |
1652 |
– |
case 2: INVERT_8(dest, -2); |
1653 |
– |
case 1: INVERT_8(dest, -1); |
1654 |
– |
} while (--n > 0); |
1655 |
– |
} |
1656 |
– |
} |
1657 |
– |
|
1658 |
– |
// 32-bit cell to invert? |
1659 |
– |
if (length & 4) { |
1660 |
– |
INVERT_4(dest, 0); |
1661 |
– |
if (bpp <= 16) |
1662 |
– |
dest += 4; |
1663 |
– |
} |
1664 |
– |
|
1665 |
– |
// 16-bit cell to invert? |
1666 |
– |
if (bpp <= 16 && (length & 2)) { |
1667 |
– |
INVERT_2(dest, 0); |
1668 |
– |
if (bpp <= 8) |
1669 |
– |
dest += 2; |
1670 |
– |
} |
1671 |
– |
|
1672 |
– |
// 8-bit cell to invert? |
1673 |
– |
if (bpp <= 8 && (length & 1)) |
1674 |
– |
INVERT_1(dest, 0); |
1675 |
– |
|
1676 |
– |
#undef INVERT_1 |
1677 |
– |
#undef INVERT_2 |
1678 |
– |
#undef INVERT_4 |
1679 |
– |
#undef INVERT_8 |
1680 |
– |
} |
1681 |
– |
|
1682 |
– |
void NQD_invrect(uint32 p) |
1683 |
– |
{ |
1684 |
– |
D(bug("accl_invrect %08x\n", p)); |
1685 |
– |
|
1686 |
– |
// Get inversion parameters |
1687 |
– |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1688 |
– |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1689 |
– |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1690 |
– |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1691 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1692 |
– |
D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes))); |
1693 |
– |
|
1694 |
– |
//!!?? pen_mode == 14 |
1695 |
– |
|
1696 |
– |
// And perform the inversion |
1697 |
– |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); |
1698 |
– |
const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1699 |
– |
uint8 *dest = (uint8 *)(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); |
1700 |
– |
width *= bpp; |
1701 |
– |
switch (bpp) { |
1702 |
– |
case 1: |
1703 |
– |
for (int i = 0; i < height; i++) { |
1704 |
– |
do_invrect<8>(dest, width); |
1705 |
– |
dest += dest_row_bytes; |
1706 |
– |
} |
1707 |
– |
break; |
1708 |
– |
case 2: |
1709 |
– |
for (int i = 0; i < height; i++) { |
1710 |
– |
do_invrect<16>(dest, width); |
1711 |
– |
dest += dest_row_bytes; |
1712 |
– |
} |
1713 |
– |
break; |
1714 |
– |
case 4: |
1715 |
– |
for (int i = 0; i < height; i++) { |
1716 |
– |
do_invrect<32>(dest, width); |
1717 |
– |
dest += dest_row_bytes; |
1718 |
– |
} |
1719 |
– |
break; |
1720 |
– |
} |
1721 |
– |
} |
1722 |
– |
|
1723 |
– |
// Rectangle filling |
1724 |
– |
template< int bpp > |
1725 |
– |
static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length) |
1726 |
– |
{ |
1727 |
– |
#define FILL_1(PTR, OFS, VAL) ((uint8 *)(PTR))[OFS] = (VAL) |
1728 |
– |
#define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL) |
1729 |
– |
#define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL) |
1730 |
– |
#define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL) |
1731 |
– |
|
1732 |
– |
#ifndef UNALIGNED_PROFITABLE |
1733 |
– |
// Align on 16-bit boundaries |
1734 |
– |
if (bpp < 16 && (((uintptr)dest) & 1)) { |
1735 |
– |
FILL_1(dest, 0, color); |
1736 |
– |
dest += 1; length -= 1; |
1737 |
– |
} |
1738 |
– |
|
1739 |
– |
// Align on 32-bit boundaries |
1740 |
– |
if (bpp < 32 && (((uintptr)dest) & 2)) { |
1741 |
– |
FILL_2(dest, 0, color); |
1742 |
– |
dest += 2; length -= 2; |
1743 |
– |
} |
1744 |
– |
#endif |
1745 |
– |
|
1746 |
– |
// Fill 8-byte words |
1747 |
– |
if (length >= 8) { |
1748 |
– |
const uint64 c = (((uint64)color) << 32) | color; |
1749 |
– |
const int r = (length / 8) % 8; |
1750 |
– |
dest += r * 8; |
1751 |
– |
|
1752 |
– |
int n = ((length / 8) + 7) / 8; |
1753 |
– |
switch (r) { |
1754 |
– |
case 0: do { |
1755 |
– |
dest += 64; |
1756 |
– |
FILL_8(dest, -8, c); |
1757 |
– |
case 7: FILL_8(dest, -7, c); |
1758 |
– |
case 6: FILL_8(dest, -6, c); |
1759 |
– |
case 5: FILL_8(dest, -5, c); |
1760 |
– |
case 4: FILL_8(dest, -4, c); |
1761 |
– |
case 3: FILL_8(dest, -3, c); |
1762 |
– |
case 2: FILL_8(dest, -2, c); |
1763 |
– |
case 1: FILL_8(dest, -1, c); |
1764 |
– |
} while (--n > 0); |
1765 |
– |
} |
1766 |
– |
} |
1767 |
– |
|
1768 |
– |
// 32-bit cell to fill? |
1769 |
– |
if (length & 4) { |
1770 |
– |
FILL_4(dest, 0, color); |
1771 |
– |
if (bpp <= 16) |
1772 |
– |
dest += 4; |
1773 |
– |
} |
1774 |
– |
|
1775 |
– |
// 16-bit cell to fill? |
1776 |
– |
if (bpp <= 16 && (length & 2)) { |
1777 |
– |
FILL_2(dest, 0, color); |
1778 |
– |
if (bpp <= 8) |
1779 |
– |
dest += 2; |
1780 |
– |
} |
1781 |
– |
|
1782 |
– |
// 8-bit cell to fill? |
1783 |
– |
if (bpp <= 8 && (length & 1)) |
1784 |
– |
FILL_1(dest, 0, color); |
1785 |
– |
|
1786 |
– |
#undef FILL_1 |
1787 |
– |
#undef FILL_2 |
1788 |
– |
#undef FILL_4 |
1789 |
– |
#undef FILL_8 |
1790 |
– |
} |
1791 |
– |
|
1792 |
– |
void NQD_fillrect(uint32 p) |
1793 |
– |
{ |
1794 |
– |
D(bug("accl_fillrect %08x\n", p)); |
1795 |
– |
|
1796 |
– |
// Get filling parameters |
1797 |
– |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1798 |
– |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1799 |
– |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1800 |
– |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1801 |
– |
uint32 color = ReadMacInt32(p + acclPenMode) == 8 ? ReadMacInt32(p + acclForePen) : ReadMacInt32(p + acclBackPen); |
1802 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1803 |
– |
D(bug(" width %d, height %d\n", width, height)); |
1804 |
– |
D(bug(" bytes_per_row %d color %08x\n", (int32)ReadMacInt32(p + acclDestRowBytes), color)); |
1805 |
– |
|
1806 |
– |
// And perform the fill |
1807 |
– |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); |
1808 |
– |
const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1809 |
– |
uint8 *dest = (uint8 *)(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); |
1810 |
– |
width *= bpp; |
1811 |
– |
switch (bpp) { |
1812 |
– |
case 1: |
1813 |
– |
for (int i = 0; i < height; i++) { |
1814 |
– |
memset(dest, color, width); |
1815 |
– |
dest += dest_row_bytes; |
1816 |
– |
} |
1817 |
– |
break; |
1818 |
– |
case 2: |
1819 |
– |
for (int i = 0; i < height; i++) { |
1820 |
– |
do_fillrect<16>(dest, color, width); |
1821 |
– |
dest += dest_row_bytes; |
1822 |
– |
} |
1823 |
– |
break; |
1824 |
– |
case 4: |
1825 |
– |
for (int i = 0; i < height; i++) { |
1826 |
– |
do_fillrect<32>(dest, color, width); |
1827 |
– |
dest += dest_row_bytes; |
1828 |
– |
} |
1829 |
– |
break; |
1830 |
– |
} |
1831 |
– |
} |
1832 |
– |
|
1833 |
– |
bool NQD_fillrect_hook(uint32 p) |
1834 |
– |
{ |
1835 |
– |
D(bug("accl_fillrect_hook %08x\n", p)); |
1836 |
– |
|
1837 |
– |
// Check if we can accelerate this fillrect |
1838 |
– |
if (ReadMacInt32(p + 0x284) != 0 && ReadMacInt32(p + acclDestPixelSize) >= 8) { |
1839 |
– |
const int transfer_mode = ReadMacInt32(p + acclTransferMode); |
1840 |
– |
if (transfer_mode == 8) { |
1841 |
– |
// Fill |
1842 |
– |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_FILLRECT)); |
1843 |
– |
return true; |
1844 |
– |
} |
1845 |
– |
else if (transfer_mode == 10) { |
1846 |
– |
// Invert |
1847 |
– |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_INVRECT)); |
1848 |
– |
return true; |
1849 |
– |
} |
1850 |
– |
} |
1851 |
– |
return false; |
1852 |
– |
} |
1853 |
– |
|
1854 |
– |
// Rectangle blitting |
1855 |
– |
// TODO: optimize for VOSF and target pixmap == screen |
1856 |
– |
void NQD_bitblt(uint32 p) |
1857 |
– |
{ |
1858 |
– |
D(bug("accl_bitblt %08x\n", p)); |
1859 |
– |
|
1860 |
– |
// Get blitting parameters |
1861 |
– |
int16 src_X = (int16)ReadMacInt16(p + acclSrcRect + 2) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 2); |
1862 |
– |
int16 src_Y = (int16)ReadMacInt16(p + acclSrcRect + 0) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 0); |
1863 |
– |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1864 |
– |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1865 |
– |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1866 |
– |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1867 |
– |
D(bug(" src addr %08x, dest addr %08x\n", ReadMacInt32(p + acclSrcBaseAddr), ReadMacInt32(p + acclDestBaseAddr))); |
1868 |
– |
D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y)); |
1869 |
– |
D(bug(" width %d, height %d\n", width, height)); |
1870 |
– |
|
1871 |
– |
// And perform the blit |
1872 |
– |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclSrcPixelSize)); |
1873 |
– |
width *= bpp; |
1874 |
– |
if ((int32)ReadMacInt32(p + acclSrcRowBytes) > 0) { |
1875 |
– |
const int src_row_bytes = (int32)ReadMacInt32(p + acclSrcRowBytes); |
1876 |
– |
const int dst_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1877 |
– |
uint8 *src = (uint8 *)ReadMacInt32(p + acclSrcBaseAddr) + (src_Y * src_row_bytes) + (src_X * bpp); |
1878 |
– |
uint8 *dst = (uint8 *)ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dst_row_bytes) + (dest_X * bpp); |
1879 |
– |
for (int i = 0; i < height; i++) { |
1880 |
– |
memcpy(dst, src, width); |
1881 |
– |
src += src_row_bytes; |
1882 |
– |
dst += dst_row_bytes; |
1883 |
– |
} |
1884 |
– |
} |
1885 |
– |
else { |
1886 |
– |
const int src_row_bytes = -(int32)ReadMacInt32(p + acclSrcRowBytes); |
1887 |
– |
const int dst_row_bytes = -(int32)ReadMacInt32(p + acclDestRowBytes); |
1888 |
– |
uint8 *src = (uint8 *)ReadMacInt32(p + acclSrcBaseAddr) + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp); |
1889 |
– |
uint8 *dst = (uint8 *)ReadMacInt32(p + acclDestBaseAddr) + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp); |
1890 |
– |
for (int i = height - 1; i >= 0; i--) { |
1891 |
– |
memcpy(dst, src, width); |
1892 |
– |
src -= src_row_bytes; |
1893 |
– |
dst -= dst_row_bytes; |
1894 |
– |
} |
1895 |
– |
} |
1896 |
– |
} |
1897 |
– |
|
1898 |
– |
/* |
1899 |
– |
BitBlt transfer modes: |
1900 |
– |
0 : srcCopy |
1901 |
– |
1 : srcOr |
1902 |
– |
2 : srcXor |
1903 |
– |
3 : srcBic |
1904 |
– |
4 : notSrcCopy |
1905 |
– |
5 : notSrcOr |
1906 |
– |
6 : notSrcXor |
1907 |
– |
7 : notSrcBic |
1908 |
– |
32 : blend |
1909 |
– |
33 : addPin |
1910 |
– |
34 : addOver |
1911 |
– |
35 : subPin |
1912 |
– |
36 : transparent |
1913 |
– |
37 : adMax |
1914 |
– |
38 : subOver |
1915 |
– |
39 : adMin |
1916 |
– |
50 : hilite |
1917 |
– |
*/ |
1918 |
– |
|
1919 |
– |
bool NQD_bitblt_hook(uint32 p) |
1920 |
– |
{ |
1921 |
– |
D(bug("accl_draw_hook %08x\n", p)); |
1922 |
– |
|
1923 |
– |
// Check if we can accelerate this bitblt |
1924 |
– |
if (ReadMacInt32(p + 0x018) + ReadMacInt32(p + 0x128) == 0 && |
1925 |
– |
ReadMacInt32(p + 0x130) == 0 && |
1926 |
– |
ReadMacInt32(p + acclSrcPixelSize) >= 8 && |
1927 |
– |
ReadMacInt32(p + acclSrcPixelSize) == ReadMacInt32(p + acclDestPixelSize) && |
1928 |
– |
(ReadMacInt32(p + acclSrcRowBytes) ^ ReadMacInt32(p + acclDestRowBytes)) >= 0 && // same sign? |
1929 |
– |
ReadMacInt32(p + acclTransferMode) == 0 && // srcCopy? |
1930 |
– |
ReadMacInt32(p + 0x15c) > 0) { |
1931 |
– |
|
1932 |
– |
// Yes, set function pointer |
1933 |
– |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_BITBLT)); |
1934 |
– |
return true; |
1935 |
– |
} |
1936 |
– |
return false; |
1937 |
– |
} |
1938 |
– |
|
1939 |
– |
// Wait for graphics operation to finish |
1940 |
– |
bool NQD_sync_hook(uint32 arg) |
1941 |
– |
{ |
1942 |
– |
D(bug("accl_sync_hook %08x\n", arg)); |
1943 |
– |
return true; |
1944 |
– |
} |
1945 |
– |
|
1946 |
– |
void VideoInstallAccel(void) |
1947 |
– |
{ |
1948 |
– |
// Temporary hack until it's fixed for e.g. little-endian & 64-bit platforms |
1949 |
– |
#ifndef __powerpc__ |
1950 |
– |
return; |
1951 |
– |
#endif |
1952 |
– |
|
1953 |
– |
// Install acceleration hooks |
1954 |
– |
if (PrefsFindBool("gfxaccel")) { |
1955 |
– |
D(bug("Video: Installing acceleration hooks\n")); |
1956 |
– |
uint32 base; |
1957 |
– |
|
1958 |
– |
SheepVar bitblt_hook_info(sizeof(accl_hook_info)); |
1959 |
– |
base = bitblt_hook_info.addr(); |
1960 |
– |
WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK)); |
1961 |
– |
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
1962 |
– |
WriteMacInt32(base + 8, ACCL_BITBLT); |
1963 |
– |
NQDMisc(6, bitblt_hook_info.ptr()); |
1964 |
– |
|
1965 |
– |
SheepVar fillrect_hook_info(sizeof(accl_hook_info)); |
1966 |
– |
base = fillrect_hook_info.addr(); |
1967 |
– |
WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK)); |
1968 |
– |
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
1969 |
– |
WriteMacInt32(base + 8, ACCL_FILLRECT); |
1970 |
– |
NQDMisc(6, fillrect_hook_info.ptr()); |
1971 |
– |
} |
1972 |
– |
} |
1973 |
– |
|
1974 |
– |
|
1975 |
– |
/* |
2150 |
|
* Change video mode |
2151 |
|
*/ |
2152 |
|
|
2165 |
|
csSave->savePage = ReadMacInt16(ParamPtr + csPage); |
2166 |
|
|
2167 |
|
// Disable interrupts and pause redraw thread |
1994 |
– |
DisableInterrupt(); |
1995 |
– |
thread_stop_ack = false; |
2168 |
|
thread_stop_req = true; |
2169 |
< |
while (!thread_stop_ack) ; |
2169 |
> |
sem_wait(&thread_stop_ack); |
2170 |
> |
thread_stop_req = false; |
2171 |
> |
DisableInterrupt(); |
2172 |
|
|
2173 |
|
/* close old display */ |
2174 |
|
close_display(); |
2189 |
|
csSave->saveMode=VModes[cur_mode].viAppleMode; |
2190 |
|
|
2191 |
|
// Enable interrupts and resume redraw thread |
2018 |
– |
thread_stop_req = false; |
2192 |
|
EnableInterrupt(); |
2193 |
+ |
sem_post(&thread_resume_req); |
2194 |
|
return noErr; |
2195 |
|
} |
2196 |
|
} |
2236 |
|
// We have to redraw everything because the interpretation of pixel values changed |
2237 |
|
LOCK_VOSF; |
2238 |
|
PFLAG_SET_ALL; |
2239 |
+ |
if (display_type == DIS_SCREEN) |
2240 |
+ |
PFLAG_SET_VERY_DIRTY; |
2241 |
|
UNLOCK_VOSF; |
2066 |
– |
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
2242 |
|
} |
2243 |
|
#endif |
2244 |
|
|
2250 |
|
|
2251 |
|
|
2252 |
|
/* |
2253 |
+ |
* Can we set the MacOS cursor image into the window? |
2254 |
+ |
*/ |
2255 |
+ |
|
2256 |
+ |
bool video_can_change_cursor(void) |
2257 |
+ |
{ |
2258 |
+ |
return hw_mac_cursor_accl && (display_type != DIS_SCREEN); |
2259 |
+ |
} |
2260 |
+ |
|
2261 |
+ |
|
2262 |
+ |
/* |
2263 |
|
* Set cursor image for window |
2264 |
|
*/ |
2265 |
|
|
2420 |
|
} |
2421 |
|
|
2422 |
|
#ifdef ENABLE_XF86_DGA |
2423 |
< |
if (display_type == DIS_SCREEN) { |
2423 |
> |
if (display_type == DIS_SCREEN && !is_fbdev_dga_mode) { |
2424 |
|
current_dga_cmap ^= 1; |
2425 |
|
if (!IsDirectMode(mode) && cmap[current_dga_cmap]) |
2426 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
2439 |
|
int64 ticks = 0; |
2440 |
|
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
2441 |
|
|
2442 |
< |
for (;;) { |
2442 |
> |
while (!redraw_thread_cancel) { |
2443 |
|
|
2444 |
|
// Pause if requested (during video mode switches) |
2445 |
< |
while (thread_stop_req) |
2446 |
< |
thread_stop_ack = true; |
2445 |
> |
if (thread_stop_req) { |
2446 |
> |
sem_post(&thread_stop_ack); |
2447 |
> |
sem_wait(&thread_resume_req); |
2448 |
> |
} |
2449 |
|
|
2450 |
|
int64 delay = next - GetTicks_usec(); |
2451 |
|
if (delay < -VIDEO_REFRESH_DELAY) { |
2467 |
|
quit_full_screen = false; |
2468 |
|
if (display_type == DIS_SCREEN) { |
2469 |
|
XDisplayLock(); |
2470 |
+ |
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) |
2471 |
|
#ifdef ENABLE_XF86_DGA |
2472 |
< |
XF86DGADirectVideo(x_display, screen, 0); |
2472 |
> |
if (!is_fbdev_dga_mode) |
2473 |
> |
XF86DGADirectVideo(x_display, screen, 0); |
2474 |
> |
#endif |
2475 |
|
XUngrabPointer(x_display, CurrentTime); |
2476 |
|
XUngrabKeyboard(x_display, CurrentTime); |
2477 |
|
XUnmapWindow(x_display, the_win); |
2509 |
|
update_display(); |
2510 |
|
|
2511 |
|
// Set new cursor image if it was changed |
2512 |
< |
if (cursor_changed) { |
2512 |
> |
if (hw_mac_cursor_accl && cursor_changed) { |
2513 |
|
cursor_changed = false; |
2514 |
< |
memcpy(cursor_image->data, MacCursor + 4, 32); |
2515 |
< |
memcpy(cursor_mask_image->data, MacCursor + 36, 32); |
2514 |
> |
uint8 *x_data = (uint8 *)cursor_image->data; |
2515 |
> |
uint8 *x_mask = (uint8 *)cursor_mask_image->data; |
2516 |
> |
for (int i = 0; i < 32; i++) { |
2517 |
> |
x_mask[i] = MacCursor[4 + i] | MacCursor[36 + i]; |
2518 |
> |
x_data[i] = MacCursor[4 + i]; |
2519 |
> |
} |
2520 |
|
XDisplayLock(); |
2521 |
|
XFreeCursor(x_display, mac_cursor); |
2522 |
|
XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16); |
2559 |
|
} |
2560 |
|
return NULL; |
2561 |
|
} |
2562 |
+ |
|
2563 |
+ |
|
2564 |
+ |
/* |
2565 |
+ |
* Record dirty area from NQD |
2566 |
+ |
*/ |
2567 |
+ |
|
2568 |
+ |
void video_set_dirty_area(int x, int y, int w, int h) |
2569 |
+ |
{ |
2570 |
+ |
VideoInfo const & mode = VModes[cur_mode]; |
2571 |
+ |
const int screen_width = VIDEO_MODE_X; |
2572 |
+ |
const int screen_height = VIDEO_MODE_Y; |
2573 |
+ |
const int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
2574 |
+ |
|
2575 |
+ |
#ifdef ENABLE_VOSF |
2576 |
+ |
if (use_vosf) { |
2577 |
+ |
vosf_set_dirty_area(x, y, w, h, screen_width, screen_height, bytes_per_row); |
2578 |
+ |
return; |
2579 |
+ |
} |
2580 |
+ |
#endif |
2581 |
+ |
|
2582 |
+ |
// XXX handle dirty bounding boxes for non-VOSF modes |
2583 |
+ |
} |