Implemented support for software-based AUX color buffers.
[mesa.git] / src / mesa / drivers / dri / savage / savage_xmesa.c
1 /*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #ifdef GLX_DIRECT_RENDERING
27
28 #include <X11/Xlibint.h>
29 #include <stdio.h>
30
31 #include "savagecontext.h"
32 #include "context.h"
33 #include "matrix.h"
34
35 #include "simple_list.h"
36
37 #include "swrast/swrast.h"
38 #include "swrast_setup/swrast_setup.h"
39 #include "tnl/tnl.h"
40 #include "array_cache/acache.h"
41
42 #include "tnl/t_pipeline.h"
43
44 #include "drivers/common/driverfuncs.h"
45
46 #include "savagedd.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"
53
54 #include "savage_dri.h"
55
56 #include "savagedma.h"
57
58 #ifndef SAVAGE_DEBUG
59 int SAVAGE_DEBUG = (0
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 */
71 );
72 #endif
73
74
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;
80 #endif
81
82 /* this is first function called in dirver*/
83
84 static GLboolean
85 savageInitDriver(__DRIscreenPrivate *sPriv)
86 {
87 savageScreenPrivate *savageScreen;
88 SAVAGEDRIPtr gDRIPriv = (SAVAGEDRIPtr)sPriv->pDevPriv;
89
90
91 /* Check the DRI version */
92 {
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);
97 return GL_FALSE;
98 }
99 }
100 }
101
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);
106 return GL_FALSE;
107 }
108
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);
113 return GL_FALSE;
114 }
115
116 /* Allocate the private area */
117 savageScreen = (savageScreenPrivate *)Xmalloc(sizeof(savageScreenPrivate));
118 if (!savageScreen)
119 return GL_FALSE;
120
121 savageScreen->driScrnPriv = sPriv;
122 sPriv->private = (void *)savageScreen;
123
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;
133
134 if (gDRIPriv->cpp == 4)
135 savageScreen->frontFormat = DV_PF_8888;
136 else
137 savageScreen->frontFormat = DV_PF_565;
138
139 savageScreen->backOffset = gDRIPriv->backOffset;
140 savageScreen->backBitmapDesc = gDRIPriv->backBitmapDesc;
141 savageScreen->depthOffset=gDRIPriv->depthOffset;
142 savageScreen->depthBitmapDesc = gDRIPriv->depthBitmapDesc;
143 #if 0
144 savageScreen->backPitch = gDRIPriv->auxPitch;
145 savageScreen->backPitchBits = gDRIPriv->auxPitchBits;
146 #endif
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;
153
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;
160
161 savageScreen->back.handle = gDRIPriv->backbuffer;
162 savageScreen->back.size = gDRIPriv->backbufferSize;
163 savageScreen->back.map =
164 (drmAddress)(((unsigned int)sPriv->pFB)+gDRIPriv->backOffset);
165
166 savageScreen->depth.handle = gDRIPriv->depthbuffer;
167 savageScreen->depth.size = gDRIPriv->depthbufferSize;
168
169 savageScreen->depth.map =
170 (drmAddress)(((unsigned int)sPriv->pFB)+gDRIPriv->depthOffset);
171
172 savageScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
173
174 savageScreen->texVirtual[SAVAGE_CARD_HEAP] =
175 (drmAddress)(((unsigned int)sPriv->pFB)+gDRIPriv->textureOffset);
176 #if 0
177 savageDDFastPathInit();
178 savageDDTrifuncInit();
179 savageDDSetupInit();
180 #endif
181 return GL_TRUE;
182 }
183
184 /* Accessed by dlsym from dri_mesa_init.c
185 */
186 static void
187 savageDestroyScreen(__DRIscreenPrivate *sPriv)
188 {
189 savageScreenPrivate *savageScreen = (savageScreenPrivate *)sPriv->private;
190
191
192 Xfree(savageScreen);
193 sPriv->private = NULL;
194 }
195
196 #if 0
197 GLvisual *XMesaCreateVisual(Display *dpy,
198 __DRIscreenPrivate *driScrnPriv,
199 const XVisualInfo *visinfo,
200 const __GLXvisualConfig *config)
201 {
202 /* Drivers may change the args to _mesa_create_visual() in order to
203 * setup special visuals.
204 */
205 return _mesa_create_visual( config->rgba,
206 config->doubleBuffer,
207 config->stereo,
208 _mesa_bitcount(visinfo->red_mask),
209 _mesa_bitcount(visinfo->green_mask),
210 _mesa_bitcount(visinfo->blue_mask),
211 config->alphaSize,
212 0, /* index bits */
213 config->depthSize,
214 config->stencilSize,
215 config->accumRedSize,
216 config->accumGreenSize,
217 config->accumBlueSize,
218 config->accumAlphaSize,
219 0 /* num samples */ );
220 }
221 #endif
222
223
224 static GLboolean
225 savageCreateContext( const __GLcontextModes *mesaVis,
226 __DRIcontextPrivate *driContextPriv,
227 void *sharedContextPrivate )
228 {
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 int i;
238 imesa = (savageContextPtr)Xcalloc(sizeof(savageContext), 1);
239 if (!imesa) {
240 return GL_FALSE;
241 }
242
243 /* Init default driver functions then plug in savage-specific texture
244 * functions that are needed as early as during context creation. */
245 _mesa_init_driver_functions( &functions );
246 savageDDInitTextureFuncs( &functions );
247
248 /* Allocate the Mesa context */
249 if (sharedContextPrivate)
250 shareCtx = ((savageContextPtr) sharedContextPrivate)->glCtx;
251 else
252 shareCtx = NULL;
253 ctx = _mesa_create_context(mesaVis, shareCtx, &functions, imesa);
254 if (!ctx) {
255 Xfree(imesa);
256 return GL_FALSE;
257 }
258 driContextPriv->driverPrivate = imesa;
259
260 /* BEGIN;*/
261 /* Set the maximum texture size small enough that we can guarentee
262 * that both texture units can bind a maximal texture and have them
263 * in memory at once.
264 */
265 if (savageScreen->textureSize[SAVAGE_CARD_HEAP] < 2*1024*1024) {
266 ctx->Const.MaxTextureLevels = 9;
267 } else if (savageScreen->textureSize[SAVAGE_CARD_HEAP] < 8*1024*1024) {
268 ctx->Const.MaxTextureLevels = 10;
269 } else {
270 ctx->Const.MaxTextureLevels = 11;
271 }
272 if (savageScreen->chipset >= S3_SAVAGE4)
273 ctx->Const.MaxTextureUnits = 2;
274 else
275 ctx->Const.MaxTextureUnits = 1;
276 ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
277 ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
278
279 #if 0
280 ctx->Const.MinLineWidth = 1.0;
281 ctx->Const.MinLineWidthAA = 1.0;
282 ctx->Const.MaxLineWidth = 3.0;
283 ctx->Const.MaxLineWidthAA = 3.0;
284 ctx->Const.LineWidthGranularity = 1.0;
285 #endif
286
287 /* Dri stuff
288 */
289 imesa->hHWContext = driContextPriv->hHWContext;
290 imesa->driFd = sPriv->fd;
291 imesa->driHwLock = &sPriv->pSAREA->lock;
292
293 imesa->savageScreen = savageScreen;
294 imesa->driScreen = sPriv;
295 imesa->sarea = saPriv;
296 imesa->glBuffer = NULL;
297
298 /* DMA buffer */
299
300 /*The shadow pointer*/
301 imesa->shadowPointer =
302 (volatile GLuint *)((((GLuint)(&saPriv->shadow_status)) + 31) & 0xffffffe0L) ;
303 /* here we use eventTag1 because eventTag0 is used by HWXvMC*/
304 imesa->eventTag1 = (volatile GLuint *)(imesa->shadowPointer + 6);
305 /* imesa->eventTag1=(volatile GLuint *)(imesa->MMIO_BASE+0x48c04);*/
306 imesa->shadowCounter = MAX_SHADOWCOUNTER;
307 imesa->shadowStatus = GL_TRUE;/*Will judge by 2d message */
308
309 if (drmMap(sPriv->fd,
310 gDRIPriv->registers.handle,
311 gDRIPriv->registers.size,
312 (drmAddress *)&(gDRIPriv->registers.map)) != 0)
313 {
314 Xfree(savageScreen);
315 sPriv->private = NULL;
316 return GL_FALSE;
317 }
318
319 if (drmMap(sPriv->fd,
320 gDRIPriv->agpTextures.handle,
321 gDRIPriv->agpTextures.size,
322 (drmAddress *)&(gDRIPriv->agpTextures.map)) != 0)
323 {
324 Xfree(savageScreen);
325 sPriv->private = NULL;
326 return GL_FALSE;
327 }
328
329 /* agp texture*/
330 savageScreen->texVirtual[SAVAGE_AGP_HEAP] =
331 (drmAddress)(gDRIPriv->agpTextures.map);
332
333
334
335 gDRIPriv->BCIcmdBuf.map = (drmAddress *)
336 ((unsigned int)gDRIPriv->registers.map+0x00010000);
337
338 imesa->MMIO_BASE = (GLuint)gDRIPriv->registers.map;
339 imesa->BCIBase= (GLuint)gDRIPriv->BCIcmdBuf.map;
340
341 savageScreen->aperture.handle = gDRIPriv->aperture.handle;
342 savageScreen->aperture.size = gDRIPriv->aperture.size;
343 if (drmMap(sPriv->fd,
344 savageScreen->aperture.handle,
345 savageScreen->aperture.size,
346 (drmAddress *)&savageScreen->aperture.map) != 0)
347 {
348 Xfree(savageScreen);
349 sPriv->private = NULL;
350 return GL_FALSE;
351 }
352
353
354
355
356
357 for(i=0;i<5;i++)
358 {
359 imesa->apertureBase[i] = ((GLuint)savageScreen->aperture.map +
360 0x01000000 * i );
361
362
363 }
364
365 {
366 volatile unsigned int * tmp;
367
368 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x850C);
369
370
371 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x48C40);
372
373
374 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x48C44);
375
376
377 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x48C48);
378
379
380
381 }
382
383 imesa->aperturePitch = gDRIPriv->aperturePitch;
384
385
386 /* change texHeap initialize to support two kind of texture heap*/
387 /* here is some parts of initialization, others in InitDriver() */
388
389 imesa->lastTexHeap = savageScreen->texVirtual[SAVAGE_AGP_HEAP] ? 2 : 1;
390
391 /*allocate texHeap for multi-tex*/
392 {
393 int i;
394
395 for(i=0;i<SAVAGE_NR_TEX_HEAPS;i++)
396 {
397 imesa->texHeap[i] = mmInit( 0, savageScreen->textureSize[i] );
398 make_empty_list(&imesa->TexObjList[i]);
399 }
400
401 make_empty_list(&imesa->SwappedOut);
402 }
403
404 imesa->hw_stencil = GL_FALSE;
405 #if HW_STENCIL
406 imesa->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
407 #endif
408 imesa->depth_scale = (imesa->savageScreen->zpp == 2) ?
409 (1.0F/0x10000):(1.0F/0x1000000);
410
411 /* Uninitialized vertex format. Force setting the vertex state in
412 * savageRenderStart.
413 */
414 imesa->vertex_size = 0;
415
416 /* Utah stuff
417 */
418 imesa->new_state = ~0;
419 imesa->RenderIndex = ~0;
420 imesa->dirty = ~0;
421 imesa->lostContext = GL_TRUE;
422 imesa->TextureMode = ctx->Texture.Unit[0].EnvMode;
423 imesa->CurrentTexObj[0] = 0;
424 imesa->CurrentTexObj[1] = 0;
425 imesa->texAge[SAVAGE_CARD_HEAP]=0;
426 imesa->texAge[SAVAGE_AGP_HEAP]=0;
427
428 /* Initialize the software rasterizer and helper modules.
429 */
430 _swrast_CreateContext( ctx );
431 _ac_CreateContext( ctx );
432 _tnl_CreateContext( ctx );
433
434 _swsetup_CreateContext( ctx );
435
436 /* Install the customized pipeline:
437 */
438 #if 0
439 _tnl_destroy_pipeline( ctx );
440 _tnl_install_pipeline( ctx, savage_pipeline );
441 #endif
442
443 /* Configure swrast to match hardware characteristics:
444 */
445 _tnl_allow_pixel_fog( ctx, GL_FALSE );
446 _tnl_allow_vertex_fog( ctx, GL_TRUE );
447 _swrast_allow_pixel_fog( ctx, GL_FALSE );
448 _swrast_allow_vertex_fog( ctx, GL_TRUE );
449
450 ctx->DriverCtx = (void *) imesa;
451 imesa->glCtx = ctx;
452 if (savageDMAInit(imesa) == GL_FALSE)
453 return GL_FALSE;
454
455 savageDDExtensionsInit( ctx );
456
457 savageDDInitStateFuncs( ctx );
458 savageDDInitSpanFuncs( ctx );
459 savageDDInitDriverFuncs( ctx );
460 savageDDInitIoctlFuncs( ctx );
461 savageInitTriFuncs( ctx );
462
463 savageDDInitState( imesa );
464
465 driContextPriv->driverPrivate = (void *) imesa;
466
467 return GL_TRUE;
468 }
469
470 static void
471 savageDestroyContext(__DRIcontextPrivate *driContextPriv)
472 {
473 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
474
475 assert (imesa); /* should never be NULL */
476 if (imesa) {
477 savageTextureObjectPtr next_t, t;
478
479 /* update for multi-tex*/
480 {
481 int i;
482 for(i=0;i<SAVAGE_NR_TEX_HEAPS;i++)
483 foreach_s (t, next_t, &(imesa->TexObjList[i]))
484 savageDestroyTexObj(imesa, t);
485 }
486 foreach_s (t, next_t, &(imesa->SwappedOut))
487 savageDestroyTexObj(imesa, t);
488 /*free the dma buffer*/
489 savageDMAClose(imesa);
490 _swsetup_DestroyContext(imesa->glCtx );
491 _tnl_DestroyContext( imesa->glCtx );
492 _ac_DestroyContext( imesa->glCtx );
493 _swrast_DestroyContext( imesa->glCtx );
494
495 /* free the Mesa context */
496 imesa->glCtx->DriverCtx = NULL;
497 _mesa_destroy_context(imesa->glCtx);
498
499 /* no longer use vertex_dma_buf*/
500 Xfree(imesa);
501 }
502 }
503
504 static GLboolean
505 savageCreateBuffer( __DRIscreenPrivate *driScrnPriv,
506 __DRIdrawablePrivate *driDrawPriv,
507 const __GLcontextModes *mesaVis,
508 GLboolean isPixmap)
509 {
510 if (isPixmap) {
511 return GL_FALSE; /* not implemented */
512 }
513 else {
514 #if HW_STENCIL
515 GLboolean swStencil = mesaVis->stencilBits > 0 && mesaVis->depthBits != 24;
516 #else
517 GLboolean swStencil = mesaVis->stencilBits > 0;
518 #endif
519 driDrawPriv->driverPrivate = (void *)
520 _mesa_create_framebuffer(mesaVis,
521 GL_FALSE, /* software depth buffer? */
522 swStencil,
523 mesaVis->accumRedBits > 0,
524 mesaVis->alphaBits > 0 );
525
526 return (driDrawPriv->driverPrivate != NULL);
527 }
528 }
529
530 static void
531 savageDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
532 {
533 _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
534 }
535
536 #if 0
537 void XMesaSwapBuffers(__DRIdrawablePrivate *driDrawPriv)
538 {
539 /* XXX should do swap according to the buffer, not the context! */
540 savageContextPtr imesa = savageCtx;
541
542 FLUSH_VB( imesa->glCtx, "swap buffers" );
543 savageSwapBuffers(imesa);
544 }
545 #endif
546
547 void savageXMesaSetFrontClipRects( savageContextPtr imesa )
548 {
549 __DRIdrawablePrivate *dPriv = imesa->driDrawable;
550
551 imesa->numClipRects = dPriv->numClipRects;
552 imesa->pClipRects = dPriv->pClipRects;
553 imesa->dirty |= SAVAGE_UPLOAD_CLIPRECTS;
554 imesa->drawX = dPriv->x;
555 imesa->drawY = dPriv->y;
556
557 savageEmitDrawingRectangle( imesa );
558 }
559
560
561 void savageXMesaSetBackClipRects( savageContextPtr imesa )
562 {
563 __DRIdrawablePrivate *dPriv = imesa->driDrawable;
564
565 if (dPriv->numBackClipRects == 0)
566 {
567
568
569 imesa->numClipRects = dPriv->numClipRects;
570 imesa->pClipRects = dPriv->pClipRects;
571 imesa->drawX = dPriv->x;
572 imesa->drawY = dPriv->y;
573 } else {
574
575
576 imesa->numClipRects = dPriv->numBackClipRects;
577 imesa->pClipRects = dPriv->pBackClipRects;
578 imesa->drawX = dPriv->backX;
579 imesa->drawY = dPriv->backY;
580 }
581
582 savageEmitDrawingRectangle( imesa );
583 imesa->dirty |= SAVAGE_UPLOAD_CLIPRECTS;
584
585
586 }
587
588
589 static void savageXMesaWindowMoved( savageContextPtr imesa )
590 {
591 if (0)
592 fprintf(stderr, "savageXMesaWindowMoved\n\n");
593
594 switch (imesa->glCtx->Color._DrawDestMask) {
595 case DD_FRONT_LEFT_BIT:
596 savageXMesaSetFrontClipRects( imesa );
597 break;
598 case DD_BACK_LEFT_BIT:
599 savageXMesaSetBackClipRects( imesa );
600 break;
601 default:
602 break;
603 }
604 }
605
606
607 static GLboolean
608 savageUnbindContext(__DRIcontextPrivate *driContextPriv)
609 {
610 savageContextPtr savage = (savageContextPtr) driContextPriv->driverPrivate;
611 if (savage)
612 savage->dirty = ~0;
613
614 return GL_TRUE;
615 }
616
617 static GLboolean
618 savageOpenFullScreen(__DRIcontextPrivate *driContextPriv)
619 {
620
621
622
623 if (driContextPriv) {
624 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
625 imesa->IsFullScreen = GL_TRUE;
626 imesa->backup_frontOffset = imesa->savageScreen->frontOffset;
627 imesa->backup_backOffset = imesa->savageScreen->backOffset;
628 imesa->backup_frontBitmapDesc = imesa->savageScreen->frontBitmapDesc;
629 imesa->savageScreen->frontBitmapDesc = imesa->savageScreen->backBitmapDesc;
630 imesa->toggle = TARGET_BACK;
631 }
632
633 return GL_TRUE;
634 }
635
636 static GLboolean
637 savageCloseFullScreen(__DRIcontextPrivate *driContextPriv)
638 {
639
640 if (driContextPriv) {
641 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
642 WAIT_IDLE_EMPTY;
643 imesa->IsFullScreen = GL_FALSE;
644 imesa->savageScreen->frontOffset = imesa->backup_frontOffset;
645 imesa->savageScreen->backOffset = imesa->backup_backOffset;
646 imesa->savageScreen->frontBitmapDesc = imesa->backup_frontBitmapDesc;
647 }
648 return GL_TRUE;
649 }
650
651
652 static GLboolean
653 savageMakeCurrent(__DRIcontextPrivate *driContextPriv,
654 __DRIdrawablePrivate *driDrawPriv,
655 __DRIdrawablePrivate *driReadPriv)
656 {
657 if (driContextPriv) {
658 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
659
660 imesa->driReadable = driReadPriv;
661 imesa->driDrawable = driDrawPriv;
662 imesa->mesa_drawable = driDrawPriv;
663 imesa->dirty = ~0;
664
665 _mesa_make_current2(imesa->glCtx,
666 (GLframebuffer *) driDrawPriv->driverPrivate,
667 (GLframebuffer *) driReadPriv->driverPrivate);
668
669 savageXMesaWindowMoved( imesa );
670
671 if (!imesa->glCtx->Viewport.Width)
672 _mesa_set_viewport(imesa->glCtx, 0, 0,
673 driDrawPriv->w, driDrawPriv->h);
674 }
675 else
676 {
677 _mesa_make_current(NULL, NULL);
678 }
679 return GL_TRUE;
680 }
681
682
683 void savageGetLock( savageContextPtr imesa, GLuint flags )
684 {
685 __DRIdrawablePrivate *dPriv = imesa->driDrawable;
686 __DRIscreenPrivate *sPriv = imesa->driScreen;
687 drm_savage_sarea_t *sarea = imesa->sarea;
688 int me = imesa->hHWContext;
689 int stamp = dPriv->lastStamp;
690 int heap;
691
692
693
694 /* We know there has been contention.
695 */
696 drmGetLock(imesa->driFd, imesa->hHWContext, flags);
697
698
699 /* Note contention for throttling hint
700 */
701 imesa->any_contend = 1;
702
703 /* If the window moved, may need to set a new cliprect now.
704 *
705 * NOTE: This releases and regains the hw lock, so all state
706 * checking must be done *after* this call:
707 */
708 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
709
710
711
712
713 /* If we lost context, need to dump all registers to hardware.
714 * Note that we don't care about 2d contexts, even if they perform
715 * accelerated commands, so the DRI locking in the X server is even
716 * more broken than usual.
717 */
718 if (sarea->ctxOwner != me) {
719 imesa->dirty |= (SAVAGE_UPLOAD_CTX |
720 SAVAGE_UPLOAD_CLIPRECTS |
721 SAVAGE_UPLOAD_TEX0 |
722 SAVAGE_UPLOAD_TEX1);
723 imesa->lostContext = GL_TRUE;
724 sarea->ctxOwner = me;
725 }
726
727 /* Shared texture managment - if another client has played with
728 * texture space, figure out which if any of our textures have been
729 * ejected, and update our global LRU.
730 */
731 /*frank just for compiling,texAge,texList,AGP*/
732
733 for(heap= 0 ;heap < imesa->lastTexHeap ; heap++)
734 {
735 if (sarea->texAge[heap] != imesa->texAge[heap]) {
736 int sz = 1 << (imesa->savageScreen->logTextureGranularity[heap]);
737 int idx, nr = 0;
738
739 /* Have to go right round from the back to ensure stuff ends up
740 * LRU in our local list...
741 */
742 for (idx = sarea->texList[heap][SAVAGE_NR_TEX_REGIONS].prev ;
743 idx != SAVAGE_NR_TEX_REGIONS && nr < SAVAGE_NR_TEX_REGIONS ;
744 idx = sarea->texList[heap][idx].prev, nr++)
745 {
746 if (sarea->texList[heap][idx].age > imesa->texAge[heap])
747 {
748 savageTexturesGone(imesa, heap ,idx * sz, sz,
749 sarea->texList[heap][idx].in_use);
750 }
751 }
752
753 if (nr == SAVAGE_NR_TEX_REGIONS)
754 {
755 savageTexturesGone(imesa, heap, 0,
756 imesa->savageScreen->textureSize[heap], 0);
757 savageResetGlobalLRU( imesa , heap );
758 }
759
760 imesa->dirty |= SAVAGE_UPLOAD_TEX0IMAGE;
761 imesa->dirty |= SAVAGE_UPLOAD_TEX1IMAGE;
762 imesa->texAge[heap] = sarea->texAge[heap];
763 }
764 } /* end of for loop */
765
766 if (dPriv->lastStamp != stamp)
767 savageXMesaWindowMoved( imesa );
768
769
770
771 }
772
773
774
775 static const struct __DriverAPIRec savageAPI = {
776 savageInitDriver,
777 savageDestroyScreen,
778 savageCreateContext,
779 savageDestroyContext,
780 savageCreateBuffer,
781 savageDestroyBuffer,
782 savageSwapBuffers,
783 savageMakeCurrent,
784 savageUnbindContext,
785 savageOpenFullScreen,
786 savageCloseFullScreen
787 };
788
789
790
791 /*
792 * This is the bootstrap function for the driver.
793 * The __driCreateScreen name is the symbol that libGL.so fetches.
794 * Return: pointer to a __DRIscreenPrivate.
795 */
796 void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
797 int numConfigs, __GLXvisualConfig *config)
798 {
799 __DRIscreenPrivate *psp;
800 psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &savageAPI);
801 return (void *) psp;
802 }
803
804
805 #endif