1 |
|
/* |
2 |
|
* video_x.cpp - Video/graphics emulation, X11 specific stuff |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2000 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2001 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 |
53 |
|
#endif |
54 |
|
|
55 |
|
#ifdef ENABLE_VOSF |
56 |
– |
# include <unistd.h> |
57 |
– |
# include <signal.h> |
56 |
|
# include <fcntl.h> |
57 |
|
# include <sys/mman.h> |
58 |
+ |
# include "sigsegv.h" |
59 |
|
#endif |
60 |
|
|
61 |
|
#include "cpu_emulation.h" |
196 |
|
int pageBits; // Shift count to get the page number |
197 |
|
uint32 pageCount; // Number of pages allocated to the screen |
198 |
|
|
199 |
+ |
bool dirty; // Flag: set if the frame buffer was touched |
200 |
|
char * dirtyPages; // Table of flags set if page was altered |
201 |
|
ScreenPageInfo * pageInfo; // Table of mappings page -> Mac scanlines |
202 |
|
}; |
234 |
|
memset(mainBuffer.dirtyPages + (first_page), PFLAG_CLEAR_VALUE, \ |
235 |
|
(last_page) - (first_page)) |
236 |
|
|
237 |
< |
#define PFLAG_SET_ALL \ |
238 |
< |
PFLAG_SET_RANGE(0, mainBuffer.pageCount) |
239 |
< |
|
240 |
< |
#define PFLAG_CLEAR_ALL \ |
241 |
< |
PFLAG_CLEAR_RANGE(0, mainBuffer.pageCount) |
237 |
> |
#define PFLAG_SET_ALL do { \ |
238 |
> |
PFLAG_SET_RANGE(0, mainBuffer.pageCount); \ |
239 |
> |
mainBuffer.dirty = true; \ |
240 |
> |
} while (0) |
241 |
> |
|
242 |
> |
#define PFLAG_CLEAR_ALL do { \ |
243 |
> |
PFLAG_CLEAR_RANGE(0, mainBuffer.pageCount); \ |
244 |
> |
mainBuffer.dirty = false; \ |
245 |
> |
} while (0) |
246 |
|
|
247 |
|
// Set the following macro definition to 1 if your system |
248 |
|
// provides a really fast strchr() implementation |
277 |
|
} |
278 |
|
|
279 |
|
static int zero_fd = -1; |
276 |
– |
static bool Screen_fault_handler_init(); |
277 |
– |
static struct sigaction vosf_sa; |
280 |
|
|
281 |
|
#ifdef HAVE_PTHREADS |
282 |
|
static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) |
577 |
|
native_byte_order = (XImageByteOrder(x_display) == LSBFirst); |
578 |
|
#endif |
579 |
|
#ifdef ENABLE_VOSF |
580 |
< |
do_update_framebuffer = GET_FBCOPY_FUNC(depth, native_byte_order, DISPLAY_WINDOW); |
580 |
> |
Screen_blitter_init(&visualInfo, native_byte_order); |
581 |
|
#endif |
582 |
|
set_video_monitor(width, height, img->bytes_per_line, native_byte_order); |
583 |
|
|
716 |
|
|
717 |
|
#if ENABLE_VOSF |
718 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
719 |
< |
// If the blit function is null, i.e. just a copy of the buffer, |
720 |
< |
// we first try to avoid the allocation of a temporary frame buffer |
721 |
< |
use_vosf = true; |
720 |
< |
do_update_framebuffer = GET_FBCOPY_FUNC(depth, true, DISPLAY_DGA); |
721 |
< |
if (do_update_framebuffer == FBCOPY_FUNC(fbcopy_raw)) |
722 |
< |
use_vosf = false; |
719 |
> |
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
720 |
> |
// i.e. the framebuffer update function is not Blit_Copy_Raw |
721 |
> |
use_vosf = Screen_blitter_init(&visualInfo, true); |
722 |
|
|
723 |
|
if (use_vosf) { |
724 |
|
the_host_buffer = the_buffer; |
823 |
|
} |
824 |
|
|
825 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
826 |
< |
// If the blit function is null, i.e. just a copy of the buffer, |
827 |
< |
// we first try to avoid the allocation of a temporary frame buffer |
828 |
< |
use_vosf = true; |
830 |
< |
do_update_framebuffer = GET_FBCOPY_FUNC(depth, true, DISPLAY_DGA); |
831 |
< |
if (do_update_framebuffer == FBCOPY_FUNC(fbcopy_raw)) |
832 |
< |
use_vosf = false; |
826 |
> |
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
827 |
> |
// i.e. the framebuffer update function is not Blit_Copy_Raw |
828 |
> |
use_vosf = Screen_blitter_init(&visualInfo, true); |
829 |
|
|
830 |
|
if (use_vosf) { |
831 |
|
the_host_buffer = the_buffer; |
948 |
|
|
949 |
|
if ((mainBuffer.dirtyPages == 0) || (mainBuffer.pageInfo == 0)) |
950 |
|
return false; |
951 |
+ |
|
952 |
+ |
mainBuffer.dirty = false; |
953 |
|
|
954 |
|
PFLAG_CLEAR_ALL; |
955 |
|
// Safety net to insure the loops in the update routines will terminate |
1169 |
|
} |
1170 |
|
|
1171 |
|
// Initialize the handler for SIGSEGV |
1172 |
< |
if (!Screen_fault_handler_init()) { |
1172 |
> |
if (!sigsegv_install_handler(screen_fault_handler)) { |
1173 |
|
// TODO: STR_VOSF_INIT_ERR ? |
1174 |
|
ErrorAlert("Could not initialize Video on SEGV signals"); |
1175 |
|
return false; |
2022 |
|
static int tick_counter = 0; |
2023 |
|
if (++tick_counter >= frame_skip) { |
2024 |
|
tick_counter = 0; |
2025 |
< |
LOCK_VOSF; |
2026 |
< |
update_display_dga_vosf(); |
2027 |
< |
UNLOCK_VOSF; |
2025 |
> |
if (mainBuffer.dirty) { |
2026 |
> |
LOCK_VOSF; |
2027 |
> |
update_display_dga_vosf(); |
2028 |
> |
UNLOCK_VOSF; |
2029 |
> |
} |
2030 |
|
} |
2031 |
|
} |
2032 |
|
#endif |
2046 |
|
static int tick_counter = 0; |
2047 |
|
if (++tick_counter >= frame_skip) { |
2048 |
|
tick_counter = 0; |
2049 |
< |
LOCK_VOSF; |
2050 |
< |
update_display_window_vosf(); |
2051 |
< |
UNLOCK_VOSF; |
2049 |
> |
if (mainBuffer.dirty) { |
2050 |
> |
LOCK_VOSF; |
2051 |
> |
update_display_window_vosf(); |
2052 |
> |
UNLOCK_VOSF; |
2053 |
> |
XSync(x_display, false); // Let the server catch up |
2054 |
> |
} |
2055 |
|
} |
2056 |
|
} |
2057 |
|
#endif // def ENABLE_VOSF |
2138 |
|
ticks++; |
2139 |
|
} |
2140 |
|
uint64 end = GetTicks_usec(); |
2141 |
< |
printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, ticks * 1000000 / (end - start)); |
2141 |
> |
// printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, ticks * 1000000 / (end - start)); |
2142 |
|
return NULL; |
2143 |
|
} |
2144 |
|
#endif |