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.18 by gbeauche, 2004-04-22T20:57:30Z vs.
Revision 1.34 by gbeauche, 2004-12-18T18:34:56Z

# Line 46 | Line 46
46   #include "about_window.h"
47   #include "video.h"
48   #include "video_defs.h"
49 + #include "video_blit.h"
50  
51   #define DEBUG 0
52   #include "debug.h"
# Line 57 | Line 58 | using std::sort;
58  
59   // Constants
60   const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes";
61 + static const bool hw_mac_cursor_accl = true;    // Flag: Enable MacOS to X11 copy of cursor?
62  
63   // Global variables
64   static int32 frame_skip;
# Line 64 | Line 66 | static int16 mouse_wheel_mode;
66   static int16 mouse_wheel_lines;
67   static bool redraw_thread_active = false;       // Flag: Redraw thread installed
68   static pthread_attr_t redraw_thread_attr;       // Redraw thread attributes
69 + static volatile bool redraw_thread_cancel;      // Flag: Cancel Redraw thread
70   static pthread_t redraw_thread;                         // Redraw thread
71  
72   static bool local_X11;                                          // Flag: X server running on local machine?
# Line 81 | Line 84 | static const bool use_vosf = false;                    //
84  
85   static bool palette_changed = false;            // Flag: Palette changed, redraw thread must update palette
86   static bool ctrl_down = false;                          // Flag: Ctrl key pressed
87 + static bool caps_on = false;                            // Flag: Caps Lock on
88   static bool quit_full_screen = false;           // Flag: DGA close requested from redraw thread
89   static volatile bool quit_full_screen_ack = false;      // Acknowledge for quit_full_screen
90   static bool emerg_quit = false;                         // Flag: Ctrl-Esc pressed, emergency quit requested from MacOS thread
# Line 98 | Line 102 | static int depth;                                                      // Depth of Mac
102   static Window rootwin, the_win;                         // Root window and our window
103   static int num_depths = 0;                                      // Number of available X depths
104   static int *avail_depths = NULL;                        // List of available X depths
105 + static VisualFormat visualFormat;
106   static XVisualInfo visualInfo;
107   static Visual *vis;
108   static int color_class;
# Line 498 | Line 503 | static bool open_window(int width, int h
503          the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line);
504          D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
505   #endif
506 <        screen_base = (uint32)the_buffer;
506 >        screen_base = Host2MacAddr(the_buffer);
507  
508          // Create GC
509          the_gc = XCreateGC(x_display, the_win, 0, 0);
510          XSetState(x_display, the_gc, black_pixel, white_pixel, GXcopy, AllPlanes);
511  
512          // Create cursor
513 <        cursor_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 4, 16, 16, 16, 2);
514 <        cursor_image->byte_order = MSBFirst;
515 <        cursor_image->bitmap_bit_order = MSBFirst;
516 <        cursor_mask_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 36, 16, 16, 16, 2);
517 <        cursor_mask_image->byte_order = MSBFirst;
518 <        cursor_mask_image->bitmap_bit_order = MSBFirst;
519 <        cursor_map = XCreatePixmap(x_display, the_win, 16, 16, 1);
520 <        cursor_mask_map = XCreatePixmap(x_display, the_win, 16, 16, 1);
521 <        cursor_gc = XCreateGC(x_display, cursor_map, 0, 0);
522 <        cursor_mask_gc = XCreateGC(x_display, cursor_mask_map, 0, 0);
523 <        mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, 0, 0);
524 <        cursor_changed = false;
513 >        if (hw_mac_cursor_accl) {
514 >                cursor_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 4, 16, 16, 16, 2);
515 >                cursor_image->byte_order = MSBFirst;
516 >                cursor_image->bitmap_bit_order = MSBFirst;
517 >                cursor_mask_image = XCreateImage(x_display, vis, 1, XYPixmap, 0, (char *)MacCursor + 36, 16, 16, 16, 2);
518 >                cursor_mask_image->byte_order = MSBFirst;
519 >                cursor_mask_image->bitmap_bit_order = MSBFirst;
520 >                cursor_map = XCreatePixmap(x_display, the_win, 16, 16, 1);
521 >                cursor_mask_map = XCreatePixmap(x_display, the_win, 16, 16, 1);
522 >                cursor_gc = XCreateGC(x_display, cursor_map, 0, 0);
523 >                cursor_mask_gc = XCreateGC(x_display, cursor_mask_map, 0, 0);
524 >                mac_cursor = XCreatePixmapCursor(x_display, cursor_map, cursor_mask_map, &black, &white, 0, 0);
525 >                cursor_changed = false;
526 >        }
527 >
528 >        // Create no_cursor
529 >        else {
530 >                mac_cursor = XCreatePixmapCursor(x_display,
531 >                        XCreatePixmap(x_display, the_win, 1, 1, 1),
532 >                        XCreatePixmap(x_display, the_win, 1, 1, 1),
533 >                        &black, &white, 0, 0);
534 >                XDefineCursor(x_display, the_win, mac_cursor);
535 >        }
536  
537          // Init blitting routines
538          bool native_byte_order;
# Line 526 | Line 542 | static bool open_window(int width, int h
542          native_byte_order = (XImageByteOrder(x_display) == LSBFirst);
543   #endif
544   #ifdef ENABLE_VOSF
545 <        Screen_blitter_init(&visualInfo, native_byte_order, depth);
545 >        Screen_blitter_init(visualFormat, native_byte_order, depth);
546   #endif
547  
548          // Set bytes per row
# Line 600 | Line 616 | static bool open_dga(int width, int heig
616   #if REAL_ADDRESSING || DIRECT_ADDRESSING
617          // Screen_blitter_init() returns TRUE if VOSF is mandatory
618          // i.e. the framebuffer update function is not Blit_Copy_Raw
619 <        use_vosf = Screen_blitter_init(&visualInfo, native_byte_order, depth);
619 >        use_vosf = Screen_blitter_init(visualFormat, native_byte_order, depth);
620          
621          if (use_vosf) {
622            // Allocate memory for frame buffer (SIZE is extended to page-boundary)
# Line 617 | Line 633 | static bool open_dga(int width, int heig
633  
634          // Set frame buffer base
635          D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf));
636 <        screen_base = (uint32)the_buffer;
636 >        screen_base = Host2MacAddr(the_buffer);
637          VModes[cur_mode].viRowBytes = bytes_per_row;
638          return true;
639   #else
# Line 637 | Line 653 | static bool open_display(void)
653                  return false;
654          }
655  
656 +        // Build up visualFormat structure
657 +        visualFormat.depth = visualInfo.depth;
658 +        visualFormat.Rmask = visualInfo.red_mask;
659 +        visualFormat.Gmask = visualInfo.green_mask;
660 +        visualFormat.Bmask = visualInfo.blue_mask;
661 +
662          // Create color maps
663          if (color_class == PseudoColor || color_class == DirectColor) {
664                  cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll);
# Line 870 | Line 892 | static void keycode_init(void)
892  
893                  // Search for server vendor string, then read keycodes
894                  const char *vendor = ServerVendor(x_display);
895 +                // Force use of MacX mappings on MacOS X with Apple's X server
896 +                int dummy;
897 +                if (XQueryExtension(x_display, "Apple-DRI", &dummy, &dummy, &dummy))
898 +                        vendor = "MacX";
899                  bool vendor_found = false;
900                  char line[256];
901                  while (fgets(line, 255, f)) {
# Line 1149 | Line 1175 | bool VideoInit(void)
1175                  if (apple_id != -1)
1176                          cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN);
1177          }
1178 <        if (cur_mode == -1)
1179 <                cur_mode = find_mode(default_mode, APPLE_W_640x480, DIS_WINDOW);
1178 >        if (cur_mode == -1) {
1179 >                // pick up first windowed mode available
1180 >                for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) {
1181 >                        if (p->viType == DIS_WINDOW && p->viAppleMode == default_mode) {
1182 >                                cur_mode = p - VModes;
1183 >                                break;
1184 >                        }
1185 >                }
1186 >        }
1187          assert(cur_mode != -1);
1188  
1189   #if DEBUG
# Line 1173 | Line 1206 | bool VideoInit(void)
1206          // Start periodic thread
1207          XSync(x_display, false);
1208          Set_pthread_attr(&redraw_thread_attr, 0);
1209 +        redraw_thread_cancel = false;
1210          redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0);
1211          D(bug("Redraw thread installed (%ld)\n", redraw_thread));
1212          return true;
# Line 1187 | Line 1221 | void VideoExit(void)
1221   {
1222          // Stop redraw thread
1223          if (redraw_thread_active) {
1224 +                redraw_thread_cancel = true;
1225                  pthread_cancel(redraw_thread);
1226                  pthread_join(redraw_thread, NULL);
1227                  redraw_thread_active = false;
# Line 1230 | Line 1265 | static void suspend_emul(void)
1265                  // Save frame buffer
1266                  fb_save = malloc(VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes);
1267                  if (fb_save)
1268 <                        memcpy(fb_save, (void *)screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes);
1268 >                        Mac2Host_memcpy(fb_save, screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes);
1269  
1270                  // Close full screen display
1271   #ifdef ENABLE_XF86_DGA
# Line 1292 | Line 1327 | static void resume_emul(void)
1327                  // Don't copy fb_save to the temporary frame buffer in VOSF mode
1328                  if (!use_vosf)
1329   #endif
1330 <                memcpy((void *)screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes);
1330 >                Host2Mac_memcpy(screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes);
1331                  free(fb_save);
1332                  fb_save = NULL;
1333          }
# Line 1465 | Line 1500 | static int kc_decode(KeySym ks)
1500          return -1;
1501   }
1502  
1503 < static int event2keycode(XKeyEvent &ev)
1503 > static int event2keycode(XKeyEvent &ev, bool key_down)
1504   {
1505          KeySym ks;
1471        int as;
1506          int i = 0;
1507  
1508          do {
1509                  ks = XLookupKeysym(&ev, i++);
1510 <                as = kc_decode(ks);
1511 <                if (as != -1)
1510 >                int as = kc_decode(ks);
1511 >                if (as >= 0)
1512 >                        return as;
1513 >                if (as == -2)
1514                          return as;
1515          } while (ks != NoSymbol);
1516  
# Line 1549 | Line 1585 | static void handle_events(void)
1585  
1586                          // Keyboard
1587                          case KeyPress: {
1588 <                                int code = event2keycode(event.xkey);
1589 <                                if (use_keycodes && code != -1)
1590 <                                        code = keycode_table[event.xkey.keycode & 0xff];
1591 <                                if (code != -1) {
1588 >                                int code = -1;
1589 >                                if (use_keycodes) {
1590 >                                        if (event2keycode(event.xkey, true) != -2)      // This is called to process the hotkeys
1591 >                                                code = keycode_table[event.xkey.keycode & 0xff];
1592 >                                } else
1593 >                                        code = event2keycode(event.xkey, true);
1594 >                                if (code >= 0) {
1595                                          if (!emul_suspended) {
1596 <                                                ADBKeyDown(code);
1596 >                                                if (code == 0x39) {     // Caps Lock pressed
1597 >                                                        if (caps_on) {
1598 >                                                                ADBKeyUp(code);
1599 >                                                                caps_on = false;
1600 >                                                        } else {
1601 >                                                                ADBKeyDown(code);
1602 >                                                                caps_on = true;
1603 >                                                        }
1604 >                                                } else
1605 >                                                        ADBKeyDown(code);
1606                                                  if (code == 0x36)
1607                                                          ctrl_down = true;
1608                                          } else {
# Line 1565 | Line 1613 | static void handle_events(void)
1613                                  break;
1614                          }
1615                          case KeyRelease: {
1616 <                                int code = event2keycode(event.xkey);
1617 <                                if (use_keycodes && code != 1)
1618 <                                        code = keycode_table[event.xkey.keycode & 0xff];
1619 <                                if (code != -1) {
1616 >                                int code = -1;
1617 >                                if (use_keycodes) {
1618 >                                        if (event2keycode(event.xkey, false) != -2)     // This is called to process the hotkeys
1619 >                                                code = keycode_table[event.xkey.keycode & 0xff];
1620 >                                } else
1621 >                                        code = event2keycode(event.xkey, false);
1622 >                                if (code >= 0 && code != 0x39) {        // Don't propagate Caps Lock releases
1623                                          ADBKeyUp(code);
1624                                          if (code == 0x36)
1625                                                  ctrl_down = false;
# Line 1608 | Line 1659 | void VideoVBL(void)
1659  
1660  
1661   /*
1611 *  Install graphics acceleration
1612 */
1613
1614 // Rectangle inversion
1615 template< int bpp >
1616 static inline void do_invrect(uint8 *dest, uint32 length)
1617 {
1618 #define INVERT_1(PTR, OFS) ((uint8  *)(PTR))[OFS] = ~((uint8  *)(PTR))[OFS]
1619 #define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS]
1620 #define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS]
1621 #define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS]
1622
1623 #ifndef UNALIGNED_PROFITABLE
1624        // Align on 16-bit boundaries
1625        if (bpp < 16 && (((uintptr)dest) & 1)) {
1626                INVERT_1(dest, 0);
1627                dest += 1; length -= 1;
1628        }
1629
1630        // Align on 32-bit boundaries
1631        if (bpp < 32 && (((uintptr)dest) & 2)) {
1632                INVERT_2(dest, 0);
1633                dest += 2; length -= 2;
1634        }
1635 #endif
1636
1637        // Invert 8-byte words
1638        if (length >= 8) {
1639                const int r = (length / 8) % 8;
1640                dest += r * 8;
1641
1642                int n = ((length / 8) + 7) / 8;
1643                switch (r) {
1644                case 0: do {
1645                                dest += 64;
1646                                INVERT_8(dest, -8);
1647                case 7: INVERT_8(dest, -7);
1648                case 6: INVERT_8(dest, -6);
1649                case 5: INVERT_8(dest, -5);
1650                case 4: INVERT_8(dest, -4);
1651                case 3: INVERT_8(dest, -3);
1652                case 2: INVERT_8(dest, -2);
1653                case 1: INVERT_8(dest, -1);
1654                                } while (--n > 0);
1655                }
1656        }
1657
1658        // 32-bit cell to invert?
1659        if (length & 4) {
1660                INVERT_4(dest, 0);
1661                if (bpp <= 16)
1662                        dest += 4;
1663        }
1664
1665        // 16-bit cell to invert?
1666        if (bpp <= 16 && (length & 2)) {
1667                INVERT_2(dest, 0);
1668                if (bpp <= 8)
1669                        dest += 2;
1670        }
1671
1672        // 8-bit cell to invert?
1673        if (bpp <= 8 && (length & 1))
1674                INVERT_1(dest, 0);
1675
1676 #undef INVERT_1
1677 #undef INVERT_2
1678 #undef INVERT_4
1679 #undef INVERT_8
1680 }
1681
1682 void NQD_invrect(uint32 arg)
1683 {
1684        D(bug("accl_invrect %08x\n", arg));
1685        accl_params *p = (accl_params *)arg;
1686
1687        // Get inversion parameters
1688        int16 dest_X = p->dest_rect[1] - p->dest_bounds[1];
1689        int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0];
1690        int16 width  = p->dest_rect[3] - p->dest_rect[1];
1691        int16 height = p->dest_rect[2] - p->dest_rect[0];
1692        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1693        D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, p->dest_row_bytes));
1694
1695        //!!?? pen_mode == 14
1696
1697        // And perform the inversion
1698        const int bpp = bytes_per_pixel(p->dest_pixel_size);
1699        const int dest_row_bytes = p->dest_row_bytes;
1700        uint8 *dest = (uint8 *)(p->dest_base_addr + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1701        width *= bpp;
1702        switch (bpp) {
1703        case 1:
1704                for (int i = 0; i < height; i++) {
1705                        do_invrect<8>(dest, width);
1706                        dest += dest_row_bytes;
1707                }
1708                break;
1709        case 2:
1710                for (int i = 0; i < height; i++) {
1711                        do_invrect<16>(dest, width);
1712                        dest += dest_row_bytes;
1713                }
1714                break;
1715        case 4:
1716                for (int i = 0; i < height; i++) {
1717                        do_invrect<32>(dest, width);
1718                        dest += dest_row_bytes;
1719                }
1720                break;
1721        }
1722 }
1723
1724 // Rectangle filling
1725 template< int bpp >
1726 static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length)
1727 {
1728 #define FILL_1(PTR, OFS, VAL) ((uint8  *)(PTR))[OFS] = (VAL)
1729 #define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL)
1730 #define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL)
1731 #define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL)
1732
1733 #ifndef UNALIGNED_PROFITABLE
1734        // Align on 16-bit boundaries
1735        if (bpp < 16 && (((uintptr)dest) & 1)) {
1736                FILL_1(dest, 0, color);
1737                dest += 1; length -= 1;
1738        }
1739
1740        // Align on 32-bit boundaries
1741        if (bpp < 32 && (((uintptr)dest) & 2)) {
1742                FILL_2(dest, 0, color);
1743                dest += 2; length -= 2;
1744        }
1745 #endif
1746
1747        // Fill 8-byte words
1748        if (length >= 8) {
1749                const uint64 c = (((uint64)color) << 32) | color;
1750                const int r = (length / 8) % 8;
1751                dest += r * 8;
1752
1753                int n = ((length / 8) + 7) / 8;
1754                switch (r) {
1755                case 0: do {
1756                                dest += 64;
1757                                FILL_8(dest, -8, c);
1758                case 7: FILL_8(dest, -7, c);
1759                case 6: FILL_8(dest, -6, c);
1760                case 5: FILL_8(dest, -5, c);
1761                case 4: FILL_8(dest, -4, c);
1762                case 3: FILL_8(dest, -3, c);
1763                case 2: FILL_8(dest, -2, c);
1764                case 1: FILL_8(dest, -1, c);
1765                                } while (--n > 0);
1766                }
1767        }
1768
1769        // 32-bit cell to fill?
1770        if (length & 4) {
1771                FILL_4(dest, 0, color);
1772                if (bpp <= 16)
1773                        dest += 4;
1774        }
1775
1776        // 16-bit cell to fill?
1777        if (bpp <= 16 && (length & 2)) {
1778                FILL_2(dest, 0, color);
1779                if (bpp <= 8)
1780                        dest += 2;
1781        }
1782
1783        // 8-bit cell to fill?
1784        if (bpp <= 8 && (length & 1))
1785                FILL_1(dest, 0, color);
1786
1787 #undef FILL_1
1788 #undef FILL_2
1789 #undef FILL_4
1790 #undef FILL_8
1791 }
1792
1793 void NQD_fillrect(uint32 arg)
1794 {
1795        D(bug("accl_fillrect %08x\n", arg));
1796        accl_params *p = (accl_params *)arg;
1797
1798        // Get filling parameters
1799        int16 dest_X = p->dest_rect[1] - p->dest_bounds[1];
1800        int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0];
1801        int16 width  = p->dest_rect[3] - p->dest_rect[1];
1802        int16 height = p->dest_rect[2] - p->dest_rect[0];
1803        uint32 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen;
1804        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1805        D(bug(" width %d, height %d\n", width, height));
1806        D(bug(" bytes_per_row %d color %08x\n", p->dest_row_bytes, color));
1807
1808        // And perform the fill
1809        const int bpp = bytes_per_pixel(p->dest_pixel_size);
1810        const int dest_row_bytes = p->dest_row_bytes;
1811        uint8 *dest = (uint8 *)(p->dest_base_addr + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1812        width *= bpp;
1813        switch (bpp) {
1814        case 1:
1815                for (int i = 0; i < height; i++) {
1816                        memset(dest, color, width);
1817                        dest += dest_row_bytes;
1818                }
1819                break;
1820        case 2:
1821                for (int i = 0; i < height; i++) {
1822                        do_fillrect<16>(dest, color, width);
1823                        dest += dest_row_bytes;
1824                }
1825                break;
1826        case 4:
1827                for (int i = 0; i < height; i++) {
1828                        do_fillrect<32>(dest, color, width);
1829                        dest += dest_row_bytes;
1830                }
1831                break;
1832        }
1833 }
1834
1835 bool NQD_fillrect_hook(uint32 arg)
1836 {
1837        D(bug("accl_fillrect_hook %08x\n", arg));
1838        accl_params *p = (accl_params *)arg;
1839
1840        // Check if we can accelerate this fillrect
1841        if (((uint32 *)p)[0x284 >> 2] != 0 && p->dest_pixel_size >= 8) {
1842                if (p->transfer_mode == 8) {
1843                        // Fill
1844                        p->draw_proc = NativeTVECT(NATIVE_FILLRECT);
1845                        return true;
1846                }
1847                else if (p->transfer_mode == 10) {
1848                        // Invert
1849                        p->draw_proc = NativeTVECT(NATIVE_INVRECT);
1850                        return true;
1851                }
1852        }
1853        return false;
1854 }
1855
1856 // Rectangle blitting
1857 // TODO: optimize for VOSF and target pixmap == screen
1858 void NQD_bitblt(uint32 arg)
1859 {
1860        D(bug("accl_bitblt %08x\n", arg));
1861        accl_params *p = (accl_params *)arg;
1862
1863        // Get blitting parameters
1864        int16 src_X = p->src_rect[1] - p->src_bounds[1];
1865        int16 src_Y = p->src_rect[0] - p->src_bounds[0];
1866        int16 dest_X = p->dest_rect[1] - p->dest_bounds[1];
1867        int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0];
1868        int16 width = p->dest_rect[3] - p->dest_rect[1];
1869        int16 height = p->dest_rect[2] - p->dest_rect[0];
1870        D(bug(" src addr %08x, dest addr %08x\n", p->src_base_addr, p->dest_base_addr));
1871        D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y));
1872        D(bug(" width %d, height %d\n", width, height));
1873
1874        // And perform the blit
1875        const int bpp = bytes_per_pixel(p->src_pixel_size);
1876        width *= bpp;
1877        if (p->src_row_bytes > 0) {
1878                const int src_row_bytes = p->src_row_bytes;
1879                const int dst_row_bytes = p->dest_row_bytes;
1880                uint8 *src = (uint8 *)p->src_base_addr + (src_Y * src_row_bytes) + (src_X * bpp);
1881                uint8 *dst = (uint8 *)p->dest_base_addr + (dest_Y * dst_row_bytes) + (dest_X * bpp);
1882                for (int i = 0; i < height; i++) {
1883                        memcpy(dst, src, width);
1884                        src += src_row_bytes;
1885                        dst += dst_row_bytes;
1886                }
1887        }
1888        else {
1889                const int src_row_bytes = -p->src_row_bytes;
1890                const int dst_row_bytes = -p->dest_row_bytes;
1891                uint8 *src = (uint8 *)p->src_base_addr + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp);
1892                uint8 *dst = (uint8 *)p->dest_base_addr + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp);
1893                for (int i = height - 1; i >= 0; i--) {
1894                        memcpy(dst, src, width);
1895                        src -= src_row_bytes;
1896                        dst -= dst_row_bytes;
1897                }
1898        }
1899 }
1900
1901 /*
1902  BitBlt transfer modes:
1903  0 : srcCopy
1904  1 : srcOr
1905  2 : srcXor
1906  3 : srcBic
1907  4 : notSrcCopy
1908  5 : notSrcOr
1909  6 : notSrcXor
1910  7 : notSrcBic
1911  32 : blend
1912  33 : addPin
1913  34 : addOver
1914  35 : subPin
1915  36 : transparent
1916  37 : adMax
1917  38 : subOver
1918  39 : adMin
1919  50 : hilite
1920 */
1921
1922 bool NQD_bitblt_hook(uint32 arg)
1923 {
1924        D(bug("accl_draw_hook %08x\n", arg));
1925        accl_params *p = (accl_params *)arg;
1926
1927        // Check if we can accelerate this bitblt
1928        if (((uint32 *)p)[0x18 >> 2] + ((uint32 *)p)[0x128 >> 2] == 0 &&
1929                ((uint32 *)p)[0x130 >> 2] == 0 &&
1930                p->src_pixel_size >= 8 && p->src_pixel_size == p->dest_pixel_size &&
1931                (p->src_row_bytes ^ p->dest_row_bytes) >= 0 &&  // same sign?
1932                p->transfer_mode == 0 &&                                                // srcCopy?
1933                ((uint32 *)p)[0x15c >> 2] > 0) {
1934
1935                // Yes, set function pointer
1936                p->draw_proc = NativeTVECT(NATIVE_BITBLT);
1937                return true;
1938        }
1939        return false;
1940 }
1941
1942 // Wait for graphics operation to finish
1943 bool NQD_sync_hook(uint32 arg)
1944 {
1945        D(bug("accl_sync_hook %08x\n", arg));
1946        return true;
1947 }
1948
1949 void VideoInstallAccel(void)
1950 {
1951        // Temporary hack until it's fixed for e.g. little-endian & 64-bit platforms
1952 #ifndef __powerpc__
1953        return;
1954 #endif
1955
1956        // Install acceleration hooks
1957        if (PrefsFindBool("gfxaccel")) {
1958                D(bug("Video: Installing acceleration hooks\n"));
1959                uint32 base;
1960
1961                SheepVar bitblt_hook_info(sizeof(accl_hook_info));
1962                base = bitblt_hook_info.addr();
1963                WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK));
1964                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
1965                WriteMacInt32(base + 8, ACCL_BITBLT);
1966                NQDMisc(6, bitblt_hook_info.ptr());
1967
1968                SheepVar fillrect_hook_info(sizeof(accl_hook_info));
1969                base = fillrect_hook_info.addr();
1970                WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK));
1971                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
1972                WriteMacInt32(base + 8, ACCL_FILLRECT);
1973                NQDMisc(6, fillrect_hook_info.ptr());
1974        }
1975 }
1976
1977
1978 /*
1662   *  Change video mode
1663   */
1664  
# Line 2078 | Line 1761 | void video_set_palette(void)
1761  
1762  
1763   /*
1764 + *  Can we set the MacOS cursor image into the window?
1765 + */
1766 +
1767 + bool video_can_change_cursor(void)
1768 + {
1769 +        return hw_mac_cursor_accl && (display_type != DIS_SCREEN);
1770 + }
1771 +
1772 +
1773 + /*
1774   *  Set cursor image for window
1775   */
1776  
# Line 2257 | Line 1950 | static void *redraw_func(void *arg)
1950          int64 ticks = 0;
1951          uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY;
1952  
1953 <        for (;;) {
1953 >        while (!redraw_thread_cancel) {
1954  
1955                  // Pause if requested (during video mode switches)
1956                  while (thread_stop_req)
# Line 2322 | Line 2015 | static void *redraw_func(void *arg)
2015                                                  update_display();
2016  
2017                                          // Set new cursor image if it was changed
2018 <                                        if (cursor_changed) {
2018 >                                        if (hw_mac_cursor_accl && cursor_changed) {
2019                                                  cursor_changed = false;
2020 <                                                memcpy(cursor_image->data, MacCursor + 4, 32);
2021 <                                                memcpy(cursor_mask_image->data, MacCursor + 36, 32);
2020 >                                                uint8 *x_data = (uint8 *)cursor_image->data;
2021 >                                                uint8 *x_mask = (uint8 *)cursor_mask_image->data;
2022 >                                                for (int i = 0; i < 32; i++) {
2023 >                                                        x_mask[i] = MacCursor[4 + i] | MacCursor[36 + i];
2024 >                                                        x_data[i] = MacCursor[4 + i];
2025 >                                                }
2026                                                  XDisplayLock();
2027                                                  XFreeCursor(x_display, mac_cursor);
2028                                                  XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines