1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_context.c,v 1.3 2003/05/06 23:52:08 daenzer Exp $ */
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
33 * Keith Whitwell <keith@tungstengraphics.com>
37 #include "api_arrayelt.h"
39 #include "simple_list.h"
42 #include "extensions.h"
43 #include "framebuffer.h"
46 #include "swrast/swrast.h"
47 #include "swrast_setup/swrast_setup.h"
48 #include "array_cache/acache.h"
51 #include "tnl/t_pipeline.h"
53 #include "drivers/common/driverfuncs.h"
55 #include "r200_context.h"
56 #include "r200_ioctl.h"
57 #include "r200_state.h"
58 #include "r200_span.h"
59 #include "r200_pixel.h"
61 #include "r200_swtcl.h"
63 #include "r200_vtxfmt.h"
64 #include "r200_maos.h"
65 #include "r200_vertprog.h"
67 #define need_GL_ARB_multisample
68 #define need_GL_ARB_texture_compression
69 #define need_GL_ARB_vertex_buffer_object
70 #define need_GL_ARB_vertex_program
71 #define need_GL_ATI_fragment_shader
72 #define need_GL_EXT_blend_minmax
73 #define need_GL_EXT_fog_coord
74 #define need_GL_EXT_secondary_color
75 #define need_GL_EXT_blend_equation_separate
76 #define need_GL_EXT_blend_func_separate
77 #define need_GL_NV_vertex_program
78 #define need_GL_ARB_point_parameters
79 #include "extension_helper.h"
81 #define DRIVER_DATE "20060602"
85 #include "xmlpool.h" /* for symbolic values of enum-type options */
91 /* Return the width and height of the given buffer.
93 static void r200GetBufferSize( GLframebuffer
*buffer
,
94 GLuint
*width
, GLuint
*height
)
96 GET_CURRENT_CONTEXT(ctx
);
97 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
99 LOCK_HARDWARE( rmesa
);
100 *width
= rmesa
->dri
.drawable
->w
;
101 *height
= rmesa
->dri
.drawable
->h
;
102 UNLOCK_HARDWARE( rmesa
);
105 /* Return various strings for glGetString().
107 static const GLubyte
*r200GetString( GLcontext
*ctx
, GLenum name
)
109 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
110 static char buffer
[128];
112 GLuint agp_mode
= (rmesa
->r200Screen
->card_type
== RADEON_CARD_PCI
)? 0 :
113 rmesa
->r200Screen
->AGPMode
;
117 return (GLubyte
*)"Tungsten Graphics, Inc.";
120 offset
= driGetRendererString( buffer
, "R200", DRIVER_DATE
,
123 sprintf( & buffer
[ offset
], " %sTCL",
124 !(rmesa
->TclFallback
& R200_TCL_FALLBACK_TCL_DISABLE
)
127 return (GLubyte
*)buffer
;
135 /* Extension strings exported by the R200 driver.
137 const struct dri_extension card_extensions
[] =
139 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
140 { "GL_ARB_multitexture", NULL
},
141 { "GL_ARB_texture_border_clamp", NULL
},
142 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
143 { "GL_ARB_texture_env_add", NULL
},
144 { "GL_ARB_texture_env_combine", NULL
},
145 { "GL_ARB_texture_env_dot3", NULL
},
146 { "GL_ARB_texture_env_crossbar", NULL
},
147 { "GL_ARB_texture_mirrored_repeat", NULL
},
148 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
149 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions
},
150 { "GL_EXT_blend_subtract", NULL
},
151 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
152 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
153 { "GL_EXT_stencil_wrap", NULL
},
154 { "GL_EXT_texture_edge_clamp", NULL
},
155 { "GL_EXT_texture_env_combine", NULL
},
156 { "GL_EXT_texture_env_dot3", NULL
},
157 { "GL_EXT_texture_filter_anisotropic", NULL
},
158 { "GL_EXT_texture_lod_bias", NULL
},
159 { "GL_EXT_texture_mirror_clamp", NULL
},
160 { "GL_EXT_texture_rectangle", NULL
},
161 { "GL_ATI_texture_env_combine3", NULL
},
162 { "GL_ATI_texture_mirror_once", NULL
},
163 { "GL_MESA_pack_invert", NULL
},
164 { "GL_NV_blend_square", NULL
},
165 { "GL_SGIS_generate_mipmap", NULL
},
169 const struct dri_extension blend_extensions
[] = {
170 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions
},
171 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
175 const struct dri_extension ARB_vp_extension
[] = {
176 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
}
179 const struct dri_extension NV_vp_extension
[] = {
180 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
}
183 const struct dri_extension ATI_fs_extension
[] = {
184 { "GL_ATI_fragment_shader", GL_ATI_fragment_shader_functions
}
187 const struct dri_extension point_extensions
[] = {
188 { "GL_ARB_point_sprite", NULL
},
189 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
193 extern const struct tnl_pipeline_stage _r200_render_stage
;
194 extern const struct tnl_pipeline_stage _r200_tcl_stage
;
196 static const struct tnl_pipeline_stage
*r200_pipeline
[] = {
198 /* Try and go straight to t&l
202 /* Catch any t&l fallbacks
204 &_tnl_vertex_transform_stage
,
205 &_tnl_normal_transform_stage
,
206 &_tnl_lighting_stage
,
207 &_tnl_fog_coordinate_stage
,
209 &_tnl_texture_transform_stage
,
210 &_tnl_point_attenuation_stage
,
211 &_tnl_arb_vertex_program_stage
,
212 &_tnl_vertex_program_stage
,
213 /* Try again to go to tcl?
214 * - no good for asymmetric-twoside (do with multipass)
215 * - no good for asymmetric-unfilled (do with multipass)
216 * - good for material
218 * - need to manipulate a bit of state
220 * - worth it/not worth it?
223 /* Else do them here.
225 /* &_r200_render_stage, */ /* FIXME: bugs with ut2003 */
226 &_tnl_render_stage
, /* FALLBACK: */
232 /* Initialize the driver's misc functions.
234 static void r200InitDriverFuncs( struct dd_function_table
*functions
)
236 functions
->GetBufferSize
= r200GetBufferSize
;
237 functions
->ResizeBuffers
= _mesa_resize_framebuffer
;
238 functions
->GetString
= r200GetString
;
240 functions
->Error
= NULL
;
241 functions
->DrawPixels
= NULL
;
242 functions
->Bitmap
= NULL
;
245 static const struct dri_debug_control debug_control
[] =
247 { "fall", DEBUG_FALLBACKS
},
248 { "tex", DEBUG_TEXTURE
},
249 { "ioctl", DEBUG_IOCTL
},
250 { "prim", DEBUG_PRIMS
},
251 { "vert", DEBUG_VERTS
},
252 { "state", DEBUG_STATE
},
253 { "code", DEBUG_CODEGEN
},
254 { "vfmt", DEBUG_VFMT
},
255 { "vtxf", DEBUG_VFMT
},
256 { "verb", DEBUG_VERBOSE
},
257 { "dri", DEBUG_DRI
},
258 { "dma", DEBUG_DMA
},
259 { "san", DEBUG_SANITY
},
260 { "sync", DEBUG_SYNC
},
261 { "pix", DEBUG_PIXEL
},
262 { "mem", DEBUG_MEMORY
},
267 /* Create the device specific rendering context.
269 GLboolean
r200CreateContext( const __GLcontextModes
*glVisual
,
270 __DRIcontextPrivate
*driContextPriv
,
271 void *sharedContextPrivate
)
273 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
274 radeonScreenPtr screen
= (radeonScreenPtr
)(sPriv
->private);
275 struct dd_function_table functions
;
276 r200ContextPtr rmesa
;
277 GLcontext
*ctx
, *shareCtx
;
279 int tcl_mode
, fthrottle_mode
;
282 assert(driContextPriv
);
285 /* Allocate the R200 context */
286 rmesa
= (r200ContextPtr
) CALLOC( sizeof(*rmesa
) );
290 /* init exp fog table data */
291 r200InitStaticFogData();
293 /* Parse configuration files.
294 * Do this here so that initialMaxAnisotropy is set before we create
295 * the default textures.
297 driParseConfigFiles (&rmesa
->optionCache
, &screen
->optionCache
,
298 screen
->driScreen
->myNum
, "r200");
299 rmesa
->initialMaxAnisotropy
= driQueryOptionf(&rmesa
->optionCache
,
300 "def_max_anisotropy");
302 if ( driQueryOptionb( &rmesa
->optionCache
, "hyperz" ) ) {
303 if ( sPriv
->drmMinor
< 13 )
304 fprintf( stderr
, "DRM version 1.%d too old to support HyperZ, "
305 "disabling.\n",sPriv
->drmMinor
);
307 rmesa
->using_hyperz
= GL_TRUE
;
310 if ( sPriv
->drmMinor
>= 15 )
311 rmesa
->texmicrotile
= GL_TRUE
;
313 /* Init default driver functions then plug in our R200-specific functions
314 * (the texture functions are especially important)
316 _mesa_init_driver_functions(&functions
);
317 r200InitDriverFuncs(&functions
);
318 r200InitIoctlFuncs(&functions
);
319 r200InitStateFuncs(&functions
);
320 r200InitTextureFuncs(&functions
);
321 r200InitShaderFuncs(&functions
);
323 /* Allocate and initialize the Mesa context */
324 if (sharedContextPrivate
)
325 shareCtx
= ((r200ContextPtr
) sharedContextPrivate
)->glCtx
;
328 rmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
329 &functions
, (void *) rmesa
);
334 driContextPriv
->driverPrivate
= rmesa
;
336 /* Init r200 context data */
337 rmesa
->dri
.context
= driContextPriv
;
338 rmesa
->dri
.screen
= sPriv
;
339 rmesa
->dri
.drawable
= NULL
; /* Set by XMesaMakeCurrent */
340 rmesa
->dri
.hwContext
= driContextPriv
->hHWContext
;
341 rmesa
->dri
.hwLock
= &sPriv
->pSAREA
->lock
;
342 rmesa
->dri
.fd
= sPriv
->fd
;
343 rmesa
->dri
.drmMinor
= sPriv
->drmMinor
;
345 rmesa
->r200Screen
= screen
;
346 rmesa
->sarea
= (drm_radeon_sarea_t
*)((GLubyte
*)sPriv
->pSAREA
+
347 screen
->sarea_priv_offset
);
350 rmesa
->dma
.buf0_address
= rmesa
->r200Screen
->buffers
->list
[0].address
;
352 (void) memset( rmesa
->texture_heaps
, 0, sizeof( rmesa
->texture_heaps
) );
353 make_empty_list( & rmesa
->swapped
);
355 rmesa
->nr_heaps
= 1 /* screen->numTexHeaps */ ;
356 assert(rmesa
->nr_heaps
< RADEON_NR_TEX_HEAPS
);
357 for ( i
= 0 ; i
< rmesa
->nr_heaps
; i
++ ) {
358 rmesa
->texture_heaps
[i
] = driCreateTextureHeap( i
, rmesa
,
361 RADEON_NR_TEX_REGIONS
,
362 (drmTextureRegionPtr
)rmesa
->sarea
->tex_list
[i
],
363 & rmesa
->sarea
->tex_age
[i
],
365 sizeof( r200TexObj
),
366 (destroy_texture_object_t
*) r200DestroyTexObj
);
368 rmesa
->texture_depth
= driQueryOptioni (&rmesa
->optionCache
,
370 if (rmesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
371 rmesa
->texture_depth
= ( screen
->cpp
== 4 ) ?
372 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
374 rmesa
->swtcl
.RenderIndex
= ~0;
375 rmesa
->hw
.all_dirty
= 1;
377 /* Set the maximum texture size small enough that we can guarentee that
378 * all texture units can bind a maximal texture and have all of them in
379 * texturable memory at once. Depending on the allow_large_textures driconf
380 * setting allow larger textures.
384 ctx
->Const
.MaxTextureUnits
= driQueryOptioni (&rmesa
->optionCache
,
386 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
387 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
389 i
= driQueryOptioni( &rmesa
->optionCache
, "allow_large_textures");
391 driCalculateMaxTextureLevels( rmesa
->texture_heaps
,
395 11, /* max 2D texture size is 2048x2048 */
396 #if ENABLE_HW_3D_TEXTURE
397 8, /* max 3D texture size is 256^3 */
399 0, /* 3D textures unsupported */
401 11, /* max cube texture size is 2048x2048 */
402 11, /* max texture rectangle size is 2048x2048 */
407 ctx
->Const
.MaxTextureMaxAnisotropy
= 16.0;
409 /* No wide AA points.
411 ctx
->Const
.MinPointSize
= 1.0;
412 ctx
->Const
.MinPointSizeAA
= 1.0;
413 ctx
->Const
.MaxPointSizeAA
= 1.0;
414 ctx
->Const
.PointSizeGranularity
= 0.0625;
415 if (rmesa
->r200Screen
->drmSupportsPointSprites
)
416 ctx
->Const
.MaxPointSize
= 2047.0;
418 ctx
->Const
.MaxPointSize
= 1.0;
420 /* mesa initialization problem - _mesa_init_point was already called */
421 ctx
->Point
.MaxSize
= ctx
->Const
.MaxPointSize
;
423 ctx
->Const
.MinLineWidth
= 1.0;
424 ctx
->Const
.MinLineWidthAA
= 1.0;
425 ctx
->Const
.MaxLineWidth
= 10.0;
426 ctx
->Const
.MaxLineWidthAA
= 10.0;
427 ctx
->Const
.LineWidthGranularity
= 0.0625;
429 ctx
->Const
.VertexProgram
.MaxNativeInstructions
= R200_VSF_MAX_INST
;
430 ctx
->Const
.VertexProgram
.MaxNativeAttribs
= 12;
431 ctx
->Const
.VertexProgram
.MaxNativeTemps
= R200_VSF_MAX_TEMPS
;
432 ctx
->Const
.VertexProgram
.MaxNativeParameters
= R200_VSF_MAX_PARAM
;
433 ctx
->Const
.VertexProgram
.MaxNativeAddressRegs
= 1;
435 /* Initialize the software rasterizer and helper modules.
437 _swrast_CreateContext( ctx
);
438 _ac_CreateContext( ctx
);
439 _tnl_CreateContext( ctx
);
440 _swsetup_CreateContext( ctx
);
441 _ae_create_context( ctx
);
443 /* Install the customized pipeline:
445 _tnl_destroy_pipeline( ctx
);
446 _tnl_install_pipeline( ctx
, r200_pipeline
);
447 ctx
->Driver
.FlushVertices
= r200FlushVertices
;
449 /* Try and keep materials and vertices separate:
451 _tnl_isolate_materials( ctx
, GL_TRUE
);
454 /* Configure swrast and TNL to match hardware characteristics:
456 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
457 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
458 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
459 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
462 for ( i
= 0 ; i
< R200_MAX_TEXTURE_UNITS
; i
++ ) {
463 _math_matrix_ctr( &rmesa
->TexGenMatrix
[i
] );
464 _math_matrix_set_identity( &rmesa
->TexGenMatrix
[i
] );
466 _math_matrix_ctr( &rmesa
->tmpmat
);
467 _math_matrix_set_identity( &rmesa
->tmpmat
);
469 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
470 if (!(rmesa
->r200Screen
->chip_flags
& R200_CHIPSET_YCBCR_BROKEN
)) {
471 /* yuv textures don't work with some chips - R200 / rv280 okay so far
472 others get the bit ordering right but don't actually do YUV-RGB conversion */
473 _mesa_enable_extension( ctx
, "GL_MESA_ycbcr_texture" );
475 if (rmesa
->glCtx
->Mesa_DXTn
) {
476 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
477 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
479 else if (driQueryOptionb (&rmesa
->optionCache
, "force_s3tc_enable")) {
480 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
483 if (rmesa
->r200Screen
->drmSupportsCubeMapsR200
)
484 _mesa_enable_extension( ctx
, "GL_ARB_texture_cube_map" );
485 if (rmesa
->r200Screen
->drmSupportsBlendColor
) {
486 driInitExtensions( ctx
, blend_extensions
, GL_FALSE
);
488 if(rmesa
->r200Screen
->drmSupportsVertexProgram
)
489 driInitSingleExtension( ctx
, ARB_vp_extension
);
490 if(driQueryOptionb(&rmesa
->optionCache
, "nv_vertex_program"))
491 driInitSingleExtension( ctx
, NV_vp_extension
);
493 if ((ctx
->Const
.MaxTextureUnits
== 6) && rmesa
->r200Screen
->drmSupportsFragShader
)
494 driInitSingleExtension( ctx
, ATI_fs_extension
);
495 if (rmesa
->r200Screen
->drmSupportsPointSprites
)
496 driInitExtensions( ctx
, point_extensions
, GL_FALSE
);
498 r200InitDriverFuncs( ctx
);
499 r200InitIoctlFuncs( ctx
);
500 r200InitStateFuncs( ctx
);
501 r200InitTextureFuncs( ctx
);
503 /* plug in a few more device driver functions */
504 /* XXX these should really go right after _mesa_init_driver_functions() */
505 r200InitPixelFuncs( ctx
);
506 r200InitSpanFuncs( ctx
);
507 r200InitTnlFuncs( ctx
);
508 r200InitState( rmesa
);
509 r200InitSwtcl( ctx
);
511 fthrottle_mode
= driQueryOptioni(&rmesa
->optionCache
, "fthrottle_mode");
512 rmesa
->iw
.irq_seq
= -1;
513 rmesa
->irqsEmitted
= 0;
514 rmesa
->do_irqs
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
&&
515 rmesa
->r200Screen
->irq
);
517 rmesa
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
521 "IRQ's not enabled, falling back to %s: %d %d\n",
522 rmesa
->do_usleeps
? "usleeps" : "busy waits",
524 rmesa
->r200Screen
->irq
);
526 rmesa
->vblank_flags
= (rmesa
->r200Screen
->irq
!= 0)
527 ? driGetDefaultVBlankFlags(&rmesa
->optionCache
) : VBLANK_FLAG_NO_IRQ
;
529 rmesa
->prefer_gart_client_texturing
=
530 (getenv("R200_GART_CLIENT_TEXTURES") != 0);
532 (*dri_interface
->getUST
)( & rmesa
->swap_ust
);
536 R200_DEBUG
= driParseDebugString( getenv( "R200_DEBUG" ),
538 R200_DEBUG
|= driParseDebugString( getenv( "RADEON_DEBUG" ),
542 tcl_mode
= driQueryOptioni(&rmesa
->optionCache
, "tcl_mode");
543 if (driQueryOptionb(&rmesa
->optionCache
, "no_rast")) {
544 fprintf(stderr
, "disabling 3D acceleration\n");
545 FALLBACK(rmesa
, R200_FALLBACK_DISABLE
, 1);
547 else if (tcl_mode
== DRI_CONF_TCL_SW
|| getenv("R200_NO_TCL") ||
548 !(rmesa
->r200Screen
->chip_flags
& RADEON_CHIPSET_TCL
)) {
549 if (rmesa
->r200Screen
->chip_flags
& RADEON_CHIPSET_TCL
) {
550 rmesa
->r200Screen
->chip_flags
&= ~RADEON_CHIPSET_TCL
;
551 fprintf(stderr
, "Disabling HW TCL support\n");
553 TCL_FALLBACK(rmesa
->glCtx
, R200_TCL_FALLBACK_TCL_DISABLE
, 1);
556 if (rmesa
->r200Screen
->chip_flags
& RADEON_CHIPSET_TCL
) {
557 if (tcl_mode
>= DRI_CONF_TCL_VTXFMT
)
558 r200VtxfmtInit( ctx
, tcl_mode
>= DRI_CONF_TCL_CODEGEN
);
560 _tnl_need_dlist_norm_lengths( ctx
, GL_FALSE
);
566 /* Destroy the device specific context.
568 /* Destroy the Mesa and driver specific context data.
570 void r200DestroyContext( __DRIcontextPrivate
*driContextPriv
)
572 GET_CURRENT_CONTEXT(ctx
);
573 r200ContextPtr rmesa
= (r200ContextPtr
) driContextPriv
->driverPrivate
;
574 r200ContextPtr current
= ctx
? R200_CONTEXT(ctx
) : NULL
;
576 /* check if we're deleting the currently bound context */
577 if (rmesa
== current
) {
578 R200_FIREVERTICES( rmesa
);
579 _mesa_make_current(NULL
, NULL
, NULL
);
582 /* Free r200 context resources */
583 assert(rmesa
); /* should never be null */
585 GLboolean release_texture_heaps
;
588 release_texture_heaps
= (rmesa
->glCtx
->Shared
->RefCount
== 1);
589 _swsetup_DestroyContext( rmesa
->glCtx
);
590 _tnl_DestroyContext( rmesa
->glCtx
);
591 _ac_DestroyContext( rmesa
->glCtx
);
592 _swrast_DestroyContext( rmesa
->glCtx
);
594 r200DestroySwtcl( rmesa
->glCtx
);
595 r200ReleaseArrays( rmesa
->glCtx
, ~0 );
597 if (rmesa
->dma
.current
.buf
) {
598 r200ReleaseDmaRegion( rmesa
, &rmesa
->dma
.current
, __FUNCTION__
);
599 r200FlushCmdBuf( rmesa
, __FUNCTION__
);
602 if (!(rmesa
->TclFallback
& R200_TCL_FALLBACK_TCL_DISABLE
)) {
603 int tcl_mode
= driQueryOptioni(&rmesa
->optionCache
, "tcl_mode");
604 if (tcl_mode
>= DRI_CONF_TCL_VTXFMT
)
605 r200VtxfmtDestroy( rmesa
->glCtx
);
608 if (rmesa
->state
.scissor
.pClipRects
) {
609 FREE(rmesa
->state
.scissor
.pClipRects
);
610 rmesa
->state
.scissor
.pClipRects
= NULL
;
613 if ( release_texture_heaps
) {
614 /* This share group is about to go away, free our private
615 * texture object data.
619 for ( i
= 0 ; i
< rmesa
->nr_heaps
; i
++ ) {
620 driDestroyTextureHeap( rmesa
->texture_heaps
[ i
] );
621 rmesa
->texture_heaps
[ i
] = NULL
;
624 assert( is_empty_list( & rmesa
->swapped
) );
627 /* free the Mesa context */
628 rmesa
->glCtx
->DriverCtx
= NULL
;
629 _mesa_destroy_context( rmesa
->glCtx
);
631 /* free the option cache */
632 driDestroyOptionCache (&rmesa
->optionCache
);
642 r200SwapBuffers( __DRIdrawablePrivate
*dPriv
)
644 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
645 r200ContextPtr rmesa
;
647 rmesa
= (r200ContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
649 if (ctx
->Visual
.doubleBufferMode
) {
650 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
651 if ( rmesa
->doPageFlip
) {
652 r200PageFlip( dPriv
);
655 r200CopyBuffer( dPriv
, NULL
);
660 /* XXX this shouldn't be an error but we can't handle it for now */
661 _mesa_problem(NULL
, "%s: drawable has no context!", __FUNCTION__
);
666 r200CopySubBuffer( __DRIdrawablePrivate
*dPriv
,
667 int x
, int y
, int w
, int h
)
669 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
670 r200ContextPtr rmesa
;
672 rmesa
= (r200ContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
674 if (ctx
->Visual
.doubleBufferMode
) {
675 drm_clip_rect_t rect
;
676 rect
.x1
= x
+ dPriv
->x
;
677 rect
.y1
= (dPriv
->h
- y
- h
) + dPriv
->y
;
678 rect
.x2
= rect
.x1
+ w
;
679 rect
.y2
= rect
.y1
+ h
;
680 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
681 r200CopyBuffer( dPriv
, &rect
);
685 /* XXX this shouldn't be an error but we can't handle it for now */
686 _mesa_problem(NULL
, "%s: drawable has no context!", __FUNCTION__
);
690 /* Force the context `c' to be the current context and associate with it
694 r200MakeCurrent( __DRIcontextPrivate
*driContextPriv
,
695 __DRIdrawablePrivate
*driDrawPriv
,
696 __DRIdrawablePrivate
*driReadPriv
)
698 if ( driContextPriv
) {
699 r200ContextPtr newCtx
=
700 (r200ContextPtr
) driContextPriv
->driverPrivate
;
702 if (R200_DEBUG
& DEBUG_DRI
)
703 fprintf(stderr
, "%s ctx %p\n", __FUNCTION__
, (void *)newCtx
->glCtx
);
705 if ( newCtx
->dri
.drawable
!= driDrawPriv
) {
706 driDrawableInitVBlank( driDrawPriv
, newCtx
->vblank_flags
,
708 newCtx
->dri
.drawable
= driDrawPriv
;
709 r200UpdateWindow( newCtx
->glCtx
);
710 r200UpdateViewportOffset( newCtx
->glCtx
);
713 _mesa_make_current( newCtx
->glCtx
,
714 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
715 (GLframebuffer
*) driReadPriv
->driverPrivate
);
717 if (newCtx
->vb
.enabled
)
718 r200VtxfmtMakeCurrent( newCtx
->glCtx
);
720 _mesa_update_state( newCtx
->glCtx
);
721 r200ValidateState( newCtx
->glCtx
);
724 if (R200_DEBUG
& DEBUG_DRI
)
725 fprintf(stderr
, "%s ctx is null\n", __FUNCTION__
);
726 _mesa_make_current( NULL
, NULL
, NULL
);
729 if (R200_DEBUG
& DEBUG_DRI
)
730 fprintf(stderr
, "End %s\n", __FUNCTION__
);
734 /* Force the context `c' to be unbound from its buffer.
737 r200UnbindContext( __DRIcontextPrivate
*driContextPriv
)
739 r200ContextPtr rmesa
= (r200ContextPtr
) driContextPriv
->driverPrivate
;
741 if (R200_DEBUG
& DEBUG_DRI
)
742 fprintf(stderr
, "%s ctx %p\n", __FUNCTION__
, (void *)rmesa
->glCtx
);
744 r200VtxfmtUnbindContext( rmesa
->glCtx
);