Merge branch 'llvm-cliptest-viewport'
[mesa.git] / src / mesa / drivers / dri / i810 / i810ioctl.c
index 1e49d1782e403ecd0771fdc8b517db464c95adb5..4b004d54c6548bf93853a437daddb6d2eac46364 100644 (file)
@@ -1,18 +1,17 @@
-/* $XFree86: xc/lib/GL/mesa/src/drv/i810/i810ioctl.c,v 1.7 2002/10/30 12:51:33 alanh Exp $ */
 
 #include <unistd.h> /* for usleep() */
 
-#include "glheader.h"
-#include "mtypes.h"
-#include "macros.h"
-#include "dd.h"
+#include "main/glheader.h"
+#include "main/mtypes.h"
+#include "main/macros.h"
+#include "main/dd.h"
 #include "swrast/swrast.h"
-#include "mm.h"
+#include "main/mm.h"
 
 #include "i810screen.h"
 #include "i810_dri.h"
 
-#include "i810context.h"
+#include "main/context.h"
 #include "i810ioctl.h"
 #include "i810state.h"
 
@@ -48,14 +47,13 @@ static drmBufPtr i810_get_buffer_ioctl( i810ContextPtr imesa )
 
 #define DEPTH_SCALE ((1<<16)-1)
 
-static void i810Clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
-                      GLint cx, GLint cy, GLint cw, GLint ch ) 
+static void i810Clear( struct gl_context *ctx, GLbitfield mask )
 {
    i810ContextPtr imesa = I810_CONTEXT( ctx );
-   __DRIdrawablePrivate *dPriv = imesa->driDrawable;
-   const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask);
+   __DRIdrawable *dPriv = imesa->driDrawable;
+   const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask[0]);
    drmI810Clear clear;
-   int i;
+   unsigned int i;
 
    clear.flags = 0;
    clear.clear_color = imesa->ClearColor;
@@ -63,25 +61,33 @@ static void i810Clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
 
    I810_FIREVERTICES( imesa );
        
-   if ((mask & DD_FRONT_LEFT_BIT) && colorMask == ~0) {
+   if ((mask & BUFFER_BIT_FRONT_LEFT) && colorMask == ~0U) {
       clear.flags |= I810_FRONT;
-      mask &= ~DD_FRONT_LEFT_BIT;
+      mask &= ~BUFFER_BIT_FRONT_LEFT;
    }
 
-   if ((mask & DD_BACK_LEFT_BIT) && colorMask == ~0) {
+   if ((mask & BUFFER_BIT_BACK_LEFT) && colorMask == ~0U) {
       clear.flags |= I810_BACK;
-      mask &= ~DD_BACK_LEFT_BIT;
+      mask &= ~BUFFER_BIT_BACK_LEFT;
    }
 
-   if (mask & DD_DEPTH_BIT) {
+   if (mask & BUFFER_BIT_DEPTH) {
       if (ctx->Depth.Mask) 
         clear.flags |= I810_DEPTH;
-      mask &= ~DD_DEPTH_BIT;
+      mask &= ~BUFFER_BIT_DEPTH;
    }
 
    if (clear.flags) {
+      GLint cx, cy, cw, ch;
+
       LOCK_HARDWARE( imesa );
 
+      /* compute region after locking: */
+      cx = ctx->DrawBuffer->_Xmin;
+      cy = ctx->DrawBuffer->_Ymin;
+      cw = ctx->DrawBuffer->_Xmax - cx;
+      ch = ctx->DrawBuffer->_Ymax - cy;
+
       /* flip top to bottom */
       cy = dPriv->h-cy-ch;
       cx += imesa->drawX;
@@ -89,12 +95,13 @@ static void i810Clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
 
       for (i = 0 ; i < imesa->numClipRects ; ) 
       {         
-        int nr = MIN2(i + I810_NR_SAREA_CLIPRECTS, imesa->numClipRects);
+        unsigned int nr = MIN2(i + I810_NR_SAREA_CLIPRECTS, imesa->numClipRects);
         drm_clip_rect_t *box = imesa->pClipRects;       
         drm_clip_rect_t *b = (drm_clip_rect_t *)imesa->sarea->boxes;
         int n = 0;
 
-        if (!all) {
+        if (cw != dPriv->w || ch != dPriv->h) {
+            /* clear sub region */
            for ( ; i < nr ; i++) {
               GLint x = box[i].x1;
               GLint y = box[i].y1;
@@ -116,6 +123,7 @@ static void i810Clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
               n++;
            }
         } else {
+            /* clear whole buffer */
            for ( ; i < nr ; i++) {
               *b++ = box[i];
               n++;
@@ -132,7 +140,7 @@ static void i810Clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
    }
 
    if (mask) 
-      _swrast_Clear( ctx, mask, all, cx, cy, cw, ch );
+      _swrast_Clear( ctx, mask );
 }
 
 
@@ -141,7 +149,7 @@ static void i810Clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
 /*
  * Copy the back buffer to the front buffer. 
  */
-void i810CopyBuffer( const __DRIdrawablePrivate *dPriv ) 
+void i810CopyBuffer( const __DRIdrawable *dPriv ) 
 {
    i810ContextPtr imesa;
    drm_clip_rect_t *pbox;
@@ -189,7 +197,7 @@ void i810CopyBuffer( const __DRIdrawablePrivate *dPriv )
 /*
  * XXX implement when full-screen extension is done.
  */
-void i810PageFlip( const __DRIdrawablePrivate *dPriv ) 
+void i810PageFlip( const __DRIdrawable *dPriv ) 
 {
   i810ContextPtr imesa;
   int tmp, ret;
@@ -225,7 +233,7 @@ void i810PageFlip( const __DRIdrawablePrivate *dPriv )
    }
 
   /*  i810SetDrawBuffer( imesa->glCtx, imesa->glCtx->Color.DriverDrawBuffer );*/
-  i810DrawBuffer( imesa->glCtx, imesa->glCtx->Color.DrawBuffer );
+  i810DrawBuffer( imesa->glCtx, imesa->glCtx->Color.DrawBuffer[0] );
   imesa->upload_cliprects = GL_TRUE;
   imesa->lastSwap = tmp;
   return;
@@ -491,13 +499,13 @@ int i810_check_copy(int fd)
    return(drmCommandNone(fd, DRM_I810_DOCOPY));
 }
 
-static void i810Flush( GLcontext *ctx )
+static void i810Flush( struct gl_context *ctx )
 {
    i810ContextPtr imesa = I810_CONTEXT( ctx );
    I810_FIREVERTICES( imesa );
 }
 
-static void i810Finish( GLcontext *ctx  ) 
+static void i810Finish( struct gl_context *ctx  ) 
 {
    i810ContextPtr imesa = I810_CONTEXT( ctx );
    i810DmaFinish( imesa );