80b573e0e51c89bbfcda87f20d8146c39e3c7cac
[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 and T&L to match hardware characteristics:
450 */
451 _swrast_allow_pixel_fog(ctx, GL_FALSE);
452 _swrast_allow_vertex_fog(ctx, GL_TRUE);
453 _tnl_allow_pixel_fog(ctx, GL_FALSE);
454 _tnl_allow_vertex_fog(ctx, GL_TRUE);
455
456 #ifndef _SOLO
457 vmesa->display = dpy;
458 vmesa->display = sPriv->display;
459 #endif
460
461 vmesa->hHWContext = driContextPriv->hHWContext;
462 vmesa->driFd = sPriv->fd;
463 vmesa->driHwLock = &sPriv->pSAREA->lock;
464
465 vmesa->viaScreen = viaScreen;
466 vmesa->driScreen = sPriv;
467 vmesa->sarea = saPriv;
468 vmesa->glBuffer = NULL;
469
470 vmesa->texHeap = mmInit(0, viaScreen->textureSize);
471 vmesa->stippleInHw = 1;
472 vmesa->renderIndex = ~0;
473 vmesa->dirty = VIA_UPLOAD_ALL;
474 vmesa->uploadCliprects = GL_TRUE;
475 vmesa->needUploadAllState = 1;
476
477 make_empty_list(&vmesa->TexObjList);
478 make_empty_list(&vmesa->SwappedOut);
479
480 vmesa->CurrentTexObj[0] = 0;
481 vmesa->CurrentTexObj[1] = 0;
482
483 vmesa->dma[0].size = DMA_SIZE * 1024 * 1024;
484 vmesa->dma[1].size = DMA_SIZE * 1024 * 1024;
485
486 _math_matrix_ctr(&vmesa->ViewportMatrix);
487
488 viaInitExtensions(ctx);
489 viaInitStateFuncs(ctx);
490 viaInitTextures(ctx);
491 viaInitTriFuncs(ctx);
492 viaInitSpanFuncs(ctx);
493 viaInitIoctlFuncs(ctx);
494 viaInitVB(ctx);
495 viaInitState(ctx);
496
497 if (getenv("VIA_DEBUG"))
498 VIA_DEBUG = 1;
499 else
500 VIA_DEBUG = 0;
501
502 if (getenv("DRAW_FRONT"))
503 DRAW_FRONT = 1;
504 else
505 DRAW_FRONT = 0;
506
507 #ifdef PERFORMANCE_MEASURE
508 if (getenv("VIA_PERFORMANCE"))
509 VIA_PERFORMANCE = 1;
510 else
511 VIA_PERFORMANCE = 0;
512
513 {
514 int i, j;
515 for (i = 0; i < HASH_TABLE_SIZE; i++) {
516 for (j = 0; j < HASH_TABLE_DEPTH; j ++) {
517 hash_table[i][j].count = 0;
518 sprintf(hash_table[i][j].func, "%s", "NULL");
519 }
520 }
521 }
522 #endif
523
524 if (!AllocateDmaBuffer(mesaVis, vmesa)) {
525 fprintf(stderr ,"AllocateDmaBuffer fail\n");
526 FREE(vmesa);
527 return GL_FALSE;
528 }
529
530 InitVertexBuffer(vmesa);
531
532 vmesa->regMMIOBase = (GLuint *)((GLuint)viaScreen->reg);
533 vmesa->pnGEMode = (GLuint *)((GLuint)viaScreen->reg + 0x4);
534 vmesa->regEngineStatus = (GLuint *)((GLuint)viaScreen->reg + 0x400);
535 vmesa->regTranSet = (GLuint *)((GLuint)viaScreen->reg + 0x43C);
536 vmesa->regTranSpace = (GLuint *)((GLuint)viaScreen->reg + 0x440);
537 vmesa->agpBase = viaScreen->agpBase;
538 #ifdef DEBUG
539 if (VIA_DEBUG) {
540 fprintf(stderr, "regEngineStatus = %x\n", *vmesa->regEngineStatus);
541 }
542
543 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
544 #endif
545 {
546 GLboolean saam;
547 int count = 0, fbSize;
548 #ifdef _SOLO
549 vmesa->saam = 0;
550 #else
551 saam = XineramaIsActive(vmesa->display);
552 if (saam && vmesa->viaScreen->drixinerama) {
553 vmesa->xsi = XineramaQueryScreens(vmesa->display, &count);
554 /* Test RightOf or Down */
555 if (vmesa->xsi[0].x_org == 0 && vmesa->xsi[0].y_org == 0) {
556 if (vmesa->xsi[1].x_org == vmesa->xsi[1].width) {
557 vmesa->saam = RightOf;
558 }
559 else {
560 vmesa->saam = Down;
561 }
562 }
563 /* Test LeftOf or Up */
564 else if (vmesa->xsi[0].x_org == vmesa->xsi[0].width) {
565 vmesa->saam = LeftOf;
566 }
567 else if (vmesa->xsi[0].y_org == vmesa->xsi[0].height) {
568 vmesa->saam = Up;
569 }
570 else
571 vmesa->saam = 0;
572
573
574 fbSize = vmesa->viaScreen->fbSize;
575 }
576 else
577 vmesa->saam = 0;
578 #endif
579 }
580
581 vmesa->pSaamRects = (drm_clip_rect_t *) malloc(sizeof(drm_clip_rect_t));
582 return GL_TRUE;
583 }
584
585 void
586 viaDestroyContext(__DRIcontextPrivate *driContextPriv)
587 {
588 viaContextPtr vmesa = (viaContextPtr)driContextPriv->driverPrivate;
589 /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
590 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
591 viaScreenPrivate *viaScreen = (viaScreenPrivate *)sPriv->private;
592 #ifdef DEBUG
593 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
594 #endif
595 assert(vmesa); /* should never be null */
596 viaFlushPrimsLocked(vmesa);
597 WAIT_IDLE
598 /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
599 /* Enable VQ */
600 if (viaScreen->VQEnable) {
601 *vmesa->regTranSet = 0x00fe0000;
602 *vmesa->regTranSet = 0x00fe0000;
603 *vmesa->regTranSpace = 0x00000006;
604 *vmesa->regTranSpace = 0x40008c0f;
605 *vmesa->regTranSpace = 0x44000000;
606 *vmesa->regTranSpace = 0x45080c04;
607 *vmesa->regTranSpace = 0x46800408;
608 }
609 if (vmesa) {
610 /*=* John Sheng [2003.5.31] flip *=*/
611 if(vmesa->doPageFlip) {
612 *((volatile GLuint *)((GLuint)vmesa->regMMIOBase + 0x43c)) = 0x00fe0000;
613 *((volatile GLuint *)((GLuint)vmesa->regMMIOBase + 0x440)) = 0x00001004;
614 WAIT_IDLE
615 *((volatile GLuint *)((GLuint)vmesa->regMMIOBase + 0x214)) = 0;
616 }
617 /*=* John Sheng [2003.5.31] agp tex *=*/
618 if(VIA_DEBUG) fprintf(stderr, "agpFullCount = %d\n", agpFullCount);
619
620 _swsetup_DestroyContext(vmesa->glCtx);
621 _tnl_DestroyContext(vmesa->glCtx);
622 _ac_DestroyContext(vmesa->glCtx);
623 _swrast_DestroyContext(vmesa->glCtx);
624 viaFreeVB(vmesa->glCtx);
625 FreeBuffer(vmesa);
626 /* free the Mesa context */
627 _mesa_destroy_context(vmesa->glCtx);
628 vmesa->glCtx->DriverCtx = NULL;
629 FREE(vmesa);
630 }
631
632 P_M_R;
633
634 #ifdef PERFORMANCE_MEASURE
635 if (VIA_PERFORMANCE) fprintf(stderr, "idle = %d\n", idle);
636 if (VIA_PERFORMANCE) fprintf(stderr, "busy = %d\n", busy);
637 #endif
638 #ifdef DEBUG
639 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
640 #endif
641 }
642
643 void viaXMesaSetFrontClipRects(viaContextPtr vmesa)
644 {
645 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
646
647 vmesa->numClipRects = dPriv->numClipRects;
648 vmesa->pClipRects = dPriv->pClipRects;
649 vmesa->drawX = dPriv->x;
650 vmesa->drawY = dPriv->y;
651 vmesa->drawW = dPriv->w;
652 vmesa->drawH = dPriv->h;
653
654 viaEmitDrawingRectangle(vmesa);
655 vmesa->uploadCliprects = GL_TRUE;
656 }
657
658 void viaXMesaSetBackClipRects(viaContextPtr vmesa)
659 {
660 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
661 /*=* John Sheng [2003.6.9] fix glxgears dirty screen */
662 /*if (vmesa->saam) {*/
663 vmesa->numClipRects = dPriv->numClipRects;
664 vmesa->pClipRects = dPriv->pClipRects;
665 vmesa->drawX = dPriv->x;
666 vmesa->drawY = dPriv->y;
667 vmesa->drawW = dPriv->w;
668 vmesa->drawH = dPriv->h;
669 /*}
670 else {
671 if (dPriv->numBackClipRects == 0) {
672 vmesa->numClipRects = dPriv->numClipRects;
673 vmesa->pClipRects = dPriv->pClipRects;
674 vmesa->drawX = dPriv->x;
675 vmesa->drawY = dPriv->y;
676 vmesa->drawW = dPriv->w;
677 vmesa->drawH = dPriv->h;
678 }
679 else {
680 vmesa->numClipRects = dPriv->numBackClipRects;
681 vmesa->pClipRects = dPriv->pBackClipRects;
682 vmesa->drawX = dPriv->backX;
683 vmesa->drawY = dPriv->backY;
684 vmesa->drawW = dPriv->w;
685 vmesa->drawH = dPriv->h;
686 }
687 }*/
688 viaEmitDrawingRectangle(vmesa);
689 vmesa->uploadCliprects = GL_TRUE;
690 }
691
692 void viaXMesaWindowMoved(viaContextPtr vmesa)
693 {
694 GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
695 GLuint side = 0;
696 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
697
698 switch (vmesa->glCtx->Color._DrawDestMask) {
699 case __GL_FRONT_BUFFER_MASK:
700 viaXMesaSetFrontClipRects(vmesa);
701 break;
702 case __GL_BACK_BUFFER_MASK:
703 viaXMesaSetBackClipRects(vmesa);
704 break;
705 default:
706 break;
707 }
708
709 #ifdef _SOLO
710 vmesa->viaScreen->fbOffset = 0;
711 vmesa->saam &= ~S1;
712 vmesa->saam |= S0;
713 #else
714 side = vmesa->saam & P_MASK;
715
716 switch (side) {
717 case RightOf:
718 /* full in screen 1 */
719 if (vmesa->drawX >= vmesa->xsi[0].width) {
720 vmesa->viaScreen->fbOffset = vmesa->viaScreen->fbSize;
721 vmesa->drawX = vmesa->drawX - vmesa->xsi[1].width;
722 vmesa->numClipRects = dPriv->numBackClipRects;
723 vmesa->pClipRects = dPriv->pBackClipRects;
724 vmesa->drawX = dPriv->backX;
725 vmesa->drawY = dPriv->backY;
726 vmesa->saam &= ~S0;
727 vmesa->saam |= S1;
728 }
729 /* full in screen 0 */
730 else if ((vmesa->drawX + vmesa->drawW) <= vmesa->xsi[0].width) {
731 vmesa->viaScreen->fbOffset = 0;
732 vmesa->saam &= ~S1;
733 vmesa->saam |= S0;
734 }
735 /* between screen 0 && screen 1 */
736 else {
737 vmesa->numSaamRects = dPriv->numBackClipRects;
738 vmesa->pSaamRects = dPriv->pBackClipRects;
739 vmesa->drawXSaam = dPriv->backX;
740 vmesa->drawYSaam = dPriv->backY;
741 vmesa->viaScreen->fbOffset = 0;
742 vmesa->saam |= S0;
743 vmesa->saam |= S1;
744 }
745 break;
746 case LeftOf:
747 /* full in screen 1 */
748 if (vmesa->drawX + vmesa->drawW <= 0) {
749 vmesa->viaScreen->fbOffset = vmesa->viaScreen->fbSize;
750 vmesa->drawX = vmesa->drawX + vmesa->xsi[1].width;
751 vmesa->numClipRects = dPriv->numBackClipRects;
752 vmesa->pClipRects = dPriv->pBackClipRects;
753 vmesa->drawX = dPriv->backX;
754 vmesa->drawY = dPriv->backY;
755 vmesa->saam &= ~S0;
756 vmesa->saam |= S1;
757 }
758 /* full in screen 0 */
759 else if (vmesa->drawX >= 0) {
760 vmesa->viaScreen->fbOffset = 0;
761 vmesa->saam &= ~S1;
762 vmesa->saam |= S0;
763 }
764 /* between screen 0 && screen 1 */
765 else {
766 vmesa->numSaamRects = dPriv->numBackClipRects;
767 vmesa->pSaamRects = dPriv->pBackClipRects;
768 vmesa->drawXSaam = dPriv->backX;
769 vmesa->drawYSaam = dPriv->backY;
770 vmesa->viaScreen->fbOffset = 0;
771 vmesa->saam |= S0;
772 vmesa->saam |= S1;
773 }
774 break;
775 case Down :
776 /* full in screen 1 */
777 if (vmesa->drawY >= vmesa->xsi[0].height) {
778 vmesa->viaScreen->fbOffset = vmesa->viaScreen->fbSize;
779 vmesa->drawY = vmesa->drawY - vmesa->xsi[1].height;
780 vmesa->numClipRects = dPriv->numBackClipRects;
781 vmesa->pClipRects = dPriv->pBackClipRects;
782 vmesa->drawX = dPriv->backX;
783 vmesa->drawY = dPriv->backY;
784 vmesa->saam &= ~S0;
785 vmesa->saam |= S1;
786 }
787 /* full in screen 0 */
788 else if ((vmesa->drawY + vmesa->drawH) <= vmesa->xsi[0].height) {
789 vmesa->viaScreen->fbOffset = 0;
790 vmesa->saam &= ~S1;
791 vmesa->saam |= S0;
792 }
793 /* between screen 0 && screen 1 */
794 else {
795 vmesa->numSaamRects = dPriv->numBackClipRects;
796 vmesa->pSaamRects = dPriv->pBackClipRects;
797 vmesa->drawXSaam = dPriv->backX;
798 vmesa->drawYSaam = dPriv->backY;
799 vmesa->viaScreen->fbOffset = 0;
800 vmesa->saam |= S0;
801 vmesa->saam |= S1;
802 }
803 break;
804 case Up :
805 /* full in screen 1 */
806 if ((vmesa->drawY + vmesa->drawH) <= 0) {
807 vmesa->viaScreen->fbOffset = vmesa->viaScreen->fbSize;
808 vmesa->drawY = vmesa->drawY + vmesa->xsi[1].height;
809 vmesa->numClipRects = dPriv->numBackClipRects;
810 vmesa->pClipRects = dPriv->pBackClipRects;
811 vmesa->drawX = dPriv->backX;
812 vmesa->drawY = dPriv->backY;
813 vmesa->saam &= ~S0;
814 vmesa->saam |= S1;
815 }
816 /* full in screen 0 */
817 else if (vmesa->drawY >= 0) {
818 vmesa->viaScreen->fbOffset = 0;
819 vmesa->saam &= ~S1;
820 vmesa->saam |= S0;
821 }
822 /* between screen 0 && screen 1 */
823 else {
824 vmesa->numSaamRects = dPriv->numBackClipRects;
825 vmesa->pSaamRects = dPriv->pBackClipRects;
826 vmesa->drawXSaam = dPriv->backX;
827 vmesa->drawYSaam = dPriv->backY;
828 vmesa->viaScreen->fbOffset = 0;
829 vmesa->saam |= S0;
830 vmesa->saam |= S1;
831 }
832 break;
833 default:
834 vmesa->viaScreen->fbOffset = 0;
835 }
836 #endif
837
838 {
839 GLuint pitch, offset;
840 pitch = vmesa->front.pitch;
841 offset = vmesa->viaScreen->fbOffset + (vmesa->drawY * pitch + vmesa->drawX * bytePerPixel);
842 vmesa->drawXoff = (GLuint)((offset & 0x1f) / bytePerPixel);
843 if (vmesa->saam) {
844 if (vmesa->pSaamRects) {
845 offset = vmesa->viaScreen->fbOffset + (vmesa->pSaamRects[0].y1 * pitch +
846 vmesa->pSaamRects[0].x1 * bytePerPixel);
847 vmesa->drawXoffSaam = (GLuint)((offset & 0x1f) / bytePerPixel);
848 }
849 else
850 vmesa->drawXoffSaam = 0;
851 }
852 else
853 vmesa->drawXoffSaam = 0;
854 }
855
856 vmesa->glCtx->Driver.Viewport(vmesa->glCtx,0 ,0 ,0 ,0);
857 }
858
859 GLboolean
860 viaUnbindContext(__DRIcontextPrivate *driContextPriv)
861 {
862 #ifdef DEBUG
863 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
864 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
865 #endif
866 return GL_TRUE;
867 }
868
869 GLboolean
870 viaMakeCurrent(__DRIcontextPrivate *driContextPriv,
871 __DRIdrawablePrivate *driDrawPriv,
872 __DRIdrawablePrivate *driReadPriv)
873 {
874 #ifdef DEBUG
875 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
876
877 if (VIA_DEBUG) {
878 fprintf(stderr, "driContextPriv = %08x\n", (GLuint)driContextPriv);
879 fprintf(stderr, "driContextPriv = %08x\n", (GLuint)driDrawPriv);
880 fprintf(stderr, "driContextPriv = %08x\n", (GLuint)driReadPriv);
881 }
882 #endif
883
884 if (driContextPriv) {
885 viaContextPtr vmesa = (viaContextPtr)driContextPriv->driverPrivate;
886 current_mesa = vmesa;
887
888 vmesa->driDrawable = driDrawPriv;
889 if (vmesa->drawType == GLX_PBUFFER_BIT) {
890 int w, h, bpp;
891
892 w = vmesa->driDrawable->w;
893 h = vmesa->driDrawable->h;
894 bpp = vmesa->viaScreen->bitsPerPixel;
895 if (bpp == 32) {
896 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4;
897 vmesa->front.size = w * h * bpp / 8;
898 vmesa->front.pitch = w << 2;
899 }
900 else {
901 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2;
902 vmesa->front.size = w * h * bpp / 8;
903 vmesa->front.pitch = w << 1;
904 }
905 }
906 /*=* John Sheng [2003.6.20] fix resolution 720x480/720x576 front pitch error *=*/
907 else {
908 GLuint w;
909 GLuint h;
910 GLuint bpp;
911 bpp = vmesa->viaScreen->bitsPerPixel;
912 h = vmesa->viaScreen->height;
913 w = vmesa->viaScreen->width;
914 if (bpp == 0x20) {
915 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4;
916 vmesa->front.size = w * h * bpp / 8;
917 vmesa->front.pitch = w << 2;
918 #ifdef DEBUG
919 if (VIA_DEBUG) fprintf(stderr, "viaScreen->bitsPerPixel = %d\n", 32);
920 #endif
921 }
922 else if (bpp == 0x10) {
923 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2;
924 vmesa->front.size = w * h * bpp / 8;
925 vmesa->front.pitch = w << 1;
926 #ifdef DEBUG
927 if (VIA_DEBUG) fprintf(stderr, "viaScreen->bitsPerPixel = %d\n", 16);
928 #endif
929 }
930 vmesa->front.offset = 0;
931 vmesa->front.map = (char *) vmesa->driScreen->pFB;
932 vmesa->front.size = w * h * vmesa->viaScreen->bitsPerPixel /8;
933 }
934
935 /* Allocate back & depth buffer */
936 {
937 int w, h, bpp;
938
939 w = vmesa->driDrawable->w;
940 #ifdef DEBUG
941 if (VIA_DEBUG) fprintf(stderr, "viaMakeCurrent: w = %d\n", w);
942 #endif
943 h = vmesa->driDrawable->h;
944
945 /* back buffer */
946 bpp = vmesa->viaScreen->bitsPerPixel;
947 #ifdef DEBUG
948 if (VIA_DEBUG) fprintf(stderr, "driScreen->fbBPP = %d\n", bpp);
949 #endif
950 if (bpp == 32) {
951 if (vmesa->drawType == GLX_PBUFFER_BIT)
952 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4;
953 else
954 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4 + 8;
955
956 vmesa->back.size = w * h * bpp / 8;
957 vmesa->back.pitch = w << 2;
958 }
959 else {
960 if (vmesa->drawType == GLX_PBUFFER_BIT)
961 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2;
962 else
963 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2 + 16;
964
965 vmesa->back.size = w * h * bpp / 8;
966 vmesa->back.pitch = w << 1;
967 }
968 #ifdef DEBUG
969 if (VIA_DEBUG) fprintf(stderr, "viaMakeCurrent backbuffer: w = %d h = %d bpp = %d sizs = %d\n",
970 w, h, bpp, vmesa->back.size);
971 #endif
972 /* depth buffer */
973 w = vmesa->driDrawable->w;
974
975 if (vmesa->hasDepth && vmesa->hasStencil) {
976 if (vmesa->drawType == GLX_PBUFFER_BIT)
977 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4;
978 else
979 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4 + 8;
980
981 vmesa->depth.size = w * h * 4;
982 vmesa->depth.pitch = w << 2;
983 vmesa->depth.bpp = 32;
984 #ifdef DEBUG
985 if (VIA_DEBUG) fprintf(stderr, "depthBits = 24\n");
986 if (VIA_DEBUG) fprintf(stderr, "StencilBits = 8\n");
987 #endif
988 }
989 else if (vmesa->hasDepth) {
990
991 /*=* John Sheng [2003.6.16] patch viewperf drv-08 draw nothing */
992 /*if(vmesa->viaScreen->bitsPerPixel == 32)*/
993 /*vmesa->depthBits = 16;*/
994
995 if (vmesa->depthBits == 16) {
996 if (vmesa->drawType == GLX_PBUFFER_BIT)
997 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2;
998 else
999 w = BUFFER_ALIGN_WIDTH(w * 2, BUFFER_ALIGNMENT) / 2 + 16;
1000
1001 vmesa->depth.size = w * h * 2;
1002 vmesa->depth.pitch = w << 1;
1003 vmesa->depth.bpp = 16;
1004 #ifdef DEBUG
1005 if (VIA_DEBUG) fprintf(stderr, "depthBits = 16\n");
1006 #endif
1007 }
1008 else {
1009 if (vmesa->drawType == GLX_PBUFFER_BIT)
1010 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4;
1011 else
1012 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4 + 8;
1013
1014 vmesa->depth.size = w * h * 4;
1015 vmesa->depth.pitch = w << 2;
1016 vmesa->depth.bpp = 32;
1017 #ifdef DEBUG
1018 if (VIA_DEBUG) fprintf(stderr, "depthBits = 32\n");
1019 #endif
1020 }
1021 }
1022 else if (vmesa->hasStencil) {
1023 if (vmesa->drawType == GLX_PBUFFER_BIT)
1024 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4;
1025 else
1026 w = BUFFER_ALIGN_WIDTH(w * 4, BUFFER_ALIGNMENT) / 4 + 8;
1027
1028 vmesa->depth.size = w * h * 4;
1029 vmesa->depth.pitch = w << 2;
1030 vmesa->depth.bpp = 32;
1031 #ifdef DEBUG
1032 if (VIA_DEBUG) fprintf(stderr, "StencilBits = 8\n");
1033 #endif
1034 }
1035 #ifdef DEBUG
1036 if (VIA_DEBUG) fprintf(stderr, "viaMakeCurrent depthbuffer: w = %d h = %d bpp = %d sizs = %d\n",
1037 w, h, vmesa->depth.bpp, vmesa->depth.size);
1038 #endif
1039 /*=* John Sheng [2003.5.31] flip *=*/
1040 {
1041 viaContextPtr vmesa = (viaContextPtr)driContextPriv->driverPrivate;
1042 if(vmesa->viaScreen->width == vmesa->driDrawable->w &&
1043 vmesa->viaScreen->height == vmesa->driDrawable->h) {
1044 vmesa->doPageFlip = GL_FALSE;
1045 vmesa->currentPage = 0;
1046 vmesa->back.pitch = vmesa->front.pitch;
1047 }
1048 }
1049
1050 if (!AllocateBuffer(vmesa)) {
1051 FREE(vmesa);
1052 return GL_FALSE;
1053 }
1054 }
1055 _mesa_make_current2(vmesa->glCtx,
1056 (GLframebuffer *)driDrawPriv->driverPrivate,
1057 (GLframebuffer *)driReadPriv->driverPrivate);
1058 #ifdef DEBUG
1059 if (VIA_DEBUG) fprintf(stderr, "Context %d MakeCurrent\n", vmesa->hHWContext);
1060 #endif
1061 viaXMesaWindowMoved(vmesa);
1062 if (!vmesa->glCtx->Viewport.Width)
1063 _mesa_set_viewport(vmesa->glCtx, 0, 0,
1064 driDrawPriv->w, driDrawPriv->h);
1065 }
1066 else {
1067 _mesa_make_current(0,0);
1068 }
1069
1070 #ifdef DEBUG
1071 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1072 #endif
1073 return GL_TRUE;
1074 }
1075
1076 void viaGetLock(viaContextPtr vmesa, GLuint flags)
1077 {
1078 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
1079 __DRIscreenPrivate *sPriv = vmesa->driScreen;
1080 drm_via_sarea_t *sarea = vmesa->sarea;
1081 int me = vmesa->hHWContext;
1082 __DRIdrawablePrivate *pdp;
1083 __DRIscreenPrivate *psp;
1084 pdp = dPriv;
1085 psp = sPriv;
1086 #ifdef DEBUG
1087 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1088 if (VIA_DEBUG) fprintf(stderr, "drmGetLock - in\n");
1089 #endif
1090 drmGetLock(vmesa->driFd, vmesa->hHWContext, flags);
1091
1092 do {
1093 DRM_UNLOCK(psp->fd, &psp->pSAREA->lock,
1094 pdp->driContextPriv->hHWContext);
1095 DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
1096 __driUtilUpdateDrawableInfo(dPriv);
1097 DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
1098 DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock,
1099 pdp->driContextPriv->hHWContext);
1100 } while (0);
1101
1102 if (sarea->ctxOwner != me) {
1103 vmesa->uploadCliprects = GL_TRUE;
1104 sarea->ctxOwner = me;
1105 }
1106
1107 viaXMesaWindowMoved(vmesa);
1108 #ifdef DEBUG
1109 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1110 #endif
1111 }
1112
1113 void viaLock(viaContextPtr vmesa, GLuint flags)
1114 {
1115 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
1116 __DRIscreenPrivate *sPriv = vmesa->driScreen;
1117
1118 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1119
1120 /*=* John Sheng [2003.6.16] for xf43 */
1121 if(dPriv->pStamp == NULL)
1122 dPriv->pStamp = &dPriv->lastStamp;
1123
1124 if (*(dPriv->pStamp) != dPriv->lastStamp || vmesa->saam) {
1125 GLuint scrn;
1126 scrn = vmesa->saam & S_MASK;
1127
1128 DRM_SPINLOCK(&sPriv->pSAREA->drawable_lock, sPriv->drawLockID);
1129
1130 if (scrn == S1)
1131 __driUtilUpdateDrawableInfo(dPriv);
1132 else
1133 DRI_VALIDATE_DRAWABLE_INFO_ONCE(dPriv);
1134
1135 viaXMesaWindowMoved(vmesa);
1136 DRM_SPINUNLOCK(&sPriv->pSAREA->drawable_lock, sPriv->drawLockID);
1137 }
1138
1139 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1140
1141 return;
1142 }
1143
1144 void viaUnLock(viaContextPtr vmesa, GLuint flags)
1145 {
1146 drm_via_sarea_t *sarea = vmesa->sarea;
1147 int me = vmesa->hHWContext;
1148
1149 #ifdef DEBUG
1150 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1151 if (VIA_DEBUG) fprintf(stderr, "sarea->ctxOwner = %d\n", sarea->ctxOwner);
1152 if (VIA_DEBUG) fprintf(stderr, "me = %d\n", me);
1153 #endif
1154 if (sarea->ctxOwner == me) {
1155 sarea->ctxOwner = 0;
1156 }
1157 #ifdef DEBUG
1158 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1159 #endif
1160 }
1161
1162 void
1163 viaSwapBuffers(__DRIdrawablePrivate *drawablePrivate)
1164 {
1165 __DRIdrawablePrivate *dPriv = (__DRIdrawablePrivate *)drawablePrivate;
1166 #ifdef DEBUG
1167 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1168 #endif
1169 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
1170 viaContextPtr vmesa;
1171 GLcontext *ctx;
1172
1173 vmesa = (viaContextPtr)dPriv->driContextPriv->driverPrivate;
1174 ctx = vmesa->glCtx;
1175 if (ctx->Visual.doubleBufferMode) {
1176 _mesa_notifySwapBuffers(ctx);
1177 if (vmesa->doPageFlip) {
1178 viaPageFlip(dPriv);
1179 }
1180 else {
1181 viaCopyBuffer(dPriv);
1182 }
1183 }
1184 else
1185 VIA_FIREVERTICES(vmesa);
1186 }
1187 else {
1188 _mesa_problem(NULL, "viaSwapBuffers: drawable has no context!\n");
1189 }
1190 #ifdef DEBUG
1191 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1192 #endif
1193 }