src/SDL12_compat.c
changeset 94 ed05888ca3eb
parent 93 20605b15ca8c
child 95 2fa2951e5c96
     1.1 --- a/src/SDL12_compat.c	Fri Mar 01 10:52:06 2019 -0500
     1.2 +++ b/src/SDL12_compat.c	Fri Mar 01 10:52:47 2019 -0500
     1.3 @@ -2856,11 +2856,26 @@
     1.4      }
     1.5  
     1.6      FIXME("Maybe lock texture always, until present, if no conversion needed?");
     1.7 -    VideoConvertSurface20->pixels = pixels;
     1.8 -    VideoConvertSurface20->pitch = pitch;
     1.9 -    SDL20_UpperBlit(VideoSurface12->surface20, NULL, VideoConvertSurface20, NULL);
    1.10 -    VideoConvertSurface20->pixels = NULL;
    1.11 -    VideoConvertSurface20->pitch = 0;
    1.12 +    if (VideoConvertSurface20) {
    1.13 +        VideoConvertSurface20->pixels = pixels;
    1.14 +        VideoConvertSurface20->pitch = pitch;
    1.15 +        SDL20_UpperBlit(VideoSurface12->surface20, NULL, VideoConvertSurface20, NULL);
    1.16 +        VideoConvertSurface20->pixels = NULL;
    1.17 +        VideoConvertSurface20->pitch = 0;
    1.18 +    } else if (pitch == VideoSurface12->pitch) {
    1.19 +        SDL_memcpy(pixels, VideoSurface12->pixels, pitch * VideoSurface12->h);
    1.20 +    } else {
    1.21 +        const int srcpitch = VideoSurface12->pitch;
    1.22 +        const int cpy = SDL_min(srcpitch, pitch);
    1.23 +        const int h = VideoSurface12->h;
    1.24 +        char *dst = (char *) pixels;
    1.25 +        char *src = (char *) VideoSurface12->pixels;
    1.26 +        for (int i = 0; i < h; i++) {
    1.27 +            SDL_memcpy(dst, src, cpy);
    1.28 +            src += srcpitch;
    1.29 +            dst += pitch;
    1.30 +        }
    1.31 +    }
    1.32  
    1.33      SDL20_UnlockTexture(VideoTexture20);
    1.34      SDL20_RenderCopy(VideoRenderer20, VideoTexture20, NULL, NULL);