8269deba664b284e9bedbb1c9333e42450a0f380
[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 intelScreen->front.tiled = sarea->front_tiled;
234
235 intelScreen->back.offset = sarea->back_offset;
236 intelScreen->back.pitch = sarea->pitch * intelScreen->cpp;
237 intelScreen->back.handle = sarea->back_handle;
238 intelScreen->back.size = sarea->back_size;
239 intelScreen->back.tiled = sarea->back_tiled;
240
241 intelScreen->depth.offset = sarea->depth_offset;
242 intelScreen->depth.pitch = sarea->pitch * intelScreen->cpp;
243 intelScreen->depth.handle = sarea->depth_handle;
244 intelScreen->depth.size = sarea->depth_size;
245 intelScreen->depth.tiled = sarea->depth_tiled;
246
247 intelScreen->tex.offset = sarea->tex_offset;
248 intelScreen->logTextureGranularity = sarea->log_tex_granularity;
249 intelScreen->tex.handle = sarea->tex_handle;
250 intelScreen->tex.size = sarea->tex_size;
251
252 intelScreen->rotated.offset = sarea->rotated_offset;
253 intelScreen->rotated.pitch = sarea->rotated_pitch * intelScreen->cpp;
254 intelScreen->rotated.size = sarea->rotated_size;
255 intelScreen->rotated.tiled = sarea->rotated_tiled;
256 intelScreen->current_rotation = sarea->rotation;
257 #if 0
258 matrix23Rotate(&intelScreen->rotMatrix,
259 sarea->width, sarea->height, sarea->rotation);
260 #endif
261 intelScreen->rotatedWidth = sarea->virtualX;
262 intelScreen->rotatedHeight = sarea->virtualY;
263
264 if (0)
265 intelPrintSAREA(sarea);
266 }
267
268
269 static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv)
270 {
271 intelScreenPrivate *intelScreen;
272 I830DRIPtr gDRIPriv = (I830DRIPtr)sPriv->pDevPriv;
273 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension =
274 (PFNGLXSCRENABLEEXTENSIONPROC) (*dri_interface->getProcAddress("glxEnableExtension"));
275 void * const psc = sPriv->psc->screenConfigs;
276 volatile drmI830Sarea *sarea;
277
278 if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
279 fprintf(stderr,"\nERROR! sizeof(I830DRIRec) (%ld) does not match passed size from device driver (%d)\n", (unsigned long)sizeof(I830DRIRec), sPriv->devPrivSize);
280 return GL_FALSE;
281 }
282
283 /* Allocate the private area */
284 intelScreen = (intelScreenPrivate *)CALLOC(sizeof(intelScreenPrivate));
285 if (!intelScreen) {
286 fprintf(stderr,"\nERROR! Allocating private area failed\n");
287 return GL_FALSE;
288 }
289 /* parse information in __driConfigOptions */
290 driParseOptionInfo (&intelScreen->optionCache,
291 __driConfigOptions, __driNConfigOptions);
292
293 intelScreen->driScrnPriv = sPriv;
294 sPriv->private = (void *)intelScreen;
295 intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
296 sarea = (volatile drmI830Sarea *)
297 (((GLubyte *)sPriv->pSAREA)+intelScreen->sarea_priv_offset);
298
299 intelScreen->deviceID = gDRIPriv->deviceID;
300 intelScreen->mem = gDRIPriv->mem;
301 intelScreen->cpp = gDRIPriv->cpp;
302
303 switch (gDRIPriv->bitsPerPixel) {
304 case 15: intelScreen->fbFormat = DV_PF_555; break;
305 case 16: intelScreen->fbFormat = DV_PF_565; break;
306 case 32: intelScreen->fbFormat = DV_PF_8888; break;
307 }
308
309 intelUpdateScreenFromSAREA(intelScreen, sarea);
310
311 if (0)
312 intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv);
313
314 if (!intelMapScreenRegions(sPriv)) {
315 fprintf(stderr,"\nERROR! mapping regions\n");
316 _mesa_free(intelScreen);
317 sPriv->private = NULL;
318 return GL_FALSE;
319 }
320
321 intelScreen->drmMinor = sPriv->drmMinor;
322
323 /* Determine if IRQs are active? */
324 {
325 int ret;
326 drmI830GetParam gp;
327
328 gp.param = I830_PARAM_IRQ_ACTIVE;
329 gp.value = &intelScreen->irq_active;
330
331 ret = drmCommandWriteRead( sPriv->fd, DRM_I830_GETPARAM,
332 &gp, sizeof(gp));
333 if (ret) {
334 fprintf(stderr, "drmI830GetParam: %d\n", ret);
335 return GL_FALSE;
336 }
337 }
338
339 /* Determine if batchbuffers are allowed */
340 {
341 int ret;
342 drmI830GetParam gp;
343
344 gp.param = I830_PARAM_ALLOW_BATCHBUFFER;
345 gp.value = &intelScreen->allow_batchbuffer;
346
347 ret = drmCommandWriteRead( sPriv->fd, DRM_I830_GETPARAM,
348 &gp, sizeof(gp));
349 if (ret) {
350 fprintf(stderr, "drmI830GetParam: (%d) %d\n", gp.param, ret);
351 return GL_FALSE;
352 }
353 }
354
355 if (glx_enable_extension != NULL) {
356 (*glx_enable_extension)( psc, "GLX_SGI_swap_control" );
357 (*glx_enable_extension)( psc, "GLX_SGI_video_sync" );
358 (*glx_enable_extension)( psc, "GLX_MESA_swap_control" );
359 (*glx_enable_extension)( psc, "GLX_MESA_swap_frame_usage" );
360 (*glx_enable_extension)( psc, "GLX_SGI_make_current_read" );
361 (*glx_enable_extension)( psc, "GLX_MESA_copy_sub_buffer" );
362 }
363
364 return GL_TRUE;
365 }
366
367
368 static void intelDestroyScreen(__DRIscreenPrivate *sPriv)
369 {
370 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
371
372 intelUnmapScreenRegions(intelScreen);
373 FREE(intelScreen);
374 sPriv->private = NULL;
375 }
376
377 static GLboolean intelCreateBuffer( __DRIscreenPrivate *driScrnPriv,
378 __DRIdrawablePrivate *driDrawPriv,
379 const __GLcontextModes *mesaVis,
380 GLboolean isPixmap )
381 {
382 intelScreenPrivate *screen = (intelScreenPrivate *) driScrnPriv->private;
383
384 if (isPixmap) {
385 return GL_FALSE; /* not implemented */
386 } else {
387 GLboolean swStencil = (mesaVis->stencilBits > 0 &&
388 mesaVis->depthBits != 24);
389
390 struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis);
391
392 {
393 driRenderbuffer *frontRb
394 = driNewRenderbuffer(GL_RGBA,
395 screen->front.map,
396 screen->cpp,
397 screen->front.offset, screen->front.pitch,
398 driDrawPriv);
399 intelSetSpanFunctions(frontRb, mesaVis);
400 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base);
401 }
402
403 if (mesaVis->doubleBufferMode) {
404 driRenderbuffer *backRb
405 = driNewRenderbuffer(GL_RGBA,
406 screen->back.map,
407 screen->cpp,
408 screen->back.offset, screen->back.pitch,
409 driDrawPriv);
410 intelSetSpanFunctions(backRb, mesaVis);
411 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backRb->Base);
412 }
413
414 if (mesaVis->depthBits == 16) {
415 driRenderbuffer *depthRb
416 = driNewRenderbuffer(GL_DEPTH_COMPONENT16,
417 screen->depth.map,
418 screen->cpp,
419 screen->depth.offset, screen->depth.pitch,
420 driDrawPriv);
421 intelSetSpanFunctions(depthRb, mesaVis);
422 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
423 }
424 else if (mesaVis->depthBits == 24) {
425 driRenderbuffer *depthRb
426 = driNewRenderbuffer(GL_DEPTH_COMPONENT24,
427 screen->depth.map,
428 screen->cpp,
429 screen->depth.offset, screen->depth.pitch,
430 driDrawPriv);
431 intelSetSpanFunctions(depthRb, mesaVis);
432 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
433 }
434
435 if (mesaVis->stencilBits > 0 && !swStencil) {
436 driRenderbuffer *stencilRb
437 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT,
438 screen->depth.map,
439 screen->cpp,
440 screen->depth.offset, screen->depth.pitch,
441 driDrawPriv);
442 intelSetSpanFunctions(stencilRb, mesaVis);
443 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &stencilRb->Base);
444 }
445
446 _mesa_add_soft_renderbuffers(fb,
447 GL_FALSE, /* color */
448 GL_FALSE, /* depth */
449 swStencil,
450 mesaVis->accumRedBits > 0,
451 GL_FALSE, /* alpha */
452 GL_FALSE /* aux */);
453 driDrawPriv->driverPrivate = (void *) fb;
454
455 return (driDrawPriv->driverPrivate != NULL);
456 }
457 }
458
459 static void intelDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
460 {
461 _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
462 }
463
464
465 /**
466 * Get information about previous buffer swaps.
467 */
468 static int
469 intelGetSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo )
470 {
471 struct intel_context *intel;
472
473 if ( (dPriv == NULL) || (dPriv->driContextPriv == NULL)
474 || (dPriv->driContextPriv->driverPrivate == NULL)
475 || (sInfo == NULL) ) {
476 return -1;
477 }
478
479 intel = dPriv->driContextPriv->driverPrivate;
480 sInfo->swap_count = intel->swap_count;
481 sInfo->swap_ust = intel->swap_ust;
482 sInfo->swap_missed_count = intel->swap_missed_count;
483
484 sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
485 ? driCalculateSwapUsage( dPriv, 0, intel->swap_missed_ust )
486 : 0.0;
487
488 return 0;
489 }
490
491
492 /* There are probably better ways to do this, such as an
493 * init-designated function to register chipids and createcontext
494 * functions.
495 */
496 extern GLboolean i830CreateContext( const __GLcontextModes *mesaVis,
497 __DRIcontextPrivate *driContextPriv,
498 void *sharedContextPrivate);
499
500 extern GLboolean i915CreateContext( const __GLcontextModes *mesaVis,
501 __DRIcontextPrivate *driContextPriv,
502 void *sharedContextPrivate);
503
504 extern GLboolean brwCreateContext( const __GLcontextModes *mesaVis,
505 __DRIcontextPrivate *driContextPriv,
506 void *sharedContextPrivate);
507
508
509
510
511 static GLboolean intelCreateContext( const __GLcontextModes *mesaVis,
512 __DRIcontextPrivate *driContextPriv,
513 void *sharedContextPrivate)
514 {
515 #if 0
516 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
517 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
518 switch (intelScreen->deviceID) {
519 case PCI_CHIP_845_G:
520 case PCI_CHIP_I830_M:
521 case PCI_CHIP_I855_GM:
522 case PCI_CHIP_I865_G:
523 return i830CreateContext( mesaVis, driContextPriv,
524 sharedContextPrivate );
525
526 case PCI_CHIP_I915_G:
527 case PCI_CHIP_I915_GM:
528 case PCI_CHIP_I945_G:
529 case PCI_CHIP_I945_GM:
530 return i915CreateContext( mesaVis, driContextPriv,
531 sharedContextPrivate );
532
533 default:
534 fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID);
535 return GL_FALSE;
536 }
537 #else
538 return brwCreateContext( mesaVis, driContextPriv,
539 sharedContextPrivate );
540 #endif
541 }
542
543
544 static const struct __DriverAPIRec intelAPI = {
545 .InitDriver = intelInitDriver,
546 .DestroyScreen = intelDestroyScreen,
547 .CreateContext = intelCreateContext,
548 .DestroyContext = intelDestroyContext,
549 .CreateBuffer = intelCreateBuffer,
550 .DestroyBuffer = intelDestroyBuffer,
551 .SwapBuffers = intelSwapBuffers,
552 .MakeCurrent = intelMakeCurrent,
553 .UnbindContext = intelUnbindContext,
554 .GetSwapInfo = intelGetSwapInfo,
555 .GetMSC = driGetMSC32,
556 .WaitForMSC = driWaitForMSC32,
557 .WaitForSBC = NULL,
558 .SwapBuffersMSC = NULL,
559 .CopySubBuffer = intelCopySubBuffer
560 };
561
562
563 static __GLcontextModes *
564 intelFillInModes( unsigned pixel_bits, unsigned depth_bits,
565 unsigned stencil_bits, GLboolean have_back_buffer )
566 {
567 __GLcontextModes * modes;
568 __GLcontextModes * m;
569 unsigned num_modes;
570 unsigned depth_buffer_factor;
571 unsigned back_buffer_factor;
572 GLenum fb_format;
573 GLenum fb_type;
574
575 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
576 * support pageflipping at all.
577 */
578 static const GLenum back_buffer_modes[] = {
579 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
580 };
581
582 u_int8_t depth_bits_array[3];
583 u_int8_t stencil_bits_array[3];
584
585
586 depth_bits_array[0] = 0;
587 depth_bits_array[1] = depth_bits;
588 depth_bits_array[2] = depth_bits;
589
590 /* Just like with the accumulation buffer, always provide some modes
591 * with a stencil buffer. It will be a sw fallback, but some apps won't
592 * care about that.
593 */
594 stencil_bits_array[0] = 0;
595 stencil_bits_array[1] = 0;
596 stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;
597
598 depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
599 back_buffer_factor = (have_back_buffer) ? 3 : 1;
600
601 num_modes = depth_buffer_factor * back_buffer_factor * 4;
602
603 if ( pixel_bits == 16 ) {
604 fb_format = GL_RGB;
605 fb_type = GL_UNSIGNED_SHORT_5_6_5;
606 }
607 else {
608 fb_format = GL_BGRA;
609 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
610 }
611
612 modes = (*dri_interface->createContextModes)( num_modes, sizeof( __GLcontextModes ) );
613 m = modes;
614 if ( ! driFillInModes( & m, fb_format, fb_type,
615 depth_bits_array, stencil_bits_array, depth_buffer_factor,
616 back_buffer_modes, back_buffer_factor,
617 GLX_TRUE_COLOR ) ) {
618 fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
619 __func__, __LINE__ );
620 return NULL;
621 }
622 if ( ! driFillInModes( & m, fb_format, fb_type,
623 depth_bits_array, stencil_bits_array, depth_buffer_factor,
624 back_buffer_modes, back_buffer_factor,
625 GLX_DIRECT_COLOR ) ) {
626 fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
627 __func__, __LINE__ );
628 return NULL;
629 }
630
631 /* Mark the visual as slow if there are "fake" stencil bits.
632 */
633 for ( m = modes ; m != NULL ; m = m->next ) {
634 if ( (m->stencilBits != 0) && (m->stencilBits != stencil_bits) ) {
635 m->visualRating = GLX_SLOW_CONFIG;
636 }
637 }
638
639 return modes;
640 }
641
642
643 /**
644 * This is the bootstrap function for the driver. libGL supplies all of the
645 * requisite information about the system, and the driver initializes itself.
646 * This routine also fills in the linked list pointed to by \c driver_modes
647 * with the \c __GLcontextModes that the driver can support for windows or
648 * pbuffers.
649 *
650 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
651 * failure.
652 */
653 PUBLIC
654 void * __driCreateNewScreen_20050727( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc,
655 const __GLcontextModes * modes,
656 const __DRIversion * ddx_version,
657 const __DRIversion * dri_version,
658 const __DRIversion * drm_version,
659 const __DRIframebuffer * frame_buffer,
660 drmAddress pSAREA, int fd,
661 int internal_api_version,
662 const __DRIinterfaceMethods * interface,
663 __GLcontextModes ** driver_modes )
664
665 {
666 __DRIscreenPrivate *psp;
667 static const __DRIversion ddx_expected = { 1, 6, 0 };
668 static const __DRIversion dri_expected = { 4, 0, 0 };
669 static const __DRIversion drm_expected = { 1, 3, 0 };
670
671 dri_interface = interface;
672
673 if ( ! driCheckDriDdxDrmVersions2( "i915",
674 dri_version, & dri_expected,
675 ddx_version, & ddx_expected,
676 drm_version, & drm_expected ) ) {
677 return NULL;
678 }
679
680 psp = __driUtilCreateNewScreen(dpy, scrn, psc, NULL,
681 ddx_version, dri_version, drm_version,
682 frame_buffer, pSAREA, fd,
683 internal_api_version, &intelAPI);
684 if ( psp != NULL ) {
685 I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
686 *driver_modes = intelFillInModes( dri_priv->cpp * 8,
687 (dri_priv->cpp == 2) ? 16 : 24,
688 (dri_priv->cpp == 2) ? 0 : 8,
689 GL_TRUE );
690
691 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
692 * enable the extensions. It just makes sure that all the dispatch offsets for all
693 * the extensions that *might* be enables are known. This is needed because the
694 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
695 * enable the extensions until we have a context pointer.
696 *
697 * Hello chicken. Hello egg. How are you two today?
698 */
699 driInitExtensions( NULL, card_extensions, GL_FALSE );
700 }
701
702 return (void *) psp;
703 }