Imported the Savage DRI driver from the savage-2-0-0-branch of DRI CVS
[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 "savagevb.h"
52 #include "savageioctl.h"
53 #include "savage_bci.h"
54
55 #include "savage_dri.h"
56
57 #include "savagedma.h"
58
59 #ifndef SAVAGE_DEBUG
60 int SAVAGE_DEBUG = (0
61 /* | DEBUG_ALWAYS_SYNC */
62 /* | DEBUG_VERBOSE_RING */
63 /* | DEBUG_VERBOSE_OUTREG */
64 /* | DEBUG_VERBOSE_MSG */
65 /* | DEBUG_NO_OUTRING */
66 /* | DEBUG_NO_OUTREG */
67 /* | DEBUG_VERBOSE_API */
68 /* | DEBUG_VERBOSE_2D */
69 /* | DEBUG_VERBOSE_DRI */
70 /* | DEBUG_VALIDATE_RING */
71 /* | DEBUG_VERBOSE_IOCTL */
72 );
73 #endif
74
75
76 /*For time caculating test*/
77 #if defined(DEBUG_TIME) && DEBUG_TIME
78 struct timeval tv_s,tv_f;
79 unsigned long time_sum=0;
80 struct timeval tv_s1,tv_f1;
81 #endif
82
83 /* this is first function called in dirver*/
84
85 static GLboolean
86 savageInitDriver(__DRIscreenPrivate *sPriv)
87 {
88 savageScreenPrivate *savageScreen;
89 SAVAGEDRIPtr gDRIPriv = (SAVAGEDRIPtr)sPriv->pDevPriv;
90
91
92 /* Check the DRI version */
93 {
94 int major, minor, patch;
95 if (XF86DRIQueryVersion(sPriv->display, &major, &minor, &patch)) {
96 if (major != 4 || minor < 0) {
97 __driUtilMessage("savage DRI driver expected DRI version 4.0.x but got version %d.%d.%d", major, minor, patch);
98 return GL_FALSE;
99 }
100 }
101 }
102
103 /* Check that the DDX driver version is compatible */
104 if (sPriv->ddxMajor != 1 ||
105 sPriv->ddxMinor < 0) {
106 __driUtilMessage("savage DRI driver expected DDX driver version 1.0.x but got version %d.%d.%d", sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch);
107 return GL_FALSE;
108 }
109
110 /* Check that the DRM driver version is compatible */
111 if (sPriv->drmMajor != 1 ||
112 sPriv->drmMinor < 0) {
113 __driUtilMessage("savage DRI driver expected DRM driver version 1.1.x but got version %d.%d.%d", sPriv->drmMajor, sPriv->drmMinor, sPriv->drmPatch);
114 return GL_FALSE;
115 }
116
117 /* Allocate the private area */
118 savageScreen = (savageScreenPrivate *)Xmalloc(sizeof(savageScreenPrivate));
119 if (!savageScreen)
120 return GL_FALSE;
121
122 savageScreen->driScrnPriv = sPriv;
123 sPriv->private = (void *)savageScreen;
124
125 savageScreen->chipset=gDRIPriv->chipset;
126 savageScreen->width=gDRIPriv->width;
127 savageScreen->height=gDRIPriv->height;
128 savageScreen->mem=gDRIPriv->mem;
129 savageScreen->cpp=gDRIPriv->cpp;
130 savageScreen->zpp=gDRIPriv->zpp;
131 savageScreen->frontPitch=gDRIPriv->frontPitch;
132 savageScreen->frontOffset=gDRIPriv->frontOffset;
133 savageScreen->frontBitmapDesc = gDRIPriv->frontBitmapDesc;
134
135 if (gDRIPriv->cpp == 4)
136 savageScreen->frontFormat = DV_PF_8888;
137 else
138 savageScreen->frontFormat = DV_PF_565;
139
140 savageScreen->backOffset = gDRIPriv->backOffset;
141 savageScreen->backBitmapDesc = gDRIPriv->backBitmapDesc;
142 savageScreen->depthOffset=gDRIPriv->depthOffset;
143 savageScreen->depthBitmapDesc = gDRIPriv->depthBitmapDesc;
144 #if 0
145 savageScreen->backPitch = gDRIPriv->auxPitch;
146 savageScreen->backPitchBits = gDRIPriv->auxPitchBits;
147 #endif
148 savageScreen->textureOffset[SAVAGE_CARD_HEAP] =
149 gDRIPriv->textureOffset;
150 savageScreen->textureSize[SAVAGE_CARD_HEAP] =
151 gDRIPriv->textureSize;
152 savageScreen->logTextureGranularity[SAVAGE_CARD_HEAP] =
153 gDRIPriv->logTextureGranularity;
154
155 savageScreen->textureOffset[SAVAGE_AGP_HEAP] =
156 gDRIPriv->agpTextures.handle;
157 savageScreen->textureSize[SAVAGE_AGP_HEAP] =
158 gDRIPriv->agpTextures.size;
159 savageScreen->logTextureGranularity[SAVAGE_AGP_HEAP] =
160 gDRIPriv->logAgpTextureGranularity;
161
162 savageScreen->back.handle = gDRIPriv->backbuffer;
163 savageScreen->back.size = gDRIPriv->backbufferSize;
164 savageScreen->back.map =
165 (drmAddress)(((unsigned int)sPriv->pFB)+gDRIPriv->backOffset);
166
167 savageScreen->depth.handle = gDRIPriv->depthbuffer;
168 savageScreen->depth.size = gDRIPriv->depthbufferSize;
169
170 savageScreen->depth.map =
171 (drmAddress)(((unsigned int)sPriv->pFB)+gDRIPriv->depthOffset);
172
173 savageScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
174
175 savageScreen->texVirtual[SAVAGE_CARD_HEAP] =
176 (drmAddress)(((unsigned int)sPriv->pFB)+gDRIPriv->textureOffset);
177 #if 0
178 savageDDFastPathInit();
179 savageDDTrifuncInit();
180 savageDDSetupInit();
181 #endif
182 return GL_TRUE;
183 }
184
185 /* Accessed by dlsym from dri_mesa_init.c
186 */
187 static void
188 savageDestroyScreen(__DRIscreenPrivate *sPriv)
189 {
190 savageScreenPrivate *savageScreen = (savageScreenPrivate *)sPriv->private;
191
192
193 Xfree(savageScreen);
194 sPriv->private = NULL;
195 }
196
197 #if 0
198 GLvisual *XMesaCreateVisual(Display *dpy,
199 __DRIscreenPrivate *driScrnPriv,
200 const XVisualInfo *visinfo,
201 const __GLXvisualConfig *config)
202 {
203 /* Drivers may change the args to _mesa_create_visual() in order to
204 * setup special visuals.
205 */
206 return _mesa_create_visual( config->rgba,
207 config->doubleBuffer,
208 config->stereo,
209 _mesa_bitcount(visinfo->red_mask),
210 _mesa_bitcount(visinfo->green_mask),
211 _mesa_bitcount(visinfo->blue_mask),
212 config->alphaSize,
213 0, /* index bits */
214 config->depthSize,
215 config->stencilSize,
216 config->accumRedSize,
217 config->accumGreenSize,
218 config->accumBlueSize,
219 config->accumAlphaSize,
220 0 /* num samples */ );
221 }
222 #endif
223
224
225 static GLboolean
226 savageCreateContext( const __GLcontextModes *mesaVis,
227 __DRIcontextPrivate *driContextPriv,
228 void *sharedContextPrivate )
229 {
230 GLcontext *ctx, *shareCtx;
231 savageContextPtr imesa;
232 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
233 struct dd_function_table functions;
234 SAVAGEDRIPtr gDRIPriv = (SAVAGEDRIPtr)sPriv->pDevPriv;
235 savageScreenPrivate *savageScreen = (savageScreenPrivate *)sPriv->private;
236 drm_savage_sarea_t *saPriv=(drm_savage_sarea_t *)(((char*)sPriv->pSAREA)+
237 savageScreen->sarea_priv_offset);
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 /* BEGIN;*/
262 /* Set the maximum texture size small enough that we can guarentee
263 * that both texture units can bind a maximal texture and have them
264 * in memory at once.
265 */
266 if (savageScreen->textureSize[SAVAGE_CARD_HEAP] < 2*1024*1024) {
267 ctx->Const.MaxTextureLevels = 9;
268 } else if (savageScreen->textureSize[SAVAGE_CARD_HEAP] < 8*1024*1024) {
269 ctx->Const.MaxTextureLevels = 10;
270 } else {
271 ctx->Const.MaxTextureLevels = 11;
272 }
273 if (savageScreen->chipset >= S3_SAVAGE4)
274 ctx->Const.MaxTextureUnits = 2;
275 else
276 ctx->Const.MaxTextureUnits = 1;
277
278 #if 0
279 ctx->Const.MinLineWidth = 1.0;
280 ctx->Const.MinLineWidthAA = 1.0;
281 ctx->Const.MaxLineWidth = 3.0;
282 ctx->Const.MaxLineWidthAA = 3.0;
283 ctx->Const.LineWidthGranularity = 1.0;
284 #endif
285
286 /* Dri stuff
287 */
288 imesa->hHWContext = driContextPriv->hHWContext;
289 imesa->driFd = sPriv->fd;
290 imesa->driHwLock = &sPriv->pSAREA->lock;
291
292 imesa->savageScreen = savageScreen;
293 imesa->driScreen = sPriv;
294 imesa->sarea = saPriv;
295 imesa->glBuffer = NULL;
296
297 /* DMA buffer */
298
299 /*The shadow pointer*/
300 imesa->shadowPointer =
301 (volatile GLuint *)((((GLuint)(&saPriv->shadow_status)) + 31) & 0xffffffe0L) ;
302 /* here we use eventTag1 because eventTag0 is used by HWXvMC*/
303 imesa->eventTag1 = (volatile GLuint *)(imesa->shadowPointer + 6);
304 /* imesa->eventTag1=(volatile GLuint *)(imesa->MMIO_BASE+0x48c04);*/
305 imesa->shadowCounter = MAX_SHADOWCOUNTER;
306 imesa->shadowStatus = GL_TRUE;/*Will judge by 2d message */
307
308 if (drmMap(sPriv->fd,
309 gDRIPriv->registers.handle,
310 gDRIPriv->registers.size,
311 (drmAddress *)&(gDRIPriv->registers.map)) != 0)
312 {
313 Xfree(savageScreen);
314 sPriv->private = NULL;
315 return GL_FALSE;
316 }
317
318 if (drmMap(sPriv->fd,
319 gDRIPriv->agpTextures.handle,
320 gDRIPriv->agpTextures.size,
321 (drmAddress *)&(gDRIPriv->agpTextures.map)) != 0)
322 {
323 Xfree(savageScreen);
324 sPriv->private = NULL;
325 return GL_FALSE;
326 }
327
328 /* agp texture*/
329 savageScreen->texVirtual[SAVAGE_AGP_HEAP] =
330 (drmAddress)(gDRIPriv->agpTextures.map);
331
332
333
334 gDRIPriv->BCIcmdBuf.map = (drmAddress *)
335 ((unsigned int)gDRIPriv->registers.map+0x00010000);
336
337 imesa->MMIO_BASE = (GLuint)gDRIPriv->registers.map;
338 imesa->BCIBase= (GLuint)gDRIPriv->BCIcmdBuf.map;
339
340 savageScreen->aperture.handle = gDRIPriv->aperture.handle;
341 savageScreen->aperture.size = gDRIPriv->aperture.size;
342 if (drmMap(sPriv->fd,
343 savageScreen->aperture.handle,
344 savageScreen->aperture.size,
345 (drmAddress *)&savageScreen->aperture.map) != 0)
346 {
347 Xfree(savageScreen);
348 sPriv->private = NULL;
349 return GL_FALSE;
350 }
351
352
353
354
355
356 for(i=0;i<5;i++)
357 {
358 imesa->apertureBase[i] = ((GLuint)savageScreen->aperture.map +
359 0x01000000 * i );
360
361
362 }
363
364 {
365 volatile unsigned int * tmp;
366
367 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x850C);
368
369
370 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x48C40);
371
372
373 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x48C44);
374
375
376 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x48C48);
377
378
379
380 }
381
382 imesa->aperturePitch = gDRIPriv->aperturePitch;
383
384
385 /* change texHeap initialize to support two kind of texture heap*/
386 /* here is some parts of initialization, others in InitDriver() */
387
388 imesa->lastTexHeap = savageScreen->texVirtual[SAVAGE_AGP_HEAP] ? 2 : 1;
389
390 /*allocate texHeap for multi-tex*/
391 {
392 int i;
393
394 for(i=0;i<SAVAGE_NR_TEX_HEAPS;i++)
395 {
396 imesa->texHeap[i] = mmInit( 0, savageScreen->textureSize[i] );
397 make_empty_list(&imesa->TexObjList[i]);
398 }
399
400 make_empty_list(&imesa->SwappedOut);
401 }
402
403 imesa->hw_stencil = GL_FALSE;
404 #if HW_STENCIL
405 imesa->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
406 #endif
407 imesa->depth_scale = (imesa->savageScreen->zpp == 2) ?
408 (1.0F/0x10000):(1.0F/0x1000000);
409
410 /* Utah stuff
411 */
412 imesa->new_state = ~0;
413 imesa->RenderIndex = ~0;
414 imesa->dirty = ~0;
415 imesa->vertex_format = 0;
416 imesa->TextureMode = ctx->Texture.Unit[0].EnvMode;
417 imesa->CurrentTexObj[0] = 0;
418 imesa->CurrentTexObj[1] = 0;
419 imesa->texAge[SAVAGE_CARD_HEAP]=0;
420 imesa->texAge[SAVAGE_AGP_HEAP]=0;
421
422 /* Initialize the software rasterizer and helper modules.
423 */
424 _swrast_CreateContext( ctx );
425 _ac_CreateContext( ctx );
426 _tnl_CreateContext( ctx );
427
428 _swsetup_CreateContext( ctx );
429
430 /* Install the customized pipeline:
431 */
432 #if 0
433 _tnl_destroy_pipeline( ctx );
434 _tnl_install_pipeline( ctx, savage_pipeline );
435 #endif
436
437 /* Configure swrast to match hardware characteristics:
438 */
439 _swrast_allow_pixel_fog( ctx, GL_FALSE );
440 _swrast_allow_vertex_fog( ctx, GL_TRUE );
441
442 ctx->DriverCtx = (void *) imesa;
443 imesa->glCtx = ctx;
444 if (savageDMAInit(imesa) == GL_FALSE)
445 return GL_FALSE;
446
447 savageDDExtensionsInit( ctx );
448
449 savageDDInitStateFuncs( ctx );
450 savageDDInitSpanFuncs( ctx );
451 savageDDInitDriverFuncs( ctx );
452 savageDDInitIoctlFuncs( ctx );
453 savageInitTriFuncs( ctx );
454
455 savageInitVB( ctx );
456 savageDDInitState( imesa );
457
458 driContextPriv->driverPrivate = (void *) imesa;
459
460 return GL_TRUE;
461 }
462
463 static void
464 savageDestroyContext(__DRIcontextPrivate *driContextPriv)
465 {
466 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
467
468 assert (imesa); /* should never be NULL */
469 if (imesa) {
470 savageTextureObjectPtr next_t, t;
471
472 /* update for multi-tex*/
473 {
474 int i;
475 for(i=0;i<SAVAGE_NR_TEX_HEAPS;i++)
476 foreach_s (t, next_t, &(imesa->TexObjList[i]))
477 savageDestroyTexObj(imesa, t);
478 }
479 foreach_s (t, next_t, &(imesa->SwappedOut))
480 savageDestroyTexObj(imesa, t);
481 /*free the dma buffer*/
482 savageDMAClose(imesa);
483 _swsetup_DestroyContext(imesa->glCtx );
484 _tnl_DestroyContext( imesa->glCtx );
485 _ac_DestroyContext( imesa->glCtx );
486 _swrast_DestroyContext( imesa->glCtx );
487
488 savageFreeVB( imesa->glCtx );
489
490 /* free the Mesa context */
491 imesa->glCtx->DriverCtx = NULL;
492 _mesa_destroy_context(imesa->glCtx);
493
494 /* no longer use vertex_dma_buf*/
495 Xfree(imesa);
496 }
497 }
498
499 static GLboolean
500 savageCreateBuffer( __DRIscreenPrivate *driScrnPriv,
501 __DRIdrawablePrivate *driDrawPriv,
502 const __GLcontextModes *mesaVis,
503 GLboolean isPixmap)
504 {
505 if (isPixmap) {
506 return GL_FALSE; /* not implemented */
507 }
508 else {
509 #if HW_STENCIL
510 GLboolean swStencil = mesaVis->stencilBits > 0 && mesaVis->depthBits != 24;
511 #else
512 GLboolean swStencil = mesaVis->stencilBits > 0;
513 #endif
514 driDrawPriv->driverPrivate = (void *)
515 _mesa_create_framebuffer(mesaVis,
516 GL_FALSE, /* software depth buffer? */
517 swStencil,
518 mesaVis->accumRedBits > 0,
519 mesaVis->alphaBits > 0 );
520
521 return (driDrawPriv->driverPrivate != NULL);
522 }
523 }
524
525 static void
526 savageDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
527 {
528 _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
529 }
530
531 #if 0
532 void XMesaSwapBuffers(__DRIdrawablePrivate *driDrawPriv)
533 {
534 /* XXX should do swap according to the buffer, not the context! */
535 savageContextPtr imesa = savageCtx;
536
537 FLUSH_VB( imesa->glCtx, "swap buffers" );
538 savageSwapBuffers(imesa);
539 }
540 #endif
541
542 void savageXMesaSetFrontClipRects( savageContextPtr imesa )
543 {
544 __DRIdrawablePrivate *dPriv = imesa->driDrawable;
545
546 imesa->numClipRects = dPriv->numClipRects;
547 imesa->pClipRects = dPriv->pClipRects;
548 imesa->dirty |= SAVAGE_UPLOAD_CLIPRECTS;
549 imesa->drawX = dPriv->x;
550 imesa->drawY = dPriv->y;
551
552 savageEmitDrawingRectangle( imesa );
553 }
554
555
556 void savageXMesaSetBackClipRects( savageContextPtr imesa )
557 {
558 __DRIdrawablePrivate *dPriv = imesa->driDrawable;
559
560 if (dPriv->numBackClipRects == 0)
561 {
562
563
564 imesa->numClipRects = dPriv->numClipRects;
565 imesa->pClipRects = dPriv->pClipRects;
566 imesa->drawX = dPriv->x;
567 imesa->drawY = dPriv->y;
568 } else {
569
570
571 imesa->numClipRects = dPriv->numBackClipRects;
572 imesa->pClipRects = dPriv->pBackClipRects;
573 imesa->drawX = dPriv->backX;
574 imesa->drawY = dPriv->backY;
575 }
576
577 savageEmitDrawingRectangle( imesa );
578 imesa->dirty |= SAVAGE_UPLOAD_CLIPRECTS;
579
580
581 }
582
583
584 static void savageXMesaWindowMoved( savageContextPtr imesa )
585 {
586 if (0)
587 fprintf(stderr, "savageXMesaWindowMoved\n\n");
588
589 switch (imesa->glCtx->Color._DrawDestMask) {
590 case FRONT_LEFT_BIT:
591 savageXMesaSetFrontClipRects( imesa );
592 break;
593 case BACK_LEFT_BIT:
594 savageXMesaSetBackClipRects( imesa );
595 break;
596 default:
597 break;
598 }
599 }
600
601
602 static GLboolean
603 savageUnbindContext(__DRIcontextPrivate *driContextPriv)
604 {
605 savageContextPtr savage = (savageContextPtr) driContextPriv->driverPrivate;
606 if (savage)
607 savage->dirty = ~0;
608
609 return GL_TRUE;
610 }
611
612 static GLboolean
613 savageOpenFullScreen(__DRIcontextPrivate *driContextPriv)
614 {
615
616
617
618 if (driContextPriv) {
619 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
620 imesa->IsFullScreen = GL_TRUE;
621 imesa->backup_frontOffset = imesa->savageScreen->frontOffset;
622 imesa->backup_backOffset = imesa->savageScreen->backOffset;
623 imesa->backup_frontBitmapDesc = imesa->savageScreen->frontBitmapDesc;
624 imesa->savageScreen->frontBitmapDesc = imesa->savageScreen->backBitmapDesc;
625 imesa->toggle = TARGET_BACK;
626 }
627
628 return GL_TRUE;
629 }
630
631 static GLboolean
632 savageCloseFullScreen(__DRIcontextPrivate *driContextPriv)
633 {
634
635 if (driContextPriv) {
636 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
637 WAIT_IDLE_EMPTY;
638 imesa->IsFullScreen = GL_FALSE;
639 imesa->savageScreen->frontOffset = imesa->backup_frontOffset;
640 imesa->savageScreen->backOffset = imesa->backup_backOffset;
641 imesa->savageScreen->frontBitmapDesc = imesa->backup_frontBitmapDesc;
642 }
643 return GL_TRUE;
644 }
645
646
647 static GLboolean
648 savageMakeCurrent(__DRIcontextPrivate *driContextPriv,
649 __DRIdrawablePrivate *driDrawPriv,
650 __DRIdrawablePrivate *driReadPriv)
651 {
652 if (driContextPriv) {
653 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
654
655 imesa->driReadable = driReadPriv;
656 imesa->driDrawable = driDrawPriv;
657 imesa->mesa_drawable = driDrawPriv;
658 imesa->dirty = ~0;
659
660 _mesa_make_current2(imesa->glCtx,
661 (GLframebuffer *) driDrawPriv->driverPrivate,
662 (GLframebuffer *) driReadPriv->driverPrivate);
663
664 savageXMesaWindowMoved( imesa );
665
666 if (!imesa->glCtx->Viewport.Width)
667 _mesa_set_viewport(imesa->glCtx, 0, 0,
668 driDrawPriv->w, driDrawPriv->h);
669 }
670 else
671 {
672 _mesa_make_current(NULL, NULL);
673 }
674 return GL_TRUE;
675 }
676
677
678 void savageGetLock( savageContextPtr imesa, GLuint flags )
679 {
680 __DRIdrawablePrivate *dPriv = imesa->driDrawable;
681 __DRIscreenPrivate *sPriv = imesa->driScreen;
682 drm_savage_sarea_t *sarea = imesa->sarea;
683 int me = imesa->hHWContext;
684 int stamp = dPriv->lastStamp;
685 int heap;
686
687
688
689 /* We know there has been contention.
690 */
691 drmGetLock(imesa->driFd, imesa->hHWContext, flags);
692
693
694 /* Note contention for throttling hint
695 */
696 imesa->any_contend = 1;
697
698 /* If the window moved, may need to set a new cliprect now.
699 *
700 * NOTE: This releases and regains the hw lock, so all state
701 * checking must be done *after* this call:
702 */
703 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
704
705
706
707
708 /* If we lost context, need to dump all registers to hardware.
709 * Note that we don't care about 2d contexts, even if they perform
710 * accelerated commands, so the DRI locking in the X server is even
711 * more broken than usual.
712 */
713 if (sarea->ctxOwner != me) {
714 imesa->dirty |= (SAVAGE_UPLOAD_CTX |
715 SAVAGE_UPLOAD_CLIPRECTS |
716 SAVAGE_UPLOAD_TEX0 |
717 SAVAGE_UPLOAD_TEX1);
718 imesa->Registers.changed.uiRegistersChanged = __HW_ALL_CHANGED;
719 sarea->ctxOwner = me;
720 }
721
722 /* Shared texture managment - if another client has played with
723 * texture space, figure out which if any of our textures have been
724 * ejected, and update our global LRU.
725 */
726 /*frank just for compiling,texAge,texList,AGP*/
727
728 for(heap= 0 ;heap < imesa->lastTexHeap ; heap++)
729 {
730 if (sarea->texAge[heap] != imesa->texAge[heap]) {
731 int sz = 1 << (imesa->savageScreen->logTextureGranularity[heap]);
732 int idx, nr = 0;
733
734 /* Have to go right round from the back to ensure stuff ends up
735 * LRU in our local list...
736 */
737 for (idx = sarea->texList[heap][SAVAGE_NR_TEX_REGIONS].prev ;
738 idx != SAVAGE_NR_TEX_REGIONS && nr < SAVAGE_NR_TEX_REGIONS ;
739 idx = sarea->texList[heap][idx].prev, nr++)
740 {
741 if (sarea->texList[heap][idx].age > imesa->texAge[heap])
742 {
743 savageTexturesGone(imesa, heap ,idx * sz, sz,
744 sarea->texList[heap][idx].in_use);
745 }
746 }
747
748 if (nr == SAVAGE_NR_TEX_REGIONS)
749 {
750 savageTexturesGone(imesa, heap, 0,
751 imesa->savageScreen->textureSize[heap], 0);
752 savageResetGlobalLRU( imesa , heap );
753 }
754
755 imesa->dirty |= SAVAGE_UPLOAD_TEX0IMAGE;
756 imesa->dirty |= SAVAGE_UPLOAD_TEX1IMAGE;
757 imesa->texAge[heap] = sarea->texAge[heap];
758 }
759 } /* end of for loop */
760
761 if (dPriv->lastStamp != stamp)
762 savageXMesaWindowMoved( imesa );
763
764
765
766 }
767
768
769
770 static const struct __DriverAPIRec savageAPI = {
771 savageInitDriver,
772 savageDestroyScreen,
773 savageCreateContext,
774 savageDestroyContext,
775 savageCreateBuffer,
776 savageDestroyBuffer,
777 savageSwapBuffers,
778 savageMakeCurrent,
779 savageUnbindContext,
780 savageOpenFullScreen,
781 savageCloseFullScreen
782 };
783
784
785
786 /*
787 * This is the bootstrap function for the driver.
788 * The __driCreateScreen name is the symbol that libGL.so fetches.
789 * Return: pointer to a __DRIscreenPrivate.
790 */
791 void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
792 int numConfigs, __GLXvisualConfig *config)
793 {
794 __DRIscreenPrivate *psp;
795 psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &savageAPI);
796 return (void *) psp;
797 }
798
799
800 #endif