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