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