Merge branch 'llvm-cliptest-viewport'
[mesa.git] / src / mesa / drivers / dri / mach64 / mach64_ioctl.c
index 752aa6ef4a77b1c677d52606cdf8e7d0db4dcafe..0146e0d05151776f5cb4b41b83814bc4cca035db 100644 (file)
@@ -1,4 +1,4 @@
-/* $XFree86$ */ /* -*- mode: c; c-basic-offset: 3 -*- */
+/* -*- mode: c; c-basic-offset: 3 -*- */
 /*
  * Copyright 2000 Gareth Hughes
  * All Rights Reserved.
@@ -35,8 +35,8 @@
 #include "mach64_ioctl.h"
 #include "mach64_tex.h"
 
-#include "imports.h"
-#include "macros.h"
+#include "main/imports.h"
+#include "main/macros.h"
 
 #include "swrast/swrast.h"
 
@@ -105,7 +105,7 @@ void mach64FlushVerticesLocked( mach64ContextPtr mmesa )
    int prim = mmesa->hw_primitive;
    int fd = mmesa->driScreen->fd;
    drm_mach64_vertex_t vertex;
-   int i, ret;
+   int i;
 
    mmesa->num_verts = 0;
    mmesa->vert_used = 0;
@@ -123,6 +123,9 @@ void mach64FlushVerticesLocked( mach64ContextPtr mmesa )
       mmesa->dirty |= MACH64_UPLOAD_CLIPRECTS;
 
    if ( !count || !(mmesa->dirty & MACH64_UPLOAD_CLIPRECTS) ) {
+      int to = 0;
+      int ret;
+
       /* FIXME: Is this really necessary */
       if ( nbox == 1 )
         mmesa->sarea->nbox = 0;
@@ -133,7 +136,10 @@ void mach64FlushVerticesLocked( mach64ContextPtr mmesa )
       vertex.buf = buffer;
       vertex.used = count;
       vertex.discard = 1;
