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