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 |
67 |
|
#include "debug.h" |
68 |
|
|
69 |
|
|
70 |
+ |
// Supported video modes |
71 |
+ |
static vector<video_mode> VideoModes; |
72 |
+ |
|
73 |
|
// Display types |
74 |
|
enum { |
75 |
|
DISPLAY_WINDOW, // X11 window, using MIT SHM extensions if possible |
139 |
|
|
140 |
|
static Colormap cmap[2] = {0, 0}; // Colormaps for indexed modes (DGA needs two of them) |
141 |
|
|
142 |
< |
static XColor palette[256]; // Color palette to be used as CLUT and gamma table |
143 |
< |
static bool palette_changed = false; // Flag: Palette changed, redraw thread must set new colors |
142 |
> |
static XColor x_palette[256]; // Color palette to be used as CLUT and gamma table |
143 |
> |
static bool x_palette_changed = false; // Flag: Palette changed, redraw thread must set new colors |
144 |
|
|
145 |
|
#ifdef ENABLE_FBDEV_DGA |
146 |
|
static int fbdev_fd = -1; |
153 |
|
|
154 |
|
// Mutex to protect palette |
155 |
|
#ifdef HAVE_PTHREADS |
156 |
< |
static pthread_mutex_t palette_lock = PTHREAD_MUTEX_INITIALIZER; |
157 |
< |
#define LOCK_PALETTE pthread_mutex_lock(&palette_lock) |
158 |
< |
#define UNLOCK_PALETTE pthread_mutex_unlock(&palette_lock) |
156 |
> |
static pthread_mutex_t x_palette_lock = PTHREAD_MUTEX_INITIALIZER; |
157 |
> |
#define LOCK_PALETTE pthread_mutex_lock(&x_palette_lock) |
158 |
> |
#define UNLOCK_PALETTE pthread_mutex_unlock(&x_palette_lock) |
159 |
|
#else |
160 |
|
#define LOCK_PALETTE |
161 |
|
#define UNLOCK_PALETTE |
194 |
|
|
195 |
|
|
196 |
|
/* |
197 |
+ |
* monitor_desc subclass for X11 display |
198 |
+ |
*/ |
199 |
+ |
|
200 |
+ |
class X11_monitor_desc : public monitor_desc { |
201 |
+ |
public: |
202 |
+ |
X11_monitor_desc(const vector<video_mode> &available_modes, video_depth default_depth, uint32 default_id) : monitor_desc(available_modes, default_depth, default_id) {} |
203 |
+ |
~X11_monitor_desc() {} |
204 |
+ |
|
205 |
+ |
virtual void switch_to_current_mode(void); |
206 |
+ |
virtual void set_palette(uint8 *pal, int num); |
207 |
+ |
|
208 |
+ |
bool video_open(void); |
209 |
+ |
void video_close(void); |
210 |
+ |
}; |
211 |
+ |
|
212 |
+ |
|
213 |
+ |
/* |
214 |
|
* Utility functions |
215 |
|
*/ |
216 |
|
|
348 |
|
} |
349 |
|
|
350 |
|
// Set Mac frame layout and base address (uses the_buffer/MacFrameBaseMac) |
351 |
< |
static void set_mac_frame_buffer(video_depth depth, bool native_byte_order) |
351 |
> |
static void set_mac_frame_buffer(X11_monitor_desc &monitor, video_depth depth, bool native_byte_order) |
352 |
|
{ |
353 |
|
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
354 |
|
int layout = FLAYOUT_DIRECT; |
360 |
|
MacFrameLayout = layout; |
361 |
|
else |
362 |
|
MacFrameLayout = FLAYOUT_DIRECT; |
363 |
< |
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
363 |
> |
monitor.set_mac_frame_base(MacFrameBaseMac); |
364 |
|
|
365 |
|
// Set variables used by UAE memory banking |
366 |
+ |
const video_mode &mode = monitor.get_current_mode(); |
367 |
|
MacFrameBaseHost = the_buffer; |
368 |
< |
MacFrameSize = VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y; |
368 |
> |
MacFrameSize = mode.bytes_per_row * mode.y; |
369 |
|
InitFrameBufferMapping(); |
370 |
|
#else |
371 |
< |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
371 |
> |
monitor.set_mac_frame_base(Host2MacAddr(the_buffer)); |
372 |
|
#endif |
373 |
< |
D(bug("VideoMonitor.mac_frame_base = %08x\n", VideoMonitor.mac_frame_base)); |
373 |
> |
D(bug("monitor.mac_frame_base = %08x\n", monitor.get_mac_frame_base())); |
374 |
|
} |
375 |
|
|
376 |
|
// Set window name and class |
448 |
|
|
449 |
|
class driver_base { |
450 |
|
public: |
451 |
< |
driver_base(); |
451 |
> |
driver_base(X11_monitor_desc &m); |
452 |
|
virtual ~driver_base(); |
453 |
|
|
454 |
|
virtual void update_palette(void); |
464 |
|
virtual void ungrab_mouse(void) {} |
465 |
|
|
466 |
|
public: |
467 |
+ |
X11_monitor_desc &monitor; // Associated video monitor |
468 |
+ |
const video_mode &mode; // Video mode handled by the driver |
469 |
+ |
|
470 |
|
bool init_ok; // Initialization succeeded (we can't use exceptions because of -fomit-frame-pointer) |
471 |
|
Window w; // The window we draw into |
472 |
|
|
484 |
|
friend void update_display_static(driver_window *drv); |
485 |
|
|
486 |
|
public: |
487 |
< |
driver_window(const video_mode &mode); |
487 |
> |
driver_window(X11_monitor_desc &monitor); |
488 |
|
~driver_window(); |
489 |
|
|
490 |
|
void toggle_mouse_grab(void); |
509 |
|
# include "video_vosf.h" |
510 |
|
#endif |
511 |
|
|
512 |
< |
driver_base::driver_base() |
513 |
< |
: init_ok(false), w(0) |
512 |
> |
driver_base::driver_base(X11_monitor_desc &m) |
513 |
> |
: monitor(m), mode(m.get_current_mode()), init_ok(false), w(0) |
514 |
|
{ |
515 |
|
the_buffer = NULL; |
516 |
|
the_buffer_copy = NULL; |
569 |
|
{ |
570 |
|
if (color_class == PseudoColor || color_class == DirectColor) { |
571 |
|
int num = vis->map_entries; |
572 |
< |
if (!IsDirectMode(VideoMonitor.mode) && color_class == DirectColor) |
572 |
> |
if (!IsDirectMode(monitor.get_current_mode()) && color_class == DirectColor) |
573 |
|
return; // Indexed mode on true color screen, don't set CLUT |
574 |
< |
XStoreColors(x_display, cmap[0], palette, num); |
575 |
< |
XStoreColors(x_display, cmap[1], palette, num); |
574 |
> |
XStoreColors(x_display, cmap[0], x_palette, num); |
575 |
> |
XStoreColors(x_display, cmap[1], x_palette, num); |
576 |
|
} |
577 |
|
XSync(x_display, false); |
578 |
|
} |
595 |
|
*/ |
596 |
|
|
597 |
|
// Open display |
598 |
< |
driver_window::driver_window(const video_mode &mode) |
599 |
< |
: gc(0), img(NULL), have_shm(false), mac_cursor(0), mouse_grabbed(false) |
598 |
> |
driver_window::driver_window(X11_monitor_desc &m) |
599 |
> |
: driver_base(m), gc(0), img(NULL), have_shm(false), mac_cursor(0), mouse_grabbed(false) |
600 |
|
{ |
601 |
|
int width = mode.x, height = mode.y; |
602 |
|
int aligned_width = (width + 15) & ~15; |
728 |
|
Screen_blitter_init(&visualInfo, native_byte_order, mode.depth); |
729 |
|
#endif |
730 |
|
|
731 |
< |
// Set VideoMonitor |
732 |
< |
VideoMonitor.mode = mode; |
713 |
< |
set_mac_frame_buffer(mode.depth, native_byte_order); |
731 |
> |
// Set frame buffer base |
732 |
> |
set_mac_frame_buffer(monitor, mode.depth, native_byte_order); |
733 |
|
|
734 |
|
// Everything went well |
735 |
|
init_ok = true; |
809 |
|
// Warped mouse motion (this code is taken from SDL) |
810 |
|
|
811 |
|
// Post first mouse event |
812 |
< |
int width = VideoMonitor.mode.x, height = VideoMonitor.mode.y; |
812 |
> |
int width = monitor.get_current_mode().x, height = monitor.get_current_mode().y; |
813 |
|
int delta_x = x - mouse_last_x, delta_y = y - mouse_last_y; |
814 |
|
mouse_last_x = x; mouse_last_y = y; |
815 |
|
ADBMouseMoved(delta_x, delta_y); |
846 |
|
|
847 |
|
class driver_dga : public driver_base { |
848 |
|
public: |
849 |
< |
driver_dga(); |
849 |
> |
driver_dga(X11_monitor_desc &monitor); |
850 |
|
~driver_dga(); |
851 |
|
|
852 |
|
void suspend(void); |
857 |
|
void *fb_save; // Saved frame buffer for suspend/resume |
858 |
|
}; |
859 |
|
|
860 |
< |
driver_dga::driver_dga() |
861 |
< |
: suspend_win(0), fb_save(NULL) |
860 |
> |
driver_dga::driver_dga(X11_monitor_desc &m) |
861 |
> |
: driver_base(m), suspend_win(0), fb_save(NULL) |
862 |
|
{ |
863 |
|
} |
864 |
|
|
879 |
|
LOCK_FRAME_BUFFER; |
880 |
|
|
881 |
|
// Save frame buffer |
882 |
< |
fb_save = malloc(VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
882 |
> |
fb_save = malloc(mode.y * mode.bytes_per_row); |
883 |
|
if (fb_save) |
884 |
< |
memcpy(fb_save, the_buffer, VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
884 |
> |
memcpy(fb_save, the_buffer, mode.y * mode.bytes_per_row); |
885 |
|
|
886 |
|
// Close full screen display |
887 |
|
#ifdef ENABLE_XF86_DGA |
934 |
|
LOCK_VOSF; |
935 |
|
PFLAG_SET_ALL; |
936 |
|
UNLOCK_VOSF; |
937 |
< |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
937 |
> |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
938 |
|
} |
939 |
|
#endif |
940 |
|
|
944 |
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
945 |
|
if (!use_vosf) |
946 |
|
#endif |
947 |
< |
memcpy(the_buffer, fb_save, VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
947 |
> |
memcpy(the_buffer, fb_save, mode.y * mode.bytes_per_row); |
948 |
|
free(fb_save); |
949 |
|
fb_save = NULL; |
950 |
|
} |
966 |
|
|
967 |
|
class driver_fbdev : public driver_dga { |
968 |
|
public: |
969 |
< |
driver_fbdev(const video_mode &mode); |
969 |
> |
driver_fbdev(X11_monitor_desc &monitor); |
970 |
|
~driver_fbdev(); |
971 |
|
}; |
972 |
|
|
973 |
|
// Open display |
974 |
< |
driver_fbdev::driver_fbdev(const video_mode &mode) |
974 |
> |
driver_fbdev::driver_fbdev(X11_monitor_desc &m) : driver_dga(m) |
975 |
|
{ |
976 |
|
int width = mode.x, height = mode.y; |
977 |
|
|
1019 |
|
if ((line[0] == '#') || (line[0] == ';') || (line[0] == '\0')) |
1020 |
|
continue; |
1021 |
|
|
1022 |
< |
if ((sscanf(line, "%19s %d %x", &fb_name, &fb_depth, &fb_offset) == 3) |
1022 |
> |
if ((sscanf(line, "%19s %d %x", fb_name, &fb_depth, &fb_offset) == 3) |
1023 |
|
&& (strcmp(fb_name, fb_name) == 0) && (fb_depth == max_depth)) { |
1024 |
|
device_found = true; |
1025 |
|
break; |
1100 |
|
#endif |
1101 |
|
#endif |
1102 |
|
|
1103 |
< |
// Set VideoMonitor |
1104 |
< |
VideoModes[0].bytes_per_row = bytes_per_row; |
1105 |
< |
VideoModes[0].depth = DepthModeForPixelDepth(fb_depth); |
1106 |
< |
VideoMonitor.mode = mode; |
1088 |
< |
set_mac_frame_buffer(mode.depth, true); |
1103 |
> |
// Set frame buffer base |
1104 |
> |
const_cast<video_mode *>(&mode)->bytes_per_row = bytes_per_row; |
1105 |
> |
const_cast<video_mode *>(&mode)->depth = DepthModeForPixelDepth(fb_depth); |
1106 |
> |
set_mac_frame_buffer(monitor, mode.depth, true); |
1107 |
|
|
1108 |
|
// Everything went well |
1109 |
|
init_ok = true; |
1139 |
|
|
1140 |
|
class driver_xf86dga : public driver_dga { |
1141 |
|
public: |
1142 |
< |
driver_xf86dga(const video_mode &mode); |
1142 |
> |
driver_xf86dga(X11_monitor_desc &monitor); |
1143 |
|
~driver_xf86dga(); |
1144 |
|
|
1145 |
|
void update_palette(void); |
1150 |
|
}; |
1151 |
|
|
1152 |
|
// Open display |
1153 |
< |
driver_xf86dga::driver_xf86dga(const video_mode &mode) |
1154 |
< |
: current_dga_cmap(0) |
1153 |
> |
driver_xf86dga::driver_xf86dga(X11_monitor_desc &m) |
1154 |
> |
: driver_dga(m), current_dga_cmap(0) |
1155 |
|
{ |
1156 |
|
int width = mode.x, height = mode.y; |
1157 |
|
|
1178 |
|
XSetWindowAttributes wattr; |
1179 |
|
wattr.event_mask = eventmask = dga_eventmask; |
1180 |
|
wattr.override_redirect = True; |
1181 |
+ |
wattr.colormap = (mode.depth == VDEPTH_1BIT ? DefaultColormap(x_display, screen) : cmap[0]); |
1182 |
|
|
1183 |
|
w = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
1184 |
< |
InputOutput, vis, CWEventMask | CWOverrideRedirect, &wattr); |
1184 |
> |
InputOutput, vis, CWEventMask | CWOverrideRedirect | |
1185 |
> |
(color_class == DirectColor ? CWColormap : 0), &wattr); |
1186 |
|
|
1187 |
|
// Set window name/class |
1188 |
|
set_window_name(w, STR_WINDOW_TITLE); |
1216 |
|
|
1217 |
|
// Init blitting routines |
1218 |
|
int bytes_per_row = TrivialBytesPerRow((v_width + 7) & ~7, mode.depth); |
1219 |
< |
#if VIDEO_VOSF |
1219 |
> |
#if ENABLE_VOSF |
1220 |
> |
bool native_byte_order; |
1221 |
> |
#ifdef WORDS_BIGENDIAN |
1222 |
> |
native_byte_order = (XImageByteOrder(x_display) == MSBFirst); |
1223 |
> |
#else |
1224 |
> |
native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
1225 |
> |
#endif |
1226 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
1227 |
|
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
1228 |
|
// i.e. the framebuffer update function is not Blit_Copy_Raw |
1229 |
< |
use_vosf = Screen_blitter_init(&visualInfo, true, mode.depth); |
1229 |
> |
use_vosf = Screen_blitter_init(&visualInfo, native_byte_order, mode.depth); |
1230 |
|
|
1231 |
|
if (use_vosf) { |
1232 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
1240 |
|
#endif |
1241 |
|
#endif |
1242 |
|
|
1243 |
< |
// Set VideoMonitor |
1243 |
> |
// Set frame buffer base |
1244 |
|
const_cast<video_mode *>(&mode)->bytes_per_row = bytes_per_row; |
1245 |
< |
VideoMonitor.mode = mode; |
1220 |
< |
set_mac_frame_buffer(mode.depth, true); |
1245 |
> |
set_mac_frame_buffer(monitor, mode.depth, true); |
1246 |
|
|
1247 |
|
// Everything went well |
1248 |
|
init_ok = true; |
1273 |
|
{ |
1274 |
|
driver_dga::update_palette(); |
1275 |
|
current_dga_cmap ^= 1; |
1276 |
< |
if (!IsDirectMode(VideoMonitor.mode) && cmap[current_dga_cmap]) |
1276 |
> |
if (!IsDirectMode(monitor.get_current_mode()) && cmap[current_dga_cmap]) |
1277 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1278 |
|
} |
1279 |
|
|
1281 |
|
void driver_xf86dga::resume(void) |
1282 |
|
{ |
1283 |
|
driver_dga::resume(); |
1284 |
< |
if (!IsDirectMode(VideoMonitor.mode)) |
1284 |
> |
if (!IsDirectMode(monitor.get_current_mode())) |
1285 |
|
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1286 |
|
} |
1287 |
|
#endif |
1356 |
|
} |
1357 |
|
} |
1358 |
|
|
1359 |
< |
// Open display for specified mode |
1360 |
< |
static bool video_open(const video_mode &mode) |
1359 |
> |
// Open display for current mode |
1360 |
> |
bool X11_monitor_desc::video_open(void) |
1361 |
|
{ |
1362 |
|
D(bug("video_open()\n")); |
1363 |
+ |
const video_mode &mode = get_current_mode(); |
1364 |
|
|
1365 |
|
// Find best available X visual |
1366 |
|
if (!find_visual_for_depth(mode.depth)) { |
1401 |
|
int num = vis->map_entries; |
1402 |
|
for (int i=0; i<num; i++) { |
1403 |
|
int c = (i * 256) / num; |
1404 |
< |
palette[i].pixel = map_rgb(c, c, c); |
1405 |
< |
palette[i].flags = DoRed | DoGreen | DoBlue; |
1404 |
> |
x_palette[i].pixel = map_rgb(c, c, c); |
1405 |
> |
x_palette[i].flags = DoRed | DoGreen | DoBlue; |
1406 |
|
} |
1407 |
|
} else if (color_class == PseudoColor) { |
1408 |
|
for (int i=0; i<256; i++) { |
1409 |
< |
palette[i].pixel = i; |
1410 |
< |
palette[i].flags = DoRed | DoGreen | DoBlue; |
1409 |
> |
x_palette[i].pixel = i; |
1410 |
> |
x_palette[i].flags = DoRed | DoGreen | DoBlue; |
1411 |
|
} |
1412 |
|
} |
1413 |
|
|
1415 |
|
int num = (color_class == DirectColor ? vis->map_entries : 256); |
1416 |
|
for (int i=0; i<num; i++) { |
1417 |
|
int c = (i * 256) / num; |
1418 |
< |
palette[i].red = c * 0x0101; |
1419 |
< |
palette[i].green = c * 0x0101; |
1420 |
< |
palette[i].blue = c * 0x0101; |
1418 |
> |
x_palette[i].red = c * 0x0101; |
1419 |
> |
x_palette[i].green = c * 0x0101; |
1420 |
> |
x_palette[i].blue = c * 0x0101; |
1421 |
|
} |
1422 |
|
if (color_class == PseudoColor || color_class == DirectColor) { |
1423 |
< |
XStoreColors(x_display, cmap[0], palette, num); |
1424 |
< |
XStoreColors(x_display, cmap[1], palette, num); |
1423 |
> |
XStoreColors(x_display, cmap[0], x_palette, num); |
1424 |
> |
XStoreColors(x_display, cmap[1], x_palette, num); |
1425 |
|
} |
1426 |
|
|
1427 |
|
#ifdef ENABLE_VOSF |
1434 |
|
// Create display driver object of requested type |
1435 |
|
switch (display_type) { |
1436 |
|
case DISPLAY_WINDOW: |
1437 |
< |
drv = new driver_window(mode); |
1437 |
> |
drv = new driver_window(*this); |
1438 |
|
break; |
1439 |
|
#ifdef ENABLE_FBDEV_DGA |
1440 |
|
case DISPLAY_DGA: |
1441 |
< |
drv = new driver_fbdev(mode); |
1441 |
> |
drv = new driver_fbdev(*this); |
1442 |
|
break; |
1443 |
|
#endif |
1444 |
|
#ifdef ENABLE_XF86_DGA |
1445 |
|
case DISPLAY_DGA: |
1446 |
< |
drv = new driver_xf86dga(mode); |
1446 |
> |
drv = new driver_xf86dga(*this); |
1447 |
|
break; |
1448 |
|
#endif |
1449 |
|
} |
1458 |
|
#ifdef ENABLE_VOSF |
1459 |
|
if (use_vosf) { |
1460 |
|
// Initialize the VOSF system |
1461 |
< |
if (!video_vosf_init()) { |
1461 |
> |
if (!video_vosf_init(*this)) { |
1462 |
|
ErrorAlert(STR_VOSF_INIT_ERR); |
1463 |
|
return false; |
1464 |
|
} |
1520 |
|
ErrorAlert(STR_UNSUPP_DEPTH_ERR); |
1521 |
|
return false; |
1522 |
|
} |
1523 |
< |
sort(avail_depths, avail_depths + num_depths); |
1523 |
> |
std::sort(avail_depths, avail_depths + num_depths); |
1524 |
|
|
1525 |
|
#ifdef ENABLE_FBDEV_DGA |
1526 |
|
// Frame buffer name |
1623 |
|
ErrorAlert(STR_NO_XVISUAL_ERR); |
1624 |
|
return false; |
1625 |
|
} |
1626 |
< |
video_init_depth_list(); |
1626 |
> |
|
1627 |
> |
// Find requested default mode with specified dimensions |
1628 |
> |
uint32 default_id; |
1629 |
> |
std::vector<video_mode>::const_iterator i, end = VideoModes.end(); |
1630 |
> |
for (i = VideoModes.begin(); i != end; ++i) { |
1631 |
> |
if (i->x == default_width && i->y == default_height && i->depth == default_depth) { |
1632 |
> |
default_id = i->resolution_id; |
1633 |
> |
break; |
1634 |
> |
} |
1635 |
> |
} |
1636 |
> |
if (i == end) { // not found, use first available mode |
1637 |
> |
default_depth = VideoModes[0].depth; |
1638 |
> |
default_id = VideoModes[0].resolution_id; |
1639 |
> |
} |
1640 |
|
|
1641 |
|
#if DEBUG |
1642 |
|
D(bug("Available video modes:\n")); |
1643 |
< |
vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end(); |
1605 |
< |
while (i != end) { |
1643 |
> |
for (i = VideoModes.begin(); i != end; ++i) { |
1644 |
|
int bits = 1 << i->depth; |
1645 |
|
if (bits == 16) |
1646 |
|
bits = 15; |
1647 |
|
else if (bits == 32) |
1648 |
|
bits = 24; |
1649 |
|
D(bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits)); |
1612 |
– |
++i; |
1650 |
|
} |
1651 |
|
#endif |
1652 |
|
|
1653 |
< |
// Find requested default mode and open display |
1654 |
< |
if (VideoModes.size() == 1) |
1655 |
< |
return video_open(VideoModes[0]); |
1656 |
< |
else { |
1657 |
< |
// Find mode with specified dimensions |
1658 |
< |
std::vector<video_mode>::const_iterator i, end = VideoModes.end(); |
1622 |
< |
for (i = VideoModes.begin(); i != end; ++i) { |
1623 |
< |
if (i->x == default_width && i->y == default_height && i->depth == default_depth) |
1624 |
< |
return video_open(*i); |
1625 |
< |
} |
1626 |
< |
return video_open(VideoModes[0]); |
1627 |
< |
} |
1653 |
> |
// Create X11_monitor_desc for this (the only) display |
1654 |
> |
X11_monitor_desc *monitor = new X11_monitor_desc(VideoModes, default_depth, default_id); |
1655 |
> |
VideoMonitors.push_back(monitor); |
1656 |
> |
|
1657 |
> |
// Open display |
1658 |
> |
return monitor->video_open(); |
1659 |
|
} |
1660 |
|
|
1661 |
|
|
1664 |
|
*/ |
1665 |
|
|
1666 |
|
// Close display |
1667 |
< |
static void video_close(void) |
1667 |
> |
void X11_monitor_desc::video_close(void) |
1668 |
|
{ |
1669 |
|
D(bug("video_close()\n")); |
1670 |
|
|
1709 |
|
|
1710 |
|
void VideoExit(void) |
1711 |
|
{ |
1712 |
< |
// Close display |
1713 |
< |
video_close(); |
1712 |
> |
// Close displays |
1713 |
> |
vector<monitor_desc *>::iterator i, end = VideoMonitors.end(); |
1714 |
> |
for (i = VideoMonitors.begin(); i != end; ++i) |
1715 |
> |
dynamic_cast<X11_monitor_desc *>(*i)->video_close(); |
1716 |
|
|
1717 |
|
#ifdef ENABLE_XF86_VIDMODE |
1718 |
|
// Free video mode list |
1770 |
|
* Set palette |
1771 |
|
*/ |
1772 |
|
|
1773 |
< |
void video_set_palette(uint8 *pal, int num_in) |
1773 |
> |
void X11_monitor_desc::set_palette(uint8 *pal, int num_in) |
1774 |
|
{ |
1775 |
+ |
const video_mode &mode = get_current_mode(); |
1776 |
+ |
|
1777 |
|
LOCK_PALETTE; |
1778 |
|
|
1779 |
|
// Convert colors to XColor array |
1780 |
|
int num_out = 256; |
1781 |
|
bool stretch = false; |
1782 |
< |
if (IsDirectMode(VideoMonitor.mode)) { |
1782 |
> |
if (IsDirectMode(mode)) { |
1783 |
|
// If X is in 565 mode we have to stretch the gamma table from 32 to 64 entries |
1784 |
|
num_out = vis->map_entries; |
1785 |
|
stretch = true; |
1786 |
|
} |
1787 |
< |
XColor *p = palette; |
1787 |
> |
XColor *p = x_palette; |
1788 |
|
for (int i=0; i<num_out; i++) { |
1789 |
|
int c = (stretch ? (i * num_in) / num_out : i); |
1790 |
|
p->red = pal[c*3 + 0] * 0x0101; |
1795 |
|
|
1796 |
|
#ifdef ENABLE_VOSF |
1797 |
|
// Recalculate pixel color expansion map |
1798 |
< |
if (!IsDirectMode(VideoMonitor.mode) && xdepth > 8) { |
1798 |
> |
if (!IsDirectMode(mode) && xdepth > 8) { |
1799 |
|
for (int i=0; i<256; i++) { |
1800 |
|
int c = i & (num_in-1); // If there are less than 256 colors, we repeat the first entries (this makes color expansion easier) |
1801 |
|
ExpandMap[i] = map_rgb(pal[c*3+0], pal[c*3+1], pal[c*3+2]); |
1805 |
|
LOCK_VOSF; |
1806 |
|
PFLAG_SET_ALL; |
1807 |
|
UNLOCK_VOSF; |
1808 |
< |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
1808 |
> |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1809 |
|
} |
1810 |
|
#endif |
1811 |
|
|
1812 |
|
// Tell redraw thread to change palette |
1813 |
< |
palette_changed = true; |
1813 |
> |
x_palette_changed = true; |
1814 |
|
|
1815 |
|
UNLOCK_PALETTE; |
1816 |
|
} |
1820 |
|
* Switch video mode |
1821 |
|
*/ |
1822 |
|
|
1823 |
< |
void video_switch_to_mode(const video_mode &mode) |
1823 |
> |
void X11_monitor_desc::switch_to_current_mode(void) |
1824 |
|
{ |
1825 |
|
// Close and reopen display |
1826 |
|
video_close(); |
1827 |
< |
video_open(mode); |
1827 |
> |
video_open(); |
1828 |
|
|
1829 |
|
if (drv == NULL) { |
1830 |
|
ErrorAlert(STR_OPEN_WINDOW_ERR); |
2094 |
|
// Hidden parts exposed, force complete refresh of window |
2095 |
|
case Expose: |
2096 |
|
if (display_type == DISPLAY_WINDOW) { |
2097 |
+ |
const video_mode &mode = VideoMonitors[0]->get_current_mode(); |
2098 |
|
#ifdef ENABLE_VOSF |
2099 |
|
if (use_vosf) { // VOSF refresh |
2100 |
|
LOCK_VOSF; |
2101 |
|
PFLAG_SET_ALL; |
2102 |
|
UNLOCK_VOSF; |
2103 |
< |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
2103 |
> |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
2104 |
|
} |
2105 |
|
else |
2106 |
|
#endif |
2111 |
|
updt_box[x1][y1] = true; |
2112 |
|
nr_boxes = 16 * 16; |
2113 |
|
} else // Static refresh |
2114 |
< |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
2114 |
> |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
2115 |
|
} |
2116 |
|
break; |
2117 |
|
|
2137 |
|
int y1, y2, y2s, y2a, i, x1, xm, xmo, ymo, yo, yi, yil, xi; |
2138 |
|
int xil = 0; |
2139 |
|
int rxm = 0, rxmo = 0; |
2140 |
< |
int bytes_per_row = VideoMonitor.mode.bytes_per_row; |
2141 |
< |
int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; |
2142 |
< |
int rx = VideoMonitor.mode.bytes_per_row / 16; |
2143 |
< |
int ry = VideoMonitor.mode.y / 16; |
2140 |
> |
const video_mode &mode = drv->monitor.get_current_mode(); |
2141 |
> |
int bytes_per_row = mode.bytes_per_row; |
2142 |
> |
int bytes_per_pixel = mode.bytes_per_row / mode.x; |
2143 |
> |
int rx = mode.bytes_per_row / 16; |
2144 |
> |
int ry = mode.y / 16; |
2145 |
|
int max_box; |
2146 |
|
|
2147 |
|
y2s = sm_uptd[ticker % 8]; |
2195 |
|
i = (yi * bytes_per_row) + xi; |
2196 |
|
for (y2=0; y2 < yil; y2++, i += bytes_per_row) |
2197 |
|
memcpy(&the_buffer_copy[i], &the_buffer[i], xil); |
2198 |
< |
if (VideoMonitor.mode.depth == VDEPTH_1BIT) { |
2198 |
> |
if (mode.depth == VDEPTH_1BIT) { |
2199 |
|
if (drv->have_shm) |
2200 |
|
XShmPutImage(x_display, drv->w, drv->gc, drv->img, xi * 8, yi, xi * 8, yi, xil * 8, yil, 0); |
2201 |
|
else |
2227 |
|
{ |
2228 |
|
// Incremental update code |
2229 |
|
unsigned wide = 0, high = 0, x1, x2, y1, y2, i, j; |
2230 |
< |
int bytes_per_row = VideoMonitor.mode.bytes_per_row; |
2231 |
< |
int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; |
2230 |
> |
const video_mode &mode = drv->monitor.get_current_mode(); |
2231 |
> |
int bytes_per_row = mode.bytes_per_row; |
2232 |
> |
int bytes_per_pixel = mode.bytes_per_row / mode.x; |
2233 |
|
uint8 *p, *p2; |
2234 |
|
|
2235 |
|
// Check for first line from top and first line from bottom that have changed |
2236 |
|
y1 = 0; |
2237 |
< |
for (j=0; j<VideoMonitor.mode.y; j++) { |
2237 |
> |
for (j=0; j<mode.y; j++) { |
2238 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
2239 |
|
y1 = j; |
2240 |
|
break; |
2241 |
|
} |
2242 |
|
} |
2243 |
|
y2 = y1 - 1; |
2244 |
< |
for (j=VideoMonitor.mode.y-1; j>=y1; j--) { |
2244 |
> |
for (j=mode.y-1; j>=y1; j--) { |
2245 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
2246 |
|
y2 = j; |
2247 |
|
break; |
2251 |
|
|
2252 |
|
// Check for first column from left and first column from right that have changed |
2253 |
|
if (high) { |
2254 |
< |
if (VideoMonitor.mode.depth == VDEPTH_1BIT) { |
2255 |
< |
x1 = VideoMonitor.mode.x - 1; |
2254 |
> |
if (mode.depth == VDEPTH_1BIT) { |
2255 |
> |
x1 = mode.x - 1; |
2256 |
|
for (j=y1; j<=y2; j++) { |
2257 |
|
p = &the_buffer[j * bytes_per_row]; |
2258 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
2270 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
2271 |
|
p += bytes_per_row; |
2272 |
|
p2 += bytes_per_row; |
2273 |
< |
for (i=(VideoMonitor.mode.x>>3); i>(x2>>3); i--) { |
2273 |
> |
for (i=(mode.x>>3); i>(x2>>3); i--) { |
2274 |
|
p--; p2--; |
2275 |
|
if (*p != *p2) { |
2276 |
|
x2 = (i << 3) + 7; |
2289 |
|
} |
2290 |
|
|
2291 |
|
} else { |
2292 |
< |
x1 = VideoMonitor.mode.x; |
2292 |
> |
x1 = mode.x; |
2293 |
|
for (j=y1; j<=y2; j++) { |
2294 |
|
p = &the_buffer[j * bytes_per_row]; |
2295 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
2307 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
2308 |
|
p += bytes_per_row; |
2309 |
|
p2 += bytes_per_row; |
2310 |
< |
for (i=VideoMonitor.mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
2310 |
> |
for (i=mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
2311 |
|
p--; |
2312 |
|
p2--; |
2313 |
|
if (*p != *p2) { |
2374 |
|
{ |
2375 |
|
LOCK_PALETTE; |
2376 |
|
|
2377 |
< |
if (palette_changed) { |
2378 |
< |
palette_changed = false; |
2377 |
> |
if (x_palette_changed) { |
2378 |
> |
x_palette_changed = false; |
2379 |
|
drv->update_palette(); |
2380 |
|
} |
2381 |
|
|