Merge branch 'master' into autoconf2
[mesa.git] / src / mesa / drivers / dri / i965 / intel_screen.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "glheader.h"
29 #include "context.h"
30 #include "framebuffer.h"
31 #include "matrix.h"
32 #include "renderbuffer.h"
33 #include "simple_list.h"
34 #include "utils.h"
35 #include "vblank.h"
36 #include "xmlpool.h"
37
38
39 #include "intel_screen.h"
40
41 #include "intel_context.h"
42 #include "intel_tex.h"
43 #include "intel_span.h"
44 #include "intel_ioctl.h"
45 #include "intel_regions.h"
46 #include "intel_bufmgr_ttm.h"
47
48 #include "i915_drm.h"
49 #include "i830_dri.h"
50
51 PUBLIC const char __driConfigOptions[] =
52 DRI_CONF_BEGIN
53 DRI_CONF_SECTION_PERFORMANCE
54 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
55 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
56 DRI_CONF_SECTION_END
57 DRI_CONF_SECTION_QUALITY
58 DRI_CONF_FORCE_S3TC_ENABLE(false)
59 DRI_CONF_ALLOW_LARGE_TEXTURES(1)
60 DRI_CONF_SECTION_END
61 DRI_CONF_END;
62 const GLuint __driNConfigOptions = 4;
63
64 #ifdef USE_NEW_INTERFACE
65 static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
66 #endif /*USE_NEW_INTERFACE*/
67
68 /**
69 * Map all the memory regions described by the screen.
70 * \return GL_TRUE if success, GL_FALSE if error.
71 */
72 GLboolean
73 intelMapScreenRegions(__DRIscreenPrivate *sPriv)
74 {
75 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
76
77 if (intelScreen->front.handle) {
78 if (drmMap(sPriv->fd,
79 intelScreen->front.handle,
80 intelScreen->front.size,
81 (drmAddress *)&intelScreen->front.map) != 0) {
82 _mesa_problem(NULL, "drmMap(frontbuffer) failed!");
83 return GL_FALSE;
84 }
85 } else {
86 /* Use the old static allocation method if the server isn't setting up
87 * a movable handle for us. Add in the front buffer offset from
88 * framebuffer start, as our span routines (unlike other drivers) expect
89 * the renderbuffer address to point to the beginning of the
90 * renderbuffer.
91 */
92 intelScreen->front.map = (char *)sPriv->pFB;
93 if (intelScreen->front.map == NULL) {
94 fprintf(stderr, "Failed to find framebuffer mapping\n");
95 return GL_FALSE;
96 }
97 }
98
99 if (drmMap(sPriv->fd,
100 intelScreen->back.handle,
101 intelScreen->back.size,
102 (drmAddress *)&intelScreen->back.map) != 0) {
103 intelUnmapScreenRegions(intelScreen);
104 return GL_FALSE;
105 }
106
107 if (drmMap(sPriv->fd,
108 intelScreen->depth.handle,
109 intelScreen->depth.size,
110 (drmAddress *)&intelScreen->depth.map) != 0) {
111 intelUnmapScreenRegions(intelScreen);
112 return GL_FALSE;
113 }
114
115 if (drmMap(sPriv->fd,
116 intelScreen->tex.handle,
117 intelScreen->tex.size,
118 (drmAddress *)&intelScreen->tex.map) != 0) {
119 intelUnmapScreenRegions(intelScreen);
120 return GL_FALSE;
121 }
122
123 if (0)
124 printf("Mappings: front: %p back: %p depth: %p tex: %p\n",
125 intelScreen->front.map,
126 intelScreen->back.map,
127 intelScreen->depth.map,
128 intelScreen->tex.map);
129 return GL_TRUE;
130 }
131
132 void
133 intelUnmapScreenRegions(intelScreenPrivate *intelScreen)
134 {
135 #define REALLY_UNMAP 1
136 /* If front.handle is present, we're doing the dynamic front buffer mapping,
137 * but if we've fallen back to static allocation then we shouldn't try to
138 * unmap here.
139 */
140 if (intelScreen->front.handle) {
141 #if REALLY_UNMAP
142 if (drmUnmap(intelScreen->front.map, intelScreen->front.size) != 0)
143 printf("drmUnmap front failed!\n");
144 #endif
145 intelScreen->front.map = NULL;
146 }
147 if (intelScreen->back.map) {
148 #if REALLY_UNMAP
149 if (drmUnmap(intelScreen->back.map, intelScreen->back.size) != 0)
150 printf("drmUnmap back failed!\n");
151 #endif
152 intelScreen->back.map = NULL;
153 }
154 if (intelScreen->depth.map) {
155 #if REALLY_UNMAP
156 drmUnmap(intelScreen->depth.map, intelScreen->depth.size);
157 intelScreen->depth.map = NULL;
158 #endif
159 }
160 if (intelScreen->tex.map) {
161 #if REALLY_UNMAP
162 drmUnmap(intelScreen->tex.map, intelScreen->tex.size);
163 intelScreen->tex.map = NULL;
164 #endif
165 }
166 }
167
168
169 static void
170 intelPrintDRIInfo(intelScreenPrivate *intelScreen,
171 __DRIscreenPrivate *sPriv,
172 I830DRIPtr gDRIPriv)
173 {
174 fprintf(stderr, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
175 intelScreen->front.size, intelScreen->front.offset,
176 intelScreen->front.pitch);
177 fprintf(stderr, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
178 intelScreen->back.size, intelScreen->back.offset,
179 intelScreen->back.pitch);
180 fprintf(stderr, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
181 intelScreen->depth.size, intelScreen->depth.offset,
182 intelScreen->depth.pitch);
183 fprintf(stderr, "*** Rotated size: 0x%x offset: 0x%x pitch: %d\n",
184 intelScreen->rotated.size, intelScreen->rotated.offset,
185 intelScreen->rotated.pitch);
186 fprintf(stderr, "*** Texture size: 0x%x offset: 0x%x\n",
187 intelScreen->tex.size, intelScreen->tex.offset);
188 fprintf(stderr, "*** Memory : 0x%x\n", gDRIPriv->mem);
189 }
190
191
192 static void
193 intelPrintSAREA(volatile drmI830Sarea *sarea)
194 {
195 fprintf(stderr, "SAREA: sarea width %d height %d\n", sarea->width, sarea->height);
196 fprintf(stderr, "SAREA: pitch: %d\n", sarea->pitch);
197 fprintf(stderr,
198 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x\n",
199 sarea->front_offset, sarea->front_size,
200 (unsigned) sarea->front_handle);
201 fprintf(stderr,
202 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x\n",
203 sarea->back_offset, sarea->back_size,
204 (unsigned) sarea->back_handle);
205 fprintf(stderr, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x\n",
206 sarea->depth_offset, sarea->depth_size,
207 (unsigned) sarea->depth_handle);
208 fprintf(stderr, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
209 sarea->tex_offset, sarea->tex_size,
210 (unsigned) sarea->tex_handle);
211 fprintf(stderr, "SAREA: rotation: %d\n", sarea->rotation);
212 fprintf(stderr,
213 "SAREA: rotated offset: 0x%08x size: 0x%x\n",
214 sarea->rotated_offset, sarea->rotated_size);
215 fprintf(stderr, "SAREA: rotated pitch: %d\n", sarea->rotated_pitch);
216 }
217
218
219 /**
220 * A number of the screen parameters are obtained/computed from
221 * information in the SAREA. This function updates those parameters.
222 */
223 void
224 intelUpdateScreenFromSAREA(intelScreenPrivate *intelScreen,
225 volatile drmI830Sarea *sarea)
226 {
227 intelScreen->width = sarea->width;
228 intelScreen->height = sarea->height;
229
230 intelScreen->front.offset = sarea->front_offset;
231 intelScreen->front.pitch = sarea->pitch * intelScreen->cpp;
232 intelScreen->front.handle = sarea->front_handle;
233 intelScreen->front.size = sarea->front_size;
234 intelScreen->front.tiled = sarea->front_tiled;
235
236 intelScreen->back.offset = sarea->back_offset;
237 intelScreen->back.pitch = sarea->pitch * intelScreen->cpp;
238 intelScreen->back.handle = sarea->back_handle;
239 intelScreen->back.size = sarea->back_size;
240 intelScreen->back.tiled = sarea->back_tiled;
241
242 intelScreen->depth.offset = sarea->depth_offset;
243 intelScreen->depth.pitch = sarea->pitch * intelScreen->cpp;
244 intelScreen->depth.handle = sarea->depth_handle;
245 intelScreen->depth.size = sarea->depth_size;
246 intelScreen->depth.tiled = sarea->depth_tiled;
247
248 if (intelScreen->driScrnPriv->ddx_version.minor >= 9) {
249 intelScreen->front.bo_handle = sarea->front_bo_handle;
250 intelScreen->back.bo_handle = sarea->back_bo_handle;
251 intelScreen->depth.bo_handle = sarea->depth_bo_handle;
252 } else {
253 intelScreen->front.bo_handle = -1;
254 intelScreen->back.bo_handle = -1;
255 intelScreen->depth.bo_handle = -1;
256 }
257
258 intelScreen->tex.offset = sarea->tex_offset;
259 intelScreen->logTextureGranularity = sarea->log_tex_granularity;
260 intelScreen->tex.handle = sarea->tex_handle;
261 intelScreen->tex.size = sarea->tex_size;
262
263 intelScreen->rotated.offset = sarea->rotated_offset;
264 intelScreen->rotated.pitch = sarea->rotated_pitch * intelScreen->cpp;
265 intelScreen->rotated.size = sarea->rotated_size;
266 intelScreen->rotated.tiled = sarea->rotated_tiled;
267 intelScreen->current_rotation = sarea->rotation;
268 #if 0
269 matrix23Rotate(&intelScreen->rotMatrix,
270 sarea->width, sarea->height, sarea->rotation);
271 #endif
272 intelScreen->rotatedWidth = sarea->virtualX;
273 intelScreen->rotatedHeight = sarea->virtualY;
274
275 if (0)
276 intelPrintSAREA(sarea);
277 }
278
279 static const __DRIextension *intelExtensions[] = {
280 &driReadDrawableExtension,
281 &driCopySubBufferExtension.base,
282 &driSwapControlExtension.base,
283 &driFrameTrackingExtension.base,
284 &driMediaStreamCounterExtension.base,
285 NULL
286 };
287
288 static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv)
289 {
290 intelScreenPrivate *intelScreen;
291 I830DRIPtr gDRIPriv = (I830DRIPtr)sPriv->pDevPriv;
292 volatile drmI830Sarea *sarea;
293
294 if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
295 fprintf(stderr,"\nERROR! sizeof(I830DRIRec) (%ld) does not match passed size from device driver (%d)\n", (unsigned long)sizeof(I830DRIRec), sPriv->devPrivSize);
296 return GL_FALSE;
297 }
298
299 /* Allocate the private area */
300 intelScreen = (intelScreenPrivate *)CALLOC(sizeof(intelScreenPrivate));
301 if (!intelScreen) {
302 fprintf(stderr,"\nERROR! Allocating private area failed\n");
303 return GL_FALSE;
304 }
305 /* parse information in __driConfigOptions */
306 driParseOptionInfo (&intelScreen->optionCache,
307 __driConfigOptions, __driNConfigOptions);
308
309 intelScreen->driScrnPriv = sPriv;
310 sPriv->private = (void *)intelScreen;
311 intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
312 sarea = (volatile drmI830Sarea *)
313 (((GLubyte *)sPriv->pSAREA)+intelScreen->sarea_priv_offset);
314
315 intelScreen->deviceID = gDRIPriv->deviceID;
316 intelScreen->mem = gDRIPriv->mem;
317 intelScreen->cpp = gDRIPriv->cpp;
318
319 switch (gDRIPriv->bitsPerPixel) {
320 case 15: intelScreen->fbFormat = DV_PF_555; break;
321 case 16: intelScreen->fbFormat = DV_PF_565; break;
322 case 32: intelScreen->fbFormat = DV_PF_8888; break;
323 }
324
325 intelUpdateScreenFromSAREA(intelScreen, sarea);
326
327 if (0)
328 intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv);
329
330 if (!intelMapScreenRegions(sPriv)) {
331 fprintf(stderr,"\nERROR! mapping regions\n");
332 _mesa_free(intelScreen);
333 sPriv->private = NULL;
334 return GL_FALSE;
335 }
336
337 intelScreen->drmMinor = sPriv->drm_version.minor;
338
339 /* Determine if IRQs are active? */
340 {
341 int ret;
342 drmI830GetParam gp;
343
344 gp.param = I830_PARAM_IRQ_ACTIVE;
345 gp.value = &intelScreen->irq_active;
346
347 ret = drmCommandWriteRead( sPriv->fd, DRM_I830_GETPARAM,
348 &gp, sizeof(gp));
349 if (ret) {
350 fprintf(stderr, "drmI830GetParam: %d\n", ret);
351 return GL_FALSE;
352 }
353 }
354
355 /* Determine if batchbuffers are allowed */
356 {
357 int ret;
358 drmI830GetParam gp;
359
360 gp.param = I830_PARAM_ALLOW_BATCHBUFFER;
361 gp.value = &intelScreen->allow_batchbuffer;
362
363 ret = drmCommandWriteRead( sPriv->fd, DRM_I830_GETPARAM,
364 &gp, sizeof(gp));
365 if (ret) {
366 fprintf(stderr, "drmI830GetParam: (%d) %d\n", gp.param, ret);
367 return GL_FALSE;
368 }
369 }
370
371 sPriv->extensions = intelExtensions;
372
373 return GL_TRUE;
374 }
375
376
377 static void intelDestroyScreen(__DRIscreenPrivate *sPriv)
378 {
379 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
380
381 intelUnmapScreenRegions(intelScreen);
382 FREE(intelScreen);
383 sPriv->private = NULL;
384 }
385
386 static GLboolean intelCreateBuffer( __DRIscreenPrivate *driScrnPriv,
387 __DRIdrawablePrivate *driDrawPriv,
388 const __GLcontextModes *mesaVis,
389 GLboolean isPixmap )
390 {
391 intelScreenPrivate *screen = (intelScreenPrivate *) driScrnPriv->private;
392
393 if (isPixmap) {
394 return GL_FALSE; /* not implemented */
395 } else {
396 GLboolean swStencil = (mesaVis->stencilBits > 0 &&
397 mesaVis->depthBits != 24);
398
399 struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis);
400
401 {
402 driRenderbuffer *frontRb
403 = driNewRenderbuffer(GL_RGBA,
404 screen->front.map,
405 screen->cpp,
406 screen->front.offset, screen->front.pitch,
407 driDrawPriv);
408 intelSetSpanFunctions(frontRb, mesaVis);
409 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base);
410 }
411
412 if (mesaVis->doubleBufferMode) {
413 driRenderbuffer *backRb
414 = driNewRenderbuffer(GL_RGBA,
415 screen->back.map,
416 screen->cpp,
417 screen->back.offset, screen->back.pitch,
418 driDrawPriv);
419 intelSetSpanFunctions(backRb, mesaVis);
420 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backRb->Base);
421 }
422
423 if (mesaVis->depthBits == 16) {
424 driRenderbuffer *depthRb
425 = driNewRenderbuffer(GL_DEPTH_COMPONENT16,
426 screen->depth.map,
427 screen->cpp,
428 screen->depth.offset, screen->depth.pitch,
429 driDrawPriv);
430 intelSetSpanFunctions(depthRb, mesaVis);
431 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
432 }
433 else if (mesaVis->depthBits == 24) {
434 driRenderbuffer *depthRb
435 = driNewRenderbuffer(GL_DEPTH_COMPONENT24,
436 screen->depth.map,
437 screen->cpp,
438 screen->depth.offset, screen->depth.pitch,
439 driDrawPriv);
440 intelSetSpanFunctions(depthRb, mesaVis);
441 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
442 }
443
444 if (mesaVis->stencilBits > 0 && !swStencil) {
445 driRenderbuffer *stencilRb
446 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT,
447 screen->depth.map,
448 screen->cpp,
449 screen->depth.offset, screen->depth.pitch,
450 driDrawPriv);
451 intelSetSpanFunctions(stencilRb, mesaVis);
452 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &stencilRb->Base);
453 }
454
455 _mesa_add_soft_renderbuffers(fb,
456 GL_FALSE, /* color */
457 GL_FALSE, /* depth */
458 swStencil,
459 mesaVis->accumRedBits > 0,
460 GL_FALSE, /* alpha */
461 GL_FALSE /* aux */);
462 driDrawPriv->driverPrivate = (void *) fb;
463
464 return (driDrawPriv->driverPrivate != NULL);
465 }
466 }
467
468 static void intelDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
469 {
470 _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
471 }
472
473
474 /**
475 * Get information about previous buffer swaps.
476 */
477 static int
478 intelGetSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo )
479 {
480 struct intel_context *intel;
481
482 if ( (dPriv == NULL) || (dPriv->driContextPriv == NULL)
483 || (dPriv->driContextPriv->driverPrivate == NULL)
484 || (sInfo == NULL) ) {
485 return -1;
486 }
487
488 intel = dPriv->driContextPriv->driverPrivate;
489 sInfo->swap_count = intel->swap_count;
490 sInfo->swap_ust = intel->swap_ust;
491 sInfo->swap_missed_count = intel->swap_missed_count;
492
493 sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
494 ? driCalculateSwapUsage( dPriv, 0, intel->swap_missed_ust )
495 : 0.0;
496
497 return 0;
498 }
499
500
501 /* There are probably better ways to do this, such as an
502 * init-designated function to register chipids and createcontext
503 * functions.
504 */
505 extern GLboolean i830CreateContext( const __GLcontextModes *mesaVis,
506 __DRIcontextPrivate *driContextPriv,
507 void *sharedContextPrivate);
508
509 extern GLboolean i915CreateContext( const __GLcontextModes *mesaVis,
510 __DRIcontextPrivate *driContextPriv,
511 void *sharedContextPrivate);
512
513 extern GLboolean brwCreateContext( const __GLcontextModes *mesaVis,
514 __DRIcontextPrivate *driContextPriv,
515 void *sharedContextPrivate);
516
517
518
519
520 static GLboolean intelCreateContext( const __GLcontextModes *mesaVis,
521 __DRIcontextPrivate *driContextPriv,
522 void *sharedContextPrivate)
523 {
524 #if 0
525 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
526 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
527 switch (intelScreen->deviceID) {
528 case PCI_CHIP_845_G:
529 case PCI_CHIP_I830_M:
530 case PCI_CHIP_I855_GM:
531 case PCI_CHIP_I865_G:
532 return i830CreateContext( mesaVis, driContextPriv,
533 sharedContextPrivate );
534
535 case PCI_CHIP_I915_G:
536 case PCI_CHIP_I915_GM:
537 case PCI_CHIP_I945_G:
538 case PCI_CHIP_I945_GM:
539 return i915CreateContext( mesaVis, driContextPriv,
540 sharedContextPrivate );
541
542 default:
543 fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID);
544 return GL_FALSE;
545 }
546 #else
547 return brwCreateContext( mesaVis, driContextPriv,
548 sharedContextPrivate );
549 #endif
550 }
551
552
553 static const struct __DriverAPIRec intelAPI = {
554 .DestroyScreen = intelDestroyScreen,
555 .CreateContext = intelCreateContext,
556 .DestroyContext = intelDestroyContext,
557 .CreateBuffer = intelCreateBuffer,
558 .DestroyBuffer = intelDestroyBuffer,
559 .SwapBuffers = intelSwapBuffers,
560 .MakeCurrent = intelMakeCurrent,
561 .UnbindContext = intelUnbindContext,
562 .GetSwapInfo = intelGetSwapInfo,
563 .GetMSC = driGetMSC32,
564 .GetDrawableMSC = driDrawableGetMSC32,
565 .WaitForMSC = driWaitForMSC32,
566 .WaitForSBC = NULL,
567 .SwapBuffersMSC = NULL,
568 .CopySubBuffer = intelCopySubBuffer
569 };
570
571
572 static __GLcontextModes *
573 intelFillInModes( unsigned pixel_bits, unsigned depth_bits,
574 unsigned stencil_bits, GLboolean have_back_buffer )
575 {
576 __GLcontextModes * modes;
577 __GLcontextModes * m;
578 unsigned num_modes;
579 unsigned depth_buffer_factor;
580 unsigned back_buffer_factor;
581 GLenum fb_format;
582 GLenum fb_type;
583
584 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
585 * support pageflipping at all.
586 */
587 static const GLenum back_buffer_modes[] = {
588 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
589 };
590
591 u_int8_t depth_bits_array[3];
592 u_int8_t stencil_bits_array[3];
593
594
595 depth_bits_array[0] = 0;
596 depth_bits_array[1] = depth_bits;
597 depth_bits_array[2] = depth_bits;
598
599 /* Just like with the accumulation buffer, always provide some modes
600 * with a stencil buffer. It will be a sw fallback, but some apps won't
601 * care about that.
602 */
603 stencil_bits_array[0] = 0;
604 stencil_bits_array[1] = 0;
605 stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;
606
607 depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
608 back_buffer_factor = (have_back_buffer) ? 3 : 1;
609
610 num_modes = depth_buffer_factor * back_buffer_factor * 4;
611
612 if ( pixel_bits == 16 ) {
613 fb_format = GL_RGB;
614 fb_type = GL_UNSIGNED_SHORT_5_6_5;
615 }
616 else {
617 fb_format = GL_BGRA;
618 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
619 }
620
621 modes = (*dri_interface->createContextModes)( num_modes, sizeof( __GLcontextModes ) );
622 m = modes;
623 if ( ! driFillInModes( & m, fb_format, fb_type,
624 depth_bits_array, stencil_bits_array, depth_buffer_factor,
625 back_buffer_modes, back_buffer_factor,
626 GLX_TRUE_COLOR ) ) {
627 fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
628 __func__, __LINE__ );
629 return NULL;
630 }
631 if ( ! driFillInModes( & m, fb_format, fb_type,
632 depth_bits_array, stencil_bits_array, depth_buffer_factor,
633 back_buffer_modes, back_buffer_factor,
634 GLX_DIRECT_COLOR ) ) {
635 fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
636 __func__, __LINE__ );
637 return NULL;
638 }
639
640 /* Mark the visual as slow if there are "fake" stencil bits.
641 */
642 for ( m = modes ; m != NULL ; m = m->next ) {
643 if ( (m->stencilBits != 0) && (m->stencilBits != stencil_bits) ) {
644 m->visualRating = GLX_SLOW_CONFIG;
645 }
646 }
647
648 return modes;
649 }
650
651
652 /**
653 * This is the driver specific part of the createNewScreen entry point.
654 *
655 * \todo maybe fold this into intelInitDriver
656 *
657 * \return the __GLcontextModes supported by this driver
658 */
659 __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp)
660 {
661 static const __DRIversion ddx_expected = { 1, 6, 0 };
662 static const __DRIversion dri_expected = { 4, 0, 0 };
663 static const __DRIversion drm_expected = { 1, 3, 0 };
664 I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
665
666 psp->DriverAPI = intelAPI;
667 if ( ! driCheckDriDdxDrmVersions2( "i915",
668 &psp->dri_version, &dri_expected,
669 &psp->ddx_version, &ddx_expected,
670 &psp->drm_version, &drm_expected ) ) {
671 return NULL;
672 }
673
674 /* Calling driInitExtensions here, with a NULL context pointer,
675 * does not actually enable the extensions. It just makes sure
676 * that all the dispatch offsets for all the extensions that
677 * *might* be enables are known. This is needed because the
678 * dispatch offsets need to be known when _mesa_context_create is
679 * called, but we can't enable the extensions until we have a
680 * context pointer.
681 *
682 * Hello chicken. Hello egg. How are you two today?
683 */
684 intelInitExtensions(NULL, GL_FALSE);
685
686 if (!intelInitDriver(psp))
687 return NULL;
688
689 return intelFillInModes( dri_priv->cpp * 8,
690 (dri_priv->cpp == 2) ? 16 : 24,
691 (dri_priv->cpp == 2) ? 0 : 8,
692 GL_TRUE );
693 }