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.29 by gbeauche, 2004-06-22T20:01:18Z 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 101 | 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 501 | 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);
# Line 540 | 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 614 | 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 631 | 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 651 | 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 884 | Line 892 | static void keycode_init(void)
892  
893                  // Search for server vendor string, then read keycodes
894                  const char *vendor = ServerVendor(x_display);
887 #if (defined(__APPLE__) && defined(__MACH__))
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";
892 #endif
899                  bool vendor_found = false;
900                  char line[256];
901                  while (fgets(line, 255, f)) {
# Line 1259 | 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 1321 | 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 1653 | Line 1659 | void VideoVBL(void)
1659  
1660  
1661   /*
1656 *  Install graphics acceleration
1657 */
1658
1659 // Rectangle inversion
1660 template< int bpp >
1661 static inline void do_invrect(uint8 *dest, uint32 length)
1662 {
1663 #define INVERT_1(PTR, OFS) ((uint8  *)(PTR))[OFS] = ~((uint8  *)(PTR))[OFS]
1664 #define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS]
1665 #define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS]
1666 #define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS]
1667
1668 #ifndef UNALIGNED_PROFITABLE
1669        // Align on 16-bit boundaries
1670        if (bpp < 16 && (((uintptr)dest) & 1)) {
1671                INVERT_1(dest, 0);
1672                dest += 1; length -= 1;
1673        }
1674
1675        // Align on 32-bit boundaries
1676        if (bpp < 32 && (((uintptr)dest) & 2)) {
1677                INVERT_2(dest, 0);
1678                dest += 2; length -= 2;
1679        }
1680 #endif
1681
1682        // Invert 8-byte words
1683        if (length >= 8) {
1684                const int r = (length / 8) % 8;
1685                dest += r * 8;
1686
1687                int n = ((length / 8) + 7) / 8;
1688                switch (r) {
1689                case 0: do {
1690                                dest += 64;
1691                                INVERT_8(dest, -8);
1692                case 7: INVERT_8(dest, -7);
1693                case 6: INVERT_8(dest, -6);
1694                case 5: INVERT_8(dest, -5);
1695                case 4: INVERT_8(dest, -4);
1696                case 3: INVERT_8(dest, -3);
1697                case 2: INVERT_8(dest, -2);
1698                case 1: INVERT_8(dest, -1);
1699                                } while (--n > 0);
1700                }
1701        }
1702
1703        // 32-bit cell to invert?
1704        if (length & 4) {
1705                INVERT_4(dest, 0);
1706                if (bpp <= 16)
1707                        dest += 4;
1708        }
1709
1710        // 16-bit cell to invert?
1711        if (bpp <= 16 && (length & 2)) {
1712                INVERT_2(dest, 0);
1713                if (bpp <= 8)
1714                        dest += 2;
1715        }
1716
1717        // 8-bit cell to invert?
1718        if (bpp <= 8 && (length & 1))
1719                INVERT_1(dest, 0);
1720
1721 #undef INVERT_1
1722 #undef INVERT_2
1723 #undef INVERT_4
1724 #undef INVERT_8
1725 }
1726
1727 void NQD_invrect(uint32 p)
1728 {
1729        D(bug("accl_invrect %08x\n", p));
1730
1731        // Get inversion parameters
1732        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1733        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1734        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1735        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1736        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1737        D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes)));
1738
1739        //!!?? pen_mode == 14
1740
1741        // And perform the inversion
1742        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize));
1743        const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1744        uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1745        width *= bpp;
1746        switch (bpp) {
1747        case 1:
1748                for (int i = 0; i < height; i++) {
1749                        do_invrect<8>(dest, width);
1750                        dest += dest_row_bytes;
1751                }
1752                break;
1753        case 2:
1754                for (int i = 0; i < height; i++) {
1755                        do_invrect<16>(dest, width);
1756                        dest += dest_row_bytes;
1757                }
1758                break;
1759        case 4:
1760                for (int i = 0; i < height; i++) {
1761                        do_invrect<32>(dest, width);
1762                        dest += dest_row_bytes;
1763                }
1764                break;
1765        }
1766 }
1767
1768 // Rectangle filling
1769 template< int bpp >
1770 static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length)
1771 {
1772 #define FILL_1(PTR, OFS, VAL) ((uint8  *)(PTR))[OFS] = (VAL)
1773 #define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL)
1774 #define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL)
1775 #define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL)
1776
1777 #ifndef UNALIGNED_PROFITABLE
1778        // Align on 16-bit boundaries
1779        if (bpp < 16 && (((uintptr)dest) & 1)) {
1780                FILL_1(dest, 0, color);
1781                dest += 1; length -= 1;
1782        }
1783
1784        // Align on 32-bit boundaries
1785        if (bpp < 32 && (((uintptr)dest) & 2)) {
1786                FILL_2(dest, 0, color);
1787                dest += 2; length -= 2;
1788        }
1789 #endif
1790
1791        // Fill 8-byte words
1792        if (length >= 8) {
1793                const uint64 c = (((uint64)color) << 32) | color;
1794                const int r = (length / 8) % 8;
1795                dest += r * 8;
1796
1797                int n = ((length / 8) + 7) / 8;
1798                switch (r) {
1799                case 0: do {
1800                                dest += 64;
1801                                FILL_8(dest, -8, c);
1802                case 7: FILL_8(dest, -7, c);
1803                case 6: FILL_8(dest, -6, c);
1804                case 5: FILL_8(dest, -5, c);
1805                case 4: FILL_8(dest, -4, c);
1806                case 3: FILL_8(dest, -3, c);
1807                case 2: FILL_8(dest, -2, c);
1808                case 1: FILL_8(dest, -1, c);
1809                                } while (--n > 0);
1810                }
1811        }
1812
1813        // 32-bit cell to fill?
1814        if (length & 4) {
1815                FILL_4(dest, 0, color);
1816                if (bpp <= 16)
1817                        dest += 4;
1818        }
1819
1820        // 16-bit cell to fill?
1821        if (bpp <= 16 && (length & 2)) {
1822                FILL_2(dest, 0, color);
1823                if (bpp <= 8)
1824                        dest += 2;
1825        }
1826
1827        // 8-bit cell to fill?
1828        if (bpp <= 8 && (length & 1))
1829                FILL_1(dest, 0, color);
1830
1831 #undef FILL_1
1832 #undef FILL_2
1833 #undef FILL_4
1834 #undef FILL_8
1835 }
1836
1837 void NQD_fillrect(uint32 p)
1838 {
1839        D(bug("accl_fillrect %08x\n", p));
1840
1841        // Get filling parameters
1842        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1843        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1844        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1845        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1846        uint32 color = htonl(ReadMacInt32(p + acclPenMode) == 8 ? ReadMacInt32(p + acclForePen) : ReadMacInt32(p + acclBackPen));
1847        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1848        D(bug(" width %d, height %d\n", width, height));
1849        D(bug(" bytes_per_row %d color %08x\n", (int32)ReadMacInt32(p + acclDestRowBytes), color));
1850
1851        // And perform the fill
1852        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize));
1853        const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1854        uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1855        width *= bpp;
1856        switch (bpp) {
1857        case 1:
1858                for (int i = 0; i < height; i++) {
1859                        memset(dest, color, width);
1860                        dest += dest_row_bytes;
1861                }
1862                break;
1863        case 2:
1864                for (int i = 0; i < height; i++) {
1865                        do_fillrect<16>(dest, color, width);
1866                        dest += dest_row_bytes;
1867                }
1868                break;
1869        case 4:
1870                for (int i = 0; i < height; i++) {
1871                        do_fillrect<32>(dest, color, width);
1872                        dest += dest_row_bytes;
1873                }
1874                break;
1875        }
1876 }
1877
1878 bool NQD_fillrect_hook(uint32 p)
1879 {
1880        D(bug("accl_fillrect_hook %08x\n", p));
1881
1882        // Check if we can accelerate this fillrect
1883        if (ReadMacInt32(p + 0x284) != 0 && ReadMacInt32(p + acclDestPixelSize) >= 8) {
1884                const int transfer_mode = ReadMacInt32(p + acclTransferMode);
1885                if (transfer_mode == 8) {
1886                        // Fill
1887                        WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_FILLRECT));
1888                        return true;
1889                }
1890                else if (transfer_mode == 10) {
1891                        // Invert
1892                        WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_INVRECT));
1893                        return true;
1894                }
1895        }
1896        return false;
1897 }
1898
1899 // Rectangle blitting
1900 // TODO: optimize for VOSF and target pixmap == screen
1901 void NQD_bitblt(uint32 p)
1902 {
1903        D(bug("accl_bitblt %08x\n", p));
1904
1905        // Get blitting parameters
1906        int16 src_X  = (int16)ReadMacInt16(p + acclSrcRect + 2) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 2);
1907        int16 src_Y  = (int16)ReadMacInt16(p + acclSrcRect + 0) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 0);
1908        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1909        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1910        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1911        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1912        D(bug(" src addr %08x, dest addr %08x\n", ReadMacInt32(p + acclSrcBaseAddr), ReadMacInt32(p + acclDestBaseAddr)));
1913        D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y));
1914        D(bug(" width %d, height %d\n", width, height));
1915
1916        // And perform the blit
1917        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclSrcPixelSize));
1918        width *= bpp;
1919        if ((int32)ReadMacInt32(p + acclSrcRowBytes) > 0) {
1920                const int src_row_bytes = (int32)ReadMacInt32(p + acclSrcRowBytes);
1921                const int dst_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1922                uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + (src_Y * src_row_bytes) + (src_X * bpp));
1923                uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dst_row_bytes) + (dest_X * bpp));
1924                for (int i = 0; i < height; i++) {
1925                        memmove(dst, src, width);
1926                        src += src_row_bytes;
1927                        dst += dst_row_bytes;
1928                }
1929        }
1930        else {
1931                const int src_row_bytes = -(int32)ReadMacInt32(p + acclSrcRowBytes);
1932                const int dst_row_bytes = -(int32)ReadMacInt32(p + acclDestRowBytes);
1933                uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp));
1934                uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp));
1935                for (int i = height - 1; i >= 0; i--) {
1936                        memmove(dst, src, width);
1937                        src -= src_row_bytes;
1938                        dst -= dst_row_bytes;
1939                }
1940        }
1941 }
1942
1943 /*
1944  BitBlt transfer modes:
1945  0 : srcCopy
1946  1 : srcOr
1947  2 : srcXor
1948  3 : srcBic
1949  4 : notSrcCopy
1950  5 : notSrcOr
1951  6 : notSrcXor
1952  7 : notSrcBic
1953  32 : blend
1954  33 : addPin
1955  34 : addOver
1956  35 : subPin
1957  36 : transparent
1958  37 : adMax
1959  38 : subOver
1960  39 : adMin
1961  50 : hilite
1962 */
1963
1964 bool NQD_bitblt_hook(uint32 p)
1965 {
1966        D(bug("accl_draw_hook %08x\n", p));
1967
1968        // Check if we can accelerate this bitblt
1969        if (ReadMacInt32(p + 0x018) + ReadMacInt32(p + 0x128) == 0 &&
1970                ReadMacInt32(p + 0x130) == 0 &&
1971                ReadMacInt32(p + acclSrcPixelSize) >= 8 &&
1972                ReadMacInt32(p + acclSrcPixelSize) == ReadMacInt32(p + acclDestPixelSize) &&
1973                (ReadMacInt32(p + acclSrcRowBytes) ^ ReadMacInt32(p + acclDestRowBytes)) >= 0 && // same sign?
1974                ReadMacInt32(p + acclTransferMode) == 0 &&                                                                               // srcCopy?
1975                ReadMacInt32(p + 0x15c) > 0) {
1976
1977                // Yes, set function pointer
1978                WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_BITBLT));
1979                return true;
1980        }
1981        return false;
1982 }
1983
1984 // Wait for graphics operation to finish
1985 bool NQD_sync_hook(uint32 arg)
1986 {
1987        D(bug("accl_sync_hook %08x\n", arg));
1988        return true;
1989 }
1990
1991 void VideoInstallAccel(void)
1992 {
1993        // Install acceleration hooks
1994        if (PrefsFindBool("gfxaccel")) {
1995                D(bug("Video: Installing acceleration hooks\n"));
1996                uint32 base;
1997
1998                SheepVar bitblt_hook_info(sizeof(accl_hook_info));
1999                base = bitblt_hook_info.addr();
2000                WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK));
2001                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
2002                WriteMacInt32(base + 8, ACCL_BITBLT);
2003                NQDMisc(6, bitblt_hook_info.ptr());
2004
2005                SheepVar fillrect_hook_info(sizeof(accl_hook_info));
2006                base = fillrect_hook_info.addr();
2007                WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK));
2008                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
2009                WriteMacInt32(base + 8, ACCL_FILLRECT);
2010                NQDMisc(6, fillrect_hook_info.ptr());
2011        }
2012 }
2013
2014
2015 /*
1662   *  Change video mode
1663   */
1664  
# Line 2371 | Line 2017 | static void *redraw_func(void *arg)
2017                                          // Set new cursor image if it was 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