Merge commit 'origin/master' into drm-gem
[mesa.git] / src / mesa / drivers / dri / r200 / r200_lock.c
index 539a4be619b17dcef25e173dcb3ae9530b4ad73d..f89b526a31202f8362ffa00dd8adb0758e8ec6c1 100644 (file)
@@ -1,4 +1,3 @@
-/* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_lock.c,v 1.1 2002/10/30 12:51:52 alanh Exp $ */
 /*
 Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
 
@@ -32,7 +31,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * Authors:
  *   Keith Whitwell <keith@tungstengraphics.com>
  */
-#include <string.h>
  
 #include "r200_context.h"
 #include "r200_lock.h"
@@ -40,6 +38,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "r200_state.h"
 #include "r200_ioctl.h"
 
+#include "drirenderbuffer.h"
+
+
 #if DEBUG_LOCKING
 char *prevLockFile = NULL;
 int prevLockLine = 0;
@@ -50,24 +51,11 @@ int prevLockLine = 0;
 static void
 r200UpdatePageFlipping( r200ContextPtr rmesa )
 {
-   int use_back;
    rmesa->doPageFlip = rmesa->sarea->pfState;
-
-   use_back = (rmesa->glCtx->Color._DrawDestMask == DD_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;
+   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->r200Screen->fbLocation;
-   rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH]  = rmesa->state.color.drawPitch;
 }
 
 
@@ -82,7 +70,8 @@ r200UpdatePageFlipping( r200ContextPtr rmesa )
  */
 void r200GetLock( r200ContextPtr rmesa, GLuint flags )
 {
-   __DRIdrawablePrivate *dPriv = rmesa->dri.drawable;
+   __DRIdrawablePrivate *drawable = rmesa->dri.drawable;
+   __DRIdrawablePrivate *readable = rmesa->dri.readable;
    __DRIscreenPrivate *sPriv = rmesa->dri.screen;
    drm_radeon_sarea_t *sarea = rmesa->sarea;
    int i;
@@ -97,17 +86,23 @@ 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.
     */
-   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 );
-      if (rmesa->glCtx->Color._DrawDestMask == DD_BACK_LEFT_BIT)
-         r200SetCliprects( rmesa, GL_BACK_LEFT );
-      else
-         r200SetCliprects( rmesa, GL_FRONT_LEFT );
+      r200SetCliprects( rmesa );
       r200UpdateViewportOffset( rmesa->glCtx );
-      rmesa->lastStamp = dPriv->lastStamp;
+      driUpdateFramebufferSize(rmesa->glCtx, drawable);
+   }
+
+   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;