c342b115080b20b9addf86b17d87d8dcf784ed41
[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 #include "drirenderbuffer.h"
45
46
47 #if DEBUG_LOCKING
48 char *prevLockFile = NULL;
49 int prevLockLine = 0;
50 #endif
51
52 /* Turn on/off page flipping according to the flags in the sarea:
53 */
54 static void
55 radeonUpdatePageFlipping( radeonContextPtr rmesa )
56 {
57 rmesa->doPageFlip = rmesa->sarea->pfState;
58 if (!rmesa->doPageFlip) {
59 driFlipRenderbuffers(rmesa->glCtx->WinSysDrawBuffer, GL_FALSE);
60 }
61 }
62
63
64
65 /* Update the hardware state. This is called if another context has
66 * grabbed the hardware lock, which includes the X server. This
67 * function also updates the driver's window state after the X server
68 * moves, resizes or restacks a window -- the change will be reflected
69 * in the drawable position and clip rects. Since the X server grabs
70 * the hardware lock when it changes the window state, this routine will
71 * automatically be called after such a change.
72 */
73 void radeonGetLock( radeonContextPtr rmesa, GLuint flags )
74 {
75 __DRIdrawablePrivate *dPriv = rmesa->dri.drawable;
76 __DRIscreenPrivate *sPriv = rmesa->dri.screen;
77 drm_radeon_sarea_t *sarea = rmesa->sarea;
78
79 drmGetLock( rmesa->dri.fd, rmesa->dri.hwContext, flags );
80
81 /* The window might have moved, so we might need to get new clip
82 * rects.
83 *
84 * NOTE: This releases and regrabs the hw lock to allow the X server
85 * to respond to the DRI protocol request for new drawable info.
86 * Since the hardware state depends on having the latest drawable
87 * clip rects, all state checking must be done _after_ this call.
88 */
89 DRI_VALIDATE_DRAWABLE_INFO( sPriv, dPriv );
90
91 if ( rmesa->lastStamp != dPriv->lastStamp ) {
92 radeonUpdatePageFlipping( rmesa );
93 if (rmesa->glCtx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT)
94 radeonSetCliprects( rmesa, GL_BACK_LEFT );
95 else
96 radeonSetCliprects( rmesa, GL_FRONT_LEFT );
97 radeonUpdateViewportOffset( rmesa->glCtx );
98 rmesa->lastStamp = dPriv->lastStamp;
99 }
100
101 RADEON_STATECHANGE( rmesa, ctx );
102 if (rmesa->sarea->tiling_enabled) {
103 rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] |= RADEON_COLOR_TILE_ENABLE;
104 }
105 else {
106 rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] &= ~RADEON_COLOR_TILE_ENABLE;
107 }
108
109 if ( sarea->ctx_owner != rmesa->dri.hwContext ) {
110 int i;
111 sarea->ctx_owner = rmesa->dri.hwContext;
112
113 for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
114 DRI_AGE_TEXTURES( rmesa->texture_heaps[ i ] );
115 }
116 }
117
118 rmesa->lost_context = GL_TRUE;
119 }