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 |
|
// Glue for SDL and X11 support |
34 |
|
#ifdef USE_SDL_VIDEO |
157 |
|
static spinlock_t vosf_lock = SPIN_LOCK_UNLOCKED; // Mutex to protect frame buffer (dirtyPages in fact) |
158 |
|
#define LOCK_VOSF spin_lock(&vosf_lock) |
159 |
|
#define UNLOCK_VOSF spin_unlock(&vosf_lock) |
160 |
+ |
#elif defined(_WIN32) |
161 |
+ |
static mutex_t vosf_lock; // Mutex to protect frame buffer (dirtyPages in fact) |
162 |
+ |
#define LOCK_VOSF vosf_lock.lock(); |
163 |
+ |
#define UNLOCK_VOSF vosf_lock.unlock(); |
164 |
|
#elif defined(HAVE_PTHREADS) |
165 |
|
static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) |
166 |
|
#define LOCK_VOSF pthread_mutex_lock(&vosf_lock); |
184 |
|
// Extend size to page boundary |
185 |
|
static uint32 page_extend(uint32 size) |
186 |
|
{ |
187 |
< |
const uint32 page_size = getpagesize(); |
187 |
> |
const uint32 page_size = vm_page_size(); |
188 |
|
const uint32 page_mask = page_size - 1; |
189 |
|
return (size + page_mask) & ~page_mask; |
190 |
|
} |
191 |
|
|
192 |
|
|
193 |
|
/* |
194 |
+ |
* Check if VOSF acceleration is profitable on this platform |
195 |
+ |
*/ |
196 |
+ |
|
197 |
+ |
const int VOSF_PROFITABLE_TRIES = 3; // Make 3 attempts for full screen update |
198 |
+ |
const int VOSF_PROFITABLE_THRESHOLD = 16667; // 60 Hz |
199 |
+ |
|
200 |
+ |
static bool video_vosf_profitable(void) |
201 |
+ |
{ |
202 |
+ |
int64 durations[VOSF_PROFITABLE_TRIES]; |
203 |
+ |
int mean_duration = 0; |
204 |
+ |
|
205 |
+ |
for (int i = 0; i < VOSF_PROFITABLE_TRIES; i++) { |
206 |
+ |
uint64 start = GetTicks_usec(); |
207 |
+ |
for (int p = 0; p < mainBuffer.pageCount; p++) { |
208 |
+ |
uint8 *addr = (uint8 *)(mainBuffer.memStart + (p * mainBuffer.pageSize)); |
209 |
+ |
addr[0] = 0; // Trigger Screen_fault_handler() |
210 |
+ |
} |
211 |
+ |
int64 duration = GetTicks_usec() - start; |
212 |
+ |
mean_duration += duration; |
213 |
+ |
durations[i] = duration; |
214 |
+ |
|
215 |
+ |
PFLAG_CLEAR_ALL; |
216 |
+ |
mainBuffer.dirty = false; |
217 |
+ |
if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0) |
218 |
+ |
return false; |
219 |
+ |
} |
220 |
+ |
|
221 |
+ |
mean_duration /= VOSF_PROFITABLE_TRIES; |
222 |
+ |
D(bug("Triggered %d screen faults in %ld usec on average\n", mainBuffer.pageCount, mean_duration)); |
223 |
+ |
return (mean_duration < (VOSF_PROFITABLE_THRESHOLD * (frame_skip ? frame_skip : 1))); |
224 |
+ |
} |
225 |
+ |
|
226 |
+ |
|
227 |
+ |
/* |
228 |
|
* Initialize the VOSF system (mainBuffer structure, SIGSEGV handler) |
229 |
|
*/ |
230 |
|
|
231 |
|
static bool video_vosf_init(MONITOR_INIT) |
232 |
|
{ |
233 |
< |
VIDEO_MODE_INIT; |
233 |
> |
VIDEO_MODE_INIT_MONITOR; |
234 |
|
|
235 |
< |
const uintptr page_size = getpagesize(); |
235 |
> |
const uintptr page_size = vm_page_size(); |
236 |
|
const uintptr page_mask = page_size - 1; |
237 |
|
|
238 |
|
// Round up frame buffer base to page boundary |
395 |
|
|
396 |
|
VIDEO_DRV_LOCK_PIXELS; |
397 |
|
|
398 |
< |
if (VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) { |
398 |
> |
if ((int)VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) { |
399 |
|
|
400 |
|
// Update the_host_buffer and copy of the_buffer |
401 |
|
const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; |