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