Merge branch 'master' into gallium-0.2
[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
361 driDestroyOptionInfo (&intelScreen->optionCache);
362
363 FREE(intelScreen);
364 sPriv->private = NULL;
365 }
366
367
368 static GLboolean intelCreateBuffer( __DRIscreenPrivate *driScrnPriv,
369 __DRIdrawablePrivate *driDrawPriv,
370 const __GLcontextModes *mesaVis,
371 GLboolean isPixmap )
372 {
373 intelScreenPrivate *screen = (intelScreenPrivate *) driScrnPriv->private;
374
375 if (isPixmap) {
376 return GL_FALSE; /* not implemented */
377 } else {
378 GLboolean swStencil = (mesaVis->stencilBits > 0 &&
379 mesaVis->depthBits != 24);
380
381 struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis);
382
383 {
384 driRenderbuffer *frontRb
385 = driNewRenderbuffer(GL_RGBA,
386 screen->front.map,
387 screen->cpp,
388 screen->front.offset, screen->front.pitch,
389 driDrawPriv);
390 intelSetSpanFunctions(frontRb, mesaVis);
391 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base);
392 }
393
394 if (mesaVis->doubleBufferMode) {
395 driRenderbuffer *backRb
396 = driNewRenderbuffer(GL_RGBA,
397 screen->back.map,
398 screen->cpp,
399 screen->back.offset, screen->back.pitch,
400 driDrawPriv);
401 intelSetSpanFunctions(backRb, mesaVis);
402 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backRb->Base);
403 }
404
405 if (mesaVis->depthBits == 16) {
406 driRenderbuffer *depthRb
407 = driNewRenderbuffer(GL_DEPTH_COMPONENT16,
408 screen->depth.map,
409 screen->cpp,
410 screen->depth.offset, screen->depth.pitch,
411 driDrawPriv);
412 intelSetSpanFunctions(depthRb, mesaVis);
413 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
414 }
415 else if (mesaVis->depthBits == 24) {
416 driRenderbuffer *depthRb
417 = driNewRenderbuffer(GL_DEPTH_COMPONENT24,
418 screen->depth.map,
419 screen->cpp,
420 screen->depth.offset, screen->depth.pitch,
421 driDrawPriv);
422 intelSetSpanFunctions(depthRb, mesaVis);
423 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
424 }
425
426 if (mesaVis->stencilBits > 0 && !swStencil) {
427 driRenderbuffer *stencilRb
428 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT,
429 screen->depth.map,
430 screen->cpp,
431 screen->depth.offset, screen->depth.pitch,
432 driDrawPriv);
433 intelSetSpanFunctions(stencilRb, mesaVis);
434 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &stencilRb->Base);
435 }
436
437 _mesa_add_soft_renderbuffers(fb,
438 GL_FALSE, /* color */
439 GL_FALSE, /* depth */
440 swStencil,
441 mesaVis->accumRedBits > 0,
442 GL_FALSE, /* alpha */
443 GL_FALSE /* aux */);
444 driDrawPriv->driverPrivate = (void *) fb;
445
446 return (driDrawPriv->driverPrivate != NULL);
447 }
448 }
449
450 static void intelDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
451 {
452 _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
453 }
454
455
456 /**
457 * Get information about previous buffer swaps.
458 */
459 static int
460 intelGetSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo )
461 {
462 intelContextPtr intel;
463
464 if ( (dPriv == NULL) || (dPriv->driContextPriv == NULL)
465 || (dPriv->driContextPriv->driverPrivate == NULL)
466 || (sInfo == NULL) ) {
467 return -1;
468 }
469
470 intel = dPriv->driContextPriv->driverPrivate;
471 sInfo->swap_count = intel->swap_count;
472 sInfo->swap_ust = intel->swap_ust;
473 sInfo->swap_missed_count = intel->swap_missed_count;
474
475 sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
476 ? driCalculateSwapUsage( dPriv, 0, intel->swap_missed_ust )
477 : 0.0;
478
479 return 0;
480 }
481
482
483 /* There are probably better ways to do this, such as an
484 * init-designated function to register chipids and createcontext
485 * functions.
486 */
487 extern GLboolean i830CreateContext( const __GLcontextModes *mesaVis,
488 __DRIcontextPrivate *driContextPriv,
489 void *sharedContextPrivate);
490
491 extern GLboolean i915CreateContext( const __GLcontextModes *mesaVis,
492 __DRIcontextPrivate *driContextPriv,
493 void *sharedContextPrivate);
494
495
496
497
498 static GLboolean intelCreateContext( const __GLcontextModes *mesaVis,
499 __DRIcontextPrivate *driContextPriv,
500 void *sharedContextPrivate)
501 {
502 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
503 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
504
505 switch (intelScreen->deviceID) {
506 case PCI_CHIP_845_G:
507 case PCI_CHIP_I830_M:
508 case PCI_CHIP_I855_GM:
509 case PCI_CHIP_I865_G:
510 return i830CreateContext( mesaVis, driContextPriv,
511 sharedContextPrivate );
512
513 case PCI_CHIP_I915_G:
514 case PCI_CHIP_I915_GM:
515 case PCI_CHIP_I945_G:
516 case PCI_CHIP_I945_GM:
517 case PCI_CHIP_I945_GME:
518 case PCI_CHIP_G33_G:
519 case PCI_CHIP_Q35_G:
520 case PCI_CHIP_Q33_G:
521 return i915CreateContext( mesaVis, driContextPriv,
522 sharedContextPrivate );
523
524 default:
525 fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID);
526 return GL_FALSE;
527 }
528 }
529
530
531 static const struct __DriverAPIRec intelAPI = {
532 .InitDriver = intelInitDriver,
533 .DestroyScreen = intelDestroyScreen,
534 .CreateContext = intelCreateContext,
535 .DestroyContext = intelDestroyContext,
536 .CreateBuffer = intelCreateBuffer,
537 .DestroyBuffer = intelDestroyBuffer,
538 .SwapBuffers = intelSwapBuffers,
539 .MakeCurrent = intelMakeCurrent,
540 .UnbindContext = intelUnbindContext,
541 .GetSwapInfo = intelGetSwapInfo,
542 .GetMSC = driGetMSC32,
543 .WaitForMSC = driWaitForMSC32,
544 .WaitForSBC = NULL,
545 .SwapBuffersMSC = NULL,
546 .CopySubBuffer = intelCopySubBuffer
547 };
548
549
550 static __GLcontextModes *
551 intelFillInModes( unsigned pixel_bits, unsigned depth_bits,
552 unsigned stencil_bits, GLboolean have_back_buffer )
553 {
554 __GLcontextModes * modes;
555 __GLcontextModes * m;
556 unsigned num_modes;
557 unsigned depth_buffer_factor;
558 unsigned back_buffer_factor;
559 GLenum fb_format;
560 GLenum fb_type;
561
562 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
563 * support pageflipping at all.
564 */
565 static const GLenum back_buffer_modes[] = {
566 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
567 };
568
569 uint8_t depth_bits_array[3];
570 uint8_t stencil_bits_array[3];
571
572
573 depth_bits_array[0] = 0;
574 depth_bits_array[1] = depth_bits;
575 depth_bits_array[2] = depth_bits;
576
577 /* Just like with the accumulation buffer, always provide some modes
578 * with a stencil buffer. It will be a sw fallback, but some apps won't
579 * care about that.
580 */
581 stencil_bits_array[0] = 0;
582 stencil_bits_array[1] = 0;
583 stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;
584
585 depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
586 back_buffer_factor = (have_back_buffer) ? 3 : 1;
587
588 num_modes = depth_buffer_factor * back_buffer_factor * 4;
589
590 if ( pixel_bits == 16 ) {
591 fb_format = GL_RGB;
592 fb_type = GL_UNSIGNED_SHORT_5_6_5;
593 }
594 else {
595 fb_format = GL_BGRA;
596 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
597 }
598
599 modes = (*dri_interface->createContextModes)( num_modes, sizeof( __GLcontextModes ) );
600 m = modes;
601 if ( ! driFillInModes( & m, fb_format, fb_type,
602 depth_bits_array, stencil_bits_array, depth_buffer_factor,
603 back_buffer_modes, back_buffer_factor,
604 GLX_TRUE_COLOR ) ) {
605 fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
606 __func__, __LINE__ );
607 return NULL;
608 }
609 if ( ! driFillInModes( & m, fb_format, fb_type,
610 depth_bits_array, stencil_bits_array, depth_buffer_factor,
611 back_buffer_modes, back_buffer_factor,
612 GLX_DIRECT_COLOR ) ) {
613 fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
614 __func__, __LINE__ );
615 return NULL;
616 }
617
618 /* Mark the visual as slow if there are "fake" stencil bits.
619 */
620 for ( m = modes ; m != NULL ; m = m->next ) {
621 if ( (m->stencilBits != 0) && (m->stencilBits != stencil_bits) ) {
622 m->visualRating = GLX_SLOW_CONFIG;
623 }
624 }
625
626 return modes;
627 }
628
629
630 /**
631 * This is the bootstrap function for the driver. libGL supplies all of the
632 * requisite information about the system, and the driver initializes itself.
633 * This routine also fills in the linked list pointed to by \c driver_modes
634 * with the \c __GLcontextModes that the driver can support for windows or
635 * pbuffers.
636 *
637 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
638 * failure.
639 */
640 PUBLIC
641 void * __driCreateNewScreen_20050727( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc,
642 const __GLcontextModes * modes,
643 const __DRIversion * ddx_version,
644 const __DRIversion * dri_version,
645 const __DRIversion * drm_version,
646 const __DRIframebuffer * frame_buffer,
647 drmAddress pSAREA, int fd,
648 int internal_api_version,
649 const __DRIinterfaceMethods * interface,
650 __GLcontextModes ** driver_modes )
651
652 {
653 __DRIscreenPrivate *psp;
654 static const __DRIversion ddx_expected = { 1, 5, 0 };
655 static const __DRIversion dri_expected = { 4, 0, 0 };
656 static const __DRIversion drm_expected = { 1, 4, 0 };
657
658 dri_interface = interface;
659
660 if ( ! driCheckDriDdxDrmVersions2( "i915",
661 dri_version, & dri_expected,
662 ddx_version, & ddx_expected,
663 drm_version, & drm_expected ) ) {
664 return NULL;
665 }
666
667 psp = __driUtilCreateNewScreen(dpy, scrn, psc, NULL,
668 ddx_version, dri_version, drm_version,
669 frame_buffer, pSAREA, fd,
670 internal_api_version, &intelAPI);
671 if ( psp != NULL ) {
672 I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
673 *driver_modes = intelFillInModes( dri_priv->cpp * 8,
674 (dri_priv->cpp == 2) ? 16 : 24,
675 (dri_priv->cpp == 2) ? 0 : 8,
676 1 );
677
678 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
679 * enable the extensions. It just makes sure that all the dispatch offsets for all
680 * the extensions that *might* be enables are known. This is needed because the
681 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
682 * enable the extensions until we have a context pointer.
683 *
684 * Hello chicken. Hello egg. How are you two today?
685 */
686 driInitExtensions( NULL, card_extensions, GL_FALSE );
687 }
688
689 return (void *) psp;
690 }