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