OSDN Git Service

616e65b2a15147186aad8711c0cf667876fa0418
[android-x86/external-mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_lock.h
1 /* -*- mode: c; c-basic-offset: 3 -*-
2  *
3  * Copyright 2000 VA Linux Systems Inc., Fremont, California.
4  *
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  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
21  * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26 /* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_lock.h,v 1.3 2002/02/22 21:45:03 dawes Exp $ */
27
28 /*
29  * Original rewrite:
30  *      Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
31  *
32  * Authors:
33  *      Gareth Hughes <gareth@valinux.com>
34  *
35  */
36
37 #ifndef __TDFX_LOCK_H__
38 #define __TDFX_LOCK_H__
39
40 /* You can turn this on to find locking conflicts.
41  */
42 #define DEBUG_LOCKING           0
43
44 #if DEBUG_LOCKING
45 extern char *prevLockFile;
46 extern int prevLockLine;
47
48 #define DEBUG_LOCK()                                                    \
49    do {                                                                 \
50       prevLockFile = (__FILE__);                                        \
51       prevLockLine = (__LINE__);                                        \
52    } while (0)
53
54 #define DEBUG_RESET()                                                   \
55    do {                                                                 \
56       prevLockFile = 0;                                                 \
57       prevLockLine = 0;                                                 \
58    } while (0)
59
60 #define DEBUG_CHECK_LOCK()                                              \
61    do {                                                                 \
62       if ( prevLockFile ) {                                             \
63          fprintf( stderr,                                               \
64                   "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n",    \
65                   prevLockFile, prevLockLine, __FILE__, __LINE__ );     \
66          exit( 1 );                                                     \
67       }                                                                 \
68    } while (0)
69
70 #else
71
72 #define DEBUG_LOCK()
73 #define DEBUG_RESET()
74 #define DEBUG_CHECK_LOCK()
75
76 #endif /* DEBUG_LOCKING */
77
78
79 extern void tdfxGetLock( tdfxContextPtr fxMesa );
80
81
82 /* !!! We may want to separate locks from locks with validation.
83    This could be used to improve performance for those things
84    commands that do not do any drawing !!! */
85
86 #define DRM_LIGHT_LOCK_RETURN(fd,lock,context,__ret)                   \
87         do {                                                           \
88                 DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret);     \
89                 if (__ret) drmGetLock(fd,context,0);                   \
90         } while(0)
91
92 #define LOCK_HARDWARE( fxMesa )                                         \
93    do {                                                                 \
94       char __ret = 0;                                                   \
95                                                                         \
96       DEBUG_CHECK_LOCK();                                               \
97       DRM_CAS( fxMesa->driHwLock, fxMesa->hHWContext,                   \
98               DRM_LOCK_HELD | fxMesa->hHWContext, __ret );              \
99       if ( __ret ) {                                                    \
100          tdfxGetLock( fxMesa );                                         \
101       }                                                                 \
102       DEBUG_LOCK();                                                     \
103    } while (0)
104
105 /* Unlock the hardware using the global current context */
106 #define UNLOCK_HARDWARE( fxMesa )                                       \
107   do {                                                                  \
108     DRM_UNLOCK( fxMesa->driFd, fxMesa->driHwLock, fxMesa->hHWContext ); \
109     DEBUG_RESET();                                                      \
110   } while (0)
111
112 /*
113  * This pair of macros makes a loop over the drawing operations
114  * so it is not self contained and doesn't have the nice single
115  * statement semantics of most macros.
116  */
117 #define BEGIN_CLIP_LOOP(fxMesa)                 \
118   do {                                          \
119     LOCK_HARDWARE( fxMesa );                    \
120     BEGIN_CLIP_LOOP_LOCKED( fxMesa )
121
122 #define BEGIN_CLIP_LOOP_LOCKED(fxMesa)                          \
123   do {                                                          \
124     int _nc = fxMesa->numClipRects;                             \
125     while (_nc--) {                                             \
126       if (fxMesa->numClipRects > 1) {                           \
127         int _height = fxMesa->screen_height;                    \
128         fxMesa->Glide.grClipWindow(fxMesa->pClipRects[_nc].x1,  \
129                      _height - fxMesa->pClipRects[_nc].y2,      \
130                      fxMesa->pClipRects[_nc].x2,                \
131                      _height - fxMesa->pClipRects[_nc].y1);     \
132       }
133
134
135 #define END_CLIP_LOOP_LOCKED( fxMesa )          \
136     }                                           \
137   } while (0)
138
139 #define END_CLIP_LOOP( fxMesa )                 \
140     END_CLIP_LOOP_LOCKED( fxMesa );             \
141     UNLOCK_HARDWARE( fxMesa );                  \
142   } while (0)
143
144 #endif /* __TDFX_LOCK_H__ */