changeset 1643:51038e80ae59

More general fix for bug #189 The clipping is done at a higher level, and the low level functions are passed clipped rectangles. Drivers which don't support source clipping have not been changed, so the image will be squished instead of clipped, but at least they will no longer crash when the destination rect was out of bounds.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 17 Apr 2006 06:47:23 +0000
parents f1211a4b7380
children 8a858076f39d
files src/video/SDL_yuv.c src/video/SDL_yuv_sw.c src/video/SDL_yuv_sw_c.h src/video/SDL_yuvfuncs.h src/video/bwindow/SDL_sysyuv.cc src/video/bwindow/SDL_sysyuv.h src/video/directfb/SDL_DirectFB_yuv.c src/video/directfb/SDL_DirectFB_yuv.h src/video/photon/SDL_ph_events.c src/video/photon/SDL_phyuv.c src/video/photon/SDL_phyuv_c.h src/video/ps2gs/SDL_gsyuv.c src/video/ps2gs/SDL_gsyuv_c.h src/video/windx5/SDL_dx5yuv.c src/video/windx5/SDL_dx5yuv_c.h src/video/x11/SDL_x11yuv.c src/video/x11/SDL_x11yuv_c.h
diffstat 17 files changed, 150 insertions(+), 129 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/SDL_yuv.c	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/SDL_yuv.c	Mon Apr 17 06:47:23 2006 +0000
@@ -75,7 +75,55 @@
 
 int SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect)
 {
-	return overlay->hwfuncs->Display(current_video, overlay, dstrect);
+	SDL_Rect src, dst;
+	int srcx, srcy, srcw, srch;
+	int dstx, dsty, dstw, dsth;
+
+	/* Clip the rectangle to the screen area */
+	srcx = 0;
+	srcy = 0;
+	srcw = overlay->w;
+	srch = overlay->h;
+	dstx = dstrect->x;
+	dsty = dstrect->y;
+	dstw = dstrect->w;
+	dsth = dstrect->h;
+	if ( dstx < 0 ) {
+		srcw += (dstx * overlay->w) / dstrect->w;
+		dstw += dstx;
+		srcx -= (dstx * overlay->w) / dstrect->w;
+		dstx = 0;
+	}
+	if ( (dstx+dstw) > current_video->screen->w ) {
+		int extra = (dstx+dstw - current_video->screen->w);
+		srcw -= (extra * overlay->w) / dstrect->w;
+		dstw -= extra;
+	}
+	if ( dsty < 0 ) {
+		srch += (dsty * overlay->h) / dstrect->h;
+		dsth += dsty;
+		srcy -= (dsty * overlay->h) / dstrect->h;
+		dsty = 0;
+	}
+	if ( (dsty+dsth) > current_video->screen->h ) {
+		int extra = (dsty+dsth - current_video->screen->h);
+		srch -= (extra * overlay->h) / dstrect->h;
+		dsth -= extra;
+	}
+	if ( srcw <= 0 || srch <= 0 ||
+	     srch <= 0 || dsth <= 0 ) {
+		return 0;
+	}
+	/* Ugh, I can't wait for SDL_Rect to be int values */
+	src.x = srcx;
+	src.y = srcy;
+	src.w = srcw;
+	src.h = srch;
+	dst.x = dstx;
+	dst.y = dsty;
+	dst.w = dstw;
+	dst.h = dsth;
+	return overlay->hwfuncs->Display(current_video, overlay, &src, &dst);
 }
 
 void SDL_FreeYUVOverlay(SDL_Overlay *overlay)
--- a/src/video/SDL_yuv_sw.c	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/SDL_yuv_sw.c	Mon Apr 17 06:47:23 2006 +0000
@@ -1164,43 +1164,44 @@
 	return;
 }
 
-int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
+int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
 {
 	struct private_yuvhwdata *swdata;
-	SDL_Surface *stretch;
-	SDL_Surface *display;
+	int stretch;
 	int scale_2x;
+	SDL_Surface *display;
 	Uint8 *lum, *Cr, *Cb;
-	Uint8 *dst;
+	Uint8 *dstp;
 	int mod;
 
 	swdata = overlay->hwdata;
+	stretch = 0;
 	scale_2x = 0;
-	stretch = 0;
-	if ( (overlay->w != dstrect->w) || (overlay->h != dstrect->h) ) {
-		if ( (dstrect->w == 2*overlay->w) &&
-		     (dstrect->h == 2*overlay->h) ) {
+	if ( src->x || src->y || src->w < overlay->w || src->h < overlay->h ) {
+		stretch = 1;
+	} else if ( (src->w != dst->w) || (src->h != dst->h) ) {
+		if ( (dst->w == 2*src->w) &&
+		     (dst->h == 2*src->h) ) {
 			scale_2x = 1;
 		} else {
-			if ( ! swdata->stretch ) {
-				display = swdata->display;
-				swdata->stretch = SDL_CreateRGBSurface(
-					SDL_SWSURFACE,
-					overlay->w, overlay->h,
-					display->format->BitsPerPixel,
-					display->format->Rmask,
-					display->format->Gmask,
-					display->format->Bmask, 0);
-				if ( ! swdata->stretch ) {
-					return(-1);
-				}
-			}
-			stretch = swdata->stretch;
+			stretch = 1;
 		}
 	}
-
 	if ( stretch ) {
-		display = stretch;
+		if ( ! swdata->stretch ) {
+			display = swdata->display;
+			swdata->stretch = SDL_CreateRGBSurface(
+				SDL_SWSURFACE,
+				overlay->w, overlay->h,
+				display->format->BitsPerPixel,
+				display->format->Rmask,
+				display->format->Gmask,
+				display->format->Bmask, 0);
+			if ( ! swdata->stretch ) {
+				return(-1);
+			}
+		}
+		display = swdata->stretch;
 	} else {
 		display = swdata->display;
 	}
@@ -1240,31 +1241,31 @@
 		}
 	}
 	if ( stretch ) {
-		dst = (Uint8 *)stretch->pixels;
+		dstp = (Uint8 *)swdata->stretch->pixels;
 	} else {
-		dst = (Uint8 *)display->pixels
-			+ dstrect->x * display->format->BytesPerPixel
-			+ dstrect->y * display->pitch;
+		dstp = (Uint8 *)display->pixels
+			+ dst->x * display->format->BytesPerPixel
+			+ dst->y * display->pitch;
 	}
 	mod = (display->pitch / display->format->BytesPerPixel);
 
 	if ( scale_2x ) {
 		mod -= (overlay->w * 2);
 		swdata->Display2X(swdata->colortab, swdata->rgb_2_pix,
-		                  lum, Cr, Cb, dst, overlay->h, overlay->w,mod);
+		                  lum, Cr, Cb, dstp, overlay->h, overlay->w, mod);
 	} else {
 		mod -= overlay->w;
 		swdata->Display1X(swdata->colortab, swdata->rgb_2_pix,
-		                  lum, Cr, Cb, dst, overlay->h, overlay->w,mod);
+		                  lum, Cr, Cb, dstp, overlay->h, overlay->w, mod);
 	}
 	if ( SDL_MUSTLOCK(display) ) {
 		SDL_UnlockSurface(display);
 	}
 	if ( stretch ) {
 		display = swdata->display;
-		SDL_SoftStretch(stretch, NULL, display, dstrect);
+		SDL_SoftStretch(swdata->stretch, src, display, dst);
 	}
-	SDL_UpdateRects(display, 1, dstrect);
+	SDL_UpdateRects(display, 1, dst);
 
 	return(0);
 }
--- a/src/video/SDL_yuv_sw_c.h	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/SDL_yuv_sw_c.h	Mon Apr 17 06:47:23 2006 +0000
@@ -32,6 +32,6 @@
 
 extern void SDL_UnlockYUV_SW(_THIS, SDL_Overlay *overlay);
 
-extern int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
+extern int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
 
 extern void SDL_FreeYUV_SW(_THIS, SDL_Overlay *overlay);
--- a/src/video/SDL_yuvfuncs.h	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/SDL_yuvfuncs.h	Mon Apr 17 06:47:23 2006 +0000
@@ -32,6 +32,6 @@
 struct private_yuvhwfuncs {
 	int (*Lock)(_THIS, SDL_Overlay *overlay);
 	void (*Unlock)(_THIS, SDL_Overlay *overlay);
-	int (*Display)(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
+	int (*Display)(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
 	void (*FreeHW)(_THIS, SDL_Overlay *overlay);
 };
--- a/src/video/bwindow/SDL_sysyuv.cc	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/bwindow/SDL_sysyuv.cc	Mon Apr 17 06:47:23 2006 +0000
@@ -263,7 +263,7 @@
     overlay->hwdata->locked = 0;
 }
 
-int BE_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect)
+int BE_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect *dst)
 {
     if ((overlay == NULL) || (overlay->hwdata==NULL)
         || (overlay->hwdata->bview==NULL) || (SDL_Win->View() == NULL))
@@ -277,11 +277,11 @@
     if (SDL_Win->IsFullScreen()) {
     	int left,top;
     	SDL_Win->GetXYOffset(left,top);
-	    bview->MoveTo(left+dstrect->x,top+dstrect->y);
+	    bview->MoveTo(left+dst->x,top+dst->y);
     } else {
-	    bview->MoveTo(dstrect->x,dstrect->y);
+	    bview->MoveTo(dst->x,dst->y);
     }
-    bview->ResizeTo(dstrect->w,dstrect->h);
+    bview->ResizeTo(dst->w,dst->h);
     bview->Flush();
 	if (overlay->hwdata->first_display) {
 		bview->Show();
--- a/src/video/bwindow/SDL_sysyuv.h	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/bwindow/SDL_sysyuv.h	Mon Apr 17 06:47:23 2006 +0000
@@ -65,7 +65,7 @@
 extern SDL_Overlay* BE_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface* display);
 extern int BE_LockYUVOverlay(_THIS, SDL_Overlay* overlay);
 extern void BE_UnlockYUVOverlay(_THIS, SDL_Overlay* overlay);
-extern int BE_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect);
+extern int BE_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect* dst);
 extern void BE_FreeYUVOverlay(_THIS, SDL_Overlay* overlay);
 
 };
--- a/src/video/directfb/SDL_DirectFB_yuv.c	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/directfb/SDL_DirectFB_yuv.c	Mon Apr 17 06:47:23 2006 +0000
@@ -241,7 +241,7 @@
   surface->Unlock (surface);
 }
 
-int DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dst)
+int DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
 {
   DFBResult              ret;
   DFBDisplayLayerConfig  conf;
--- a/src/video/directfb/SDL_DirectFB_yuv.h	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/directfb/SDL_DirectFB_yuv.h	Mon Apr 17 06:47:23 2006 +0000
@@ -32,7 +32,7 @@
 
 extern void DirectFB_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay);
 
-extern int DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
+extern int DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
 
 extern void DirectFB_FreeYUVOverlay(_THIS, SDL_Overlay *overlay);
 
--- a/src/video/photon/SDL_ph_events.c	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/photon/SDL_ph_events.c	Mon Apr 17 06:47:23 2006 +0000
@@ -245,15 +245,19 @@
                    int lockedstate=current_overlay->hwdata->locked;
                    int chromastate=current_overlay->hwdata->ischromakey;
                    int error;
-                   SDL_Rect target;
+                   SDL_Rect src, dst;
 
                    current_overlay->hwdata->locked=1;
-                   target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
-                   target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
-                   target.w=current_overlay->hwdata->CurrentViewPort.size.w;
-                   target.h=current_overlay->hwdata->CurrentViewPort.size.h;
+                   src.x = 0;
+                   src.y = 0;
+                   src.w = current_overlay->w;
+                   src.y = current_overlay->h;
+                   dst.x=current_overlay->hwdata->CurrentViewPort.pos.x;
+                   dst.y=current_overlay->hwdata->CurrentViewPort.pos.y;
+                   dst.w=current_overlay->hwdata->CurrentViewPort.size.w;
+                   dst.h=current_overlay->hwdata->CurrentViewPort.size.h;
                    current_overlay->hwdata->ischromakey=0;
-                   error=ph_DisplayYUVOverlay(this, current_overlay, &target);
+                   error=ph_DisplayYUVOverlay(this, current_overlay, &src, &dst);
                    if (!error)
                    {
                        current_overlay->hwdata->ischromakey=chromastate;
@@ -306,15 +310,19 @@
                     {
                         int lockedstate=current_overlay->hwdata->locked;
                         int error;
-                        SDL_Rect target;
+                        SDL_Rect src, dst;
 
                         current_overlay->hwdata->locked=1;
-                        target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
-                        target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
-                        target.w=current_overlay->hwdata->CurrentViewPort.size.w;
-                        target.h=current_overlay->hwdata->CurrentViewPort.size.h;
+                        src.x = 0;
+                        src.y = 0;
+                        src.w = current_overlay->w;
+                        src.y = current_overlay->h;
+                        dst.x=current_overlay->hwdata->CurrentViewPort.pos.x;
+                        dst.y=current_overlay->hwdata->CurrentViewPort.pos.y;
+                        dst.w=current_overlay->hwdata->CurrentViewPort.size.w;
+                        dst.h=current_overlay->hwdata->CurrentViewPort.size.h;
                         current_overlay->hwdata->forcedredraw=1;
-                        error=ph_DisplayYUVOverlay(this, current_overlay, &target);
+                        error=ph_DisplayYUVOverlay(this, current_overlay, &src, &dst);
                         if (!error)
                         {
                             current_overlay->hwdata->forcedredraw=0;
--- a/src/video/photon/SDL_phyuv.c	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/photon/SDL_phyuv.c	Mon Apr 17 06:47:23 2006 +0000
@@ -334,7 +334,7 @@
     overlay->hwdata->locked = 0;
 }
 
-int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect)
+int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect* dst)
 {
     int rtncode;
     PhPoint_t pos;
@@ -362,10 +362,10 @@
     }
 
     /* If CurrentViewPort position/size has been changed, then move/resize the viewport */
-    if ((overlay->hwdata->CurrentViewPort.pos.x != dstrect->x) ||
-        (overlay->hwdata->CurrentViewPort.pos.y != dstrect->y) ||
-        (overlay->hwdata->CurrentViewPort.size.w != dstrect->w) ||
-        (overlay->hwdata->CurrentViewPort.size.h != dstrect->h) ||
+    if ((overlay->hwdata->CurrentViewPort.pos.x != dst->x) ||
+        (overlay->hwdata->CurrentViewPort.pos.y != dst->y) ||
+        (overlay->hwdata->CurrentViewPort.size.w != dst->w) ||
+        (overlay->hwdata->CurrentViewPort.size.h != dst->h) ||
         (overlay->hwdata->scaler_on==0) || (winchanged==1) ||
         (overlay->hwdata->forcedredraw==1))
     {
@@ -381,7 +381,7 @@
 
             /* Draw the new rectangle of the chroma color at the viewport position */
             PgSetFillColor(overlay->hwdata->chromakey);
-            PgDrawIRect(dstrect->x, dstrect->y, dstrect->x+dstrect->w-1, dstrect->y+dstrect->h-1, Pg_DRAW_FILL);
+            PgDrawIRect(dst->x, dst->y, dst->x+dst->w-1, dst->y+dst->h-1, Pg_DRAW_FILL);
             PgFlush();
         }
 
@@ -389,13 +389,13 @@
         overlay->hwdata->scaler_on = 1;
 
         PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, PtWidgetRid(window), &windowextent);
-        overlay->hwdata->CurrentViewPort.pos.x = pos.x-windowextent.ul.x+dstrect->x;
-        overlay->hwdata->CurrentViewPort.pos.y = pos.y-windowextent.ul.y+dstrect->y;
-        overlay->hwdata->CurrentViewPort.size.w = dstrect->w;
-        overlay->hwdata->CurrentViewPort.size.h = dstrect->h;
+        overlay->hwdata->CurrentViewPort.pos.x = pos.x-windowextent.ul.x+dst->x;
+        overlay->hwdata->CurrentViewPort.pos.y = pos.y-windowextent.ul.y+dst->y;
+        overlay->hwdata->CurrentViewPort.size.w = dst->w;
+        overlay->hwdata->CurrentViewPort.size.h = dst->h;
         PhAreaToRect(&overlay->hwdata->CurrentViewPort, &overlay->hwdata->props.viewport);
-        overlay->hwdata->CurrentViewPort.pos.x = dstrect->x;
-        overlay->hwdata->CurrentViewPort.pos.y = dstrect->y;
+        overlay->hwdata->CurrentViewPort.pos.x = dst->x;
+        overlay->hwdata->CurrentViewPort.pos.y = dst->y;
 
         rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
 
--- a/src/video/photon/SDL_phyuv_c.h	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/photon/SDL_phyuv_c.h	Mon Apr 17 06:47:23 2006 +0000
@@ -56,7 +56,7 @@
 extern SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface* display);
 extern int ph_LockYUVOverlay(_THIS, SDL_Overlay* overlay);
 extern void ph_UnlockYUVOverlay(_THIS, SDL_Overlay* overlay);
-extern int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect);
+extern int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect* dst);
 extern void ph_FreeYUVOverlay(_THIS, SDL_Overlay* overlay);
 
 #endif /* __SDL_PH_YUV_H__ */
--- a/src/video/ps2gs/SDL_gsyuv.c	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/ps2gs/SDL_gsyuv.c	Mon Apr 17 06:47:23 2006 +0000
@@ -315,7 +315,7 @@
 	return;
 }
 
-int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
+int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
 {
 	struct private_yuvhwdata *hwdata;
 	__u32 cmd;
@@ -423,8 +423,8 @@
 
 	/* Send the current image to the screen and scale it */
 	screen = this->screen;
-	x = (unsigned int)dstrect->x;
-	y = (unsigned int)dstrect->y;
+	x = (unsigned int)dst->x;
+	y = (unsigned int)dst->y;
 	if ( screen->offset ) {
 		x += (screen->offset % screen->pitch) /
 		     screen->format->BytesPerPixel;
@@ -432,8 +432,8 @@
 	}
 	y += screen_image.y;
 	*hwdata->stretch_x1y1 = (x * 16) + ((y * 16) << 16);
-	x += (unsigned int)dstrect->w;
-	y += (unsigned int)dstrect->h;
+	x += (unsigned int)dst->w;
+	y += (unsigned int)dst->h;
 	*hwdata->stretch_x2y2 = (x * 16) + ((y * 16) << 16);
 	return ioctl(console_fd, PS2IOC_SENDL, &hwdata->plist);
 }
--- a/src/video/ps2gs/SDL_gsyuv_c.h	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/ps2gs/SDL_gsyuv_c.h	Mon Apr 17 06:47:23 2006 +0000
@@ -32,6 +32,6 @@
 
 extern void GS_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay);
 
-extern int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
+extern int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
 
 extern void GS_FreeYUVOverlay(_THIS, SDL_Overlay *overlay);
--- a/src/video/windx5/SDL_dx5yuv.c	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/windx5/SDL_dx5yuv.c	Mon Apr 17 06:47:23 2006 +0000
@@ -247,30 +247,30 @@
 	IDirectDrawSurface3_Unlock(surface, NULL);
 }
 
-int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
+int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
 {
 	HRESULT result;
 	LPDIRECTDRAWSURFACE3 surface;
-	RECT src, dst;
+	RECT srcrect, dstrect;
 
 	surface = overlay->hwdata->surface;
-	src.top = 0;
-	src.bottom = overlay->h;
-	src.left = 0;
-	src.right = overlay->w;
-	dst.top = SDL_bounds.top+dstrect->y;
-	dst.left = SDL_bounds.left+dstrect->x;
-	dst.bottom = dst.top+dstrect->h;
-	dst.right = dst.left+dstrect->w;
+	srcrect.top = src->y;
+	srcrect.bottom = srcrect.top+src->h;
+	srcrect.left = src->x;
+	srcrect.right = srcrect.left+src->w;
+	dstrect.top = SDL_bounds.top+dst->y;
+	dstrect.left = SDL_bounds.left+dst->x;
+	dstrect.bottom = dstrect.top+dst->h;
+	dstrect.right = dstrect.left+dst->w;
 #ifdef USE_DIRECTX_OVERLAY
-	result = IDirectDrawSurface3_UpdateOverlay(surface, &src,
-				SDL_primary, &dst, DDOVER_SHOW, NULL);
+	result = IDirectDrawSurface3_UpdateOverlay(surface, &srcrect,
+				SDL_primary, &dstrect, DDOVER_SHOW, NULL);
 	if ( result != DD_OK ) {
 		SetDDerror("DirectDrawSurface3::UpdateOverlay", result);
 		return(-1);
 	}
 #else
-	result = IDirectDrawSurface3_Blt(SDL_primary, &dst, surface, &src,
+	result = IDirectDrawSurface3_Blt(SDL_primary, &dstrect, surface, &srcrect,
 							DDBLT_WAIT, NULL);
 	if ( result != DD_OK ) {
 		SetDDerror("DirectDrawSurface3::Blt", result);
--- a/src/video/windx5/SDL_dx5yuv_c.h	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/windx5/SDL_dx5yuv_c.h	Mon Apr 17 06:47:23 2006 +0000
@@ -33,6 +33,6 @@
 
 extern void DX5_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay);
 
-extern int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
+extern int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
 
 extern void DX5_FreeYUVOverlay(_THIS, SDL_Overlay *overlay);
--- a/src/video/x11/SDL_x11yuv.c	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/x11/SDL_x11yuv.c	Mon Apr 17 06:47:23 2006 +0000
@@ -354,62 +354,26 @@
 	return;
 }
 
-int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
+int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
 {
 	struct private_yuvhwdata *hwdata;
-	int srcx, srcy, srcw, srch;
-	int dstx, dsty, dstw, dsth;
 
 	hwdata = overlay->hwdata;
 
-	/* Clip the rectangle to the screen area */
-	srcx = 0;
-	srcy = 0;
-	srcw = overlay->w;
-	srch = overlay->h;
-	dstx = dstrect->x;
-	dsty = dstrect->y;
-	dstw = dstrect->w;
-	dsth = dstrect->h;
-	if ( dstx < 0 ) {
-		srcw += (dstx * overlay->w) / dstrect->w;
-		dstw += dstx;
-		srcx -= (dstx * overlay->w) / dstrect->w;
-		dstx = 0;
-	}
-	if ( (dstx+dstw) > this->screen->w ) {
-		int extra = (dstx+dstw - this->screen->w);
-		srcw -= (extra * overlay->w) / dstrect->w;
-		dstw -= extra;
-	}
-	if ( dsty < 0 ) {
-		srch += (dsty * overlay->h) / dstrect->h;
-		dsth += dsty;
-		srcy -= (dsty * overlay->h) / dstrect->h;
-		dsty = 0;
-	}
-	if ( (dsty+dsth) > this->screen->h ) {
-		int extra = (dsty+dsth - this->screen->h);
-		srch -= (extra * overlay->h) / dstrect->h;
-		dsth -= extra;
-	}
-	if ( srcw <= 0 || srch <= 0 ||
-	     srch <= 0 || dsth <= 0 ) {
-		return;
-	}
-
 #ifndef NO_SHARED_MEMORY
 	if ( hwdata->yuv_use_mitshm ) {
 		SDL_NAME(XvShmPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
 	              hwdata->image,
-		      srcx, srcy, srcw, srch, dstx, dsty, dstw, dsth, False);
+		      src->x, src->y, src->w, src->h,
+		      dst->x, dst->y, dst->w, dst->h, False);
 	}
 	else
 #endif
 	{
 		SDL_NAME(XvPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
 				     hwdata->image,
-		                     srcx, srcy, srcw, srch, dstx, dsty, dstw, dsth);
+		                     src->x, src->y, src->w, src->h,
+		                     dst->x, dst->y, dst->w, dst->h);
 	}
 	XSync(GFX_Display, False);
 	return(0);
--- a/src/video/x11/SDL_x11yuv_c.h	Mon Apr 17 05:38:33 2006 +0000
+++ b/src/video/x11/SDL_x11yuv_c.h	Mon Apr 17 06:47:23 2006 +0000
@@ -34,7 +34,7 @@
 
 extern void X11_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay);
 
-extern int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
+extern int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
 
 extern void X11_FreeYUVOverlay(_THIS, SDL_Overlay *overlay);