comparison src/video/windib/SDL_dibvideo.c @ 1336:3692456e7b0f

Use SDL_ prefixed versions of C library functions. FIXME: Change #include <stdlib.h> to #include "SDL_stdlib.h" Change #include <string.h> to #include "SDL_string.h" Make sure nothing else broke because of this...
author Sam Lantinga <slouken@libsdl.org>
date Tue, 07 Feb 2006 06:59:48 +0000
parents 450721ad5436
children 604d73db6802
comparison
equal deleted inserted replaced
1335:c39265384763 1336:3692456e7b0f
103 103
104 static void DIB_DeleteDevice(SDL_VideoDevice *device) 104 static void DIB_DeleteDevice(SDL_VideoDevice *device)
105 { 105 {
106 if ( device ) { 106 if ( device ) {
107 if ( device->hidden ) { 107 if ( device->hidden ) {
108 free(device->hidden); 108 SDL_free(device->hidden);
109 } 109 }
110 if ( device->gl_data ) { 110 if ( device->gl_data ) {
111 free(device->gl_data); 111 SDL_free(device->gl_data);
112 } 112 }
113 free(device); 113 SDL_free(device);
114 } 114 }
115 } 115 }
116 116
117 static SDL_VideoDevice *DIB_CreateDevice(int devindex) 117 static SDL_VideoDevice *DIB_CreateDevice(int devindex)
118 { 118 {
119 SDL_VideoDevice *device; 119 SDL_VideoDevice *device;
120 120
121 /* Initialize all variables that we clean on shutdown */ 121 /* Initialize all variables that we clean on shutdown */
122 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); 122 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
123 if ( device ) { 123 if ( device ) {
124 memset(device, 0, (sizeof *device)); 124 SDL_memset(device, 0, (sizeof *device));
125 device->hidden = (struct SDL_PrivateVideoData *) 125 device->hidden = (struct SDL_PrivateVideoData *)
126 malloc((sizeof *device->hidden)); 126 SDL_malloc((sizeof *device->hidden));
127 device->gl_data = (struct SDL_PrivateGLData *) 127 device->gl_data = (struct SDL_PrivateGLData *)
128 malloc((sizeof *device->gl_data)); 128 SDL_malloc((sizeof *device->gl_data));
129 } 129 }
130 if ( (device == NULL) || (device->hidden == NULL) || 130 if ( (device == NULL) || (device->hidden == NULL) ||
131 (device->gl_data == NULL) ) { 131 (device->gl_data == NULL) ) {
132 SDL_OutOfMemory(); 132 SDL_OutOfMemory();
133 DIB_DeleteDevice(device); 133 DIB_DeleteDevice(device);
134 return(NULL); 134 return(NULL);
135 } 135 }
136 memset(device->hidden, 0, (sizeof *device->hidden)); 136 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
137 memset(device->gl_data, 0, (sizeof *device->gl_data)); 137 SDL_memset(device->gl_data, 0, (sizeof *device->gl_data));
138 138
139 /* Set the function pointers */ 139 /* Set the function pointers */
140 device->VideoInit = DIB_VideoInit; 140 device->VideoInit = DIB_VideoInit;
141 device->ListModes = DIB_ListModes; 141 device->ListModes = DIB_ListModes;
142 device->SetVideoMode = DIB_SetVideoMode; 142 device->SetVideoMode = DIB_SetVideoMode;
221 return(0); 221 return(0);
222 } 222 }
223 } 223 }
224 224
225 /* Set up the new video mode rectangle */ 225 /* Set up the new video mode rectangle */
226 mode = (SDL_Rect *)malloc(sizeof *mode); 226 mode = (SDL_Rect *)SDL_malloc(sizeof *mode);
227 if ( mode == NULL ) { 227 if ( mode == NULL ) {
228 SDL_OutOfMemory(); 228 SDL_OutOfMemory();
229 return(-1); 229 return(-1);
230 } 230 }
231 mode->x = 0; 231 mode->x = 0;
234 mode->h = h; 234 mode->h = h;
235 235
236 /* Allocate the new list of modes, and fill in the new mode */ 236 /* Allocate the new list of modes, and fill in the new mode */
237 next_mode = SDL_nummodes[index]; 237 next_mode = SDL_nummodes[index];
238 SDL_modelist[index] = (SDL_Rect **) 238 SDL_modelist[index] = (SDL_Rect **)
239 realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); 239 SDL_realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
240 if ( SDL_modelist[index] == NULL ) { 240 if ( SDL_modelist[index] == NULL ) {
241 SDL_OutOfMemory(); 241 SDL_OutOfMemory();
242 SDL_nummodes[index] = 0; 242 SDL_nummodes[index] = 0;
243 free(mode); 243 SDL_free(mode);
244 return(-1); 244 return(-1);
245 } 245 }
246 SDL_modelist[index][next_mode] = mode; 246 SDL_modelist[index][next_mode] = mode;
247 SDL_modelist[index][next_mode+1] = NULL; 247 SDL_modelist[index][next_mode+1] = NULL;
248 SDL_nummodes[index]++; 248 SDL_nummodes[index]++;
268 268
269 ncolors = 1; 269 ncolors = 1;
270 for ( i=0; i<bpp; ++i ) { 270 for ( i=0; i<bpp; ++i ) {
271 ncolors *= 2; 271 ncolors *= 2;
272 } 272 }
273 palette = (LOGPALETTE *)malloc(sizeof(*palette)+ 273 palette = (LOGPALETTE *)SDL_malloc(sizeof(*palette)+
274 ncolors*sizeof(PALETTEENTRY)); 274 ncolors*sizeof(PALETTEENTRY));
275 palette->palVersion = 0x300; 275 palette->palVersion = 0x300;
276 palette->palNumEntries = ncolors; 276 palette->palNumEntries = ncolors;
277 hdc = GetDC(SDL_Window); 277 hdc = GetDC(SDL_Window);
278 GetSystemPaletteEntries(hdc, 0, ncolors, palette->palPalEntry); 278 GetSystemPaletteEntries(hdc, 0, ncolors, palette->palPalEntry);
279 ReleaseDC(SDL_Window, hdc); 279 ReleaseDC(SDL_Window, hdc);
280 handle = CreatePalette(palette); 280 handle = CreatePalette(palette);
281 free(palette); 281 SDL_free(palette);
282 } 282 }
283 283
284 return handle; 284 return handle;
285 } 285 }
286 286
337 settings.dmPelsWidth, settings.dmPelsHeight); 337 settings.dmPelsWidth, settings.dmPelsHeight);
338 } 338 }
339 /* Sort the mode lists */ 339 /* Sort the mode lists */
340 for ( i=0; i<NUM_MODELISTS; ++i ) { 340 for ( i=0; i<NUM_MODELISTS; ++i ) {
341 if ( SDL_nummodes[i] > 0 ) { 341 if ( SDL_nummodes[i] > 0 ) {
342 qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes); 342 SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);
343 } 343 }
344 } 344 }
345 #endif /* !NO_CHANGEDISPLAYSETTINGS */ 345 #endif /* !NO_CHANGEDISPLAYSETTINGS */
346 346
347 /* Grab an identity palette if we are in a palettized mode */ 347 /* Grab an identity palette if we are in a palettized mode */
398 398
399 /* Allocate enough space for a DIB header plus palette (for 399 /* Allocate enough space for a DIB header plus palette (for
400 * 8-bit modes) or bitfields (for 16- and 32-bit modes) 400 * 8-bit modes) or bitfields (for 16- and 32-bit modes)
401 */ 401 */
402 dib_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD); 402 dib_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD);
403 dib_hdr = (LPBITMAPINFOHEADER) malloc(dib_size); 403 dib_hdr = (LPBITMAPINFOHEADER) SDL_malloc(dib_size);
404 memset(dib_hdr, 0, dib_size); 404 SDL_memset(dib_hdr, 0, dib_size);
405 dib_hdr->biSize = sizeof(BITMAPINFOHEADER); 405 dib_hdr->biSize = sizeof(BITMAPINFOHEADER);
406 406
407 /* Get a device-dependent bitmap that's compatible with the 407 /* Get a device-dependent bitmap that's compatible with the
408 screen. 408 screen.
409 */ 409 */
529 /* Set fullscreen mode if appropriate */ 529 /* Set fullscreen mode if appropriate */
530 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 530 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
531 DEVMODE settings; 531 DEVMODE settings;
532 BOOL changed; 532 BOOL changed;
533 533
534 memset(&settings, 0, sizeof(DEVMODE)); 534 SDL_memset(&settings, 0, sizeof(DEVMODE));
535 settings.dmSize = sizeof(DEVMODE); 535 settings.dmSize = sizeof(DEVMODE);
536 settings.dmBitsPerPel = video->format->BitsPerPixel; 536 settings.dmBitsPerPel = video->format->BitsPerPixel;
537 settings.dmPelsWidth = width; 537 settings.dmPelsWidth = width;
538 settings.dmPelsHeight = height; 538 settings.dmPelsHeight = height;
539 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; 539 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
614 binfo_size += 3*sizeof(DWORD); 614 binfo_size += 3*sizeof(DWORD);
615 } else if ( video->format->palette ) { 615 } else if ( video->format->palette ) {
616 binfo_size += video->format->palette->ncolors * 616 binfo_size += video->format->palette->ncolors *
617 sizeof(RGBQUAD); 617 sizeof(RGBQUAD);
618 } 618 }
619 binfo = (BITMAPINFO *)malloc(binfo_size); 619 binfo = (BITMAPINFO *)SDL_malloc(binfo_size);
620 if ( ! binfo ) { 620 if ( ! binfo ) {
621 if ( video != current ) { 621 if ( video != current ) {
622 SDL_FreeSurface(video); 622 SDL_FreeSurface(video);
623 } 623 }
624 SDL_OutOfMemory(); 624 SDL_OutOfMemory();
643 ((Uint32*)binfo->bmiColors)[1] = video->format->Gmask; 643 ((Uint32*)binfo->bmiColors)[1] = video->format->Gmask;
644 ((Uint32*)binfo->bmiColors)[2] = video->format->Bmask; 644 ((Uint32*)binfo->bmiColors)[2] = video->format->Bmask;
645 } else { 645 } else {
646 binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */ 646 binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */
647 if ( video->format->palette ) { 647 if ( video->format->palette ) {
648 memset(binfo->bmiColors, 0, 648 SDL_memset(binfo->bmiColors, 0,
649 video->format->palette->ncolors*sizeof(RGBQUAD)); 649 video->format->palette->ncolors*sizeof(RGBQUAD));
650 } 650 }
651 } 651 }
652 652
653 /* Create the offscreen bitmap buffer */ 653 /* Create the offscreen bitmap buffer */
654 hdc = GetDC(SDL_Window); 654 hdc = GetDC(SDL_Window);
655 screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS, 655 screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS,
656 (void **)(&video->pixels), NULL, 0); 656 (void **)(&video->pixels), NULL, 0);
657 ReleaseDC(SDL_Window, hdc); 657 ReleaseDC(SDL_Window, hdc);
658 free(binfo); 658 SDL_free(binfo);
659 if ( screen_bmp == NULL ) { 659 if ( screen_bmp == NULL ) {
660 if ( video != current ) { 660 if ( video != current ) {
661 SDL_FreeSurface(video); 661 SDL_FreeSurface(video);
662 } 662 }
663 SDL_SetError("Couldn't create DIB section"); 663 SDL_SetError("Couldn't create DIB section");
678 UINT swp_flags; 678 UINT swp_flags;
679 const char *window = NULL; 679 const char *window = NULL;
680 const char *center = NULL; 680 const char *center = NULL;
681 681
682 if ( !SDL_windowX && !SDL_windowY ) { 682 if ( !SDL_windowX && !SDL_windowY ) {
683 window = getenv("SDL_VIDEO_WINDOW_POS"); 683 window = SDL_getenv("SDL_VIDEO_WINDOW_POS");
684 center = getenv("SDL_VIDEO_CENTERED"); 684 center = SDL_getenv("SDL_VIDEO_CENTERED");
685 if ( window ) { 685 if ( window ) {
686 if ( sscanf(window, "%d,%d", &x, &y) == 2 ) { 686 if ( SDL_sscanf(window, "%d,%d", &x, &y) == 2 ) {
687 SDL_windowX = x; 687 SDL_windowX = x;
688 SDL_windowY = y; 688 SDL_windowY = y;
689 } 689 }
690 if ( strcmp(window, "center") == 0 ) { 690 if ( SDL_strcmp(window, "center") == 0 ) {
691 center = window; 691 center = window;
692 } 692 }
693 } 693 }
694 } 694 }
695 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW); 695 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW);
876 SetDeviceGammaRamp(hdc, gamma_saved); 876 SetDeviceGammaRamp(hdc, gamma_saved);
877 ReleaseDC(SDL_Window, hdc); 877 ReleaseDC(SDL_Window, hdc);
878 } 878 }
879 879
880 /* Free the saved gamma memory */ 880 /* Free the saved gamma memory */
881 free(gamma_saved); 881 SDL_free(gamma_saved);
882 gamma_saved = 0; 882 gamma_saved = 0;
883 } 883 }
884 #endif /* !NO_GAMMA_SUPPORT */ 884 #endif /* !NO_GAMMA_SUPPORT */
885 } 885 }
886 886
893 HDC hdc; 893 HDC hdc;
894 BOOL succeeded; 894 BOOL succeeded;
895 895
896 /* Set the ramp for the display */ 896 /* Set the ramp for the display */
897 if ( ! gamma_saved ) { 897 if ( ! gamma_saved ) {
898 gamma_saved = (WORD *)malloc(3*256*sizeof(*gamma_saved)); 898 gamma_saved = (WORD *)SDL_malloc(3*256*sizeof(*gamma_saved));
899 if ( ! gamma_saved ) { 899 if ( ! gamma_saved ) {
900 SDL_OutOfMemory(); 900 SDL_OutOfMemory();
901 return -1; 901 return -1;
902 } 902 }
903 hdc = GetDC(SDL_Window); 903 hdc = GetDC(SDL_Window);