Update DRI drivers to current DRI CVS and make them work.
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_lock.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/radeon/radeon_lock.c,v 1.5 2002/10/30 12:51:55 alanh Exp $ */
2 /**************************************************************************
3
4 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
5 VA Linux Systems Inc., Fremont, California.
6
7 All Rights Reserved.
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 * Kevin E. Martin <martin@valinux.com>
34 * Gareth Hughes <gareth@valinux.com>
35 */
36
37 #include "glheader.h"
38 #include "radeon_context.h"
39 #include "radeon_lock.h"
40 #include "radeon_tex.h"
41 #include "radeon_state.h"
42 #include "radeon_ioctl.h"
43
44 #if DEBUG_LOCKING
45 char *prevLockFile = NULL;
46 int prevLockLine = 0;
47 #endif
48
49 /* Turn on/off page flipping according to the flags in the sarea:
50 */
51 static void
52 radeonUpdatePageFlipping( radeonContextPtr rmesa )
53 {
54 int use_back;
55
56
57 rmesa->doPageFlip = rmesa->sarea->pfAllowPageFlip;
58
59 use_back = (rmesa->glCtx->Color._DrawDestMask == BACK_LEFT_BIT);
60 use_back ^= (rmesa->sarea->pfCurrentPage == 1);
61
62 if ( RADEON_DEBUG & DEBUG_VERBOSE )
63 fprintf(stderr, "%s allow %d current %d\n", __FUNCTION__,
64 rmesa->doPageFlip,
65 rmesa->sarea->pfCurrentPage );
66
67 if ( use_back ) {
68 rmesa->state.color.drawOffset = rmesa->radeonScreen->backOffset;
69 rmesa->state.color.drawPitch = rmesa->radeonScreen->backPitch;
70 } else {
71 rmesa->state.color.drawOffset = rmesa->radeonScreen->frontOffset;
72 rmesa->state.color.drawPitch = rmesa->radeonScreen->frontPitch;
73 }
74
75 RADEON_STATECHANGE( rmesa, ctx );
76 rmesa->hw.ctx.cmd[CTX_RB3D_COLOROFFSET] = rmesa->state.color.drawOffset;
77 rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] = rmesa->state.color.drawPitch;
78 }
79
80
81
82 /* Update the hardware state. This is called if another context has
83 * grabbed the hardware lock, which includes the X server. This
84 * function also updates the driver's window state after the X server
85 * moves, resizes or restacks a window -- the change will be reflected
86 * in the drawable position and clip rects. Since the X server grabs
87 * the hardware lock when it changes the window state, this routine will
88 * automatically be called after such a change.
89 */
90 void radeonGetLock( radeonContextPtr rmesa, GLuint flags )
91 {
92 __DRIdrawablePrivate *dPriv = rmesa->dri.drawable;
93 __DRIscreenPrivate *sPriv = rmesa->dri.screen;
94 RADEONSAREAPrivPtr sarea = rmesa->sarea;
95
96 drmGetLock( rmesa->dri.fd, rmesa->dri.hwContext, flags );
97
98 /* The window might have moved, so we might need to get new clip
99 * rects.
100 *
101 * NOTE: This releases and regrabs the hw lock to allow the X server
102 * to respond to the DRI protocol request for new drawable info.
103 * Since the hardware state depends on having the latest drawable
104 * clip rects, all state checking must be done _after_ this call.
105 */
106 DRI_VALIDATE_DRAWABLE_INFO( sPriv, dPriv );
107
108 if ( rmesa->lastStamp != dPriv->lastStamp ) {
109 radeonUpdatePageFlipping( rmesa );
110 if (rmesa->glCtx->Color._DrawDestMask == BACK_LEFT_BIT)
111 radeonSetCliprects( rmesa, GL_BACK_LEFT );
112 else
113 radeonSetCliprects( rmesa, GL_FRONT_LEFT );
114 radeonUpdateViewportOffset( rmesa->glCtx );
115 rmesa->lastStamp = dPriv->lastStamp;
116 }
117
118 if ( sarea->ctxOwner != rmesa->dri.hwContext ) {
119 int i;
120 sarea->ctxOwner = rmesa->dri.hwContext;
121
122 for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
123 DRI_AGE_TEXTURES( rmesa->texture_heaps[ i ] );
124 }
125 }
126 }