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 |
|
// Variables for Video on SEGV support |
75 |
|
static uint8 *the_host_buffer; // Host frame buffer in VOSF mode |
38 |
– |
static uint32 the_buffer_size; // Size of allocated the_buffer |
76 |
|
|
77 |
|
struct ScreenPageInfo { |
78 |
|
int top, bottom; // Mapping between this virtual page and Mac scanlines |
79 |
|
}; |
80 |
|
|
81 |
|
struct ScreenInfo { |
45 |
– |
uintptr memBase; // Real start address |
82 |
|
uintptr memStart; // Start address aligned to page boundary |
47 |
– |
uintptr memEnd; // Address of one-past-the-end of the screen |
83 |
|
uint32 memLength; // Length of the memory addressed by the screen pages |
84 |
|
|
85 |
< |
uint32 pageSize; // Size of a page |
85 |
> |
uintptr pageSize; // Size of a page |
86 |
|
int pageBits; // Shift count to get the page number |
87 |
|
uint32 pageCount; // Number of pages allocated to the screen |
88 |
|
|
89 |
|
bool dirty; // Flag: set if the frame buffer was touched |
90 |
+ |
bool very_dirty; // Flag: set if the frame buffer was completely modified (e.g. colormap changes) |
91 |
|
char * dirtyPages; // Table of flags set if page was altered |
92 |
|
ScreenPageInfo * pageInfo; // Table of mappings page -> Mac scanlines |
93 |
|
}; |
133 |
|
#define PFLAG_CLEAR_ALL do { \ |
134 |
|
PFLAG_CLEAR_RANGE(0, mainBuffer.pageCount); \ |
135 |
|
mainBuffer.dirty = false; \ |
136 |
+ |
mainBuffer.very_dirty = false; \ |
137 |
+ |
} while (0) |
138 |
+ |
|
139 |
+ |
#define PFLAG_SET_VERY_DIRTY do { \ |
140 |
+ |
mainBuffer.very_dirty = true; \ |
141 |
|
} while (0) |
142 |
|
|
143 |
|
// Set the following macro definition to 1 if your system |
172 |
|
#endif |
173 |
|
} |
174 |
|
|
175 |
< |
#ifdef HAVE_PTHREADS |
175 |
> |
#if defined(HAVE_PTHREADS) |
176 |
|
static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) |
177 |
|
#define LOCK_VOSF pthread_mutex_lock(&vosf_lock); |
178 |
|
#define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock); |
179 |
+ |
#elif defined(_WIN32) |
180 |
+ |
static mutex_t vosf_lock; // Mutex to protect frame buffer (dirtyPages in fact) |
181 |
+ |
#define LOCK_VOSF vosf_lock.lock(); |
182 |
+ |
#define UNLOCK_VOSF vosf_lock.unlock(); |
183 |
+ |
#elif defined(HAVE_SPINLOCKS) |
184 |
+ |
static spinlock_t vosf_lock = SPIN_LOCK_UNLOCKED; // Mutex to protect frame buffer (dirtyPages in fact) |
185 |
+ |
#define LOCK_VOSF spin_lock(&vosf_lock) |
186 |
+ |
#define UNLOCK_VOSF spin_unlock(&vosf_lock) |
187 |
|
#else |
188 |
|
#define LOCK_VOSF |
189 |
|
#define UNLOCK_VOSF |
203 |
|
// Extend size to page boundary |
204 |
|
static uint32 page_extend(uint32 size) |
205 |
|
{ |
206 |
< |
const uint32 page_size = getpagesize(); |
206 |
> |
const uint32 page_size = vm_get_page_size(); |
207 |
|
const uint32 page_mask = page_size - 1; |
208 |
|
return (size + page_mask) & ~page_mask; |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
/* |
213 |
< |
* Initialize mainBuffer structure |
213 |
> |
* Check if VOSF acceleration is profitable on this platform |
214 |
|
*/ |
215 |
|
|
216 |
< |
static bool video_init_buffer(void) |
216 |
> |
const int VOSF_PROFITABLE_TRIES = 3; // Make 3 attempts for full screen update |
217 |
> |
const int VOSF_PROFITABLE_THRESHOLD = 16667; // 60 Hz |
218 |
> |
|
219 |
> |
static bool video_vosf_profitable(void) |
220 |
|
{ |
221 |
< |
if (use_vosf) { |
222 |
< |
const uint32 page_size = getpagesize(); |
223 |
< |
const uint32 page_mask = page_size - 1; |
224 |
< |
|
225 |
< |
mainBuffer.memBase = (uintptr) the_buffer; |
226 |
< |
// Round up frame buffer base to page boundary |
227 |
< |
mainBuffer.memStart = (uintptr)((((unsigned long) the_buffer) + page_mask) & ~page_mask); |
228 |
< |
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; |
221 |
> |
int64 durations[VOSF_PROFITABLE_TRIES]; |
222 |
> |
int mean_duration = 0; |
223 |
> |
|
224 |
> |
for (int i = 0; i < VOSF_PROFITABLE_TRIES; i++) { |
225 |
> |
uint64 start = GetTicks_usec(); |
226 |
> |
for (int p = 0; p < mainBuffer.pageCount; p++) { |
227 |
> |
uint8 *addr = (uint8 *)(mainBuffer.memStart + (p * mainBuffer.pageSize)); |
228 |
> |
addr[0] = 0; // Trigger Screen_fault_handler() |
229 |
|
} |
230 |
+ |
int64 duration = GetTicks_usec() - start; |
231 |
+ |
mean_duration += duration; |
232 |
+ |
durations[i] = duration; |
233 |
|
|
234 |
< |
mainBuffer.dirtyPages = (char *) malloc(mainBuffer.pageCount + 2); |
234 |
> |
PFLAG_CLEAR_ALL; |
235 |
> |
mainBuffer.dirty = false; |
236 |
> |
if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0) |
237 |
> |
return false; |
238 |
> |
} |
239 |
|
|
240 |
< |
if (mainBuffer.pageInfo) { |
241 |
< |
free(mainBuffer.pageInfo); |
242 |
< |
mainBuffer.pageInfo = NULL; |
243 |
< |
} |
240 |
> |
mean_duration /= VOSF_PROFITABLE_TRIES; |
241 |
> |
D(bug("Triggered %d screen faults in %ld usec on average\n", mainBuffer.pageCount, mean_duration)); |
242 |
> |
return (mean_duration < (VOSF_PROFITABLE_THRESHOLD * (frame_skip ? frame_skip : 1))); |
243 |
> |
} |
244 |
|
|
195 |
– |
mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo)); |
245 |
|
|
246 |
< |
if ((mainBuffer.dirtyPages == NULL) || (mainBuffer.pageInfo == NULL)) |
247 |
< |
return false; |
248 |
< |
|
200 |
< |
mainBuffer.dirty = false; |
246 |
> |
/* |
247 |
> |
* Initialize the VOSF system (mainBuffer structure, SIGSEGV handler) |
248 |
> |
*/ |
249 |
|
|
250 |
< |
PFLAG_CLEAR_ALL; |
251 |
< |
// Safety net to insure the loops in the update routines will terminate |
252 |
< |
// See "How can we deal with array overrun conditions ?" hereunder for further details |
253 |
< |
PFLAG_CLEAR(mainBuffer.pageCount); |
254 |
< |
PFLAG_SET(mainBuffer.pageCount+1); |
255 |
< |
|
256 |
< |
uint32 a = 0; |
257 |
< |
for (int i = 0; i < mainBuffer.pageCount; i++) { |
258 |
< |
int y1 = a / VideoMonitor.mode.bytes_per_row; |
259 |
< |
if (y1 >= VideoMonitor.mode.y) |
260 |
< |
y1 = VideoMonitor.mode.y - 1; |
261 |
< |
|
262 |
< |
int y2 = (a + mainBuffer.pageSize) / VideoMonitor.mode.bytes_per_row; |
263 |
< |
if (y2 >= VideoMonitor.mode.y) |
264 |
< |
y2 = VideoMonitor.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 |
< |
} |
250 |
> |
static bool video_vosf_init(MONITOR_INIT) |
251 |
> |
{ |
252 |
> |
VIDEO_MODE_INIT_MONITOR; |
253 |
> |
|
254 |
> |
const uintptr page_size = vm_get_page_size(); |
255 |
> |
const uintptr page_mask = page_size - 1; |
256 |
> |
|
257 |
> |
// Round up frame buffer base to page boundary |
258 |
> |
mainBuffer.memStart = (((uintptr) the_buffer) + page_mask) & ~page_mask; |
259 |
> |
|
260 |
> |
// The frame buffer size shall already be aligned to page boundary (use page_extend) |
261 |
> |
mainBuffer.memLength = the_buffer_size; |
262 |
> |
|
263 |
> |
mainBuffer.pageSize = page_size; |
264 |
> |
mainBuffer.pageBits = log_base_2(mainBuffer.pageSize); |
265 |
> |
mainBuffer.pageCount = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize; |
266 |
> |
|
267 |
> |
// The "2" more bytes requested are a safety net to insure the |
268 |
> |
// loops in the update routines will terminate. |
269 |
> |
// See "How can we deal with array overrun conditions ?" hereunder for further details. |
270 |
> |
mainBuffer.dirtyPages = (char *) malloc(mainBuffer.pageCount + 2); |
271 |
> |
if (mainBuffer.dirtyPages == NULL) |
272 |
> |
return false; |
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; |
274 |
> |
PFLAG_CLEAR_ALL; |
275 |
> |
PFLAG_CLEAR(mainBuffer.pageCount); |
276 |
> |
PFLAG_SET(mainBuffer.pageCount+1); |
277 |
> |
|
278 |
> |
// Allocate and fill in pageInfo with start and end (inclusive) row in number of bytes |
279 |
> |
mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo)); |
280 |
> |
if (mainBuffer.pageInfo == NULL) |
281 |
> |
return false; |
282 |
> |
|
283 |
> |
uint32 a = 0; |
284 |
> |
for (unsigned i = 0; i < mainBuffer.pageCount; i++) { |
285 |
> |
unsigned y1 = a / VIDEO_MODE_ROW_BYTES; |
286 |
> |
if (y1 >= VIDEO_MODE_Y) |
287 |
> |
y1 = VIDEO_MODE_Y - 1; |
288 |
> |
|
289 |
> |
unsigned y2 = (a + mainBuffer.pageSize) / VIDEO_MODE_ROW_BYTES; |
290 |
> |
if (y2 >= VIDEO_MODE_Y) |
291 |
> |
y2 = VIDEO_MODE_Y - 1; |
292 |
> |
|
293 |
> |
mainBuffer.pageInfo[i].top = y1; |
294 |
> |
mainBuffer.pageInfo[i].bottom = y2; |
295 |
> |
|
296 |
> |
a += mainBuffer.pageSize; |
297 |
> |
if (a > mainBuffer.memLength) |
298 |
> |
a = mainBuffer.memLength; |
299 |
|
} |
300 |
+ |
|
301 |
+ |
// We can now write-protect the frame buffer |
302 |
+ |
if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0) |
303 |
+ |
return false; |
304 |
+ |
|
305 |
+ |
// The frame buffer is sane, i.e. there is no write to it yet |
306 |
+ |
mainBuffer.dirty = false; |
307 |
|
return true; |
308 |
|
} |
309 |
|
|
310 |
|
|
311 |
|
/* |
312 |
+ |
* Deinitialize VOSF system |
313 |
+ |
*/ |
314 |
+ |
|
315 |
+ |
static void video_vosf_exit(void) |
316 |
+ |
{ |
317 |
+ |
if (mainBuffer.pageInfo) { |
318 |
+ |
free(mainBuffer.pageInfo); |
319 |
+ |
mainBuffer.pageInfo = NULL; |
320 |
+ |
} |
321 |
+ |
if (mainBuffer.dirtyPages) { |
322 |
+ |
free(mainBuffer.dirtyPages); |
323 |
+ |
mainBuffer.dirtyPages = NULL; |
324 |
+ |
} |
325 |
+ |
} |
326 |
+ |
|
327 |
+ |
|
328 |
+ |
/* |
329 |
|
* Screen fault handler |
330 |
|
*/ |
331 |
|
|
332 |
< |
static bool screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
332 |
> |
bool Screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
333 |
|
{ |
240 |
– |
// D(bug("screen_fault_handler: ADDR=0x%08X from IP=0x%08X\n", fault_address, fault_instruction)); |
334 |
|
const uintptr addr = (uintptr)fault_address; |
335 |
|
|
336 |
|
/* Someone attempted to write to the frame buffer. Make it writeable |
337 |
|
* now so that the data could actually be written to. It will be made |
338 |
|
* read-only back in one of the screen update_*() functions. |
339 |
|
*/ |
340 |
< |
if ((addr >= mainBuffer.memStart) && (addr < mainBuffer.memEnd)) { |
341 |
< |
const int page = (addr - mainBuffer.memStart) >> mainBuffer.pageBits; |
249 |
< |
caddr_t page_ad = (caddr_t)(addr & -mainBuffer.pageSize); |
340 |
> |
if (((uintptr)addr - mainBuffer.memStart) < mainBuffer.memLength) { |
341 |
> |
const int page = ((uintptr)addr - mainBuffer.memStart) >> mainBuffer.pageBits; |
342 |
|
LOCK_VOSF; |
343 |
|
PFLAG_SET(page); |
344 |
< |
vm_protect((char *)page_ad, mainBuffer.pageSize, VM_PAGE_READ | VM_PAGE_WRITE); |
344 |
> |
vm_protect((char *)(addr & -mainBuffer.pageSize), mainBuffer.pageSize, VM_PAGE_READ | VM_PAGE_WRITE); |
345 |
|
mainBuffer.dirty = true; |
346 |
|
UNLOCK_VOSF; |
347 |
|
return true; |
348 |
|
} |
349 |
|
|
350 |
|
/* 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 |
351 |
|
return false; |
352 |
|
} |
353 |
|
|
356 |
|
* Update display for Windowed mode and VOSF |
357 |
|
*/ |
358 |
|
|
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 |
– |
|
359 |
|
/* How can we deal with array overrun conditions ? |
360 |
|
|
361 |
|
The state of the framebuffer pages that have been touched are maintained |
389 |
|
than pageCount. |
390 |
|
*/ |
391 |
|
|
392 |
< |
static inline void update_display_window_vosf(driver_window *drv) |
392 |
> |
#ifndef TEST_VOSF_PERFORMANCE |
393 |
> |
static void update_display_window_vosf(VIDEO_DRV_WIN_INIT) |
394 |
|
{ |
395 |
+ |
VIDEO_MODE_INIT; |
396 |
+ |
|
397 |
|
int page = 0; |
398 |
|
for (;;) { |
399 |
< |
const int first_page = find_next_page_set(page); |
399 |
> |
const unsigned first_page = find_next_page_set(page); |
400 |
|
if (first_page >= mainBuffer.pageCount) |
401 |
|
break; |
402 |
|
|
412 |
|
const int y1 = mainBuffer.pageInfo[first_page].top; |
413 |
|
const int y2 = mainBuffer.pageInfo[page - 1].bottom; |
414 |
|
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 |
– |
} |
415 |
|
|
416 |
< |
} else { |
417 |
< |
|
418 |
< |
// Update the_host_buffer and copy of the_buffer |
419 |
< |
const int src_bytes_per_row = VideoMonitor.mode.bytes_per_row; |
420 |
< |
const int dst_bytes_per_row = drv->img->bytes_per_line; |
421 |
< |
const int bytes_per_pixel = src_bytes_per_row / VideoMonitor.mode.x; |
422 |
< |
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
423 |
< |
for (j = y1; j <= y2; j++) { |
424 |
< |
Screen_blit(the_host_buffer + i2, the_buffer + i1, bytes_per_pixel * VideoMonitor.mode.x); |
363 |
< |
i1 += src_bytes_per_row; |
364 |
< |
i2 += dst_bytes_per_row; |
365 |
< |
} |
416 |
> |
// Update the_host_buffer |
417 |
> |
VIDEO_DRV_LOCK_PIXELS; |
418 |
> |
const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; |
419 |
> |
const int dst_bytes_per_row = VIDEO_DRV_ROW_BYTES; |
420 |
> |
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
421 |
> |
for (j = y1; j <= y2; j++) { |
422 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, src_bytes_per_row); |
423 |
> |
i1 += src_bytes_per_row; |
424 |
> |
i2 += dst_bytes_per_row; |
425 |
|
} |
426 |
+ |
VIDEO_DRV_UNLOCK_PIXELS; |
427 |
|
|
428 |
< |
if (drv->have_shm) |
429 |
< |
XShmPutImage(x_display, drv->w, drv->gc, drv->img, 0, y1, 0, y1, VideoMonitor.mode.x, height, 0); |
428 |
> |
#ifdef USE_SDL_VIDEO |
429 |
> |
SDL_UpdateRect(drv->s, 0, y1, VIDEO_MODE_X, height); |
430 |
> |
#else |
431 |
> |
if (VIDEO_DRV_HAVE_SHM) |
432 |
> |
XShmPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height, 0); |
433 |
|
else |
434 |
< |
XPutImage(x_display, drv->w, drv->gc, drv->img, 0, y1, 0, y1, VideoMonitor.mode.x, height); |
434 |
> |
XPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height); |
435 |
> |
#endif |
436 |
|
} |
437 |
|
mainBuffer.dirty = false; |
438 |
|
} |
439 |
+ |
#endif |
440 |
|
|
441 |
|
|
442 |
|
/* |
444 |
|
* (only in Real or Direct Addressing mode) |
445 |
|
*/ |
446 |
|
|
447 |
+ |
#ifndef TEST_VOSF_PERFORMANCE |
448 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
449 |
< |
static inline void update_display_dga_vosf(void) |
449 |
> |
static void update_display_dga_vosf(VIDEO_DRV_DGA_INIT) |
450 |
|
{ |
451 |
< |
int page = 0; |
451 |
> |
VIDEO_MODE_INIT; |
452 |
> |
|
453 |
> |
// Compute number of bytes per row, take care to virtual screens |
454 |
> |
const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; |
455 |
> |
const int dst_bytes_per_row = TrivialBytesPerRow(VIDEO_MODE_X, DepthModeForPixelDepth(VIDEO_DRV_DEPTH)); |
456 |
> |
const int scr_bytes_per_row = VIDEO_DRV_ROW_BYTES; |
457 |
> |
assert(dst_bytes_per_row <= scr_bytes_per_row); |
458 |
> |
const int scr_bytes_left = scr_bytes_per_row - dst_bytes_per_row; |
459 |
> |
|
460 |
> |
// Full screen update requested? |
461 |
> |
if (mainBuffer.very_dirty) { |
462 |
> |
PFLAG_CLEAR_ALL; |
463 |
> |
vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ); |
464 |
> |
memcpy(the_buffer_copy, the_buffer, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
465 |
> |
VIDEO_DRV_LOCK_PIXELS; |
466 |
> |
int i1 = 0, i2 = 0; |
467 |
> |
for (int j = 0; j < VIDEO_MODE_Y; j++) { |
468 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, src_bytes_per_row); |
469 |
> |
i1 += src_bytes_per_row; |
470 |
> |
i2 += scr_bytes_per_row; |
471 |
> |
} |
472 |
> |
#ifdef USE_SDL_VIDEO |
473 |
> |
SDL_UpdateRect(drv->s, 0, 0, VIDEO_MODE_X, VIDEO_MODE_Y); |
474 |
> |
#endif |
475 |
> |
VIDEO_DRV_UNLOCK_PIXELS; |
476 |
> |
return; |
477 |
> |
} |
478 |
> |
|
479 |
> |
// Setup partial blitter (use 64-pixel wide chunks) |
480 |
> |
const int n_pixels = 64; |
481 |
> |
const int n_chunks = VIDEO_MODE_X / n_pixels; |
482 |
> |
const int n_pixels_left = VIDEO_MODE_X - (n_chunks * n_pixels); |
483 |
> |
const int src_chunk_size = src_bytes_per_row / n_chunks; |
484 |
> |
const int dst_chunk_size = dst_bytes_per_row / n_chunks; |
485 |
> |
const int src_chunk_size_left = src_bytes_per_row - (n_chunks * src_chunk_size); |
486 |
> |
const int dst_chunk_size_left = dst_bytes_per_row - (n_chunks * dst_chunk_size); |
487 |
> |
|
488 |
> |
int page = 0, last_scanline = -1; |
489 |
|
for (;;) { |
490 |
< |
const int first_page = find_next_page_set(page); |
490 |
> |
const unsigned first_page = find_next_page_set(page); |
491 |
|
if (first_page >= mainBuffer.pageCount) |
492 |
|
break; |
493 |
|
|
498 |
|
const int32 offset = first_page << mainBuffer.pageBits; |
499 |
|
const uint32 length = (page - first_page) << mainBuffer.pageBits; |
500 |
|
vm_protect((char *)mainBuffer.memStart + offset, length, VM_PAGE_READ); |
501 |
< |
|
502 |
< |
// I am sure that y2 >= y1 and depth != 1 |
503 |
< |
const int y1 = mainBuffer.pageInfo[first_page].top; |
504 |
< |
const int y2 = mainBuffer.pageInfo[page - 1].bottom; |
505 |
< |
|
506 |
< |
const int bytes_per_row = VideoMonitor.mode.bytes_per_row; |
507 |
< |
const int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; |
508 |
< |
int i, j; |
509 |
< |
|
510 |
< |
// Check for first column from left and first column |
511 |
< |
// from right that have changed |
512 |
< |
int x1 = VideoMonitor.mode.x * bytes_per_pixel - 1; |
513 |
< |
for (j = y1; j <= y2; j++) { |
514 |
< |
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
515 |
< |
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
516 |
< |
for (i = 0; i < x1; i++) { |
517 |
< |
if (p1[i] != p2[i]) { |
518 |
< |
x1 = i; |
519 |
< |
break; |
501 |
> |
|
502 |
> |
// Optimized for scanlines, don't process overlapping lines again |
503 |
> |
int y1 = mainBuffer.pageInfo[first_page].top; |
504 |
> |
int y2 = mainBuffer.pageInfo[page - 1].bottom; |
505 |
> |
if (y1 <= last_scanline && ++y1 >= VIDEO_MODE_Y) |
506 |
> |
continue; |
507 |
> |
if (y2 <= last_scanline && ++y2 >= VIDEO_MODE_Y) |
508 |
> |
continue; |
509 |
> |
last_scanline = y2; |
510 |
> |
|
511 |
> |
// Update the_host_buffer and copy of the_buffer, one line at a time |
512 |
> |
int i1 = y1 * src_bytes_per_row; |
513 |
> |
int i2 = y1 * scr_bytes_per_row; |
514 |
> |
#ifdef USE_SDL_VIDEO |
515 |
> |
int bbi = 0; |
516 |
> |
SDL_Rect bb[3] = { |
517 |
> |
{ VIDEO_MODE_X, y1, 0, 0 }, |
518 |
> |
{ VIDEO_MODE_X, -1, 0, 0 }, |
519 |
> |
{ VIDEO_MODE_X, -1, 0, 0 } |
520 |
> |
}; |
521 |
> |
#endif |
522 |
> |
VIDEO_DRV_LOCK_PIXELS; |
523 |
> |
for (int j = y1; j <= y2; j++) { |
524 |
> |
for (int i = 0; i < n_chunks; i++) { |
525 |
> |
if (memcmp(the_buffer_copy + i1, the_buffer + i1, src_chunk_size) != 0) { |
526 |
> |
memcpy(the_buffer_copy + i1, the_buffer + i1, src_chunk_size); |
527 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, src_chunk_size); |
528 |
> |
#ifdef USE_SDL_VIDEO |
529 |
> |
const int x = i * n_pixels; |
530 |
> |
if (x < bb[bbi].x) { |
531 |
> |
if (bb[bbi].w) |
532 |
> |
bb[bbi].w += bb[bbi].x - x; |
533 |
> |
else |
534 |
> |
bb[bbi].w = n_pixels; |
535 |
> |
bb[bbi].x = x; |
536 |
> |
} |
537 |
> |
else if (x >= bb[bbi].x + bb[bbi].w) |
538 |
> |
bb[bbi].w = x + n_pixels - bb[bbi].x; |
539 |
> |
#endif |
540 |
|
} |
541 |
+ |
i1 += src_chunk_size; |
542 |
+ |
i2 += dst_chunk_size; |
543 |
|
} |
544 |
< |
} |
545 |
< |
x1 /= bytes_per_pixel; |
546 |
< |
|
547 |
< |
int x2 = x1 * bytes_per_pixel; |
548 |
< |
for (j = y2; j >= y1; j--) { |
549 |
< |
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
550 |
< |
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
551 |
< |
for (i = VideoMonitor.mode.x * bytes_per_pixel - 1; i > x2; i--) { |
552 |
< |
if (p1[i] != p2[i]) { |
553 |
< |
x2 = i; |
554 |
< |
break; |
544 |
> |
if (src_chunk_size_left && dst_chunk_size_left) { |
545 |
> |
if (memcmp(the_buffer_copy + i1, the_buffer + i1, src_chunk_size_left) != 0) { |
546 |
> |
memcpy(the_buffer_copy + i1, the_buffer + i1, src_chunk_size_left); |
547 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, src_chunk_size_left); |
548 |
> |
} |
549 |
> |
i1 += src_chunk_size_left; |
550 |
> |
i2 += dst_chunk_size_left; |
551 |
> |
#ifdef USE_SDL_VIDEO |
552 |
> |
const int x = n_chunks * n_pixels; |
553 |
> |
if (x < bb[bbi].x) { |
554 |
> |
if (bb[bbi].w) |
555 |
> |
bb[bbi].w += bb[bbi].x - x; |
556 |
> |
else |
557 |
> |
bb[bbi].w = n_pixels_left; |
558 |
> |
bb[bbi].x = x; |
559 |
|
} |
560 |
+ |
else if (x >= bb[bbi].x + bb[bbi].w) |
561 |
+ |
bb[bbi].w = x + n_pixels_left - bb[bbi].x; |
562 |
+ |
#endif |
563 |
|
} |
564 |
+ |
i2 += scr_bytes_left; |
565 |
+ |
#ifdef USE_SDL_VIDEO |
566 |
+ |
bb[bbi].h++; |
567 |
+ |
if (bb[bbi].w && (j == y1 || j == y2 - 1 || j == y2)) { |
568 |
+ |
bbi++; |
569 |
+ |
assert(bbi <= 3); |
570 |
+ |
if (j != y2) |
571 |
+ |
bb[bbi].y = j + 1; |
572 |
+ |
} |
573 |
+ |
#endif |
574 |
|
} |
575 |
< |
x2 /= bytes_per_pixel; |
576 |
< |
|
577 |
< |
// Update the_host_buffer and copy of the_buffer |
578 |
< |
// 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 |
< |
} |
575 |
> |
#ifdef USE_SDL_VIDEO |
576 |
> |
SDL_UpdateRects(drv->s, bbi, bb); |
577 |
> |
#endif |
578 |
> |
VIDEO_DRV_UNLOCK_PIXELS; |
579 |
|
} |
580 |
|
mainBuffer.dirty = false; |
581 |
|
} |
582 |
|
#endif |
583 |
+ |
#endif |
584 |
|
|
585 |
|
#endif /* ENABLE_VOSF */ |
586 |
|
|