1 |
|
/* |
2 |
|
* video_x.cpp - Video/graphics emulation, X11 specific stuff |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2004 Marc Hellwig and Christian Bauer |
4 |
> |
* SheepShaver (C) 1997-2005 Marc Hellwig and Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
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" |
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); |
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); |
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)) { |
970 |
|
return -1; |
971 |
|
} |
972 |
|
|
973 |
+ |
// Add custom video mode |
974 |
+ |
static void add_custom_mode(VideoInfo *&p, int type, uint32 x, uint32 y, int apple_mode, int apple_id) |
975 |
+ |
{ |
976 |
+ |
p->viType = type; |
977 |
+ |
p->viXsize = x; |
978 |
+ |
p->viYsize = y; |
979 |
+ |
p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); |
980 |
+ |
p->viAppleMode = apple_mode; |
981 |
+ |
p->viAppleID = apple_id; |
982 |
+ |
p++; |
983 |
+ |
} |
984 |
+ |
|
985 |
|
// Add mode to list of supported modes |
986 |
|
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type) |
987 |
|
{ |
988 |
|
if (allow & test) { |
989 |
< |
p->viType = type; |
989 |
> |
uint32 x = 0, y = 0; |
990 |
|
switch (apple_id) { |
991 |
|
case APPLE_W_640x480: |
992 |
|
case APPLE_640x480: |
993 |
< |
p->viXsize = 640; |
994 |
< |
p->viYsize = 480; |
993 |
> |
x = 640; |
994 |
> |
y = 480; |
995 |
|
break; |
996 |
|
case APPLE_W_800x600: |
997 |
|
case APPLE_800x600: |
998 |
< |
p->viXsize = 800; |
999 |
< |
p->viYsize = 600; |
998 |
> |
x = 800; |
999 |
> |
y = 600; |
1000 |
|
break; |
1001 |
|
case APPLE_1024x768: |
1002 |
< |
p->viXsize = 1024; |
1003 |
< |
p->viYsize = 768; |
1002 |
> |
x = 1024; |
1003 |
> |
y = 768; |
1004 |
|
break; |
1005 |
|
case APPLE_1152x768: |
1006 |
< |
p->viXsize = 1152; |
1007 |
< |
p->viYsize = 768; |
1006 |
> |
x = 1152; |
1007 |
> |
y = 768; |
1008 |
|
break; |
1009 |
|
case APPLE_1152x900: |
1010 |
< |
p->viXsize = 1152; |
1011 |
< |
p->viYsize = 900; |
1010 |
> |
x = 1152; |
1011 |
> |
y = 900; |
1012 |
|
break; |
1013 |
|
case APPLE_1280x1024: |
1014 |
< |
p->viXsize = 1280; |
1015 |
< |
p->viYsize = 1024; |
1014 |
> |
x = 1280; |
1015 |
> |
y = 1024; |
1016 |
|
break; |
1017 |
|
case APPLE_1600x1200: |
1018 |
< |
p->viXsize = 1600; |
1019 |
< |
p->viYsize = 1200; |
1018 |
> |
x = 1600; |
1019 |
> |
y = 1200; |
1020 |
|
break; |
1021 |
|
} |
1022 |
< |
p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); |
1005 |
< |
p->viAppleMode = apple_mode; |
1006 |
< |
p->viAppleID = apple_id; |
1007 |
< |
p++; |
1022 |
> |
add_custom_mode(p, type, x, y, apple_mode, apple_id); |
1023 |
|
} |
1024 |
|
} |
1025 |
|
|
1129 |
|
break; |
1130 |
|
} |
1131 |
|
|
1132 |
+ |
// Get screen mode from preferences |
1133 |
+ |
const char *mode_str = PrefsFindString("screen"); |
1134 |
+ |
int default_width = 640, default_height = 480; |
1135 |
+ |
if (mode_str) { |
1136 |
+ |
display_type = DIS_INVALID; |
1137 |
+ |
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) |
1138 |
+ |
display_type = DIS_WINDOW; |
1139 |
+ |
#ifdef ENABLE_XF86_DGA |
1140 |
+ |
else if (has_dga && sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2) |
1141 |
+ |
display_type = DIS_SCREEN; |
1142 |
+ |
#endif |
1143 |
+ |
if (display_type == DIS_INVALID) { |
1144 |
+ |
D(bug("Invalid screen mode specified, defaulting to old modes selection\n")); |
1145 |
+ |
mode_str = NULL; |
1146 |
+ |
} |
1147 |
+ |
else { |
1148 |
+ |
if (default_width <= 0) |
1149 |
+ |
default_width = DisplayWidth(x_display, screen); |
1150 |
+ |
else if (default_width > DisplayWidth(x_display, screen)) |
1151 |
+ |
default_width = DisplayWidth(x_display, screen); |
1152 |
+ |
if (default_height <= 0) |
1153 |
+ |
default_height = DisplayHeight(x_display, screen); |
1154 |
+ |
else if (default_height > DisplayHeight(x_display, screen)) |
1155 |
+ |
default_height = DisplayHeight(x_display, screen); |
1156 |
+ |
} |
1157 |
+ |
} |
1158 |
+ |
|
1159 |
|
// Construct video mode table |
1160 |
|
uint32 window_modes = PrefsFindInt32("windowmodes"); |
1161 |
|
uint32 screen_modes = PrefsFindInt32("screenmodes"); |
1162 |
|
if (!has_dga) |
1163 |
|
screen_modes = 0; |
1164 |
< |
if (window_modes == 0 && screen_modes == 0) |
1164 |
> |
if (mode_str) |
1165 |
> |
window_modes = screen_modes = 0; |
1166 |
> |
else if (window_modes == 0 && screen_modes == 0) |
1167 |
|
window_modes |= 3; // Allow at least 640x480 and 800x600 window modes |
1168 |
|
|
1169 |
|
VideoInfo *p = VModes; |
1170 |
< |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) |
1171 |
< |
if (find_visual_for_depth(d)) |
1172 |
< |
add_window_modes(p, window_modes, d); |
1173 |
< |
|
1174 |
< |
if (has_vidmode) { |
1170 |
> |
if (mode_str) { |
1171 |
> |
if (display_type == DIS_WINDOW) { |
1172 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) { |
1173 |
> |
if (find_visual_for_depth(d)) { |
1174 |
> |
if (default_width > 640 && default_height > 480) |
1175 |
> |
add_mode(p, 3, 1, d, APPLE_W_640x480, DIS_WINDOW); |
1176 |
> |
if (default_width > 800 && default_height > 600) |
1177 |
> |
add_mode(p, 3, 2, d, APPLE_W_800x600, DIS_WINDOW); |
1178 |
> |
add_custom_mode(p, display_type, default_width, default_height, d, APPLE_CUSTOM); |
1179 |
> |
} |
1180 |
> |
} |
1181 |
> |
} else |
1182 |
> |
add_custom_mode(p, display_type, default_width, default_height, default_mode, APPLE_CUSTOM); |
1183 |
> |
} else if (window_modes) { |
1184 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) |
1185 |
> |
if (find_visual_for_depth(d)) |
1186 |
> |
add_window_modes(p, window_modes, d); |
1187 |
> |
} else if (has_vidmode) { |
1188 |
|
if (has_mode(640, 480)) |
1189 |
|
add_mode(p, screen_modes, 1, default_mode, APPLE_640x480, DIS_SCREEN); |
1190 |
|
if (has_mode(800, 600)) |
1225 |
|
int apple_id = find_apple_resolution(screen_width, screen_height); |
1226 |
|
if (apple_id != -1) |
1227 |
|
cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN); |
1228 |
< |
} |
1228 |
> |
} else if (has_dga && mode_str) |
1229 |
> |
cur_mode = find_mode(default_mode, APPLE_CUSTOM, DIS_SCREEN); |
1230 |
> |
|
1231 |
|
if (cur_mode == -1) { |
1232 |
|
// pick up first windowed mode available |
1233 |
|
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
1318 |
|
// Save frame buffer |
1319 |
|
fb_save = malloc(VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1320 |
|
if (fb_save) |
1321 |
< |
memcpy(fb_save, (void *)screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1321 |
> |
Mac2Host_memcpy(fb_save, screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1322 |
|
|
1323 |
|
// Close full screen display |
1324 |
|
#ifdef ENABLE_XF86_DGA |
1380 |
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1381 |
|
if (!use_vosf) |
1382 |
|
#endif |
1383 |
< |
memcpy((void *)screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1383 |
> |
Host2Mac_memcpy(screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1384 |
|
free(fb_save); |
1385 |
|
fb_save = NULL; |
1386 |
|
} |
1712 |
|
|
1713 |
|
|
1714 |
|
/* |
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 |
– |
/* |
1715 |
|
* Change video mode |
1716 |
|
*/ |
1717 |
|
|
2070 |
|
// Set new cursor image if it was changed |
2071 |
|
if (hw_mac_cursor_accl && cursor_changed) { |
2072 |
|
cursor_changed = false; |
2073 |
< |
memcpy(cursor_image->data, MacCursor + 4, 32); |
2074 |
< |
memcpy(cursor_mask_image->data, MacCursor + 36, 32); |
2073 |
> |
uint8 *x_data = (uint8 *)cursor_image->data; |
2074 |
> |
uint8 *x_mask = (uint8 *)cursor_mask_image->data; |
2075 |
> |
for (int i = 0; i < 32; i++) { |
2076 |
> |
x_mask[i] = MacCursor[4 + i] | MacCursor[36 + i]; |
2077 |
> |
x_data[i] = MacCursor[4 + i]; |
2078 |
> |
} |
2079 |
|
XDisplayLock(); |
2080 |
|
XFreeCursor(x_display, mac_cursor); |
2081 |
|
XPutImage(x_display, cursor_map, cursor_gc, cursor_image, 0, 0, 0, 0, 16, 16); |