Open/Close FullScreen die. unichrome and savage implemented, code is ifdef'd out
[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 GLuint maxTextureSize, minTextureSize, maxTextureLevels;
238 int i;
239 imesa = (savageContextPtr)Xcalloc(sizeof(savageContext), 1);
240 if (!imesa) {
241 return GL_FALSE;
242 }
243
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 );
248
249 /* Allocate the Mesa context */
250 if (sharedContextPrivate)
251 shareCtx = ((savageContextPtr) sharedContextPrivate)->glCtx;
252 else
253 shareCtx = NULL;
254 ctx = _mesa_create_context(mesaVis, shareCtx, &functions, imesa);
255 if (!ctx) {
256 Xfree(imesa);
257 return GL_FALSE;
258 }
259 driContextPriv->driverPrivate = imesa;
260
261 if (savageScreen->chipset >= S3_SAVAGE4)
262 ctx->Const.MaxTextureUnits = 2;
263 else
264 ctx->Const.MaxTextureUnits = 1;
265 ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
266 ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
267
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
270 * in memory at once.
271 */
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];
276 } else {
277 maxTextureSize = savageScreen->textureSize[SAVAGE_AGP_HEAP];
278 minTextureSize = savageScreen->textureSize[SAVAGE_CARD_HEAP];
279 }
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;
287 else
288 maxTextureSize = minTextureSize;
289 }
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
294 the biggest level */
295 if (size > maxTextureSize)
296 break;
297 }
298 ctx->Const.MaxTextureLevels = maxTextureLevels;
299 assert (ctx->Const.MaxTextureLevels > 6); /*spec requires at least 64x64*/
300
301 #if 0
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;
307 #endif
308
309 /* Dri stuff
310 */
311 imesa->hHWContext = driContextPriv->hHWContext;
312 imesa->driFd = sPriv->fd;
313 imesa->driHwLock = &sPriv->pSAREA->lock;
314
315 imesa->savageScreen = savageScreen;
316 imesa->driScreen = sPriv;
317 imesa->sarea = saPriv;
318 imesa->glBuffer = NULL;
319
320 /* DMA buffer */
321
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 */
330
331 if (drmMap(sPriv->fd,
332 gDRIPriv->registers.handle,
333 gDRIPriv->registers.size,
334 (drmAddress *)&(gDRIPriv->registers.map)) != 0)
335 {
336 Xfree(savageScreen);
337 sPriv->private = NULL;
338 return GL_FALSE;
339 }
340
341 if (drmMap(sPriv->fd,
342 gDRIPriv->agpTextures.handle,
343 gDRIPriv->agpTextures.size,
344 (drmAddress *)&(gDRIPriv->agpTextures.map)) != 0)
345 {
346 Xfree(savageScreen);
347 sPriv->private = NULL;
348 return GL_FALSE;
349 }
350
351 /* agp texture*/
352 savageScreen->texVirtual[SAVAGE_AGP_HEAP] =
353 (drmAddress)(gDRIPriv->agpTextures.map);
354
355
356
357 gDRIPriv->BCIcmdBuf.map = (drmAddress *)
358 ((unsigned int)gDRIPriv->registers.map+0x00010000);
359
360 imesa->MMIO_BASE = (GLuint)gDRIPriv->registers.map;
361 imesa->BCIBase= (GLuint)gDRIPriv->BCIcmdBuf.map;
362
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)
369 {
370 Xfree(savageScreen);
371 sPriv->private = NULL;
372 return GL_FALSE;
373 }
374
375
376
377
378
379 for(i=0;i<5;i++)
380 {
381 imesa->apertureBase[i] = ((GLuint)savageScreen->aperture.map +
382 0x01000000 * i );
383
384
385 }
386
387 {
388 volatile unsigned int * tmp;
389
390 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x850C);
391
392
393 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x48C40);
394
395
396 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x48C44);
397
398
399 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x48C48);
400
401
402
403 }
404
405 imesa->aperturePitch = gDRIPriv->aperturePitch;
406
407
408 /* change texHeap initialize to support two kind of texture heap*/
409 /* here is some parts of initialization, others in InitDriver() */
410
411 imesa->lastTexHeap = savageScreen->texVirtual[SAVAGE_AGP_HEAP] ? 2 : 1;
412
413 /*allocate texHeap for multi-tex*/
414 {
415 int i;
416
417 for(i=0;i<SAVAGE_NR_TEX_HEAPS;i++)
418 {
419 imesa->texHeap[i] = mmInit( 0, savageScreen->textureSize[i] );
420 make_empty_list(&imesa->TexObjList[i]);
421 }
422
423 make_empty_list(&imesa->SwappedOut);
424 }
425
426 imesa->hw_stencil = GL_FALSE;
427 #if HW_STENCIL
428 imesa->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
429 #endif
430 imesa->depth_scale = (imesa->savageScreen->zpp == 2) ?
431 (1.0F/0x10000):(1.0F/0x1000000);
432
433 imesa->vertex_dma_buffer = NULL;
434
435 /* Uninitialized vertex format. Force setting the vertex state in
436 * savageRenderStart.
437 */
438 imesa->vertex_size = 0;
439
440 /* Utah stuff
441 */
442 imesa->new_state = ~0;
443 imesa->RenderIndex = ~0;
444 imesa->dirty = ~0;
445 imesa->lostContext = GL_TRUE;
446 imesa->TextureMode = ctx->Texture.Unit[0].EnvMode;
447 imesa->CurrentTexObj[0] = 0;
448 imesa->CurrentTexObj[1] = 0;
449 imesa->texAge[SAVAGE_CARD_HEAP]=0;
450 imesa->texAge[SAVAGE_AGP_HEAP]=0;
451
452 /* Initialize the software rasterizer and helper modules.
453 */
454 _swrast_CreateContext( ctx );
455 _ac_CreateContext( ctx );
456 _tnl_CreateContext( ctx );
457
458 _swsetup_CreateContext( ctx );
459
460 /* Install the customized pipeline:
461 */
462 #if 0
463 _tnl_destroy_pipeline( ctx );
464 _tnl_install_pipeline( ctx, savage_pipeline );
465 #endif
466
467 /* Configure swrast to match hardware characteristics:
468 */
469 _tnl_allow_pixel_fog( ctx, GL_FALSE );
470 _tnl_allow_vertex_fog( ctx, GL_TRUE );
471 _swrast_allow_pixel_fog( ctx, GL_FALSE );
472 _swrast_allow_vertex_fog( ctx, GL_TRUE );
473
474 ctx->DriverCtx = (void *) imesa;
475 imesa->glCtx = ctx;
476 if (savageDMAInit(imesa) == GL_FALSE)
477 return GL_FALSE;
478
479 savageDDExtensionsInit( ctx );
480
481 savageDDInitStateFuncs( ctx );
482 savageDDInitSpanFuncs( ctx );
483 savageDDInitDriverFuncs( ctx );
484 savageDDInitIoctlFuncs( ctx );
485 savageInitTriFuncs( ctx );
486
487 savageDDInitState( imesa );
488
489 driContextPriv->driverPrivate = (void *) imesa;
490
491 return GL_TRUE;
492 }
493
494 static void
495 savageDestroyContext(__DRIcontextPrivate *driContextPriv)
496 {
497 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
498
499 assert (imesa); /* should never be NULL */
500 if (imesa) {
501 savageTextureObjectPtr next_t, t;
502
503 FLUSH_BATCH(imesa);
504
505 /* update for multi-tex*/
506 {
507 int i;
508 for(i=0;i<SAVAGE_NR_TEX_HEAPS;i++)
509 foreach_s (t, next_t, &(imesa->TexObjList[i]))
510 savageDestroyTexObj(imesa, t);
511 }
512 foreach_s (t, next_t, &(imesa->SwappedOut))
513 savageDestroyTexObj(imesa, t);
514 /*free the dma buffer*/
515 savageDMAClose(imesa);
516 _swsetup_DestroyContext(imesa->glCtx );
517 _tnl_DestroyContext( imesa->glCtx );
518 _ac_DestroyContext( imesa->glCtx );
519 _swrast_DestroyContext( imesa->glCtx );
520
521 /* free the Mesa context */
522 imesa->glCtx->DriverCtx = NULL;
523 _mesa_destroy_context(imesa->glCtx);
524
525 /* no longer use vertex_dma_buf*/
526 Xfree(imesa);
527 }
528 }
529
530 static GLboolean
531 savageCreateBuffer( __DRIscreenPrivate *driScrnPriv,
532 __DRIdrawablePrivate *driDrawPriv,
533 const __GLcontextModes *mesaVis,
534 GLboolean isPixmap)
535 {
536 if (isPixmap) {
537 return GL_FALSE; /* not implemented */
538 }
539 else {
540 #if HW_STENCIL
541 GLboolean swStencil = mesaVis->stencilBits > 0 && mesaVis->depthBits != 24;
542 #else
543 GLboolean swStencil = mesaVis->stencilBits > 0;
544 #endif
545 driDrawPriv->driverPrivate = (void *)
546 _mesa_create_framebuffer(mesaVis,
547 GL_FALSE, /* software depth buffer? */
548 swStencil,
549 mesaVis->accumRedBits > 0,
550 mesaVis->alphaBits > 0 );
551
552 return (driDrawPriv->driverPrivate != NULL);
553 }
554 }
555
556 static void
557 savageDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
558 {
559 _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
560 }
561
562 #if 0
563 void XMesaSwapBuffers(__DRIdrawablePrivate *driDrawPriv)
564 {
565 /* XXX should do swap according to the buffer, not the context! */
566 savageContextPtr imesa = savageCtx;
567
568 FLUSH_VB( imesa->glCtx, "swap buffers" );
569 savageSwapBuffers(imesa);
570 }
571 #endif
572
573 void savageXMesaSetFrontClipRects( savageContextPtr imesa )
574 {
575 __DRIdrawablePrivate *dPriv = imesa->driDrawable;
576
577 imesa->numClipRects = dPriv->numClipRects;
578 imesa->pClipRects = dPriv->pClipRects;
579 imesa->dirty |= SAVAGE_UPLOAD_CLIPRECTS;
580 imesa->drawX = dPriv->x;
581 imesa->drawY = dPriv->y;
582
583 savageEmitDrawingRectangle( imesa );
584 }
585
586
587 void savageXMesaSetBackClipRects( savageContextPtr imesa )
588 {
589 __DRIdrawablePrivate *dPriv = imesa->driDrawable;
590
591 if (dPriv->numBackClipRects == 0)
592 {
593
594
595 imesa->numClipRects = dPriv->numClipRects;
596 imesa->pClipRects = dPriv->pClipRects;
597 imesa->drawX = dPriv->x;
598 imesa->drawY = dPriv->y;
599 } else {
600
601
602 imesa->numClipRects = dPriv->numBackClipRects;
603 imesa->pClipRects = dPriv->pBackClipRects;
604 imesa->drawX = dPriv->backX;
605 imesa->drawY = dPriv->backY;
606 }
607
608 savageEmitDrawingRectangle( imesa );
609 imesa->dirty |= SAVAGE_UPLOAD_CLIPRECTS;
610
611
612 }
613
614
615 static void savageXMesaWindowMoved( savageContextPtr imesa )
616 {
617 if (0)
618 fprintf(stderr, "savageXMesaWindowMoved\n\n");
619
620 switch (imesa->glCtx->Color._DrawDestMask) {
621 case DD_FRONT_LEFT_BIT:
622 savageXMesaSetFrontClipRects( imesa );
623 break;
624 case DD_BACK_LEFT_BIT:
625 savageXMesaSetBackClipRects( imesa );
626 break;
627 default:
628 break;
629 }
630 }
631
632
633 static GLboolean
634 savageUnbindContext(__DRIcontextPrivate *driContextPriv)
635 {
636 savageContextPtr savage = (savageContextPtr) driContextPriv->driverPrivate;
637 if (savage)
638 savage->dirty = ~0;
639
640 return GL_TRUE;
641 }
642
643 #if 0
644 static GLboolean
645 savageOpenFullScreen(__DRIcontextPrivate *driContextPriv)
646 {
647
648
649
650 if (driContextPriv) {
651 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
652 imesa->IsFullScreen = GL_TRUE;
653 imesa->backup_frontOffset = imesa->savageScreen->frontOffset;
654 imesa->backup_backOffset = imesa->savageScreen->backOffset;
655 imesa->backup_frontBitmapDesc = imesa->savageScreen->frontBitmapDesc;
656 imesa->savageScreen->frontBitmapDesc = imesa->savageScreen->backBitmapDesc;
657 imesa->toggle = TARGET_BACK;
658 }
659
660 return GL_TRUE;
661 }
662
663 static GLboolean
664 savageCloseFullScreen(__DRIcontextPrivate *driContextPriv)
665 {
666
667 if (driContextPriv) {
668 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
669 WAIT_IDLE_EMPTY;
670 imesa->IsFullScreen = GL_FALSE;
671 imesa->savageScreen->frontOffset = imesa->backup_frontOffset;
672 imesa->savageScreen->backOffset = imesa->backup_backOffset;
673 imesa->savageScreen->frontBitmapDesc = imesa->backup_frontBitmapDesc;
674 }
675 return GL_TRUE;
676 }
677 #endif
678
679 static GLboolean
680 savageMakeCurrent(__DRIcontextPrivate *driContextPriv,
681 __DRIdrawablePrivate *driDrawPriv,
682 __DRIdrawablePrivate *driReadPriv)
683 {
684 if (driContextPriv) {
685 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
686
687 imesa->driReadable = driReadPriv;
688 imesa->driDrawable = driDrawPriv;
689 imesa->mesa_drawable = driDrawPriv;
690 imesa->dirty = ~0;
691
692 _mesa_make_current2(imesa->glCtx,
693 (GLframebuffer *) driDrawPriv->driverPrivate,
694 (GLframebuffer *) driReadPriv->driverPrivate);
695
696 savageXMesaWindowMoved( imesa );
697
698 if (!imesa->glCtx->Viewport.Width)
699 _mesa_set_viewport(imesa->glCtx, 0, 0,
700 driDrawPriv->w, driDrawPriv->h);
701 }
702 else
703 {
704 _mesa_make_current(NULL, NULL);
705 }
706 return GL_TRUE;
707 }
708
709
710 void savageGetLock( savageContextPtr imesa, GLuint flags )
711 {
712 __DRIdrawablePrivate *dPriv = imesa->driDrawable;
713 __DRIscreenPrivate *sPriv = imesa->driScreen;
714 drm_savage_sarea_t *sarea = imesa->sarea;
715 int me = imesa->hHWContext;
716 int stamp = dPriv->lastStamp;
717 int heap;
718
719
720
721 /* We know there has been contention.
722 */
723 drmGetLock(imesa->driFd, imesa->hHWContext, flags);
724
725
726 /* Note contention for throttling hint
727 */
728 imesa->any_contend = 1;
729
730 /* If the window moved, may need to set a new cliprect now.
731 *
732 * NOTE: This releases and regains the hw lock, so all state
733 * checking must be done *after* this call:
734 */
735 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
736
737
738
739
740 /* If we lost context, need to dump all registers to hardware.
741 * Note that we don't care about 2d contexts, even if they perform
742 * accelerated commands, so the DRI locking in the X server is even
743 * more broken than usual.
744 */
745 if (sarea->ctxOwner != me) {
746 imesa->dirty |= (SAVAGE_UPLOAD_CTX |
747 SAVAGE_UPLOAD_CLIPRECTS |
748 SAVAGE_UPLOAD_TEX0 |
749 SAVAGE_UPLOAD_TEX1);
750 imesa->lostContext = GL_TRUE;
751 sarea->ctxOwner = me;
752 }
753
754 /* Shared texture managment - if another client has played with
755 * texture space, figure out which if any of our textures have been
756 * ejected, and update our global LRU.
757 */
758 /*frank just for compiling,texAge,texList,AGP*/
759
760 for(heap= 0 ;heap < imesa->lastTexHeap ; heap++)
761 {
762 if (sarea->texAge[heap] != imesa->texAge[heap]) {
763 int sz = 1 << (imesa->savageScreen->logTextureGranularity[heap]);
764 int idx, nr = 0;
765
766 /* Have to go right round from the back to ensure stuff ends up
767 * LRU in our local list...
768 */
769 for (idx = sarea->texList[heap][SAVAGE_NR_TEX_REGIONS].prev ;
770 idx != SAVAGE_NR_TEX_REGIONS && nr < SAVAGE_NR_TEX_REGIONS ;
771 idx = sarea->texList[heap][idx].prev, nr++)
772 {
773 if (sarea->texList[heap][idx].age > imesa->texAge[heap])
774 {
775 savageTexturesGone(imesa, heap ,idx * sz, sz,
776 sarea->texList[heap][idx].in_use);
777 }
778 }
779
780 if (nr == SAVAGE_NR_TEX_REGIONS)
781 {
782 savageTexturesGone(imesa, heap, 0,
783 imesa->savageScreen->textureSize[heap], 0);
784 savageResetGlobalLRU( imesa , heap );
785 }
786
787 imesa->dirty |= SAVAGE_UPLOAD_TEX0IMAGE;
788 imesa->dirty |= SAVAGE_UPLOAD_TEX1IMAGE;
789 imesa->texAge[heap] = sarea->texAge[heap];
790 }
791 } /* end of for loop */
792
793 if (dPriv->lastStamp != stamp)
794 savageXMesaWindowMoved( imesa );
795
796
797
798 }
799
800
801
802 static const struct __DriverAPIRec savageAPI = {
803 savageInitDriver,
804 savageDestroyScreen,
805 savageCreateContext,
806 savageDestroyContext,
807 savageCreateBuffer,
808 savageDestroyBuffer,
809 savageSwapBuffers,
810 savageMakeCurrent,
811 savageUnbindContext
812 };
813
814
815
816 /*
817 * This is the bootstrap function for the driver.
818 * The __driCreateScreen name is the symbol that libGL.so fetches.
819 * Return: pointer to a __DRIscreenPrivate.
820 */
821 void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
822 int numConfigs, __GLXvisualConfig *config)
823 {
824 __DRIscreenPrivate *psp;
825 psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &savageAPI);
826 return (void *) psp;
827 }
828
829
830 #endif