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.69 by gbeauche, 2003-05-22T22:13:56Z vs.
Revision 1.77 by gbeauche, 2005-03-21T23:57:34Z

# Line 1 | Line 1
1   /*
2   *  video_x.cpp - Video/graphics emulation, X11 specific stuff
3   *
4 < *  Basilisk II (C) 1997-2002 Christian Bauer
4 > *  Basilisk II (C) 1997-2005 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 62 | Line 62
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"
# Line 98 | Line 99 | static bool redraw_thread_active = false
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 volatile bool redraw_thread_cancel_ack;          // Flag: Acknowledge for redraw thread cancellation
103   static pthread_t redraw_thread;                                         // Redraw thread
104   #endif
105  
# Line 122 | Line 124 | static bool use_keycodes = false;                                      //
124   static int keycode_table[256];                                          // X keycode -> Mac keycode translation table
125  
126   // X11 variables
127 + char *x_display_name = NULL;                                            // X11 display name
128 + Display *x_display = NULL;                                                      // X11 display handle
129   static int screen;                                                                      // Screen number
130   static Window rootwin;                                                          // Root window and our window
131   static int num_depths = 0;                                                      // Number of available X depths
# Line 131 | Line 135 | static unsigned long black_pixel, white_
135   static int eventmask;
136  
137   static int xdepth;                                                                      // Depth of X screen
138 + static VisualFormat visualFormat;
139   static XVisualInfo visualInfo;
140   static Visual *vis;
141   static int color_class;
# Line 188 | Line 193 | static void *redraw_func(void *arg);
193   // From main_unix.cpp
194   extern char *x_display_name;
195   extern Display *x_display;
196 + extern void *vm_acquire_mac(size_t size);
197  
198   // From sys_unix.cpp
199   extern void SysMountFirstFloppy(void);
200  
201 + // From clip_unix.cpp
202 + extern void ClipboardSelectionClear(XSelectionClearEvent *);
203 + extern void ClipboardSelectionRequest(XSelectionRequestEvent *);
204 +
205  
206   /*
207   *  monitor_desc subclass for X11 display
# Line 726 | Line 736 | driver_window::driver_window(X11_monitor
736          // Allocate memory for frame buffer (SIZE is extended to page-boundary)
737          the_host_buffer = the_buffer_copy;
738          the_buffer_size = page_extend((aligned_height + 2) * img->bytes_per_line);
739 <        the_buffer = (uint8 *)vm_acquire(the_buffer_size);
739 >        the_buffer = (uint8 *)vm_acquire_mac(the_buffer_size);
740          the_buffer_copy = (uint8 *)malloc(the_buffer_size);
741          D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
742   #else
# Line 754 | Line 764 | driver_window::driver_window(X11_monitor
764          native_byte_order = (XImageByteOrder(x_display) == LSBFirst);
765   #endif
766   #ifdef ENABLE_VOSF
767 <        Screen_blitter_init(&visualInfo, native_byte_order, depth_of_video_mode(mode));
767 >        Screen_blitter_init(visualFormat, native_byte_order, depth_of_video_mode(mode));
768   #endif
769  
770          // Set frame buffer base
# Line 1115 | Line 1125 | driver_fbdev::driver_fbdev(X11_monitor_d
1125   #if REAL_ADDRESSING || DIRECT_ADDRESSING
1126          // Screen_blitter_init() returns TRUE if VOSF is mandatory
1127          // i.e. the framebuffer update function is not Blit_Copy_Raw
1128 <        use_vosf = Screen_blitter_init(&visualInfo, true, mode.depth);
1128 >        use_vosf = Screen_blitter_init(visualFormat, true, mode.depth);
1129          
1130          if (use_vosf) {
1131            // Allocate memory for frame buffer (SIZE is extended to page-boundary)
1132            the_host_buffer = the_buffer;
1133            the_buffer_size = page_extend((height + 2) * bytes_per_row);
1134            the_buffer_copy = (uint8 *)malloc(the_buffer_size);
1135 <          the_buffer = (uint8 *)vm_acquire(the_buffer_size);
1135 >          the_buffer = (uint8 *)vm_acquire_mac(the_buffer_size);
1136          }
1137   #else
1138          use_vosf = false;
# Line 1255 | Line 1265 | driver_xf86dga::driver_xf86dga(X11_monit
1265   #if REAL_ADDRESSING || DIRECT_ADDRESSING
1266          // Screen_blitter_init() returns TRUE if VOSF is mandatory
1267          // i.e. the framebuffer update function is not Blit_Copy_Raw
1268 <        use_vosf = Screen_blitter_init(&visualInfo, native_byte_order, depth_of_video_mode(mode));
1268 >        use_vosf = Screen_blitter_init(visualFormat, native_byte_order, depth_of_video_mode(mode));
1269          
1270          if (use_vosf) {
1271            // Allocate memory for frame buffer (SIZE is extended to page-boundary)
1272            the_host_buffer = the_buffer;
1273            the_buffer_size = page_extend((height + 2) * bytes_per_row);
1274            the_buffer_copy = (uint8 *)malloc(the_buffer_size);
1275 <          the_buffer = (uint8 *)vm_acquire(the_buffer_size);
1275 >          the_buffer = (uint8 *)vm_acquire_mac(the_buffer_size);
1276          }
1277   #else
1278          use_vosf = false;
# Line 1344 | Line 1354 | static void keycode_init(void)
1354  
1355                  // Search for server vendor string, then read keycodes
1356                  const char *vendor = ServerVendor(x_display);
1357 +                // Force use of MacX mappings on MacOS X with Apple's X server
1358 +                int dummy;
1359 +                if (XQueryExtension(x_display, "Apple-DRI", &dummy, &dummy, &dummy))
1360 +                        vendor = "MacX";
1361                  bool vendor_found = false;
1362                  char line[256];
1363                  while (fgets(line, 255, f)) {
# Line 1397 | Line 1411 | bool X11_monitor_desc::video_open(void)
1411                  return false;
1412          }
1413  
1414 +        // Build up visualFormat structure
1415 +        visualFormat.depth = visualInfo.depth;
1416 +        visualFormat.Rmask = visualInfo.red_mask;
1417 +        visualFormat.Gmask = visualInfo.green_mask;
1418 +        visualFormat.Bmask = visualInfo.blue_mask;
1419 +
1420          // Create color maps
1421          if (color_class == PseudoColor || color_class == DirectColor) {
1422                  cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll);
# Line 1701 | Line 1721 | void X11_monitor_desc::video_close(void)
1721   #ifdef HAVE_PTHREADS
1722          if (redraw_thread_active) {
1723                  redraw_thread_cancel = true;
1724 < #ifdef HAVE_PTHREAD_CANCEL
1705 <                pthread_cancel(redraw_thread);
1706 < #endif
1724 >                redraw_thread_cancel_ack = false;
1725                  pthread_join(redraw_thread, NULL);
1726 +                while (!redraw_thread_cancel_ack) ;
1727          }
1728   #endif
1729          redraw_thread_active = false;
# Line 2032 | Line 2051 | static int event2keycode(XKeyEvent &ev,
2051  
2052   static void handle_events(void)
2053   {
2054 <        while (XPending(x_display)) {
2054 >        for (;;) {
2055                  XEvent event;
2056 <                XNextEvent(x_display, &event);
2056 >                XDisplayLock();
2057  
2058 +                if (!XCheckMaskEvent(x_display, eventmask, &event)) {
2059 +                        // Handle clipboard events
2060 +                        if (XCheckTypedEvent(x_display, SelectionRequest, &event))
2061 +                                ClipboardSelectionRequest(&event.xselectionrequest);
2062 +                        else if (XCheckTypedEvent(x_display, SelectionClear, &event))
2063 +                                ClipboardSelectionClear(&event.xselectionclear);
2064 +
2065 +                        // Window "close" widget clicked
2066 +                        else if (XCheckTypedEvent(x_display, ClientMessage, &event)) {
2067 +                                if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW) {
2068 +                                        ADBKeyDown(0x7f);       // Power key
2069 +                                        ADBKeyUp(0x7f);
2070 +                                }
2071 +                        }
2072 +                        XDisplayUnlock();
2073 +                        break;
2074 +                }
2075 +                
2076                  switch (event.type) {
2077  
2078                          // Mouse button
# Line 2143 | Line 2180 | static void handle_events(void)
2180                                                  memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y);
2181                                  }
2182                                  break;
2146
2147                        // Window "close" widget clicked
2148                        case ClientMessage:
2149                                if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW) {
2150                                        ADBKeyDown(0x7f);       // Power key
2151                                        ADBKeyUp(0x7f);
2152                                }
2153                                break;
2183                  }
2184 +
2185 +                XDisplayUnlock();
2186          }
2187   }
2188  
# Line 2196 | Line 2227 | static void update_display_dynamic(int t
2227                  }
2228          }
2229  
2230 +        XDisplayLock();
2231          if ((nr_boxes <= max_box) && (nr_boxes)) {
2232                  for (y1=0; y1<16; y1++) {
2233                          for (x1=0; x1<16; x1++) {
# Line 2249 | Line 2281 | static void update_display_dynamic(int t
2281                  }
2282                  nr_boxes = 0;
2283          }
2284 +        XDisplayUnlock();
2285   }
2286  
2287   // Static display update (fixed frame rate, but incremental)
# Line 2358 | Line 2391 | static void update_display_static(driver
2391          }
2392  
2393          // Refresh display
2394 +        XDisplayLock();
2395          if (high && wide) {
2396                  if (drv->have_shm)
2397                          XShmPutImage(x_display, drv->w, drv->gc, drv->img, x1, y1, x1, y1, wide, high, 0);
2398                  else
2399                          XPutImage(x_display, drv->w, drv->gc, drv->img, x1, y1, x1, y1, wide, high);
2400          }
2401 +        XDisplayUnlock();
2402   }
2403  
2404  
# Line 2405 | Line 2440 | static inline void handle_palette_change
2440  
2441          if (x_palette_changed) {
2442                  x_palette_changed = false;
2443 +                XDisplayLock();
2444                  drv->update_palette();
2445 +                XDisplayUnlock();
2446          }
2447  
2448          UNLOCK_PALETTE;
# Line 2447 | Line 2484 | static void video_refresh_window_vosf(vo
2484          if (++tick_counter >= frame_skip) {
2485                  tick_counter = 0;
2486                  if (mainBuffer.dirty) {
2487 +                        XDisplayLock();
2488                          LOCK_VOSF;
2489                          update_display_window_vosf(static_cast<driver_window *>(drv));
2490                          UNLOCK_VOSF;
2491                          XSync(x_display, false); // Let the server catch up
2492 +                        XDisplayUnlock();
2493                  }
2494          }
2495   }
# Line 2572 | Line 2611 | static void *redraw_func(void *arg)
2611  
2612          uint64 end = GetTicks_usec();
2613          D(bug("%Ld refreshes in %Ld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start)));
2614 +
2615 +        redraw_thread_cancel_ack = true;
2616          return NULL;
2617   }
2618   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines