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