Merge branch '7.8'
[mesa.git] / src / glx / drisw_glx.c
index 5a47e4a097f47f4fa643f018d33adcf71a632a74..786faff81c1733651f27f3adc06f1d8f027d10ed 100644 (file)
@@ -55,10 +55,6 @@ struct __GLXDRIdrawablePrivateRec
    XImage *ximage;
 };
 
-/**
- * swrast loader functions
- */
-
 static Bool
 XCreateDrawable(__GLXDRIdrawablePrivate * pdp,
                 Display * dpy, XID drawable, int visualid)
@@ -78,12 +74,13 @@ XCreateDrawable(__GLXDRIdrawablePrivate * pdp,
    XChangeGC(dpy, pdp->swapgc, GCFunction, &gcvalues);
    XChangeGC(dpy, pdp->swapgc, GCGraphicsExposures, &gcvalues);
 
-   /* create XImage  */
+   /* visual */
    visTemp.screen = DefaultScreen(dpy);
    visTemp.visualid = visualid;
    visMask = (VisualScreenMask | VisualIDMask);
    pdp->visinfo = XGetVisualInfo(dpy, visMask, &visTemp, &num_visuals);
 
+   /* create XImage */
    pdp->ximage = XCreateImage(dpy,
                               pdp->visinfo->visual,
                               pdp->visinfo->depth,
@@ -106,6 +103,10 @@ XDestroyDrawable(__GLXDRIdrawablePrivate * pdp, Display * dpy, XID drawable)
    XFreeGC(dpy, pdp->swapgc);
 }
 
+/**
+ * swrast loader functions
+ */
+
 static void
 swrastGetDrawableInfo(__DRIdrawable * draw,
                       int *x, int *y, int *w, int *h,
@@ -128,10 +129,32 @@ swrastGetDrawableInfo(__DRIdrawable * draw,
    *h = uh;
 }
 
+/**
+ * Align renderbuffer pitch.
+ *
+ * This should be chosen by the driver and the loader (libGL, xserver/glx)
+ * should use the driver provided pitch.
+ *
+ * It seems that the xorg loader (that is the xserver loading swrast_dri for
+ * indirect rendering, not client-side libGL) requires that the pitch is
+ * exactly the image width padded to 32 bits. XXX
+ *
+ * The above restriction can probably be overcome by using ScratchPixmap and
+ * CopyArea in the xserver, similar to ShmPutImage, and setting the width of
+ * the scratch pixmap to 'pitch / cpp'.
+ */
+static inline int
+bytes_per_line(unsigned pitch_bits, unsigned mul)
+{
+   unsigned mask = mul - 1;
+
+   return ((pitch_bits + mask) & ~mask) / 8;
+}
+
 static void
-swrastPutImage2(__DRIdrawable * draw, int op,
-                int x, int y, int w, int h,
-                char *data, int pitch, void *loaderPrivate)
+swrastPutImage(__DRIdrawable * draw, int op,
+               int x, int y, int w, int h,
+               char *data, void *loaderPrivate)
 {
    __GLXDRIdrawablePrivate *pdp = loaderPrivate;
    __GLXDRIdrawable *pdraw = &(pdp->base);
@@ -157,7 +180,7 @@ swrastPutImage2(__DRIdrawable * draw, int op,
    ximage->data = data;
    ximage->width = w;
    ximage->height = h;
-   ximage->bytes_per_line = pitch;
+   ximage->bytes_per_line = bytes_per_line(w * ximage->bits_per_pixel, 32);
 
    XPutImage(dpy, drawable, gc, ximage, 0, 0, x, y, w, h);
 
@@ -165,9 +188,9 @@ swrastPutImage2(__DRIdrawable * draw, int op,
 }
 
 static void
-swrastGetImage2(__DRIdrawable * read,
-                int x, int y, int w, int h,
-                char *data, int pitch, void *loaderPrivate)
+swrastGetImage(__DRIdrawable * read,
+               int x, int y, int w, int h,
+               char *data, void *loaderPrivate)
 {
    __GLXDRIdrawablePrivate *prp = loaderPrivate;
    __GLXDRIdrawable *pread = &(prp->base);
@@ -181,59 +204,13 @@ swrastGetImage2(__DRIdrawable * read,
    ximage->data = data;
    ximage->width = w;
    ximage->height = h;
-   ximage->bytes_per_line = pitch;
+   ximage->bytes_per_line = bytes_per_line(w * ximage->bits_per_pixel, 32);
 
    XGetSubImage(dpy, readable, x, y, w, h, ~0L, ZPixmap, ximage, 0, 0);
 
    ximage->data = NULL;
 }
 
-/**
- * Renderbuffer pitch alignment (in bits).
- *
- * This should be chosen by the driver and the loader (libGL, xserver/glx)
- * should use the driver provided pitch. I had a comment that the xserver
- * requires padding images to 32 bits. Is this a hard requirement or can it use
- * the driver pitch without extra copies ? XXX
- */
-static inline int
-bytes_per_line(unsigned pitch_bits, unsigned mul)
-{
-   unsigned mask = mul - 1;
-
-   return ((pitch_bits + mask) & ~mask) / 8;
-}
-
-static void
-swrastPutImage(__DRIdrawable * draw, int op,
-               int x, int y, int w, int h,
-               char *data, void *loaderPrivate)
-{
-   __GLXDRIdrawablePrivate *pdp = loaderPrivate;
-   int bpp, pitch;
-
-   bpp = pdp->ximage->bits_per_pixel;
-
-   pitch = bytes_per_line(w * bpp, 32);
-
-   swrastPutImage2(draw, op, x, y, w, h, data, pitch, loaderPrivate);
-}
-
-static void
-swrastGetImage(__DRIdrawable * read,
-               int x, int y, int w, int h,
-               char *data, void *loaderPrivate)
-{
-   __GLXDRIdrawablePrivate *prp = loaderPrivate;
-   int bpp, pitch;
-
-   bpp = prp->ximage->bits_per_pixel;
-
-   pitch = bytes_per_line(w * bpp, 32);
-
-   swrastGetImage2(read, x, y, w, h, data, pitch, loaderPrivate);
-}
-
 static const __DRIswrastLoaderExtension swrastLoaderExtension = {
    {__DRI_SWRAST_LOADER, __DRI_SWRAST_LOADER_VERSION},
    swrastGetDrawableInfo,