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?
33 #include "main/glheader.h"
34 #include "main/context.h"
35 #include "main/formats.h"
36 #include "main/matrix.h"
37 #include "main/state.h"
38 #include "main/simple_list.h"
39 #include "main/extensions.h"
40 #include "main/framebuffer.h"
41 #include "main/renderbuffer.h"
43 #include "swrast/swrast.h"
44 #include "swrast_setup/swrast_setup.h"
48 #include "tnl/t_pipeline.h"
50 #include "drivers/common/driverfuncs.h"
52 #include "via_screen.h"
55 #include "via_state.h"
59 #include "via_ioctl.h"
63 #include "main/macros.h"
64 #include "drirenderbuffer.h"
66 #define need_GL_ARB_point_parameters
67 #define need_GL_EXT_fog_coord
68 #define need_GL_EXT_secondary_color
69 #include "main/remap_helper.h"
71 #define DRIVER_DATE "20060710"
79 * Return various strings for \c glGetString.
83 static const GLubyte
*viaGetString(GLcontext
*ctx
, GLenum name
)
85 static char buffer
[128];
91 return (GLubyte
*)"VIA Technology";
94 static const char * const chipset_names
[] = {
96 "CastleRock (CLE266)",
99 "UniChrome (PM8x0/CN400)",
101 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
102 unsigned id
= vmesa
->viaScreen
->deviceID
;
104 offset
= driGetRendererString( buffer
,
105 chipset_names
[(id
> VIA_PM800
) ? 0 : id
],
107 return (GLubyte
*)buffer
;
117 * Calculate a width that satisfies the hardware's alignment requirements.
118 * On the Unichrome hardware, each scanline must be aligned to a multiple of
121 * \param width Minimum buffer width, in pixels.
123 * \returns A pixel width that meets the alignment requirements.
125 static INLINE
unsigned
126 buffer_align( unsigned width
)
128 return (width
+ 0x0f) & ~0x0f;
133 viaDeleteRenderbuffer(struct gl_renderbuffer
*rb
)
135 /* Don't free() since we're contained in via_context struct. */
139 viaRenderbufferStorage(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
140 GLenum internalFormat
, GLuint width
, GLuint height
)
144 rb
->InternalFormat
= internalFormat
;
150 viaInitRenderbuffer(struct via_renderbuffer
*vrb
, GLenum format
,
151 __DRIdrawable
*dPriv
)
153 const GLuint name
= 0;
154 struct gl_renderbuffer
*rb
= & vrb
->Base
;
157 _mesa_init_renderbuffer(rb
, name
);
159 /* Make sure we're using a null-valued GetPointer routine */
160 assert(rb
->GetPointer(NULL
, rb
, 0, 0) == NULL
);
162 rb
->InternalFormat
= format
;
164 if (format
== GL_RGBA
) {
166 rb
->_BaseFormat
= GL_RGBA
;
167 rb
->Format
= MESA_FORMAT_ARGB8888
;
168 rb
->DataType
= GL_UNSIGNED_BYTE
;
170 else if (format
== GL_DEPTH_COMPONENT16
) {
172 rb
->_BaseFormat
= GL_DEPTH_COMPONENT
;
173 /* we always Get/Put 32-bit Z values */
174 rb
->Format
= MESA_FORMAT_Z16
;
175 rb
->DataType
= GL_UNSIGNED_INT
;
177 else if (format
== GL_DEPTH_COMPONENT24
) {
179 rb
->_BaseFormat
= GL_DEPTH_COMPONENT
;
180 /* we always Get/Put 32-bit Z values */
181 rb
->Format
= MESA_FORMAT_Z32
;
182 rb
->DataType
= GL_UNSIGNED_INT
;
186 ASSERT(format
== GL_STENCIL_INDEX8_EXT
);
187 rb
->_BaseFormat
= GL_STENCIL_INDEX
;
188 rb
->Format
= MESA_FORMAT_S8
;
189 rb
->DataType
= GL_UNSIGNED_BYTE
;
192 rb
->Delete
= viaDeleteRenderbuffer
;
193 rb
->AllocStorage
= viaRenderbufferStorage
;
198 * Calculate the framebuffer parameters for all buffers (front, back, depth,
199 * and stencil) associated with the specified context.
202 * This function also calls \c AllocateBuffer to actually allocate the
208 calculate_buffer_parameters(struct via_context
*vmesa
,
209 struct gl_framebuffer
*fb
,
210 __DRIdrawable
*dPriv
)
212 const unsigned shift
= vmesa
->viaScreen
->bitsPerPixel
/ 16;
213 const unsigned extra
= 32;
217 /* Normally, the renderbuffer would be added to the framebuffer just once
218 * when the framebuffer was created. The VIA driver is a bit funny
219 * though in that the front/back/depth renderbuffers are in the per-context
221 * That should be fixed someday.
224 if (!vmesa
->front
.Base
.InternalFormat
) {
225 /* do one-time init for the renderbuffers */
226 viaInitRenderbuffer(&vmesa
->front
, GL_RGBA
, dPriv
);
227 viaSetSpanFunctions(&vmesa
->front
, &fb
->Visual
);
228 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &vmesa
->front
.Base
);
230 if (fb
->Visual
.doubleBufferMode
) {
231 viaInitRenderbuffer(&vmesa
->back
, GL_RGBA
, dPriv
);
232 viaSetSpanFunctions(&vmesa
->back
, &fb
->Visual
);
233 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &vmesa
->back
.Base
);
236 if (vmesa
->glCtx
->Visual
.depthBits
> 0) {
237 viaInitRenderbuffer(&vmesa
->depth
,
238 (vmesa
->glCtx
->Visual
.depthBits
== 16
239 ? GL_DEPTH_COMPONENT16
: GL_DEPTH_COMPONENT24
),
241 viaSetSpanFunctions(&vmesa
->depth
, &fb
->Visual
);
242 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &vmesa
->depth
.Base
);
245 if (vmesa
->glCtx
->Visual
.stencilBits
> 0) {
246 viaInitRenderbuffer(&vmesa
->stencil
, GL_STENCIL_INDEX8_EXT
,
248 viaSetSpanFunctions(&vmesa
->stencil
, &fb
->Visual
);
249 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &vmesa
->stencil
.Base
);
253 assert(vmesa
->front
.Base
.InternalFormat
);
254 assert(vmesa
->front
.Base
.AllocStorage
);
255 if (fb
->Visual
.doubleBufferMode
) {
256 assert(vmesa
->back
.Base
.AllocStorage
);
258 if (fb
->Visual
.depthBits
) {
259 assert(vmesa
->depth
.Base
.AllocStorage
);
263 /* Allocate front-buffer */
264 if (vmesa
->drawType
== GLX_PBUFFER_BIT
) {
265 w
= vmesa
->driDrawable
->w
;
266 h
= vmesa
->driDrawable
->h
;
268 vmesa
->front
.bpp
= vmesa
->viaScreen
->bitsPerPixel
;
269 vmesa
->front
.pitch
= buffer_align( w
) << shift
; /* bytes, not pixels */
270 vmesa
->front
.size
= vmesa
->front
.pitch
* h
;
272 if (vmesa
->front
.map
)
273 via_free_draw_buffer(vmesa
, &vmesa
->front
);
274 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->front
))
278 w
= vmesa
->viaScreen
->width
;
279 h
= vmesa
->viaScreen
->height
;
281 vmesa
->front
.bpp
= vmesa
->viaScreen
->bitsPerPixel
;
282 vmesa
->front
.pitch
= buffer_align( w
) << shift
; /* bytes, not pixels */
283 vmesa
->front
.size
= vmesa
->front
.pitch
* h
;
284 if (getenv("ALTERNATE_SCREEN"))
285 vmesa
->front
.offset
= vmesa
->front
.size
;
287 vmesa
->front
.offset
= 0;
288 vmesa
->front
.map
= (char *) vmesa
->driScreen
->pFB
;
292 /* Allocate back-buffer */
293 if (vmesa
->hasBack
) {
294 vmesa
->back
.bpp
= vmesa
->viaScreen
->bitsPerPixel
;
295 vmesa
->back
.pitch
= (buffer_align( vmesa
->driDrawable
->w
) << shift
);
296 vmesa
->back
.pitch
+= extra
;
297 vmesa
->back
.pitch
= MIN2(vmesa
->back
.pitch
, vmesa
->front
.pitch
);
298 vmesa
->back
.size
= vmesa
->back
.pitch
* vmesa
->driDrawable
->h
;
300 via_free_draw_buffer(vmesa
, &vmesa
->back
);
301 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->back
))
306 via_free_draw_buffer(vmesa
, &vmesa
->back
);
307 (void) memset( &vmesa
->back
, 0, sizeof( vmesa
->back
) );
311 /* Allocate depth-buffer */
312 if ( vmesa
->hasStencil
|| vmesa
->hasDepth
) {
313 vmesa
->depth
.bpp
= vmesa
->depthBits
;
314 if (vmesa
->depth
.bpp
== 24)
315 vmesa
->depth
.bpp
= 32;
317 vmesa
->depth
.pitch
= (buffer_align( vmesa
->driDrawable
->w
) *
318 (vmesa
->depth
.bpp
/8)) + extra
;
319 vmesa
->depth
.size
= vmesa
->depth
.pitch
* vmesa
->driDrawable
->h
;
321 if (vmesa
->depth
.map
)
322 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
323 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->depth
)) {
328 if (vmesa
->depth
.map
)
329 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
330 (void) memset( & vmesa
->depth
, 0, sizeof( vmesa
->depth
) );
333 /* stencil buffer is same as depth buffer */
334 vmesa
->stencil
.handle
= vmesa
->depth
.handle
;
335 vmesa
->stencil
.size
= vmesa
->depth
.size
;
336 vmesa
->stencil
.offset
= vmesa
->depth
.offset
;
337 vmesa
->stencil
.index
= vmesa
->depth
.index
;
338 vmesa
->stencil
.pitch
= vmesa
->depth
.pitch
;
339 vmesa
->stencil
.bpp
= vmesa
->depth
.bpp
;
340 vmesa
->stencil
.map
= vmesa
->depth
.map
;
341 vmesa
->stencil
.orig
= vmesa
->depth
.orig
;
342 vmesa
->stencil
.origMap
= vmesa
->depth
.origMap
;
344 if( vmesa
->viaScreen
->width
== vmesa
->driDrawable
->w
&&
345 vmesa
->viaScreen
->height
== vmesa
->driDrawable
->h
) {
346 vmesa
->doPageFlip
= vmesa
->allowPageFlip
;
347 if (vmesa
->hasBack
) {
348 assert(vmesa
->back
.pitch
== vmesa
->front
.pitch
);
352 vmesa
->doPageFlip
= GL_FALSE
;
358 void viaReAllocateBuffers(GLcontext
*ctx
, GLframebuffer
*drawbuffer
,
359 GLuint width
, GLuint height
)
361 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
363 calculate_buffer_parameters(vmesa
, drawbuffer
, vmesa
->driDrawable
);
365 _mesa_resize_framebuffer(ctx
, drawbuffer
, width
, height
);
368 /* Extension strings exported by the Unichrome driver.
370 static const struct dri_extension card_extensions
[] =
372 { "GL_ARB_multitexture", NULL
},
373 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
374 { "GL_ARB_texture_env_add", NULL
},
375 { "GL_ARB_texture_env_combine", NULL
},
376 /* { "GL_ARB_texture_env_dot3", NULL }, */
377 { "GL_ARB_texture_mirrored_repeat", NULL
},
378 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
379 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
380 { "GL_EXT_stencil_wrap", NULL
},
381 { "GL_EXT_texture_env_combine", NULL
},
382 /* { "GL_EXT_texture_env_dot3", NULL }, */
383 { "GL_EXT_texture_lod_bias", NULL
},
384 { "GL_NV_blend_square", NULL
},
388 extern const struct tnl_pipeline_stage _via_fastrender_stage
;
389 extern const struct tnl_pipeline_stage _via_render_stage
;
391 static const struct tnl_pipeline_stage
*via_pipeline
[] = {
392 &_tnl_vertex_transform_stage
,
393 &_tnl_normal_transform_stage
,
394 &_tnl_lighting_stage
,
395 &_tnl_fog_coordinate_stage
,
397 &_tnl_texture_transform_stage
,
398 /* REMOVE: point attenuation stage */
400 &_via_fastrender_stage
, /* ADD: unclipped rastersetup-to-dma */
407 static const struct dri_debug_control debug_control
[] =
409 { "fall", DEBUG_FALLBACKS
},
410 { "tex", DEBUG_TEXTURE
},
411 { "ioctl", DEBUG_IOCTL
},
412 { "prim", DEBUG_PRIMS
},
413 { "vert", DEBUG_VERTS
},
414 { "state", DEBUG_STATE
},
415 { "verb", DEBUG_VERBOSE
},
416 { "dri", DEBUG_DRI
},
417 { "dma", DEBUG_DMA
},
418 { "san", DEBUG_SANITY
},
419 { "sync", DEBUG_SYNC
},
420 { "sleep", DEBUG_SLEEP
},
421 { "pix", DEBUG_PIXEL
},
428 AllocateDmaBuffer(struct via_context
*vmesa
)
431 via_free_dma_buffer(vmesa
);
433 if (!via_alloc_dma_buffer(vmesa
))
437 vmesa
->dmaCliprectAddr
= ~0;
442 FreeBuffer(struct via_context
*vmesa
)
444 if (vmesa
->front
.map
&& vmesa
->drawType
== GLX_PBUFFER_BIT
)
445 via_free_draw_buffer(vmesa
, &vmesa
->front
);
448 via_free_draw_buffer(vmesa
, &vmesa
->back
);
450 if (vmesa
->depth
.map
)
451 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
453 if (vmesa
->breadcrumb
.map
)
454 via_free_draw_buffer(vmesa
, &vmesa
->breadcrumb
);
457 via_free_dma_buffer(vmesa
);
462 viaCreateContext(const __GLcontextModes
*visual
,
463 __DRIcontext
*driContextPriv
,
464 void *sharedContextPrivate
)
466 GLcontext
*ctx
, *shareCtx
;
467 struct via_context
*vmesa
;
468 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
469 viaScreenPrivate
*viaScreen
= (viaScreenPrivate
*)sPriv
->private;
470 drm_via_sarea_t
*saPriv
= (drm_via_sarea_t
*)
471 (((GLubyte
*)sPriv
->pSAREA
) + viaScreen
->sareaPrivOffset
);
472 struct dd_function_table functions
;
474 /* Allocate via context */
475 vmesa
= (struct via_context
*) CALLOC_STRUCT(via_context
);
480 /* Parse configuration files.
482 driParseConfigFiles (&vmesa
->optionCache
, &viaScreen
->optionCache
,
483 sPriv
->myNum
, "unichrome");
485 /* pick back buffer */
486 vmesa
->hasBack
= visual
->doubleBufferMode
;
488 switch(visual
->depthBits
) {
490 vmesa
->hasDepth
= GL_FALSE
;
491 vmesa
->depthBits
= 0;
492 vmesa
->depth_max
= 1.0;
495 vmesa
->hasDepth
= GL_TRUE
;
496 vmesa
->depthBits
= visual
->depthBits
;
497 vmesa
->have_hw_stencil
= GL_FALSE
;
498 vmesa
->depth_max
= (GLfloat
)0xffff;
499 vmesa
->depth_clear_mask
= 0xf << 28;
500 vmesa
->ClearDepth
= 0xffff;
501 vmesa
->polygon_offset_scale
= 1.0 / vmesa
->depth_max
;
504 vmesa
->hasDepth
= GL_TRUE
;
505 vmesa
->depthBits
= visual
->depthBits
;
506 vmesa
->depth_max
= (GLfloat
) 0xffffff;
507 vmesa
->depth_clear_mask
= 0xe << 28;
508 vmesa
->ClearDepth
= 0xffffff00;
510 assert(visual
->haveStencilBuffer
);
511 assert(visual
->stencilBits
== 8);
513 vmesa
->have_hw_stencil
= GL_TRUE
;
514 vmesa
->stencilBits
= visual
->stencilBits
;
515 vmesa
->stencil_clear_mask
= 0x1 << 28;
516 vmesa
->polygon_offset_scale
= 2.0 / vmesa
->depth_max
;
519 vmesa
->hasDepth
= GL_TRUE
;
520 vmesa
->depthBits
= visual
->depthBits
;
521 assert(!visual
->haveStencilBuffer
);
522 vmesa
->have_hw_stencil
= GL_FALSE
;
523 vmesa
->depth_max
= (GLfloat
)0xffffffff;
524 vmesa
->depth_clear_mask
= 0xf << 28;
525 vmesa
->ClearDepth
= 0xffffffff;
526 vmesa
->polygon_offset_scale
= 2.0 / vmesa
->depth_max
;
533 make_empty_list(&vmesa
->freed_tex_buffers
);
534 make_empty_list(&vmesa
->tex_image_list
[VIA_MEM_VIDEO
]);
535 make_empty_list(&vmesa
->tex_image_list
[VIA_MEM_AGP
]);
536 make_empty_list(&vmesa
->tex_image_list
[VIA_MEM_SYSTEM
]);
538 _mesa_init_driver_functions(&functions
);
539 viaInitTextureFuncs(&functions
);
541 /* Allocate the Mesa context */
542 if (sharedContextPrivate
)
543 shareCtx
= ((struct via_context
*) sharedContextPrivate
)->glCtx
;
547 vmesa
->glCtx
= _mesa_create_context(visual
, shareCtx
, &functions
,
550 vmesa
->shareCtx
= shareCtx
;
556 driContextPriv
->driverPrivate
= vmesa
;
560 if (driQueryOptionb(&vmesa
->optionCache
, "excess_mipmap"))
561 ctx
->Const
.MaxTextureLevels
= 11;
563 ctx
->Const
.MaxTextureLevels
= 10;
565 ctx
->Const
.MaxTextureUnits
= 2;
566 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
567 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
569 ctx
->Const
.MinLineWidth
= 1.0;
570 ctx
->Const
.MinLineWidthAA
= 1.0;
571 ctx
->Const
.MaxLineWidth
= 1.0;
572 ctx
->Const
.MaxLineWidthAA
= 1.0;
573 ctx
->Const
.LineWidthGranularity
= 1.0;
575 ctx
->Const
.MinPointSize
= 1.0;
576 ctx
->Const
.MinPointSizeAA
= 1.0;
577 ctx
->Const
.MaxPointSize
= 1.0;
578 ctx
->Const
.MaxPointSizeAA
= 1.0;
579 ctx
->Const
.PointSizeGranularity
= 1.0;
581 ctx
->Const
.MaxDrawBuffers
= 1;
583 ctx
->Driver
.GetString
= viaGetString
;
585 ctx
->DriverCtx
= (void *)vmesa
;
588 /* Initialize the software rasterizer and helper modules.
590 _swrast_CreateContext(ctx
);
591 _vbo_CreateContext(ctx
);
592 _tnl_CreateContext(ctx
);
593 _swsetup_CreateContext(ctx
);
595 /* Install the customized pipeline:
597 _tnl_destroy_pipeline(ctx
);
598 _tnl_install_pipeline(ctx
, via_pipeline
);
600 /* Configure swrast and T&L to match hardware characteristics:
602 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
603 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
604 _tnl_allow_pixel_fog(ctx
, GL_FALSE
);
605 _tnl_allow_vertex_fog(ctx
, GL_TRUE
);
607 vmesa
->hHWContext
= driContextPriv
->hHWContext
;
608 vmesa
->driFd
= sPriv
->fd
;
609 vmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
611 vmesa
->viaScreen
= viaScreen
;
612 vmesa
->driScreen
= sPriv
;
613 vmesa
->sarea
= saPriv
;
615 vmesa
->renderIndex
= ~0;
616 vmesa
->setupIndex
= ~0;
617 vmesa
->hwPrimitive
= GL_POLYGON
+1;
619 /* KW: Hardwire this. Was previously set bogusly in
620 * viaCreateBuffer. Needs work before PBUFFER can be used:
622 vmesa
->drawType
= GLX_WINDOW_BIT
;
625 _math_matrix_ctr(&vmesa
->ViewportMatrix
);
627 /* Do this early, before VIA_FLUSH_DMA can be called:
629 if (!AllocateDmaBuffer(vmesa
)) {
630 fprintf(stderr
,"AllocateDmaBuffer fail\n");
636 /* Allocate a small piece of fb memory for synchronization:
638 vmesa
->breadcrumb
.bpp
= 32;
639 vmesa
->breadcrumb
.pitch
= buffer_align( 64 ) << 2;
640 vmesa
->breadcrumb
.size
= vmesa
->breadcrumb
.pitch
;
642 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->breadcrumb
)) {
643 fprintf(stderr
,"AllocateDmaBuffer fail\n");
649 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
650 viaInitStateFuncs(ctx
);
651 viaInitTriFuncs(ctx
);
652 viaInitSpanFuncs(ctx
);
653 viaInitIoctlFuncs(ctx
);
656 if (getenv("VIA_DEBUG"))
657 VIA_DEBUG
= driParseDebugString( getenv( "VIA_DEBUG" ),
660 if (getenv("VIA_NO_RAST") ||
661 driQueryOptionb(&vmesa
->optionCache
, "no_rast"))
662 FALLBACK(vmesa
, VIA_FALLBACK_USER_DISABLE
, 1);
664 if (getenv("VIA_PAGEFLIP"))
665 vmesa
->allowPageFlip
= 1;
667 (*sPriv
->systemTime
->getUST
)( &vmesa
->swap_ust
);
670 vmesa
->regMMIOBase
= (GLuint
*)((unsigned long)viaScreen
->reg
);
671 vmesa
->pnGEMode
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x4);
672 vmesa
->regEngineStatus
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x400);
673 vmesa
->regTranSet
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x43C);
674 vmesa
->regTranSpace
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x440);
675 vmesa
->agpBase
= viaScreen
->agpBase
;
682 viaDestroyContext(__DRIcontext
*driContextPriv
)
684 GET_CURRENT_CONTEXT(ctx
);
685 struct via_context
*vmesa
=
686 (struct via_context
*)driContextPriv
->driverPrivate
;
687 struct via_context
*current
= ctx
? VIA_CONTEXT(ctx
) : NULL
;
689 assert(vmesa
); /* should never be null */
691 if (vmesa
->driDrawable
) {
692 viaWaitIdle(vmesa
, GL_FALSE
);
694 if (vmesa
->doPageFlip
) {
695 LOCK_HARDWARE(vmesa
);
696 if (vmesa
->pfCurrentOffset
!= 0) {
697 fprintf(stderr
, "%s - reset pf\n", __FUNCTION__
);
698 viaResetPageFlippingLocked(vmesa
);
700 UNLOCK_HARDWARE(vmesa
);
704 /* check if we're deleting the currently bound context */
705 if (vmesa
== current
) {
706 VIA_FLUSH_DMA(vmesa
);
707 _mesa_make_current(NULL
, NULL
, NULL
);
710 _swsetup_DestroyContext(vmesa
->glCtx
);
711 _tnl_DestroyContext(vmesa
->glCtx
);
712 _vbo_DestroyContext(vmesa
->glCtx
);
713 _swrast_DestroyContext(vmesa
->glCtx
);
714 /* free the Mesa context */
715 _mesa_destroy_context(vmesa
->glCtx
);
716 /* release our data */
719 assert (is_empty_list(&vmesa
->tex_image_list
[VIA_MEM_AGP
]));
720 assert (is_empty_list(&vmesa
->tex_image_list
[VIA_MEM_VIDEO
]));
721 assert (is_empty_list(&vmesa
->tex_image_list
[VIA_MEM_SYSTEM
]));
722 assert (is_empty_list(&vmesa
->freed_tex_buffers
));
724 driDestroyOptionCache(&vmesa
->optionCache
);
730 void viaXMesaWindowMoved(struct via_context
*vmesa
)
732 __DRIdrawable
*const drawable
= vmesa
->driDrawable
;
733 __DRIdrawable
*const readable
= vmesa
->driReadable
;
734 struct via_renderbuffer
* draw_buffer
;
735 struct via_renderbuffer
* read_buffer
;
736 GLuint bytePerPixel
= vmesa
->viaScreen
->bitsPerPixel
>> 3;
741 draw_buffer
= (struct via_renderbuffer
*) drawable
->driverPrivate
;
742 read_buffer
= (struct via_renderbuffer
*) readable
->driverPrivate
;
744 switch (vmesa
->glCtx
->DrawBuffer
->_ColorDrawBufferIndexes
[0]) {
745 case BUFFER_BACK_LEFT
:
746 if (drawable
->numBackClipRects
== 0) {
747 vmesa
->numClipRects
= drawable
->numClipRects
;
748 vmesa
->pClipRects
= drawable
->pClipRects
;
751 vmesa
->numClipRects
= drawable
->numBackClipRects
;
752 vmesa
->pClipRects
= drawable
->pBackClipRects
;
755 case BUFFER_FRONT_LEFT
:
756 vmesa
->numClipRects
= drawable
->numClipRects
;
757 vmesa
->pClipRects
= drawable
->pClipRects
;
760 vmesa
->numClipRects
= 0;
764 if ((draw_buffer
->drawW
!= drawable
->w
)
765 || (draw_buffer
->drawH
!= drawable
->h
)) {
766 calculate_buffer_parameters(vmesa
, vmesa
->glCtx
->DrawBuffer
,
770 draw_buffer
->drawX
= drawable
->x
;
771 draw_buffer
->drawY
= drawable
->y
;
772 draw_buffer
->drawW
= drawable
->w
;
773 draw_buffer
->drawH
= drawable
->h
;
775 if (drawable
!= readable
) {
776 if ((read_buffer
->drawW
!= readable
->w
)
777 || (read_buffer
->drawH
!= readable
->h
)) {
778 calculate_buffer_parameters(vmesa
, vmesa
->glCtx
->ReadBuffer
,
782 read_buffer
->drawX
= readable
->x
;
783 read_buffer
->drawY
= readable
->y
;
784 read_buffer
->drawW
= readable
->w
;
785 read_buffer
->drawH
= readable
->h
;
788 vmesa
->front
.orig
= (vmesa
->front
.offset
+
789 draw_buffer
->drawY
* vmesa
->front
.pitch
+
790 draw_buffer
->drawX
* bytePerPixel
);
792 vmesa
->front
.origMap
= (vmesa
->front
.map
+
793 draw_buffer
->drawY
* vmesa
->front
.pitch
+
794 draw_buffer
->drawX
* bytePerPixel
);
796 vmesa
->back
.orig
= (vmesa
->back
.offset
+
797 draw_buffer
->drawY
* vmesa
->back
.pitch
+
798 draw_buffer
->drawX
* bytePerPixel
);
800 vmesa
->back
.origMap
= (vmesa
->back
.map
+
801 draw_buffer
->drawY
* vmesa
->back
.pitch
+
802 draw_buffer
->drawX
* bytePerPixel
);
804 vmesa
->depth
.orig
= (vmesa
->depth
.offset
+
805 draw_buffer
->drawY
* vmesa
->depth
.pitch
+
806 draw_buffer
->drawX
* bytePerPixel
);
808 vmesa
->depth
.origMap
= (vmesa
->depth
.map
+
809 draw_buffer
->drawY
* vmesa
->depth
.pitch
+
810 draw_buffer
->drawX
* bytePerPixel
);
812 viaCalcViewport(vmesa
->glCtx
);
816 viaUnbindContext(__DRIcontext
*driContextPriv
)
822 viaMakeCurrent(__DRIcontext
*driContextPriv
,
823 __DRIdrawable
*driDrawPriv
,
824 __DRIdrawable
*driReadPriv
)
826 if (VIA_DEBUG
& DEBUG_DRI
) {
827 fprintf(stderr
, "driContextPriv = %016lx\n", (unsigned long)driContextPriv
);
828 fprintf(stderr
, "driDrawPriv = %016lx\n", (unsigned long)driDrawPriv
);
829 fprintf(stderr
, "driReadPriv = %016lx\n", (unsigned long)driReadPriv
);
832 if (driContextPriv
) {
833 struct via_context
*vmesa
=
834 (struct via_context
*)driContextPriv
->driverPrivate
;
835 GLcontext
*ctx
= vmesa
->glCtx
;
836 struct gl_framebuffer
*drawBuffer
, *readBuffer
;
838 drawBuffer
= (GLframebuffer
*)driDrawPriv
->driverPrivate
;
839 readBuffer
= (GLframebuffer
*)driReadPriv
->driverPrivate
;
841 if ((vmesa
->driDrawable
!= driDrawPriv
)
842 || (vmesa
->driReadable
!= driReadPriv
)) {
843 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
844 driDrawPriv
->vblFlags
=
845 vmesa
->viaScreen
->irqEnabled
?
846 driGetDefaultVBlankFlags(&vmesa
->optionCache
) :
849 driDrawableInitVBlank(driDrawPriv
);
852 vmesa
->driDrawable
= driDrawPriv
;
853 vmesa
->driReadable
= driReadPriv
;
855 if ((drawBuffer
->Width
!= driDrawPriv
->w
)
856 || (drawBuffer
->Height
!= driDrawPriv
->h
)) {
857 _mesa_resize_framebuffer(ctx
, drawBuffer
,
858 driDrawPriv
->w
, driDrawPriv
->h
);
859 drawBuffer
->Initialized
= GL_TRUE
;
862 if (!calculate_buffer_parameters(vmesa
, drawBuffer
, driDrawPriv
)) {
866 if (driDrawPriv
!= driReadPriv
) {
867 if ((readBuffer
->Width
!= driReadPriv
->w
)
868 || (readBuffer
->Height
!= driReadPriv
->h
)) {
869 _mesa_resize_framebuffer(ctx
, readBuffer
,
870 driReadPriv
->w
, driReadPriv
->h
);
871 readBuffer
->Initialized
= GL_TRUE
;
874 if (!calculate_buffer_parameters(vmesa
, readBuffer
, driReadPriv
)) {
880 _mesa_make_current(vmesa
->glCtx
, drawBuffer
, readBuffer
);
882 ctx
->Driver
.DrawBuffer( ctx
, ctx
->Color
.DrawBuffer
[0] );
884 viaXMesaWindowMoved(vmesa
);
885 ctx
->Driver
.Scissor(vmesa
->glCtx
,
886 vmesa
->glCtx
->Scissor
.X
,
887 vmesa
->glCtx
->Scissor
.Y
,
888 vmesa
->glCtx
->Scissor
.Width
,
889 vmesa
->glCtx
->Scissor
.Height
);
892 _mesa_make_current(NULL
, NULL
, NULL
);
898 void viaGetLock(struct via_context
*vmesa
, GLuint flags
)
900 __DRIdrawable
*dPriv
= vmesa
->driDrawable
;
901 __DRIscreen
*sPriv
= vmesa
->driScreen
;
903 drmGetLock(vmesa
->driFd
, vmesa
->hHWContext
, flags
);
905 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
906 if (dPriv
!= vmesa
->driReadable
) {
907 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, vmesa
->driReadable
);
910 if (vmesa
->sarea
->ctxOwner
!= vmesa
->hHWContext
) {
911 vmesa
->sarea
->ctxOwner
= vmesa
->hHWContext
;
912 vmesa
->newEmitState
= ~0;
915 if (vmesa
->lastStamp
!= dPriv
->lastStamp
) {
916 viaXMesaWindowMoved(vmesa
);
917 driUpdateFramebufferSize(vmesa
->glCtx
, dPriv
);
918 vmesa
->newEmitState
= ~0;
919 vmesa
->lastStamp
= dPriv
->lastStamp
;
922 if (vmesa
->doPageFlip
&&
923 vmesa
->pfCurrentOffset
!= vmesa
->sarea
->pfCurrentOffset
) {
924 fprintf(stderr
, "%s - reset pf\n", __FUNCTION__
);
925 viaResetPageFlippingLocked(vmesa
);
931 viaSwapBuffers(__DRIdrawable
*drawablePrivate
)
933 __DRIdrawable
*dPriv
= (__DRIdrawable
*)drawablePrivate
;
936 dPriv
->driContextPriv
&&
937 dPriv
->driContextPriv
->driverPrivate
) {
938 struct via_context
*vmesa
=
939 (struct via_context
*)dPriv
->driContextPriv
->driverPrivate
;
940 GLcontext
*ctx
= vmesa
->glCtx
;
942 _mesa_notifySwapBuffers(ctx
);
944 if (ctx
->Visual
.doubleBufferMode
) {
945 if (vmesa
->doPageFlip
) {
949 viaCopyBuffer(dPriv
);
953 VIA_FLUSH_DMA(vmesa
);
956 _mesa_problem(NULL
, "viaSwapBuffers: drawable has no context!\n");