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.14 by gbeauche, 2004-04-11T10:46:32Z vs.
Revision 1.19 by gbeauche, 2004-04-22T21:45:16Z

# Line 32 | Line 32
32   #include <algorithm>
33  
34   #ifdef ENABLE_XF86_DGA
35 < #include <X11/extensions/xf86dga.h>
35 > # include <X11/extensions/xf86dga.h>
36   #endif
37  
38   #ifdef ENABLE_XF86_VIDMODE
# Line 63 | Line 63 | static int32 frame_skip;
63   static int16 mouse_wheel_mode;
64   static int16 mouse_wheel_lines;
65   static bool redraw_thread_active = false;       // Flag: Redraw thread installed
66 + static pthread_attr_t redraw_thread_attr;       // Redraw thread attributes
67   static pthread_t redraw_thread;                         // Redraw thread
68  
69   static bool local_X11;                                          // Flag: X server running on local machine?
# Line 125 | Line 126 | static uint8 *the_buffer_copy = NULL;          /
126   static uint32 the_buffer_size;                          // Size of allocated the_buffer
127  
128   // Variables for DGA mode
128 static char *dga_screen_base;
129 static int dga_fb_width;
129   static int current_dga_cmap;
130  
131   #ifdef ENABLE_XF86_VIDMODE
# Line 196 | Line 195 | static int palette_size(int mode)
195          }
196   }
197  
198 + // Return bits per pixel for requested depth
199 + static inline int bytes_per_pixel(int depth)
200 + {
201 +        int bpp;
202 +        switch (depth) {
203 +        case 8:
204 +                bpp = 1;
205 +                break;
206 +        case 15: case 16:
207 +                bpp = 2;
208 +                break;
209 +        case 24: case 32:
210 +                bpp = 4;
211 +                break;
212 +        default:
213 +                abort();
214 +        }
215 +        return bpp;
216 + }
217 +
218   // Map video_mode depth ID to numerical depth value
219   static inline int depth_of_video_mode(int mode)
220   {
221 <        int depth = -1;
221 >        int depth;
222          switch (mode) {
223          case APPLE_1_BIT:
224                  depth = 1;
# Line 349 | Line 368 | static void set_window_delete_protocol(W
368   }
369  
370   // Wait until window is mapped/unmapped
371 < void wait_mapped(Window w)
371 > static void wait_mapped(Window w)
372   {
373          XEvent e;
374          do {
# Line 357 | Line 376 | void wait_mapped(Window w)
376          } while ((e.type != MapNotify) || (e.xmap.event != w));
377   }
378  
379 < void wait_unmapped(Window w)
379 > static void wait_unmapped(Window w)
380   {
381          XEvent e;
382          do {
# Line 522 | Line 541 | static bool open_dga(int width, int heig
541          // Set relative mouse mode
542          ADBSetRelMouseMode(true);
543  
544 +        // Create window
545 +        XSetWindowAttributes wattr;
546 +        wattr.event_mask = eventmask = dga_eventmask;
547 +        wattr.override_redirect = True;
548 +        wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]);
549 +        the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
550 +                InputOutput, vis, CWEventMask | CWOverrideRedirect |
551 +                (color_class == DirectColor ? CWColormap : 0), &wattr);
552 +
553 +        // Show window
554 +        XMapRaised(x_display, the_win);
555 +        wait_mapped(the_win);
556 +
557   #ifdef ENABLE_XF86_VIDMODE
558          // Switch to best mode
559          if (has_vidmode) {
# Line 538 | Line 570 | static bool open_dga(int width, int heig
570   #endif
571  
572          // Establish direct screen connection
573 +        XMoveResizeWindow(x_display, the_win, 0, 0, width, height);
574 +        XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0);
575          XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime);
576          XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
577 +
578 +        int v_width, v_bank, v_size;
579 +        XF86DGAGetVideo(x_display, screen, (char **)&the_buffer, &v_width, &v_bank, &v_size);
580          XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse);
581          XF86DGASetViewPort(x_display, screen, 0, 0);
582          XF86DGASetVidPage(x_display, screen, 0);
583  
584          // Set colormap
585 <        if (depth == 8)
585 >        if (!IsDirectMode(get_current_mode())) {
586 >                XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]);
587                  XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
588 +        }
589 +        XSync(x_display, false);
590  
591 <        // Set bytes per row
592 <        int bytes_per_row = TrivialBytesPerRow((dga_fb_width + 7) & ~7, DepthModeForPixelDepth(depth));
553 <
591 >        // Init blitting routines
592 >        int bytes_per_row = TrivialBytesPerRow((v_width + 7) & ~7, DepthModeForPixelDepth(depth));
593   #if ENABLE_VOSF
594          bool native_byte_order;
595   #ifdef WORDS_BIGENDIAN
# Line 569 | Line 608 | static bool open_dga(int width, int heig
608            the_buffer_size = page_extend((height + 2) * bytes_per_row);
609            the_buffer_copy = (uint8 *)malloc(the_buffer_size);
610            the_buffer = (uint8 *)vm_acquire(the_buffer_size);
611 +          D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
612          }
613   #else
614          use_vosf = false;
575        the_buffer = dga_screen_base;
615   #endif
616   #endif
578        screen_base = (uint32)the_buffer;
617  
618 +        // Set frame buffer base
619 +        D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf));
620 +        screen_base = (uint32)the_buffer;
621          VModes[cur_mode].viRowBytes = bytes_per_row;
581        XSync(x_display, false);
622          return true;
623   #else
624          ErrorAlert("SheepShaver has been compiled with DGA support disabled.");
# Line 711 | Line 751 | static void close_window(void)
751          if (the_gc)
752                  XFreeGC(x_display, the_gc);
753  
714        // Close window
715        if (the_win) {
716                XUnmapWindow(x_display, the_win);
717                wait_unmapped(the_win);
718                XDestroyWindow(x_display, the_win);
719        }
720
754          XFlush(x_display);
755          XSync(x_display, false);
756   }
# Line 755 | Line 788 | static void close_display(void)
788          else if (display_type == DIS_WINDOW)
789                  close_window();
790  
791 +        // Close window
792 +        if (the_win) {
793 +                XUnmapWindow(x_display, the_win);
794 +                wait_unmapped(the_win);
795 +                XDestroyWindow(x_display, the_win);
796 +        }
797 +
798          // Free colormaps
799          if (cmap[0]) {
800                  XFreeColormap(x_display, cmap[0]);
# Line 871 | Line 911 | static void keycode_init(void)
911          }
912   }
913  
914 + // Find Apple mode matching best specified dimensions
915 + static int find_apple_resolution(int xsize, int ysize)
916 + {
917 +        int apple_id;
918 +        if (xsize < 800)
919 +                apple_id = APPLE_640x480;
920 +        else if (xsize < 1024)
921 +                apple_id = APPLE_800x600;
922 +        else if (xsize < 1152)
923 +                apple_id = APPLE_1024x768;
924 +        else if (xsize < 1280) {
925 +                if (ysize < 900)
926 +                        apple_id = APPLE_1152x768;
927 +                else
928 +                        apple_id = APPLE_1152x900;
929 +        }
930 +        else if (xsize < 1600)
931 +                apple_id = APPLE_1280x1024;
932 +        else
933 +                apple_id = APPLE_1600x1200;
934 +        return apple_id;
935 + }
936 +
937 + // Find mode in list of supported modes
938 + static int find_mode(int apple_mode, int apple_id, int type)
939 + {
940 +        for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) {
941 +                if (p->viType == type && p->viAppleID == apple_id && p->viAppleMode == apple_mode)
942 +                        return p - VModes;
943 +        }
944 +        return -1;
945 + }
946 +
947   // Add mode to list of supported modes
948   static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type)
949   {
# Line 891 | Line 964 | static void add_mode(VideoInfo *&p, uint
964                                  p->viXsize = 1024;
965                                  p->viYsize = 768;
966                                  break;
967 +                        case APPLE_1152x768:
968 +                                p->viXsize = 1152;
969 +                                p->viYsize = 768;
970 +                                break;
971                          case APPLE_1152x900:
972                                  p->viXsize = 1152;
973                                  p->viYsize = 900;
# Line 1037 | Line 1114 | bool VideoInit(void)
1114                          add_mode(p, screen_modes, 2, default_mode, APPLE_800x600, DIS_SCREEN);
1115                  if (has_mode(1024, 768))
1116                          add_mode(p, screen_modes, 4, default_mode, APPLE_1024x768, DIS_SCREEN);
1117 +                if (has_mode(1152, 768))
1118 +                        add_mode(p, screen_modes, 64, default_mode, APPLE_1152x768, DIS_SCREEN);
1119                  if (has_mode(1152, 900))
1120                          add_mode(p, screen_modes, 8, default_mode, APPLE_1152x900, DIS_SCREEN);
1121                  if (has_mode(1280, 1024))
# Line 1046 | Line 1125 | bool VideoInit(void)
1125          } else if (screen_modes) {
1126                  int xsize = DisplayWidth(x_display, screen);
1127                  int ysize = DisplayHeight(x_display, screen);
1128 <                int apple_id;
1050 <                if (xsize < 800)
1051 <                        apple_id = APPLE_640x480;
1052 <                else if (xsize < 1024)
1053 <                        apple_id = APPLE_800x600;
1054 <                else if (xsize < 1152)
1055 <                        apple_id = APPLE_1024x768;
1056 <                else if (xsize < 1280)
1057 <                        apple_id = APPLE_1152x900;
1058 <                else if (xsize < 1600)
1059 <                        apple_id = APPLE_1280x1024;
1060 <                else
1061 <                        apple_id = APPLE_1600x1200;
1128 >                int apple_id = find_apple_resolution(xsize, ysize);
1129                  p->viType = DIS_SCREEN;
1130                  p->viRowBytes = 0;
1131                  p->viXsize = xsize;
# Line 1075 | Line 1142 | bool VideoInit(void)
1142  
1143          // Find default mode (window 640x480)
1144          cur_mode = -1;
1145 <        for (p = VModes; p->viType != DIS_INVALID; p++) {
1146 <                if (p->viType == DIS_WINDOW
1147 <                        && p->viAppleID == APPLE_W_640x480
1148 <                        && p->viAppleMode == default_mode) {
1149 <                        cur_mode = p - VModes;
1150 <                        break;
1084 <                }
1145 >        if (has_dga && screen_modes) {
1146 >                int screen_width = DisplayWidth(x_display, screen);
1147 >                int screen_height = DisplayHeight(x_display, screen);
1148 >                int apple_id = find_apple_resolution(screen_width, screen_height);
1149 >                if (apple_id != -1)
1150 >                        cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN);
1151          }
1152 +        if (cur_mode == -1)
1153 +                cur_mode = find_mode(default_mode, APPLE_W_640x480, DIS_WINDOW);
1154          assert(cur_mode != -1);
1155  
1156   #if DEBUG
# Line 1093 | Line 1161 | bool VideoInit(void)
1161          }
1162   #endif
1163  
1096 #ifdef ENABLE_XF86_DGA
1097        if (has_dga && screen_modes) {
1098                int v_bank, v_size;
1099                XF86DGAGetVideo(x_display, screen, &dga_screen_base, &dga_fb_width, &v_bank, &v_size);
1100                D(bug("DGA screen_base %p, v_width %d\n", dga_screen_base, dga_fb_width));
1101        }
1102 #endif
1103
1164          // Open window/screen
1165          if (!open_display())
1166                  return false;
# Line 1112 | Line 1172 | bool VideoInit(void)
1172  
1173          // Start periodic thread
1174          XSync(x_display, false);
1175 <        redraw_thread_active = (pthread_create(&redraw_thread, NULL, redraw_func, NULL) == 0);
1175 >        Set_pthread_attr(&redraw_thread_attr, 0);
1176 >        redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0);
1177          D(bug("Redraw thread installed (%ld)\n", redraw_thread));
1178          return true;
1179   }
# Line 1475 | Line 1536 | static void handle_events(void)
1536                                  break;
1537                          }
1538  
1539 <                        // Mouse moved
1539 >                        // Mouse entered window
1540                          case EnterNotify:
1541 <                                ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y);
1541 >                                if (event.xcrossing.mode != NotifyGrab && event.xcrossing.mode != NotifyUngrab)
1542 >                                        ADBMouseMoved(event.xmotion.x, event.xmotion.y);
1543                                  break;
1544 +
1545 +                        // Mouse moved
1546                          case MotionNotify:
1547 <                                ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y);
1547 >                                ADBMouseMoved(event.xmotion.x, event.xmotion.y);
1548                                  break;
1549  
1550                          // Keyboard
# Line 1547 | Line 1611 | void VideoVBL(void)
1611   *  Install graphics acceleration
1612   */
1613  
1614 < #if 0
1615 < // Rectangle blitting
1616 < static void accl_bitblt(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_bitblt\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 <        // Get blitting parameters
1624 <        int16 src_X = p->src_rect[1] - p->src_bounds[1];
1625 <        int16 src_Y = p->src_rect[0] - p->src_bounds[0];
1626 <        int16 dest_X = p->dest_rect[1] - p->dest_bounds[1];
1627 <        int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0];
1628 <        int16 width = p->dest_rect[3] - p->dest_rect[1] - 1;
1562 <        int16 height = p->dest_rect[2] - p->dest_rect[0] - 1;
1563 <        D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y));
1564 <        D(bug(" width %d, height %d\n", width, height));
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 <        // And perform the blit
1631 <        bitblt_hook(src_X, src_Y, dest_X, dest_Y, width, height);
1632 < }
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 < static bool accl_bitblt_hook(accl_params *p)
1638 < {
1639 <        D(bug("accl_draw_hook %p\n", p));
1637 >        // Invert 8-byte words
1638 >        if (length >= 8) {
1639 >                const int r = (length / 8) % 8;
1640 >                dest += r * 8;
1641  
1642 <        // Check if we can accelerate this bitblt
1643 <        if (p->src_base_addr == screen_base && p->dest_base_addr == screen_base &&
1644 <                display_type == DIS_SCREEN && bitblt_hook != NULL &&
1645 <                ((uint32 *)p)[0x18 >> 2] + ((uint32 *)p)[0x128 >> 2] == 0 &&
1646 <                ((uint32 *)p)[0x130 >> 2] == 0 &&
1647 <                p->transfer_mode == 0 &&
1648 <                p->src_row_bytes > 0 && ((uint32 *)p)[0x15c >> 2] > 0) {
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 <                // Yes, set function pointer
1659 <                p->draw_proc = accl_bitblt;
1660 <                return true;
1658 >        // 32-bit cell to invert?
1659 >        if (length & 4) {
1660 >                INVERT_4(dest, 0);
1661 >                if (bpp <= 16)
1662 >                        dest += 4;
1663          }
1664 <        return false;
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 < // Rectangle filling/inversion
1590 < static void accl_fillrect8(accl_params *p)
1682 > void NQD_invrect(uint32 p)
1683   {
1684 <        D(bug("accl_fillrect8\n"));
1684 >        D(bug("accl_invrect %08x\n", p));
1685  
1686 <        // Get filling parameters
1687 <        int16 dest_X = p->dest_rect[1] - p->dest_bounds[1];
1688 <        int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0];
1689 <        int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1;
1690 <        int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1;
1599 <        uint8 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen;
1686 >        // Get inversion parameters
1687 >        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1688 >        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1689 >        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1690 >        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1691          D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1692 <        D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max));
1692 >        D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes)));
1693  
1694 <        // And perform the fill
1695 <        fillrect8_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color);
1694 >        //!!?? pen_mode == 14
1695 >
1696 >        // And perform the inversion
1697 >        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize));
1698 >        const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1699 >        uint8 *dest = (uint8 *)(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1700 >        width *= bpp;
1701 >        switch (bpp) {
1702 >        case 1:
1703 >                for (int i = 0; i < height; i++) {
1704 >                        do_invrect<8>(dest, width);
1705 >                        dest += dest_row_bytes;
1706 >                }
1707 >                break;
1708 >        case 2:
1709 >                for (int i = 0; i < height; i++) {
1710 >                        do_invrect<16>(dest, width);
1711 >                        dest += dest_row_bytes;
1712 >                }
1713 >                break;
1714 >        case 4:
1715 >                for (int i = 0; i < height; i++) {
1716 >                        do_invrect<32>(dest, width);
1717 >                        dest += dest_row_bytes;
1718 >                }
1719 >                break;
1720 >        }
1721   }
1722  
1723 < static void accl_fillrect32(accl_params *p)
1723 > // Rectangle filling
1724 > template< int bpp >
1725 > static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length)
1726   {
1727 <        D(bug("accl_fillrect32\n"));
1727 > #define FILL_1(PTR, OFS, VAL) ((uint8  *)(PTR))[OFS] = (VAL)
1728 > #define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL)
1729 > #define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL)
1730 > #define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL)
1731  
1732 <        // Get filling parameters
1733 <        int16 dest_X = p->dest_rect[1] - p->dest_bounds[1];
1734 <        int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0];
1735 <        int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1;
1736 <        int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1;
1737 <        uint32 color = p->pen_mode == 8 ? p->fore_pen : p->back_pen;
1617 <        D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1618 <        D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max));
1732 > #ifndef UNALIGNED_PROFITABLE
1733 >        // Align on 16-bit boundaries
1734 >        if (bpp < 16 && (((uintptr)dest) & 1)) {
1735 >                FILL_1(dest, 0, color);
1736 >                dest += 1; length -= 1;
1737 >        }
1738  
1739 <        // And perform the fill
1740 <        fillrect32_hook(dest_X, dest_Y, dest_X_max, dest_Y_max, color);
1739 >        // Align on 32-bit boundaries
1740 >        if (bpp < 32 && (((uintptr)dest) & 2)) {
1741 >                FILL_2(dest, 0, color);
1742 >                dest += 2; length -= 2;
1743 >        }
1744 > #endif
1745 >
1746 >        // Fill 8-byte words
1747 >        if (length >= 8) {
1748 >                const uint64 c = (((uint64)color) << 32) | color;
1749 >                const int r = (length / 8) % 8;
1750 >                dest += r * 8;
1751 >
1752 >                int n = ((length / 8) + 7) / 8;
1753 >                switch (r) {
1754 >                case 0: do {
1755 >                                dest += 64;
1756 >                                FILL_8(dest, -8, c);
1757 >                case 7: FILL_8(dest, -7, c);
1758 >                case 6: FILL_8(dest, -6, c);
1759 >                case 5: FILL_8(dest, -5, c);
1760 >                case 4: FILL_8(dest, -4, c);
1761 >                case 3: FILL_8(dest, -3, c);
1762 >                case 2: FILL_8(dest, -2, c);
1763 >                case 1: FILL_8(dest, -1, c);
1764 >                                } while (--n > 0);
1765 >                }
1766 >        }
1767 >
1768 >        // 32-bit cell to fill?
1769 >        if (length & 4) {
1770 >                FILL_4(dest, 0, color);
1771 >                if (bpp <= 16)
1772 >                        dest += 4;
1773 >        }
1774 >
1775 >        // 16-bit cell to fill?
1776 >        if (bpp <= 16 && (length & 2)) {
1777 >                FILL_2(dest, 0, color);
1778 >                if (bpp <= 8)
1779 >                        dest += 2;
1780 >        }
1781 >
1782 >        // 8-bit cell to fill?
1783 >        if (bpp <= 8 && (length & 1))
1784 >                FILL_1(dest, 0, color);
1785 >
1786 > #undef FILL_1
1787 > #undef FILL_2
1788 > #undef FILL_4
1789 > #undef FILL_8
1790   }
1791  
1792 < static void accl_invrect(accl_params *p)
1792 > void NQD_fillrect(uint32 p)
1793   {
1794 <        D(bug("accl_invrect\n"));
1794 >        D(bug("accl_fillrect %08x\n", p));
1795  
1796 <        // Get inversion parameters
1797 <        int16 dest_X = p->dest_rect[1] - p->dest_bounds[1];
1798 <        int16 dest_Y = p->dest_rect[0] - p->dest_bounds[0];
1799 <        int16 dest_X_max = p->dest_rect[3] - p->dest_bounds[1] - 1;
1800 <        int16 dest_Y_max = p->dest_rect[2] - p->dest_bounds[0] - 1;
1796 >        // Get filling parameters
1797 >        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1798 >        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1799 >        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1800 >        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1801 >        uint32 color = ReadMacInt32(p + acclPenMode) == 8 ? ReadMacInt32(p + acclForePen) : ReadMacInt32(p + acclBackPen);
1802          D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y));
1803 <        D(bug(" dest X max %d, dest Y max %d\n", dest_X_max, dest_Y_max));
1804 <
1636 <        //!!?? pen_mode == 14
1803 >        D(bug(" width %d, height %d\n", width, height));
1804 >        D(bug(" bytes_per_row %d color %08x\n", (int32)ReadMacInt32(p + acclDestRowBytes), color));
1805  
1806 <        // And perform the inversion
1807 <        invrect_hook(dest_X, dest_Y, dest_X_max, dest_Y_max);
1806 >        // And perform the fill
1807 >        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize));
1808 >        const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1809 >        uint8 *dest = (uint8 *)(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp));
1810 >        width *= bpp;
1811 >        switch (bpp) {
1812 >        case 1:
1813 >                for (int i = 0; i < height; i++) {
1814 >                        memset(dest, color, width);
1815 >                        dest += dest_row_bytes;
1816 >                }
1817 >                break;
1818 >        case 2:
1819 >                for (int i = 0; i < height; i++) {
1820 >                        do_fillrect<16>(dest, color, width);
1821 >                        dest += dest_row_bytes;
1822 >                }
1823 >                break;
1824 >        case 4:
1825 >                for (int i = 0; i < height; i++) {
1826 >                        do_fillrect<32>(dest, color, width);
1827 >                        dest += dest_row_bytes;
1828 >                }
1829 >                break;
1830 >        }
1831   }
1832  
1833 < static bool accl_fillrect_hook(accl_params *p)
1833 > bool NQD_fillrect_hook(uint32 p)
1834   {
1835 <        D(bug("accl_fillrect_hook %p\n", p));
1835 >        D(bug("accl_fillrect_hook %08x\n", p));
1836  
1837          // Check if we can accelerate this fillrect
1838 <        if (p->dest_base_addr == screen_base && ((uint32 *)p)[0x284 >> 2] != 0 && display_type == DIS_SCREEN) {
1839 <                if (p->transfer_mode == 8) {
1838 >        if (ReadMacInt32(p + 0x284) != 0 && ReadMacInt32(p + acclDestPixelSize) >= 8) {
1839 >                const int transfer_mode = ReadMacInt32(p + acclTransferMode);
1840 >                if (transfer_mode == 8) {
1841                          // Fill
1842 <                        if (p->dest_pixel_size == 8 && fillrect8_hook != NULL) {
1843 <                                p->draw_proc = accl_fillrect8;
1844 <                                return true;
1845 <                        } else if (p->dest_pixel_size == 32 && fillrect32_hook != NULL) {
1654 <                                p->draw_proc = accl_fillrect32;
1655 <                                return true;
1656 <                        }
1657 <                } else if (p->transfer_mode == 10 && invrect_hook != NULL) {
1842 >                        WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_FILLRECT));
1843 >                        return true;
1844 >                }
1845 >                else if (transfer_mode == 10) {
1846                          // Invert
1847 <                        p->draw_proc = accl_invrect;
1847 >                        WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_INVRECT));
1848                          return true;
1849                  }
1850          }
1851          return false;
1852   }
1853  
1854 + // Rectangle blitting
1855 + // TODO: optimize for VOSF and target pixmap == screen
1856 + void NQD_bitblt(uint32 p)
1857 + {
1858 +        D(bug("accl_bitblt %08x\n", p));
1859 +
1860 +        // Get blitting parameters
1861 +        int16 src_X  = (int16)ReadMacInt16(p + acclSrcRect + 2) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 2);
1862 +        int16 src_Y  = (int16)ReadMacInt16(p + acclSrcRect + 0) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 0);
1863 +        int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2);
1864 +        int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0);
1865 +        int16 width  = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2);
1866 +        int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0);
1867 +        D(bug(" src addr %08x, dest addr %08x\n", ReadMacInt32(p + acclSrcBaseAddr), ReadMacInt32(p + acclDestBaseAddr)));
1868 +        D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y));
1869 +        D(bug(" width %d, height %d\n", width, height));
1870 +
1871 +        // And perform the blit
1872 +        const int bpp = bytes_per_pixel(ReadMacInt32(p + acclSrcPixelSize));
1873 +        width *= bpp;
1874 +        if ((int32)ReadMacInt32(p + acclSrcRowBytes) > 0) {
1875 +                const int src_row_bytes = (int32)ReadMacInt32(p + acclSrcRowBytes);
1876 +                const int dst_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes);
1877 +                uint8 *src = (uint8 *)ReadMacInt32(p + acclSrcBaseAddr) + (src_Y * src_row_bytes) + (src_X * bpp);
1878 +                uint8 *dst = (uint8 *)ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dst_row_bytes) + (dest_X * bpp);
1879 +                for (int i = 0; i < height; i++) {
1880 +                        memcpy(dst, src, width);
1881 +                        src += src_row_bytes;
1882 +                        dst += dst_row_bytes;
1883 +                }
1884 +        }
1885 +        else {
1886 +                const int src_row_bytes = -(int32)ReadMacInt32(p + acclSrcRowBytes);
1887 +                const int dst_row_bytes = -(int32)ReadMacInt32(p + acclDestRowBytes);
1888 +                uint8 *src = (uint8 *)ReadMacInt32(p + acclSrcBaseAddr) + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp);
1889 +                uint8 *dst = (uint8 *)ReadMacInt32(p + acclDestBaseAddr) + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp);
1890 +                for (int i = height - 1; i >= 0; i--) {
1891 +                        memcpy(dst, src, width);
1892 +                        src -= src_row_bytes;
1893 +                        dst -= dst_row_bytes;
1894 +                }
1895 +        }
1896 + }
1897 +
1898 + /*
1899 +  BitBlt transfer modes:
1900 +  0 : srcCopy
1901 +  1 : srcOr
1902 +  2 : srcXor
1903 +  3 : srcBic
1904 +  4 : notSrcCopy
1905 +  5 : notSrcOr
1906 +  6 : notSrcXor
1907 +  7 : notSrcBic
1908 +  32 : blend
1909 +  33 : addPin
1910 +  34 : addOver
1911 +  35 : subPin
1912 +  36 : transparent
1913 +  37 : adMax
1914 +  38 : subOver
1915 +  39 : adMin
1916 +  50 : hilite
1917 + */
1918 +
1919 + bool NQD_bitblt_hook(uint32 p)
1920 + {
1921 +        D(bug("accl_draw_hook %08x\n", p));
1922 +
1923 +        // Check if we can accelerate this bitblt
1924 +        if (ReadMacInt32(p + 0x018) + ReadMacInt32(p + 0x128) == 0 &&
1925 +                ReadMacInt32(p + 0x130) == 0 &&
1926 +                ReadMacInt32(p + acclSrcPixelSize) >= 8 &&
1927 +                ReadMacInt32(p + acclSrcPixelSize) == ReadMacInt32(p + acclDestPixelSize) &&
1928 +                (ReadMacInt32(p + acclSrcRowBytes) ^ ReadMacInt32(p + acclDestRowBytes)) >= 0 && // same sign?
1929 +                ReadMacInt32(p + acclTransferMode) == 0 &&                                                                               // srcCopy?
1930 +                ReadMacInt32(p + 0x15c) > 0) {
1931 +
1932 +                // Yes, set function pointer
1933 +                WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_BITBLT));
1934 +                return true;
1935 +        }
1936 +        return false;
1937 + }
1938 +
1939   // Wait for graphics operation to finish
1940 < static bool accl_sync_hook(void *arg)
1940 > bool NQD_sync_hook(uint32 arg)
1941   {
1942 <        D(bug("accl_sync_hook %p\n", arg));
1670 <        if (sync_hook != NULL)
1671 <                sync_hook();
1942 >        D(bug("accl_sync_hook %08x\n", arg));
1943          return true;
1944   }
1945  
1675 static struct accl_hook_info bitblt_hook_info = {accl_bitblt_hook, accl_sync_hook, ACCL_BITBLT};
1676 static struct accl_hook_info fillrect_hook_info = {accl_fillrect_hook, accl_sync_hook, ACCL_FILLRECT};
1677 #endif
1678
1946   void VideoInstallAccel(void)
1947   {
1948 +        // Temporary hack until it's fixed for e.g. little-endian & 64-bit platforms
1949 + #ifndef __powerpc__
1950 +        return;
1951 + #endif
1952 +
1953          // Install acceleration hooks
1954          if (PrefsFindBool("gfxaccel")) {
1955                  D(bug("Video: Installing acceleration hooks\n"));
1956 < //!!    NQDMisc(6, &bitblt_hook_info);
1957 < //              NQDMisc(6, &fillrect_hook_info);
1956 >                uint32 base;
1957 >
1958 >                SheepVar bitblt_hook_info(sizeof(accl_hook_info));
1959 >                base = bitblt_hook_info.addr();
1960 >                WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK));
1961 >                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
1962 >                WriteMacInt32(base + 8, ACCL_BITBLT);
1963 >                NQDMisc(6, bitblt_hook_info.ptr());
1964 >
1965 >                SheepVar fillrect_hook_info(sizeof(accl_hook_info));
1966 >                base = fillrect_hook_info.addr();
1967 >                WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK));
1968 >                WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK));
1969 >                WriteMacInt32(base + 8, ACCL_FILLRECT);
1970 >                NQDMisc(6, fillrect_hook_info.ptr());
1971          }
1972   }
1973  
# Line 1999 | Line 2284 | static void *redraw_func(void *arg)
2284                                          XF86DGADirectVideo(x_display, screen, 0);
2285                                          XUngrabPointer(x_display, CurrentTime);
2286                                          XUngrabKeyboard(x_display, CurrentTime);
2287 +                                        XUnmapWindow(x_display, the_win);
2288 +                                        wait_unmapped(the_win);
2289 +                                        XDestroyWindow(x_display, the_win);
2290   #endif
2291                                          XSync(x_display, false);
2292                                          XDisplayUnlock();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines