DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
include/sdlmain.h
00001 #include "dosbox.h"
00002 
00003 #include "control.h"
00004 #include "menu.h"
00005 #include "mouse.h"
00006 #include "render.h"
00007 #include "video.h"
00008 
00009 #include "cross.h"
00010 #include "SDL.h"
00011 #include "SDL_video.h"
00012 
00013 #ifdef __WIN32__
00014 #include "SDL_syswm.h"
00015 #endif
00016 
00017 #ifndef DOSBOX_SDLMAIN_H
00018 #define DOSBOX_SDLMAIN_H
00019 
00020 enum SCREEN_TYPES {
00021     SCREEN_SURFACE
00022     ,SCREEN_OPENGL // [FIXME] cannot make this conditional because somehow SDL2 code uses it while C_OPENGL is definitely disabled by C_SDL2 so SCREEN_OPENGL is unavailable
00023 #if C_DIRECT3D
00024     ,SCREEN_DIRECT3D
00025 #endif
00026 };
00027 
00028 enum AUTOLOCK_FEEDBACK
00029 {
00030     AUTOLOCK_FEEDBACK_NONE,
00031     AUTOLOCK_FEEDBACK_BEEP,
00032     AUTOLOCK_FEEDBACK_FLASH
00033 };
00034 
00035 enum PRIORITY_LEVELS {
00036     PRIORITY_LEVEL_PAUSE,
00037     PRIORITY_LEVEL_LOWEST,
00038     PRIORITY_LEVEL_LOWER,
00039     PRIORITY_LEVEL_NORMAL,
00040     PRIORITY_LEVEL_HIGHER,
00041     PRIORITY_LEVEL_HIGHEST
00042 };
00043 
00044 enum method {
00045     METHOD_NONE = 0,
00046     METHOD_X11,
00047     METHOD_XRANDR,
00048     METHOD_WIN98BASE,
00049     METHOD_COREGRAPHICS
00050 };
00051 
00052 // Screen DPI and size info
00053 class ScreenSizeInfo {
00054 public:
00055     struct wxh {
00056         double      width = -1;
00057         double      height = -1;
00058 
00059         void clear(void) {
00060             width = height = -1;
00061         }
00062     };
00063     struct xvy {
00064         double      x = 0;
00065         double      y = 0;
00066 
00067         void clear(void) {
00068             x = y = 0;
00069         }
00070     };
00071 public:
00072     xvy             screen_position_pixels;     // position of the screen on the "virtual" overall desktop
00073     wxh             screen_dimensions_pixels;   // size of the screen in pixels
00074     wxh             screen_dimensions_mm;       // size of the screen in mm
00075     wxh             screen_dpi;                 // DPI of the screen
00076     enum method     method = METHOD_NONE;
00077 public:
00078     void clear(void) {
00079         screen_dpi.clear();
00080         screen_dimensions_mm.clear();
00081         screen_dimensions_pixels.clear();
00082         screen_position_pixels.clear();
00083         method = METHOD_NONE;
00084     }
00085 };
00086 
00087 extern ScreenSizeInfo       screen_size_info;
00088 
00089 struct SDL_Block {
00090     bool inited = false;
00091     bool active = false; // if this isn't set don't draw
00092     bool updating = false;
00093 #if defined(C_SDL2)
00094     bool update_window = false;
00095     bool update_display_contents = false;
00096     int window_desired_width = 0, window_desired_height = 0;
00097 #endif
00098     struct {
00099         Bit32u width = 0;
00100         Bit32u height = 0;
00101         Bit32u bpp = 0;
00102         Bitu flags = 0;
00103         double scalex = 0, scaley = 0;
00104         GFX_CallBack_t callback = 0;
00105     } draw;
00106     bool wait_on_error = false;
00107     struct {
00108         struct {
00109             Bit16u width = 0, height = 0;
00110             bool fixed = false;
00111             bool display_res = false;
00112             bool width_auto = false, height_auto = false;
00113         } full;
00114         struct {
00115             Bit16u width = 0, height = 0;
00116         } window;
00117         Bit8u bpp = 0;
00118 #if defined(C_SDL2)
00119         Bit32u pixelFormat = 0;
00120 #endif
00121         bool fullscreen = false;
00122         bool lazy_fullscreen = false;
00123         bool prevent_fullscreen = false;
00124         bool lazy_fullscreen_req = false;
00125         bool doublebuf = false;
00126         SCREEN_TYPES type = (SCREEN_TYPES)0;
00127         SCREEN_TYPES want_type = (SCREEN_TYPES)0;
00128     } desktop;
00129     struct {
00130         SDL_Surface * surface = NULL;
00131 #if (HAVE_DDRAW_H) && defined(WIN32)
00132         RECT rect = {};
00133 #endif
00134     } blit;
00135     struct {
00136         PRIORITY_LEVELS focus = (PRIORITY_LEVELS)0;
00137         PRIORITY_LEVELS nofocus = (PRIORITY_LEVELS)0;
00138     } priority;
00139     SDL_Rect clip = {};
00140     SDL_Surface * surface = NULL;
00141 #if defined(C_SDL2)
00142     SDL_Window * window = NULL;
00143     SDL_Renderer * renderer = NULL;
00144     const char * rendererDriver = NULL;
00145     int displayNumber = 0;
00146     struct {
00147         SDL_Texture * texture = NULL;
00148         SDL_PixelFormat * pixelFormat = NULL;
00149     } texture;
00150 #endif
00151     SDL_cond *cond = NULL;
00152     struct {
00153         bool autolock = false;
00154         AUTOLOCK_FEEDBACK autolock_feedback = (AUTOLOCK_FEEDBACK)0;
00155         bool autoenable = false;
00156         bool requestlock = false;
00157         bool locked = false;
00158         int xsensitivity = 0;
00159         int ysensitivity = 0;
00160         MOUSE_EMULATION emulation = (MOUSE_EMULATION)0;
00161     } mouse;
00162     SDL_Rect updateRects[1024] = {};
00163     Bitu overscan_color = 0;
00164     Bitu overscan_width = 0;
00165     Bitu num_joysticks = 0;
00166 #if defined (WIN32)
00167     bool using_windib = false;
00168     // Time when sdl regains focus (alt-tab) in windowed mode
00169     Bit32u focus_ticks = 0;
00170 #endif
00171     // state of alt-keys for certain special handlings
00172     Bit16u laltstate = 0, raltstate = 0;
00173     Bit16u lctrlstate = 0, rctrlstate = 0;
00174     Bit16u lshiftstate = 0, rshiftstate = 0;
00175     bool must_redraw_all = false;
00176     bool deferred_resize = false;
00177     bool init_ignore = false;
00178     unsigned int gfx_force_redraw_count = 0;
00179     struct {
00180         int x = 0;
00181         int y = 0;
00182         double xToY = 0;
00183         double yToX = 0;
00184     } srcAspect;
00185 #if C_SURFACE_POSTRENDER_ASPECT
00186     std::vector<uint32_t> aspectbuf = {};
00187 #endif
00188 };
00189 
00190 #if defined(WIN32) && !defined(C_SDL2)
00191 extern "C" unsigned int SDL1_hax_inhibit_WM_PAINT;
00192 #endif
00193 
00194 extern Bitu frames;
00195 extern SDL_Block sdl;
00196 
00197 #include <output/output_surface.h>
00198 #include <output/output_direct3d.h>
00199 #include <output/output_opengl.h>
00200 #include <output/output_tools.h>
00201 #include <output/output_tools_xbrz.h>
00202 
00203 #include "zipfile.h"
00204 
00205 extern Bitu userResizeWindowWidth;
00206 extern Bitu userResizeWindowHeight;
00207 extern Bitu currentWindowWidth;
00208 extern Bitu currentWindowHeight;
00209 
00210 void GFX_DrawSDLMenu(DOSBoxMenu &menu, DOSBoxMenu::displaylist &dl);
00211 void GFX_LogSDLState(void);
00212 void GFX_SDL_Overscan(void);
00213 void GFX_SetIcon(void);
00214 void SDL_rect_cliptoscreen(SDL_Rect &r);
00215 void UpdateWindowDimensions(void);
00216 void UpdateWindowDimensions(Bitu width, Bitu height);
00217 
00218 #if defined(C_SDL2)
00219 SDL_Window* GFX_SetSDLWindowMode(Bit16u width, Bit16u height, SCREEN_TYPES screenType);
00220 #endif
00221 
00222 #if defined(C_SDL2) && defined(C_OPENGL)/*HACK*/
00223 void SDL_GL_SwapBuffers(void);
00224 #endif
00225 
00226 #endif /*DOSBOX_SDLMAIN_H*/