Merge branch 'master' into gallium-0.2
[mesa.git] / src / gallium / winsys / drm / intel / dri / intel_lock.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "main/glheader.h"
30 #include "pipe/p_thread.h"
31 #include <GL/internal/glcore.h>
32 #include "state_tracker/st_public.h"
33 #include "intel_context.h"
34 #include "i830_dri.h"
35
36
37
38 pipe_static_mutex( lockMutex );
39
40
41 static void
42 intelContendedLock(struct intel_context *intel, uint flags)
43 {
44 __DRIdrawablePrivate *dPriv = intel->driDrawable;
45 __DRIscreenPrivate *sPriv = intel->driScreen;
46 struct intel_screen *intelScreen = intel_screen(sPriv);
47 drmI830Sarea *sarea = intel->sarea;
48
49 drmGetLock(intel->driFd, intel->hHWContext, flags);
50
51 DBG(LOCK, "%s - got contended lock\n", __progname);
52
53 /* If the window moved, may need to set a new cliprect now.
54 *
55 * NOTE: This releases and regains the hw lock, so all state
56 * checking must be done *after* this call:
57 */
58 if (dPriv)
59 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
60
61 if (sarea->width != intelScreen->front.width ||
62 sarea->height != intelScreen->front.height) {
63
64 intelUpdateScreenRotation(sPriv, sarea);
65 }
66 }
67
68
69 /* Lock the hardware and validate our state.
70 */
71 void LOCK_HARDWARE( struct intel_context *intel )
72 {
73 char __ret = 0;
74
75 pipe_mutex_lock(lockMutex);
76 assert(!intel->locked);
77
78 DRM_CAS(intel->driHwLock, intel->hHWContext,
79 (DRM_LOCK_HELD|intel->hHWContext), __ret);
80
81 if (__ret)
82 intelContendedLock( intel, 0 );
83
84 DBG(LOCK, "%s - locked\n", __progname);
85
86 intel->locked = 1;
87 }
88
89
90 /* Unlock the hardware using the global current context
91 */
92 void UNLOCK_HARDWARE( struct intel_context *intel )
93 {
94 assert(intel->locked);
95 intel->locked = 0;
96
97 DRM_UNLOCK(intel->driFd, intel->driHwLock, intel->hHWContext);
98
99 pipe_mutex_unlock(lockMutex);
100
101 DBG(LOCK, "%s - unlocked\n", __progname);
102 }