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