b6c2c37aeddc7e0b5d863351b336597d7a8a17bb
[mesa.git] / src / mesa / drivers / dri / unichrome / via_context.c
1 /*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file via_context.c
27 *
28 * \author John Sheng (presumably of either VIA Technologies or S3 Graphics)
29 * \author Others at VIA Technologies?
30 * \author Others at S3 Graphics?
31 */
32
33 #include "glheader.h"
34 #include "context.h"
35 #include "matrix.h"
36 #include "simple_list.h"
37 #include "extensions.h"
38
39 #include "swrast/swrast.h"
40 #include "swrast_setup/swrast_setup.h"
41 #include "tnl/tnl.h"
42 #include "array_cache/acache.h"
43
44 #include "tnl/t_pipeline.h"
45
46 #include "drivers/common/driverfuncs.h"
47
48 #include "via_screen.h"
49 #include "via_dri.h"
50
51 #include "via_state.h"
52 #include "via_tex.h"
53 #include "via_span.h"
54 #include "via_tris.h"
55 #include "via_vb.h"
56 #include "via_ioctl.h"
57 #include "via_fb.h"
58 #include "via_regs.h"
59
60 #include <stdio.h>
61 #include "macros.h"
62
63 #define DRIVER_DATE "20041215"
64
65 #include "vblank.h"
66 #include "utils.h"
67
68 #ifdef DEBUG
69 GLuint VIA_DEBUG = 0;
70 #endif
71
72
73 /**
74 * Return various strings for \c glGetString.
75 *
76 * \sa glGetString
77 */
78 static const GLubyte *viaGetString(GLcontext *ctx, GLenum name)
79 {
80 static char buffer[128];
81 unsigned offset;
82
83
84 switch (name) {
85 case GL_VENDOR:
86 return (GLubyte *)"VIA Technology";
87
88 case GL_RENDERER: {
89 static const char * const chipset_names[] = {
90 "UniChrome",
91 "CastleRock (CLE266)",
92 "UniChrome (KM400)",
93 "UniChrome (K8M800)",
94 "UniChrome (PM8x0/CN400)",
95 };
96 const viaContext * const via = VIA_CONTEXT(ctx);
97 const unsigned id = via->viaScreen->deviceID;
98
99 offset = driGetRendererString( buffer,
100 chipset_names[(id > VIA_PM800) ? 0 : id],
101 DRIVER_DATE, 0 );
102 return (GLubyte *)buffer;
103 }
104
105 default:
106 return NULL;
107 }
108 }
109
110
111 /**
112 * Calculate a width that satisfies the hardware's alignment requirements.
113 * On the Unichrome hardware, each scanline must be aligned to a multiple of
114 * 16 pixels.
115 *
116 * \param width Minimum buffer width, in pixels.
117 *
118 * \returns A pixel width that meets the alignment requirements.
119 */
120 static __inline__ unsigned
121 buffer_align( unsigned width )
122 {
123 return (width + 0x0f) & ~0x0f;
124 }
125
126
127 /**
128 * Calculate the framebuffer parameters for all buffers (front, back, depth,
129 * and stencil) associated with the specified context.
130 *
131 * \warning
132 * This function also calls \c AllocateBuffer to actually allocate the
133 * buffers.
134 *
135 * \sa AllocateBuffer
136 */
137 static GLboolean
138 calculate_buffer_parameters( viaContextPtr vmesa )
139 {
140 const unsigned shift = vmesa->viaScreen->bitsPerPixel / 16;
141 const unsigned extra = 32;
142 unsigned w;
143 unsigned h;
144
145 /* Allocate front-buffer */
146 if (vmesa->drawType == GLX_PBUFFER_BIT) {
147 w = vmesa->driDrawable->w;
148 h = vmesa->driDrawable->h;
149
150 vmesa->front.bpp = vmesa->viaScreen->bitsPerPixel;
151 vmesa->front.pitch = buffer_align( w ) << shift;
152 vmesa->front.size = vmesa->front.pitch * h;
153
154 if (vmesa->front.map)
155 via_free_draw_buffer(vmesa, &vmesa->front);
156 if (!via_alloc_draw_buffer(vmesa, &vmesa->front))
157 return GL_FALSE;
158
159 }
160 else {
161 w = vmesa->viaScreen->width;
162 h = vmesa->viaScreen->height;
163
164 vmesa->front.bpp = vmesa->viaScreen->bitsPerPixel;
165 vmesa->front.pitch = buffer_align( w ) << shift;
166 vmesa->front.size = vmesa->front.pitch * h;
167 vmesa->front.offset = 0;
168 vmesa->front.map = (char *) vmesa->driScreen->pFB;
169 }
170
171
172 /* Allocate back-buffer */
173 if (vmesa->hasBack) {
174 vmesa->back.bpp = vmesa->viaScreen->bitsPerPixel;
175 vmesa->back.pitch = (buffer_align( vmesa->driDrawable->w ) << shift) + extra;
176 vmesa->back.size = vmesa->back.pitch * vmesa->driDrawable->h;
177 if (vmesa->back.map)
178 via_free_draw_buffer(vmesa, &vmesa->back);
179 if (!via_alloc_draw_buffer(vmesa, &vmesa->back))
180 return GL_FALSE;
181 }
182 else {
183 /* KW: mem leak if vmesa->hasBack ever changes:
184 */
185 (void) memset( &vmesa->back, 0, sizeof( vmesa->back ) );
186 }
187
188
189 /* Allocate depth-buffer */
190 if ( vmesa->hasStencil || vmesa->hasDepth ) {
191 vmesa->depth.bpp = vmesa->depthBits;
192 if (vmesa->depth.bpp == 24)
193 vmesa->depth.bpp = 32;
194
195 vmesa->depth.pitch = (buffer_align( vmesa->driDrawable->w ) * (vmesa->depth.bpp/8)) + extra;
196 vmesa->depth.size = vmesa->depth.pitch * vmesa->driDrawable->h;
197
198 if (vmesa->depth.map)
199 via_free_draw_buffer(vmesa, &vmesa->depth);
200 if (!via_alloc_draw_buffer(vmesa, &vmesa->depth)) {
201 return GL_FALSE;
202 }
203 }
204 else {
205 /* KW: mem leak if vmesa->hasStencil/hasDepth ever changes:
206 */
207 (void) memset( & vmesa->depth, 0, sizeof( vmesa->depth ) );
208 }
209
210 /*=* John Sheng [2003.5.31] flip *=*/
211 if( vmesa->viaScreen->width == vmesa->driDrawable->w &&
212 vmesa->viaScreen->height == vmesa->driDrawable->h ) {
213 #define ALLOW_EXPERIMENTAL_PAGEFLIP 0
214 #if ALLOW_EXPERIMENTAL_PAGEFLIP
215 vmesa->doPageFlip = GL_TRUE;
216 #else
217 vmesa->doPageFlip = GL_FALSE;
218 #endif
219 /* vmesa->currentPage = 0; */
220 assert(vmesa->back.pitch == vmesa->front.pitch);
221 }
222 else
223 vmesa->doPageFlip = GL_FALSE;
224
225 return GL_TRUE;
226 }
227
228
229 void viaReAllocateBuffers(GLframebuffer *drawbuffer)
230 {
231 GET_CURRENT_CONTEXT(ctx);
232 viaContextPtr vmesa = VIA_CONTEXT(ctx);
233
234 _swrast_alloc_buffers( drawbuffer );
235 calculate_buffer_parameters( vmesa );
236 }
237
238 static void viaBufferSize(GLframebuffer *buffer, GLuint *width, GLuint *height)
239 {
240 GET_CURRENT_CONTEXT(ctx);
241 viaContextPtr vmesa = VIA_CONTEXT(ctx);
242 *width = vmesa->driDrawable->w;
243 *height = vmesa->driDrawable->h;
244 }
245
246 /* Extension strings exported by the Unichrome driver.
247 */
248 static const char * const card_extensions[] =
249 {
250 "GL_ARB_multitexture",
251 "GL_ARB_point_parameters",
252 "GL_ARB_texture_env_add",
253 "GL_ARB_texture_env_combine",
254 "GL_ARB_texture_env_dot3",
255 "GL_ARB_texture_mirrored_repeat",
256 "GL_EXT_stencil_wrap",
257 "GL_EXT_texture_env_combine",
258 "GL_EXT_texture_env_dot3",
259 "GL_EXT_texture_lod_bias",
260 "GL_NV_blend_square",
261 NULL
262 };
263
264 extern const struct tnl_pipeline_stage _via_fastrender_stage;
265 extern const struct tnl_pipeline_stage _via_render_stage;
266
267 static const struct tnl_pipeline_stage *via_pipeline[] = {
268 &_tnl_vertex_transform_stage,
269 &_tnl_normal_transform_stage,
270 &_tnl_lighting_stage,
271 &_tnl_fog_coordinate_stage,
272 &_tnl_texgen_stage,
273 &_tnl_texture_transform_stage,
274 /* REMOVE: point attenuation stage */
275 &_via_fastrender_stage, /* ADD: unclipped rastersetup-to-dma */
276 &_tnl_render_stage,
277 0,
278 };
279
280
281 static GLboolean
282 AllocateDmaBuffer(const GLvisual *visual, viaContextPtr vmesa)
283 {
284 if (vmesa->dma)
285 via_free_dma_buffer(vmesa);
286
287 if (!via_alloc_dma_buffer(vmesa))
288 return GL_FALSE;
289
290 vmesa->dmaLow = 0;
291 vmesa->dmaCliprectAddr = 0;
292 return GL_TRUE;
293 }
294
295 static void
296 FreeBuffer(viaContextPtr vmesa)
297 {
298 if (vmesa->front.map)
299 via_free_draw_buffer(vmesa, &vmesa->front);
300
301 if (vmesa->back.map)
302 via_free_draw_buffer(vmesa, &vmesa->back);
303
304 if (vmesa->depth.map)
305 via_free_draw_buffer(vmesa, &vmesa->depth);
306
307 if (vmesa->dma)
308 via_free_dma_buffer(vmesa);
309 }
310
311 static int
312 get_ust_nop( int64_t * ust )
313 {
314 *ust = 1;
315 return 0;
316 }
317
318 GLboolean
319 viaCreateContext(const __GLcontextModes *mesaVis,
320 __DRIcontextPrivate *driContextPriv,
321 void *sharedContextPrivate)
322 {
323 GLcontext *ctx, *shareCtx;
324 viaContextPtr vmesa;
325 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
326 viaScreenPrivate *viaScreen = (viaScreenPrivate *)sPriv->private;
327 drm_via_sarea_t *saPriv = (drm_via_sarea_t *)
328 (((GLubyte *)sPriv->pSAREA) + viaScreen->sareaPrivOffset);
329 struct dd_function_table functions;
330
331 /* Allocate via context */
332 vmesa = (viaContextPtr) CALLOC_STRUCT(via_context_t);
333 if (!vmesa) {
334 return GL_FALSE;
335 }
336 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
337
338 /* Parse configuration files.
339 */
340 driParseConfigFiles (&vmesa->optionCache, &viaScreen->optionCache,
341 sPriv->myNum, "via");
342
343 /* pick back buffer */
344 vmesa->hasBack = mesaVis->doubleBufferMode;
345
346 switch(mesaVis->depthBits) {
347 case 0:
348 vmesa->hasDepth = GL_FALSE;
349 vmesa->depthBits = 0;
350 vmesa->depth_max = 1.0;
351 break;
352 case 16:
353 vmesa->hasDepth = GL_TRUE;
354 vmesa->depthBits = mesaVis->depthBits;
355 vmesa->have_hw_stencil = GL_FALSE;
356 vmesa->depth_max = (GLfloat)0xffff;
357 vmesa->depth_clear_mask = 0xf << 28;
358 vmesa->ClearDepth = 0xffff;
359 break;
360 case 24:
361 vmesa->hasDepth = GL_TRUE;
362 vmesa->depthBits = mesaVis->depthBits;
363 vmesa->depth_max = (GLfloat) 0xffffff;
364 vmesa->depth_clear_mask = 0xe << 28;
365 vmesa->ClearDepth = 0xffffff00;
366
367 assert(mesaVis->haveStencilBuffer);
368 assert(mesaVis->stencilBits == 8);
369
370 vmesa->have_hw_stencil = GL_TRUE;
371 vmesa->stencilBits = mesaVis->stencilBits;
372 vmesa->stencil_clear_mask = 0x1 << 28;
373 break;
374 case 32:
375 vmesa->hasDepth = GL_TRUE;
376 vmesa->depthBits = mesaVis->depthBits;
377 assert(!mesaVis->haveStencilBuffer);
378 vmesa->have_hw_stencil = GL_FALSE;
379 vmesa->depth_max = (GLfloat)0xffffffff;
380 vmesa->depth_clear_mask = 0;
381 vmesa->ClearDepth = 0xffffffff;
382 vmesa->depth_clear_mask = 0xf << 28;
383 break;
384 default:
385 assert(0);
386 break;
387 }
388
389
390 _mesa_init_driver_functions(&functions);
391 viaInitTextureFuncs(&functions);
392
393 /* Allocate the Mesa context */
394 if (sharedContextPrivate)
395 shareCtx = ((viaContextPtr) sharedContextPrivate)->glCtx;
396 else
397 shareCtx = NULL;
398
399 vmesa->glCtx = _mesa_create_context(mesaVis, shareCtx, &functions, (void*) vmesa);
400
401 vmesa->shareCtx = shareCtx;
402
403 if (!vmesa->glCtx) {
404 FREE(vmesa);
405 return GL_FALSE;
406 }
407 driContextPriv->driverPrivate = vmesa;
408
409 ctx = vmesa->glCtx;
410
411 ctx->Const.MaxTextureLevels = 10;
412 ctx->Const.MaxTextureUnits = 2;
413 ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
414 ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
415
416 ctx->Const.MinLineWidth = 1.0;
417 ctx->Const.MinLineWidthAA = 1.0;
418 ctx->Const.MaxLineWidth = 1.0;
419 ctx->Const.MaxLineWidthAA = 1.0;
420 ctx->Const.LineWidthGranularity = 1.0;
421
422 ctx->Const.MinPointSize = 1.0;
423 ctx->Const.MinPointSizeAA = 1.0;
424 ctx->Const.MaxPointSize = 1.0;
425 ctx->Const.MaxPointSizeAA = 1.0;
426 ctx->Const.PointSizeGranularity = 1.0;
427
428 ctx->Driver.GetBufferSize = viaBufferSize;
429 /* ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; *//* FIXME ?? */
430 ctx->Driver.GetString = viaGetString;
431
432 ctx->DriverCtx = (void *)vmesa;
433 vmesa->glCtx = ctx;
434
435 /* Initialize the software rasterizer and helper modules.
436 */
437 _swrast_CreateContext(ctx);
438 _ac_CreateContext(ctx);
439 _tnl_CreateContext(ctx);
440 _swsetup_CreateContext(ctx);
441
442 /* Install the customized pipeline:
443 */
444 _tnl_destroy_pipeline(ctx);
445 _tnl_install_pipeline(ctx, via_pipeline);
446
447 /* Configure swrast and T&L to match hardware characteristics:
448 */
449 _swrast_allow_pixel_fog(ctx, GL_FALSE);
450 _swrast_allow_vertex_fog(ctx, GL_TRUE);
451 _tnl_allow_pixel_fog(ctx, GL_FALSE);
452 _tnl_allow_vertex_fog(ctx, GL_TRUE);
453
454 /* vmesa->display = dpy; */
455 vmesa->display = sPriv->display;
456
457 vmesa->hHWContext = driContextPriv->hHWContext;
458 vmesa->driFd = sPriv->fd;
459 vmesa->driHwLock = &sPriv->pSAREA->lock;
460
461 vmesa->viaScreen = viaScreen;
462 vmesa->driScreen = sPriv;
463 vmesa->sarea = saPriv;
464 vmesa->glBuffer = NULL;
465
466 vmesa->texHeap = mmInit(0, viaScreen->textureSize);
467 vmesa->renderIndex = ~0;
468
469 make_empty_list(&vmesa->TexObjList);
470 make_empty_list(&vmesa->SwappedOut);
471
472 vmesa->CurrentTexObj[0] = 0;
473 vmesa->CurrentTexObj[1] = 0;
474
475 _math_matrix_ctr(&vmesa->ViewportMatrix);
476
477 /* Do this early, before VIA_FLUSH_DMA can be called:
478 */
479 if (!AllocateDmaBuffer(mesaVis, vmesa)) {
480 fprintf(stderr ,"AllocateDmaBuffer fail\n");
481 FreeBuffer(vmesa);
482 FREE(vmesa);
483 return GL_FALSE;
484 }
485
486 driInitExtensions( ctx, card_extensions, GL_TRUE );
487 viaInitStateFuncs(ctx);
488 viaInitTextures(ctx);
489 viaInitTriFuncs(ctx);
490 viaInitSpanFuncs(ctx);
491 viaInitIoctlFuncs(ctx);
492 viaInitVB(ctx);
493 viaInitState(ctx);
494
495 #ifdef DEBUG
496 if (getenv("VIA_DEBUG"))
497 VIA_DEBUG = 1;
498 else
499 VIA_DEBUG = 0;
500 #endif
501
502 if (getenv("VIA_NO_RAST"))
503 FALLBACK(vmesa, VIA_FALLBACK_USER_DISABLE, 1);
504
505
506
507 /* I don't understand why this isn't working:
508 */
509 vmesa->vblank_flags =
510 vmesa->viaScreen->irqEnabled ?
511 driGetDefaultVBlankFlags(&vmesa->optionCache) : VBLANK_FLAG_NO_IRQ;
512
513 /* Hack this up in its place:
514 */
515 vmesa->vblank_flags = getenv("VIA_VSYNC") ? VBLANK_FLAG_SYNC : VBLANK_FLAG_NO_IRQ;
516
517
518 vmesa->get_ust = (PFNGLXGETUSTPROC) glXGetProcAddress( (const GLubyte *) "__glXGetUST" );
519 if ( vmesa->get_ust == NULL ) {
520 vmesa->get_ust = get_ust_nop;
521 }
522 vmesa->get_ust( &vmesa->swap_ust );
523
524
525 vmesa->regMMIOBase = (GLuint *)((GLuint)viaScreen->reg);
526 vmesa->pnGEMode = (GLuint *)((GLuint)viaScreen->reg + 0x4);
527 vmesa->regEngineStatus = (GLuint *)((GLuint)viaScreen->reg + 0x400);
528 vmesa->regTranSet = (GLuint *)((GLuint)viaScreen->reg + 0x43C);
529 vmesa->regTranSpace = (GLuint *)((GLuint)viaScreen->reg + 0x440);
530 vmesa->agpBase = viaScreen->agpBase;
531 if (VIA_DEBUG) {
532 fprintf(stderr, "regEngineStatus = %x\n", *vmesa->regEngineStatus);
533 }
534
535 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
536 return GL_TRUE;
537 }
538
539 void
540 viaDestroyContext(__DRIcontextPrivate *driContextPriv)
541 {
542 viaContextPtr vmesa = (viaContextPtr)driContextPriv->driverPrivate;
543 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
544 assert(vmesa); /* should never be null */
545
546 if (vmesa) {
547 /*=* John Sheng [2003.5.31] agp tex *=*/
548 WAIT_IDLE(vmesa);
549 if(VIA_DEBUG) fprintf(stderr, "agpFullCount = %d\n", vmesa->agpFullCount);
550
551 _swsetup_DestroyContext(vmesa->glCtx);
552 _tnl_DestroyContext(vmesa->glCtx);
553 _ac_DestroyContext(vmesa->glCtx);
554 _swrast_DestroyContext(vmesa->glCtx);
555 viaFreeVB(vmesa->glCtx);
556 FreeBuffer(vmesa);
557 /* free the Mesa context */
558 _mesa_destroy_context(vmesa->glCtx);
559 vmesa->glCtx->DriverCtx = NULL;
560 FREE(vmesa);
561 }
562
563 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
564 }
565
566
567 void viaXMesaWindowMoved(viaContextPtr vmesa)
568 {
569 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
570 GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
571
572 if (!dPriv)
573 return;
574
575 switch (vmesa->glCtx->Color._DrawDestMask[0]) {
576 case DD_FRONT_LEFT_BIT:
577 if (dPriv->numBackClipRects == 0) {
578 vmesa->numClipRects = dPriv->numClipRects;
579 vmesa->pClipRects = dPriv->pClipRects;
580 }
581 else {
582 vmesa->numClipRects = dPriv->numBackClipRects;
583 vmesa->pClipRects = dPriv->pBackClipRects;
584 }
585 break;
586 case DD_BACK_LEFT_BIT:
587 vmesa->numClipRects = dPriv->numClipRects;
588 vmesa->pClipRects = dPriv->pClipRects;
589 break;
590 default:
591 vmesa->numClipRects = 0;
592 break;
593 }
594
595 if (vmesa->drawW != dPriv->w ||
596 vmesa->drawH != dPriv->h)
597 calculate_buffer_parameters( vmesa );
598
599 vmesa->drawXoff = (GLuint)(((dPriv->x * bytePerPixel) & 0x1f) / bytePerPixel);
600 vmesa->drawX = dPriv->x - vmesa->drawXoff;
601 vmesa->drawY = dPriv->y;
602 vmesa->drawW = dPriv->w;
603 vmesa->drawH = dPriv->h;
604
605 vmesa->front.orig = (vmesa->front.offset +
606 vmesa->drawY * vmesa->front.pitch +
607 vmesa->drawX * bytePerPixel);
608
609 vmesa->front.origMap = (vmesa->front.map +
610 vmesa->drawY * vmesa->front.pitch +
611 vmesa->drawX * bytePerPixel);
612
613 vmesa->back.orig = vmesa->back.offset;
614 vmesa->depth.orig = vmesa->depth.offset;
615 vmesa->back.origMap = vmesa->back.map;
616 vmesa->depth.origMap = vmesa->depth.map;
617
618 viaCalcViewport(vmesa->glCtx);
619 }
620
621 GLboolean
622 viaUnbindContext(__DRIcontextPrivate *driContextPriv)
623 {
624 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
625 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
626 return GL_TRUE;
627 }
628
629 GLboolean
630 viaMakeCurrent(__DRIcontextPrivate *driContextPriv,
631 __DRIdrawablePrivate *driDrawPriv,
632 __DRIdrawablePrivate *driReadPriv)
633 {
634 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
635
636 if (VIA_DEBUG) {
637 fprintf(stderr, "driContextPriv = %08x\n", (GLuint)driContextPriv);
638 fprintf(stderr, "driContextPriv = %08x\n", (GLuint)driDrawPriv);
639 fprintf(stderr, "driContextPriv = %08x\n", (GLuint)driReadPriv);
640 }
641
642 if (driContextPriv) {
643 viaContextPtr vmesa = (viaContextPtr)driContextPriv->driverPrivate;
644 GLcontext *ctx = vmesa->glCtx;
645
646 if (VIA_DEBUG) fprintf(stderr, "viaMakeCurrent: w = %d\n", vmesa->driDrawable->w);
647
648 if ( vmesa->driDrawable != driDrawPriv ) {
649 driDrawableInitVBlank( driDrawPriv, vmesa->vblank_flags );
650 vmesa->driDrawable = driDrawPriv;
651 if ( ! calculate_buffer_parameters( vmesa ) ) {
652 return GL_FALSE;
653 }
654 ctx->Driver.DrawBuffer( ctx, ctx->Color.DrawBuffer[0] );
655 }
656
657 _mesa_make_current2(vmesa->glCtx,
658 (GLframebuffer *)driDrawPriv->driverPrivate,
659 (GLframebuffer *)driReadPriv->driverPrivate);
660 if (VIA_DEBUG) fprintf(stderr, "Context %d MakeCurrent\n", vmesa->hHWContext);
661 viaXMesaWindowMoved(vmesa);
662
663
664 }
665 else {
666 _mesa_make_current(0,0);
667 }
668
669 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
670 return GL_TRUE;
671 }
672
673 void viaGetLock(viaContextPtr vmesa, GLuint flags)
674 {
675 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
676 __DRIscreenPrivate *sPriv = vmesa->driScreen;
677
678 drmGetLock(vmesa->driFd, vmesa->hHWContext, flags);
679
680 DRI_VALIDATE_DRAWABLE_INFO( sPriv, dPriv );
681
682 if (vmesa->sarea->ctxOwner != vmesa->hHWContext) {
683 vmesa->sarea->ctxOwner = vmesa->hHWContext;
684 vmesa->newState = ~0;
685 }
686
687 if (vmesa->lastStamp != dPriv->lastStamp) {
688 viaXMesaWindowMoved(vmesa);
689 vmesa->lastStamp = dPriv->lastStamp;
690 }
691 }
692
693
694 void
695 viaSwapBuffers(__DRIdrawablePrivate *drawablePrivate)
696 {
697 __DRIdrawablePrivate *dPriv = (__DRIdrawablePrivate *)drawablePrivate;
698 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
699 if (dPriv && dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
700 viaContextPtr vmesa;
701 GLcontext *ctx;
702
703 vmesa = (viaContextPtr)dPriv->driContextPriv->driverPrivate;
704 ctx = vmesa->glCtx;
705 if (ctx->Visual.doubleBufferMode) {
706 _mesa_notifySwapBuffers(ctx);
707 if (vmesa->doPageFlip) {
708 viaPageFlip(dPriv);
709 }
710 else {
711 viaCopyBuffer(dPriv);
712 }
713 }
714 else
715 VIA_FLUSH_DMA(vmesa);
716 }
717 else {
718 _mesa_problem(NULL, "viaSwapBuffers: drawable has no context!\n");
719 }
720 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
721 }