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