DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/output/output_surface_sdl2.cpp
00001 #include <sys/types.h>
00002 #include <assert.h>
00003 #include <math.h>
00004 
00005 #include "dosbox.h"
00006 #include "sdlmain.h"
00007 #include "vga.h"
00008 
00009 #include <algorithm> // std::transform
00010 
00011 using namespace std;
00012 
00013 #if defined(C_SDL2)
00014 Bitu OUTPUT_SURFACE_SetSize()
00015 {
00016     Bitu bpp = 0;
00017     Bitu retFlags = 0;
00018     (void)bpp;
00019 
00020 retry:
00021     sdl.clip.w = sdl.draw.width;
00022     sdl.clip.h = sdl.draw.height;
00023     if (GFX_IsFullscreen()) {
00024         if (sdl.desktop.full.fixed) {
00025             sdl.clip.x = (Sint16)((sdl.desktop.full.width - sdl.draw.width) / 2);
00026             sdl.clip.y = (Sint16)((sdl.desktop.full.height - sdl.draw.height) / 2);
00027             sdl.window = GFX_SetSDLWindowMode(sdl.desktop.full.width, sdl.desktop.full.height, SCREEN_SURFACE);
00028             if (sdl.window == NULL)
00029                 E_Exit("Could not set fullscreen video mode %ix%i-%i: %s", sdl.desktop.full.width, sdl.desktop.full.height, sdl.desktop.bpp, SDL_GetError());
00030         }
00031         else {
00032             sdl.clip.x = 0;
00033             sdl.clip.y = 0;
00034             sdl.window = GFX_SetSDLWindowMode(sdl.draw.width, sdl.draw.height, SCREEN_SURFACE);
00035             if (sdl.window == NULL)
00036                 LOG_MSG("Fullscreen not supported: %s", SDL_GetError());
00037             SDL_SetWindowFullscreen(sdl.window, 0);
00038             GFX_CaptureMouse();
00039             goto retry;
00040         }
00041     }
00042     else {
00043         int menuheight = 0;
00044 #if DOSBOXMENU_TYPE == DOSBOXMENU_SDLDRAW
00045         if (mainMenu.isVisible()) menuheight = mainMenu.menuBox.h;
00046 #endif
00047 
00048         sdl.clip.x = sdl.overscan_width;
00049         sdl.clip.y = sdl.overscan_width + menuheight;
00050         sdl.window = GFX_SetSDLWindowMode(sdl.draw.width + 2 * sdl.overscan_width, sdl.draw.height + menuheight + 2 * sdl.overscan_width, SCREEN_SURFACE);
00051         if (sdl.window == NULL)
00052             E_Exit("Could not set windowed video mode %ix%i: %s", (int)sdl.draw.width, (int)sdl.draw.height, SDL_GetError());
00053     }
00054     sdl.surface = SDL_GetWindowSurface(sdl.window);
00055     if (sdl.surface == NULL)
00056         E_Exit("Could not retrieve window surface: %s", SDL_GetError());
00057     switch (sdl.surface->format->BitsPerPixel) {
00058     case 8:
00059         retFlags = GFX_CAN_8;
00060         break;
00061     case 15:
00062         retFlags = GFX_CAN_15;
00063         break;
00064     case 16:
00065         retFlags = GFX_CAN_16;
00066         break;
00067     case 32:
00068         retFlags = GFX_CAN_32;
00069         break;
00070     }
00071 
00072     sdl.deferred_resize = false;
00073     sdl.must_redraw_all = true;
00074 
00075     /* Fix a glitch with aspect=true occuring when
00076     changing between modes with different dimensions */
00077     SDL_FillRect(sdl.surface, NULL, SDL_MapRGB(sdl.surface->format, 0, 0, 0));
00078 #if DOSBOXMENU_TYPE == DOSBOXMENU_SDLDRAW
00079     mainMenu.screenWidth = sdl.surface->w;
00080     mainMenu.updateRect();
00081     mainMenu.setRedraw();
00082     GFX_DrawSDLMenu(mainMenu, mainMenu.display_list);
00083 #endif
00084 
00085     return retFlags;
00086 }
00087 #endif /*defined(C_SDL2)*/