27 |
|
* Ctrl-F5 = grab mouse (in windowed mode) |
28 |
|
* |
29 |
|
* FIXMEs and TODOs: |
30 |
+ |
* - Windows requires an extra mouse event to update the actual cursor image? |
31 |
|
* - Ctr-Tab for suspend/resume but how? SDL does not support that for non-Linux |
32 |
|
* - Ctrl-Fn doesn't generate SDL_KEYDOWN events (SDL bug?) |
33 |
|
* - Mouse acceleration, there is no API in SDL yet for that |
34 |
|
* - Force relative mode in Grab mode even if SDL provides absolute coordinates? |
34 |
– |
* - Fullscreen mode |
35 |
|
* - Gamma tables support is likely to be broken here |
36 |
|
* - Events processing is bound to the general emulation thread as SDL requires |
37 |
|
* to PumpEvents() within the same thread as the one that called SetVideoMode(). |
38 |
|
* Besides, there can't seem to be a way to call SetVideoMode() from a child thread. |
39 |
– |
* - Refresh performance is still slow. Use SDL_CreateRGBSurface()? |
39 |
|
* - Backport hw cursor acceleration to Basilisk II? |
40 |
|
* - Factor out code |
41 |
|
*/ |
48 |
|
#include <errno.h> |
49 |
|
#include <vector> |
50 |
|
|
51 |
+ |
#ifdef WIN32 |
52 |
+ |
#include <malloc.h> /* alloca() */ |
53 |
+ |
#endif |
54 |
+ |
|
55 |
|
#include "cpu_emulation.h" |
56 |
|
#include "main.h" |
57 |
|
#include "adb.h" |
719 |
|
* Windowed display driver |
720 |
|
*/ |
721 |
|
|
722 |
+ |
static int SDL_display_opened = FALSE; |
723 |
+ |
|
724 |
|
// Open display |
725 |
|
driver_window::driver_window(SDL_monitor_desc &m) |
726 |
|
: driver_base(m), mouse_grabbed(false) |
732 |
|
// Set absolute mouse mode |
733 |
|
ADBSetRelMouseMode(mouse_grabbed); |
734 |
|
|
735 |
+ |
// This is ugly: |
736 |
+ |
// If we're switching resolutions (ie, not setting it for the first time), |
737 |
+ |
// there's a bug in SDL where the SDL_Surface created will not be properly |
738 |
+ |
// setup. The solution is to SDL_Quit() before calling SDL_SetVideoMode for |
739 |
+ |
// the second time (SDL_SetVideoMode will call SDL_Init() and all will be |
740 |
+ |
// well). Without this, the video becomes corrupted (at least on Mac OS X), |
741 |
+ |
// after the resolution switch (for the second and subsequent times). |
742 |
+ |
if (SDL_display_opened) |
743 |
+ |
SDL_Quit(); |
744 |
+ |
|
745 |
|
// Create surface |
746 |
|
int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH); |
747 |
|
if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL) |
748 |
|
return; |
749 |
|
|
750 |
+ |
SDL_display_opened = TRUE; |
751 |
+ |
|
752 |
|
#ifdef ENABLE_VOSF |
753 |
|
use_vosf = true; |
754 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
2001 |
|
} |
2002 |
|
} |
2003 |
|
|
2004 |
+ |
// Static display update (fixed frame rate, bounding boxes based) |
2005 |
+ |
// XXX use NQD bounding boxes to help detect dirty areas? |
2006 |
+ |
static void update_display_static_bbox(driver_window *drv) |
2007 |
+ |
{ |
2008 |
+ |
const VIDEO_MODE &mode = drv->mode; |
2009 |
+ |
|
2010 |
+ |
// Allocate bounding boxes for SDL_UpdateRects() |
2011 |
+ |
const int N_PIXELS = 64; |
2012 |
+ |
const int n_x_boxes = (VIDEO_MODE_X + N_PIXELS - 1) / N_PIXELS; |
2013 |
+ |
const int n_y_boxes = (VIDEO_MODE_Y + N_PIXELS - 1) / N_PIXELS; |
2014 |
+ |
SDL_Rect *boxes = (SDL_Rect *)alloca(sizeof(SDL_Rect) * n_x_boxes * n_y_boxes); |
2015 |
+ |
int nr_boxes = 0; |
2016 |
+ |
|
2017 |
+ |
// Lock surface, if required |
2018 |
+ |
if (SDL_MUSTLOCK(drv->s)) |
2019 |
+ |
SDL_LockSurface(drv->s); |
2020 |
+ |
|
2021 |
+ |
// Update the surface from Mac screen |
2022 |
+ |
const int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
2023 |
+ |
const int bytes_per_pixel = bytes_per_row / VIDEO_MODE_X; |
2024 |
+ |
int x, y; |
2025 |
+ |
for (y = 0; y < VIDEO_MODE_Y; y += N_PIXELS) { |
2026 |
+ |
int h = N_PIXELS; |
2027 |
+ |
if (h > VIDEO_MODE_Y - y) |
2028 |
+ |
h = VIDEO_MODE_Y - y; |
2029 |
+ |
for (x = 0; x < VIDEO_MODE_X; x += N_PIXELS) { |
2030 |
+ |
int w = N_PIXELS; |
2031 |
+ |
if (w > VIDEO_MODE_X - x) |
2032 |
+ |
w = VIDEO_MODE_X - x; |
2033 |
+ |
const int xs = w * bytes_per_pixel; |
2034 |
+ |
const int xb = x * bytes_per_pixel; |
2035 |
+ |
bool dirty = false; |
2036 |
+ |
for (int j = y; j < (y + h); j++) { |
2037 |
+ |
const int yb = j * bytes_per_row; |
2038 |
+ |
if (memcmp(&the_buffer[yb + xb], &the_buffer_copy[yb + xb], xs) != 0) { |
2039 |
+ |
memcpy(&the_buffer_copy[yb + xb], &the_buffer[yb + xb], xs); |
2040 |
+ |
Screen_blit((uint8 *)drv->s->pixels + yb + xb, the_buffer + yb + xb, xs); |
2041 |
+ |
dirty = true; |
2042 |
+ |
} |
2043 |
+ |
} |
2044 |
+ |
if (dirty) { |
2045 |
+ |
boxes[nr_boxes].x = x; |
2046 |
+ |
boxes[nr_boxes].y = y; |
2047 |
+ |
boxes[nr_boxes].w = w; |
2048 |
+ |
boxes[nr_boxes].h = h; |
2049 |
+ |
nr_boxes++; |
2050 |
+ |
} |
2051 |
+ |
} |
2052 |
+ |
} |
2053 |
+ |
|
2054 |
+ |
// Unlock surface, if required |
2055 |
+ |
if (SDL_MUSTLOCK(drv->s)) |
2056 |
+ |
SDL_UnlockSurface(drv->s); |
2057 |
+ |
|
2058 |
+ |
// Refresh display |
2059 |
+ |
if (nr_boxes) |
2060 |
+ |
SDL_UpdateRects(drv->s, nr_boxes, boxes); |
2061 |
+ |
} |
2062 |
+ |
|
2063 |
|
|
2064 |
|
// We suggest the compiler to inline the next two functions so that it |
2065 |
|
// may specialise the code according to the current screen depth and |
2154 |
|
static int tick_counter = 0; |
2155 |
|
if (++tick_counter >= frame_skip) { |
2156 |
|
tick_counter = 0; |
2157 |
< |
update_display_static(static_cast<driver_window *>(drv)); |
2157 |
> |
const VIDEO_MODE &mode = drv->mode; |
2158 |
> |
if ((int)VIDEO_MODE_DEPTH >= VIDEO_DEPTH_8BIT) |
2159 |
> |
update_display_static_bbox(static_cast<driver_window *>(drv)); |
2160 |
> |
else |
2161 |
> |
update_display_static(static_cast<driver_window *>(drv)); |
2162 |
|
} |
2163 |
|
} |
2164 |
|
|
2203 |
|
LOCK_EVENTS; |
2204 |
|
SDL_FreeCursor(sdl_cursor); |
2205 |
|
sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]); |
2206 |
< |
if (sdl_cursor) |
2206 |
> |
if (sdl_cursor) { |
2207 |
|
SDL_SetCursor(sdl_cursor); |
2208 |
+ |
#ifdef WIN32 |
2209 |
+ |
// XXX Windows apparently needs an extra mouse event to |
2210 |
+ |
// make the new cursor image visible |
2211 |
+ |
int visible = SDL_ShowCursor(-1); |
2212 |
+ |
if (visible) { |
2213 |
+ |
int x, y; |
2214 |
+ |
SDL_GetMouseState(&x, &y); |
2215 |
+ |
SDL_WarpMouse(x, y); |
2216 |
+ |
} |
2217 |
+ |
#endif |
2218 |
+ |
} |
2219 |
|
UNLOCK_EVENTS; |
2220 |
|
} |
2221 |
|
#endif |
2274 |
|
return 0; |
2275 |
|
} |
2276 |
|
#endif |
2277 |
+ |
|
2278 |
+ |
|
2279 |
+ |
/* |
2280 |
+ |
* Record dirty area from NQD |
2281 |
+ |
*/ |
2282 |
+ |
|
2283 |
+ |
#ifdef SHEEPSHAVER |
2284 |
+ |
void video_set_dirty_area(int x, int y, int w, int h) |
2285 |
+ |
{ |
2286 |
+ |
const VIDEO_MODE &mode = drv->mode; |
2287 |
+ |
const int screen_width = VIDEO_MODE_X; |
2288 |
+ |
const int screen_height = VIDEO_MODE_Y; |
2289 |
+ |
const int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
2290 |
+ |
|
2291 |
+ |
#ifdef ENABLE_VOSF |
2292 |
+ |
if (use_vosf) { |
2293 |
+ |
vosf_set_dirty_area(x, y, w, h, screen_width, screen_height, bytes_per_row); |
2294 |
+ |
return; |
2295 |
+ |
} |
2296 |
+ |
#endif |
2297 |
+ |
|
2298 |
+ |
// XXX handle dirty bounding boxes for non-VOSF modes |
2299 |
+ |
} |
2300 |
+ |
#endif |