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.28 by cebix, 2000-11-03T12:23:49Z

# 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 326 | Line 336 | static bool init_window(int width, int h
336          XSetWindowAttributes wattr;
337          wattr.event_mask = eventmask = win_eventmask;
338          wattr.background_pixel = black_pixel;
329        wattr.border_pixel = black_pixel;
330        wattr.backing_store = NotUseful;
331        wattr.save_under = false;
332        wattr.backing_planes = xdepth;
339  
340          XSync(x_display, false);
341          the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
342 <                InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel |
337 <                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);
342 >                InputOutput, vis, CWEventMask | CWBackPixel, &wattr);
343  
344 <        // Set colormap
345 <        if (depth == 8) {
346 <                XSetWindowColormap(x_display, the_win, cmap[0]);
347 <                XSetWMColormapWindows(x_display, the_win, &the_win, 1);
344 >        // Indicate that we want keyboard input
345 >        {
346 >                XWMHints *hints = XAllocWMHints();
347 >                if (hints) {
348 >                        hints->input = True;
349 >                        hints->flags = InputHint;
350 >                        XSetWMHints(x_display, the_win, hints);
351 >                        XFree((char *)hints);
352 >                }
353          }
354  
355          // Make window unresizable
356 <        XSizeHints *hints;
357 <        if ((hints = XAllocSizeHints()) != NULL) {
358 <                hints->min_width = width;
359 <                hints->max_width = width;
360 <                hints->min_height = height;
361 <                hints->max_height = height;
362 <                hints->flags = PMinSize | PMaxSize;
363 <                XSetWMNormalHints(x_display, the_win, hints);
364 <                XFree((char *)hints);
356 >        {
357 >                XSizeHints *hints = XAllocSizeHints();
358 >                if (hints) {
359 >                        hints->min_width = width;
360 >                        hints->max_width = width;
361 >                        hints->min_height = height;
362 >                        hints->max_height = height;
363 >                        hints->flags = PMinSize | PMaxSize;
364 >                        XSetWMNormalHints(x_display, the_win, hints);
365 >                        XFree((char *)hints);
366 >                }
367          }
368          
369 +        // Set window title
370 +        XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE));
371 +
372 +        // Set window class
373 +        {
374 +                XClassHint *hints;
375 +                hints = XAllocClassHint();
376 +                if (hints) {
377 +                        hints->res_name = "BasiliskII";
378 +                        hints->res_class = "BasiliskII";
379 +                        XSetClassHint(x_display, the_win, hints);
380 +                        XFree((char *)hints);
381 +                }
382 +        }
383 +
384 +        // Show window
385 +        XSync(x_display, false);
386 +        XMapRaised(x_display, the_win);
387 +        XFlush(x_display);
388 +
389 +        // Set colormap
390 +        if (depth == 8)
391 +                XSetWindowColormap(x_display, the_win, cmap[0]);
392 +
393          // Try to create and attach SHM image
394          have_shm = false;
395          if (depth != 1 && local_X11 && XShmQueryExtension(x_display)) {
# Line 529 | Line 561 | static bool init_fbdev_dga(char *in_fb_n
561          
562          // Create window
563          XSetWindowAttributes wattr;
532        wattr.override_redirect = True;
533        wattr.backing_store             = NotUseful;
534        wattr.background_pixel  = white_pixel;
535        wattr.border_pixel              = black_pixel;
564          wattr.event_mask                = eventmask = dga_eventmask;
565 +        wattr.background_pixel  = white_pixel;
566 +        wattr.override_redirect = True;
567          
568          XSync(x_display, false);
569          the_win = XCreateWindow(x_display, rootwin,
570                  0, 0, width, height,
571                  0, xdepth, InputOutput, vis,
572 <                CWEventMask|CWBackPixel|CWBorderPixel|CWOverrideRedirect|CWBackingStore,
572 >                CWEventMask | CWBackPixel | CWOverrideRedirect,
573                  &wattr);
574          XSync(x_display, false);
575          XMapRaised(x_display, the_win);
# Line 553 | Line 583 | static bool init_fbdev_dga(char *in_fb_n
583                  GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime);
584          
585          // Set colormap
586 <        if (depth == 8) {
586 >        if (depth == 8)
587                  XSetWindowColormap(x_display, the_win, cmap[0]);
558                XSetWMColormapWindows(x_display, the_win, &the_win, 1);
559        }
588          
589          // Set VideoMonitor
590          int bytes_per_row = width;
# Line 583 | Line 611 | static bool init_fbdev_dga(char *in_fb_n
611                  }
612          }
613          
614 + #if ENABLE_VOSF
615   #if REAL_ADDRESSING || DIRECT_ADDRESSING
616          // If the blit function is null, i.e. just a copy of the buffer,
617          // we first try to avoid the allocation of a temporary frame buffer
# Line 599 | Line 628 | static bool init_fbdev_dga(char *in_fb_n
628                  the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size);
629                  memset(the_buffer, 0, the_buffer_size);
630          }
631 < #elif ENABLE_VOSF
631 > #else
632          use_vosf = false;
633   #endif
634 + #endif
635          
636          set_video_monitor(width, height, bytes_per_row, true);
637   #if REAL_ADDRESSING || DIRECT_ADDRESSING
# Line 641 | Line 671 | static bool init_xf86_dga(int width, int
671          // Create window
672          XSetWindowAttributes wattr;
673          wattr.event_mask = eventmask = dga_eventmask;
644        wattr.border_pixel = black_pixel;
674          wattr.override_redirect = True;
675  
676          XSync(x_display, false);
677          the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
678 <                InputOutput, vis, CWEventMask | CWBorderPixel | CWOverrideRedirect, &wattr);
678 >                InputOutput, vis, CWEventMask | CWOverrideRedirect, &wattr);
679          XSync(x_display, false);
680          XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE));
681          XMapRaised(x_display, the_win);
# Line 667 | Line 696 | static bool init_xf86_dga(int width, int
696          // Set colormap
697          if (depth == 8) {
698                  XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]);
670                XSetWMColormapWindows(x_display, the_win, &the_win, 1);
699                  XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
700          }
701  
# Line 703 | Line 731 | static bool init_xf86_dga(int width, int
731                  the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size);
732                  memset(the_buffer, 0, the_buffer_size);
733          }
734 < #elif ENABLE_VOSF
734 > #elif defined(ENABLE_VOSF)
735          // The UAE memory handlers will already handle color conversion, if needed.
736          use_vosf = false;
737   #endif
# Line 802 | Line 830 | bool VideoInitBuffer()
830  
831                  mainBuffer.pageSize     = page_size;
832                  mainBuffer.pageCount    = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize;
833 <                mainBuffer.pageBits     = int( log(mainBuffer.pageSize) / log(2.0) );
833 >                mainBuffer.pageBits     = log_base_2(mainBuffer.pageSize);
834  
835                  if (mainBuffer.dirtyPages != 0)
836                          free(mainBuffer.dirtyPages);
# Line 1197 | Line 1225 | void VideoInterrupt(void)
1225  
1226   void video_set_palette(uint8 *pal)
1227   {
1228 < #ifdef HAVE_PTHREDS
1228 > #ifdef HAVE_PTHREADS
1229          pthread_mutex_lock(&palette_lock);
1230   #endif
1231  
# Line 1254 | Line 1282 | static void suspend_emul(void)
1282                  XSetWindowAttributes wattr;
1283                  wattr.event_mask = KeyPressMask;
1284                  wattr.background_pixel = black_pixel;
1285 <                wattr.border_pixel = black_pixel;
1258 <                wattr.backing_store = Always;
1285 >                wattr.backing_store = WhenMapped;
1286                  wattr.backing_planes = xdepth;
1287                  wattr.colormap = DefaultColormap(x_display, screen);
1288                  
1289                  XSync(x_display, false);
1290                  suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth,
1291 <                        InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel |
1292 <                        CWBackingStore | CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr);
1291 >                        InputOutput, vis, CWEventMask | CWBackPixel | CWBackingStore |
1292 >                        CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr);
1293                  XSync(x_display, false);
1294                  XStoreName(x_display, suspend_win, GetString(STR_SUSPEND_WINDOW_TITLE));
1295                  XMapRaised(x_display, suspend_win);
# Line 1288 | Line 1315 | static void resume_emul(void)
1315          XF86DGASetViewPort(x_display, screen, 0, 0);
1316   #endif
1317          XSync(x_display, false);
1318 <
1319 <        // Restore frame buffer
1320 <        if (fb_save) {
1321 < #if REAL_ADDRESSING || DIRECT_ADDRESSING
1322 <                if (use_vosf)
1323 <                        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);
1318 >        
1319 >        // the_buffer already contains the data to restore. i.e. since a temporary
1320 >        // frame buffer is used when VOSF is actually used, fb_save is therefore
1321 >        // not necessary.
1322 > #ifdef ENABLE_VOSF
1323 >        if (use_vosf) {
1324   #ifdef HAVE_PTHREADS
1325 <                        pthread_mutex_lock(&Screen_draw_lock);
1325 >                pthread_mutex_lock(&Screen_draw_lock);
1326   #endif
1327 <                        PFLAG_CLEAR_ALL;
1327 >                PFLAG_SET_ALL;
1328   #ifdef HAVE_PTHREADS
1329 <                        pthread_mutex_unlock(&Screen_draw_lock);
1329 >                pthread_mutex_unlock(&Screen_draw_lock);
1330   #endif
1331 <                }
1331 >                memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
1332 >        }
1333   #endif
1334 +        
1335 +        // Restore frame buffer
1336 +        if (fb_save) {
1337 + #ifdef ENABLE_VOSF
1338 +                // Don't copy fb_save to the temporary frame buffer in VOSF mode
1339 +                if (!use_vosf)
1340 + #endif
1341 +                memcpy(the_buffer, fb_save, VideoMonitor.y * VideoMonitor.bytes_per_row);
1342                  free(fb_save);
1343                  fb_save = NULL;
1344          }
# Line 1589 | Line 1619 | static void handle_events(void)
1619                          // Hidden parts exposed, force complete refresh of window
1620                          case Expose:
1621                                  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 {
1622   #ifdef ENABLE_VOSF
1623 +                                        if (use_vosf) {                 // VOSF refresh
1624   #ifdef HAVE_PTHREADS
1625                                                  pthread_mutex_lock(&Screen_draw_lock);
1626   #endif
# Line 1604 | Line 1628 | static void handle_events(void)
1628   #ifdef HAVE_PTHREADS
1629                                                  pthread_mutex_unlock(&Screen_draw_lock);
1630   #endif
1607 #endif
1631                                                  memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
1632                                          }
1633 +                                        else
1634 + #endif
1635 +                                        if (frame_skip == 0) {  // Dynamic refresh
1636 +                                                int x1, y1;
1637 +                                                for (y1=0; y1<16; y1++)
1638 +                                                for (x1=0; x1<16; x1++)
1639 +                                                        updt_box[x1][y1] = true;
1640 +                                                nr_boxes = 16 * 16;
1641 +                                        } else                                  // Static refresh
1642 +                                                memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
1643                                  }
1644                                  break;
1645 +
1646 +                        case FocusIn:
1647 +                        case FocusOut:
1648 +                                break;
1649                  }
1650          }
1651   }
# Line 1737 | Line 1774 | static void update_display_static(void)
1774          // Check for first column from left and first column from right that have changed
1775          if (high) {
1776                  if (depth == 1) {
1777 <                        x1 = VideoMonitor.x;
1777 >                        x1 = VideoMonitor.x - 1;
1778                          for (j=y1; j<=y2; j++) {
1779                                  p = &the_buffer[j * bytes_per_row];
1780                                  p2 = &the_buffer_copy[j * bytes_per_row];
# Line 1758 | Line 1795 | static void update_display_static(void)
1795                                  for (i=(VideoMonitor.x>>3); i>(x2>>3); i--) {
1796                                          p--; p2--;
1797                                          if (*p != *p2) {
1798 <                                                x2 = i << 3;
1798 >                                                x2 = (i << 3) + 7;
1799                                                  break;
1800                                          }
1801                                  }
1802                          }
1803 <                        wide = x2 - x1;
1803 >                        wide = x2 - x1 + 1;
1804  
1805                          // Update copy of the_buffer
1806                          if (high && wide) {
# Line 1899 | Line 1936 | static void video_refresh_dga(void)
1936          handle_palette_changes(depth, DISPLAY_DGA);
1937   }
1938  
1939 + #ifdef ENABLE_VOSF
1940   #if REAL_ADDRESSING || DIRECT_ADDRESSING
1941   static void video_refresh_dga_vosf(void)
1942   {
# Line 1926 | Line 1964 | static void video_refresh_dga_vosf(void)
1964   }
1965   #endif
1966  
1929 #ifdef ENABLE_VOSF
1967   static void video_refresh_window_vosf(void)
1968   {
1969          // Quit DGA mode if requested
# Line 1951 | Line 1988 | static void video_refresh_window_vosf(vo
1988   #endif
1989          }
1990   }
1991 < #endif
1991 > #endif // def ENABLE_VOSF
1992  
1993   static void video_refresh_window_static(void)
1994   {
# Line 1992 | Line 2029 | void VideoRefreshInit(void)
2029   {
2030          // TODO: set up specialised 8bpp VideoRefresh handlers ?
2031          if (display_type == DISPLAY_DGA) {
2032 < #if REAL_ADDRESSING || DIRECT_ADDRESSING
2032 > #if ENABLE_VOSF && (REAL_ADDRESSING || DIRECT_ADDRESSING)
2033                  if (use_vosf)
2034                          video_refresh = video_refresh_dga_vosf;
2035                  else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines