b73e350111fc2fb82a25bae7a9329ff2d52109f0
[mesa.git] / src / mesa / drivers / dri / mach64 / mach64_lock.c
1 /* $XFree86$ */ /* -*- mode: c; c-basic-offset: 3 -*- */
2 /*
3 * Copyright 2000 Gareth Hughes
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * GARETH HUGHES BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /*
26 * Authors:
27 * Gareth Hughes <gareth@valinux.com>
28 * Leif Delgass <ldelgass@retinalburn.net>
29 * José Fonseca <j_r_fonseca@yahoo.co.uk>
30 */
31
32 #include "mach64_context.h"
33 #include "mach64_state.h"
34 #include "mach64_lock.h"
35 #include "mach64_tex.h"
36 #include "drirenderbuffer.h"
37
38 #if DEBUG_LOCKING
39 char *prevLockFile = NULL;
40 int prevLockLine = 0;
41 #endif
42
43
44 /* Update the hardware state. This is called if another context has
45 * grabbed the hardware lock, which includes the X server. This
46 * function also updates the driver's window state after the X server
47 * moves, resizes or restacks a window -- the change will be reflected
48 * in the drawable position and clip rects. Since the X server grabs
49 * the hardware lock when it changes the window state, this routine will
50 * automatically be called after such a change.
51 */
52 void mach64GetLock( mach64ContextPtr mmesa, GLuint flags )
53 {
54 __DRIdrawablePrivate *dPriv = mmesa->driDrawable;
55 __DRIscreenPrivate *sPriv = mmesa->driScreen;
56 drm_mach64_sarea_t *sarea = mmesa->sarea;
57 int i;
58
59 drmGetLock( mmesa->driFd, mmesa->hHWContext, flags );
60
61 /* The window might have moved, so we might need to get new clip
62 * rects.
63 *
64 * NOTE: This releases and regrabs the hw lock to allow the X server
65 * to respond to the DRI protocol request for new drawable info.
66 * Since the hardware state depends on having the latest drawable
67 * clip rects, all state checking must be done _after_ this call.
68 */
69 DRI_VALIDATE_DRAWABLE_INFO( sPriv, dPriv );
70
71 if ( mmesa->lastStamp != dPriv->lastStamp ) {
72 mmesa->lastStamp = dPriv->lastStamp;
73 if (mmesa->glCtx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT)
74 mach64SetCliprects( mmesa->glCtx, GL_BACK_LEFT );
75 else
76 mach64SetCliprects( mmesa->glCtx, GL_FRONT_LEFT );
77 driUpdateFramebufferSize( mmesa->glCtx, dPriv );
78 mach64CalcViewport( mmesa->glCtx );
79 }
80
81 mmesa->dirty |= (MACH64_UPLOAD_CONTEXT
82 | MACH64_UPLOAD_MISC
83 | MACH64_UPLOAD_CLIPRECTS);
84
85 /* EXA render acceleration uses the texture engine, so restore it */
86 mmesa->dirty |= (MACH64_UPLOAD_TEXTURE);
87
88 if ( sarea->ctx_owner != mmesa->hHWContext ) {
89 sarea->ctx_owner = mmesa->hHWContext;
90 mmesa->dirty = MACH64_UPLOAD_ALL;
91 }
92
93 for ( i = mmesa->firstTexHeap ; i < mmesa->lastTexHeap ; i++ ) {
94 DRI_AGE_TEXTURES( mmesa->texture_heaps[i] );
95 }
96 }