1 /**************************************************************************
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.
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.
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:
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.
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.
33 **************************************************************************/
37 * Gareth Hughes <gareth@valinux.com>
38 * Keith Whitwell <keith@tungstengraphics.com>
39 * Kevin E. Martin <martin@valinux.com>
42 #include "radeon_lock.h"
43 #include "radeon_ioctl.h"
44 #include "radeon_state.h"
45 #include "r300_context.h"
46 #include "r300_state.h"
48 #include "framebuffer.h"
50 #include "drirenderbuffer.h"
53 char *prevLockFile
= NULL
;
57 /* Turn on/off page flipping according to the flags in the sarea:
59 void radeonUpdatePageFlipping(radeonContextPtr rmesa
)
63 rmesa
->doPageFlip
= rmesa
->sarea
->pfState
;
64 if (rmesa
->glCtx
->WinSysDrawBuffer
) {
65 driFlipRenderbuffers(rmesa
->glCtx
->WinSysDrawBuffer
,
66 rmesa
->sarea
->pfCurrentPage
);
67 r300UpdateDrawBuffer(rmesa
->glCtx
);
70 use_back
= rmesa
->glCtx
->DrawBuffer
?
71 (rmesa
->glCtx
->DrawBuffer
->_ColorDrawBufferMask
[0] ==
72 BUFFER_BIT_BACK_LEFT
) : 1;
73 use_back
^= (rmesa
->sarea
->pfCurrentPage
== 1);
76 rmesa
->state
.color
.drawOffset
=
77 rmesa
->radeonScreen
->backOffset
;
78 rmesa
->state
.color
.drawPitch
= rmesa
->radeonScreen
->backPitch
;
80 rmesa
->state
.color
.drawOffset
=
81 rmesa
->radeonScreen
->frontOffset
;
82 rmesa
->state
.color
.drawPitch
=
83 rmesa
->radeonScreen
->frontPitch
;
87 /* Update the hardware state. This is called if another context has
88 * grabbed the hardware lock, which includes the X server. This
89 * function also updates the driver's window state after the X server
90 * moves, resizes or restacks a window -- the change will be reflected
91 * in the drawable position and clip rects. Since the X server grabs
92 * the hardware lock when it changes the window state, this routine will
93 * automatically be called after such a change.
95 void radeonGetLock(radeonContextPtr rmesa
, GLuint flags
)
97 __DRIdrawablePrivate
*const drawable
= rmesa
->dri
.drawable
;
98 __DRIdrawablePrivate
*const readable
= rmesa
->dri
.readable
;
99 __DRIscreenPrivate
*sPriv
= rmesa
->dri
.screen
;
100 drm_radeon_sarea_t
*sarea
= rmesa
->sarea
;
101 r300ContextPtr r300
= (r300ContextPtr
) rmesa
;
103 assert(drawable
!= NULL
);
105 drmGetLock(rmesa
->dri
.fd
, rmesa
->dri
.hwContext
, flags
);
107 /* The window might have moved, so we might need to get new clip
110 * NOTE: This releases and regrabs the hw lock to allow the X server
111 * to respond to the DRI protocol request for new drawable info.
112 * Since the hardware state depends on having the latest drawable
113 * clip rects, all state checking must be done _after_ this call.
115 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, drawable
);
116 if (drawable
!= readable
) {
117 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, readable
);
120 if (rmesa
->lastStamp
!= drawable
->lastStamp
) {
121 radeonUpdatePageFlipping(rmesa
);
122 radeonSetCliprects(rmesa
);
123 r300UpdateViewportOffset(rmesa
->glCtx
);
124 driUpdateFramebufferSize(rmesa
->glCtx
, drawable
);
127 if (sarea
->ctx_owner
!= rmesa
->dri
.hwContext
) {
130 sarea
->ctx_owner
= rmesa
->dri
.hwContext
;
131 for (i
= 0; i
< r300
->nr_heaps
; i
++) {
132 DRI_AGE_TEXTURES(r300
->texture_heaps
[i
]);
136 rmesa
->lost_context
= GL_TRUE
;