comparison src/video/SDL_video.c @ 662:66c02f83f5bf

Date: Sun, 27 Jul 2003 22:37:59 +0200 From: Max Horn Subject: SDL whitespace patch this patch is lowest priority: it only contains indention fixes. In some places, instead of tabs, whitespaces where used for indention. But of course that only "looks good" if you use the exact same tab width as the author of those files. I tried to replace such cases with tabs for a more uniform indention. I only did that for a few files. So, no code changes in this, only whitespaces transformed.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 28 Jul 2003 01:47:55 +0000
parents 864e2d2a9a55
children 8bedd6d61642
comparison
equal deleted inserted replaced
661:04028d47b1ea 662:66c02f83f5bf
258 * The application can't do anything with the display surface until 258 * The application can't do anything with the display surface until
259 * a video mode has been set anyway. :) 259 * a video mode has been set anyway. :)
260 */ 260 */
261 /* If we have a palettized surface, create a default palette */ 261 /* If we have a palettized surface, create a default palette */
262 if ( SDL_VideoSurface->format->palette ) { 262 if ( SDL_VideoSurface->format->palette ) {
263 SDL_PixelFormat *vf = SDL_VideoSurface->format; 263 SDL_PixelFormat *vf = SDL_VideoSurface->format;
264 SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel); 264 SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel);
265 video->SetColors(video, 265 video->SetColors(video,
266 0, vf->palette->ncolors, vf->palette->colors); 266 0, vf->palette->ncolors, vf->palette->colors);
267 } 267 }
268 #endif 268 #endif
631 free(video->physpal->colors); 631 free(video->physpal->colors);
632 free(video->physpal); 632 free(video->physpal);
633 video->physpal = NULL; 633 video->physpal = NULL;
634 } 634 }
635 if( video->gammacols) { 635 if( video->gammacols) {
636 free(video->gammacols); 636 free(video->gammacols);
637 video->gammacols = NULL; 637 video->gammacols = NULL;
638 } 638 }
639 639
640 /* Save the previous grab state and turn off grab for mode switch */ 640 /* Save the previous grab state and turn off grab for mode switch */
641 saved_grab = SDL_WM_GrabInputOff(); 641 saved_grab = SDL_WM_GrabInputOff();
650 650
651 /* Sam - If we asked for OpenGL mode, and didn't get it, fail */ 651 /* Sam - If we asked for OpenGL mode, and didn't get it, fail */
652 if ( is_opengl && !(mode->flags & SDL_OPENGL) ) { 652 if ( is_opengl && !(mode->flags & SDL_OPENGL) ) {
653 mode = NULL; 653 mode = NULL;
654 } 654 }
655 } 655 }
656 /* 656 /*
657 * rcg11292000 657 * rcg11292000
658 * If you try to set an SDL_OPENGL surface, and fail to find a 658 * If you try to set an SDL_OPENGL surface, and fail to find a
659 * matching visual, then the next call to SDL_SetVideoMode() 659 * matching visual, then the next call to SDL_SetVideoMode()
660 * will segfault, since we no longer point to a dummy surface, 660 * will segfault, since we no longer point to a dummy surface,
673 return(NULL); 673 return(NULL);
674 } 674 }
675 675
676 /* If we have a palettized surface, create a default palette */ 676 /* If we have a palettized surface, create a default palette */
677 if ( mode->format->palette ) { 677 if ( mode->format->palette ) {
678 SDL_PixelFormat *vf = mode->format; 678 SDL_PixelFormat *vf = mode->format;
679 SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel); 679 SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel);
680 video->SetColors(this, 0, vf->palette->ncolors, 680 video->SetColors(this, 0, vf->palette->ncolors,
681 vf->palette->colors); 681 vf->palette->colors);
682 } 682 }
683 683
803 SDL_VideoSurface->flags = mode->flags | SDL_OPENGLBLIT; 803 SDL_VideoSurface->flags = mode->flags | SDL_OPENGLBLIT;
804 804
805 /* Free the original video mode surface (is this safe?) */ 805 /* Free the original video mode surface (is this safe?) */
806 SDL_FreeSurface(mode); 806 SDL_FreeSurface(mode);
807 807
808 /* Set the surface completely opaque & white by default */ 808 /* Set the surface completely opaque & white by default */
809 memset( SDL_VideoSurface->pixels, 255, SDL_VideoSurface->h * SDL_VideoSurface->pitch ); 809 memset( SDL_VideoSurface->pixels, 255, SDL_VideoSurface->h * SDL_VideoSurface->pitch );
810 video->glGenTextures( 1, &video->texture ); 810 video->glGenTextures( 1, &video->texture );
811 video->glBindTexture( GL_TEXTURE_2D, video->texture ); 811 video->glBindTexture( GL_TEXTURE_2D, video->texture );
812 video->glTexImage2D( 812 video->glTexImage2D(
813 GL_TEXTURE_2D, 813 GL_TEXTURE_2D,
1091 } 1091 }
1092 1092
1093 static void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors, 1093 static void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors,
1094 int firstcolor, int ncolors) 1094 int firstcolor, int ncolors)
1095 { 1095 {
1096 SDL_Palette *pal = screen->format->palette; 1096 SDL_Palette *pal = screen->format->palette;
1097 SDL_Palette *vidpal; 1097 SDL_Palette *vidpal;
1098 1098
1099 if ( colors != (pal->colors + firstcolor) ) { 1099 if ( colors != (pal->colors + firstcolor) ) {
1100 memcpy(pal->colors + firstcolor, colors, 1100 memcpy(pal->colors + firstcolor, colors,
1101 ncolors * sizeof(*colors)); 1101 ncolors * sizeof(*colors));
1102 } 1102 }
1103 1103
1104 vidpal = SDL_VideoSurface->format->palette; 1104 vidpal = SDL_VideoSurface->format->palette;
1105 if ( (screen == SDL_ShadowSurface) && vidpal ) { 1105 if ( (screen == SDL_ShadowSurface) && vidpal ) {
1106 /* 1106 /*
1107 * This is a shadow surface, and the physical 1107 * This is a shadow surface, and the physical
1108 * framebuffer is also indexed. Propagate the 1108 * framebuffer is also indexed. Propagate the
1109 * changes to its logical palette so that 1109 * changes to its logical palette so that
1110 * updates are always identity blits 1110 * updates are always identity blits
1111 */ 1111 */
1168 } 1168 }
1169 1169
1170 if ( screen == SDL_VideoSurface ) { 1170 if ( screen == SDL_VideoSurface ) {
1171 SDL_Color gcolors[256]; 1171 SDL_Color gcolors[256];
1172 1172
1173 if ( video->gamma ) { 1173 if ( video->gamma ) {
1174 SDL_ApplyGamma(video->gamma, colors, gcolors, ncolors); 1174 SDL_ApplyGamma(video->gamma, colors, gcolors, ncolors);
1175 colors = gcolors; 1175 colors = gcolors;
1176 } 1176 }
1177 gotall = video->SetColors(video, firstcolor, ncolors, colors); 1177 gotall = video->SetColors(video, firstcolor, ncolors, colors);
1178 if ( ! gotall ) { 1178 if ( ! gotall ) {
1179 /* The video flags shouldn't have SDL_HWPALETTE, and 1179 /* The video flags shouldn't have SDL_HWPALETTE, and
1197 * Return nonzero if all colours were set as requested, or 0 otherwise. 1197 * Return nonzero if all colours were set as requested, or 0 otherwise.
1198 */ 1198 */
1199 int SDL_SetPalette(SDL_Surface *screen, int which, 1199 int SDL_SetPalette(SDL_Surface *screen, int which,
1200 SDL_Color *colors, int firstcolor, int ncolors) 1200 SDL_Color *colors, int firstcolor, int ncolors)
1201 { 1201 {
1202 SDL_Palette *pal; 1202 SDL_Palette *pal;
1203 int gotall; 1203 int gotall;
1204 int palsize; 1204 int palsize;
1205 1205
1206 if ( ! current_video ) { 1206 if ( ! current_video ) {
1207 return 0; 1207 return 0;
1208 } 1208 }
1209 if ( screen != SDL_PublicSurface ) { 1209 if ( screen != SDL_PublicSurface ) {
1210 /* only screens have physical palettes */ 1210 /* only screens have physical palettes */
1211 which &= ~SDL_PHYSPAL; 1211 which &= ~SDL_PHYSPAL;
1212 } else if( (screen->flags & SDL_HWPALETTE) != SDL_HWPALETTE ) { 1212 } else if( (screen->flags & SDL_HWPALETTE) != SDL_HWPALETTE ) {
1213 /* hardware palettes required for split colormaps */ 1213 /* hardware palettes required for split colormaps */
1214 which |= SDL_PHYSPAL | SDL_LOGPAL; 1214 which |= SDL_PHYSPAL | SDL_LOGPAL;
1215 } 1215 }
1216 1216
1217 /* Verify the parameters */ 1217 /* Verify the parameters */
1218 pal = screen->format->palette; 1218 pal = screen->format->palette;
1219 if( !pal ) { 1219 if( !pal ) {
1220 return 0; /* not a palettized surface */ 1220 return 0; /* not a palettized surface */
1221 } 1221 }
1222 gotall = 1; 1222 gotall = 1;
1223 palsize = 1 << screen->format->BitsPerPixel; 1223 palsize = 1 << screen->format->BitsPerPixel;
1224 if ( ncolors > (palsize - firstcolor) ) { 1224 if ( ncolors > (palsize - firstcolor) ) {
1225 ncolors = (palsize - firstcolor); 1225 ncolors = (palsize - firstcolor);
1226 gotall = 0; 1226 gotall = 0;
1227 } 1227 }
1228 1228
1229 if ( which & SDL_LOGPAL ) { 1229 if ( which & SDL_LOGPAL ) {
1230 /* 1230 /*
1231 * Logical palette change: The actual screen isn't affected, 1231 * Logical palette change: The actual screen isn't affected,
1232 * but the internal colormap is altered so that the 1232 * but the internal colormap is altered so that the
1233 * interpretation of the pixel values (for blits etc) is 1233 * interpretation of the pixel values (for blits etc) is
1234 * changed. 1234 * changed.
1235 */ 1235 */
1236 SetPalette_logical(screen, colors, firstcolor, ncolors); 1236 SetPalette_logical(screen, colors, firstcolor, ncolors);
1237 } 1237 }
1238 if ( which & SDL_PHYSPAL ) { 1238 if ( which & SDL_PHYSPAL ) {
1239 SDL_VideoDevice *video = current_video; 1239 SDL_VideoDevice *video = current_video;
1240 /* 1240 /*
1241 * Physical palette change: This doesn't affect the 1241 * Physical palette change: This doesn't affect the
1242 * program's idea of what the screen looks like, but changes 1242 * program's idea of what the screen looks like, but changes
1243 * its actual appearance. 1243 * its actual appearance.
1244 */ 1244 */
1245 if(!video) 1245 if(!video)
1246 return gotall; /* video not yet initialized */ 1246 return gotall; /* video not yet initialized */
1247 if(!video->physpal && !(which & SDL_LOGPAL) ) { 1247 if(!video->physpal && !(which & SDL_LOGPAL) ) {
1248 /* Lazy physical palette allocation */ 1248 /* Lazy physical palette allocation */
1249 int size; 1249 int size;
1250 SDL_Palette *pp = malloc(sizeof(*pp)); 1250 SDL_Palette *pp = malloc(sizeof(*pp));
1251 current_video->physpal = pp; 1251 current_video->physpal = pp;
1252 pp->ncolors = pal->ncolors; 1252 pp->ncolors = pal->ncolors;
1253 size = pp->ncolors * sizeof(SDL_Color); 1253 size = pp->ncolors * sizeof(SDL_Color);
1254 pp->colors = malloc(size); 1254 pp->colors = malloc(size);
1263 } 1263 }
1264 1264
1265 int SDL_SetColors(SDL_Surface *screen, SDL_Color *colors, int firstcolor, 1265 int SDL_SetColors(SDL_Surface *screen, SDL_Color *colors, int firstcolor,
1266 int ncolors) 1266 int ncolors)
1267 { 1267 {
1268 return SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL, 1268 return SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL,
1269 colors, firstcolor, ncolors); 1269 colors, firstcolor, ncolors);
1270 } 1270 }
1271 1271
1272 /* 1272 /*
1273 * Clean up the video subsystem 1273 * Clean up the video subsystem
1396 video->gl_config.alpha_size = value; 1396 video->gl_config.alpha_size = value;
1397 break; 1397 break;
1398 case SDL_GL_DOUBLEBUFFER: 1398 case SDL_GL_DOUBLEBUFFER:
1399 video->gl_config.double_buffer = value; 1399 video->gl_config.double_buffer = value;
1400 break; 1400 break;
1401 case SDL_GL_BUFFER_SIZE: 1401 case SDL_GL_BUFFER_SIZE:
1402 video->gl_config.buffer_size = value; 1402 video->gl_config.buffer_size = value;
1403 break; 1403 break;
1404 case SDL_GL_DEPTH_SIZE: 1404 case SDL_GL_DEPTH_SIZE:
1405 video->gl_config.depth_size = value; 1405 video->gl_config.depth_size = value;
1406 break; 1406 break;
1407 case SDL_GL_STENCIL_SIZE: 1407 case SDL_GL_STENCIL_SIZE: