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