enable feedback rendering
[mesa.git] / src / mesa / drivers / dri / r300 / radeon_lock.c
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 #include <string.h>
35
36 #include "r200_context.h"
37 #include "radeon_lock.h"
38 #if R200_MERGED
39 #include "r200_tex.h"
40 #endif
41 #include "r200_state.h"
42 #include "radeon_ioctl.h"
43 #include "radeon_state.h"
44 #include "r300_context.h"
45 #include "r300_state.h"
46
47 #include "framebuffer.h"
48
49 #include "drirenderbuffer.h"
50
51 #if DEBUG_LOCKING
52 char *prevLockFile = NULL;
53 int prevLockLine = 0;
54 #endif
55
56 /* Turn on/off page flipping according to the flags in the sarea:
57 */
58 static void radeonUpdatePageFlipping(radeonContextPtr radeon)
59 {
60 int use_back;
61
62 radeon->doPageFlip = radeon->sarea->pfState;
63 if (!radeon->doPageFlip) {
64 driFlipRenderbuffers(radeon->glCtx->WinSysDrawBuffer, GL_FALSE);
65 }
66
67 use_back = (radeon->glCtx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT);
68 use_back ^= (radeon->sarea->pfCurrentPage == 1);
69
70 if (use_back) {
71 radeon->state.color.drawOffset = radeon->radeonScreen->backOffset;
72 radeon->state.color.drawPitch = radeon->radeonScreen->backPitch;
73 } else {
74 radeon->state.color.drawOffset = radeon->radeonScreen->frontOffset;
75 radeon->state.color.drawPitch = radeon->radeonScreen->frontPitch;
76 }
77 }
78
79 /**
80 * Called by radeonGetLock() after the lock has been obtained.
81 */
82 #if R200_MERGED
83 static void r200RegainedLock(r200ContextPtr r200)
84 {
85 __DRIdrawablePrivate *dPriv = r200->radeon.dri.drawable;
86 int i;
87
88 if (r200->radeon.lastStamp != dPriv->lastStamp) {
89 radeonUpdatePageFlipping(&r200->radeon);
90 R200_STATECHANGE(r200, ctx);
91 r200->hw.ctx.cmd[CTX_RB3D_COLOROFFSET] =
92 r200->radeon.state.color.drawOffset
93 + r200->radeon.radeonScreen->fbLocation;
94 r200->hw.ctx.cmd[CTX_RB3D_COLORPITCH] =
95 r200->radeon.state.color.drawPitch;
96
97 if (r200->radeon.glCtx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT)
98 radeonSetCliprects(&r200->radeon, GL_BACK_LEFT);
99 else
100 radeonSetCliprects(&r200->radeon, GL_FRONT_LEFT);
101 r200UpdateViewportOffset(r200->radeon.glCtx);
102 r200->radeon.lastStamp = dPriv->lastStamp;
103 }
104
105 for (i = 0; i < r200->nr_heaps; i++) {
106 DRI_AGE_TEXTURES(r200->texture_heaps[i]);
107 }
108 }
109 #endif
110
111 static void r300RegainedLock(radeonContextPtr radeon)
112 {
113 __DRIdrawablePrivate *dPriv = radeon->dri.drawable;
114 int i;
115 r300ContextPtr r300 = (r300ContextPtr)radeon;
116
117 if (radeon->lastStamp != dPriv->lastStamp) {
118 _mesa_resize_framebuffer(radeon->glCtx,
119 (GLframebuffer*)dPriv->driverPrivate,
120 dPriv->w, dPriv->h);
121
122 radeonUpdatePageFlipping(radeon);
123
124 if (radeon->glCtx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT)
125 radeonSetCliprects(radeon, GL_BACK_LEFT);
126 else
127 radeonSetCliprects(radeon, GL_FRONT_LEFT);
128
129 #if 1
130 r300UpdateViewportOffset( radeon->glCtx );
131 driUpdateFramebufferSize(radeon->glCtx, dPriv);
132 #else
133 radeonUpdateScissor(radeon->glCtx);
134 #endif
135 radeon->lastStamp = dPriv->lastStamp;
136 }
137
138 for (i = 0; i < r300->nr_heaps; i++) {
139 DRI_AGE_TEXTURES(r300->texture_heaps[i]);
140 }
141 }
142
143 /* Update the hardware state. This is called if another context has
144 * grabbed the hardware lock, which includes the X server. This
145 * function also updates the driver's window state after the X server
146 * moves, resizes or restacks a window -- the change will be reflected
147 * in the drawable position and clip rects. Since the X server grabs
148 * the hardware lock when it changes the window state, this routine will
149 * automatically be called after such a change.
150 */
151 void radeonGetLock(radeonContextPtr radeon, GLuint flags)
152 {
153 __DRIdrawablePrivate *dPriv = radeon->dri.drawable;
154 __DRIscreenPrivate *sPriv = radeon->dri.screen;
155 drm_radeon_sarea_t *sarea = radeon->sarea;
156
157 drmGetLock(radeon->dri.fd, radeon->dri.hwContext, flags);
158
159 /* The window might have moved, so we might need to get new clip
160 * rects.
161 *
162 * NOTE: This releases and regrabs the hw lock to allow the X server
163 * to respond to the DRI protocol request for new drawable info.
164 * Since the hardware state depends on having the latest drawable
165 * clip rects, all state checking must be done _after_ this call.
166 */
167 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
168
169 if (sarea->ctx_owner != radeon->dri.hwContext)
170 sarea->ctx_owner = radeon->dri.hwContext;
171
172 if (IS_R300_CLASS(radeon->radeonScreen))
173 r300RegainedLock(radeon);
174 #if R200_MERGED
175 else
176 r200RegainedLock((r200ContextPtr)radeon);
177 #endif
178
179 radeon->lost_context = GL_TRUE;
180 }