ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/video_x.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/video_x.cpp (file contents):
Revision 1.62 by gbeauche, 2001-07-14T18:41:05Z vs.
Revision 1.67 by cebix, 2002-04-28T12:09:23Z

# Line 1 | Line 1
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-2002 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
# Line 39 | Line 39
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
# Line 71 | Line 67 | using std::sort;
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
# Line 97 | Line 96 | static uint32 the_buffer_size;                                         // S
96  
97   static bool redraw_thread_active = false;                       // Flag: Redraw thread installed
98   #ifdef HAVE_PTHREADS
99 + static pthread_attr_t redraw_thread_attr;                       // Redraw thread attributes
100   static volatile bool redraw_thread_cancel;                      // Flag: Cancel Redraw thread
101   static pthread_t redraw_thread;                                         // Redraw thread
102   #endif
# Line 139 | Line 139 | static int rshift, rloss, gshift, gloss,
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;
# Line 153 | Line 153 | static int num_x_video_modes;
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
# Line 194 | Line 194 | extern void SysMountFirstFloppy(void);
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  
# Line 331 | Line 348 | static void add_window_modes(video_depth
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;
# Line 343 | Line 360 | static void set_mac_frame_buffer(video_d
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
# Line 430 | Line 448 | static int error_handler(Display *d, XEr
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);
# Line 446 | Line 464 | public:
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  
# Line 463 | Line 484 | class driver_window : public driver_base
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);
# Line 488 | Line 509 | static driver_base *drv = NULL;        // Point
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;
# Line 548 | Line 569 | void driver_base::update_palette(void)
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   }
# Line 574 | Line 595 | void driver_base::restore_mouse_accel(vo
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;
# Line 707 | Line 728 | driver_window::driver_window(const video
728          Screen_blitter_init(&visualInfo, native_byte_order, mode.depth);
729   #endif
730  
731 <        // Set VideoMonitor
732 <        VideoMonitor.mode = mode;
712 <        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;
# Line 789 | Line 809 | void driver_window::mouse_moved(int x, i
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);
# Line 826 | Line 846 | void driver_window::mouse_moved(int x, i
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);
# Line 837 | Line 857 | private:
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  
# Line 859 | Line 879 | void driver_dga::suspend(void)
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
# Line 914 | Line 934 | void driver_dga::resume(void)
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          
# Line 924 | Line 944 | void driver_dga::resume(void)
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          }
# Line 946 | Line 966 | const char FBDEVICE_FILE_NAME[] = "/dev/
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  
# Line 999 | Line 1019 | driver_fbdev::driver_fbdev(const video_m
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;
# Line 1080 | Line 1100 | driver_fbdev::driver_fbdev(const video_m
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;
1087 <        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;
# Line 1120 | Line 1139 | driver_fbdev::~driver_fbdev()
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);
# Line 1131 | Line 1150 | private:
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  
# Line 1213 | Line 1232 | driver_xf86dga::driver_xf86dga(const vid
1232   #endif
1233   #endif
1234          
1235 <        // Set VideoMonitor
1235 >        // Set frame buffer base
1236          const_cast<video_mode *>(&mode)->bytes_per_row = bytes_per_row;
1237 <        VideoMonitor.mode = mode;
1219 <        set_mac_frame_buffer(mode.depth, true);
1237 >        set_mac_frame_buffer(monitor, mode.depth, true);
1238  
1239          // Everything went well
1240          init_ok = true;
# Line 1247 | Line 1265 | void driver_xf86dga::update_palette(void
1265   {
1266          driver_dga::update_palette();
1267          current_dga_cmap ^= 1;
1268 <        if (!IsDirectMode(VideoMonitor.mode) && cmap[current_dga_cmap])
1268 >        if (!IsDirectMode(monitor.get_current_mode()) && cmap[current_dga_cmap])
1269                  XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
1270   }
1271  
# Line 1255 | Line 1273 | void driver_xf86dga::update_palette(void
1273   void driver_xf86dga::resume(void)
1274   {
1275          driver_dga::resume();
1276 <        if (!IsDirectMode(VideoMonitor.mode))
1276 >        if (!IsDirectMode(monitor.get_current_mode()))
1277                  XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
1278   }
1279   #endif
# Line 1330 | Line 1348 | static void keycode_init(void)
1348          }
1349   }
1350  
1351 < // Open display for specified mode
1352 < static bool video_open(const video_mode &mode)
1351 > // Open display for current mode
1352 > bool X11_monitor_desc::video_open(void)
1353   {
1354          D(bug("video_open()\n"));
1355 +        const video_mode &mode = get_current_mode();
1356  
1357          // Find best available X visual
1358          if (!find_visual_for_depth(mode.depth)) {
# Line 1374 | Line 1393 | static bool video_open(const video_mode
1393                  int num = vis->map_entries;
1394                  for (int i=0; i<num; i++) {
1395                          int c = (i * 256) / num;
1396 <                        palette[i].pixel = map_rgb(c, c, c);
1397 <                        palette[i].flags = DoRed | DoGreen | DoBlue;
1396 >                        x_palette[i].pixel = map_rgb(c, c, c);
1397 >                        x_palette[i].flags = DoRed | DoGreen | DoBlue;
1398                  }
1399          } else if (color_class == PseudoColor) {
1400                  for (int i=0; i<256; i++) {
1401 <                        palette[i].pixel = i;
1402 <                        palette[i].flags = DoRed | DoGreen | DoBlue;
1401 >                        x_palette[i].pixel = i;
1402 >                        x_palette[i].flags = DoRed | DoGreen | DoBlue;
1403                  }
1404          }
1405  
# Line 1388 | Line 1407 | static bool video_open(const video_mode
1407          int num = (color_class == DirectColor ? vis->map_entries : 256);
1408          for (int i=0; i<num; i++) {
1409                  int c = (i * 256) / num;
1410 <                palette[i].red = c * 0x0101;
1411 <                palette[i].green = c * 0x0101;
1412 <                palette[i].blue = c * 0x0101;
1410 >                x_palette[i].red = c * 0x0101;
1411 >                x_palette[i].green = c * 0x0101;
1412 >                x_palette[i].blue = c * 0x0101;
1413          }
1414          if (color_class == PseudoColor || color_class == DirectColor) {
1415 <                XStoreColors(x_display, cmap[0], palette, num);
1416 <                XStoreColors(x_display, cmap[1], palette, num);
1415 >                XStoreColors(x_display, cmap[0], x_palette, num);
1416 >                XStoreColors(x_display, cmap[1], x_palette, num);
1417          }
1418  
1419   #ifdef ENABLE_VOSF
# Line 1407 | Line 1426 | static bool video_open(const video_mode
1426          // Create display driver object of requested type
1427          switch (display_type) {
1428                  case DISPLAY_WINDOW:
1429 <                        drv = new driver_window(mode);
1429 >                        drv = new driver_window(*this);
1430                          break;
1431   #ifdef ENABLE_FBDEV_DGA
1432                  case DISPLAY_DGA:
1433 <                        drv = new driver_fbdev(mode);
1433 >                        drv = new driver_fbdev(*this);
1434                          break;
1435   #endif
1436   #ifdef ENABLE_XF86_DGA
1437                  case DISPLAY_DGA:
1438 <                        drv = new driver_xf86dga(mode);
1438 >                        drv = new driver_xf86dga(*this);
1439                          break;
1440   #endif
1441          }
# Line 1431 | Line 1450 | static bool video_open(const video_mode
1450   #ifdef ENABLE_VOSF
1451          if (use_vosf) {
1452                  // Initialize the VOSF system
1453 <                if (!video_vosf_init()) {
1453 >                if (!video_vosf_init(*this)) {
1454                          ErrorAlert(STR_VOSF_INIT_ERR);
1455                  return false;
1456                  }
# Line 1448 | Line 1467 | static bool video_open(const video_mode
1467          // Start redraw/input thread
1468   #ifdef HAVE_PTHREADS
1469          redraw_thread_cancel = false;
1470 <        redraw_thread_active = (pthread_create(&redraw_thread, NULL, redraw_func, NULL) == 0);
1470 >        Set_pthread_attr(&redraw_thread_attr, 0);
1471 >        redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0);
1472          if (!redraw_thread_active) {
1473                  printf("FATAL: cannot create redraw thread\n");
1474                  return false;
# Line 1492 | Line 1512 | bool VideoInit(bool classic)
1512                  ErrorAlert(STR_UNSUPP_DEPTH_ERR);
1513                  return false;
1514          }
1515 <        sort(avail_depths, avail_depths + num_depths);
1515 >        std::sort(avail_depths, avail_depths + num_depths);
1516          
1517   #ifdef ENABLE_FBDEV_DGA
1518          // Frame buffer name
# Line 1595 | Line 1615 | bool VideoInit(bool classic)
1615                  ErrorAlert(STR_NO_XVISUAL_ERR);
1616                  return false;
1617          }
1618 <        video_init_depth_list();
1618 >
1619 >        // Find requested default mode with specified dimensions
1620 >        uint32 default_id;
1621 >        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 >                        default_id = i->resolution_id;
1625 >                        break;
1626 >                }
1627 >        }
1628 >        if (i == end) { // not found, use first available mode
1629 >                default_depth = VideoModes[0].depth;
1630 >                default_id = VideoModes[0].resolution_id;
1631 >        }
1632  
1633   #if DEBUG
1634          D(bug("Available video modes:\n"));
1635 <        vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
1603 <        while (i != end) {
1635 >        for (i = VideoModes.begin(); i != end; ++i) {
1636                  int bits = 1 << i->depth;
1637                  if (bits == 16)
1638                          bits = 15;
1639                  else if (bits == 32)
1640                          bits = 24;
1641                  D(bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits));
1610                ++i;
1642          }
1643   #endif
1644  
1645 <        // Find requested default mode and open display
1646 <        if (VideoModes.size() == 1)
1647 <                return video_open(VideoModes[0]);
1648 <        else {
1649 <                // Find mode with specified dimensions
1650 <                std::vector<video_mode>::const_iterator i, end = VideoModes.end();
1620 <                for (i = VideoModes.begin(); i != end; ++i) {
1621 <                        if (i->x == default_width && i->y == default_height && i->depth == default_depth)
1622 <                                return video_open(*i);
1623 <                }
1624 <                return video_open(VideoModes[0]);
1625 <        }
1645 >        // Create X11_monitor_desc for this (the only) display
1646 >        X11_monitor_desc *monitor = new X11_monitor_desc(VideoModes, default_depth, default_id);
1647 >        VideoMonitors.push_back(monitor);
1648 >
1649 >        // Open display
1650 >        return monitor->video_open();
1651   }
1652  
1653  
# Line 1631 | Line 1656 | bool VideoInit(bool classic)
1656   */
1657  
1658   // Close display
1659 < static void video_close(void)
1659 > void X11_monitor_desc::video_close(void)
1660   {
1661          D(bug("video_close()\n"));
1662  
# Line 1676 | Line 1701 | static void video_close(void)
1701  
1702   void VideoExit(void)
1703   {
1704 <        // Close display
1705 <        video_close();
1704 >        // Close displays
1705 >        vector<monitor_desc *>::iterator i, end = VideoMonitors.end();
1706 >        for (i = VideoMonitors.begin(); i != end; ++i)
1707 >                dynamic_cast<X11_monitor_desc *>(*i)->video_close();
1708  
1709   #ifdef ENABLE_XF86_VIDMODE
1710          // Free video mode list
# Line 1735 | Line 1762 | void VideoInterrupt(void)
1762   *  Set palette
1763   */
1764  
1765 < void video_set_palette(uint8 *pal, int num_in)
1765 > void X11_monitor_desc::set_palette(uint8 *pal, int num_in)
1766   {
1767 +        const video_mode &mode = get_current_mode();
1768 +
1769          LOCK_PALETTE;
1770  
1771          // Convert colors to XColor array
1772          int num_out = 256;
1773          bool stretch = false;
1774 <        if (IsDirectMode(VideoMonitor.mode)) {
1774 >        if (IsDirectMode(mode)) {
1775                  // If X is in 565 mode we have to stretch the gamma table from 32 to 64 entries
1776                  num_out = vis->map_entries;
1777                  stretch = true;
1778          }
1779 <        XColor *p = palette;
1779 >        XColor *p = x_palette;
1780          for (int i=0; i<num_out; i++) {
1781                  int c = (stretch ? (i * num_in) / num_out : i);
1782                  p->red = pal[c*3 + 0] * 0x0101;
# Line 1758 | Line 1787 | void video_set_palette(uint8 *pal, int n
1787  
1788   #ifdef ENABLE_VOSF
1789          // Recalculate pixel color expansion map
1790 <        if (!IsDirectMode(VideoMonitor.mode) && xdepth > 8) {
1790 >        if (!IsDirectMode(mode) && xdepth > 8) {
1791                  for (int i=0; i<256; i++) {
1792                          int c = i & (num_in-1); // If there are less than 256 colors, we repeat the first entries (this makes color expansion easier)
1793                          ExpandMap[i] = map_rgb(pal[c*3+0], pal[c*3+1], pal[c*3+2]);
# Line 1768 | Line 1797 | void video_set_palette(uint8 *pal, int n
1797                  LOCK_VOSF;
1798                  PFLAG_SET_ALL;
1799                  UNLOCK_VOSF;
1800 <                memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y);
1800 >                memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y);
1801          }
1802   #endif
1803  
1804          // Tell redraw thread to change palette
1805 <        palette_changed = true;
1805 >        x_palette_changed = true;
1806  
1807          UNLOCK_PALETTE;
1808   }
# Line 1783 | Line 1812 | void video_set_palette(uint8 *pal, int n
1812   *  Switch video mode
1813   */
1814  
1815 < void video_switch_to_mode(const video_mode &mode)
1815 > void X11_monitor_desc::switch_to_current_mode(void)
1816   {
1817          // Close and reopen display
1818          video_close();
1819 <        video_open(mode);
1819 >        video_open();
1820  
1821          if (drv == NULL) {
1822                  ErrorAlert(STR_OPEN_WINDOW_ERR);
# Line 2057 | Line 2086 | static void handle_events(void)
2086                          // Hidden parts exposed, force complete refresh of window
2087                          case Expose:
2088                                  if (display_type == DISPLAY_WINDOW) {
2089 +                                        const video_mode &mode = VideoMonitors[0]->get_current_mode();
2090   #ifdef ENABLE_VOSF
2091                                          if (use_vosf) {                 // VOSF refresh
2092                                                  LOCK_VOSF;
2093                                                  PFLAG_SET_ALL;
2094                                                  UNLOCK_VOSF;
2095 <                                                memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y);
2095 >                                                memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y);
2096                                          }
2097                                          else
2098   #endif
# Line 2073 | Line 2103 | static void handle_events(void)
2103                                                          updt_box[x1][y1] = true;
2104                                                  nr_boxes = 16 * 16;
2105                                          } else                                  // Static refresh
2106 <                                                memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y);
2106 >                                                memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y);
2107                                  }
2108                                  break;
2109  
# Line 2099 | Line 2129 | static void update_display_dynamic(int t
2129          int y1, y2, y2s, y2a, i, x1, xm, xmo, ymo, yo, yi, yil, xi;
2130          int xil = 0;
2131          int rxm = 0, rxmo = 0;
2132 <        int bytes_per_row = VideoMonitor.mode.bytes_per_row;
2133 <        int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x;
2134 <        int rx = VideoMonitor.mode.bytes_per_row / 16;
2135 <        int ry = VideoMonitor.mode.y / 16;
2132 >        const video_mode &mode = drv->monitor.get_current_mode();
2133 >        int bytes_per_row = mode.bytes_per_row;
2134 >        int bytes_per_pixel = mode.bytes_per_row / mode.x;
2135 >        int rx = mode.bytes_per_row / 16;
2136 >        int ry = mode.y / 16;
2137          int max_box;
2138  
2139          y2s = sm_uptd[ticker % 8];
# Line 2156 | Line 2187 | static void update_display_dynamic(int t
2187                                          i = (yi * bytes_per_row) + xi;
2188                                          for (y2=0; y2 < yil; y2++, i += bytes_per_row)
2189                                                  memcpy(&the_buffer_copy[i], &the_buffer[i], xil);
2190 <                                        if (VideoMonitor.mode.depth == VDEPTH_1BIT) {
2190 >                                        if (mode.depth == VDEPTH_1BIT) {
2191                                                  if (drv->have_shm)
2192                                                          XShmPutImage(x_display, drv->w, drv->gc, drv->img, xi * 8, yi, xi * 8, yi, xil * 8, yil, 0);
2193                                                  else
# Line 2188 | Line 2219 | static void update_display_static(driver
2219   {
2220          // Incremental update code
2221          unsigned wide = 0, high = 0, x1, x2, y1, y2, i, j;
2222 <        int bytes_per_row = VideoMonitor.mode.bytes_per_row;
2223 <        int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x;
2222 >        const video_mode &mode = drv->monitor.get_current_mode();
2223 >        int bytes_per_row = mode.bytes_per_row;
2224 >        int bytes_per_pixel = mode.bytes_per_row / mode.x;
2225          uint8 *p, *p2;
2226  
2227          // Check for first line from top and first line from bottom that have changed
2228          y1 = 0;
2229 <        for (j=0; j<VideoMonitor.mode.y; j++) {
2229 >        for (j=0; j<mode.y; j++) {
2230                  if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) {
2231                          y1 = j;
2232                          break;
2233                  }
2234          }
2235          y2 = y1 - 1;
2236 <        for (j=VideoMonitor.mode.y-1; j>=y1; j--) {
2236 >        for (j=mode.y-1; j>=y1; j--) {
2237                  if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) {
2238                          y2 = j;
2239                          break;
# Line 2211 | Line 2243 | static void update_display_static(driver
2243  
2244          // Check for first column from left and first column from right that have changed
2245          if (high) {
2246 <                if (VideoMonitor.mode.depth == VDEPTH_1BIT) {
2247 <                        x1 = VideoMonitor.mode.x - 1;
2246 >                if (mode.depth == VDEPTH_1BIT) {
2247 >                        x1 = mode.x - 1;
2248                          for (j=y1; j<=y2; j++) {
2249                                  p = &the_buffer[j * bytes_per_row];
2250                                  p2 = &the_buffer_copy[j * bytes_per_row];
# Line 2230 | Line 2262 | static void update_display_static(driver
2262                                  p2 = &the_buffer_copy[j * bytes_per_row];
2263                                  p += bytes_per_row;
2264                                  p2 += bytes_per_row;
2265 <                                for (i=(VideoMonitor.mode.x>>3); i>(x2>>3); i--) {
2265 >                                for (i=(mode.x>>3); i>(x2>>3); i--) {
2266                                          p--; p2--;
2267                                          if (*p != *p2) {
2268                                                  x2 = (i << 3) + 7;
# Line 2249 | Line 2281 | static void update_display_static(driver
2281                          }
2282  
2283                  } else {
2284 <                        x1 = VideoMonitor.mode.x;
2284 >                        x1 = mode.x;
2285                          for (j=y1; j<=y2; j++) {
2286                                  p = &the_buffer[j * bytes_per_row];
2287                                  p2 = &the_buffer_copy[j * bytes_per_row];
# Line 2267 | Line 2299 | static void update_display_static(driver
2299                                  p2 = &the_buffer_copy[j * bytes_per_row];
2300                                  p += bytes_per_row;
2301                                  p2 += bytes_per_row;
2302 <                                for (i=VideoMonitor.mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) {
2302 >                                for (i=mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) {
2303                                          p--;
2304                                          p2--;
2305                                          if (*p != *p2) {
# Line 2334 | Line 2366 | static inline void handle_palette_change
2366   {
2367          LOCK_PALETTE;
2368  
2369 <        if (palette_changed) {
2370 <                palette_changed = false;
2369 >        if (x_palette_changed) {
2370 >                x_palette_changed = false;
2371                  drv->update_palette();
2372          }
2373  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines