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