1 |
|
/* |
2 |
|
* video_x.cpp - Video/graphics emulation, X11 specific stuff |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2002 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> |
33 |
|
#include <X11/Xutil.h> |
34 |
|
#include <X11/keysym.h> |
35 |
|
#include <X11/extensions/XShm.h> |
36 |
|
#include <sys/ipc.h> |
37 |
|
#include <sys/shm.h> |
38 |
+ |
#include <errno.h> |
39 |
|
#include <pthread.h> |
40 |
|
|
41 |
< |
#include "sysdeps.h" |
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> |
50 |
> |
#endif |
51 |
> |
|
52 |
> |
#ifdef ENABLE_XF86_VIDMODE |
53 |
> |
# include <X11/extensions/xf86vmode.h> |
54 |
> |
#endif |
55 |
> |
|
56 |
|
#include "main.h" |
57 |
|
#include "adb.h" |
58 |
|
#include "prefs.h" |
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 |
< |
#ifdef ENABLE_XF86_DGA |
69 |
< |
#include <X11/extensions/xf86dga.h> |
68 |
> |
#ifndef NO_STD_NAMESPACE |
69 |
> |
using std::sort; |
70 |
|
#endif |
71 |
|
|
45 |
– |
#ifdef ENABLE_XF86_VIDMODE |
46 |
– |
#include <X11/extensions/xf86vmode.h> |
47 |
– |
#endif |
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? |
87 |
|
static volatile bool thread_stop_req = false; |
88 |
|
static volatile bool thread_stop_ack = false; // Acknowledge for thread_stop_req |
89 |
|
|
90 |
|
static bool has_dga = false; // Flag: Video DGA capable |
91 |
|
static bool has_vidmode = false; // Flag: VidMode extension available |
92 |
|
|
93 |
+ |
#ifdef ENABLE_VOSF |
94 |
+ |
static bool use_vosf = true; // Flag: VOSF enabled |
95 |
+ |
#else |
96 |
+ |
static const bool use_vosf = false; // VOSF not possible |
97 |
+ |
#endif |
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 |
106 |
|
static bool emul_suspended = false; // Flag: emulator suspended |
107 |
|
static Window suspend_win; // "Suspend" window |
108 |
|
static void *fb_save = NULL; // Saved frame buffer for suspend |
109 |
+ |
static bool use_keycodes = false; // Flag: Use keycodes rather than keysyms |
110 |
+ |
static int keycode_table[256]; // X keycode -> Mac keycode translation table |
111 |
|
|
112 |
|
// X11 variables |
113 |
|
static int screen; // Screen number |
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; |
141 |
|
static GC cursor_gc, cursor_mask_gc; |
142 |
|
static bool cursor_changed = false; // Flag: Cursor changed, window_func must update cursor |
143 |
|
static bool have_shm = false; // Flag: SHM present and usable |
144 |
< |
static uint8 *the_buffer; // Pointer to Mac frame buffer |
144 |
> |
static uint8 *the_buffer = NULL; // Pointer to Mac frame buffer |
145 |
|
static uint8 *the_buffer_copy = NULL; // Copy of Mac frame buffer |
146 |
+ |
static uint32 the_buffer_size; // Size of allocated the_buffer |
147 |
|
|
148 |
|
// Variables for DGA mode |
149 |
< |
static char *dga_screen_base; |
100 |
< |
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); |
197 |
|
|
198 |
|
|
199 |
< |
// From main_linux.cpp |
199 |
> |
// From main_unix.cpp |
200 |
> |
extern char *x_display_name; |
201 |
|
extern Display *x_display; |
202 |
|
|
203 |
|
// From sys_unix.cpp |
204 |
|
extern void SysMountFirstFloppy(void); |
205 |
|
|
206 |
+ |
// From clip_unix.cpp |
207 |
+ |
extern void ClipboardSelectionClear(XSelectionClearEvent *); |
208 |
+ |
extern void ClipboardSelectionRequest(XSelectionRequestEvent *); |
209 |
+ |
|
210 |
+ |
|
211 |
+ |
// Video acceleration through SIGSEGV |
212 |
+ |
#ifdef ENABLE_VOSF |
213 |
+ |
# include "video_vosf.h" |
214 |
+ |
#endif |
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 *); |
485 |
|
// Open window |
486 |
|
static bool open_window(int width, int height) |
487 |
|
{ |
488 |
+ |
int aligned_width = (width + 15) & ~15; |
489 |
+ |
int aligned_height = (height + 15) & ~15; |
490 |
+ |
|
491 |
|
// Set absolute mouse mode |
492 |
|
ADBSetRelMouseMode(false); |
493 |
|
|
144 |
– |
// Read frame skip prefs |
145 |
– |
frame_skip = PrefsFindInt32("frameskip"); |
146 |
– |
if (frame_skip == 0) |
147 |
– |
frame_skip = 1; |
148 |
– |
|
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 |
< |
|
156 |
< |
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); |
159 |
< |
XSync(x_display, false); |
160 |
< |
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); |
161 |
< |
XMapRaised(x_display, the_win); |
162 |
< |
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); |
532 |
+ |
|
533 |
|
// Try to create and attach SHM image |
534 |
|
have_shm = false; |
535 |
< |
if (depth != 1 && XShmQueryExtension(x_display)) { |
535 |
> |
if (local_X11 && !need_msb_image && XShmQueryExtension(x_display)) { |
536 |
|
|
537 |
|
// Create SHM image ("height + 2" for safety) |
538 |
< |
img = XShmCreateImage(x_display, vis, depth, depth == 1 ? XYBitmap : ZPixmap, 0, &shminfo, width, height); |
539 |
< |
shminfo.shmid = shmget(IPC_PRIVATE, (height + 2) * img->bytes_per_line, IPC_CREAT | 0777); |
540 |
< |
screen_base = (uint32)shmat(shminfo.shmid, 0, 0); |
541 |
< |
the_buffer = (uint8 *)screen_base; |
542 |
< |
shminfo.shmaddr = img->data = (char *)screen_base; |
538 |
> |
img = XShmCreateImage(x_display, vis, depth == 1 ? 1 : xdepth, depth == 1 ? XYBitmap : ZPixmap, 0, &shminfo, width, height); |
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; |
544 |
|
|
545 |
|
// Try to attach SHM image, catching errors |
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 = width; |
565 |
< |
switch (depth) { |
566 |
< |
case 1: |
567 |
< |
bytes_per_row /= 8; |
216 |
< |
break; |
217 |
< |
case 15: |
218 |
< |
case 16: |
219 |
< |
bytes_per_row *= 2; |
220 |
< |
break; |
221 |
< |
case 24: |
222 |
< |
case 32: |
223 |
< |
bytes_per_row *= 4; |
224 |
< |
break; |
225 |
< |
} |
226 |
< |
screen_base = (uint32)malloc((height + 2) * bytes_per_row); |
227 |
< |
the_buffer = (uint8 *)screen_base; |
228 |
< |
img = XCreateImage(x_display, vis, depth, depth == 1 ? XYBitmap : ZPixmap, 0, (char *)screen_base, width, height, 32, bytes_per_row); |
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 |
|
} |
575 |
|
|
576 |
< |
// Allocate memory for frame buffer copy |
577 |
< |
the_buffer_copy = (uint8 *)malloc((height + 2) * img->bytes_per_line); |
576 |
> |
#ifdef ENABLE_VOSF |
577 |
> |
use_vosf = true; |
578 |
> |
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
579 |
> |
the_host_buffer = the_buffer_copy; |
580 |
> |
the_buffer_size = page_extend((aligned_height + 2) * (the_host_buffer_row_bytes = img->bytes_per_line)); |
581 |
> |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
582 |
> |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
583 |
> |
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
584 |
> |
#else |
585 |
> |
// Allocate memory for frame buffer |
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 = 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; |
622 |
> |
#ifdef WORDS_BIGENDIAN |
623 |
> |
native_byte_order = (XImageByteOrder(x_display) == MSBFirst); |
624 |
> |
#else |
625 |
> |
native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
626 |
> |
#endif |
627 |
> |
#ifdef ENABLE_VOSF |
628 |
> |
Screen_blitter_init(visualFormat, native_byte_order, depth); |
629 |
> |
#endif |
630 |
|
|
631 |
|
// Set bytes per row |
259 |
– |
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 |
+ |
|
647 |
+ |
int fb_type = fb_finfo.type; |
648 |
+ |
const char *fb_type_str = NULL; |
649 |
+ |
switch (fb_type) { |
650 |
+ |
case FB_TYPE_PACKED_PIXELS: fb_type_str = "Packed Pixels"; break; |
651 |
+ |
case FB_TYPE_PLANES: fb_type_str = "Non interleaved planes"; break; |
652 |
+ |
case FB_TYPE_INTERLEAVED_PLANES: fb_type_str = "Interleaved planes"; break; |
653 |
+ |
case FB_TYPE_TEXT: fb_type_str = "Text/attributes"; break; |
654 |
+ |
case FB_TYPE_VGA_PLANES: fb_type_str = "EGA/VGA planes"; break; |
655 |
+ |
default: fb_type_str = "<unknown>"; break; |
656 |
+ |
} |
657 |
+ |
D(bug("[fbdev] type: %s\n", fb_type_str)); |
658 |
+ |
|
659 |
+ |
if (fb_type != FB_TYPE_PACKED_PIXELS) { |
660 |
+ |
D(bug("[fbdev] type '%s' not supported\n", fb_type_str)); |
661 |
+ |
return false; |
662 |
+ |
} |
663 |
+ |
|
664 |
+ |
int fb_visual = fb_finfo.visual; |
665 |
+ |
const char *fb_visual_str; |
666 |
+ |
switch (fb_visual) { |
667 |
+ |
case FB_VISUAL_MONO01: fb_visual_str = "Monochrome 1=Black 0=White"; break; |
668 |
+ |
case FB_VISUAL_MONO10: fb_visual_str = "Monochrome 1=While 0=Black"; break; |
669 |
+ |
case FB_VISUAL_TRUECOLOR: fb_visual_str = "True color"; break; |
670 |
+ |
case FB_VISUAL_PSEUDOCOLOR: fb_visual_str = "Pseudo color (like atari)"; break; |
671 |
+ |
case FB_VISUAL_DIRECTCOLOR: fb_visual_str = "Direct color"; break; |
672 |
+ |
case FB_VISUAL_STATIC_PSEUDOCOLOR: fb_visual_str = "Pseudo color readonly"; break; |
673 |
+ |
default: fb_visual_str = "<unknown>"; break; |
674 |
+ |
} |
675 |
+ |
D(bug("[fbdev] visual: %s\n", fb_visual_str)); |
676 |
+ |
|
677 |
+ |
if (fb_visual != FB_VISUAL_TRUECOLOR) { |
678 |
+ |
D(bug("[fbdev] visual '%s' not supported\n", fb_visual_str)); |
679 |
+ |
return false; |
680 |
+ |
} |
681 |
+ |
|
682 |
+ |
// Map frame buffer |
683 |
+ |
the_buffer = (uint8 *)mmap(NULL, fb_finfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb_dev_fd, 0); |
684 |
+ |
if (the_buffer == MAP_FAILED) { |
685 |
+ |
D(bug("[fbdev] Can't mmap /dev/fb0: %s\n", strerror(errno))); |
686 |
+ |
return false; |
687 |
+ |
} |
688 |
+ |
|
689 |
+ |
// Set absolute mouse mode |
690 |
+ |
ADBSetRelMouseMode(false); |
691 |
+ |
|
692 |
+ |
// Create window |
693 |
+ |
XSetWindowAttributes wattr; |
694 |
+ |
wattr.event_mask = eventmask = dga_eventmask; |
695 |
+ |
wattr.override_redirect = True; |
696 |
+ |
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
697 |
+ |
InputOutput, DefaultVisual(x_display, screen), |
698 |
+ |
CWEventMask | CWOverrideRedirect, &wattr); |
699 |
+ |
|
700 |
+ |
// Show window |
701 |
+ |
XMapRaised(x_display, the_win); |
702 |
+ |
wait_mapped(the_win); |
703 |
+ |
|
704 |
+ |
// Grab mouse and keyboard |
705 |
+ |
XGrabKeyboard(x_display, the_win, True, |
706 |
+ |
GrabModeAsync, GrabModeAsync, CurrentTime); |
707 |
+ |
XGrabPointer(x_display, the_win, True, |
708 |
+ |
PointerMotionMask | ButtonPressMask | ButtonReleaseMask, |
709 |
+ |
GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
710 |
+ |
disable_mouse_accel(); |
711 |
+ |
|
712 |
+ |
// Create no_cursor |
713 |
+ |
mac_cursor = XCreatePixmapCursor(x_display, |
714 |
+ |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
715 |
+ |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
716 |
+ |
&black, &white, 0, 0); |
717 |
+ |
XDefineCursor(x_display, the_win, mac_cursor); |
718 |
+ |
|
719 |
+ |
// Init blitting routines |
720 |
+ |
#if ENABLE_VOSF |
721 |
+ |
// Extract current screen color masks (we are in True Color mode) |
722 |
+ |
VisualFormat visualFormat; |
723 |
+ |
visualFormat.depth = xdepth = DefaultDepth(x_display, screen); |
724 |
+ |
XMatchVisualInfo(x_display, screen, xdepth, TrueColor, &visualInfo); |
725 |
+ |
assert(visualFormat.depth == visualInfo.depth); |
726 |
+ |
visualFormat.Rmask = visualInfo.red_mask; |
727 |
+ |
visualFormat.Gmask = visualInfo.green_mask; |
728 |
+ |
visualFormat.Bmask = visualInfo.blue_mask; |
729 |
+ |
D(bug("[fbdev] %d bpp, (%08x,%08x,%08x)\n", |
730 |
+ |
visualFormat.depth, |
731 |
+ |
visualFormat.Rmask, visualFormat.Gmask, visualFormat.Bmask)); |
732 |
+ |
D(bug("[fbdev] Mac depth %d bpp\n", depth)); |
733 |
+ |
|
734 |
+ |
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
735 |
+ |
// i.e. the framebuffer update function is not Blit_Copy_Raw |
736 |
+ |
#ifdef WORDS_BIGENDIAN |
737 |
+ |
const bool native_byte_order = (XImageByteOrder(x_display) == MSBFirst); |
738 |
+ |
#else |
739 |
+ |
const bool native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
740 |
+ |
#endif |
741 |
+ |
Screen_blitter_init(visualFormat, native_byte_order, depth); |
742 |
+ |
|
743 |
+ |
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
744 |
+ |
use_vosf = true; |
745 |
+ |
the_host_buffer = the_buffer; |
746 |
+ |
the_host_buffer_row_bytes = TrivialBytesPerRow((width + 7) & ~7, DepthModeForPixelDepth(visualFormat.depth)); |
747 |
+ |
the_buffer_size = page_extend((height + 2) * the_host_buffer_row_bytes); |
748 |
+ |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
749 |
+ |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
750 |
+ |
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
751 |
+ |
#endif |
752 |
+ |
|
753 |
+ |
// Set frame buffer base |
754 |
+ |
D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); |
755 |
+ |
screen_base = Host2MacAddr(the_buffer); |
756 |
+ |
VModes[cur_mode].viRowBytes = TrivialBytesPerRow((width + 7) & ~7, DepthModeForPixelDepth(depth)); |
757 |
+ |
return true; |
758 |
+ |
#else |
759 |
+ |
ErrorAlert("SheepShaver has been compiled with DGA support disabled."); |
760 |
+ |
return false; |
761 |
+ |
#endif |
762 |
+ |
} |
763 |
+ |
|
764 |
|
// Open DGA display (!! should use X11 VidMode extensions to set mode) |
765 |
|
static bool open_dga(int width, int height) |
766 |
|
{ |
767 |
+ |
if (is_fbdev_dga_mode) |
768 |
+ |
return false; |
769 |
+ |
|
770 |
|
#ifdef ENABLE_XF86_DGA |
771 |
|
// Set relative mouse mode |
772 |
|
ADBSetRelMouseMode(true); |
773 |
|
|
774 |
+ |
// Create window |
775 |
+ |
XSetWindowAttributes wattr; |
776 |
+ |
wattr.event_mask = eventmask = dga_eventmask; |
777 |
+ |
wattr.override_redirect = True; |
778 |
+ |
wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); |
779 |
+ |
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
780 |
+ |
InputOutput, vis, CWEventMask | CWOverrideRedirect | |
781 |
+ |
(color_class == DirectColor ? CWColormap : 0), &wattr); |
782 |
+ |
|
783 |
+ |
// Show window |
784 |
+ |
XMapRaised(x_display, the_win); |
785 |
+ |
wait_mapped(the_win); |
786 |
+ |
|
787 |
|
#ifdef ENABLE_XF86_VIDMODE |
788 |
|
// Switch to best mode |
789 |
|
if (has_vidmode) { |
800 |
|
#endif |
801 |
|
|
802 |
|
// Establish direct screen connection |
803 |
+ |
XMoveResizeWindow(x_display, the_win, 0, 0, width, height); |
804 |
+ |
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
805 |
|
XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
806 |
|
XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
807 |
+ |
|
808 |
+ |
int v_width, v_bank, v_size; |
809 |
+ |
XF86DGAGetVideo(x_display, screen, (char **)&the_buffer, &v_width, &v_bank, &v_size); |
810 |
|
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
811 |
|
XF86DGASetViewPort(x_display, screen, 0, 0); |
812 |
|
XF86DGASetVidPage(x_display, screen, 0); |
292 |
– |
screen_base = (uint32)dga_screen_base; |
813 |
|
|
814 |
|
// Set colormap |
815 |
< |
if (depth == 8) |
815 |
> |
if (!IsDirectMode(get_current_mode())) { |
816 |
> |
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); |
817 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
818 |
+ |
} |
819 |
+ |
XSync(x_display, false); |
820 |
|
|
821 |
< |
// Set bytes per row |
822 |
< |
int bytes_per_row = (dga_fb_width + 7) & ~7; |
823 |
< |
switch (depth) { |
824 |
< |
case 15: |
825 |
< |
case 16: |
826 |
< |
bytes_per_row *= 2; |
827 |
< |
break; |
828 |
< |
case 24: |
829 |
< |
case 32: |
830 |
< |
bytes_per_row *= 4; |
831 |
< |
break; |
821 |
> |
// Init blitting routines |
822 |
> |
int bytes_per_row = TrivialBytesPerRow((v_width + 7) & ~7, DepthModeForPixelDepth(depth)); |
823 |
> |
#if ENABLE_VOSF |
824 |
> |
bool native_byte_order; |
825 |
> |
#ifdef WORDS_BIGENDIAN |
826 |
> |
native_byte_order = (XImageByteOrder(x_display) == MSBFirst); |
827 |
> |
#else |
828 |
> |
native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
829 |
> |
#endif |
830 |
> |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
831 |
> |
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
832 |
> |
// i.e. the framebuffer update function is not Blit_Copy_Raw |
833 |
> |
use_vosf = Screen_blitter_init(visualFormat, native_byte_order, depth); |
834 |
> |
|
835 |
> |
if (use_vosf) { |
836 |
> |
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
837 |
> |
the_host_buffer = the_buffer; |
838 |
> |
the_buffer_size = page_extend((height + 2) * (the_host_buffer_row_bytes = bytes_per_row)); |
839 |
> |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
840 |
> |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
841 |
> |
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
842 |
|
} |
843 |
+ |
#else |
844 |
+ |
use_vosf = false; |
845 |
+ |
#endif |
846 |
+ |
#endif |
847 |
+ |
|
848 |
+ |
// Set frame buffer base |
849 |
+ |
D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); |
850 |
+ |
screen_base = Host2MacAddr(the_buffer); |
851 |
|
VModes[cur_mode].viRowBytes = bytes_per_row; |
311 |
– |
XSync(x_display, false); |
852 |
|
return true; |
853 |
|
#else |
854 |
|
ErrorAlert("SheepShaver has been compiled with DGA support disabled."); |
858 |
|
|
859 |
|
static bool open_display(void) |
860 |
|
{ |
861 |
< |
display_type = VModes[cur_mode].viType; |
862 |
< |
switch (VModes[cur_mode].viAppleMode) { |
863 |
< |
case APPLE_1_BIT: |
864 |
< |
depth = 1; |
865 |
< |
break; |
866 |
< |
case APPLE_2_BIT: |
867 |
< |
depth = 2; |
868 |
< |
break; |
869 |
< |
case APPLE_4_BIT: |
870 |
< |
depth = 4; |
871 |
< |
break; |
872 |
< |
case APPLE_8_BIT: |
873 |
< |
depth = 8; |
874 |
< |
break; |
875 |
< |
case APPLE_16_BIT: |
876 |
< |
depth = xdepth == 15 ? 15 : 16; |
877 |
< |
break; |
878 |
< |
case APPLE_32_BIT: |
879 |
< |
depth = 32; |
880 |
< |
break; |
861 |
> |
D(bug("open_display()\n")); |
862 |
> |
const VideoInfo &mode = VModes[cur_mode]; |
863 |
> |
|
864 |
> |
// Get original mouse acceleration |
865 |
> |
XGetPointerControl(x_display, &orig_accel_numer, &orig_accel_denom, &orig_threshold); |
866 |
> |
|
867 |
> |
// Find best available X visual |
868 |
> |
if (!find_visual_for_depth(mode.viAppleMode)) { |
869 |
> |
ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); |
870 |
> |
return false; |
871 |
> |
} |
872 |
> |
|
873 |
> |
// Build up visualFormat structure |
874 |
> |
visualFormat.fullscreen = (display_type == DIS_SCREEN); |
875 |
> |
visualFormat.depth = visualInfo.depth; |
876 |
> |
visualFormat.Rmask = visualInfo.red_mask; |
877 |
> |
visualFormat.Gmask = visualInfo.green_mask; |
878 |
> |
visualFormat.Bmask = visualInfo.blue_mask; |
879 |
> |
|
880 |
> |
// Create color maps |
881 |
> |
if (color_class == PseudoColor || color_class == DirectColor) { |
882 |
> |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
883 |
> |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
884 |
> |
} else { |
885 |
> |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocNone); |
886 |
> |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocNone); |
887 |
> |
} |
888 |
> |
|
889 |
> |
// Find pixel format of direct modes |
890 |
> |
if (color_class == DirectColor || color_class == TrueColor) { |
891 |
> |
rshift = gshift = bshift = 0; |
892 |
> |
rloss = gloss = bloss = 8; |
893 |
> |
uint32 mask; |
894 |
> |
for (mask=vis->red_mask; !(mask&1); mask>>=1) |
895 |
> |
++rshift; |
896 |
> |
for (; mask&1; mask>>=1) |
897 |
> |
--rloss; |
898 |
> |
for (mask=vis->green_mask; !(mask&1); mask>>=1) |
899 |
> |
++gshift; |
900 |
> |
for (; mask&1; mask>>=1) |
901 |
> |
--gloss; |
902 |
> |
for (mask=vis->blue_mask; !(mask&1); mask>>=1) |
903 |
> |
++bshift; |
904 |
> |
for (; mask&1; mask>>=1) |
905 |
> |
--bloss; |
906 |
> |
} |
907 |
> |
|
908 |
> |
// Preset palette pixel values for CLUT or gamma table |
909 |
> |
if (color_class == DirectColor) { |
910 |
> |
int num = vis->map_entries; |
911 |
> |
for (int i=0; i<num; i++) { |
912 |
> |
int c = (i * 256) / num; |
913 |
> |
x_palette[i].pixel = map_rgb(c, c, c); |
914 |
> |
x_palette[i].flags = DoRed | DoGreen | DoBlue; |
915 |
> |
} |
916 |
> |
} else if (color_class == PseudoColor) { |
917 |
> |
for (int i=0; i<256; i++) { |
918 |
> |
x_palette[i].pixel = i; |
919 |
> |
x_palette[i].flags = DoRed | DoGreen | DoBlue; |
920 |
> |
} |
921 |
> |
} |
922 |
> |
|
923 |
> |
// Load gray ramp to color map |
924 |
> |
int num = (color_class == DirectColor ? vis->map_entries : 256); |
925 |
> |
for (int i=0; i<num; i++) { |
926 |
> |
int c = (i * 256) / num; |
927 |
> |
x_palette[i].red = c * 0x0101; |
928 |
> |
x_palette[i].green = c * 0x0101; |
929 |
> |
x_palette[i].blue = c * 0x0101; |
930 |
> |
} |
931 |
> |
if (color_class == PseudoColor || color_class == DirectColor) { |
932 |
> |
XStoreColors(x_display, cmap[0], x_palette, num); |
933 |
> |
XStoreColors(x_display, cmap[1], x_palette, num); |
934 |
> |
} |
935 |
> |
|
936 |
> |
#ifdef ENABLE_VOSF |
937 |
> |
// Load gray ramp to 8->16/32 expand map |
938 |
> |
if (!IsDirectMode(get_current_mode()) && xdepth > 8) |
939 |
> |
for (int i=0; i<256; i++) |
940 |
> |
ExpandMap[i] = map_rgb(i, i, i); |
941 |
> |
#endif |
942 |
> |
|
943 |
> |
// Create display of requested type |
944 |
> |
display_type = mode.viType; |
945 |
> |
depth = depth_of_video_mode(mode.viAppleMode); |
946 |
> |
|
947 |
> |
bool display_open = false; |
948 |
> |
if (display_type == DIS_SCREEN) { |
949 |
> |
display_open = open_dga(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
950 |
> |
#ifdef ENABLE_FBDEV_DGA |
951 |
> |
// Try to fallback to FBDev DGA mode |
952 |
> |
if (!display_open) { |
953 |
> |
is_fbdev_dga_mode = true; |
954 |
> |
display_open = open_fbdev(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
955 |
> |
} |
956 |
> |
#endif |
957 |
> |
|
958 |
|
} |
342 |
– |
if (display_type == DIS_SCREEN) |
343 |
– |
return open_dga(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
959 |
|
else if (display_type == DIS_WINDOW) |
960 |
< |
return open_window(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
961 |
< |
else |
962 |
< |
return false; |
960 |
> |
display_open = open_window(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
961 |
> |
|
962 |
> |
#ifdef ENABLE_VOSF |
963 |
> |
if (use_vosf) { |
964 |
> |
// Initialize the VOSF system |
965 |
> |
LOCK_VOSF; |
966 |
> |
if (!video_vosf_init()) { |
967 |
> |
ErrorAlert(GetString(STR_VOSF_INIT_ERR)); |
968 |
> |
UNLOCK_VOSF; |
969 |
> |
return false; |
970 |
> |
} |
971 |
> |
UNLOCK_VOSF; |
972 |
> |
} |
973 |
> |
#endif |
974 |
> |
|
975 |
> |
// Zero screen buffers, viRowBytes is initialized at this stage |
976 |
> |
memset(the_buffer, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
977 |
> |
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
978 |
> |
return display_open; |
979 |
|
} |
980 |
|
|
981 |
|
|
986 |
|
// Close window |
987 |
|
static void close_window(void) |
988 |
|
{ |
989 |
< |
// Close window |
990 |
< |
XDestroyWindow(x_display, the_win); |
989 |
> |
if (have_shm) { |
990 |
> |
XShmDetach(x_display, &shminfo); |
991 |
> |
#ifdef ENABLE_VOSF |
992 |
> |
the_host_buffer = NULL; // don't free() in driver_base dtor |
993 |
> |
#else |
994 |
> |
the_buffer_copy = NULL; // don't free() in driver_base dtor |
995 |
> |
#endif |
996 |
> |
} |
997 |
> |
if (img) { |
998 |
> |
if (!have_shm) |
999 |
> |
img->data = NULL; |
1000 |
> |
XDestroyImage(img); |
1001 |
> |
} |
1002 |
> |
if (have_shm) { |
1003 |
> |
shmdt(shminfo.shmaddr); |
1004 |
> |
shmctl(shminfo.shmid, IPC_RMID, 0); |
1005 |
> |
} |
1006 |
> |
if (the_gc) |
1007 |
> |
XFreeGC(x_display, the_gc); |
1008 |
> |
|
1009 |
> |
XFlush(x_display); |
1010 |
> |
XSync(x_display, false); |
1011 |
> |
} |
1012 |
> |
|
1013 |
> |
// Close FBDev mode |
1014 |
> |
static void close_fbdev(void) |
1015 |
> |
{ |
1016 |
> |
#ifdef ENABLE_FBDEV_DGA |
1017 |
> |
XUngrabPointer(x_display, CurrentTime); |
1018 |
> |
XUngrabKeyboard(x_display, CurrentTime); |
1019 |
|
|
1020 |
< |
// Close frame buffer copy |
1021 |
< |
if (the_buffer_copy) { |
1022 |
< |
free(the_buffer_copy); |
1023 |
< |
the_buffer_copy = NULL; |
1020 |
> |
uint8 *fb_base; |
1021 |
> |
if (!use_vosf) { |
1022 |
> |
// don't free() the screen buffer in driver_base dtor |
1023 |
> |
fb_base = the_buffer; |
1024 |
> |
the_buffer = NULL; |
1025 |
> |
} |
1026 |
> |
#ifdef ENABLE_VOSF |
1027 |
> |
else { |
1028 |
> |
// don't free() the screen buffer in driver_base dtor |
1029 |
> |
fb_base = the_host_buffer; |
1030 |
> |
the_host_buffer = NULL; |
1031 |
|
} |
1032 |
+ |
#endif |
1033 |
+ |
munmap(fb_base, fb_finfo.smem_len); |
1034 |
+ |
#endif |
1035 |
|
} |
1036 |
|
|
1037 |
|
// Close DGA mode |
1038 |
|
static void close_dga(void) |
1039 |
|
{ |
1040 |
+ |
if (is_fbdev_dga_mode) |
1041 |
+ |
return; |
1042 |
+ |
|
1043 |
|
#ifdef ENABLE_XF86_DGA |
1044 |
|
XF86DGADirectVideo(x_display, screen, 0); |
1045 |
|
XUngrabPointer(x_display, CurrentTime); |
1050 |
|
if (has_vidmode) |
1051 |
|
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[0]); |
1052 |
|
#endif |
1053 |
+ |
|
1054 |
+ |
if (!use_vosf) { |
1055 |
+ |
// don't free() the screen buffer in driver_base dtor |
1056 |
+ |
the_buffer = NULL; |
1057 |
+ |
} |
1058 |
+ |
#ifdef ENABLE_VOSF |
1059 |
+ |
else { |
1060 |
+ |
// don't free() the screen buffer in driver_base dtor |
1061 |
+ |
the_host_buffer = NULL; |
1062 |
+ |
} |
1063 |
+ |
#endif |
1064 |
|
} |
1065 |
|
|
1066 |
|
static void close_display(void) |
1067 |
|
{ |
1068 |
< |
if (display_type == DIS_SCREEN) |
1069 |
< |
close_dga(); |
1068 |
> |
if (display_type == DIS_SCREEN) { |
1069 |
> |
if (is_fbdev_dga_mode) |
1070 |
> |
close_fbdev(); |
1071 |
> |
else |
1072 |
> |
close_dga(); |
1073 |
> |
} |
1074 |
|
else if (display_type == DIS_WINDOW) |
1075 |
|
close_window(); |
1076 |
+ |
|
1077 |
+ |
// Close window |
1078 |
+ |
if (the_win) { |
1079 |
+ |
XUnmapWindow(x_display, the_win); |
1080 |
+ |
wait_unmapped(the_win); |
1081 |
+ |
XDestroyWindow(x_display, the_win); |
1082 |
+ |
} |
1083 |
+ |
|
1084 |
+ |
// Free colormaps |
1085 |
+ |
if (cmap[0]) { |
1086 |
+ |
XFreeColormap(x_display, cmap[0]); |
1087 |
+ |
cmap[0] = 0; |
1088 |
+ |
} |
1089 |
+ |
if (cmap[1]) { |
1090 |
+ |
XFreeColormap(x_display, cmap[1]); |
1091 |
+ |
cmap[1] = 0; |
1092 |
+ |
} |
1093 |
+ |
|
1094 |
+ |
#ifdef ENABLE_VOSF |
1095 |
+ |
if (use_vosf) { |
1096 |
+ |
// Deinitialize VOSF |
1097 |
+ |
video_vosf_exit(); |
1098 |
+ |
} |
1099 |
+ |
#endif |
1100 |
+ |
|
1101 |
+ |
// Free frame buffer(s) |
1102 |
+ |
if (!use_vosf) { |
1103 |
+ |
if (the_buffer_copy) { |
1104 |
+ |
free(the_buffer_copy); |
1105 |
+ |
the_buffer_copy = NULL; |
1106 |
+ |
} |
1107 |
+ |
} |
1108 |
+ |
#ifdef ENABLE_VOSF |
1109 |
+ |
else { |
1110 |
+ |
// the_buffer shall always be mapped through vm_acquire() so that we can vm_protect() it at will |
1111 |
+ |
if (the_buffer != VM_MAP_FAILED) { |
1112 |
+ |
D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size)); |
1113 |
+ |
vm_release(the_buffer, the_buffer_size); |
1114 |
+ |
the_buffer = NULL; |
1115 |
+ |
} |
1116 |
+ |
if (the_host_buffer) { |
1117 |
+ |
D(bug(" freeing the_host_buffer at %p\n", the_host_buffer)); |
1118 |
+ |
free(the_host_buffer); |
1119 |
+ |
the_host_buffer = NULL; |
1120 |
+ |
} |
1121 |
+ |
if (the_buffer_copy) { |
1122 |
+ |
D(bug(" freeing the_buffer_copy at %p\n", the_buffer_copy)); |
1123 |
+ |
free(the_buffer_copy); |
1124 |
+ |
the_buffer_copy = NULL; |
1125 |
+ |
} |
1126 |
+ |
} |
1127 |
+ |
#endif |
1128 |
+ |
|
1129 |
+ |
// Restore mouse acceleration |
1130 |
+ |
restore_mouse_accel(); |
1131 |
|
} |
1132 |
|
|
1133 |
|
|
1135 |
|
* Initialization |
1136 |
|
*/ |
1137 |
|
|
1138 |
< |
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, long apple_mode, long apple_id, int type) |
1138 |
> |
// Init keycode translation table |
1139 |
> |
static void keycode_init(void) |
1140 |
> |
{ |
1141 |
> |
bool use_kc = PrefsFindBool("keycodes"); |
1142 |
> |
if (use_kc) { |
1143 |
> |
|
1144 |
> |
// Get keycode file path from preferences |
1145 |
> |
const char *kc_path = PrefsFindString("keycodefile"); |
1146 |
> |
|
1147 |
> |
// Open keycode table |
1148 |
> |
FILE *f = fopen(kc_path ? kc_path : KEYCODE_FILE_NAME, "r"); |
1149 |
> |
if (f == NULL) { |
1150 |
> |
char str[256]; |
1151 |
> |
sprintf(str, GetString(STR_KEYCODE_FILE_WARN), kc_path ? kc_path : KEYCODE_FILE_NAME, strerror(errno)); |
1152 |
> |
WarningAlert(str); |
1153 |
> |
return; |
1154 |
> |
} |
1155 |
> |
|
1156 |
> |
// Default translation table |
1157 |
> |
for (int i=0; i<256; i++) |
1158 |
> |
keycode_table[i] = -1; |
1159 |
> |
|
1160 |
> |
// Search for server vendor string, then read keycodes |
1161 |
> |
const char *vendor = ServerVendor(x_display); |
1162 |
> |
// Force use of MacX mappings on MacOS X with Apple's X server |
1163 |
> |
int dummy; |
1164 |
> |
if (XQueryExtension(x_display, "Apple-DRI", &dummy, &dummy, &dummy)) |
1165 |
> |
vendor = "MacX"; |
1166 |
> |
bool vendor_found = false; |
1167 |
> |
char line[256]; |
1168 |
> |
while (fgets(line, 255, f)) { |
1169 |
> |
// Read line |
1170 |
> |
int len = strlen(line); |
1171 |
> |
if (len == 0) |
1172 |
> |
continue; |
1173 |
> |
line[len-1] = 0; |
1174 |
> |
|
1175 |
> |
// Comments begin with "#" or ";" |
1176 |
> |
if (line[0] == '#' || line[0] == ';' || line[0] == 0) |
1177 |
> |
continue; |
1178 |
> |
|
1179 |
> |
if (vendor_found) { |
1180 |
> |
// Read keycode |
1181 |
> |
int x_code, mac_code; |
1182 |
> |
if (sscanf(line, "%d %d", &x_code, &mac_code) == 2) |
1183 |
> |
keycode_table[x_code & 0xff] = mac_code; |
1184 |
> |
else |
1185 |
> |
break; |
1186 |
> |
} else { |
1187 |
> |
// Search for vendor string |
1188 |
> |
if (strstr(vendor, line) == vendor) |
1189 |
> |
vendor_found = true; |
1190 |
> |
} |
1191 |
> |
} |
1192 |
> |
|
1193 |
> |
// Keycode file completely read |
1194 |
> |
fclose(f); |
1195 |
> |
use_keycodes = vendor_found; |
1196 |
> |
|
1197 |
> |
// Vendor not found? Then display warning |
1198 |
> |
if (!vendor_found) { |
1199 |
> |
char str[256]; |
1200 |
> |
sprintf(str, GetString(STR_KEYCODE_VENDOR_WARN), vendor, kc_path ? kc_path : KEYCODE_FILE_NAME); |
1201 |
> |
WarningAlert(str); |
1202 |
> |
return; |
1203 |
> |
} |
1204 |
> |
} |
1205 |
> |
} |
1206 |
> |
|
1207 |
> |
// Find Apple mode matching best specified dimensions |
1208 |
> |
static int find_apple_resolution(int xsize, int ysize) |
1209 |
> |
{ |
1210 |
> |
int apple_id; |
1211 |
> |
if (xsize < 800) |
1212 |
> |
apple_id = APPLE_640x480; |
1213 |
> |
else if (xsize < 1024) |
1214 |
> |
apple_id = APPLE_800x600; |
1215 |
> |
else if (xsize < 1152) |
1216 |
> |
apple_id = APPLE_1024x768; |
1217 |
> |
else if (xsize < 1280) { |
1218 |
> |
if (ysize < 900) |
1219 |
> |
apple_id = APPLE_1152x768; |
1220 |
> |
else |
1221 |
> |
apple_id = APPLE_1152x900; |
1222 |
> |
} |
1223 |
> |
else if (xsize < 1600) |
1224 |
> |
apple_id = APPLE_1280x1024; |
1225 |
> |
else |
1226 |
> |
apple_id = APPLE_1600x1200; |
1227 |
> |
return apple_id; |
1228 |
> |
} |
1229 |
> |
|
1230 |
> |
// Find mode in list of supported modes |
1231 |
> |
static int find_mode(int apple_mode, int apple_id, int type) |
1232 |
> |
{ |
1233 |
> |
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
1234 |
> |
if (p->viType == type && p->viAppleID == apple_id && p->viAppleMode == apple_mode) |
1235 |
> |
return p - VModes; |
1236 |
> |
} |
1237 |
> |
return -1; |
1238 |
> |
} |
1239 |
> |
|
1240 |
> |
// Add custom video mode |
1241 |
> |
static void add_custom_mode(VideoInfo *&p, int type, uint32 x, uint32 y, int apple_mode, int apple_id) |
1242 |
> |
{ |
1243 |
> |
p->viType = type; |
1244 |
> |
p->viXsize = x; |
1245 |
> |
p->viYsize = y; |
1246 |
> |
p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); |
1247 |
> |
p->viAppleMode = apple_mode; |
1248 |
> |
p->viAppleID = apple_id; |
1249 |
> |
p++; |
1250 |
> |
} |
1251 |
> |
|
1252 |
> |
// Add mode to list of supported modes |
1253 |
> |
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type) |
1254 |
|
{ |
1255 |
|
if (allow & test) { |
1256 |
< |
p->viType = type; |
1256 |
> |
uint32 x = 0, y = 0; |
1257 |
|
switch (apple_id) { |
1258 |
|
case APPLE_W_640x480: |
1259 |
|
case APPLE_640x480: |
1260 |
< |
p->viXsize = 640; |
1261 |
< |
p->viYsize = 480; |
1260 |
> |
x = 640; |
1261 |
> |
y = 480; |
1262 |
|
break; |
1263 |
|
case APPLE_W_800x600: |
1264 |
|
case APPLE_800x600: |
1265 |
< |
p->viXsize = 800; |
1266 |
< |
p->viYsize = 600; |
1265 |
> |
x = 800; |
1266 |
> |
y = 600; |
1267 |
|
break; |
1268 |
|
case APPLE_1024x768: |
1269 |
< |
p->viXsize = 1024; |
1270 |
< |
p->viYsize = 768; |
1269 |
> |
x = 1024; |
1270 |
> |
y = 768; |
1271 |
> |
break; |
1272 |
> |
case APPLE_1152x768: |
1273 |
> |
x = 1152; |
1274 |
> |
y = 768; |
1275 |
|
break; |
1276 |
|
case APPLE_1152x900: |
1277 |
< |
p->viXsize = 1152; |
1278 |
< |
p->viYsize = 900; |
1277 |
> |
x = 1152; |
1278 |
> |
y = 900; |
1279 |
|
break; |
1280 |
|
case APPLE_1280x1024: |
1281 |
< |
p->viXsize = 1280; |
1282 |
< |
p->viYsize = 1024; |
1281 |
> |
x = 1280; |
1282 |
> |
y = 1024; |
1283 |
|
break; |
1284 |
|
case APPLE_1600x1200: |
1285 |
< |
p->viXsize = 1600; |
1286 |
< |
p->viYsize = 1200; |
1285 |
> |
x = 1600; |
1286 |
> |
y = 1200; |
1287 |
|
break; |
1288 |
|
} |
1289 |
< |
switch (apple_mode) { |
429 |
< |
case APPLE_8_BIT: |
430 |
< |
p->viRowBytes = p->viXsize; |
431 |
< |
break; |
432 |
< |
case APPLE_16_BIT: |
433 |
< |
p->viRowBytes = p->viXsize * 2; |
434 |
< |
break; |
435 |
< |
case APPLE_32_BIT: |
436 |
< |
p->viRowBytes = p->viXsize * 4; |
437 |
< |
break; |
438 |
< |
} |
439 |
< |
p->viAppleMode = apple_mode; |
440 |
< |
p->viAppleID = apple_id; |
441 |
< |
p++; |
1289 |
> |
add_custom_mode(p, type, x, y, apple_mode, apple_id); |
1290 |
|
} |
1291 |
|
} |
1292 |
|
|
1293 |
+ |
// Add standard list of windowed modes for given color depth |
1294 |
+ |
static void add_window_modes(VideoInfo *&p, int window_modes, int mode) |
1295 |
+ |
{ |
1296 |
+ |
add_mode(p, window_modes, 1, mode, APPLE_W_640x480, DIS_WINDOW); |
1297 |
+ |
add_mode(p, window_modes, 2, mode, APPLE_W_800x600, DIS_WINDOW); |
1298 |
+ |
} |
1299 |
+ |
|
1300 |
|
static bool has_mode(int x, int y) |
1301 |
|
{ |
1302 |
|
#ifdef ENABLE_XF86_VIDMODE |
1311 |
|
|
1312 |
|
bool VideoInit(void) |
1313 |
|
{ |
1314 |
+ |
#ifdef ENABLE_VOSF |
1315 |
+ |
// Zero the mainBuffer structure |
1316 |
+ |
mainBuffer.dirtyPages = NULL; |
1317 |
+ |
mainBuffer.pageInfo = NULL; |
1318 |
+ |
#endif |
1319 |
+ |
|
1320 |
+ |
// Check if X server runs on local machine |
1321 |
+ |
local_X11 = (strncmp(XDisplayName(x_display_name), ":", 1) == 0) |
1322 |
+ |
|| (strncmp(XDisplayName(x_display_name), "unix:", 5) == 0); |
1323 |
+ |
|
1324 |
+ |
// Init keycode translation |
1325 |
+ |
keycode_init(); |
1326 |
+ |
|
1327 |
+ |
// Read frame skip prefs |
1328 |
+ |
frame_skip = PrefsFindInt32("frameskip"); |
1329 |
+ |
if (frame_skip == 0) |
1330 |
+ |
frame_skip = 1; |
1331 |
+ |
|
1332 |
+ |
// Read mouse wheel prefs |
1333 |
+ |
mouse_wheel_mode = PrefsFindInt32("mousewheelmode"); |
1334 |
+ |
mouse_wheel_lines = PrefsFindInt32("mousewheellines"); |
1335 |
+ |
|
1336 |
|
// Init variables |
1337 |
|
private_data = NULL; |
461 |
– |
cur_mode = 0; // Window 640x480 |
1338 |
|
video_activated = true; |
1339 |
|
|
1340 |
|
// Find screen and root window |
1341 |
|
screen = XDefaultScreen(x_display); |
1342 |
|
rootwin = XRootWindow(x_display, screen); |
1343 |
|
|
1344 |
+ |
// Get sorted list of available depths |
1345 |
+ |
avail_depths = XListDepths(x_display, screen, &num_depths); |
1346 |
+ |
if (avail_depths == NULL) { |
1347 |
+ |
ErrorAlert(GetString(STR_UNSUPP_DEPTH_ERR)); |
1348 |
+ |
return false; |
1349 |
+ |
} |
1350 |
+ |
sort(avail_depths, avail_depths + num_depths); |
1351 |
+ |
|
1352 |
|
// Get screen depth |
1353 |
|
xdepth = DefaultDepth(x_display, screen); |
1354 |
|
|
1355 |
|
#ifdef ENABLE_XF86_DGA |
1356 |
|
// DGA available? |
1357 |
|
int event_base, error_base; |
1358 |
< |
if (XF86DGAQueryExtension(x_display, &event_base, &error_base)) { |
1358 |
> |
is_fbdev_dga_mode = false; |
1359 |
> |
if (local_X11 && XF86DGAQueryExtension(x_display, &event_base, &error_base)) { |
1360 |
|
int dga_flags = 0; |
1361 |
|
XF86DGAQueryDirectVideo(x_display, screen, &dga_flags); |
1362 |
|
has_dga = dga_flags & XF86DGADirectPresent; |
1363 |
+ |
#if defined(__linux__) |
1364 |
+ |
// Check r/w permission on /dev/mem for DGA mode to work |
1365 |
+ |
if (has_dga && access("/dev/mem", R_OK | W_OK) != 0) |
1366 |
+ |
has_dga = false; |
1367 |
+ |
#endif |
1368 |
|
} else |
1369 |
|
has_dga = false; |
1370 |
|
#endif |
1377 |
|
XF86VidModeGetAllModeLines(x_display, screen, &num_x_video_modes, &x_video_modes); |
1378 |
|
#endif |
1379 |
|
|
1380 |
+ |
#ifdef ENABLE_FBDEV_DGA |
1381 |
+ |
// FBDev available? |
1382 |
+ |
bool has_fbdev_dga = false; |
1383 |
+ |
if (local_X11) { |
1384 |
+ |
if ((fb_dev_fd = open("/dev/fb0", O_RDWR)) > 0) { |
1385 |
+ |
if (ioctl(fb_dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo) != 0) |
1386 |
+ |
close(fb_dev_fd); |
1387 |
+ |
else { |
1388 |
+ |
has_fbdev_dga = true; |
1389 |
+ |
if (!has_dga) { |
1390 |
+ |
// Fallback to FBDev DGA mode if XF86 DGA is not possible |
1391 |
+ |
has_dga = true; |
1392 |
+ |
is_fbdev_dga_mode = true; |
1393 |
+ |
} |
1394 |
+ |
fb_orig_vinfo = fb_vinfo; |
1395 |
+ |
D(bug("Frame buffer device initial resolution: %dx%dx%d\n", fb_vinfo.xres, fb_vinfo.yres, fb_vinfo.bits_per_pixel)); |
1396 |
+ |
} |
1397 |
+ |
} |
1398 |
+ |
} |
1399 |
+ |
#endif |
1400 |
+ |
|
1401 |
|
// Find black and white colors |
1402 |
|
XParseColor(x_display, DefaultColormap(x_display, screen), "rgb:00/00/00", &black); |
1403 |
|
XAllocColor(x_display, DefaultColormap(x_display, screen), &black); |
1406 |
|
black_pixel = BlackPixel(x_display, screen); |
1407 |
|
white_pixel = WhitePixel(x_display, screen); |
1408 |
|
|
498 |
– |
// Get appropriate visual |
499 |
– |
int color_class; |
500 |
– |
switch (xdepth) { |
501 |
– |
#if 0 |
502 |
– |
case 1: |
503 |
– |
color_class = StaticGray; |
504 |
– |
break; |
505 |
– |
#endif |
506 |
– |
case 8: |
507 |
– |
color_class = PseudoColor; |
508 |
– |
break; |
509 |
– |
case 15: |
510 |
– |
case 16: |
511 |
– |
case 24: |
512 |
– |
case 32: |
513 |
– |
color_class = TrueColor; |
514 |
– |
break; |
515 |
– |
default: |
516 |
– |
ErrorAlert(GetString(STR_UNSUPP_DEPTH_ERR)); |
517 |
– |
return false; |
518 |
– |
} |
519 |
– |
if (!XMatchVisualInfo(x_display, screen, xdepth, color_class, &visualInfo)) { |
520 |
– |
ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); |
521 |
– |
return false; |
522 |
– |
} |
523 |
– |
if (visualInfo.depth != xdepth) { |
524 |
– |
ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); |
525 |
– |
return false; |
526 |
– |
} |
527 |
– |
vis = visualInfo.visual; |
528 |
– |
|
1409 |
|
// Mac screen depth follows X depth (for now) |
1410 |
< |
depth = xdepth; |
1411 |
< |
|
1412 |
< |
// Create color maps for 8 bit mode |
1413 |
< |
if (depth == 8) { |
1414 |
< |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1415 |
< |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1416 |
< |
XInstallColormap(x_display, cmap[0]); |
1417 |
< |
XInstallColormap(x_display, cmap[1]); |
1410 |
> |
int default_mode = APPLE_8_BIT; |
1411 |
> |
switch (DefaultDepth(x_display, screen)) { |
1412 |
> |
case 1: |
1413 |
> |
default_mode = APPLE_1_BIT; |
1414 |
> |
break; |
1415 |
> |
case 8: |
1416 |
> |
default_mode = APPLE_8_BIT; |
1417 |
> |
break; |
1418 |
> |
case 15: case 16: |
1419 |
> |
default_mode = APPLE_16_BIT; |
1420 |
> |
break; |
1421 |
> |
case 24: case 32: |
1422 |
> |
default_mode = APPLE_32_BIT; |
1423 |
> |
break; |
1424 |
> |
} |
1425 |
> |
|
1426 |
> |
// Get screen mode from preferences |
1427 |
> |
const char *mode_str = PrefsFindString("screen"); |
1428 |
> |
int default_width = 640, default_height = 480; |
1429 |
> |
if (mode_str) { |
1430 |
> |
display_type = DIS_INVALID; |
1431 |
> |
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) |
1432 |
> |
display_type = DIS_WINDOW; |
1433 |
> |
#ifdef ENABLE_XF86_DGA |
1434 |
> |
else if (has_dga && sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2) |
1435 |
> |
display_type = DIS_SCREEN; |
1436 |
> |
#endif |
1437 |
> |
#ifdef ENABLE_FBDEV_DGA |
1438 |
> |
else if (has_fbdev_dga && sscanf(mode_str, "fbdev/%d/%d", &default_width, &default_height) == 2) { |
1439 |
> |
is_fbdev_dga_mode = true; |
1440 |
> |
display_type = DIS_SCREEN; |
1441 |
> |
} |
1442 |
> |
#endif |
1443 |
> |
if (display_type == DIS_INVALID) { |
1444 |
> |
D(bug("Invalid screen mode specified, defaulting to old modes selection\n")); |
1445 |
> |
mode_str = NULL; |
1446 |
> |
} |
1447 |
> |
else { |
1448 |
> |
if (default_width <= 0) |
1449 |
> |
default_width = DisplayWidth(x_display, screen); |
1450 |
> |
else if (default_width > DisplayWidth(x_display, screen)) |
1451 |
> |
default_width = DisplayWidth(x_display, screen); |
1452 |
> |
if (default_height <= 0) |
1453 |
> |
default_height = DisplayHeight(x_display, screen); |
1454 |
> |
else if (default_height > DisplayHeight(x_display, screen)) |
1455 |
> |
default_height = DisplayHeight(x_display, screen); |
1456 |
> |
} |
1457 |
|
} |
1458 |
|
|
1459 |
|
// Construct video mode table |
541 |
– |
int mode = APPLE_8_BIT; |
542 |
– |
int bpr_mult = 8; |
543 |
– |
switch (depth) { |
544 |
– |
case 1: |
545 |
– |
mode = APPLE_1_BIT; |
546 |
– |
bpr_mult = 1; |
547 |
– |
break; |
548 |
– |
case 8: |
549 |
– |
mode = APPLE_8_BIT; |
550 |
– |
bpr_mult = 8; |
551 |
– |
break; |
552 |
– |
case 15: |
553 |
– |
case 16: |
554 |
– |
mode = APPLE_16_BIT; |
555 |
– |
bpr_mult = 16; |
556 |
– |
break; |
557 |
– |
case 24: |
558 |
– |
case 32: |
559 |
– |
mode = APPLE_32_BIT; |
560 |
– |
bpr_mult = 32; |
561 |
– |
break; |
562 |
– |
} |
563 |
– |
|
1460 |
|
uint32 window_modes = PrefsFindInt32("windowmodes"); |
1461 |
|
uint32 screen_modes = PrefsFindInt32("screenmodes"); |
1462 |
|
if (!has_dga) |
1463 |
|
screen_modes = 0; |
1464 |
< |
if (window_modes == 0 && screen_modes == 0) |
1464 |
> |
if (mode_str) |
1465 |
> |
window_modes = screen_modes = 0; |
1466 |
> |
else if (window_modes == 0 && screen_modes == 0) |
1467 |
|
window_modes |= 3; // Allow at least 640x480 and 800x600 window modes |
1468 |
|
|
1469 |
|
VideoInfo *p = VModes; |
1470 |
< |
add_mode(p, window_modes, 1, mode, APPLE_W_640x480, DIS_WINDOW); |
1471 |
< |
add_mode(p, window_modes, 2, mode, APPLE_W_800x600, DIS_WINDOW); |
1472 |
< |
if (has_vidmode) { |
1470 |
> |
if (mode_str) { |
1471 |
> |
if (display_type == DIS_WINDOW) { |
1472 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) { |
1473 |
> |
if (find_visual_for_depth(d)) { |
1474 |
> |
if (default_width > 640 && default_height > 480) |
1475 |
> |
add_mode(p, 3, 1, d, APPLE_W_640x480, DIS_WINDOW); |
1476 |
> |
if (default_width > 800 && default_height > 600) |
1477 |
> |
add_mode(p, 3, 2, d, APPLE_W_800x600, DIS_WINDOW); |
1478 |
> |
add_custom_mode(p, display_type, default_width, default_height, d, APPLE_CUSTOM); |
1479 |
> |
} |
1480 |
> |
} |
1481 |
> |
#ifdef ENABLE_VOSF |
1482 |
> |
} else if (display_type == DIS_SCREEN && is_fbdev_dga_mode) { |
1483 |
> |
for (unsigned int d = APPLE_1_BIT; d <= default_mode; d++) |
1484 |
> |
if (find_visual_for_depth(d)) |
1485 |
> |
add_custom_mode(p, display_type, default_width, default_height, d, APPLE_CUSTOM); |
1486 |
> |
#endif |
1487 |
> |
} else |
1488 |
> |
add_custom_mode(p, display_type, default_width, default_height, default_mode, APPLE_CUSTOM); |
1489 |
> |
} else if (window_modes) { |
1490 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) |
1491 |
> |
if (find_visual_for_depth(d)) |
1492 |
> |
add_window_modes(p, window_modes, d); |
1493 |
> |
} else if (has_vidmode) { |
1494 |
|
if (has_mode(640, 480)) |
1495 |
< |
add_mode(p, screen_modes, 1, mode, APPLE_640x480, DIS_SCREEN); |
1495 |
> |
add_mode(p, screen_modes, 1, default_mode, APPLE_640x480, DIS_SCREEN); |
1496 |
|
if (has_mode(800, 600)) |
1497 |
< |
add_mode(p, screen_modes, 2, mode, APPLE_800x600, DIS_SCREEN); |
1497 |
> |
add_mode(p, screen_modes, 2, default_mode, APPLE_800x600, DIS_SCREEN); |
1498 |
|
if (has_mode(1024, 768)) |
1499 |
< |
add_mode(p, screen_modes, 4, mode, APPLE_1024x768, DIS_SCREEN); |
1499 |
> |
add_mode(p, screen_modes, 4, default_mode, APPLE_1024x768, DIS_SCREEN); |
1500 |
> |
if (has_mode(1152, 768)) |
1501 |
> |
add_mode(p, screen_modes, 64, default_mode, APPLE_1152x768, DIS_SCREEN); |
1502 |
|
if (has_mode(1152, 900)) |
1503 |
< |
add_mode(p, screen_modes, 8, mode, APPLE_1152x900, DIS_SCREEN); |
1503 |
> |
add_mode(p, screen_modes, 8, default_mode, APPLE_1152x900, DIS_SCREEN); |
1504 |
|
if (has_mode(1280, 1024)) |
1505 |
< |
add_mode(p, screen_modes, 16, mode, APPLE_1280x1024, DIS_SCREEN); |
1505 |
> |
add_mode(p, screen_modes, 16, default_mode, APPLE_1280x1024, DIS_SCREEN); |
1506 |
|
if (has_mode(1600, 1200)) |
1507 |
< |
add_mode(p, screen_modes, 32, mode, APPLE_1600x1200, DIS_SCREEN); |
1507 |
> |
add_mode(p, screen_modes, 32, default_mode, APPLE_1600x1200, DIS_SCREEN); |
1508 |
|
} else if (screen_modes) { |
1509 |
|
int xsize = DisplayWidth(x_display, screen); |
1510 |
|
int ysize = DisplayHeight(x_display, screen); |
1511 |
< |
int apple_id; |
591 |
< |
if (xsize < 800) |
592 |
< |
apple_id = APPLE_640x480; |
593 |
< |
else if (xsize < 1024) |
594 |
< |
apple_id = APPLE_800x600; |
595 |
< |
else if (xsize < 1152) |
596 |
< |
apple_id = APPLE_1024x768; |
597 |
< |
else if (xsize < 1280) |
598 |
< |
apple_id = APPLE_1152x900; |
599 |
< |
else if (xsize < 1600) |
600 |
< |
apple_id = APPLE_1280x1024; |
601 |
< |
else |
602 |
< |
apple_id = APPLE_1600x1200; |
1511 |
> |
int apple_id = find_apple_resolution(xsize, ysize); |
1512 |
|
p->viType = DIS_SCREEN; |
1513 |
|
p->viRowBytes = 0; |
1514 |
|
p->viXsize = xsize; |
1515 |
|
p->viYsize = ysize; |
1516 |
< |
p->viAppleMode = mode; |
1516 |
> |
p->viAppleMode = default_mode; |
1517 |
|
p->viAppleID = apple_id; |
1518 |
|
p++; |
1519 |
|
} |
1523 |
|
p->viAppleMode = 0; |
1524 |
|
p->viAppleID = 0; |
1525 |
|
|
1526 |
< |
#ifdef ENABLE_XF86_DGA |
1526 |
> |
// Find default mode (window 640x480) |
1527 |
> |
cur_mode = -1; |
1528 |
|
if (has_dga && screen_modes) { |
1529 |
< |
int v_bank, v_size; |
1530 |
< |
XF86DGAGetVideo(x_display, screen, &dga_screen_base, &dga_fb_width, &v_bank, &v_size); |
1531 |
< |
D(bug("DGA screen_base %p, v_width %d\n", dga_screen_base, dga_fb_width)); |
1529 |
> |
int screen_width = DisplayWidth(x_display, screen); |
1530 |
> |
int screen_height = DisplayHeight(x_display, screen); |
1531 |
> |
int apple_id = find_apple_resolution(screen_width, screen_height); |
1532 |
> |
if (apple_id != -1) |
1533 |
> |
cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN); |
1534 |
> |
} else if (has_dga && mode_str) |
1535 |
> |
cur_mode = find_mode(default_mode, APPLE_CUSTOM, DIS_SCREEN); |
1536 |
> |
|
1537 |
> |
if (cur_mode == -1) { |
1538 |
> |
// pick up first windowed mode available |
1539 |
> |
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
1540 |
> |
if (p->viType == DIS_WINDOW && p->viAppleMode == default_mode) { |
1541 |
> |
cur_mode = p - VModes; |
1542 |
> |
break; |
1543 |
> |
} |
1544 |
> |
} |
1545 |
> |
} |
1546 |
> |
assert(cur_mode != -1); |
1547 |
> |
|
1548 |
> |
#if DEBUG |
1549 |
> |
D(bug("Available video modes:\n")); |
1550 |
> |
for (p = VModes; p->viType != DIS_INVALID; p++) { |
1551 |
> |
int bits = depth_of_video_mode(p->viAppleMode); |
1552 |
> |
D(bug(" %dx%d (ID %02x), %d colors\n", p->viXsize, p->viYsize, p->viAppleID, 1 << bits)); |
1553 |
|
} |
1554 |
|
#endif |
1555 |
|
|
1562 |
|
XSetErrorHandler(ignore_errors); |
1563 |
|
#endif |
1564 |
|
|
1565 |
+ |
// Lock down frame buffer |
1566 |
+ |
XSync(x_display, false); |
1567 |
+ |
LOCK_FRAME_BUFFER; |
1568 |
+ |
|
1569 |
|
// Start periodic thread |
1570 |
|
XSync(x_display, false); |
1571 |
< |
redraw_thread_active = (pthread_create(&redraw_thread, NULL, redraw_func, NULL) == 0); |
1571 |
> |
Set_pthread_attr(&redraw_thread_attr, 0); |
1572 |
> |
redraw_thread_cancel = false; |
1573 |
> |
redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0); |
1574 |
|
D(bug("Redraw thread installed (%ld)\n", redraw_thread)); |
1575 |
|
return true; |
1576 |
|
} |
1584 |
|
{ |
1585 |
|
// Stop redraw thread |
1586 |
|
if (redraw_thread_active) { |
1587 |
+ |
redraw_thread_cancel = true; |
1588 |
|
pthread_cancel(redraw_thread); |
1589 |
|
pthread_join(redraw_thread, NULL); |
1590 |
|
redraw_thread_active = false; |
1591 |
|
} |
1592 |
|
|
1593 |
+ |
// Unlock frame buffer |
1594 |
+ |
UNLOCK_FRAME_BUFFER; |
1595 |
+ |
XSync(x_display, false); |
1596 |
+ |
D(bug(" frame buffer unlocked\n")); |
1597 |
+ |
|
1598 |
+ |
#ifdef ENABLE_VOSF |
1599 |
+ |
if (use_vosf) { |
1600 |
+ |
// Deinitialize VOSF |
1601 |
+ |
video_vosf_exit(); |
1602 |
+ |
} |
1603 |
+ |
#endif |
1604 |
+ |
|
1605 |
|
// Close window and server connection |
1606 |
|
if (x_display != NULL) { |
1607 |
|
XSync(x_display, false); |
1608 |
|
close_display(); |
1609 |
|
XFlush(x_display); |
1610 |
|
XSync(x_display, false); |
661 |
– |
if (depth == 8) { |
662 |
– |
XFreeColormap(x_display, cmap[0]); |
663 |
– |
XFreeColormap(x_display, cmap[1]); |
664 |
– |
} |
1611 |
|
} |
1612 |
+ |
|
1613 |
+ |
#ifdef ENABLE_FBDEV_DGA |
1614 |
+ |
// Close framebuffer device |
1615 |
+ |
if (fb_dev_fd >= 0) { |
1616 |
+ |
close(fb_dev_fd); |
1617 |
+ |
fb_dev_fd = -1; |
1618 |
+ |
} |
1619 |
+ |
#endif |
1620 |
|
} |
1621 |
|
|
1622 |
|
|
1624 |
|
* Suspend/resume emulator |
1625 |
|
*/ |
1626 |
|
|
673 |
– |
extern void PauseEmulator(void); |
674 |
– |
extern void ResumeEmulator(void); |
675 |
– |
|
1627 |
|
static void suspend_emul(void) |
1628 |
|
{ |
1629 |
|
if (display_type == DIS_SCREEN) { |
1631 |
|
ADBKeyUp(0x36); |
1632 |
|
ctrl_down = false; |
1633 |
|
|
1634 |
< |
// Pause MacOS thread |
1635 |
< |
PauseEmulator(); |
685 |
< |
emul_suspended = true; |
1634 |
> |
// Lock frame buffer (this will stop the MacOS thread) |
1635 |
> |
LOCK_FRAME_BUFFER; |
1636 |
|
|
1637 |
|
// Save frame buffer |
1638 |
|
fb_save = malloc(VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1639 |
|
if (fb_save) |
1640 |
< |
memcpy(fb_save, (void *)screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1640 |
> |
Mac2Host_memcpy(fb_save, screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1641 |
|
|
1642 |
|
// Close full screen display |
1643 |
+ |
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) |
1644 |
|
#ifdef ENABLE_XF86_DGA |
1645 |
< |
XF86DGADirectVideo(x_display, screen, 0); |
1645 |
> |
if (!is_fbdev_dga_mode) |
1646 |
> |
XF86DGADirectVideo(x_display, screen, 0); |
1647 |
> |
#endif |
1648 |
|
XUngrabPointer(x_display, CurrentTime); |
1649 |
|
XUngrabKeyboard(x_display, CurrentTime); |
1650 |
|
#endif |
1651 |
+ |
restore_mouse_accel(); |
1652 |
+ |
XUnmapWindow(x_display, the_win); |
1653 |
+ |
wait_unmapped(the_win); |
1654 |
|
XSync(x_display, false); |
1655 |
|
|
1656 |
|
// Open "suspend" window |
1657 |
|
XSetWindowAttributes wattr; |
1658 |
|
wattr.event_mask = KeyPressMask; |
1659 |
< |
wattr.background_pixel = black_pixel; |
704 |
< |
wattr.border_pixel = black_pixel; |
1659 |
> |
wattr.background_pixel = (vis == DefaultVisual(x_display, screen) ? black_pixel : 0); |
1660 |
|
wattr.backing_store = Always; |
1661 |
< |
wattr.backing_planes = xdepth; |
1662 |
< |
wattr.colormap = DefaultColormap(x_display, screen); |
708 |
< |
XSync(x_display, false); |
1661 |
> |
wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); |
1662 |
> |
|
1663 |
|
suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth, |
1664 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | |
1665 |
< |
CWBackingStore | CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr); |
1666 |
< |
XSync(x_display, false); |
1667 |
< |
XStoreName(x_display, suspend_win, GetString(STR_SUSPEND_WINDOW_TITLE)); |
1668 |
< |
XMapRaised(x_display, suspend_win); |
715 |
< |
XSync(x_display, false); |
1664 |
> |
InputOutput, vis, CWEventMask | CWBackPixel | CWBackingStore | CWColormap, &wattr); |
1665 |
> |
set_window_name(suspend_win, STR_SUSPEND_WINDOW_TITLE); |
1666 |
> |
set_window_focus(suspend_win); |
1667 |
> |
XMapWindow(x_display, suspend_win); |
1668 |
> |
emul_suspended = true; |
1669 |
|
} |
1670 |
|
} |
1671 |
|
|
1676 |
|
XSync(x_display, false); |
1677 |
|
|
1678 |
|
// Reopen full screen display |
1679 |
< |
XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime); |
1680 |
< |
XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
1681 |
< |
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
1682 |
< |
XF86DGASetViewPort(x_display, screen, 0, 0); |
1679 |
> |
XMapRaised(x_display, the_win); |
1680 |
> |
wait_mapped(the_win); |
1681 |
> |
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
1682 |
> |
Window w = is_fbdev_dga_mode ? the_win : rootwin; |
1683 |
> |
XGrabKeyboard(x_display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
1684 |
> |
XGrabPointer(x_display, w, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
1685 |
> |
disable_mouse_accel(); |
1686 |
> |
#ifdef ENABLE_XF86_DGA |
1687 |
> |
if (!is_fbdev_dga_mode) { |
1688 |
> |
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
1689 |
> |
XF86DGASetViewPort(x_display, screen, 0, 0); |
1690 |
> |
} |
1691 |
> |
#endif |
1692 |
|
XSync(x_display, false); |
1693 |
|
|
1694 |
+ |
// the_buffer already contains the data to restore. i.e. since a temporary |
1695 |
+ |
// frame buffer is used when VOSF is actually used, fb_save is therefore |
1696 |
+ |
// not necessary. |
1697 |
+ |
#ifdef ENABLE_VOSF |
1698 |
+ |
if (use_vosf) { |
1699 |
+ |
LOCK_VOSF; |
1700 |
+ |
PFLAG_SET_ALL; |
1701 |
+ |
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
1702 |
+ |
UNLOCK_VOSF; |
1703 |
+ |
} |
1704 |
+ |
#endif |
1705 |
+ |
|
1706 |
|
// Restore frame buffer |
1707 |
|
if (fb_save) { |
1708 |
< |
memcpy((void *)screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1708 |
> |
#ifdef ENABLE_VOSF |
1709 |
> |
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1710 |
> |
if (!use_vosf) |
1711 |
> |
#endif |
1712 |
> |
Host2Mac_memcpy(screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1713 |
|
free(fb_save); |
1714 |
|
fb_save = NULL; |
1715 |
|
} |
738 |
– |
if (depth == 8) |
739 |
– |
palette_changed = true; |
1716 |
|
|
1717 |
< |
// Resume MacOS thread |
1717 |
> |
// Unlock frame buffer (and continue MacOS thread) |
1718 |
> |
UNLOCK_FRAME_BUFFER; |
1719 |
|
emul_suspended = false; |
743 |
– |
ResumeEmulator(); |
1720 |
|
} |
1721 |
|
|
1722 |
|
|
1880 |
|
return -1; |
1881 |
|
} |
1882 |
|
|
1883 |
< |
static int event2keycode(XKeyEvent *ev) |
1883 |
> |
static int event2keycode(XKeyEvent &ev, bool key_down) |
1884 |
|
{ |
1885 |
|
KeySym ks; |
910 |
– |
int as; |
1886 |
|
int i = 0; |
1887 |
|
|
1888 |
|
do { |
1889 |
< |
ks = XLookupKeysym(ev, i++); |
1890 |
< |
as = kc_decode(ks); |
1891 |
< |
if (as != -1) |
1889 |
> |
ks = XLookupKeysym(&ev, i++); |
1890 |
> |
int as = kc_decode(ks); |
1891 |
> |
if (as >= 0) |
1892 |
> |
return as; |
1893 |
> |
if (as == -2) |
1894 |
|
return as; |
1895 |
|
} while (ks != NoSymbol); |
1896 |
|
|
1903 |
|
for (;;) { |
1904 |
|
XEvent event; |
1905 |
|
|
1906 |
< |
if (!XCheckMaskEvent(x_display, eventmask, &event)) |
1906 |
> |
XDisplayLock(); |
1907 |
> |
if (!XCheckMaskEvent(x_display, eventmask, &event)) { |
1908 |
> |
// Handle clipboard events |
1909 |
> |
if (XCheckTypedEvent(x_display, SelectionRequest, &event)) |
1910 |
> |
ClipboardSelectionRequest(&event.xselectionrequest); |
1911 |
> |
else if (XCheckTypedEvent(x_display, SelectionClear, &event)) |
1912 |
> |
ClipboardSelectionClear(&event.xselectionclear); |
1913 |
> |
|
1914 |
> |
// Window "close" widget clicked |
1915 |
> |
else if (XCheckTypedEvent(x_display, ClientMessage, &event)) { |
1916 |
> |
if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW) { |
1917 |
> |
ADBKeyDown(0x7f); // Power key |
1918 |
> |
ADBKeyUp(0x7f); |
1919 |
> |
} |
1920 |
> |
} |
1921 |
> |
|
1922 |
> |
XDisplayUnlock(); |
1923 |
|
break; |
1924 |
+ |
} |
1925 |
+ |
XDisplayUnlock(); |
1926 |
|
|
1927 |
|
switch (event.type) { |
1928 |
|
// Mouse button |
1930 |
|
unsigned int button = ((XButtonEvent *)&event)->button; |
1931 |
|
if (button < 4) |
1932 |
|
ADBMouseDown(button - 1); |
1933 |
+ |
else if (button < 6) { // Wheel mouse |
1934 |
+ |
if (mouse_wheel_mode == 0) { |
1935 |
+ |
int key = (button == 5) ? 0x79 : 0x74; // Page up/down |
1936 |
+ |
ADBKeyDown(key); |
1937 |
+ |
ADBKeyUp(key); |
1938 |
+ |
} else { |
1939 |
+ |
int key = (button == 5) ? 0x3d : 0x3e; // Cursor up/down |
1940 |
+ |
for(int i=0; i<mouse_wheel_lines; i++) { |
1941 |
+ |
ADBKeyDown(key); |
1942 |
+ |
ADBKeyUp(key); |
1943 |
+ |
} |
1944 |
+ |
} |
1945 |
+ |
} |
1946 |
|
break; |
1947 |
|
} |
1948 |
|
case ButtonRelease: { |
1952 |
|
break; |
1953 |
|
} |
1954 |
|
|
1955 |
< |
// Mouse moved |
1955 |
> |
// Mouse entered window |
1956 |
|
case EnterNotify: |
1957 |
< |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1957 |
> |
if (event.xcrossing.mode != NotifyGrab && event.xcrossing.mode != NotifyUngrab) |
1958 |
> |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
1959 |
|
break; |
1960 |
+ |
|
1961 |
+ |
// Mouse moved |
1962 |
|
case MotionNotify: |
1963 |
< |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1963 |
> |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
1964 |
|
break; |
1965 |
|
|
1966 |
|
// Keyboard |
1967 |
|
case KeyPress: { |
1968 |
< |
int code; |
1969 |
< |
if ((code = event2keycode((XKeyEvent *)&event)) != -1) { |
1968 |
> |
int code = -1; |
1969 |
> |
if (use_keycodes) { |
1970 |
> |
if (event2keycode(event.xkey, true) != -2) // This is called to process the hotkeys |
1971 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1972 |
> |
} else |
1973 |
> |
code = event2keycode(event.xkey, true); |
1974 |
> |
if (code >= 0) { |
1975 |
|
if (!emul_suspended) { |
1976 |
< |
ADBKeyDown(code); |
1976 |
> |
if (code == 0x39) { // Caps Lock pressed |
1977 |
> |
if (caps_on) { |
1978 |
> |
ADBKeyUp(code); |
1979 |
> |
caps_on = false; |
1980 |
> |
} else { |
1981 |
> |
ADBKeyDown(code); |
1982 |
> |
caps_on = true; |
1983 |
> |
} |
1984 |
> |
} else |
1985 |
> |
ADBKeyDown(code); |
1986 |
|
if (code == 0x36) |
1987 |
|
ctrl_down = true; |
1988 |
|
} else { |
1993 |
|
break; |
1994 |
|
} |
1995 |
|
case KeyRelease: { |
1996 |
< |
int code; |
1997 |
< |
if ((code = event2keycode((XKeyEvent *)&event)) != -1) { |
1996 |
> |
int code = -1; |
1997 |
> |
if (use_keycodes) { |
1998 |
> |
if (event2keycode(event.xkey, false) != -2) // This is called to process the hotkeys |
1999 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
2000 |
> |
} else |
2001 |
> |
code = event2keycode(event.xkey, false); |
2002 |
> |
if (code >= 0 && code != 0x39) { // Don't propagate Caps Lock releases |
2003 |
|
ADBKeyUp(code); |
2004 |
|
if (code == 0x36) |
2005 |
|
ctrl_down = false; |
2009 |
|
|
2010 |
|
// Hidden parts exposed, force complete refresh |
2011 |
|
case Expose: |
2012 |
< |
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
2012 |
> |
#ifdef ENABLE_VOSF |
2013 |
> |
if (use_vosf) { // VOSF refresh |
2014 |
> |
LOCK_VOSF; |
2015 |
> |
PFLAG_SET_ALL; |
2016 |
> |
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
2017 |
> |
UNLOCK_VOSF; |
2018 |
> |
} |
2019 |
> |
else |
2020 |
> |
#endif |
2021 |
> |
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
2022 |
|
break; |
2023 |
|
} |
2024 |
|
} |
2034 |
|
if (emerg_quit) |
2035 |
|
QuitEmulator(); |
2036 |
|
|
2037 |
+ |
// Temporarily give up frame buffer lock (this is the point where |
2038 |
+ |
// we are suspended when the user presses Ctrl-Tab) |
2039 |
+ |
UNLOCK_FRAME_BUFFER; |
2040 |
+ |
LOCK_FRAME_BUFFER; |
2041 |
+ |
|
2042 |
|
// Execute video VBL |
2043 |
|
if (private_data != NULL && private_data->interruptsEnabled) |
2044 |
|
VSLDoInterruptService(private_data->vslServiceID); |
2046 |
|
|
2047 |
|
|
2048 |
|
/* |
1005 |
– |
* Install graphics acceleration |
1006 |
– |
*/ |
1007 |
– |
|
1008 |
– |
#if 0 |
1009 |
– |
// Rectangle blitting |
1010 |
– |
static void accl_bitblt(accl_params *p) |
1011 |
– |
{ |
1012 |
– |
D(bug("accl_bitblt\n")); |
1013 |
– |
|
1014 |
– |
// Get blitting parameters |
1015 |
– |
int16 src_X = p->src_rect[1] - p->src_bounds[1]; |
1016 |
– |
int16 src_Y = p->src_rect[0] - p->src_bounds[0]; |
1017 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1018 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1019 |
– |
int16 width = p->dest_rect[3] - p->dest_rect[1] - 1; |
1020 |
– |
int16 height = p->dest_rect[2] - p->dest_rect[0] - 1; |
1021 |
– |
D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y)); |
1022 |
– |
D(bug(" width %d, height %d\n", width, height)); |
1023 |
– |
|
1024 |
– |
// And perform the blit |
1025 |
– |
bitblt_hook(src_X, src_Y, dest_X, dest_Y, width, height); |
1026 |
– |
} |
1027 |
– |
|
1028 |
– |
static bool accl_bitblt_hook(accl_params *p) |
1029 |
– |
{ |
1030 |
– |
D(bug("accl_draw_hook %p\n", p)); |
1031 |
– |
|
1032 |
– |
// Check if we can accelerate this bitblt |
1033 |
– |
if (p->src_base_addr == screen_base && p->dest_base_addr == screen_base && |
1034 |
– |
display_type == DIS_SCREEN && bitblt_hook != NULL && |
1035 |
– |
((uint32 *)p)[0x18 >> 2] + ((uint32 *)p)[0x128 >> 2] == 0 && |
1036 |
– |
((uint32 *)p)[0x130 >> 2] == 0 && |
1037 |
– |
p->transfer_mode == 0 && |
1038 |
– |
p->src_row_bytes > 0 && ((uint32 *)p)[0x15c >> 2] > 0) { |
1039 |
– |
|
1040 |
– |
// Yes, set function pointer |
1041 |
– |
p->draw_proc = accl_bitblt; |
1042 |
– |
return true; |
1043 |
– |
} |
1044 |
– |
return false; |
1045 |
– |
} |
1046 |
– |
|
1047 |
– |
// Rectangle filling/inversion |
1048 |
– |
static void accl_fillrect8(accl_params *p) |
1049 |
– |
{ |
1050 |
– |
D(bug("accl_fillrect8\n")); |
1051 |
– |
|
1052 |
– |
// Get filling parameters |
1053 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1054 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1055 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1056 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1057 |
– |
uint8 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
1058 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1059 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1060 |
– |
|
1061 |
– |
// And perform the fill |
1062 |
– |
fillrect8_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
1063 |
– |
} |
1064 |
– |
|
1065 |
– |
static void accl_fillrect32(accl_params *p) |
1066 |
– |
{ |
1067 |
– |
D(bug("accl_fillrect32\n")); |
1068 |
– |
|
1069 |
– |
// Get filling parameters |
1070 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1071 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1072 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1073 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1074 |
– |
uint32 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
1075 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1076 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1077 |
– |
|
1078 |
– |
// And perform the fill |
1079 |
– |
fillrect32_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
1080 |
– |
} |
1081 |
– |
|
1082 |
– |
static void accl_invrect(accl_params *p) |
1083 |
– |
{ |
1084 |
– |
D(bug("accl_invrect\n")); |
1085 |
– |
|
1086 |
– |
// Get inversion parameters |
1087 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1088 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1089 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1090 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1091 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1092 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1093 |
– |
|
1094 |
– |
//!!?? pen_mode == 14 |
1095 |
– |
|
1096 |
– |
// And perform the inversion |
1097 |
– |
invrect_hook(dest_X, dest_Y, dest_X_max, dest_Y_max); |
1098 |
– |
} |
1099 |
– |
|
1100 |
– |
static bool accl_fillrect_hook(accl_params *p) |
1101 |
– |
{ |
1102 |
– |
D(bug("accl_fillrect_hook %p\n", p)); |
1103 |
– |
|
1104 |
– |
// Check if we can accelerate this fillrect |
1105 |
– |
if (p->dest_base_addr == screen_base && ((uint32 *)p)[0x284 >> 2] != 0 && display_type == DIS_SCREEN) { |
1106 |
– |
if (p->transfer_mode == 8) { |
1107 |
– |
// Fill |
1108 |
– |
if (p->dest_pixel_size == 8 && fillrect8_hook != NULL) { |
1109 |
– |
p->draw_proc = accl_fillrect8; |
1110 |
– |
return true; |
1111 |
– |
} else if (p->dest_pixel_size == 32 && fillrect32_hook != NULL) { |
1112 |
– |
p->draw_proc = accl_fillrect32; |
1113 |
– |
return true; |
1114 |
– |
} |
1115 |
– |
} else if (p->transfer_mode == 10 && invrect_hook != NULL) { |
1116 |
– |
// Invert |
1117 |
– |
p->draw_proc = accl_invrect; |
1118 |
– |
return true; |
1119 |
– |
} |
1120 |
– |
} |
1121 |
– |
return false; |
1122 |
– |
} |
1123 |
– |
|
1124 |
– |
// Wait for graphics operation to finish |
1125 |
– |
static bool accl_sync_hook(void *arg) |
1126 |
– |
{ |
1127 |
– |
D(bug("accl_sync_hook %p\n", arg)); |
1128 |
– |
if (sync_hook != NULL) |
1129 |
– |
sync_hook(); |
1130 |
– |
return true; |
1131 |
– |
} |
1132 |
– |
|
1133 |
– |
static struct accl_hook_info bitblt_hook_info = {accl_bitblt_hook, accl_sync_hook, ACCL_BITBLT}; |
1134 |
– |
static struct accl_hook_info fillrect_hook_info = {accl_fillrect_hook, accl_sync_hook, ACCL_FILLRECT}; |
1135 |
– |
#endif |
1136 |
– |
|
1137 |
– |
void VideoInstallAccel(void) |
1138 |
– |
{ |
1139 |
– |
// Install acceleration hooks |
1140 |
– |
if (PrefsFindBool("gfxaccel")) { |
1141 |
– |
D(bug("Video: Installing acceleration hooks\n")); |
1142 |
– |
//!! NQDMisc(6, &bitblt_hook_info); |
1143 |
– |
// NQDMisc(6, &fillrect_hook_info); |
1144 |
– |
} |
1145 |
– |
} |
1146 |
– |
|
1147 |
– |
|
1148 |
– |
/* |
2049 |
|
* Change video mode |
2050 |
|
*/ |
2051 |
|
|
2103 |
|
|
2104 |
|
void video_set_palette(void) |
2105 |
|
{ |
2106 |
+ |
LOCK_PALETTE; |
2107 |
+ |
|
2108 |
+ |
// Convert colors to XColor array |
2109 |
+ |
int mode = get_current_mode(); |
2110 |
+ |
int num_in = palette_size(mode); |
2111 |
+ |
int num_out = 256; |
2112 |
+ |
bool stretch = false; |
2113 |
+ |
if (IsDirectMode(mode)) { |
2114 |
+ |
// If X is in 565 mode we have to stretch the gamma table from 32 to 64 entries |
2115 |
+ |
num_out = vis->map_entries; |
2116 |
+ |
stretch = true; |
2117 |
+ |
} |
2118 |
+ |
XColor *p = x_palette; |
2119 |
+ |
for (int i=0; i<num_out; i++) { |
2120 |
+ |
int c = (stretch ? (i * num_in) / num_out : i); |
2121 |
+ |
p->red = mac_pal[c].red * 0x0101; |
2122 |
+ |
p->green = mac_pal[c].green * 0x0101; |
2123 |
+ |
p->blue = mac_pal[c].blue * 0x0101; |
2124 |
+ |
p++; |
2125 |
+ |
} |
2126 |
+ |
|
2127 |
+ |
#ifdef ENABLE_VOSF |
2128 |
+ |
// Recalculate pixel color expansion map |
2129 |
+ |
if (!IsDirectMode(mode) && xdepth > 8) { |
2130 |
+ |
for (int i=0; i<256; i++) { |
2131 |
+ |
int c = i & (num_in-1); // If there are less than 256 colors, we repeat the first entries (this makes color expansion easier) |
2132 |
+ |
ExpandMap[i] = map_rgb(mac_pal[c].red, mac_pal[c].green, mac_pal[c].blue); |
2133 |
+ |
} |
2134 |
+ |
|
2135 |
+ |
// We have to redraw everything because the interpretation of pixel values changed |
2136 |
+ |
LOCK_VOSF; |
2137 |
+ |
PFLAG_SET_ALL; |
2138 |
+ |
if (display_type == DIS_SCREEN) |
2139 |
+ |
PFLAG_SET_VERY_DIRTY; |
2140 |
+ |
UNLOCK_VOSF; |
2141 |
+ |
} |
2142 |
+ |
#endif |
2143 |
+ |
|
2144 |
+ |
// Tell redraw thread to change palette |
2145 |
|
palette_changed = true; |
2146 |
+ |
|
2147 |
+ |
UNLOCK_PALETTE; |
2148 |
+ |
} |
2149 |
+ |
|
2150 |
+ |
|
2151 |
+ |
/* |
2152 |
+ |
* Can we set the MacOS cursor image into the window? |
2153 |
+ |
*/ |
2154 |
+ |
|
2155 |
+ |
bool video_can_change_cursor(void) |
2156 |
+ |
{ |
2157 |
+ |
return hw_mac_cursor_accl && (display_type != DIS_SCREEN); |
2158 |
|
} |
2159 |
|
|
2160 |
|
|
2281 |
|
|
2282 |
|
// Refresh display |
2283 |
|
if (high && wide) { |
2284 |
+ |
XDisplayLock(); |
2285 |
|
if (have_shm) |
2286 |
|
XShmPutImage(x_display, the_win, the_gc, img, x1, y1, x1, y1, wide, high, 0); |
2287 |
|
else |
2288 |
|
XPutImage(x_display, the_win, the_gc, img, x1, y1, x1, y1, wide, high); |
2289 |
+ |
XDisplayUnlock(); |
2290 |
+ |
} |
2291 |
+ |
} |
2292 |
+ |
|
2293 |
+ |
const int VIDEO_REFRESH_HZ = 60; |
2294 |
+ |
const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ; |
2295 |
+ |
|
2296 |
+ |
static void handle_palette_changes(void) |
2297 |
+ |
{ |
2298 |
+ |
LOCK_PALETTE; |
2299 |
+ |
|
2300 |
+ |
if (palette_changed && !emul_suspended) { |
2301 |
+ |
palette_changed = false; |
2302 |
+ |
|
2303 |
+ |
int mode = get_current_mode(); |
2304 |
+ |
if (color_class == PseudoColor || color_class == DirectColor) { |
2305 |
+ |
int num = vis->map_entries; |
2306 |
+ |
bool set_clut = true; |
2307 |
+ |
if (!IsDirectMode(mode) && color_class == DirectColor) { |
2308 |
+ |
if (display_type == DIS_WINDOW) |
2309 |
+ |
set_clut = false; // Indexed mode on true color screen, don't set CLUT |
2310 |
+ |
} |
2311 |
+ |
|
2312 |
+ |
if (set_clut) { |
2313 |
+ |
XDisplayLock(); |
2314 |
+ |
XStoreColors(x_display, cmap[0], x_palette, num); |
2315 |
+ |
XStoreColors(x_display, cmap[1], x_palette, num); |
2316 |
+ |
XSync(x_display, false); |
2317 |
+ |
XDisplayUnlock(); |
2318 |
+ |
} |
2319 |
+ |
} |
2320 |
+ |
|
2321 |
+ |
#ifdef ENABLE_XF86_DGA |
2322 |
+ |
if (display_type == DIS_SCREEN && !is_fbdev_dga_mode) { |
2323 |
+ |
current_dga_cmap ^= 1; |
2324 |
+ |
if (!IsDirectMode(mode) && cmap[current_dga_cmap]) |
2325 |
+ |
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
2326 |
+ |
} |
2327 |
+ |
#endif |
2328 |
|
} |
2329 |
+ |
|
2330 |
+ |
UNLOCK_PALETTE; |
2331 |
|
} |
2332 |
|
|
2333 |
|
static void *redraw_func(void *arg) |
2334 |
|
{ |
2335 |
< |
int tick_counter = 0; |
1343 |
< |
struct timespec req = {0, 16666667}; |
2335 |
> |
int fd = ConnectionNumber(x_display); |
2336 |
|
|
2337 |
< |
for (;;) { |
2337 |
> |
uint64 start = GetTicks_usec(); |
2338 |
> |
int64 ticks = 0; |
2339 |
> |
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
2340 |
|
|
2341 |
< |
// Wait |
1348 |
< |
nanosleep(&req, NULL); |
2341 |
> |
while (!redraw_thread_cancel) { |
2342 |
|
|
2343 |
|
// Pause if requested (during video mode switches) |
2344 |
|
while (thread_stop_req) |
2345 |
|
thread_stop_ack = true; |
2346 |
|
|
2347 |
< |
// Handle X11 events |
2348 |
< |
handle_events(); |
2347 |
> |
int64 delay = next - GetTicks_usec(); |
2348 |
> |
if (delay < -VIDEO_REFRESH_DELAY) { |
2349 |
> |
|
2350 |
> |
// We are lagging far behind, so we reset the delay mechanism |
2351 |
> |
next = GetTicks_usec(); |
2352 |
|
|
2353 |
< |
// Quit DGA mode if requested |
2354 |
< |
if (quit_full_screen) { |
2355 |
< |
quit_full_screen = false; |
2356 |
< |
if (display_type == DIS_SCREEN) { |
2353 |
> |
} else if (delay <= 0) { |
2354 |
> |
|
2355 |
> |
// Delay expired, refresh display |
2356 |
> |
next += VIDEO_REFRESH_DELAY; |
2357 |
> |
ticks++; |
2358 |
> |
|
2359 |
> |
// Handle X11 events |
2360 |
> |
handle_events(); |
2361 |
> |
|
2362 |
> |
// Quit DGA mode if requested |
2363 |
> |
if (quit_full_screen) { |
2364 |
> |
quit_full_screen = false; |
2365 |
> |
if (display_type == DIS_SCREEN) { |
2366 |
> |
XDisplayLock(); |
2367 |
> |
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) |
2368 |
|
#ifdef ENABLE_XF86_DGA |
2369 |
< |
XF86DGADirectVideo(x_display, screen, 0); |
2370 |
< |
XUngrabPointer(x_display, CurrentTime); |
1364 |
< |
XUngrabKeyboard(x_display, CurrentTime); |
2369 |
> |
if (is_fbdev_dga_mode) |
2370 |
> |
XF86DGADirectVideo(x_display, screen, 0); |
2371 |
|
#endif |
2372 |
< |
XSync(x_display, false); |
2373 |
< |
quit_full_screen_ack = true; |
2374 |
< |
return NULL; |
2372 |
> |
XUngrabPointer(x_display, CurrentTime); |
2373 |
> |
XUngrabKeyboard(x_display, CurrentTime); |
2374 |
> |
XUnmapWindow(x_display, the_win); |
2375 |
> |
wait_unmapped(the_win); |
2376 |
> |
XDestroyWindow(x_display, the_win); |
2377 |
> |
#endif |
2378 |
> |
XSync(x_display, false); |
2379 |
> |
XDisplayUnlock(); |
2380 |
> |
quit_full_screen_ack = true; |
2381 |
> |
return NULL; |
2382 |
> |
} |
2383 |
|
} |
1370 |
– |
} |
2384 |
|
|
2385 |
< |
// Refresh display and set cursor image in window mode |
2386 |
< |
if (display_type == DIS_WINDOW) { |
2387 |
< |
tick_counter++; |
2388 |
< |
if (tick_counter >= frame_skip) { |
2389 |
< |
tick_counter = 0; |
2390 |
< |
|
2391 |
< |
// Update display |
2392 |
< |
update_display(); |
2393 |
< |
|
2394 |
< |
// Set new cursor image if it was changed |
2395 |
< |
if (cursor_changed) { |
2396 |
< |
cursor_changed = false; |
2397 |
< |
memcpy(cursor_image->data, MacCursor + 4, 32); |
2398 |
< |
memcpy(cursor_mask_image->data, MacCursor + 36, 32); |
2399 |
< |
XFreeCursor(x_display, mac_cursor); |
2400 |
< |
XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16); |
2401 |
< |
XPutImage(x_display, cursor_mask_map, cursor_mask_gc, cursor_mask_image, 0, 0, 0, 0, 16, 16); |
2402 |
< |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, MacCursor[2], MacCursor[3]); |
2403 |
< |
XDefineCursor(x_display, the_win, mac_cursor); |
2385 |
> |
// Refresh display and set cursor image in window mode |
2386 |
> |
static int tick_counter = 0; |
2387 |
> |
if (display_type == DIS_WINDOW) { |
2388 |
> |
tick_counter++; |
2389 |
> |
if (tick_counter >= frame_skip) { |
2390 |
> |
tick_counter = 0; |
2391 |
> |
|
2392 |
> |
// Update display |
2393 |
> |
#ifdef ENABLE_VOSF |
2394 |
> |
if (use_vosf) { |
2395 |
> |
XDisplayLock(); |
2396 |
> |
if (mainBuffer.dirty) { |
2397 |
> |
LOCK_VOSF; |
2398 |
> |
update_display_window_vosf(); |
2399 |
> |
UNLOCK_VOSF; |
2400 |
> |
XSync(x_display, false); // Let the server catch up |
2401 |
> |
} |
2402 |
> |
XDisplayUnlock(); |
2403 |
> |
} |
2404 |
> |
else |
2405 |
> |
#endif |
2406 |
> |
update_display(); |
2407 |
> |
|
2408 |
> |
// Set new cursor image if it was changed |
2409 |
> |
if (hw_mac_cursor_accl && cursor_changed) { |
2410 |
> |
cursor_changed = false; |
2411 |
> |
uint8 *x_data = (uint8 *)cursor_image->data; |
2412 |
> |
uint8 *x_mask = (uint8 *)cursor_mask_image->data; |
2413 |
> |
for (int i = 0; i < 32; i++) { |
2414 |
> |
x_mask[i] = MacCursor[4 + i] | MacCursor[36 + i]; |
2415 |
> |
x_data[i] = MacCursor[4 + i]; |
2416 |
> |
} |
2417 |
> |
XDisplayLock(); |
2418 |
> |
XFreeCursor(x_display, mac_cursor); |
2419 |
> |
XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16); |
2420 |
> |
XPutImage(x_display, cursor_mask_map, cursor_mask_gc, cursor_mask_image, 0, 0, 0, 0, 16, 16); |
2421 |
> |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, MacCursor[2], MacCursor[3]); |
2422 |
> |
XDefineCursor(x_display, the_win, mac_cursor); |
2423 |
> |
XDisplayUnlock(); |
2424 |
> |
} |
2425 |
|
} |
2426 |
|
} |
2427 |
< |
} |
2428 |
< |
|
2429 |
< |
// Set new palette if it was changed |
2430 |
< |
if (palette_changed && !emul_suspended) { |
2431 |
< |
palette_changed = false; |
2432 |
< |
XColor c[256]; |
2433 |
< |
for (int i=0; i<256; i++) { |
2434 |
< |
c[i].pixel = i; |
2435 |
< |
c[i].red = mac_pal[i].red * 0x0101; |
2436 |
< |
c[i].green = mac_pal[i].green * 0x0101; |
1403 |
< |
c[i].blue = mac_pal[i].blue * 0x0101; |
1404 |
< |
c[i].flags = DoRed | DoGreen | DoBlue; |
1405 |
< |
} |
1406 |
< |
if (depth == 8) { |
1407 |
< |
XStoreColors(x_display, cmap[0], c, 256); |
1408 |
< |
XStoreColors(x_display, cmap[1], c, 256); |
1409 |
< |
#ifdef ENABLE_XF86_DGA |
1410 |
< |
if (display_type == DIS_SCREEN) { |
1411 |
< |
current_dga_cmap ^= 1; |
1412 |
< |
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
2427 |
> |
#ifdef ENABLE_VOSF |
2428 |
> |
else if (use_vosf) { |
2429 |
> |
// Update display (VOSF variant) |
2430 |
> |
if (++tick_counter >= frame_skip) { |
2431 |
> |
tick_counter = 0; |
2432 |
> |
if (mainBuffer.dirty) { |
2433 |
> |
LOCK_VOSF; |
2434 |
> |
update_display_dga_vosf(); |
2435 |
> |
UNLOCK_VOSF; |
2436 |
> |
} |
2437 |
|
} |
1414 |
– |
#endif |
2438 |
|
} |
2439 |
+ |
#endif |
2440 |
+ |
|
2441 |
+ |
// Set new palette if it was changed |
2442 |
+ |
handle_palette_changes(); |
2443 |
+ |
|
2444 |
+ |
} else { |
2445 |
+ |
|
2446 |
+ |
// No display refresh pending, check for X events |
2447 |
+ |
fd_set readfds; |
2448 |
+ |
FD_ZERO(&readfds); |
2449 |
+ |
FD_SET(fd, &readfds); |
2450 |
+ |
struct timeval timeout; |
2451 |
+ |
timeout.tv_sec = 0; |
2452 |
+ |
timeout.tv_usec = delay; |
2453 |
+ |
if (select(fd+1, &readfds, NULL, NULL, &timeout) > 0) |
2454 |
+ |
handle_events(); |
2455 |
|
} |
2456 |
|
} |
2457 |
|
return NULL; |