Merge branch 'crestline-qa', adding support for the 965GM chipset.
[mesa.git] / src / mesa / drivers / dri / r128 / r128_lock.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_lock.c,v 1.5 2002/10/30 12:51:38 alanh Exp $ */
2 /**************************************************************************
3
4 Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
5 Cedar Park, Texas.
6 All Rights Reserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 on the rights to use, copy, modify, merge, publish, distribute, sub
12 license, and/or sell copies of the Software, and to permit persons to whom
13 the Software is furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice (including the next
16 paragraph) shall be included in all copies or substantial portions of the
17 Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27 **************************************************************************/
28
29 /*
30 * Authors:
31 * Gareth Hughes <gareth@valinux.com>
32 *
33 */
34
35 #include "r128_context.h"
36 #include "r128_lock.h"
37 #include "r128_tex.h"
38 #include "r128_state.h"
39
40 #include "drirenderbuffer.h"
41
42
43 #if DEBUG_LOCKING
44 char *prevLockFile = NULL;
45 int prevLockLine = 0;
46 #endif
47
48
49 /* Turn on/off page flipping according to the flags in the sarea:
50 */
51 static void
52 r128UpdatePageFlipping( r128ContextPtr rmesa )
53 {
54 rmesa->doPageFlip = rmesa->sarea->pfAllowPageFlip;
55 if (rmesa->glCtx->WinSysDrawBuffer) {
56 driFlipRenderbuffers(rmesa->glCtx->WinSysDrawBuffer,
57 rmesa->sarea->pfCurrentPage);
58 }
59 rmesa->new_state |= R128_NEW_WINDOW;
60 }
61
62 /* Update the hardware state. This is called if another context has
63 * grabbed the hardware lock, which includes the X server. This
64 * function also updates the driver's window state after the X server
65 * moves, resizes or restacks a window -- the change will be reflected
66 * in the drawable position and clip rects. Since the X server grabs
67 * the hardware lock when it changes the window state, this routine will
68 * automatically be called after such a change.
69 */
70 void r128GetLock( r128ContextPtr rmesa, GLuint flags )
71 {
72 __DRIdrawablePrivate *dPriv = rmesa->driDrawable;
73 __DRIscreenPrivate *sPriv = rmesa->driScreen;
74 drm_r128_sarea_t *sarea = rmesa->sarea;
75 int i;
76
77 drmGetLock( rmesa->driFd, rmesa->hHWContext, flags );
78
79 /* The window might have moved, so we might need to get new clip
80 * rects.
81 *
82 * NOTE: This releases and regrabs the hw lock to allow the X server
83 * to respond to the DRI protocol request for new drawable info.
84 * Since the hardware state depends on having the latest drawable
85 * clip rects, all state checking must be done _after_ this call.
86 */
87 DRI_VALIDATE_DRAWABLE_INFO( sPriv, dPriv );
88
89 if ( rmesa->lastStamp != dPriv->lastStamp ) {
90 r128UpdatePageFlipping( rmesa );
91 driUpdateFramebufferSize(rmesa->glCtx, dPriv);
92 rmesa->lastStamp = dPriv->lastStamp;
93 rmesa->new_state |= R128_NEW_CLIP;
94 RENDERINPUTS_ONES( rmesa->tnl_state_bitset );
95 }
96
97 rmesa->dirty |= R128_UPLOAD_CONTEXT | R128_UPLOAD_CLIPRECTS;
98
99 rmesa->numClipRects = dPriv->numClipRects;
100 rmesa->pClipRects = dPriv->pClipRects;
101
102 if ( sarea->ctx_owner != rmesa->hHWContext ) {
103 sarea->ctx_owner = rmesa->hHWContext;
104 rmesa->dirty = R128_UPLOAD_ALL;
105 }
106
107 for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
108 DRI_AGE_TEXTURES( rmesa->texture_heaps[i] );
109 }
110 }