1 |
|
/* |
2 |
|
* video_vosf.h - Video/graphics emulation, video on SEGV signals support |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2002 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 |
29 |
|
#include "sigsegv.h" |
30 |
|
#include "vm_alloc.h" |
31 |
|
|
32 |
< |
// Glue for SheepShaver and BasiliskII |
33 |
< |
#if POWERPC_ROM |
34 |
< |
#define X11_MONITOR_INIT /* nothing */ |
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 |
40 |
– |
#define VIDEO_MODE_INIT VideoInfo const & mode = VModes[cur_mode] |
41 |
– |
#define VIDEO_MODE_ROW_BYTES mode.viRowBytes |
42 |
– |
#define VIDEO_MODE_X mode.viXsize |
43 |
– |
#define VIDEO_MODE_Y mode.viYsize |
44 |
– |
#define VIDEO_MODE_DEPTH mode.viAppleMode |
45 |
– |
enum { |
46 |
– |
VIDEO_DEPTH_1BIT = APPLE_1_BIT, |
47 |
– |
VIDEO_DEPTH_2BIT = APPLE_2_BIT, |
48 |
– |
VIDEO_DEPTH_4BIT = APPLE_4_BIT, |
49 |
– |
VIDEO_DEPTH_8BIT = APPLE_8_BIT, |
50 |
– |
VIDEO_DEPTH_16BIT = APPLE_16_BIT, |
51 |
– |
VIDEO_DEPTH_32BIT = APPLE_32_BIT |
52 |
– |
}; |
47 |
|
#else |
48 |
< |
#define X11_MONITOR_INIT X11_monitor_desc &monitor |
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 |
< |
#define VIDEO_MODE_INIT video_mode const & mode = drv->monitor.get_current_mode(); |
55 |
< |
#define VIDEO_MODE_ROW_BYTES mode.bytes_per_row |
56 |
< |
#define VIDEO_MODE_X mode.x |
57 |
< |
#define VIDEO_MODE_Y mode.y |
64 |
< |
#define VIDEO_MODE_DEPTH (int)mode.depth |
65 |
< |
enum { |
66 |
< |
VIDEO_DEPTH_1BIT = VDEPTH_1BIT, |
67 |
< |
VIDEO_DEPTH_2BIT = VDEPTH_2BIT, |
68 |
< |
VIDEO_DEPTH_4BIT = VDEPTH_4BIT, |
69 |
< |
VIDEO_DEPTH_8BIT = VDEPTH_8BIT, |
70 |
< |
VIDEO_DEPTH_16BIT = VDEPTH_16BIT, |
71 |
< |
VIDEO_DEPTH_32BIT = VDEPTH_32BIT |
72 |
< |
}; |
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 |
|
// Variables for Video on SEGV support |
186 |
|
|
187 |
|
|
188 |
|
/* |
189 |
+ |
* Check if VOSF acceleration is profitable on this platform |
190 |
+ |
*/ |
191 |
+ |
|
192 |
+ |
const int VOSF_PROFITABLE_TRIES = 3; // Make 3 attempts for full screen update |
193 |
+ |
const int VOSF_PROFITABLE_THRESHOLD = 16667; // 60 Hz |
194 |
+ |
|
195 |
+ |
static bool video_vosf_profitable(void) |
196 |
+ |
{ |
197 |
+ |
int64 durations[VOSF_PROFITABLE_TRIES]; |
198 |
+ |
int mean_duration = 0; |
199 |
+ |
|
200 |
+ |
for (int i = 0; i < VOSF_PROFITABLE_TRIES; i++) { |
201 |
+ |
uint64 start = GetTicks_usec(); |
202 |
+ |
for (int p = 0; p < mainBuffer.pageCount; p++) { |
203 |
+ |
uint8 *addr = (uint8 *)(mainBuffer.memStart + (p * mainBuffer.pageSize)); |
204 |
+ |
addr[0] = 0; // Trigger Screen_fault_handler() |
205 |
+ |
} |
206 |
+ |
int64 duration = GetTicks_usec() - start; |
207 |
+ |
mean_duration += duration; |
208 |
+ |
durations[i] = duration; |
209 |
+ |
|
210 |
+ |
PFLAG_CLEAR_ALL; |
211 |
+ |
mainBuffer.dirty = false; |
212 |
+ |
if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0) |
213 |
+ |
return false; |
214 |
+ |
} |
215 |
+ |
|
216 |
+ |
mean_duration /= VOSF_PROFITABLE_TRIES; |
217 |
+ |
D(bug("Triggered %d screen faults in %ld usec on average\n", mainBuffer.pageCount, mean_duration)); |
218 |
+ |
return (mean_duration < (VOSF_PROFITABLE_THRESHOLD * (frame_skip ? frame_skip : 1))); |
219 |
+ |
} |
220 |
+ |
|
221 |
+ |
|
222 |
+ |
/* |
223 |
|
* Initialize the VOSF system (mainBuffer structure, SIGSEGV handler) |
224 |
|
*/ |
225 |
|
|
226 |
< |
static bool video_vosf_init(X11_MONITOR_INIT) |
226 |
> |
static bool video_vosf_init(MONITOR_INIT) |
227 |
|
{ |
228 |
< |
VIDEO_MODE_INIT; |
228 |
> |
VIDEO_MODE_INIT_MONITOR; |
229 |
|
|
230 |
|
const uintptr page_size = getpagesize(); |
231 |
|
const uintptr page_mask = page_size - 1; |
332 |
|
* Update display for Windowed mode and VOSF |
333 |
|
*/ |
334 |
|
|
316 |
– |
// From video_blit.cpp |
317 |
– |
extern void (*Screen_blit)(uint8 * dest, const uint8 * source, uint32 length); |
318 |
– |
extern bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order, int mac_depth); |
319 |
– |
extern uint32 ExpandMap[256]; |
320 |
– |
|
335 |
|
/* How can we deal with array overrun conditions ? |
336 |
|
|
337 |
|
The state of the framebuffer pages that have been touched are maintained |
368 |
|
static inline void update_display_window_vosf(VIDEO_DRV_INIT) |
369 |
|
{ |
370 |
|
VIDEO_MODE_INIT; |
371 |
+ |
XDisplayLock(); |
372 |
|
|
373 |
|
int page = 0; |
374 |
|
for (;;) { |
388 |
|
const int y1 = mainBuffer.pageInfo[first_page].top; |
389 |
|
const int y2 = mainBuffer.pageInfo[page - 1].bottom; |
390 |
|
const int height = y2 - y1 + 1; |
391 |
< |
|
392 |
< |
if (VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) { |
391 |
> |
|
392 |
> |
VIDEO_DRV_LOCK_PIXELS; |
393 |
> |
|
394 |
> |
if ((int)VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) { |
395 |
|
|
396 |
|
// Update the_host_buffer and copy of the_buffer |
397 |
|
const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; |
398 |
< |
const int dst_bytes_per_row = VIDEO_DRV_IMAGE->bytes_per_line; |
398 |
> |
const int dst_bytes_per_row = VIDEO_DRV_ROW_BYTES; |
399 |
|
const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row; |
400 |
|
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
401 |
|
for (j = y1; j <= y2; j++) { |
408 |
|
|
409 |
|
// Update the_host_buffer and copy of the_buffer |
410 |
|
const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; |
411 |
< |
const int dst_bytes_per_row = VIDEO_DRV_IMAGE->bytes_per_line; |
411 |
> |
const int dst_bytes_per_row = VIDEO_DRV_ROW_BYTES; |
412 |
|
const int bytes_per_pixel = src_bytes_per_row / VIDEO_MODE_X; |
413 |
|
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
414 |
|
for (j = y1; j <= y2; j++) { |
418 |
|
} |
419 |
|
} |
420 |
|
|
421 |
+ |
VIDEO_DRV_UNLOCK_PIXELS; |
422 |
+ |
|
423 |
+ |
#ifdef USE_SDL_VIDEO |
424 |
+ |
SDL_UpdateRect(drv->s, 0, y1, VIDEO_MODE_X, height); |
425 |
+ |
#else |
426 |
|
if (VIDEO_DRV_HAVE_SHM) |
427 |
|
XShmPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height, 0); |
428 |
|
else |
429 |
|
XPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height); |
430 |
+ |
#endif |
431 |
|
} |
432 |
+ |
|
433 |
+ |
XDisplayUnlock(); |
434 |
|
mainBuffer.dirty = false; |
435 |
|
} |
436 |
|
|
497 |
|
|
498 |
|
// Update the_host_buffer and copy of the_buffer |
499 |
|
// There should be at least one pixel to copy |
500 |
+ |
VIDEO_DRV_LOCK_PIXELS; |
501 |
|
const int width = x2 - x1 + 1; |
502 |
|
i = y1 * bytes_per_row + x1 * bytes_per_pixel; |
503 |
|
for (j = y1; j <= y2; j++) { |
505 |
|
memcpy(the_buffer_copy + i, the_buffer + i, bytes_per_pixel * width); |
506 |
|
i += bytes_per_row; |
507 |
|
} |
508 |
+ |
VIDEO_DRV_UNLOCK_PIXELS; |
509 |
|
} |
510 |
|
mainBuffer.dirty = false; |
511 |
|
} |