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