uint*t -> u_int*t
[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 "utils.h"
38
39 #include "swrast/swrast.h"
40 #include "swrast_setup/swrast_setup.h"
41 #include "tnl/tnl.h"
42 #include "array_cache/acache.h"
43
44 #include "tnl/t_pipeline.h"
45
46 #include "drivers/common/driverfuncs.h"
47
48 #include "savagedd.h"
49 #include "savagestate.h"
50 #include "savagetex.h"
51 #include "savagespan.h"
52 #include "savagetris.h"
53 #include "savageioctl.h"
54 #include "savage_bci.h"
55
56 #include "savage_dri.h"
57
58 #include "savagedma.h"
59
60 #ifdef USE_NEW_INTERFACE
61 static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
62 #endif /* USE_NEW_INTERFACE */
63
64 #ifndef SAVAGE_DEBUG
65 int SAVAGE_DEBUG = (0
66 /* | DEBUG_ALWAYS_SYNC */
67 /* | DEBUG_VERBOSE_RING */
68 /* | DEBUG_VERBOSE_OUTREG */
69 /* | DEBUG_VERBOSE_MSG */
70 /* | DEBUG_NO_OUTRING */
71 /* | DEBUG_NO_OUTREG */
72 /* | DEBUG_VERBOSE_API */
73 /* | DEBUG_VERBOSE_2D */
74 /* | DEBUG_VERBOSE_DRI */
75 /* | DEBUG_VALIDATE_RING */
76 /* | DEBUG_VERBOSE_IOCTL */
77 );
78 #endif
79
80
81 /*For time caculating test*/
82 #if defined(DEBUG_TIME) && DEBUG_TIME
83 struct timeval tv_s,tv_f;
84 unsigned long time_sum=0;
85 struct timeval tv_s1,tv_f1;
86 #endif
87
88 static const char *const card_extensions[] =
89 {
90 "GL_ARB_multitexture",
91 "GL_EXT_texture_lod_bias",
92 "GL_EXT_texture_env_add",
93 NULL
94 };
95
96 /* this is first function called in dirver*/
97
98 static GLboolean
99 savageInitDriver(__DRIscreenPrivate *sPriv)
100 {
101 savageScreenPrivate *savageScreen;
102 SAVAGEDRIPtr gDRIPriv = (SAVAGEDRIPtr)sPriv->pDevPriv;
103
104
105 /* Allocate the private area */
106 savageScreen = (savageScreenPrivate *)Xmalloc(sizeof(savageScreenPrivate));
107 if (!savageScreen)
108 return GL_FALSE;
109
110 savageScreen->driScrnPriv = sPriv;
111 sPriv->private = (void *)savageScreen;
112
113 savageScreen->chipset=gDRIPriv->chipset;
114 savageScreen->width=gDRIPriv->width;
115 savageScreen->height=gDRIPriv->height;
116 savageScreen->mem=gDRIPriv->mem;
117 savageScreen->cpp=gDRIPriv->cpp;
118 savageScreen->zpp=gDRIPriv->zpp;
119 savageScreen->frontPitch=gDRIPriv->frontPitch;
120 savageScreen->frontOffset=gDRIPriv->frontOffset;
121 savageScreen->frontBitmapDesc = gDRIPriv->frontBitmapDesc;
122
123 if (gDRIPriv->cpp == 4)
124 savageScreen->frontFormat = DV_PF_8888;
125 else
126 savageScreen->frontFormat = DV_PF_565;
127
128 savageScreen->backOffset = gDRIPriv->backOffset;
129 savageScreen->backBitmapDesc = gDRIPriv->backBitmapDesc;
130 savageScreen->depthOffset=gDRIPriv->depthOffset;
131 savageScreen->depthBitmapDesc = gDRIPriv->depthBitmapDesc;
132 #if 0
133 savageScreen->backPitch = gDRIPriv->auxPitch;
134 savageScreen->backPitchBits = gDRIPriv->auxPitchBits;
135 #endif
136 savageScreen->textureOffset[SAVAGE_CARD_HEAP] =
137 gDRIPriv->textureOffset;
138 savageScreen->textureSize[SAVAGE_CARD_HEAP] =
139 gDRIPriv->textureSize;
140 savageScreen->logTextureGranularity[SAVAGE_CARD_HEAP] =
141 gDRIPriv->logTextureGranularity;
142
143 savageScreen->textureOffset[SAVAGE_AGP_HEAP] =
144 gDRIPriv->agpTextures.handle;
145 savageScreen->textureSize[SAVAGE_AGP_HEAP] =
146 gDRIPriv->agpTextures.size;
147 savageScreen->logTextureGranularity[SAVAGE_AGP_HEAP] =
148 gDRIPriv->logAgpTextureGranularity;
149
150 savageScreen->back.handle = gDRIPriv->backbuffer;
151 savageScreen->back.size = gDRIPriv->backbufferSize;
152 savageScreen->back.map =
153 (drmAddress)(((unsigned int)sPriv->pFB)+gDRIPriv->backOffset);
154
155 savageScreen->depth.handle = gDRIPriv->depthbuffer;
156 savageScreen->depth.size = gDRIPriv->depthbufferSize;
157
158 savageScreen->depth.map =
159 (drmAddress)(((unsigned int)sPriv->pFB)+gDRIPriv->depthOffset);
160
161 savageScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
162
163 savageScreen->texVirtual[SAVAGE_CARD_HEAP] =
164 (drmAddress)(((unsigned int)sPriv->pFB)+gDRIPriv->textureOffset);
165 #if 0
166 savageDDFastPathInit();
167 savageDDTrifuncInit();
168 savageDDSetupInit();
169 #endif
170 return GL_TRUE;
171 }
172
173 /* Accessed by dlsym from dri_mesa_init.c
174 */
175 static void
176 savageDestroyScreen(__DRIscreenPrivate *sPriv)
177 {
178 savageScreenPrivate *savageScreen = (savageScreenPrivate *)sPriv->private;
179
180
181 Xfree(savageScreen);
182 sPriv->private = NULL;
183 }
184
185 #if 0
186 GLvisual *XMesaCreateVisual(Display *dpy,
187 __DRIscreenPrivate *driScrnPriv,
188 const XVisualInfo *visinfo,
189 const __GLXvisualConfig *config)
190 {
191 /* Drivers may change the args to _mesa_create_visual() in order to
192 * setup special visuals.
193 */
194 return _mesa_create_visual( config->rgba,
195 config->doubleBuffer,
196 config->stereo,
197 _mesa_bitcount(visinfo->red_mask),
198 _mesa_bitcount(visinfo->green_mask),
199 _mesa_bitcount(visinfo->blue_mask),
200 config->alphaSize,
201 0, /* index bits */
202 config->depthSize,
203 config->stencilSize,
204 config->accumRedSize,
205 config->accumGreenSize,
206 config->accumBlueSize,
207 config->accumAlphaSize,
208 0 /* num samples */ );
209 }
210 #endif
211
212
213 static GLboolean
214 savageCreateContext( const __GLcontextModes *mesaVis,
215 __DRIcontextPrivate *driContextPriv,
216 void *sharedContextPrivate )
217 {
218 GLcontext *ctx, *shareCtx;
219 savageContextPtr imesa;
220 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
221 struct dd_function_table functions;
222 SAVAGEDRIPtr gDRIPriv = (SAVAGEDRIPtr)sPriv->pDevPriv;
223 savageScreenPrivate *savageScreen = (savageScreenPrivate *)sPriv->private;
224 drm_savage_sarea_t *saPriv=(drm_savage_sarea_t *)(((char*)sPriv->pSAREA)+
225 savageScreen->sarea_priv_offset);
226 GLuint maxTextureSize, minTextureSize, maxTextureLevels;
227 int i;
228 imesa = (savageContextPtr)Xcalloc(sizeof(savageContext), 1);
229 if (!imesa) {
230 return GL_FALSE;
231 }
232
233 /* Init default driver functions then plug in savage-specific texture
234 * functions that are needed as early as during context creation. */
235 _mesa_init_driver_functions( &functions );
236 savageDDInitTextureFuncs( &functions );
237
238 /* Allocate the Mesa context */
239 if (sharedContextPrivate)
240 shareCtx = ((savageContextPtr) sharedContextPrivate)->glCtx;
241 else
242 shareCtx = NULL;
243 ctx = _mesa_create_context(mesaVis, shareCtx, &functions, imesa);
244 if (!ctx) {
245 Xfree(imesa);
246 return GL_FALSE;
247 }
248 driContextPriv->driverPrivate = imesa;
249
250 if (savageScreen->chipset >= S3_SAVAGE4)
251 ctx->Const.MaxTextureUnits = 2;
252 else
253 ctx->Const.MaxTextureUnits = 1;
254 ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
255 ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
256
257 /* Set the maximum texture size small enough that we can guarentee
258 * that all texture units can bind a maximal texture and have them
259 * in memory at once.
260 */
261 if (savageScreen->textureSize[SAVAGE_CARD_HEAP] >
262 savageScreen->textureSize[SAVAGE_AGP_HEAP]) {
263 maxTextureSize = savageScreen->textureSize[SAVAGE_CARD_HEAP];
264 minTextureSize = savageScreen->textureSize[SAVAGE_AGP_HEAP];
265 } else {
266 maxTextureSize = savageScreen->textureSize[SAVAGE_AGP_HEAP];
267 minTextureSize = savageScreen->textureSize[SAVAGE_CARD_HEAP];
268 }
269 if (ctx->Const.MaxTextureUnits == 2) {
270 /* How to distribute two maximum sized textures to two texture heaps?
271 * If the smaller heap is less then half the size of the bigger one
272 * then the maximum size is half the size of the bigger heap.
273 * Otherwise it's the size of the smaller heap. */
274 if (minTextureSize < maxTextureSize / 2)
275 maxTextureSize = maxTextureSize / 2;
276 else
277 maxTextureSize = minTextureSize;
278 }
279 for (maxTextureLevels = 1; maxTextureLevels <= 11; ++maxTextureLevels) {
280 GLuint size = 1 << maxTextureLevels;
281 size *= size * 4; /* 4 bytes per texel */
282 size *= 2; /* all mipmap levels together take roughly twice the size of
283 the biggest level */
284 if (size > maxTextureSize)
285 break;
286 }
287 ctx->Const.MaxTextureLevels = maxTextureLevels;
288 assert (ctx->Const.MaxTextureLevels > 6); /*spec requires at least 64x64*/
289
290 #if 0
291 ctx->Const.MinLineWidth = 1.0;
292 ctx->Const.MinLineWidthAA = 1.0;
293 ctx->Const.MaxLineWidth = 3.0;
294 ctx->Const.MaxLineWidthAA = 3.0;
295 ctx->Const.LineWidthGranularity = 1.0;
296 #endif
297
298 /* Dri stuff
299 */
300 imesa->hHWContext = driContextPriv->hHWContext;
301 imesa->driFd = sPriv->fd;
302 imesa->driHwLock = &sPriv->pSAREA->lock;
303
304 imesa->savageScreen = savageScreen;
305 imesa->driScreen = sPriv;
306 imesa->sarea = saPriv;
307 imesa->glBuffer = NULL;
308
309 /* DMA buffer */
310
311 /*The shadow pointer*/
312 imesa->shadowPointer =
313 (volatile GLuint *)((((GLuint)(&saPriv->shadow_status)) + 31) & 0xffffffe0L) ;
314 /* here we use eventTag1 because eventTag0 is used by HWXvMC*/
315 imesa->eventTag1 = (volatile GLuint *)(imesa->shadowPointer + 6);
316 /* imesa->eventTag1=(volatile GLuint *)(imesa->MMIO_BASE+0x48c04);*/
317 imesa->shadowCounter = MAX_SHADOWCOUNTER;
318 imesa->shadowStatus = GL_TRUE;/*Will judge by 2d message */
319
320 if (drmMap(sPriv->fd,
321 gDRIPriv->registers.handle,
322 gDRIPriv->registers.size,
323 (drmAddress *)&(gDRIPriv->registers.map)) != 0)
324 {
325 Xfree(savageScreen);
326 sPriv->private = NULL;
327 return GL_FALSE;
328 }
329
330 if (drmMap(sPriv->fd,
331 gDRIPriv->agpTextures.handle,
332 gDRIPriv->agpTextures.size,
333 (drmAddress *)&(gDRIPriv->agpTextures.map)) != 0)
334 {
335 Xfree(savageScreen);
336 sPriv->private = NULL;
337 return GL_FALSE;
338 }
339
340 /* agp texture*/
341 savageScreen->texVirtual[SAVAGE_AGP_HEAP] =
342 (drmAddress)(gDRIPriv->agpTextures.map);
343
344
345
346 gDRIPriv->BCIcmdBuf.map = (drmAddress *)
347 ((unsigned int)gDRIPriv->registers.map+0x00010000);
348
349 imesa->MMIO_BASE = (GLuint)gDRIPriv->registers.map;
350 imesa->BCIBase= (GLuint)gDRIPriv->BCIcmdBuf.map;
351
352 savageScreen->aperture.handle = gDRIPriv->aperture.handle;
353 savageScreen->aperture.size = gDRIPriv->aperture.size;
354 if (drmMap(sPriv->fd,
355 savageScreen->aperture.handle,
356 savageScreen->aperture.size,
357 (drmAddress *)&savageScreen->aperture.map) != 0)
358 {
359 Xfree(savageScreen);
360 sPriv->private = NULL;
361 return GL_FALSE;
362 }
363
364
365
366
367
368 for(i=0;i<5;i++)
369 {
370 imesa->apertureBase[i] = ((GLuint)savageScreen->aperture.map +
371 0x01000000 * i );
372
373
374 }
375
376 {
377 volatile unsigned int * tmp;
378
379 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x850C);
380
381
382 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x48C40);
383
384
385 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x48C44);
386
387
388 tmp=(volatile unsigned int *)(imesa->MMIO_BASE + 0x48C48);
389
390
391
392 }
393
394 imesa->aperturePitch = gDRIPriv->aperturePitch;
395
396
397 /* change texHeap initialize to support two kind of texture heap*/
398 /* here is some parts of initialization, others in InitDriver() */
399
400 imesa->lastTexHeap = savageScreen->texVirtual[SAVAGE_AGP_HEAP] ? 2 : 1;
401
402 /*allocate texHeap for multi-tex*/
403 {
404 int i;
405
406 for(i=0;i<SAVAGE_NR_TEX_HEAPS;i++)
407 {
408 imesa->texHeap[i] = mmInit( 0, savageScreen->textureSize[i] );
409 make_empty_list(&imesa->TexObjList[i]);
410 }
411
412 make_empty_list(&imesa->SwappedOut);
413 }
414
415 imesa->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
416 imesa->depth_scale = (imesa->savageScreen->zpp == 2) ?
417 (1.0F/0x10000):(1.0F/0x1000000);
418
419 imesa->vertex_dma_buffer = NULL;
420
421 /* Uninitialized vertex format. Force setting the vertex state in
422 * savageRenderStart.
423 */
424 imesa->vertex_size = 0;
425
426 /* Utah stuff
427 */
428 imesa->new_state = ~0;
429 imesa->RenderIndex = ~0;
430 imesa->dirty = ~0;
431 imesa->lostContext = GL_TRUE;
432 imesa->TextureMode = ctx->Texture.Unit[0].EnvMode;
433 imesa->CurrentTexObj[0] = 0;
434 imesa->CurrentTexObj[1] = 0;
435 imesa->texAge[SAVAGE_CARD_HEAP]=0;
436 imesa->texAge[SAVAGE_AGP_HEAP]=0;
437
438 /* Initialize the software rasterizer and helper modules.
439 */
440 _swrast_CreateContext( ctx );
441 _ac_CreateContext( ctx );
442 _tnl_CreateContext( ctx );
443
444 _swsetup_CreateContext( ctx );
445
446 /* Install the customized pipeline:
447 */
448 #if 0
449 _tnl_destroy_pipeline( ctx );
450 _tnl_install_pipeline( ctx, savage_pipeline );
451 #endif
452
453 /* Configure swrast to match hardware characteristics:
454 */
455 _tnl_allow_pixel_fog( ctx, GL_FALSE );
456 _tnl_allow_vertex_fog( ctx, GL_TRUE );
457 _swrast_allow_pixel_fog( ctx, GL_FALSE );
458 _swrast_allow_vertex_fog( ctx, GL_TRUE );
459
460 ctx->DriverCtx = (void *) imesa;
461 imesa->glCtx = ctx;
462 if (savageDMAInit(imesa) == GL_FALSE)
463 return GL_FALSE;
464
465 driInitExtensions( ctx, card_extensions, GL_TRUE );
466
467 savageDDInitStateFuncs( ctx );
468 savageDDInitSpanFuncs( ctx );
469 savageDDInitDriverFuncs( ctx );
470 savageDDInitIoctlFuncs( ctx );
471 savageInitTriFuncs( ctx );
472
473 savageDDInitState( imesa );
474
475 driContextPriv->driverPrivate = (void *) imesa;
476
477 return GL_TRUE;
478 }
479
480 static void
481 savageDestroyContext(__DRIcontextPrivate *driContextPriv)
482 {
483 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
484
485 assert (imesa); /* should never be NULL */
486 if (imesa) {
487 savageTextureObjectPtr next_t, t;
488
489 FLUSH_BATCH(imesa);
490
491 /* update for multi-tex*/
492 {
493 int i;
494 for(i=0;i<SAVAGE_NR_TEX_HEAPS;i++)
495 foreach_s (t, next_t, &(imesa->TexObjList[i]))
496 savageDestroyTexObj(imesa, t);
497 }
498 foreach_s (t, next_t, &(imesa->SwappedOut))
499 savageDestroyTexObj(imesa, t);
500 /*free the dma buffer*/
501 savageDMAClose(imesa);
502 _swsetup_DestroyContext(imesa->glCtx );
503 _tnl_DestroyContext( imesa->glCtx );
504 _ac_DestroyContext( imesa->glCtx );
505 _swrast_DestroyContext( imesa->glCtx );
506
507 /* free the Mesa context */
508 imesa->glCtx->DriverCtx = NULL;
509 _mesa_destroy_context(imesa->glCtx);
510
511 /* no longer use vertex_dma_buf*/
512 Xfree(imesa);
513 }
514 }
515
516 static GLboolean
517 savageCreateBuffer( __DRIscreenPrivate *driScrnPriv,
518 __DRIdrawablePrivate *driDrawPriv,
519 const __GLcontextModes *mesaVis,
520 GLboolean isPixmap)
521 {
522 if (isPixmap) {
523 return GL_FALSE; /* not implemented */
524 }
525 else {
526 GLboolean swStencil = mesaVis->stencilBits > 0 && mesaVis->depthBits != 24;
527 driDrawPriv->driverPrivate = (void *)
528 _mesa_create_framebuffer(mesaVis,
529 GL_FALSE, /* software depth buffer? */
530 swStencil,
531 mesaVis->accumRedBits > 0,
532 mesaVis->alphaBits > 0 );
533
534 return (driDrawPriv->driverPrivate != NULL);
535 }
536 }
537
538 static void
539 savageDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
540 {
541 _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
542 }
543
544 #if 0
545 void XMesaSwapBuffers(__DRIdrawablePrivate *driDrawPriv)
546 {
547 /* XXX should do swap according to the buffer, not the context! */
548 savageContextPtr imesa = savageCtx;
549
550 FLUSH_VB( imesa->glCtx, "swap buffers" );
551 savageSwapBuffers(imesa);
552 }
553 #endif
554
555 void savageXMesaSetFrontClipRects( savageContextPtr imesa )
556 {
557 __DRIdrawablePrivate *dPriv = imesa->driDrawable;
558
559 imesa->numClipRects = dPriv->numClipRects;
560 imesa->pClipRects = dPriv->pClipRects;
561 imesa->dirty |= SAVAGE_UPLOAD_CLIPRECTS;
562 imesa->drawX = dPriv->x;
563 imesa->drawY = dPriv->y;
564
565 savageEmitDrawingRectangle( imesa );
566 }
567
568
569 void savageXMesaSetBackClipRects( savageContextPtr imesa )
570 {
571 __DRIdrawablePrivate *dPriv = imesa->driDrawable;
572
573 if (dPriv->numBackClipRects == 0)
574 {
575
576
577 imesa->numClipRects = dPriv->numClipRects;
578 imesa->pClipRects = dPriv->pClipRects;
579 imesa->drawX = dPriv->x;
580 imesa->drawY = dPriv->y;
581 } else {
582
583
584 imesa->numClipRects = dPriv->numBackClipRects;
585 imesa->pClipRects = dPriv->pBackClipRects;
586 imesa->drawX = dPriv->backX;
587 imesa->drawY = dPriv->backY;
588 }
589
590 savageEmitDrawingRectangle( imesa );
591 imesa->dirty |= SAVAGE_UPLOAD_CLIPRECTS;
592
593
594 }
595
596
597 static void savageXMesaWindowMoved( savageContextPtr imesa )
598 {
599 if (0)
600 fprintf(stderr, "savageXMesaWindowMoved\n\n");
601
602 switch (imesa->glCtx->Color._DrawDestMask[0]) {
603 case DD_FRONT_LEFT_BIT:
604 savageXMesaSetFrontClipRects( imesa );
605 break;
606 case DD_BACK_LEFT_BIT:
607 savageXMesaSetBackClipRects( imesa );
608 break;
609 default:
610 break;
611 }
612 }
613
614
615 static GLboolean
616 savageUnbindContext(__DRIcontextPrivate *driContextPriv)
617 {
618 savageContextPtr savage = (savageContextPtr) driContextPriv->driverPrivate;
619 if (savage)
620 savage->dirty = ~0;
621
622 return GL_TRUE;
623 }
624
625 #if 0
626 static GLboolean
627 savageOpenFullScreen(__DRIcontextPrivate *driContextPriv)
628 {
629
630
631
632 if (driContextPriv) {
633 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
634 imesa->IsFullScreen = GL_TRUE;
635 imesa->backup_frontOffset = imesa->savageScreen->frontOffset;
636 imesa->backup_backOffset = imesa->savageScreen->backOffset;
637 imesa->backup_frontBitmapDesc = imesa->savageScreen->frontBitmapDesc;
638 imesa->savageScreen->frontBitmapDesc = imesa->savageScreen->backBitmapDesc;
639 imesa->toggle = TARGET_BACK;
640 }
641
642 return GL_TRUE;
643 }
644
645 static GLboolean
646 savageCloseFullScreen(__DRIcontextPrivate *driContextPriv)
647 {
648
649 if (driContextPriv) {
650 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
651 WAIT_IDLE_EMPTY;
652 imesa->IsFullScreen = GL_FALSE;
653 imesa->savageScreen->frontOffset = imesa->backup_frontOffset;
654 imesa->savageScreen->backOffset = imesa->backup_backOffset;
655 imesa->savageScreen->frontBitmapDesc = imesa->backup_frontBitmapDesc;
656 }
657 return GL_TRUE;
658 }
659 #endif
660
661 static GLboolean
662 savageMakeCurrent(__DRIcontextPrivate *driContextPriv,
663 __DRIdrawablePrivate *driDrawPriv,
664 __DRIdrawablePrivate *driReadPriv)
665 {
666 if (driContextPriv) {
667 savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
668
669 imesa->driReadable = driReadPriv;
670 imesa->driDrawable = driDrawPriv;
671 imesa->mesa_drawable = driDrawPriv;
672 imesa->dirty = ~0;
673
674 _mesa_make_current2(imesa->glCtx,
675 (GLframebuffer *) driDrawPriv->driverPrivate,
676 (GLframebuffer *) driReadPriv->driverPrivate);
677
678 savageXMesaWindowMoved( imesa );
679 }
680 else
681 {
682 _mesa_make_current(NULL, NULL);
683 }
684 return GL_TRUE;
685 }
686
687
688 void savageGetLock( savageContextPtr imesa, GLuint flags )
689 {
690 __DRIdrawablePrivate *dPriv = imesa->driDrawable;
691 __DRIscreenPrivate *sPriv = imesa->driScreen;
692 drm_savage_sarea_t *sarea = imesa->sarea;
693 int me = imesa->hHWContext;
694 int stamp = dPriv->lastStamp;
695 int heap;
696
697
698
699 /* We know there has been contention.
700 */
701 drmGetLock(imesa->driFd, imesa->hHWContext, flags);
702
703
704 /* Note contention for throttling hint
705 */
706 imesa->any_contend = 1;
707
708 /* If the window moved, may need to set a new cliprect now.
709 *
710 * NOTE: This releases and regains the hw lock, so all state
711 * checking must be done *after* this call:
712 */
713 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
714
715
716
717
718 /* If we lost context, need to dump all registers to hardware.
719 * Note that we don't care about 2d contexts, even if they perform
720 * accelerated commands, so the DRI locking in the X server is even
721 * more broken than usual.
722 */
723 if (sarea->ctxOwner != me) {
724 imesa->dirty |= (SAVAGE_UPLOAD_CTX |
725 SAVAGE_UPLOAD_CLIPRECTS |
726 SAVAGE_UPLOAD_TEX0 |
727 SAVAGE_UPLOAD_TEX1);
728 imesa->lostContext = GL_TRUE;
729 sarea->ctxOwner = me;
730 }
731
732 /* Shared texture managment - if another client has played with
733 * texture space, figure out which if any of our textures have been
734 * ejected, and update our global LRU.
735 */
736 /*frank just for compiling,texAge,texList,AGP*/
737
738 for(heap= 0 ;heap < imesa->lastTexHeap ; heap++)
739 {
740 if (sarea->texAge[heap] != imesa->texAge[heap]) {
741 int sz = 1 << (imesa->savageScreen->logTextureGranularity[heap]);
742 int idx, nr = 0;
743
744 /* Have to go right round from the back to ensure stuff ends up
745 * LRU in our local list...
746 */
747 for (idx = sarea->texList[heap][SAVAGE_NR_TEX_REGIONS].prev ;
748 idx != SAVAGE_NR_TEX_REGIONS && nr < SAVAGE_NR_TEX_REGIONS ;
749 idx = sarea->texList[heap][idx].prev, nr++)
750 {
751 if (sarea->texList[heap][idx].age > imesa->texAge[heap])
752 {
753 savageTexturesGone(imesa, heap ,idx * sz, sz,
754 sarea->texList[heap][idx].in_use);
755 }
756 }
757
758 if (nr == SAVAGE_NR_TEX_REGIONS)
759 {
760 savageTexturesGone(imesa, heap, 0,
761 imesa->savageScreen->textureSize[heap], 0);
762 savageResetGlobalLRU( imesa , heap );
763 }
764
765 imesa->dirty |= SAVAGE_UPLOAD_TEX0IMAGE;
766 imesa->dirty |= SAVAGE_UPLOAD_TEX1IMAGE;
767 imesa->texAge[heap] = sarea->texAge[heap];
768 }
769 } /* end of for loop */
770
771 if (dPriv->lastStamp != stamp)
772 savageXMesaWindowMoved( imesa );
773
774
775
776 }
777
778
779
780 static const struct __DriverAPIRec savageAPI = {
781 savageInitDriver,
782 savageDestroyScreen,
783 savageCreateContext,
784 savageDestroyContext,
785 savageCreateBuffer,
786 savageDestroyBuffer,
787 savageSwapBuffers,
788 savageMakeCurrent,
789 savageUnbindContext
790 };
791
792
793
794 #ifndef DRI_NEW_INTERFACE_ONLY
795 /*
796 * This is the (old) bootstrap function for the driver.
797 * The __driCreateScreen name is the symbol that libGL.so fetches.
798 * Return: pointer to a __DRIscreenPrivate.
799 */
800 void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
801 int numConfigs, __GLXvisualConfig *config)
802 {
803 __DRIscreenPrivate *psp;
804 psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &savageAPI);
805 return (void *) psp;
806 }
807 #endif /* DRI_NEW_INTERFACE_ONLY */
808
809
810
811 #ifdef USE_NEW_INTERFACE
812 static __GLcontextModes *
813 savageFillInModes( unsigned pixel_bits, unsigned depth_bits,
814 unsigned stencil_bits, GLboolean have_back_buffer )
815 {
816 __GLcontextModes * modes;
817 __GLcontextModes * m;
818 unsigned num_modes;
819 unsigned depth_buffer_factor;
820 unsigned back_buffer_factor;
821 GLenum fb_format;
822 GLenum fb_type;
823
824 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
825 * enough to add support. Basically, if a context is created with an
826 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
827 * will never be used.
828 *
829 * FK: What about drivers that don't use page flipping? Could they
830 * just expose GLX_SWAP_COPY_OML?
831 */
832 static const GLenum back_buffer_modes[] = {
833 GLX_NONE, GLX_SWAP_UNDEFINED_OML /*, GLX_SWAP_COPY_OML */
834 };
835
836 u_int8_t depth_bits_array[2];
837 u_int8_t stencil_bits_array[2];
838
839
840 depth_bits_array[0] = depth_bits;
841 depth_bits_array[1] = depth_bits;
842
843 /* Just like with the accumulation buffer, always provide some modes
844 * with a stencil buffer. It will be a sw fallback, but some apps won't
845 * care about that.
846 */
847 stencil_bits_array[0] = 0;
848 stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
849
850 depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 2 : 1;
851 back_buffer_factor = (have_back_buffer) ? 2 : 1;
852
853 num_modes = depth_buffer_factor * back_buffer_factor * 4;
854
855 if ( pixel_bits == 16 ) {
856 fb_format = GL_RGB;
857 fb_type = GL_UNSIGNED_SHORT_5_6_5;
858 }
859 else {
860 fb_format = GL_BGR;
861 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
862 }
863
864 modes = (*create_context_modes)( num_modes, sizeof( __GLcontextModes ) );
865 m = modes;
866 if ( ! driFillInModes( & m, fb_format, fb_type,
867 depth_bits_array, stencil_bits_array, depth_buffer_factor,
868 back_buffer_modes, back_buffer_factor,
869 GLX_TRUE_COLOR ) ) {
870 fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
871 __func__, __LINE__ );
872 return NULL;
873 }
874
875 if ( ! driFillInModes( & m, fb_format, fb_type,
876 depth_bits_array, stencil_bits_array, depth_buffer_factor,
877 back_buffer_modes, back_buffer_factor,
878 GLX_DIRECT_COLOR ) ) {
879 fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
880 __func__, __LINE__ );
881 return NULL;
882 }
883
884 /* Mark the visual as slow if there are "fake" stencil bits.
885 */
886 for ( m = modes ; m != NULL ; m = m->next ) {
887 if ( (m->stencilBits != 0) && (m->stencilBits != stencil_bits) ) {
888 m->visualRating = GLX_SLOW_CONFIG;
889 }
890 }
891
892 return modes;
893 }
894
895
896 /**
897 * This is the bootstrap function for the driver. libGL supplies all of the
898 * requisite information about the system, and the driver initializes itself.
899 * This routine also fills in the linked list pointed to by \c driver_modes
900 * with the \c __GLcontextModes that the driver can support for windows or
901 * pbuffers.
902 *
903 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
904 * failure.
905 */
906 void * __driCreateNewScreen( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc,
907 const __GLcontextModes * modes,
908 const __DRIversion * ddx_version,
909 const __DRIversion * dri_version,
910 const __DRIversion * drm_version,
911 const __DRIframebuffer * frame_buffer,
912 drmAddress pSAREA, int fd,
913 int internal_api_version,
914 __GLcontextModes ** driver_modes )
915
916 {
917 __DRIscreenPrivate *psp;
918 static const __DRIversion ddx_expected = { 1, 0, 0 };
919 static const __DRIversion dri_expected = { 4, 0, 0 };
920 static const __DRIversion drm_expected = { 1, 0, 0 };
921
922
923 if ( ! driCheckDriDdxDrmVersions2( "Savage",
924 dri_version, & dri_expected,
925 ddx_version, & ddx_expected,
926 drm_version, & drm_expected ) ) {
927 return NULL;
928 }
929
930 psp = __driUtilCreateNewScreen(dpy, scrn, psc, NULL,
931 ddx_version, dri_version, drm_version,
932 frame_buffer, pSAREA, fd,
933 internal_api_version, &savageAPI);
934 if ( psp != NULL ) {
935 create_context_modes = (PFNGLXCREATECONTEXTMODES)
936 glXGetProcAddress( (const GLubyte *) "__glXCreateContextModes" );
937 if ( create_context_modes != NULL ) {
938 SAVAGEDRIPtr dri_priv = (SAVAGEDRIPtr)psp->pDevPriv;
939 *driver_modes = savageFillInModes( dri_priv->cpp*8,
940 (dri_priv->cpp == 2) ? 16 : 24,
941 (dri_priv->cpp == 2) ? 0 : 8,
942 (dri_priv->backOffset != dri_priv->depthOffset) );
943 }
944 }
945
946 return (void *) psp;
947 }
948 #endif /* USE_NEW_INTERFACE */
949
950 #endif