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.31 by gbeauche, 2004-06-30T22:03:34Z vs.
Revision 1.32 by gbeauche, 2004-07-02T06:06:34Z

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines