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 **************************************************************************/
31 * \file radeon_context.c
32 * Common context initialization.
34 * \author Keith Whitwell <keith@tungstengraphics.com>
39 #include "main/glheader.h"
40 #include "main/imports.h"
41 #include "main/context.h"
42 #include "main/state.h"
43 #include "main/matrix.h"
44 #include "main/framebuffer.h"
46 #include "drivers/common/driverfuncs.h"
47 #include "swrast/swrast.h"
49 #include "radeon_screen.h"
50 #include "radeon_ioctl.h"
51 #include "radeon_macros.h"
52 #include "radeon_reg.h"
54 #include "radeon_state.h"
55 #include "r300_state.h"
59 #include "xmlpool.h" /* for symbolic values of enum-type options */
61 #define DRIVER_DATE "20060815"
64 /* Return various strings for glGetString().
66 static const GLubyte
*radeonGetString(GLcontext
* ctx
, GLenum name
)
68 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
69 static char buffer
[128];
73 if (IS_R300_CLASS(radeon
->radeonScreen
))
74 return (GLubyte
*) "DRI R300 Project";
76 return (GLubyte
*) "Tungsten Graphics, Inc.";
81 GLuint agp_mode
= (radeon
->radeonScreen
->card_type
==RADEON_CARD_PCI
) ? 0 :
82 radeon
->radeonScreen
->AGPMode
;
85 if (IS_R300_CLASS(radeon
->radeonScreen
))
90 offset
= driGetRendererString(buffer
, chipname
, DRIVER_DATE
,
93 if (IS_R300_CLASS(radeon
->radeonScreen
)) {
94 sprintf(&buffer
[offset
], " %sTCL",
95 (radeon
->radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
)
98 sprintf(&buffer
[offset
], " %sTCL",
99 !(radeon
->TclFallback
& RADEON_TCL_FALLBACK_TCL_DISABLE
)
103 return (GLubyte
*) buffer
;
111 /* Initialize the driver's misc functions.
113 static void radeonInitDriverFuncs(struct dd_function_table
*functions
)
115 functions
->GetString
= radeonGetString
;
120 * Create and initialize all common fields of the context,
121 * including the Mesa context itself.
123 GLboolean
radeonInitContext(radeonContextPtr radeon
,
124 struct dd_function_table
* functions
,
125 const __GLcontextModes
* glVisual
,
126 __DRIcontextPrivate
* driContextPriv
,
127 void *sharedContextPrivate
)
129 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
130 radeonScreenPtr screen
= (radeonScreenPtr
) (sPriv
->private);
135 /* Fill in additional standard functions. */
136 radeonInitDriverFuncs(functions
);
138 radeon
->radeonScreen
= screen
;
139 /* Allocate and initialize the Mesa context */
140 if (sharedContextPrivate
)
141 shareCtx
= ((radeonContextPtr
)sharedContextPrivate
)->glCtx
;
144 radeon
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
145 functions
, (void *)radeon
);
150 driContextPriv
->driverPrivate
= radeon
;
153 radeon
->dri
.context
= driContextPriv
;
154 radeon
->dri
.screen
= sPriv
;
155 radeon
->dri
.drawable
= NULL
;
156 radeon
->dri
.readable
= NULL
;
157 radeon
->dri
.hwContext
= driContextPriv
->hHWContext
;
158 radeon
->dri
.hwLock
= &sPriv
->pSAREA
->lock
;
159 radeon
->dri
.fd
= sPriv
->fd
;
160 radeon
->dri
.drmMinor
= sPriv
->drm_version
.minor
;
162 radeon
->sarea
= (drm_radeon_sarea_t
*) ((GLubyte
*) sPriv
->pSAREA
+
163 screen
->sarea_priv_offset
);
166 fthrottle_mode
= driQueryOptioni(&radeon
->optionCache
, "fthrottle_mode");
167 radeon
->iw
.irq_seq
= -1;
168 radeon
->irqsEmitted
= 0;
169 radeon
->do_irqs
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
&&
170 radeon
->radeonScreen
->irq
);
172 radeon
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
174 if (!radeon
->do_irqs
)
176 "IRQ's not enabled, falling back to %s: %d %d\n",
177 radeon
->do_usleeps
? "usleeps" : "busy waits",
178 fthrottle_mode
, radeon
->radeonScreen
->irq
);
180 (*sPriv
->systemTime
->getUST
) (&radeon
->swap_ust
);
187 * Cleanup common context fields.
188 * Called by r200DestroyContext/r300DestroyContext
190 void radeonCleanupContext(radeonContextPtr radeon
)
192 /* _mesa_destroy_context() might result in calls to functions that
193 * depend on the DriverCtx, so don't set it to NULL before.
195 * radeon->glCtx->DriverCtx = NULL;
198 /* free the Mesa context */
199 _mesa_destroy_context(radeon
->glCtx
);
201 if (radeon
->state
.scissor
.pClipRects
) {
202 FREE(radeon
->state
.scissor
.pClipRects
);
203 radeon
->state
.scissor
.pClipRects
= 0;
209 * Swap front and back buffer.
211 void radeonSwapBuffers(__DRIdrawablePrivate
* dPriv
)
213 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
214 radeonContextPtr radeon
;
217 radeon
= (radeonContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
220 if (ctx
->Visual
.doubleBufferMode
) {
221 _mesa_notifySwapBuffers(ctx
); /* flush pending rendering comands */
222 if (radeon
->doPageFlip
) {
223 radeonPageFlip(dPriv
);
225 radeonCopyBuffer(dPriv
, NULL
);
229 /* XXX this shouldn't be an error but we can't handle it for now */
230 _mesa_problem(NULL
, "%s: drawable has no context!",
235 void radeonCopySubBuffer(__DRIdrawablePrivate
* dPriv
,
236 int x
, int y
, int w
, int h
)
238 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
239 radeonContextPtr radeon
;
242 radeon
= (radeonContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
245 if (ctx
->Visual
.doubleBufferMode
) {
246 drm_clip_rect_t rect
;
247 rect
.x1
= x
+ dPriv
->x
;
248 rect
.y1
= (dPriv
->h
- y
- h
) + dPriv
->y
;
249 rect
.x2
= rect
.x1
+ w
;
250 rect
.y2
= rect
.y1
+ h
;
251 _mesa_notifySwapBuffers(ctx
); /* flush pending rendering comands */
252 radeonCopyBuffer(dPriv
, &rect
);
255 /* XXX this shouldn't be an error but we can't handle it for now */
256 _mesa_problem(NULL
, "%s: drawable has no context!",
261 /* Force the context `c' to be the current context and associate with it
264 GLboolean
radeonMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
265 __DRIdrawablePrivate
* driDrawPriv
,
266 __DRIdrawablePrivate
* driReadPriv
)
268 if (driContextPriv
) {
269 radeonContextPtr radeon
=
270 (radeonContextPtr
) driContextPriv
->driverPrivate
;
272 if (RADEON_DEBUG
& DEBUG_DRI
)
273 fprintf(stderr
, "%s ctx %p\n", __FUNCTION__
,
276 if (radeon
->dri
.drawable
!= driDrawPriv
) {
277 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
278 driDrawPriv
->vblFlags
=
279 (radeon
->radeonScreen
->irq
!= 0)
280 ? driGetDefaultVBlankFlags(&radeon
->
282 : VBLANK_FLAG_NO_IRQ
;
284 driDrawableInitVBlank(driDrawPriv
);
288 radeon
->dri
.readable
= driReadPriv
;
290 if (radeon
->dri
.drawable
!= driDrawPriv
||
291 radeon
->lastStamp
!= driDrawPriv
->lastStamp
) {
292 radeon
->dri
.drawable
= driDrawPriv
;
294 radeonSetCliprects(radeon
);
295 r300UpdateViewportOffset(radeon
->glCtx
);
298 _mesa_make_current(radeon
->glCtx
,
299 (GLframebuffer
*) driDrawPriv
->
301 (GLframebuffer
*) driReadPriv
->
304 _mesa_update_state(radeon
->glCtx
);
306 radeonUpdatePageFlipping(radeon
);
308 if (RADEON_DEBUG
& DEBUG_DRI
)
309 fprintf(stderr
, "%s ctx is null\n", __FUNCTION__
);
310 _mesa_make_current(0, 0, 0);
313 if (RADEON_DEBUG
& DEBUG_DRI
)
314 fprintf(stderr
, "End %s\n", __FUNCTION__
);
318 /* Force the context `c' to be unbound from its buffer.
320 GLboolean
radeonUnbindContext(__DRIcontextPrivate
* driContextPriv
)
322 radeonContextPtr radeon
= (radeonContextPtr
) driContextPriv
->driverPrivate
;
324 if (RADEON_DEBUG
& DEBUG_DRI
)
325 fprintf(stderr
, "%s ctx %p\n", __FUNCTION__
,