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.
26 #ifdef GLX_DIRECT_RENDERING
28 #include <X11/Xlibint.h>
31 #include "savagecontext.h"
35 #include "simple_list.h"
37 #include "swrast/swrast.h"
38 #include "swrast_setup/swrast_setup.h"
40 #include "array_cache/acache.h"
42 #include "tnl/t_pipeline.h"
44 #include "drivers/common/driverfuncs.h"
47 #include "savagestate.h"
48 #include "savagetex.h"
49 #include "savagespan.h"
50 #include "savagetris.h"
51 #include "savageioctl.h"
52 #include "savage_bci.h"
54 #include "savage_dri.h"
56 #include "savagedma.h"
60 /* | DEBUG_ALWAYS_SYNC */
61 /* | DEBUG_VERBOSE_RING */
62 /* | DEBUG_VERBOSE_OUTREG */
63 /* | DEBUG_VERBOSE_MSG */
64 /* | DEBUG_NO_OUTRING */
65 /* | DEBUG_NO_OUTREG */
66 /* | DEBUG_VERBOSE_API */
67 /* | DEBUG_VERBOSE_2D */
68 /* | DEBUG_VERBOSE_DRI */
69 /* | DEBUG_VALIDATE_RING */
70 /* | DEBUG_VERBOSE_IOCTL */
75 /*For time caculating test*/
76 #if defined(DEBUG_TIME) && DEBUG_TIME
77 struct timeval tv_s
,tv_f
;
78 unsigned long time_sum
=0;
79 struct timeval tv_s1
,tv_f1
;
82 /* this is first function called in dirver*/
85 savageInitDriver(__DRIscreenPrivate
*sPriv
)
87 savageScreenPrivate
*savageScreen
;
88 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
91 /* Check the DRI version */
93 int major
, minor
, patch
;
94 if (XF86DRIQueryVersion(sPriv
->display
, &major
, &minor
, &patch
)) {
95 if (major
!= 4 || minor
< 0) {
96 __driUtilMessage("savage DRI driver expected DRI version 4.0.x but got version %d.%d.%d", major
, minor
, patch
);
102 /* Check that the DDX driver version is compatible */
103 if (sPriv
->ddxMajor
!= 1 ||
104 sPriv
->ddxMinor
< 0) {
105 __driUtilMessage("savage DRI driver expected DDX driver version 1.0.x but got version %d.%d.%d", sPriv
->ddxMajor
, sPriv
->ddxMinor
, sPriv
->ddxPatch
);
109 /* Check that the DRM driver version is compatible */
110 if (sPriv
->drmMajor
!= 1 ||
111 sPriv
->drmMinor
< 0) {
112 __driUtilMessage("savage DRI driver expected DRM driver version 1.1.x but got version %d.%d.%d", sPriv
->drmMajor
, sPriv
->drmMinor
, sPriv
->drmPatch
);
116 /* Allocate the private area */
117 savageScreen
= (savageScreenPrivate
*)Xmalloc(sizeof(savageScreenPrivate
));
121 savageScreen
->driScrnPriv
= sPriv
;
122 sPriv
->private = (void *)savageScreen
;
124 savageScreen
->chipset
=gDRIPriv
->chipset
;
125 savageScreen
->width
=gDRIPriv
->width
;
126 savageScreen
->height
=gDRIPriv
->height
;
127 savageScreen
->mem
=gDRIPriv
->mem
;
128 savageScreen
->cpp
=gDRIPriv
->cpp
;
129 savageScreen
->zpp
=gDRIPriv
->zpp
;
130 savageScreen
->frontPitch
=gDRIPriv
->frontPitch
;
131 savageScreen
->frontOffset
=gDRIPriv
->frontOffset
;
132 savageScreen
->frontBitmapDesc
= gDRIPriv
->frontBitmapDesc
;
134 if (gDRIPriv
->cpp
== 4)
135 savageScreen
->frontFormat
= DV_PF_8888
;
137 savageScreen
->frontFormat
= DV_PF_565
;
139 savageScreen
->backOffset
= gDRIPriv
->backOffset
;
140 savageScreen
->backBitmapDesc
= gDRIPriv
->backBitmapDesc
;
141 savageScreen
->depthOffset
=gDRIPriv
->depthOffset
;
142 savageScreen
->depthBitmapDesc
= gDRIPriv
->depthBitmapDesc
;
144 savageScreen
->backPitch
= gDRIPriv
->auxPitch
;
145 savageScreen
->backPitchBits
= gDRIPriv
->auxPitchBits
;
147 savageScreen
->textureOffset
[SAVAGE_CARD_HEAP
] =
148 gDRIPriv
->textureOffset
;
149 savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] =
150 gDRIPriv
->textureSize
;
151 savageScreen
->logTextureGranularity
[SAVAGE_CARD_HEAP
] =
152 gDRIPriv
->logTextureGranularity
;
154 savageScreen
->textureOffset
[SAVAGE_AGP_HEAP
] =
155 gDRIPriv
->agpTextures
.handle
;
156 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
] =
157 gDRIPriv
->agpTextures
.size
;
158 savageScreen
->logTextureGranularity
[SAVAGE_AGP_HEAP
] =
159 gDRIPriv
->logAgpTextureGranularity
;
161 savageScreen
->back
.handle
= gDRIPriv
->backbuffer
;
162 savageScreen
->back
.size
= gDRIPriv
->backbufferSize
;
163 savageScreen
->back
.map
=
164 (drmAddress
)(((unsigned int)sPriv
->pFB
)+gDRIPriv
->backOffset
);
166 savageScreen
->depth
.handle
= gDRIPriv
->depthbuffer
;
167 savageScreen
->depth
.size
= gDRIPriv
->depthbufferSize
;
169 savageScreen
->depth
.map
=
170 (drmAddress
)(((unsigned int)sPriv
->pFB
)+gDRIPriv
->depthOffset
);
172 savageScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
174 savageScreen
->texVirtual
[SAVAGE_CARD_HEAP
] =
175 (drmAddress
)(((unsigned int)sPriv
->pFB
)+gDRIPriv
->textureOffset
);
177 savageDDFastPathInit();
178 savageDDTrifuncInit();
184 /* Accessed by dlsym from dri_mesa_init.c
187 savageDestroyScreen(__DRIscreenPrivate
*sPriv
)
189 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
193 sPriv
->private = NULL
;
197 GLvisual
*XMesaCreateVisual(Display
*dpy
,
198 __DRIscreenPrivate
*driScrnPriv
,
199 const XVisualInfo
*visinfo
,
200 const __GLXvisualConfig
*config
)
202 /* Drivers may change the args to _mesa_create_visual() in order to
203 * setup special visuals.
205 return _mesa_create_visual( config
->rgba
,
206 config
->doubleBuffer
,
208 _mesa_bitcount(visinfo
->red_mask
),
209 _mesa_bitcount(visinfo
->green_mask
),
210 _mesa_bitcount(visinfo
->blue_mask
),
215 config
->accumRedSize
,
216 config
->accumGreenSize
,
217 config
->accumBlueSize
,
218 config
->accumAlphaSize
,
219 0 /* num samples */ );
225 savageCreateContext( const __GLcontextModes
*mesaVis
,
226 __DRIcontextPrivate
*driContextPriv
,
227 void *sharedContextPrivate
)
229 GLcontext
*ctx
, *shareCtx
;
230 savageContextPtr imesa
;
231 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
232 struct dd_function_table functions
;
233 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
234 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
235 drm_savage_sarea_t
*saPriv
=(drm_savage_sarea_t
*)(((char*)sPriv
->pSAREA
)+
236 savageScreen
->sarea_priv_offset
);
237 GLuint maxTextureSize
, minTextureSize
, maxTextureLevels
;
239 imesa
= (savageContextPtr
)Xcalloc(sizeof(savageContext
), 1);
244 /* Init default driver functions then plug in savage-specific texture
245 * functions that are needed as early as during context creation. */
246 _mesa_init_driver_functions( &functions
);
247 savageDDInitTextureFuncs( &functions
);
249 /* Allocate the Mesa context */
250 if (sharedContextPrivate
)
251 shareCtx
= ((savageContextPtr
) sharedContextPrivate
)->glCtx
;
254 ctx
= _mesa_create_context(mesaVis
, shareCtx
, &functions
, imesa
);
259 driContextPriv
->driverPrivate
= imesa
;
261 if (savageScreen
->chipset
>= S3_SAVAGE4
)
262 ctx
->Const
.MaxTextureUnits
= 2;
264 ctx
->Const
.MaxTextureUnits
= 1;
265 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
266 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
268 /* Set the maximum texture size small enough that we can guarentee
269 * that all texture units can bind a maximal texture and have them
272 if (savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] >
273 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
]) {
274 maxTextureSize
= savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
275 minTextureSize
= savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
277 maxTextureSize
= savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
278 minTextureSize
= savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
280 if (ctx
->Const
.MaxTextureUnits
== 2) {
281 /* How to distribute two maximum sized textures to two texture heaps?
282 * If the smaller heap is less then half the size of the bigger one
283 * then the maximum size is half the size of the bigger heap.
284 * Otherwise it's the size of the smaller heap. */
285 if (minTextureSize
< maxTextureSize
/ 2)
286 maxTextureSize
= maxTextureSize
/ 2;
288 maxTextureSize
= minTextureSize
;
290 for (maxTextureLevels
= 1; maxTextureLevels
<= 11; ++maxTextureLevels
) {
291 GLuint size
= 1 << maxTextureLevels
;
292 size
*= size
* 4; /* 4 bytes per texel */
293 size
*= 2; /* all mipmap levels together take roughly twice the size of
295 if (size
> maxTextureSize
)
298 ctx
->Const
.MaxTextureLevels
= maxTextureLevels
-1;
299 assert (ctx
->Const
.MaxTextureLevels
>= 6); /*spec requires at least 64x64*/
302 ctx
->Const
.MinLineWidth
= 1.0;
303 ctx
->Const
.MinLineWidthAA
= 1.0;
304 ctx
->Const
.MaxLineWidth
= 3.0;
305 ctx
->Const
.MaxLineWidthAA
= 3.0;
306 ctx
->Const
.LineWidthGranularity
= 1.0;
311 imesa
->hHWContext
= driContextPriv
->hHWContext
;
312 imesa
->driFd
= sPriv
->fd
;
313 imesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
315 imesa
->savageScreen
= savageScreen
;
316 imesa
->driScreen
= sPriv
;
317 imesa
->sarea
= saPriv
;
318 imesa
->glBuffer
= NULL
;
322 /*The shadow pointer*/
323 imesa
->shadowPointer
=
324 (volatile GLuint
*)((((GLuint
)(&saPriv
->shadow_status
)) + 31) & 0xffffffe0L
) ;
325 /* here we use eventTag1 because eventTag0 is used by HWXvMC*/
326 imesa
->eventTag1
= (volatile GLuint
*)(imesa
->shadowPointer
+ 6);
327 /* imesa->eventTag1=(volatile GLuint *)(imesa->MMIO_BASE+0x48c04);*/
328 imesa
->shadowCounter
= MAX_SHADOWCOUNTER
;
329 imesa
->shadowStatus
= GL_TRUE
;/*Will judge by 2d message */
331 if (drmMap(sPriv
->fd
,
332 gDRIPriv
->registers
.handle
,
333 gDRIPriv
->registers
.size
,
334 (drmAddress
*)&(gDRIPriv
->registers
.map
)) != 0)
337 sPriv
->private = NULL
;
341 if (drmMap(sPriv
->fd
,
342 gDRIPriv
->agpTextures
.handle
,
343 gDRIPriv
->agpTextures
.size
,
344 (drmAddress
*)&(gDRIPriv
->agpTextures
.map
)) != 0)
347 sPriv
->private = NULL
;
352 savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] =
353 (drmAddress
)(gDRIPriv
->agpTextures
.map
);
357 gDRIPriv
->BCIcmdBuf
.map
= (drmAddress
*)
358 ((unsigned int)gDRIPriv
->registers
.map
+0x00010000);
360 imesa
->MMIO_BASE
= (GLuint
)gDRIPriv
->registers
.map
;
361 imesa
->BCIBase
= (GLuint
)gDRIPriv
->BCIcmdBuf
.map
;
363 savageScreen
->aperture
.handle
= gDRIPriv
->aperture
.handle
;
364 savageScreen
->aperture
.size
= gDRIPriv
->aperture
.size
;
365 if (drmMap(sPriv
->fd
,
366 savageScreen
->aperture
.handle
,
367 savageScreen
->aperture
.size
,
368 (drmAddress
*)&savageScreen
->aperture
.map
) != 0)
371 sPriv
->private = NULL
;
381 imesa
->apertureBase
[i
] = ((GLuint
)savageScreen
->aperture
.map
+
388 volatile unsigned int * tmp
;
390 tmp
=(volatile unsigned int *)(imesa
->MMIO_BASE
+ 0x850C);
393 tmp
=(volatile unsigned int *)(imesa
->MMIO_BASE
+ 0x48C40);
396 tmp
=(volatile unsigned int *)(imesa
->MMIO_BASE
+ 0x48C44);
399 tmp
=(volatile unsigned int *)(imesa
->MMIO_BASE
+ 0x48C48);
405 imesa
->aperturePitch
= gDRIPriv
->aperturePitch
;
408 /* change texHeap initialize to support two kind of texture heap*/
409 /* here is some parts of initialization, others in InitDriver() */
411 imesa
->lastTexHeap
= savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] ? 2 : 1;
413 /*allocate texHeap for multi-tex*/
417 for(i
=0;i
<SAVAGE_NR_TEX_HEAPS
;i
++)
419 imesa
->texHeap
[i
] = mmInit( 0, savageScreen
->textureSize
[i
] );
420 make_empty_list(&imesa
->TexObjList
[i
]);
423 make_empty_list(&imesa
->SwappedOut
);
426 imesa
->hw_stencil
= GL_FALSE
;
428 imesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
430 imesa
->depth_scale
= (imesa
->savageScreen
->zpp
== 2) ?
431 (1.0F
/0x10000):(1.0F
/0x1000000);
433 /* Uninitialized vertex format. Force setting the vertex state in
436 imesa
->vertex_size
= 0;
440 imesa
->new_state
= ~0;
441 imesa
->RenderIndex
= ~0;
443 imesa
->lostContext
= GL_TRUE
;
444 imesa
->TextureMode
= ctx
->Texture
.Unit
[0].EnvMode
;
445 imesa
->CurrentTexObj
[0] = 0;
446 imesa
->CurrentTexObj
[1] = 0;
447 imesa
->texAge
[SAVAGE_CARD_HEAP
]=0;
448 imesa
->texAge
[SAVAGE_AGP_HEAP
]=0;
450 /* Initialize the software rasterizer and helper modules.
452 _swrast_CreateContext( ctx
);
453 _ac_CreateContext( ctx
);
454 _tnl_CreateContext( ctx
);
456 _swsetup_CreateContext( ctx
);
458 /* Install the customized pipeline:
461 _tnl_destroy_pipeline( ctx
);
462 _tnl_install_pipeline( ctx
, savage_pipeline
);
465 /* Configure swrast to match hardware characteristics:
467 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
468 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
469 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
470 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
472 ctx
->DriverCtx
= (void *) imesa
;
474 if (savageDMAInit(imesa
) == GL_FALSE
)
477 savageDDExtensionsInit( ctx
);
479 savageDDInitStateFuncs( ctx
);
480 savageDDInitSpanFuncs( ctx
);
481 savageDDInitDriverFuncs( ctx
);
482 savageDDInitIoctlFuncs( ctx
);
483 savageInitTriFuncs( ctx
);
485 savageDDInitState( imesa
);
487 driContextPriv
->driverPrivate
= (void *) imesa
;
493 savageDestroyContext(__DRIcontextPrivate
*driContextPriv
)
495 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
497 assert (imesa
); /* should never be NULL */
499 savageTextureObjectPtr next_t
, t
;
501 /* update for multi-tex*/
504 for(i
=0;i
<SAVAGE_NR_TEX_HEAPS
;i
++)
505 foreach_s (t
, next_t
, &(imesa
->TexObjList
[i
]))
506 savageDestroyTexObj(imesa
, t
);
508 foreach_s (t
, next_t
, &(imesa
->SwappedOut
))
509 savageDestroyTexObj(imesa
, t
);
510 /*free the dma buffer*/
511 savageDMAClose(imesa
);
512 _swsetup_DestroyContext(imesa
->glCtx
);
513 _tnl_DestroyContext( imesa
->glCtx
);
514 _ac_DestroyContext( imesa
->glCtx
);
515 _swrast_DestroyContext( imesa
->glCtx
);
517 /* free the Mesa context */
518 imesa
->glCtx
->DriverCtx
= NULL
;
519 _mesa_destroy_context(imesa
->glCtx
);
521 /* no longer use vertex_dma_buf*/
527 savageCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
528 __DRIdrawablePrivate
*driDrawPriv
,
529 const __GLcontextModes
*mesaVis
,
533 return GL_FALSE
; /* not implemented */
537 GLboolean swStencil
= mesaVis
->stencilBits
> 0 && mesaVis
->depthBits
!= 24;
539 GLboolean swStencil
= mesaVis
->stencilBits
> 0;
541 driDrawPriv
->driverPrivate
= (void *)
542 _mesa_create_framebuffer(mesaVis
,
543 GL_FALSE
, /* software depth buffer? */
545 mesaVis
->accumRedBits
> 0,
546 mesaVis
->alphaBits
> 0 );
548 return (driDrawPriv
->driverPrivate
!= NULL
);
553 savageDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
555 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
559 void XMesaSwapBuffers(__DRIdrawablePrivate
*driDrawPriv
)
561 /* XXX should do swap according to the buffer, not the context! */
562 savageContextPtr imesa
= savageCtx
;
564 FLUSH_VB( imesa
->glCtx
, "swap buffers" );
565 savageSwapBuffers(imesa
);
569 void savageXMesaSetFrontClipRects( savageContextPtr imesa
)
571 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
573 imesa
->numClipRects
= dPriv
->numClipRects
;
574 imesa
->pClipRects
= dPriv
->pClipRects
;
575 imesa
->dirty
|= SAVAGE_UPLOAD_CLIPRECTS
;
576 imesa
->drawX
= dPriv
->x
;
577 imesa
->drawY
= dPriv
->y
;
579 savageEmitDrawingRectangle( imesa
);
583 void savageXMesaSetBackClipRects( savageContextPtr imesa
)
585 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
587 if (dPriv
->numBackClipRects
== 0)
591 imesa
->numClipRects
= dPriv
->numClipRects
;
592 imesa
->pClipRects
= dPriv
->pClipRects
;
593 imesa
->drawX
= dPriv
->x
;
594 imesa
->drawY
= dPriv
->y
;
598 imesa
->numClipRects
= dPriv
->numBackClipRects
;
599 imesa
->pClipRects
= dPriv
->pBackClipRects
;
600 imesa
->drawX
= dPriv
->backX
;
601 imesa
->drawY
= dPriv
->backY
;
604 savageEmitDrawingRectangle( imesa
);
605 imesa
->dirty
|= SAVAGE_UPLOAD_CLIPRECTS
;
611 static void savageXMesaWindowMoved( savageContextPtr imesa
)
614 fprintf(stderr
, "savageXMesaWindowMoved\n\n");
616 switch (imesa
->glCtx
->Color
._DrawDestMask
) {
617 case DD_FRONT_LEFT_BIT
:
618 savageXMesaSetFrontClipRects( imesa
);
620 case DD_BACK_LEFT_BIT
:
621 savageXMesaSetBackClipRects( imesa
);
630 savageUnbindContext(__DRIcontextPrivate
*driContextPriv
)
632 savageContextPtr savage
= (savageContextPtr
) driContextPriv
->driverPrivate
;
640 savageOpenFullScreen(__DRIcontextPrivate
*driContextPriv
)
645 if (driContextPriv
) {
646 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
647 imesa
->IsFullScreen
= GL_TRUE
;
648 imesa
->backup_frontOffset
= imesa
->savageScreen
->frontOffset
;
649 imesa
->backup_backOffset
= imesa
->savageScreen
->backOffset
;
650 imesa
->backup_frontBitmapDesc
= imesa
->savageScreen
->frontBitmapDesc
;
651 imesa
->savageScreen
->frontBitmapDesc
= imesa
->savageScreen
->backBitmapDesc
;
652 imesa
->toggle
= TARGET_BACK
;
659 savageCloseFullScreen(__DRIcontextPrivate
*driContextPriv
)
662 if (driContextPriv
) {
663 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
665 imesa
->IsFullScreen
= GL_FALSE
;
666 imesa
->savageScreen
->frontOffset
= imesa
->backup_frontOffset
;
667 imesa
->savageScreen
->backOffset
= imesa
->backup_backOffset
;
668 imesa
->savageScreen
->frontBitmapDesc
= imesa
->backup_frontBitmapDesc
;
675 savageMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
676 __DRIdrawablePrivate
*driDrawPriv
,
677 __DRIdrawablePrivate
*driReadPriv
)
679 if (driContextPriv
) {
680 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
682 imesa
->driReadable
= driReadPriv
;
683 imesa
->driDrawable
= driDrawPriv
;
684 imesa
->mesa_drawable
= driDrawPriv
;
687 _mesa_make_current2(imesa
->glCtx
,
688 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
689 (GLframebuffer
*) driReadPriv
->driverPrivate
);
691 savageXMesaWindowMoved( imesa
);
693 if (!imesa
->glCtx
->Viewport
.Width
)
694 _mesa_set_viewport(imesa
->glCtx
, 0, 0,
695 driDrawPriv
->w
, driDrawPriv
->h
);
699 _mesa_make_current(NULL
, NULL
);
705 void savageGetLock( savageContextPtr imesa
, GLuint flags
)
707 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
708 __DRIscreenPrivate
*sPriv
= imesa
->driScreen
;
709 drm_savage_sarea_t
*sarea
= imesa
->sarea
;
710 int me
= imesa
->hHWContext
;
711 int stamp
= dPriv
->lastStamp
;
716 /* We know there has been contention.
718 drmGetLock(imesa
->driFd
, imesa
->hHWContext
, flags
);
721 /* Note contention for throttling hint
723 imesa
->any_contend
= 1;
725 /* If the window moved, may need to set a new cliprect now.
727 * NOTE: This releases and regains the hw lock, so all state
728 * checking must be done *after* this call:
730 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
735 /* If we lost context, need to dump all registers to hardware.
736 * Note that we don't care about 2d contexts, even if they perform
737 * accelerated commands, so the DRI locking in the X server is even
738 * more broken than usual.
740 if (sarea
->ctxOwner
!= me
) {
741 imesa
->dirty
|= (SAVAGE_UPLOAD_CTX
|
742 SAVAGE_UPLOAD_CLIPRECTS
|
745 imesa
->lostContext
= GL_TRUE
;
746 sarea
->ctxOwner
= me
;
749 /* Shared texture managment - if another client has played with
750 * texture space, figure out which if any of our textures have been
751 * ejected, and update our global LRU.
753 /*frank just for compiling,texAge,texList,AGP*/
755 for(heap
= 0 ;heap
< imesa
->lastTexHeap
; heap
++)
757 if (sarea
->texAge
[heap
] != imesa
->texAge
[heap
]) {
758 int sz
= 1 << (imesa
->savageScreen
->logTextureGranularity
[heap
]);
761 /* Have to go right round from the back to ensure stuff ends up
762 * LRU in our local list...
764 for (idx
= sarea
->texList
[heap
][SAVAGE_NR_TEX_REGIONS
].prev
;
765 idx
!= SAVAGE_NR_TEX_REGIONS
&& nr
< SAVAGE_NR_TEX_REGIONS
;
766 idx
= sarea
->texList
[heap
][idx
].prev
, nr
++)
768 if (sarea
->texList
[heap
][idx
].age
> imesa
->texAge
[heap
])
770 savageTexturesGone(imesa
, heap
,idx
* sz
, sz
,
771 sarea
->texList
[heap
][idx
].in_use
);
775 if (nr
== SAVAGE_NR_TEX_REGIONS
)
777 savageTexturesGone(imesa
, heap
, 0,
778 imesa
->savageScreen
->textureSize
[heap
], 0);
779 savageResetGlobalLRU( imesa
, heap
);
782 imesa
->dirty
|= SAVAGE_UPLOAD_TEX0IMAGE
;
783 imesa
->dirty
|= SAVAGE_UPLOAD_TEX1IMAGE
;
784 imesa
->texAge
[heap
] = sarea
->texAge
[heap
];
786 } /* end of for loop */
788 if (dPriv
->lastStamp
!= stamp
)
789 savageXMesaWindowMoved( imesa
);
797 static const struct __DriverAPIRec savageAPI
= {
801 savageDestroyContext
,
807 savageOpenFullScreen
,
808 savageCloseFullScreen
814 * This is the bootstrap function for the driver.
815 * The __driCreateScreen name is the symbol that libGL.so fetches.
816 * Return: pointer to a __DRIscreenPrivate.
818 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
819 int numConfigs
, __GLXvisualConfig
*config
)
821 __DRIscreenPrivate
*psp
;
822 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &savageAPI
);