-      ret = drmCommandWrite( fd, DRM_MACH64_VERTEX, &vertex, sizeof(drm_mach64_vertex_t) );
+      do {
+        ret = drmCommandWrite( fd, DRM_MACH64_VERTEX,
+                               &vertex, sizeof(drm_mach64_vertex_t) );
+      } while ( ( ret == -EAGAIN ) && ( to++ < MACH64_TIMEOUT ) );
       if ( ret ) {
         UNLOCK_HARDWARE( mmesa );
         fprintf( stderr, "Error flushing vertex buffer: return = %d\n", ret );
@@ -146,6 +152,8 @@ void mach64FlushVerticesLocked( mach64ContextPtr mmesa )
         int nr = MIN2( i + MACH64_NR_SAREA_CLIPRECTS, nbox );
         drm_clip_rect_t *b = mmesa->sarea->boxes;
         int discard = 0;
+        int to = 0;
+        int ret;
 
         mmesa->sarea->nbox = nr - i;
         for ( ; i < nr ; i++ ) {
@@ -164,7 +172,10 @@ void mach64FlushVerticesLocked( mach64ContextPtr mmesa )
         vertex.buf = buffer;
         vertex.used = count;
         vertex.discard = discard;
-        ret = drmCommandWrite( fd, DRM_MACH64_VERTEX, &vertex, sizeof(drm_mach64_vertex_t) );
+        do {
+           ret = drmCommandWrite( fd, DRM_MACH64_VERTEX,
+                                  &vertex, sizeof(drm_mach64_vertex_t) );
+        } while ( ( ret == -EAGAIN ) && ( to++ < MACH64_TIMEOUT ) );
         if ( ret ) {
            UNLOCK_HARDWARE( mmesa );
            fprintf( stderr, "Error flushing vertex buffer: return = %d\n", ret );
@@ -180,14 +191,15 @@ void mach64FlushVerticesLocked( mach64ContextPtr mmesa )
  * Texture uploads
  */
 
-void mach64FireBlitLocked( mach64ContextPtr mmesa, drmBufPtr buffer,
+void mach64FireBlitLocked( mach64ContextPtr mmesa, void *buffer,
                           GLint offset, GLint pitch, GLint format,
                           GLint x, GLint y, GLint width, GLint height )
 {
    drm_mach64_blit_t blit;
-   GLint ret;
+   int to = 0;
+   int ret;
 
-   blit.idx = buffer->idx;
+   blit.buf = buffer;
    blit.offset = offset;
    blit.pitch = pitch;
    blit.format = format;
@@ -196,8 +208,10 @@ void mach64FireBlitLocked( mach64ContextPtr mmesa, drmBufPtr buffer,
    blit.width = width;
    blit.height = height;
 
-   ret = drmCommandWrite( mmesa->driFd, DRM_MACH64_BLIT, 
-                          &blit, sizeof(drm_mach64_blit_t) );
+   do {
+      ret = drmCommandWrite( mmesa->driFd, DRM_MACH64_BLIT, 
+                            &blit, sizeof(drm_mach64_blit_t) );
+   } while ( ( ret == -EAGAIN ) && ( to++ < MACH64_TIMEOUT ) );
 
    if ( ret ) {
       UNLOCK_HARDWARE( mmesa );
@@ -265,7 +279,7 @@ static int mach64WaitForFrameCompletion( mach64ContextPtr mmesa )
 
 /* Copy the back color buffer to the front color buffer.
  */
-void mach64CopyBuffer( const __DRIdrawablePrivate *dPriv )
+void mach64CopyBuffer( __DRIdrawable *dPriv )
 {
    mach64ContextPtr mmesa;
    GLint nbox, i, ret;
@@ -306,7 +320,7 @@ void mach64CopyBuffer( const __DRIdrawablePrivate *dPriv )
 #endif
 
    UNLOCK_HARDWARE( mmesa );
-   driWaitForVBlank( dPriv, &mmesa->vbl_seq, mmesa->vblank_flags, &missed_target );
+   driWaitForVBlank( dPriv, &missed_target );
    LOCK_HARDWARE( mmesa );
 
    /* use front buffer cliprects */
@@ -651,19 +665,18 @@ void mach64PerformanceBoxesLocked( mach64ContextPtr mmesa )
  * Buffer clear
  */
 
-static void mach64DDClear( GLcontext *ctx, GLbitfield mask, GLboolean all,
-                          GLint cx, GLint cy, GLint cw, GLint ch )
+static void mach64DDClear( struct gl_context *ctx, GLbitfield mask )
 {
    mach64ContextPtr mmesa = MACH64_CONTEXT( ctx );
-   __DRIdrawablePrivate *dPriv = mmesa->driDrawable;
+   __DRIdrawable *dPriv = mmesa->driDrawable;
    drm_mach64_clear_t clear;
    GLuint flags = 0;
    GLint i;
    GLint ret;
+   GLint cx, cy, cw, ch;
 
    if ( MACH64_DEBUG & DEBUG_VERBOSE_API ) {
-      fprintf( stderr, "%s: all=%d %d,%d %dx%d\n",
-              __FUNCTION__, all, cx, cy, cw, ch );
+      fprintf( stderr, "mach64DDClear\n");
    }
 
 #if ENABLE_PERF_BOXES
@@ -683,30 +696,35 @@ static void mach64DDClear( GLcontext *ctx, GLbitfield mask, GLboolean all,
       mmesa->new_state = save_state & ~(MACH64_NEW_MASKS | MACH64_NEW_CLIP);
    }
 
-   if ( mask & DD_FRONT_LEFT_BIT ) {
+   if ( mask & BUFFER_BIT_FRONT_LEFT ) {
       flags |= MACH64_FRONT;
-      mask &= ~DD_FRONT_LEFT_BIT;
+      mask &= ~BUFFER_BIT_FRONT_LEFT;
    }
 
-   if ( mask & DD_BACK_LEFT_BIT ) {
+   if ( mask & BUFFER_BIT_BACK_LEFT ) {
       flags |= MACH64_BACK;
-      mask &= ~DD_BACK_LEFT_BIT;
+      mask &= ~BUFFER_BIT_BACK_LEFT;
    }
 
-   if ( ( mask & DD_DEPTH_BIT ) && ctx->Depth.Mask ) {
+   if ( ( mask & BUFFER_BIT_DEPTH ) && ctx->Depth.Mask ) {
       flags |= MACH64_DEPTH;
-      mask &= ~DD_DEPTH_BIT;
+      mask &= ~BUFFER_BIT_DEPTH;
    }
 
    if ( mask )
-      _swrast_Clear( ctx, mask, all, cx, cy, cw, ch );
+      _swrast_Clear( ctx, mask );
 
    if ( !flags )
       return;
 
    LOCK_HARDWARE( mmesa );
 
-   /* This needs to be in the locked region, so updated drawable origin is used */
+   /* 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 */
    cx += mmesa->drawX;
    cy  = mmesa->drawY + dPriv->h - cy - ch;
@@ -723,7 +741,8 @@ static void mach64DDClear( GLcontext *ctx, GLbitfield mask, GLboolean all,
       drm_clip_rect_t *b = mmesa->sarea->boxes;
       GLint n = 0;
 
-      if ( !all ) {
+      if (cw != dPriv->w || ch != dPriv->h) {
+         /* clear subregion */
         for ( ; i < nr ; i++ ) {
            GLint x = box[i].x1;
            GLint y = box[i].y1;
@@ -745,6 +764,7 @@ static void mach64DDClear( GLcontext *ctx, GLbitfield mask, GLboolean all,
            n++;
         }
       } else {
+         /* clear whole window */
         for ( ; i < nr ; i++ ) {
            *b++ = box[i];
            n++;