Some fixes
[mesa.git] / src / mesa / drivers / dri / r200 / r200_lock.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_lock.c,v 1.1 2002/10/30 12:51:52 alanh Exp $ */
2 /*
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
8
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31 /*
32 * Authors:
33 * Keith Whitwell <keith@tungstengraphics.com>
34 */
35 #include <string.h>
36
37 #include "r200_context.h"
38 #include "r200_lock.h"
39 #include "r200_tex.h"
40 #include "r200_state.h"
41 #include "r200_ioctl.h"
42
43 #if DEBUG_LOCKING
44 char *prevLockFile = NULL;
45 int prevLockLine = 0;
46 #endif
47
48 /* Turn on/off page flipping according to the flags in the sarea:
49 */
50 static void
51 r200UpdatePageFlipping( r200ContextPtr rmesa )
52 {
53 int use_back;
54 rmesa->doPageFlip = rmesa->sarea->pfState;
55
56 use_back = (rmesa->glCtx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT);
57 use_back ^= (rmesa->sarea->pfCurrentPage == 1);
58
59 if (use_back) {
60 rmesa->state.color.drawOffset = rmesa->r200Screen->backOffset;
61 rmesa->state.color.drawPitch = rmesa->r200Screen->backPitch;
62 } else {
63 rmesa->state.color.drawOffset = rmesa->r200Screen->frontOffset;
64 rmesa->state.color.drawPitch = rmesa->r200Screen->frontPitch;
65 }
66
67 R200_STATECHANGE( rmesa, ctx );
68 rmesa->hw.ctx.cmd[CTX_RB3D_COLOROFFSET] = rmesa->state.color.drawOffset
69 + rmesa->r200Screen->fbLocation;
70 rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] = rmesa->state.color.drawPitch;
71 }
72
73
74
75 /* Update the hardware state. This is called if another context has
76 * grabbed the hardware lock, which includes the X server. This
77 * function also updates the driver's window state after the X server
78 * moves, resizes or restacks a window -- the change will be reflected
79 * in the drawable position and clip rects. Since the X server grabs
80 * the hardware lock when it changes the window state, this routine will
81 * automatically be called after such a change.
82 */
83 void r200GetLock( r200ContextPtr rmesa, GLuint flags )
84 {
85 __DRIdrawablePrivate *dPriv = rmesa->dri.drawable;
86 __DRIscreenPrivate *sPriv = rmesa->dri.screen;
87 drm_radeon_sarea_t *sarea = rmesa->sarea;
88 int i;
89
90 drmGetLock( rmesa->dri.fd, rmesa->dri.hwContext, flags );
91
92 /* The window might have moved, so we might need to get new clip
93 * rects.
94 *
95 * NOTE: This releases and regrabs the hw lock to allow the X server
96 * to respond to the DRI protocol request for new drawable info.
97 * Since the hardware state depends on having the latest drawable
98 * clip rects, all state checking must be done _after_ this call.
99 */
100 DRI_VALIDATE_DRAWABLE_INFO( sPriv, dPriv );
101
102 if ( rmesa->lastStamp != dPriv->lastStamp ) {
103 r200UpdatePageFlipping( rmesa );
104 if (rmesa->glCtx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT)
105 r200SetCliprects( rmesa, GL_BACK_LEFT );
106 else
107 r200SetCliprects( rmesa, GL_FRONT_LEFT );
108 r200UpdateViewportOffset( rmesa->glCtx );
109 rmesa->lastStamp = dPriv->lastStamp;
110 }
111
112 R200_STATECHANGE( rmesa, ctx );
113 if (rmesa->sarea->tiling_enabled) {
114 rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] |= R200_COLOR_TILE_ENABLE;
115 }
116 else rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] &= ~R200_COLOR_TILE_ENABLE;
117
118 if ( sarea->ctx_owner != rmesa->dri.hwContext ) {
119 sarea->ctx_owner = rmesa->dri.hwContext;
120 }
121
122 for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
123 DRI_AGE_TEXTURES( rmesa->texture_heaps[ i ] );
124 }
125
126 rmesa->lost_context = GL_TRUE;
127 }