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