void GAPI_VideoQuit(_THIS) { writeDebugInfo("GAPI_VideoQuit"); /* Destroy the window and everything associated with it */ if ( SDL_Window ) { /* Delete the screen bitmap (also frees screen->pixels) */ if ( this->screen ) { #ifdef HAVE_OPENGL //maks if ( this->screen->flags & SDL_OPENGL ) { WIN_GL_ShutDown(this); } #endif if ( this->screen->flags & SDL_FULLSCREEN ) { SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON); bShowTaskBar = 1; } #ifndef NO_CHANGEDISPLAYSETTINGS if ( this->screen->flags & SDL_FULLSCREEN ) { ChangeDisplaySettings(NULL, 0); ShowWindow(SDL_Window, SW_HIDE); } #endif this->screen->pixels = NULL; } GAPI_QuitGamma(this); GAPI_DestroyWindow(this); FlushMessageQueue(); SDL_Window = NULL; CloseGAPI(); } if(gxHandle) { FreeLibrary(gxHandle); gxHandle = NULL; } //Make sure restore task bar SHFullScreen(GetForegroundWindow(), SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON); }
void DIB_VideoQuit(_THIS) { /* Destroy the window and everything associated with it */ if ( SDL_Window ) { /* Delete the screen bitmap (also frees screen->pixels) */ if ( this->screen ) { #ifdef WIN32_PLATFORM_PSPC if ( this->screen->flags & SDL_FULLSCREEN ) { /* Unhide taskbar, etc. */ SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR); SHFullScreen(SDL_Window, SHFS_SHOWSIPBUTTON); ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL); } #endif #ifndef NO_CHANGEDISPLAYSETTINGS if ( this->screen->flags & SDL_FULLSCREEN ) { ChangeDisplaySettings(NULL, 0); ShowWindow(SDL_Window, SW_HIDE); } #endif #ifdef HAVE_OPENGL //maks if ( this->screen->flags & SDL_OPENGL ) { WIN_GL_ShutDown(this); } #endif this->screen->pixels = NULL; } if ( screen_bmp ) { DeleteObject(screen_bmp); screen_bmp = NULL; } if ( screen_icn ) { DestroyIcon(screen_icn); screen_icn = NULL; } DIB_QuitGamma(this); DIB_DestroyWindow(this); FlushMessageQueue(); SDL_Window = NULL; } }
SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { SDL_Surface *video; Uint32 prev_flags; DWORD style; const DWORD directstyle = (WS_POPUP); const DWORD windowstyle = (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX); const DWORD resizestyle = (WS_THICKFRAME|WS_MAXIMIZEBOX); int binfo_size; BITMAPINFO *binfo; HDC hdc; RECT bounds; int x, y; Uint32 Rmask, Gmask, Bmask; #ifdef HAVE_OPENGL //maks /* Clean up any GL context that may be hanging around */ if ( current->flags & SDL_OPENGL ) { //maks: close only in viewo quit to avoid texture lost when go to game mode WIN_GL_ShutDown(this); } #endif /* Recalculate the bitmasks if necessary */ if ( bpp == current->format->BitsPerPixel ) { video = current; } else { switch (bpp) { case 15: case 16: if ( DIB_SussScreenDepth() == 15 ) { /* 5-5-5 */ Rmask = 0x00007c00; Gmask = 0x000003e0; Bmask = 0x0000001f; } else { /* 5-6-5 */ Rmask = 0x0000f800; Gmask = 0x000007e0; Bmask = 0x0000001f; } break; case 24: case 32: /* GDI defined as 8-8-8 */ Rmask = 0x00ff0000; Gmask = 0x0000ff00; Bmask = 0x000000ff; break; default: Rmask = 0x00000000; Gmask = 0x00000000; Bmask = 0x00000000; break; } video = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, bpp, Rmask, Gmask, Bmask, 0); if ( video == NULL ) { SDL_OutOfMemory(); return(NULL); } } /* Fill in part of the video surface */ prev_flags = video->flags; video->flags = 0; /* Clear flags */ video->w = width; video->h = height; video->pitch = SDL_CalculatePitch(video); #ifdef WIN32_PLATFORM_PSPC /* Stuff to hide that $#!^%#$ WinCE taskbar in fullscreen... */ if ( flags & SDL_FULLSCREEN ) { if ( !(prev_flags & SDL_FULLSCREEN) ) { SHFullScreen(SDL_Window, SHFS_HIDETASKBAR); SHFullScreen(SDL_Window, SHFS_HIDESIPBUTTON); ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_HIDE); } video->flags |= SDL_FULLSCREEN; } else { if ( prev_flags & SDL_FULLSCREEN ) { SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR); SHFullScreen(SDL_Window, SHFS_SHOWSIPBUTTON); ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL); } } #endif #ifndef NO_CHANGEDISPLAYSETTINGS /* Set fullscreen mode if appropriate */ if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { DEVMODE settings; memset(&settings, 0, sizeof(DEVMODE)); settings.dmSize = sizeof(DEVMODE); settings.dmBitsPerPel = video->format->BitsPerPixel; settings.dmPelsWidth = width; settings.dmPelsHeight = height; settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; if ( ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL ) { video->flags |= SDL_FULLSCREEN; SDL_fullscreen_mode = settings; } } #endif /* !NO_CHANGEDISPLAYSETTINGS */ /* Reset the palette and create a new one if necessary */ if ( screen_pal != NULL ) { /* RJR: March 28, 2000 delete identity palette if switching from a palettized mode */ DeleteObject(screen_pal); screen_pal = NULL; } if ( bpp <= 8 ) { /* RJR: March 28, 2000 create identity palette switching to a palettized mode */ screen_pal = DIB_CreatePalette(bpp); } style = GetWindowLong(SDL_Window, GWL_STYLE); style &= ~(resizestyle|WS_MAXIMIZE); if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { style &= ~windowstyle; style |= directstyle; } else { #ifndef NO_CHANGEDISPLAYSETTINGS if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { ChangeDisplaySettings(NULL, 0); } #endif if ( flags & SDL_NOFRAME ) { style &= ~windowstyle; style |= directstyle; video->flags |= SDL_NOFRAME; } else { style &= ~directstyle; style |= windowstyle; if ( flags & SDL_RESIZABLE ) { style |= resizestyle; video->flags |= SDL_RESIZABLE; } } #if WS_MAXIMIZE if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; #endif } /* DJM: Don't piss of anyone who has setup his own window */ if ( SDL_windowid == NULL ) SetWindowLong(SDL_Window, GWL_STYLE, style); /* Delete the old bitmap if necessary */ if ( screen_bmp != NULL ) { DeleteObject(screen_bmp); } if ( ! (flags & SDL_OPENGL) ) { BOOL is16bitmode = (video->format->BytesPerPixel == 2); /* Suss out the bitmap info header */ binfo_size = sizeof(*binfo); if( is16bitmode ) { /* 16bit modes, palette area used for rgb bitmasks */ binfo_size += 3*sizeof(DWORD); } else if ( video->format->palette ) { binfo_size += video->format->palette->ncolors * sizeof(RGBQUAD); } binfo = (BITMAPINFO *)malloc(binfo_size); if ( ! binfo ) { if ( video != current ) { SDL_FreeSurface(video); } SDL_OutOfMemory(); return(NULL); } binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); binfo->bmiHeader.biWidth = video->w; binfo->bmiHeader.biHeight = -video->h; /* -ve for topdown bitmap */ binfo->bmiHeader.biPlanes = 1; binfo->bmiHeader.biSizeImage = video->h * video->pitch; binfo->bmiHeader.biXPelsPerMeter = 0; binfo->bmiHeader.biYPelsPerMeter = 0; binfo->bmiHeader.biClrUsed = 0; binfo->bmiHeader.biClrImportant = 0; binfo->bmiHeader.biBitCount = video->format->BitsPerPixel; if ( is16bitmode ) { /* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */ binfo->bmiHeader.biCompression = BI_BITFIELDS; ((Uint32*)binfo->bmiColors)[0] = video->format->Rmask; ((Uint32*)binfo->bmiColors)[1] = video->format->Gmask; ((Uint32*)binfo->bmiColors)[2] = video->format->Bmask; } else { binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */ if ( video->format->palette ) { memset(binfo->bmiColors, 0, video->format->palette->ncolors*sizeof(RGBQUAD)); } } /* Create the offscreen bitmap buffer */ hdc = GetDC(SDL_Window); screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS, (void **)(&video->pixels), NULL, 0); ReleaseDC(SDL_Window, hdc); free(binfo); if ( screen_bmp == NULL ) { if ( video != current ) { SDL_FreeSurface(video); } SDL_SetError("Couldn't create DIB section"); return(NULL); } this->UpdateRects = DIB_NormalUpdate; /* Set video surface flags */ if ( bpp <= 8 ) { /* BitBlt() maps colors for us */ video->flags |= SDL_HWPALETTE; } } /* Resize the window */ if ( SDL_windowid == NULL ) { HWND top; UINT swp_flags; const char *window = getenv("SDL_VIDEO_WINDOW_POS"); const char *center = getenv("SDL_VIDEO_CENTERED"); if ( !SDL_windowX && !SDL_windowY ) { if ( window ) { if ( sscanf(window, "%d,%d", &x, &y) == 2 ) { SDL_windowX = x; SDL_windowY = y; } if ( strcmp(window, "center") == 0 ) { center = window; window = NULL; } } } swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW); SDL_resizing = 1; bounds.left = SDL_windowX; bounds.top = SDL_windowY; bounds.right = SDL_windowX+video->w; bounds.bottom = SDL_windowY+video->h; AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0); width = bounds.right-bounds.left; height = bounds.bottom-bounds.top; if ( (flags & SDL_FULLSCREEN) ) { x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; } else if ( SDL_windowX || SDL_windowY || window ) { x = bounds.left; y = bounds.top; } else if ( center ) { x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; } else { x = y = -1; swp_flags |= SWP_NOMOVE; } if ( y < 0 ) { /* Cover up title bar for more client area */ y -= GetSystemMetrics(SM_CYCAPTION)/2; } if ( flags & SDL_FULLSCREEN ) { top = HWND_TOPMOST; } else { top = HWND_NOTOPMOST; } SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags); SDL_resizing = 0; SetForegroundWindow(SDL_Window); } #ifdef HAVE_OPENGL //maks /* Set up for OpenGL */ if ( flags & SDL_OPENGL ) { /*if ( WIN_GL_SetupWindow(this) < 0 ) { return(NULL); } video->flags |= SDL_OPENGL;*/ if ( WIN_GL_SetupWindow(this) >= 0 ) { video->flags |= SDL_OPENGL; } } #endif /* We're live! */ return(video); }
SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { SDL_Surface *video; Uint32 prev_flags; DWORD style; const DWORD directstyle = (WS_POPUP); const DWORD windowstyle = (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX); const DWORD resizestyle = (WS_THICKFRAME|WS_MAXIMIZEBOX); int x, y; BOOL was_visible; Uint32 Rmask, Gmask, Bmask; #ifdef HAVE_OPENGL //maks /* Clean up any GL context that may be hanging around */ if ( current->flags & SDL_OPENGL ) { //maks: close only in video quit to avoid texture lost when go to game mode WIN_GL_ShutDown(this); } #endif #ifdef _USE_POCKET_HAL_ halWidth = width; halHeight = height; //Don't use GAPI or PocketHAL with OpenGL //Hybrid will show a blank screen OpenGAPI(1); //Can open PocketHAL in Intel 2700G //Go to the game, monitor task bar HookTaskBar(); /*if( flags & SDL_FULLSCREEN ) { //maks: native resolution only //Causes "Error - not enough memory to execute the game" halGetDimensions(&width, &height); }*/ /* Recalculate the bitmasks if necessary */ if ( bpp == current->format->BitsPerPixel ) { video = current; } else { bpp = 16; /* 5-6-5 */ Rmask = 0x0000f800; Gmask = 0x000007e0; Bmask = 0x0000001f; video = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, bpp, Rmask, Gmask, Bmask, 0); if ( video == NULL ) { SDL_OutOfMemory(); return(NULL); } } #else int m_nXPitch, m_nYPitch; GXDisplayProperties m_dispProps = GXGetDisplayProperties(); m_nXPitch = m_dispProps.cbxPitch >> 1; m_nYPitch = m_dispProps.cbyPitch >> 1; if (m_nXPitch < 0) { this->hidden->m_nBufferStartOffset = m_nXPitch * (m_dispProps.cxWidth - 1); } else { this->hidden->m_nBufferEndOffset = m_nXPitch * (m_dispProps.cxWidth - 1); } if (m_nYPitch < 0) { this->hidden->m_nBufferStartOffset += m_nYPitch * (m_dispProps.cyHeight - 1); } else { this->hidden->m_nBufferEndOffset += m_nYPitch * (m_dispProps.cyHeight - 1); } /* Recalculate the bitmasks if necessary */ if ( bpp == current->format->BitsPerPixel ) { video = current; } else { bpp = m_dispProps.cBPP; if(m_dispProps.ffFormat | kfDirect565) { /* 5-6-5 */ Rmask = 0x0000f800; Gmask = 0x000007e0; Bmask = 0x0000001f; } else if(m_dispProps.ffFormat | kfDirect555) { /* 5-5-5 */ Rmask = 0x00007c00; Gmask = 0x000003e0; Bmask = 0x0000001f; } else if(m_dispProps.ffFormat | kfDirect888) { /* 8-8-8 */ Rmask = 0x00ff0000; Gmask = 0x0000ff00; Bmask = 0x000000ff; } video = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, bpp, Rmask, Gmask, Bmask, 0); if ( video == NULL ) { SDL_OutOfMemory(); return(NULL); } } if( flags & SDL_FULLSCREEN ) { //maks: native resolution only width = m_dispProps.cxWidth; height = m_dispProps.cyHeight; } #endif //_USE_POCKET_HAL_ /* See whether or not we should center the window */ was_visible = IsWindowVisible(SDL_Window); /* Fill in part of the video surface */ prev_flags = video->flags; video->flags = 0; /* Clear flags */ video->w = width; video->h = height; video->pitch = SDL_CalculatePitch(video); /* Stuff to hide that $#!^%#$ WinCE taskbar in fullscreen... */ if ( flags & SDL_FULLSCREEN ) { if ( !(prev_flags & SDL_FULLSCREEN) ) { SHFullScreen(SDL_Window, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON); bShowTaskBar = 0; } video->flags |= SDL_FULLSCREEN; } else { if ( prev_flags & SDL_FULLSCREEN ) { SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON); bShowTaskBar = 1; } } #ifndef NO_CHANGEDISPLAYSETTINGS /* Set fullscreen mode if appropriate */ if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { DEVMODE settings; memset(&settings, 0, sizeof(DEVMODE)); settings.dmSize = sizeof(DEVMODE); settings.dmBitsPerPel = video->format->BitsPerPixel; settings.dmPelsWidth = width; settings.dmPelsHeight = height; settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; if ( ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL ) { video->flags |= SDL_FULLSCREEN; SDL_fullscreen_mode = settings; } } #endif /* !NO_CHANGEDISPLAYSETTINGS */ style = GetWindowLong(SDL_Window, GWL_STYLE); style &= ~(resizestyle|WS_MAXIMIZE); if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { style &= ~windowstyle; style |= directstyle; } else { #ifndef NO_CHANGEDISPLAYSETTINGS if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { ChangeDisplaySettings(NULL, 0); } #endif if ( flags & SDL_NOFRAME ) { style &= ~windowstyle; style |= directstyle; video->flags |= SDL_NOFRAME; } else { style &= ~directstyle; style |= windowstyle; if ( flags & SDL_RESIZABLE ) { style |= resizestyle; video->flags |= SDL_RESIZABLE; } } #if WS_MAXIMIZE if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; #endif } /* DJM: Don't piss of anyone who has setup his own window */ if (!SDL_windowid) SetWindowLong(SDL_Window, GWL_STYLE, style); /* Resize the window */ if ( SDL_windowid == NULL ) { HWND top; UINT swp_flags; //RECT bounds; //Aways full screen, don't need calculate the bounds int realW = width, realH = height, screenW, screenH; GetPokcetPCScreenDimensions(&screenW, &screenH); if(width > height && screenW < screenH) { //Rotate realW = height; realH = width; } SDL_resizing = 1; /*bounds.left = 0; bounds.top = 0; bounds.right = realW; bounds.bottom = realH; AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0); //If need to use, consider the system screen rotation realW = bounds.right-bounds.left; realH = bounds.bottom-bounds.top;*/ x = (screenW-realW)/2; y = (screenH-realH)/2; //if(x < 0 || y < 0) //maks: to avoid crash when run a 480x640 game in a 240x320 device if((realW != screenW && 2*realW != screenW) || (realH != screenH && 2*realH != screenH)) { //maks: Avoid a game running in a different system resolution, //but can 240x320 in a 480x640 device CloseGAPI(); return NULL; } if ( y < 0 ) { /* Cover up title bar for more client area */ y -= GetSystemMetrics(SM_CYCAPTION)/2; } swp_flags = (SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_SHOWWINDOW); if ( was_visible && !(flags & SDL_FULLSCREEN) ) { swp_flags |= SWP_NOMOVE; } if ( flags & SDL_FULLSCREEN ) { top = HWND_TOPMOST; } else { top = HWND_NOTOPMOST; } sdlWindowSize.left = x; sdlWindowSize.top = y; sdlWindowSize.right = realW; sdlWindowSize.bottom = realH; SetWindowPos(SDL_Window, top, x, y, realW, realH, swp_flags); SDL_resizing = 0; SetForegroundWindow(SDL_Window); } /* If not fullscreen, locking is possible, but it doesn't do what the caller really expects -- if the locked surface is written to, the appropriate portion of the entire screen is modified, not the application window, as we would like. Note that it is still possible to write directly to display memory, but the application must respect the clip list of the surface. There might be some odd timing interactions involving clip list updates and background refreshing as Windows moves other windows across our window. We currently don't support this, even though it might be a good idea since BeOS has an implementation of BDirectWindow that does the same thing. This would be most useful for applications that do complete screen updates every frame. -- Fixme? */ if ( (flags & SDL_FULLSCREEN) != SDL_FULLSCREEN ) { /* Necessary if we're going from fullscreen to window */ #if 0 if ( video->pixels == NULL ) { video->pitch = (width*video->format->BytesPerPixel); /* Pitch needs to be QWORD (8-byte) aligned */ video->pitch = (video->pitch + 7) & ~7; video->pixels = (void *)malloc(video->h*video->pitch); if ( video->pixels == NULL ) { if ( video != current ) { SDL_FreeSurface(video); } SDL_OutOfMemory(); return(NULL); } } #endif //#if 0 /* FIXME: enable this when SDL consistently reports lost surfaces */ if ( (flags & SDL_HWSURFACE) == SDL_HWSURFACE ) { video->flags |= SDL_HWSURFACE; } else { video->flags |= SDL_SWSURFACE; } /*#else video->flags |= SDL_SWSURFACE; #endif*/ if ( (flags & SDL_RESIZABLE) && !(flags & SDL_NOFRAME) ) { video->flags |= SDL_RESIZABLE; } if ( flags & SDL_NOFRAME ) { video->flags |= SDL_NOFRAME; } } else { /* Necessary if we're going from window to fullscreen */ if ( video->pixels != NULL ) { free(video->pixels); video->pixels = NULL; } video->flags |= SDL_HWSURFACE; } #ifndef _USE_POCKET_HAL_ backBuferSize = (this->hidden->m_nBufferEndOffset - this->hidden->m_nBufferStartOffset + 1)*2; if(!OpenGAPI((video->flags & SDL_FULLSCREEN)?1:0)) { if ( video != current ) { SDL_FreeSurface(video); } SDL_SetError("Couldn't open GAPI"); return NULL; } //Go to the game, monitor task bar HookTaskBar(); #endif //_USE_POCKET_HAL_ #ifdef HAVE_OPENGL /* Set up for OpenGL */ if ( flags & SDL_OPENGL ) { if ( WIN_GL_SetupWindow(this) >= 0 ) { video->flags |= SDL_OPENGL; } } #endif /* We're live! */ videoSurface = video; return(video); }
SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { SDL_Surface *video; int prev_w, prev_h; Uint32 prev_flags; DWORD style; const DWORD directstyle = (WS_POPUP); const DWORD windowstyle = (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX); const DWORD resizestyle = (WS_THICKFRAME|WS_MAXIMIZEBOX); int binfo_size; BITMAPINFO *binfo; HDC hdc; RECT bounds; int x, y; Uint32 Rmask, Gmask, Bmask; /* Clean up any GL context that may be hanging around */ if ( current->flags & SDL_OPENGL ) { WIN_GL_ShutDown(this); } SDL_resizing = 1; /* Recalculate the bitmasks if necessary */ if ( bpp == current->format->BitsPerPixel ) { video = current; } else { switch (bpp) { case 15: case 16: if ( DIB_SussScreenDepth() == 15 ) { /* 5-5-5 */ Rmask = 0x00007c00; Gmask = 0x000003e0; Bmask = 0x0000001f; } else { /* 5-6-5 */ Rmask = 0x0000f800; Gmask = 0x000007e0; Bmask = 0x0000001f; } break; case 24: case 32: /* GDI defined as 8-8-8 */ Rmask = 0x00ff0000; Gmask = 0x0000ff00; Bmask = 0x000000ff; break; default: Rmask = 0x00000000; Gmask = 0x00000000; Bmask = 0x00000000; break; } video = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, bpp, Rmask, Gmask, Bmask, 0); if ( video == NULL ) { SDL_OutOfMemory(); return(NULL); } } /* Fill in part of the video surface */ prev_flags = video->flags; prev_w = video->w; prev_h = video->h; video->flags = 0; /* Clear flags */ video->w = width; video->h = height; video->pitch = SDL_CalculatePitch(video); /* Small fix for WinCE/Win32 - when activating window SDL_VideoSurface is equal to zero, so activating code is not called properly for fullscreen windows because macros WINDIB_FULLSCREEN uses SDL_VideoSurface */ SDL_VideoSurface = video; #if defined(_WIN32_WCE) if ( flags & SDL_FULLSCREEN ) video->flags |= SDL_FULLSCREEN; #endif #ifndef NO_CHANGEDISPLAYSETTINGS /* Set fullscreen mode if appropriate */ if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { DEVMODE settings; BOOL changed; SDL_memset(&settings, 0, sizeof(DEVMODE)); settings.dmSize = sizeof(DEVMODE); #ifdef _WIN32_WCE // try to rotate screen to fit requested resolution if( this->hidden->supportRotation ) { DWORD rotation; // ask current mode settings.dmFields = DM_DISPLAYORIENTATION; ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL); rotation = settings.dmDisplayOrientation; if( (width > GetDeviceCaps(GetDC(NULL), HORZRES)) && (height < GetDeviceCaps(GetDC(NULL), VERTRES))) { switch( rotation ) { case DMDO_0: settings.dmDisplayOrientation = DMDO_90; break; case DMDO_270: settings.dmDisplayOrientation = DMDO_180; break; } if( settings.dmDisplayOrientation != rotation ) { // go to landscape this->hidden->origRotation = rotation; ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL); } } if( (width < GetDeviceCaps(GetDC(NULL), HORZRES)) && (height > GetDeviceCaps(GetDC(NULL), VERTRES))) { switch( rotation ) { case DMDO_90: settings.dmDisplayOrientation = DMDO_0; break; case DMDO_180: settings.dmDisplayOrientation = DMDO_270; break; } if( settings.dmDisplayOrientation != rotation ) { // go to portrait this->hidden->origRotation = rotation; ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL); } } } #endif #ifndef _WIN32_WCE settings.dmBitsPerPel = video->format->BitsPerPixel; settings.dmPelsWidth = width; settings.dmPelsHeight = height; settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; if ( width <= (int)SDL_desktop_mode.dmPelsWidth && height <= (int)SDL_desktop_mode.dmPelsHeight ) { settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency; settings.dmFields |= DM_DISPLAYFREQUENCY; } changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); if ( ! changed && (settings.dmFields & DM_DISPLAYFREQUENCY) ) { settings.dmFields &= ~DM_DISPLAYFREQUENCY; changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); } #else changed = 1; #endif if ( changed ) { video->flags |= SDL_FULLSCREEN; SDL_fullscreen_mode = settings; } } #endif /* !NO_CHANGEDISPLAYSETTINGS */ /* Reset the palette and create a new one if necessary */ if ( grab_palette ) { DIB_ReleaseStaticColors(SDL_Window); grab_palette = FALSE; } if ( screen_pal != NULL ) { /* RJR: March 28, 2000 delete identity palette if switching from a palettized mode */ DeleteObject(screen_pal); screen_pal = NULL; } if ( screen_logpal != NULL ) { SDL_free(screen_logpal); screen_logpal = NULL; } if ( bpp <= 8 ) { /* RJR: March 28, 2000 create identity palette switching to a palettized mode */ DIB_CreatePalette(this, bpp); } style = GetWindowLong(SDL_Window, GWL_STYLE); style &= ~(resizestyle|WS_MAXIMIZE); if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { style &= ~windowstyle; style |= directstyle; } else { #ifndef NO_CHANGEDISPLAYSETTINGS if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { ChangeDisplaySettings(NULL, 0); } #endif if ( flags & SDL_NOFRAME ) { style &= ~windowstyle; style |= directstyle; video->flags |= SDL_NOFRAME; } else { style &= ~directstyle; style |= windowstyle; if ( flags & SDL_RESIZABLE ) { style |= resizestyle; video->flags |= SDL_RESIZABLE; } } #if WS_MAXIMIZE if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; #endif } /* DJM: Don't piss of anyone who has setup his own window */ if ( !SDL_windowid ) SetWindowLong(SDL_Window, GWL_STYLE, style); /* Delete the old bitmap if necessary */ if ( screen_bmp != NULL ) { DeleteObject(screen_bmp); } if ( ! (flags & SDL_OPENGL) ) { BOOL is16bitmode = (video->format->BytesPerPixel == 2); /* Suss out the bitmap info header */ binfo_size = sizeof(*binfo); if( is16bitmode ) { /* 16bit modes, palette area used for rgb bitmasks */ binfo_size += 3*sizeof(DWORD); } else if ( video->format->palette ) { binfo_size += video->format->palette->ncolors * sizeof(RGBQUAD); } binfo = (BITMAPINFO *)SDL_malloc(binfo_size); if ( ! binfo ) { if ( video != current ) { SDL_FreeSurface(video); } SDL_OutOfMemory(); return(NULL); } binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); binfo->bmiHeader.biWidth = video->w; binfo->bmiHeader.biHeight = -video->h; /* -ve for topdown bitmap */ binfo->bmiHeader.biPlanes = 1; binfo->bmiHeader.biSizeImage = video->h * video->pitch; binfo->bmiHeader.biXPelsPerMeter = 0; binfo->bmiHeader.biYPelsPerMeter = 0; binfo->bmiHeader.biClrUsed = 0; binfo->bmiHeader.biClrImportant = 0; binfo->bmiHeader.biBitCount = video->format->BitsPerPixel; if ( is16bitmode ) { /* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */ binfo->bmiHeader.biCompression = BI_BITFIELDS; ((Uint32*)binfo->bmiColors)[0] = video->format->Rmask; ((Uint32*)binfo->bmiColors)[1] = video->format->Gmask; ((Uint32*)binfo->bmiColors)[2] = video->format->Bmask; } else { binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */ if ( video->format->palette ) { SDL_memset(binfo->bmiColors, 0, video->format->palette->ncolors*sizeof(RGBQUAD)); } } /* Create the offscreen bitmap buffer */ hdc = GetDC(SDL_Window); screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS, (void **)(&video->pixels), NULL, 0); ReleaseDC(SDL_Window, hdc); SDL_free(binfo); if ( screen_bmp == NULL ) { if ( video != current ) { SDL_FreeSurface(video); } SDL_SetError("Couldn't create DIB section"); return(NULL); } this->UpdateRects = DIB_NormalUpdate; /* Set video surface flags */ if ( screen_pal && (flags & (SDL_FULLSCREEN|SDL_HWPALETTE)) ) { grab_palette = TRUE; } /* BitBlt() maps colors for us */ video->flags |= SDL_HWPALETTE; } #ifndef _WIN32_WCE /* Resize the window */ if ( !SDL_windowid && !IsZoomed(SDL_Window) ) { #else if ( !SDL_windowid ) { #endif HWND top; UINT swp_flags; const char *window = NULL; const char *center = NULL; if ( video->w != prev_w || video->h != prev_h ) { window = SDL_getenv("SDL_VIDEO_WINDOW_POS"); center = SDL_getenv("SDL_VIDEO_CENTERED"); if ( window ) { if ( SDL_sscanf(window, "%d,%d", &x, &y) == 2 ) { SDL_windowX = x; SDL_windowY = y; } if ( SDL_strcmp(window, "center") == 0 ) { center = window; } } } swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW); bounds.left = SDL_windowX; bounds.top = SDL_windowY; bounds.right = SDL_windowX+video->w; bounds.bottom = SDL_windowY+video->h; #ifndef _WIN32_WCE AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), (GetMenu(SDL_Window) != NULL), 0); #else // The bMenu parameter must be FALSE; menu bars are not supported AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), 0, 0); #endif width = bounds.right-bounds.left; height = bounds.bottom-bounds.top; if ( (flags & SDL_FULLSCREEN) ) { x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; } else if ( center ) { x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; } else if ( SDL_windowX || SDL_windowY || window ) { x = bounds.left; y = bounds.top; } else { x = y = -1; swp_flags |= SWP_NOMOVE; } if ( flags & SDL_FULLSCREEN ) { top = HWND_TOPMOST; } else { top = HWND_NOTOPMOST; } SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags); if ( !(flags & SDL_FULLSCREEN) ) { SDL_windowX = SDL_bounds.left; SDL_windowY = SDL_bounds.top; } SetForegroundWindow(SDL_Window); } SDL_resizing = 0; /* Set up for OpenGL */ if ( flags & SDL_OPENGL ) { if ( WIN_GL_SetupWindow(this) < 0 ) { return(NULL); } video->flags |= SDL_OPENGL; } /* JC 14 Mar 2006 Flush the message loop or this can cause big problems later Especially if the user decides to use dialog boxes or assert()! */ WIN_FlushMessageQueue(); /* We're live! */ return(video); } /* We don't actually allow hardware surfaces in the DIB driver */ static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface) { return(-1); } static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface) { return; } static int DIB_LockHWSurface(_THIS, SDL_Surface *surface) { return(0); } static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface) { return; } static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) { HDC hdc, mdc; int i; hdc = GetDC(SDL_Window); if ( screen_pal ) { SelectPalette(hdc, screen_pal, FALSE); } mdc = CreateCompatibleDC(hdc); SelectObject(mdc, screen_bmp); for ( i=0; i<numrects; ++i ) { BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h, mdc, rects[i].x, rects[i].y, SRCCOPY); } DeleteDC(mdc); ReleaseDC(SDL_Window, hdc); }
void DIB_VideoQuit(_THIS) { int i, j; /* Destroy the window and everything associated with it */ if ( SDL_Window ) { /* Delete the screen bitmap (also frees screen->pixels) */ if ( this->screen ) { if ( grab_palette ) { DIB_ReleaseStaticColors(SDL_Window); } #ifndef NO_CHANGEDISPLAYSETTINGS if ( this->screen->flags & SDL_FULLSCREEN ) { ChangeDisplaySettings(NULL, 0); ShowWindow(SDL_Window, SW_HIDE); } #endif if ( this->screen->flags & SDL_OPENGL ) { WIN_GL_ShutDown(this); } this->screen->pixels = NULL; } if ( screen_pal != NULL ) { DeleteObject(screen_pal); screen_pal = NULL; } if ( screen_logpal != NULL ) { SDL_free(screen_logpal); screen_logpal = NULL; } if ( screen_bmp ) { DeleteObject(screen_bmp); screen_bmp = NULL; } if ( screen_icn ) { DestroyIcon(screen_icn); screen_icn = NULL; } DIB_QuitGamma(this); DIB_DestroyWindow(this); SDL_Window = NULL; #if defined(_WIN32_WCE) // Unload wince aygshell library to prevent leak if( aygshell ) { FreeLibrary(aygshell); aygshell = NULL; } #endif } for ( i=0; i < SDL_arraysize(SDL_modelist); ++i ) { if ( !SDL_modelist[i] ) { continue; } for ( j=0; SDL_modelist[i][j]; ++j ) { SDL_free(SDL_modelist[i][j]); } SDL_free(SDL_modelist[i]); SDL_modelist[i] = NULL; SDL_nummodes[i] = 0; } }