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" |
58 |
|
|
59 |
|
// Constants |
60 |
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; |
61 |
< |
static const bool mac_cursor_enabled = false; // Flag: Enable MacOS to X11 copy of cursor? |
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; |
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? |
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 |
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; |
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 |
< |
if (mac_cursor_enabled) { |
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; |
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 |
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) |
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 |
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); |
892 |
|
|
893 |
|
// Search for server vendor string, then read keycodes |
894 |
|
const char *vendor = ServerVendor(x_display); |
895 |
+ |
#if (defined(__APPLE__) && defined(__MACH__)) |
896 |
+ |
// Force use of MacX mappings on MacOS X with Apple's X server |
897 |
+ |
int dummy; |
898 |
+ |
if (XQueryExtension(x_display, "Apple-DRI", &dummy, &dummy, &dummy)) |
899 |
+ |
vendor = "MacX"; |
900 |
+ |
#endif |
901 |
|
bool vendor_found = false; |
902 |
|
char line[256]; |
903 |
|
while (fgets(line, 255, f)) { |
1177 |
|
if (apple_id != -1) |
1178 |
|
cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN); |
1179 |
|
} |
1180 |
< |
if (cur_mode == -1) |
1181 |
< |
cur_mode = find_mode(default_mode, APPLE_W_640x480, DIS_WINDOW); |
1180 |
> |
if (cur_mode == -1) { |
1181 |
> |
// pick up first windowed mode available |
1182 |
> |
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
1183 |
> |
if (p->viType == DIS_WINDOW && p->viAppleMode == default_mode) { |
1184 |
> |
cur_mode = p - VModes; |
1185 |
> |
break; |
1186 |
> |
} |
1187 |
> |
} |
1188 |
> |
} |
1189 |
|
assert(cur_mode != -1); |
1190 |
|
|
1191 |
|
#if DEBUG |
1208 |
|
// Start periodic thread |
1209 |
|
XSync(x_display, false); |
1210 |
|
Set_pthread_attr(&redraw_thread_attr, 0); |
1211 |
+ |
redraw_thread_cancel = false; |
1212 |
|
redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0); |
1213 |
|
D(bug("Redraw thread installed (%ld)\n", redraw_thread)); |
1214 |
|
return true; |
1223 |
|
{ |
1224 |
|
// Stop redraw thread |
1225 |
|
if (redraw_thread_active) { |
1226 |
+ |
redraw_thread_cancel = true; |
1227 |
|
pthread_cancel(redraw_thread); |
1228 |
|
pthread_join(redraw_thread, NULL); |
1229 |
|
redraw_thread_active = false; |
1267 |
|
// Save frame buffer |
1268 |
|
fb_save = malloc(VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1269 |
|
if (fb_save) |
1270 |
< |
memcpy(fb_save, (void *)screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1270 |
> |
Mac2Host_memcpy(fb_save, screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1271 |
|
|
1272 |
|
// Close full screen display |
1273 |
|
#ifdef ENABLE_XF86_DGA |
1329 |
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1330 |
|
if (!use_vosf) |
1331 |
|
#endif |
1332 |
< |
memcpy((void *)screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1332 |
> |
Host2Mac_memcpy(screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1333 |
|
free(fb_save); |
1334 |
|
fb_save = NULL; |
1335 |
|
} |
1502 |
|
return -1; |
1503 |
|
} |
1504 |
|
|
1505 |
< |
static int event2keycode(XKeyEvent &ev) |
1505 |
> |
static int event2keycode(XKeyEvent &ev, bool key_down) |
1506 |
|
{ |
1507 |
|
KeySym ks; |
1483 |
– |
int as; |
1508 |
|
int i = 0; |
1509 |
|
|
1510 |
|
do { |
1511 |
|
ks = XLookupKeysym(&ev, i++); |
1512 |
< |
as = kc_decode(ks); |
1513 |
< |
if (as != -1) |
1512 |
> |
int as = kc_decode(ks); |
1513 |
> |
if (as >= 0) |
1514 |
> |
return as; |
1515 |
> |
if (as == -2) |
1516 |
|
return as; |
1517 |
|
} while (ks != NoSymbol); |
1518 |
|
|
1587 |
|
|
1588 |
|
// Keyboard |
1589 |
|
case KeyPress: { |
1590 |
< |
int code = event2keycode(event.xkey); |
1591 |
< |
if (use_keycodes && code != -1) |
1592 |
< |
code = keycode_table[event.xkey.keycode & 0xff]; |
1593 |
< |
if (code != -1) { |
1590 |
> |
int code = -1; |
1591 |
> |
if (use_keycodes) { |
1592 |
> |
if (event2keycode(event.xkey, true) != -2) // This is called to process the hotkeys |
1593 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1594 |
> |
} else |
1595 |
> |
code = event2keycode(event.xkey, true); |
1596 |
> |
if (code >= 0) { |
1597 |
|
if (!emul_suspended) { |
1598 |
< |
ADBKeyDown(code); |
1598 |
> |
if (code == 0x39) { // Caps Lock pressed |
1599 |
> |
if (caps_on) { |
1600 |
> |
ADBKeyUp(code); |
1601 |
> |
caps_on = false; |
1602 |
> |
} else { |
1603 |
> |
ADBKeyDown(code); |
1604 |
> |
caps_on = true; |
1605 |
> |
} |
1606 |
> |
} else |
1607 |
> |
ADBKeyDown(code); |
1608 |
|
if (code == 0x36) |
1609 |
|
ctrl_down = true; |
1610 |
|
} else { |
1615 |
|
break; |
1616 |
|
} |
1617 |
|
case KeyRelease: { |
1618 |
< |
int code = event2keycode(event.xkey); |
1619 |
< |
if (use_keycodes && code != 1) |
1620 |
< |
code = keycode_table[event.xkey.keycode & 0xff]; |
1621 |
< |
if (code != -1) { |
1618 |
> |
int code = -1; |
1619 |
> |
if (use_keycodes) { |
1620 |
> |
if (event2keycode(event.xkey, false) != -2) // This is called to process the hotkeys |
1621 |
> |
code = keycode_table[event.xkey.keycode & 0xff]; |
1622 |
> |
} else |
1623 |
> |
code = event2keycode(event.xkey, false); |
1624 |
> |
if (code >= 0 && code != 0x39) { // Don't propagate Caps Lock releases |
1625 |
|
ADBKeyUp(code); |
1626 |
|
if (code == 0x36) |
1627 |
|
ctrl_down = false; |
1661 |
|
|
1662 |
|
|
1663 |
|
/* |
1623 |
– |
* Install graphics acceleration |
1624 |
– |
*/ |
1625 |
– |
|
1626 |
– |
// Rectangle inversion |
1627 |
– |
template< int bpp > |
1628 |
– |
static inline void do_invrect(uint8 *dest, uint32 length) |
1629 |
– |
{ |
1630 |
– |
#define INVERT_1(PTR, OFS) ((uint8 *)(PTR))[OFS] = ~((uint8 *)(PTR))[OFS] |
1631 |
– |
#define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS] |
1632 |
– |
#define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS] |
1633 |
– |
#define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS] |
1634 |
– |
|
1635 |
– |
#ifndef UNALIGNED_PROFITABLE |
1636 |
– |
// Align on 16-bit boundaries |
1637 |
– |
if (bpp < 16 && (((uintptr)dest) & 1)) { |
1638 |
– |
INVERT_1(dest, 0); |
1639 |
– |
dest += 1; length -= 1; |
1640 |
– |
} |
1641 |
– |
|
1642 |
– |
// Align on 32-bit boundaries |
1643 |
– |
if (bpp < 32 && (((uintptr)dest) & 2)) { |
1644 |
– |
INVERT_2(dest, 0); |
1645 |
– |
dest += 2; length -= 2; |
1646 |
– |
} |
1647 |
– |
#endif |
1648 |
– |
|
1649 |
– |
// Invert 8-byte words |
1650 |
– |
if (length >= 8) { |
1651 |
– |
const int r = (length / 8) % 8; |
1652 |
– |
dest += r * 8; |
1653 |
– |
|
1654 |
– |
int n = ((length / 8) + 7) / 8; |
1655 |
– |
switch (r) { |
1656 |
– |
case 0: do { |
1657 |
– |
dest += 64; |
1658 |
– |
INVERT_8(dest, -8); |
1659 |
– |
case 7: INVERT_8(dest, -7); |
1660 |
– |
case 6: INVERT_8(dest, -6); |
1661 |
– |
case 5: INVERT_8(dest, -5); |
1662 |
– |
case 4: INVERT_8(dest, -4); |
1663 |
– |
case 3: INVERT_8(dest, -3); |
1664 |
– |
case 2: INVERT_8(dest, -2); |
1665 |
– |
case 1: INVERT_8(dest, -1); |
1666 |
– |
} while (--n > 0); |
1667 |
– |
} |
1668 |
– |
} |
1669 |
– |
|
1670 |
– |
// 32-bit cell to invert? |
1671 |
– |
if (length & 4) { |
1672 |
– |
INVERT_4(dest, 0); |
1673 |
– |
if (bpp <= 16) |
1674 |
– |
dest += 4; |
1675 |
– |
} |
1676 |
– |
|
1677 |
– |
// 16-bit cell to invert? |
1678 |
– |
if (bpp <= 16 && (length & 2)) { |
1679 |
– |
INVERT_2(dest, 0); |
1680 |
– |
if (bpp <= 8) |
1681 |
– |
dest += 2; |
1682 |
– |
} |
1683 |
– |
|
1684 |
– |
// 8-bit cell to invert? |
1685 |
– |
if (bpp <= 8 && (length & 1)) |
1686 |
– |
INVERT_1(dest, 0); |
1687 |
– |
|
1688 |
– |
#undef INVERT_1 |
1689 |
– |
#undef INVERT_2 |
1690 |
– |
#undef INVERT_4 |
1691 |
– |
#undef INVERT_8 |
1692 |
– |
} |
1693 |
– |
|
1694 |
– |
void NQD_invrect(uint32 p) |
1695 |
– |
{ |
1696 |
– |
D(bug("accl_invrect %08x\n", p)); |
1697 |
– |
|
1698 |
– |
// Get inversion parameters |
1699 |
– |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1700 |
– |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1701 |
– |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1702 |
– |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1703 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1704 |
– |
D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes))); |
1705 |
– |
|
1706 |
– |
//!!?? pen_mode == 14 |
1707 |
– |
|
1708 |
– |
// And perform the inversion |
1709 |
– |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); |
1710 |
– |
const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1711 |
– |
uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); |
1712 |
– |
width *= bpp; |
1713 |
– |
switch (bpp) { |
1714 |
– |
case 1: |
1715 |
– |
for (int i = 0; i < height; i++) { |
1716 |
– |
do_invrect<8>(dest, width); |
1717 |
– |
dest += dest_row_bytes; |
1718 |
– |
} |
1719 |
– |
break; |
1720 |
– |
case 2: |
1721 |
– |
for (int i = 0; i < height; i++) { |
1722 |
– |
do_invrect<16>(dest, width); |
1723 |
– |
dest += dest_row_bytes; |
1724 |
– |
} |
1725 |
– |
break; |
1726 |
– |
case 4: |
1727 |
– |
for (int i = 0; i < height; i++) { |
1728 |
– |
do_invrect<32>(dest, width); |
1729 |
– |
dest += dest_row_bytes; |
1730 |
– |
} |
1731 |
– |
break; |
1732 |
– |
} |
1733 |
– |
} |
1734 |
– |
|
1735 |
– |
// Rectangle filling |
1736 |
– |
template< int bpp > |
1737 |
– |
static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length) |
1738 |
– |
{ |
1739 |
– |
#define FILL_1(PTR, OFS, VAL) ((uint8 *)(PTR))[OFS] = (VAL) |
1740 |
– |
#define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL) |
1741 |
– |
#define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL) |
1742 |
– |
#define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL) |
1743 |
– |
|
1744 |
– |
#ifndef UNALIGNED_PROFITABLE |
1745 |
– |
// Align on 16-bit boundaries |
1746 |
– |
if (bpp < 16 && (((uintptr)dest) & 1)) { |
1747 |
– |
FILL_1(dest, 0, color); |
1748 |
– |
dest += 1; length -= 1; |
1749 |
– |
} |
1750 |
– |
|
1751 |
– |
// Align on 32-bit boundaries |
1752 |
– |
if (bpp < 32 && (((uintptr)dest) & 2)) { |
1753 |
– |
FILL_2(dest, 0, color); |
1754 |
– |
dest += 2; length -= 2; |
1755 |
– |
} |
1756 |
– |
#endif |
1757 |
– |
|
1758 |
– |
// Fill 8-byte words |
1759 |
– |
if (length >= 8) { |
1760 |
– |
const uint64 c = (((uint64)color) << 32) | color; |
1761 |
– |
const int r = (length / 8) % 8; |
1762 |
– |
dest += r * 8; |
1763 |
– |
|
1764 |
– |
int n = ((length / 8) + 7) / 8; |
1765 |
– |
switch (r) { |
1766 |
– |
case 0: do { |
1767 |
– |
dest += 64; |
1768 |
– |
FILL_8(dest, -8, c); |
1769 |
– |
case 7: FILL_8(dest, -7, c); |
1770 |
– |
case 6: FILL_8(dest, -6, c); |
1771 |
– |
case 5: FILL_8(dest, -5, c); |
1772 |
– |
case 4: FILL_8(dest, -4, c); |
1773 |
– |
case 3: FILL_8(dest, -3, c); |
1774 |
– |
case 2: FILL_8(dest, -2, c); |
1775 |
– |
case 1: FILL_8(dest, -1, c); |
1776 |
– |
} while (--n > 0); |
1777 |
– |
} |
1778 |
– |
} |
1779 |
– |
|
1780 |
– |
// 32-bit cell to fill? |
1781 |
– |
if (length & 4) { |
1782 |
– |
FILL_4(dest, 0, color); |
1783 |
– |
if (bpp <= 16) |
1784 |
– |
dest += 4; |
1785 |
– |
} |
1786 |
– |
|
1787 |
– |
// 16-bit cell to fill? |
1788 |
– |
if (bpp <= 16 && (length & 2)) { |
1789 |
– |
FILL_2(dest, 0, color); |
1790 |
– |
if (bpp <= 8) |
1791 |
– |
dest += 2; |
1792 |
– |
} |
1793 |
– |
|
1794 |
– |
// 8-bit cell to fill? |
1795 |
– |
if (bpp <= 8 && (length & 1)) |
1796 |
– |
FILL_1(dest, 0, color); |
1797 |
– |
|
1798 |
– |
#undef FILL_1 |
1799 |
– |
#undef FILL_2 |
1800 |
– |
#undef FILL_4 |
1801 |
– |
#undef FILL_8 |
1802 |
– |
} |
1803 |
– |
|
1804 |
– |
void NQD_fillrect(uint32 p) |
1805 |
– |
{ |
1806 |
– |
D(bug("accl_fillrect %08x\n", p)); |
1807 |
– |
|
1808 |
– |
// Get filling parameters |
1809 |
– |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1810 |
– |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1811 |
– |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1812 |
– |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1813 |
– |
uint32 color = ReadMacInt32(p + acclPenMode) == 8 ? ReadMacInt32(p + acclForePen) : ReadMacInt32(p + acclBackPen); |
1814 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1815 |
– |
D(bug(" width %d, height %d\n", width, height)); |
1816 |
– |
D(bug(" bytes_per_row %d color %08x\n", (int32)ReadMacInt32(p + acclDestRowBytes), color)); |
1817 |
– |
|
1818 |
– |
// And perform the fill |
1819 |
– |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); |
1820 |
– |
const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1821 |
– |
uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); |
1822 |
– |
width *= bpp; |
1823 |
– |
switch (bpp) { |
1824 |
– |
case 1: |
1825 |
– |
for (int i = 0; i < height; i++) { |
1826 |
– |
memset(dest, color, width); |
1827 |
– |
dest += dest_row_bytes; |
1828 |
– |
} |
1829 |
– |
break; |
1830 |
– |
case 2: |
1831 |
– |
for (int i = 0; i < height; i++) { |
1832 |
– |
do_fillrect<16>(dest, color, width); |
1833 |
– |
dest += dest_row_bytes; |
1834 |
– |
} |
1835 |
– |
break; |
1836 |
– |
case 4: |
1837 |
– |
for (int i = 0; i < height; i++) { |
1838 |
– |
do_fillrect<32>(dest, color, width); |
1839 |
– |
dest += dest_row_bytes; |
1840 |
– |
} |
1841 |
– |
break; |
1842 |
– |
} |
1843 |
– |
} |
1844 |
– |
|
1845 |
– |
bool NQD_fillrect_hook(uint32 p) |
1846 |
– |
{ |
1847 |
– |
D(bug("accl_fillrect_hook %08x\n", p)); |
1848 |
– |
|
1849 |
– |
// Check if we can accelerate this fillrect |
1850 |
– |
if (ReadMacInt32(p + 0x284) != 0 && ReadMacInt32(p + acclDestPixelSize) >= 8) { |
1851 |
– |
const int transfer_mode = ReadMacInt32(p + acclTransferMode); |
1852 |
– |
if (transfer_mode == 8) { |
1853 |
– |
// Fill |
1854 |
– |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_FILLRECT)); |
1855 |
– |
return true; |
1856 |
– |
} |
1857 |
– |
else if (transfer_mode == 10) { |
1858 |
– |
// Invert |
1859 |
– |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_INVRECT)); |
1860 |
– |
return true; |
1861 |
– |
} |
1862 |
– |
} |
1863 |
– |
return false; |
1864 |
– |
} |
1865 |
– |
|
1866 |
– |
// Rectangle blitting |
1867 |
– |
// TODO: optimize for VOSF and target pixmap == screen |
1868 |
– |
void NQD_bitblt(uint32 p) |
1869 |
– |
{ |
1870 |
– |
D(bug("accl_bitblt %08x\n", p)); |
1871 |
– |
|
1872 |
– |
// Get blitting parameters |
1873 |
– |
int16 src_X = (int16)ReadMacInt16(p + acclSrcRect + 2) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 2); |
1874 |
– |
int16 src_Y = (int16)ReadMacInt16(p + acclSrcRect + 0) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 0); |
1875 |
– |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1876 |
– |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1877 |
– |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1878 |
– |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1879 |
– |
D(bug(" src addr %08x, dest addr %08x\n", ReadMacInt32(p + acclSrcBaseAddr), ReadMacInt32(p + acclDestBaseAddr))); |
1880 |
– |
D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y)); |
1881 |
– |
D(bug(" width %d, height %d\n", width, height)); |
1882 |
– |
|
1883 |
– |
// And perform the blit |
1884 |
– |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclSrcPixelSize)); |
1885 |
– |
width *= bpp; |
1886 |
– |
if ((int32)ReadMacInt32(p + acclSrcRowBytes) > 0) { |
1887 |
– |
const int src_row_bytes = (int32)ReadMacInt32(p + acclSrcRowBytes); |
1888 |
– |
const int dst_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1889 |
– |
uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + (src_Y * src_row_bytes) + (src_X * bpp)); |
1890 |
– |
uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dst_row_bytes) + (dest_X * bpp)); |
1891 |
– |
for (int i = 0; i < height; i++) { |
1892 |
– |
memcpy(dst, src, width); |
1893 |
– |
src += src_row_bytes; |
1894 |
– |
dst += dst_row_bytes; |
1895 |
– |
} |
1896 |
– |
} |
1897 |
– |
else { |
1898 |
– |
const int src_row_bytes = -(int32)ReadMacInt32(p + acclSrcRowBytes); |
1899 |
– |
const int dst_row_bytes = -(int32)ReadMacInt32(p + acclDestRowBytes); |
1900 |
– |
uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp)); |
1901 |
– |
uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp)); |
1902 |
– |
for (int i = height - 1; i >= 0; i--) { |
1903 |
– |
memcpy(dst, src, width); |
1904 |
– |
src -= src_row_bytes; |
1905 |
– |
dst -= dst_row_bytes; |
1906 |
– |
} |
1907 |
– |
} |
1908 |
– |
} |
1909 |
– |
|
1910 |
– |
/* |
1911 |
– |
BitBlt transfer modes: |
1912 |
– |
0 : srcCopy |
1913 |
– |
1 : srcOr |
1914 |
– |
2 : srcXor |
1915 |
– |
3 : srcBic |
1916 |
– |
4 : notSrcCopy |
1917 |
– |
5 : notSrcOr |
1918 |
– |
6 : notSrcXor |
1919 |
– |
7 : notSrcBic |
1920 |
– |
32 : blend |
1921 |
– |
33 : addPin |
1922 |
– |
34 : addOver |
1923 |
– |
35 : subPin |
1924 |
– |
36 : transparent |
1925 |
– |
37 : adMax |
1926 |
– |
38 : subOver |
1927 |
– |
39 : adMin |
1928 |
– |
50 : hilite |
1929 |
– |
*/ |
1930 |
– |
|
1931 |
– |
bool NQD_bitblt_hook(uint32 p) |
1932 |
– |
{ |
1933 |
– |
D(bug("accl_draw_hook %08x\n", p)); |
1934 |
– |
|
1935 |
– |
// Check if we can accelerate this bitblt |
1936 |
– |
if (ReadMacInt32(p + 0x018) + ReadMacInt32(p + 0x128) == 0 && |
1937 |
– |
ReadMacInt32(p + 0x130) == 0 && |
1938 |
– |
ReadMacInt32(p + acclSrcPixelSize) >= 8 && |
1939 |
– |
ReadMacInt32(p + acclSrcPixelSize) == ReadMacInt32(p + acclDestPixelSize) && |
1940 |
– |
(ReadMacInt32(p + acclSrcRowBytes) ^ ReadMacInt32(p + acclDestRowBytes)) >= 0 && // same sign? |
1941 |
– |
ReadMacInt32(p + acclTransferMode) == 0 && // srcCopy? |
1942 |
– |
ReadMacInt32(p + 0x15c) > 0) { |
1943 |
– |
|
1944 |
– |
// Yes, set function pointer |
1945 |
– |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_BITBLT)); |
1946 |
– |
return true; |
1947 |
– |
} |
1948 |
– |
return false; |
1949 |
– |
} |
1950 |
– |
|
1951 |
– |
// Wait for graphics operation to finish |
1952 |
– |
bool NQD_sync_hook(uint32 arg) |
1953 |
– |
{ |
1954 |
– |
D(bug("accl_sync_hook %08x\n", arg)); |
1955 |
– |
return true; |
1956 |
– |
} |
1957 |
– |
|
1958 |
– |
void VideoInstallAccel(void) |
1959 |
– |
{ |
1960 |
– |
// Temporary hack until it's fixed for e.g. little-endian & 64-bit platforms |
1961 |
– |
#ifndef __powerpc__ |
1962 |
– |
return; |
1963 |
– |
#endif |
1964 |
– |
|
1965 |
– |
// Install acceleration hooks |
1966 |
– |
if (PrefsFindBool("gfxaccel")) { |
1967 |
– |
D(bug("Video: Installing acceleration hooks\n")); |
1968 |
– |
uint32 base; |
1969 |
– |
|
1970 |
– |
SheepVar bitblt_hook_info(sizeof(accl_hook_info)); |
1971 |
– |
base = bitblt_hook_info.addr(); |
1972 |
– |
WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK)); |
1973 |
– |
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
1974 |
– |
WriteMacInt32(base + 8, ACCL_BITBLT); |
1975 |
– |
NQDMisc(6, bitblt_hook_info.ptr()); |
1976 |
– |
|
1977 |
– |
SheepVar fillrect_hook_info(sizeof(accl_hook_info)); |
1978 |
– |
base = fillrect_hook_info.addr(); |
1979 |
– |
WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK)); |
1980 |
– |
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
1981 |
– |
WriteMacInt32(base + 8, ACCL_FILLRECT); |
1982 |
– |
NQDMisc(6, fillrect_hook_info.ptr()); |
1983 |
– |
} |
1984 |
– |
} |
1985 |
– |
|
1986 |
– |
|
1987 |
– |
/* |
1664 |
|
* Change video mode |
1665 |
|
*/ |
1666 |
|
|
1768 |
|
|
1769 |
|
bool video_can_change_cursor(void) |
1770 |
|
{ |
1771 |
< |
return mac_cursor_enabled && (display_type != DIS_SCREEN); |
1771 |
> |
return hw_mac_cursor_accl && (display_type != DIS_SCREEN); |
1772 |
|
} |
1773 |
|
|
1774 |
|
|
1952 |
|
int64 ticks = 0; |
1953 |
|
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
1954 |
|
|
1955 |
< |
for (;;) { |
1955 |
> |
while (!redraw_thread_cancel) { |
1956 |
|
|
1957 |
|
// Pause if requested (during video mode switches) |
1958 |
|
while (thread_stop_req) |
2017 |
|
update_display(); |
2018 |
|
|
2019 |
|
// Set new cursor image if it was changed |
2020 |
< |
if (mac_cursor_enabled && cursor_changed) { |
2020 |
> |
if (hw_mac_cursor_accl && cursor_changed) { |
2021 |
|
cursor_changed = false; |
2022 |
< |
memcpy(cursor_image->data, MacCursor + 4, 32); |
2023 |
< |
memcpy(cursor_mask_image->data, MacCursor + 36, 32); |
2022 |
> |
uint8 *x_data = (uint8 *)cursor_image->data; |
2023 |
> |
uint8 *x_mask = (uint8 *)cursor_mask_image->data; |
2024 |
> |
for (int i = 0; i < 32; i++) { |
2025 |
> |
x_mask[i] = MacCursor[4 + i] | MacCursor[36 + i]; |
2026 |
> |
x_data[i] = MacCursor[4 + i]; |
2027 |
> |
} |
2028 |
|
XDisplayLock(); |
2029 |
|
XFreeCursor(x_display, mac_cursor); |
2030 |
|
XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16); |