Fixed a crash blitting RLE surfaces to RLE surfaces
authorSam Lantinga <slouken@libsdl.org>
Fri, 11 Oct 2002 07:56:36 +0000
changeset 5264314a501d7be
parent 525 f55cdaec12b9
child 527 5c74ac147358
Fixed a crash blitting RLE surfaces to RLE surfaces
src/video/SDL_RLEaccel.c
src/video/SDL_blit.c
src/video/SDL_surface.c
     1.1 --- a/src/video/SDL_RLEaccel.c	Fri Oct 11 07:55:22 2002 +0000
     1.2 +++ b/src/video/SDL_RLEaccel.c	Fri Oct 11 07:56:36 2002 +0000
     1.3 @@ -463,10 +463,8 @@
     1.4  	unsigned alpha;
     1.5  
     1.6  	/* Lock the destination if necessary */
     1.7 -	if ( dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
     1.8 -		SDL_VideoDevice *video = current_video;
     1.9 -		SDL_VideoDevice *this  = current_video;
    1.10 -		if ( video->LockHWSurface(this, dst) < 0 ) {
    1.11 +	if ( SDL_MUSTLOCK(dst) ) {
    1.12 +		if ( SDL_LockSurface(dst) < 0 ) {
    1.13  			return(-1);
    1.14  		}
    1.15  	}
    1.16 @@ -474,7 +472,7 @@
    1.17  	/* Set up the source and destination pointers */
    1.18  	x = dstrect->x;
    1.19  	y = dstrect->y;
    1.20 -	dstbuf = (Uint8 *)dst->pixels + dst->offset
    1.21 +	dstbuf = (Uint8 *)dst->pixels
    1.22  	         + y * dst->pitch + x * src->format->BytesPerPixel;
    1.23  	srcbuf = (Uint8 *)src->map->sw_data->aux_data;
    1.24  
    1.25 @@ -553,10 +551,8 @@
    1.26  
    1.27  done:
    1.28  	/* Unlock the destination if necessary */
    1.29 -	if ( dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
    1.30 -		SDL_VideoDevice *video = current_video;
    1.31 -		SDL_VideoDevice *this  = current_video;
    1.32 -		video->UnlockHWSurface(this, dst);
    1.33 +	if ( SDL_MUSTLOCK(dst) ) {
    1.34 +		SDL_UnlockSurface(dst);
    1.35  	}
    1.36  	return(0);
    1.37  }
    1.38 @@ -733,17 +729,15 @@
    1.39      SDL_PixelFormat *df = dst->format;
    1.40  
    1.41      /* Lock the destination if necessary */
    1.42 -    if(dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT)) {
    1.43 -	SDL_VideoDevice *video = current_video;
    1.44 -	SDL_VideoDevice *this  = current_video;
    1.45 -	if(video->LockHWSurface(this, dst) < 0) {
    1.46 +    if ( SDL_MUSTLOCK(dst) ) {
    1.47 +	if ( SDL_LockSurface(dst) < 0 ) {
    1.48  	    return -1;
    1.49  	}
    1.50      }
    1.51  
    1.52      x = dstrect->x;
    1.53      y = dstrect->y;
    1.54 -    dstbuf = (Uint8 *)dst->pixels + dst->offset
    1.55 +    dstbuf = (Uint8 *)dst->pixels
    1.56  	     + y * dst->pitch + x * df->BytesPerPixel;
    1.57      srcbuf = (Uint8 *)src->map->sw_data->aux_data + sizeof(RLEDestFormat);
    1.58  
    1.59 @@ -874,10 +868,8 @@
    1.60  
    1.61   done:
    1.62      /* Unlock the destination if necessary */
    1.63 -    if(dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT)) {
    1.64 -	SDL_VideoDevice *video = current_video;
    1.65 -	SDL_VideoDevice *this  = current_video;
    1.66 -	video->UnlockHWSurface(this, dst);
    1.67 +    if ( SDL_MUSTLOCK(dst) ) {
    1.68 +	SDL_UnlockSurface(dst);
    1.69      }
    1.70      return 0;
    1.71  }
    1.72 @@ -1117,7 +1109,7 @@
    1.73  	int x, y;
    1.74  	int h = surface->h, w = surface->w;
    1.75  	SDL_PixelFormat *sf = surface->format;
    1.76 -	Uint32 *src = (Uint32 *)((Uint8 *)surface->pixels + surface->offset);
    1.77 +	Uint32 *src = (Uint32 *)surface->pixels;
    1.78  	Uint8 *lastline = dst;	/* end of last non-blank line */
    1.79  
    1.80  	/* opaque counts are 8 or 16 bits, depending on target depth */
    1.81 @@ -1303,7 +1295,7 @@
    1.82  	}
    1.83  
    1.84  	/* Set up the conversion */
    1.85 -	srcbuf = (Uint8 *)surface->pixels+surface->offset;
    1.86 +	srcbuf = (Uint8 *)surface->pixels;
    1.87  	curbuf = srcbuf;
    1.88  	maxn = bpp == 4 ? 65535 : 255;
    1.89  	skip = run = 0;
    1.90 @@ -1409,10 +1401,8 @@
    1.91  	}
    1.92  
    1.93  	/* Lock the surface if it's in hardware */
    1.94 -	if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
    1.95 -		SDL_VideoDevice *video = current_video;
    1.96 -		SDL_VideoDevice *this  = current_video;
    1.97 -		if ( video->LockHWSurface(this, surface) < 0 ) {
    1.98 +	if ( SDL_MUSTLOCK(surface) ) {
    1.99 +		if ( SDL_LockSurface(surface) < 0 ) {
   1.100  			return(-1);
   1.101  		}
   1.102  	}
   1.103 @@ -1429,10 +1419,8 @@
   1.104  	}
   1.105  
   1.106  	/* Unlock the surface if it's in hardware */
   1.107 -	if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
   1.108 -		SDL_VideoDevice *video = current_video;
   1.109 -		SDL_VideoDevice *this  = current_video;
   1.110 -		video->UnlockHWSurface(this, surface);
   1.111 +	if ( SDL_MUSTLOCK(surface) ) {
   1.112 +		SDL_UnlockSurface(surface);
   1.113  	}
   1.114  
   1.115  	if(retcode < 0)
     2.1 --- a/src/video/SDL_blit.c	Fri Oct 11 07:55:22 2002 +0000
     2.2 +++ b/src/video/SDL_blit.c	Fri Oct 11 07:56:36 2002 +0000
     2.3 @@ -50,10 +50,8 @@
     2.4  
     2.5  	/* Lock the destination if it's in hardware */
     2.6  	dst_locked = 0;
     2.7 -	if ( dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
     2.8 -		SDL_VideoDevice *video = current_video;
     2.9 -		SDL_VideoDevice *this  = current_video;
    2.10 -		if ( video->LockHWSurface(this, dst) < 0 ) {
    2.11 +	if ( SDL_MUSTLOCK(dst) ) {
    2.12 +		if ( SDL_LockSurface(dst) < 0 ) {
    2.13  			okay = 0;
    2.14  		} else {
    2.15  			dst_locked = 1;
    2.16 @@ -61,35 +59,27 @@
    2.17  	}
    2.18  	/* Lock the source if it's in hardware */
    2.19  	src_locked = 0;
    2.20 -	if ( src->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
    2.21 -		SDL_VideoDevice *video = current_video;
    2.22 -		SDL_VideoDevice *this  = current_video;
    2.23 -		if ( video->LockHWSurface(this, src) < 0 ) {
    2.24 +	if ( SDL_MUSTLOCK(src) ) {
    2.25 +		if ( SDL_LockSurface(src) < 0 ) {
    2.26  			okay = 0;
    2.27  		} else {
    2.28  			src_locked = 1;
    2.29  		}
    2.30  	}
    2.31  
    2.32 -	/* Unencode the destination if it's RLE encoded */
    2.33 -	if ( dst->flags & SDL_RLEACCEL ) {
    2.34 -		SDL_UnRLESurface(dst, 1);
    2.35 -		dst->flags |= SDL_RLEACCEL;	/* save accel'd state */
    2.36 -	}
    2.37 -
    2.38  	/* Set up source and destination buffer pointers, and BLIT! */
    2.39  	if ( okay  && srcrect->w && srcrect->h ) {
    2.40  		SDL_BlitInfo info;
    2.41  		SDL_loblit RunBlit;
    2.42  
    2.43  		/* Set up the blit information */
    2.44 -		info.s_pixels = (Uint8 *)src->pixels + src->offset +
    2.45 +		info.s_pixels = (Uint8 *)src->pixels +
    2.46  				(Uint16)srcrect->y*src->pitch +
    2.47  				(Uint16)srcrect->x*src->format->BytesPerPixel;
    2.48  		info.s_width = srcrect->w;
    2.49  		info.s_height = srcrect->h;
    2.50  		info.s_skip=src->pitch-info.s_width*src->format->BytesPerPixel;
    2.51 -		info.d_pixels = (Uint8 *)dst->pixels + dst->offset +
    2.52 +		info.d_pixels = (Uint8 *)dst->pixels +
    2.53  				(Uint16)dstrect->y*dst->pitch +
    2.54  				(Uint16)dstrect->x*dst->format->BytesPerPixel;
    2.55  		info.d_width = dstrect->w;
    2.56 @@ -105,22 +95,12 @@
    2.57  		RunBlit(&info);
    2.58  	}
    2.59  
    2.60 -	/* Re-encode the destination if it's RLE encoded */
    2.61 -	if ( dst->flags & SDL_RLEACCEL ) {
    2.62 -	        dst->flags &= ~SDL_RLEACCEL; /* stop lying */
    2.63 -		SDL_RLESurface(dst);
    2.64 -	}
    2.65 -
    2.66  	/* We need to unlock the surfaces if they're locked */
    2.67  	if ( dst_locked ) {
    2.68 -		SDL_VideoDevice *video = current_video;
    2.69 -		SDL_VideoDevice *this  = current_video;
    2.70 -		video->UnlockHWSurface(this, dst);
    2.71 +		SDL_UnlockSurface(dst);
    2.72  	}
    2.73  	if ( src_locked ) {
    2.74 -		SDL_VideoDevice *video = current_video;
    2.75 -		SDL_VideoDevice *this  = current_video;
    2.76 -		video->UnlockHWSurface(this, src);
    2.77 +		SDL_UnlockSurface(src);
    2.78  	}
    2.79  	/* Blit is done! */
    2.80  	return(okay ? 0 : -1);
     3.1 --- a/src/video/SDL_surface.c	Fri Oct 11 07:55:22 2002 +0000
     3.2 +++ b/src/video/SDL_surface.c	Fri Oct 11 07:56:36 2002 +0000
     3.3 @@ -692,10 +692,6 @@
     3.4  
     3.5  /*
     3.6   * Lock a surface to directly access the pixels
     3.7 - * -- Do not call this from any blit function, as SDL_DrawCursor() may recurse
     3.8 - *    Instead, use:
     3.9 - *    if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )
    3.10 - *               video->LockHWSurface(video, surface);
    3.11   */
    3.12  int SDL_LockSurface (SDL_Surface *surface)
    3.13  {
    3.14 @@ -724,10 +720,6 @@
    3.15  }
    3.16  /*
    3.17   * Unlock a previously locked surface
    3.18 - * -- Do not call this from any blit function, as SDL_DrawCursor() may recurse
    3.19 - *    Instead, use:
    3.20 - *    if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )
    3.21 - *               video->UnlockHWSurface(video, surface);
    3.22   */
    3.23  void SDL_UnlockSurface (SDL_Surface *surface)
    3.24  {