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