1 |
|
/* |
2 |
|
* video_x.cpp - Video/graphics emulation, X11 specific stuff |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2003 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 |
29 |
|
#include <errno.h> |
30 |
|
#include <pthread.h> |
31 |
|
|
32 |
+ |
#include <algorithm> |
33 |
+ |
|
34 |
|
#ifdef ENABLE_XF86_DGA |
35 |
< |
#include <X11/extensions/xf86dga.h> |
35 |
> |
# include <X11/extensions/xf86dga.h> |
36 |
|
#endif |
37 |
|
|
38 |
|
#ifdef ENABLE_XF86_VIDMODE |
46 |
|
#include "about_window.h" |
47 |
|
#include "video.h" |
48 |
|
#include "video_defs.h" |
49 |
+ |
#include "video_blit.h" |
50 |
|
|
51 |
|
#define DEBUG 0 |
52 |
|
#include "debug.h" |
53 |
|
|
54 |
+ |
#ifndef NO_STD_NAMESPACE |
55 |
+ |
using std::sort; |
56 |
+ |
#endif |
57 |
+ |
|
58 |
|
|
59 |
|
// Constants |
60 |
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; |
61 |
+ |
static const bool hw_mac_cursor_accl = true; // Flag: Enable MacOS to X11 copy of cursor? |
62 |
|
|
63 |
|
// Global variables |
64 |
|
static int32 frame_skip; |
65 |
|
static int16 mouse_wheel_mode; |
66 |
|
static int16 mouse_wheel_lines; |
67 |
|
static bool redraw_thread_active = false; // Flag: Redraw thread installed |
68 |
+ |
static pthread_attr_t redraw_thread_attr; // Redraw thread attributes |
69 |
+ |
static volatile bool redraw_thread_cancel; // Flag: Cancel Redraw thread |
70 |
|
static pthread_t redraw_thread; // Redraw thread |
71 |
|
|
72 |
|
static bool local_X11; // Flag: X server running on local machine? |
84 |
|
|
85 |
|
static bool palette_changed = false; // Flag: Palette changed, redraw thread must update palette |
86 |
|
static bool ctrl_down = false; // Flag: Ctrl key pressed |
87 |
+ |
static bool caps_on = false; // Flag: Caps Lock on |
88 |
|
static bool quit_full_screen = false; // Flag: DGA close requested from redraw thread |
89 |
|
static volatile bool quit_full_screen_ack = false; // Acknowledge for quit_full_screen |
90 |
|
static bool emerg_quit = false; // Flag: Ctrl-Esc pressed, emergency quit requested from MacOS thread |
100 |
|
static int xdepth; // Depth of X screen |
101 |
|
static int depth; // Depth of Mac frame buffer |
102 |
|
static Window rootwin, the_win; // Root window and our window |
103 |
+ |
static int num_depths = 0; // Number of available X depths |
104 |
+ |
static int *avail_depths = NULL; // List of available X depths |
105 |
+ |
static VisualFormat visualFormat; |
106 |
|
static XVisualInfo visualInfo; |
107 |
|
static Visual *vis; |
108 |
+ |
static int color_class; |
109 |
+ |
static int rshift, rloss, gshift, gloss, bshift, bloss; // Pixel format of DirectColor/TrueColor modes |
110 |
|
static Colormap cmap[2]; // Two colormaps (DGA) for 8-bit mode |
111 |
+ |
static XColor x_palette[256]; // Color palette to be used as CLUT and gamma table |
112 |
+ |
|
113 |
|
static XColor black, white; |
114 |
|
static unsigned long black_pixel, white_pixel; |
115 |
|
static int eventmask; |
116 |
< |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask; |
117 |
< |
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; |
116 |
> |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask | StructureNotifyMask; |
117 |
> |
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask; |
118 |
|
|
119 |
|
// Variables for window mode |
120 |
|
static GC the_gc; |
131 |
|
static uint32 the_buffer_size; // Size of allocated the_buffer |
132 |
|
|
133 |
|
// Variables for DGA mode |
116 |
– |
static char *dga_screen_base; |
117 |
– |
static int dga_fb_width; |
134 |
|
static int current_dga_cmap; |
135 |
|
|
136 |
|
#ifdef ENABLE_XF86_VIDMODE |
139 |
|
static int num_x_video_modes; |
140 |
|
#endif |
141 |
|
|
142 |
+ |
// Mutex to protect palette |
143 |
+ |
#ifdef HAVE_SPINLOCKS |
144 |
+ |
static spinlock_t x_palette_lock = SPIN_LOCK_UNLOCKED; |
145 |
+ |
#define LOCK_PALETTE spin_lock(&x_palette_lock) |
146 |
+ |
#define UNLOCK_PALETTE spin_unlock(&x_palette_lock) |
147 |
+ |
#elif defined(HAVE_PTHREADS) |
148 |
+ |
static pthread_mutex_t x_palette_lock = PTHREAD_MUTEX_INITIALIZER; |
149 |
+ |
#define LOCK_PALETTE pthread_mutex_lock(&x_palette_lock) |
150 |
+ |
#define UNLOCK_PALETTE pthread_mutex_unlock(&x_palette_lock) |
151 |
+ |
#else |
152 |
+ |
#define LOCK_PALETTE |
153 |
+ |
#define UNLOCK_PALETTE |
154 |
+ |
#endif |
155 |
+ |
|
156 |
|
|
157 |
|
// Prototypes |
158 |
|
static void *redraw_func(void *arg); |
177 |
|
|
178 |
|
|
179 |
|
/* |
180 |
+ |
* Utility functions |
181 |
+ |
*/ |
182 |
+ |
|
183 |
+ |
// Get current video mode |
184 |
+ |
static inline int get_current_mode(void) |
185 |
+ |
{ |
186 |
+ |
return VModes[cur_mode].viAppleMode; |
187 |
+ |
} |
188 |
+ |
|
189 |
+ |
// Find palette size for given color depth |
190 |
+ |
static int palette_size(int mode) |
191 |
+ |
{ |
192 |
+ |
switch (mode) { |
193 |
+ |
case APPLE_1_BIT: return 2; |
194 |
+ |
case APPLE_2_BIT: return 4; |
195 |
+ |
case APPLE_4_BIT: return 16; |
196 |
+ |
case APPLE_8_BIT: return 256; |
197 |
+ |
case APPLE_16_BIT: return 32; |
198 |
+ |
case APPLE_32_BIT: return 256; |
199 |
+ |
default: return 0; |
200 |
+ |
} |
201 |
+ |
} |
202 |
+ |
|
203 |
+ |
// Return bits per pixel for requested depth |
204 |
+ |
static inline int bytes_per_pixel(int depth) |
205 |
+ |
{ |
206 |
+ |
int bpp; |
207 |
+ |
switch (depth) { |
208 |
+ |
case 8: |
209 |
+ |
bpp = 1; |
210 |
+ |
break; |
211 |
+ |
case 15: case 16: |
212 |
+ |
bpp = 2; |
213 |
+ |
break; |
214 |
+ |
case 24: case 32: |
215 |
+ |
bpp = 4; |
216 |
+ |
break; |
217 |
+ |
default: |
218 |
+ |
abort(); |
219 |
+ |
} |
220 |
+ |
return bpp; |
221 |
+ |
} |
222 |
+ |
|
223 |
+ |
// Map video_mode depth ID to numerical depth value |
224 |
+ |
static inline int depth_of_video_mode(int mode) |
225 |
+ |
{ |
226 |
+ |
int depth; |
227 |
+ |
switch (mode) { |
228 |
+ |
case APPLE_1_BIT: |
229 |
+ |
depth = 1; |
230 |
+ |
break; |
231 |
+ |
case APPLE_2_BIT: |
232 |
+ |
depth = 2; |
233 |
+ |
break; |
234 |
+ |
case APPLE_4_BIT: |
235 |
+ |
depth = 4; |
236 |
+ |
break; |
237 |
+ |
case APPLE_8_BIT: |
238 |
+ |
depth = 8; |
239 |
+ |
break; |
240 |
+ |
case APPLE_16_BIT: |
241 |
+ |
depth = 16; |
242 |
+ |
break; |
243 |
+ |
case APPLE_32_BIT: |
244 |
+ |
depth = 32; |
245 |
+ |
break; |
246 |
+ |
default: |
247 |
+ |
abort(); |
248 |
+ |
} |
249 |
+ |
return depth; |
250 |
+ |
} |
251 |
+ |
|
252 |
+ |
// Map RGB color to pixel value (this only works in TrueColor/DirectColor visuals) |
253 |
+ |
static inline uint32 map_rgb(uint8 red, uint8 green, uint8 blue) |
254 |
+ |
{ |
255 |
+ |
return ((red >> rloss) << rshift) | ((green >> gloss) << gshift) | ((blue >> bloss) << bshift); |
256 |
+ |
} |
257 |
+ |
|
258 |
+ |
|
259 |
+ |
// Do we have a visual for handling the specified Mac depth? If so, set the |
260 |
+ |
// global variables "xdepth", "visualInfo", "vis" and "color_class". |
261 |
+ |
static bool find_visual_for_depth(int depth) |
262 |
+ |
{ |
263 |
+ |
D(bug("have_visual_for_depth(%d)\n", depth_of_video_mode(depth))); |
264 |
+ |
|
265 |
+ |
// 1-bit works always and uses default visual |
266 |
+ |
if (depth == APPLE_1_BIT) { |
267 |
+ |
vis = DefaultVisual(x_display, screen); |
268 |
+ |
visualInfo.visualid = XVisualIDFromVisual(vis); |
269 |
+ |
int num = 0; |
270 |
+ |
XVisualInfo *vi = XGetVisualInfo(x_display, VisualIDMask, &visualInfo, &num); |
271 |
+ |
visualInfo = vi[0]; |
272 |
+ |
XFree(vi); |
273 |
+ |
xdepth = visualInfo.depth; |
274 |
+ |
color_class = visualInfo.c_class; |
275 |
+ |
D(bug(" found visual ID 0x%02x, depth %d\n", visualInfo.visualid, xdepth)); |
276 |
+ |
return true; |
277 |
+ |
} |
278 |
+ |
|
279 |
+ |
// Calculate minimum and maximum supported X depth |
280 |
+ |
int min_depth = 1, max_depth = 32; |
281 |
+ |
switch (depth) { |
282 |
+ |
#ifdef ENABLE_VOSF |
283 |
+ |
case APPLE_2_BIT: |
284 |
+ |
case APPLE_4_BIT: // VOSF blitters can convert 2/4/8-bit -> 8/16/32-bit |
285 |
+ |
case APPLE_8_BIT: |
286 |
+ |
min_depth = 8; |
287 |
+ |
max_depth = 32; |
288 |
+ |
break; |
289 |
+ |
#else |
290 |
+ |
case APPLE_2_BIT: |
291 |
+ |
case APPLE_4_BIT: // 2/4-bit requires VOSF blitters |
292 |
+ |
return false; |
293 |
+ |
case APPLE_8_BIT: // 8-bit without VOSF requires an 8-bit visual |
294 |
+ |
min_depth = 8; |
295 |
+ |
max_depth = 8; |
296 |
+ |
break; |
297 |
+ |
#endif |
298 |
+ |
case APPLE_16_BIT: // 16-bit requires a 15/16-bit visual |
299 |
+ |
min_depth = 15; |
300 |
+ |
max_depth = 16; |
301 |
+ |
break; |
302 |
+ |
case APPLE_32_BIT: // 32-bit requires a 24/32-bit visual |
303 |
+ |
min_depth = 24; |
304 |
+ |
max_depth = 32; |
305 |
+ |
break; |
306 |
+ |
} |
307 |
+ |
D(bug(" minimum required X depth is %d, maximum supported X depth is %d\n", min_depth, max_depth)); |
308 |
+ |
|
309 |
+ |
// Try to find a visual for one of the color depths |
310 |
+ |
bool visual_found = false; |
311 |
+ |
for (int i=0; i<num_depths && !visual_found; i++) { |
312 |
+ |
|
313 |
+ |
xdepth = avail_depths[i]; |
314 |
+ |
D(bug(" trying to find visual for depth %d\n", xdepth)); |
315 |
+ |
if (xdepth < min_depth || xdepth > max_depth) |
316 |
+ |
continue; |
317 |
+ |
|
318 |
+ |
// Determine best color class for this depth |
319 |
+ |
switch (xdepth) { |
320 |
+ |
case 1: // Try StaticGray or StaticColor |
321 |
+ |
if (XMatchVisualInfo(x_display, screen, xdepth, StaticGray, &visualInfo) |
322 |
+ |
|| XMatchVisualInfo(x_display, screen, xdepth, StaticColor, &visualInfo)) |
323 |
+ |
visual_found = true; |
324 |
+ |
break; |
325 |
+ |
case 8: // Need PseudoColor |
326 |
+ |
if (XMatchVisualInfo(x_display, screen, xdepth, PseudoColor, &visualInfo)) |
327 |
+ |
visual_found = true; |
328 |
+ |
break; |
329 |
+ |
case 15: |
330 |
+ |
case 16: |
331 |
+ |
case 24: |
332 |
+ |
case 32: // Try DirectColor first, as this will allow gamma correction |
333 |
+ |
if (XMatchVisualInfo(x_display, screen, xdepth, DirectColor, &visualInfo) |
334 |
+ |
|| XMatchVisualInfo(x_display, screen, xdepth, TrueColor, &visualInfo)) |
335 |
+ |
visual_found = true; |
336 |
+ |
break; |
337 |
+ |
default: |
338 |
+ |
D(bug(" not a supported depth\n")); |
339 |
+ |
break; |
340 |
+ |
} |
341 |
+ |
} |
342 |
+ |
if (!visual_found) |
343 |
+ |
return false; |
344 |
+ |
|
345 |
+ |
// Visual was found |
346 |
+ |
vis = visualInfo.visual; |
347 |
+ |
color_class = visualInfo.c_class; |
348 |
+ |
D(bug(" found visual ID 0x%02x, depth %d, class ", visualInfo.visualid, xdepth)); |
349 |
+ |
#if DEBUG |
350 |
+ |
switch (color_class) { |
351 |
+ |
case StaticGray: D(bug("StaticGray\n")); break; |
352 |
+ |
case GrayScale: D(bug("GrayScale\n")); break; |
353 |
+ |
case StaticColor: D(bug("StaticColor\n")); break; |
354 |
+ |
case PseudoColor: D(bug("PseudoColor\n")); break; |
355 |
+ |
case TrueColor: D(bug("TrueColor\n")); break; |
356 |
+ |
case DirectColor: D(bug("DirectColor\n")); break; |
357 |
+ |
} |
358 |
+ |
#endif |
359 |
+ |
return true; |
360 |
+ |
} |
361 |
+ |
|
362 |
+ |
|
363 |
+ |
/* |
364 |
|
* Open display (window or fullscreen) |
365 |
|
*/ |
366 |
|
|
367 |
+ |
// Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget) |
368 |
+ |
static Atom WM_DELETE_WINDOW = (Atom)0; |
369 |
+ |
static void set_window_delete_protocol(Window w) |
370 |
+ |
{ |
371 |
+ |
WM_DELETE_WINDOW = XInternAtom(x_display, "WM_DELETE_WINDOW", false); |
372 |
+ |
XSetWMProtocols(x_display, w, &WM_DELETE_WINDOW, 1); |
373 |
+ |
} |
374 |
+ |
|
375 |
+ |
// Wait until window is mapped/unmapped |
376 |
+ |
static void wait_mapped(Window w) |
377 |
+ |
{ |
378 |
+ |
XEvent e; |
379 |
+ |
do { |
380 |
+ |
XMaskEvent(x_display, StructureNotifyMask, &e); |
381 |
+ |
} while ((e.type != MapNotify) || (e.xmap.event != w)); |
382 |
+ |
} |
383 |
+ |
|
384 |
+ |
static void wait_unmapped(Window w) |
385 |
+ |
{ |
386 |
+ |
XEvent e; |
387 |
+ |
do { |
388 |
+ |
XMaskEvent(x_display, StructureNotifyMask, &e); |
389 |
+ |
} while ((e.type != UnmapNotify) || (e.xmap.event != w)); |
390 |
+ |
} |
391 |
+ |
|
392 |
|
// Trap SHM errors |
393 |
|
static bool shm_error = false; |
394 |
|
static int (*old_error_handler)(Display *, XErrorEvent *); |
414 |
|
// Create window |
415 |
|
XSetWindowAttributes wattr; |
416 |
|
wattr.event_mask = eventmask = win_eventmask; |
417 |
< |
wattr.background_pixel = black_pixel; |
418 |
< |
wattr.border_pixel = black_pixel; |
417 |
> |
wattr.background_pixel = (vis == DefaultVisual(x_display, screen) ? black_pixel : 0); |
418 |
> |
wattr.border_pixel = 0; |
419 |
|
wattr.backing_store = NotUseful; |
420 |
< |
|
182 |
< |
XSync(x_display, false); |
420 |
> |
wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); |
421 |
|
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
422 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | CWBackingStore, &wattr); |
423 |
< |
XSync(x_display, false); |
422 |
> |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | CWBackingStore | CWColormap, &wattr); |
423 |
> |
|
424 |
> |
// Set window name |
425 |
|
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); |
187 |
– |
XMapRaised(x_display, the_win); |
188 |
– |
XSync(x_display, false); |
426 |
|
|
427 |
< |
// Set colormap |
428 |
< |
if (depth == 8) { |
192 |
< |
XSetWindowColormap(x_display, the_win, cmap[0]); |
193 |
< |
XSetWMColormapWindows(x_display, the_win, &the_win, 1); |
194 |
< |
} |
427 |
> |
// Set delete protocol property |
428 |
> |
set_window_delete_protocol(the_win); |
429 |
|
|
430 |
|
// Make window unresizable |
431 |
|
XSizeHints *hints; |
439 |
|
XFree((char *)hints); |
440 |
|
} |
441 |
|
|
442 |
+ |
// Show window |
443 |
+ |
XMapWindow(x_display, the_win); |
444 |
+ |
wait_mapped(the_win); |
445 |
+ |
|
446 |
|
// 1-bit mode is big-endian; if the X server is little-endian, we can't |
447 |
|
// use SHM because that doesn't allow changing the image byte order |
448 |
|
bool need_msb_image = (depth == 1 && XImageByteOrder(x_display) == LSBFirst); |
453 |
|
|
454 |
|
// Create SHM image ("height + 2" for safety) |
455 |
|
img = XShmCreateImage(x_display, vis, depth == 1 ? 1 : xdepth, depth == 1 ? XYBitmap : ZPixmap, 0, &shminfo, width, height); |
456 |
< |
shminfo.shmid = shmget(IPC_PRIVATE, (height + 2) * img->bytes_per_line, IPC_CREAT | 0777); |
456 |
> |
shminfo.shmid = shmget(IPC_PRIVATE, (aligned_height + 2) * img->bytes_per_line, IPC_CREAT | 0777); |
457 |
> |
D(bug(" shm image created\n")); |
458 |
|
the_buffer_copy = (uint8 *)shmat(shminfo.shmid, 0, 0); |
459 |
|
shminfo.shmaddr = img->data = (char *)the_buffer_copy; |
460 |
|
shminfo.readOnly = False; |
473 |
|
have_shm = true; |
474 |
|
shmctl(shminfo.shmid, IPC_RMID, 0); |
475 |
|
} |
476 |
+ |
D(bug(" shm image attached\n")); |
477 |
|
} |
478 |
|
|
479 |
|
// Create normal X image if SHM doesn't work ("height + 2" for safety) |
480 |
|
if (!have_shm) { |
481 |
< |
int bytes_per_row = aligned_width; |
242 |
< |
switch (depth) { |
243 |
< |
case 1: |
244 |
< |
bytes_per_row /= 8; |
245 |
< |
break; |
246 |
< |
case 15: |
247 |
< |
case 16: |
248 |
< |
bytes_per_row *= 2; |
249 |
< |
break; |
250 |
< |
case 24: |
251 |
< |
case 32: |
252 |
< |
bytes_per_row *= 4; |
253 |
< |
break; |
254 |
< |
} |
481 |
> |
int bytes_per_row = depth == 1 ? aligned_width/8 : TrivialBytesPerRow(aligned_width, DepthModeForPixelDepth(xdepth)); |
482 |
|
the_buffer_copy = (uint8 *)malloc((aligned_height + 2) * bytes_per_row); |
483 |
|
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); |
484 |
+ |
D(bug(" X image created\n")); |
485 |
|
} |
486 |
|
|
487 |
|
// 1-Bit mode is big-endian |
488 |
< |
if (depth == 1) { |
488 |
> |
if (need_msb_image) { |
489 |
|
img->byte_order = MSBFirst; |
490 |
|
img->bitmap_bit_order = MSBFirst; |
491 |
|
} |
503 |
|
the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line); |
504 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); |
505 |
|
#endif |
506 |
< |
screen_base = (uint32)the_buffer; |
506 |
> |
screen_base = Host2MacAddr(the_buffer); |
507 |
|
|
508 |
|
// Create GC |
509 |
|
the_gc = XCreateGC(x_display, the_win, 0, 0); |
510 |
< |
XSetForeground(x_display, the_gc, black_pixel); |
510 |
> |
XSetState(x_display, the_gc, black_pixel, white_pixel, GXcopy, AllPlanes); |
511 |
|
|
512 |
|
// Create cursor |
513 |
< |
cursor_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 4, 16, 16, 16, 2); |
514 |
< |
cursor_image->byte_order = MSBFirst; |
515 |
< |
cursor_image->bitmap_bit_order = MSBFirst; |
516 |
< |
cursor_mask_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 36, 16, 16, 16, 2); |
517 |
< |
cursor_mask_image->byte_order = MSBFirst; |
518 |
< |
cursor_mask_image->bitmap_bit_order = MSBFirst; |
519 |
< |
cursor_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
520 |
< |
cursor_mask_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
521 |
< |
cursor_gc = XCreateGC(x_display, cursor_map, 0, 0); |
522 |
< |
cursor_mask_gc = XCreateGC(x_display, cursor_mask_map, 0, 0); |
523 |
< |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, 0, 0); |
524 |
< |
cursor_changed = false; |
513 |
> |
if (hw_mac_cursor_accl) { |
514 |
> |
cursor_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 4, 16, 16, 16, 2); |
515 |
> |
cursor_image->byte_order = MSBFirst; |
516 |
> |
cursor_image->bitmap_bit_order = MSBFirst; |
517 |
> |
cursor_mask_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 36, 16, 16, 16, 2); |
518 |
> |
cursor_mask_image->byte_order = MSBFirst; |
519 |
> |
cursor_mask_image->bitmap_bit_order = MSBFirst; |
520 |
> |
cursor_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
521 |
> |
cursor_mask_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
522 |
> |
cursor_gc = XCreateGC(x_display, cursor_map, 0, 0); |
523 |
> |
cursor_mask_gc = XCreateGC(x_display, cursor_mask_map, 0, 0); |
524 |
> |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, 0, 0); |
525 |
> |
cursor_changed = false; |
526 |
> |
} |
527 |
> |
|
528 |
> |
// Create no_cursor |
529 |
> |
else { |
530 |
> |
mac_cursor = XCreatePixmapCursor(x_display, |
531 |
> |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
532 |
> |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
533 |
> |
&black, &white, 0, 0); |
534 |
> |
XDefineCursor(x_display, the_win, mac_cursor); |
535 |
> |
} |
536 |
|
|
537 |
|
// Init blitting routines |
538 |
|
bool native_byte_order; |
542 |
|
native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
543 |
|
#endif |
544 |
|
#ifdef ENABLE_VOSF |
545 |
< |
Screen_blitter_init(&visualInfo, native_byte_order, depth); |
545 |
> |
Screen_blitter_init(visualFormat, native_byte_order, depth); |
546 |
|
#endif |
547 |
|
|
548 |
|
// Set bytes per row |
310 |
– |
VModes[cur_mode].viRowBytes = img->bytes_per_line; |
549 |
|
XSync(x_display, false); |
550 |
|
return true; |
551 |
|
} |
557 |
|
// Set relative mouse mode |
558 |
|
ADBSetRelMouseMode(true); |
559 |
|
|
560 |
+ |
// Create window |
561 |
+ |
XSetWindowAttributes wattr; |
562 |
+ |
wattr.event_mask = eventmask = dga_eventmask; |
563 |
+ |
wattr.override_redirect = True; |
564 |
+ |
wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); |
565 |
+ |
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
566 |
+ |
InputOutput, vis, CWEventMask | CWOverrideRedirect | |
567 |
+ |
(color_class == DirectColor ? CWColormap : 0), &wattr); |
568 |
+ |
|
569 |
+ |
// Show window |
570 |
+ |
XMapRaised(x_display, the_win); |
571 |
+ |
wait_mapped(the_win); |
572 |
+ |
|
573 |
|
#ifdef ENABLE_XF86_VIDMODE |
574 |
|
// Switch to best mode |
575 |
|
if (has_vidmode) { |
586 |
|
#endif |
587 |
|
|
588 |
|
// Establish direct screen connection |
589 |
+ |
XMoveResizeWindow(x_display, the_win, 0, 0, width, height); |
590 |
+ |
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
591 |
|
XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
592 |
|
XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
593 |
+ |
|
594 |
+ |
int v_width, v_bank, v_size; |
595 |
+ |
XF86DGAGetVideo(x_display, screen, (char **)&the_buffer, &v_width, &v_bank, &v_size); |
596 |
|
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
597 |
|
XF86DGASetViewPort(x_display, screen, 0, 0); |
598 |
|
XF86DGASetVidPage(x_display, screen, 0); |
599 |
|
|
600 |
|
// Set colormap |
601 |
< |
if (depth == 8) |
601 |
> |
if (!IsDirectMode(get_current_mode())) { |
602 |
> |
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); |
603 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
347 |
– |
|
348 |
– |
// Set bytes per row |
349 |
– |
int bytes_per_row = (dga_fb_width + 7) & ~7; |
350 |
– |
switch (depth) { |
351 |
– |
case 15: |
352 |
– |
case 16: |
353 |
– |
bytes_per_row *= 2; |
354 |
– |
break; |
355 |
– |
case 24: |
356 |
– |
case 32: |
357 |
– |
bytes_per_row *= 4; |
358 |
– |
break; |
604 |
|
} |
605 |
+ |
XSync(x_display, false); |
606 |
|
|
607 |
+ |
// Init blitting routines |
608 |
+ |
int bytes_per_row = TrivialBytesPerRow((v_width + 7) & ~7, DepthModeForPixelDepth(depth)); |
609 |
|
#if ENABLE_VOSF |
610 |
|
bool native_byte_order; |
611 |
|
#ifdef WORDS_BIGENDIAN |
616 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
617 |
|
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
618 |
|
// i.e. the framebuffer update function is not Blit_Copy_Raw |
619 |
< |
use_vosf = Screen_blitter_init(&visualInfo, native_byte_order, depth); |
619 |
> |
use_vosf = Screen_blitter_init(visualFormat, native_byte_order, depth); |
620 |
|
|
621 |
|
if (use_vosf) { |
622 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
624 |
|
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
625 |
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
626 |
|
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
627 |
+ |
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
628 |
|
} |
629 |
|
#else |
630 |
|
use_vosf = false; |
382 |
– |
the_buffer = dga_screen_base; |
631 |
|
#endif |
632 |
|
#endif |
385 |
– |
screen_base = (uint32)the_buffer; |
633 |
|
|
634 |
+ |
// Set frame buffer base |
635 |
+ |
D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); |
636 |
+ |
screen_base = Host2MacAddr(the_buffer); |
637 |
|
VModes[cur_mode].viRowBytes = bytes_per_row; |
388 |
– |
XSync(x_display, false); |
638 |
|
return true; |
639 |
|
#else |
640 |
|
ErrorAlert("SheepShaver has been compiled with DGA support disabled."); |
644 |
|
|
645 |
|
static bool open_display(void) |
646 |
|
{ |
647 |
< |
display_type = VModes[cur_mode].viType; |
648 |
< |
switch (VModes[cur_mode].viAppleMode) { |
649 |
< |
case APPLE_1_BIT: |
650 |
< |
depth = 1; |
651 |
< |
break; |
652 |
< |
case APPLE_2_BIT: |
653 |
< |
depth = 2; |
405 |
< |
break; |
406 |
< |
case APPLE_4_BIT: |
407 |
< |
depth = 4; |
408 |
< |
break; |
409 |
< |
case APPLE_8_BIT: |
410 |
< |
depth = 8; |
411 |
< |
break; |
412 |
< |
case APPLE_16_BIT: |
413 |
< |
depth = xdepth == 15 ? 15 : 16; |
414 |
< |
break; |
415 |
< |
case APPLE_32_BIT: |
416 |
< |
depth = 32; |
417 |
< |
break; |
647 |
> |
D(bug("open_display()\n")); |
648 |
> |
const VideoInfo &mode = VModes[cur_mode]; |
649 |
> |
|
650 |
> |
// Find best available X visual |
651 |
> |
if (!find_visual_for_depth(mode.viAppleMode)) { |
652 |
> |
ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); |
653 |
> |
return false; |
654 |
|
} |
655 |
|
|
656 |
+ |
// Build up visualFormat structure |
657 |
+ |
visualFormat.depth = visualInfo.depth; |
658 |
+ |
visualFormat.Rmask = visualInfo.red_mask; |
659 |
+ |
visualFormat.Gmask = visualInfo.green_mask; |
660 |
+ |
visualFormat.Bmask = visualInfo.blue_mask; |
661 |
+ |
|
662 |
+ |
// Create color maps |
663 |
+ |
if (color_class == PseudoColor || color_class == DirectColor) { |
664 |
+ |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
665 |
+ |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
666 |
+ |
} else { |
667 |
+ |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocNone); |
668 |
+ |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocNone); |
669 |
+ |
} |
670 |
+ |
|
671 |
+ |
// Find pixel format of direct modes |
672 |
+ |
if (color_class == DirectColor || color_class == TrueColor) { |
673 |
+ |
rshift = gshift = bshift = 0; |
674 |
+ |
rloss = gloss = bloss = 8; |
675 |
+ |
uint32 mask; |
676 |
+ |
for (mask=vis->red_mask; !(mask&1); mask>>=1) |
677 |
+ |
++rshift; |
678 |
+ |
for (; mask&1; mask>>=1) |
679 |
+ |
--rloss; |
680 |
+ |
for (mask=vis->green_mask; !(mask&1); mask>>=1) |
681 |
+ |
++gshift; |
682 |
+ |
for (; mask&1; mask>>=1) |
683 |
+ |
--gloss; |
684 |
+ |
for (mask=vis->blue_mask; !(mask&1); mask>>=1) |
685 |
+ |
++bshift; |
686 |
+ |
for (; mask&1; mask>>=1) |
687 |
+ |
--bloss; |
688 |
+ |
} |
689 |
+ |
|
690 |
+ |
// Preset palette pixel values for CLUT or gamma table |
691 |
+ |
if (color_class == DirectColor) { |
692 |
+ |
int num = vis->map_entries; |
693 |
+ |
for (int i=0; i<num; i++) { |
694 |
+ |
int c = (i * 256) / num; |
695 |
+ |
x_palette[i].pixel = map_rgb(c, c, c); |
696 |
+ |
x_palette[i].flags = DoRed | DoGreen | DoBlue; |
697 |
+ |
} |
698 |
+ |
} else if (color_class == PseudoColor) { |
699 |
+ |
for (int i=0; i<256; i++) { |
700 |
+ |
x_palette[i].pixel = i; |
701 |
+ |
x_palette[i].flags = DoRed | DoGreen | DoBlue; |
702 |
+ |
} |
703 |
+ |
} |
704 |
+ |
|
705 |
+ |
// Load gray ramp to color map |
706 |
+ |
int num = (color_class == DirectColor ? vis->map_entries : 256); |
707 |
+ |
for (int i=0; i<num; i++) { |
708 |
+ |
int c = (i * 256) / num; |
709 |
+ |
x_palette[i].red = c * 0x0101; |
710 |
+ |
x_palette[i].green = c * 0x0101; |
711 |
+ |
x_palette[i].blue = c * 0x0101; |
712 |
+ |
} |
713 |
+ |
if (color_class == PseudoColor || color_class == DirectColor) { |
714 |
+ |
XStoreColors(x_display, cmap[0], x_palette, num); |
715 |
+ |
XStoreColors(x_display, cmap[1], x_palette, num); |
716 |
+ |
} |
717 |
+ |
|
718 |
+ |
#ifdef ENABLE_VOSF |
719 |
+ |
// Load gray ramp to 8->16/32 expand map |
720 |
+ |
if (!IsDirectMode(get_current_mode()) && xdepth > 8) |
721 |
+ |
for (int i=0; i<256; i++) |
722 |
+ |
ExpandMap[i] = map_rgb(i, i, i); |
723 |
+ |
#endif |
724 |
+ |
|
725 |
+ |
// Create display of requested type |
726 |
+ |
display_type = mode.viType; |
727 |
+ |
depth = depth_of_video_mode(mode.viAppleMode); |
728 |
+ |
|
729 |
|
bool display_open = false; |
730 |
|
if (display_type == DIS_SCREEN) |
731 |
|
display_open = open_dga(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
773 |
|
if (the_gc) |
774 |
|
XFreeGC(x_display, the_gc); |
775 |
|
|
776 |
< |
// Close window |
777 |
< |
XDestroyWindow(x_display, the_win); |
776 |
> |
XFlush(x_display); |
777 |
> |
XSync(x_display, false); |
778 |
|
} |
779 |
|
|
780 |
|
// Close DGA mode |
810 |
|
else if (display_type == DIS_WINDOW) |
811 |
|
close_window(); |
812 |
|
|
813 |
+ |
// Close window |
814 |
+ |
if (the_win) { |
815 |
+ |
XUnmapWindow(x_display, the_win); |
816 |
+ |
wait_unmapped(the_win); |
817 |
+ |
XDestroyWindow(x_display, the_win); |
818 |
+ |
} |
819 |
+ |
|
820 |
+ |
// Free colormaps |
821 |
+ |
if (cmap[0]) { |
822 |
+ |
XFreeColormap(x_display, cmap[0]); |
823 |
+ |
cmap[0] = 0; |
824 |
+ |
} |
825 |
+ |
if (cmap[1]) { |
826 |
+ |
XFreeColormap(x_display, cmap[1]); |
827 |
+ |
cmap[1] = 0; |
828 |
+ |
} |
829 |
+ |
|
830 |
|
#ifdef ENABLE_VOSF |
831 |
|
if (use_vosf) { |
832 |
|
// Deinitialize VOSF |
892 |
|
|
893 |
|
// Search for server vendor string, then read keycodes |
894 |
|
const char *vendor = ServerVendor(x_display); |
895 |
+ |
// Force use of MacX mappings on MacOS X with Apple's X server |
896 |
+ |
int dummy; |
897 |
+ |
if (XQueryExtension(x_display, "Apple-DRI", &dummy, &dummy, &dummy)) |
898 |
+ |
vendor = "MacX"; |
899 |
|
bool vendor_found = false; |
900 |
|
char line[256]; |
901 |
|
while (fgets(line, 255, f)) { |
937 |
|
} |
938 |
|
} |
939 |
|
|
940 |
< |
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, long apple_mode, long apple_id, int type) |
940 |
> |
// Find Apple mode matching best specified dimensions |
941 |
> |
static int find_apple_resolution(int xsize, int ysize) |
942 |
> |
{ |
943 |
> |
int apple_id; |
944 |
> |
if (xsize < 800) |
945 |
> |
apple_id = APPLE_640x480; |
946 |
> |
else if (xsize < 1024) |
947 |
> |
apple_id = APPLE_800x600; |
948 |
> |
else if (xsize < 1152) |
949 |
> |
apple_id = APPLE_1024x768; |
950 |
> |
else if (xsize < 1280) { |
951 |
> |
if (ysize < 900) |
952 |
> |
apple_id = APPLE_1152x768; |
953 |
> |
else |
954 |
> |
apple_id = APPLE_1152x900; |
955 |
> |
} |
956 |
> |
else if (xsize < 1600) |
957 |
> |
apple_id = APPLE_1280x1024; |
958 |
> |
else |
959 |
> |
apple_id = APPLE_1600x1200; |
960 |
> |
return apple_id; |
961 |
> |
} |
962 |
> |
|
963 |
> |
// Find mode in list of supported modes |
964 |
> |
static int find_mode(int apple_mode, int apple_id, int type) |
965 |
> |
{ |
966 |
> |
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
967 |
> |
if (p->viType == type && p->viAppleID == apple_id && p->viAppleMode == apple_mode) |
968 |
> |
return p - VModes; |
969 |
> |
} |
970 |
> |
return -1; |
971 |
> |
} |
972 |
> |
|
973 |
> |
// Add custom video mode |
974 |
> |
static void add_custom_mode(VideoInfo *&p, int type, uint32 x, uint32 y, int apple_mode, int apple_id) |
975 |
> |
{ |
976 |
> |
p->viType = type; |
977 |
> |
p->viXsize = x; |
978 |
> |
p->viYsize = y; |
979 |
> |
p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); |
980 |
> |
p->viAppleMode = apple_mode; |
981 |
> |
p->viAppleID = apple_id; |
982 |
> |
p++; |
983 |
> |
} |
984 |
> |
|
985 |
> |
// Add mode to list of supported modes |
986 |
> |
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type) |
987 |
|
{ |
988 |
|
if (allow & test) { |
989 |
< |
p->viType = type; |
989 |
> |
uint32 x = 0, y = 0; |
990 |
|
switch (apple_id) { |
991 |
|
case APPLE_W_640x480: |
992 |
|
case APPLE_640x480: |
993 |
< |
p->viXsize = 640; |
994 |
< |
p->viYsize = 480; |
993 |
> |
x = 640; |
994 |
> |
y = 480; |
995 |
|
break; |
996 |
|
case APPLE_W_800x600: |
997 |
|
case APPLE_800x600: |
998 |
< |
p->viXsize = 800; |
999 |
< |
p->viYsize = 600; |
998 |
> |
x = 800; |
999 |
> |
y = 600; |
1000 |
|
break; |
1001 |
|
case APPLE_1024x768: |
1002 |
< |
p->viXsize = 1024; |
1003 |
< |
p->viYsize = 768; |
1002 |
> |
x = 1024; |
1003 |
> |
y = 768; |
1004 |
> |
break; |
1005 |
> |
case APPLE_1152x768: |
1006 |
> |
x = 1152; |
1007 |
> |
y = 768; |
1008 |
|
break; |
1009 |
|
case APPLE_1152x900: |
1010 |
< |
p->viXsize = 1152; |
1011 |
< |
p->viYsize = 900; |
1010 |
> |
x = 1152; |
1011 |
> |
y = 900; |
1012 |
|
break; |
1013 |
|
case APPLE_1280x1024: |
1014 |
< |
p->viXsize = 1280; |
1015 |
< |
p->viYsize = 1024; |
1014 |
> |
x = 1280; |
1015 |
> |
y = 1024; |
1016 |
|
break; |
1017 |
|
case APPLE_1600x1200: |
1018 |
< |
p->viXsize = 1600; |
1019 |
< |
p->viYsize = 1200; |
1018 |
> |
x = 1600; |
1019 |
> |
y = 1200; |
1020 |
|
break; |
1021 |
|
} |
1022 |
< |
switch (apple_mode) { |
643 |
< |
case APPLE_8_BIT: |
644 |
< |
p->viRowBytes = p->viXsize; |
645 |
< |
break; |
646 |
< |
case APPLE_16_BIT: |
647 |
< |
p->viRowBytes = p->viXsize * 2; |
648 |
< |
break; |
649 |
< |
case APPLE_32_BIT: |
650 |
< |
p->viRowBytes = p->viXsize * 4; |
651 |
< |
break; |
652 |
< |
} |
653 |
< |
p->viAppleMode = apple_mode; |
654 |
< |
p->viAppleID = apple_id; |
655 |
< |
p++; |
1022 |
> |
add_custom_mode(p, type, x, y, apple_mode, apple_id); |
1023 |
|
} |
1024 |
|
} |
1025 |
|
|
1026 |
+ |
// Add standard list of windowed modes for given color depth |
1027 |
+ |
static void add_window_modes(VideoInfo *&p, int window_modes, int mode) |
1028 |
+ |
{ |
1029 |
+ |
add_mode(p, window_modes, 1, mode, APPLE_W_640x480, DIS_WINDOW); |
1030 |
+ |
add_mode(p, window_modes, 2, mode, APPLE_W_800x600, DIS_WINDOW); |
1031 |
+ |
} |
1032 |
+ |
|
1033 |
|
static bool has_mode(int x, int y) |
1034 |
|
{ |
1035 |
|
#ifdef ENABLE_XF86_VIDMODE |
1068 |
|
|
1069 |
|
// Init variables |
1070 |
|
private_data = NULL; |
697 |
– |
cur_mode = 0; // Window 640x480 |
1071 |
|
video_activated = true; |
1072 |
|
|
1073 |
|
// Find screen and root window |
1074 |
|
screen = XDefaultScreen(x_display); |
1075 |
|
rootwin = XRootWindow(x_display, screen); |
1076 |
|
|
1077 |
+ |
// Get sorted list of available depths |
1078 |
+ |
avail_depths = XListDepths(x_display, screen, &num_depths); |
1079 |
+ |
if (avail_depths == NULL) { |
1080 |
+ |
ErrorAlert(GetString(STR_UNSUPP_DEPTH_ERR)); |
1081 |
+ |
return false; |
1082 |
+ |
} |
1083 |
+ |
sort(avail_depths, avail_depths + num_depths); |
1084 |
+ |
|
1085 |
|
// Get screen depth |
1086 |
|
xdepth = DefaultDepth(x_display, screen); |
1087 |
|
|
1112 |
|
black_pixel = BlackPixel(x_display, screen); |
1113 |
|
white_pixel = WhitePixel(x_display, screen); |
1114 |
|
|
734 |
– |
// Get appropriate visual |
735 |
– |
int color_class; |
736 |
– |
switch (xdepth) { |
737 |
– |
#if 0 |
738 |
– |
case 1: |
739 |
– |
color_class = StaticGray; |
740 |
– |
break; |
741 |
– |
#endif |
742 |
– |
case 8: |
743 |
– |
color_class = PseudoColor; |
744 |
– |
break; |
745 |
– |
case 15: |
746 |
– |
case 16: |
747 |
– |
case 24: |
748 |
– |
case 32: |
749 |
– |
color_class = TrueColor; |
750 |
– |
break; |
751 |
– |
default: |
752 |
– |
ErrorAlert(GetString(STR_UNSUPP_DEPTH_ERR)); |
753 |
– |
return false; |
754 |
– |
} |
755 |
– |
if (!XMatchVisualInfo(x_display, screen, xdepth, color_class, &visualInfo)) { |
756 |
– |
ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); |
757 |
– |
return false; |
758 |
– |
} |
759 |
– |
if (visualInfo.depth != xdepth) { |
760 |
– |
ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); |
761 |
– |
return false; |
762 |
– |
} |
763 |
– |
vis = visualInfo.visual; |
764 |
– |
|
1115 |
|
// Mac screen depth follows X depth (for now) |
1116 |
< |
depth = xdepth; |
1117 |
< |
|
1118 |
< |
// Create color maps for 8 bit mode |
1119 |
< |
if (depth == 8) { |
1120 |
< |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1121 |
< |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1122 |
< |
XInstallColormap(x_display, cmap[0]); |
1123 |
< |
XInstallColormap(x_display, cmap[1]); |
1116 |
> |
int default_mode = APPLE_8_BIT; |
1117 |
> |
switch (DefaultDepth(x_display, screen)) { |
1118 |
> |
case 1: |
1119 |
> |
default_mode = APPLE_1_BIT; |
1120 |
> |
break; |
1121 |
> |
case 8: |
1122 |
> |
default_mode = APPLE_8_BIT; |
1123 |
> |
break; |
1124 |
> |
case 15: case 16: |
1125 |
> |
default_mode = APPLE_16_BIT; |
1126 |
> |
break; |
1127 |
> |
case 24: case 32: |
1128 |
> |
default_mode = APPLE_32_BIT; |
1129 |
> |
break; |
1130 |
|
} |
1131 |
|
|
1132 |
|
// Construct video mode table |
777 |
– |
int mode = APPLE_8_BIT; |
778 |
– |
int bpr_mult = 8; |
779 |
– |
switch (depth) { |
780 |
– |
case 1: |
781 |
– |
mode = APPLE_1_BIT; |
782 |
– |
bpr_mult = 1; |
783 |
– |
break; |
784 |
– |
case 8: |
785 |
– |
mode = APPLE_8_BIT; |
786 |
– |
bpr_mult = 8; |
787 |
– |
break; |
788 |
– |
case 15: |
789 |
– |
case 16: |
790 |
– |
mode = APPLE_16_BIT; |
791 |
– |
bpr_mult = 16; |
792 |
– |
break; |
793 |
– |
case 24: |
794 |
– |
case 32: |
795 |
– |
mode = APPLE_32_BIT; |
796 |
– |
bpr_mult = 32; |
797 |
– |
break; |
798 |
– |
} |
799 |
– |
|
1133 |
|
uint32 window_modes = PrefsFindInt32("windowmodes"); |
1134 |
|
uint32 screen_modes = PrefsFindInt32("screenmodes"); |
1135 |
|
if (!has_dga) |
1138 |
|
window_modes |= 3; // Allow at least 640x480 and 800x600 window modes |
1139 |
|
|
1140 |
|
VideoInfo *p = VModes; |
1141 |
< |
add_mode(p, window_modes, 1, mode, APPLE_W_640x480, DIS_WINDOW); |
1142 |
< |
add_mode(p, window_modes, 2, mode, APPLE_W_800x600, DIS_WINDOW); |
1141 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) |
1142 |
> |
if (find_visual_for_depth(d)) |
1143 |
> |
add_window_modes(p, window_modes, d); |
1144 |
> |
|
1145 |
|
if (has_vidmode) { |
1146 |
|
if (has_mode(640, 480)) |
1147 |
< |
add_mode(p, screen_modes, 1, mode, APPLE_640x480, DIS_SCREEN); |
1147 |
> |
add_mode(p, screen_modes, 1, default_mode, APPLE_640x480, DIS_SCREEN); |
1148 |
|
if (has_mode(800, 600)) |
1149 |
< |
add_mode(p, screen_modes, 2, mode, APPLE_800x600, DIS_SCREEN); |
1149 |
> |
add_mode(p, screen_modes, 2, default_mode, APPLE_800x600, DIS_SCREEN); |
1150 |
|
if (has_mode(1024, 768)) |
1151 |
< |
add_mode(p, screen_modes, 4, mode, APPLE_1024x768, DIS_SCREEN); |
1151 |
> |
add_mode(p, screen_modes, 4, default_mode, APPLE_1024x768, DIS_SCREEN); |
1152 |
> |
if (has_mode(1152, 768)) |
1153 |
> |
add_mode(p, screen_modes, 64, default_mode, APPLE_1152x768, DIS_SCREEN); |
1154 |
|
if (has_mode(1152, 900)) |
1155 |
< |
add_mode(p, screen_modes, 8, mode, APPLE_1152x900, DIS_SCREEN); |
1155 |
> |
add_mode(p, screen_modes, 8, default_mode, APPLE_1152x900, DIS_SCREEN); |
1156 |
|
if (has_mode(1280, 1024)) |
1157 |
< |
add_mode(p, screen_modes, 16, mode, APPLE_1280x1024, DIS_SCREEN); |
1157 |
> |
add_mode(p, screen_modes, 16, default_mode, APPLE_1280x1024, DIS_SCREEN); |
1158 |
|
if (has_mode(1600, 1200)) |
1159 |
< |
add_mode(p, screen_modes, 32, mode, APPLE_1600x1200, DIS_SCREEN); |
1159 |
> |
add_mode(p, screen_modes, 32, default_mode, APPLE_1600x1200, DIS_SCREEN); |
1160 |
|
} else if (screen_modes) { |
1161 |
|
int xsize = DisplayWidth(x_display, screen); |
1162 |
|
int ysize = DisplayHeight(x_display, screen); |
1163 |
< |
int apple_id; |
827 |
< |
if (xsize < 800) |
828 |
< |
apple_id = APPLE_640x480; |
829 |
< |
else if (xsize < 1024) |
830 |
< |
apple_id = APPLE_800x600; |
831 |
< |
else if (xsize < 1152) |
832 |
< |
apple_id = APPLE_1024x768; |
833 |
< |
else if (xsize < 1280) |
834 |
< |
apple_id = APPLE_1152x900; |
835 |
< |
else if (xsize < 1600) |
836 |
< |
apple_id = APPLE_1280x1024; |
837 |
< |
else |
838 |
< |
apple_id = APPLE_1600x1200; |
1163 |
> |
int apple_id = find_apple_resolution(xsize, ysize); |
1164 |
|
p->viType = DIS_SCREEN; |
1165 |
|
p->viRowBytes = 0; |
1166 |
|
p->viXsize = xsize; |
1167 |
|
p->viYsize = ysize; |
1168 |
< |
p->viAppleMode = mode; |
1168 |
> |
p->viAppleMode = default_mode; |
1169 |
|
p->viAppleID = apple_id; |
1170 |
|
p++; |
1171 |
|
} |
1175 |
|
p->viAppleMode = 0; |
1176 |
|
p->viAppleID = 0; |
1177 |
|
|
1178 |
< |
#ifdef ENABLE_XF86_DGA |
1178 |
> |
// Find default mode (window 640x480) |
1179 |
> |
cur_mode = -1; |
1180 |
|
if (has_dga && screen_modes) { |
1181 |
< |
int v_bank, v_size; |
1182 |
< |
XF86DGAGetVideo(x_display, screen, &dga_screen_base, &dga_fb_width, &v_bank, &v_size); |
1183 |
< |
D(bug("DGA screen_base %p, v_width %d\n", dga_screen_base, dga_fb_width)); |
1181 |
> |
int screen_width = DisplayWidth(x_display, screen); |
1182 |
> |
int screen_height = DisplayHeight(x_display, screen); |
1183 |
> |
int apple_id = find_apple_resolution(screen_width, screen_height); |
1184 |
> |
if (apple_id != -1) |
1185 |
> |
cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN); |
1186 |
> |
} |
1187 |
> |
if (cur_mode == -1) { |
1188 |
> |
// pick up first windowed mode available |
1189 |
> |
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
1190 |
> |
if (p->viType == DIS_WINDOW && p->viAppleMode == default_mode) { |
1191 |
> |
cur_mode = p - VModes; |
1192 |
> |
break; |
1193 |
> |
} |
1194 |
> |
} |
1195 |
> |
} |
1196 |
> |
assert(cur_mode != -1); |
1197 |
> |
|
1198 |
> |
#if DEBUG |
1199 |
> |
D(bug("Available video modes:\n")); |
1200 |
> |
for (p = VModes; p->viType != DIS_INVALID; p++) { |
1201 |
> |
int bits = depth_of_video_mode(p->viAppleMode); |
1202 |
> |
D(bug(" %dx%d (ID %02x), %d colors\n", p->viXsize, p->viYsize, p->viAppleID, 1 << bits)); |
1203 |
|
} |
1204 |
|
#endif |
1205 |
|
|
1214 |
|
|
1215 |
|
// Start periodic thread |
1216 |
|
XSync(x_display, false); |
1217 |
< |
redraw_thread_active = (pthread_create(&redraw_thread, NULL, redraw_func, NULL) == 0); |
1217 |
> |
Set_pthread_attr(&redraw_thread_attr, 0); |
1218 |
> |
redraw_thread_cancel = false; |
1219 |
> |
redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0); |
1220 |
|
D(bug("Redraw thread installed (%ld)\n", redraw_thread)); |
1221 |
|
return true; |
1222 |
|
} |
1230 |
|
{ |
1231 |
|
// Stop redraw thread |
1232 |
|
if (redraw_thread_active) { |
1233 |
+ |
redraw_thread_cancel = true; |
1234 |
|
pthread_cancel(redraw_thread); |
1235 |
|
pthread_join(redraw_thread, NULL); |
1236 |
|
redraw_thread_active = false; |
1249 |
|
close_display(); |
1250 |
|
XFlush(x_display); |
1251 |
|
XSync(x_display, false); |
904 |
– |
if (depth == 8) { |
905 |
– |
XFreeColormap(x_display, cmap[0]); |
906 |
– |
XFreeColormap(x_display, cmap[1]); |
907 |
– |
} |
1252 |
|
} |
1253 |
|
} |
1254 |
|
|
1274 |
|
// Save frame buffer |
1275 |
|
fb_save = malloc(VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1276 |
|
if (fb_save) |
1277 |
< |
memcpy(fb_save, (void *)screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1277 |
> |
Mac2Host_memcpy(fb_save, screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1278 |
|
|
1279 |
|
// Close full screen display |
1280 |
|
#ifdef ENABLE_XF86_DGA |
1312 |
|
// Reopen full screen display |
1313 |
|
XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime); |
1314 |
|
XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
1315 |
+ |
#ifdef ENABLE_XF86_DGA |
1316 |
|
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
1317 |
|
XF86DGASetViewPort(x_display, screen, 0, 0); |
1318 |
+ |
#endif |
1319 |
|
XSync(x_display, false); |
1320 |
|
|
1321 |
|
// the_buffer already contains the data to restore. i.e. since a temporary |
1336 |
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1337 |
|
if (!use_vosf) |
1338 |
|
#endif |
1339 |
< |
memcpy((void *)screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1339 |
> |
Host2Mac_memcpy(screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1340 |
|
free(fb_save); |
1341 |
|
fb_save = NULL; |
1342 |
|
} |
1509 |
|
return -1; |
1510 |
|
} |
1511 |
|
|
1512 |
< |
static int event2keycode(XKeyEvent &ev) |
1512 |
> |
static int event2keycode(XKeyEvent &ev, bool key_down) |
1513 |
|
{ |
1514 |
|
KeySym ks; |
1169 |
– |
int as; |
1515 |
|
int i = 0; |
1516 |
|
|
1517 |
|
do { |
1518 |
|
ks = XLookupKeysym(&ev, i++); |
1519 |
< |
as = kc_decode(ks); |
1520 |
< |
if (as != -1) |
1519 |
> |
int as = kc_decode(ks); |
1520 |
> |
if (as >= 0) |
1521 |
> |
return as; |
1522 |
> |
if (as == -2) |
1523 |
|
return as; |
1524 |
|
} while (ks != NoSymbol); |
1525 |
|
|
1540 |
|
else if (XCheckTypedEvent(x_display, SelectionClear, &event)) |
1541 |
|
ClipboardSelectionClear(&event.xselectionclear); |
1542 |
|
|
1543 |
+ |
// Window "close" widget clicked |
1544 |
+ |
else if (XCheckTypedEvent(x_display, ClientMessage, &event)) { |
1545 |
+ |
if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW) { |
1546 |
+ |
ADBKeyDown(0x7f); // Power key |
1547 |
+ |
ADBKeyUp(0x7f); |
1548 |
+ |
} |
1549 |
+ |
} |
1550 |
+ |
|
1551 |
|
XDisplayUnlock(); |
1552 |
|
break; |
1553 |
|
} |
1581 |
|
break; |
1582 |
|
} |
1583 |
|
|
1584 |
< |
// Mouse moved |
1584 |
> |
// Mouse entered window |
1585 |
|
case EnterNotify: |
1586 |
< |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1586 |
> |
if (event.xcrossing.mode != NotifyGrab && event.xcrossing.mode != NotifyUngrab) |
1587 |
> |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
1588 |
|
break; |
1589 |
+ |
|
1590 |
+ |
// Mouse moved |
1591 |
|
case MotionNotify: |
1592 |
< |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1592 |
> |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
1593 |
|
break; |
1594 |
|
|
1595 |
|
// Keyboard |
1596 |
|
case KeyPress: { |
1597 |
< |
int code = event2keycode(event.xkey); |
1598 |
< |
if (use_keycodes && code != -1) |
1599 |
< |
code = keycode_table[event.xkey.keycode & 0xff]; |
1600 |
< |
if (code != -1) { |
1597 |
> |
int code = -1; |
1598 |
> |
if (use_keycodes) { |
1599 |
> |
if (event2keycode(event.xkey, true) != -2) // This is called to process the hotkeys |
1600 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1601 |
> |
} else |
1602 |
> |
code = event2keycode(event.xkey, true); |
1603 |
> |
if (code >= 0) { |
1604 |
|
if (!emul_suspended) { |
1605 |
< |
ADBKeyDown(code); |
1605 |
> |
if (code == 0x39) { // Caps Lock pressed |
1606 |
> |
if (caps_on) { |
1607 |
> |
ADBKeyUp(code); |
1608 |
> |
caps_on = false; |
1609 |
> |
} else { |
1610 |
> |
ADBKeyDown(code); |
1611 |
> |
caps_on = true; |
1612 |
> |
} |
1613 |
> |
} else |
1614 |
> |
ADBKeyDown(code); |
1615 |
|
if (code == 0x36) |
1616 |
|
ctrl_down = true; |
1617 |
|
} else { |
1622 |
|
break; |
1623 |
|
} |
1624 |
|
case KeyRelease: { |
1625 |
< |
int code = event2keycode(event.xkey); |
1626 |
< |
if (use_keycodes && code != 1) |
1627 |
< |
code = keycode_table[event.xkey.keycode & 0xff]; |
1628 |
< |
if (code != -1) { |
1625 |
> |
int code = -1; |
1626 |
> |
if (use_keycodes) { |
1627 |
> |
if (event2keycode(event.xkey, false) != -2) // This is called to process the hotkeys |
1628 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1629 |
> |
} else |
1630 |
> |
code = event2keycode(event.xkey, false); |
1631 |
> |
if (code >= 0 && code != 0x39) { // Don't propagate Caps Lock releases |
1632 |
|
ADBKeyUp(code); |
1633 |
|
if (code == 0x36) |
1634 |
|
ctrl_down = false; |
1668 |
|
|
1669 |
|
|
1670 |
|
/* |
1298 |
– |
* Install graphics acceleration |
1299 |
– |
*/ |
1300 |
– |
|
1301 |
– |
#if 0 |
1302 |
– |
// Rectangle blitting |
1303 |
– |
static void accl_bitblt(accl_params *p) |
1304 |
– |
{ |
1305 |
– |
D(bug("accl_bitblt\n")); |
1306 |
– |
|
1307 |
– |
// Get blitting parameters |
1308 |
– |
int16 src_X = p->src_rect[1] - p->src_bounds[1]; |
1309 |
– |
int16 src_Y = p->src_rect[0] - p->src_bounds[0]; |
1310 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1311 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1312 |
– |
int16 width = p->dest_rect[3] - p->dest_rect[1] - 1; |
1313 |
– |
int16 height = p->dest_rect[2] - p->dest_rect[0] - 1; |
1314 |
– |
D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y)); |
1315 |
– |
D(bug(" width %d, height %d\n", width, height)); |
1316 |
– |
|
1317 |
– |
// And perform the blit |
1318 |
– |
bitblt_hook(src_X, src_Y, dest_X, dest_Y, width, height); |
1319 |
– |
} |
1320 |
– |
|
1321 |
– |
static bool accl_bitblt_hook(accl_params *p) |
1322 |
– |
{ |
1323 |
– |
D(bug("accl_draw_hook %p\n", p)); |
1324 |
– |
|
1325 |
– |
// Check if we can accelerate this bitblt |
1326 |
– |
if (p->src_base_addr == screen_base && p->dest_base_addr == screen_base && |
1327 |
– |
display_type == DIS_SCREEN && bitblt_hook != NULL && |
1328 |
– |
((uint32 *)p)[0x18 >> 2] + ((uint32 *)p)[0x128 >> 2] == 0 && |
1329 |
– |
((uint32 *)p)[0x130 >> 2] == 0 && |
1330 |
– |
p->transfer_mode == 0 && |
1331 |
– |
p->src_row_bytes > 0 && ((uint32 *)p)[0x15c >> 2] > 0) { |
1332 |
– |
|
1333 |
– |
// Yes, set function pointer |
1334 |
– |
p->draw_proc = accl_bitblt; |
1335 |
– |
return true; |
1336 |
– |
} |
1337 |
– |
return false; |
1338 |
– |
} |
1339 |
– |
|
1340 |
– |
// Rectangle filling/inversion |
1341 |
– |
static void accl_fillrect8(accl_params *p) |
1342 |
– |
{ |
1343 |
– |
D(bug("accl_fillrect8\n")); |
1344 |
– |
|
1345 |
– |
// Get filling parameters |
1346 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1347 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1348 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1349 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1350 |
– |
uint8 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
1351 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1352 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1353 |
– |
|
1354 |
– |
// And perform the fill |
1355 |
– |
fillrect8_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
1356 |
– |
} |
1357 |
– |
|
1358 |
– |
static void accl_fillrect32(accl_params *p) |
1359 |
– |
{ |
1360 |
– |
D(bug("accl_fillrect32\n")); |
1361 |
– |
|
1362 |
– |
// Get filling parameters |
1363 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1364 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1365 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1366 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1367 |
– |
uint32 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
1368 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1369 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1370 |
– |
|
1371 |
– |
// And perform the fill |
1372 |
– |
fillrect32_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
1373 |
– |
} |
1374 |
– |
|
1375 |
– |
static void accl_invrect(accl_params *p) |
1376 |
– |
{ |
1377 |
– |
D(bug("accl_invrect\n")); |
1378 |
– |
|
1379 |
– |
// Get inversion parameters |
1380 |
– |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1381 |
– |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1382 |
– |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1383 |
– |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1384 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1385 |
– |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1386 |
– |
|
1387 |
– |
//!!?? pen_mode == 14 |
1388 |
– |
|
1389 |
– |
// And perform the inversion |
1390 |
– |
invrect_hook(dest_X, dest_Y, dest_X_max, dest_Y_max); |
1391 |
– |
} |
1392 |
– |
|
1393 |
– |
static bool accl_fillrect_hook(accl_params *p) |
1394 |
– |
{ |
1395 |
– |
D(bug("accl_fillrect_hook %p\n", p)); |
1396 |
– |
|
1397 |
– |
// Check if we can accelerate this fillrect |
1398 |
– |
if (p->dest_base_addr == screen_base && ((uint32 *)p)[0x284 >> 2] != 0 && display_type == DIS_SCREEN) { |
1399 |
– |
if (p->transfer_mode == 8) { |
1400 |
– |
// Fill |
1401 |
– |
if (p->dest_pixel_size == 8 && fillrect8_hook != NULL) { |
1402 |
– |
p->draw_proc = accl_fillrect8; |
1403 |
– |
return true; |
1404 |
– |
} else if (p->dest_pixel_size == 32 && fillrect32_hook != NULL) { |
1405 |
– |
p->draw_proc = accl_fillrect32; |
1406 |
– |
return true; |
1407 |
– |
} |
1408 |
– |
} else if (p->transfer_mode == 10 && invrect_hook != NULL) { |
1409 |
– |
// Invert |
1410 |
– |
p->draw_proc = accl_invrect; |
1411 |
– |
return true; |
1412 |
– |
} |
1413 |
– |
} |
1414 |
– |
return false; |
1415 |
– |
} |
1416 |
– |
|
1417 |
– |
// Wait for graphics operation to finish |
1418 |
– |
static bool accl_sync_hook(void *arg) |
1419 |
– |
{ |
1420 |
– |
D(bug("accl_sync_hook %p\n", arg)); |
1421 |
– |
if (sync_hook != NULL) |
1422 |
– |
sync_hook(); |
1423 |
– |
return true; |
1424 |
– |
} |
1425 |
– |
|
1426 |
– |
static struct accl_hook_info bitblt_hook_info = {accl_bitblt_hook, accl_sync_hook, ACCL_BITBLT}; |
1427 |
– |
static struct accl_hook_info fillrect_hook_info = {accl_fillrect_hook, accl_sync_hook, ACCL_FILLRECT}; |
1428 |
– |
#endif |
1429 |
– |
|
1430 |
– |
void VideoInstallAccel(void) |
1431 |
– |
{ |
1432 |
– |
// Install acceleration hooks |
1433 |
– |
if (PrefsFindBool("gfxaccel")) { |
1434 |
– |
D(bug("Video: Installing acceleration hooks\n")); |
1435 |
– |
//!! NQDMisc(6, &bitblt_hook_info); |
1436 |
– |
// NQDMisc(6, &fillrect_hook_info); |
1437 |
– |
} |
1438 |
– |
} |
1439 |
– |
|
1440 |
– |
|
1441 |
– |
/* |
1671 |
|
* Change video mode |
1672 |
|
*/ |
1673 |
|
|
1725 |
|
|
1726 |
|
void video_set_palette(void) |
1727 |
|
{ |
1728 |
+ |
LOCK_PALETTE; |
1729 |
+ |
|
1730 |
+ |
// Convert colors to XColor array |
1731 |
+ |
int mode = get_current_mode(); |
1732 |
+ |
int num_in = palette_size(mode); |
1733 |
+ |
int num_out = 256; |
1734 |
+ |
bool stretch = false; |
1735 |
+ |
if (IsDirectMode(mode)) { |
1736 |
+ |
// If X is in 565 mode we have to stretch the gamma table from 32 to 64 entries |
1737 |
+ |
num_out = vis->map_entries; |
1738 |
+ |
stretch = true; |
1739 |
+ |
} |
1740 |
+ |
XColor *p = x_palette; |
1741 |
+ |
for (int i=0; i<num_out; i++) { |
1742 |
+ |
int c = (stretch ? (i * num_in) / num_out : i); |
1743 |
+ |
p->red = mac_pal[c].red * 0x0101; |
1744 |
+ |
p->green = mac_pal[c].green * 0x0101; |
1745 |
+ |
p->blue = mac_pal[c].blue * 0x0101; |
1746 |
+ |
p++; |
1747 |
+ |
} |
1748 |
+ |
|
1749 |
+ |
#ifdef ENABLE_VOSF |
1750 |
+ |
// Recalculate pixel color expansion map |
1751 |
+ |
if (!IsDirectMode(mode) && xdepth > 8) { |
1752 |
+ |
for (int i=0; i<256; i++) { |
1753 |
+ |
int c = i & (num_in-1); // If there are less than 256 colors, we repeat the first entries (this makes color expansion easier) |
1754 |
+ |
ExpandMap[i] = map_rgb(mac_pal[c].red, mac_pal[c].green, mac_pal[c].blue); |
1755 |
+ |
} |
1756 |
+ |
|
1757 |
+ |
// We have to redraw everything because the interpretation of pixel values changed |
1758 |
+ |
LOCK_VOSF; |
1759 |
+ |
PFLAG_SET_ALL; |
1760 |
+ |
UNLOCK_VOSF; |
1761 |
+ |
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
1762 |
+ |
} |
1763 |
+ |
#endif |
1764 |
+ |
|
1765 |
+ |
// Tell redraw thread to change palette |
1766 |
|
palette_changed = true; |
1767 |
+ |
|
1768 |
+ |
UNLOCK_PALETTE; |
1769 |
+ |
} |
1770 |
+ |
|
1771 |
+ |
|
1772 |
+ |
/* |
1773 |
+ |
* Can we set the MacOS cursor image into the window? |
1774 |
+ |
*/ |
1775 |
+ |
|
1776 |
+ |
bool video_can_change_cursor(void) |
1777 |
+ |
{ |
1778 |
+ |
return hw_mac_cursor_accl && (display_type != DIS_SCREEN); |
1779 |
|
} |
1780 |
|
|
1781 |
|
|
1914 |
|
const int VIDEO_REFRESH_HZ = 60; |
1915 |
|
const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ; |
1916 |
|
|
1917 |
+ |
static void handle_palette_changes(void) |
1918 |
+ |
{ |
1919 |
+ |
LOCK_PALETTE; |
1920 |
+ |
|
1921 |
+ |
if (palette_changed && !emul_suspended) { |
1922 |
+ |
palette_changed = false; |
1923 |
+ |
|
1924 |
+ |
int mode = get_current_mode(); |
1925 |
+ |
if (color_class == PseudoColor || color_class == DirectColor) { |
1926 |
+ |
int num = vis->map_entries; |
1927 |
+ |
bool set_clut = true; |
1928 |
+ |
if (!IsDirectMode(mode) && color_class == DirectColor) { |
1929 |
+ |
if (display_type == DIS_WINDOW) |
1930 |
+ |
set_clut = false; // Indexed mode on true color screen, don't set CLUT |
1931 |
+ |
} |
1932 |
+ |
|
1933 |
+ |
if (set_clut) { |
1934 |
+ |
XDisplayLock(); |
1935 |
+ |
XStoreColors(x_display, cmap[0], x_palette, num); |
1936 |
+ |
XStoreColors(x_display, cmap[1], x_palette, num); |
1937 |
+ |
XSync(x_display, false); |
1938 |
+ |
XDisplayUnlock(); |
1939 |
+ |
} |
1940 |
+ |
} |
1941 |
+ |
|
1942 |
+ |
#ifdef ENABLE_XF86_DGA |
1943 |
+ |
if (display_type == DIS_SCREEN) { |
1944 |
+ |
current_dga_cmap ^= 1; |
1945 |
+ |
if (!IsDirectMode(mode) && cmap[current_dga_cmap]) |
1946 |
+ |
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1947 |
+ |
} |
1948 |
+ |
#endif |
1949 |
+ |
} |
1950 |
+ |
|
1951 |
+ |
UNLOCK_PALETTE; |
1952 |
+ |
} |
1953 |
+ |
|
1954 |
|
static void *redraw_func(void *arg) |
1955 |
|
{ |
1956 |
|
int fd = ConnectionNumber(x_display); |
1959 |
|
int64 ticks = 0; |
1960 |
|
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
1961 |
|
|
1962 |
< |
for (;;) { |
1962 |
> |
while (!redraw_thread_cancel) { |
1963 |
|
|
1964 |
|
// Pause if requested (during video mode switches) |
1965 |
|
while (thread_stop_req) |
1989 |
|
XF86DGADirectVideo(x_display, screen, 0); |
1990 |
|
XUngrabPointer(x_display, CurrentTime); |
1991 |
|
XUngrabKeyboard(x_display, CurrentTime); |
1992 |
+ |
XUnmapWindow(x_display, the_win); |
1993 |
+ |
wait_unmapped(the_win); |
1994 |
+ |
XDestroyWindow(x_display, the_win); |
1995 |
|
#endif |
1996 |
|
XSync(x_display, false); |
1997 |
|
XDisplayUnlock(); |
2024 |
|
update_display(); |
2025 |
|
|
2026 |
|
// Set new cursor image if it was changed |
2027 |
< |
if (cursor_changed) { |
2027 |
> |
if (hw_mac_cursor_accl && cursor_changed) { |
2028 |
|
cursor_changed = false; |
2029 |
< |
memcpy(cursor_image->data, MacCursor + 4, 32); |
2030 |
< |
memcpy(cursor_mask_image->data, MacCursor + 36, 32); |
2029 |
> |
uint8 *x_data = (uint8 *)cursor_image->data; |
2030 |
> |
uint8 *x_mask = (uint8 *)cursor_mask_image->data; |
2031 |
> |
for (int i = 0; i < 32; i++) { |
2032 |
> |
x_mask[i] = MacCursor[4 + i] | MacCursor[36 + i]; |
2033 |
> |
x_data[i] = MacCursor[4 + i]; |
2034 |
> |
} |
2035 |
|
XDisplayLock(); |
2036 |
|
XFreeCursor(x_display, mac_cursor); |
2037 |
|
XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16); |
2057 |
|
#endif |
2058 |
|
|
2059 |
|
// Set new palette if it was changed |
2060 |
< |
if (palette_changed && !emul_suspended) { |
1738 |
< |
palette_changed = false; |
1739 |
< |
XColor c[256]; |
1740 |
< |
for (int i=0; i<256; i++) { |
1741 |
< |
c[i].pixel = i; |
1742 |
< |
c[i].red = mac_pal[i].red * 0x0101; |
1743 |
< |
c[i].green = mac_pal[i].green * 0x0101; |
1744 |
< |
c[i].blue = mac_pal[i].blue * 0x0101; |
1745 |
< |
c[i].flags = DoRed | DoGreen | DoBlue; |
1746 |
< |
} |
1747 |
< |
if (depth == 8) { |
1748 |
< |
XDisplayLock(); |
1749 |
< |
XStoreColors(x_display, cmap[0], c, 256); |
1750 |
< |
XStoreColors(x_display, cmap[1], c, 256); |
1751 |
< |
#ifdef ENABLE_XF86_DGA |
1752 |
< |
if (display_type == DIS_SCREEN) { |
1753 |
< |
current_dga_cmap ^= 1; |
1754 |
< |
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1755 |
< |
} |
1756 |
< |
#endif |
1757 |
< |
XDisplayUnlock(); |
1758 |
< |
} |
1759 |
< |
} |
2060 |
> |
handle_palette_changes(); |
2061 |
|
|
2062 |
|
} else { |
2063 |
|
|