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?
36 #include "simple_list.h"
37 #include "extensions.h"
39 #include "swrast/swrast.h"
40 #include "swrast_setup/swrast_setup.h"
42 #include "array_cache/acache.h"
44 #include "tnl/t_pipeline.h"
46 #include "drivers/common/driverfuncs.h"
48 #include "via_screen.h"
51 #include "via_state.h"
56 #include "via_ioctl.h"
62 #define DRIVER_DATE "20040923"
66 viaContextPtr current_mesa
;
68 GLuint DRAW_FRONT
= 0;
70 GLuint VIA_PERFORMANCE
= 0;
71 #ifdef PERFORMANCE_MEASURE
74 hash_element hash_table
[HASH_TABLE_SIZE
][HASH_TABLE_DEPTH
];
76 /*=* John Sheng [2003.5.31] agp tex *=*/
77 extern GLuint agpFullCount
;
80 AllocateBuffer(viaContextPtr vmesa
)
82 vmesa
->front_base
= vmesa
->driScreen
->pFB
;
83 if (vmesa
->drawType
== GLX_PBUFFER_BIT
) {
85 via_free_front_buffer(vmesa
);
86 if (!via_alloc_front_buffer(vmesa
))
92 via_free_back_buffer(vmesa
);
93 if (!via_alloc_back_buffer(vmesa
))
97 if (vmesa
->hasDepth
|| vmesa
->hasStencil
) {
99 via_free_depth_buffer(vmesa
);
100 if (!via_alloc_depth_buffer(vmesa
)) {
101 via_free_depth_buffer(vmesa
);
110 * Return various strings for \c glGetString.
113 * This function should look at the PCI ID of the chipset to determine what
114 * name to use. Users with a KM400, for example, might get confused when
115 * the driver says "CLE266". Having the correct information may also help
116 * folks on the DRI mailing lists debug problems for people.
120 static const GLubyte
*viaGetString(GLcontext
*ctx
, GLenum name
)
122 static char buffer
[128];
128 return (GLubyte
*)"VIA Technology";
131 offset
= driGetRendererString( buffer
, "CLE266", DRIVER_DATE
, 0 );
132 return (GLubyte
*)buffer
;
141 * Calculate a width that satisfies the hardware's alignment requirements.
142 * On the Unichrome hardware, each scanline must be aligned to a multiple of
145 * \param width Minimum buffer width, in pixels.
147 * \returns A pixel width that meets the alignment requirements.
149 static __inline__
unsigned
150 buffer_align( unsigned width
)
152 return (width
+ 0x0f) & ~0x0f;
157 * Calculate the framebuffer parameters for all buffers (front, back, depth,
158 * and stencil) associated with the specified context.
161 * This function also calls \c AllocateBuffer to actually allocate the
167 calculate_buffer_parameters( viaContextPtr vmesa
)
169 const unsigned shift
= vmesa
->viaScreen
->bitsPerPixel
/ 16;
170 const unsigned extra
= (vmesa
->drawType
== GLX_PBUFFER_BIT
) ? 0 : 32;
174 if (vmesa
->drawType
== GLX_PBUFFER_BIT
) {
175 w
= vmesa
->driDrawable
->w
;
176 h
= vmesa
->driDrawable
->h
;
179 w
= vmesa
->viaScreen
->width
;
180 h
= vmesa
->viaScreen
->height
;
182 vmesa
->front
.offset
= 0;
183 vmesa
->front
.map
= (char *) vmesa
->driScreen
->pFB
;
186 vmesa
->front
.pitch
= buffer_align( w
) << shift
;
187 vmesa
->front
.size
= vmesa
->front
.pitch
* h
;
190 /* Allocate back-buffer */
192 vmesa
->back
.pitch
= (buffer_align( vmesa
->driDrawable
->w
) << shift
)
194 vmesa
->back
.size
= vmesa
->back
.pitch
* vmesa
->driDrawable
->h
;
197 if (VIA_DEBUG
) fprintf(stderr
, "viaMakeCurrent backbuffer: w = %d h = %d bpp = %d sizs = %d\n",
199 vmesa
->driDrawable
->h
,
204 /* Allocate depth-buffer */
205 if ( vmesa
->hasStencil
|| vmesa
->hasDepth
) {
206 const unsigned dShift
= (vmesa
->hasStencil
)
207 ? 2 : (vmesa
->depthBits
/ 16);
209 vmesa
->depth
.pitch
= (buffer_align( vmesa
->driDrawable
->w
) << dShift
)
211 vmesa
->depth
.bpp
= 8 << dShift
;
212 vmesa
->depth
.size
= vmesa
->depth
.pitch
* vmesa
->driDrawable
->h
;
215 (void) memset( & vmesa
->depth
, 0, sizeof( vmesa
->depth
) );
219 if (VIA_DEBUG
) fprintf(stderr
, "viaMakeCurrent depthbuffer: w = %d h = %d bpp = %d sizs = %d\n",
221 vmesa
->driDrawable
->h
,
226 /*=* John Sheng [2003.5.31] flip *=*/
227 if( (vmesa
->viaScreen
->width
== vmesa
->driDrawable
->w
)
228 && (vmesa
->viaScreen
->height
== vmesa
->driDrawable
->h
) ) {
229 vmesa
->doPageFlip
= GL_FALSE
;
230 vmesa
->currentPage
= 0;
231 vmesa
->back
.pitch
= vmesa
->front
.pitch
;
234 if (!AllocateBuffer(vmesa
)) {
243 void viaReAllocateBuffers(GLframebuffer
*drawbuffer
)
246 viaContextPtr vmesa
= current_mesa
;
249 ctx
->DrawBuffer
->Width
= drawbuffer
->Width
;
250 ctx
->DrawBuffer
->Height
= drawbuffer
->Height
;
253 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
255 ctx
->DrawBuffer
->Accum
= 0;
257 vmesa
->driDrawable
->w
= ctx
->DrawBuffer
->Width
;
258 vmesa
->driDrawable
->h
= ctx
->DrawBuffer
->Height
;
260 LOCK_HARDWARE(vmesa
);
261 calculate_buffer_parameters( vmesa
);
262 UNLOCK_HARDWARE(vmesa
);
265 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
268 static void viaBufferSize(GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
272 viaContextPtr vmesa
= current_mesa
;
273 *width
= vmesa
->driDrawable
->w
;
274 *height
= vmesa
->driDrawable
->h
;
277 /* Extension strings exported by the Unichrome driver.
279 static const char * const card_extensions
[] =
281 "GL_ARB_multitexture",
282 "GL_ARB_point_parameters",
283 "GL_ARB_texture_env_add",
284 "GL_ARB_texture_env_combine",
285 "GL_ARB_texture_env_dot3",
286 "GL_ARB_texture_mirrored_repeat",
287 "GL_EXT_stencil_wrap",
288 "GL_EXT_texture_env_combine",
289 "GL_EXT_texture_env_dot3",
290 "GL_EXT_texture_lod_bias",
291 "GL_NV_blend_square",
295 extern const struct tnl_pipeline_stage _via_fastrender_stage
;
296 extern const struct tnl_pipeline_stage _via_render_stage
;
298 static const struct tnl_pipeline_stage
*via_pipeline
[] = {
299 &_tnl_vertex_transform_stage
,
300 &_tnl_normal_transform_stage
,
301 &_tnl_lighting_stage
,
302 &_tnl_fog_coordinate_stage
,
304 &_tnl_texture_transform_stage
,
305 /* REMOVE: point attenuation stage */
307 &_via_fastrender_stage
, /* ADD: unclipped rastersetup-to-dma */
308 &_via_render_stage
, /* ADD: modification from _tnl_render_stage */
316 AllocateDmaBuffer(const GLvisual
*visual
, viaContextPtr vmesa
)
319 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
321 if (vmesa
->dma
[0].map
&& vmesa
->dma
[1].map
)
322 via_free_dma_buffer(vmesa
);
324 if (!via_alloc_dma_buffer(vmesa
)) {
325 if (vmesa
->front
.map
)
326 via_free_front_buffer(vmesa
);
328 via_free_back_buffer(vmesa
);
329 if (vmesa
->depth
.map
)
330 via_free_depth_buffer(vmesa
);
335 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
341 InitVertexBuffer(viaContextPtr vmesa
)
345 addr
= (GLuint
*)vmesa
->dma
[0].map
;
347 *addr
= (HC_ParaType_NotTex
<< 16);
351 addr
= (GLuint
*)vmesa
->dma
[1].map
;
353 *addr
= (HC_ParaType_NotTex
<< 16);
358 vmesa
->dmaLow
= DMA_OFFSET
;
359 vmesa
->dmaHigh
= vmesa
->dma
[0].size
;
360 vmesa
->dmaAddr
= (unsigned char *)vmesa
->dma
[0].map
;
361 vmesa
->dmaLastPrim
= vmesa
->dmaLow
;
365 FreeBuffer(viaContextPtr vmesa
)
367 if (vmesa
->front
.map
)
368 via_free_front_buffer(vmesa
);
371 via_free_back_buffer(vmesa
);
373 if (vmesa
->depth
.map
)
374 via_free_depth_buffer(vmesa
);
376 if (vmesa
->dma
[0].map
&& vmesa
->dma
[1].map
)
377 via_free_dma_buffer(vmesa
);
381 viaCreateContext(const __GLcontextModes
*mesaVis
,
382 __DRIcontextPrivate
*driContextPriv
,
383 void *sharedContextPrivate
)
385 GLcontext
*ctx
, *shareCtx
;
387 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
388 viaScreenPrivate
*viaScreen
= (viaScreenPrivate
*)sPriv
->private;
389 drm_via_sarea_t
*saPriv
= (drm_via_sarea_t
*)
390 (((GLubyte
*)sPriv
->pSAREA
) + viaScreen
->sareaPrivOffset
);
391 struct dd_function_table functions
;
393 /* Allocate via context */
394 vmesa
= (viaContextPtr
) CALLOC_STRUCT(via_context_t
);
399 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
401 current_mesa
= vmesa
;
402 /* pick back buffer */
403 if (mesaVis
->doubleBufferMode
) {
404 vmesa
->hasBack
= GL_TRUE
;
407 vmesa
->hasBack
= GL_FALSE
;
410 if (mesaVis
->haveDepthBuffer
) {
411 vmesa
->hasDepth
= GL_TRUE
;
412 vmesa
->depthBits
= mesaVis
->depthBits
;
415 vmesa
->hasDepth
= GL_FALSE
;
416 vmesa
->depthBits
= 0;
418 /* pick stencil buffer */
419 if (mesaVis
->haveStencilBuffer
) {
420 vmesa
->hasStencil
= GL_TRUE
;
421 vmesa
->stencilBits
= mesaVis
->stencilBits
;
424 vmesa
->hasStencil
= GL_FALSE
;
425 vmesa
->stencilBits
= 0;
428 _mesa_init_driver_functions(&functions
);
429 viaInitTextureFuncs(&functions
);
431 /* Allocate the Mesa context */
432 if (sharedContextPrivate
)
433 shareCtx
= ((viaContextPtr
) sharedContextPrivate
)->glCtx
;
437 vmesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
, &functions
, (void*) vmesa
);
439 vmesa
->shareCtx
= shareCtx
;
445 driContextPriv
->driverPrivate
= vmesa
;
450 /*=* John Sheng [2003.7.2] for visual config number can't excess 8 *=*/
451 /*if (viaScreen->textureSize < 2 * 1024 * 1024) {
452 ctx->Const.MaxTextureLevels = 9;
454 else if (viaScreen->textureSize < 8 * 1024 * 1024) {
455 ctx->Const.MaxTextureLevels = 10;
458 ctx->Const.MaxTextureLevels = 11;
460 ctx
->Const
.MaxTextureLevels
= 11;
462 ctx
->Const
.MaxTextureUnits
= 2;
463 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
464 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
466 ctx
->Const
.MinLineWidth
= 1.0;
467 ctx
->Const
.MinLineWidthAA
= 1.0;
468 ctx
->Const
.MaxLineWidth
= 3.0;
469 ctx
->Const
.MaxLineWidthAA
= 3.0;
470 ctx
->Const
.LineWidthGranularity
= 1.0;
472 ctx
->Const
.MinPointSize
= 1.0;
473 ctx
->Const
.MinPointSizeAA
= 1.0;
474 ctx
->Const
.MaxPointSize
= 3.0;
475 ctx
->Const
.MaxPointSizeAA
= 3.0;
476 ctx
->Const
.PointSizeGranularity
= 1.0;
478 ctx
->Driver
.GetBufferSize
= viaBufferSize
;
479 /* ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; *//* FIXME ?? */
480 ctx
->Driver
.GetString
= viaGetString
;
482 ctx
->DriverCtx
= (void *)vmesa
;
485 /* Initialize the software rasterizer and helper modules.
487 _swrast_CreateContext(ctx
);
488 _ac_CreateContext(ctx
);
489 _tnl_CreateContext(ctx
);
490 _swsetup_CreateContext(ctx
);
492 /* Install the customized pipeline:
494 _tnl_destroy_pipeline(ctx
);
495 _tnl_install_pipeline(ctx
, via_pipeline
);
497 /* Configure swrast and T&L to match hardware characteristics:
499 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
500 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
501 _tnl_allow_pixel_fog(ctx
, GL_FALSE
);
502 _tnl_allow_vertex_fog(ctx
, GL_TRUE
);
504 /* vmesa->display = dpy; */
505 vmesa
->display
= sPriv
->display
;
507 vmesa
->hHWContext
= driContextPriv
->hHWContext
;
508 vmesa
->driFd
= sPriv
->fd
;
509 vmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
511 vmesa
->viaScreen
= viaScreen
;
512 vmesa
->driScreen
= sPriv
;
513 vmesa
->sarea
= saPriv
;
514 vmesa
->glBuffer
= NULL
;
516 vmesa
->texHeap
= mmInit(0, viaScreen
->textureSize
);
517 vmesa
->stippleInHw
= 1;
518 vmesa
->renderIndex
= ~0;
519 vmesa
->dirty
= VIA_UPLOAD_ALL
;
520 vmesa
->uploadCliprects
= GL_TRUE
;
521 vmesa
->needUploadAllState
= 1;
523 make_empty_list(&vmesa
->TexObjList
);
524 make_empty_list(&vmesa
->SwappedOut
);
526 vmesa
->CurrentTexObj
[0] = 0;
527 vmesa
->CurrentTexObj
[1] = 0;
529 vmesa
->dma
[0].size
= DMA_SIZE
* 1024 * 1024;
530 vmesa
->dma
[1].size
= DMA_SIZE
* 1024 * 1024;
532 _math_matrix_ctr(&vmesa
->ViewportMatrix
);
534 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
535 viaInitStateFuncs(ctx
);
536 viaInitTextures(ctx
);
537 viaInitTriFuncs(ctx
);
538 viaInitSpanFuncs(ctx
);
539 viaInitIoctlFuncs(ctx
);
543 if (getenv("VIA_DEBUG"))
548 if (getenv("DRAW_FRONT"))
553 #ifdef PERFORMANCE_MEASURE
554 if (getenv("VIA_PERFORMANCE"))
561 for (i
= 0; i
< HASH_TABLE_SIZE
; i
++) {
562 for (j
= 0; j
< HASH_TABLE_DEPTH
; j
++) {
563 hash_table
[i
][j
].count
= 0;
564 sprintf(hash_table
[i
][j
].func
, "%s", "NULL");
570 if (!AllocateDmaBuffer(mesaVis
, vmesa
)) {
571 fprintf(stderr
,"AllocateDmaBuffer fail\n");
576 InitVertexBuffer(vmesa
);
578 vmesa
->regMMIOBase
= (GLuint
*)((GLuint
)viaScreen
->reg
);
579 vmesa
->pnGEMode
= (GLuint
*)((GLuint
)viaScreen
->reg
+ 0x4);
580 vmesa
->regEngineStatus
= (GLuint
*)((GLuint
)viaScreen
->reg
+ 0x400);
581 vmesa
->regTranSet
= (GLuint
*)((GLuint
)viaScreen
->reg
+ 0x43C);
582 vmesa
->regTranSpace
= (GLuint
*)((GLuint
)viaScreen
->reg
+ 0x440);
583 vmesa
->agpBase
= viaScreen
->agpBase
;
586 fprintf(stderr
, "regEngineStatus = %x\n", *vmesa
->regEngineStatus
);
589 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
595 GLboolean saam
= XineramaIsActive(vmesa
->display
);
596 int count
= 0, fbSize
;
598 if (saam
&& vmesa
->viaScreen
->drixinerama
) {
599 vmesa
->xsi
= XineramaQueryScreens(vmesa
->display
, &count
);
600 /* Test RightOf or Down */
601 if (vmesa
->xsi
[0].x_org
== 0 && vmesa
->xsi
[0].y_org
== 0) {
602 if (vmesa
->xsi
[1].x_org
== vmesa
->xsi
[1].width
) {
603 vmesa
->saam
= RightOf
;
609 /* Test LeftOf or Up */
610 else if (vmesa
->xsi
[0].x_org
== vmesa
->xsi
[0].width
) {
611 vmesa
->saam
= LeftOf
;
613 else if (vmesa
->xsi
[0].y_org
== vmesa
->xsi
[0].height
) {
620 fbSize
= vmesa
->viaScreen
->fbSize
;
627 vmesa
->pSaamRects
= (drm_clip_rect_t
*) malloc(sizeof(drm_clip_rect_t
));
632 viaDestroyContext(__DRIcontextPrivate
*driContextPriv
)
634 viaContextPtr vmesa
= (viaContextPtr
)driContextPriv
->driverPrivate
;
635 /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
636 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
637 viaScreenPrivate
*viaScreen
= (viaScreenPrivate
*)sPriv
->private;
639 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
641 assert(vmesa
); /* should never be null */
642 viaFlushPrimsLocked(vmesa
);
644 /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
646 if (viaScreen
->VQEnable
) {
647 *vmesa
->regTranSet
= 0x00fe0000;
648 *vmesa
->regTranSet
= 0x00fe0000;
649 *vmesa
->regTranSpace
= 0x00000006;
650 *vmesa
->regTranSpace
= 0x40008c0f;
651 *vmesa
->regTranSpace
= 0x44000000;
652 *vmesa
->regTranSpace
= 0x45080c04;
653 *vmesa
->regTranSpace
= 0x46800408;
656 /*=* John Sheng [2003.5.31] flip *=*/
657 if(vmesa
->doPageFlip
) {
658 *((volatile GLuint
*)((GLuint
)vmesa
->regMMIOBase
+ 0x43c)) = 0x00fe0000;
659 *((volatile GLuint
*)((GLuint
)vmesa
->regMMIOBase
+ 0x440)) = 0x00001004;
661 *((volatile GLuint
*)((GLuint
)vmesa
->regMMIOBase
+ 0x214)) = 0;
663 /*=* John Sheng [2003.5.31] agp tex *=*/
664 if(VIA_DEBUG
) fprintf(stderr
, "agpFullCount = %d\n", agpFullCount
);
666 _swsetup_DestroyContext(vmesa
->glCtx
);
667 _tnl_DestroyContext(vmesa
->glCtx
);
668 _ac_DestroyContext(vmesa
->glCtx
);
669 _swrast_DestroyContext(vmesa
->glCtx
);
670 viaFreeVB(vmesa
->glCtx
);
672 /* free the Mesa context */
673 _mesa_destroy_context(vmesa
->glCtx
);
674 vmesa
->glCtx
->DriverCtx
= NULL
;
680 #ifdef PERFORMANCE_MEASURE
681 if (VIA_PERFORMANCE
) fprintf(stderr
, "idle = %d\n", idle
);
682 if (VIA_PERFORMANCE
) fprintf(stderr
, "busy = %d\n", busy
);
685 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
689 void viaXMesaSetFrontClipRects(viaContextPtr vmesa
)
691 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
693 vmesa
->numClipRects
= dPriv
->numClipRects
;
694 vmesa
->pClipRects
= dPriv
->pClipRects
;
695 vmesa
->drawX
= dPriv
->x
;
696 vmesa
->drawY
= dPriv
->y
;
697 vmesa
->drawW
= dPriv
->w
;
698 vmesa
->drawH
= dPriv
->h
;
700 viaEmitDrawingRectangle(vmesa
);
701 vmesa
->uploadCliprects
= GL_TRUE
;
704 void viaXMesaSetBackClipRects(viaContextPtr vmesa
)
706 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
707 /*=* John Sheng [2003.6.9] fix glxgears dirty screen */
708 /*if (vmesa->saam) {*/
709 vmesa
->numClipRects
= dPriv
->numClipRects
;
710 vmesa
->pClipRects
= dPriv
->pClipRects
;
711 vmesa
->drawX
= dPriv
->x
;
712 vmesa
->drawY
= dPriv
->y
;
713 vmesa
->drawW
= dPriv
->w
;
714 vmesa
->drawH
= dPriv
->h
;
717 if (dPriv->numBackClipRects == 0) {
718 vmesa->numClipRects = dPriv->numClipRects;
719 vmesa->pClipRects = dPriv->pClipRects;
720 vmesa->drawX = dPriv->x;
721 vmesa->drawY = dPriv->y;
722 vmesa->drawW = dPriv->w;
723 vmesa->drawH = dPriv->h;
726 vmesa->numClipRects = dPriv->numBackClipRects;
727 vmesa->pClipRects = dPriv->pBackClipRects;
728 vmesa->drawX = dPriv->backX;
729 vmesa->drawY = dPriv->backY;
730 vmesa->drawW = dPriv->w;
731 vmesa->drawH = dPriv->h;
734 viaEmitDrawingRectangle(vmesa
);
735 vmesa
->uploadCliprects
= GL_TRUE
;
738 void viaXMesaWindowMoved(viaContextPtr vmesa
)
740 GLuint bytePerPixel
= vmesa
->viaScreen
->bitsPerPixel
>> 3;
743 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
746 switch (vmesa
->glCtx
->Color
._DrawDestMask
[0]) {
747 case __GL_FRONT_BUFFER_MASK
:
748 viaXMesaSetFrontClipRects(vmesa
);
750 case __GL_BACK_BUFFER_MASK
:
751 viaXMesaSetBackClipRects(vmesa
);
758 vmesa
->viaScreen
->fbOffset
= 0;
762 side
= vmesa
->saam
& P_MASK
;
766 /* full in screen 1 */
767 if (vmesa
->drawX
>= vmesa
->xsi
[0].width
) {
768 vmesa
->viaScreen
->fbOffset
= vmesa
->viaScreen
->fbSize
;
769 vmesa
->drawX
= vmesa
->drawX
- vmesa
->xsi
[1].width
;
770 vmesa
->numClipRects
= dPriv
->numBackClipRects
;
771 vmesa
->pClipRects
= dPriv
->pBackClipRects
;
772 vmesa
->drawX
= dPriv
->backX
;
773 vmesa
->drawY
= dPriv
->backY
;
777 /* full in screen 0 */
778 else if ((vmesa
->drawX
+ vmesa
->drawW
) <= vmesa
->xsi
[0].width
) {
779 vmesa
->viaScreen
->fbOffset
= 0;
783 /* between screen 0 && screen 1 */
785 vmesa
->numSaamRects
= dPriv
->numBackClipRects
;
786 vmesa
->pSaamRects
= dPriv
->pBackClipRects
;
787 vmesa
->drawXSaam
= dPriv
->backX
;
788 vmesa
->drawYSaam
= dPriv
->backY
;
789 vmesa
->viaScreen
->fbOffset
= 0;
795 /* full in screen 1 */
796 if (vmesa
->drawX
+ vmesa
->drawW
<= 0) {
797 vmesa
->viaScreen
->fbOffset
= vmesa
->viaScreen
->fbSize
;
798 vmesa
->drawX
= vmesa
->drawX
+ vmesa
->xsi
[1].width
;
799 vmesa
->numClipRects
= dPriv
->numBackClipRects
;
800 vmesa
->pClipRects
= dPriv
->pBackClipRects
;
801 vmesa
->drawX
= dPriv
->backX
;
802 vmesa
->drawY
= dPriv
->backY
;
806 /* full in screen 0 */
807 else if (vmesa
->drawX
>= 0) {
808 vmesa
->viaScreen
->fbOffset
= 0;
812 /* between screen 0 && screen 1 */
814 vmesa
->numSaamRects
= dPriv
->numBackClipRects
;
815 vmesa
->pSaamRects
= dPriv
->pBackClipRects
;
816 vmesa
->drawXSaam
= dPriv
->backX
;
817 vmesa
->drawYSaam
= dPriv
->backY
;
818 vmesa
->viaScreen
->fbOffset
= 0;
824 /* full in screen 1 */
825 if (vmesa
->drawY
>= vmesa
->xsi
[0].height
) {
826 vmesa
->viaScreen
->fbOffset
= vmesa
->viaScreen
->fbSize
;
827 vmesa
->drawY
= vmesa
->drawY
- vmesa
->xsi
[1].height
;
828 vmesa
->numClipRects
= dPriv
->numBackClipRects
;
829 vmesa
->pClipRects
= dPriv
->pBackClipRects
;
830 vmesa
->drawX
= dPriv
->backX
;
831 vmesa
->drawY
= dPriv
->backY
;
835 /* full in screen 0 */
836 else if ((vmesa
->drawY
+ vmesa
->drawH
) <= vmesa
->xsi
[0].height
) {
837 vmesa
->viaScreen
->fbOffset
= 0;
841 /* between screen 0 && screen 1 */
843 vmesa
->numSaamRects
= dPriv
->numBackClipRects
;
844 vmesa
->pSaamRects
= dPriv
->pBackClipRects
;
845 vmesa
->drawXSaam
= dPriv
->backX
;
846 vmesa
->drawYSaam
= dPriv
->backY
;
847 vmesa
->viaScreen
->fbOffset
= 0;
853 /* full in screen 1 */
854 if ((vmesa
->drawY
+ vmesa
->drawH
) <= 0) {
855 vmesa
->viaScreen
->fbOffset
= vmesa
->viaScreen
->fbSize
;
856 vmesa
->drawY
= vmesa
->drawY
+ vmesa
->xsi
[1].height
;
857 vmesa
->numClipRects
= dPriv
->numBackClipRects
;
858 vmesa
->pClipRects
= dPriv
->pBackClipRects
;
859 vmesa
->drawX
= dPriv
->backX
;
860 vmesa
->drawY
= dPriv
->backY
;
864 /* full in screen 0 */
865 else if (vmesa
->drawY
>= 0) {
866 vmesa
->viaScreen
->fbOffset
= 0;
870 /* between screen 0 && screen 1 */
872 vmesa
->numSaamRects
= dPriv
->numBackClipRects
;
873 vmesa
->pSaamRects
= dPriv
->pBackClipRects
;
874 vmesa
->drawXSaam
= dPriv
->backX
;
875 vmesa
->drawYSaam
= dPriv
->backY
;
876 vmesa
->viaScreen
->fbOffset
= 0;
882 vmesa
->viaScreen
->fbOffset
= 0;
887 GLuint pitch
, offset
;
888 pitch
= vmesa
->front
.pitch
;
889 offset
= vmesa
->viaScreen
->fbOffset
+ (vmesa
->drawY
* pitch
+ vmesa
->drawX
* bytePerPixel
);
890 vmesa
->drawXoff
= (GLuint
)((offset
& 0x1f) / bytePerPixel
);
892 if (vmesa
->pSaamRects
) {
893 offset
= vmesa
->viaScreen
->fbOffset
+ (vmesa
->pSaamRects
[0].y1
* pitch
+
894 vmesa
->pSaamRects
[0].x1
* bytePerPixel
);
895 vmesa
->drawXoffSaam
= (GLuint
)((offset
& 0x1f) / bytePerPixel
);
898 vmesa
->drawXoffSaam
= 0;
901 vmesa
->drawXoffSaam
= 0;
904 vmesa
->glCtx
->Driver
.Viewport(vmesa
->glCtx
,0 ,0 ,0 ,0);
908 viaUnbindContext(__DRIcontextPrivate
*driContextPriv
)
911 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
912 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
918 viaMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
919 __DRIdrawablePrivate
*driDrawPriv
,
920 __DRIdrawablePrivate
*driReadPriv
)
923 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
926 fprintf(stderr
, "driContextPriv = %08x\n", (GLuint
)driContextPriv
);
927 fprintf(stderr
, "driContextPriv = %08x\n", (GLuint
)driDrawPriv
);
928 fprintf(stderr
, "driContextPriv = %08x\n", (GLuint
)driReadPriv
);
932 if (driContextPriv
) {
933 viaContextPtr vmesa
= (viaContextPtr
)driContextPriv
->driverPrivate
;
935 current_mesa
= vmesa
;
938 if (VIA_DEBUG
) fprintf(stderr
, "viaScreen->bitsPerPixel = %d\n", viaScreen
->bitsPerPixel
);
939 if (VIA_DEBUG
) fprintf(stderr
, "viaMakeCurrent: w = %d\n", vmesa
->driDrawable
->w
);
942 vmesa
->driDrawable
= driDrawPriv
;
943 if ( ! calculate_buffer_parameters( vmesa
) ) {
947 _mesa_make_current2(vmesa
->glCtx
,
948 (GLframebuffer
*)driDrawPriv
->driverPrivate
,
949 (GLframebuffer
*)driReadPriv
->driverPrivate
);
951 if (VIA_DEBUG
) fprintf(stderr
, "Context %d MakeCurrent\n", vmesa
->hHWContext
);
953 viaXMesaWindowMoved(vmesa
);
954 if (!vmesa
->glCtx
->Viewport
.Width
)
955 _mesa_set_viewport(vmesa
->glCtx
, 0, 0,
956 driDrawPriv
->w
, driDrawPriv
->h
);
959 _mesa_make_current(0,0);
963 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
968 void viaGetLock(viaContextPtr vmesa
, GLuint flags
)
970 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
971 __DRIscreenPrivate
*sPriv
= vmesa
->driScreen
;
972 drm_via_sarea_t
*sarea
= vmesa
->sarea
;
973 int me
= vmesa
->hHWContext
;
974 __DRIdrawablePrivate
*pdp
;
975 __DRIscreenPrivate
*psp
;
979 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
980 if (VIA_DEBUG
) fprintf(stderr
, "drmGetLock - in\n");
982 drmGetLock(vmesa
->driFd
, vmesa
->hHWContext
, flags
);
985 DRM_UNLOCK(psp
->fd
, &psp
->pSAREA
->lock
,
986 pdp
->driContextPriv
->hHWContext
);
987 DRM_SPINLOCK(&psp
->pSAREA
->drawable_lock
, psp
->drawLockID
);
988 __driUtilUpdateDrawableInfo(dPriv
);
989 DRM_SPINUNLOCK(&psp
->pSAREA
->drawable_lock
, psp
->drawLockID
);
990 DRM_LIGHT_LOCK(psp
->fd
, &psp
->pSAREA
->lock
,
991 pdp
->driContextPriv
->hHWContext
);
994 if (sarea
->ctxOwner
!= me
) {
995 vmesa
->uploadCliprects
= GL_TRUE
;
996 sarea
->ctxOwner
= me
;
999 viaXMesaWindowMoved(vmesa
);
1001 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1005 void viaLock(viaContextPtr vmesa
, GLuint flags
)
1007 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
1008 __DRIscreenPrivate
*sPriv
= vmesa
->driScreen
;
1010 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1012 /*=* John Sheng [2003.6.16] for xf43 */
1013 if(dPriv
->pStamp
== NULL
)
1014 dPriv
->pStamp
= &dPriv
->lastStamp
;
1016 if (*(dPriv
->pStamp
) != dPriv
->lastStamp
|| vmesa
->saam
) {
1018 scrn
= vmesa
->saam
& S_MASK
;
1020 DRM_SPINLOCK(&sPriv
->pSAREA
->drawable_lock
, sPriv
->drawLockID
);
1023 __driUtilUpdateDrawableInfo(dPriv
);
1025 DRI_VALIDATE_DRAWABLE_INFO_ONCE(dPriv
);
1027 viaXMesaWindowMoved(vmesa
);
1028 DRM_SPINUNLOCK(&sPriv
->pSAREA
->drawable_lock
, sPriv
->drawLockID
);
1031 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1036 void viaUnLock(viaContextPtr vmesa
, GLuint flags
)
1038 drm_via_sarea_t
*sarea
= vmesa
->sarea
;
1039 int me
= vmesa
->hHWContext
;
1042 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1043 if (VIA_DEBUG
) fprintf(stderr
, "sarea->ctxOwner = %d\n", sarea
->ctxOwner
);
1044 if (VIA_DEBUG
) fprintf(stderr
, "me = %d\n", me
);
1046 if (sarea
->ctxOwner
== me
) {
1047 sarea
->ctxOwner
= 0;
1050 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1055 viaSwapBuffers(__DRIdrawablePrivate
*drawablePrivate
)
1057 __DRIdrawablePrivate
*dPriv
= (__DRIdrawablePrivate
*)drawablePrivate
;
1059 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1061 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
1062 viaContextPtr vmesa
;
1065 vmesa
= (viaContextPtr
)dPriv
->driContextPriv
->driverPrivate
;
1067 if (ctx
->Visual
.doubleBufferMode
) {
1068 _mesa_notifySwapBuffers(ctx
);
1069 if (vmesa
->doPageFlip
) {
1073 viaCopyBuffer(dPriv
);
1077 VIA_FIREVERTICES(vmesa
);
1080 _mesa_problem(NULL
, "viaSwapBuffers: drawable has no context!\n");
1083 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);