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

Comparing SheepShaver/src/Unix/video_x.cpp (file contents):
Revision 1.9 by gbeauche, 2003-12-31T11:37:26Z vs.
Revision 1.10 by gbeauche, 2003-12-31T18:16:55Z

# Line 138 | Line 138 | extern void SysMountFirstFloppy(void);
138   // From clip_unix.cpp
139   extern void ClipboardSelectionClear(XSelectionClearEvent *);
140   extern void ClipboardSelectionRequest(XSelectionRequestEvent *);
141 extern void ClipboardSelectionNotify(XSelectionEvent *req);
141  
142  
143   // Video acceleration through SIGSEGV
# Line 1186 | Line 1185 | static void handle_events(void)
1185          for (;;) {
1186                  XEvent event;
1187  
1188 +                XDisplayLock();
1189                  if (!XCheckMaskEvent(x_display, eventmask, &event)) {
1190                          // Handle clipboard events
1191                          if (XCheckTypedEvent(x_display, SelectionRequest, &event))
1192                                  ClipboardSelectionRequest(&event.xselectionrequest);
1193                          else if (XCheckTypedEvent(x_display, SelectionClear, &event))
1194                                  ClipboardSelectionClear(&event.xselectionclear);
1195 <                        else if (XCheckTypedEvent(x_display, SelectionNotify, &event))
1196 <                                ClipboardSelectionNotify(&event.xselection);
1195 >
1196 >                        XDisplayUnlock();
1197                          break;
1198                  }
1199 +                XDisplayUnlock();
1200  
1201                  switch (event.type) {
1202                          // Mouse button
# Line 1622 | Line 1623 | static void update_display(void)
1623  
1624          // Refresh display
1625          if (high && wide) {
1626 +                XDisplayLock();
1627                  if (have_shm)
1628                          XShmPutImage(x_display, the_win, the_gc, img, x1, y1, x1, y1, wide, high, 0);
1629                  else
1630                          XPutImage(x_display, the_win, the_gc, img, x1, y1, x1, y1, wide, high);
1631 +                XDisplayUnlock();
1632          }
1633   }
1634  
1635 + const int VIDEO_REFRESH_HZ = 60;
1636 + const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ;
1637 +
1638   static void *redraw_func(void *arg)
1639   {
1640 <        int tick_counter = 0;
1635 <        struct timespec req = {0, 16666667};
1640 >        int fd = ConnectionNumber(x_display);
1641  
1642 <        for (;;) {
1642 >        uint64 start = GetTicks_usec();
1643 >        int64 ticks = 0;
1644 >        uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY;
1645  
1646 <                // Wait
1640 <                nanosleep(&req, NULL);
1646 >        for (;;) {
1647  
1648                  // Pause if requested (during video mode switches)
1649                  while (thread_stop_req)
1650                          thread_stop_ack = true;
1651  
1652 <                // Handle X11 events
1653 <                handle_events();
1652 >                int64 delay = next - GetTicks_usec();
1653 >                if (delay < -VIDEO_REFRESH_DELAY) {
1654 >
1655 >                        // We are lagging far behind, so we reset the delay mechanism
1656 >                        next = GetTicks_usec();
1657  
1658 <                // Quit DGA mode if requested
1659 <                if (quit_full_screen) {
1660 <                        quit_full_screen = false;
1661 <                        if (display_type == DIS_SCREEN) {
1658 >                } else if (delay <= 0) {
1659 >
1660 >                        // Delay expired, refresh display
1661 >                        next += VIDEO_REFRESH_DELAY;
1662 >                        ticks++;
1663 >
1664 >                        // Handle X11 events
1665 >                        handle_events();
1666 >
1667 >                        // Quit DGA mode if requested
1668 >                        if (quit_full_screen) {
1669 >                                quit_full_screen = false;
1670 >                                if (display_type == DIS_SCREEN) {
1671 >                                        XDisplayLock();
1672   #ifdef ENABLE_XF86_DGA
1673 <                                XF86DGADirectVideo(x_display, screen, 0);
1674 <                                XUngrabPointer(x_display, CurrentTime);
1675 <                                XUngrabKeyboard(x_display, CurrentTime);
1676 < #endif
1677 <                                XSync(x_display, false);
1678 <                                quit_full_screen_ack = true;
1679 <                                return NULL;
1673 >                                        XF86DGADirectVideo(x_display, screen, 0);
1674 >                                        XUngrabPointer(x_display, CurrentTime);
1675 >                                        XUngrabKeyboard(x_display, CurrentTime);
1676 > #endif
1677 >                                        XSync(x_display, false);
1678 >                                        XDisplayUnlock();
1679 >                                        quit_full_screen_ack = true;
1680 >                                        return NULL;
1681 >                                }
1682                          }
1662                }
1683  
1684 <                // Refresh display and set cursor image in window mode
1685 <                if (display_type == DIS_WINDOW) {
1686 <                        tick_counter++;
1687 <                        if (tick_counter >= frame_skip) {
1688 <                                tick_counter = 0;
1684 >                        // Refresh display and set cursor image in window mode
1685 >                        static int tick_counter = 0;
1686 >                        if (display_type == DIS_WINDOW) {
1687 >                                tick_counter++;
1688 >                                if (tick_counter >= frame_skip) {
1689 >                                        tick_counter = 0;
1690  
1691 <                                // Update display
1691 >                                        // Update display
1692   #ifdef ENABLE_VOSF
1693 <                                if (use_vosf) {
1694 <                                        if (mainBuffer.dirty) {
1695 <                                                LOCK_VOSF;
1696 <                                                update_display_window_vosf();
1697 <                                                UNLOCK_VOSF;
1698 <                                                XSync(x_display, false); // Let the server catch up
1693 >                                        if (use_vosf) {
1694 >                                                XDisplayLock();
1695 >                                                if (mainBuffer.dirty) {
1696 >                                                        LOCK_VOSF;
1697 >                                                        update_display_window_vosf();
1698 >                                                        UNLOCK_VOSF;
1699 >                                                        XSync(x_display, false); // Let the server catch up
1700 >                                                }
1701 >                                                XDisplayUnlock();
1702                                          }
1703 <                                }
1680 <                                else
1703 >                                        else
1704   #endif
1705 <                                        update_display();
1705 >                                                update_display();
1706  
1707 <                                // Set new cursor image if it was changed
1708 <                                if (cursor_changed) {
1709 <                                        cursor_changed = false;
1710 <                                        memcpy(cursor_image->data, MacCursor + 4, 32);
1711 <                                        memcpy(cursor_mask_image->data, MacCursor + 36, 32);
1712 <                                        XFreeCursor(x_display, mac_cursor);
1713 <                                        XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16);
1714 <                                        XPutImage(x_display, cursor_mask_map, cursor_mask_gc, cursor_mask_image, 0, 0, 0, 0, 16, 16);
1715 <                                        mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, MacCursor[2], MacCursor[3]);
1716 <                                        XDefineCursor(x_display, the_win, mac_cursor);
1707 >                                        // Set new cursor image if it was changed
1708 >                                        if (cursor_changed) {
1709 >                                                cursor_changed = false;
1710 >                                                memcpy(cursor_image->data, MacCursor + 4, 32);
1711 >                                                memcpy(cursor_mask_image->data, MacCursor + 36, 32);
1712 >                                                XDisplayLock();
1713 >                                                XFreeCursor(x_display, mac_cursor);
1714 >                                                XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16);
1715 >                                                XPutImage(x_display, cursor_mask_map, cursor_mask_gc, cursor_mask_image, 0, 0, 0, 0, 16, 16);
1716 >                                                mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, MacCursor[2], MacCursor[3]);
1717 >                                                XDefineCursor(x_display, the_win, mac_cursor);
1718 >                                                XDisplayUnlock();
1719 >                                        }
1720                                  }
1721                          }
1696                }
1722   #ifdef ENABLE_VOSF
1723 <                else if (use_vosf) {
1724 <                        // Update display (VOSF variant)
1725 <                        static int tick_counter = 0;
1726 <                        if (++tick_counter >= frame_skip) {
1727 <                                tick_counter = 0;
1728 <                                if (mainBuffer.dirty) {
1729 <                                        LOCK_VOSF;
1730 <                                        update_display_dga_vosf();
1731 <                                        UNLOCK_VOSF;
1723 >                        else if (use_vosf) {
1724 >                                // Update display (VOSF variant)
1725 >                                if (++tick_counter >= frame_skip) {
1726 >                                        tick_counter = 0;
1727 >                                        if (mainBuffer.dirty) {
1728 >                                                LOCK_VOSF;
1729 >                                                update_display_dga_vosf();
1730 >                                                UNLOCK_VOSF;
1731 >                                        }
1732                                  }
1733                          }
1709                }
1734   #endif
1735  
1736 <                // Set new palette if it was changed
1737 <                if (palette_changed && !emul_suspended) {
1738 <                        palette_changed = false;
1739 <                        XColor c[256];
1740 <                        for (int i=0; i<256; i++) {
1741 <                                c[i].pixel = i;
1742 <                                c[i].red = mac_pal[i].red * 0x0101;
1743 <                                c[i].green = mac_pal[i].green * 0x0101;
1744 <                                c[i].blue = mac_pal[i].blue * 0x0101;
1745 <                                c[i].flags = DoRed | DoGreen | DoBlue;
1722 <                        }
1723 <                        if (depth == 8) {
1724 <                                XStoreColors(x_display, cmap[0], c, 256);
1725 <                                XStoreColors(x_display, cmap[1], c, 256);
1726 < #ifdef ENABLE_XF86_DGA
1727 <                                if (display_type == DIS_SCREEN) {
1728 <                                        current_dga_cmap ^= 1;
1729 <                                        XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
1736 >                        // Set new palette if it was changed
1737 >                        if (palette_changed && !emul_suspended) {
1738 >                                palette_changed = false;
1739 >                                XColor c[256];
1740 >                                for (int i=0; i<256; i++) {
1741 >                                        c[i].pixel = i;
1742 >                                        c[i].red = mac_pal[i].red * 0x0101;
1743 >                                        c[i].green = mac_pal[i].green * 0x0101;
1744 >                                        c[i].blue = mac_pal[i].blue * 0x0101;
1745 >                                        c[i].flags = DoRed | DoGreen | DoBlue;
1746                                  }
1747 +                                if (depth == 8) {
1748 +                                        XDisplayLock();
1749 +                                        XStoreColors(x_display, cmap[0], c, 256);
1750 +                                        XStoreColors(x_display, cmap[1], c, 256);
1751 + #ifdef ENABLE_XF86_DGA
1752 +                                        if (display_type == DIS_SCREEN) {
1753 +                                                current_dga_cmap ^= 1;
1754 +                                                XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
1755 +                                        }
1756   #endif
1757 +                                        XDisplayUnlock();
1758 +                                }
1759                          }
1760 +
1761 +                } else {
1762 +
1763 +                        // No display refresh pending, check for X events
1764 +                        fd_set readfds;
1765 +                        FD_ZERO(&readfds);
1766 +                        FD_SET(fd, &readfds);
1767 +                        struct timeval timeout;
1768 +                        timeout.tv_sec = 0;
1769 +                        timeout.tv_usec = delay;
1770 +                        if (select(fd+1, &readfds, NULL, NULL, &timeout) > 0)
1771 +                                handle_events();
1772                  }
1773          }
1774          return NULL;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines