704bf42
From 85577ae6bad8fd8673b9abc81e7f2531ae64fcec Mon Sep 17 00:00:00 2001
704bf42
From: Dave Airlie <airlied@redhat.com>
704bf42
Date: Mon, 21 Dec 2009 11:47:19 +1000
704bf42
Subject: [PATCH] fb: backport fb changes from master for src window operations.
704bf42
704bf42
This rolls up the following commits and also keeps the image_from_pict
704bf42
API compatiblity. It introduces a new image_from_pict_18 API that is
704bf42
used by the server leaving the old API alone.
704bf42
704bf42
I've rolled this up as I don't want to introduce ABI breaks in bisection.
704bf42
704bf42
a72c65e9176c51de95db2fdbf4c5d946a4911695 fb: Adjust transform or composite coordinates for pixman operations
704bf42
bd567061c8b84b268d9bbb01bc4d8981feefb862 Split fbGetDrawable into fbGetDrawablePixmap and fbGetPixmapBitsData
704bf42
61335052972a78d67c0ba74f902273b34c63a198 Revert "Fix clipping when windows are used as sources"
704bf42
071b3c1810d9f2602173acc8578caac20e0b771e Revert "Use IncludeInferiors when copying windows before compositing."
704bf42
8e640d6b131d2865a9725d8997023865b0ef3d69 Revert "Reserve space for two GC values in copy_drawable()."
704bf42
704bf42
Signed-off-by: Dave Airlie <airlied@redhat.com>
704bf42
---
704bf42
 fb/fb.h        |   76 ++++++++++++++++++++++++++++---------------------
704bf42
 fb/fbpict.c    |   85 +++++++++++++++++++++++++++++++++++++++----------------
704bf42
 fb/fbtrap.c    |    6 ++-
704bf42
 fb/wfbrename.h |    1 +
704bf42
 4 files changed, 108 insertions(+), 60 deletions(-)
704bf42
704bf42
diff --git a/fb/fb.h b/fb/fb.h
704bf42
index 37de71e..8b2839a 100644
704bf42
--- a/fb/fb.h
704bf42
+++ b/fb/fb.h
704bf42
@@ -700,38 +700,41 @@ typedef struct {
704bf42
 #define __fbPixOffXPix(pPix)	(__fbPixDrawableX(pPix))
704bf42
 #define __fbPixOffYPix(pPix)	(__fbPixDrawableY(pPix))
704bf42
 
704bf42
-#define fbGetDrawable(pDrawable, pointer, stride, bpp, xoff, yoff) { \
704bf42
-    PixmapPtr   _pPix; \
704bf42
-    if ((pDrawable)->type != DRAWABLE_PIXMAP) { \
704bf42
-	_pPix = fbGetWindowPixmap(pDrawable); \
704bf42
-	(xoff) = __fbPixOffXWin(_pPix); \
704bf42
-	(yoff) = __fbPixOffYWin(_pPix); \
704bf42
-    } else { \
704bf42
-	_pPix = (PixmapPtr) (pDrawable); \
704bf42
-	(xoff) = __fbPixOffXPix(_pPix); \
704bf42
-	(yoff) = __fbPixOffYPix(_pPix); \
704bf42
-    } \
704bf42
-    fbPrepareAccess(pDrawable); \
704bf42
-    (pointer) = (FbBits *) _pPix->devPrivate.ptr; \
704bf42
-    (stride) = ((int) _pPix->devKind) / sizeof (FbBits); (void)(stride); \
704bf42
-    (bpp) = _pPix->drawable.bitsPerPixel;  (void)(bpp); \
704bf42
+#define fbGetDrawablePixmap(pDrawable, pixmap, xoff, yoff) {			\
704bf42
+    if ((pDrawable)->type != DRAWABLE_PIXMAP) { 				\
704bf42
+	(pixmap) = fbGetWindowPixmap(pDrawable);				\
704bf42
+	(xoff) = __fbPixOffXWin(pixmap); 					\
704bf42
+	(yoff) = __fbPixOffYWin(pixmap); 					\
704bf42
+    } else { 									\
704bf42
+	(pixmap) = (PixmapPtr) (pDrawable);					\
704bf42
+	(xoff) = __fbPixOffXPix(pixmap); 					\
704bf42
+	(yoff) = __fbPixOffYPix(pixmap); 					\
704bf42
+    } 										\
704bf42
+    fbPrepareAccess(pDrawable); 						\
704bf42
 }
704bf42
 
704bf42
-#define fbGetStipDrawable(pDrawable, pointer, stride, bpp, xoff, yoff) { \
704bf42
-    PixmapPtr   _pPix; \
704bf42
-    if ((pDrawable)->type != DRAWABLE_PIXMAP) { \
704bf42
-	_pPix = fbGetWindowPixmap(pDrawable); \
704bf42
-	(xoff) = __fbPixOffXWin(_pPix); \
704bf42
-	(yoff) = __fbPixOffYWin(_pPix); \
704bf42
-    } else { \
704bf42
-	_pPix = (PixmapPtr) (pDrawable); \
704bf42
-	(xoff) = __fbPixOffXPix(_pPix); \
704bf42
-	(yoff) = __fbPixOffYPix(_pPix); \
704bf42
-    } \
704bf42
-    fbPrepareAccess(pDrawable); \
704bf42
-    (pointer) = (FbStip *) _pPix->devPrivate.ptr; \
704bf42
-    (stride) = ((int) _pPix->devKind) / sizeof (FbStip); (void)(stride); \
704bf42
-    (bpp) = _pPix->drawable.bitsPerPixel; (void)(bpp); \
704bf42
+#define fbGetPixmapBitsData(pixmap, pointer, stride, bpp) {			\
704bf42
+    (pointer) = (FbBits *) (pixmap)->devPrivate.ptr; 			       	\
704bf42
+    (stride) = ((int) (pixmap)->devKind) / sizeof (FbBits); (void)(stride);	\
704bf42
+    (bpp) = (pixmap)->drawable.bitsPerPixel;  (void)(bpp); 			\
704bf42
+}
704bf42
+
704bf42
+#define fbGetPixmapStipData(pixmap, pointer, stride, bpp) {			\
704bf42
+    (pointer) = (FbStip *) (pixmap)->devPrivate.ptr; 			       	\
704bf42
+    (stride) = ((int) (pixmap)->devKind) / sizeof (FbStip); (void)(stride);	\
704bf42
+    (bpp) = (pixmap)->drawable.bitsPerPixel;  (void)(bpp); 			\
704bf42
+}
704bf42
+
704bf42
+#define fbGetDrawable(pDrawable, pointer, stride, bpp, xoff, yoff) { 		\
704bf42
+    PixmapPtr   _pPix; 								\
704bf42
+    fbGetDrawablePixmap(pDrawable, _pPix, xoff, yoff); 				\
704bf42
+    fbGetPixmapBitsData(_pPix, pointer, stride, bpp);				\
704bf42
+}
704bf42
+
704bf42
+#define fbGetStipDrawable(pDrawable, pointer, stride, bpp, xoff, yoff) { 	\
704bf42
+    PixmapPtr   _pPix; 								\
704bf42
+    fbGetDrawablePixmap(pDrawable, _pPix, xoff, yoff);				\
704bf42
+    fbGetPixmapStipData(_pPix, pointer, stride, bpp);				\
704bf42
 }
704bf42
 
704bf42
 /*
704bf42
@@ -2079,9 +2082,16 @@ fbFillRegionSolid (DrawablePtr	pDrawable,
704bf42
 		   FbBits	xor);
704bf42
 
704bf42
 extern _X_EXPORT pixman_image_t *
704bf42
-image_from_pict (PicturePtr pict,
704bf42
-		 Bool       has_clip,
704bf42
-		 Bool       is_src);
704bf42
+image_from_pict (PicturePtr	pict,
704bf42
+		 Bool		has_clip,
704bf42
+		 Bool		is_src);
704bf42
+
704bf42
+extern _X_EXPORT pixman_image_t *
704bf42
+image_from_pict_18 (PicturePtr	pict,
704bf42
+		 Bool		has_clip,
704bf42
+		 int		*xoff,
704bf42
+		 int		*yoff);
704bf42
+
704bf42
 extern _X_EXPORT void free_pixman_pict (PicturePtr, pixman_image_t *);
704bf42
 
704bf42
 #endif /* _FB_H_ */
704bf42
diff --git a/fb/fbpict.c b/fb/fbpict.c
704bf42
index 8fdaa58..f9f4343 100644
704bf42
--- a/fb/fbpict.c
704bf42
+++ b/fb/fbpict.c
704bf42
@@ -158,19 +158,24 @@ fbComposite (CARD8      op,
704bf42
 	     CARD16     height)
704bf42
 {
704bf42
     pixman_image_t *src, *mask, *dest;
704bf42
+    int src_xoff, src_yoff;
704bf42
+    int msk_xoff, msk_yoff;
704bf42
+    int dst_xoff, dst_yoff;
704bf42
     
704bf42
-    miCompositeSourceValidate (pSrc, xSrc, ySrc, width, height);
704bf42
+    miCompositeSourceValidate (pSrc, xSrc - xDst, ySrc - yDst, width, height);
704bf42
     if (pMask)
704bf42
-	miCompositeSourceValidate (pMask, xMask, yMask, width, height);
704bf42
+	miCompositeSourceValidate (pMask, xMask - xDst, yMask - yDst, width, height);
704bf42
     
704bf42
-    src = image_from_pict (pSrc, TRUE, TRUE);
704bf42
-    mask = image_from_pict (pMask, TRUE, TRUE);
704bf42
-    dest = image_from_pict (pDst, TRUE, FALSE);
704bf42
+    src = image_from_pict_18 (pSrc, FALSE, &src_xoff, &src_yoff);
704bf42
+    mask = image_from_pict_18 (pMask, FALSE, &msk_xoff, &msk_yoff);
704bf42
+    dest = image_from_pict_18 (pDst, TRUE, &dst_xoff, &dst_yoff);
704bf42
 
704bf42
     if (src && dest && !(pMask && !mask))
704bf42
     {
704bf42
 	pixman_image_composite (op, src, mask, dest,
704bf42
-				xSrc, ySrc, xMask, yMask, xDst, yDst,
704bf42
+				xSrc + src_xoff, ySrc + src_yoff,
704bf42
+				xMask + msk_xoff, yMask + msk_yoff,
704bf42
+				xDst + dst_xoff, yDst + dst_yoff,
704bf42
 				width, height);
704bf42
     }
704bf42
 
704bf42
@@ -270,22 +275,22 @@ create_conical_gradient_image (PictGradient *gradient)
704bf42
 
704bf42
 static pixman_image_t *
704bf42
 create_bits_picture (PicturePtr pict,
704bf42
-		     Bool       has_clip)
704bf42
+		     Bool       has_clip,
704bf42
+		     int	*xoff,
704bf42
+		     int	*yoff)
704bf42
 {
704bf42
+    PixmapPtr pixmap;
704bf42
     FbBits *bits;
704bf42
     FbStride stride;
704bf42
-    int bpp, xoff, yoff;
704bf42
+    int bpp;
704bf42
     pixman_image_t *image;
704bf42
     
704bf42
-    fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff);
704bf42
-
704bf42
-    bits = (FbBits*)((CARD8*)bits +
704bf42
-		     (pict->pDrawable->y + yoff) * stride * sizeof(FbBits) +
704bf42
-		     (pict->pDrawable->x + xoff) * (bpp / 8));
704bf42
+    fbGetDrawablePixmap (pict->pDrawable, pixmap, *xoff, *yoff);
704bf42
+    fbGetPixmapBitsData(pixmap, bits, stride, bpp);
704bf42
 
