radeon/r200/r300: merge span code into single shared file
[mesa.git] / src / mesa / drivers / dri / radeon / common_lock.c
1 /**************************************************************************
2
3 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
4 VA Linux Systems Inc., Fremont, California.
5 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
6
7 The Weather Channel (TM) funded Tungsten Graphics to develop the
8 initial release of the Radeon 8500 driver under the XFree86 license.
9 This notice must be preserved.
10
11 All Rights Reserved.
12
13 Permission is hereby granted, free of charge, to any person obtaining
14 a copy of this software and associated documentation files (the
15 "Software"), to deal in the Software without restriction, including
16 without limitation the rights to use, copy, modify, merge, publish,
17 distribute, sublicense, and/or sell copies of the Software, and to
18 permit persons to whom the Software is furnished to do so, subject to
19 the following conditions:
20
21 The above copyright notice and this permission notice (including the
22 next paragraph) shall be included in all copies or substantial
23 portions of the Software.
24
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
29 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
33 **************************************************************************/
34
35 /*
36 * Authors:
37 * Gareth Hughes <gareth@valinux.com>
38 * Keith Whitwell <keith@tungstengraphics.com>
39 * Kevin E. Martin <martin@valinux.com>
40 */
41
42 #include "main/glheader.h"
43 #include "main/mtypes.h"
44 #include "main/colormac.h"
45 #include "dri_util.h"
46 #include "radeon_screen.h"
47 #include "common_context.h"
48 #include "common_lock.h"
49 #include "common_misc.h"
50
51 #include "drirenderbuffer.h"
52
53 #if DEBUG_LOCKING
54 char *prevLockFile = NULL;
55 int prevLockLine = 0;
56 #endif
57
58 /* Turn on/off page flipping according to the flags in the sarea:
59 */
60 void radeonUpdatePageFlipping(radeonContextPtr rmesa)
61 {
62 int use_back;
63 __DRIdrawablePrivate *const drawable = rmesa->dri.drawable;
64 GLframebuffer *fb = drawable->driverPrivate;
65
66 rmesa->doPageFlip = rmesa->sarea->pfState;
67 if (rmesa->glCtx->WinSysDrawBuffer) {
68 rmesa->vtbl.update_draw_buffer(rmesa->glCtx);
69 }
70
71 use_back = rmesa->glCtx->DrawBuffer ?
72 (rmesa->glCtx->DrawBuffer->_ColorDrawBufferIndexes[0] ==
73 BUFFER_BACK_LEFT) : 1;
74 use_back ^= (rmesa->sarea->pfCurrentPage == 1);
75
76 if (use_back)
77 rmesa->state.color.rrb = (void *)fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
78 else
79 rmesa->state.color.rrb = (void *)fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
80
81 rmesa->state.depth.rrb = (void *)fb->Attachment[BUFFER_DEPTH].Renderbuffer;
82 }
83
84 /* Update the hardware state. This is called if another context has
85 * grabbed the hardware lock, which includes the X server. This
86 * function also updates the driver's window state after the X server
87 * moves, resizes or restacks a window -- the change will be reflected
88 * in the drawable position and clip rects. Since the X server grabs
89 * the hardware lock when it changes the window state, this routine will
90 * automatically be called after such a change.
91 */
92 void radeonGetLock(radeonContextPtr rmesa, GLuint flags)
93 {
94 __DRIdrawablePrivate *const drawable = rmesa->dri.drawable;
95 __DRIdrawablePrivate *const readable = rmesa->dri.readable;
96 __DRIscreenPrivate *sPriv = rmesa->dri.screen;
97 drm_radeon_sarea_t *sarea = rmesa->sarea;
98
99 assert(drawable != NULL);
100
101 drmGetLock(rmesa->dri.fd, rmesa->dri.hwContext, flags);
102
103 /* The window might have moved, so we might need to get new clip
104 * rects.
105 *
106 * NOTE: This releases and regrabs the hw lock to allow the X server
107 * to respond to the DRI protocol request for new drawable info.
108 * Since the hardware state depends on having the latest drawable
109 * clip rects, all state checking must be done _after_ this call.
110 */
111 DRI_VALIDATE_DRAWABLE_INFO(sPriv, drawable);
112 if (drawable != readable) {
113 DRI_VALIDATE_DRAWABLE_INFO(sPriv, readable);
114 }
115
116 if (rmesa->lastStamp != drawable->lastStamp) {
117 radeonUpdatePageFlipping(rmesa);
118 radeonSetCliprects(rmesa);
119 rmesa->vtbl.update_viewport_offset(rmesa->glCtx);
120 driUpdateFramebufferSize(rmesa->glCtx, drawable);
121 }
122
123 rmesa->vtbl.get_lock(rmesa);
124
125 rmesa->lost_context = GL_TRUE;
126 }