comparison src/video/windx5/SDL_dx5video.c @ 1330:450721ad5436

It's now possible to build SDL without any C runtime at all on Windows, using Visual C++ 2005
author Sam Lantinga <slouken@libsdl.org>
date Mon, 06 Feb 2006 08:28:51 +0000
parents c9b51268668f
children 3692456e7b0f
comparison
equal deleted inserted replaced
1329:bc67bbf87818 1330:450721ad5436
18 18
19 Sam Lantinga 19 Sam Lantinga
20 slouken@libsdl.org 20 slouken@libsdl.org
21 */ 21 */
22 22
23 #include <stdio.h> 23 #include "SDL_windows.h"
24 #include <stdlib.h>
25 #include <malloc.h>
26 #include <windows.h>
27 #include "directx.h" 24 #include "directx.h"
28 25
29 /* Not yet in the mingw32 cross-compile headers */ 26 /* Not yet in the mingw32 cross-compile headers */
30 #ifndef CDS_FULLSCREEN 27 #ifndef CDS_FULLSCREEN
31 #define CDS_FULLSCREEN 4 28 #define CDS_FULLSCREEN 4
33 30
34 #include "SDL_error.h" 31 #include "SDL_error.h"
35 #include "SDL_timer.h" 32 #include "SDL_timer.h"
36 #include "SDL_events.h" 33 #include "SDL_events.h"
37 #include "SDL_syswm.h" 34 #include "SDL_syswm.h"
35 #include "SDL_stdlib.h"
36 #include "SDL_string.h"
38 #include "SDL_sysvideo.h" 37 #include "SDL_sysvideo.h"
39 #include "SDL_blit.h" 38 #include "SDL_blit.h"
40 #include "SDL_pixels_c.h" 39 #include "SDL_pixels_c.h"
41 #include "SDL_dx5video.h" 40 #include "SDL_dx5video.h"
42 #include "SDL_syswm_c.h" 41 #include "SDL_syswm_c.h"
808 break; 807 break;
809 case E_NOINTERFACE: 808 case E_NOINTERFACE:
810 error = "Interface not present"; 809 error = "Interface not present";
811 break; 810 break;
812 default: 811 default:
813 sprintf(errbuf, "%s: Unknown DirectDraw error: 0x%x", 812 snprintf(errbuf, SDL_arraysize(errbuf),
813 "%s: Unknown DirectDraw error: 0x%x",
814 function, code); 814 function, code);
815 break; 815 break;
816 } 816 }
817 if ( ! errbuf[0] ) { 817 if ( ! errbuf[0] ) {
818 sprintf(errbuf, "%s: %s", function, error); 818 snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
819 } 819 }
820 SDL_SetError("%s", errbuf); 820 SDL_SetError("%s", errbuf);
821 return; 821 return;
822 } 822 }
823 823
1107 settings.dmSize = sizeof(DEVMODE); 1107 settings.dmSize = sizeof(DEVMODE);
1108 settings.dmBitsPerPel = video->format->BitsPerPixel; 1108 settings.dmBitsPerPel = video->format->BitsPerPixel;
1109 settings.dmPelsWidth = width; 1109 settings.dmPelsWidth = width;
1110 settings.dmPelsHeight = height; 1110 settings.dmPelsHeight = height;
1111 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; 1111 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
1112 if ( width <= SDL_desktop_mode.dmPelsWidth && height <= SDL_desktop_mode.dmPelsHeight ) { 1112 if ( width <= (int)SDL_desktop_mode.dmPelsWidth &&
1113 height <= (int)SDL_desktop_mode.dmPelsHeight ) {
1113 settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency; 1114 settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency;
1114 settings.dmFields |= DM_DISPLAYFREQUENCY; 1115 settings.dmFields |= DM_DISPLAYFREQUENCY;
1115 } 1116 }
1116 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); 1117 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL);
1117 if ( ! changed && (settings.dmFields & DM_DISPLAYFREQUENCY) ) { 1118 if ( ! changed && (settings.dmFields & DM_DISPLAYFREQUENCY) ) {
2168 SDL_colors[j].peGreen = colors[i].g; 2169 SDL_colors[j].peGreen = colors[i].g;
2169 SDL_colors[j].peBlue = colors[i].b; 2170 SDL_colors[j].peBlue = colors[i].b;
2170 } 2171 }
2171 #else 2172 #else
2172 /* Allocate memory for the arrays we use */ 2173 /* Allocate memory for the arrays we use */
2173 pool = (int *)alloca(2*ncolors*sizeof(int)); 2174 pool = SDL_stack_alloc(int, 2*ncolors);
2174 if ( pool == NULL ) { 2175 if ( pool == NULL ) {
2175 /* No worries, just return */; 2176 /* No worries, just return */;
2176 return; 2177 return;
2177 } 2178 }
2178 seen = pool; 2179 seen = pool;
2215 for ( j=10, i=0; i<maxcolors; ++i, ++j ) { 2216 for ( j=10, i=0; i<maxcolors; ++i, ++j ) {
2216 SDL_colors[j].peRed = colors[order[i]].r; 2217 SDL_colors[j].peRed = colors[order[i]].r;
2217 SDL_colors[j].peGreen = colors[order[i]].g; 2218 SDL_colors[j].peGreen = colors[order[i]].g;
2218 SDL_colors[j].peBlue = colors[order[i]].b; 2219 SDL_colors[j].peBlue = colors[order[i]].b;
2219 } 2220 }
2221 SDL_stack_free(pool);
2220 #endif /* SIMPLE_COMPRESSION */ 2222 #endif /* SIMPLE_COMPRESSION */
2221 } 2223 }
2222 2224
2223 /* Set the system colormap in both fullscreen and windowed modes */ 2225 /* Set the system colormap in both fullscreen and windowed modes */
2224 int DX5_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 2226 int DX5_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
2456 if(!palette) 2458 if(!palette)
2457 palette = SDL_VideoSurface->format->palette; 2459 palette = SDL_VideoSurface->format->palette;
2458 if ( palette == NULL ) { /* Sometimes we don't have a palette */ 2460 if ( palette == NULL ) { /* Sometimes we don't have a palette */
2459 return; 2461 return;
2460 } 2462 }
2461 entries = (PALETTEENTRY *)alloca(palette->ncolors*sizeof(*entries)); 2463 entries = SDL_stack_alloc(PALETTEENTRY, palette->ncolors);
2462 hdc = GetDC(window); 2464 hdc = GetDC(window);
2463 GetSystemPaletteEntries(hdc, 0, palette->ncolors, entries); 2465 GetSystemPaletteEntries(hdc, 0, palette->ncolors, entries);
2464 ReleaseDC(window, hdc); 2466 ReleaseDC(window, hdc);
2465 if ( ! colorchange_expected ) { 2467 if ( ! colorchange_expected ) {
2466 saved = (SDL_Color *)alloca(palette->ncolors*sizeof(SDL_Color)); 2468 saved = SDL_stack_alloc(SDL_Color, palette->ncolors);
2467 memcpy(saved, palette->colors, 2469 memcpy(saved, palette->colors,
2468 palette->ncolors*sizeof(SDL_Color)); 2470 palette->ncolors*sizeof(SDL_Color));
2469 } 2471 }
2470 for ( i=0; i<palette->ncolors; ++i ) { 2472 for ( i=0; i<palette->ncolors; ++i ) {
2471 palette->colors[i].r = entries[i].peRed; 2473 palette->colors[i].r = entries[i].peRed;
2472 palette->colors[i].g = entries[i].peGreen; 2474 palette->colors[i].g = entries[i].peGreen;
2473 palette->colors[i].b = entries[i].peBlue; 2475 palette->colors[i].b = entries[i].peBlue;
2474 } 2476 }
2477 SDL_stack_free(entries);
2475 if ( ! colorchange_expected ) { 2478 if ( ! colorchange_expected ) {
2476 Uint8 mapping[256]; 2479 Uint8 mapping[256];
2477 2480
2478 memset(mapping, 0, sizeof(mapping)); 2481 memset(mapping, 0, sizeof(mapping));
2479 for ( i=0; i<palette->ncolors; ++i ) { 2482 for ( i=0; i<palette->ncolors; ++i ) {
2480 mapping[i] = SDL_FindColor(palette, 2483 mapping[i] = SDL_FindColor(palette,
2481 saved[i].r, saved[i].g, saved[i].b); 2484 saved[i].r, saved[i].g, saved[i].b);
2482 } 2485 }
2483 DX5_Recolor8Bit(this, SDL_VideoSurface, mapping); 2486 DX5_Recolor8Bit(this, SDL_VideoSurface, mapping);
2487 SDL_stack_free(saved);
2484 } 2488 }
2485 colorchange_expected = 0; 2489 colorchange_expected = 0;
2486 2490
2487 /* Notify all mapped surfaces of the change */ 2491 /* Notify all mapped surfaces of the change */
2488 SDL_FormatChanged(SDL_VideoSurface); 2492 SDL_FormatChanged(SDL_VideoSurface);