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