fix typo
[mesa.git] / src / mesa / drivers / dri / r200 / r200_lock.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_lock.c,v 1.1 2002/10/30 12:51:52 alanh Exp $ */
2 /*
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
8
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31 /*
32 * Authors:
33 * Keith Whitwell <keith@tungstengraphics.com>
34 */
35 #include <string.h>
36
37 #include "r200_context.h"
38 #include "r200_lock.h"
39 #include "r200_tex.h"
40 #include "r200_state.h"
41 #include "r200_ioctl.h"
42 #include "drirenderbuffer.h"
43
44 #if DEBUG_LOCKING
45 char *prevLockFile = NULL;
46 int prevLockLine = 0;
47 #endif
48
49 /* Turn on/off page flipping according to the flags in the sarea:
50 */
51 static void
52 r200UpdatePageFlipping( r200ContextPtr rmesa )
53 {
54 #if 000
55 int use_back;
56 rmesa->doPageFlip = rmesa->sarea->pfState;
57
58 use_back = (rmesa->glCtx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT);
59 use_back ^= (rmesa->sarea->pfCurrentPage == 1);
60
61 if (use_back) {
62 rmesa->state.color.drawOffset = rmesa->r200Screen->backOffset;
63 rmesa->state.color.drawPitch = rmesa->r200Screen->backPitch;
64 } else {
65 rmesa->state.color.drawOffset = rmesa->r200Screen->frontOffset;
66 rmesa->state.color.drawPitch = rmesa->r200Screen->frontPitch;
67 }
68
69 R200_STATECHANGE( rmesa, ctx );
70 rmesa->hw.ctx.cmd[CTX_RB3D_COLOROFFSET] = rmesa->state.color.drawOffset
71 + rmesa->r200Screen->fbLocation;
72 rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] = rmesa->state.color.drawPitch;
73 #else
74 if (rmesa->doPageFlip != rmesa->sarea->pfState
75 || rmesa->sarea->pfState) {
76 /* If page flipping is on, or we're turning it on/off now we need
77 * to update the flipped buffer info.
78 */
79 struct gl_framebuffer *fb = rmesa->glCtx->WinSysDrawBuffer;
80 driRenderbuffer *front_drb
81 = (driRenderbuffer *) fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
82 driRenderbuffer *back_drb
83 = (driRenderbuffer *) fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
84
85 if (rmesa->sarea->pfState && rmesa->sarea->pfCurrentPage == 1) {
86 /* flipped buffers */
87 front_drb->flippedOffset = back_drb->offset;
88 front_drb->flippedPitch = back_drb->pitch;
89 back_drb->flippedOffset = front_drb->offset;
90 back_drb->flippedPitch = front_drb->pitch;
91 }
92 else {
93 /* unflipped buffers */
94 front_drb->flippedOffset = front_drb->offset;
95 front_drb->flippedPitch = front_drb->pitch;
96 if (back_drb) {
97 /* back buffer is non-existant when single buffered */
98 back_drb->flippedOffset = back_drb->offset;
99 back_drb->flippedPitch = back_drb->pitch;
100 }
101 }
102
103 /* update local state */
104 rmesa->doPageFlip = rmesa->sarea->pfState;
105
106 /* set hw.ctx.cmd state here */
107 r200UpdateDrawBuffer(rmesa->glCtx);
108 }
109 #endif
110 }
111
112
113
114 /* Update the hardware state. This is called if another context has
115 * grabbed the hardware lock, which includes the X server. This
116 * function also updates the driver's window state after the X server
117 * moves, resizes or restacks a window -- the change will be reflected
118 * in the drawable position and clip rects. Since the X server grabs
119 * the hardware lock when it changes the window state, this routine will
120 * automatically be called after such a change.
121 */
122 void r200GetLock( r200ContextPtr rmesa, GLuint flags )
123 {
124 __DRIdrawablePrivate *dPriv = rmesa->dri.drawable;
125 __DRIscreenPrivate *sPriv = rmesa->dri.screen;
126 drm_radeon_sarea_t *sarea = rmesa->sarea;
127 int i;
128
129 drmGetLock( rmesa->dri.fd, rmesa->dri.hwContext, flags );
130
131 /* The window might have moved, so we might need to get new clip
132 * rects.
133 *
134 * NOTE: This releases and regrabs the hw lock to allow the X server
135 * to respond to the DRI protocol request for new drawable info.
136 * Since the hardware state depends on having the latest drawable
137 * clip rects, all state checking must be done _after_ this call.
138 */
139 DRI_VALIDATE_DRAWABLE_INFO( sPriv, dPriv );
140
141 if ( rmesa->lastStamp != dPriv->lastStamp ) {
142 r200UpdatePageFlipping( rmesa );
143 if (rmesa->glCtx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT)
144 r200SetCliprects( rmesa, GL_BACK_LEFT );
145 else
146 r200SetCliprects( rmesa, GL_FRONT_LEFT );
147 r200UpdateViewportOffset( rmesa->glCtx );
148 rmesa->lastStamp = dPriv->lastStamp;
149 }
150
151 R200_STATECHANGE( rmesa, ctx );
152 if (rmesa->sarea->tiling_enabled) {
153 rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] |= R200_COLOR_TILE_ENABLE;
154 }
155 else rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] &= ~R200_COLOR_TILE_ENABLE;
156
157 if ( sarea->ctx_owner != rmesa->dri.hwContext ) {
158 sarea->ctx_owner = rmesa->dri.hwContext;
159 }
160
161 for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
162 DRI_AGE_TEXTURES( rmesa->texture_heaps[ i ] );
163 }
164
165 rmesa->lost_context = GL_TRUE;
166 }