2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
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.
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:
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.
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.
28 **************************************************************************/
32 * Keith Whitwell <keith@tungstengraphics.com>
36 #include "r200_context.h"
37 #include "radeon_lock.h"
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"
47 #include "framebuffer.h"
49 #include "drirenderbuffer.h"
52 char *prevLockFile
= NULL
;
56 /* Turn on/off page flipping according to the flags in the sarea:
58 static void radeonUpdatePageFlipping(radeonContextPtr radeon
)
62 radeon
->doPageFlip
= radeon
->sarea
->pfState
;
63 if (!radeon
->doPageFlip
) {
64 driFlipRenderbuffers(radeon
->glCtx
->WinSysDrawBuffer
, GL_FALSE
);
67 use_back
= (radeon
->glCtx
->DrawBuffer
->_ColorDrawBufferMask
[0] == BUFFER_BIT_BACK_LEFT
);
68 use_back
^= (radeon
->sarea
->pfCurrentPage
== 1);
71 radeon
->state
.color
.drawOffset
= radeon
->radeonScreen
->backOffset
;
72 radeon
->state
.color
.drawPitch
= radeon
->radeonScreen
->backPitch
;
74 radeon
->state
.color
.drawOffset
= radeon
->radeonScreen
->frontOffset
;
75 radeon
->state
.color
.drawPitch
= radeon
->radeonScreen
->frontPitch
;
80 * Called by radeonGetLock() after the lock has been obtained.
83 static void r200RegainedLock(r200ContextPtr r200
)
85 __DRIdrawablePrivate
*dPriv
= r200
->radeon
.dri
.drawable
;
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
;
97 if (r200
->radeon
.glCtx
->DrawBuffer
->_ColorDrawBufferMask
[0] == BUFFER_BIT_BACK_LEFT
)
98 radeonSetCliprects(&r200
->radeon
, GL_BACK_LEFT
);
100 radeonSetCliprects(&r200
->radeon
, GL_FRONT_LEFT
);
101 r200UpdateViewportOffset(r200
->radeon
.glCtx
);
102 r200
->radeon
.lastStamp
= dPriv
->lastStamp
;
105 for (i
= 0; i
< r200
->nr_heaps
; i
++) {
106 DRI_AGE_TEXTURES(r200
->texture_heaps
[i
]);
111 static void r300RegainedLock(radeonContextPtr radeon
)
113 __DRIdrawablePrivate
*dPriv
= radeon
->dri
.drawable
;
115 r300ContextPtr r300
= (r300ContextPtr
)radeon
;
117 if (radeon
->lastStamp
!= dPriv
->lastStamp
) {
118 _mesa_resize_framebuffer(radeon
->glCtx
,
119 (GLframebuffer
*)dPriv
->driverPrivate
,
122 radeonUpdatePageFlipping(radeon
);
124 if (radeon
->glCtx
->DrawBuffer
->_ColorDrawBufferMask
[0] == BUFFER_BIT_BACK_LEFT
)
125 radeonSetCliprects(radeon
, GL_BACK_LEFT
);
127 radeonSetCliprects(radeon
, GL_FRONT_LEFT
);
130 r300UpdateViewportOffset( radeon
->glCtx
);
131 driUpdateFramebufferSize(radeon
->glCtx
, dPriv
);
133 radeonUpdateScissor(radeon
->glCtx
);
135 radeon
->lastStamp
= dPriv
->lastStamp
;
138 for (i
= 0; i
< r300
->nr_heaps
; i
++) {
139 DRI_AGE_TEXTURES(r300
->texture_heaps
[i
]);
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.
151 void radeonGetLock(radeonContextPtr radeon
, GLuint flags
)
153 __DRIdrawablePrivate
*dPriv
= radeon
->dri
.drawable
;
154 __DRIscreenPrivate
*sPriv
= radeon
->dri
.screen
;
155 drm_radeon_sarea_t
*sarea
= radeon
->sarea
;
157 drmGetLock(radeon
->dri
.fd
, radeon
->dri
.hwContext
, flags
);
159 /* The window might have moved, so we might need to get new clip
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.
167 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
169 if (sarea
->ctx_owner
!= radeon
->dri
.hwContext
)
170 sarea
->ctx_owner
= radeon
->dri
.hwContext
;
172 if (IS_R300_CLASS(radeon
->radeonScreen
))
173 r300RegainedLock(radeon
);
176 r200RegainedLock((r200ContextPtr
)radeon
);
179 radeon
->lost_context
= GL_TRUE
;