2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
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.
28 * \author John Sheng (presumably of either VIA Technologies or S3 Graphics)
29 * \author Others at VIA Technologies?
30 * \author Others at S3 Graphics?
37 #include "simple_list.h"
38 #include "extensions.h"
39 #include "framebuffer.h"
41 #include "swrast/swrast.h"
42 #include "swrast_setup/swrast_setup.h"
44 #include "array_cache/acache.h"
46 #include "tnl/t_pipeline.h"
48 #include "drivers/common/driverfuncs.h"
50 #include "via_screen.h"
53 #include "via_state.h"
57 #include "via_ioctl.h"
63 #define DRIVER_DATE "20050526"
71 * Return various strings for \c glGetString.
75 static const GLubyte
*viaGetString(GLcontext
*ctx
, GLenum name
)
77 static char buffer
[128];
83 return (GLubyte
*)"VIA Technology";
86 static const char * const chipset_names
[] = {
88 "CastleRock (CLE266)",
91 "UniChrome (PM8x0/CN400)",
93 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
94 unsigned id
= vmesa
->viaScreen
->deviceID
;
96 offset
= driGetRendererString( buffer
,
97 chipset_names
[(id
> VIA_PM800
) ? 0 : id
],
99 return (GLubyte
*)buffer
;
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
113 * \param width Minimum buffer width, in pixels.
115 * \returns A pixel width that meets the alignment requirements.
117 static __inline__
unsigned
118 buffer_align( unsigned width
)
120 return (width
+ 0x0f) & ~0x0f;
125 * Calculate the framebuffer parameters for all buffers (front, back, depth,
126 * and stencil) associated with the specified context.
129 * This function also calls \c AllocateBuffer to actually allocate the
135 calculate_buffer_parameters( struct via_context
*vmesa
)
137 const unsigned shift
= vmesa
->viaScreen
->bitsPerPixel
/ 16;
138 const unsigned extra
= 32;
142 /* Allocate front-buffer */
143 if (vmesa
->drawType
== GLX_PBUFFER_BIT
) {
144 w
= vmesa
->driDrawable
->w
;
145 h
= vmesa
->driDrawable
->h
;
147 vmesa
->front
.bpp
= vmesa
->viaScreen
->bitsPerPixel
;
148 vmesa
->front
.pitch
= buffer_align( w
) << shift
;
149 vmesa
->front
.size
= vmesa
->front
.pitch
* h
;
151 if (vmesa
->front
.map
)
152 via_free_draw_buffer(vmesa
, &vmesa
->front
);
153 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->front
))
157 w
= vmesa
->viaScreen
->width
;
158 h
= vmesa
->viaScreen
->height
;
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
;
166 vmesa
->front
.offset
= 0;
167 vmesa
->front
.map
= (char *) vmesa
->driScreen
->pFB
;
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
;
179 via_free_draw_buffer(vmesa
, &vmesa
->back
);
180 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->back
))
185 via_free_draw_buffer(vmesa
, &vmesa
->back
);
186 (void) memset( &vmesa
->back
, 0, sizeof( vmesa
->back
) );
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;
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
;
200 if (vmesa
->depth
.map
)
201 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
202 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->depth
)) {
207 if (vmesa
->depth
.map
)
208 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
209 (void) memset( & vmesa
->depth
, 0, sizeof( vmesa
->depth
) );
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
);
218 vmesa
->doPageFlip
= GL_FALSE
;
224 void viaReAllocateBuffers(GLcontext
*ctx
, GLframebuffer
*drawbuffer
,
225 GLuint width
, GLuint height
)
227 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
230 _swrast_alloc_buffers( drawbuffer
);
232 _mesa_resize_framebuffer(ctx
, drawbuffer
, width
, height
);
235 calculate_buffer_parameters( vmesa
);
238 static void viaBufferSize(GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
240 GET_CURRENT_CONTEXT(ctx
);
241 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
242 *width
= vmesa
->driDrawable
->w
;
243 *height
= vmesa
->driDrawable
->h
;
246 /* Extension strings exported by the Unichrome driver.
248 static const char * const card_extensions
[] =
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",
262 "GL_NV_blend_square",
266 extern const struct tnl_pipeline_stage _via_fastrender_stage
;
267 extern const struct tnl_pipeline_stage _via_render_stage
;
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
,
275 &_tnl_texture_transform_stage
,
276 /* REMOVE: point attenuation stage */
278 &_via_fastrender_stage
, /* ADD: unclipped rastersetup-to-dma */
285 static const struct dri_debug_control debug_control
[] =
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
},
306 AllocateDmaBuffer(struct via_context
*vmesa
)
309 via_free_dma_buffer(vmesa
);
311 if (!via_alloc_dma_buffer(vmesa
))
315 vmesa
->dmaCliprectAddr
= ~0;
320 FreeBuffer(struct via_context
*vmesa
)
322 if (vmesa
->front
.map
&& vmesa
->drawType
== GLX_PBUFFER_BIT
)
323 via_free_draw_buffer(vmesa
, &vmesa
->front
);
326 via_free_draw_buffer(vmesa
, &vmesa
->back
);
328 if (vmesa
->depth
.map
)
329 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
331 if (vmesa
->breadcrumb
.map
)
332 via_free_draw_buffer(vmesa
, &vmesa
->breadcrumb
);
335 via_free_dma_buffer(vmesa
);
339 get_ust_nop( int64_t * ust
)
346 viaCreateContext(const __GLcontextModes
*visual
,
347 __DRIcontextPrivate
*driContextPriv
,
348 void *sharedContextPrivate
)
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
;
358 /* Allocate via context */
359 vmesa
= (struct via_context
*) CALLOC_STRUCT(via_context
);
364 /* Parse configuration files.
366 driParseConfigFiles (&vmesa
->optionCache
, &viaScreen
->optionCache
,
367 sPriv
->myNum
, "via");
369 /* pick back buffer */
370 vmesa
->hasBack
= visual
->doubleBufferMode
;
372 switch(visual
->depthBits
) {
374 vmesa
->hasDepth
= GL_FALSE
;
375 vmesa
->depthBits
= 0;
376 vmesa
->depth_max
= 1.0;
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
;
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;
394 assert(visual
->haveStencilBuffer
);
395 assert(visual
->stencilBits
== 8);
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
;
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
;
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
]);
422 _mesa_init_driver_functions(&functions
);
423 viaInitTextureFuncs(&functions
);
425 /* Allocate the Mesa context */
426 if (sharedContextPrivate
)
427 shareCtx
= ((struct via_context
*) sharedContextPrivate
)->glCtx
;
431 vmesa
->glCtx
= _mesa_create_context(visual
, shareCtx
, &functions
,
434 vmesa
->shareCtx
= shareCtx
;
440 driContextPriv
->driverPrivate
= vmesa
;
444 ctx
->Const
.MaxTextureLevels
= 10;
445 ctx
->Const
.MaxTextureUnits
= 2;
446 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
447 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
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;
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;
461 ctx
->Driver
.GetBufferSize
= viaBufferSize
;
462 /* ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; *//* FIXME ?? */
463 ctx
->Driver
.GetString
= viaGetString
;
465 ctx
->DriverCtx
= (void *)vmesa
;
468 /* Initialize the software rasterizer and helper modules.
470 _swrast_CreateContext(ctx
);
471 _ac_CreateContext(ctx
);
472 _tnl_CreateContext(ctx
);
473 _swsetup_CreateContext(ctx
);
475 /* Install the customized pipeline:
477 _tnl_destroy_pipeline(ctx
);
478 _tnl_install_pipeline(ctx
, via_pipeline
);
480 /* Configure swrast and T&L to match hardware characteristics:
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
);
487 /* vmesa->display = dpy; */
488 vmesa
->display
= sPriv
->display
;
490 vmesa
->hHWContext
= driContextPriv
->hHWContext
;
491 vmesa
->driFd
= sPriv
->fd
;
492 vmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
494 vmesa
->viaScreen
= viaScreen
;
495 vmesa
->driScreen
= sPriv
;
496 vmesa
->sarea
= saPriv
;
498 vmesa
->renderIndex
= ~0;
499 vmesa
->setupIndex
= ~0;
500 vmesa
->hwPrimitive
= GL_POLYGON
+1;
502 /* KW: Hardwire this. Was previously set bogusly in
503 * viaCreateBuffer. Needs work before PBUFFER can be used:
505 vmesa
->drawType
= GLX_WINDOW_BIT
;
508 _math_matrix_ctr(&vmesa
->ViewportMatrix
);
510 /* Do this early, before VIA_FLUSH_DMA can be called:
512 if (!AllocateDmaBuffer(vmesa
)) {
513 fprintf(stderr
,"AllocateDmaBuffer fail\n");
519 /* Allocate a small piece of fb memory for synchronization:
521 vmesa
->breadcrumb
.bpp
= 32;
522 vmesa
->breadcrumb
.pitch
= buffer_align( 64 ) << 2;
523 vmesa
->breadcrumb
.size
= vmesa
->breadcrumb
.pitch
;
525 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->breadcrumb
)) {
526 fprintf(stderr
,"AllocateDmaBuffer fail\n");
532 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
533 viaInitStateFuncs(ctx
);
534 viaInitTriFuncs(ctx
);
535 viaInitSpanFuncs(ctx
);
536 viaInitIoctlFuncs(ctx
);
539 if (getenv("VIA_DEBUG"))
540 VIA_DEBUG
= driParseDebugString( getenv( "VIA_DEBUG" ),
543 if (getenv("VIA_NO_RAST"))
544 FALLBACK(vmesa
, VIA_FALLBACK_USER_DISABLE
, 1);
546 /* I don't understand why this isn't working:
548 vmesa
->vblank_flags
=
549 vmesa
->viaScreen
->irqEnabled
?
550 driGetDefaultVBlankFlags(&vmesa
->optionCache
) : VBLANK_FLAG_NO_IRQ
;
552 /* Hack this up in its place:
554 vmesa
->vblank_flags
= (getenv("VIA_VSYNC") ?
555 VBLANK_FLAG_SYNC
: VBLANK_FLAG_NO_IRQ
);
557 if (getenv("VIA_PAGEFLIP"))
558 vmesa
->allowPageFlip
= 1;
561 (PFNGLXGETUSTPROC
) glXGetProcAddress( (const GLubyte
*) "__glXGetUST" );
562 if ( vmesa
->get_ust
== NULL
) {
563 vmesa
->get_ust
= get_ust_nop
;
565 vmesa
->get_ust( &vmesa
->swap_ust
);
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
;
579 viaDestroyContext(__DRIcontextPrivate
*driContextPriv
)
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 */
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
);
595 if (vmesa
->doPageFlip
) {
596 LOCK_HARDWARE(vmesa
);
597 if (vmesa
->pfCurrentOffset
!= 0) {
598 fprintf(stderr
, "%s - reset pf\n", __FUNCTION__
);
599 viaResetPageFlippingLocked(vmesa
);
601 UNLOCK_HARDWARE(vmesa
);
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 */
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
));
623 void viaXMesaWindowMoved(struct via_context
*vmesa
)
625 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
626 GLuint bytePerPixel
= vmesa
->viaScreen
->bitsPerPixel
>> 3;
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
;
638 vmesa
->numClipRects
= dPriv
->numBackClipRects
;
639 vmesa
->pClipRects
= dPriv
->pBackClipRects
;
642 case BUFFER_BIT_FRONT_LEFT
:
643 vmesa
->numClipRects
= dPriv
->numClipRects
;
644 vmesa
->pClipRects
= dPriv
->pClipRects
;
647 vmesa
->numClipRects
= 0;
651 if (vmesa
->drawW
!= dPriv
->w
||
652 vmesa
->drawH
!= dPriv
->h
)
653 calculate_buffer_parameters( vmesa
);
655 vmesa
->drawXoff
= (GLuint
)(((dPriv
->x
* bytePerPixel
) & 0x1f) /
657 vmesa
->drawX
= dPriv
->x
- vmesa
->drawXoff
;
658 vmesa
->drawY
= dPriv
->y
;
659 vmesa
->drawW
= dPriv
->w
;
660 vmesa
->drawH
= dPriv
->h
;
662 vmesa
->front
.orig
= (vmesa
->front
.offset
+
663 vmesa
->drawY
* vmesa
->front
.pitch
+
664 vmesa
->drawX
* bytePerPixel
);
666 vmesa
->front
.origMap
= (vmesa
->front
.map
+
667 vmesa
->drawY
* vmesa
->front
.pitch
+
668 vmesa
->drawX
* bytePerPixel
);
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
;
675 viaCalcViewport(vmesa
->glCtx
);
679 viaUnbindContext(__DRIcontextPrivate
*driContextPriv
)
685 viaMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
686 __DRIdrawablePrivate
*driDrawPriv
,
687 __DRIdrawablePrivate
*driReadPriv
)
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
);
695 if (driContextPriv
) {
696 struct via_context
*vmesa
=
697 (struct via_context
*)driContextPriv
->driverPrivate
;
698 GLcontext
*ctx
= vmesa
->glCtx
;
700 if ( vmesa
->driDrawable
!= driDrawPriv
) {
701 driDrawableInitVBlank( driDrawPriv
, vmesa
->vblank_flags
);
702 vmesa
->driDrawable
= driDrawPriv
;
703 if ( ! calculate_buffer_parameters( vmesa
) ) {
708 _mesa_make_current(vmesa
->glCtx
,
709 (GLframebuffer
*)driDrawPriv
->driverPrivate
,
710 (GLframebuffer
*)driReadPriv
->driverPrivate
);
713 ctx
->Driver
.DrawBuffer( ctx
, ctx
->Color
.DrawBuffer
[0] );
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
);
723 _mesa_make_current(NULL
, NULL
, NULL
);
729 void viaGetLock(struct via_context
*vmesa
, GLuint flags
)
731 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
732 __DRIscreenPrivate
*sPriv
= vmesa
->driScreen
;
734 drmGetLock(vmesa
->driFd
, vmesa
->hHWContext
, flags
);
736 DRI_VALIDATE_DRAWABLE_INFO( sPriv
, dPriv
);
738 if (vmesa
->sarea
->ctxOwner
!= vmesa
->hHWContext
) {
739 vmesa
->sarea
->ctxOwner
= vmesa
->hHWContext
;
740 vmesa
->newEmitState
= ~0;
743 if (vmesa
->lastStamp
!= dPriv
->lastStamp
) {
744 viaXMesaWindowMoved(vmesa
);
745 vmesa
->newEmitState
= ~0;
746 vmesa
->lastStamp
= dPriv
->lastStamp
;
749 if (vmesa
->doPageFlip
&&
750 vmesa
->pfCurrentOffset
!= vmesa
->sarea
->pfCurrentOffset
) {
751 fprintf(stderr
, "%s - reset pf\n", __FUNCTION__
);
752 viaResetPageFlippingLocked(vmesa
);
758 viaSwapBuffers(__DRIdrawablePrivate
*drawablePrivate
)
760 __DRIdrawablePrivate
*dPriv
= (__DRIdrawablePrivate
*)drawablePrivate
;
763 dPriv
->driContextPriv
&&
764 dPriv
->driContextPriv
->driverPrivate
) {
765 struct via_context
*vmesa
=
766 (struct via_context
*)dPriv
->driContextPriv
->driverPrivate
;
767 GLcontext
*ctx
= vmesa
->glCtx
;
769 _mesa_notifySwapBuffers(ctx
);
771 if (ctx
->Visual
.doubleBufferMode
) {
772 if (vmesa
->doPageFlip
) {
776 viaCopyBuffer(dPriv
);
780 VIA_FLUSH_DMA(vmesa
);
783 _mesa_problem(NULL
, "viaSwapBuffers: drawable has no context!\n");