Merge commit 'origin/master' into drm-gem
[mesa.git] / src / mesa / drivers / dri / r200 / r200_lock.c
index c2c5d30c582494e592c17395fc3c8937737c5012..f89b526a31202f8362ffa00dd8adb0758e8ec6c1 100644 (file)
@@ -1,5 +1,4 @@
-/* $XFree86$ */
-/**************************************************************************
+/*
 Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
 
 The Weather Channel (TM) funded Tungsten Graphics to develop the
 Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
 
 The Weather Channel (TM) funded Tungsten Graphics to develop the
@@ -32,13 +31,16 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * Authors:
  *   Keith Whitwell <keith@tungstengraphics.com>
  */
  * Authors:
  *   Keith Whitwell <keith@tungstengraphics.com>
  */
-
 #include "r200_context.h"
 #include "r200_lock.h"
 #include "r200_tex.h"
 #include "r200_state.h"
 #include "r200_ioctl.h"
 
 #include "r200_context.h"
 #include "r200_lock.h"
 #include "r200_tex.h"
 #include "r200_state.h"
 #include "r200_ioctl.h"
 
+#include "drirenderbuffer.h"
+
+
 #if DEBUG_LOCKING
 char *prevLockFile = NULL;
 int prevLockLine = 0;
 #if DEBUG_LOCKING
 char *prevLockFile = NULL;
 int prevLockLine = 0;
@@ -49,23 +51,11 @@ int prevLockLine = 0;
 static void
 r200UpdatePageFlipping( r200ContextPtr rmesa )
 {
 static void
 r200UpdatePageFlipping( r200ContextPtr rmesa )
 {
-   int use_back;
-   rmesa->doPageFlip = rmesa->sarea->pfAllowPageFlip;
-
-   use_back = (rmesa->glCtx->Color._DrawDestMask == BACK_LEFT_BIT);
-   use_back ^= (rmesa->sarea->pfCurrentPage == 1);
-   
-   if (use_back) {
-        rmesa->state.color.drawOffset = rmesa->r200Screen->backOffset;
-        rmesa->state.color.drawPitch  = rmesa->r200Screen->backPitch;
-   } else {
-        rmesa->state.color.drawOffset = rmesa->r200Screen->frontOffset;
-        rmesa->state.color.drawPitch  = rmesa->r200Screen->frontPitch;
+   rmesa->doPageFlip = rmesa->sarea->pfState;
+   if (rmesa->glCtx->WinSysDrawBuffer) {
+      driFlipRenderbuffers(rmesa->glCtx->WinSysDrawBuffer,
+                           rmesa->sarea->pfCurrentPage);
    }
    }
-
-   R200_STATECHANGE( rmesa, ctx );
-   rmesa->hw.ctx.cmd[CTX_RB3D_COLOROFFSET] = rmesa->state.color.drawOffset;
-   rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH]  = rmesa->state.color.drawPitch;
 }
 
 
 }
 
 
@@ -80,8 +70,10 @@ r200UpdatePageFlipping( r200ContextPtr rmesa )
  */
 void r200GetLock( r200ContextPtr rmesa, GLuint flags )
 {
  */
 void r200GetLock( r200ContextPtr rmesa, GLuint flags )
 {
-   __DRIdrawablePrivate *dPriv = rmesa->dri.drawable;
-   RADEONSAREAPrivPtr sarea = rmesa->sarea;
+   __DRIdrawablePrivate *drawable = rmesa->dri.drawable;
+   __DRIdrawablePrivate *readable = rmesa->dri.readable;
+   __DRIscreenPrivate *sPriv = rmesa->dri.screen;
+   drm_radeon_sarea_t *sarea = rmesa->sarea;
    int i;
 
    drmGetLock( rmesa->dri.fd, rmesa->dri.hwContext, flags );
    int i;
 
    drmGetLock( rmesa->dri.fd, rmesa->dri.hwContext, flags );
@@ -94,23 +86,31 @@ void r200GetLock( r200ContextPtr rmesa, GLuint flags )
     * Since the hardware state depends on having the latest drawable
     * clip rects, all state checking must be done _after_ this call.
     */
     * Since the hardware state depends on having the latest drawable
     * clip rects, all state checking must be done _after_ this call.
     */
-   DRI_VALIDATE_DRAWABLE_INFO( sPriv, dPriv );
+   DRI_VALIDATE_DRAWABLE_INFO( sPriv, drawable );
+   if (drawable != readable) {
+      DRI_VALIDATE_DRAWABLE_INFO( sPriv, readable );
+   }
 
 
-   if ( rmesa->lastStamp != dPriv->lastStamp ) {
+   if ( rmesa->lastStamp != drawable->lastStamp ) {
       r200UpdatePageFlipping( rmesa );
       r200UpdatePageFlipping( rmesa );
-      if (rmesa->glCtx->Color._DrawDestMask == BACK_LEFT_BIT)
-         r200SetCliprects( rmesa, GL_BACK_LEFT );
-      else
-         r200SetCliprects( rmesa, GL_FRONT_LEFT );
+      r200SetCliprects( rmesa );
       r200UpdateViewportOffset( rmesa->glCtx );
       r200UpdateViewportOffset( rmesa->glCtx );
-      rmesa->lastStamp = dPriv->lastStamp;
+      driUpdateFramebufferSize(rmesa->glCtx, drawable);
    }
 
    }
 
-   if ( sarea->ctxOwner != rmesa->dri.hwContext ) {
-      sarea->ctxOwner = rmesa->dri.hwContext;
+   R200_STATECHANGE( rmesa, ctx );
+   if (rmesa->sarea->tiling_enabled) {
+      rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] |= R200_COLOR_TILE_ENABLE;
+   }
+   else rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] &= ~R200_COLOR_TILE_ENABLE;
+
+   if ( sarea->ctx_owner != rmesa->dri.hwContext ) {
+      sarea->ctx_owner = rmesa->dri.hwContext;
    }
 
    for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
       DRI_AGE_TEXTURES( rmesa->texture_heaps[ i ] );
    }
    }
 
    for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
       DRI_AGE_TEXTURES( rmesa->texture_heaps[ i ] );
    }
+
+   rmesa->lost_context = GL_TRUE;
 }
 }