i965: fix bugs in projective texture coordinates
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_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 "radeon_context.h"
45 #include "radeon_lock.h"
46 #include "radeon_tex.h"
47 #include "radeon_state.h"
48 #include "radeon_ioctl.h"
49
50 #include "drirenderbuffer.h"
51
52 #if DEBUG_LOCKING
53 char *prevLockFile = NULL;
54 int prevLockLine = 0;
55 #endif
56
57 /* Turn on/off page flipping according to the flags in the sarea:
58 */
59 static void radeonUpdatePageFlipping(radeonContextPtr rmesa)
60 {
61 rmesa->doPageFlip = rmesa->sarea->pfState;
62 if (rmesa->glCtx->WinSysDrawBuffer) {
63 driFlipRenderbuffers(rmesa->glCtx->WinSysDrawBuffer,
64 rmesa->sarea->pfCurrentPage);
65 }
66 }
67
68 /* Update the hardware state. This is called if another context has
69 * grabbed the hardware lock, which includes the X server. This
70 * function also updates the driver's window state after the X server
71 * moves, resizes or restacks a window -- the change will be reflected
72 * in the drawable position and clip rects. Since the X server grabs
73 * the hardware lock when it changes the window state, this routine will
74 * automatically be called after such a change.
75 */
76 void radeonGetLock(radeonContextPtr rmesa, GLuint flags)
77 {
78 __DRIdrawablePrivate *const drawable = rmesa->dri.drawable;
79 __DRIdrawablePrivate *const readable = rmesa->dri.readable;
80 __DRIscreenPrivate *sPriv = rmesa->dri.screen;
81 drm_radeon_sarea_t *sarea = rmesa->sarea;
82
83 drmGetLock(rmesa->dri.fd, rmesa->dri.hwContext, flags);
84
85 /* The window might have moved, so we might need to get new clip
86 * rects.
87 *
88 * NOTE: This releases and regrabs the hw lock to allow the X server
89 * to respond to the DRI protocol request for new drawable info.
90 * Since the hardware state depends on having the latest drawable
91 * clip rects, all state checking must be done _after_ this call.
92 */
93 DRI_VALIDATE_DRAWABLE_INFO(sPriv, drawable);
94 if (drawable != readable) {
95 DRI_VALIDATE_DRAWABLE_INFO(sPriv, readable);
96 }
97
98 if (rmesa->lastStamp != drawable->lastStamp) {
99 radeonUpdatePageFlipping(rmesa);
100 radeonSetCliprects(rmesa);
101 radeonUpdateViewportOffset(rmesa->glCtx);
102 driUpdateFramebufferSize(rmesa->glCtx, drawable);
103 }
104
105 RADEON_STATECHANGE(rmesa, ctx);
106 if (rmesa->sarea->tiling_enabled) {
107 rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] |=
108 RADEON_COLOR_TILE_ENABLE;
109 } else {
110 rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] &=
111 ~RADEON_COLOR_TILE_ENABLE;
112 }
113
114 if (sarea->ctx_owner != rmesa->dri.hwContext) {
115 int i;
116 sarea->ctx_owner = rmesa->dri.hwContext;
117
118 for (i = 0; i < rmesa->nr_heaps; i++) {
119 DRI_AGE_TEXTURES(rmesa->texture_heaps[i]);
120 }
121 }
122
123 rmesa->lost_context = GL_TRUE;
124 }