updates from Erdi Chen
[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 #include "glheader.h"
26 #include "context.h"
27 #include "matrix.h"
28 #include "simple_list.h"
29 #include "extensions.h"
30
31 #include "swrast/swrast.h"
32 #include "swrast_setup/swrast_setup.h"
33 #include "tnl/tnl.h"
34 #include "array_cache/acache.h"
35
36 #include "tnl/t_pipeline.h"
37
38 #include "drivers/common/driverfuncs.h"
39
40 #include "via_screen.h"
41 #include "via_dri.h"
42
43 #include "via_state.h"
44 #include "via_tex.h"
45 #include "via_span.h"
46 #include "via_tris.h"
47 #include "via_vb.h"
48 #include "via_ioctl.h"
49 #include "via_fb.h"
50
51 #ifndef _SOLO
52 #include <X11/Xlibint.h>
53 #endif
54 #include <stdio.h>
55 #include "macros.h"
56
57 viaContextPtr current_mesa;
58 GLuint VIA_DEBUG = 0;
59 GLuint DRAW_FRONT = 0;
60 #define DMA_SIZE 2
61 GLuint VIA_PERFORMANCE = 0;
62 #ifdef PERFORMANCE_MEASURE
63 GLuint busy = 0;
64 GLuint idle = 0;
65 hash_element hash_table[HASH_TABLE_SIZE][HASH_TABLE_DEPTH];
66 #endif
67 /*=* John Sheng [2003.5.31] agp tex *=*/
68 extern GLuint agpFullCount;
69
70 static GLboolean
71 AllocateBuffer(viaContextPtr vmesa)
72 {
73 vmesa->front_base = vmesa->driScreen->pFB;
74 if (vmesa->drawType == GLX_PBUFFER_BIT) {
75 if (vmesa->front.map)
76 via_free_front_buffer(vmesa);
77 if (!via_alloc_front_buffer(vmesa))
78 return GL_FALSE;
79 }
80
81 if (vmesa->hasBack) {
82 if (vmesa->back.map)
83 via_free_back_buffer(vmesa);
84 if (!via_alloc_back_buffer(vmesa))
85 return GL_FALSE;
86 }
87
88 if (vmesa->hasDepth || vmesa->hasStencil) {
89 if (vmesa->depth.map)
90 via_free_depth_buffer(vmesa);
91 if (!via_alloc_depth_buffer(vmesa)) {
92 via_free_depth_buffer(vmesa);
93 return GL_FALSE;
94 }
95 }
96
97 return GL_TRUE;
98 }
99
100 static const GLubyte *viaGetString(GLcontext *ctx, GLenum name)
101 {
102 switch (name) {
103 case GL_VENDOR:
104 return (GLubyte *)"VIA Technology";
105 case GL_RENDERER:
106 return (GLubyte *)"Mesa DRI VIA CLE266 20020221";
107 default:
108 return 0;
109 }
110 }
111
112 void viaReAllocateBuffers(GLframebuffer *drawbuffer)
113 {
114 GLcontext *ctx;
115 viaContextPtr vmesa = current_mesa;
116
117 ctx = vmesa->glCtx;
118 ctx->DrawBuffer->Width = drawbuffer->Width;
119 ctx->DrawBuffer->Height = drawbuffer->Height;
120
121 #ifdef DEBUG
122 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
123 #endif
124 ctx->DrawBuffer->Accum = 0;
125
126 vmesa->driDrawable->w = ctx->DrawBuffer->Width;
127 vmesa->driDrawable->h = ctx->DrawBuffer->Height;
128 LOCK_HARDWARE(vmesa);
129
130 /* Allocate back & depth buffer */
131 {
132 int w, h, bpp;
133 w = vmesa->driDrawable->w;
134 h = vmesa->driDrawable->h;
135 /* back buffer */
136 bpp = vmesa->viaScreen->bitsPerPixel;
137 #ifdef DEBUG
138 if (VIA_DEBUG) fprintf(stderr, "driScreen->fbBPP = %d\n", bpp);
139 #endif
140 if (bpp == 32) {
141 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4 + 8;
142 vmesa->back.size = w * h * bpp / 8;
143 vmesa->back.pitch = w << 2;
144 }
145 else {
146 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2 + 16;
147 vmesa->back.size = w * h * bpp / 8;
148 vmesa->back.pitch = w << 1;
149 }
150 #ifdef DEBUG
151 if (VIA_DEBUG) fprintf(stderr, "resizebuffer backbuffer: w = %d h = %d bpp = %d sizs = %d\n",
152 w, h, bpp, vmesa->back.size);
153 #endif
154 /* depth buffer */
155 w = vmesa->driDrawable->w;
156 if (vmesa->hasDepth && vmesa->hasStencil) {
157 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4 + 8;
158 vmesa->depth.size = w * h * 4;
159 vmesa->depth.pitch = w << 2;
160 vmesa->depth.bpp = 32;
161 #ifdef DEBUG
162 if (VIA_DEBUG) fprintf(stderr, "depthBits = 24\n");
163 if (VIA_DEBUG) fprintf(stderr, "StencilBits = 8\n");
164 #endif
165 }
166 else if (vmesa->hasDepth) {
167 /*=* John Sheng [2003.6.16] patch viewperf drv-08 draw nothing */
168 /*if(vmesa->viaScreen->bitsPerPixel == 32)*/
169 /*vmesa->depthBits = 16;*/
170
171 if (vmesa->depthBits == 16) {
172 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2 + 16;
173 vmesa->depth.size = w * h * 2;
174 vmesa->depth.pitch = w << 1;
175 vmesa->depth.bpp = 16;
176 #ifdef DEBUG
177 if (VIA_DEBUG) fprintf(stderr, "depthBits = 16\n");
178 #endif
179 }
180 else {
181 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4 + 8;
182 vmesa->depth.size = w * h * 4;
183 vmesa->depth.pitch = w << 2;
184 vmesa->depth.bpp = 32;
185 #ifdef DEBUG
186 if (VIA_DEBUG) fprintf(stderr, "depthBits = 32\n");
187 #endif
188 }
189 }
190 else if (vmesa->hasStencil) {
191 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4 + 8;
192 vmesa->depth.size = w * h * 4;
193 vmesa->depth.pitch = w << 2;
194 vmesa->depth.bpp = 32;
195 #ifdef DEBUG
196 if (VIA_DEBUG) fprintf(stderr, "StencilBits = 8\n");
197 #endif
198 }
199 #ifdef DEBUG
200 if (VIA_DEBUG) fprintf(stderr, "resizebuffer depthbuffer: w = %d h = %d bpp = %d sizs = %d\n",
201 w, h, vmesa->depth.bpp, vmesa->depth.size);
202 #endif
203 /*=* John Sheng [2003.5.31] flip *=*/
204 {
205 if(vmesa->viaScreen->width == vmesa->driDrawable->w &&
206 vmesa->viaScreen->height == vmesa->driDrawable->h) {
207 vmesa->back.pitch = vmesa->front.pitch;
208 vmesa->back.size = vmesa->front.size;
209 }
210 }
211
212 if (!AllocateBuffer(vmesa)) {
213 FREE(vmesa);
214 }
215 }
216 UNLOCK_HARDWARE(vmesa);
217 #ifdef DEBUG
218 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
219 #endif
220 }
221 static void viaBufferSize(GLframebuffer *buffer, GLuint *width, GLuint *height)
222
223 {
224 /* MESA5.0 */
225 viaContextPtr vmesa = current_mesa;
226 *width = vmesa->driDrawable->w;
227 *height = vmesa->driDrawable->h;
228 }
229
230 static void viaInitExtensions(GLcontext *ctx)
231 {
232 _mesa_enable_imaging_extensions(ctx);
233 _mesa_enable_extension(ctx, "GL_ARB_multitexture");
234 _mesa_enable_extension(ctx, "GL_ARB_texture_env_add");
235 _mesa_enable_extension(ctx, "GL_EXT_texture_env_add");
236 _mesa_enable_extension(ctx, "GL_EXT_stencil_wrap");
237 _mesa_enable_extension(ctx, "GL_EXT_texture_lod_bias");
238 /*=* John Sheng [2003.7.18] texture combine *=*/
239 _mesa_enable_extension(ctx, "GL_ARB_texture_env_combine");
240 _mesa_enable_extension(ctx, "GL_EXT_texture_env_combine");
241 /*=* John Sheng [2003.7.18] texture dot3 *=*/
242 _mesa_enable_extension(ctx, "GL_ARB_texture_env_dot3");
243 _mesa_enable_extension(ctx, "GL_EXT_texture_env_dot3");
244 /*=* John Sheng [2003.7.18] point parameters */
245 _mesa_enable_extension(ctx, "GL_ARB_point_parameters");
246 _mesa_enable_extension(ctx, "GL_EXT_point_parameters");
247 }
248
249 extern const struct tnl_pipeline_stage _via_fastrender_stage;
250 extern const struct tnl_pipeline_stage _via_render_stage;
251
252 static const struct tnl_pipeline_stage *via_pipeline[] = {
253 &_tnl_vertex_transform_stage,
254 &_tnl_normal_transform_stage,
255 &_tnl_lighting_stage,
256 &_tnl_fog_coordinate_stage,
257 &_tnl_texgen_stage,
258 &_tnl_texture_transform_stage,
259 /* REMOVE: point attenuation stage */
260 #if 1
261 &_via_fastrender_stage, /* ADD: unclipped rastersetup-to-dma */
262 &_via_render_stage, /* ADD: modification from _tnl_render_stage */
263 #endif
264 &_tnl_render_stage,
265 0,
266 };
267
268
269 static GLboolean
270 AllocateDmaBuffer(const GLvisual *visual, viaContextPtr vmesa)
271 {
272 #ifdef DEBUG
273 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
274 #endif
275 if (vmesa->dma[0].map && vmesa->dma[1].map)
276 via_free_dma_buffer(vmesa);
277
278 if (!via_alloc_dma_buffer(vmesa)) {
279 if (vmesa->front.map)
280 via_free_front_buffer(vmesa);
281 if (vmesa->back.map)
282 via_free_back_buffer(vmesa);
283 if (vmesa->depth.map)
284 via_free_depth_buffer(vmesa);
285
286 return GL_FALSE;
287 }
288 #ifdef DEBUG
289 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
290 #endif
291 return GL_TRUE;
292 }
293
294 static void
295 InitVertexBuffer(viaContextPtr vmesa)
296 {
297 GLuint *addr;
298
299 addr = (GLuint *)vmesa->dma[0].map;
300 *addr = 0xF210F110;
301 *addr = (HC_ParaType_NotTex << 16);
302 *addr = 0xcccccccc;
303 *addr = 0xdddddddd;
304
305 addr = (GLuint *)vmesa->dma[1].map;
306 *addr = 0xF210F110;
307 *addr = (HC_ParaType_NotTex << 16);
308 *addr = 0xcccccccc;
309 *addr = 0xdddddddd;
310
311 vmesa->dmaIndex = 0;
312 vmesa->dmaLow = DMA_OFFSET;
313 vmesa->dmaHigh = vmesa->dma[0].size;
314 vmesa->dmaAddr = (unsigned char *)vmesa->dma[0].map;
315 vmesa->dmaLastPrim = vmesa->dmaLow;
316 }
317
318 static void
319 FreeBuffer(viaContextPtr vmesa)
320 {
321 if (vmesa->front.map)
322 via_free_front_buffer(vmesa);
323
324 if (vmesa->back.map)
325 via_free_back_buffer(vmesa);
326
327 if (vmesa->depth.map)
328 via_free_depth_buffer(vmesa);
329
330 if (vmesa->dma[0].map && vmesa->dma[1].map)
331 via_free_dma_buffer(vmesa);
332 }
333
334 GLboolean
335 viaCreateContext(const __GLcontextModes *mesaVis,
336 __DRIcontextPrivate *driContextPriv,
337 void *sharedContextPrivate)
338 {
339 GLcontext *ctx, *shareCtx;
340 viaContextPtr vmesa;
341 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
342 viaScreenPrivate *viaScreen = (viaScreenPrivate *)sPriv->private;
343 drm_via_sarea_t *saPriv = (drm_via_sarea_t *)
344 (((GLubyte *)sPriv->pSAREA) + viaScreen->sareaPrivOffset);
345 struct dd_function_table functions;
346
347 /* Allocate via context */
348 vmesa = (viaContextPtr) CALLOC_STRUCT(via_context_t);
349 if (!vmesa) {
350 return GL_FALSE;
351 }
352 #ifdef DEBUG
353 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
354 #endif
355 current_mesa = vmesa;
356 /* pick back buffer */
357 if (mesaVis->doubleBufferMode) {
358 vmesa->hasBack = GL_TRUE;
359 }
360 else {
361 vmesa->hasBack = GL_FALSE;
362 }
363 /* pick z buffer */
364 if (mesaVis->haveDepthBuffer) {
365 vmesa->hasDepth = GL_TRUE;
366 vmesa->depthBits = mesaVis->depthBits;
367 }
368 else {
369 vmesa->hasDepth = GL_FALSE;
370 vmesa->depthBits = 0;
371 }
372 /* pick stencil buffer */
373 if (mesaVis->haveStencilBuffer) {
374 vmesa->hasStencil = GL_TRUE;
375 vmesa->stencilBits = mesaVis->stencilBits;
376 }
377 else {
378 vmesa->hasStencil = GL_FALSE;
379 vmesa->stencilBits = 0;
380 }
381
382 _mesa_init_driver_functions(&functions);
383 viaInitTextureFuncs(&functions);
384
385 /* Allocate the Mesa context */
386 if (sharedContextPrivate)
387 shareCtx = ((viaContextPtr) sharedContextPrivate)->glCtx;
388 else
389 shareCtx = NULL;
390
391 vmesa->glCtx = _mesa_create_context(mesaVis, shareCtx, &functions, (void*) vmesa);
392
393 vmesa->shareCtx = shareCtx;
394
395 if (!vmesa->glCtx) {
396 FREE(vmesa);
397 return GL_FALSE;
398 }
399 driContextPriv->driverPrivate = vmesa;
400
401 ctx = vmesa->glCtx;
402
403 /* check */
404 /*=* John Sheng [2003.7.2] for visual config number can't excess 8 *=*/
405 /*if (viaScreen->textureSize < 2 * 1024 * 1024) {
406 ctx->Const.MaxTextureLevels = 9;
407 }
408 else if (viaScreen->textureSize < 8 * 1024 * 1024) {
409 ctx->Const.MaxTextureLevels = 10;
410 }
411 else {
412 ctx->Const.MaxTextureLevels = 11;
413 }*/
414 ctx->Const.MaxTextureLevels = 11;
415
416 ctx->Const.MaxTextureUnits = 2;
417
418 ctx->Const.MinLineWidth = 1.0;
419 ctx->Const.MinLineWidthAA = 1.0;
420 ctx->Const.MaxLineWidth = 3.0;
421 ctx->Const.MaxLineWidthAA = 3.0;
422 ctx->Const.LineWidthGranularity = 1.0;
423
424 ctx->Const.MinPointSize = 1.0;
425 ctx->Const.MinPointSizeAA = 1.0;
426 ctx->Const.MaxPointSize = 3.0;
427 ctx->Const.MaxPointSizeAA = 3.0;
428 ctx->Const.PointSizeGranularity = 1.0;
429
430 ctx->Driver.GetBufferSize = viaBufferSize;
431 /* ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; *//* FIXME ?? */
432 ctx->Driver.GetString = viaGetString;
433
434 ctx->DriverCtx = (void *)vmesa;
435 vmesa->glCtx = ctx;
436
437 /* Initialize the software rasterizer and helper modules.
438 */
439 _swrast_CreateContext(ctx);
440 _ac_CreateContext(ctx);
441 _tnl_CreateContext(ctx);
442 _swsetup_CreateContext(ctx);
443
444 /* Install the customized pipeline:
445 */
446 _tnl_destroy_pipeline(ctx);
447 _tnl_install_pipeline(ctx, via_pipeline);
448
449 /* Configure swrast to match hardware characteristics:
450 */
451 _swrast_allow_pixel_fog(ctx, GL_FALSE);
452 _swrast_allow_vertex_fog(ctx, GL_TRUE);
453
454 #ifndef _SOLO
455 vmesa->display = dpy;
456 vmesa->display = sPriv->display;
457 #endif
458
459 vmesa->hHWContext = driContextPriv->hHWContext;
460 vmesa->driFd = sPriv->fd;
461 vmesa->driHwLock = &sPriv->pSAREA->lock;
462
463 vmesa->viaScreen = viaScreen;
464 vmesa->driScreen = sPriv;
465 vmesa->sarea = saPriv;
466 vmesa->glBuffer = NULL;
467
468 vmesa->texHeap = mmInit(0, viaScreen->textureSize);
469 vmesa->stippleInHw = 1;
470 vmesa->renderIndex = ~0;
471 vmesa->dirty = VIA_UPLOAD_ALL;
472 vmesa->uploadCliprects = GL_TRUE;
473 vmesa->needUploadAllState = 1;
474
475 make_empty_list(&vmesa->TexObjList);
476 make_empty_list(&vmesa->SwappedOut);
477
478 vmesa->CurrentTexObj[0] = 0;
479 vmesa->CurrentTexObj[1] = 0;
480
481 vmesa->dma[0].size = DMA_SIZE * 1024 * 1024;
482 vmesa->dma[1].size = DMA_SIZE * 1024 * 1024;
483
484 _math_matrix_ctr(&vmesa->ViewportMatrix);
485
486 viaInitExtensions(ctx);
487 viaInitStateFuncs(ctx);
488 viaInitTextures(ctx);
489 viaInitTriFuncs(ctx);
490 viaInitSpanFuncs(ctx);
491 viaInitIoctlFuncs(ctx);
492 viaInitVB(ctx);
493 viaInitState(ctx);
494
495 if (getenv("VIA_DEBUG"))
496 VIA_DEBUG = 1;
497 else
498 VIA_DEBUG = 0;
499
500 if (getenv("DRAW_FRONT"))
501 DRAW_FRONT = 1;
502 else
503 DRAW_FRONT = 0;
504
505 #ifdef PERFORMANCE_MEASURE
506 if (getenv("VIA_PERFORMANCE"))
507 VIA_PERFORMANCE = 1;
508 else
509 VIA_PERFORMANCE = 0;
510
511 {
512 int i, j;
513 for (i = 0; i < HASH_TABLE_SIZE; i++) {
514 for (j = 0; j < HASH_TABLE_DEPTH; j ++) {
515 hash_table[i][j].count = 0;
516 sprintf(hash_table[i][j].func, "%s", "NULL");
517 }
518 }
519 }
520 #endif
521
522 if (!AllocateDmaBuffer(mesaVis, vmesa)) {
523 fprintf(stderr ,"AllocateDmaBuffer fail\n");
524 FREE(vmesa);
525 return GL_FALSE;
526 }
527
528 InitVertexBuffer(vmesa);
529
530 vmesa->regMMIOBase = (GLuint *)((GLuint)viaScreen->reg);
531 vmesa->pnGEMode = (GLuint *)((GLuint)viaScreen->reg + 0x4);
532 vmesa->regEngineStatus = (GLuint *)((GLuint)viaScreen->reg + 0x400);
533 vmesa->regTranSet = (GLuint *)((GLuint)viaScreen->reg + 0x43C);
534 vmesa->regTranSpace = (GLuint *)((GLuint)viaScreen->reg + 0x440);
535 vmesa->agpBase = viaScreen->agpBase;
536 #ifdef DEBUG
537 if (VIA_DEBUG) {
538 fprintf(stderr, "regEngineStatus = %x\n", *vmesa->regEngineStatus);
539 }
540
541 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
542 #endif
543 {
544 GLboolean saam;
545 int count = 0, fbSize;
546 #ifdef _SOLO
547 vmesa->saam = 0;
548 #else
549 saam = XineramaIsActive(vmesa->display);
550 if (saam && vmesa->viaScreen->drixinerama) {
551 vmesa->xsi = XineramaQueryScreens(vmesa->display, &count);
552 /* Test RightOf or Down */
553 if (vmesa->xsi[0].x_org == 0 && vmesa->xsi[0].y_org == 0) {
554 if (vmesa->xsi[1].x_org == vmesa->xsi[1].width) {
555 vmesa->saam = RightOf;
556 }
557 else {
558 vmesa->saam = Down;
559 }
560 }
561 /* Test LeftOf or Up */
562 else if (vmesa->xsi[0].x_org == vmesa->xsi[0].width) {
563 vmesa->saam = LeftOf;
564 }
565 else if (vmesa->xsi[0].y_org == vmesa->xsi[0].height) {
566 vmesa->saam = Up;
567 }
568 else
569 vmesa->saam = 0;
570
571
572 fbSize = vmesa->viaScreen->fbSize;
573 }
574 else
575 vmesa->saam = 0;
576 #endif
577 }
578
579 vmesa->pSaamRects = (XF86DRIClipRectPtr) malloc(sizeof(XF86DRIClipRectRec));
580 return GL_TRUE;
581 }
582
583 void
584 viaDestroyContext(__DRIcontextPrivate *driContextPriv)
585 {
586 viaContextPtr vmesa = (viaContextPtr)driContextPriv->driverPrivate;
587 /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
588 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
589 viaScreenPrivate *viaScreen = (viaScreenPrivate *)sPriv->private;
590 #ifdef DEBUG
591 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
592 #endif
593 assert(vmesa); /* should never be null */
594 viaFlushPrimsLocked(vmesa);
595 WAIT_IDLE
596 /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
597 /* Enable VQ */
598 if (viaScreen->VQEnable) {
599 *vmesa->regTranSet = 0x00fe0000;
600 *vmesa->regTranSet = 0x00fe0000;
601 *vmesa->regTranSpace = 0x00000006;
602 *vmesa->regTranSpace = 0x40008c0f;
603 *vmesa->regTranSpace = 0x44000000;
604 *vmesa->regTranSpace = 0x45080c04;
605 *vmesa->regTranSpace = 0x46800408;
606 }
607 if (vmesa) {
608 /*=* John Sheng [2003.5.31] flip *=*/
609 if(vmesa->doPageFlip) {
610 *((volatile GLuint *)((GLuint)vmesa->regMMIOBase + 0x43c)) = 0x00fe0000;
611 *((volatile GLuint *)((GLuint)vmesa->regMMIOBase + 0x440)) = 0x00001004;
612 WAIT_IDLE
613 *((volatile GLuint *)((GLuint)vmesa->regMMIOBase + 0x214)) = 0;
614 }
615 /*=* John Sheng [2003.5.31] agp tex *=*/
616 if(VIA_DEBUG) fprintf(stderr, "agpFullCount = %d\n", agpFullCount);
617
618 _swsetup_DestroyContext(vmesa->glCtx);
619 _tnl_DestroyContext(vmesa->glCtx);
620 _ac_DestroyContext(vmesa->glCtx);
621 _swrast_DestroyContext(vmesa->glCtx);
622 viaFreeVB(vmesa->glCtx);
623 FreeBuffer(vmesa);
624 /* free the Mesa context */
625 _mesa_destroy_context(vmesa->glCtx);
626 vmesa->glCtx->DriverCtx = NULL;
627 FREE(vmesa);
628 }
629
630 P_M_R;
631
632 #ifdef PERFORMANCE_MEASURE
633 if (VIA_PERFORMANCE) fprintf(stderr, "idle = %d\n", idle);
634 if (VIA_PERFORMANCE) fprintf(stderr, "busy = %d\n", busy);
635 #endif
636 #ifdef DEBUG
637 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
638 #endif
639 }
640
641 void viaXMesaSetFrontClipRects(viaContextPtr vmesa)
642 {
643 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
644
645 vmesa->numClipRects = dPriv->numClipRects;
646 vmesa->pClipRects = dPriv->pClipRects;
647 vmesa->drawX = dPriv->x;
648 vmesa->drawY = dPriv->y;
649 vmesa->drawW = dPriv->w;
650 vmesa->drawH = dPriv->h;
651
652 viaEmitDrawingRectangle(vmesa);
653 vmesa->uploadCliprects = GL_TRUE;
654 }
655
656 void viaXMesaSetBackClipRects(viaContextPtr vmesa)
657 {
658 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
659 /*=* John Sheng [2003.6.9] fix glxgears dirty screen */
660 /*if (vmesa->saam) {*/
661 vmesa->numClipRects = dPriv->numClipRects;
662 vmesa->pClipRects = dPriv->pClipRects;
663 vmesa->drawX = dPriv->x;
664 vmesa->drawY = dPriv->y;
665 vmesa->drawW = dPriv->w;
666 vmesa->drawH = dPriv->h;
667 /*}
668 else {
669 if (dPriv->numBackClipRects == 0) {
670 vmesa->numClipRects = dPriv->numClipRects;
671 vmesa->pClipRects = dPriv->pClipRects;
672 vmesa->drawX = dPriv->x;
673 vmesa->drawY = dPriv->y;
674 vmesa->drawW = dPriv->w;
675 vmesa->drawH = dPriv->h;
676 }
677 else {
678 vmesa->numClipRects = dPriv->numBackClipRects;
679 vmesa->pClipRects = dPriv->pBackClipRects;
680 vmesa->drawX = dPriv->backX;
681 vmesa->drawY = dPriv->backY;
682 vmesa->drawW = dPriv->w;
683 vmesa->drawH = dPriv->h;
684 }
685 }*/
686 viaEmitDrawingRectangle(vmesa);
687 vmesa->uploadCliprects = GL_TRUE;
688 }
689
690 void viaXMesaWindowMoved(viaContextPtr vmesa)
691 {
692 GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
693 GLuint side = 0;
694 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
695
696 switch (vmesa->glCtx->Color._DrawDestMask) {
697 case __GL_FRONT_BUFFER_MASK:
698 viaXMesaSetFrontClipRects(vmesa);
699 break;
700 case __GL_BACK_BUFFER_MASK:
701 viaXMesaSetBackClipRects(vmesa);
702 break;
703 default:
704 break;
705 }
706
707 #ifdef _SOLO
708 vmesa->viaScreen->fbOffset = 0;
709 vmesa->saam &= ~S1;
710 vmesa->saam |= S0;
711 #else
712 side = vmesa->saam & P_MASK;
713
714 switch (side) {
715 case RightOf:
716 /* full in screen 1 */
717 if (vmesa->drawX >= vmesa->xsi[0].width) {
718 vmesa->viaScreen->fbOffset = vmesa->viaScreen->fbSize;
719 vmesa->drawX = vmesa->drawX - vmesa->xsi[1].width;
720 vmesa->numClipRects = dPriv->numBackClipRects;
721 vmesa->pClipRects = dPriv->pBackClipRects;
722 vmesa->drawX = dPriv->backX;
723 vmesa->drawY = dPriv->backY;
724 vmesa->saam &= ~S0;
725 vmesa->saam |= S1;
726 }
727 /* full in screen 0 */
728 else if ((vmesa->drawX + vmesa->drawW) <= vmesa->xsi[0].width) {
729 vmesa->viaScreen->fbOffset = 0;
730 vmesa->saam &= ~S1;
731 vmesa->saam |= S0;
732 }
733 /* between screen 0 && screen 1 */
734 else {
735 vmesa->numSaamRects = dPriv->numBackClipRects;
736 vmesa->pSaamRects = dPriv->pBackClipRects;
737 vmesa->drawXSaam = dPriv->backX;
738 vmesa->drawYSaam = dPriv->backY;
739 vmesa->viaScreen->fbOffset = 0;
740 vmesa->saam |= S0;
741 vmesa->saam |= S1;
742 }
743 break;
744 case LeftOf:
745 /* full in screen 1 */
746 if (vmesa->drawX + vmesa->drawW <= 0) {
747 vmesa->viaScreen->fbOffset = vmesa->viaScreen->fbSize;
748 vmesa->drawX = vmesa->drawX + vmesa->xsi[1].width;
749 vmesa->numClipRects = dPriv->numBackClipRects;
750 vmesa->pClipRects = dPriv->pBackClipRects;
751 vmesa->drawX = dPriv->backX;
752 vmesa->drawY = dPriv->backY;
753 vmesa->saam &= ~S0;
754 vmesa->saam |= S1;
755 }
756 /* full in screen 0 */
757 else if (vmesa->drawX >= 0) {
758 vmesa->viaScreen->fbOffset = 0;
759 vmesa->saam &= ~S1;
760 vmesa->saam |= S0;
761 }
762 /* between screen 0 && screen 1 */
763 else {
764 vmesa->numSaamRects = dPriv->numBackClipRects;
765 vmesa->pSaamRects = dPriv->pBackClipRects;
766 vmesa->drawXSaam = dPriv->backX;
767 vmesa->drawYSaam = dPriv->backY;
768 vmesa->viaScreen->fbOffset = 0;
769 vmesa->saam |= S0;
770 vmesa->saam |= S1;
771 }
772 break;
773 case Down :
774 /* full in screen 1 */
775 if (vmesa->drawY >= vmesa->xsi[0].height) {
776 vmesa->viaScreen->fbOffset = vmesa->viaScreen->fbSize;
777 vmesa->drawY = vmesa->drawY - vmesa->xsi[1].height;
778 vmesa->numClipRects = dPriv->numBackClipRects;
779 vmesa->pClipRects = dPriv->pBackClipRects;
780 vmesa->drawX = dPriv->backX;
781 vmesa->drawY = dPriv->backY;
782 vmesa->saam &= ~S0;
783 vmesa->saam |= S1;
784 }
785 /* full in screen 0 */
786 else if ((vmesa->drawY + vmesa->drawH) <= vmesa->xsi[0].height) {
787 vmesa->viaScreen->fbOffset = 0;
788 vmesa->saam &= ~S1;
789 vmesa->saam |= S0;
790 }
791 /* between screen 0 && screen 1 */
792 else {
793 vmesa->numSaamRects = dPriv->numBackClipRects;
794 vmesa->pSaamRects = dPriv->pBackClipRects;
795 vmesa->drawXSaam = dPriv->backX;
796 vmesa->drawYSaam = dPriv->backY;
797 vmesa->viaScreen->fbOffset = 0;
798 vmesa->saam |= S0;
799 vmesa->saam |= S1;
800 }
801 break;
802 case Up :
803 /* full in screen 1 */
804 if ((vmesa->drawY + vmesa->drawH) <= 0) {
805 vmesa->viaScreen->fbOffset = vmesa->viaScreen->fbSize;
806 vmesa->drawY = vmesa->drawY + vmesa->xsi[1].height;
807 vmesa->numClipRects = dPriv->numBackClipRects;
808 vmesa->pClipRects = dPriv->pBackClipRects;
809 vmesa->drawX = dPriv->backX;
810 vmesa->drawY = dPriv->backY;
811 vmesa->saam &= ~S0;
812 vmesa->saam |= S1;
813 }
814 /* full in screen 0 */
815 else if (vmesa->drawY >= 0) {
816 vmesa->viaScreen->fbOffset = 0;
817 vmesa->saam &= ~S1;
818 vmesa->saam |= S0;
819 }
820 /* between screen 0 && screen 1 */
821 else {
822 vmesa->numSaamRects = dPriv->numBackClipRects;
823 vmesa->pSaamRects = dPriv->pBackClipRects;
824 vmesa->drawXSaam = dPriv->backX;
825 vmesa->drawYSaam = dPriv->backY;
826 vmesa->viaScreen->fbOffset = 0;
827 vmesa->saam |= S0;
828 vmesa->saam |= S1;
829 }
830 break;
831 default:
832 vmesa->viaScreen->fbOffset = 0;
833 }
834 #endif
835
836 {
837 GLuint pitch, offset;
838 pitch = vmesa->front.pitch;
839 offset = vmesa->viaScreen->fbOffset + (vmesa->drawY * pitch + vmesa->drawX * bytePerPixel);
840 vmesa->drawXoff = (GLuint)((offset & 0x1f) / bytePerPixel);
841 if (vmesa->saam) {
842 if (vmesa->pSaamRects) {
843 offset = vmesa->viaScreen->fbOffset + (vmesa->pSaamRects[0].y1 * pitch +
844 vmesa->pSaamRects[0].x1 * bytePerPixel);
845 vmesa->drawXoffSaam = (GLuint)((offset & 0x1f) / bytePerPixel);
846 }
847 else
848 vmesa->drawXoffSaam = 0;
849 }
850 else
851 vmesa->drawXoffSaam = 0;
852 }
853
854 vmesa->glCtx->Driver.Viewport(vmesa->glCtx,0 ,0 ,0 ,0);
855 }
856
857 GLboolean
858 viaUnbindContext(__DRIcontextPrivate *driContextPriv)
859 {
860 #ifdef DEBUG
861 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
862 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
863 #endif
864 return GL_TRUE;
865 }
866
867 GLboolean
868 viaMakeCurrent(__DRIcontextPrivate *driContextPriv,
869 __DRIdrawablePrivate *driDrawPriv,
870 __DRIdrawablePrivate *driReadPriv)
871 {
872 #ifdef DEBUG
873 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
874
875 if (VIA_DEBUG) {
876 fprintf(stderr, "driContextPriv = %08x\n", (GLuint)driContextPriv);
877 fprintf(stderr, "driContextPriv = %08x\n", (GLuint)driDrawPriv);
878 fprintf(stderr, "driContextPriv = %08x\n", (GLuint)driReadPriv);
879 }
880 #endif
881
882 if (driContextPriv) {
883 viaContextPtr vmesa = (viaContextPtr)driContextPriv->driverPrivate;
884 current_mesa = vmesa;
885
886 vmesa->driDrawable = driDrawPriv;
887 if (vmesa->drawType == GLX_PBUFFER_BIT) {
888 int w, h, bpp;
889
890 w = vmesa->driDrawable->w;
891 h = vmesa->driDrawable->h;
892 bpp = vmesa->viaScreen->bitsPerPixel;
893 if (bpp == 32) {
894 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4;
895 vmesa->front.size = w * h * bpp / 8;
896 vmesa->front.pitch = w << 2;
897 }
898 else {
899 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2;
900 vmesa->front.size = w * h * bpp / 8;
901 vmesa->front.pitch = w << 1;
902 }
903 }
904 /*=* John Sheng [2003.6.20] fix resolution 720x480/720x576 front pitch error *=*/
905 else {
906 GLuint w;
907 GLuint h;
908 GLuint bpp;
909 bpp = vmesa->viaScreen->bitsPerPixel;
910 h = vmesa->viaScreen->height;
911 w = vmesa->viaScreen->width;
912 if (bpp == 0x20) {
913 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4;
914 vmesa->front.size = w * h * bpp / 8;
915 vmesa->front.pitch = w << 2;
916 #ifdef DEBUG
917 if (VIA_DEBUG) fprintf(stderr, "viaScreen->bitsPerPixel = %d\n", 32);
918 #endif
919 }
920 else if (bpp == 0x10) {
921 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2;
922 vmesa->front.size = w * h * bpp / 8;
923 vmesa->front.pitch = w << 1;
924 #ifdef DEBUG
925 if (VIA_DEBUG) fprintf(stderr, "viaScreen->bitsPerPixel = %d\n", 16);
926 #endif
927 }
928 vmesa->front.offset = 0;
929 vmesa->front.map = (char *) vmesa->driScreen->pFB;
930 vmesa->front.size = w * h * vmesa->viaScreen->bitsPerPixel /8;
931 }
932
933 /* Allocate back & depth buffer */
934 {
935 int w, h, bpp;
936
937 w = vmesa->driDrawable->w;
938 #ifdef DEBUG
939 if (VIA_DEBUG) fprintf(stderr, "viaMakeCurrent: w = %d\n", w);
940 #endif
941 h = vmesa->driDrawable->h;
942
943 /* back buffer */
944 bpp = vmesa->viaScreen->bitsPerPixel;
945 #ifdef DEBUG
946 if (VIA_DEBUG) fprintf(stderr, "driScreen->fbBPP = %d\n", bpp);
947 #endif
948 if (bpp == 32) {
949 if (vmesa->drawType == GLX_PBUFFER_BIT)
950 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4;
951 else
952 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4 + 8;
953
954 vmesa->back.size = w * h * bpp / 8;
955 vmesa->back.pitch = w << 2;
956 }
957 else {
958 if (vmesa->drawType == GLX_PBUFFER_BIT)
959 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2;
960 else
961 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2 + 16;
962
963 vmesa->back.size = w * h * bpp / 8;
964 vmesa->back.pitch = w << 1;
965 }
966 #ifdef DEBUG
967 if (VIA_DEBUG) fprintf(stderr, "viaMakeCurrent backbuffer: w = %d h = %d bpp = %d sizs = %d\n",
968 w, h, bpp, vmesa->back.size);
969 #endif
970 /* depth buffer */
971 w = vmesa->driDrawable->w;
972
973 if (vmesa->hasDepth && vmesa->hasStencil) {
974 if (vmesa->drawType == GLX_PBUFFER_BIT)
975 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4;
976 else
977 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4 + 8;
978
979 vmesa->depth.size = w * h * 4;
980 vmesa->depth.pitch = w << 2;
981 vmesa->depth.bpp = 32;
982 #ifdef DEBUG
983 if (VIA_DEBUG) fprintf(stderr, "depthBits = 24\n");
984 if (VIA_DEBUG) fprintf(stderr, "StencilBits = 8\n");
985 #endif
986 }
987 else if (vmesa->hasDepth) {
988
989 /*=* John Sheng [2003.6.16] patch viewperf drv-08 draw nothing */
990 /*if(vmesa->viaScreen->bitsPerPixel == 32)*/
991 /*vmesa->depthBits = 16;*/
992
993 if (vmesa->depthBits == 16) {
994 if (vmesa->drawType == GLX_PBUFFER_BIT)
995 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2;
996 else
997 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2 + 16;
998
999 vmesa->depth.size = w * h * 2;
1000 vmesa->depth.pitch = w << 1;
1001 vmesa->depth.bpp = 16;
1002 #ifdef DEBUG
1003 if (VIA_DEBUG) fprintf(stderr, "depthBits = 16\n");
1004 #endif
1005 }
1006 else {
1007 if (vmesa->drawType == GLX_PBUFFER_BIT)
1008 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4;
1009 else
1010 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4 + 8;
1011
1012 vmesa->depth.size = w * h * 4;
1013 vmesa->depth.pitch = w << 2;
1014 vmesa->depth.bpp = 32;
1015 #ifdef DEBUG
1016 if (VIA_DEBUG) fprintf(stderr, "depthBits = 32\n");
1017 #endif
1018 }
1019 }
1020 else if (vmesa->hasStencil) {
1021 if (vmesa->drawType == GLX_PBUFFER_BIT)
1022 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4;
1023 else
1024 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4 + 8;
1025
1026 vmesa->depth.size = w * h * 4;
1027 vmesa->depth.pitch = w << 2;
1028 vmesa->depth.bpp = 32;
1029 #ifdef DEBUG
1030 if (VIA_DEBUG) fprintf(stderr, "StencilBits = 8\n");
1031 #endif
1032 }
1033 #ifdef DEBUG
1034 if (VIA_DEBUG) fprintf(stderr, "viaMakeCurrent depthbuffer: w = %d h = %d bpp = %d sizs = %d\n",
1035 w, h, vmesa->depth.bpp, vmesa->depth.size);
1036 #endif
1037 /*=* John Sheng [2003.5.31] flip *=*/
1038 {
1039 viaContextPtr vmesa = (viaContextPtr)driContextPriv->driverPrivate;
1040 if(vmesa->viaScreen->width == vmesa->driDrawable->w &&
1041 vmesa->viaScreen->height == vmesa->driDrawable->h) {
1042 vmesa->doPageFlip = GL_FALSE;
1043 vmesa->currentPage = 0;
1044 vmesa->back.pitch = vmesa->front.pitch;
1045 }
1046 }
1047
1048 if (!AllocateBuffer(vmesa)) {
1049 FREE(vmesa);
1050 return GL_FALSE;
1051 }
1052 }
1053 _mesa_make_current2(vmesa->glCtx,
1054 (GLframebuffer *)driDrawPriv->driverPrivate,
1055 (GLframebuffer *)driReadPriv->driverPrivate);
1056 #ifdef DEBUG
1057 if (VIA_DEBUG) fprintf(stderr, "Context %d MakeCurrent\n", vmesa->hHWContext);
1058 #endif
1059 viaXMesaWindowMoved(vmesa);
1060 if (!vmesa->glCtx->Viewport.Width)
1061 _mesa_set_viewport(vmesa->glCtx, 0, 0,
1062 driDrawPriv->w, driDrawPriv->h);
1063 }
1064 else {
1065 _mesa_make_current(0,0);
1066 }
1067
1068 #ifdef DEBUG
1069 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1070 #endif
1071 return GL_TRUE;
1072 }
1073
1074 void viaGetLock(viaContextPtr vmesa, GLuint flags)
1075 {
1076 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
1077 __DRIscreenPrivate *sPriv = vmesa->driScreen;
1078 drm_via_sarea_t *sarea = vmesa->sarea;
1079 int me = vmesa->hHWContext;
1080 __DRIdrawablePrivate *pdp;
1081 __DRIscreenPrivate *psp;
1082 pdp = dPriv;
1083 psp = sPriv;
1084 #ifdef DEBUG
1085 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1086 if (VIA_DEBUG) fprintf(stderr, "drmGetLock - in\n");
1087 #endif
1088 drmGetLock(vmesa->driFd, vmesa->hHWContext, flags);
1089
1090 do {
1091 DRM_UNLOCK(psp->fd, &psp->pSAREA->lock,
1092 pdp->driContextPriv->hHWContext);
1093 DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
1094 __driUtilUpdateDrawableInfo(dPriv);
1095 DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
1096 DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock,
1097 pdp->driContextPriv->hHWContext);
1098 } while (0);
1099
1100 if (sarea->ctxOwner != me) {
1101 vmesa->uploadCliprects = GL_TRUE;
1102 sarea->ctxOwner = me;
1103 }
1104
1105 viaXMesaWindowMoved(vmesa);
1106 #ifdef DEBUG
1107 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1108 #endif
1109 }
1110
1111 void viaLock(viaContextPtr vmesa, GLuint flags)
1112 {
1113 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
1114 __DRIscreenPrivate *sPriv = vmesa->driScreen;
1115
1116 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1117
1118 /*=* John Sheng [2003.6.16] for xf43 */
1119 if(dPriv->pStamp == NULL)
1120 dPriv->pStamp = &dPriv->lastStamp;
1121
1122 if (*(dPriv->pStamp) != dPriv->lastStamp || vmesa->saam) {
1123 GLuint scrn;
1124 scrn = vmesa->saam & S_MASK;
1125
1126 DRM_SPINLOCK(&sPriv->pSAREA->drawable_lock, sPriv->drawLockID);
1127
1128 if (scrn == S1)
1129 __driUtilUpdateDrawableInfo(dPriv);
1130 else
1131 DRI_VALIDATE_DRAWABLE_INFO_ONCE(dPriv);
1132
1133 viaXMesaWindowMoved(vmesa);
1134 DRM_SPINUNLOCK(&sPriv->pSAREA->drawable_lock, sPriv->drawLockID);
1135 }
1136
1137 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1138
1139 return;
1140 }
1141
1142 void viaUnLock(viaContextPtr vmesa, GLuint flags)
1143 {
1144 drm_via_sarea_t *sarea = vmesa->sarea;
1145 int me = vmesa->hHWContext;
1146
1147 #ifdef DEBUG
1148 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1149 if (VIA_DEBUG) fprintf(stderr, "sarea->ctxOwner = %d\n", sarea->ctxOwner);
1150 if (VIA_DEBUG) fprintf(stderr, "me = %d\n", me);
1151 #endif
1152 if (sarea->ctxOwner == me) {
1153 sarea->ctxOwner = 0;
1154 }
1155 #ifdef DEBUG
1156 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1157 #endif
1158 }
1159
1160 void
1161 viaSwapBuffers(__DRIdrawablePrivate *drawablePrivate)
1162 {
1163 __DRIdrawablePrivate *dPriv = (__DRIdrawablePrivate *)drawablePrivate;
1164 #ifdef DEBUG
1165 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1166 #endif
1167 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
1168 viaContextPtr vmesa;
1169 GLcontext *ctx;
1170
1171 vmesa = (viaContextPtr)dPriv->driContextPriv->driverPrivate;
1172 ctx = vmesa->glCtx;
1173 if (ctx->Visual.doubleBufferMode) {
1174 _mesa_notifySwapBuffers(ctx);
1175 if (vmesa->doPageFlip) {
1176 viaPageFlip(dPriv);
1177 }
1178 else {
1179 viaCopyBuffer(dPriv);
1180 }
1181 }
1182 else
1183 VIA_FIREVERTICES(vmesa);
1184 }
1185 else {
1186 _mesa_problem(NULL, "viaSwapBuffers: drawable has no context!\n");
1187 }
1188 #ifdef DEBUG
1189 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1190 #endif
1191 }