Fix/improve framebuffer object reference counting.
[mesa.git] / src / mesa / drivers / x11 / xm_line.c
index 43de9a98ab7f0883e4b55360a8526ba214468740..c31054251599db1a0c9c0f4fff32e7f71c85416f 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.3
+ * Version:  6.5
  *
- * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -69,7 +69,7 @@ static void draw_points_ANY_pixmap( GLcontext *ctx, const SWvertex *vert )
                                                  color[2], color[3],
                                                  xmesa->pixelformat);
       XMesaSetForeground( dpy, gc, pixel );
-      x =                         (GLint) vert->win[0];
+      x = (GLint) vert->win[0];
       y = YFLIP( xrb, (GLint) vert->win[1] );
       XMesaDrawPoint( dpy, buffer, gc, x, y);
    }
@@ -117,8 +117,11 @@ void xmesa_choose_point( GLcontext *ctx )
 /**********************************************************************/
 
 
+#if CHAN_BITS == 8
+
+
 #define GET_XRB(XRB)  struct xmesa_renderbuffer *XRB = \
-   (struct xmesa_renderbuffer *) ctx->DrawBuffer->_ColorDrawBuffers[0][0]
+   xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0][0]->Wrapped)
 
 
 /*
@@ -533,13 +536,58 @@ void xmesa_choose_point( GLcontext *ctx )
 
 
 
-static swrast_line_func get_line_func( GLcontext *ctx )
+
+#ifndef XFree86Server
+/**
+ * Draw fast, XOR line with XDrawLine in front color buffer.
+ * WARNING: this isn't fully OpenGL conformant because different pixels
+ * will be hit versus using the other line functions.
+ * Don't use the code in X server GLcore module since we need a wrapper
+ * for the XSetLineAttributes() function call.
+ */
+static void
+xor_line(GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1)
+{
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
+   XMesaDisplay *dpy = xmesa->xm_visual->display;
+   XMesaGC gc = xmesa->xm_buffer->gc;
+   GET_XRB(xrb);
+   unsigned long pixel = xmesa_color_to_pixel(ctx,
+                                              vert1->color[0], vert1->color[1],
+                                              vert1->color[2], vert1->color[3],
+                                              xmesa->pixelformat);
+   int x0 = (int) vert0->win[0];
+   int y0 = YFLIP(xrb, (GLint) vert0->win[1]);
+   int x1 = (int) vert1->win[0];
+   int y1 = YFLIP(xrb, (GLint) vert1->win[1]);
+   XMesaSetForeground(dpy, gc, pixel);
+   XMesaSetFunction(dpy, gc, GXxor);
+   XSetLineAttributes(dpy, gc, (int) ctx->Line.Width,
+                      LineSolid, CapButt, JoinMiter);
+   XDrawLine(dpy, xrb->pixmap, gc, x0, y0, x1, y1);
+   XMesaSetFunction(dpy, gc, GXcopy);  /* this gc is used elsewhere */
+}
+#endif /* XFree86Server */
+
+
+#endif /* CHAN_BITS == 8 */
+
+
+/**
+ * Return pointer to line drawing function, or NULL if we should use a
+ * swrast fallback.
+ */
+static swrast_line_func
+get_line_func(GLcontext *ctx)
 {
+#if CHAN_BITS == 8
    XMesaContext xmesa = XMESA_CONTEXT(ctx);
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    int depth = GET_VISUAL_DEPTH(xmesa->xm_visual);
-   struct xmesa_renderbuffer *xrb = (struct xmesa_renderbuffer *)
-      ctx->DrawBuffer->_ColorDrawBuffers[0][0];
+   struct xmesa_renderbuffer *xrb;
+
+   if (CHAN_BITS != 8)
+      return NULL;
 
    if ((ctx->DrawBuffer->_ColorDrawBufferMask[0]
         & (BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT)) == 0)
@@ -551,6 +599,8 @@ static swrast_line_func get_line_func( GLcontext *ctx )
    if (ctx->Line.StippleFlag)             return (swrast_line_func) NULL;
    if (swrast->_RasterMask & MULTI_DRAW_BIT) return (swrast_line_func) NULL;
 
+   xrb = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0][0]->Wrapped);
+
    if (xrb->ximage
        && swrast->_RasterMask==DEPTH_BIT
        && ctx->Depth.Func==GL_LESS
@@ -611,14 +661,29 @@ static swrast_line_func get_line_func( GLcontext *ctx )
       }
    }
 
+#ifndef XFree86Server
+   if (ctx->DrawBuffer->_NumColorDrawBuffers[0] == 1
+       && ctx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT
+       && swrast->_RasterMask == LOGIC_OP_BIT
+       && ctx->Color.LogicOp == GL_XOR
+       && !ctx->Line.StippleFlag
+       && !ctx->Line.SmoothFlag) {
+      return xor_line;
+   }
+#endif /* XFree86Server */
+
+#endif /* CHAN_BITS == 8 */
    return (swrast_line_func) NULL;
 }
 
-/* Override for the swrast line-selection function.  Try to use one
+
+/**
+ * Override for the swrast line-selection function.  Try to use one
  * of our internal line functions, otherwise fall back to the
  * standard swrast functions.
  */
-void xmesa_choose_line( GLcontext *ctx )
+void
+xmesa_choose_line(GLcontext *ctx)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);