From 7812a4e83f5f04f8fdfe2b19ef102cd70df59c02 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 11 Oct 2002 07:56:36 +0000 Subject: [PATCH] Fixed a crash blitting RLE surfaces to RLE surfaces --- src/video/SDL_RLEaccel.c | 44 +++++++++++++++------------------------- src/video/SDL_blit.c | 36 ++++++++------------------------ src/video/SDL_surface.c | 8 -------- 3 files changed, 24 insertions(+), 64 deletions(-) diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c index 236875371..c10730eb2 100644 --- a/src/video/SDL_RLEaccel.c +++ b/src/video/SDL_RLEaccel.c @@ -463,10 +463,8 @@ int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect, unsigned alpha; /* Lock the destination if necessary */ - if ( dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - if ( video->LockHWSurface(this, dst) < 0 ) { + if ( SDL_MUSTLOCK(dst) ) { + if ( SDL_LockSurface(dst) < 0 ) { return(-1); } } @@ -474,7 +472,7 @@ int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect, /* Set up the source and destination pointers */ x = dstrect->x; y = dstrect->y; - dstbuf = (Uint8 *)dst->pixels + dst->offset + dstbuf = (Uint8 *)dst->pixels + y * dst->pitch + x * src->format->BytesPerPixel; srcbuf = (Uint8 *)src->map->sw_data->aux_data; @@ -553,10 +551,8 @@ int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect, done: /* Unlock the destination if necessary */ - if ( dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - video->UnlockHWSurface(this, dst); + if ( SDL_MUSTLOCK(dst) ) { + SDL_UnlockSurface(dst); } return(0); } @@ -733,17 +729,15 @@ int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_PixelFormat *df = dst->format; /* Lock the destination if necessary */ - if(dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT)) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - if(video->LockHWSurface(this, dst) < 0) { + if ( SDL_MUSTLOCK(dst) ) { + if ( SDL_LockSurface(dst) < 0 ) { return -1; } } x = dstrect->x; y = dstrect->y; - dstbuf = (Uint8 *)dst->pixels + dst->offset + dstbuf = (Uint8 *)dst->pixels + y * dst->pitch + x * df->BytesPerPixel; srcbuf = (Uint8 *)src->map->sw_data->aux_data + sizeof(RLEDestFormat); @@ -874,10 +868,8 @@ int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect, done: /* Unlock the destination if necessary */ - if(dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT)) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - video->UnlockHWSurface(this, dst); + if ( SDL_MUSTLOCK(dst) ) { + SDL_UnlockSurface(dst); } return 0; } @@ -1117,7 +1109,7 @@ static int RLEAlphaSurface(SDL_Surface *surface) int x, y; int h = surface->h, w = surface->w; SDL_PixelFormat *sf = surface->format; - Uint32 *src = (Uint32 *)((Uint8 *)surface->pixels + surface->offset); + Uint32 *src = (Uint32 *)surface->pixels; Uint8 *lastline = dst; /* end of last non-blank line */ /* opaque counts are 8 or 16 bits, depending on target depth */ @@ -1303,7 +1295,7 @@ static int RLEColorkeySurface(SDL_Surface *surface) } /* Set up the conversion */ - srcbuf = (Uint8 *)surface->pixels+surface->offset; + srcbuf = (Uint8 *)surface->pixels; curbuf = srcbuf; maxn = bpp == 4 ? 65535 : 255; skip = run = 0; @@ -1409,10 +1401,8 @@ int SDL_RLESurface(SDL_Surface *surface) } /* Lock the surface if it's in hardware */ - if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - if ( video->LockHWSurface(this, surface) < 0 ) { + if ( SDL_MUSTLOCK(surface) ) { + if ( SDL_LockSurface(surface) < 0 ) { return(-1); } } @@ -1429,10 +1419,8 @@ int SDL_RLESurface(SDL_Surface *surface) } /* Unlock the surface if it's in hardware */ - if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - video->UnlockHWSurface(this, surface); + if ( SDL_MUSTLOCK(surface) ) { + SDL_UnlockSurface(surface); } if(retcode < 0) diff --git a/src/video/SDL_blit.c b/src/video/SDL_blit.c index df69fba4d..90c8ca399 100644 --- a/src/video/SDL_blit.c +++ b/src/video/SDL_blit.c @@ -50,10 +50,8 @@ static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect, /* Lock the destination if it's in hardware */ dst_locked = 0; - if ( dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - if ( video->LockHWSurface(this, dst) < 0 ) { + if ( SDL_MUSTLOCK(dst) ) { + if ( SDL_LockSurface(dst) < 0 ) { okay = 0; } else { dst_locked = 1; @@ -61,35 +59,27 @@ static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect, } /* Lock the source if it's in hardware */ src_locked = 0; - if ( src->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - if ( video->LockHWSurface(this, src) < 0 ) { + if ( SDL_MUSTLOCK(src) ) { + if ( SDL_LockSurface(src) < 0 ) { okay = 0; } else { src_locked = 1; } } - /* Unencode the destination if it's RLE encoded */ - if ( dst->flags & SDL_RLEACCEL ) { - SDL_UnRLESurface(dst, 1); - dst->flags |= SDL_RLEACCEL; /* save accel'd state */ - } - /* Set up source and destination buffer pointers, and BLIT! */ if ( okay && srcrect->w && srcrect->h ) { SDL_BlitInfo info; SDL_loblit RunBlit; /* Set up the blit information */ - info.s_pixels = (Uint8 *)src->pixels + src->offset + + info.s_pixels = (Uint8 *)src->pixels + (Uint16)srcrect->y*src->pitch + (Uint16)srcrect->x*src->format->BytesPerPixel; info.s_width = srcrect->w; info.s_height = srcrect->h; info.s_skip=src->pitch-info.s_width*src->format->BytesPerPixel; - info.d_pixels = (Uint8 *)dst->pixels + dst->offset + + info.d_pixels = (Uint8 *)dst->pixels + (Uint16)dstrect->y*dst->pitch + (Uint16)dstrect->x*dst->format->BytesPerPixel; info.d_width = dstrect->w; @@ -105,22 +95,12 @@ static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect, RunBlit(&info); } - /* Re-encode the destination if it's RLE encoded */ - if ( dst->flags & SDL_RLEACCEL ) { - dst->flags &= ~SDL_RLEACCEL; /* stop lying */ - SDL_RLESurface(dst); - } - /* We need to unlock the surfaces if they're locked */ if ( dst_locked ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - video->UnlockHWSurface(this, dst); + SDL_UnlockSurface(dst); } if ( src_locked ) { - SDL_VideoDevice *video = current_video; - SDL_VideoDevice *this = current_video; - video->UnlockHWSurface(this, src); + SDL_UnlockSurface(src); } /* Blit is done! */ return(okay ? 0 : -1); diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 1ac517e10..0d444b0af 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -692,10 +692,6 @@ int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color) /* * Lock a surface to directly access the pixels - * -- Do not call this from any blit function, as SDL_DrawCursor() may recurse - * Instead, use: - * if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) - * video->LockHWSurface(video, surface); */ int SDL_LockSurface (SDL_Surface *surface) { @@ -724,10 +720,6 @@ int SDL_LockSurface (SDL_Surface *surface) } /* * Unlock a previously locked surface - * -- Do not call this from any blit function, as SDL_DrawCursor() may recurse - * Instead, use: - * if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) - * video->UnlockHWSurface(video, surface); */ void SDL_UnlockSurface (SDL_Surface *surface) {