src/SDL_compat.c
changeset 5309 da080d3247c9
parent 5308 50ceebd6e12f
child 5312 035797f48321
equal deleted inserted replaced
5308:50ceebd6e12f 5309:da080d3247c9
   845         SDL_SetError("SDL_SetVideoMode() hasn't been called");
   845         SDL_SetError("SDL_SetVideoMode() hasn't been called");
   846         return 0;
   846         return 0;
   847     }
   847     }
   848 
   848 
   849     /* Copy the old bits out */
   849     /* Copy the old bits out */
   850     length = SDL_VideoSurface->w * SDL_VideoSurface->format->BytesPerPixel;
   850     length = SDL_PublicSurface->w * SDL_PublicSurface->format->BytesPerPixel;
   851     pixels = SDL_malloc(SDL_VideoSurface->h * length);
   851     pixels = SDL_malloc(SDL_PublicSurface->h * length);
   852     if (pixels) {
   852     if (pixels) {
   853         src = (Uint8*)SDL_VideoSurface->pixels;
   853         src = (Uint8*)SDL_PublicSurface->pixels;
   854         dst = (Uint8*)pixels;
   854         dst = (Uint8*)pixels;
   855         for (row = 0; row < SDL_VideoSurface->h; ++row) {
   855         for (row = 0; row < SDL_PublicSurface->h; ++row) {
   856             SDL_memcpy(dst, src, length);
   856             SDL_memcpy(dst, src, length);
   857             src += SDL_VideoSurface->pitch;
   857             src += SDL_PublicSurface->pitch;
   858             dst += length;
   858             dst += length;
   859         }
   859         }
   860     }
   860     }
   861 
   861 
   862     /* Do the physical mode switch */
   862     /* Do the physical mode switch */
   892             if (SDL_ShadowSurface->format->format == SDL_WindowSurface->format->format) {
   892             if (SDL_ShadowSurface->format->format == SDL_WindowSurface->format->format) {
   893                 /* Whee!  We don't need a shadow surface anymore! */
   893                 /* Whee!  We don't need a shadow surface anymore! */
   894                 SDL_VideoSurface->flags &= ~SDL_DONTFREE;
   894                 SDL_VideoSurface->flags &= ~SDL_DONTFREE;
   895                 SDL_FreeSurface(SDL_VideoSurface);
   895                 SDL_FreeSurface(SDL_VideoSurface);
   896                 SDL_free(SDL_ShadowSurface->pixels);
   896                 SDL_free(SDL_ShadowSurface->pixels);
   897                 SDL_ShadowSurface->flags |= SDL_PREALLOC;
       
   898                 SDL_VideoSurface = SDL_ShadowSurface;
   897                 SDL_VideoSurface = SDL_ShadowSurface;
       
   898                 SDL_VideoSurface->flags |= SDL_PREALLOC;
   899                 SDL_ShadowSurface = NULL;
   899                 SDL_ShadowSurface = NULL;
   900             } else {
   900             } else {
   901                 /* No problem, just change the video surface format */
   901                 /* No problem, just change the video surface format */
   902                 SDL_FreeFormat(SDL_VideoSurface->format);
   902                 SDL_FreeFormat(SDL_VideoSurface->format);
   903                 SDL_VideoSurface->format = SDL_WindowSurface->format;
   903                 SDL_VideoSurface->format = SDL_WindowSurface->format;
   905                 SDL_InvalidateMap(SDL_ShadowSurface->map);
   905                 SDL_InvalidateMap(SDL_ShadowSurface->map);
   906             }
   906             }
   907         } else {
   907         } else {
   908             /* We can make the video surface the shadow surface */
   908             /* We can make the video surface the shadow surface */
   909             SDL_ShadowSurface = SDL_VideoSurface;
   909             SDL_ShadowSurface = SDL_VideoSurface;
       
   910             SDL_ShadowSurface->pitch = SDL_CalculatePitch(SDL_ShadowSurface);
       
   911             SDL_ShadowSurface->pixels = SDL_malloc(SDL_ShadowSurface->h * SDL_ShadowSurface->pitch);
       
   912             if (!SDL_ShadowSurface->pixels) {
       
   913                 /* Uh oh, we're hosed */
       
   914                 SDL_ShadowSurface = NULL;
       
   915                 return 0;
       
   916             }
       
   917             SDL_ShadowSurface->flags &= ~SDL_PREALLOC;
   910 
   918 
   911             SDL_VideoSurface = SDL_CreateRGBSurfaceFrom(NULL, 0, 0, 32, 0, 0, 0, 0, 0);
   919             SDL_VideoSurface = SDL_CreateRGBSurfaceFrom(NULL, 0, 0, 32, 0, 0, 0, 0, 0);
   912             SDL_VideoSurface->flags = SDL_ShadowSurface->flags;
   920             SDL_VideoSurface->flags = SDL_ShadowSurface->flags;
       
   921             SDL_VideoSurface->flags |= SDL_PREALLOC;
   913             SDL_FreeFormat(SDL_VideoSurface->format);
   922             SDL_FreeFormat(SDL_VideoSurface->format);
   914             SDL_VideoSurface->format = SDL_WindowSurface->format;
   923             SDL_VideoSurface->format = SDL_WindowSurface->format;
   915             SDL_VideoSurface->format->refcount++;
   924             SDL_VideoSurface->format->refcount++;
   916             SDL_VideoSurface->w = SDL_ShadowSurface->w;
   925             SDL_VideoSurface->w = SDL_ShadowSurface->w;
   917             SDL_VideoSurface->h = SDL_ShadowSurface->h;
   926             SDL_VideoSurface->h = SDL_ShadowSurface->h;
   926     SDL_SetClipRect(SDL_VideoSurface, NULL);
   935     SDL_SetClipRect(SDL_VideoSurface, NULL);
   927 
   936 
   928     /* Copy the old bits back */
   937     /* Copy the old bits back */
   929     if (pixels) {
   938     if (pixels) {
   930         src = (Uint8*)pixels;
   939         src = (Uint8*)pixels;
   931         dst = (Uint8*)SDL_VideoSurface->pixels;
   940         dst = (Uint8*)SDL_PublicSurface->pixels;
   932         for (row = 0; row < SDL_VideoSurface->h; ++row) {
   941         for (row = 0; row < SDL_PublicSurface->h; ++row) {
   933             SDL_memcpy(dst, src, length);
   942             SDL_memcpy(dst, src, length);
   934             src += length;
   943             src += length;
   935             dst += SDL_VideoSurface->pitch;
   944             dst += SDL_PublicSurface->pitch;
   936         }
   945         }
   937         SDL_Flip(SDL_VideoSurface);
   946         SDL_Flip(SDL_PublicSurface);
   938         SDL_free(pixels);
   947         SDL_free(pixels);
   939     }
   948     }
   940 
   949 
   941     /* We're done! */
   950     /* We're done! */
   942     return 1;
   951     return 1;