704bf42
     image = pixman_image_create_bits (
704bf42
 	pict->format,
704bf42
-	pict->pDrawable->width, pict->pDrawable->height,
704bf42
+	pixmap->drawable.width, pixmap->drawable.height,
704bf42
 	(uint32_t *)bits, stride * sizeof (FbStride));
704bf42
     
704bf42
     
704bf42
@@ -311,30 +316,52 @@ create_bits_picture (PicturePtr pict,
704bf42
 	if (pict->clientClipType != CT_NONE)
704bf42
 	    pixman_image_set_has_client_clip (image, TRUE);
704bf42
 
704bf42
-	pixman_region_translate (pict->pCompositeClip, - pict->pDrawable->x, - pict->pDrawable->y);
704bf42
+	if (*xoff || *yoff)
704bf42
+	    pixman_region_translate (pict->pCompositeClip, *xoff, *yoff);
704bf42
 
704bf42
 	pixman_image_set_clip_region (image, pict->pCompositeClip);
704bf42
 
704bf42
-	pixman_region_translate (pict->pCompositeClip, pict->pDrawable->x, pict->pDrawable->y);
704bf42
+	if (*xoff || *yoff)
704bf42
+	    pixman_region_translate (pict->pCompositeClip, -*xoff, -*yoff);
704bf42
     }
704bf42
     
704bf42
     /* Indexed table */
704bf42
     if (pict->pFormat->index.devPrivate)
704bf42
 	pixman_image_set_indexed (image, pict->pFormat->index.devPrivate);
704bf42
 
704bf42
+    /* Add in drawable origin to position within the image */
704bf42
+    *xoff += pict->pDrawable->x;
704bf42
+    *yoff += pict->pDrawable->y;
704bf42
+
704bf42
     return image;
704bf42
 }
704bf42
 
704bf42
 static void
