1 |
|
/* |
2 |
|
* video_x.cpp - Video/graphics emulation, X11 specific stuff |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2001 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2004 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 |
39 |
|
|
40 |
|
#include <algorithm> |
41 |
|
|
42 |
– |
#ifndef NO_STD_NAMESPACE |
43 |
– |
using std::sort; |
44 |
– |
#endif |
45 |
– |
|
42 |
|
#ifdef HAVE_PTHREADS |
43 |
|
# include <pthread.h> |
44 |
|
#endif |
62 |
|
#include "prefs.h" |
63 |
|
#include "user_strings.h" |
64 |
|
#include "video.h" |
65 |
+ |
#include "video_blit.h" |
66 |
|
|
67 |
|
#define DEBUG 0 |
68 |
|
#include "debug.h" |
69 |
|
|
70 |
|
|
71 |
+ |
// Supported video modes |
72 |
+ |
static vector<video_mode> VideoModes; |
73 |
+ |
|
74 |
|
// Display types |
75 |
|
enum { |
76 |
|
DISPLAY_WINDOW, // X11 window, using MIT SHM extensions if possible |
80 |
|
// Constants |
81 |
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; |
82 |
|
|
83 |
< |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | StructureNotifyMask; |
83 |
> |
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask | StructureNotifyMask; |
84 |
|
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask; |
85 |
|
|
86 |
|
|
97 |
|
|
98 |
|
static bool redraw_thread_active = false; // Flag: Redraw thread installed |
99 |
|
#ifdef HAVE_PTHREADS |
100 |
+ |
static pthread_attr_t redraw_thread_attr; // Redraw thread attributes |
101 |
|
static volatile bool redraw_thread_cancel; // Flag: Cancel Redraw thread |
102 |
|
static pthread_t redraw_thread; // Redraw thread |
103 |
|
#endif |
123 |
|
static int keycode_table[256]; // X keycode -> Mac keycode translation table |
124 |
|
|
125 |
|
// X11 variables |
126 |
+ |
char *x_display_name = NULL; // X11 display name |
127 |
+ |
Display *x_display = NULL; // X11 display handle |
128 |
|
static int screen; // Screen number |
129 |
|
static Window rootwin; // Root window and our window |
130 |
|
static int num_depths = 0; // Number of available X depths |
134 |
|
static int eventmask; |
135 |
|
|
136 |
|
static int xdepth; // Depth of X screen |
137 |
+ |
static VisualFormat visualFormat; |
138 |
|
static XVisualInfo visualInfo; |
139 |
|
static Visual *vis; |
140 |
|
static int color_class; |
143 |
|
|
144 |
|
static Colormap cmap[2] = {0, 0}; // Colormaps for indexed modes (DGA needs two of them) |
145 |
|
|
146 |
< |
static XColor palette[256]; // Color palette to be used as CLUT and gamma table |
147 |
< |
static bool palette_changed = false; // Flag: Palette changed, redraw thread must set new colors |
146 |
> |
static XColor x_palette[256]; // Color palette to be used as CLUT and gamma table |
147 |
> |
static bool x_palette_changed = false; // Flag: Palette changed, redraw thread must set new colors |
148 |
|
|
149 |
|
#ifdef ENABLE_FBDEV_DGA |
150 |
|
static int fbdev_fd = -1; |
157 |
|
|
158 |
|
// Mutex to protect palette |
159 |
|
#ifdef HAVE_PTHREADS |
160 |
< |
static pthread_mutex_t palette_lock = PTHREAD_MUTEX_INITIALIZER; |
161 |
< |
#define LOCK_PALETTE pthread_mutex_lock(&palette_lock) |
162 |
< |
#define UNLOCK_PALETTE pthread_mutex_unlock(&palette_lock) |
160 |
> |
static pthread_mutex_t x_palette_lock = PTHREAD_MUTEX_INITIALIZER; |
161 |
> |
#define LOCK_PALETTE pthread_mutex_lock(&x_palette_lock) |
162 |
> |
#define UNLOCK_PALETTE pthread_mutex_unlock(&x_palette_lock) |
163 |
|
#else |
164 |
|
#define LOCK_PALETTE |
165 |
|
#define UNLOCK_PALETTE |
188 |
|
|
189 |
|
// Prototypes |
190 |
|
static void *redraw_func(void *arg); |
187 |
– |
static int event2keycode(XKeyEvent &ev); |
191 |
|
|
192 |
|
// From main_unix.cpp |
193 |
|
extern char *x_display_name; |
194 |
|
extern Display *x_display; |
195 |
+ |
extern void *vm_acquire_mac(size_t size); |
196 |
|
|
197 |
|
// From sys_unix.cpp |
198 |
|
extern void SysMountFirstFloppy(void); |
199 |
|
|
200 |
|
|
201 |
|
/* |
202 |
+ |
* monitor_desc subclass for X11 display |
203 |
+ |
*/ |
204 |
+ |
|
205 |
+ |
class X11_monitor_desc : public monitor_desc { |
206 |
+ |
public: |
207 |
+ |
X11_monitor_desc(const vector<video_mode> &available_modes, video_depth default_depth, uint32 default_id) : monitor_desc(available_modes, default_depth, default_id) {} |
208 |
+ |
~X11_monitor_desc() {} |
209 |
+ |
|
210 |
+ |
virtual void switch_to_current_mode(void); |
211 |
+ |
virtual void set_palette(uint8 *pal, int num); |
212 |
+ |
|
213 |
+ |
bool video_open(void); |
214 |
+ |
void video_close(void); |
215 |
+ |
}; |
216 |
+ |
|
217 |
+ |
|
218 |
+ |
/* |
219 |
|
* Utility functions |
220 |
|
*/ |
221 |
|
|
222 |
+ |
// Map video_mode depth ID to numerical depth value |
223 |
+ |
static inline int depth_of_video_mode(video_mode const & mode) |
224 |
+ |
{ |
225 |
+ |
int depth = -1; |
226 |
+ |
switch (mode.depth) { |
227 |
+ |
case VDEPTH_1BIT: |
228 |
+ |
depth = 1; |
229 |
+ |
break; |
230 |
+ |
case VDEPTH_2BIT: |
231 |
+ |
depth = 2; |
232 |
+ |
break; |
233 |
+ |
case VDEPTH_4BIT: |
234 |
+ |
depth = 4; |
235 |
+ |
break; |
236 |
+ |
case VDEPTH_8BIT: |
237 |
+ |
depth = 8; |
238 |
+ |
break; |
239 |
+ |
case VDEPTH_16BIT: |
240 |
+ |
depth = 16; |
241 |
+ |
break; |
242 |
+ |
case VDEPTH_32BIT: |
243 |
+ |
depth = 32; |
244 |
+ |
break; |
245 |
+ |
default: |
246 |
+ |
abort(); |
247 |
+ |
} |
248 |
+ |
return depth; |
249 |
+ |
} |
250 |
+ |
|
251 |
|
// Map RGB color to pixel value (this only works in TrueColor/DirectColor visuals) |
252 |
|
static inline uint32 map_rgb(uint8 red, uint8 green, uint8 blue) |
253 |
|
{ |
260 |
|
{ |
261 |
|
D(bug("have_visual_for_depth(%d)\n", 1 << depth)); |
262 |
|
|
263 |
+ |
// 1-bit works always and uses default visual |
264 |
+ |
if (depth == VDEPTH_1BIT) { |
265 |
+ |
vis = DefaultVisual(x_display, screen); |
266 |
+ |
visualInfo.visualid = XVisualIDFromVisual(vis); |
267 |
+ |
int num = 0; |
268 |
+ |
XVisualInfo *vi = XGetVisualInfo(x_display, VisualIDMask, &visualInfo, &num); |
269 |
+ |
visualInfo = vi[0]; |
270 |
+ |
XFree(vi); |
271 |
+ |
xdepth = visualInfo.depth; |
272 |
+ |
color_class = visualInfo.c_class; |
273 |
+ |
D(bug(" found visual ID 0x%02x, depth %d\n", visualInfo.visualid, xdepth)); |
274 |
+ |
return true; |
275 |
+ |
} |
276 |
+ |
|
277 |
|
// Calculate minimum and maximum supported X depth |
278 |
|
int min_depth = 1, max_depth = 32; |
279 |
|
switch (depth) { |
216 |
– |
case VDEPTH_1BIT: // 1-bit works always |
217 |
– |
min_depth = 1; |
218 |
– |
max_depth = 32; |
219 |
– |
break; |
280 |
|
#ifdef ENABLE_VOSF |
281 |
|
case VDEPTH_2BIT: |
282 |
|
case VDEPTH_4BIT: // VOSF blitters can convert 2/4/8-bit -> 8/16/32-bit |
354 |
|
case DirectColor: D(bug("DirectColor\n")); break; |
355 |
|
} |
356 |
|
#endif |
357 |
+ |
return true; |
358 |
|
} |
359 |
|
|
360 |
|
// Add mode to list of supported modes |
382 |
|
} |
383 |
|
|
384 |
|
// Set Mac frame layout and base address (uses the_buffer/MacFrameBaseMac) |
385 |
< |
static void set_mac_frame_buffer(video_depth depth, bool native_byte_order) |
385 |
> |
static void set_mac_frame_buffer(X11_monitor_desc &monitor, video_depth depth, bool native_byte_order) |
386 |
|
{ |
387 |
|
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
388 |
|
int layout = FLAYOUT_DIRECT; |
394 |
|
MacFrameLayout = layout; |
395 |
|
else |
396 |
|
MacFrameLayout = FLAYOUT_DIRECT; |
397 |
< |
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
397 |
> |
monitor.set_mac_frame_base(MacFrameBaseMac); |
398 |
|
|
399 |
|
// Set variables used by UAE memory banking |
400 |
+ |
const video_mode &mode = monitor.get_current_mode(); |
401 |
|
MacFrameBaseHost = the_buffer; |
402 |
< |
MacFrameSize = VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y; |
402 |
> |
MacFrameSize = mode.bytes_per_row * mode.y; |
403 |
|
InitFrameBufferMapping(); |
404 |
|
#else |
405 |
< |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
405 |
> |
monitor.set_mac_frame_base(Host2MacAddr(the_buffer)); |
406 |
|
#endif |
407 |
< |
D(bug("VideoMonitor.mac_frame_base = %08x\n", VideoMonitor.mac_frame_base)); |
407 |
> |
D(bug("monitor.mac_frame_base = %08x\n", monitor.get_mac_frame_base())); |
408 |
|
} |
409 |
|
|
410 |
|
// Set window name and class |
482 |
|
|
483 |
|
class driver_base { |
484 |
|
public: |
485 |
< |
driver_base(); |
485 |
> |
driver_base(X11_monitor_desc &m); |
486 |
|
virtual ~driver_base(); |
487 |
|
|
488 |
|
virtual void update_palette(void); |
491 |
|
virtual void toggle_mouse_grab(void) {} |
492 |
|
virtual void mouse_moved(int x, int y) { ADBMouseMoved(x, y); } |
493 |
|
|
494 |
+ |
void disable_mouse_accel(void); |
495 |
+ |
void restore_mouse_accel(void); |
496 |
+ |
|
497 |
|
virtual void grab_mouse(void) {} |
498 |
|
virtual void ungrab_mouse(void) {} |
499 |
|
|
500 |
|
public: |
501 |
+ |
X11_monitor_desc &monitor; // Associated video monitor |
502 |
+ |
const video_mode &mode; // Video mode handled by the driver |
503 |
+ |
|
504 |
|
bool init_ok; // Initialization succeeded (we can't use exceptions because of -fomit-frame-pointer) |
505 |
|
Window w; // The window we draw into |
506 |
+ |
|
507 |
+ |
int orig_accel_numer, orig_accel_denom, orig_threshold; // Original mouse acceleration |
508 |
|
}; |
509 |
|
|
510 |
|
class driver_window; |
518 |
|
friend void update_display_static(driver_window *drv); |
519 |
|
|
520 |
|
public: |
521 |
< |
driver_window(const video_mode &mode); |
521 |
> |
driver_window(X11_monitor_desc &monitor); |
522 |
|
~driver_window(); |
523 |
|
|
524 |
|
void toggle_mouse_grab(void); |
543 |
|
# include "video_vosf.h" |
544 |
|
#endif |
545 |
|
|
546 |
< |
driver_base::driver_base() |
547 |
< |
: init_ok(false), w(0) |
546 |
> |
driver_base::driver_base(X11_monitor_desc &m) |
547 |
> |
: monitor(m), mode(m.get_current_mode()), init_ok(false), w(0) |
548 |
|
{ |
549 |
|
the_buffer = NULL; |
550 |
|
the_buffer_copy = NULL; |
551 |
+ |
XGetPointerControl(x_display, &orig_accel_numer, &orig_accel_denom, &orig_threshold); |
552 |
|
} |
553 |
|
|
554 |
|
driver_base::~driver_base() |
555 |
|
{ |
556 |
|
ungrab_mouse(); |
557 |
+ |
restore_mouse_accel(); |
558 |
|
|
559 |
|
if (w) { |
560 |
|
XUnmapWindow(x_display, w); |
578 |
|
} |
579 |
|
#ifdef ENABLE_VOSF |
580 |
|
else { |
581 |
+ |
// the_buffer shall always be mapped through vm_acquire() so that we can vm_protect() it at will |
582 |
+ |
if (the_buffer != VM_MAP_FAILED) { |
583 |
+ |
D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size)); |
584 |
+ |
vm_release(the_buffer, the_buffer_size); |
585 |
+ |
the_buffer = NULL; |
586 |
+ |
} |
587 |
|
if (the_host_buffer) { |
588 |
+ |
D(bug(" freeing the_host_buffer at %p\n", the_host_buffer)); |
589 |
|
free(the_host_buffer); |
590 |
|
the_host_buffer = NULL; |
591 |
|
} |
513 |
– |
if (the_buffer) { |
514 |
– |
free(the_buffer); |
515 |
– |
the_buffer = NULL; |
516 |
– |
} |
592 |
|
if (the_buffer_copy) { |
593 |
+ |
D(bug(" freeing the_buffer_copy at %p\n", the_buffer_copy)); |
594 |
|
free(the_buffer_copy); |
595 |
|
the_buffer_copy = NULL; |
596 |
|
} |
601 |
|
// Palette has changed |
602 |
|
void driver_base::update_palette(void) |
603 |
|
{ |
604 |
< |
if (cmap[0] && cmap[1]) { |
604 |
> |
if (color_class == PseudoColor || color_class == DirectColor) { |
605 |
|
int num = vis->map_entries; |
606 |
< |
if (!IsDirectMode(VideoMonitor.mode) && color_class == DirectColor) |
606 |
> |
if (!IsDirectMode(monitor.get_current_mode()) && color_class == DirectColor) |
607 |
|
return; // Indexed mode on true color screen, don't set CLUT |
608 |
< |
XStoreColors(x_display, cmap[0], palette, num); |
609 |
< |
XStoreColors(x_display, cmap[1], palette, num); |
608 |
> |
XStoreColors(x_display, cmap[0], x_palette, num); |
609 |
> |
XStoreColors(x_display, cmap[1], x_palette, num); |
610 |
|
} |
611 |
|
XSync(x_display, false); |
612 |
|
} |
613 |
|
|
614 |
+ |
// Disable mouse acceleration |
615 |
+ |
void driver_base::disable_mouse_accel(void) |
616 |
+ |
{ |
617 |
+ |
XChangePointerControl(x_display, True, False, 1, 1, 0); |
618 |
+ |
} |
619 |
+ |
|
620 |
+ |
// Restore mouse acceleration to original value |
621 |
+ |
void driver_base::restore_mouse_accel(void) |
622 |
+ |
{ |
623 |
+ |
XChangePointerControl(x_display, True, True, orig_accel_numer, orig_accel_denom, orig_threshold); |
624 |
+ |
} |
625 |
+ |
|
626 |
|
|
627 |
|
/* |
628 |
|
* Windowed display driver |
629 |
|
*/ |
630 |
|
|
631 |
|
// Open display |
632 |
< |
driver_window::driver_window(const video_mode &mode) |
633 |
< |
: gc(0), img(NULL), have_shm(false), mouse_grabbed(false), mac_cursor(0) |
632 |
> |
driver_window::driver_window(X11_monitor_desc &m) |
633 |
> |
: driver_base(m), gc(0), img(NULL), have_shm(false), mac_cursor(0), mouse_grabbed(false) |
634 |
|
{ |
635 |
|
int width = mode.x, height = mode.y; |
636 |
|
int aligned_width = (width + 15) & ~15; |
639 |
|
// Set absolute mouse mode |
640 |
|
ADBSetRelMouseMode(mouse_grabbed); |
641 |
|
|
642 |
< |
// Create window |
642 |
> |
// Create window (setting background_pixel, border_pixel and colormap is |
643 |
> |
// mandatory when using a non-default visual; in 1-bit mode we use the |
644 |
> |
// default visual, so we can also use the default colormap) |
645 |
|
XSetWindowAttributes wattr; |
646 |
|
wattr.event_mask = eventmask = win_eventmask; |
647 |
< |
wattr.background_pixel = black_pixel; |
648 |
< |
wattr.colormap = (mode.depth == VDEPTH_1BIT && color_class == PseudoColor ? DefaultColormap(x_display, screen) : cmap[0]); |
647 |
> |
wattr.background_pixel = (vis == DefaultVisual(x_display, screen) ? black_pixel : 0); |
648 |
> |
wattr.border_pixel = 0; |
649 |
> |
wattr.colormap = (mode.depth == VDEPTH_1BIT ? DefaultColormap(x_display, screen) : cmap[0]); |
650 |
|
w = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
651 |
< |
InputOutput, vis, CWEventMask | CWBackPixel | (color_class == PseudoColor || color_class == DirectColor ? CWColormap : 0), &wattr); |
651 |
> |
InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | CWColormap, &wattr); |
652 |
> |
D(bug(" window created\n")); |
653 |
|
|
654 |
|
// Set window name/class |
655 |
|
set_window_name(w, STR_WINDOW_TITLE); |
673 |
|
XFree(hints); |
674 |
|
} |
675 |
|
} |
676 |
+ |
D(bug(" window attributes set\n")); |
677 |
|
|
678 |
|
// Show window |
679 |
|
XMapWindow(x_display, w); |
680 |
|
wait_mapped(w); |
681 |
+ |
D(bug(" window mapped\n")); |
682 |
|
|
683 |
|
// 1-bit mode is big-endian; if the X server is little-endian, we can't |
684 |
|
// use SHM because that doesn't allow changing the image byte order |
689 |
|
|
690 |
|
// Create SHM image ("height + 2" for safety) |
691 |
|
img = XShmCreateImage(x_display, vis, mode.depth == VDEPTH_1BIT ? 1 : xdepth, mode.depth == VDEPTH_1BIT ? XYBitmap : ZPixmap, 0, &shminfo, width, height); |
692 |
+ |
D(bug(" shm image created\n")); |
693 |
|
shminfo.shmid = shmget(IPC_PRIVATE, (aligned_height + 2) * img->bytes_per_line, IPC_CREAT | 0777); |
694 |
|
the_buffer_copy = (uint8 *)shmat(shminfo.shmid, 0, 0); |
695 |
|
shminfo.shmaddr = img->data = (char *)the_buffer_copy; |
710 |
|
have_shm = true; |
711 |
|
shmctl(shminfo.shmid, IPC_RMID, 0); |
712 |
|
} |
713 |
+ |
D(bug(" shm image attached\n")); |
714 |
|
} |
715 |
|
|
716 |
|
// Create normal X image if SHM doesn't work ("height + 2" for safety) |
718 |
|
int bytes_per_row = (mode.depth == VDEPTH_1BIT ? aligned_width/8 : TrivialBytesPerRow(aligned_width, DepthModeForPixelDepth(xdepth))); |
719 |
|
the_buffer_copy = (uint8 *)malloc((aligned_height + 2) * bytes_per_row); |
720 |
|
img = XCreateImage(x_display, vis, mode.depth == VDEPTH_1BIT ? 1 : xdepth, mode.depth == VDEPTH_1BIT ? XYBitmap : ZPixmap, 0, (char *)the_buffer_copy, aligned_width, aligned_height, 32, bytes_per_row); |
721 |
+ |
D(bug(" X image created\n")); |
722 |
|
} |
723 |
|
|
724 |
|
if (need_msb_image) { |
731 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
732 |
|
the_host_buffer = the_buffer_copy; |
733 |
|
the_buffer_size = page_extend((aligned_height + 2) * img->bytes_per_line); |
734 |
< |
the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size); |
735 |
< |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
734 |
> |
the_buffer = (uint8 *)vm_acquire_mac(the_buffer_size); |
735 |
> |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
736 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
737 |
|
#else |
738 |
|
// Allocate memory for frame buffer |
759 |
|
native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
760 |
|
#endif |
761 |
|
#ifdef ENABLE_VOSF |
762 |
< |
Screen_blitter_init(&visualInfo, native_byte_order, mode.depth); |
762 |
> |
Screen_blitter_init(visualFormat, native_byte_order, depth_of_video_mode(mode)); |
763 |
|
#endif |
764 |
|
|
765 |
< |
// Set VideoMonitor |
766 |
< |
VideoMonitor.mode = mode; |
670 |
< |
set_mac_frame_buffer(mode.depth, native_byte_order); |
765 |
> |
// Set frame buffer base |
766 |
> |
set_mac_frame_buffer(monitor, mode.depth, native_byte_order); |
767 |
|
|
768 |
|
// Everything went well |
769 |
|
init_ok = true; |
780 |
|
the_buffer_copy = NULL; // don't free() in driver_base dtor |
781 |
|
#endif |
782 |
|
} |
783 |
< |
#ifdef ENABLE_VOSF |
784 |
< |
if (use_vosf) { |
785 |
< |
// don't free() memory mapped buffers in driver_base dtor |
690 |
< |
if (the_buffer != VM_MAP_FAILED) { |
691 |
< |
vm_release(the_buffer, the_buffer_size); |
692 |
< |
the_buffer = NULL; |
693 |
< |
} |
694 |
< |
if (the_buffer_copy != VM_MAP_FAILED) { |
695 |
< |
vm_release(the_buffer_copy, the_buffer_size); |
696 |
< |
the_buffer_copy = NULL; |
697 |
< |
} |
698 |
< |
} |
699 |
< |
#endif |
700 |
< |
if (img) |
783 |
> |
if (img) { |
784 |
> |
if (!have_shm) |
785 |
> |
img->data = NULL; |
786 |
|
XDestroyImage(img); |
787 |
+ |
} |
788 |
|
if (have_shm) { |
789 |
|
shmdt(shminfo.shmaddr); |
790 |
|
shmctl(shminfo.shmid, IPC_RMID, 0); |
814 |
|
Delay_usec(100000); |
815 |
|
} |
816 |
|
if (result == GrabSuccess) { |
731 |
– |
ADBSetRelMouseMode(mouse_grabbed = true); |
817 |
|
XStoreName(x_display, w, GetString(STR_WINDOW_TITLE_GRABBED)); |
818 |
< |
XSync(x_display, false); |
818 |
> |
ADBSetRelMouseMode(mouse_grabbed = true); |
819 |
> |
disable_mouse_accel(); |
820 |
|
} |
821 |
|
} |
822 |
|
|
827 |
|
XUngrabPointer(x_display, CurrentTime); |
828 |
|
XStoreName(x_display, w, GetString(STR_WINDOW_TITLE)); |
829 |
|
ADBSetRelMouseMode(mouse_grabbed = false); |
830 |
+ |
restore_mouse_accel(); |
831 |
|
} |
832 |
|
} |
833 |
|
|
843 |
|
// Warped mouse motion (this code is taken from SDL) |
844 |
|
|
845 |
|
// Post first mouse event |
846 |
< |
int width = VideoMonitor.mode.x, height = VideoMonitor.mode.y; |
846 |
> |
int width = monitor.get_current_mode().x, height = monitor.get_current_mode().y; |
847 |
|
int delta_x = x - mouse_last_x, delta_y = y - mouse_last_y; |
848 |
|
mouse_last_x = x; mouse_last_y = y; |
849 |
|
ADBMouseMoved(delta_x, delta_y); |
880 |
|
|
881 |
|
class driver_dga : public driver_base { |
882 |
|
public: |
883 |
< |
driver_dga(); |
883 |
> |
driver_dga(X11_monitor_desc &monitor); |
884 |
|
~driver_dga(); |
885 |
|
|
886 |
|
void suspend(void); |
891 |
|
void *fb_save; // Saved frame buffer for suspend/resume |
892 |
|
}; |
893 |
|
|
894 |
< |
driver_dga::driver_dga() |
895 |
< |
: suspend_win(0), fb_save(NULL) |
894 |
> |
driver_dga::driver_dga(X11_monitor_desc &m) |
895 |
> |
: driver_base(m), suspend_win(0), fb_save(NULL) |
896 |
|
{ |
897 |
|
} |
898 |
|
|
913 |
|
LOCK_FRAME_BUFFER; |
914 |
|
|
915 |
|
// Save frame buffer |
916 |
< |
fb_save = malloc(VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
916 |
> |
fb_save = malloc(mode.y * mode.bytes_per_row); |
917 |
|
if (fb_save) |
918 |
< |
memcpy(fb_save, the_buffer, VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
918 |
> |
memcpy(fb_save, the_buffer, mode.y * mode.bytes_per_row); |
919 |
|
|
920 |
|
// Close full screen display |
921 |
|
#ifdef ENABLE_XF86_DGA |
923 |
|
#endif |
924 |
|
XUngrabPointer(x_display, CurrentTime); |
925 |
|
XUngrabKeyboard(x_display, CurrentTime); |
926 |
+ |
restore_mouse_accel(); |
927 |
|
XUnmapWindow(x_display, w); |
928 |
|
wait_unmapped(w); |
929 |
|
|
953 |
|
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
954 |
|
XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
955 |
|
XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
956 |
+ |
disable_mouse_accel(); |
957 |
|
#ifdef ENABLE_XF86_DGA |
958 |
|
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
959 |
|
XF86DGASetViewPort(x_display, screen, 0, 0); |
968 |
|
LOCK_VOSF; |
969 |
|
PFLAG_SET_ALL; |
970 |
|
UNLOCK_VOSF; |
971 |
< |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
971 |
> |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
972 |
|
} |
973 |
|
#endif |
974 |
|
|
978 |
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
979 |
|
if (!use_vosf) |
980 |
|
#endif |
981 |
< |
memcpy(the_buffer, fb_save, VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
981 |
> |
memcpy(the_buffer, fb_save, mode.y * mode.bytes_per_row); |
982 |
|
free(fb_save); |
983 |
|
fb_save = NULL; |
984 |
|
} |
1000 |
|
|
1001 |
|
class driver_fbdev : public driver_dga { |
1002 |
|
public: |
1003 |
< |
driver_fbdev(const video_mode &mode); |
1003 |
> |
driver_fbdev(X11_monitor_desc &monitor); |
1004 |
|
~driver_fbdev(); |
1005 |
|
}; |
1006 |
|
|
1007 |
|
// Open display |
1008 |
< |
driver_fbdev::driver_fbdev(const video_mode &mode) |
1008 |
> |
driver_fbdev::driver_fbdev(X11_monitor_desc &m) : driver_dga(m) |
1009 |
|
{ |
1010 |
|
int width = mode.x, height = mode.y; |
1011 |
|
|
1053 |
|
if ((line[0] == '#') || (line[0] == ';') || (line[0] == '\0')) |
1054 |
|
continue; |
1055 |
|
|
1056 |
< |
if ((sscanf(line, "%19s %d %x", &fb_name, &fb_depth, &fb_offset) == 3) |
1056 |
> |
if ((sscanf(line, "%19s %d %x", fb_name, &fb_depth, &fb_offset) == 3) |
1057 |
|
&& (strcmp(fb_name, fb_name) == 0) && (fb_depth == max_depth)) { |
1058 |
|
device_found = true; |
1059 |
|
break; |
1100 |
|
XGrabPointer(x_display, w, True, |
1101 |
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask, |
1102 |
|
GrabModeAsync, GrabModeAsync, w, None, CurrentTime); |
1103 |
+ |
disable_mouse_accel(); |
1104 |
|
|
1105 |
|
// Calculate bytes per row |
1106 |
|
int bytes_per_row = TrivialBytesPerRow(mode.x, mode.depth); |
1120 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
1121 |
|
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
1122 |
|
// i.e. the framebuffer update function is not Blit_Copy_Raw |
1123 |
< |
use_vosf = Screen_blitter_init(&visualInfo, true, mode.depth); |
1123 |
> |
use_vosf = Screen_blitter_init(visualFormat, true, mode.depth); |
1124 |
|
|
1125 |
|
if (use_vosf) { |
1126 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
1127 |
|
the_host_buffer = the_buffer; |
1128 |
|
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
1129 |
< |
the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size); |
1130 |
< |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
1129 |
> |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
1130 |
> |
the_buffer = (uint8 *)vm_acquire_mac(the_buffer_size); |
1131 |
|
} |
1132 |
|
#else |
1133 |
|
use_vosf = false; |
1134 |
|
#endif |
1135 |
|
#endif |
1136 |
|
|
1137 |
< |
// Set VideoMonitor |
1138 |
< |
VideoModes[0].bytes_per_row = bytes_per_row; |
1139 |
< |
VideoModes[0].depth = DepthModeForPixelDepth(fb_depth); |
1140 |
< |
VideoMonitor.mode = mode; |
1051 |
< |
set_mac_frame_buffer(mode.depth, true); |
1137 |
> |
// Set frame buffer base |
1138 |
> |
const_cast<video_mode *>(&mode)->bytes_per_row = bytes_per_row; |
1139 |
> |
const_cast<video_mode *>(&mode)->depth = DepthModeForPixelDepth(fb_depth); |
1140 |
> |
set_mac_frame_buffer(monitor, mode.depth, true); |
1141 |
|
|
1142 |
|
// Everything went well |
1143 |
|
init_ok = true; |
1160 |
|
munmap(the_host_buffer, the_buffer_size); |
1161 |
|
the_host_buffer = NULL; |
1162 |
|
} |
1074 |
– |
if (the_buffer_copy != VM_MAP_FAILED) { |
1075 |
– |
vm_release(the_buffer_copy, the_buffer_size); |
1076 |
– |
the_buffer_copy = NULL; |
1077 |
– |
} |
1078 |
– |
if (the_buffer != VM_MAP_FAILED) { |
1079 |
– |
vm_release(the_buffer, the_buffer_size); |
1080 |
– |
the_buffer = NULL; |
1081 |
– |
} |
1163 |
|
} |
1164 |
|
#endif |
1165 |
|
} |
1173 |
|
|
1174 |
|
class driver_xf86dga : public driver_dga { |
1175 |
|
public: |
1176 |
< |
driver_xf86dga(const video_mode &mode); |
1176 |
> |
driver_xf86dga(X11_monitor_desc &monitor); |
1177 |
|
~driver_xf86dga(); |
1178 |
|
|
1179 |
|
void update_palette(void); |
1184 |
|
}; |
1185 |
|
|
1186 |
|
// Open display |
1187 |
< |
driver_xf86dga::driver_xf86dga(const video_mode &mode) |
1188 |
< |
: current_dga_cmap(0) |
1187 |
> |
driver_xf86dga::driver_xf86dga(X11_monitor_desc &m) |
1188 |
> |
: driver_dga(m), current_dga_cmap(0) |
1189 |
|
{ |
1190 |
|
int width = mode.x, height = mode.y; |
1191 |
|
|
1212 |
|
XSetWindowAttributes wattr; |
1213 |
|
wattr.event_mask = eventmask = dga_eventmask; |
1214 |
|
wattr.override_redirect = True; |
1215 |
+ |
wattr.colormap = (mode.depth == VDEPTH_1BIT ? DefaultColormap(x_display, screen) : cmap[0]); |
1216 |
|
|
1217 |
|
w = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
1218 |
< |
InputOutput, vis, CWEventMask | CWOverrideRedirect, &wattr); |
1218 |
> |
InputOutput, vis, CWEventMask | CWOverrideRedirect | |
1219 |
> |
(color_class == DirectColor ? CWColormap : 0), &wattr); |
1220 |
|
|
1221 |
|
// Set window name/class |
1222 |
|
set_window_name(w, STR_WINDOW_TITLE); |
1233 |
|
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
1234 |
|
XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
1235 |
|
XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
1236 |
+ |
disable_mouse_accel(); |
1237 |
|
|
1238 |
|
int v_width, v_bank, v_size; |
1239 |
|
XF86DGAGetVideo(x_display, screen, (char **)&the_buffer, &v_width, &v_bank, &v_size); |
1250 |
|
|
1251 |
|
// Init blitting routines |
1252 |
|
int bytes_per_row = TrivialBytesPerRow((v_width + 7) & ~7, mode.depth); |
1253 |
< |
#if VIDEO_VOSF |
1253 |
> |
#if ENABLE_VOSF |
1254 |
> |
bool native_byte_order; |
1255 |
> |
#ifdef WORDS_BIGENDIAN |
1256 |
> |
native_byte_order = (XImageByteOrder(x_display) == MSBFirst); |
1257 |
> |
#else |
1258 |
> |
native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
1259 |
> |
#endif |
1260 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
1261 |
|
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
1262 |
|
// i.e. the framebuffer update function is not Blit_Copy_Raw |
1263 |
< |
use_vosf = Screen_blitter_init(&visualInfo, true, mode.depth); |
1263 |
> |
use_vosf = Screen_blitter_init(visualFormat, native_byte_order, depth_of_video_mode(mode)); |
1264 |
|
|
1265 |
|
if (use_vosf) { |
1266 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
1267 |
|
the_host_buffer = the_buffer; |
1268 |
|
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
1269 |
< |
the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size); |
1270 |
< |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
1269 |
> |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
1270 |
> |
the_buffer = (uint8 *)vm_acquire_mac(the_buffer_size); |
1271 |
|
} |
1272 |
|
#else |
1273 |
|
use_vosf = false; |
1274 |
|
#endif |
1275 |
|
#endif |
1276 |
|
|
1277 |
< |
// Set VideoMonitor |
1277 |
> |
// Set frame buffer base |
1278 |
|
const_cast<video_mode *>(&mode)->bytes_per_row = bytes_per_row; |
1279 |
< |
VideoMonitor.mode = mode; |
1190 |
< |
set_mac_frame_buffer(mode.depth, true); |
1279 |
> |
set_mac_frame_buffer(monitor, mode.depth, true); |
1280 |
|
|
1281 |
|
// Everything went well |
1282 |
|
init_ok = true; |
1294 |
|
else { |
1295 |
|
// don't free() the screen buffer in driver_base dtor |
1296 |
|
the_host_buffer = NULL; |
1208 |
– |
|
1209 |
– |
if (the_buffer_copy != VM_MAP_FAILED) { |
1210 |
– |
vm_release(the_buffer_copy, the_buffer_size); |
1211 |
– |
the_buffer_copy = NULL; |
1212 |
– |
} |
1213 |
– |
if (the_buffer != VM_MAP_FAILED) { |
1214 |
– |
vm_release(the_buffer, the_buffer_size); |
1215 |
– |
the_buffer = NULL; |
1216 |
– |
} |
1297 |
|
} |
1298 |
|
#endif |
1299 |
|
#ifdef ENABLE_XF86_VIDMODE |
1307 |
|
{ |
1308 |
|
driver_dga::update_palette(); |
1309 |
|
current_dga_cmap ^= 1; |
1310 |
< |
if (!IsDirectMode(VideoMonitor.mode) && cmap[current_dga_cmap]) |
1310 |
> |
if (!IsDirectMode(monitor.get_current_mode()) && cmap[current_dga_cmap]) |
1311 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1312 |
|
} |
1313 |
|
|
1315 |
|
void driver_xf86dga::resume(void) |
1316 |
|
{ |
1317 |
|
driver_dga::resume(); |
1318 |
< |
if (!IsDirectMode(VideoMonitor.mode)) |
1318 |
> |
if (!IsDirectMode(monitor.get_current_mode())) |
1319 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1320 |
|
} |
1321 |
|
#endif |
1390 |
|
} |
1391 |
|
} |
1392 |
|
|
1393 |
< |
// Open display for specified mode |
1394 |
< |
static bool video_open(const video_mode &mode) |
1393 |
> |
// Open display for current mode |
1394 |
> |
bool X11_monitor_desc::video_open(void) |
1395 |
|
{ |
1396 |
+ |
D(bug("video_open()\n")); |
1397 |
+ |
const video_mode &mode = get_current_mode(); |
1398 |
+ |
|
1399 |
|
// Find best available X visual |
1400 |
|
if (!find_visual_for_depth(mode.depth)) { |
1401 |
|
ErrorAlert(STR_NO_XVISUAL_ERR); |
1402 |
|
return false; |
1403 |
|
} |
1404 |
|
|
1405 |
+ |
// Build up visualFormat structure |
1406 |
+ |
visualFormat.depth = visualInfo.depth; |
1407 |
+ |
visualFormat.Rmask = visualInfo.red_mask; |
1408 |
+ |
visualFormat.Gmask = visualInfo.green_mask; |
1409 |
+ |
visualFormat.Bmask = visualInfo.blue_mask; |
1410 |
+ |
|
1411 |
|
// Create color maps |
1412 |
|
if (color_class == PseudoColor || color_class == DirectColor) { |
1413 |
|
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1414 |
|
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll); |
1415 |
+ |
} else { |
1416 |
+ |
cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocNone); |
1417 |
+ |
cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocNone); |
1418 |
|
} |
1419 |
|
|
1420 |
|
// Find pixel format of direct modes |
1436 |
|
--bloss; |
1437 |
|
} |
1438 |
|
|
1439 |
< |
// Preset palette pixel values for gamma table |
1439 |
> |
// Preset palette pixel values for CLUT or gamma table |
1440 |
|
if (color_class == DirectColor) { |
1441 |
|
int num = vis->map_entries; |
1442 |
|
for (int i=0; i<num; i++) { |
1443 |
|
int c = (i * 256) / num; |
1444 |
< |
palette[i].pixel = map_rgb(c, c, c); |
1444 |
> |
x_palette[i].pixel = map_rgb(c, c, c); |
1445 |
> |
x_palette[i].flags = DoRed | DoGreen | DoBlue; |
1446 |
> |
} |
1447 |
> |
} else if (color_class == PseudoColor) { |
1448 |
> |
for (int i=0; i<256; i++) { |
1449 |
> |
x_palette[i].pixel = i; |
1450 |
> |
x_palette[i].flags = DoRed | DoGreen | DoBlue; |
1451 |
|
} |
1452 |
|
} |
1453 |
|
|
1455 |
|
int num = (color_class == DirectColor ? vis->map_entries : 256); |
1456 |
|
for (int i=0; i<num; i++) { |
1457 |
|
int c = (i * 256) / num; |
1458 |
< |
palette[i].red = c * 0x0101; |
1459 |
< |
palette[i].green = c * 0x0101; |
1460 |
< |
palette[i].blue = c * 0x0101; |
1461 |
< |
if (color_class == PseudoColor) |
1462 |
< |
palette[i].pixel = i; |
1463 |
< |
palette[i].flags = DoRed | DoGreen | DoBlue; |
1464 |
< |
} |
1367 |
< |
if (cmap[0] && cmap[1]) { |
1368 |
< |
XStoreColors(x_display, cmap[0], palette, num); |
1369 |
< |
XStoreColors(x_display, cmap[1], palette, num); |
1458 |
> |
x_palette[i].red = c * 0x0101; |
1459 |
> |
x_palette[i].green = c * 0x0101; |
1460 |
> |
x_palette[i].blue = c * 0x0101; |
1461 |
> |
} |
1462 |
> |
if (color_class == PseudoColor || color_class == DirectColor) { |
1463 |
> |
XStoreColors(x_display, cmap[0], x_palette, num); |
1464 |
> |
XStoreColors(x_display, cmap[1], x_palette, num); |
1465 |
|
} |
1466 |
|
|
1467 |
|
#ifdef ENABLE_VOSF |
1468 |
|
// Load gray ramp to 8->16/32 expand map |
1469 |
< |
if (!IsDirectMode(mode) && (color_class == TrueColor || color_class == DirectColor)) |
1469 |
> |
if (!IsDirectMode(mode) && xdepth > 8) |
1470 |
|
for (int i=0; i<256; i++) |
1471 |
|
ExpandMap[i] = map_rgb(i, i, i); |
1472 |
|
#endif |
1474 |
|
// Create display driver object of requested type |
1475 |
|
switch (display_type) { |
1476 |
|
case DISPLAY_WINDOW: |
1477 |
< |
drv = new driver_window(mode); |
1477 |
> |
drv = new driver_window(*this); |
1478 |
|
break; |
1479 |
|
#ifdef ENABLE_FBDEV_DGA |
1480 |
|
case DISPLAY_DGA: |
1481 |
< |
drv = new driver_fbdev(mode); |
1481 |
> |
drv = new driver_fbdev(*this); |
1482 |
|
break; |
1483 |
|
#endif |
1484 |
|
#ifdef ENABLE_XF86_DGA |
1485 |
|
case DISPLAY_DGA: |
1486 |
< |
drv = new driver_xf86dga(mode); |
1486 |
> |
drv = new driver_xf86dga(*this); |
1487 |
|
break; |
1488 |
|
#endif |
1489 |
|
} |
1498 |
|
#ifdef ENABLE_VOSF |
1499 |
|
if (use_vosf) { |
1500 |
|
// Initialize the VOSF system |
1501 |
< |
if (!video_vosf_init()) { |
1501 |
> |
if (!video_vosf_init(*this)) { |
1502 |
|
ErrorAlert(STR_VOSF_INIT_ERR); |
1503 |
|
return false; |
1504 |
|
} |
1515 |
|
// Start redraw/input thread |
1516 |
|
#ifdef HAVE_PTHREADS |
1517 |
|
redraw_thread_cancel = false; |
1518 |
< |
redraw_thread_active = (pthread_create(&redraw_thread, NULL, redraw_func, NULL) == 0); |
1518 |
> |
Set_pthread_attr(&redraw_thread_attr, 0); |
1519 |
> |
redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0); |
1520 |
|
if (!redraw_thread_active) { |
1521 |
|
printf("FATAL: cannot create redraw thread\n"); |
1522 |
|
return false; |
1560 |
|
ErrorAlert(STR_UNSUPP_DEPTH_ERR); |
1561 |
|
return false; |
1562 |
|
} |
1563 |
< |
sort(avail_depths, avail_depths + num_depths); |
1563 |
> |
std::sort(avail_depths, avail_depths + num_depths); |
1564 |
|
|
1565 |
|
#ifdef ENABLE_FBDEV_DGA |
1566 |
|
// Frame buffer name |
1663 |
|
ErrorAlert(STR_NO_XVISUAL_ERR); |
1664 |
|
return false; |
1665 |
|
} |
1666 |
< |
video_init_depth_list(); |
1666 |
> |
|
1667 |
> |
// Find requested default mode with specified dimensions |
1668 |
> |
uint32 default_id; |
1669 |
> |
std::vector<video_mode>::const_iterator i, end = VideoModes.end(); |
1670 |
> |
for (i = VideoModes.begin(); i != end; ++i) { |
1671 |
> |
if (i->x == default_width && i->y == default_height && i->depth == default_depth) { |
1672 |
> |
default_id = i->resolution_id; |
1673 |
> |
break; |
1674 |
> |
} |
1675 |
> |
} |
1676 |
> |
if (i == end) { // not found, use first available mode |
1677 |
> |
default_depth = VideoModes[0].depth; |
1678 |
> |
default_id = VideoModes[0].resolution_id; |
1679 |
> |
} |
1680 |
|
|
1681 |
|
#if DEBUG |
1682 |
|
D(bug("Available video modes:\n")); |
1683 |
< |
vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end(); |
1575 |
< |
while (i != end) { |
1683 |
> |
for (i = VideoModes.begin(); i != end; ++i) { |
1684 |
|
int bits = 1 << i->depth; |
1685 |
|
if (bits == 16) |
1686 |
|
bits = 15; |
1687 |
|
else if (bits == 32) |
1688 |
|
bits = 24; |
1689 |
|
D(bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits)); |
1582 |
– |
++i; |
1690 |
|
} |
1691 |
|
#endif |
1692 |
|
|
1693 |
< |
// Find requested default mode and open display |
1694 |
< |
if (VideoModes.size() == 1) |
1695 |
< |
return video_open(VideoModes[0]); |
1696 |
< |
else { |
1697 |
< |
// Find mode with specified dimensions |
1698 |
< |
std::vector<video_mode>::const_iterator i, end = VideoModes.end(); |
1592 |
< |
for (i = VideoModes.begin(); i != end; ++i) { |
1593 |
< |
if (i->x == default_width && i->y == default_height && i->depth == default_depth) |
1594 |
< |
return video_open(*i); |
1595 |
< |
} |
1596 |
< |
return video_open(VideoModes[0]); |
1597 |
< |
} |
1693 |
> |
// Create X11_monitor_desc for this (the only) display |
1694 |
> |
X11_monitor_desc *monitor = new X11_monitor_desc(VideoModes, default_depth, default_id); |
1695 |
> |
VideoMonitors.push_back(monitor); |
1696 |
> |
|
1697 |
> |
// Open display |
1698 |
> |
return monitor->video_open(); |
1699 |
|
} |
1700 |
|
|
1701 |
|
|
1704 |
|
*/ |
1705 |
|
|
1706 |
|
// Close display |
1707 |
< |
static void video_close(void) |
1707 |
> |
void X11_monitor_desc::video_close(void) |
1708 |
|
{ |
1709 |
+ |
D(bug("video_close()\n")); |
1710 |
+ |
|
1711 |
|
// Stop redraw thread |
1712 |
|
#ifdef HAVE_PTHREADS |
1713 |
|
if (redraw_thread_active) { |
1723 |
|
// Unlock frame buffer |
1724 |
|
UNLOCK_FRAME_BUFFER; |
1725 |
|
XSync(x_display, false); |
1726 |
+ |
D(bug(" frame buffer unlocked\n")); |
1727 |
|
|
1728 |
|
#ifdef ENABLE_VOSF |
1729 |
|
if (use_vosf) { |
1749 |
|
|
1750 |
|
void VideoExit(void) |
1751 |
|
{ |
1752 |
< |
// Close display |
1753 |
< |
video_close(); |
1752 |
> |
// Close displays |
1753 |
> |
vector<monitor_desc *>::iterator i, end = VideoMonitors.end(); |
1754 |
> |
for (i = VideoMonitors.begin(); i != end; ++i) |
1755 |
> |
dynamic_cast<X11_monitor_desc *>(*i)->video_close(); |
1756 |
|
|
1757 |
|
#ifdef ENABLE_XF86_VIDMODE |
1758 |
|
// Free video mode list |
1810 |
|
* Set palette |
1811 |
|
*/ |
1812 |
|
|
1813 |
< |
void video_set_palette(uint8 *pal, int num_in) |
1813 |
> |
void X11_monitor_desc::set_palette(uint8 *pal, int num_in) |
1814 |
|
{ |
1815 |
+ |
const video_mode &mode = get_current_mode(); |
1816 |
+ |
|
1817 |
|
LOCK_PALETTE; |
1818 |
|
|
1819 |
|
// Convert colors to XColor array |
1820 |
|
int num_out = 256; |
1821 |
|
bool stretch = false; |
1822 |
< |
if (IsDirectMode(VideoMonitor.mode)) { |
1822 |
> |
if (IsDirectMode(mode)) { |
1823 |
|
// If X is in 565 mode we have to stretch the gamma table from 32 to 64 entries |
1824 |
|
num_out = vis->map_entries; |
1825 |
|
stretch = true; |
1826 |
|
} |
1827 |
< |
XColor *p = palette; |
1827 |
> |
XColor *p = x_palette; |
1828 |
|
for (int i=0; i<num_out; i++) { |
1829 |
|
int c = (stretch ? (i * num_in) / num_out : i); |
1830 |
|
p->red = pal[c*3 + 0] * 0x0101; |
1831 |
|
p->green = pal[c*3 + 1] * 0x0101; |
1832 |
|
p->blue = pal[c*3 + 2] * 0x0101; |
1725 |
– |
if (color_class == PseudoColor) |
1726 |
– |
p->pixel = i; |
1727 |
– |
p->flags = DoRed | DoGreen | DoBlue; |
1833 |
|
p++; |
1834 |
|
} |
1835 |
|
|
1836 |
|
#ifdef ENABLE_VOSF |
1837 |
|
// Recalculate pixel color expansion map |
1838 |
< |
if (!IsDirectMode(VideoMonitor.mode) && (color_class == TrueColor || color_class == DirectColor)) { |
1838 |
> |
if (!IsDirectMode(mode) && xdepth > 8) { |
1839 |
|
for (int i=0; i<256; i++) { |
1840 |
|
int c = i & (num_in-1); // If there are less than 256 colors, we repeat the first entries (this makes color expansion easier) |
1841 |
|
ExpandMap[i] = map_rgb(pal[c*3+0], pal[c*3+1], pal[c*3+2]); |
1845 |
|
LOCK_VOSF; |
1846 |
|
PFLAG_SET_ALL; |
1847 |
|
UNLOCK_VOSF; |
1848 |
< |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
1848 |
> |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1849 |
|
} |
1850 |
|
#endif |
1851 |
|
|
1852 |
|
// Tell redraw thread to change palette |
1853 |
< |
palette_changed = true; |
1853 |
> |
x_palette_changed = true; |
1854 |
|
|
1855 |
|
UNLOCK_PALETTE; |
1856 |
|
} |
1860 |
|
* Switch video mode |
1861 |
|
*/ |
1862 |
|
|
1863 |
< |
void video_switch_to_mode(const video_mode &mode) |
1863 |
> |
void X11_monitor_desc::switch_to_current_mode(void) |
1864 |
|
{ |
1865 |
|
// Close and reopen display |
1866 |
|
video_close(); |
1867 |
< |
video_open(mode); |
1867 |
> |
video_open(); |
1868 |
|
|
1869 |
|
if (drv == NULL) { |
1870 |
|
ErrorAlert(STR_OPEN_WINDOW_ERR); |
2048 |
|
XNextEvent(x_display, &event); |
2049 |
|
|
2050 |
|
switch (event.type) { |
2051 |
+ |
|
2052 |
|
// Mouse button |
2053 |
|
case ButtonPress: { |
2054 |
|
unsigned int button = event.xbutton.button; |
2081 |
|
drv->mouse_moved(event.xmotion.x, event.xmotion.y); |
2082 |
|
break; |
2083 |
|
|
2084 |
+ |
// Mouse entered window |
2085 |
+ |
case EnterNotify: |
2086 |
+ |
if (event.xcrossing.mode != NotifyGrab && event.xcrossing.mode != NotifyUngrab) |
2087 |
+ |
drv->mouse_moved(event.xmotion.x, event.xmotion.y); |
2088 |
+ |
break; |
2089 |
+ |
|
2090 |
|
// Keyboard |
2091 |
|
case KeyPress: { |
2092 |
|
int code = -1; |
2134 |
|
// Hidden parts exposed, force complete refresh of window |
2135 |
|
case Expose: |
2136 |
|
if (display_type == DISPLAY_WINDOW) { |
2137 |
+ |
const video_mode &mode = VideoMonitors[0]->get_current_mode(); |
2138 |
|
#ifdef ENABLE_VOSF |
2139 |
|
if (use_vosf) { // VOSF refresh |
2140 |
|
LOCK_VOSF; |
2141 |
|
PFLAG_SET_ALL; |
2142 |
|
UNLOCK_VOSF; |
2143 |
< |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
2143 |
> |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
2144 |
|
} |
2145 |
|
else |
2146 |
|
#endif |
2151 |
|
updt_box[x1][y1] = true; |
2152 |
|
nr_boxes = 16 * 16; |
2153 |
|
} else // Static refresh |
2154 |
< |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
2154 |
> |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
2155 |
|
} |
2156 |
|
break; |
2157 |
|
|
2177 |
|
int y1, y2, y2s, y2a, i, x1, xm, xmo, ymo, yo, yi, yil, xi; |
2178 |
|
int xil = 0; |
2179 |
|
int rxm = 0, rxmo = 0; |
2180 |
< |
int bytes_per_row = VideoMonitor.mode.bytes_per_row; |
2181 |
< |
int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; |
2182 |
< |
int rx = VideoMonitor.mode.bytes_per_row / 16; |
2183 |
< |
int ry = VideoMonitor.mode.y / 16; |
2180 |
> |
const video_mode &mode = drv->monitor.get_current_mode(); |
2181 |
> |
int bytes_per_row = mode.bytes_per_row; |
2182 |
> |
int bytes_per_pixel = mode.bytes_per_row / mode.x; |
2183 |
> |
int rx = mode.bytes_per_row / 16; |
2184 |
> |
int ry = mode.y / 16; |
2185 |
|
int max_box; |
2186 |
|
|
2187 |
|
y2s = sm_uptd[ticker % 8]; |
2235 |
|
i = (yi * bytes_per_row) + xi; |
2236 |
|
for (y2=0; y2 < yil; y2++, i += bytes_per_row) |
2237 |
|
memcpy(&the_buffer_copy[i], &the_buffer[i], xil); |
2238 |
< |
if (VideoMonitor.mode.depth == VDEPTH_1BIT) { |
2238 |
> |
if (mode.depth == VDEPTH_1BIT) { |
2239 |
|
if (drv->have_shm) |
2240 |
|
XShmPutImage(x_display, drv->w, drv->gc, drv->img, xi * 8, yi, xi * 8, yi, xil * 8, yil, 0); |
2241 |
|
else |
2266 |
|
static void update_display_static(driver_window *drv) |
2267 |
|
{ |
2268 |
|
// Incremental update code |
2269 |
< |
int wide = 0, high = 0, x1, x2, y1, y2, i, j; |
2270 |
< |
int bytes_per_row = VideoMonitor.mode.bytes_per_row; |
2271 |
< |
int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; |
2269 |
> |
unsigned wide = 0, high = 0, x1, x2, y1, y2, i, j; |
2270 |
> |
const video_mode &mode = drv->monitor.get_current_mode(); |
2271 |
> |
int bytes_per_row = mode.bytes_per_row; |
2272 |
> |
int bytes_per_pixel = mode.bytes_per_row / mode.x; |
2273 |
|
uint8 *p, *p2; |
2274 |
|
|
2275 |
|
// Check for first line from top and first line from bottom that have changed |
2276 |
|
y1 = 0; |
2277 |
< |
for (j=0; j<VideoMonitor.mode.y; j++) { |
2277 |
> |
for (j=0; j<mode.y; j++) { |
2278 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
2279 |
|
y1 = j; |
2280 |
|
break; |
2281 |
|
} |
2282 |
|
} |
2283 |
|
y2 = y1 - 1; |
2284 |
< |
for (j=VideoMonitor.mode.y-1; j>=y1; j--) { |
2284 |
> |
for (j=mode.y-1; j>=y1; j--) { |
2285 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
2286 |
|
y2 = j; |
2287 |
|
break; |
2291 |
|
|
2292 |
|
// Check for first column from left and first column from right that have changed |
2293 |
|
if (high) { |
2294 |
< |
if (VideoMonitor.mode.depth == VDEPTH_1BIT) { |
2295 |
< |
x1 = VideoMonitor.mode.x - 1; |
2294 |
> |
if (mode.depth == VDEPTH_1BIT) { |
2295 |
> |
x1 = mode.x - 1; |
2296 |
|
for (j=y1; j<=y2; j++) { |
2297 |
|
p = &the_buffer[j * bytes_per_row]; |
2298 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
2310 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
2311 |
|
p += bytes_per_row; |
2312 |
|
p2 += bytes_per_row; |
2313 |
< |
for (i=(VideoMonitor.mode.x>>3); i>(x2>>3); i--) { |
2313 |
> |
for (i=(mode.x>>3); i>(x2>>3); i--) { |
2314 |
|
p--; p2--; |
2315 |
|
if (*p != *p2) { |
2316 |
|
x2 = (i << 3) + 7; |
2329 |
|
} |
2330 |
|
|
2331 |
|
} else { |
2332 |
< |
x1 = VideoMonitor.mode.x; |
2332 |
> |
x1 = mode.x; |
2333 |
|
for (j=y1; j<=y2; j++) { |
2334 |
|
p = &the_buffer[j * bytes_per_row]; |
2335 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
2347 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
2348 |
|
p += bytes_per_row; |
2349 |
|
p2 += bytes_per_row; |
2350 |
< |
for (i=VideoMonitor.mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
2350 |
> |
for (i=mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
2351 |
|
p--; |
2352 |
|
p2--; |
2353 |
|
if (*p != *p2) { |
2414 |
|
{ |
2415 |
|
LOCK_PALETTE; |
2416 |
|
|
2417 |
< |
if (palette_changed) { |
2418 |
< |
palette_changed = false; |
2417 |
> |
if (x_palette_changed) { |
2418 |
> |
x_palette_changed = false; |
2419 |
|
drv->update_palette(); |
2420 |
|
} |
2421 |
|
|
2426 |
|
{ |
2427 |
|
// Quit DGA mode if requested |
2428 |
|
possibly_quit_dga_mode(); |
2314 |
– |
|
2315 |
– |
// Handle X events |
2316 |
– |
handle_events(); |
2317 |
– |
|
2318 |
– |
// Handle palette changes |
2319 |
– |
handle_palette_changes(); |
2429 |
|
} |
2430 |
|
|
2431 |
|
#ifdef ENABLE_VOSF |
2435 |
|
// Quit DGA mode if requested |
2436 |
|
possibly_quit_dga_mode(); |
2437 |
|
|
2329 |
– |
// Handle X events |
2330 |
– |
handle_events(); |
2331 |
– |
|
2332 |
– |
// Handle palette changes |
2333 |
– |
handle_palette_changes(); |
2334 |
– |
|
2438 |
|
// Update display (VOSF variant) |
2439 |
|
static int tick_counter = 0; |
2440 |
|
if (++tick_counter >= frame_skip) { |
2453 |
|
// Ungrab mouse if requested |
2454 |
|
possibly_ungrab_mouse(); |
2455 |
|
|
2353 |
– |
// Handle X events |
2354 |
– |
handle_events(); |
2355 |
– |
|
2356 |
– |
// Handle palette changes |
2357 |
– |
handle_palette_changes(); |
2358 |
– |
|
2456 |
|
// Update display (VOSF variant) |
2457 |
|
static int tick_counter = 0; |
2458 |
|
if (++tick_counter >= frame_skip) { |
2472 |
|
// Ungrab mouse if requested |
2473 |
|
possibly_ungrab_mouse(); |
2474 |
|
|
2378 |
– |
// Handle X events |
2379 |
– |
handle_events(); |
2380 |
– |
|
2381 |
– |
// Handle_palette changes |
2382 |
– |
handle_palette_changes(); |
2383 |
– |
|
2475 |
|
// Update display (static variant) |
2476 |
|
static int tick_counter = 0; |
2477 |
|
if (++tick_counter >= frame_skip) { |
2485 |
|
// Ungrab mouse if requested |
2486 |
|
possibly_ungrab_mouse(); |
2487 |
|
|
2397 |
– |
// Handle X events |
2398 |
– |
handle_events(); |
2399 |
– |
|
2400 |
– |
// Handle_palette changes |
2401 |
– |
handle_palette_changes(); |
2402 |
– |
|
2488 |
|
// Update display (dynamic variant) |
2489 |
|
static int tick_counter = 0; |
2490 |
|
tick_counter++; |
2520 |
|
} |
2521 |
|
} |
2522 |
|
|
2523 |
+ |
// This function is called on non-threaded platforms from a timer interrupt |
2524 |
|
void VideoRefresh(void) |
2525 |
|
{ |
2526 |
|
// We need to check redraw_thread_active to inhibit refreshed during |
2527 |
|
// mode changes on non-threaded platforms |
2528 |
< |
if (redraw_thread_active) |
2529 |
< |
video_refresh(); |
2528 |
> |
if (!redraw_thread_active) |
2529 |
> |
return; |
2530 |
> |
|
2531 |
> |
// Handle X events |
2532 |
> |
handle_events(); |
2533 |
> |
|
2534 |
> |
// Handle palette changes |
2535 |
> |
handle_palette_changes(); |
2536 |
> |
|
2537 |
> |
// Update display |
2538 |
> |
video_refresh(); |
2539 |
|
} |
2540 |
|
|
2541 |
+ |
const int VIDEO_REFRESH_HZ = 60; |
2542 |
+ |
const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ; |
2543 |
+ |
|
2544 |
|
#ifdef HAVE_PTHREADS |
2545 |
|
static void *redraw_func(void *arg) |
2546 |
|
{ |
2547 |
+ |
int fd = ConnectionNumber(x_display); |
2548 |
+ |
|
2549 |
|
uint64 start = GetTicks_usec(); |
2550 |
|
int64 ticks = 0; |
2551 |
< |
uint64 next = GetTicks_usec(); |
2551 |
> |
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
2552 |
> |
|
2553 |
|
while (!redraw_thread_cancel) { |
2554 |
< |
video_refresh(); |
2454 |
< |
next += 16667; |
2554 |
> |
|
2555 |
|
int64 delay = next - GetTicks_usec(); |
2556 |
< |
if (delay > 0) |
2557 |
< |
Delay_usec(delay); |
2558 |
< |
else if (delay < -16667) |
2556 |
> |
if (delay < -VIDEO_REFRESH_DELAY) { |
2557 |
> |
|
2558 |
> |
// We are lagging far behind, so we reset the delay mechanism |
2559 |
|
next = GetTicks_usec(); |
2560 |
< |
ticks++; |
2560 |
> |
|
2561 |
> |
} else if (delay <= 0) { |
2562 |
> |
|
2563 |
> |
// Delay expired, refresh display |
2564 |
> |
handle_events(); |
2565 |
> |
handle_palette_changes(); |
2566 |
> |
video_refresh(); |
2567 |
> |
next += VIDEO_REFRESH_DELAY; |
2568 |
> |
ticks++; |
2569 |
> |
|
2570 |
> |
} else { |
2571 |
> |
|
2572 |
> |
// No display refresh pending, check for X events |
2573 |
> |
fd_set readfds; |
2574 |
> |
FD_ZERO(&readfds); |
2575 |
> |
FD_SET(fd, &readfds); |
2576 |
> |
struct timeval timeout; |
2577 |
> |
timeout.tv_sec = 0; |
2578 |
> |
timeout.tv_usec = delay; |
2579 |
> |
if (select(fd+1, &readfds, NULL, NULL, &timeout) > 0) |
2580 |
> |
handle_events(); |
2581 |
> |
} |
2582 |
|
} |
2583 |
+ |
|
2584 |
|
uint64 end = GetTicks_usec(); |
2585 |
< |
// printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, ticks * 1000000 / (end - start)); |
2585 |
> |
D(bug("%Ld refreshes in %Ld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start))); |
2586 |
|
return NULL; |
2587 |
|
} |
2588 |
|
#endif |