1611 |
|
* Install graphics acceleration |
1612 |
|
*/ |
1613 |
|
|
1614 |
< |
#if 0 |
1615 |
< |
// Rectangle filling/inversion |
1616 |
< |
static void accl_fillrect8(accl_params *p) |
1614 |
> |
// Rectangle inversion |
1615 |
> |
template< int bpp > |
1616 |
> |
static inline void do_invrect(uint8 *dest, uint32 length) |
1617 |
|
{ |
1618 |
< |
D(bug("accl_fillrect8\n")); |
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 |
< |
// Get filling parameters |
1631 |
< |
int16 dest_X = p->dest_rect[1] - p->dest_bounds[1]; |
1632 |
< |
int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0]; |
1633 |
< |
int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1634 |
< |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1635 |
< |
uint8 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
1626 |
< |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1627 |
< |
D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
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 |
< |
// And perform the fill |
1638 |
< |
fillrect8_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
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 |
< |
static void accl_fillrect32(accl_params *p) |
1682 |
> |
void NQD_invrect(uint32 arg) |
1683 |
|
{ |
1684 |
< |
D(bug("accl_fillrect32\n")); |
1684 |
> |
D(bug("accl_invrect %08x\n", arg)); |
1685 |
> |
accl_params *p = (accl_params *)arg; |
1686 |
|
|
1687 |
< |
// Get filling parameters |
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 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1691 |
< |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
1642 |
< |
uint32 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen; |
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(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1693 |
> |
D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, p->dest_row_bytes)); |
1694 |
|
|
1695 |
< |
// And perform the fill |
1696 |
< |
fillrect32_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color); |
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 |
< |
static void accl_invrect(accl_params *p) |
1724 |
> |
// Rectangle filling |
1725 |
> |
template< int bpp > |
1726 |
> |
static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length) |
1727 |
|
{ |
1728 |
< |
D(bug("accl_invrect\n")); |
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 |
< |
// Get inversion parameters |
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 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1; |
1802 |
< |
int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1; |
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(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max)); |
1806 |
< |
|
1662 |
< |
//!!?? pen_mode == 14 |
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 inversion |
1809 |
< |
invrect_hook(dest_X, dest_Y, dest_X_max, dest_Y_max); |
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 |
< |
static bool accl_fillrect_hook(accl_params *p) |
1835 |
> |
bool NQD_fillrect_hook(uint32 arg) |
1836 |
|
{ |
1837 |
< |
D(bug("accl_fillrect_hook %p\n", p)); |
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 (p->dest_base_addr == screen_base && ((uint32 *)p)[0x284 >> 2] != 0 && display_type == DIS_SCREEN) { |
1841 |
> |
if (((uint32 *)p)[0x284 >> 2] != 0 && p->dest_pixel_size >= 8) { |
1842 |
|
if (p->transfer_mode == 8) { |
1843 |
|
// Fill |
1844 |
< |
if (p->dest_pixel_size == 8 && fillrect8_hook != NULL) { |
1845 |
< |
p->draw_proc = accl_fillrect8; |
1846 |
< |
return true; |
1847 |
< |
} else if (p->dest_pixel_size == 32 && fillrect32_hook != NULL) { |
1680 |
< |
p->draw_proc = accl_fillrect32; |
1681 |
< |
return true; |
1682 |
< |
} |
1683 |
< |
} else if (p->transfer_mode == 10 && invrect_hook != NULL) { |
1844 |
> |
p->draw_proc = NativeTVECT(NATIVE_FILLRECT); |
1845 |
> |
return true; |
1846 |
> |
} |
1847 |
> |
else if (p->transfer_mode == 10) { |
1848 |
|
// Invert |
1849 |
< |
p->draw_proc = accl_invrect; |
1849 |
> |
p->draw_proc = NativeTVECT(NATIVE_INVRECT); |
1850 |
|
return true; |
1851 |
|
} |
1852 |
|
} |
1853 |
|
return false; |
1854 |
|
} |
1855 |
|
|
1692 |
– |
static struct accl_hook_info fillrect_hook_info = {accl_fillrect_hook, accl_sync_hook, ACCL_FILLRECT}; |
1693 |
– |
#endif |
1694 |
– |
|
1856 |
|
// Rectangle blitting |
1857 |
|
// TODO: optimize for VOSF and target pixmap == screen |
1858 |
|
void NQD_bitblt(uint32 arg) |
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)); |
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) >> 31) == 0 && |
1932 |
< |
p->transfer_mode == 0 && |
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 |
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")); |
1963 |
|
WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK)); |
1964 |
|
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
1965 |
|
WriteMacInt32(base + 8, ACCL_BITBLT); |
1779 |
– |
#if defined(__powerpc__) // Temporary hack until it's fixed for e.g. little-endian & 64-bit platforms |
1966 |
|
NQDMisc(6, bitblt_hook_info.ptr()); |
1781 |
– |
#endif |
1967 |
|
|
1968 |
< |
// NQDMisc(6, &fillrect_hook_info); |
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 |
|
|