1 |
|
/* |
2 |
|
* video_sdl.cpp - Video/graphics emulation, SDL specific stuff |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2005 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2008 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 |
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 |
|
*/ |
136 |
|
static volatile bool cursor_changed = false; // Flag: cursor changed, redraw_func must update the cursor |
137 |
|
static SDL_Color sdl_palette[256]; // Color palette to be used as CLUT and gamma table |
138 |
|
static bool sdl_palette_changed = false; // Flag: Palette changed, redraw thread must set new colors |
139 |
< |
static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK; |
139 |
> |
static const int sdl_eventmask = SDL_MOUSEEVENTMASK | SDL_KEYEVENTMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK | SDL_ACTIVEEVENTMASK; |
140 |
|
|
141 |
|
// Mutex to protect SDL events |
142 |
|
static SDL_mutex *sdl_events_lock = NULL; |
197 |
|
|
198 |
|
static void *vm_acquire_framebuffer(uint32 size) |
199 |
|
{ |
200 |
< |
return vm_acquire(size); |
200 |
> |
// always try to reallocate framebuffer at the same address |
201 |
> |
static void *fb = VM_MAP_FAILED; |
202 |
> |
if (fb != VM_MAP_FAILED) { |
203 |
> |
if (vm_acquire_fixed(fb, size) < 0) { |
204 |
> |
#ifndef SHEEPSHAVER |
205 |
> |
printf("FATAL: Could not reallocate framebuffer at previous address\n"); |
206 |
> |
#endif |
207 |
> |
fb = VM_MAP_FAILED; |
208 |
> |
} |
209 |
> |
} |
210 |
> |
if (fb == VM_MAP_FAILED) |
211 |
> |
fb = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT); |
212 |
> |
return fb; |
213 |
|
} |
214 |
|
|
215 |
|
static inline void vm_release_framebuffer(void *fb, uint32 size) |
731 |
|
* Windowed display driver |
732 |
|
*/ |
733 |
|
|
734 |
+ |
static bool SDL_display_opened = false; |
735 |
+ |
|
736 |
|
// Open display |
737 |
|
driver_window::driver_window(SDL_monitor_desc &m) |
738 |
|
: driver_base(m), mouse_grabbed(false) |
744 |
|
// Set absolute mouse mode |
745 |
|
ADBSetRelMouseMode(mouse_grabbed); |
746 |
|
|
747 |
+ |
// This is ugly: |
748 |
+ |
// If we're switching resolutions (ie, not setting it for the first time), |
749 |
+ |
// there's a bug in SDL where the SDL_Surface created will not be properly |
750 |
+ |
// setup. The solution is to SDL_QuitSubSystem(SDL_INIT_VIDEO) before calling |
751 |
+ |
// SDL_SetVideoMode for the second time (SDL_SetVideoMode will call SDL_Init() |
752 |
+ |
// and all will be well). Without this, the video becomes corrupted (at least |
753 |
+ |
// on Mac OS X), after the resolution switch. |
754 |
+ |
if (SDL_display_opened) |
755 |
+ |
SDL_QuitSubSystem(SDL_INIT_VIDEO); |
756 |
+ |
|
757 |
|
// Create surface |
758 |
|
int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH); |
759 |
|
if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL) |
760 |
|
return; |
761 |
|
|
762 |
+ |
SDL_display_opened = true; |
763 |
+ |
|
764 |
|
#ifdef ENABLE_VOSF |
765 |
|
use_vosf = true; |
766 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
1858 |
|
ADBKeyDown(0x7f); // Power key |
1859 |
|
ADBKeyUp(0x7f); |
1860 |
|
break; |
1861 |
+ |
|
1862 |
+ |
// Application activate/deactivate; consume the event but otherwise ignore it |
1863 |
+ |
case SDL_ACTIVEEVENT: |
1864 |
+ |
break; |
1865 |
|
} |
1866 |
|
} |
1867 |
|
} |
2219 |
|
LOCK_EVENTS; |
2220 |
|
SDL_FreeCursor(sdl_cursor); |
2221 |
|
sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]); |
2222 |
< |
if (sdl_cursor) |
2222 |
> |
if (sdl_cursor) { |
2223 |
|
SDL_SetCursor(sdl_cursor); |
2224 |
+ |
#ifdef WIN32 |
2225 |
+ |
// XXX Windows apparently needs an extra mouse event to |
2226 |
+ |
// make the new cursor image visible |
2227 |
+ |
int visible = SDL_ShowCursor(-1); |
2228 |
+ |
if (visible) { |
2229 |
+ |
int x, y; |
2230 |
+ |
SDL_GetMouseState(&x, &y); |
2231 |
+ |
SDL_WarpMouse(x, y); |
2232 |
+ |
} |
2233 |
+ |
#endif |
2234 |
+ |
} |
2235 |
|
UNLOCK_EVENTS; |
2236 |
|
} |
2237 |
|
#endif |