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-2005 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 |
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 |
– |
#include <fcntl.h> |
28 |
– |
#include <sys/mman.h> |
27 |
|
#include "sigsegv.h" |
28 |
|
#include "vm_alloc.h" |
29 |
+ |
#ifdef _WIN32 |
30 |
+ |
#include "util_windows.h" |
31 |
+ |
#endif |
32 |
|
|
33 |
< |
#ifdef ENABLE_MON |
34 |
< |
# include "mon.h" |
33 |
> |
// Glue for SDL and X11 support |
34 |
> |
#ifdef TEST_VOSF_PERFORMANCE |
35 |
> |
#define MONITOR_INIT /* nothing */ |
36 |
> |
#else |
37 |
> |
#ifdef USE_SDL_VIDEO |
38 |
> |
#define MONITOR_INIT SDL_monitor_desc &monitor |
39 |
> |
#define VIDEO_DRV_WIN_INIT driver_window *drv |
40 |
> |
#define VIDEO_DRV_DGA_INIT driver_fullscreen *drv |
41 |
> |
#define VIDEO_DRV_LOCK_PIXELS SDL_VIDEO_LOCK_SURFACE(drv->s) |
42 |
> |
#define VIDEO_DRV_UNLOCK_PIXELS SDL_VIDEO_UNLOCK_SURFACE(drv->s) |
43 |
> |
#define VIDEO_DRV_DEPTH drv->s->format->BitsPerPixel |
44 |
> |
#define VIDEO_DRV_WIDTH drv->s->w |
45 |
> |
#define VIDEO_DRV_HEIGHT drv->s->h |
46 |
> |
#define VIDEO_DRV_ROW_BYTES drv->s->pitch |
47 |
> |
#else |
48 |
> |
#ifdef SHEEPSHAVER |
49 |
> |
#define MONITOR_INIT /* nothing */ |
50 |
> |
#define VIDEO_DRV_WIN_INIT /* nothing */ |
51 |
> |
#define VIDEO_DRV_DGA_INIT /* nothing */ |
52 |
> |
#define VIDEO_DRV_WINDOW the_win |
53 |
> |
#define VIDEO_DRV_GC the_gc |
54 |
> |
#define VIDEO_DRV_IMAGE img |
55 |
> |
#define VIDEO_DRV_HAVE_SHM have_shm |
56 |
> |
#else |
57 |
> |
#define MONITOR_INIT X11_monitor_desc &monitor |
58 |
> |
#define VIDEO_DRV_WIN_INIT driver_window *drv |
59 |
> |
#define VIDEO_DRV_DGA_INIT driver_dga *drv |
60 |
> |
#define VIDEO_DRV_WINDOW drv->w |
61 |
> |
#define VIDEO_DRV_GC drv->gc |
62 |
> |
#define VIDEO_DRV_IMAGE drv->img |
63 |
> |
#define VIDEO_DRV_HAVE_SHM drv->have_shm |
64 |
> |
#endif |
65 |
> |
#define VIDEO_DRV_LOCK_PIXELS /* nothing */ |
66 |
> |
#define VIDEO_DRV_UNLOCK_PIXELS /* nothing */ |
67 |
> |
#define VIDEO_DRV_DEPTH VIDEO_DRV_IMAGE->depth |
68 |
> |
#define VIDEO_DRV_WIDTH VIDEO_DRV_IMAGE->width |
69 |
> |
#define VIDEO_DRV_HEIGHT VIDEO_DRV_IMAGE->height |
70 |
> |
#define VIDEO_DRV_ROW_BYTES VIDEO_DRV_IMAGE->bytes_per_line |
71 |
> |
#endif |
72 |
|
#endif |
73 |
|
|
74 |
+ |
// Prototypes |
75 |
+ |
static void vosf_do_set_dirty_area(uintptr first, uintptr last); |
76 |
+ |
static void vosf_set_dirty_area(int x, int y, int w, int h, int screen_width, int bytes_per_row); |
77 |
+ |
|
78 |
|
// Variables for Video on SEGV support |
79 |
|
static uint8 *the_host_buffer; // Host frame buffer in VOSF mode |
38 |
– |
static uint32 the_buffer_size; // Size of allocated the_buffer |
80 |
|
|
81 |
|
struct ScreenPageInfo { |
82 |
|
int top, bottom; // Mapping between this virtual page and Mac scanlines |
83 |
|
}; |
84 |
|
|
85 |
|
struct ScreenInfo { |
45 |
– |
uintptr memBase; // Real start address |
86 |
|
uintptr memStart; // Start address aligned to page boundary |
47 |
– |
uintptr memEnd; // Address of one-past-the-end of the screen |
87 |
|
uint32 memLength; // Length of the memory addressed by the screen pages |
88 |
|
|
89 |
< |
uint32 pageSize; // Size of a page |
89 |
> |
uintptr pageSize; // Size of a page |
90 |
|
int pageBits; // Shift count to get the page number |
91 |
|
uint32 pageCount; // Number of pages allocated to the screen |
92 |
|
|
93 |
|
bool dirty; // Flag: set if the frame buffer was touched |
94 |
+ |
bool very_dirty; // Flag: set if the frame buffer was completely modified (e.g. colormap changes) |
95 |
|
char * dirtyPages; // Table of flags set if page was altered |
96 |
|
ScreenPageInfo * pageInfo; // Table of mappings page -> Mac scanlines |
97 |
|
}; |
137 |
|
#define PFLAG_CLEAR_ALL do { \ |
138 |
|
PFLAG_CLEAR_RANGE(0, mainBuffer.pageCount); \ |
139 |
|
mainBuffer.dirty = false; \ |
140 |
+ |
mainBuffer.very_dirty = false; \ |
141 |
+ |
} while (0) |
142 |
+ |
|
143 |
+ |
#define PFLAG_SET_VERY_DIRTY do { \ |
144 |
+ |
mainBuffer.very_dirty = true; \ |
145 |
|
} while (0) |
146 |
|
|
147 |
|
// Set the following macro definition to 1 if your system |
176 |
|
#endif |
177 |
|
} |
178 |
|
|
179 |
< |
#ifdef HAVE_PTHREADS |
179 |
> |
#if defined(HAVE_PTHREADS) |
180 |
|
static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) |
181 |
|
#define LOCK_VOSF pthread_mutex_lock(&vosf_lock); |
182 |
|
#define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock); |
183 |
+ |
#elif defined(_WIN32) |
184 |
+ |
static mutex_t vosf_lock; // Mutex to protect frame buffer (dirtyPages in fact) |
185 |
+ |
#define LOCK_VOSF vosf_lock.lock(); |
186 |
+ |
#define UNLOCK_VOSF vosf_lock.unlock(); |
187 |
+ |
#elif defined(HAVE_SPINLOCKS) |
188 |
+ |
static spinlock_t vosf_lock = SPIN_LOCK_UNLOCKED; // Mutex to protect frame buffer (dirtyPages in fact) |
189 |
+ |
#define LOCK_VOSF spin_lock(&vosf_lock) |
190 |
+ |
#define UNLOCK_VOSF spin_unlock(&vosf_lock) |
191 |
|
#else |
192 |
|
#define LOCK_VOSF |
193 |
|
#define UNLOCK_VOSF |
207 |
|
// Extend size to page boundary |
208 |
|
static uint32 page_extend(uint32 size) |
209 |
|
{ |
210 |
< |
const uint32 page_size = getpagesize(); |
210 |
> |
const uint32 page_size = vm_get_page_size(); |
211 |
|
const uint32 page_mask = page_size - 1; |
212 |
|
return (size + page_mask) & ~page_mask; |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
|
/* |
217 |
< |
* Initialize mainBuffer structure |
217 |
> |
* Check if VOSF acceleration is profitable on this platform |
218 |
|
*/ |
219 |
|
|
220 |
< |
static bool video_init_buffer(void) |
220 |
> |
const int VOSF_PROFITABLE_TRIES = 3; // Make 3 attempts for full screen update |
221 |
> |
const int VOSF_PROFITABLE_THRESHOLD = 16667; // 60 Hz |
222 |
> |
|
223 |
> |
static bool video_vosf_profitable(void) |
224 |
|
{ |
225 |
< |
if (use_vosf) { |
226 |
< |
const uint32 page_size = getpagesize(); |
171 |
< |
const uint32 page_mask = page_size - 1; |
172 |
< |
|
173 |
< |
mainBuffer.memBase = (uintptr) the_buffer; |
174 |
< |
// Round up frame buffer base to page boundary |
175 |
< |
mainBuffer.memStart = (uintptr)((((unsigned long) the_buffer) + page_mask) & ~page_mask); |
176 |
< |
mainBuffer.memLength = the_buffer_size; |
177 |
< |
mainBuffer.memEnd = mainBuffer.memStart + mainBuffer.memLength; |
178 |
< |
|
179 |
< |
mainBuffer.pageSize = page_size; |
180 |
< |
mainBuffer.pageCount = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize; |
181 |
< |
mainBuffer.pageBits = log_base_2(mainBuffer.pageSize); |
182 |
< |
|
183 |
< |
if (mainBuffer.dirtyPages) { |
184 |
< |
free(mainBuffer.dirtyPages); |
185 |
< |
mainBuffer.dirtyPages = NULL; |
186 |
< |
} |
225 |
> |
int64 durations[VOSF_PROFITABLE_TRIES]; |
226 |
> |
int mean_duration = 0; |
227 |
|
|
228 |
< |
mainBuffer.dirtyPages = (char *) malloc(mainBuffer.pageCount + 2); |
228 |
> |
#ifdef SHEEPSHAVER |
229 |
> |
const bool accel = PrefsFindBool("gfxaccel"); |
230 |
> |
#else |
231 |
> |
const bool accel = false; |
232 |
> |
#endif |
233 |
|
|
234 |
< |
if (mainBuffer.pageInfo) { |
235 |
< |
free(mainBuffer.pageInfo); |
236 |
< |
mainBuffer.pageInfo = NULL; |
234 |
> |
for (int i = 0; i < VOSF_PROFITABLE_TRIES; i++) { |
235 |
> |
uint64 start = GetTicks_usec(); |
236 |
> |
for (int p = 0; p < mainBuffer.pageCount; p++) { |
237 |
> |
uint8 *addr = (uint8 *)(mainBuffer.memStart + (p * mainBuffer.pageSize)); |
238 |
> |
if (accel) |
239 |
> |
vosf_do_set_dirty_area((uintptr)addr, (uintptr)addr + mainBuffer.pageSize - 1); |
240 |
> |
else |
241 |
> |
addr[0] = 0; // Trigger Screen_fault_handler() |
242 |
|
} |
243 |
< |
|
244 |
< |
mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo)); |
245 |
< |
|
197 |
< |
if ((mainBuffer.dirtyPages == NULL) || (mainBuffer.pageInfo == NULL)) |
198 |
< |
return false; |
199 |
< |
|
200 |
< |
mainBuffer.dirty = false; |
243 |
> |
int64 duration = GetTicks_usec() - start; |
244 |
> |
mean_duration += duration; |
245 |
> |
durations[i] = duration; |
246 |
|
|
247 |
|
PFLAG_CLEAR_ALL; |
248 |
< |
// Safety net to insure the loops in the update routines will terminate |
204 |
< |
// See "How can we deal with array overrun conditions ?" hereunder for further details |
205 |
< |
PFLAG_CLEAR(mainBuffer.pageCount); |
206 |
< |
PFLAG_SET(mainBuffer.pageCount+1); |
207 |
< |
|
208 |
< |
uint32 a = 0; |
209 |
< |
for (int i = 0; i < mainBuffer.pageCount; i++) { |
210 |
< |
int y1 = a / VideoMonitor.mode.bytes_per_row; |
211 |
< |
if (y1 >= VideoMonitor.mode.y) |
212 |
< |
y1 = VideoMonitor.mode.y - 1; |
213 |
< |
|
214 |
< |
int y2 = (a + mainBuffer.pageSize) / VideoMonitor.mode.bytes_per_row; |
215 |
< |
if (y2 >= VideoMonitor.mode.y) |
216 |
< |
y2 = VideoMonitor.mode.y - 1; |
217 |
< |
|
218 |
< |
mainBuffer.pageInfo[i].top = y1; |
219 |
< |
mainBuffer.pageInfo[i].bottom = y2; |
220 |
< |
|
221 |
< |
a += mainBuffer.pageSize; |
222 |
< |
if (a > mainBuffer.memLength) |
223 |
< |
a = mainBuffer.memLength; |
224 |
< |
} |
225 |
< |
|
226 |
< |
// We can now write-protect the frame buffer |
248 |
> |
mainBuffer.dirty = false; |
249 |
|
if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0) |
250 |
|
return false; |
251 |
|
} |
252 |
+ |
|
253 |
+ |
mean_duration /= VOSF_PROFITABLE_TRIES; |
254 |
+ |
D(bug("Triggered %d screen faults in %ld usec on average\n", mainBuffer.pageCount, mean_duration)); |
255 |
+ |
return (mean_duration < (VOSF_PROFITABLE_THRESHOLD * (frame_skip ? frame_skip : 1))); |
256 |
+ |
} |
257 |
+ |
|
258 |
+ |
|
259 |
+ |
/* |
260 |
+ |
* Initialize the VOSF system (mainBuffer structure, SIGSEGV handler) |
261 |
+ |
*/ |
262 |
+ |
|
263 |
+ |
static bool video_vosf_init(MONITOR_INIT) |
264 |
+ |
{ |
265 |
+ |
VIDEO_MODE_INIT_MONITOR; |
266 |
+ |
|
267 |
+ |
const uintptr page_size = vm_get_page_size(); |
268 |
+ |
const uintptr page_mask = page_size - 1; |
269 |
+ |
|
270 |
+ |
// Round up frame buffer base to page boundary |
271 |
+ |
mainBuffer.memStart = (((uintptr) the_buffer) + page_mask) & ~page_mask; |
272 |
+ |
|
273 |
+ |
// The frame buffer size shall already be aligned to page boundary (use page_extend) |
274 |
+ |
mainBuffer.memLength = the_buffer_size; |
275 |
+ |
|
276 |
+ |
mainBuffer.pageSize = page_size; |
277 |
+ |
mainBuffer.pageBits = log_base_2(mainBuffer.pageSize); |
278 |
+ |
mainBuffer.pageCount = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize; |
279 |
+ |
|
280 |
+ |
// The "2" more bytes requested are a safety net to insure the |
281 |
+ |
// loops in the update routines will terminate. |
282 |
+ |
// See "How can we deal with array overrun conditions ?" hereunder for further details. |
283 |
+ |
mainBuffer.dirtyPages = (char *) malloc(mainBuffer.pageCount + 2); |
284 |
+ |
if (mainBuffer.dirtyPages == NULL) |
285 |
+ |
return false; |
286 |
+ |
|
287 |
+ |
PFLAG_CLEAR_ALL; |
288 |
+ |
PFLAG_CLEAR(mainBuffer.pageCount); |
289 |
+ |
PFLAG_SET(mainBuffer.pageCount+1); |
290 |
+ |
|
291 |
+ |
// Allocate and fill in pageInfo with start and end (inclusive) row in number of bytes |
292 |
+ |
mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo)); |
293 |
+ |
if (mainBuffer.pageInfo == NULL) |
294 |
+ |
return false; |
295 |
+ |
|
296 |
+ |
uint32 a = 0; |
297 |
+ |
for (unsigned i = 0; i < mainBuffer.pageCount; i++) { |
298 |
+ |
unsigned y1 = a / VIDEO_MODE_ROW_BYTES; |
299 |
+ |
if (y1 >= VIDEO_MODE_Y) |
300 |
+ |
y1 = VIDEO_MODE_Y - 1; |
301 |
+ |
|
302 |
+ |
unsigned y2 = (a + mainBuffer.pageSize) / VIDEO_MODE_ROW_BYTES; |
303 |
+ |
if (y2 >= VIDEO_MODE_Y) |
304 |
+ |
y2 = VIDEO_MODE_Y - 1; |
305 |
+ |
|
306 |
+ |
mainBuffer.pageInfo[i].top = y1; |
307 |
+ |
mainBuffer.pageInfo[i].bottom = y2; |
308 |
+ |
|
309 |
+ |
a += mainBuffer.pageSize; |
310 |
+ |
if (a > mainBuffer.memLength) |
311 |
+ |
a = mainBuffer.memLength; |
312 |
+ |
} |
313 |
+ |
|
314 |
+ |
// We can now write-protect the frame buffer |
315 |
+ |
if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0) |
316 |
+ |
return false; |
317 |
+ |
|
318 |
+ |
// The frame buffer is sane, i.e. there is no write to it yet |
319 |
+ |
mainBuffer.dirty = false; |
320 |
|
return true; |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
|
/* |
325 |
+ |
* Deinitialize VOSF system |
326 |
+ |
*/ |
327 |
+ |
|
328 |
+ |
static void video_vosf_exit(void) |
329 |
+ |
{ |
330 |
+ |
if (mainBuffer.pageInfo) { |
331 |
+ |
free(mainBuffer.pageInfo); |
332 |
+ |
mainBuffer.pageInfo = NULL; |
333 |
+ |
} |
334 |
+ |
if (mainBuffer.dirtyPages) { |
335 |
+ |
free(mainBuffer.dirtyPages); |
336 |
+ |
mainBuffer.dirtyPages = NULL; |
337 |
+ |
} |
338 |
+ |
} |
339 |
+ |
|
340 |
+ |
|
341 |
+ |
/* |
342 |
+ |
* Update VOSF state with specified dirty area |
343 |
+ |
*/ |
344 |
+ |
|
345 |
+ |
static void vosf_do_set_dirty_area(uintptr first, uintptr last) |
346 |
+ |
{ |
347 |
+ |
const int first_page = (first - mainBuffer.memStart) >> mainBuffer.pageBits; |
348 |
+ |
const int last_page = (last - mainBuffer.memStart) >> mainBuffer.pageBits; |
349 |
+ |
uint8 *addr = (uint8 *)first; |
350 |
+ |
for (int i = first_page; i <= last_page; i++) { |
351 |
+ |
if (PFLAG_ISCLEAR(i)) { |
352 |
+ |
PFLAG_SET(i); |
353 |
+ |
vm_protect(addr, mainBuffer.pageSize, VM_PAGE_READ | VM_PAGE_WRITE); |
354 |
+ |
} |
355 |
+ |
addr += mainBuffer.pageSize; |
356 |
+ |
} |
357 |
+ |
} |
358 |
+ |
|
359 |
+ |
static void vosf_set_dirty_area(int x, int y, int w, int h, int screen_width, int bytes_per_row) |
360 |
+ |
{ |
361 |
+ |
if (x < 0) { |
362 |
+ |
w -= -x; |
363 |
+ |
x = 0; |
364 |
+ |
} |
365 |
+ |
if (y < 0) { |
366 |
+ |
h -= -y; |
367 |
+ |
y = 0; |
368 |
+ |
} |
369 |
+ |
if (w <= 0 || h <= 0) |
370 |
+ |
return; |
371 |
+ |
LOCK_VOSF; |
372 |
+ |
if (bytes_per_row >= screen_width) { |
373 |
+ |
const int bytes_per_pixel = bytes_per_row / screen_width; |
374 |
+ |
if (bytes_per_row <= mainBuffer.pageSize) { |
375 |
+ |
const uintptr a0 = mainBuffer.memStart + y * bytes_per_row + x * bytes_per_pixel; |
376 |
+ |
const uintptr a1 = mainBuffer.memStart + (y + h - 1) * bytes_per_row + (x + w - 1) * bytes_per_pixel; |
377 |
+ |
vosf_do_set_dirty_area(a0, a1); |
378 |
+ |
} else { |
379 |
+ |
for (int j = y; j < y + h; j++) { |
380 |
+ |
const uintptr a0 = mainBuffer.memStart + j * bytes_per_row + x * bytes_per_pixel; |
381 |
+ |
const uintptr a1 = a0 + (w - 1) * bytes_per_pixel; |
382 |
+ |
vosf_do_set_dirty_area(a0, a1); |
383 |
+ |
} |
384 |
+ |
} |
385 |
+ |
} else { |
386 |
+ |
const int pixels_per_byte = screen_width / bytes_per_row; |
387 |
+ |
if (bytes_per_row <= mainBuffer.pageSize) { |
388 |
+ |
const uintptr a0 = mainBuffer.memStart + y * bytes_per_row + x / pixels_per_byte; |
389 |
+ |
const uintptr a1 = mainBuffer.memStart + (y + h - 1) * bytes_per_row + (x + w - 1) / pixels_per_byte; |
390 |
+ |
vosf_do_set_dirty_area(a0, a1); |
391 |
+ |
} else { |
392 |
+ |
for (int j = y; j < y + h; j++) { |
393 |
+ |
const uintptr a0 = mainBuffer.memStart + j * bytes_per_row + x / pixels_per_byte; |
394 |
+ |
const uintptr a1 = mainBuffer.memStart + j * bytes_per_row + (x + w - 1) / pixels_per_byte; |
395 |
+ |
vosf_do_set_dirty_area(a0, a1); |
396 |
+ |
} |
397 |
+ |
} |
398 |
+ |
} |
399 |
+ |
mainBuffer.dirty = true; |
400 |
+ |
UNLOCK_VOSF; |
401 |
+ |
} |
402 |
+ |
|
403 |
+ |
|
404 |
+ |
/* |
405 |
|
* Screen fault handler |
406 |
|
*/ |
407 |
|
|
408 |
< |
static bool screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
408 |
> |
bool Screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
409 |
|
{ |
240 |
– |
// D(bug("screen_fault_handler: ADDR=0x%08X from IP=0x%08X\n", fault_address, fault_instruction)); |
410 |
|
const uintptr addr = (uintptr)fault_address; |
411 |
|
|
412 |
|
/* Someone attempted to write to the frame buffer. Make it writeable |
413 |
|
* now so that the data could actually be written to. It will be made |
414 |
|
* read-only back in one of the screen update_*() functions. |
415 |
|
*/ |
416 |
< |
if ((addr >= mainBuffer.memStart) && (addr < mainBuffer.memEnd)) { |
417 |
< |
const int page = (addr - mainBuffer.memStart) >> mainBuffer.pageBits; |
249 |
< |
caddr_t page_ad = (caddr_t)(addr & -mainBuffer.pageSize); |
416 |
> |
if (((uintptr)addr - mainBuffer.memStart) < mainBuffer.memLength) { |
417 |
> |
const int page = ((uintptr)addr - mainBuffer.memStart) >> mainBuffer.pageBits; |
418 |
|
LOCK_VOSF; |
419 |
< |
PFLAG_SET(page); |
420 |
< |
vm_protect((char *)page_ad, mainBuffer.pageSize, VM_PAGE_READ | VM_PAGE_WRITE); |
419 |
> |
if (PFLAG_ISCLEAR(page)) { |
420 |
> |
PFLAG_SET(page); |
421 |
> |
vm_protect((char *)(addr & -mainBuffer.pageSize), mainBuffer.pageSize, VM_PAGE_READ | VM_PAGE_WRITE); |
422 |
> |
} |
423 |
|
mainBuffer.dirty = true; |
424 |
|
UNLOCK_VOSF; |
425 |
|
return true; |
426 |
|
} |
427 |
|
|
428 |
|
/* Otherwise, we don't know how to handle the fault, let it crash */ |
259 |
– |
fprintf(stderr, "do_handle_screen_fault: unhandled address 0x%08X", addr); |
260 |
– |
if (fault_instruction != SIGSEGV_INVALID_PC) |
261 |
– |
fprintf(stderr, " [IP=0x%08X]", fault_instruction); |
262 |
– |
fprintf(stderr, "\n"); |
263 |
– |
#if EMULATED_68K |
264 |
– |
uaecptr nextpc; |
265 |
– |
extern void m68k_dumpstate(uaecptr *nextpc); |
266 |
– |
m68k_dumpstate(&nextpc); |
267 |
– |
#endif |
268 |
– |
VideoQuitFullScreen(); |
269 |
– |
#ifdef ENABLE_MON |
270 |
– |
char *arg[4] = {"mon", "-m", "-r", NULL}; |
271 |
– |
mon(3, arg); |
272 |
– |
QuitEmulator(); |
273 |
– |
#endif |
429 |
|
return false; |
430 |
|
} |
431 |
|
|
434 |
|
* Update display for Windowed mode and VOSF |
435 |
|
*/ |
436 |
|
|
282 |
– |
// From video_blit.cpp |
283 |
– |
extern void (*Screen_blit)(uint8 * dest, const uint8 * source, uint32 length); |
284 |
– |
extern bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order, video_depth mac_depth); |
285 |
– |
extern uint32 ExpandMap[256]; |
286 |
– |
|
437 |
|
/* How can we deal with array overrun conditions ? |
438 |
|
|
439 |
|
The state of the framebuffer pages that have been touched are maintained |
467 |
|
than pageCount. |
468 |
|
*/ |
469 |
|
|
470 |
< |
static inline void update_display_window_vosf(driver_window *drv) |
470 |
> |
#ifndef TEST_VOSF_PERFORMANCE |
471 |
> |
static void update_display_window_vosf(VIDEO_DRV_WIN_INIT) |
472 |
|
{ |
473 |
+ |
VIDEO_MODE_INIT; |
474 |
+ |
|
475 |
|
int page = 0; |
476 |
|
for (;;) { |
477 |
< |
const int first_page = find_next_page_set(page); |
477 |
> |
const unsigned first_page = find_next_page_set(page); |
478 |
|
if (first_page >= mainBuffer.pageCount) |
479 |
|
break; |
480 |
|
|
490 |
|
const int y1 = mainBuffer.pageInfo[first_page].top; |
491 |
|
const int y2 = mainBuffer.pageInfo[page - 1].bottom; |
492 |
|
const int height = y2 - y1 + 1; |
340 |
– |
|
341 |
– |
if (VideoMonitor.mode.depth < VDEPTH_8BIT) { |
342 |
– |
|
343 |
– |
// Update the_host_buffer and copy of the_buffer |
344 |
– |
const int src_bytes_per_row = VideoMonitor.mode.bytes_per_row; |
345 |
– |
const int dst_bytes_per_row = drv->img->bytes_per_line; |
346 |
– |
const int pixels_per_byte = VideoMonitor.mode.x / src_bytes_per_row; |
347 |
– |
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
348 |
– |
for (j = y1; j <= y2; j++) { |
349 |
– |
Screen_blit(the_host_buffer + i2, the_buffer + i1, VideoMonitor.mode.x / pixels_per_byte); |
350 |
– |
i1 += src_bytes_per_row; |
351 |
– |
i2 += dst_bytes_per_row; |
352 |
– |
} |
353 |
– |
|
354 |
– |
} else { |
493 |
|
|
494 |
< |
// Update the_host_buffer and copy of the_buffer |
495 |
< |
const int src_bytes_per_row = VideoMonitor.mode.bytes_per_row; |
496 |
< |
const int dst_bytes_per_row = drv->img->bytes_per_line; |
497 |
< |
const int bytes_per_pixel = src_bytes_per_row / VideoMonitor.mode.x; |
498 |
< |
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
499 |
< |
for (j = y1; j <= y2; j++) { |
500 |
< |
Screen_blit(the_host_buffer + i2, the_buffer + i1, bytes_per_pixel * VideoMonitor.mode.x); |
501 |
< |
i1 += src_bytes_per_row; |
502 |
< |
i2 += dst_bytes_per_row; |
365 |
< |
} |
494 |
> |
// Update the_host_buffer |
495 |
> |
VIDEO_DRV_LOCK_PIXELS; |
496 |
> |
const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; |
497 |
> |
const int dst_bytes_per_row = VIDEO_DRV_ROW_BYTES; |
498 |
> |
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
499 |
> |
for (j = y1; j <= y2; j++) { |
500 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, src_bytes_per_row); |
501 |
> |
i1 += src_bytes_per_row; |
502 |
> |
i2 += dst_bytes_per_row; |
503 |
|
} |
504 |
+ |
VIDEO_DRV_UNLOCK_PIXELS; |
505 |
|
|
506 |
< |
if (drv->have_shm) |
507 |
< |
XShmPutImage(x_display, drv->w, drv->gc, drv->img, 0, y1, 0, y1, VideoMonitor.mode.x, height, 0); |
506 |
> |
#ifdef USE_SDL_VIDEO |
507 |
> |
SDL_UpdateRect(drv->s, 0, y1, VIDEO_MODE_X, height); |
508 |
> |
#else |
509 |
> |
if (VIDEO_DRV_HAVE_SHM) |
510 |
> |
XShmPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height, 0); |
511 |
|
else |
512 |
< |
XPutImage(x_display, drv->w, drv->gc, drv->img, 0, y1, 0, y1, VideoMonitor.mode.x, height); |
512 |
> |
XPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height); |
513 |
> |
#endif |
514 |
|
} |
515 |
|
mainBuffer.dirty = false; |
516 |
|
} |
517 |
+ |
#endif |
518 |
|
|
519 |
|
|
520 |
|
/* |
522 |
|
* (only in Real or Direct Addressing mode) |
523 |
|
*/ |
524 |
|
|
525 |
+ |
#ifndef TEST_VOSF_PERFORMANCE |
526 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
527 |
< |
static inline void update_display_dga_vosf(void) |
527 |
> |
static void update_display_dga_vosf(VIDEO_DRV_DGA_INIT) |
528 |
|
{ |
529 |
< |
int page = 0; |
529 |
> |
VIDEO_MODE_INIT; |
530 |
> |
|
531 |
> |
// Compute number of bytes per row, take care to virtual screens |
532 |
> |
const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; |
533 |
> |
const int dst_bytes_per_row = TrivialBytesPerRow(VIDEO_MODE_X, DepthModeForPixelDepth(VIDEO_DRV_DEPTH)); |
534 |
> |
const int scr_bytes_per_row = VIDEO_DRV_ROW_BYTES; |
535 |
> |
assert(dst_bytes_per_row <= scr_bytes_per_row); |
536 |
> |
const int scr_bytes_left = scr_bytes_per_row - dst_bytes_per_row; |
537 |
> |
|
538 |
> |
// Full screen update requested? |
539 |
> |
if (mainBuffer.very_dirty) { |
540 |
> |
PFLAG_CLEAR_ALL; |
541 |
> |
vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ); |
542 |
> |
memcpy(the_buffer_copy, the_buffer, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
543 |
> |
VIDEO_DRV_LOCK_PIXELS; |
544 |
> |
int i1 = 0, i2 = 0; |
545 |
> |
for (int j = 0; j < VIDEO_MODE_Y; j++) { |
546 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, src_bytes_per_row); |
547 |
> |
i1 += src_bytes_per_row; |
548 |
> |
i2 += scr_bytes_per_row; |
549 |
> |
} |
550 |
> |
#ifdef USE_SDL_VIDEO |
551 |
> |
SDL_UpdateRect(drv->s, 0, 0, VIDEO_MODE_X, VIDEO_MODE_Y); |
552 |
> |
#endif |
553 |
> |
VIDEO_DRV_UNLOCK_PIXELS; |
554 |
> |
return; |
555 |
> |
} |
556 |
> |
|
557 |
> |
// Setup partial blitter (use 64-pixel wide chunks) |
558 |
> |
const int n_pixels = 64; |
559 |
> |
const int n_chunks = VIDEO_MODE_X / n_pixels; |
560 |
> |
const int n_pixels_left = VIDEO_MODE_X - (n_chunks * n_pixels); |
561 |
> |
const int src_chunk_size = src_bytes_per_row / n_chunks; |
562 |
> |
const int dst_chunk_size = dst_bytes_per_row / n_chunks; |
563 |
> |
const int src_chunk_size_left = src_bytes_per_row - (n_chunks * src_chunk_size); |
564 |
> |
const int dst_chunk_size_left = dst_bytes_per_row - (n_chunks * dst_chunk_size); |
565 |
> |
|
566 |
> |
int page = 0, last_scanline = -1; |
567 |
|
for (;;) { |
568 |
< |
const int first_page = find_next_page_set(page); |
568 |
> |
const unsigned first_page = find_next_page_set(page); |
569 |
|
if (first_page >= mainBuffer.pageCount) |
570 |
|
break; |
571 |
|
|
576 |
|
const int32 offset = first_page << mainBuffer.pageBits; |
577 |
|
const uint32 length = (page - first_page) << mainBuffer.pageBits; |
578 |
|
vm_protect((char *)mainBuffer.memStart + offset, length, VM_PAGE_READ); |
579 |
< |
|
580 |
< |
// I am sure that y2 >= y1 and depth != 1 |
581 |
< |
const int y1 = mainBuffer.pageInfo[first_page].top; |
582 |
< |
const int y2 = mainBuffer.pageInfo[page - 1].bottom; |
583 |
< |
|
584 |
< |
const int bytes_per_row = VideoMonitor.mode.bytes_per_row; |
585 |
< |
const int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; |
586 |
< |
int i, j; |
587 |
< |
|
588 |
< |
// Check for first column from left and first column |
589 |
< |
// from right that have changed |
590 |
< |
int x1 = VideoMonitor.mode.x * bytes_per_pixel - 1; |
591 |
< |
for (j = y1; j <= y2; j++) { |
592 |
< |
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
593 |
< |
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
594 |
< |
for (i = 0; i < x1; i++) { |
595 |
< |
if (p1[i] != p2[i]) { |
596 |
< |
x1 = i; |
597 |
< |
break; |
579 |
> |
|
580 |
> |
// Optimized for scanlines, don't process overlapping lines again |
581 |
> |
int y1 = mainBuffer.pageInfo[first_page].top; |
582 |
> |
int y2 = mainBuffer.pageInfo[page - 1].bottom; |
583 |
> |
if (y1 <= last_scanline && ++y1 >= VIDEO_MODE_Y) |
584 |
> |
continue; |
585 |
> |
if (y2 <= last_scanline && ++y2 >= VIDEO_MODE_Y) |
586 |
> |
continue; |
587 |
> |
last_scanline = y2; |
588 |
> |
|
589 |
> |
// Update the_host_buffer and copy of the_buffer, one line at a time |
590 |
> |
int i1 = y1 * src_bytes_per_row; |
591 |
> |
int i2 = y1 * scr_bytes_per_row; |
592 |
> |
#ifdef USE_SDL_VIDEO |
593 |
> |
int bbi = 0; |
594 |
> |
SDL_Rect bb[3] = { |
595 |
> |
{ VIDEO_MODE_X, y1, 0, 0 }, |
596 |
> |
{ VIDEO_MODE_X, -1, 0, 0 }, |
597 |
> |
{ VIDEO_MODE_X, -1, 0, 0 } |
598 |
> |
}; |
599 |
> |
#endif |
600 |
> |
VIDEO_DRV_LOCK_PIXELS; |
601 |
> |
for (int j = y1; j <= y2; j++) { |
602 |
> |
for (int i = 0; i < n_chunks; i++) { |
603 |
> |
if (memcmp(the_buffer_copy + i1, the_buffer + i1, src_chunk_size) != 0) { |
604 |
> |
memcpy(the_buffer_copy + i1, the_buffer + i1, src_chunk_size); |
605 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, src_chunk_size); |
606 |
> |
#ifdef USE_SDL_VIDEO |
607 |
> |
const int x = i * n_pixels; |
608 |
> |
if (x < bb[bbi].x) { |
609 |
> |
if (bb[bbi].w) |
610 |
> |
bb[bbi].w += bb[bbi].x - x; |
611 |
> |
else |
612 |
> |
bb[bbi].w = n_pixels; |
613 |
> |
bb[bbi].x = x; |
614 |
> |
} |
615 |
> |
else if (x >= bb[bbi].x + bb[bbi].w) |
616 |
> |
bb[bbi].w = x + n_pixels - bb[bbi].x; |
617 |
> |
#endif |
618 |
|
} |
619 |
+ |
i1 += src_chunk_size; |
620 |
+ |
i2 += dst_chunk_size; |
621 |
|
} |
622 |
< |
} |
623 |
< |
x1 /= bytes_per_pixel; |
624 |
< |
|
625 |
< |
int x2 = x1 * bytes_per_pixel; |
626 |
< |
for (j = y2; j >= y1; j--) { |
627 |
< |
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
628 |
< |
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
629 |
< |
for (i = VideoMonitor.mode.x * bytes_per_pixel - 1; i > x2; i--) { |
630 |
< |
if (p1[i] != p2[i]) { |
631 |
< |
x2 = i; |
632 |
< |
break; |
622 |
> |
if (src_chunk_size_left && dst_chunk_size_left) { |
623 |
> |
if (memcmp(the_buffer_copy + i1, the_buffer + i1, src_chunk_size_left) != 0) { |
624 |
> |
memcpy(the_buffer_copy + i1, the_buffer + i1, src_chunk_size_left); |
625 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, src_chunk_size_left); |
626 |
> |
} |
627 |
> |
i1 += src_chunk_size_left; |
628 |
> |
i2 += dst_chunk_size_left; |
629 |
> |
#ifdef USE_SDL_VIDEO |
630 |
> |
const int x = n_chunks * n_pixels; |
631 |
> |
if (x < bb[bbi].x) { |
632 |
> |
if (bb[bbi].w) |
633 |
> |
bb[bbi].w += bb[bbi].x - x; |
634 |
> |
else |
635 |
> |
bb[bbi].w = n_pixels_left; |
636 |
> |
bb[bbi].x = x; |
637 |
|
} |
638 |
+ |
else if (x >= bb[bbi].x + bb[bbi].w) |
639 |
+ |
bb[bbi].w = x + n_pixels_left - bb[bbi].x; |
640 |
+ |
#endif |
641 |
|
} |
642 |
+ |
i2 += scr_bytes_left; |
643 |
+ |
#ifdef USE_SDL_VIDEO |
644 |
+ |
bb[bbi].h++; |
645 |
+ |
if (bb[bbi].w && (j == y1 || j == y2 - 1 || j == y2)) { |
646 |
+ |
bbi++; |
647 |
+ |
assert(bbi <= 3); |
648 |
+ |
if (j != y2) |
649 |
+ |
bb[bbi].y = j + 1; |
650 |
+ |
} |
651 |
+ |
#endif |
652 |
|
} |
653 |
< |
x2 /= bytes_per_pixel; |
654 |
< |
|
655 |
< |
// Update the_host_buffer and copy of the_buffer |
656 |
< |
// There should be at least one pixel to copy |
437 |
< |
const int width = x2 - x1 + 1; |
438 |
< |
i = y1 * bytes_per_row + x1 * bytes_per_pixel; |
439 |
< |
for (j = y1; j <= y2; j++) { |
440 |
< |
Screen_blit(the_host_buffer + i, the_buffer + i, bytes_per_pixel * width); |
441 |
< |
memcpy(the_buffer_copy + i, the_buffer + i, bytes_per_pixel * width); |
442 |
< |
i += bytes_per_row; |
443 |
< |
} |
653 |
> |
#ifdef USE_SDL_VIDEO |
654 |
> |
SDL_UpdateRects(drv->s, bbi, bb); |
655 |
> |
#endif |
656 |
> |
VIDEO_DRV_UNLOCK_PIXELS; |
657 |
|
} |
658 |
|
mainBuffer.dirty = false; |
659 |
|
} |
660 |
|
#endif |
661 |
+ |
#endif |
662 |
|
|
663 |
|
#endif /* ENABLE_VOSF */ |
664 |
|
|