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

Comparing BasiliskII/src/Unix/video_vosf.h (file contents):
Revision 1.15 by cebix, 2001-03-06T18:41:12Z vs.
Revision 1.40 by gbeauche, 2004-06-26T15:22:02Z

# Line 1 | Line 1
1   /*
2   *  video_vosf.h - Video/graphics emulation, video on SEGV signals support
3   *
4 < *  Basilisk II (C) 1997-2001 Christian Bauer
4 > *  Basilisk II (C) 1997-2004 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
# Line 21 | Line 21
21   #ifndef VIDEO_VOSF_H
22   #define VIDEO_VOSF_H
23  
24 < // Note: this file is #include'd in video_x.cpp
24 > // Note: this file must be #include'd only in video_x.cpp
25   #ifdef ENABLE_VOSF
26  
27 < /*
28 < *  Page-aligned memory allocation
29 < */
27 > #include <fcntl.h>
28 > #include <sys/mman.h>
29 > #include "sigsegv.h"
30 > #include "vm_alloc.h"
31 >
32 > // Glue for SDL and X11 support
33 > #ifdef USE_SDL_VIDEO
34 > #define MONITOR_INIT                    SDL_monitor_desc &monitor
35 > #define VIDEO_DRV_INIT                  driver_window *drv
36 > #define VIDEO_DRV_ROW_BYTES             drv->s->pitch
37 > #define VIDEO_DRV_LOCK_PIXELS   if (SDL_MUSTLOCK(drv->s)) SDL_LockSurface(drv->s)
38 > #define VIDEO_DRV_UNLOCK_PIXELS if (SDL_MUSTLOCK(drv->s)) SDL_UnlockSurface(drv->s)
39 > #else
40 > #ifdef SHEEPSHAVER
41 > #define MONITOR_INIT                    /* nothing */
42 > #define VIDEO_DRV_INIT                  /* nothing */
43 > #define VIDEO_DRV_WINDOW                the_win
44 > #define VIDEO_DRV_GC                    the_gc
45 > #define VIDEO_DRV_IMAGE                 img
46 > #define VIDEO_DRV_HAVE_SHM              have_shm
47 > #else
48 > #define MONITOR_INIT                    X11_monitor_desc &monitor
49 > #define VIDEO_DRV_INIT                  driver_window *drv
50 > #define VIDEO_DRV_WINDOW                drv->w
51 > #define VIDEO_DRV_GC                    drv->gc
52 > #define VIDEO_DRV_IMAGE                 drv->img
53 > #define VIDEO_DRV_HAVE_SHM              drv->have_shm
54 > #endif
55 > #define VIDEO_DRV_LOCK_PIXELS   /* nothing */
56 > #define VIDEO_DRV_UNLOCK_PIXELS /* nothing */
57 > #define VIDEO_DRV_ROW_BYTES             VIDEO_DRV_IMAGE->bytes_per_line
58 > #endif
59  
60 < // Align on page boundaries
61 < static uintptr align_on_page_boundary(uintptr size)
62 < {
63 <        const uint32 page_size = getpagesize();
64 <        const uint32 page_mask = page_size - 1;
65 <        return (size + page_mask) & ~page_mask;
60 > // Variables for Video on SEGV support
61 > static uint8 *the_host_buffer;  // Host frame buffer in VOSF mode
62 >
63 > struct ScreenPageInfo {
64 >    int top, bottom;                    // Mapping between this virtual page and Mac scanlines
65 > };
66 >
67 > struct ScreenInfo {
68 >    uintptr memStart;                   // Start address aligned to page boundary
69 >    uint32 memLength;                   // Length of the memory addressed by the screen pages
70 >    
71 >    uintptr pageSize;                   // Size of a page
72 >    int pageBits;                               // Shift count to get the page number
73 >    uint32 pageCount;                   // Number of pages allocated to the screen
74 >    
75 >        bool dirty;                                     // Flag: set if the frame buffer was touched
76 >    char * dirtyPages;                  // Table of flags set if page was altered
77 >    ScreenPageInfo * pageInfo;  // Table of mappings page -> Mac scanlines
78 > };
79 >
80 > static ScreenInfo mainBuffer;
81 >
82 > #define PFLAG_SET_VALUE                 0x00
83 > #define PFLAG_CLEAR_VALUE               0x01
84 > #define PFLAG_SET_VALUE_4               0x00000000
85 > #define PFLAG_CLEAR_VALUE_4             0x01010101
86 > #define PFLAG_SET(page)                 mainBuffer.dirtyPages[page] = PFLAG_SET_VALUE
87 > #define PFLAG_CLEAR(page)               mainBuffer.dirtyPages[page] = PFLAG_CLEAR_VALUE
88 > #define PFLAG_ISSET(page)               (mainBuffer.dirtyPages[page] == PFLAG_SET_VALUE)
89 > #define PFLAG_ISCLEAR(page)             (mainBuffer.dirtyPages[page] != PFLAG_SET_VALUE)
90 >
91 > #ifdef UNALIGNED_PROFITABLE
92 > # define PFLAG_ISSET_4(page)    (*((uint32 *)(mainBuffer.dirtyPages + (page))) == PFLAG_SET_VALUE_4)
93 > # define PFLAG_ISCLEAR_4(page)  (*((uint32 *)(mainBuffer.dirtyPages + (page))) == PFLAG_CLEAR_VALUE_4)
94 > #else
95 > # define PFLAG_ISSET_4(page) \
96 >                PFLAG_ISSET(page  ) && PFLAG_ISSET(page+1) \
97 >        &&      PFLAG_ISSET(page+2) && PFLAG_ISSET(page+3)
98 > # define PFLAG_ISCLEAR_4(page) \
99 >                PFLAG_ISCLEAR(page  ) && PFLAG_ISCLEAR(page+1) \
100 >        &&      PFLAG_ISCLEAR(page+2) && PFLAG_ISCLEAR(page+3)
101 > #endif
102 >
103 > // Set the selected page range [ first_page, last_page [ into the SET state
104 > #define PFLAG_SET_RANGE(first_page, last_page) \
105 >        memset(mainBuffer.dirtyPages + (first_page), PFLAG_SET_VALUE, \
106 >                (last_page) - (first_page))
107 >
108 > // Set the selected page range [ first_page, last_page [ into the CLEAR state
109 > #define PFLAG_CLEAR_RANGE(first_page, last_page) \
110 >        memset(mainBuffer.dirtyPages + (first_page), PFLAG_CLEAR_VALUE, \
111 >                (last_page) - (first_page))
112 >
113 > #define PFLAG_SET_ALL do { \
114 >        PFLAG_SET_RANGE(0, mainBuffer.pageCount); \
115 >        mainBuffer.dirty = true; \
116 > } while (0)
117 >
118 > #define PFLAG_CLEAR_ALL do { \
119 >        PFLAG_CLEAR_RANGE(0, mainBuffer.pageCount); \
120 >        mainBuffer.dirty = false; \
121 > } while (0)
122 >
123 > // Set the following macro definition to 1 if your system
124 > // provides a really fast strchr() implementation
125 > //#define HAVE_FAST_STRCHR 0
126 >
127 > static inline int find_next_page_set(int page)
128 > {
129 > #if HAVE_FAST_STRCHR
130 >        char *match = strchr(mainBuffer.dirtyPages + page, PFLAG_SET_VALUE);
131 >        return match ? match - mainBuffer.dirtyPages : mainBuffer.pageCount;
132 > #else
133 >        while (PFLAG_ISCLEAR_4(page))
134 >                page += 4;
135 >        while (PFLAG_ISCLEAR(page))
136 >                page++;
137 >        return page;
138 > #endif
139   }
140  
141 < // Allocate memory on page boundary
40 < static void * allocate_framebuffer(uint32 size, uint8 * hint = 0)
141 > static inline int find_next_page_clear(int page)
142   {
143 <        // Remind that the system can allocate at 0x00000000...
144 <        return mmap((caddr_t)hint, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, zero_fd, 0);
143 > #if HAVE_FAST_STRCHR
144 >        char *match = strchr(mainBuffer.dirtyPages + page, PFLAG_CLEAR_VALUE);
145 >        return match ? match - mainBuffer.dirtyPages : mainBuffer.pageCount;
146 > #else
147 >        while (PFLAG_ISSET_4(page))
148 >                page += 4;
149 >        while (PFLAG_ISSET(page))
150 >                page++;
151 >        return page;
152 > #endif
153   }
154  
155 + #ifdef HAVE_SPINLOCKS
156 + static spinlock_t vosf_lock = SPIN_LOCK_UNLOCKED;                               // Mutex to protect frame buffer (dirtyPages in fact)
157 + #define LOCK_VOSF spin_lock(&vosf_lock)
158 + #define UNLOCK_VOSF spin_unlock(&vosf_lock)
159 + #elif defined(HAVE_PTHREADS)
160 + static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER;   // Mutex to protect frame buffer (dirtyPages in fact)
161 + #define LOCK_VOSF pthread_mutex_lock(&vosf_lock);
162 + #define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock);
163 + #else
164 + #define LOCK_VOSF
165 + #define UNLOCK_VOSF
166 + #endif
167  
168 < /*
48 < *      Screen fault handler
49 < */
50 <
51 < const uintptr INVALID_PC = (uintptr)-1;
52 <
53 < static inline void do_handle_screen_fault(uintptr addr, uintptr pc = INVALID_PC)
168 > static int log_base_2(uint32 x)
169   {
170 <        /* Someone attempted to write to the frame buffer. Make it writeable
171 <         * now so that the data could actually be written. It will be made
172 <         * read-only back in one of the screen update_*() functions.
173 <         */
174 <        if ((addr >= mainBuffer.memStart) && (addr < mainBuffer.memEnd)) {
60 <                const int page  = (addr - mainBuffer.memStart) >> mainBuffer.pageBits;
61 <                caddr_t page_ad = (caddr_t)(addr & ~(mainBuffer.pageSize - 1));
62 <                LOCK_VOSF;
63 <                PFLAG_SET(page);
64 <                mprotect(page_ad, mainBuffer.pageSize, PROT_READ | PROT_WRITE);
65 <                mainBuffer.dirty = true;
66 <                UNLOCK_VOSF;
67 <                return;
170 >        uint32 mask = 0x80000000;
171 >        int l = 31;
172 >        while (l >= 0 && (x & mask) == 0) {
173 >                mask >>= 1;
174 >                l--;
175          }
176 <        
70 <        /* Otherwise, we don't know how to handle the fault, let it crash */
71 <        fprintf(stderr, "do_handle_screen_fault: unhandled address 0x%08X", addr);
72 <        if (pc != INVALID_PC)
73 <                fprintf(stderr, " [IP=0x%08X]", pc);
74 <        fprintf(stderr, "\n");
75 <        
76 <        signal(SIGSEGV, SIG_DFL);
176 >        return l;
177   }
178  
179 < #if defined(HAVE_SIGINFO_T)
180 <
81 < static void Screen_fault_handler(int, siginfo_t * sip, void *)
179 > // Extend size to page boundary
180 > static uint32 page_extend(uint32 size)
181   {
182 <        D(bug("Screen_fault_handler: ADDR=0x%08X\n", sip->si_addr));
183 <        do_handle_screen_fault((uintptr)sip->si_addr);
182 >        const uint32 page_size = getpagesize();
183 >        const uint32 page_mask = page_size - 1;
184 >        return (size + page_mask) & ~page_mask;
185   }
186  
87 #elif defined(HAVE_SIGCONTEXT_SUBTERFUGE)
187  
188 < # if defined(__i386__) && defined(__linux__)
189 < static void Screen_fault_handler(int, struct sigcontext scs)
190 < {
92 <        D(bug("Screen_fault_handler: ADDR=0x%08X from IP=0x%08X\n", scs.cr2, scs.eip));
93 <        do_handle_screen_fault((uintptr)scs.cr2, (uintptr)scs.eip);
94 < }
188 > /*
189 > *  Check if VOSF acceleration is profitable on this platform
190 > */
191  
192 < # elif defined(__m68k__) && defined(__NetBSD__)
192 > const int VOSF_PROFITABLE_THRESHOLD = 8000; // 8 ms, aka (60 Hz / 2) for work processing
193  
194 < # include <m68k/frame.h>
99 < static void Screen_fault_handler(int, int code, struct sigcontext *scp)
194 > static bool video_vosf_profitable(void)
195   {
196 <        D(bug("Screen_fault_handler: ADDR=0x%08X\n", code));
197 <        struct sigstate {
198 <                int ss_flags;
199 <                struct frame ss_frame;
200 <        };
106 <        struct sigstate *state = (struct sigstate *)scp->sc_ap;
107 <        uintptr fault_addr;
108 <        switch (state->ss_frame.f_format) {
109 <                case 7:         // 68040 access error
110 <                        // "code" is sometimes unreliable (i.e. contains NULL or a bogus address), reason unknown
111 <                        fault_addr = state->ss_frame.f_fmt7.f_fa;
112 <                        break;
113 <                default:
114 <                        fault_addr = (uintptr)code;
115 <                        break;
196 >        uint64 start = GetTicks_usec();
197 >
198 >        for (int i = 0; i < mainBuffer.pageCount; i++) {
199 >                uint8 *addr = (uint8 *)(mainBuffer.memStart + (i * mainBuffer.pageSize));
200 >                memset(addr, 0, mainBuffer.pageSize); // Trigger Screen_fault_handler()
201          }
202 <        do_handle_screen_fault(fault_addr);
202 >
203 >        uint64 end = GetTicks_usec();
204 >        const int diff = end - start;
205 >        D(bug("Triggered %d screen faults in %ld usec\n", mainBuffer.pageCount, diff));
206 >
207 >        if (diff > (VOSF_PROFITABLE_THRESHOLD * (frame_skip + 1)))
208 >                return false;
209 >
210 >        // Reset VOSF variables to initial state
211 >        PFLAG_CLEAR_ALL;
212 >        if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0)
213 >                return false;
214 >        mainBuffer.dirty = false;
215 >        return true;
216   }
217  
120 # elif defined(__powerpc__) && defined(__linux__)
218  
219 < static void Screen_fault_handler(int, struct sigcontext_struct *scs)
219 > /*
220 > *  Initialize the VOSF system (mainBuffer structure, SIGSEGV handler)
221 > */
222 >
223 > static bool video_vosf_init(MONITOR_INIT)
224   {
225 <        D(bug("Screen_fault_handler: ADDR=0x%08X from IP=0x%08X\n", scs->regs->dar, scs->regs->nip));
125 <        do_handle_screen_fault((uintptr)scs->regs->dar, (uintptr)scs->regs->nip);
126 < }
225 >        VIDEO_MODE_INIT;
226  
227 < # else
228 < #  error "No suitable subterfuge for Video on SEGV signals"
229 < # endif
230 < #else
231 < # error "Can't do Video on SEGV signals"
232 < #endif
227 >        const uintptr page_size = getpagesize();
228 >        const uintptr page_mask = page_size - 1;
229 >        
230 >        // Round up frame buffer base to page boundary
231 >        mainBuffer.memStart = (((uintptr) the_buffer) + page_mask) & ~page_mask;
232 >        
233 >        // The frame buffer size shall already be aligned to page boundary (use page_extend)
234 >        mainBuffer.memLength = the_buffer_size;
235 >        
236 >        mainBuffer.pageSize = page_size;
237 >        mainBuffer.pageBits = log_base_2(mainBuffer.pageSize);
238 >        mainBuffer.pageCount =  (mainBuffer.memLength + page_mask)/mainBuffer.pageSize;
239 >        
240 >        // The "2" more bytes requested are a safety net to insure the
241 >        // loops in the update routines will terminate.
242 >        // See "How can we deal with array overrun conditions ?" hereunder for further details.
243 >        mainBuffer.dirtyPages = (char *) malloc(mainBuffer.pageCount + 2);
244 >        if (mainBuffer.dirtyPages == NULL)
245 >                return false;
246 >                
247 >        PFLAG_CLEAR_ALL;
248 >        PFLAG_CLEAR(mainBuffer.pageCount);
249 >        PFLAG_SET(mainBuffer.pageCount+1);
250 >        
251 >        // Allocate and fill in pageInfo with start and end (inclusive) row in number of bytes
252 >        mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo));
253 >        if (mainBuffer.pageInfo == NULL)
254 >                return false;
255 >        
256 >        uint32 a = 0;
257 >        for (unsigned i = 0; i < mainBuffer.pageCount; i++) {
258 >                unsigned y1 = a / VIDEO_MODE_ROW_BYTES;
259 >                if (y1 >= VIDEO_MODE_Y)
260 >                        y1 = VIDEO_MODE_Y - 1;
261 >
262 >                unsigned y2 = (a + mainBuffer.pageSize) / VIDEO_MODE_ROW_BYTES;
263 >                if (y2 >= VIDEO_MODE_Y)
264 >                        y2 = VIDEO_MODE_Y - 1;
265 >
266 >                mainBuffer.pageInfo[i].top = y1;
267 >                mainBuffer.pageInfo[i].bottom = y2;
268 >
269 >                a += mainBuffer.pageSize;
270 >                if (a > mainBuffer.memLength)
271 >                        a = mainBuffer.memLength;
272 >        }
273 >        
274 >        // We can now write-protect the frame buffer
275 >        if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0)
276 >                return false;
277 >        
278 >        // The frame buffer is sane, i.e. there is no write to it yet
279 >        mainBuffer.dirty = false;
280 >        return true;
281 > }
282  
283  
284   /*
285 < *      Screen fault handler initialization
285 > * Deinitialize VOSF system
286   */
287  
288 < #if defined(HAVE_SIGINFO_T)
141 < static bool Screen_fault_handler_init()
288 > static void video_vosf_exit(void)
289   {
290 <        // Setup SIGSEGV handler to process writes to frame buffer
291 <        sigemptyset(&vosf_sa.sa_mask);
292 <        vosf_sa.sa_sigaction = Screen_fault_handler;
293 <        vosf_sa.sa_flags = SA_SIGINFO;
294 <        return (sigaction(SIGSEGV, &vosf_sa, NULL) == 0);
290 >        if (mainBuffer.pageInfo) {
291 >                free(mainBuffer.pageInfo);
292 >                mainBuffer.pageInfo = NULL;
293 >        }
294 >        if (mainBuffer.dirtyPages) {
295 >                free(mainBuffer.dirtyPages);
296 >                mainBuffer.dirtyPages = NULL;
297 >        }
298   }
299 < #elif defined(HAVE_SIGCONTEXT_SUBTERFUGE)
300 < static bool Screen_fault_handler_init()
299 >
300 >
301 > /*
302 > * Screen fault handler
303 > */
304 >
305 > bool Screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction)
306   {
307 <        // Setup SIGSEGV handler to process writes to frame buffer
308 <        sigemptyset(&vosf_sa.sa_mask);
309 <        vosf_sa.sa_handler = (void (*)(int)) Screen_fault_handler;
310 < #if !EMULATED_68K && defined(__NetBSD__)
311 <        sigaddset(&vosf_sa.sa_mask, SIGALRM);
312 <        vosf_sa.sa_flags = SA_ONSTACK;
313 < #else
314 <        vosf_sa.sa_flags = 0;
315 < #endif
316 <        return (sigaction(SIGSEGV, &vosf_sa, NULL) == 0);
307 >        const uintptr addr = (uintptr)fault_address;
308 >        
309 >        /* Someone attempted to write to the frame buffer. Make it writeable
310 >         * now so that the data could actually be written to. It will be made
311 >         * read-only back in one of the screen update_*() functions.
312 >         */
313 >        if (((uintptr)addr - mainBuffer.memStart) < mainBuffer.memLength) {
314 >                const int page  = ((uintptr)addr - mainBuffer.memStart) >> mainBuffer.pageBits;
315 >                LOCK_VOSF;
316 >                PFLAG_SET(page);
317 >                vm_protect((char *)(addr & -mainBuffer.pageSize), mainBuffer.pageSize, VM_PAGE_READ | VM_PAGE_WRITE);
318 >                mainBuffer.dirty = true;
319 >                UNLOCK_VOSF;
320 >                return true;
321 >        }
322 >        
323 >        /* Otherwise, we don't know how to handle the fault, let it crash */
324 >        return false;
325   }
163 #endif
326  
327  
328   /*
329   *      Update display for Windowed mode and VOSF
330   */
331  
170 // From video_blit.cpp
171 extern void (*Screen_blit)(uint8 * dest, const uint8 * source, uint32 length);
172 extern bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order);
173
332   /*      How can we deal with array overrun conditions ?
333          
334          The state of the framebuffer pages that have been touched are maintained
# Line 204 | Line 362 | There are two cases to check:
362          than pageCount.
363   */
364  
365 < static inline void update_display_window_vosf(void)
365 > static inline void update_display_window_vosf(VIDEO_DRV_INIT)
366   {
367 +        VIDEO_MODE_INIT;
368 +
369          int page = 0;
370          for (;;) {
371 <                const int first_page = find_next_page_set(page);
371 >                const unsigned first_page = find_next_page_set(page);
372                  if (first_page >= mainBuffer.pageCount)
373                          break;
374  
# Line 218 | Line 378 | static inline void update_display_window
378                  // Make the dirty pages read-only again
379                  const int32 offset  = first_page << mainBuffer.pageBits;
380                  const uint32 length = (page - first_page) << mainBuffer.pageBits;
381 <                mprotect((caddr_t)(mainBuffer.memStart + offset), length, PROT_READ);
381 >                vm_protect((char *)mainBuffer.memStart + offset, length, VM_PAGE_READ);
382                  
383                  // There is at least one line to update
384                  const int y1 = mainBuffer.pageInfo[first_page].top;
385                  const int y2 = mainBuffer.pageInfo[page - 1].bottom;
386                  const int height = y2 - y1 + 1;
387 <                
388 <                const int bytes_per_row = VideoMonitor.bytes_per_row;
389 <                const int bytes_per_pixel = VideoMonitor.bytes_per_row / VideoMonitor.x;
390 <                int i = y1 * bytes_per_row, j;
231 <                
232 <                if (depth == 1) {
387 >
388 >                VIDEO_DRV_LOCK_PIXELS;
389 >
390 >                if (VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) {
391  
392                          // Update the_host_buffer and copy of the_buffer
393 +                        const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES;
394 +                        const int dst_bytes_per_row = VIDEO_DRV_ROW_BYTES;
395 +                        const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row;
396 +                        int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j;
397                          for (j = y1; j <= y2; j++) {
398 <                                Screen_blit(the_host_buffer + i, the_buffer + i, VideoMonitor.x >> 3);
399 <                                i += bytes_per_row;
398 >                                Screen_blit(the_host_buffer + i2, the_buffer + i1, VIDEO_MODE_X / pixels_per_byte);
399 >                                i1 += src_bytes_per_row;
400 >                                i2 += dst_bytes_per_row;
401                          }
402  
403                  } else {
404  
405                          // Update the_host_buffer and copy of the_buffer
406 +                        const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES;
407 +                        const int dst_bytes_per_row = VIDEO_DRV_ROW_BYTES;
408 +                        const int bytes_per_pixel = src_bytes_per_row / VIDEO_MODE_X;
409 +                        int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j;
410                          for (j = y1; j <= y2; j++) {
411 <                                Screen_blit(the_host_buffer + i, the_buffer + i, bytes_per_pixel * VideoMonitor.x);
412 <                                i += bytes_per_row;
411 >                                Screen_blit(the_host_buffer + i2, the_buffer + i1, bytes_per_pixel * VIDEO_MODE_X);
412 >                                i1 += src_bytes_per_row;
413 >                                i2 += dst_bytes_per_row;
414                          }
415                  }
416  
417 <                if (have_shm)
418 <                        XShmPutImage(x_display, the_win, the_gc, img, 0, y1, 0, y1, VideoMonitor.x, height, 0);
417 >                VIDEO_DRV_UNLOCK_PIXELS;
418 >
419 > #ifdef USE_SDL_VIDEO
420 >                SDL_UpdateRect(drv->s, 0, y1, VIDEO_MODE_X, height);
421 > #else
422 >                if (VIDEO_DRV_HAVE_SHM)
423 >                        XShmPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height, 0);
424                  else
425 <                        XPutImage(x_display, the_win, the_gc, img, 0, y1, 0, y1, VideoMonitor.x, height);
425 >                        XPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height);
426 > #endif
427          }
254
428          mainBuffer.dirty = false;
429   }
430  
431  
432   /*
433   *      Update display for DGA mode and VOSF
434 < *      (only in Direct Addressing mode)
434 > *      (only in Real or Direct Addressing mode)
435   */
436  
437   #if REAL_ADDRESSING || DIRECT_ADDRESSING
438   static inline void update_display_dga_vosf(void)
439   {
440 +        VIDEO_MODE_INIT;
441 +
442          int page = 0;
443          for (;;) {
444 <                const int first_page = find_next_page_set(page);
444 >                const unsigned first_page = find_next_page_set(page);
445                  if (first_page >= mainBuffer.pageCount)
446                          break;
447  
# Line 276 | Line 451 | static inline void update_display_dga_vo
451                  // Make the dirty pages read-only again
452                  const int32 offset  = first_page << mainBuffer.pageBits;
453                  const uint32 length = (page - first_page) << mainBuffer.pageBits;
454 <                mprotect((caddr_t)(mainBuffer.memStart + offset), length, PROT_READ);
454 >                vm_protect((char *)mainBuffer.memStart + offset, length, VM_PAGE_READ);
455                  
456                  // I am sure that y2 >= y1 and depth != 1
457                  const int y1 = mainBuffer.pageInfo[first_page].top;
458                  const int y2 = mainBuffer.pageInfo[page - 1].bottom;
459                  
460 <                const int bytes_per_row = VideoMonitor.bytes_per_row;
461 <                const int bytes_per_pixel = VideoMonitor.bytes_per_row / VideoMonitor.x;
460 >                const int bytes_per_row = VIDEO_MODE_ROW_BYTES;
461 >                const int bytes_per_pixel = VIDEO_MODE_ROW_BYTES / VIDEO_MODE_X;
462                  int i, j;
463                  
464                  // Check for first column from left and first column
465                  // from right that have changed
466 <                int x1 = VideoMonitor.x * bytes_per_pixel - 1;
466 >                int x1 = VIDEO_MODE_X * bytes_per_pixel - 1;
467                  for (j = y1; j <= y2; j++) {
468                          uint8 * const p1 = &the_buffer[j * bytes_per_row];
469                          uint8 * const p2 = &the_buffer_copy[j * bytes_per_row];
# Line 305 | Line 480 | static inline void update_display_dga_vo
480                  for (j = y2; j >= y1; j--) {
481                          uint8 * const p1 = &the_buffer[j * bytes_per_row];
482                          uint8 * const p2 = &the_buffer_copy[j * bytes_per_row];
483 <                        for (i = VideoMonitor.x * bytes_per_pixel - 1; i > x2; i--) {
483 >                        for (i = VIDEO_MODE_X * bytes_per_pixel - 1; i > x2; i--) {
484                                  if (p1[i] != p2[i]) {
485                                          x2 = i;
486                                          break;
# Line 316 | Line 491 | static inline void update_display_dga_vo
491                  
492                  // Update the_host_buffer and copy of the_buffer
493                  // There should be at least one pixel to copy
494 +                VIDEO_DRV_LOCK_PIXELS;
495                  const int width = x2 - x1 + 1;
496                  i = y1 * bytes_per_row + x1 * bytes_per_pixel;
497                  for (j = y1; j <= y2; j++) {
# Line 323 | Line 499 | static inline void update_display_dga_vo
499                          memcpy(the_buffer_copy + i, the_buffer + i, bytes_per_pixel * width);
500                          i += bytes_per_row;
501                  }
502 +                VIDEO_DRV_UNLOCK_PIXELS;
503          }
504          mainBuffer.dirty = false;
505   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines