i915tex: Make sure renderbuffers don't get deleted when flipping them.
[mesa.git] / src / mesa / drivers / dri / r300 / radeon_lock.h
1 /*
2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
3
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
15
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 **************************************************************************/
29
30 /*
31 * Authors:
32 * Keith Whitwell <keith@tungstengraphics.com>
33 */
34
35 #ifndef __RADEON_LOCK_H__
36 #define __RADEON_LOCK_H__
37
38 #if 0
39 #include "r200_ioctl.h"
40 #endif
41 #include "radeon_context.h"
42
43 extern void radeonGetLock(radeonContextPtr radeon, GLuint flags);
44
45 /* Turn DEBUG_LOCKING on to find locking conflicts.
46 */
47 #define DEBUG_LOCKING 0
48
49 #if DEBUG_LOCKING
50 extern char *prevLockFile;
51 extern int prevLockLine;
52
53 #define DEBUG_LOCK() \
54 do { \
55 prevLockFile = (__FILE__); \
56 prevLockLine = (__LINE__); \
57 } while (0)
58
59 #define DEBUG_RESET() \
60 do { \
61 prevLockFile = 0; \
62 prevLockLine = 0; \
63 } while (0)
64
65 #define DEBUG_CHECK_LOCK() \
66 do { \
67 if ( prevLockFile ) { \
68 fprintf( stderr, \
69 "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n", \
70 prevLockFile, prevLockLine, __FILE__, __LINE__ ); \
71 exit( 1 ); \
72 } \
73 } while (0)
74
75 #else
76
77 #define DEBUG_LOCK()
78 #define DEBUG_RESET()
79 #define DEBUG_CHECK_LOCK()
80
81 #endif
82
83 /*
84 * !!! We may want to separate locks from locks with validation. This
85 * could be used to improve performance for those things commands that
86 * do not do any drawing !!!
87 */
88
89 /* Lock the hardware and validate our state.
90 */
91 #define LOCK_HARDWARE( radeon ) \
92 do { \
93 char __ret = 0; \
94 DEBUG_CHECK_LOCK(); \
95 DRM_CAS( (radeon)->dri.hwLock, (radeon)->dri.hwContext, \
96 (DRM_LOCK_HELD | (radeon)->dri.hwContext), __ret ); \
97 if ( __ret ) \
98 radeonGetLock( (radeon), 0 ); \
99 DEBUG_LOCK(); \
100 } while (0)
101
102 #if R200_MERGED
103 #define UNLOCK_HARDWARE( radeon ) \
104 do { \
105 DRM_UNLOCK( (radeon)->dri.fd, \
106 (radeon)->dri.hwLock, \
107 (radeon)->dri.hwContext ); \
108 DEBUG_RESET(); \
109 if (IS_R200_CLASS(radeon->radeonScreen)) { \
110 r200ContextPtr __r200 = (r200ContextPtr)(radeon); \
111 if (__r200->save_on_next_unlock) \
112 r200SaveHwState( __r200 ); \
113 __r200->save_on_next_unlock = GL_FALSE; \
114 } \
115 } while (0)
116 #else
117 #define UNLOCK_HARDWARE( radeon ) \
118 do { \
119 DRM_UNLOCK( (radeon)->dri.fd, \
120 (radeon)->dri.hwLock, \
121 (radeon)->dri.hwContext ); \
122 DEBUG_RESET(); \
123 } while (0)
124 #endif
125 #endif /* __RADEON_LOCK_H__ */