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