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.20 by gbeauche, 2000-09-25T21:49:19Z vs.
Revision 1.27 by cebix, 2000-11-02T14:45:16Z

# Line 53 | Line 53
53   #endif
54  
55   #ifdef ENABLE_VOSF
56 # include <math.h> // log()
56   # include <unistd.h>
57   # include <signal.h>
58   # include <fcntl.h>
# Line 123 | Line 122 | static Colormap cmap[2];                                                       // Two co
122   static XColor black, white;
123   static unsigned long black_pixel, white_pixel;
124   static int eventmask;
125 < static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask;
125 > static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | FocusChangeMask | ExposureMask;
126   static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
127  
128   static XColor palette[256];                                                     // Color palette for 8-bit mode
# Line 219 | Line 218 | static struct sigaction vosf_sa;
218   static pthread_mutex_t Screen_draw_lock = PTHREAD_MUTEX_INITIALIZER;    // Mutex to protect frame buffer (dirtyPages in fact)
219   #endif
220  
221 + static int log_base_2(uint32 x)
222 + {
223 +        uint32 mask = 0x80000000;
224 +        int l = 31;
225 +        while (l >= 0 && (x & mask) == 0) {
226 +                mask >>= 1;
227 +                l--;
228 +        }
229 +        return l;
230 + }
231 +
232   #endif
233  
234   // VideoRefresh function
# Line 335 | Line 345 | static bool init_window(int width, int h
345          the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
346                  InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel |
347                  CWBackingStore | CWBackingPlanes, &wattr);
338        XSync(x_display, false);
339        XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE));
340        XMapRaised(x_display, the_win);
341        XSync(x_display, false);
348  
349 <        // Set colormap
350 <        if (depth == 8) {
351 <                XSetWindowColormap(x_display, the_win, cmap[0]);
352 <                XSetWMColormapWindows(x_display, the_win, &the_win, 1);
349 >        // Indicate that we want keyboard input
350 >        {
351 >                XWMHints *hints = XAllocWMHints();
352 >                if (hints) {
353 >                        hints->input = True;
354 >                        hints->flags = InputHint;
355 >                        XSetWMHints(x_display, the_win, hints);
356 >                        XFree((char *)hints);
357 >                }
358          }
359  
360          // Make window unresizable
361 <        XSizeHints *hints;
362 <        if ((hints = XAllocSizeHints()) != NULL) {
363 <                hints->min_width = width;
364 <                hints->max_width = width;
365 <                hints->min_height = height;
366 <                hints->max_height = height;
367 <                hints->flags = PMinSize | PMaxSize;
368 <                XSetWMNormalHints(x_display, the_win, hints);
369 <                XFree((char *)hints);
361 >        {
362 >                XSizeHints *hints = XAllocSizeHints();
363 >                if (hints) {
364 >                        hints->min_width = width;
365 >                        hints->max_width = width;
366 >                        hints->min_height = height;
367 >                        hints->max_height = height;
368 >                        hints->flags = PMinSize | PMaxSize;
369 >                        XSetWMNormalHints(x_display, the_win, hints);
370 >                        XFree((char *)hints);
371 >                }
372          }
373          
374 +        // Set window title
375 +        {
376 +                XTextProperty title_prop;
377 +                const char *title = GetString(STR_WINDOW_TITLE);
378 +                XStringListToTextProperty((char **)&title, 1, &title_prop);
379 +                XSetWMName(x_display, the_win, &title_prop);
380 +                XFree(title_prop.value);
381 +        }
382 +
383 +        // Set window class
384 +        {
385 +                XClassHint *hints;
386 +                hints = XAllocClassHint();
387 +                if (hints) {
388 +                        hints->res_name = "BasiliskII";
389 +                        hints->res_class = "BasiliskII";
390 +                        XSetClassHint(x_display, the_win, hints);
391 +                        XFree((char *)hints);
392 +                }
393 +        }
394 +
395 +        // Show window
396 +        XSync(x_display, false);
397 +        XMapRaised(x_display, the_win);
398 +        XFlush(x_display);
399 +
400 +        // Set colormap
401 +        if (depth == 8)
402 +                XSetWindowColormap(x_display, the_win, cmap[0]);
403 +
404          // Try to create and attach SHM image
405          have_shm = false;
406          if (depth != 1 && local_X11 && XShmQueryExtension(x_display)) {
# Line 553 | Line 596 | static bool init_fbdev_dga(char *in_fb_n
596                  GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime);
597          
598          // Set colormap
599 <        if (depth == 8) {
599 >        if (depth == 8)
600                  XSetWindowColormap(x_display, the_win, cmap[0]);
558                XSetWMColormapWindows(x_display, the_win, &the_win, 1);
559        }
601          
602          // Set VideoMonitor
603          int bytes_per_row = width;
# Line 583 | Line 624 | static bool init_fbdev_dga(char *in_fb_n
624                  }
625          }
626          
627 + #if ENABLE_VOSF
628   #if REAL_ADDRESSING || DIRECT_ADDRESSING
629          // If the blit function is null, i.e. just a copy of the buffer,
630          // we first try to avoid the allocation of a temporary frame buffer
# Line 599 | Line 641 | static bool init_fbdev_dga(char *in_fb_n
641                  the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size);
642                  memset(the_buffer, 0, the_buffer_size);
643          }
644 < #elif ENABLE_VOSF
644 > #else
645          use_vosf = false;
646   #endif
647 + #endif
648          
649          set_video_monitor(width, height, bytes_per_row, true);
650   #if REAL_ADDRESSING || DIRECT_ADDRESSING
# Line 667 | Line 710 | static bool init_xf86_dga(int width, int
710          // Set colormap
711          if (depth == 8) {
712                  XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]);
670                XSetWMColormapWindows(x_display, the_win, &the_win, 1);
713                  XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
714          }
715  
# Line 703 | Line 745 | static bool init_xf86_dga(int width, int
745                  the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size);
746                  memset(the_buffer, 0, the_buffer_size);
747          }
748 < #elif ENABLE_VOSF
748 > #elif defined(ENABLE_VOSF)
749          // The UAE memory handlers will already handle color conversion, if needed.
750          use_vosf = false;
751   #endif
# Line 802 | Line 844 | bool VideoInitBuffer()
844  
845                  mainBuffer.pageSize     = page_size;
846                  mainBuffer.pageCount    = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize;
847 <                mainBuffer.pageBits     = int( log(mainBuffer.pageSize) / log(2.0) );
847 >                mainBuffer.pageBits     = log_base_2(mainBuffer.pageSize);
848  
849                  if (mainBuffer.dirtyPages != 0)
850                          free(mainBuffer.dirtyPages);
# Line 1197 | Line 1239 | void VideoInterrupt(void)
1239  
1240   void video_set_palette(uint8 *pal)
1241   {
1242 < #ifdef HAVE_PTHREDS
1242 > #ifdef HAVE_PTHREADS
1243          pthread_mutex_lock(&palette_lock);
1244   #endif
1245  
# Line 1288 | Line 1330 | static void resume_emul(void)
1330          XF86DGASetViewPort(x_display, screen, 0, 0);
1331   #endif
1332          XSync(x_display, false);
1333 <
1334 <        // Restore frame buffer
1335 <        if (fb_save) {
1336 < #if REAL_ADDRESSING || DIRECT_ADDRESSING
1337 <                if (use_vosf)
1338 <                        mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ|PROT_WRITE);
1297 < #endif
1298 <                memcpy(the_buffer, fb_save, VideoMonitor.y * VideoMonitor.bytes_per_row);
1299 < #if REAL_ADDRESSING || DIRECT_ADDRESSING
1300 <                if (use_vosf) {
1301 <                        mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ);
1302 <                        do_update_framebuffer(the_host_buffer, the_buffer, VideoMonitor.x * VideoMonitor.bytes_per_row);
1333 >        
1334 >        // the_buffer already contains the data to restore. i.e. since a temporary
1335 >        // frame buffer is used when VOSF is actually used, fb_save is therefore
1336 >        // not necessary.
1337 > #ifdef ENABLE_VOSF
1338 >        if (use_vosf) {
1339   #ifdef HAVE_PTHREADS
1340 <                        pthread_mutex_lock(&Screen_draw_lock);
1340 >                pthread_mutex_lock(&Screen_draw_lock);
1341   #endif
1342 <                        PFLAG_CLEAR_ALL;
1342 >                PFLAG_SET_ALL;
1343   #ifdef HAVE_PTHREADS
1344 <                        pthread_mutex_unlock(&Screen_draw_lock);
1344 >                pthread_mutex_unlock(&Screen_draw_lock);
1345   #endif
1346 <                }
1346 >                memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
1347 >        }
1348   #endif
1349 +        
1350 +        // Restore frame buffer
1351 +        if (fb_save) {
1352 + #ifdef ENABLE_VOSF
1353 +                // Don't copy fb_save to the temporary frame buffer in VOSF mode
1354 +                if (!use_vosf)
1355 + #endif
1356 +                memcpy(the_buffer, fb_save, VideoMonitor.y * VideoMonitor.bytes_per_row);
1357                  free(fb_save);
1358                  fb_save = NULL;
1359          }
# Line 1589 | Line 1634 | static void handle_events(void)
1634                          // Hidden parts exposed, force complete refresh of window
1635                          case Expose:
1636                                  if (display_type == DISPLAY_WINDOW) {
1592                                        if (frame_skip == 0) {  // Dynamic refresh
1593                                                int x1, y1;
1594                                                for (y1=0; y1<16; y1++)
1595                                                for (x1=0; x1<16; x1++)
1596                                                        updt_box[x1][y1] = true;
1597                                                nr_boxes = 16 * 16;
1598                                        } else {
1637   #ifdef ENABLE_VOSF
1638 +                                        if (use_vosf) {                 // VOSF refresh
1639   #ifdef HAVE_PTHREADS
1640                                                  pthread_mutex_lock(&Screen_draw_lock);
1641   #endif
# Line 1604 | Line 1643 | static void handle_events(void)
1643   #ifdef HAVE_PTHREADS
1644                                                  pthread_mutex_unlock(&Screen_draw_lock);
1645   #endif
1607 #endif
1646                                                  memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
1647                                          }
1648 +                                        else
1649 + #endif
1650 +                                        if (frame_skip == 0) {  // Dynamic refresh
1651 +                                                int x1, y1;
1652 +                                                for (y1=0; y1<16; y1++)
1653 +                                                for (x1=0; x1<16; x1++)
1654 +                                                        updt_box[x1][y1] = true;
1655 +                                                nr_boxes = 16 * 16;
1656 +                                        } else                                  // Static refresh
1657 +                                                memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
1658                                  }
1659                                  break;
1660 +
1661 +                        case FocusIn:
1662 +                        case FocusOut:
1663 +                                break;
1664                  }
1665          }
1666   }
# Line 1737 | Line 1789 | static void update_display_static(void)
1789          // Check for first column from left and first column from right that have changed
1790          if (high) {
1791                  if (depth == 1) {
1792 <                        x1 = VideoMonitor.x;
1792 >                        x1 = VideoMonitor.x - 1;
1793                          for (j=y1; j<=y2; j++) {
1794                                  p = &the_buffer[j * bytes_per_row];
1795                                  p2 = &the_buffer_copy[j * bytes_per_row];
# Line 1758 | Line 1810 | static void update_display_static(void)
1810                                  for (i=(VideoMonitor.x>>3); i>(x2>>3); i--) {
1811                                          p--; p2--;
1812                                          if (*p != *p2) {
1813 <                                                x2 = i << 3;
1813 >                                                x2 = (i << 3) + 7;
1814                                                  break;
1815                                          }
1816                                  }
1817                          }
1818 <                        wide = x2 - x1;
1818 >                        wide = x2 - x1 + 1;
1819  
1820                          // Update copy of the_buffer
1821                          if (high && wide) {
# Line 1899 | Line 1951 | static void video_refresh_dga(void)
1951          handle_palette_changes(depth, DISPLAY_DGA);
1952   }
1953  
1954 + #ifdef ENABLE_VOSF
1955   #if REAL_ADDRESSING || DIRECT_ADDRESSING
1956   static void video_refresh_dga_vosf(void)
1957   {
# Line 1926 | Line 1979 | static void video_refresh_dga_vosf(void)
1979   }
1980   #endif
1981  
1929 #ifdef ENABLE_VOSF
1982   static void video_refresh_window_vosf(void)
1983   {
1984          // Quit DGA mode if requested
# Line 1951 | Line 2003 | static void video_refresh_window_vosf(vo
2003   #endif
2004          }
2005   }
2006 < #endif
2006 > #endif // def ENABLE_VOSF
2007  
2008   static void video_refresh_window_static(void)
2009   {
# Line 1992 | Line 2044 | void VideoRefreshInit(void)
2044   {
2045          // TODO: set up specialised 8bpp VideoRefresh handlers ?
2046          if (display_type == DISPLAY_DGA) {
2047 < #if REAL_ADDRESSING || DIRECT_ADDRESSING
2047 > #if ENABLE_VOSF && (REAL_ADDRESSING || DIRECT_ADDRESSING)
2048                  if (use_vosf)
2049                          video_refresh = video_refresh_dga_vosf;
2050                  else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines