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-2004 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 |
50 |
|
#define DEBUG 0 |
51 |
|
#include "debug.h" |
52 |
|
|
53 |
+ |
#ifndef NO_STD_NAMESPACE |
54 |
+ |
using std::sort; |
55 |
+ |
#endif |
56 |
+ |
|
57 |
|
|
58 |
|
// Constants |
59 |
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; |
60 |
+ |
static const bool hw_mac_cursor_accl = true; // Flag: Enable MacOS to X11 copy of cursor? |
61 |
|
|
62 |
|
// Global variables |
63 |
|
static int32 frame_skip; |
64 |
+ |
static int16 mouse_wheel_mode; |
65 |
+ |
static int16 mouse_wheel_lines; |
66 |
|
static bool redraw_thread_active = false; // Flag: Redraw thread installed |
67 |
+ |
static pthread_attr_t redraw_thread_attr; // Redraw thread attributes |
68 |
|
static pthread_t redraw_thread; // Redraw thread |
69 |
|
|
70 |
|
static bool local_X11; // Flag: X server running on local machine? |
97 |
|
static int xdepth; // Depth of X screen |
98 |
|
static int depth; // Depth of Mac frame buffer |
99 |
|
static Window rootwin, the_win; // Root window and our window |
100 |
+ |
static int num_depths = 0; // Number of available X depths |
101 |
+ |
static int *avail_depths = NULL; // List of available X depths |
102 |
|
static XVisualInfo visualInfo; |
103 |
|
static Visual *vis; |
104 |
+ |
static int color_class; |
105 |
+ |
static int rshift, rloss, gshift, gloss, bshift, bloss; // Pixel format of DirectColor/TrueColor modes |
106 |
|
static Colormap cmap[2]; // Two colormaps (DGA) for 8-bit mode |
107 |
+ |
static XColor x_palette[256]; // Color palette to be used as CLUT and gamma table |
108 |
+ |
|
109 |
|
static XColor black, white; |
110 |
|
static unsigned long black_pixel, white_pixel; |
111 |
|
static int eventmask; |
112 |
< |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask; |
113 |
< |
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; |
112 |
> |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask | StructureNotifyMask; |
113 |
> |
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask; |
114 |
|
|
115 |
|
// Variables for window mode |
116 |
|
static GC the_gc; |
127 |
|
static uint32 the_buffer_size; // Size of allocated the_buffer |
128 |
|
|
129 |
|
// Variables for DGA mode |
114 |
– |
static char *dga_screen_base; |
115 |
– |
static int dga_fb_width; |
130 |
|
static int current_dga_cmap; |
131 |
|
|
132 |
|
#ifdef ENABLE_XF86_VIDMODE |
135 |
|
static int num_x_video_modes; |
136 |
|
#endif |
137 |
|
|
138 |
+ |
// Mutex to protect palette |
139 |
+ |
#ifdef HAVE_SPINLOCKS |
140 |
+ |
static spinlock_t x_palette_lock = SPIN_LOCK_UNLOCKED; |
141 |
+ |
#define LOCK_PALETTE spin_lock(&x_palette_lock) |
142 |
+ |
#define UNLOCK_PALETTE spin_unlock(&x_palette_lock) |
143 |
+ |
#elif defined(HAVE_PTHREADS) |
144 |
+ |
static pthread_mutex_t x_palette_lock = PTHREAD_MUTEX_INITIALIZER; |
145 |
+ |
#define LOCK_PALETTE pthread_mutex_lock(&x_palette_lock) |
146 |
+ |
#define UNLOCK_PALETTE pthread_mutex_unlock(&x_palette_lock) |
147 |
+ |
#else |
148 |
+ |
#define LOCK_PALETTE |
149 |
+ |
#define UNLOCK_PALETTE |
150 |
+ |
#endif |
151 |
+ |
|
152 |
|
|
153 |
|
// Prototypes |
154 |
|
static void *redraw_func(void *arg); |
161 |
|
// From sys_unix.cpp |
162 |
|
extern void SysMountFirstFloppy(void); |
163 |
|
|
164 |
+ |
// From clip_unix.cpp |
165 |
+ |
extern void ClipboardSelectionClear(XSelectionClearEvent *); |
166 |
+ |
extern void ClipboardSelectionRequest(XSelectionRequestEvent *); |
167 |
+ |
|
168 |
|
|
169 |
|
// Video acceleration through SIGSEGV |
170 |
|
#ifdef ENABLE_VOSF |
173 |
|
|
174 |
|
|
175 |
|
/* |
176 |
+ |
* Utility functions |
177 |
+ |
*/ |
178 |
+ |
|
179 |
+ |
// Get current video mode |
180 |
+ |
static inline int get_current_mode(void) |
181 |
+ |
{ |
182 |
+ |
return VModes[cur_mode].viAppleMode; |
183 |
+ |
} |
184 |
+ |
|
185 |
+ |
// Find palette size for given color depth |
186 |
+ |
static int palette_size(int mode) |
187 |
+ |
{ |
188 |
+ |
switch (mode) { |
189 |
+ |
case APPLE_1_BIT: return 2; |
190 |
+ |
case APPLE_2_BIT: return 4; |
191 |
+ |
case APPLE_4_BIT: return 16; |
192 |
+ |
case APPLE_8_BIT: return 256; |
193 |
+ |
case APPLE_16_BIT: return 32; |
194 |
+ |
case APPLE_32_BIT: return 256; |
195 |
+ |
default: return 0; |
196 |
+ |
} |
197 |
+ |
} |
198 |
+ |
|
199 |
+ |
// Return bits per pixel for requested depth |
200 |
+ |
static inline int bytes_per_pixel(int depth) |
201 |
+ |
{ |
202 |
+ |
int bpp; |
203 |
+ |
switch (depth) { |
204 |
+ |
case 8: |
205 |
+ |
bpp = 1; |
206 |
+ |
break; |
207 |
+ |
case 15: case 16: |
208 |
+ |
bpp = 2; |
209 |
+ |
break; |
210 |
+ |
case 24: case 32: |
211 |
+ |
bpp = 4; |
212 |
+ |
break; |
213 |
+ |
default: |
214 |
+ |
abort(); |
215 |
+ |
} |
216 |
+ |
return bpp; |
217 |
+ |
} |
218 |
+ |
|
219 |
+ |
// Map video_mode depth ID to numerical depth value |
220 |
+ |
static inline int depth_of_video_mode(int mode) |
221 |
+ |
{ |
222 |
+ |
int depth; |
223 |
+ |
switch (mode) { |
224 |
+ |
case APPLE_1_BIT: |
225 |
+ |
depth = 1; |
226 |
+ |
break; |
227 |
+ |
case APPLE_2_BIT: |
228 |
+ |
depth = 2; |
229 |
+ |
break; |
230 |
+ |
case APPLE_4_BIT: |
231 |
+ |
depth = 4; |
232 |
+ |
break; |
233 |
+ |
case APPLE_8_BIT: |
234 |
+ |
depth = 8; |
235 |
+ |
break; |
236 |
+ |
case APPLE_16_BIT: |
237 |
+ |
depth = 16; |
238 |
+ |
break; |
239 |
+ |
case APPLE_32_BIT: |
240 |
+ |
depth = 32; |
241 |
+ |
break; |
242 |
+ |
default: |
243 |
+ |
abort(); |
244 |
+ |
} |
245 |
+ |
return depth; |
246 |
+ |
} |
247 |
+ |
|
248 |
+ |
// Map RGB color to pixel value (this only works in TrueColor/DirectColor visuals) |
249 |
+ |
static inline uint32 map_rgb(uint8 red, uint8 green, uint8 blue) |
250 |
+ |
{ |
251 |
+ |
return ((red >> rloss) << rshift) | ((green >> gloss) << gshift) | ((blue >> bloss) << bshift); |
252 |
+ |
} |
253 |
+ |
|
254 |
+ |
|
255 |
+ |
// Do we have a visual for handling the specified Mac depth? If so, set the |
256 |
+ |
// global variables "xdepth", "visualInfo", "vis" and "color_class". |
257 |
+ |
static bool find_visual_for_depth(int depth) |
258 |
+ |
{ |
259 |
+ |
D(bug("have_visual_for_depth(%d)\n", depth_of_video_mode(depth))); |
260 |
+ |
|
261 |
+ |
// 1-bit works always and uses default visual |
262 |
+ |
if (depth == APPLE_1_BIT) { |
263 |
+ |
vis = DefaultVisual(x_display, screen); |
264 |
+ |
visualInfo.visualid = XVisualIDFromVisual(vis); |
265 |
+ |
int num = 0; |
266 |
+ |
XVisualInfo *vi = XGetVisualInfo(x_display, VisualIDMask, &visualInfo, &num); |
267 |
+ |
visualInfo = vi[0]; |
268 |
+ |
XFree(vi); |
269 |
+ |
xdepth = visualInfo.depth; |
270 |
+ |
color_class = visualInfo.c_class; |
271 |
+ |
D(bug(" found visual ID 0x%02x, depth %d\n", visualInfo.visualid, xdepth)); |
272 |
+ |
return true; |
273 |
+ |
} |
274 |
+ |
|
275 |
+ |
// Calculate minimum and maximum supported X depth |
276 |
+ |
int min_depth = 1, max_depth = 32; |
277 |
+ |
switch (depth) { |
278 |
+ |
#ifdef ENABLE_VOSF |
279 |
+ |
case APPLE_2_BIT: |
280 |
+ |
case APPLE_4_BIT: // VOSF blitters can convert 2/4/8-bit -> 8/16/32-bit |
281 |
+ |
case APPLE_8_BIT: |
282 |
+ |
min_depth = 8; |
283 |
+ |
max_depth = 32; |
284 |
+ |
break; |
285 |
+ |
#else |
286 |
+ |
case APPLE_2_BIT: |
287 |
+ |
case APPLE_4_BIT: // 2/4-bit requires VOSF blitters |
288 |
+ |
return false; |
289 |
+ |
case APPLE_8_BIT: // 8-bit without VOSF requires an 8-bit visual |
290 |
+ |
min_depth = 8; |
291 |
+ |
max_depth = 8; |
292 |
+ |
break; |
293 |
+ |
#endif |
294 |
+ |
case APPLE_16_BIT: // 16-bit requires a 15/16-bit visual |
295 |
+ |
min_depth = 15; |
296 |
+ |
max_depth = 16; |
297 |
+ |
break; |
298 |
+ |
case APPLE_32_BIT: // 32-bit requires a 24/32-bit visual |
299 |
+ |
min_depth = 24; |
300 |
+ |
max_depth = 32; |
301 |
+ |
break; |
302 |
+ |
} |
303 |
+ |
D(bug(" minimum required X depth is %d, maximum supported X depth is %d\n", min_depth, max_depth)); |
304 |
+ |
|
305 |
+ |
// Try to find a visual for one of the color depths |
306 |
+ |
bool visual_found = false; |
307 |
+ |
for (int i=0; i<num_depths && !visual_found; i++) { |
308 |
+ |
|
309 |
+ |
xdepth = avail_depths[i]; |
310 |
+ |
D(bug(" trying to find visual for depth %d\n", xdepth)); |
311 |
+ |
if (xdepth < min_depth || xdepth > max_depth) |
312 |
+ |
continue; |
313 |
+ |
|
314 |
+ |
// Determine best color class for this depth |
315 |
+ |
switch (xdepth) { |
316 |
+ |
case 1: // Try StaticGray or StaticColor |
317 |
+ |
if (XMatchVisualInfo(x_display, screen, xdepth, StaticGray, &visualInfo) |
318 |
+ |
|| XMatchVisualInfo(x_display, screen, xdepth, StaticColor, &visualInfo)) |
319 |
+ |
visual_found = true; |
320 |
+ |
break; |
321 |
+ |
case 8: // Need PseudoColor |
322 |
+ |
if (XMatchVisualInfo(x_display, screen, xdepth, PseudoColor, &visualInfo)) |
323 |
+ |
visual_found = true; |
324 |
+ |
break; |
325 |
+ |
case 15: |
326 |
+ |
case 16: |
327 |
+ |
case 24: |
328 |
+ |
case 32: // Try DirectColor first, as this will allow gamma correction |
329 |
+ |
if (XMatchVisualInfo(x_display, screen, xdepth, DirectColor, &visualInfo) |
330 |
+ |
|| XMatchVisualInfo(x_display, screen, xdepth, TrueColor, &visualInfo)) |
331 |
+ |
visual_found = true; |
332 |
+ |
break; |
333 |
+ |
default: |
334 |
+ |
D(bug(" not a supported depth\n")); |
335 |
+ |
break; |
336 |
+ |
} |
337 |
+ |
} |
338 |
+ |
if (!visual_found) |
339 |
+ |
return false; |
340 |
+ |
|
341 |
+ |
// Visual was found |
342 |
+ |
vis = visualInfo.visual; |
343 |
+ |
color_class = visualInfo.c_class; |
344 |
+ |
D(bug(" found visual ID 0x%02x, depth %d, class ", visualInfo.visualid, xdepth)); |
345 |
+ |
#if DEBUG |
346 |
+ |
switch (color_class) { |
347 |
+ |
case StaticGray: D(bug("StaticGray\n")); break; |
348 |
+ |
case GrayScale: D(bug("GrayScale\n")); break; |
349 |
+ |
case StaticColor: D(bug("StaticColor\n")); break; |
350 |
+ |
case PseudoColor: D(bug("PseudoColor\n")); break; |
351 |
+ |
case TrueColor: D(bug("TrueColor\n")); break; |
352 |
+ |
case DirectColor: D(bug("DirectColor\n")); break; |
353 |
+ |
} |
354 |
+ |
#endif |
355 |
+ |
return true; |
356 |
+ |
} |
357 |
+ |
|
358 |
+ |
|
359 |
+ |
/* |
360 |
|
* Open display (window or fullscreen) |
361 |
|
*/ |
362 |
|
|
363 |
+ |
// Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget) |
364 |
+ |
static Atom WM_DELETE_WINDOW = (Atom)0; |
365 |
+ |
static void set_window_delete_protocol(Window w) |
366 |
+ |
{ |
367 |
+ |
WM_DELETE_WINDOW = XInternAtom(x_display, "WM_DELETE_WINDOW", false); |
368 |
+ |
XSetWMProtocols(x_display, w, &WM_DELETE_WINDOW, 1); |
369 |
+ |
} |
370 |
+ |
|
371 |
+ |
// Wait until window is mapped/unmapped |
372 |
+ |
static void wait_mapped(Window w) |
373 |
+ |
{ |
374 |
+ |
XEvent e; |
375 |
+ |
do { |
376 |
+ |
XMaskEvent(x_display, StructureNotifyMask, &e); |
377 |
+ |
} while ((e.type != MapNotify) || (e.xmap.event != w)); |
378 |
+ |
} |
379 |
+ |
|
380 |
+ |
static void wait_unmapped(Window w) |
381 |
+ |
{ |
382 |
+ |
XEvent e; |
383 |
+ |
do { |
384 |
+ |
XMaskEvent(x_display, StructureNotifyMask, &e); |
385 |
+ |
} while ((e.type != UnmapNotify) || (e.xmap.event != w)); |
386 |
+ |
} |
387 |
+ |
|
388 |
|
// Trap SHM errors |
389 |
|
static bool shm_error = false; |
390 |
|
static int (*old_error_handler)(Display *, XErrorEvent *); |
407 |
|
// Set absolute mouse mode |
408 |
|
ADBSetRelMouseMode(false); |
409 |
|
|
169 |
– |
// Read frame skip prefs |
170 |
– |
frame_skip = PrefsFindInt32("frameskip"); |
171 |
– |
if (frame_skip == 0) |
172 |
– |
frame_skip = 1; |
173 |
– |
|
410 |
|
// Create window |
411 |
|
XSetWindowAttributes wattr; |
412 |
|
wattr.event_mask = eventmask = win_eventmask; |
413 |
< |
wattr.background_pixel = black_pixel; |
414 |
< |
wattr.border_pixel = black_pixel; |
413 |
> |
wattr.background_pixel = (vis == DefaultVisual(x_display, screen) ? black_pixel : 0); |
414 |
> |
wattr.border_pixel = 0; |
415 |
|
wattr.backing_store = NotUseful; |
416 |
< |
|
181 |
< |
XSync(x_display, false); |
416 |
> |
wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); |
417 |
|
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
418 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | CWBackingStore, &wattr); |
419 |
< |
XSync(x_display, false); |
418 |
> |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | CWBackingStore | CWColormap, &wattr); |
419 |
> |
|
420 |
> |
// Set window name |
421 |
|
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); |
186 |
– |
XMapRaised(x_display, the_win); |
187 |
– |
XSync(x_display, false); |
422 |
|
|
423 |
< |
// Set colormap |
424 |
< |
if (depth == 8) { |
191 |
< |
XSetWindowColormap(x_display, the_win, cmap[0]); |
192 |
< |
XSetWMColormapWindows(x_display, the_win, &the_win, 1); |
193 |
< |
} |
423 |
> |
// Set delete protocol property |
424 |
> |
set_window_delete_protocol(the_win); |
425 |
|
|
426 |
|
// Make window unresizable |
427 |
|
XSizeHints *hints; |
435 |
|
XFree((char *)hints); |
436 |
|
} |
437 |
|
|
438 |
+ |
// Show window |
439 |
+ |
XMapWindow(x_display, the_win); |
440 |
+ |
wait_mapped(the_win); |
441 |
+ |
|
442 |
|
// 1-bit mode is big-endian; if the X server is little-endian, we can't |
443 |
|
// use SHM because that doesn't allow changing the image byte order |
444 |
|
bool need_msb_image = (depth == 1 && XImageByteOrder(x_display) == LSBFirst); |
449 |
|
|
450 |
|
// Create SHM image ("height + 2" for safety) |
451 |
|
img = XShmCreateImage(x_display, vis, depth == 1 ? 1 : xdepth, depth == 1 ? XYBitmap : ZPixmap, 0, &shminfo, width, height); |
452 |
< |
shminfo.shmid = shmget(IPC_PRIVATE, (height + 2) * img->bytes_per_line, IPC_CREAT | 0777); |
452 |
> |
shminfo.shmid = shmget(IPC_PRIVATE, (aligned_height + 2) * img->bytes_per_line, IPC_CREAT | 0777); |
453 |
> |
D(bug(" shm image created\n")); |
454 |
|
the_buffer_copy = (uint8 *)shmat(shminfo.shmid, 0, 0); |
455 |
|
shminfo.shmaddr = img->data = (char *)the_buffer_copy; |
456 |
|
shminfo.readOnly = False; |
469 |
|
have_shm = true; |
470 |
|
shmctl(shminfo.shmid, IPC_RMID, 0); |
471 |
|
} |
472 |
+ |
D(bug(" shm image attached\n")); |
473 |
|
} |
474 |
|
|
475 |
|
// Create normal X image if SHM doesn't work ("height + 2" for safety) |
476 |
|
if (!have_shm) { |
477 |
< |
int bytes_per_row = aligned_width; |
241 |
< |
switch (depth) { |
242 |
< |
case 1: |
243 |
< |
bytes_per_row /= 8; |
244 |
< |
break; |
245 |
< |
case 15: |
246 |
< |
case 16: |
247 |
< |
bytes_per_row *= 2; |
248 |
< |
break; |
249 |
< |
case 24: |
250 |
< |
case 32: |
251 |
< |
bytes_per_row *= 4; |
252 |
< |
break; |
253 |
< |
} |
477 |
> |
int bytes_per_row = depth == 1 ? aligned_width/8 : TrivialBytesPerRow(aligned_width, DepthModeForPixelDepth(xdepth)); |
478 |
|
the_buffer_copy = (uint8 *)malloc((aligned_height + 2) * bytes_per_row); |
479 |
|
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); |
480 |
+ |
D(bug(" X image created\n")); |
481 |
|
} |
482 |
|
|
483 |
|
// 1-Bit mode is big-endian |
484 |
< |
if (depth == 1) { |
484 |
> |
if (need_msb_image) { |
485 |
|
img->byte_order = MSBFirst; |
486 |
|
img->bitmap_bit_order = MSBFirst; |
487 |
|
} |
503 |
|
|
504 |
|
// Create GC |
505 |
|
the_gc = XCreateGC(x_display, the_win, 0, 0); |
506 |
< |
XSetForeground(x_display, the_gc, black_pixel); |
506 |
> |
XSetState(x_display, the_gc, black_pixel, white_pixel, GXcopy, AllPlanes); |
507 |
|
|
508 |
|
// Create cursor |
509 |
< |
cursor_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 4, 16, 16, 16, 2); |
510 |
< |
cursor_image->byte_order = MSBFirst; |
511 |
< |
cursor_image->bitmap_bit_order = MSBFirst; |
512 |
< |
cursor_mask_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 36, 16, 16, 16, 2); |
513 |
< |
cursor_mask_image->byte_order = MSBFirst; |
514 |
< |
cursor_mask_image->bitmap_bit_order = MSBFirst; |
515 |
< |
cursor_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
516 |
< |
cursor_mask_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
517 |
< |
cursor_gc = XCreateGC(x_display, cursor_map, 0, 0); |
518 |
< |
cursor_mask_gc = XCreateGC(x_display, cursor_mask_map, 0, 0); |
519 |
< |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, 0, 0); |
520 |
< |
cursor_changed = false; |
509 |
> |
if (hw_mac_cursor_accl) { |
510 |
> |
cursor_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 4, 16, 16, 16, 2); |
511 |
> |
cursor_image->byte_order = MSBFirst; |
512 |
> |
cursor_image->bitmap_bit_order = MSBFirst; |
513 |
> |
cursor_mask_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 36, 16, 16, 16, 2); |
514 |
> |
cursor_mask_image->byte_order = MSBFirst; |
515 |
> |
cursor_mask_image->bitmap_bit_order = MSBFirst; |
516 |
> |
cursor_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
517 |
> |
cursor_mask_map = XCreatePixmap(x_display, the_win, 16, 16, 1); |
518 |
> |
cursor_gc = XCreateGC(x_display, cursor_map, 0, 0); |
519 |
> |
cursor_mask_gc = XCreateGC(x_display, cursor_mask_map, 0, 0); |
520 |
> |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, 0, 0); |
521 |
> |
cursor_changed = false; |
522 |
> |
} |
523 |
> |
|
524 |
> |
// Create no_cursor |
525 |
> |
else { |
526 |
> |
mac_cursor = XCreatePixmapCursor(x_display, |
527 |
> |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
528 |
> |
XCreatePixmap(x_display, the_win, 1, 1, 1), |
529 |
> |
&black, &white, 0, 0); |
530 |
> |
XDefineCursor(x_display, the_win, mac_cursor); |
531 |
> |
} |
532 |
|
|
533 |
|
// Init blitting routines |
534 |
|
bool native_byte_order; |
542 |
|
#endif |
543 |
|
|
544 |
|
// Set bytes per row |
309 |
– |
VModes[cur_mode].viRowBytes = img->bytes_per_line; |
545 |
|
XSync(x_display, false); |
546 |
|
return true; |
547 |
|
} |
553 |
|
// Set relative mouse mode |
554 |
|
ADBSetRelMouseMode(true); |
555 |
|
|
556 |
+ |
// Create window |
557 |
+ |
XSetWindowAttributes wattr; |
558 |
+ |
wattr.event_mask = eventmask = dga_eventmask; |
559 |
+ |
wattr.override_redirect = True; |
560 |
+ |
wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); |
561 |
+ |
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
562 |
+ |
InputOutput, vis, CWEventMask | CWOverrideRedirect | |
563 |
+ |
(color_class == DirectColor ? CWColormap : 0), &wattr); |
564 |
+ |
|
565 |
+ |
// Show window |
566 |
+ |
XMapRaised(x_display, the_win); |
567 |
+ |
wait_mapped(the_win); |
568 |
+ |
|
569 |
|
#ifdef ENABLE_XF86_VIDMODE |
570 |
|
// Switch to best mode |
571 |
|
if (has_vidmode) { |
582 |
|
#endif |
583 |
|
|
584 |
|
// Establish direct screen connection |
585 |
+ |
XMoveResizeWindow(x_display, the_win, 0, 0, width, height); |
586 |
+ |
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
587 |
|
XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
588 |
|
XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
589 |
+ |
|
590 |
+ |
int v_width, v_bank, v_size; |
591 |
+ |
XF86DGAGetVideo(x_display, screen, (char **)&the_buffer, &v_width, &v_bank, &v_size); |
592 |
|
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
593 |
|
XF86DGASetViewPort(x_display, screen, 0, 0); |
594 |
|
XF86DGASetVidPage(x_display, screen, 0); |
595 |
|
|
596 |
|
// Set colormap |
597 |
< |
if (depth == 8) |
597 |
> |
if (!IsDirectMode(get_current_mode())) { |
598 |
> |
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); |
599 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
346 |
– |
|
347 |
– |
// Set bytes per row |
348 |
– |
int bytes_per_row = (dga_fb_width + 7) & ~7; |
349 |
– |
switch (depth) { |
350 |
– |
case 15: |
351 |
– |
case 16: |
352 |
– |
bytes_per_row *= 2; |
353 |
– |
break; |
354 |
– |
case 24: |
355 |
– |
case 32: |
356 |
– |
bytes_per_row *= 4; |
357 |
– |
break; |
600 |
|
} |
601 |
+ |
XSync(x_display, false); |
602 |
|
|
603 |
+ |
// Init blitting routines |
604 |
+ |
int bytes_per_row = TrivialBytesPerRow((v_width + 7) & ~7, DepthModeForPixelDepth(depth)); |
605 |
|
#if ENABLE_VOSF |
606 |
|
bool native_byte_order; |
607 |
|
#ifdef WORDS_BIGENDIAN |
620 |
|
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
621 |
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
622 |
|
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
623 |
+ |
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
624 |
|
} |
625 |
|
#else |
626 |
|
use_vosf = false; |
381 |
– |
the_buffer = dga_screen_base; |
627 |
|
#endif |
628 |
|
#endif |
384 |
– |
screen_base = (uint32)the_buffer; |
629 |
|
|
630 |
+ |
// Set frame buffer base |
631 |
+ |
D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); |
632 |
+ |
screen_base = (uint32)the_buffer; |
633 |
|
VModes[cur_mode].viRowBytes = bytes_per_row; |
387 |
– |
XSync(x_display, false); |
634 |
|
return true; |
635 |
|
#else |
636 |
|
ErrorAlert("SheepShaver has been compiled with DGA support disabled."); |
640 |
|
|
641 |
|
static bool open_display(void) |
642 |
|
{ |
643 |
< |
display_type = VModes[cur_mode].viType; |
644 |
< |
switch (VModes[cur_mode].viAppleMode) { |
645 |
< |
case APPLE_1_BIT: |
646 |
< |
depth = 1; |
647 |
< |
break; |
648 |
< |
case APPLE_2_BIT: |
649 |
< |
depth = 2; |
650 |
< |
break; |
651 |
< |
case APPLE_4_BIT: |
652 |
< |
depth = 4; |
653 |
< |
break; |
654 |
< |
case APPLE_8_BIT: |
655 |
< |
depth = 8; |
656 |
< |
break; |
657 |
< |
case APPLE_16_BIT: |
658 |
< |
depth = xdepth == 15 ? 15 : 16; |
659 |
< |
break; |
660 |
< |
case APPLE_32_BIT: |
661 |
< |
depth = 32; |
662 |
< |
break; |
643 |
> |
D(bug("open_display()\n")); |
644 |
> |
const VideoInfo &mode = VModes[cur_mode]; |
645 |
> |
|
646 |
> |
// Find best available X visual |
647 |
> |
if (!find_visual_for_depth(mode.viAppleMode)) { |
648 |
> |
ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); |
649 |
> |
return false; |
650 |
> |
} |
651 |
> |
|
652 |
> |
// Create color maps |
653 |
> |
if (color_class == PseudoColor || color_class == DirectColor) { |
654 |
> |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
655 |
> |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
656 |
> |
} else { |
657 |
> |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocNone); |
658 |
> |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocNone); |
659 |
> |
} |
660 |
> |
|
661 |
> |
// Find pixel format of direct modes |
662 |
> |
if (color_class == DirectColor || color_class == TrueColor) { |
663 |
> |
rshift = gshift = bshift = 0; |
664 |
> |
rloss = gloss = bloss = 8; |
665 |
> |
uint32 mask; |
666 |
> |
for (mask=vis->red_mask; !(mask&1); mask>>=1) |
667 |
> |
++rshift; |
668 |
> |
for (; mask&1; mask>>=1) |
669 |
> |
--rloss; |
670 |
> |
for (mask=vis->green_mask; !(mask&1); mask>>=1) |
671 |
> |
++gshift; |
672 |
> |
for (; mask&1; mask>>=1) |
673 |
> |
--gloss; |
674 |
> |
for (mask=vis->blue_mask; !(mask&1); mask>>=1) |
675 |
> |
++bshift; |
676 |
> |
for (; mask&1; mask>>=1) |
677 |
> |
--bloss; |
678 |
> |
} |
679 |
> |
|
680 |
> |
// Preset palette pixel values for CLUT or gamma table |
681 |
> |
if (color_class == DirectColor) { |
682 |
> |
int num = vis->map_entries; |
683 |
> |
for (int i=0; i<num; i++) { |
684 |
> |
int c = (i * 256) / num; |
685 |
> |
x_palette[i].pixel = map_rgb(c, c, c); |
686 |
> |
x_palette[i].flags = DoRed | DoGreen | DoBlue; |
687 |
> |
} |
688 |
> |
} else if (color_class == PseudoColor) { |
689 |
> |
for (int i=0; i<256; i++) { |
690 |
> |
x_palette[i].pixel = i; |
691 |
> |
x_palette[i].flags = DoRed | DoGreen | DoBlue; |
692 |
> |
} |
693 |
|
} |
694 |
|
|
695 |
+ |
// Load gray ramp to color map |
696 |
+ |
int num = (color_class == DirectColor ? vis->map_entries : 256); |
697 |
+ |
for (int i=0; i<num; i++) { |
698 |
+ |
int c = (i * 256) / num; |
699 |
+ |
x_palette[i].red = c * 0x0101; |
700 |
+ |
x_palette[i].green = c * 0x0101; |
701 |
+ |
x_palette[i].blue = c * 0x0101; |
702 |
+ |
} |
703 |
+ |
if (color_class == PseudoColor || color_class == DirectColor) { |
704 |
+ |
XStoreColors(x_display, cmap[0], x_palette, num); |
705 |
+ |
XStoreColors(x_display, cmap[1], x_palette, num); |
706 |
+ |
} |
707 |
+ |
|
708 |
+ |
#ifdef ENABLE_VOSF |
709 |
+ |
// Load gray ramp to 8->16/32 expand map |
710 |
+ |
if (!IsDirectMode(get_current_mode()) && xdepth > 8) |
711 |
+ |
for (int i=0; i<256; i++) |
712 |
+ |
ExpandMap[i] = map_rgb(i, i, i); |
713 |
+ |
#endif |
714 |
+ |
|
715 |
+ |
// Create display of requested type |
716 |
+ |
display_type = mode.viType; |
717 |
+ |
depth = depth_of_video_mode(mode.viAppleMode); |
718 |
+ |
|
719 |
|
bool display_open = false; |
720 |
|
if (display_type == DIS_SCREEN) |
721 |
|
display_open = open_dga(VModes[cur_mode].viXsize, VModes[cur_mode].viYsize); |
763 |
|
if (the_gc) |
764 |
|
XFreeGC(x_display, the_gc); |
765 |
|
|
766 |
< |
// Close window |
767 |
< |
XDestroyWindow(x_display, the_win); |
766 |
> |
XFlush(x_display); |
767 |
> |
XSync(x_display, false); |
768 |
|
} |
769 |
|
|
770 |
|
// Close DGA mode |
800 |
|
else if (display_type == DIS_WINDOW) |
801 |
|
close_window(); |
802 |
|
|
803 |
+ |
// Close window |
804 |
+ |
if (the_win) { |
805 |
+ |
XUnmapWindow(x_display, the_win); |
806 |
+ |
wait_unmapped(the_win); |
807 |
+ |
XDestroyWindow(x_display, the_win); |
808 |
+ |
} |
809 |
+ |
|
810 |
+ |
// Free colormaps |
811 |
+ |
if (cmap[0]) { |
812 |
+ |
XFreeColormap(x_display, cmap[0]); |
813 |
+ |
cmap[0] = 0; |
814 |
+ |
} |
815 |
+ |
if (cmap[1]) { |
816 |
+ |
XFreeColormap(x_display, cmap[1]); |
817 |
+ |
cmap[1] = 0; |
818 |
+ |
} |
819 |
+ |
|
820 |
|
#ifdef ENABLE_VOSF |
821 |
|
if (use_vosf) { |
822 |
|
// Deinitialize VOSF |
923 |
|
} |
924 |
|
} |
925 |
|
|
926 |
< |
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, long apple_mode, long apple_id, int type) |
926 |
> |
// Find Apple mode matching best specified dimensions |
927 |
> |
static int find_apple_resolution(int xsize, int ysize) |
928 |
> |
{ |
929 |
> |
int apple_id; |
930 |
> |
if (xsize < 800) |
931 |
> |
apple_id = APPLE_640x480; |
932 |
> |
else if (xsize < 1024) |
933 |
> |
apple_id = APPLE_800x600; |
934 |
> |
else if (xsize < 1152) |
935 |
> |
apple_id = APPLE_1024x768; |
936 |
> |
else if (xsize < 1280) { |
937 |
> |
if (ysize < 900) |
938 |
> |
apple_id = APPLE_1152x768; |
939 |
> |
else |
940 |
> |
apple_id = APPLE_1152x900; |
941 |
> |
} |
942 |
> |
else if (xsize < 1600) |
943 |
> |
apple_id = APPLE_1280x1024; |
944 |
> |
else |
945 |
> |
apple_id = APPLE_1600x1200; |
946 |
> |
return apple_id; |
947 |
> |
} |
948 |
> |
|
949 |
> |
// Find mode in list of supported modes |
950 |
> |
static int find_mode(int apple_mode, int apple_id, int type) |
951 |
> |
{ |
952 |
> |
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
953 |
> |
if (p->viType == type && p->viAppleID == apple_id && p->viAppleMode == apple_mode) |
954 |
> |
return p - VModes; |
955 |
> |
} |
956 |
> |
return -1; |
957 |
> |
} |
958 |
> |
|
959 |
> |
// Add mode to list of supported modes |
960 |
> |
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type) |
961 |
|
{ |
962 |
|
if (allow & test) { |
963 |
|
p->viType = type; |
976 |
|
p->viXsize = 1024; |
977 |
|
p->viYsize = 768; |
978 |
|
break; |
979 |
+ |
case APPLE_1152x768: |
980 |
+ |
p->viXsize = 1152; |
981 |
+ |
p->viYsize = 768; |
982 |
+ |
break; |
983 |
|
case APPLE_1152x900: |
984 |
|
p->viXsize = 1152; |
985 |
|
p->viYsize = 900; |
993 |
|
p->viYsize = 1200; |
994 |
|
break; |
995 |
|
} |
996 |
< |
switch (apple_mode) { |
642 |
< |
case APPLE_8_BIT: |
643 |
< |
p->viRowBytes = p->viXsize; |
644 |
< |
break; |
645 |
< |
case APPLE_16_BIT: |
646 |
< |
p->viRowBytes = p->viXsize * 2; |
647 |
< |
break; |
648 |
< |
case APPLE_32_BIT: |
649 |
< |
p->viRowBytes = p->viXsize * 4; |
650 |
< |
break; |
651 |
< |
} |
996 |
> |
p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); |
997 |
|
p->viAppleMode = apple_mode; |
998 |
|
p->viAppleID = apple_id; |
999 |
|
p++; |
1000 |
|
} |
1001 |
|
} |
1002 |
|
|
1003 |
+ |
// Add standard list of windowed modes for given color depth |
1004 |
+ |
static void add_window_modes(VideoInfo *&p, int window_modes, int mode) |
1005 |
+ |
{ |
1006 |
+ |
add_mode(p, window_modes, 1, mode, APPLE_W_640x480, DIS_WINDOW); |
1007 |
+ |
add_mode(p, window_modes, 2, mode, APPLE_W_800x600, DIS_WINDOW); |
1008 |
+ |
} |
1009 |
+ |
|
1010 |
|
static bool has_mode(int x, int y) |
1011 |
|
{ |
1012 |
|
#ifdef ENABLE_XF86_VIDMODE |
1034 |
|
// Init keycode translation |
1035 |
|
keycode_init(); |
1036 |
|
|
1037 |
+ |
// Read frame skip prefs |
1038 |
+ |
frame_skip = PrefsFindInt32("frameskip"); |
1039 |
+ |
if (frame_skip == 0) |
1040 |
+ |
frame_skip = 1; |
1041 |
+ |
|
1042 |
+ |
// Read mouse wheel prefs |
1043 |
+ |
mouse_wheel_mode = PrefsFindInt32("mousewheelmode"); |
1044 |
+ |
mouse_wheel_lines = PrefsFindInt32("mousewheellines"); |
1045 |
+ |
|
1046 |
|
// Init variables |
1047 |
|
private_data = NULL; |
687 |
– |
cur_mode = 0; // Window 640x480 |
1048 |
|
video_activated = true; |
1049 |
|
|
1050 |
|
// Find screen and root window |
1051 |
|
screen = XDefaultScreen(x_display); |
1052 |
|
rootwin = XRootWindow(x_display, screen); |
1053 |
|
|
1054 |
+ |
// Get sorted list of available depths |
1055 |
+ |
avail_depths = XListDepths(x_display, screen, &num_depths); |
1056 |
+ |
if (avail_depths == NULL) { |
1057 |
+ |
ErrorAlert(GetString(STR_UNSUPP_DEPTH_ERR)); |
1058 |
+ |
return false; |
1059 |
+ |
} |
1060 |
+ |
sort(avail_depths, avail_depths + num_depths); |
1061 |
+ |
|
1062 |
|
// Get screen depth |
1063 |
|
xdepth = DefaultDepth(x_display, screen); |
1064 |
|
|
1089 |
|
black_pixel = BlackPixel(x_display, screen); |
1090 |
|
white_pixel = WhitePixel(x_display, screen); |
1091 |
|
|
724 |
– |
// Get appropriate visual |
725 |
– |
int color_class; |
726 |
– |
switch (xdepth) { |
727 |
– |
#if 0 |
728 |
– |
case 1: |
729 |
– |
color_class = StaticGray; |
730 |
– |
break; |
731 |
– |
#endif |
732 |
– |
case 8: |
733 |
– |
color_class = PseudoColor; |
734 |
– |
break; |
735 |
– |
case 15: |
736 |
– |
case 16: |
737 |
– |
case 24: |
738 |
– |
case 32: |
739 |
– |
color_class = TrueColor; |
740 |
– |
break; |
741 |
– |
default: |
742 |
– |
ErrorAlert(GetString(STR_UNSUPP_DEPTH_ERR)); |
743 |
– |
return false; |
744 |
– |
} |
745 |
– |
if (!XMatchVisualInfo(x_display, screen, xdepth, color_class, &visualInfo)) { |
746 |
– |
ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); |
747 |
– |
return false; |
748 |
– |
} |
749 |
– |
if (visualInfo.depth != xdepth) { |
750 |
– |
ErrorAlert(GetString(STR_NO_XVISUAL_ERR)); |
751 |
– |
return false; |
752 |
– |
} |
753 |
– |
vis = visualInfo.visual; |
754 |
– |
|
1092 |
|
// Mac screen depth follows X depth (for now) |
1093 |
< |
depth = xdepth; |
1094 |
< |
|
1095 |
< |
// Create color maps for 8 bit mode |
1096 |
< |
if (depth == 8) { |
1097 |
< |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1098 |
< |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1099 |
< |
XInstallColormap(x_display, cmap[0]); |
1100 |
< |
XInstallColormap(x_display, cmap[1]); |
1093 |
> |
int default_mode = APPLE_8_BIT; |
1094 |
> |
switch (DefaultDepth(x_display, screen)) { |
1095 |
> |
case 1: |
1096 |
> |
default_mode = APPLE_1_BIT; |
1097 |
> |
break; |
1098 |
> |
case 8: |
1099 |
> |
default_mode = APPLE_8_BIT; |
1100 |
> |
break; |
1101 |
> |
case 15: case 16: |
1102 |
> |
default_mode = APPLE_16_BIT; |
1103 |
> |
break; |
1104 |
> |
case 24: case 32: |
1105 |
> |
default_mode = APPLE_32_BIT; |
1106 |
> |
break; |
1107 |
|
} |
1108 |
|
|
1109 |
|
// Construct video mode table |
767 |
– |
int mode = APPLE_8_BIT; |
768 |
– |
int bpr_mult = 8; |
769 |
– |
switch (depth) { |
770 |
– |
case 1: |
771 |
– |
mode = APPLE_1_BIT; |
772 |
– |
bpr_mult = 1; |
773 |
– |
break; |
774 |
– |
case 8: |
775 |
– |
mode = APPLE_8_BIT; |
776 |
– |
bpr_mult = 8; |
777 |
– |
break; |
778 |
– |
case 15: |
779 |
– |
case 16: |
780 |
– |
mode = APPLE_16_BIT; |
781 |
– |
bpr_mult = 16; |
782 |
– |
break; |
783 |
– |
case 24: |
784 |
– |
case 32: |
785 |
– |
mode = APPLE_32_BIT; |
786 |
– |
bpr_mult = 32; |
787 |
– |
break; |
788 |
– |
} |
789 |
– |
|
1110 |
|
uint32 window_modes = PrefsFindInt32("windowmodes"); |
1111 |
|
uint32 screen_modes = PrefsFindInt32("screenmodes"); |
1112 |
|
if (!has_dga) |
1115 |
|
window_modes |= 3; // Allow at least 640x480 and 800x600 window modes |
1116 |
|
|
1117 |
|
VideoInfo *p = VModes; |
1118 |
< |
add_mode(p, window_modes, 1, mode, APPLE_W_640x480, DIS_WINDOW); |
1119 |
< |
add_mode(p, window_modes, 2, mode, APPLE_W_800x600, DIS_WINDOW); |
1118 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) |
1119 |
> |
if (find_visual_for_depth(d)) |
1120 |
> |
add_window_modes(p, window_modes, d); |
1121 |
> |
|
1122 |
|
if (has_vidmode) { |
1123 |
|
if (has_mode(640, 480)) |
1124 |
< |
add_mode(p, screen_modes, 1, mode, APPLE_640x480, DIS_SCREEN); |
1124 |
> |
add_mode(p, screen_modes, 1, default_mode, APPLE_640x480, DIS_SCREEN); |
1125 |
|
if (has_mode(800, 600)) |
1126 |
< |
add_mode(p, screen_modes, 2, mode, APPLE_800x600, DIS_SCREEN); |
1126 |
> |
add_mode(p, screen_modes, 2, default_mode, APPLE_800x600, DIS_SCREEN); |
1127 |
|
if (has_mode(1024, 768)) |
1128 |
< |
add_mode(p, screen_modes, 4, mode, APPLE_1024x768, DIS_SCREEN); |
1128 |
> |
add_mode(p, screen_modes, 4, default_mode, APPLE_1024x768, DIS_SCREEN); |
1129 |
> |
if (has_mode(1152, 768)) |
1130 |
> |
add_mode(p, screen_modes, 64, default_mode, APPLE_1152x768, DIS_SCREEN); |
1131 |
|
if (has_mode(1152, 900)) |
1132 |
< |
add_mode(p, screen_modes, 8, mode, APPLE_1152x900, DIS_SCREEN); |
1132 |
> |
add_mode(p, screen_modes, 8, default_mode, APPLE_1152x900, DIS_SCREEN); |
1133 |
|
if (has_mode(1280, 1024)) |
1134 |
< |
add_mode(p, screen_modes, 16, mode, APPLE_1280x1024, DIS_SCREEN); |
1134 |
> |
add_mode(p, screen_modes, 16, default_mode, APPLE_1280x1024, DIS_SCREEN); |
1135 |
|
if (has_mode(1600, 1200)) |
1136 |
< |
add_mode(p, screen_modes, 32, mode, APPLE_1600x1200, DIS_SCREEN); |
1136 |
> |
add_mode(p, screen_modes, 32, default_mode, APPLE_1600x1200, DIS_SCREEN); |
1137 |
|
} else if (screen_modes) { |
1138 |
|
int xsize = DisplayWidth(x_display, screen); |
1139 |
|
int ysize = DisplayHeight(x_display, screen); |
1140 |
< |
int apple_id; |
817 |
< |
if (xsize < 800) |
818 |
< |
apple_id = APPLE_640x480; |
819 |
< |
else if (xsize < 1024) |
820 |
< |
apple_id = APPLE_800x600; |
821 |
< |
else if (xsize < 1152) |
822 |
< |
apple_id = APPLE_1024x768; |
823 |
< |
else if (xsize < 1280) |
824 |
< |
apple_id = APPLE_1152x900; |
825 |
< |
else if (xsize < 1600) |
826 |
< |
apple_id = APPLE_1280x1024; |
827 |
< |
else |
828 |
< |
apple_id = APPLE_1600x1200; |
1140 |
> |
int apple_id = find_apple_resolution(xsize, ysize); |
1141 |
|
p->viType = DIS_SCREEN; |
1142 |
|
p->viRowBytes = 0; |
1143 |
|
p->viXsize = xsize; |
1144 |
|
p->viYsize = ysize; |
1145 |
< |
p->viAppleMode = mode; |
1145 |
> |
p->viAppleMode = default_mode; |
1146 |
|
p->viAppleID = apple_id; |
1147 |
|
p++; |
1148 |
|
} |
1152 |
|
p->viAppleMode = 0; |
1153 |
|
p->viAppleID = 0; |
1154 |
|
|
1155 |
< |
#ifdef ENABLE_XF86_DGA |
1155 |
> |
// Find default mode (window 640x480) |
1156 |
> |
cur_mode = -1; |
1157 |
|
if (has_dga && screen_modes) { |
1158 |
< |
int v_bank, v_size; |
1159 |
< |
XF86DGAGetVideo(x_display, screen, &dga_screen_base, &dga_fb_width, &v_bank, &v_size); |
1160 |
< |
D(bug("DGA screen_base %p, v_width %d\n", dga_screen_base, dga_fb_width)); |
1158 |
> |
int screen_width = DisplayWidth(x_display, screen); |
1159 |
> |
int screen_height = DisplayHeight(x_display, screen); |
1160 |
> |
int apple_id = find_apple_resolution(screen_width, screen_height); |
1161 |
> |
if (apple_id != -1) |
1162 |
> |
cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN); |
1163 |
> |
} |
1164 |
> |
if (cur_mode == -1) |
1165 |
> |
cur_mode = find_mode(default_mode, APPLE_W_640x480, DIS_WINDOW); |
1166 |
> |
assert(cur_mode != -1); |
1167 |
> |
|
1168 |
> |
#if DEBUG |
1169 |
> |
D(bug("Available video modes:\n")); |
1170 |
> |
for (p = VModes; p->viType != DIS_INVALID; p++) { |
1171 |
> |
int bits = depth_of_video_mode(p->viAppleMode); |
1172 |
> |
D(bug(" %dx%d (ID %02x), %d colors\n", p->viXsize, p->viYsize, p->viAppleID, 1 << bits)); |
1173 |
|
} |
1174 |
|
#endif |
1175 |
|
|
1184 |
|
|
1185 |
|
// Start periodic thread |
1186 |
|
XSync(x_display, false); |
1187 |
< |
redraw_thread_active = (pthread_create(&redraw_thread, NULL, redraw_func, NULL) == 0); |
1187 |
> |
Set_pthread_attr(&redraw_thread_attr, 0); |
1188 |
> |
redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0); |
1189 |
|
D(bug("Redraw thread installed (%ld)\n", redraw_thread)); |
1190 |
|
return true; |
1191 |
|
} |
1217 |
|
close_display(); |
1218 |
|
XFlush(x_display); |
1219 |
|
XSync(x_display, false); |
894 |
– |
if (depth == 8) { |
895 |
– |
XFreeColormap(x_display, cmap[0]); |
896 |
– |
XFreeColormap(x_display, cmap[1]); |
897 |
– |
} |
1220 |
|
} |
1221 |
|
} |
1222 |
|
|
1280 |
|
// Reopen full screen display |
1281 |
|
XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime); |
1282 |
|
XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
1283 |
+ |
#ifdef ENABLE_XF86_DGA |
1284 |
|
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
1285 |
|
XF86DGASetViewPort(x_display, screen, 0, 0); |
1286 |
+ |
#endif |
1287 |
|
XSync(x_display, false); |
1288 |
|
|
1289 |
|
// the_buffer already contains the data to restore. i.e. since a temporary |
1499 |
|
for (;;) { |
1500 |
|
XEvent event; |
1501 |
|
|
1502 |
< |
if (!XCheckMaskEvent(x_display, eventmask, &event)) |
1502 |
> |
XDisplayLock(); |
1503 |
> |
if (!XCheckMaskEvent(x_display, eventmask, &event)) { |
1504 |
> |
// Handle clipboard events |
1505 |
> |
if (XCheckTypedEvent(x_display, SelectionRequest, &event)) |
1506 |
> |
ClipboardSelectionRequest(&event.xselectionrequest); |
1507 |
> |
else if (XCheckTypedEvent(x_display, SelectionClear, &event)) |
1508 |
> |
ClipboardSelectionClear(&event.xselectionclear); |
1509 |
> |
|
1510 |
> |
// Window "close" widget clicked |
1511 |
> |
else if (XCheckTypedEvent(x_display, ClientMessage, &event)) { |
1512 |
> |
if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW) { |
1513 |
> |
ADBKeyDown(0x7f); // Power key |
1514 |
> |
ADBKeyUp(0x7f); |
1515 |
> |
} |
1516 |
> |
} |
1517 |
> |
|
1518 |
> |
XDisplayUnlock(); |
1519 |
|
break; |
1520 |
+ |
} |
1521 |
+ |
XDisplayUnlock(); |
1522 |
|
|
1523 |
|
switch (event.type) { |
1524 |
|
// Mouse button |
1526 |
|
unsigned int button = ((XButtonEvent *)&event)->button; |
1527 |
|
if (button < 4) |
1528 |
|
ADBMouseDown(button - 1); |
1529 |
+ |
else if (button < 6) { // Wheel mouse |
1530 |
+ |
if (mouse_wheel_mode == 0) { |
1531 |
+ |
int key = (button == 5) ? 0x79 : 0x74; // Page up/down |
1532 |
+ |
ADBKeyDown(key); |
1533 |
+ |
ADBKeyUp(key); |
1534 |
+ |
} else { |
1535 |
+ |
int key = (button == 5) ? 0x3d : 0x3e; // Cursor up/down |
1536 |
+ |
for(int i=0; i<mouse_wheel_lines; i++) { |
1537 |
+ |
ADBKeyDown(key); |
1538 |
+ |
ADBKeyUp(key); |
1539 |
+ |
} |
1540 |
+ |
} |
1541 |
+ |
} |
1542 |
|
break; |
1543 |
|
} |
1544 |
|
case ButtonRelease: { |
1548 |
|
break; |
1549 |
|
} |
1550 |
|
|
1551 |
< |
// Mouse moved |
1551 |
> |
// Mouse entered window |
1552 |
|
case EnterNotify: |
1553 |
< |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1553 |
> |
if (event.xcrossing.mode != NotifyGrab && event.xcrossing.mode != NotifyUngrab) |
1554 |
> |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
1555 |
|
break; |
1556 |
+ |
|
1557 |
+ |
// Mouse moved |
1558 |
|
case MotionNotify: |
1559 |
< |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
1559 |
> |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
1560 |
|
break; |
1561 |
|
|
1562 |
|
// Keyboard |
1623 |
|
* Install graphics acceleration |
1624 |
|
*/ |
1625 |
|
|
1626 |
< |
#if 0 |
1627 |
< |
// Rectangle blitting |
1628 |
< |
static void accl_bitblt(accl_params *p) |
1626 |
> |
// Rectangle inversion |
1627 |
> |
template< int bpp > |
1628 |
> |
static inline void do_invrect(uint8 *dest, uint32 length) |
1629 |
|
{ |
1630 |
< |
D(bug("accl_bitblt\n")); |
1630 |
> |
#define INVERT_1(PTR, OFS) ((uint8 *)(PTR))[OFS] = ~((uint8 *)(PTR))[OFS] |
1631 |
> |
#define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS] |
1632 |
> |
#define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS] |
1633 |
> |
#define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS] |
1634 |
|
|
1635 |
< |
// Get blitting parameters |
1636 |
< |
int16 src_X = p->src_rect[1] - p->src_bounds[1]; |
1637 |
< |
int16 src_Y = p->src_rect[0] - p->src_bounds[0]; |
1638 |
< |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1639 |
< |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1640 |
< |
int16 width = p->dest_rect[3] - p->dest_rect[1] - 1; |
1280 |
< |
int16 height = p->dest_rect[2] - p->dest_rect[0] - 1; |
1281 |
< |
D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y)); |
1282 |
< |
D(bug(" width %d, height %d\n", width, height)); |
1635 |
> |
#ifndef UNALIGNED_PROFITABLE |
1636 |
> |
// Align on 16-bit boundaries |
1637 |
> |
if (bpp < 16 && (((uintptr)dest) & 1)) { |
1638 |
> |
INVERT_1(dest, 0); |
1639 |
> |
dest += 1; length -= 1; |
1640 |
> |
} |
1641 |
|
|
1642 |
< |
// And perform the blit |
1643 |
< |
bitblt_hook(src_X, src_Y, dest_X, dest_Y, width, height); |
1644 |
< |
} |
1642 |
> |
// Align on 32-bit boundaries |
1643 |
> |
if (bpp < 32 && (((uintptr)dest) & 2)) { |
1644 |
> |
INVERT_2(dest, 0); |
1645 |
> |
dest += 2; length -= 2; |
1646 |
> |
} |
1647 |
> |
#endif |
1648 |
|
|
1649 |
< |
static bool accl_bitblt_hook(accl_params *p) |
1650 |
< |
{ |
1651 |
< |
D(bug("accl_draw_hook %p\n", p)); |
1649 |
> |
// Invert 8-byte words |
1650 |
> |
if (length >= 8) { |
1651 |
> |
const int r = (length / 8) % 8; |
1652 |
> |
dest += r * 8; |
1653 |
|
|
1654 |
< |
// Check if we can accelerate this bitblt |
1655 |
< |
if (p->src_base_addr == screen_base && p->dest_base_addr == screen_base && |
1656 |
< |
display_type == DIS_SCREEN && bitblt_hook != NULL && |
1657 |
< |
((uint32 *)p)[0x18 >> 2] + ((uint32 *)p)[0x128 >> 2] == 0 && |
1658 |
< |
((uint32 *)p)[0x130 >> 2] == 0 && |
1659 |
< |
p->transfer_mode == 0 && |
1660 |
< |
p->src_row_bytes > 0 && ((uint32 *)p)[0x15c >> 2] > 0) { |
1654 |
> |
int n = ((length / 8) + 7) / 8; |
1655 |
> |
switch (r) { |
1656 |
> |
case 0: do { |
1657 |
> |
dest += 64; |
1658 |
> |
INVERT_8(dest, -8); |
1659 |
> |
case 7: INVERT_8(dest, -7); |
1660 |
> |
case 6: INVERT_8(dest, -6); |
1661 |
> |
case 5: INVERT_8(dest, -5); |
1662 |
> |
case 4: INVERT_8(dest, -4); |
1663 |
> |
case 3: INVERT_8(dest, -3); |
1664 |
> |
case 2: INVERT_8(dest, -2); |
1665 |
> |
case 1: INVERT_8(dest, -1); |
1666 |
> |
} while (--n > 0); |
1667 |
> |
} |
1668 |
> |
} |
1669 |
|
|
1670 |
< |
// Yes, set function pointer |
1671 |
< |
p->draw_proc = accl_bitblt; |
1672 |
< |
return true; |
1670 |
> |
// 32-bit cell to invert? |
1671 |
> |
if (length & 4) { |
1672 |
> |
INVERT_4(dest, 0); |
1673 |
> |
if (bpp <= 16) |
1674 |
> |
dest += 4; |
1675 |
|
} |
1676 |
< |
return false; |
1676 |
> |
|
1677 |
> |
// 16-bit cell to invert? |
1678 |
> |
if (bpp <= 16 && (length & 2)) { |
1679 |
> |
INVERT_2(dest, 0); |
1680 |
> |
if (bpp <= 8) |
1681 |
> |
dest += 2; |
1682 |
> |
} |
1683 |
> |
|
1684 |
> |
// 8-bit cell to invert? |
1685 |
> |
if (bpp <= 8 && (length & 1)) |
1686 |
> |
INVERT_1(dest, 0); |
1687 |
> |
|
1688 |
> |
#undef INVERT_1 |
1689 |
> |
#undef INVERT_2 |
1690 |
> |
#undef INVERT_4 |
1691 |
> |
#undef INVERT_8 |
1692 |
|
} |
1693 |
|
|
1694 |
< |
// Rectangle filling/inversion |
1308 |
< |
static void accl_fillrect8(accl_params *p) |
1694 |
> |
void NQD_invrect(uint32 p) |
1695 |
|
{ |
1696 |
< |
D(bug("accl_fillrect8\n")); |
1696 |
> |
D(bug("accl_invrect %08x\n", p)); |
1697 |
|
|
1698 |
< |
// Get filling parameters |
1699 |
< |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1700 |
< |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1701 |
< |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1702 |
< |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1317 |
< |
uint8 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
1698 |
> |
// Get inversion parameters |
1699 |
> |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1700 |
> |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1701 |
> |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1702 |
> |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1703 |
|
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1704 |
< |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1704 |
> |
D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes))); |
1705 |
|
|
1706 |
< |
// And perform the fill |
1707 |
< |
fillrect8_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
1706 |
> |
//!!?? pen_mode == 14 |
1707 |
> |
|
1708 |
> |
// And perform the inversion |
1709 |
> |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); |
1710 |
> |
const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1711 |
> |
uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); |
1712 |
> |
width *= bpp; |
1713 |
> |
switch (bpp) { |
1714 |
> |
case 1: |
1715 |
> |
for (int i = 0; i < height; i++) { |
1716 |
> |
do_invrect<8>(dest, width); |
1717 |
> |
dest += dest_row_bytes; |
1718 |
> |
} |
1719 |
> |
break; |
1720 |
> |
case 2: |
1721 |
> |
for (int i = 0; i < height; i++) { |
1722 |
> |
do_invrect<16>(dest, width); |
1723 |
> |
dest += dest_row_bytes; |
1724 |
> |
} |
1725 |
> |
break; |
1726 |
> |
case 4: |
1727 |
> |
for (int i = 0; i < height; i++) { |
1728 |
> |
do_invrect<32>(dest, width); |
1729 |
> |
dest += dest_row_bytes; |
1730 |
> |
} |
1731 |
> |
break; |
1732 |
> |
} |
1733 |
|
} |
1734 |
|
|
1735 |
< |
static void accl_fillrect32(accl_params *p) |
1735 |
> |
// Rectangle filling |
1736 |
> |
template< int bpp > |
1737 |
> |
static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length) |
1738 |
|
{ |
1739 |
< |
D(bug("accl_fillrect32\n")); |
1739 |
> |
#define FILL_1(PTR, OFS, VAL) ((uint8 *)(PTR))[OFS] = (VAL) |
1740 |
> |
#define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL) |
1741 |
> |
#define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL) |
1742 |
> |
#define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL) |
1743 |
|
|
1744 |
< |
// Get filling parameters |
1745 |
< |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1746 |
< |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1747 |
< |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1748 |
< |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1749 |
< |
uint32 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
1335 |
< |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1336 |
< |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1744 |
> |
#ifndef UNALIGNED_PROFITABLE |
1745 |
> |
// Align on 16-bit boundaries |
1746 |
> |
if (bpp < 16 && (((uintptr)dest) & 1)) { |
1747 |
> |
FILL_1(dest, 0, color); |
1748 |
> |
dest += 1; length -= 1; |
1749 |
> |
} |
1750 |
|
|
1751 |
< |
// And perform the fill |
1752 |
< |
fillrect32_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
1751 |
> |
// Align on 32-bit boundaries |
1752 |
> |
if (bpp < 32 && (((uintptr)dest) & 2)) { |
1753 |
> |
FILL_2(dest, 0, color); |
1754 |
> |
dest += 2; length -= 2; |
1755 |
> |
} |
1756 |
> |
#endif |
1757 |
> |
|
1758 |
> |
// Fill 8-byte words |
1759 |
> |
if (length >= 8) { |
1760 |
> |
const uint64 c = (((uint64)color) << 32) | color; |
1761 |
> |
const int r = (length / 8) % 8; |
1762 |
> |
dest += r * 8; |
1763 |
> |
|
1764 |
> |
int n = ((length / 8) + 7) / 8; |
1765 |
> |
switch (r) { |
1766 |
> |
case 0: do { |
1767 |
> |
dest += 64; |
1768 |
> |
FILL_8(dest, -8, c); |
1769 |
> |
case 7: FILL_8(dest, -7, c); |
1770 |
> |
case 6: FILL_8(dest, -6, c); |
1771 |
> |
case 5: FILL_8(dest, -5, c); |
1772 |
> |
case 4: FILL_8(dest, -4, c); |
1773 |
> |
case 3: FILL_8(dest, -3, c); |
1774 |
> |
case 2: FILL_8(dest, -2, c); |
1775 |
> |
case 1: FILL_8(dest, -1, c); |
1776 |
> |
} while (--n > 0); |
1777 |
> |
} |
1778 |
> |
} |
1779 |
> |
|
1780 |
> |
// 32-bit cell to fill? |
1781 |
> |
if (length & 4) { |
1782 |
> |
FILL_4(dest, 0, color); |
1783 |
> |
if (bpp <= 16) |
1784 |
> |
dest += 4; |
1785 |
> |
} |
1786 |
> |
|
1787 |
> |
// 16-bit cell to fill? |
1788 |
> |
if (bpp <= 16 && (length & 2)) { |
1789 |
> |
FILL_2(dest, 0, color); |
1790 |
> |
if (bpp <= 8) |
1791 |
> |
dest += 2; |
1792 |
> |
} |
1793 |
> |
|
1794 |
> |
// 8-bit cell to fill? |
1795 |
> |
if (bpp <= 8 && (length & 1)) |
1796 |
> |
FILL_1(dest, 0, color); |
1797 |
> |
|
1798 |
> |
#undef FILL_1 |
1799 |
> |
#undef FILL_2 |
1800 |
> |
#undef FILL_4 |
1801 |
> |
#undef FILL_8 |
1802 |
|
} |
1803 |
|
|
1804 |
< |
static void accl_invrect(accl_params *p) |
1804 |
> |
void NQD_fillrect(uint32 p) |
1805 |
|
{ |
1806 |
< |
D(bug("accl_invrect\n")); |
1806 |
> |
D(bug("accl_fillrect %08x\n", p)); |
1807 |
|
|
1808 |
< |
// Get inversion parameters |
1809 |
< |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1810 |
< |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1811 |
< |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1812 |
< |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1808 |
> |
// Get filling parameters |
1809 |
> |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1810 |
> |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1811 |
> |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1812 |
> |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1813 |
> |
uint32 color = ReadMacInt32(p + acclPenMode) == 8 ? ReadMacInt32(p + acclForePen) : ReadMacInt32(p + acclBackPen); |
1814 |
|
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1815 |
< |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1816 |
< |
|
1354 |
< |
//!!?? pen_mode == 14 |
1815 |
> |
D(bug(" width %d, height %d\n", width, height)); |
1816 |
> |
D(bug(" bytes_per_row %d color %08x\n", (int32)ReadMacInt32(p + acclDestRowBytes), color)); |
1817 |
|
|
1818 |
< |
// And perform the inversion |
1819 |
< |
invrect_hook(dest_X, dest_Y, dest_X_max, dest_Y_max); |
1818 |
> |
// And perform the fill |
1819 |
> |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); |
1820 |
> |
const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1821 |
> |
uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); |
1822 |
> |
width *= bpp; |
1823 |
> |
switch (bpp) { |
1824 |
> |
case 1: |
1825 |
> |
for (int i = 0; i < height; i++) { |
1826 |
> |
memset(dest, color, width); |
1827 |
> |
dest += dest_row_bytes; |
1828 |
> |
} |
1829 |
> |
break; |
1830 |
> |
case 2: |
1831 |
> |
for (int i = 0; i < height; i++) { |
1832 |
> |
do_fillrect<16>(dest, color, width); |
1833 |
> |
dest += dest_row_bytes; |
1834 |
> |
} |
1835 |
> |
break; |
1836 |
> |
case 4: |
1837 |
> |
for (int i = 0; i < height; i++) { |
1838 |
> |
do_fillrect<32>(dest, color, width); |
1839 |
> |
dest += dest_row_bytes; |
1840 |
> |
} |
1841 |
> |
break; |
1842 |
> |
} |
1843 |
|
} |
1844 |
|
|
1845 |
< |
static bool accl_fillrect_hook(accl_params *p) |
1845 |
> |
bool NQD_fillrect_hook(uint32 p) |
1846 |
|
{ |
1847 |
< |
D(bug("accl_fillrect_hook %p\n", p)); |
1847 |
> |
D(bug("accl_fillrect_hook %08x\n", p)); |
1848 |
|
|
1849 |
|
// Check if we can accelerate this fillrect |
1850 |
< |
if (p->dest_base_addr == screen_base && ((uint32 *)p)[0x284 >> 2] != 0 && display_type == DIS_SCREEN) { |
1851 |
< |
if (p->transfer_mode == 8) { |
1850 |
> |
if (ReadMacInt32(p + 0x284) != 0 && ReadMacInt32(p + acclDestPixelSize) >= 8) { |
1851 |
> |
const int transfer_mode = ReadMacInt32(p + acclTransferMode); |
1852 |
> |
if (transfer_mode == 8) { |
1853 |
|
// Fill |
1854 |
< |
if (p->dest_pixel_size == 8 && fillrect8_hook != NULL) { |
1855 |
< |
p->draw_proc = accl_fillrect8; |
1856 |
< |
return true; |
1857 |
< |
} else if (p->dest_pixel_size == 32 && fillrect32_hook != NULL) { |
1372 |
< |
p->draw_proc = accl_fillrect32; |
1373 |
< |
return true; |
1374 |
< |
} |
1375 |
< |
} else if (p->transfer_mode == 10 && invrect_hook != NULL) { |
1854 |
> |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_FILLRECT)); |
1855 |
> |
return true; |
1856 |
> |
} |
1857 |
> |
else if (transfer_mode == 10) { |
1858 |
|
// Invert |
1859 |
< |
p->draw_proc = accl_invrect; |
1859 |
> |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_INVRECT)); |
1860 |
|
return true; |
1861 |
|
} |
1862 |
|
} |
1863 |
|
return false; |
1864 |
|
} |
1865 |
|
|
1866 |
+ |
// Rectangle blitting |
1867 |
+ |
// TODO: optimize for VOSF and target pixmap == screen |
1868 |
+ |
void NQD_bitblt(uint32 p) |
1869 |
+ |
{ |
1870 |
+ |
D(bug("accl_bitblt %08x\n", p)); |
1871 |
+ |
|
1872 |
+ |
// Get blitting parameters |
1873 |
+ |
int16 src_X = (int16)ReadMacInt16(p + acclSrcRect + 2) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 2); |
1874 |
+ |
int16 src_Y = (int16)ReadMacInt16(p + acclSrcRect + 0) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 0); |
1875 |
+ |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1876 |
+ |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1877 |
+ |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1878 |
+ |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1879 |
+ |
D(bug(" src addr %08x, dest addr %08x\n", ReadMacInt32(p + acclSrcBaseAddr), ReadMacInt32(p + acclDestBaseAddr))); |
1880 |
+ |
D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y)); |
1881 |
+ |
D(bug(" width %d, height %d\n", width, height)); |
1882 |
+ |
|
1883 |
+ |
// And perform the blit |
1884 |
+ |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclSrcPixelSize)); |
1885 |
+ |
width *= bpp; |
1886 |
+ |
if ((int32)ReadMacInt32(p + acclSrcRowBytes) > 0) { |
1887 |
+ |
const int src_row_bytes = (int32)ReadMacInt32(p + acclSrcRowBytes); |
1888 |
+ |
const int dst_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1889 |
+ |
uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + (src_Y * src_row_bytes) + (src_X * bpp)); |
1890 |
+ |
uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dst_row_bytes) + (dest_X * bpp)); |
1891 |
+ |
for (int i = 0; i < height; i++) { |
1892 |
+ |
memmove(dst, src, width); |
1893 |
+ |
src += src_row_bytes; |
1894 |
+ |
dst += dst_row_bytes; |
1895 |
+ |
} |
1896 |
+ |
} |
1897 |
+ |
else { |
1898 |
+ |
const int src_row_bytes = -(int32)ReadMacInt32(p + acclSrcRowBytes); |
1899 |
+ |
const int dst_row_bytes = -(int32)ReadMacInt32(p + acclDestRowBytes); |
1900 |
+ |
uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp)); |
1901 |
+ |
uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp)); |
1902 |
+ |
for (int i = height - 1; i >= 0; i--) { |
1903 |
+ |
memmove(dst, src, width); |
1904 |
+ |
src -= src_row_bytes; |
1905 |
+ |
dst -= dst_row_bytes; |
1906 |
+ |
} |
1907 |
+ |
} |
1908 |
+ |
} |
1909 |
+ |
|
1910 |
+ |
/* |
1911 |
+ |
BitBlt transfer modes: |
1912 |
+ |
0 : srcCopy |
1913 |
+ |
1 : srcOr |
1914 |
+ |
2 : srcXor |
1915 |
+ |
3 : srcBic |
1916 |
+ |
4 : notSrcCopy |
1917 |
+ |
5 : notSrcOr |
1918 |
+ |
6 : notSrcXor |
1919 |
+ |
7 : notSrcBic |
1920 |
+ |
32 : blend |
1921 |
+ |
33 : addPin |
1922 |
+ |
34 : addOver |
1923 |
+ |
35 : subPin |
1924 |
+ |
36 : transparent |
1925 |
+ |
37 : adMax |
1926 |
+ |
38 : subOver |
1927 |
+ |
39 : adMin |
1928 |
+ |
50 : hilite |
1929 |
+ |
*/ |
1930 |
+ |
|
1931 |
+ |
bool NQD_bitblt_hook(uint32 p) |
1932 |
+ |
{ |
1933 |
+ |
D(bug("accl_draw_hook %08x\n", p)); |
1934 |
+ |
|
1935 |
+ |
// Check if we can accelerate this bitblt |
1936 |
+ |
if (ReadMacInt32(p + 0x018) + ReadMacInt32(p + 0x128) == 0 && |
1937 |
+ |
ReadMacInt32(p + 0x130) == 0 && |
1938 |
+ |
ReadMacInt32(p + acclSrcPixelSize) >= 8 && |
1939 |
+ |
ReadMacInt32(p + acclSrcPixelSize) == ReadMacInt32(p + acclDestPixelSize) && |
1940 |
+ |
(ReadMacInt32(p + acclSrcRowBytes) ^ ReadMacInt32(p + acclDestRowBytes)) >= 0 && // same sign? |
1941 |
+ |
ReadMacInt32(p + acclTransferMode) == 0 && // srcCopy? |
1942 |
+ |
ReadMacInt32(p + 0x15c) > 0) { |
1943 |
+ |
|
1944 |
+ |
// Yes, set function pointer |
1945 |
+ |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_BITBLT)); |
1946 |
+ |
return true; |
1947 |
+ |
} |
1948 |
+ |
return false; |
1949 |
+ |
} |
1950 |
+ |
|
1951 |
|
// Wait for graphics operation to finish |
1952 |
< |
static bool accl_sync_hook(void *arg) |
1952 |
> |
bool NQD_sync_hook(uint32 arg) |
1953 |
|
{ |
1954 |
< |
D(bug("accl_sync_hook %p\n", arg)); |
1388 |
< |
if (sync_hook != NULL) |
1389 |
< |
sync_hook(); |
1954 |
> |
D(bug("accl_sync_hook %08x\n", arg)); |
1955 |
|
return true; |
1956 |
|
} |
1957 |
|
|
1393 |
– |
static struct accl_hook_info bitblt_hook_info = {accl_bitblt_hook, accl_sync_hook, ACCL_BITBLT}; |
1394 |
– |
static struct accl_hook_info fillrect_hook_info = {accl_fillrect_hook, accl_sync_hook, ACCL_FILLRECT}; |
1395 |
– |
#endif |
1396 |
– |
|
1958 |
|
void VideoInstallAccel(void) |
1959 |
|
{ |
1960 |
+ |
// Temporary hack until it's fixed for e.g. little-endian & 64-bit platforms |
1961 |
+ |
#ifndef __powerpc__ |
1962 |
+ |
return; |
1963 |
+ |
#endif |
1964 |
+ |
|
1965 |
|
// Install acceleration hooks |
1966 |
|
if (PrefsFindBool("gfxaccel")) { |
1967 |
|
D(bug("Video: Installing acceleration hooks\n")); |
1968 |
< |
//!! NQDMisc(6, &bitblt_hook_info); |
1969 |
< |
// NQDMisc(6, &fillrect_hook_info); |
1968 |
> |
uint32 base; |
1969 |
> |
|
1970 |
> |
SheepVar bitblt_hook_info(sizeof(accl_hook_info)); |
1971 |
> |
base = bitblt_hook_info.addr(); |
1972 |
> |
WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK)); |
1973 |
> |
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
1974 |
> |
WriteMacInt32(base + 8, ACCL_BITBLT); |
1975 |
> |
NQDMisc(6, bitblt_hook_info.ptr()); |
1976 |
> |
|
1977 |
> |
SheepVar fillrect_hook_info(sizeof(accl_hook_info)); |
1978 |
> |
base = fillrect_hook_info.addr(); |
1979 |
> |
WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK)); |
1980 |
> |
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
1981 |
> |
WriteMacInt32(base + 8, ACCL_FILLRECT); |
1982 |
> |
NQDMisc(6, fillrect_hook_info.ptr()); |
1983 |
|
} |
1984 |
|
} |
1985 |
|
|
2042 |
|
|
2043 |
|
void video_set_palette(void) |
2044 |
|
{ |
2045 |
+ |
LOCK_PALETTE; |
2046 |
+ |
|
2047 |
+ |
// Convert colors to XColor array |
2048 |
+ |
int mode = get_current_mode(); |
2049 |
+ |
int num_in = palette_size(mode); |
2050 |
+ |
int num_out = 256; |
2051 |
+ |
bool stretch = false; |
2052 |
+ |
if (IsDirectMode(mode)) { |
2053 |
+ |
// If X is in 565 mode we have to stretch the gamma table from 32 to 64 entries |
2054 |
+ |
num_out = vis->map_entries; |
2055 |
+ |
stretch = true; |
2056 |
+ |
} |
2057 |
+ |
XColor *p = x_palette; |
2058 |
+ |
for (int i=0; i<num_out; i++) { |
2059 |
+ |
int c = (stretch ? (i * num_in) / num_out : i); |
2060 |
+ |
p->red = mac_pal[c].red * 0x0101; |
2061 |
+ |
p->green = mac_pal[c].green * 0x0101; |
2062 |
+ |
p->blue = mac_pal[c].blue * 0x0101; |
2063 |
+ |
p++; |
2064 |
+ |
} |
2065 |
+ |
|
2066 |
+ |
#ifdef ENABLE_VOSF |
2067 |
+ |
// Recalculate pixel color expansion map |
2068 |
+ |
if (!IsDirectMode(mode) && xdepth > 8) { |
2069 |
+ |
for (int i=0; i<256; i++) { |
2070 |
+ |
int c = i & (num_in-1); // If there are less than 256 colors, we repeat the first entries (this makes color expansion easier) |
2071 |
+ |
ExpandMap[i] = map_rgb(mac_pal[c].red, mac_pal[c].green, mac_pal[c].blue); |
2072 |
+ |
} |
2073 |
+ |
|
2074 |
+ |
// We have to redraw everything because the interpretation of pixel values changed |
2075 |
+ |
LOCK_VOSF; |
2076 |
+ |
PFLAG_SET_ALL; |
2077 |
+ |
UNLOCK_VOSF; |
2078 |
+ |
memset(the_buffer_copy, 0, VModes[cur_mode].viRowBytes * VModes[cur_mode].viYsize); |
2079 |
+ |
} |
2080 |
+ |
#endif |
2081 |
+ |
|
2082 |
+ |
// Tell redraw thread to change palette |
2083 |
|
palette_changed = true; |
2084 |
+ |
|
2085 |
+ |
UNLOCK_PALETTE; |
2086 |
+ |
} |
2087 |
+ |
|
2088 |
+ |
|
2089 |
+ |
/* |
2090 |
+ |
* Can we set the MacOS cursor image into the window? |
2091 |
+ |
*/ |
2092 |
+ |
|
2093 |
+ |
bool video_can_change_cursor(void) |
2094 |
+ |
{ |
2095 |
+ |
return hw_mac_cursor_accl && (display_type != DIS_SCREEN); |
2096 |
|
} |
2097 |
|
|
2098 |
|
|
2219 |
|
|
2220 |
|
// Refresh display |
2221 |
|
if (high && wide) { |
2222 |
+ |
XDisplayLock(); |
2223 |
|
if (have_shm) |
2224 |
|
XShmPutImage(x_display, the_win, the_gc, img, x1, y1, x1, y1, wide, high, 0); |
2225 |
|
else |
2226 |
|
XPutImage(x_display, the_win, the_gc, img, x1, y1, x1, y1, wide, high); |
2227 |
+ |
XDisplayUnlock(); |
2228 |
|
} |
2229 |
|
} |
2230 |
|
|
2231 |
+ |
const int VIDEO_REFRESH_HZ = 60; |
2232 |
+ |
const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ; |
2233 |
+ |
|
2234 |
+ |
static void handle_palette_changes(void) |
2235 |
+ |
{ |
2236 |
+ |
LOCK_PALETTE; |
2237 |
+ |
|
2238 |
+ |
if (palette_changed && !emul_suspended) { |
2239 |
+ |
palette_changed = false; |
2240 |
+ |
|
2241 |
+ |
int mode = get_current_mode(); |
2242 |
+ |
if (color_class == PseudoColor || color_class == DirectColor) { |
2243 |
+ |
int num = vis->map_entries; |
2244 |
+ |
bool set_clut = true; |
2245 |
+ |
if (!IsDirectMode(mode) && color_class == DirectColor) { |
2246 |
+ |
if (display_type == DIS_WINDOW) |
2247 |
+ |
set_clut = false; // Indexed mode on true color screen, don't set CLUT |
2248 |
+ |
} |
2249 |
+ |
|
2250 |
+ |
if (set_clut) { |
2251 |
+ |
XDisplayLock(); |
2252 |
+ |
XStoreColors(x_display, cmap[0], x_palette, num); |
2253 |
+ |
XStoreColors(x_display, cmap[1], x_palette, num); |
2254 |
+ |
XSync(x_display, false); |
2255 |
+ |
XDisplayUnlock(); |
2256 |
+ |
} |
2257 |
+ |
} |
2258 |
+ |
|
2259 |
+ |
#ifdef ENABLE_XF86_DGA |
2260 |
+ |
if (display_type == DIS_SCREEN) { |
2261 |
+ |
current_dga_cmap ^= 1; |
2262 |
+ |
if (!IsDirectMode(mode) && cmap[current_dga_cmap]) |
2263 |
+ |
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
2264 |
+ |
} |
2265 |
+ |
#endif |
2266 |
+ |
} |
2267 |
+ |
|
2268 |
+ |
UNLOCK_PALETTE; |
2269 |
+ |
} |
2270 |
+ |
|
2271 |
|
static void *redraw_func(void *arg) |
2272 |
|
{ |
2273 |
< |
int tick_counter = 0; |
1603 |
< |
struct timespec req = {0, 16666667}; |
2273 |
> |
int fd = ConnectionNumber(x_display); |
2274 |
|
|
2275 |
< |
for (;;) { |
2275 |
> |
uint64 start = GetTicks_usec(); |
2276 |
> |
int64 ticks = 0; |
2277 |
> |
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
2278 |
|
|
2279 |
< |
// Wait |
1608 |
< |
nanosleep(&req, NULL); |
2279 |
> |
for (;;) { |
2280 |
|
|
2281 |
|
// Pause if requested (during video mode switches) |
2282 |
|
while (thread_stop_req) |
2283 |
|
thread_stop_ack = true; |
2284 |
|
|
2285 |
< |
// Handle X11 events |
2286 |
< |
handle_events(); |
2285 |
> |
int64 delay = next - GetTicks_usec(); |
2286 |
> |
if (delay < -VIDEO_REFRESH_DELAY) { |
2287 |
> |
|
2288 |
> |
// We are lagging far behind, so we reset the delay mechanism |
2289 |
> |
next = GetTicks_usec(); |
2290 |
> |
|
2291 |
> |
} else if (delay <= 0) { |
2292 |
|
|
2293 |
< |
// Quit DGA mode if requested |
2294 |
< |
if (quit_full_screen) { |
2295 |
< |
quit_full_screen = false; |
2296 |
< |
if (display_type == DIS_SCREEN) { |
2293 |
> |
// Delay expired, refresh display |
2294 |
> |
next += VIDEO_REFRESH_DELAY; |
2295 |
> |
ticks++; |
2296 |
> |
|
2297 |
> |
// Handle X11 events |
2298 |
> |
handle_events(); |
2299 |
> |
|
2300 |
> |
// Quit DGA mode if requested |
2301 |
> |
if (quit_full_screen) { |
2302 |
> |
quit_full_screen = false; |
2303 |
> |
if (display_type == DIS_SCREEN) { |
2304 |
> |
XDisplayLock(); |
2305 |
|
#ifdef ENABLE_XF86_DGA |
2306 |
< |
XF86DGADirectVideo(x_display, screen, 0); |
2307 |
< |
XUngrabPointer(x_display, CurrentTime); |
2308 |
< |
XUngrabKeyboard(x_display, CurrentTime); |
2309 |
< |
#endif |
2310 |
< |
XSync(x_display, false); |
2311 |
< |
quit_full_screen_ack = true; |
2312 |
< |
return NULL; |
2306 |
> |
XF86DGADirectVideo(x_display, screen, 0); |
2307 |
> |
XUngrabPointer(x_display, CurrentTime); |
2308 |
> |
XUngrabKeyboard(x_display, CurrentTime); |
2309 |
> |
XUnmapWindow(x_display, the_win); |
2310 |
> |
wait_unmapped(the_win); |
2311 |
> |
XDestroyWindow(x_display, the_win); |
2312 |
> |
#endif |
2313 |
> |
XSync(x_display, false); |
2314 |
> |
XDisplayUnlock(); |
2315 |
> |
quit_full_screen_ack = true; |
2316 |
> |
return NULL; |
2317 |
> |
} |
2318 |
|
} |
1630 |
– |
} |
2319 |
|
|
2320 |
< |
// Refresh display and set cursor image in window mode |
2321 |
< |
if (display_type == DIS_WINDOW) { |
2322 |
< |
tick_counter++; |
2323 |
< |
if (tick_counter >= frame_skip) { |
2324 |
< |
tick_counter = 0; |
2320 |
> |
// Refresh display and set cursor image in window mode |
2321 |
> |
static int tick_counter = 0; |
2322 |
> |
if (display_type == DIS_WINDOW) { |
2323 |
> |
tick_counter++; |
2324 |
> |
if (tick_counter >= frame_skip) { |
2325 |
> |
tick_counter = 0; |
2326 |
|
|
2327 |
< |
// Update display |
2327 |
> |
// Update display |
2328 |
|
#ifdef ENABLE_VOSF |
2329 |
< |
if (use_vosf) { |
2330 |
< |
if (mainBuffer.dirty) { |
2331 |
< |
LOCK_VOSF; |
2332 |
< |
update_display_window_vosf(); |
2333 |
< |
UNLOCK_VOSF; |
2334 |
< |
XSync(x_display, false); // Let the server catch up |
2329 |
> |
if (use_vosf) { |
2330 |
> |
XDisplayLock(); |
2331 |
> |
if (mainBuffer.dirty) { |
2332 |
> |
LOCK_VOSF; |
2333 |
> |
update_display_window_vosf(); |
2334 |
> |
UNLOCK_VOSF; |
2335 |
> |
XSync(x_display, false); // Let the server catch up |
2336 |
> |
} |
2337 |
> |
XDisplayUnlock(); |
2338 |
|
} |
2339 |
< |
} |
1648 |
< |
else |
2339 |
> |
else |
2340 |
|
#endif |
2341 |
< |
update_display(); |
2341 |
> |
update_display(); |
2342 |
|
|
2343 |
< |
// Set new cursor image if it was changed |
2344 |
< |
if (cursor_changed) { |
2345 |
< |
cursor_changed = false; |
2346 |
< |
memcpy(cursor_image->data, MacCursor + 4, 32); |
2347 |
< |
memcpy(cursor_mask_image->data, MacCursor + 36, 32); |
2348 |
< |
XFreeCursor(x_display, mac_cursor); |
2349 |
< |
XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16); |
2350 |
< |
XPutImage(x_display, cursor_mask_map, cursor_mask_gc, cursor_mask_image, 0, 0, 0, 0, 16, 16); |
2351 |
< |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, MacCursor[2], MacCursor[3]); |
2352 |
< |
XDefineCursor(x_display, the_win, mac_cursor); |
2343 |
> |
// Set new cursor image if it was changed |
2344 |
> |
if (hw_mac_cursor_accl && cursor_changed) { |
2345 |
> |
cursor_changed = false; |
2346 |
> |
memcpy(cursor_image->data, MacCursor + 4, 32); |
2347 |
> |
memcpy(cursor_mask_image->data, MacCursor + 36, 32); |
2348 |
> |
XDisplayLock(); |
2349 |
> |
XFreeCursor(x_display, mac_cursor); |
2350 |
> |
XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16); |
2351 |
> |
XPutImage(x_display, cursor_mask_map, cursor_mask_gc, cursor_mask_image, 0, 0, 0, 0, 16, 16); |
2352 |
> |
mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, MacCursor[2], MacCursor[3]); |
2353 |
> |
XDefineCursor(x_display, the_win, mac_cursor); |
2354 |
> |
XDisplayUnlock(); |
2355 |
> |
} |
2356 |
|
} |
2357 |
|
} |
1664 |
– |
} |
2358 |
|
#ifdef ENABLE_VOSF |
2359 |
< |
else if (use_vosf) { |
2360 |
< |
// Update display (VOSF variant) |
2361 |
< |
static int tick_counter = 0; |
2362 |
< |
if (++tick_counter >= frame_skip) { |
2363 |
< |
tick_counter = 0; |
2364 |
< |
if (mainBuffer.dirty) { |
2365 |
< |
LOCK_VOSF; |
2366 |
< |
update_display_dga_vosf(); |
2367 |
< |
UNLOCK_VOSF; |
2359 |
> |
else if (use_vosf) { |
2360 |
> |
// Update display (VOSF variant) |
2361 |
> |
if (++tick_counter >= frame_skip) { |
2362 |
> |
tick_counter = 0; |
2363 |
> |
if (mainBuffer.dirty) { |
2364 |
> |
LOCK_VOSF; |
2365 |
> |
update_display_dga_vosf(); |
2366 |
> |
UNLOCK_VOSF; |
2367 |
> |
} |
2368 |
|
} |
2369 |
|
} |
1677 |
– |
} |
2370 |
|
#endif |
2371 |
|
|
2372 |
< |
// Set new palette if it was changed |
2373 |
< |
if (palette_changed && !emul_suspended) { |
2374 |
< |
palette_changed = false; |
2375 |
< |
XColor c[256]; |
2376 |
< |
for (int i=0; i<256; i++) { |
2377 |
< |
c[i].pixel = i; |
2378 |
< |
c[i].red = mac_pal[i].red * 0x0101; |
2379 |
< |
c[i].green = mac_pal[i].green * 0x0101; |
2380 |
< |
c[i].blue = mac_pal[i].blue * 0x0101; |
2381 |
< |
c[i].flags = DoRed | DoGreen | DoBlue; |
2382 |
< |
} |
2383 |
< |
if (depth == 8) { |
2384 |
< |
XStoreColors(x_display, cmap[0], c, 256); |
2385 |
< |
XStoreColors(x_display, cmap[1], c, 256); |
1694 |
< |
#ifdef ENABLE_XF86_DGA |
1695 |
< |
if (display_type == DIS_SCREEN) { |
1696 |
< |
current_dga_cmap ^= 1; |
1697 |
< |
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1698 |
< |
} |
1699 |
< |
#endif |
1700 |
< |
} |
2372 |
> |
// Set new palette if it was changed |
2373 |
> |
handle_palette_changes(); |
2374 |
> |
|
2375 |
> |
} else { |
2376 |
> |
|
2377 |
> |
// No display refresh pending, check for X events |
2378 |
> |
fd_set readfds; |
2379 |
> |
FD_ZERO(&readfds); |
2380 |
> |
FD_SET(fd, &readfds); |
2381 |
> |
struct timeval timeout; |
2382 |
> |
timeout.tv_sec = 0; |
2383 |
> |
timeout.tv_usec = delay; |
2384 |
> |
if (select(fd+1, &readfds, NULL, NULL, &timeout) > 0) |
2385 |
> |
handle_events(); |
2386 |
|
} |
2387 |
|
} |
2388 |
|
return NULL; |