00ae138f99a258b3c4189dac225dba77ad290256
[mesa.git] / src / mesa / drivers / dri / r200 / r200_context.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_context.c,v 1.3 2003/05/06 23:52:08 daenzer Exp $ */
2 /*
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4
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.
8
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:
16
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.
20
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.
28
29 **************************************************************************/
30
31 /*
32 * Authors:
33 * Keith Whitwell <keith@tungstengraphics.com>
34 */
35
36 #include "glheader.h"
37 #include "api_arrayelt.h"
38 #include "context.h"
39 #include "simple_list.h"
40 #include "imports.h"
41 #include "matrix.h"
42 #include "extensions.h"
43 #include "framebuffer.h"
44 #include "state.h"
45
46 #include "swrast/swrast.h"
47 #include "swrast_setup/swrast_setup.h"
48 #include "array_cache/acache.h"
49
50 #include "tnl/tnl.h"
51 #include "tnl/t_pipeline.h"
52
53 #include "drivers/common/driverfuncs.h"
54
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"
60 #include "r200_tex.h"
61 #include "r200_swtcl.h"
62 #include "r200_tcl.h"
63 #include "r200_vtxfmt.h"
64 #include "r200_maos.h"
65
66 #define need_GL_ARB_multisample
67 #define need_GL_ARB_texture_compression
68 #define need_GL_ARB_vertex_buffer_object
69 #define need_GL_ARB_vertex_program
70 #define need_GL_EXT_blend_minmax
71 #define need_GL_EXT_fog_coord
72 #define need_GL_EXT_secondary_color
73 #define need_GL_EXT_blend_equation_separate
74 #define need_GL_EXT_blend_func_separate
75 #define need_GL_NV_vertex_program
76 #include "extension_helper.h"
77
78 #define DRIVER_DATE "20041207"
79
80 #include "vblank.h"
81 #include "utils.h"
82 #include "xmlpool.h" /* for symbolic values of enum-type options */
83 #ifndef R200_DEBUG
84 int R200_DEBUG = (0);
85 #endif
86
87
88 /* Return the width and height of the given buffer.
89 */
90 static void r200GetBufferSize( GLframebuffer *buffer,
91 GLuint *width, GLuint *height )
92 {
93 GET_CURRENT_CONTEXT(ctx);
94 r200ContextPtr rmesa = R200_CONTEXT(ctx);
95
96 LOCK_HARDWARE( rmesa );
97 *width = rmesa->dri.drawable->w;
98 *height = rmesa->dri.drawable->h;
99 UNLOCK_HARDWARE( rmesa );
100 }
101
102 /* Return various strings for glGetString().
103 */
104 static const GLubyte *r200GetString( GLcontext *ctx, GLenum name )
105 {
106 r200ContextPtr rmesa = R200_CONTEXT(ctx);
107 static char buffer[128];
108 unsigned offset;
109 GLuint agp_mode = rmesa->r200Screen->IsPCI ? 0 :
110 rmesa->r200Screen->AGPMode;
111
112 switch ( name ) {
113 case GL_VENDOR:
114 return (GLubyte *)"Tungsten Graphics, Inc.";
115
116 case GL_RENDERER:
117 offset = driGetRendererString( buffer, "R200", DRIVER_DATE,
118 agp_mode );
119
120 sprintf( & buffer[ offset ], " %sTCL",
121 !(rmesa->TclFallback & R200_TCL_FALLBACK_TCL_DISABLE)
122 ? "" : "NO-" );
123
124 return (GLubyte *)buffer;
125
126 default:
127 return NULL;
128 }
129 }
130
131
132 /* Extension strings exported by the R200 driver.
133 */
134 static const struct dri_extension card_extensions[] =
135 {
136 { "GL_ARB_multisample", GL_ARB_multisample_functions },
137 { "GL_ARB_multitexture", NULL },
138 { "GL_ARB_texture_border_clamp", NULL },
139 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions },
140 { "GL_ARB_texture_env_add", NULL },
141 { "GL_ARB_texture_env_combine", NULL },
142 { "GL_ARB_texture_env_dot3", NULL },
143 { "GL_ARB_texture_mirrored_repeat", NULL },
144 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions },
145 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions },
146 { "GL_EXT_blend_subtract", NULL },
147 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions },
148 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions },
149 { "GL_EXT_stencil_wrap", NULL },
150 { "GL_EXT_texture_edge_clamp", NULL },
151 { "GL_EXT_texture_env_combine", NULL },
152 { "GL_EXT_texture_env_dot3", NULL },
153 { "GL_EXT_texture_filter_anisotropic", NULL },
154 { "GL_EXT_texture_lod_bias", NULL },
155 { "GL_EXT_texture_mirror_clamp", NULL },
156 { "GL_EXT_texture_rectangle", NULL },
157 { "GL_ATI_texture_env_combine3", NULL },
158 { "GL_ATI_texture_mirror_once", NULL },
159 { "GL_MESA_pack_invert", NULL },
160 { "GL_NV_blend_square", NULL },
161 { "GL_SGIS_generate_mipmap", NULL },
162 { NULL, NULL }
163 };
164
165 static const struct dri_extension blend_extensions[] = {
166 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions },
167 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions },
168 { NULL, NULL }
169 };
170
171 static const struct dri_extension ARB_vp_extension[] = {
172 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions }
173 };
174
175 static const struct dri_extension NV_vp_extension[] = {
176 { "GL_NV_vertex_program", GL_NV_vertex_program_functions }
177 };
178
179 extern const struct tnl_pipeline_stage _r200_render_stage;
180 extern const struct tnl_pipeline_stage _r200_tcl_stage;
181
182 static const struct tnl_pipeline_stage *r200_pipeline[] = {
183
184 /* Try and go straight to t&l
185 */
186 &_r200_tcl_stage,
187
188 /* Catch any t&l fallbacks
189 */
190 &_tnl_vertex_transform_stage,
191 &_tnl_normal_transform_stage,
192 &_tnl_lighting_stage,
193 &_tnl_fog_coordinate_stage,
194 &_tnl_texgen_stage,
195 &_tnl_texture_transform_stage,
196 &_tnl_vertex_program_stage,
197
198 /* Try again to go to tcl?
199 * - no good for asymmetric-twoside (do with multipass)
200 * - no good for asymmetric-unfilled (do with multipass)
201 * - good for material
202 * - good for texgen
203 * - need to manipulate a bit of state
204 *
205 * - worth it/not worth it?
206 */
207
208 /* Else do them here.
209 */
210 /* &_r200_render_stage, */ /* FIXME: bugs with ut2003 */
211 &_tnl_render_stage, /* FALLBACK: */
212 NULL,
213 };
214
215
216
217 /* Initialize the driver's misc functions.
218 */
219 static void r200InitDriverFuncs( struct dd_function_table *functions )
220 {
221 functions->GetBufferSize = r200GetBufferSize;
222 functions->ResizeBuffers = _mesa_resize_framebuffer;
223 functions->GetString = r200GetString;
224
225 functions->Error = NULL;
226 functions->DrawPixels = NULL;
227 functions->Bitmap = NULL;
228 }
229
230 static const struct dri_debug_control debug_control[] =
231 {
232 { "fall", DEBUG_FALLBACKS },
233 { "tex", DEBUG_TEXTURE },
234 { "ioctl", DEBUG_IOCTL },
235 { "prim", DEBUG_PRIMS },
236 { "vert", DEBUG_VERTS },
237 { "state", DEBUG_STATE },
238 { "code", DEBUG_CODEGEN },
239 { "vfmt", DEBUG_VFMT },
240 { "vtxf", DEBUG_VFMT },
241 { "verb", DEBUG_VERBOSE },
242 { "dri", DEBUG_DRI },
243 { "dma", DEBUG_DMA },
244 { "san", DEBUG_SANITY },
245 { "sync", DEBUG_SYNC },
246 { "pix", DEBUG_PIXEL },
247 { "mem", DEBUG_MEMORY },
248 { NULL, 0 }
249 };
250
251
252 static int
253 get_ust_nop( int64_t * ust )
254 {
255 *ust = 1;
256 return 0;
257 }
258
259
260 /* Create the device specific rendering context.
261 */
262 GLboolean r200CreateContext( const __GLcontextModes *glVisual,
263 __DRIcontextPrivate *driContextPriv,
264 void *sharedContextPrivate)
265 {
266 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
267 r200ScreenPtr screen = (r200ScreenPtr)(sPriv->private);
268 struct dd_function_table functions;
269 r200ContextPtr rmesa;
270 GLcontext *ctx, *shareCtx;
271 int i;
272 int tcl_mode, fthrottle_mode;
273
274 assert(glVisual);
275 assert(driContextPriv);
276 assert(screen);
277
278 /* Allocate the R200 context */
279 rmesa = (r200ContextPtr) CALLOC( sizeof(*rmesa) );
280 if ( !rmesa )
281 return GL_FALSE;
282
283 /* init exp fog table data */
284 r200InitStaticFogData();
285
286 /* Parse configuration files.
287 * Do this here so that initialMaxAnisotropy is set before we create
288 * the default textures.
289 */
290 driParseConfigFiles (&rmesa->optionCache, &screen->optionCache,
291 screen->driScreen->myNum, "r200");
292 rmesa->initialMaxAnisotropy = driQueryOptionf(&rmesa->optionCache,
293 "def_max_anisotropy");
294
295 if ( driQueryOptionb( &rmesa->optionCache, "hyperz" ) ) {
296 if ( sPriv->drmMinor < 13 )
297 fprintf( stderr, "DRM version 1.%d too old to support HyperZ, "
298 "disabling.\n",sPriv->drmMinor );
299 else
300 rmesa->using_hyperz = GL_TRUE;
301 }
302
303 if ( sPriv->drmMinor >= 15 )
304 rmesa->texmicrotile = GL_TRUE;
305
306 /* Init default driver functions then plug in our R200-specific functions
307 * (the texture functions are especially important)
308 */
309 _mesa_init_driver_functions(&functions);
310 r200InitDriverFuncs(&functions);
311 r200InitIoctlFuncs(&functions);
312 r200InitStateFuncs(&functions);
313 r200InitTextureFuncs(&functions);
314
315 /* Allocate and initialize the Mesa context */
316 if (sharedContextPrivate)
317 shareCtx = ((r200ContextPtr) sharedContextPrivate)->glCtx;
318 else
319 shareCtx = NULL;
320 rmesa->glCtx = _mesa_create_context(glVisual, shareCtx,
321 &functions, (void *) rmesa);
322 if (!rmesa->glCtx) {
323 FREE(rmesa);
324 return GL_FALSE;
325 }
326 driContextPriv->driverPrivate = rmesa;
327
328 /* Init r200 context data */
329 rmesa->dri.context = driContextPriv;
330 rmesa->dri.screen = sPriv;
331 rmesa->dri.drawable = NULL; /* Set by XMesaMakeCurrent */
332 rmesa->dri.hwContext = driContextPriv->hHWContext;
333 rmesa->dri.hwLock = &sPriv->pSAREA->lock;
334 rmesa->dri.fd = sPriv->fd;
335 rmesa->dri.drmMinor = sPriv->drmMinor;
336
337 rmesa->r200Screen = screen;
338 rmesa->sarea = (drm_radeon_sarea_t *)((GLubyte *)sPriv->pSAREA +
339 screen->sarea_priv_offset);
340
341
342 rmesa->dma.buf0_address = rmesa->r200Screen->buffers->list[0].address;
343
344 (void) memset( rmesa->texture_heaps, 0, sizeof( rmesa->texture_heaps ) );
345 make_empty_list( & rmesa->swapped );
346
347 rmesa->nr_heaps = 1 /* screen->numTexHeaps */ ;
348 assert(rmesa->nr_heaps < R200_NR_TEX_HEAPS);
349 for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
350 rmesa->texture_heaps[i] = driCreateTextureHeap( i, rmesa,
351 screen->texSize[i],
352 12,
353 RADEON_NR_TEX_REGIONS,
354 (drmTextureRegionPtr)rmesa->sarea->tex_list[i],
355 & rmesa->sarea->tex_age[i],
356 & rmesa->swapped,
357 sizeof( r200TexObj ),
358 (destroy_texture_object_t *) r200DestroyTexObj );
359 }
360 rmesa->texture_depth = driQueryOptioni (&rmesa->optionCache,
361 "texture_depth");
362 if (rmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FB)
363 rmesa->texture_depth = ( screen->cpp == 4 ) ?
364 DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
365
366 rmesa->swtcl.RenderIndex = ~0;
367 rmesa->hw.all_dirty = 1;
368
369 /* Set the maximum texture size small enough that we can guarentee that
370 * all texture units can bind a maximal texture and have them both in
371 * texturable memory at once.
372 */
373
374 ctx = rmesa->glCtx;
375 ctx->Const.MaxTextureUnits = driQueryOptioni (&rmesa->optionCache,
376 "texture_units");
377 ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
378 ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
379
380 driCalculateMaxTextureLevels( rmesa->texture_heaps,
381 rmesa->nr_heaps,
382 & ctx->Const,
383 4,
384 11, /* max 2D texture size is 2048x2048 */
385 #if ENABLE_HW_3D_TEXTURE
386 8, /* max 3D texture size is 256^3 */
387 #else
388 0, /* 3D textures unsupported */
389 #endif
390 11, /* max cube texture size is 2048x2048 */
391 11, /* max texture rectangle size is 2048x2048 */
392 12,
393 GL_FALSE );
394
395 /* adjust max texture size a bit. Hack, but I really want to use larger textures
396 which will work just fine in 99.999999% of all cases, especially with texture compression... */
397 if (driQueryOptionb( &rmesa->optionCache, "texture_level_hack" ))
398 {
399 if (ctx->Const.MaxTextureLevels < 12) ctx->Const.MaxTextureLevels += 1;
400 }
401
402 ctx->Const.MaxTextureMaxAnisotropy = 16.0;
403
404 /* No wide points.
405 */
406 ctx->Const.MinPointSize = 1.0;
407 ctx->Const.MinPointSizeAA = 1.0;
408 ctx->Const.MaxPointSize = 1.0;
409 ctx->Const.MaxPointSizeAA = 1.0;
410
411 ctx->Const.MinLineWidth = 1.0;
412 ctx->Const.MinLineWidthAA = 1.0;
413 ctx->Const.MaxLineWidth = 10.0;
414 ctx->Const.MaxLineWidthAA = 10.0;
415 ctx->Const.LineWidthGranularity = 0.0625;
416
417 /* Initialize the software rasterizer and helper modules.
418 */
419 _swrast_CreateContext( ctx );
420 _ac_CreateContext( ctx );
421 _tnl_CreateContext( ctx );
422 _swsetup_CreateContext( ctx );
423 _ae_create_context( ctx );
424
425 /* Install the customized pipeline:
426 */
427 _tnl_destroy_pipeline( ctx );
428 _tnl_install_pipeline( ctx, r200_pipeline );
429 ctx->Driver.FlushVertices = r200FlushVertices;
430
431 /* Try and keep materials and vertices separate:
432 */
433 _tnl_isolate_materials( ctx, GL_TRUE );
434
435
436 /* Configure swrast and TNL to match hardware characteristics:
437 */
438 _swrast_allow_pixel_fog( ctx, GL_FALSE );
439 _swrast_allow_vertex_fog( ctx, GL_TRUE );
440 _tnl_allow_pixel_fog( ctx, GL_FALSE );
441 _tnl_allow_vertex_fog( ctx, GL_TRUE );
442
443
444 for ( i = 0 ; i < R200_MAX_TEXTURE_UNITS ; i++ ) {
445 _math_matrix_ctr( &rmesa->TexGenMatrix[i] );
446 _math_matrix_set_identity( &rmesa->TexGenMatrix[i] );
447 }
448 _math_matrix_ctr( &rmesa->tmpmat );
449 _math_matrix_set_identity( &rmesa->tmpmat );
450
451 driInitExtensions( ctx, card_extensions, GL_TRUE );
452 if (!(rmesa->r200Screen->chipset & R200_CHIPSET_YCBCR_BROKEN)) {
453 /* yuv textures don't work with some chips - R200 / rv280 okay so far
454 others get the bit ordering right but don't actually do YUV-RGB conversion */
455 _mesa_enable_extension( ctx, "GL_MESA_ycbcr_texture" );
456 }
457 if (rmesa->glCtx->Mesa_DXTn) {
458 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
459 _mesa_enable_extension( ctx, "GL_S3_s3tc" );
460 }
461 else if (driQueryOptionb (&rmesa->optionCache, "force_s3tc_enable")) {
462 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
463 }
464
465 if (rmesa->r200Screen->drmSupportsCubeMaps)
466 _mesa_enable_extension( ctx, "GL_ARB_texture_cube_map" );
467 if (rmesa->r200Screen->drmSupportsBlendColor) {
468 driInitExtensions( ctx, blend_extensions, GL_FALSE );
469 }
470 if(driQueryOptionb(&rmesa->optionCache, "arb_vertex_program"))
471 driInitSingleExtension( ctx, ARB_vp_extension );
472 if(driQueryOptionb(&rmesa->optionCache, "nv_vertex_program"))
473 driInitSingleExtension( ctx, NV_vp_extension );
474
475 #if 0
476 r200InitDriverFuncs( ctx );
477 r200InitIoctlFuncs( ctx );
478 r200InitStateFuncs( ctx );
479 r200InitTextureFuncs( ctx );
480 #endif
481 /* plug in a few more device driver functions */
482 /* XXX these should really go right after _mesa_init_driver_functions() */
483 r200InitPixelFuncs( ctx );
484 #if 0
485 r200InitSpanFuncs( ctx );
486 #endif
487 r200InitTnlFuncs( ctx );
488 r200InitState( rmesa );
489 r200InitSwtcl( ctx );
490
491 fthrottle_mode = driQueryOptioni(&rmesa->optionCache, "fthrottle_mode");
492 rmesa->iw.irq_seq = -1;
493 rmesa->irqsEmitted = 0;
494 rmesa->do_irqs = (rmesa->dri.drmMinor >= 6 &&
495 fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS &&
496 rmesa->r200Screen->irq);
497
498 rmesa->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
499
500 if (!rmesa->do_irqs)
501 fprintf(stderr,
502 "IRQ's not enabled, falling back to %s: %d %d %d\n",
503 rmesa->do_usleeps ? "usleeps" : "busy waits",
504 rmesa->dri.drmMinor,
505 fthrottle_mode,
506 rmesa->r200Screen->irq);
507
508 rmesa->vblank_flags = (rmesa->r200Screen->irq != 0)
509 ? driGetDefaultVBlankFlags(&rmesa->optionCache) : VBLANK_FLAG_NO_IRQ;
510
511 rmesa->prefer_gart_client_texturing =
512 (getenv("R200_GART_CLIENT_TEXTURES") != 0);
513
514 rmesa->get_ust = (PFNGLXGETUSTPROC) glXGetProcAddress( (const GLubyte *) "__glXGetUST" );
515 if ( rmesa->get_ust == NULL ) {
516 rmesa->get_ust = get_ust_nop;
517 }
518 (*rmesa->get_ust)( & rmesa->swap_ust );
519
520
521 #if DO_DEBUG
522 R200_DEBUG = driParseDebugString( getenv( "R200_DEBUG" ),
523 debug_control );
524 R200_DEBUG |= driParseDebugString( getenv( "RADEON_DEBUG" ),
525 debug_control );
526 #endif
527
528 tcl_mode = driQueryOptioni(&rmesa->optionCache, "tcl_mode");
529 if (driQueryOptionb(&rmesa->optionCache, "no_rast")) {
530 fprintf(stderr, "disabling 3D acceleration\n");
531 FALLBACK(rmesa, R200_FALLBACK_DISABLE, 1);
532 }
533 else if (tcl_mode == DRI_CONF_TCL_SW || getenv("R200_NO_TCL") ||
534 !(rmesa->r200Screen->chipset & R200_CHIPSET_TCL)) {
535 if (rmesa->r200Screen->chipset & R200_CHIPSET_TCL) {
536 rmesa->r200Screen->chipset &= ~R200_CHIPSET_TCL;
537 fprintf(stderr, "Disabling HW TCL support\n");
538 }
539 TCL_FALLBACK(rmesa->glCtx, R200_TCL_FALLBACK_TCL_DISABLE, 1);
540 }
541 if (rmesa->r200Screen->chipset & R200_CHIPSET_TCL) {
542 if (tcl_mode >= DRI_CONF_TCL_VTXFMT && !getenv("R200_NO_VTXFMT")) {
543 r200VtxfmtInit( ctx, tcl_mode >= DRI_CONF_TCL_CODEGEN );
544 }
545 _tnl_need_dlist_norm_lengths( ctx, GL_FALSE );
546 }
547 return GL_TRUE;
548 }
549
550
551 /* Destroy the device specific context.
552 */
553 /* Destroy the Mesa and driver specific context data.
554 */
555 void r200DestroyContext( __DRIcontextPrivate *driContextPriv )
556 {
557 GET_CURRENT_CONTEXT(ctx);
558 r200ContextPtr rmesa = (r200ContextPtr) driContextPriv->driverPrivate;
559 r200ContextPtr current = ctx ? R200_CONTEXT(ctx) : NULL;
560
561 /* check if we're deleting the currently bound context */
562 if (rmesa == current) {
563 R200_FIREVERTICES( rmesa );
564 _mesa_make_current(NULL, NULL, NULL);
565 }
566
567 /* Free r200 context resources */
568 assert(rmesa); /* should never be null */
569 if ( rmesa ) {
570 GLboolean release_texture_heaps;
571
572
573 release_texture_heaps = (rmesa->glCtx->Shared->RefCount == 1);
574 _swsetup_DestroyContext( rmesa->glCtx );
575 _tnl_DestroyContext( rmesa->glCtx );
576 _ac_DestroyContext( rmesa->glCtx );
577 _swrast_DestroyContext( rmesa->glCtx );
578
579 r200DestroySwtcl( rmesa->glCtx );
580 r200ReleaseArrays( rmesa->glCtx, ~0 );
581
582 if (rmesa->dma.current.buf) {
583 r200ReleaseDmaRegion( rmesa, &rmesa->dma.current, __FUNCTION__ );
584 r200FlushCmdBuf( rmesa, __FUNCTION__ );
585 }
586
587 if (!(rmesa->TclFallback & R200_TCL_FALLBACK_TCL_DISABLE)) {
588 int tcl_mode = driQueryOptioni(&rmesa->optionCache, "tcl_mode");
589 if (tcl_mode >= DRI_CONF_TCL_VTXFMT)
590 r200VtxfmtDestroy( rmesa->glCtx );
591 }
592
593 /* free the Mesa context */
594 rmesa->glCtx->DriverCtx = NULL;
595 _mesa_destroy_context( rmesa->glCtx );
596
597 if (rmesa->state.scissor.pClipRects) {
598 FREE(rmesa->state.scissor.pClipRects);
599 rmesa->state.scissor.pClipRects = NULL;
600 }
601
602 if ( release_texture_heaps ) {
603 /* This share group is about to go away, free our private
604 * texture object data.
605 */
606 int i;
607
608 for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
609 driDestroyTextureHeap( rmesa->texture_heaps[ i ] );
610 rmesa->texture_heaps[ i ] = NULL;
611 }
612
613 assert( is_empty_list( & rmesa->swapped ) );
614 }
615
616 /* free the option cache */
617 driDestroyOptionCache (&rmesa->optionCache);
618
619 FREE( rmesa );
620 }
621 }
622
623
624
625
626 void
627 r200SwapBuffers( __DRIdrawablePrivate *dPriv )
628 {
629 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
630 r200ContextPtr rmesa;
631 GLcontext *ctx;
632 rmesa = (r200ContextPtr) dPriv->driContextPriv->driverPrivate;
633 ctx = rmesa->glCtx;
634 if (ctx->Visual.doubleBufferMode) {
635 _mesa_notifySwapBuffers( ctx ); /* flush pending rendering comands */
636 if ( rmesa->doPageFlip ) {
637 r200PageFlip( dPriv );
638 }
639 else {
640 r200CopyBuffer( dPriv );
641 }
642 }
643 }
644 else {
645 /* XXX this shouldn't be an error but we can't handle it for now */
646 _mesa_problem(NULL, "%s: drawable has no context!", __FUNCTION__);
647 }
648 }
649
650
651 /* Force the context `c' to be the current context and associate with it
652 * buffer `b'.
653 */
654 GLboolean
655 r200MakeCurrent( __DRIcontextPrivate *driContextPriv,
656 __DRIdrawablePrivate *driDrawPriv,
657 __DRIdrawablePrivate *driReadPriv )
658 {
659 if ( driContextPriv ) {
660 r200ContextPtr newCtx =
661 (r200ContextPtr) driContextPriv->driverPrivate;
662
663 if (R200_DEBUG & DEBUG_DRI)
664 fprintf(stderr, "%s ctx %p\n", __FUNCTION__, (void *)newCtx->glCtx);
665
666 if ( newCtx->dri.drawable != driDrawPriv ) {
667 driDrawableInitVBlank( driDrawPriv, newCtx->vblank_flags );
668 newCtx->dri.drawable = driDrawPriv;
669 r200UpdateWindow( newCtx->glCtx );
670 r200UpdateViewportOffset( newCtx->glCtx );
671 }
672
673 _mesa_make_current( newCtx->glCtx,
674 (GLframebuffer *) driDrawPriv->driverPrivate,
675 (GLframebuffer *) driReadPriv->driverPrivate );
676
677 if (newCtx->vb.enabled)
678 r200VtxfmtMakeCurrent( newCtx->glCtx );
679
680 _mesa_update_state( newCtx->glCtx );
681 r200ValidateState( newCtx->glCtx );
682
683 } else {
684 if (R200_DEBUG & DEBUG_DRI)
685 fprintf(stderr, "%s ctx is null\n", __FUNCTION__);
686 _mesa_make_current( NULL, NULL, NULL );
687 }
688
689 if (R200_DEBUG & DEBUG_DRI)
690 fprintf(stderr, "End %s\n", __FUNCTION__);
691 return GL_TRUE;
692 }
693
694 /* Force the context `c' to be unbound from its buffer.
695 */
696 GLboolean
697 r200UnbindContext( __DRIcontextPrivate *driContextPriv )
698 {
699 r200ContextPtr rmesa = (r200ContextPtr) driContextPriv->driverPrivate;
700
701 if (R200_DEBUG & DEBUG_DRI)
702 fprintf(stderr, "%s ctx %p\n", __FUNCTION__, (void *)rmesa->glCtx);
703
704 r200VtxfmtUnbindContext( rmesa->glCtx );
705 return GL_TRUE;
706 }