1 |
|
/* |
2 |
|
* video_x.cpp - Video/graphics emulation, X11 specific stuff |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2004 Marc Hellwig and Christian Bauer |
4 |
> |
* SheepShaver (C) 1997-2005 Marc Hellwig and Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
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> |
38 |
|
#include <errno.h> |
39 |
|
#include <pthread.h> |
40 |
|
|
41 |
+ |
#include <algorithm> |
42 |
+ |
|
43 |
+ |
#ifdef ENABLE_FBDEV_DGA |
44 |
+ |
# include <linux/fb.h> |
45 |
+ |
# include <sys/ioctl.h> |
46 |
+ |
#endif |
47 |
+ |
|
48 |
|
#ifdef ENABLE_XF86_DGA |
49 |
< |
#include <X11/extensions/xf86dga.h> |
49 |
> |
# include <X11/extensions/xf86dga.h> |
50 |
|
#endif |
51 |
|
|
52 |
|
#ifdef ENABLE_XF86_VIDMODE |
60 |
|
#include "about_window.h" |
61 |
|
#include "video.h" |
62 |
|
#include "video_defs.h" |
63 |
+ |
#include "video_blit.h" |
64 |
|
|
65 |
|
#define DEBUG 0 |
66 |
|
#include "debug.h" |
67 |
|
|
68 |
+ |
#ifndef NO_STD_NAMESPACE |
69 |
+ |
using std::sort; |
70 |
+ |
#endif |
71 |
+ |
|
72 |
|
|
73 |
|
// Constants |
74 |
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; |
75 |
+ |
static const bool hw_mac_cursor_accl = true; // Flag: Enable MacOS to X11 copy of cursor? |
76 |
|
|
77 |
|
// Global variables |
78 |
|
static int32 frame_skip; |
79 |
|
static int16 mouse_wheel_mode; |
80 |
|
static int16 mouse_wheel_lines; |
81 |
|
static bool redraw_thread_active = false; // Flag: Redraw thread installed |
82 |
+ |
static pthread_attr_t redraw_thread_attr; // Redraw thread attributes |
83 |
+ |
static volatile bool redraw_thread_cancel; // Flag: Cancel Redraw thread |
84 |
|
static pthread_t redraw_thread; // Redraw thread |
85 |
|
|
86 |
|
static bool local_X11; // Flag: X server running on local machine? |
98 |
|
|
99 |
|
static bool palette_changed = false; // Flag: Palette changed, redraw thread must update palette |
100 |
|
static bool ctrl_down = false; // Flag: Ctrl key pressed |
101 |
+ |
static bool caps_on = false; // Flag: Caps Lock on |
102 |
|
static bool quit_full_screen = false; // Flag: DGA close requested from redraw thread |
103 |
|
static volatile bool quit_full_screen_ack = false; // Acknowledge for quit_full_screen |
104 |
|
static bool emerg_quit = false; // Flag: Ctrl-Esc pressed, emergency quit requested from MacOS thread |
114 |
|
static int xdepth; // Depth of X screen |
115 |
|
static int depth; // Depth of Mac frame buffer |
116 |
|
static Window rootwin, the_win; // Root window and our window |
117 |
+ |
static int num_depths = 0; // Number of available X depths |
118 |
+ |
static int *avail_depths = NULL; // List of available X depths |
119 |
+ |
static VisualFormat visualFormat; |
120 |
|
static XVisualInfo visualInfo; |
121 |
|
static Visual *vis; |
122 |
+ |
static int color_class; |
123 |
+ |
static int rshift, rloss, gshift, gloss, bshift, bloss; // Pixel format of DirectColor/TrueColor modes |
124 |
|
static Colormap cmap[2]; // Two colormaps (DGA) for 8-bit mode |
125 |
+ |
static XColor x_palette[256]; // Color palette to be used as CLUT and gamma table |
126 |
+ |
static int orig_accel_numer, orig_accel_denom, orig_threshold; // Original mouse acceleration |
127 |
+ |
|
128 |
|
static XColor black, white; |
129 |
|
static unsigned long black_pixel, white_pixel; |
130 |
|
static int eventmask; |
131 |
< |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask; |
132 |
< |
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; |
131 |
> |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask | StructureNotifyMask; |
132 |
> |
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask; |
133 |
|
|
134 |
|
// Variables for window mode |
135 |
|
static GC the_gc; |
146 |
|
static uint32 the_buffer_size; // Size of allocated the_buffer |
147 |
|
|
148 |
|
// Variables for DGA mode |
149 |
< |
static char *dga_screen_base; |
117 |
< |
static int dga_fb_width; |
149 |
> |
static bool is_fbdev_dga_mode = false; // Flag: Use FBDev DGA mode? |
150 |
|
static int current_dga_cmap; |
151 |
|
|
152 |
+ |
#ifdef ENABLE_FBDEV_DGA |
153 |
+ |
static int fb_dev_fd = -1; // Handle to fb device name |
154 |
+ |
static struct fb_fix_screeninfo fb_finfo; // Fixed info |
155 |
+ |
static struct fb_var_screeninfo fb_vinfo; // Variable info |
156 |
+ |
static struct fb_var_screeninfo fb_orig_vinfo; // Variable info to restore later |
157 |
+ |
static struct fb_cmap fb_oldcmap; // Colormap to restore later |
158 |
+ |
#endif |
159 |
+ |
|
160 |
|
#ifdef ENABLE_XF86_VIDMODE |
161 |
|
// Variables for XF86 VidMode support |
162 |
|
static XF86VidModeModeInfo **x_video_modes; // Array of all available modes |
163 |
|
static int num_x_video_modes; |
164 |
|
#endif |
165 |
|
|
166 |
+ |
// Mutex to protect palette |
167 |
+ |
#ifdef HAVE_SPINLOCKS |
168 |
+ |
static spinlock_t x_palette_lock = SPIN_LOCK_UNLOCKED; |
169 |
+ |
#define LOCK_PALETTE spin_lock(&x_palette_lock) |
170 |
+ |
#define UNLOCK_PALETTE spin_unlock(&x_palette_lock) |
171 |
+ |
#elif defined(HAVE_PTHREADS) |
172 |
+ |
static pthread_mutex_t x_palette_lock = PTHREAD_MUTEX_INITIALIZER; |
173 |
+ |
#define LOCK_PALETTE pthread_mutex_lock(&x_palette_lock) |
174 |
+ |
#define UNLOCK_PALETTE pthread_mutex_unlock(&x_palette_lock) |
175 |
+ |
#else |
176 |
+ |
#define LOCK_PALETTE |
177 |
+ |
#define UNLOCK_PALETTE |
178 |
+ |
#endif |
179 |
+ |
|
180 |
+ |
// Mutex to protect frame buffer |
181 |
+ |
#ifdef HAVE_SPINLOCKS |
182 |
+ |
static spinlock_t frame_buffer_lock = SPIN_LOCK_UNLOCKED; |
183 |
+ |
#define LOCK_FRAME_BUFFER spin_lock(&frame_buffer_lock) |
184 |
+ |
#define UNLOCK_FRAME_BUFFER spin_unlock(&frame_buffer_lock) |
185 |
+ |
#elif defined(HAVE_PTHREADS) |
186 |
+ |
static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER; |
187 |
+ |
#define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock); |
188 |
+ |
#define UNLOCK_FRAME_BUFFER pthread_mutex_unlock(&frame_buffer_lock); |
189 |
+ |
#else |
190 |
+ |
#define LOCK_FRAME_BUFFER |
191 |
+ |
#define UNLOCK_FRAME_BUFFER |
192 |
+ |
#endif |
193 |
+ |
|
194 |
|
|
195 |
|
// Prototypes |
196 |
|
static void *redraw_func(void *arg); |
215 |
|
|
216 |
|
|
217 |
|
/* |
218 |
+ |
* Utility functions |
219 |
+ |
*/ |
220 |
+ |
|
221 |
+ |
// Get current video mode |
222 |
+ |
static inline int get_current_mode(void) |
223 |
+ |
{ |
224 |
+ |
return VModes[cur_mode].viAppleMode; |
225 |
+ |
} |
226 |
+ |
|
227 |
+ |
// Find palette size for given color depth |
228 |
+ |
static int palette_size(int mode) |
229 |
+ |
{ |
230 |
+ |
switch (mode) { |
231 |
+ |
case APPLE_1_BIT: return 2; |
232 |
+ |
case APPLE_2_BIT: return 4; |
233 |
+ |
case APPLE_4_BIT: return 16; |
234 |
+ |
case APPLE_8_BIT: return 256; |
235 |
+ |
case APPLE_16_BIT: return 32; |
236 |
+ |
case APPLE_32_BIT: return 256; |
237 |
+ |
default: return 0; |
238 |
+ |
} |
239 |
+ |
} |
240 |
+ |
|
241 |
+ |
// Return bits per pixel for requested depth |
242 |
+ |
static inline int bytes_per_pixel(int depth) |
243 |
+ |
{ |
244 |
+ |
int bpp; |
245 |
+ |
switch (depth) { |
246 |
+ |
case 8: |
247 |
+ |
bpp = 1; |
248 |
+ |
break; |
249 |
+ |
case 15: case 16: |
250 |
+ |
bpp = 2; |
251 |
+ |
break; |
252 |
+ |
case 24: case 32: |
253 |
+ |
bpp = 4; |
254 |
+ |
break; |
255 |
+ |
default: |
256 |
+ |
abort(); |
257 |
+ |
} |
258 |
+ |
return bpp; |
259 |
+ |
} |
260 |
+ |
|
261 |
+ |
// Map video_mode depth ID to numerical depth value |
262 |
+ |
static inline int depth_of_video_mode(int mode) |
263 |
+ |
{ |
264 |
+ |
int depth; |
265 |
+ |
switch (mode) { |
266 |
+ |
case APPLE_1_BIT: |
267 |
+ |
depth = 1; |
268 |
+ |
break; |
269 |
+ |
case APPLE_2_BIT: |
270 |
+ |
depth = 2; |
271 |
+ |
break; |
272 |
+ |
case APPLE_4_BIT: |
273 |
+ |
depth = 4; |
274 |
+ |
break; |
275 |
+ |
case APPLE_8_BIT: |
276 |
+ |
depth = 8; |
277 |
+ |
break; |
278 |
+ |
case APPLE_16_BIT: |
279 |
+ |
depth = 16; |
280 |
+ |
break; |
281 |
+ |
case APPLE_32_BIT: |
282 |
+ |
depth = 32; |
283 |
+ |
break; |
284 |
+ |
default: |
285 |
+ |
abort(); |
286 |
+ |
} |
287 |
+ |
return depth; |
288 |
+ |
} |
289 |
+ |
|
290 |
+ |
// Map RGB color to pixel value (this only works in TrueColor/DirectColor visuals) |
291 |
+ |
static inline uint32 map_rgb(uint8 red, uint8 green, uint8 blue) |
292 |
+ |
{ |
293 |
+ |
return ((red >> rloss) << rshift) | ((green >> gloss) << gshift) | ((blue >> bloss) << bshift); |
294 |
+ |
} |
295 |
+ |
|
296 |
+ |
|
297 |
+ |
// Do we have a visual for handling the specified Mac depth? If so, set the |
298 |
+ |
// global variables "xdepth", "visualInfo", "vis" and "color_class". |
299 |
+ |
static bool find_visual_for_depth(int depth) |
300 |
+ |
{ |
301 |
+ |
D(bug("have_visual_for_depth(%d)\n", depth_of_video_mode(depth))); |
302 |
+ |
|
303 |
+ |
// 1-bit works always and uses default visual |
304 |
+ |
if (depth == APPLE_1_BIT) { |
305 |
+ |
vis = DefaultVisual(x_display, screen); |
306 |
+ |
visualInfo.visualid = XVisualIDFromVisual(vis); |
307 |
+ |
int num = 0; |
308 |
+ |
XVisualInfo *vi = XGetVisualInfo(x_display, VisualIDMask, &visualInfo, &num); |
309 |
+ |
visualInfo = vi[0]; |
310 |
+ |
XFree(vi); |
311 |
+ |
xdepth = visualInfo.depth; |
312 |
+ |
color_class = visualInfo.c_class; |
313 |
+ |
D(bug(" found visual ID 0x%02x, depth %d\n", visualInfo.visualid, xdepth)); |
314 |
+ |
return true; |
315 |
+ |
} |
316 |
+ |
|
317 |
+ |
// Calculate minimum and maximum supported X depth |
318 |
+ |
int min_depth = 1, max_depth = 32; |
319 |
+ |
switch (depth) { |
320 |
+ |
#ifdef ENABLE_VOSF |
321 |
+ |
case APPLE_2_BIT: |
322 |
+ |
case APPLE_4_BIT: // VOSF blitters can convert 2/4/8-bit -> 8/16/32-bit |
323 |
+ |
case APPLE_8_BIT: |
324 |
+ |
min_depth = 8; |
325 |
+ |
max_depth = 32; |
326 |
+ |
break; |
327 |
+ |
#else |
328 |
+ |
case APPLE_2_BIT: |
329 |
+ |
case APPLE_4_BIT: // 2/4-bit requires VOSF blitters |
330 |
+ |
return false; |
331 |
+ |
case APPLE_8_BIT: // 8-bit without VOSF requires an 8-bit visual |
332 |
+ |
min_depth = 8; |
333 |
+ |
max_depth = 8; |
334 |
+ |
break; |
335 |
+ |
#endif |
336 |
+ |
case APPLE_16_BIT: // 16-bit requires a 15/16-bit visual |
337 |
+ |
min_depth = 15; |
338 |
+ |
max_depth = 16; |
339 |
+ |
break; |
340 |
+ |
case APPLE_32_BIT: // 32-bit requires a 24/32-bit visual |
341 |
+ |
min_depth = 24; |
342 |
+ |
max_depth = 32; |
343 |
+ |
break; |
344 |
+ |
} |
345 |
+ |
D(bug(" minimum required X depth is %d, maximum supported X depth is %d\n", min_depth, max_depth)); |
346 |
+ |
|
347 |
+ |
// Try to find a visual for one of the color depths |
348 |
+ |
bool visual_found = false; |
349 |
+ |
for (int i=0; i<num_depths && !visual_found; i++) { |
350 |
+ |
|
351 |
+ |
xdepth = avail_depths[i]; |
352 |
+ |
D(bug(" trying to find visual for depth %d\n", xdepth)); |
353 |
+ |
if (xdepth < min_depth || xdepth > max_depth) |
354 |
+ |
continue; |
355 |
+ |
|
356 |
+ |
// Determine best color class for this depth |
357 |
+ |
switch (xdepth) { |
358 |
+ |
case 1: // Try StaticGray or StaticColor |
359 |
+ |
if (XMatchVisualInfo(x_display, screen, xdepth, StaticGray, &visualInfo) |
360 |
+ |
|| XMatchVisualInfo(x_display, screen, xdepth, StaticColor, &visualInfo)) |
361 |
+ |
visual_found = true; |
362 |
+ |
break; |
363 |
+ |
case 8: // Need PseudoColor |
364 |
+ |
if (XMatchVisualInfo(x_display, screen, xdepth, PseudoColor, &visualInfo)) |
365 |
+ |
visual_found = true; |
366 |
+ |
break; |
367 |
+ |
case 15: |
368 |
+ |
case 16: |
369 |
+ |
case 24: |
370 |
+ |
case 32: // Try DirectColor first, as this will allow gamma correction |
371 |
+ |
if (XMatchVisualInfo(x_display, screen, xdepth, DirectColor, &visualInfo) |
372 |
+ |
|| XMatchVisualInfo(x_display, screen, xdepth, TrueColor, &visualInfo)) |
373 |
+ |
visual_found = true; |
374 |
+ |
break; |
375 |
+ |
default: |
376 |
+ |
D(bug(" not a supported depth\n")); |
377 |
+ |
break; |
378 |
+ |
} |
379 |
+ |
} |
380 |
+ |
if (!visual_found) |
381 |
+ |
return false; |
382 |
+ |
|
383 |
+ |
// Visual was found |
384 |
+ |
vis = visualInfo.visual; |
385 |
+ |
color_class = visualInfo.c_class; |
386 |
+ |
D(bug(" found visual ID 0x%02x, depth %d, class ", visualInfo.visualid, xdepth)); |
387 |
+ |
#if DEBUG |
388 |
+ |
switch (color_class) { |
389 |
+ |
case StaticGray: D(bug("StaticGray\n")); break; |
390 |
+ |
case GrayScale: D(bug("GrayScale\n")); break; |
391 |
+ |
case StaticColor: D(bug("StaticColor\n")); break; |
392 |
+ |
case PseudoColor: D(bug("PseudoColor\n")); break; |
393 |
+ |
case TrueColor: D(bug("TrueColor\n")); break; |
394 |
+ |
case DirectColor: D(bug("DirectColor\n")); break; |
395 |
+ |
} |
396 |
+ |
#endif |
397 |
+ |
return true; |
398 |
+ |
} |
399 |
+ |
|
400 |
+ |
|
401 |
+ |
/* |
402 |
|
* Open display (window or fullscreen) |
403 |
|
*/ |
404 |
|
|
405 |
+ |
// Set window name and class |
406 |
+ |
static void set_window_name(Window w, int name) |
407 |
+ |
{ |
408 |
+ |
const char *str = GetString(name); |
409 |
+ |
XStoreName(x_display, w, str); |
410 |
+ |
XSetIconName(x_display, w, str); |
411 |
+ |
|
412 |
+ |
XClassHint *hints; |
413 |
+ |
hints = XAllocClassHint(); |
414 |
+ |
if (hints) { |
415 |
+ |
hints->res_name = "SheepShaver"; |
416 |
+ |
hints->res_class = "SheepShaver"; |
417 |
+ |
XSetClassHint(x_display, w, hints); |
418 |
+ |
XFree(hints); |
419 |
+ |
} |
420 |
+ |
} |
421 |
+ |
|
422 |
+ |
// Set window input focus flag |
423 |
+ |
static void set_window_focus(Window w) |
424 |
+ |
{ |
425 |
+ |
XWMHints *hints = XAllocWMHints(); |
426 |
+ |
if (hints) { |
427 |
+ |
hints->input = True; |
428 |
+ |
hints->initial_state = NormalState; |
429 |
+ |
hints->flags = InputHint | StateHint; |
430 |
+ |
XSetWMHints(x_display, w, hints); |
431 |
+ |
XFree(hints); |
432 |
+ |
} |
433 |
+ |
} |
434 |
+ |
|
435 |
+ |
// Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget) |
436 |
+ |
static Atom WM_DELETE_WINDOW = (Atom)0; |
437 |
+ |
static void set_window_delete_protocol(Window w) |
438 |
+ |
{ |
439 |
+ |
WM_DELETE_WINDOW = XInternAtom(x_display, "WM_DELETE_WINDOW", false); |
440 |
+ |
XSetWMProtocols(x_display, w, &WM_DELETE_WINDOW, 1); |
441 |
+ |
} |
442 |
+ |
|
443 |
+ |
// Wait until window is mapped/unmapped |
444 |
+ |
static void wait_mapped(Window w) |
445 |
+ |
{ |
446 |
+ |
XEvent e; |
447 |
+ |
do { |
448 |
+ |
XMaskEvent(x_display, StructureNotifyMask, &e); |
449 |
+ |
} while ((e.type != MapNotify) || (e.xmap.event != w)); |
450 |
+ |
} |
451 |
+ |
|
452 |
+ |
static void wait_unmapped(Window w) |
453 |
+ |
{ |
454 |
+ |
XEvent e; |
455 |
+ |
do { |
456 |
+ |
XMaskEvent(x_display, StructureNotifyMask, &e); |
457 |
+ |
} while ((e.type != UnmapNotify) || (e.xmap.event != w)); |
458 |
+ |
} |
459 |
+ |
|
460 |
+ |
// Disable mouse acceleration |
461 |
+ |
static void disable_mouse_accel(void) |
462 |
+ |
{ |
463 |
+ |
XChangePointerControl(x_display, True, False, 1, 1, 0); |
464 |
+ |
} |
465 |
+ |
|
466 |
+ |
// Restore mouse acceleration to original value |
467 |
+ |
static void restore_mouse_accel(void) |
468 |
+ |
{ |
469 |
+ |
XChangePointerControl(x_display, True, True, orig_accel_numer, orig_accel_denom, orig_threshold); |
470 |
+ |
} |
471 |
+ |
|
472 |
|
// Trap SHM errors |
473 |
|
static bool shm_error = false; |
474 |
|
static int (*old_error_handler)(Display *, XErrorEvent *); |
494 |
|
// Create window |
495 |
|
XSetWindowAttributes wattr; |
496 |
|
wattr.event_mask = eventmask = win_eventmask; |
497 |
< |
wattr.background_pixel = black_pixel; |
498 |
< |
wattr.border_pixel = black_pixel; |
497 |
> |
wattr.background_pixel = (vis == DefaultVisual(x_display, screen) ? black_pixel : 0); |
498 |
> |
wattr.border_pixel = 0; |
499 |
|
wattr.backing_store = NotUseful; |
500 |
< |
|
182 |
< |
XSync(x_display, false); |
500 |
> |
wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); |
501 |
|
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
502 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | CWBackingStore, &wattr); |
185 |
< |
XSync(x_display, false); |
186 |
< |
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); |
187 |
< |
XMapRaised(x_display, the_win); |
188 |
< |
XSync(x_display, false); |
502 |
> |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | CWBackingStore | CWColormap, &wattr); |
503 |
|
|
504 |
< |
// Set colormap |
505 |
< |
if (depth == 8) { |
506 |
< |
XSetWindowColormap(x_display, the_win, cmap[0]); |
507 |
< |
XSetWMColormapWindows(x_display, the_win, &the_win, 1); |
508 |
< |
} |
504 |
> |
// Set window name/class |
505 |
> |
set_window_name(the_win, STR_WINDOW_TITLE); |
506 |
> |
|
507 |
> |
// Indicate that we want keyboard input |
508 |
> |
set_window_focus(the_win); |
509 |
> |
|
510 |
> |
// Set delete protocol property |
511 |
> |
set_window_delete_protocol(the_win); |
512 |
|
|
513 |
|
// Make window unresizable |
514 |
|
XSizeHints *hints; |
522 |
|
XFree((char *)hints); |
523 |
|
} |
524 |
|
|
525 |
+ |
// Show window |
526 |
+ |
XMapWindow(x_display, the_win); |
527 |
+ |
wait_mapped(the_win); |
528 |
+ |
|
529 |
|
// 1-bit mode is big-endian; if the X server is little-endian, we can't |
530 |
|
// use SHM because that doesn't allow changing the image byte order |
531 |
|
bool need_msb_image = (depth == 1 && XImageByteOrder(x_display) == LSBFirst); |
536 |
|
|
537 |
|
// Create SHM image ("height + 2" for safety) |
538 |
|
img = XShmCreateImage(x_display, vis, depth == 1 ? 1 : xdepth, depth == 1 ? XYBitmap : ZPixmap, 0, &shminfo, width, height); |
539 |
< |
shminfo.shmid = shmget(IPC_PRIVATE, (height + 2) * img->bytes_per_line, IPC_CREAT | 0777); |
539 |
> |
shminfo.shmid = shmget(IPC_PRIVATE, (aligned_height + 2) * img->bytes_per_line, IPC_CREAT | 0777); |
540 |
> |
D(bug(" shm image created\n")); |
541 |
|
the_buffer_copy = (uint8 *)shmat(shminfo.shmid, 0, 0); |
542 |
|
shminfo.shmaddr = img->data = (char *)the_buffer_copy; |
543 |
|
shminfo.readOnly = False; |
556 |
|
have_shm = true; |
557 |
|
shmctl(shminfo.shmid, IPC_RMID, 0); |
558 |
|
} |
559 |
+ |
D(bug(" shm image attached\n")); |
560 |
|
} |
561 |
|
|
562 |
|
// Create normal X image if SHM doesn't work ("height + 2" for safety) |
563 |
|
if (!have_shm) { |
564 |
< |
int bytes_per_row = aligned_width; |
242 |
< |
switch (depth) { |
243 |
< |
case 1: |
244 |
< |
bytes_per_row /= 8; |
245 |
< |
break; |
246 |
< |
case 15: |
247 |
< |
case 16: |
248 |
< |
bytes_per_row *= 2; |
249 |
< |
break; |
250 |
< |
case 24: |
251 |
< |
case 32: |
252 |
< |
bytes_per_row *= 4; |
253 |
< |
break; |
254 |
< |
} |
564 |
> |
int bytes_per_row = depth == 1 ? aligned_width/8 : TrivialBytesPerRow(aligned_width, DepthModeForPixelDepth(xdepth)); |
565 |
|
the_buffer_copy = (uint8 *)malloc((aligned_height + 2) * bytes_per_row); |
566 |
|
img = XCreateImage(x_display, vis, depth == 1 ? 1 : xdepth, depth == 1 ? XYBitmap : ZPixmap, 0, (char *)the_buffer_copy, aligned_width, aligned_height, 32, bytes_per_row); |
567 |
+ |
D(bug(" X image created\n")); |
568 |
|
} |
569 |
|
|
570 |
|
// 1-Bit mode is big-endian |
571 |
< |
if (depth == 1) { |
571 |
> |
if (need_msb_image) { |
572 |
|
img->byte_order = MSBFirst; |
573 |
|
img->bitmap_bit_order = MSBFirst; |
574 |
|
} |
586 |
|
the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line); |
587 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); |
588 |
|
#endif |
589 |
< |
screen_base = (uint32)the_buffer; |
589 |
> |
screen_base = Host2MacAddr(the_buffer); |
590 |
|
|
591 |
|
// Create GC |
592 |
|
the_gc = XCreateGC(x_display, the_win, 0, 0); |
593 |
< |
XSetForeground(x_display, the_gc, black_pixel); |
593 |
> |
XSetState(x_display, the_gc, black_pixel, white_pixel, GXcopy, AllPlanes); |
594 |
|
|
595 |
|
// Create cursor |
596 |
< |
cursor_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 4, 16, 16, 16, 2); |
597 |
< |
cursor_image->byte_order = MSBFirst; |
598 |
< |
cursor_image->bitmap_bit_order = MSBFirst; |
599 |
< |
cursor_mask_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 36, 16, 16, 16, 2); |
600 |
< |
cursor_mask_image->byte_order = MSBFirst; |
601 |
< |
cursor_mask_image->bitmap_bit_order = MSBFirst; |
602 |
< |
cursor_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
603 |
< |
cursor_mask_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
604 |
< |
cursor_gc = XCreateGC(x_display, cursor_map, 0, 0); |
605 |
< |
cursor_mask_gc = XCreateGC(x_display, cursor_mask_map, 0, 0); |
606 |
< |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, 0, 0); |
607 |
< |
cursor_changed = false; |
596 |
> |
if (hw_mac_cursor_accl) { |
597 |
> |
cursor_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 4, 16, 16, 16, 2); |
598 |
> |
cursor_image->byte_order = MSBFirst; |
599 |
> |
cursor_image->bitmap_bit_order = MSBFirst; |
600 |
> |
cursor_mask_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 36, 16, 16, 16, 2); |
601 |
> |
cursor_mask_image->byte_order = MSBFirst; |
602 |
> |
cursor_mask_image->bitmap_bit_order = MSBFirst; |
603 |
> |
cursor_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
604 |
> |
cursor_mask_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
605 |
> |
cursor_gc = XCreateGC(x_display, cursor_map, 0, 0); |
606 |
> |
cursor_mask_gc = XCreateGC(x_display, cursor_mask_map, 0, 0); |
607 |
> |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, 0, 0); |
608 |
> |
cursor_changed = false; |
609 |
> |
} |
610 |
> |
|
611 |
> |
// Create no_cursor |
612 |
> |
else { |
613 |
> |
mac_cursor = XCreatePixmapCursor(x_display, |
614 |
> |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
615 |
> |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
616 |
> |
&black, &white, 0, 0); |
617 |
> |
XDefineCursor(x_display, the_win, mac_cursor); |
618 |
> |
} |
619 |
|
|
620 |
|
// Init blitting routines |
621 |
|
bool native_byte_order; |
625 |
|
native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
626 |
|
#endif |
627 |
|
#ifdef ENABLE_VOSF |
628 |
< |
Screen_blitter_init(&visualInfo, native_byte_order, depth); |
628 |
> |
Screen_blitter_init(visualFormat, native_byte_order, depth); |
629 |
|
#endif |
630 |
|
|
631 |
|
// Set bytes per row |
310 |
– |
VModes[cur_mode].viRowBytes = img->bytes_per_line; |
632 |
|
XSync(x_display, false); |
633 |
|
return true; |
634 |
|
} |
635 |
|
|
636 |
+ |
// Open FBDev display |
637 |
+ |
static bool open_fbdev(int width, int height) |
638 |
+ |
{ |
639 |
+ |
#ifdef ENABLE_FBDEV_DGA |
640 |
+ |
if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo) != 0) { |
641 |
+ |
D(bug("[fbdev] Can't get FSCREENINFO: %s\n", strerror(errno))); |
642 |
+ |
return false; |
643 |
+ |
} |
644 |
+ |
D(bug("[fbdev] Device ID: %s\n", fb_finfo.id)); |
645 |
+ |
D(bug("[fbdev] smem_start: %p [%d bytes]\n", fb_finfo.smem_start, fb_finfo.smem_len)); |
646 |
+ |
int fb_type = fb_finfo.type; |
647 |
+ |
const char *fb_type_str = NULL; |
648 |
+ |
switch (fb_type) { |
649 |
+ |
case FB_TYPE_PACKED_PIXELS: fb_type_str = "Packed Pixels"; break; |
650 |
+ |
case FB_TYPE_PLANES: fb_type_str = "Non interleaved planes"; break; |
651 |
+ |
case FB_TYPE_INTERLEAVED_PLANES: fb_type_str = "Interleaved planes"; break; |
652 |
+ |
case FB_TYPE_TEXT: fb_type_str = "Text/attributes"; break; |
653 |
+ |
case FB_TYPE_VGA_PLANES: fb_type_str = "EGA/VGA planes"; break; |
654 |
+ |
default: fb_type_str = "<unknown>"; break; |
655 |
+ |
} |
656 |
+ |
D(bug("[fbdev] type: %s\n", fb_type_str)); |
657 |
+ |
int fb_visual = fb_finfo.visual; |
658 |
+ |
const char *fb_visual_str; |
659 |
+ |
switch (fb_visual) { |
660 |
+ |
case FB_VISUAL_MONO01: fb_visual_str = "Monochrome 1=Black 0=White"; break; |
661 |
+ |
case FB_VISUAL_MONO10: fb_visual_str = "Monochrome 1=While 0=Black"; break; |
662 |
+ |
case FB_VISUAL_TRUECOLOR: fb_visual_str = "True color"; break; |
663 |
+ |
case FB_VISUAL_PSEUDOCOLOR: fb_visual_str = "Pseudo color (like atari)"; break; |
664 |
+ |
case FB_VISUAL_DIRECTCOLOR: fb_visual_str = "Direct color"; break; |
665 |
+ |
case FB_VISUAL_STATIC_PSEUDOCOLOR: fb_visual_str = "Pseudo color readonly"; break; |
666 |
+ |
default: fb_visual_str = "<unknown>"; break; |
667 |
+ |
} |
668 |
+ |
D(bug("[fbdev] visual: %s\n", fb_visual_str)); |
669 |
+ |
|
670 |
+ |
if (fb_type != FB_TYPE_PACKED_PIXELS) { |
671 |
+ |
D(bug("[fbdev] type %s not supported\n", fb_type_str)); |
672 |
+ |
return false; |
673 |
+ |
} |
674 |
+ |
|
675 |
+ |
// Map frame buffer |
676 |
+ |
the_buffer = (uint8 *)mmap(NULL, fb_finfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb_dev_fd, 0); |
677 |
+ |
if (the_buffer == MAP_FAILED) { |
678 |
+ |
D(bug("[fbdev] Can't mmap /dev/fb0: %s\n", strerror(errno))); |
679 |
+ |
return false; |
680 |
+ |
} |
681 |
+ |
|
682 |
+ |
// Set absolute mouse mode |
683 |
+ |
ADBSetRelMouseMode(false); |
684 |
+ |
|
685 |
+ |
// Create window |
686 |
+ |
XSetWindowAttributes wattr; |
687 |
+ |
wattr.event_mask = eventmask = dga_eventmask; |
688 |
+ |
wattr.override_redirect = True; |
689 |
+ |
wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); |
690 |
+ |
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
691 |
+ |
InputOutput, vis, CWEventMask | CWOverrideRedirect | |
692 |
+ |
(color_class == DirectColor ? CWColormap : 0), &wattr); |
693 |
+ |
|
694 |
+ |
// Show window |
695 |
+ |
XMapRaised(x_display, the_win); |
696 |
+ |
wait_mapped(the_win); |
697 |
+ |
|
698 |
+ |
// Grab mouse and keyboard |
699 |
+ |
XGrabKeyboard(x_display, the_win, True, |
700 |
+ |
GrabModeAsync, GrabModeAsync, CurrentTime); |
701 |
+ |
XGrabPointer(x_display, the_win, True, |
702 |
+ |
PointerMotionMask | ButtonPressMask | ButtonReleaseMask, |
703 |
+ |
GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
704 |
+ |
disable_mouse_accel(); |
705 |
+ |
|
706 |
+ |
// Create no_cursor |
707 |
+ |
mac_cursor = XCreatePixmapCursor(x_display, |
708 |
+ |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
709 |
+ |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
710 |
+ |
&black, &white, 0, 0); |
711 |
+ |
XDefineCursor(x_display, the_win, mac_cursor); |
712 |
+ |
|
713 |
+ |
// Init blitting routines |
714 |
+ |
int bytes_per_row = TrivialBytesPerRow((width + 7) & ~7, DepthModeForPixelDepth(depth)); |
715 |
+ |
#if ENABLE_VOSF |
716 |
+ |
bool native_byte_order; |
717 |
+ |
#ifdef WORDS_BIGENDIAN |
718 |
+ |
native_byte_order = (XImageByteOrder(x_display) == MSBFirst); |
719 |
+ |
#else |
720 |
+ |
native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
721 |
+ |
#endif |
722 |
+ |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
723 |
+ |
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
724 |
+ |
// i.e. the framebuffer update function is not Blit_Copy_Raw |
725 |
+ |
use_vosf = Screen_blitter_init(visualFormat, native_byte_order, depth); |
726 |
+ |
|
727 |
+ |
if (use_vosf) { |
728 |
+ |
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
729 |
+ |
the_host_buffer = the_buffer; |
730 |
+ |
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
731 |
+ |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
732 |
+ |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
733 |
+ |
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
734 |
+ |
} |
735 |
+ |
#else |
736 |
+ |
use_vosf = false; |
737 |
+ |
#endif |
738 |
+ |
#endif |
739 |
+ |
|
740 |
+ |
// Set frame buffer base |
741 |
+ |
D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); |
742 |
+ |
screen_base = Host2MacAddr(the_buffer); |
743 |
+ |
VModes[cur_mode].viRowBytes = bytes_per_row; |
744 |
+ |
return true; |
745 |
+ |
#else |
746 |
+ |
ErrorAlert("SheepShaver has been compiled with DGA support disabled."); |
747 |
+ |
return false; |
748 |
+ |
#endif |
749 |
+ |
} |
750 |
+ |
|
751 |
|
// Open DGA display (!! should use X11 VidMode extensions to set mode) |
752 |
|
static bool open_dga(int width, int height) |
753 |
|
{ |
754 |
+ |
if (is_fbdev_dga_mode) |
755 |
+ |
return false; |
756 |
+ |
|
757 |
|
#ifdef ENABLE_XF86_DGA |
758 |
|
// Set relative mouse mode |
759 |
|
ADBSetRelMouseMode(true); |
760 |
|
|
761 |
+ |
// Create window |
762 |
+ |
XSetWindowAttributes wattr; |
763 |
+ |
wattr.event_mask = eventmask = dga_eventmask; |
764 |
+ |
wattr.override_redirect = True; |
765 |
+ |
wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); |
766 |
+ |
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
767 |
+ |
InputOutput, vis, CWEventMask | CWOverrideRedirect | |
768 |
+ |
(color_class == DirectColor ? CWColormap : 0), &wattr); |
769 |
+ |
|
770 |
+ |
// Show window |
771 |
+ |
XMapRaised(x_display, the_win); |
772 |
+ |
wait_mapped(the_win); |
773 |
+ |
|
774 |
|
#ifdef ENABLE_XF86_VIDMODE |
775 |
|
// Switch to best mode |
776 |
|
if (has_vidmode) { |
787 |
|
#endif |
788 |
|
|
789 |
|
// Establish direct screen connection |
790 |
+ |
XMoveResizeWindow(x_display, the_win, 0, 0, width, height); |
791 |
+ |
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
792 |
|
XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
793 |
|
XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
794 |
+ |
|
795 |
+ |
int v_width, v_bank, v_size; |
796 |
+ |
XF86DGAGetVideo(x_display, screen, (char **)&the_buffer, &v_width, &v_bank, &v_size); |
797 |
|
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
798 |
|
XF86DGASetViewPort(x_display, screen, 0, 0); |
799 |
|
XF86DGASetVidPage(x_display, screen, 0); |
800 |
|
|
801 |
|
// Set colormap |
802 |
< |
if (depth == 8) |
802 |
> |
if (!IsDirectMode(get_current_mode())) { |
803 |
> |
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); |
804 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
347 |
– |
|
348 |
– |
// Set bytes per row |
349 |
– |
int bytes_per_row = (dga_fb_width + 7) & ~7; |
350 |
– |
switch (depth) { |
351 |
– |
case 15: |
352 |
– |
case 16: |
353 |
– |
bytes_per_row *= 2; |
354 |
– |
break; |
355 |
– |
case 24: |
356 |
– |
case 32: |
357 |
– |
bytes_per_row *= 4; |
358 |
– |
break; |
805 |
|
} |
806 |
+ |
XSync(x_display, false); |
807 |
|
|
808 |
+ |
// Init blitting routines |
809 |
+ |
int bytes_per_row = TrivialBytesPerRow((v_width + 7) & ~7, DepthModeForPixelDepth(depth)); |
810 |
|
#if ENABLE_VOSF |
811 |
|
bool native_byte_order; |
812 |
|
#ifdef WORDS_BIGENDIAN |
817 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
818 |
|
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
819 |
|
// i.e. the framebuffer update function is not Blit_Copy_Raw |
820 |
< |
use_vosf = Screen_blitter_init(&visualInfo, native_byte_order, depth); |
820 |
> |
use_vosf = Screen_blitter_init(visualFormat, native_byte_order, depth); |
821 |
|
|
822 |
|
if (use_vosf) { |
823 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
825 |
|
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
826 |
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
827 |
|
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
828 |
+ |
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
829 |
|
} |
830 |
|
#else |
831 |
|
use_vosf = false; |
382 |
– |
the_buffer = dga_screen_base; |
832 |
|
#endif |
833 |
|
#endif |
385 |
– |
screen_base = (uint32)the_buffer; |
834 |
|
|
835 |
+ |
// Set frame buffer base |
836 |
+ |
D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); |
837 |
+ |
screen_base = Host2MacAddr(the_buffer); |
838 |
|
VModes[cur_mode].viRowBytes = bytes_per_row; |
388 |
– |
XSync(x_display, false); |
839 |
|
return true; |
840 |
|
#else |
841 |
|
ErrorAlert("SheepShaver has been compiled with DGA support disabled."); |
845 |
|
|
846 |
|
static bool open_display(void) |
847 |
|
{ |
848 |
< |
display_type = VModes[cur_mode].viType; |
849 |
< |
switch (VModes[cur_mode].viAppleMode) { |
850 |
< |
case APPLE_1_BIT: |
851 |
< |
depth = 1; |
852 |
< |
break; |
853 |
< |
case APPLE_2_BIT: |
854 |
< |
depth = 2; |
855 |
< |
break; |
856 |
< |
case APPLE_4_BIT: |
857 |
< |
depth = 4; |
408 |
< |
break; |
409 |
< |
case APPLE_8_BIT: |
410 |
< |
depth = 8; |
411 |
< |
break; |
412 |
< |
case APPLE_16_BIT: |
413 |
< |
depth = xdepth == 15 ? 15 : 16; |
414 |
< |
break; |
415 |
< |
case APPLE_32_BIT: |
416 |
< |
depth = 32; |
417 |
< |
break; |
848 |
> |
D(bug("open_display()\n")); |
849 |
> |
const VideoInfo &mode = VModes[cur_mode]; |
850 |
> |
|
851 |
> |
// Get original mouse acceleration |
852 |
> |
XGetPointerControl(x_display, &orig_accel_numer, &orig_accel_denom, &orig_threshold); |
853 |
> |
|
854 |
> |
// Find best available X visual |
855 |
> |
if (!find_visual_for_depth(mode.viAppleMode)) { |
856 |
> |
ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); |
857 |
> |
return false; |
858 |
|
} |
859 |
|
|
860 |
+ |
// Build up visualFormat structure |
861 |
+ |
visualFormat.depth = visualInfo.depth; |
862 |
+ |
visualFormat.Rmask = visualInfo.red_mask; |
863 |
+ |
visualFormat.Gmask = visualInfo.green_mask; |
864 |
+ |
visualFormat.Bmask = visualInfo.blue_mask; |
865 |
+ |
|
866 |
+ |
// Create color maps |
867 |
+ |
if (color_class == PseudoColor || color_class == DirectColor) { |
868 |
+ |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
869 |
+ |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
870 |
+ |
} else { |
871 |
+ |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocNone); |
872 |
+ |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocNone); |
873 |
+ |
} |
874 |
+ |
|
875 |
+ |
// Find pixel format of direct modes |
876 |
+ |
if (color_class == DirectColor || color_class == TrueColor) { |
877 |
+ |
rshift = gshift = bshift = 0; |
878 |
+ |
rloss = gloss = bloss = 8; |
879 |
+ |
uint32 mask; |
880 |
+ |
for (mask=vis->red_mask; !(mask&1); mask>>=1) |
881 |
+ |
++rshift; |
882 |
+ |
for (; mask&1; mask>>=1) |
883 |
+ |
--rloss; |
884 |
+ |
for (mask=vis->green_mask; !(mask&1); mask>>=1) |
885 |
+ |
++gshift; |
886 |
+ |
for (; mask&1; mask>>=1) |
887 |
+ |
--gloss; |
888 |
+ |
for (mask=vis->blue_mask; !(mask&1); mask>>=1) |
889 |
+ |
++bshift; |
890 |
+ |
for (; mask&1; mask>>=1) |
891 |
+ |
--bloss; |
892 |
+ |
} |
893 |
+ |
|
894 |
+ |
// Preset palette pixel values for CLUT or gamma table |
895 |
+ |
if (color_class == DirectColor) { |
896 |
+ |
int num = vis->map_entries; |
897 |
+ |
for (int i=0; i<num; i++) { |
898 |
+ |
int c = (i * 256) / num; |
899 |
+ |
x_palette[i].pixel = map_rgb(c, c, c); |
900 |
+ |
x_palette[i].flags = DoRed | DoGreen | DoBlue; |
901 |
+ |
} |
902 |
+ |
} else if (color_class == PseudoColor) { |
903 |
+ |
for (int i=0; i<256; i++) { |
904 |
+ |
x_palette[i].pixel = i; |
905 |
+ |
x_palette[i].flags = DoRed | DoGreen | DoBlue; |
906 |
+ |
} |
907 |
+ |
} |
908 |
+ |
|
909 |
+ |
// Load gray ramp to color map |
910 |
+ |
int num = (color_class == DirectColor ? vis->map_entries : 256); |
911 |
+ |
for (int i=0; i<num; i++) { |
912 |
+ |
int c = (i * 256) / num; |
913 |
+ |
x_palette[i].red = c * 0x0101; |
914 |
+ |
x_palette[i].green = c * 0x0101; |
915 |
+ |
x_palette[i].blue = c * 0x0101; |
916 |
+ |
} |
917 |
+ |
if (color_class == PseudoColor || color_class == DirectColor) { |
918 |
+ |
XStoreColors(x_display, cmap[0], x_palette, num); |
919 |
+ |
XStoreColors(x_display, cmap[1], x_palette, num); |
920 |
+ |
} |
921 |
+ |
|
922 |
+ |
#ifdef ENABLE_VOSF |
923 |
+ |
// Load gray ramp to 8->16/32 expand map |
924 |
+ |
if (!IsDirectMode(get_current_mode()) && xdepth > 8) |
925 |
+ |
for (int i=0; i<256; i++) |
926 |
+ |
ExpandMap[i] = map_rgb(i, i, i); |
927 |
+ |
#endif |
928 |
+ |
|
929 |
+ |
// Create display of requested type |
930 |
+ |
display_type = mode.viType; |
931 |
+ |
depth = depth_of_video_mode(mode.viAppleMode); |
932 |
+ |
|
933 |
|
bool display_open = false; |
934 |
< |
if (display_type == DIS_SCREEN) |
934 |
> |
if (display_type == DIS_SCREEN) { |
935 |
|
display_open = open_dga(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
936 |
+ |
#ifdef ENABLE_FBDEV_DGA |
937 |
+ |
// Try to fallback to FBDev DGA mode |
938 |
+ |
if (!display_open) { |
939 |
+ |
is_fbdev_dga_mode = true; |
940 |
+ |
display_open = open_fbdev(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
941 |
+ |
} |
942 |
+ |
#endif |
943 |
+ |
|
944 |
+ |
} |
945 |
|
else if (display_type == DIS_WINDOW) |
946 |
|
display_open = open_window(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
947 |
|
|
986 |
|
if (the_gc) |
987 |
|
XFreeGC(x_display, the_gc); |
988 |
|
|
989 |
< |
// Close window |
990 |
< |
XDestroyWindow(x_display, the_win); |
989 |
> |
XFlush(x_display); |
990 |
> |
XSync(x_display, false); |
991 |
> |
} |
992 |
> |
|
993 |
> |
// Close FBDev mode |
994 |
> |
static void close_fbdev(void) |
995 |
> |
{ |
996 |
> |
#ifdef ENABLE_FBDEV_DGA |
997 |
> |
XUngrabPointer(x_display, CurrentTime); |
998 |
> |
XUngrabKeyboard(x_display, CurrentTime); |
999 |
> |
|
1000 |
> |
uint8 *fb_base; |
1001 |
> |
if (!use_vosf) { |
1002 |
> |
// don't free() the screen buffer in driver_base dtor |
1003 |
> |
fb_base = the_buffer; |
1004 |
> |
the_buffer = NULL; |
1005 |
> |
} |
1006 |
> |
#ifdef ENABLE_VOSF |
1007 |
> |
else { |
1008 |
> |
// don't free() the screen buffer in driver_base dtor |
1009 |
> |
fb_base = the_host_buffer; |
1010 |
> |
the_host_buffer = NULL; |
1011 |
> |
} |
1012 |
> |
#endif |
1013 |
> |
munmap(fb_base, fb_finfo.smem_len); |
1014 |
> |
#endif |
1015 |
|
} |
1016 |
|
|
1017 |
|
// Close DGA mode |
1018 |
|
static void close_dga(void) |
1019 |
|
{ |
1020 |
+ |
if (is_fbdev_dga_mode) |
1021 |
+ |
return; |
1022 |
+ |
|
1023 |
|
#ifdef ENABLE_XF86_DGA |
1024 |
|
XF86DGADirectVideo(x_display, screen, 0); |
1025 |
|
XUngrabPointer(x_display, CurrentTime); |
1045 |
|
|
1046 |
|
static void close_display(void) |
1047 |
|
{ |
1048 |
< |
if (display_type == DIS_SCREEN) |
1049 |
< |
close_dga(); |
1048 |
> |
if (display_type == DIS_SCREEN) { |
1049 |
> |
if (is_fbdev_dga_mode) |
1050 |
> |
close_fbdev(); |
1051 |
> |
else |
1052 |
> |
close_dga(); |
1053 |
> |
} |
1054 |
|
else if (display_type == DIS_WINDOW) |
1055 |
|
close_window(); |
1056 |
|
|
1057 |
+ |
// Close window |
1058 |
+ |
if (the_win) { |
1059 |
+ |
XUnmapWindow(x_display, the_win); |
1060 |
+ |
wait_unmapped(the_win); |
1061 |
+ |
XDestroyWindow(x_display, the_win); |
1062 |
+ |
} |
1063 |
+ |
|
1064 |
+ |
// Free colormaps |
1065 |
+ |
if (cmap[0]) { |
1066 |
+ |
XFreeColormap(x_display, cmap[0]); |
1067 |
+ |
cmap[0] = 0; |
1068 |
+ |
} |
1069 |
+ |
if (cmap[1]) { |
1070 |
+ |
XFreeColormap(x_display, cmap[1]); |
1071 |
+ |
cmap[1] = 0; |
1072 |
+ |
} |
1073 |
+ |
|
1074 |
|
#ifdef ENABLE_VOSF |
1075 |
|
if (use_vosf) { |
1076 |
|
// Deinitialize VOSF |
1105 |
|
} |
1106 |
|
} |
1107 |
|
#endif |
1108 |
+ |
|
1109 |
+ |
// Restore mouse acceleration |
1110 |
+ |
restore_mouse_accel(); |
1111 |
|
} |
1112 |
|
|
1113 |
|
|
1139 |
|
|
1140 |
|
// Search for server vendor string, then read keycodes |
1141 |
|
const char *vendor = ServerVendor(x_display); |
1142 |
+ |
// Force use of MacX mappings on MacOS X with Apple's X server |
1143 |
+ |
int dummy; |
1144 |
+ |
if (XQueryExtension(x_display, "Apple-DRI", &dummy, &dummy, &dummy)) |
1145 |
+ |
vendor = "MacX"; |
1146 |
|
bool vendor_found = false; |
1147 |
|
char line[256]; |
1148 |
|
while (fgets(line, 255, f)) { |
1184 |
|
} |
1185 |
|
} |
1186 |
|
|
1187 |
< |
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, long apple_mode, long apple_id, int type) |
1187 |
> |
// Find Apple mode matching best specified dimensions |
1188 |
> |
static int find_apple_resolution(int xsize, int ysize) |
1189 |
> |
{ |
1190 |
> |
int apple_id; |
1191 |
> |
if (xsize < 800) |
1192 |
> |
apple_id = APPLE_640x480; |
1193 |
> |
else if (xsize < 1024) |
1194 |
> |
apple_id = APPLE_800x600; |
1195 |
> |
else if (xsize < 1152) |
1196 |
> |
apple_id = APPLE_1024x768; |
1197 |
> |
else if (xsize < 1280) { |
1198 |
> |
if (ysize < 900) |
1199 |
> |
apple_id = APPLE_1152x768; |
1200 |
> |
else |
1201 |
> |
apple_id = APPLE_1152x900; |
1202 |
> |
} |
1203 |
> |
else if (xsize < 1600) |
1204 |
> |
apple_id = APPLE_1280x1024; |
1205 |
> |
else |
1206 |
> |
apple_id = APPLE_1600x1200; |
1207 |
> |
return apple_id; |
1208 |
> |
} |
1209 |
> |
|
1210 |
> |
// Find mode in list of supported modes |
1211 |
> |
static int find_mode(int apple_mode, int apple_id, int type) |
1212 |
> |
{ |
1213 |
> |
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
1214 |
> |
if (p->viType == type && p->viAppleID == apple_id && p->viAppleMode == apple_mode) |
1215 |
> |
return p - VModes; |
1216 |
> |
} |
1217 |
> |
return -1; |
1218 |
> |
} |
1219 |
> |
|
1220 |
> |
// Add custom video mode |
1221 |
> |
static void add_custom_mode(VideoInfo *&p, int type, uint32 x, uint32 y, int apple_mode, int apple_id) |
1222 |
> |
{ |
1223 |
> |
p->viType = type; |
1224 |
> |
p->viXsize = x; |
1225 |
> |
p->viYsize = y; |
1226 |
> |
p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); |
1227 |
> |
p->viAppleMode = apple_mode; |
1228 |
> |
p->viAppleID = apple_id; |
1229 |
> |
p++; |
1230 |
> |
} |
1231 |
> |
|
1232 |
> |
// Add mode to list of supported modes |
1233 |
> |
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type) |
1234 |
|
{ |
1235 |
|
if (allow & test) { |
1236 |
< |
p->viType = type; |
1236 |
> |
uint32 x = 0, y = 0; |
1237 |
|
switch (apple_id) { |
1238 |
|
case APPLE_W_640x480: |
1239 |
|
case APPLE_640x480: |
1240 |
< |
p->viXsize = 640; |
1241 |
< |
p->viYsize = 480; |
1240 |
> |
x = 640; |
1241 |
> |
y = 480; |
1242 |
|
break; |
1243 |
|
case APPLE_W_800x600: |
1244 |
|
case APPLE_800x600: |
1245 |
< |
p->viXsize = 800; |
1246 |
< |
p->viYsize = 600; |
1245 |
> |
x = 800; |
1246 |
> |
y = 600; |
1247 |
|
break; |
1248 |
|
case APPLE_1024x768: |
1249 |
< |
p->viXsize = 1024; |
1250 |
< |
p->viYsize = 768; |
1249 |
> |
x = 1024; |
1250 |
> |
y = 768; |
1251 |
> |
break; |
1252 |
> |
case APPLE_1152x768: |
1253 |
> |
x = 1152; |
1254 |
> |
y = 768; |
1255 |
|
break; |
1256 |
|
case APPLE_1152x900: |
1257 |
< |
p->viXsize = 1152; |
1258 |
< |
p->viYsize = 900; |
1257 |
> |
x = 1152; |
1258 |
> |
y = 900; |
1259 |
|
break; |
1260 |
|
case APPLE_1280x1024: |
1261 |
< |
p->viXsize = 1280; |
1262 |
< |
p->viYsize = 1024; |
1261 |
> |
x = 1280; |
1262 |
> |
y = 1024; |
1263 |
|
break; |
1264 |
|
case APPLE_1600x1200: |
1265 |
< |
p->viXsize = 1600; |
1266 |
< |
p->viYsize = 1200; |
640 |
< |
break; |
641 |
< |
} |
642 |
< |
switch (apple_mode) { |
643 |
< |
case APPLE_8_BIT: |
644 |
< |
p->viRowBytes = p->viXsize; |
645 |
< |
break; |
646 |
< |
case APPLE_16_BIT: |
647 |
< |
p->viRowBytes = p->viXsize * 2; |
648 |
< |
break; |
649 |
< |
case APPLE_32_BIT: |
650 |
< |
p->viRowBytes = p->viXsize * 4; |
1265 |
> |
x = 1600; |
1266 |
> |
y = 1200; |
1267 |
|
break; |
1268 |
|
} |
1269 |
< |
p->viAppleMode = apple_mode; |
654 |
< |
p->viAppleID = apple_id; |
655 |
< |
p++; |
1269 |
> |
add_custom_mode(p, type, x, y, apple_mode, apple_id); |
1270 |
|
} |
1271 |
|
} |
1272 |
|
|
1273 |
+ |
// Add standard list of windowed modes for given color depth |
1274 |
+ |
static void add_window_modes(VideoInfo *&p, int window_modes, int mode) |
1275 |
+ |
{ |
1276 |
+ |
add_mode(p, window_modes, 1, mode, APPLE_W_640x480, DIS_WINDOW); |
1277 |
+ |
add_mode(p, window_modes, 2, mode, APPLE_W_800x600, DIS_WINDOW); |
1278 |
+ |
} |
1279 |
+ |
|
1280 |
|
static bool has_mode(int x, int y) |
1281 |
|
{ |
1282 |
|
#ifdef ENABLE_XF86_VIDMODE |
1315 |
|
|
1316 |
|
// Init variables |
1317 |
|
private_data = NULL; |
697 |
– |
cur_mode = 0; // Window 640x480 |
1318 |
|
video_activated = true; |
1319 |
|
|
1320 |
|
// Find screen and root window |
1321 |
|
screen = XDefaultScreen(x_display); |
1322 |
|
rootwin = XRootWindow(x_display, screen); |
1323 |
|
|
1324 |
+ |
// Get sorted list of available depths |
1325 |
+ |
avail_depths = XListDepths(x_display, screen, &num_depths); |
1326 |
+ |
if (avail_depths == NULL) { |
1327 |
+ |
ErrorAlert(GetString(STR_UNSUPP_DEPTH_ERR)); |
1328 |
+ |
return false; |
1329 |
+ |
} |
1330 |
+ |
sort(avail_depths, avail_depths + num_depths); |
1331 |
+ |
|
1332 |
|
// Get screen depth |
1333 |
|
xdepth = DefaultDepth(x_display, screen); |
1334 |
|
|
1335 |
|
#ifdef ENABLE_XF86_DGA |
1336 |
|
// DGA available? |
1337 |
|
int event_base, error_base; |
1338 |
+ |
is_fbdev_dga_mode = false; |
1339 |
|
if (local_X11 && XF86DGAQueryExtension(x_display, &event_base, &error_base)) { |
1340 |
|
int dga_flags = 0; |
1341 |
|
XF86DGAQueryDirectVideo(x_display, screen, &dga_flags); |
1342 |
|
has_dga = dga_flags & XF86DGADirectPresent; |
1343 |
+ |
#if defined(__linux__) |
1344 |
+ |
// Check r/w permission on /dev/mem for DGA mode to work |
1345 |
+ |
if (has_dga && access("/dev/mem", R_OK | W_OK) != 0) |
1346 |
+ |
has_dga = false; |
1347 |
+ |
#endif |
1348 |
|
} else |
1349 |
|
has_dga = false; |
1350 |
|
#endif |
1357 |
|
XF86VidModeGetAllModeLines(x_display, screen, &num_x_video_modes, &x_video_modes); |
1358 |
|
#endif |
1359 |
|
|
1360 |
+ |
#ifdef ENABLE_FBDEV_DGA |
1361 |
+ |
// FBDev available? |
1362 |
+ |
if (!has_dga && local_X11) { |
1363 |
+ |
if ((fb_dev_fd = open("/dev/fb0", O_RDWR)) > 0) { |
1364 |
+ |
if (ioctl(fb_dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo) != 0) |
1365 |
+ |
close(fb_dev_fd); |
1366 |
+ |
else { |
1367 |
+ |
has_dga = true; |
1368 |
+ |
is_fbdev_dga_mode = true; |
1369 |
+ |
fb_orig_vinfo = fb_vinfo; |
1370 |
+ |
D(bug("Frame buffer device initial resolution: %dx%dx%d\n", fb_vinfo.xres, fb_vinfo.yres, fb_vinfo.bits_per_pixel)); |
1371 |
+ |
} |
1372 |
+ |
} |
1373 |
+ |
} |
1374 |
+ |
#endif |
1375 |
+ |
|
1376 |
|
// Find black and white colors |
1377 |
|
XParseColor(x_display, DefaultColormap(x_display, screen), "rgb:00/00/00", &black); |
1378 |
|
XAllocColor(x_display, DefaultColormap(x_display, screen), &black); |
1381 |
|
black_pixel = BlackPixel(x_display, screen); |
1382 |
|
white_pixel = WhitePixel(x_display, screen); |
1383 |
|
|
734 |
– |
// Get appropriate visual |
735 |
– |
int color_class; |
736 |
– |
switch (xdepth) { |
737 |
– |
#if 0 |
738 |
– |
case 1: |
739 |
– |
color_class = StaticGray; |
740 |
– |
break; |
741 |
– |
#endif |
742 |
– |
case 8: |
743 |
– |
color_class = PseudoColor; |
744 |
– |
break; |
745 |
– |
case 15: |
746 |
– |
case 16: |
747 |
– |
case 24: |
748 |
– |
case 32: |
749 |
– |
color_class = TrueColor; |
750 |
– |
break; |
751 |
– |
default: |
752 |
– |
ErrorAlert(GetString(STR_UNSUPP_DEPTH_ERR)); |
753 |
– |
return false; |
754 |
– |
} |
755 |
– |
if (!XMatchVisualInfo(x_display, screen, xdepth, color_class, &visualInfo)) { |
756 |
– |
ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); |
757 |
– |
return false; |
758 |
– |
} |
759 |
– |
if (visualInfo.depth != xdepth) { |
760 |
– |
ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); |
761 |
– |
return false; |
762 |
– |
} |
763 |
– |
vis = visualInfo.visual; |
764 |
– |
|
1384 |
|
// Mac screen depth follows X depth (for now) |
1385 |
< |
depth = xdepth; |
1386 |
< |
|
1387 |
< |
// Create color maps for 8 bit mode |
1388 |
< |
if (depth == 8) { |
1389 |
< |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1390 |
< |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1391 |
< |
XInstallColormap(x_display, cmap[0]); |
1392 |
< |
XInstallColormap(x_display, cmap[1]); |
1385 |
> |
int default_mode = APPLE_8_BIT; |
1386 |
> |
switch (DefaultDepth(x_display, screen)) { |
1387 |
> |
case 1: |
1388 |
> |
default_mode = APPLE_1_BIT; |
1389 |
> |
break; |
1390 |
> |
case 8: |
1391 |
> |
default_mode = APPLE_8_BIT; |
1392 |
> |
break; |
1393 |
> |
case 15: case 16: |
1394 |
> |
default_mode = APPLE_16_BIT; |
1395 |
> |
break; |
1396 |
> |
case 24: case 32: |
1397 |
> |
default_mode = APPLE_32_BIT; |
1398 |
> |
break; |
1399 |
> |
} |
1400 |
> |
|
1401 |
> |
// Get screen mode from preferences |
1402 |
> |
const char *mode_str = PrefsFindString("screen"); |
1403 |
> |
int default_width = 640, default_height = 480; |
1404 |
> |
if (mode_str) { |
1405 |
> |
display_type = DIS_INVALID; |
1406 |
> |
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) |
1407 |
> |
display_type = DIS_WINDOW; |
1408 |
> |
#ifdef ENABLE_XF86_DGA |
1409 |
> |
else if (has_dga && sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2) |
1410 |
> |
display_type = DIS_SCREEN; |
1411 |
> |
#endif |
1412 |
> |
if (display_type == DIS_INVALID) { |
1413 |
> |
D(bug("Invalid screen mode specified, defaulting to old modes selection\n")); |
1414 |
> |
mode_str = NULL; |
1415 |
> |
} |
1416 |
> |
else { |
1417 |
> |
if (default_width <= 0) |
1418 |
> |
default_width = DisplayWidth(x_display, screen); |
1419 |
> |
else if (default_width > DisplayWidth(x_display, screen)) |
1420 |
> |
default_width = DisplayWidth(x_display, screen); |
1421 |
> |
if (default_height <= 0) |
1422 |
> |
default_height = DisplayHeight(x_display, screen); |
1423 |
> |
else if (default_height > DisplayHeight(x_display, screen)) |
1424 |
> |
default_height = DisplayHeight(x_display, screen); |
1425 |
> |
} |
1426 |
|
} |
1427 |
|
|
1428 |
|
// Construct video mode table |
777 |
– |
int mode = APPLE_8_BIT; |
778 |
– |
int bpr_mult = 8; |
779 |
– |
switch (depth) { |
780 |
– |
case 1: |
781 |
– |
mode = APPLE_1_BIT; |
782 |
– |
bpr_mult = 1; |
783 |
– |
break; |
784 |
– |
case 8: |
785 |
– |
mode = APPLE_8_BIT; |
786 |
– |
bpr_mult = 8; |
787 |
– |
break; |
788 |
– |
case 15: |
789 |
– |
case 16: |
790 |
– |
mode = APPLE_16_BIT; |
791 |
– |
bpr_mult = 16; |
792 |
– |
break; |
793 |
– |
case 24: |
794 |
– |
case 32: |
795 |
– |
mode = APPLE_32_BIT; |
796 |
– |
bpr_mult = 32; |
797 |
– |
break; |
798 |
– |
} |
799 |
– |
|
1429 |
|
uint32 window_modes = PrefsFindInt32("windowmodes"); |
1430 |
|
uint32 screen_modes = PrefsFindInt32("screenmodes"); |
1431 |
|
if (!has_dga) |
1432 |
|
screen_modes = 0; |
1433 |
< |
if (window_modes == 0 && screen_modes == 0) |
1433 |
> |
if (mode_str) |
1434 |
> |
window_modes = screen_modes = 0; |
1435 |
> |
else if (window_modes == 0 && screen_modes == 0) |
1436 |
|
window_modes |= 3; // Allow at least 640x480 and 800x600 window modes |
1437 |
|
|
1438 |
|
VideoInfo *p = VModes; |
1439 |
< |
add_mode(p, window_modes, 1, mode, APPLE_W_640x480, DIS_WINDOW); |
1440 |
< |
add_mode(p, window_modes, 2, mode, APPLE_W_800x600, DIS_WINDOW); |
1441 |
< |
if (has_vidmode) { |
1439 |
> |
if (mode_str) { |
1440 |
> |
if (display_type == DIS_WINDOW) { |
1441 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) { |
1442 |
> |
if (find_visual_for_depth(d)) { |
1443 |
> |
if (default_width > 640 && default_height > 480) |
1444 |
> |
add_mode(p, 3, 1, d, APPLE_W_640x480, DIS_WINDOW); |
1445 |
> |
if (default_width > 800 && default_height > 600) |
1446 |
> |
add_mode(p, 3, 2, d, APPLE_W_800x600, DIS_WINDOW); |
1447 |
> |
add_custom_mode(p, display_type, default_width, default_height, d, APPLE_CUSTOM); |
1448 |
> |
} |
1449 |
> |
} |
1450 |
> |
} else |
1451 |
> |
add_custom_mode(p, display_type, default_width, default_height, default_mode, APPLE_CUSTOM); |
1452 |
> |
} else if (window_modes) { |
1453 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) |
1454 |
> |
if (find_visual_for_depth(d)) |
1455 |
> |
add_window_modes(p, window_modes, d); |
1456 |
> |
} else if (has_vidmode) { |
1457 |
|
if (has_mode(640, 480)) |
1458 |
< |
add_mode(p, screen_modes, 1, mode, APPLE_640x480, DIS_SCREEN); |
1458 |
> |
add_mode(p, screen_modes, 1, default_mode, APPLE_640x480, DIS_SCREEN); |
1459 |
|
if (has_mode(800, 600)) |
1460 |
< |
add_mode(p, screen_modes, 2, mode, APPLE_800x600, DIS_SCREEN); |
1460 |
> |
add_mode(p, screen_modes, 2, default_mode, APPLE_800x600, DIS_SCREEN); |
1461 |
|
if (has_mode(1024, 768)) |
1462 |
< |
add_mode(p, screen_modes, 4, mode, APPLE_1024x768, DIS_SCREEN); |
1462 |
> |
add_mode(p, screen_modes, 4, default_mode, APPLE_1024x768, DIS_SCREEN); |
1463 |
> |
if (has_mode(1152, 768)) |
1464 |
> |
add_mode(p, screen_modes, 64, default_mode, APPLE_1152x768, DIS_SCREEN); |
1465 |
|
if (has_mode(1152, 900)) |
1466 |
< |
add_mode(p, screen_modes, 8, mode, APPLE_1152x900, DIS_SCREEN); |
1466 |
> |
add_mode(p, screen_modes, 8, default_mode, APPLE_1152x900, DIS_SCREEN); |
1467 |
|
if (has_mode(1280, 1024)) |
1468 |
< |
add_mode(p, screen_modes, 16, mode, APPLE_1280x1024, DIS_SCREEN); |
1468 |
> |
add_mode(p, screen_modes, 16, default_mode, APPLE_1280x1024, DIS_SCREEN); |
1469 |
|
if (has_mode(1600, 1200)) |
1470 |
< |
add_mode(p, screen_modes, 32, mode, APPLE_1600x1200, DIS_SCREEN); |
1470 |
> |
add_mode(p, screen_modes, 32, default_mode, APPLE_1600x1200, DIS_SCREEN); |
1471 |
|
} else if (screen_modes) { |
1472 |
|
int xsize = DisplayWidth(x_display, screen); |
1473 |
|
int ysize = DisplayHeight(x_display, screen); |
1474 |
< |
int apple_id; |
827 |
< |
if (xsize < 800) |
828 |
< |
apple_id = APPLE_640x480; |
829 |
< |
else if (xsize < 1024) |
830 |
< |
apple_id = APPLE_800x600; |
831 |
< |
else if (xsize < 1152) |
832 |
< |
apple_id = APPLE_1024x768; |
833 |
< |
else if (xsize < 1280) |
834 |
< |
apple_id = APPLE_1152x900; |
835 |
< |
else if (xsize < 1600) |
836 |
< |
apple_id = APPLE_1280x1024; |
837 |
< |
else |
838 |
< |
apple_id = APPLE_1600x1200; |
1474 |
> |
int apple_id = find_apple_resolution(xsize, ysize); |
1475 |
|
p->viType = DIS_SCREEN; |
1476 |
|
p->viRowBytes = 0; |
1477 |
|
p->viXsize = xsize; |
1478 |
|
p->viYsize = ysize; |
1479 |
< |
p->viAppleMode = mode; |
1479 |
> |
p->viAppleMode = default_mode; |
1480 |
|
p->viAppleID = apple_id; |
1481 |
|
p++; |
1482 |
|
} |
1486 |
|
p->viAppleMode = 0; |
1487 |
|
p->viAppleID = 0; |
1488 |
|
|
1489 |
< |
#ifdef ENABLE_XF86_DGA |
1489 |
> |
// Find default mode (window 640x480) |
1490 |
> |
cur_mode = -1; |
1491 |
|
if (has_dga && screen_modes) { |
1492 |
< |
int v_bank, v_size; |
1493 |
< |
XF86DGAGetVideo(x_display, screen, &dga_screen_base, &dga_fb_width, &v_bank, &v_size); |
1494 |
< |
D(bug("DGA screen_base %p, v_width %d\n", dga_screen_base, dga_fb_width)); |
1492 |
> |
int screen_width = DisplayWidth(x_display, screen); |
1493 |
> |
int screen_height = DisplayHeight(x_display, screen); |
1494 |
> |
int apple_id = find_apple_resolution(screen_width, screen_height); |
1495 |
> |
if (apple_id != -1) |
1496 |
> |
cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN); |
1497 |
> |
} else if (has_dga && mode_str) |
1498 |
> |
cur_mode = find_mode(default_mode, APPLE_CUSTOM, DIS_SCREEN); |
1499 |
> |
|
1500 |
> |
if (cur_mode == -1) { |
1501 |
> |
// pick up first windowed mode available |
1502 |
> |
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
1503 |
> |
if (p->viType == DIS_WINDOW && p->viAppleMode == default_mode) { |
1504 |
> |
cur_mode = p - VModes; |
1505 |
> |
break; |
1506 |
> |
} |
1507 |
> |
} |
1508 |
> |
} |
1509 |
> |
assert(cur_mode != -1); |
1510 |
> |
|
1511 |
> |
#if DEBUG |
1512 |
> |
D(bug("Available video modes:\n")); |
1513 |
> |
for (p = VModes; p->viType != DIS_INVALID; p++) { |
1514 |
> |
int bits = depth_of_video_mode(p->viAppleMode); |
1515 |
> |
D(bug(" %dx%d (ID %02x), %d colors\n", p->viXsize, p->viYsize, p->viAppleID, 1 << bits)); |
1516 |
|
} |
1517 |
|
#endif |
1518 |
|
|
1525 |
|
XSetErrorHandler(ignore_errors); |
1526 |
|
#endif |
1527 |
|
|
1528 |
+ |
// Lock down frame buffer |
1529 |
+ |
XSync(x_display, false); |
1530 |
+ |
LOCK_FRAME_BUFFER; |
1531 |
+ |
|
1532 |
|
// Start periodic thread |
1533 |
|
XSync(x_display, false); |
1534 |
< |
redraw_thread_active = (pthread_create(&redraw_thread, NULL, redraw_func, NULL) == 0); |
1534 |
> |
Set_pthread_attr(&redraw_thread_attr, 0); |
1535 |
> |
redraw_thread_cancel = false; |
1536 |
> |
redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0); |
1537 |
|
D(bug("Redraw thread installed (%ld)\n", redraw_thread)); |
1538 |
|
return true; |
1539 |
|
} |
1547 |
|
{ |
1548 |
|
// Stop redraw thread |
1549 |
|
if (redraw_thread_active) { |
1550 |
+ |
redraw_thread_cancel = true; |
1551 |
|
pthread_cancel(redraw_thread); |
1552 |
|
pthread_join(redraw_thread, NULL); |
1553 |
|
redraw_thread_active = false; |
1554 |
|
} |
1555 |
|
|
1556 |
+ |
// Unlock frame buffer |
1557 |
+ |
UNLOCK_FRAME_BUFFER; |
1558 |
+ |
XSync(x_display, false); |
1559 |
+ |
D(bug(" frame buffer unlocked\n")); |
1560 |
+ |
|
1561 |
|
#ifdef ENABLE_VOSF |
1562 |
|
if (use_vosf) { |
1563 |
|
// Deinitialize VOSF |
1571 |
|
close_display(); |
1572 |
|
XFlush(x_display); |
1573 |
|
XSync(x_display, false); |
904 |
– |
if (depth == 8) { |
905 |
– |
XFreeColormap(x_display, cmap[0]); |
906 |
– |
XFreeColormap(x_display, cmap[1]); |
907 |
– |
} |
1574 |
|
} |
1575 |
+ |
|
1576 |
+ |
#ifdef ENABLE_FBDEV_DGA |
1577 |
+ |
// Close framebuffer device |
1578 |
+ |
if (fb_dev_fd >= 0) { |
1579 |
+ |
close(fb_dev_fd); |
1580 |
+ |
fb_dev_fd = -1; |
1581 |
+ |
} |
1582 |
+ |
#endif |
1583 |
|
} |
1584 |
|
|
1585 |
|
|
1587 |
|
* Suspend/resume emulator |
1588 |
|
*/ |
1589 |
|
|
916 |
– |
extern void PauseEmulator(void); |
917 |
– |
extern void ResumeEmulator(void); |
918 |
– |
|
1590 |
|
static void suspend_emul(void) |
1591 |
|
{ |
1592 |
|
if (display_type == DIS_SCREEN) { |
1594 |
|
ADBKeyUp(0x36); |
1595 |
|
ctrl_down = false; |
1596 |
|
|
1597 |
< |
// Pause MacOS thread |
1598 |
< |
PauseEmulator(); |
928 |
< |
emul_suspended = true; |
1597 |
> |
// Lock frame buffer (this will stop the MacOS thread) |
1598 |
> |
LOCK_FRAME_BUFFER; |
1599 |
|
|
1600 |
|
// Save frame buffer |
1601 |
|
fb_save = malloc(VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1602 |
|
if (fb_save) |
1603 |
< |
memcpy(fb_save, (void *)screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1603 |
> |
Mac2Host_memcpy(fb_save, screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1604 |
|
|
1605 |
|
// Close full screen display |
1606 |
+ |
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) |
1607 |
|
#ifdef ENABLE_XF86_DGA |
1608 |
< |
XF86DGADirectVideo(x_display, screen, 0); |
1608 |
> |
if (!is_fbdev_dga_mode) |
1609 |
> |
XF86DGADirectVideo(x_display, screen, 0); |
1610 |
> |
#endif |
1611 |
|
XUngrabPointer(x_display, CurrentTime); |
1612 |
|
XUngrabKeyboard(x_display, CurrentTime); |
1613 |
|
#endif |
1614 |
+ |
restore_mouse_accel(); |
1615 |
+ |
XUnmapWindow(x_display, the_win); |
1616 |
+ |
wait_unmapped(the_win); |
1617 |
|
XSync(x_display, false); |
1618 |
|
|
1619 |
|
// Open "suspend" window |
1620 |
|
XSetWindowAttributes wattr; |
1621 |
|
wattr.event_mask = KeyPressMask; |
1622 |
< |
wattr.background_pixel = black_pixel; |
947 |
< |
wattr.border_pixel = black_pixel; |
1622 |
> |
wattr.background_pixel = (vis == DefaultVisual(x_display, screen) ? black_pixel : 0); |
1623 |
|
wattr.backing_store = Always; |
1624 |
< |
wattr.backing_planes = xdepth; |
1625 |
< |
wattr.colormap = DefaultColormap(x_display, screen); |
951 |
< |
XSync(x_display, false); |
1624 |
> |
wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); |
1625 |
> |
|
1626 |
|
suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth, |
1627 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | |
1628 |
< |
CWBackingStore | CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr); |
1629 |
< |
XSync(x_display, false); |
1630 |
< |
XStoreName(x_display, suspend_win, GetString(STR_SUSPEND_WINDOW_TITLE)); |
1631 |
< |
XMapRaised(x_display, suspend_win); |
958 |
< |
XSync(x_display, false); |
1627 |
> |
InputOutput, vis, CWEventMask | CWBackPixel | CWBackingStore | CWColormap, &wattr); |
1628 |
> |
set_window_name(suspend_win, STR_SUSPEND_WINDOW_TITLE); |
1629 |
> |
set_window_focus(suspend_win); |
1630 |
> |
XMapWindow(x_display, suspend_win); |
1631 |
> |
emul_suspended = true; |
1632 |
|
} |
1633 |
|
} |
1634 |
|
|
1639 |
|
XSync(x_display, false); |
1640 |
|
|
1641 |
|
// Reopen full screen display |
1642 |
< |
XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime); |
1643 |
< |
XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
1644 |
< |
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
1645 |
< |
XF86DGASetViewPort(x_display, screen, 0, 0); |
1642 |
> |
XMapRaised(x_display, the_win); |
1643 |
> |
wait_mapped(the_win); |
1644 |
> |
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
1645 |
> |
Window w = is_fbdev_dga_mode ? the_win : rootwin; |
1646 |
> |
XGrabKeyboard(x_display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
1647 |
> |
XGrabPointer(x_display, w, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
1648 |
> |
disable_mouse_accel(); |
1649 |
> |
#ifdef ENABLE_XF86_DGA |
1650 |
> |
if (!is_fbdev_dga_mode) { |
1651 |
> |
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
1652 |
> |
XF86DGASetViewPort(x_display, screen, 0, 0); |
1653 |
> |
} |
1654 |
> |
#endif |
1655 |
|
XSync(x_display, false); |
1656 |
|
|
1657 |
|
// the_buffer already contains the data to restore. i.e. since a temporary |
1672 |
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1673 |
|
if (!use_vosf) |
1674 |
|
#endif |
1675 |
< |
memcpy((void *)screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1675 |
> |
Host2Mac_memcpy(screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1676 |
|
free(fb_save); |
1677 |
|
fb_save = NULL; |
1678 |
|
} |
1679 |
|
if (depth == 8) |
1680 |
|
palette_changed = true; |
1681 |
|
|
1682 |
< |
// Resume MacOS thread |
1682 |
> |
// Unlock frame buffer (and continue MacOS thread) |
1683 |
> |
UNLOCK_FRAME_BUFFER; |
1684 |
|
emul_suspended = false; |
1002 |
– |
ResumeEmulator(); |
1685 |
|
} |
1686 |
|
|
1687 |
|
|
1845 |
|
return -1; |
1846 |
|
} |
1847 |
|
|
1848 |
< |
static int event2keycode(XKeyEvent &ev) |
1848 |
> |
static int event2keycode(XKeyEvent &ev, bool key_down) |
1849 |
|
{ |
1850 |
|
KeySym ks; |
1169 |
– |
int as; |
1851 |
|
int i = 0; |
1852 |
|
|
1853 |
|
do { |
1854 |
|
ks = XLookupKeysym(&ev, i++); |
1855 |
< |
as = kc_decode(ks); |
1856 |
< |
if (as != -1) |
1855 |
> |
int as = kc_decode(ks); |
1856 |
> |
if (as >= 0) |
1857 |
> |
return as; |
1858 |
> |
if (as == -2) |
1859 |
|
return as; |
1860 |
|
} while (ks != NoSymbol); |
1861 |
|
|
1876 |
|
else if (XCheckTypedEvent(x_display, SelectionClear, &event)) |
1877 |
|
ClipboardSelectionClear(&event.xselectionclear); |
1878 |
|
|
1879 |
+ |
// Window "close" widget clicked |
1880 |
+ |
else if (XCheckTypedEvent(x_display, ClientMessage, &event)) { |
1881 |
+ |
if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW) { |
1882 |
+ |
ADBKeyDown(0x7f); // Power key |
1883 |
+ |
ADBKeyUp(0x7f); |
1884 |
+ |
} |
1885 |
+ |
} |
1886 |
+ |
|
1887 |
|
XDisplayUnlock(); |
1888 |
|
break; |
1889 |
|
} |
1917 |
|
break; |
1918 |
|
} |
1919 |
|
|
1920 |
< |
// Mouse moved |
1920 |
> |
// Mouse entered window |
1921 |
|
case EnterNotify: |
1922 |
< |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1922 |
> |
if (event.xcrossing.mode != NotifyGrab && event.xcrossing.mode != NotifyUngrab) |
1923 |
> |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
1924 |
|
break; |
1925 |
+ |
|
1926 |
+ |
// Mouse moved |
1927 |
|
case MotionNotify: |
1928 |
< |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1928 |
> |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
1929 |
|
break; |
1930 |
|
|
1931 |
|
// Keyboard |
1932 |
|
case KeyPress: { |
1933 |
< |
int code = event2keycode(event.xkey); |
1934 |
< |
if (use_keycodes && code != -1) |
1935 |
< |
code = keycode_table[event.xkey.keycode & 0xff]; |
1936 |
< |
if (code != -1) { |
1933 |
> |
int code = -1; |
1934 |
> |
if (use_keycodes) { |
1935 |
> |
if (event2keycode(event.xkey, true) != -2) // This is called to process the hotkeys |
1936 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1937 |
> |
} else |
1938 |
> |
code = event2keycode(event.xkey, true); |
1939 |
> |
if (code >= 0) { |
1940 |
|
if (!emul_suspended) { |
1941 |
< |
ADBKeyDown(code); |
1941 |
> |
if (code == 0x39) { // Caps Lock pressed |
1942 |
> |
if (caps_on) { |
1943 |
> |
ADBKeyUp(code); |
1944 |
> |
caps_on = false; |
1945 |
> |
} else { |
1946 |
> |
ADBKeyDown(code); |
1947 |
> |
caps_on = true; |
1948 |
> |
} |
1949 |
> |
} else |
1950 |
> |
ADBKeyDown(code); |
1951 |
|
if (code == 0x36) |
1952 |
|
ctrl_down = true; |
1953 |
|
} else { |
1958 |
|
break; |
1959 |
|
} |
1960 |
|
case KeyRelease: { |
1961 |
< |
int code = event2keycode(event.xkey); |
1962 |
< |
if (use_keycodes && code != 1) |
1963 |
< |
code = keycode_table[event.xkey.keycode & 0xff]; |
1964 |
< |
if (code != -1) { |
1961 |
> |
int code = -1; |
1962 |
> |
if (use_keycodes) { |
1963 |
> |
if (event2keycode(event.xkey, false) != -2) // This is called to process the hotkeys |
1964 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1965 |
> |
} else |
1966 |
> |
code = event2keycode(event.xkey, false); |
1967 |
> |
if (code >= 0 && code != 0x39) { // Don't propagate Caps Lock releases |
1968 |
|
ADBKeyUp(code); |
1969 |
|
if (code == 0x36) |
1970 |
|
ctrl_down = false; |
1997 |
|
if (emerg_quit) |
1998 |
|
QuitEmulator(); |
1999 |
|
|
2000 |
+ |
// Temporarily give up frame buffer lock (this is the point where |
2001 |
+ |
// we are suspended when the user presses Ctrl-Tab) |
2002 |
+ |
UNLOCK_FRAME_BUFFER; |
2003 |
+ |
LOCK_FRAME_BUFFER; |
2004 |
+ |
|
2005 |
|
// Execute video VBL |
2006 |
|
if (private_data != NULL && private_data->interruptsEnabled) |
2007 |
|
VSLDoInterruptService(private_data->vslServiceID); |
2009 |
|
|
2010 |
|
|
2011 |
|
/* |
1298 |
– |
* Install graphics acceleration |
1299 |
– |
*/ |
1300 |
– |
|
1301 |
– |
#if 0 |
1302 |
– |
// Rectangle blitting |
1303 |
– |
static void accl_bitblt(accl_params *p) |
1304 |
– |
{ |
1305 |
– |
D(bug("accl_bitblt\n")); |
1306 |
– |
|
1307 |
– |
// Get blitting parameters |
1308 |
– |
int16 src_X = p->src_rect[1] - p->src_bounds[1]; |
1309 |
– |
int16 src_Y = p->src_rect[0] - p->src_bounds[0]; |
1310 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1311 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1312 |
– |
int16 width = p->dest_rect[3] - p->dest_rect[1] - 1; |
1313 |
– |
int16 height = p->dest_rect[2] - p->dest_rect[0] - 1; |
1314 |
– |
D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y)); |
1315 |
– |
D(bug(" width %d, height %d\n", width, height)); |
1316 |
– |
|
1317 |
– |
// And perform the blit |
1318 |
– |
bitblt_hook(src_X, src_Y, dest_X, dest_Y, width, height); |
1319 |
– |
} |
1320 |
– |
|
1321 |
– |
static bool accl_bitblt_hook(accl_params *p) |
1322 |
– |
{ |
1323 |
– |
D(bug("accl_draw_hook %p\n", p)); |
1324 |
– |
|
1325 |
– |
// Check if we can accelerate this bitblt |
1326 |
– |
if (p->src_base_addr == screen_base && p->dest_base_addr == screen_base && |
1327 |
– |
display_type == DIS_SCREEN && bitblt_hook != NULL && |
1328 |
– |
((uint32 *)p)[0x18 >> 2] + ((uint32 *)p)[0x128 >> 2] == 0 && |
1329 |
– |
((uint32 *)p)[0x130 >> 2] == 0 && |
1330 |
– |
p->transfer_mode == 0 && |
1331 |
– |
p->src_row_bytes > 0 && ((uint32 *)p)[0x15c >> 2] > 0) { |
1332 |
– |
|
1333 |
– |
// Yes, set function pointer |
1334 |
– |
p->draw_proc = accl_bitblt; |
1335 |
– |
return true; |
1336 |
– |
} |
1337 |
– |
return false; |
1338 |
– |
} |
1339 |
– |
|
1340 |
– |
// Rectangle filling/inversion |
1341 |
– |
static void accl_fillrect8(accl_params *p) |
1342 |
– |
{ |
1343 |
– |
D(bug("accl_fillrect8\n")); |
1344 |
– |
|
1345 |
– |
// Get filling parameters |
1346 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1347 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1348 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1349 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1350 |
– |
uint8 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
1351 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1352 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1353 |
– |
|
1354 |
– |
// And perform the fill |
1355 |
– |
fillrect8_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
1356 |
– |
} |
1357 |
– |
|
1358 |
– |
static void accl_fillrect32(accl_params *p) |
1359 |
– |
{ |
1360 |
– |
D(bug("accl_fillrect32\n")); |
1361 |
– |
|
1362 |
– |
// Get filling parameters |
1363 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1364 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1365 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1366 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1367 |
– |
uint32 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
1368 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1369 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1370 |
– |
|
1371 |
– |
// And perform the fill |
1372 |
– |
fillrect32_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
1373 |
– |
} |
1374 |
– |
|
1375 |
– |
static void accl_invrect(accl_params *p) |
1376 |
– |
{ |
1377 |
– |
D(bug("accl_invrect\n")); |
1378 |
– |
|
1379 |
– |
// Get inversion parameters |
1380 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1381 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1382 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1383 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1384 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1385 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1386 |
– |
|
1387 |
– |
//!!?? pen_mode == 14 |
1388 |
– |
|
1389 |
– |
// And perform the inversion |
1390 |
– |
invrect_hook(dest_X, dest_Y, dest_X_max, dest_Y_max); |
1391 |
– |
} |
1392 |
– |
|
1393 |
– |
static bool accl_fillrect_hook(accl_params *p) |
1394 |
– |
{ |
1395 |
– |
D(bug("accl_fillrect_hook %p\n", p)); |
1396 |
– |
|
1397 |
– |
// Check if we can accelerate this fillrect |
1398 |
– |
if (p->dest_base_addr == screen_base && ((uint32 *)p)[0x284 >> 2] != 0 && display_type == DIS_SCREEN) { |
1399 |
– |
if (p->transfer_mode == 8) { |
1400 |
– |
// Fill |
1401 |
– |
if (p->dest_pixel_size == 8 && fillrect8_hook != NULL) { |
1402 |
– |
p->draw_proc = accl_fillrect8; |
1403 |
– |
return true; |
1404 |
– |
} else if (p->dest_pixel_size == 32 && fillrect32_hook != NULL) { |
1405 |
– |
p->draw_proc = accl_fillrect32; |
1406 |
– |
return true; |
1407 |
– |
} |
1408 |
– |
} else if (p->transfer_mode == 10 && invrect_hook != NULL) { |
1409 |
– |
// Invert |
1410 |
– |
p->draw_proc = accl_invrect; |
1411 |
– |
return true; |
1412 |
– |
} |
1413 |
– |
} |
1414 |
– |
return false; |
1415 |
– |
} |
1416 |
– |
|
1417 |
– |
// Wait for graphics operation to finish |
1418 |
– |
static bool accl_sync_hook(void *arg) |
1419 |
– |
{ |
1420 |
– |
D(bug("accl_sync_hook %p\n", arg)); |
1421 |
– |
if (sync_hook != NULL) |
1422 |
– |
sync_hook(); |
1423 |
– |
return true; |
1424 |
– |
} |
1425 |
– |
|
1426 |
– |
static struct accl_hook_info bitblt_hook_info = {accl_bitblt_hook, accl_sync_hook, ACCL_BITBLT}; |
1427 |
– |
static struct accl_hook_info fillrect_hook_info = {accl_fillrect_hook, accl_sync_hook, ACCL_FILLRECT}; |
1428 |
– |
#endif |
1429 |
– |
|
1430 |
– |
void VideoInstallAccel(void) |
1431 |
– |
{ |
1432 |
– |
// Install acceleration hooks |
1433 |
– |
if (PrefsFindBool("gfxaccel")) { |
1434 |
– |
D(bug("Video: Installing acceleration hooks\n")); |
1435 |
– |
//!! NQDMisc(6, &bitblt_hook_info); |
1436 |
– |
// NQDMisc(6, &fillrect_hook_info); |
1437 |
– |
} |
1438 |
– |
} |
1439 |
– |
|
1440 |
– |
|
1441 |
– |
/* |
2012 |
|
* Change video mode |
2013 |
|
*/ |
2014 |
|
|
2066 |
|
|
2067 |
|
void video_set_palette(void) |
2068 |
|
{ |
2069 |
+ |
LOCK_PALETTE; |
2070 |
+ |
|
2071 |
+ |
// Convert colors to XColor array |
2072 |
+ |
int mode = get_current_mode(); |
2073 |
+ |
int num_in = palette_size(mode); |
2074 |
+ |
int num_out = 256; |
2075 |
+ |
bool stretch = false; |
2076 |
+ |
if (IsDirectMode(mode)) { |
2077 |
+ |
// If X is in 565 mode we have to stretch the gamma table from 32 to 64 entries |
2078 |
+ |
num_out = vis->map_entries; |
2079 |
+ |
stretch = true; |
2080 |
+ |
} |
2081 |
+ |
XColor *p = x_palette; |
2082 |
+ |
for (int i=0; i<num_out; i++) { |
2083 |
+ |
int c = (stretch ? (i * num_in) / num_out : i); |
2084 |
+ |
p->red = mac_pal[c].red * 0x0101; |
2085 |
+ |
p->green = mac_pal[c].green * 0x0101; |
2086 |
+ |
p->blue = mac_pal[c].blue * 0x0101; |
2087 |
+ |
p++; |
2088 |
+ |
} |
2089 |
+ |
|
2090 |
+ |
#ifdef ENABLE_VOSF |
2091 |
+ |
// Recalculate pixel color expansion map |
2092 |
+ |
if (!IsDirectMode(mode) && xdepth > 8) { |
2093 |
+ |
for (int i=0; i<256; i++) { |
2094 |
+ |
int c = i & (num_in-1); // If there are less than 256 colors, we repeat the first entries (this makes color expansion easier) |
2095 |
+ |
ExpandMap[i] = map_rgb(mac_pal[c].red, mac_pal[c].green, mac_pal[c].blue); |
2096 |
+ |
} |
2097 |
+ |
|
2098 |
+ |
// We have to redraw everything because the interpretation of pixel values changed |
2099 |
+ |
LOCK_VOSF; |
2100 |
+ |
PFLAG_SET_ALL; |
2101 |
+ |
UNLOCK_VOSF; |
2102 |
+ |
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
2103 |
+ |
} |
2104 |
+ |
#endif |
2105 |
+ |
|
2106 |
+ |
// Tell redraw thread to change palette |
2107 |
|
palette_changed = true; |
2108 |
+ |
|
2109 |
+ |
UNLOCK_PALETTE; |
2110 |
+ |
} |
2111 |
+ |
|
2112 |
+ |
|
2113 |
+ |
/* |
2114 |
+ |
* Can we set the MacOS cursor image into the window? |
2115 |
+ |
*/ |
2116 |
+ |
|
2117 |
+ |
bool video_can_change_cursor(void) |
2118 |
+ |
{ |
2119 |
+ |
return hw_mac_cursor_accl && (display_type != DIS_SCREEN); |
2120 |
|
} |
2121 |
|
|
2122 |
|
|
2255 |
|
const int VIDEO_REFRESH_HZ = 60; |
2256 |
|
const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ; |
2257 |
|
|
2258 |
+ |
static void handle_palette_changes(void) |
2259 |
+ |
{ |
2260 |
+ |
LOCK_PALETTE; |
2261 |
+ |
|
2262 |
+ |
if (palette_changed && !emul_suspended) { |
2263 |
+ |
palette_changed = false; |
2264 |
+ |
|
2265 |
+ |
int mode = get_current_mode(); |
2266 |
+ |
if (color_class == PseudoColor || color_class == DirectColor) { |
2267 |
+ |
int num = vis->map_entries; |
2268 |
+ |
bool set_clut = true; |
2269 |
+ |
if (!IsDirectMode(mode) && color_class == DirectColor) { |
2270 |
+ |
if (display_type == DIS_WINDOW) |
2271 |
+ |
set_clut = false; // Indexed mode on true color screen, don't set CLUT |
2272 |
+ |
} |
2273 |
+ |
|
2274 |
+ |
if (set_clut) { |
2275 |
+ |
XDisplayLock(); |
2276 |
+ |
XStoreColors(x_display, cmap[0], x_palette, num); |
2277 |
+ |
XStoreColors(x_display, cmap[1], x_palette, num); |
2278 |
+ |
XSync(x_display, false); |
2279 |
+ |
XDisplayUnlock(); |
2280 |
+ |
} |
2281 |
+ |
} |
2282 |
+ |
|
2283 |
+ |
#ifdef ENABLE_XF86_DGA |
2284 |
+ |
if (display_type == DIS_SCREEN && !is_fbdev_dga_mode) { |
2285 |
+ |
current_dga_cmap ^= 1; |
2286 |
+ |
if (!IsDirectMode(mode) && cmap[current_dga_cmap]) |
2287 |
+ |
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
2288 |
+ |
} |
2289 |
+ |
#endif |
2290 |
+ |
} |
2291 |
+ |
|
2292 |
+ |
UNLOCK_PALETTE; |
2293 |
+ |
} |
2294 |
+ |
|
2295 |
|
static void *redraw_func(void *arg) |
2296 |
|
{ |
2297 |
|
int fd = ConnectionNumber(x_display); |
2300 |
|
int64 ticks = 0; |
2301 |
|
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
2302 |
|
|
2303 |
< |
for (;;) { |
2303 |
> |
while (!redraw_thread_cancel) { |
2304 |
|
|
2305 |
|
// Pause if requested (during video mode switches) |
2306 |
|
while (thread_stop_req) |
2326 |
|
quit_full_screen = false; |
2327 |
|
if (display_type == DIS_SCREEN) { |
2328 |
|
XDisplayLock(); |
2329 |
+ |
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) |
2330 |
|
#ifdef ENABLE_XF86_DGA |
2331 |
< |
XF86DGADirectVideo(x_display, screen, 0); |
2331 |
> |
if (is_fbdev_dga_mode) |
2332 |
> |
XF86DGADirectVideo(x_display, screen, 0); |
2333 |
> |
#endif |
2334 |
|
XUngrabPointer(x_display, CurrentTime); |
2335 |
|
XUngrabKeyboard(x_display, CurrentTime); |
2336 |
+ |
XUnmapWindow(x_display, the_win); |
2337 |
+ |
wait_unmapped(the_win); |
2338 |
+ |
XDestroyWindow(x_display, the_win); |
2339 |
|
#endif |
2340 |
|
XSync(x_display, false); |
2341 |
|
XDisplayUnlock(); |
2368 |
|
update_display(); |
2369 |
|
|
2370 |
|
// Set new cursor image if it was changed |
2371 |
< |
if (cursor_changed) { |
2371 |
> |
if (hw_mac_cursor_accl && cursor_changed) { |
2372 |
|
cursor_changed = false; |
2373 |
< |
memcpy(cursor_image->data, MacCursor + 4, 32); |
2374 |
< |
memcpy(cursor_mask_image->data, MacCursor + 36, 32); |
2373 |
> |
uint8 *x_data = (uint8 *)cursor_image->data; |
2374 |
> |
uint8 *x_mask = (uint8 *)cursor_mask_image->data; |
2375 |
> |
for (int i = 0; i < 32; i++) { |
2376 |
> |
x_mask[i] = MacCursor[4 + i] | MacCursor[36 + i]; |
2377 |
> |
x_data[i] = MacCursor[4 + i]; |
2378 |
> |
} |
2379 |
|
XDisplayLock(); |
2380 |
|
XFreeCursor(x_display, mac_cursor); |
2381 |
|
XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16); |
2401 |
|
#endif |
2402 |
|
|
2403 |
|
// Set new palette if it was changed |
2404 |
< |
if (palette_changed && !emul_suspended) { |
1738 |
< |
palette_changed = false; |
1739 |
< |
XColor c[256]; |
1740 |
< |
for (int i=0; i<256; i++) { |
1741 |
< |
c[i].pixel = i; |
1742 |
< |
c[i].red = mac_pal[i].red * 0x0101; |
1743 |
< |
c[i].green = mac_pal[i].green * 0x0101; |
1744 |
< |
c[i].blue = mac_pal[i].blue * 0x0101; |
1745 |
< |
c[i].flags = DoRed | DoGreen | DoBlue; |
1746 |
< |
} |
1747 |
< |
if (depth == 8) { |
1748 |
< |
XDisplayLock(); |
1749 |
< |
XStoreColors(x_display, cmap[0], c, 256); |
1750 |
< |
XStoreColors(x_display, cmap[1], c, 256); |
1751 |
< |
#ifdef ENABLE_XF86_DGA |
1752 |
< |
if (display_type == DIS_SCREEN) { |
1753 |
< |
current_dga_cmap ^= 1; |
1754 |
< |
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1755 |
< |
} |
1756 |
< |
#endif |
1757 |
< |
XDisplayUnlock(); |
1758 |
< |
} |
1759 |
< |
} |
2404 |
> |
handle_palette_changes(); |
2405 |
|
|
2406 |
|
} else { |
2407 |
|
|