704bf42
-set_image_properties (pixman_image_t *image, PicturePtr pict)
704bf42
+set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
704bf42
 {
704bf42
     pixman_repeat_t repeat;
704bf42
     pixman_filter_t filter;
704bf42
     
704bf42
     if (pict->transform)
704bf42
     {
704bf42
-	pixman_image_set_transform (
704bf42
-	    image, (pixman_transform_t *)pict->transform);
704bf42
+	/* For source images, adjust the transform to account
704bf42
+	 * for the drawable offset within the pixman image,
704bf42
+	 * then set the offset to 0 as it will be used
704bf42
+	 * to compute positions within the transformed image.
704bf42
+	 */
704bf42
+	if (!has_clip) {
704bf42
+	    struct pixman_transform	adjusted;
704bf42
+
704bf42
+	    adjusted = *pict->transform;
704bf42
+	    pixman_transform_translate(&adjusted,
704bf42
+				       NULL,
704bf42
+				       pixman_int_to_fixed(*xoff),
704bf42
+				       pixman_int_to_fixed(*yoff));
704bf42
+	    pixman_image_set_transform (image, &adjusted);
704bf42
+	    *xoff = 0;
704bf42
+	    *yoff = 0;
704bf42
+	} else
704bf42
+	    pixman_image_set_transform (image, pict->transform);
704bf42
     }
704bf42
     
704bf42
     switch (pict->repeatType)
704bf42
@@ -361,7 +388,8 @@ set_image_properties (pixman_image_t *image, PicturePtr pict)
704bf42
     
704bf42
     if (pict->alphaMap)
704bf42
     {
704bf42
-	pixman_image_t *alpha_map = image_from_pict (pict->alphaMap, TRUE, TRUE);
704bf42
+	int alpha_xoff, alpha_yoff;
704bf42
+	pixman_image_t *alpha_map = image_from_pict_18 (pict->alphaMap, FALSE, &alpha_xoff, &alpha_yoff);
704bf42
 	
704bf42
 	pixman_image_set_alpha_map (
704bf42
 	    image, alpha_map, pict->alphaOrigin.x, pict->alphaOrigin.y);
704bf42
@@ -393,10 +421,9 @@ set_image_properties (pixman_image_t *image, PicturePtr pict)
704bf42
     pixman_image_set_source_clipping (image, TRUE);
704bf42
 }
704bf42
 
704bf42
+
704bf42
 pixman_image_t *
704bf42
-image_from_pict (PicturePtr pict,
704bf42
-		 Bool has_clip,
704bf42
-		 Bool is_src)
704bf42
+image_from_pict_18 (PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
704bf42
 {
704bf42
     pixman_image_t *image = NULL;
704bf42
 
704bf42
@@ -405,7 +432,7 @@ image_from_pict (PicturePtr pict,
704bf42
 
704bf42
     if (pict->pDrawable)
704bf42
     {
704bf42
-	image = create_bits_picture (pict, has_clip);
704bf42
+	image = create_bits_picture (pict, has_clip, xoff, yoff);
704bf42
     }
704bf42
     else if (pict->pSourcePict)
704bf42
     {
704bf42
@@ -429,11 +456,18 @@ image_from_pict (PicturePtr pict,
704bf42
     }
704bf42
     
704bf42
     if (image)
704bf42
-	set_image_properties (image, pict);
704bf42
+	set_image_properties (image, pict, has_clip, xoff, yoff);
704bf42
     
704bf42
     return image;
704bf42
 }
704bf42
 
704bf42
+pixman_image_t *
704bf42
+image_from_pict (PicturePtr pict, Bool has_clip, Bool is_src)
704bf42
+{
704bf42
+    int xoff = 0, yoff = 0;
704bf42
+    return image_from_pict_18(pict, has_clip, &xoff, &yoff);
704bf42
+}
704bf42
+
704bf42
 void
704bf42
 free_pixman_pict (PicturePtr pict, pixman_image_t *image)
704bf42
 {
704bf42
@@ -463,3 +497,4 @@ fbPictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats)
704bf42
 
704bf42
     return TRUE;
704bf42
 }
704bf42
+
704bf42
diff --git a/fb/fbtrap.c b/fb/fbtrap.c
704bf42
index b1e1eff..5b5aeae 100644
704bf42
--- a/fb/fbtrap.c
704bf42
+++ b/fb/fbtrap.c
704bf42
@@ -40,7 +40,8 @@ fbAddTraps (PicturePtr	pPicture,
704bf42
 	    int		ntrap,
704bf42
 	    xTrap	*traps)
704bf42
 {
704bf42
-    pixman_image_t *image = image_from_pict (pPicture, FALSE, FALSE);
704bf42
+    int image_xoff, image_yoff;
704bf42
+    pixman_image_t *image = image_from_pict_18 (pPicture, FALSE, &image_xoff, &image_yoff);
704bf42
 
704bf42
     if (!image)
704bf42
 	return;
704bf42
@@ -56,7 +57,8 @@ fbRasterizeTrapezoid (PicturePtr    pPicture,
704bf42
 		      int	    x_off,
704bf42
 		      int	    y_off)
704bf42
 {
704bf42
-    pixman_image_t *image = image_from_pict (pPicture, FALSE, FALSE);
704bf42
+    int	mask_xoff, mask_yoff;
704bf42
+    pixman_image_t *image = image_from_pict_18 (pPicture, FALSE, &mask_xoff, &mask_yoff);
704bf42
 
704bf42
     if (!image)
704bf42
 	return;
704bf42
diff --git a/fb/wfbrename.h b/fb/wfbrename.h
704bf42
index 73ee510..e9cdca8 100644
704bf42
--- a/fb/wfbrename.h
704bf42
+++ b/fb/wfbrename.h
704bf42
@@ -187,4 +187,5 @@
704bf42
 #define fbZeroSegment wfbZeroSegment
704bf42
 #define free_pixman_pict wfb_free_pixman_pict
704bf42
 #define image_from_pict wfb_image_from_pict
704bf42
+#define image_from_pict_18 wfb_image_from_pict_18
704bf42
 #define composeFunctions wfbComposeFunctions
704bf42
-- 
704bf42
1.6.5.2
704bf42