ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/video_x.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/video_x.cpp (file contents):
Revision 1.18 by cebix, 2000-07-22T18:12:35Z vs.
Revision 1.19 by gbeauche, 2000-09-22T17:16:31Z

# Line 52 | Line 52
52   # include <sys/mman.h>
53   #endif
54  
55 + #ifdef ENABLE_VOSF
56 + # include <math.h> // log()
57 + # include <unistd.h>
58 + # include <signal.h>
59 + # include <fcntl.h>
60 + # include <sys/mman.h>
61 + #endif
62 +
63   #include "cpu_emulation.h"
64   #include "main.h"
65   #include "adb.h"
# Line 154 | Line 162 | static XF86VidModeModeInfo **x_video_mod
162   static int num_x_video_modes;
163   #endif
164  
165 + #ifdef ENABLE_VOSF
166 + static bool use_vosf = true;                                            // Flag: VOSF enabled
167 + #else
168 + static const bool use_vosf = false;                                     // Flag: VOSF enabled
169 + #endif
170 +
171 + #ifdef ENABLE_VOSF
172 + static uint8 * the_host_buffer;                                         // Host frame buffer in VOSF mode
173 + static uint32 the_buffer_size;                                          // Size of allocated the_buffer
174 + #endif
175 +
176 + #ifdef ENABLE_VOSF
177 + // Variables for Video on SEGV support (taken from the Win32 port)
178 + struct ScreenPageInfo {
179 +    int top, bottom;                    // Mapping between this virtual page and Mac scanlines
180 + };
181 +
182 + struct ScreenInfo {
183 +    uint32 memBase;                             // Real start address
184 +    uint32 memStart;                    // Start address aligned to page boundary
185 +    uint32 memEnd;                              // Address of one-past-the-end of the screen
186 +    uint32 memLength;                   // Length of the memory addressed by the screen pages
187 +    
188 +    uint32 pageSize;                    // Size of a page
189 +    int pageBits;                               // Shift count to get the page number
190 +    uint32 pageCount;                   // Number of pages allocated to the screen
191 +    
192 +    uint8 * dirtyPages;                 // Table of flags set if page was altered
193 +    ScreenPageInfo * pageInfo;  // Table of mappings page -> Mac scanlines
194 + };
195 +
196 + static ScreenInfo mainBuffer;
197 +
198 + #define PFLAG_SET(page)                 mainBuffer.dirtyPages[page] = 1
199 + #define PFLAG_CLEAR(page)               mainBuffer.dirtyPages[page] = 0
200 + #define PFLAG_ISSET(page)               mainBuffer.dirtyPages[page]
201 + #define PFLAG_ISCLEAR(page)             (mainBuffer.dirtyPages[page] == 0)
202 + #ifdef UNALIGNED_PROFITABLE
203 + # define PFLAG_ISCLEAR_4(page)  (*((uint32 *)(mainBuffer.dirtyPages + page)) == 0)
204 + #else
205 + # define PFLAG_ISCLEAR_4(page)  \
206 +                (mainBuffer.dirtyPages[page  ] == 0) \
207 +        &&      (mainBuffer.dirtyPages[page+1] == 0) \
208 +        &&      (mainBuffer.dirtyPages[page+2] == 0) \
209 +        &&      (mainBuffer.dirtyPages[page+3] == 0)
210 + #endif
211 + #define PFLAG_CLEAR_ALL                 memset(mainBuffer.dirtyPages, 0, mainBuffer.pageCount)
212 + #define PFLAG_SET_ALL                   memset(mainBuffer.dirtyPages, 1, mainBuffer.pageCount)
213 +
214 + static int zero_fd = -1;
215 + static bool Screen_fault_handler_init();
216 + static struct sigaction vosf_sa;
217 +
218 + #ifdef HAVE_PTHREADS
219 + static pthread_mutex_t Screen_draw_lock = PTHREAD_MUTEX_INITIALIZER;    // Mutex to protect frame buffer (dirtyPages in fact)
220 + #endif
221 +
222 + #endif
223 +
224 + // VideoRefresh function
225 + void VideoRefreshInit(void);
226 + static void (*video_refresh)(void);
227  
228   // Prototypes
229   static void *redraw_func(void *arg);
# Line 167 | Line 237 | extern Display *x_display;
237   // From sys_unix.cpp
238   extern void SysMountFirstFloppy(void);
239  
240 + #ifdef ENABLE_VOSF
241 + # include "video_vosf.h"
242 + #endif
243 +
244  
245   /*
246   *  Initialization
# Line 175 | Line 249 | extern void SysMountFirstFloppy(void);
249   // Set VideoMonitor according to video mode
250   void set_video_monitor(int width, int height, int bytes_per_row, bool native_byte_order)
251   {
252 < #if !REAL_ADDRESSING
252 > #if !REAL_ADDRESSING && !DIRECT_ADDRESSING
253          int layout = FLAYOUT_DIRECT;
254          switch (depth) {
255                  case 1:
# Line 337 | Line 411 | static bool init_window(int width, int h
411                  img->bitmap_bit_order = MSBFirst;
412          }
413  
414 + #ifdef ENABLE_VOSF
415 +        // Allocate a page-aligned chunk of memory for frame buffer
416 +        the_buffer_size = align_on_page_boundary((aligned_height + 2) * img->bytes_per_line);
417 +        the_host_buffer = the_buffer_copy;
418 +        
419 +        the_buffer_copy = (uint8 *)allocate_framebuffer(the_buffer_size);
420 +        memset(the_buffer_copy, 0, the_buffer_size);
421 +        
422 +        the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size);
423 +        memset(the_buffer, 0, the_buffer_size);
424 + #else
425          // Allocate memory for frame buffer
426          the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line);
427 + #endif
428  
429          // Create GC
430          the_gc = XCreateGC(x_display, the_win, 0, 0);
# Line 352 | Line 438 | static bool init_window(int width, int h
438          XDefineCursor(x_display, the_win, mac_cursor);
439  
440          // Set VideoMonitor
441 +        bool native_byte_order;
442   #ifdef WORDS_BIGENDIAN
443 <        set_video_monitor(width, height, img->bytes_per_line, img->bitmap_bit_order == MSBFirst);
443 >        native_byte_order = (img->bitmap_bit_order == MSBFirst);
444   #else
445 <        set_video_monitor(width, height, img->bytes_per_line, img->bitmap_bit_order == LSBFirst);
445 >        native_byte_order = (img->bitmap_bit_order == LSBFirst);
446 > #endif
447 > #ifdef ENABLE_VOSF
448 >        do_update_framebuffer = GET_FBCOPY_FUNC(depth, native_byte_order, DISPLAY_WINDOW);
449   #endif
450 +        set_video_monitor(width, height, img->bytes_per_line, native_byte_order);
451          
452 < #if REAL_ADDRESSING
453 <        VideoMonitor.mac_frame_base = (uint32)the_buffer;
452 > #if REAL_ADDRESSING || DIRECT_ADDRESSING
453 >        VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer);
454   #else
455          VideoMonitor.mac_frame_base = MacFrameBaseMac;
456   #endif
# Line 492 | Line 583 | static bool init_fbdev_dga(char *in_fb_n
583                  }
584          }
585          
586 + #if REAL_ADDRESSING || DIRECT_ADDRESSING
587 +        // If the blit function is null, i.e. just a copy of the buffer,
588 +        // we first try to avoid the allocation of a temporary frame buffer
589 +        use_vosf = true;
590 +        do_update_framebuffer = GET_FBCOPY_FUNC(depth, true, DISPLAY_DGA);
591 +        if (do_update_framebuffer == FBCOPY_FUNC(fbcopy_raw))
592 +                use_vosf = false;
593 +        
594 +        if (use_vosf) {
595 +                the_host_buffer = the_buffer;
596 +                the_buffer_size = align_on_page_boundary((height + 2) * bytes_per_row);
597 +                the_buffer_copy = (uint8 *)malloc(the_buffer_size);
598 +                memset(the_buffer_copy, 0, the_buffer_size);
599 +                the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size);
600 +                memset(the_buffer, 0, the_buffer_size);
601 +        }
602 + #elif ENABLE_VOSF
603 +        use_vosf = false;
604 + #endif
605 +        
606          set_video_monitor(width, height, bytes_per_row, true);
607 < #if REAL_ADDRESSING
608 <        VideoMonitor.mac_frame_base = (uint32)the_buffer;
607 > #if REAL_ADDRESSING || DIRECT_ADDRESSING
608 >        VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer);
609   #else
610          VideoMonitor.mac_frame_base = MacFrameBaseMac;
611   #endif
# Line 575 | Line 686 | static bool init_xf86_dga(int width, int
686                          bytes_per_row *= 4;
687                          break;
688          }
689 +        
690 + #if REAL_ADDRESSING || DIRECT_ADDRESSING
691 +        // If the blit function is null, i.e. just a copy of the buffer,
692 +        // we first try to avoid the allocation of a temporary frame buffer
693 +        use_vosf = true;
694 +        do_update_framebuffer = GET_FBCOPY_FUNC(depth, true, DISPLAY_DGA);
695 +        if (do_update_framebuffer == FBCOPY_FUNC(fbcopy_raw))
696 +                use_vosf = false;
697 +        
698 +        if (use_vosf) {
699 +                the_host_buffer = the_buffer;
700 +                the_buffer_size = align_on_page_boundary((height + 2) * bytes_per_row);
701 +                the_buffer_copy = (uint8 *)malloc(the_buffer_size);
702 +                memset(the_buffer_copy, 0, the_buffer_size);
703 +                the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size);
704 +                memset(the_buffer, 0, the_buffer_size);
705 +        }
706 + #elif ENABLE_VOSF
707 +        // The UAE memory handlers will already color conversion, if needed.
708 +        use_vosf = false;
709 + #endif
710 +        
711          set_video_monitor(width, height, bytes_per_row, true);
712 < #if REAL_ADDRESSING
713 <        VideoMonitor.mac_frame_base = (uint32)the_buffer;
714 <        MacFrameLayout = FLAYOUT_DIRECT;
712 > #if REAL_ADDRESSING || DIRECT_ADDRESSING
713 >        VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer);
714 > //      MacFrameLayout = FLAYOUT_DIRECT;
715   #else
716          VideoMonitor.mac_frame_base = MacFrameBaseMac;
717   #endif
# Line 654 | Line 787 | static void keycode_init(void)
787          }
788   }
789  
790 + bool VideoInitBuffer()
791 + {
792 + #ifdef ENABLE_VOSF
793 +        if (use_vosf) {
794 +                const uint32 page_size  = getpagesize();
795 +                const uint32 page_mask  = page_size - 1;
796 +                
797 +                mainBuffer.memBase      = (uint32) the_buffer;
798 +                // Align the frame buffer on page boundary
799 +                mainBuffer.memStart             = (uint32)((((unsigned long) the_buffer) + page_mask) & ~page_mask);
800 +                mainBuffer.memLength    = the_buffer_size;
801 +                mainBuffer.memEnd       = mainBuffer.memStart + mainBuffer.memLength;
802 +
803 +                mainBuffer.pageSize     = page_size;
804 +                mainBuffer.pageCount    = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize;
805 +                mainBuffer.pageBits     = int( log(mainBuffer.pageSize) / log(2.0) );
806 +
807 +                if (mainBuffer.dirtyPages != 0)
808 +                        free(mainBuffer.dirtyPages);
809 +
810 +                mainBuffer.dirtyPages = (uint8 *) malloc(mainBuffer.pageCount);
811 +
812 +                if (mainBuffer.pageInfo != 0)
813 +                        free(mainBuffer.pageInfo);
814 +
815 +                mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo));
816 +
817 +                if ((mainBuffer.dirtyPages == 0) || (mainBuffer.pageInfo == 0))
818 +                        return false;
819 +
820 +                PFLAG_CLEAR_ALL;
821 +
822 +                uint32 a = 0;
823 +                for (int i = 0; i < mainBuffer.pageCount; i++) {
824 +                        int y1 = a / VideoMonitor.bytes_per_row;
825 +                        if (y1 >= VideoMonitor.y)
826 +                                y1 = VideoMonitor.y - 1;
827 +
828 +                        int y2 = (a + mainBuffer.pageSize) / VideoMonitor.bytes_per_row;
829 +                        if (y2 >= VideoMonitor.y)
830 +                                y2 = VideoMonitor.y - 1;
831 +
832 +                        mainBuffer.pageInfo[i].top = y1;
833 +                        mainBuffer.pageInfo[i].bottom = y2;
834 +
835 +                        a += mainBuffer.pageSize;
836 +                        if (a > mainBuffer.memLength)
837 +                                a = mainBuffer.memLength;
838 +                }
839 +                
840 +                // We can now write-protect the frame buffer
841 +                if (mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ) != 0)
842 +                        return false;
843 +        }
844 + #endif
845 +        return true;
846 + }
847 +
848   bool VideoInit(bool classic)
849   {
850 + #ifdef ENABLE_VOSF
851 +        // Open /dev/zero
852 +        zero_fd = open("/dev/zero", O_RDWR);
853 +        if (zero_fd < 0) {
854 +        char str[256];
855 +                sprintf(str, GetString(STR_NO_DEV_ZERO_ERR), strerror(errno));
856 +                ErrorAlert(str);
857 +        return false;
858 +        }
859 +        
860 +        // Zero the mainBuffer structure
861 +        mainBuffer.dirtyPages = 0;
862 +        mainBuffer.pageInfo = 0;
863 + #endif
864 +        
865          // Check if X server runs on local machine
866          local_X11 = (strncmp(XDisplayName(x_display_name), ":", 1) == 0)
867                   || (strncmp(XDisplayName(x_display_name), "unix:", 5) == 0);
# Line 807 | Line 1013 | bool VideoInit(bool classic)
1013          pthread_mutex_lock(&frame_buffer_lock);
1014   #endif
1015  
1016 < #if !REAL_ADDRESSING
1016 > #if !REAL_ADDRESSING && !DIRECT_ADDRESSING
1017          // Set variables for UAE memory mapping
1018          MacFrameBaseHost = the_buffer;
1019          MacFrameSize = VideoMonitor.bytes_per_row * VideoMonitor.y;
# Line 817 | Line 1023 | bool VideoInit(bool classic)
1023                  MacFrameLayout = FLAYOUT_NONE;
1024   #endif
1025  
1026 + #ifdef ENABLE_VOSF
1027 +        if (use_vosf) {
1028 +                // Initialize the mainBuffer structure
1029 +                if (!VideoInitBuffer()) {
1030 +                        // TODO: STR_VOSF_INIT_ERR ?
1031 +                        ErrorAlert("Could not initialize Video on SEGV signals");
1032 +                return false;
1033 +                }
1034 +
1035 +                // Initialize the handler for SIGSEGV
1036 +                if (!Screen_fault_handler_init()) {
1037 +                        // TODO: STR_VOSF_INIT_ERR ?
1038 +                        ErrorAlert("Could not initialize Video on SEGV signals");
1039 +                        return false;
1040 +                }
1041 +        }
1042 + #endif
1043 +        
1044 +        // Initialize VideoRefresh function
1045 +        VideoRefreshInit();
1046 +        
1047          XSync(x_display, false);
1048  
1049   #ifdef HAVE_PTHREADS
# Line 885 | Line 1112 | void VideoExit(void)
1112                          XFreeColormap(x_display, cmap[0]);
1113                          XFreeColormap(x_display, cmap[1]);
1114                  }
1115 +                
1116 +                if (!use_vosf) {
1117 +                        if (the_buffer) {
1118 +                                free(the_buffer);
1119 +                                the_buffer = NULL;
1120 +                        }
1121  
1122 <                if (the_buffer) {
1123 <                        free(the_buffer);
1124 <                        the_buffer = NULL;
1122 >                        if (!have_shm && the_buffer_copy) {
1123 >                                free(the_buffer_copy);
1124 >                                the_buffer_copy = NULL;
1125 >                        }
1126 >                }
1127 > #ifdef ENABLE_VOSF
1128 >                else {
1129 >                        if (the_buffer != (uint8 *)MAP_FAILED) {
1130 >                                munmap((caddr_t)the_buffer, the_buffer_size);
1131 >                                the_buffer = 0;
1132 >                        }
1133 >                        
1134 >                        if (the_buffer_copy != (uint8 *)MAP_FAILED) {
1135 >                                munmap((caddr_t)the_buffer_copy, the_buffer_size);
1136 >                                the_buffer_copy = 0;
1137 >                        }
1138 >                }
1139 > #endif
1140 >        }
1141 >        
1142 > #ifdef ENABLE_VOSF
1143 >        if (use_vosf) {
1144 >                // Clear mainBuffer data
1145 >                if (mainBuffer.pageInfo) {
1146 >                        free(mainBuffer.pageInfo);
1147 >                        mainBuffer.pageInfo = 0;
1148                  }
1149  
1150 <                if (!have_shm && the_buffer_copy) {
1151 <                        free(the_buffer_copy);
1152 <                        the_buffer_copy = NULL;
1150 >                if (mainBuffer.dirtyPages) {
1151 >                        free(mainBuffer.dirtyPages);
1152 >                        mainBuffer.dirtyPages = 0;
1153                  }
1154          }
1155 +
1156 +        // Close /dev/zero
1157 +        if (zero_fd > 0)
1158 +                close(zero_fd);
1159 + #endif
1160   }
1161  
1162  
# Line 1030 | Line 1291 | static void resume_emul(void)
1291  
1292          // Restore frame buffer
1293          if (fb_save) {
1294 + #if REAL_ADDRESSING || DIRECT_ADDRESSING
1295 +                if (use_vosf)
1296 +                        mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ|PROT_WRITE);
1297 + #endif
1298                  memcpy(the_buffer, fb_save, VideoMonitor.y * VideoMonitor.bytes_per_row);
1299 + #if REAL_ADDRESSING || DIRECT_ADDRESSING
1300 +                if (use_vosf) {
1301 +                        mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ);
1302 +                        do_update_framebuffer(the_host_buffer, the_buffer, VideoMonitor.x * VideoMonitor.bytes_per_row);
1303 + #ifdef HAVE_PTHREADS
1304 +                        pthread_mutex_lock(&Screen_draw_lock);
1305 + #endif
1306 +                        PFLAG_CLEAR_ALL;
1307 + #ifdef HAVE_PTHREADS
1308 +                        pthread_mutex_unlock(&Screen_draw_lock);
1309 + #endif
1310 +                }
1311 + #endif
1312                  free(fb_save);
1313                  fb_save = NULL;
1314          }
# Line 1311 | Line 1589 | static void handle_events(void)
1589                          // Hidden parts exposed, force complete refresh of window
1590                          case Expose:
1591                                  if (display_type == DISPLAY_WINDOW) {
1592 + #ifdef ENABLE_VOSF
1593 +                                        const XExposeEvent & xev = event.xexpose;
1594 +                                        const uint32 start = xev.y * VideoMonitor.bytes_per_row + xev.x;
1595 +                                        const uint32 end = (xev.y + xev.height - 1) * VideoMonitor.bytes_per_row + (xev.x + xev.width);
1596 +                                        int page = start >> mainBuffer.pageBits;
1597 +                                        uint32 addr = start;
1598 +                                        while (addr < end) {
1599 +                                                memset(the_buffer_copy + addr, 0, mainBuffer.pageSize);
1600 +                                                addr += mainBuffer.pageSize;
1601 + #ifdef HAVE_PTHREADS
1602 +                                                pthread_mutex_lock(&Screen_draw_lock);
1603 + #endif
1604 +                                                PFLAG_SET(page);
1605 + #ifdef HAVE_PTHREADS
1606 +                                                pthread_mutex_unlock(&Screen_draw_lock);
1607 + #endif
1608 +                                                ++page;
1609 +                                        }
1610 + #else
1611                                          if (frame_skip == 0) {  // Dynamic refresh
1612                                                  int x1, y1;
1613                                                  for (y1=0; y1<16; y1++)
# Line 1319 | Line 1616 | static void handle_events(void)
1616                                                  nr_boxes = 16 * 16;
1617                                          } else
1618                                                  memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
1619 + #endif /* ENABLE_VOSF */
1620                                  }
1621                                  break;
1622                  }
# Line 1536 | Line 1834 | static void update_display_static(void)
1834  
1835  
1836   /*
1837 + *      Screen refresh functions
1838 + */
1839 +
1840 + // The specialisations hereunder are meant to enable VOSF with DGA in direct
1841 + // addressing mode in case the address spaces (RAM, ROM, FrameBuffer) could
1842 + // not get mapped correctly with respect to the predetermined host frame
1843 + // buffer base address.
1844 + //
1845 + // Hmm, in other words, when in direct addressing mode and DGA is requested,
1846 + // we first try to "triple allocate" the address spaces according to the real
1847 + // host frame buffer address. Then, if it fails, we will use a temporary
1848 + // frame buffer thus making the real host frame buffer updated when pages
1849 + // of the temp frame buffer are altered.
1850 + //
1851 + // As a side effect, a little speed gain in screen updates could be noticed
1852 + // for other modes than DGA.
1853 + //
1854 + // The following two functions below are inline so that a clever compiler
1855 + // could specialise the code according to the current screen depth and
1856 + // display type. A more clever compiler would the job by itself though...
1857 + // (update_display_vosf is inlined as well)
1858 +
1859 + static inline void possibly_quit_dga_mode()
1860 + {
1861 + #if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA)
1862 +        // Quit DGA mode if requested
1863 +        if (quit_full_screen) {
1864 +                quit_full_screen = false;
1865 + #ifdef ENABLE_XF86_DGA
1866 +                XF86DGADirectVideo(x_display, screen, 0);
1867 + #endif
1868 +                XUngrabPointer(x_display, CurrentTime);
1869 +                XUngrabKeyboard(x_display, CurrentTime);
1870 +                XUnmapWindow(x_display, the_win);
1871 +                XSync(x_display, false);
1872 +        }
1873 + #endif
1874 + }
1875 +
1876 + static inline void handle_palette_changes(int depth, int display_type)
1877 + {
1878 + #ifdef HAVE_PTHREADS
1879 +        pthread_mutex_lock(&palette_lock);
1880 + #endif
1881 +        if (palette_changed) {
1882 +                palette_changed = false;
1883 +                if (depth == 8) {
1884 +                        XStoreColors(x_display, cmap[0], palette, 256);
1885 +                        XStoreColors(x_display, cmap[1], palette, 256);
1886 +                                
1887 + #ifdef ENABLE_XF86_DGA
1888 +                        if (display_type == DISPLAY_DGA) {
1889 +                                current_dga_cmap ^= 1;
1890 +                                XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
1891 +                        }
1892 + #endif
1893 +                }
1894 +        }
1895 + #ifdef HAVE_PTHREADS
1896 +        pthread_mutex_unlock(&palette_lock);
1897 + #endif
1898 + }
1899 +
1900 + static void video_refresh_dga(void)
1901 + {
1902 +        // Quit DGA mode if requested
1903 +        possibly_quit_dga_mode();
1904 +        
1905 +        // Handle X events
1906 +        handle_events();
1907 +        
1908 +        // Handle palette changes
1909 +        handle_palette_changes(depth, DISPLAY_DGA);
1910 + }
1911 +
1912 + #if REAL_ADDRESSING || DIRECT_ADDRESSING
1913 + static void video_refresh_dga_vosf(void)
1914 + {
1915 +        // Quit DGA mode if requested
1916 +        possibly_quit_dga_mode();
1917 +        
1918 +        // Handle X events
1919 +        handle_events();
1920 +        
1921 +        // Handle palette changes
1922 +        handle_palette_changes(depth, DISPLAY_DGA);
1923 +        
1924 +        // Update display (VOSF variant)
1925 +        static int tick_counter = 0;
1926 +        if (++tick_counter >= frame_skip) {
1927 +                tick_counter = 0;
1928 + #ifdef HAVE_PTHREADS
1929 +                pthread_mutex_lock(&Screen_draw_lock);
1930 + #endif
1931 +                update_display_dga_vosf();
1932 + #ifdef HAVE_PTHREADS
1933 +                pthread_mutex_unlock(&Screen_draw_lock);
1934 + #endif
1935 +        }
1936 + }
1937 + #endif
1938 +
1939 + #ifdef ENABLE_VOSF
1940 + static void video_refresh_window_vosf(void)
1941 + {
1942 +        // Quit DGA mode if requested
1943 +        possibly_quit_dga_mode();
1944 +        
1945 +        // Handle X events
1946 +        handle_events();
1947 +        
1948 +        // Handle palette changes
1949 +        handle_palette_changes(depth, DISPLAY_WINDOW);
1950 +        
1951 +        // Update display (VOSF variant)
1952 +        static int tick_counter = 0;
1953 +        if (++tick_counter >= frame_skip) {
1954 +                tick_counter = 0;
1955 + #ifdef HAVE_PTHREADS
1956 +                pthread_mutex_lock(&Screen_draw_lock);
1957 + #endif
1958 +                update_display_window_vosf();
1959 + #ifdef HAVE_PTHREADS
1960 +                pthread_mutex_unlock(&Screen_draw_lock);
1961 + #endif
1962 +        }
1963 + }
1964 + #endif
1965 +
1966 + static void video_refresh_window_static(void)
1967 + {
1968 +        // Handle X events
1969 +        handle_events();
1970 +        
1971 +        // Handle_palette changes
1972 +        handle_palette_changes(depth, DISPLAY_WINDOW);
1973 +        
1974 +        // Update display (static variant)
1975 +        static int tick_counter = 0;
1976 +        if (++tick_counter >= frame_skip) {
1977 +                tick_counter = 0;
1978 +                update_display_static();
1979 +        }
1980 + }
1981 +
1982 + static void video_refresh_window_dynamic(void)
1983 + {
1984 +        // Handle X events
1985 +        handle_events();
1986 +        
1987 +        // Handle_palette changes
1988 +        handle_palette_changes(depth, DISPLAY_WINDOW);
1989 +        
1990 +        // Update display (dynamic variant)
1991 +        static int tick_counter = 0;
1992 +        tick_counter++;
1993 +        update_display_dynamic(tick_counter);
1994 + }
1995 +
1996 +
1997 + /*
1998   *  Thread for screen refresh, input handling etc.
1999   */
2000  
2001 + void VideoRefreshInit(void)
2002 + {
2003 +        // TODO: set up specialised 8bpp VideoRefresh handlers ?
2004 +        if (display_type == DISPLAY_DGA) {
2005 + #if REAL_ADDRESSING || DIRECT_ADDRESSING
2006 +                if (use_vosf)
2007 +                        video_refresh = video_refresh_dga_vosf;
2008 +                else
2009 + #endif
2010 +                        video_refresh = video_refresh_dga;
2011 +        }
2012 +        else {
2013 + #ifdef ENABLE_VOSF
2014 +                if (use_vosf)
2015 +                        video_refresh = video_refresh_window_vosf;
2016 +                else
2017 + #endif
2018 +                if (frame_skip == 0)
2019 +                        video_refresh = video_refresh_window_dynamic;
2020 +                else
2021 +                        video_refresh = video_refresh_window_static;
2022 +        }
2023 + }
2024 +
2025 + void VideoRefresh(void)
2026 + {
2027 +        // TODO: make main_unix/VideoRefresh call directly video_refresh() ?
2028 +        video_refresh();
2029 + }
2030 +
2031 + #if 0
2032   void VideoRefresh(void)
2033   {
2034   #if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA)
# Line 1594 | Line 2084 | void VideoRefresh(void)
2084                  }
2085          }
2086   }
2087 + #endif
2088  
2089   #ifdef HAVE_PTHREADS
2090   static void *redraw_func(void *arg)
2091   {
2092 < uint64 start = GetTicks_usec();
2093 < int64 ticks = 0;
2092 >        uint64 start = GetTicks_usec();
2093 >        int64 ticks = 0;
2094          uint64 next = GetTicks_usec();
2095          while (!redraw_thread_cancel) {
2096 <                VideoRefresh();
2096 > //              VideoRefresh();
2097 >                video_refresh();
2098                  next += 16667;
2099                  int64 delay = next - GetTicks_usec();
2100                  if (delay > 0)
2101                          Delay_usec(delay);
2102                  else if (delay < -16667)
2103                          next = GetTicks_usec();
2104 < ticks++;
2104 >                ticks++;
2105          }
2106 < uint64 end = GetTicks_usec();
2107 < printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, (end - start) / ticks);
2106 >        uint64 end = GetTicks_usec();
2107 >        printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, (end - start) / ticks);
2108          return NULL;
2109   }
2110   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines