c193830f05fb40dbabeeede87d555656423ea5ce
[mesa.git] / src / mesa / drivers / dri / intel / 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_buffers.h"
42 #include "intel_tex.h"
43 #include "intel_span.h"
44 #include "intel_ioctl.h"
45 #include "intel_fbo.h"
46 #include "intel_chipset.h"
47
48 #include "i915_drm.h"
49 #include "i830_dri.h"
50 #include "intel_regions.h"
51 #include "intel_batchbuffer.h"
52 #include "intel_bufmgr.h"
53
54 PUBLIC const char __driConfigOptions[] =
55 DRI_CONF_BEGIN
56 DRI_CONF_SECTION_PERFORMANCE
57 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
58 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC)
59 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
60 * DRI_CONF_BO_REUSE_ALL
61 */
62 DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1")
63 DRI_CONF_DESC_BEGIN(en, "Buffer object reuse")
64 DRI_CONF_ENUM(0, "Disable buffer object reuse")
65 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
66 DRI_CONF_DESC_END
67 DRI_CONF_OPT_END
68 DRI_CONF_SECTION_END
69 DRI_CONF_SECTION_QUALITY
70 DRI_CONF_FORCE_S3TC_ENABLE(false)
71 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
72 DRI_CONF_SECTION_END
73 DRI_CONF_SECTION_DEBUG
74 DRI_CONF_NO_RAST(false)
75 DRI_CONF_SECTION_END
76 DRI_CONF_END;
77
78 const GLuint __driNConfigOptions = 6;
79
80 #ifdef USE_NEW_INTERFACE
81 static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
82 #endif /*USE_NEW_INTERFACE */
83
84 /**
85 * Map all the memory regions described by the screen.
86 * \return GL_TRUE if success, GL_FALSE if error.
87 */
88 GLboolean
89 intelMapScreenRegions(__DRIscreenPrivate * sPriv)
90 {
91 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
92
93 if (0)
94 _mesa_printf("TEX 0x%08x ", intelScreen->tex.handle);
95 if (intelScreen->tex.size != 0) {
96 if (drmMap(sPriv->fd,
97 intelScreen->tex.handle,
98 intelScreen->tex.size,
99 (drmAddress *) & intelScreen->tex.map) != 0) {
100 intelUnmapScreenRegions(intelScreen);
101 return GL_FALSE;
102 }
103 }
104
105 return GL_TRUE;
106 }
107
108 void
109 intelUnmapScreenRegions(intelScreenPrivate * intelScreen)
110 {
111 if (intelScreen->tex.map) {
112 drmUnmap(intelScreen->tex.map, intelScreen->tex.size);
113 intelScreen->tex.map = NULL;
114 }
115 }
116
117
118 static void
119 intelPrintDRIInfo(intelScreenPrivate * intelScreen,
120 __DRIscreenPrivate * sPriv, I830DRIPtr gDRIPriv)
121 {
122 fprintf(stderr, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
123 intelScreen->front.size, intelScreen->front.offset,
124 intelScreen->pitch);
125 fprintf(stderr, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
126 intelScreen->back.size, intelScreen->back.offset,
127 intelScreen->pitch);
128 fprintf(stderr, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
129 intelScreen->depth.size, intelScreen->depth.offset,
130 intelScreen->pitch);
131 fprintf(stderr, "*** Texture size: 0x%x offset: 0x%x\n",
132 intelScreen->tex.size, intelScreen->tex.offset);
133 fprintf(stderr, "*** Memory : 0x%x\n", gDRIPriv->mem);
134 }
135
136
137 static void
138 intelPrintSAREA(const struct drm_i915_sarea * sarea)
139 {
140 fprintf(stderr, "SAREA: sarea width %d height %d\n", sarea->width,
141 sarea->height);
142 fprintf(stderr, "SAREA: pitch: %d\n", sarea->pitch);
143 fprintf(stderr,
144 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
145 sarea->front_offset, sarea->front_size,
146 (unsigned) sarea->front_handle, sarea->front_tiled);
147 fprintf(stderr,
148 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
149 sarea->back_offset, sarea->back_size,
150 (unsigned) sarea->back_handle, sarea->back_tiled);
151 fprintf(stderr, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
152 sarea->depth_offset, sarea->depth_size,
153 (unsigned) sarea->depth_handle, sarea->depth_tiled);
154 fprintf(stderr, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
155 sarea->tex_offset, sarea->tex_size, (unsigned) sarea->tex_handle);
156 }
157
158
159 /**
160 * A number of the screen parameters are obtained/computed from
161 * information in the SAREA. This function updates those parameters.
162 */
163 void
164 intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen,
165 struct drm_i915_sarea * sarea)
166 {
167 intelScreen->width = sarea->width;
168 intelScreen->height = sarea->height;
169 intelScreen->pitch = sarea->pitch;
170
171 intelScreen->front.offset = sarea->front_offset;
172 intelScreen->front.handle = sarea->front_handle;
173 intelScreen->front.size = sarea->front_size;
174 intelScreen->front.tiled = sarea->front_tiled;
175
176 intelScreen->back.offset = sarea->back_offset;
177 intelScreen->back.handle = sarea->back_handle;
178 intelScreen->back.size = sarea->back_size;
179 intelScreen->back.tiled = sarea->back_tiled;
180
181 if (intelScreen->driScrnPriv->ddx_version.minor >= 8) {
182 intelScreen->third.offset = sarea->third_offset;
183 intelScreen->third.handle = sarea->third_handle;
184 intelScreen->third.size = sarea->third_size;
185 intelScreen->third.tiled = sarea->third_tiled;
186 }
187
188 intelScreen->depth.offset = sarea->depth_offset;
189 intelScreen->depth.handle = sarea->depth_handle;
190 intelScreen->depth.size = sarea->depth_size;
191 intelScreen->depth.tiled = sarea->depth_tiled;
192
193 if (intelScreen->driScrnPriv->ddx_version.minor >= 9) {
194 intelScreen->front.bo_handle = sarea->front_bo_handle;
195 intelScreen->back.bo_handle = sarea->back_bo_handle;
196 intelScreen->third.bo_handle = sarea->third_bo_handle;
197 intelScreen->depth.bo_handle = sarea->depth_bo_handle;
198 } else {
199 intelScreen->front.bo_handle = -1;
200 intelScreen->back.bo_handle = -1;
201 intelScreen->third.bo_handle = -1;
202 intelScreen->depth.bo_handle = -1;
203 }
204
205 intelScreen->tex.offset = sarea->tex_offset;
206 intelScreen->logTextureGranularity = sarea->log_tex_granularity;
207 intelScreen->tex.handle = sarea->tex_handle;
208 intelScreen->tex.size = sarea->tex_size;
209
210 if (0)
211 intelPrintSAREA(sarea);
212 }
213
214 static const __DRItexOffsetExtension intelTexOffsetExtension = {
215 { __DRI_TEX_OFFSET },
216 intelSetTexOffset,
217 };
218
219 static const __DRItexBufferExtension intelTexBufferExtension = {
220 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
221 intelSetTexBuffer,
222 };
223
224 static const __DRIextension *intelScreenExtensions[] = {
225 &driReadDrawableExtension,
226 &driCopySubBufferExtension.base,
227 &driSwapControlExtension.base,
228 &driFrameTrackingExtension.base,
229 &driMediaStreamCounterExtension.base,
230 &intelTexOffsetExtension.base,
231 &intelTexBufferExtension.base,
232 NULL
233 };
234
235 static GLboolean
236 intel_get_param(__DRIscreenPrivate *psp, int param, int *value)
237 {
238 int ret;
239 struct drm_i915_getparam gp;
240
241 gp.param = param;
242 gp.value = value;
243
244 ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
245 if (ret) {
246 fprintf(stderr, "drm_i915_getparam: %d\n", ret);
247 return GL_FALSE;
248 }
249
250 return GL_TRUE;
251 }
252
253 static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv)
254 {
255 intelScreenPrivate *intelScreen;
256 I830DRIPtr gDRIPriv = (I830DRIPtr) sPriv->pDevPriv;
257 struct drm_i915_sarea *sarea;
258
259 if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
260 fprintf(stderr,
261 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
262 return GL_FALSE;
263 }
264
265 /* Allocate the private area */
266 intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
267 if (!intelScreen) {
268 fprintf(stderr, "\nERROR! Allocating private area failed\n");
269 return GL_FALSE;
270 }
271 /* parse information in __driConfigOptions */
272 driParseOptionInfo(&intelScreen->optionCache,
273 __driConfigOptions, __driNConfigOptions);
274
275 intelScreen->driScrnPriv = sPriv;
276 sPriv->private = (void *) intelScreen;
277 intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
278 sarea = (struct drm_i915_sarea *)
279 (((GLubyte *) sPriv->pSAREA) + intelScreen->sarea_priv_offset);
280
281 intelScreen->deviceID = gDRIPriv->deviceID;
282
283 intelUpdateScreenFromSAREA(intelScreen, sarea);
284
285 if (!intelMapScreenRegions(sPriv)) {
286 fprintf(stderr, "\nERROR! mapping regions\n");
287 _mesa_free(intelScreen);
288 sPriv->private = NULL;
289 return GL_FALSE;
290 }
291
292 intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
293
294 if (0)
295 intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv);
296
297 intelScreen->drmMinor = sPriv->drm_version.minor;
298
299 /* Determine if IRQs are active? */
300 if (!intel_get_param(sPriv, I915_PARAM_IRQ_ACTIVE,
301 &intelScreen->irq_active))
302 return GL_FALSE;
303
304 /* Determine if batchbuffers are allowed */
305 if (!intel_get_param(sPriv, I915_PARAM_ALLOW_BATCHBUFFER,
306 &intelScreen->allow_batchbuffer))
307 return GL_FALSE;
308
309 sPriv->extensions = intelScreenExtensions;
310
311 return GL_TRUE;
312 }
313
314
315 static void
316 intelDestroyScreen(__DRIscreenPrivate * sPriv)
317 {
318 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
319
320 intelUnmapScreenRegions(intelScreen);
321
322 FREE(intelScreen);
323 sPriv->private = NULL;
324 }
325
326
327 /**
328 * This is called when we need to set up GL rendering to a new X window.
329 */
330 static GLboolean
331 intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
332 __DRIdrawablePrivate * driDrawPriv,
333 const __GLcontextModes * mesaVis, GLboolean isPixmap)
334 {
335 intelScreenPrivate *screen = (intelScreenPrivate *) driScrnPriv->private;
336
337 if (isPixmap) {
338 return GL_FALSE; /* not implemented */
339 }
340 else {
341 GLboolean swStencil = (mesaVis->stencilBits > 0 &&
342 mesaVis->depthBits != 24);
343 GLenum rgbFormat = (mesaVis->redBits == 5 ? GL_RGB5 : GL_RGBA8);
344
345 struct intel_framebuffer *intel_fb = CALLOC_STRUCT(intel_framebuffer);
346
347 if (!intel_fb)
348 return GL_FALSE;
349
350 _mesa_initialize_framebuffer(&intel_fb->Base, mesaVis);
351
352 /* setup the hardware-based renderbuffers */
353 intel_fb->color_rb[0] = intel_create_renderbuffer(rgbFormat);
354 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_FRONT_LEFT,
355 &intel_fb->color_rb[0]->Base);
356
357 if (mesaVis->doubleBufferMode) {
358 intel_fb->color_rb[1] = intel_create_renderbuffer(rgbFormat);
359
360 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT,
361 &intel_fb->color_rb[1]->Base);
362
363 if (screen->third.handle) {
364 struct gl_renderbuffer *tmp_rb = NULL;
365
366 intel_fb->color_rb[2] = intel_create_renderbuffer(rgbFormat);
367 _mesa_reference_renderbuffer(&tmp_rb, &intel_fb->color_rb[2]->Base);
368 }
369 }
370
371 if (mesaVis->depthBits == 24) {
372 if (mesaVis->stencilBits == 8) {
373 /* combined depth/stencil buffer */
374 struct intel_renderbuffer *depthStencilRb
375 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT);
376 /* note: bind RB to two attachment points */
377 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
378 &depthStencilRb->Base);
379 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_STENCIL,
380 &depthStencilRb->Base);
381 } else {
382 struct intel_renderbuffer *depthRb
383 = intel_create_renderbuffer(GL_DEPTH_COMPONENT24);
384 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
385 &depthRb->Base);
386 }
387 }
388 else if (mesaVis->depthBits == 16) {
389 /* just 16-bit depth buffer, no hw stencil */
390 struct intel_renderbuffer *depthRb
391 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16);
392 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, &depthRb->Base);
393 }
394
395 /* now add any/all software-based renderbuffers we may need */
396 _mesa_add_soft_renderbuffers(&intel_fb->Base,
397 GL_FALSE, /* never sw color */
398 GL_FALSE, /* never sw depth */
399 swStencil, mesaVis->accumRedBits > 0,
400 GL_FALSE, /* never sw alpha */
401 GL_FALSE /* never sw aux */ );
402 driDrawPriv->driverPrivate = (void *) intel_fb;
403
404 return GL_TRUE;
405 }
406 }
407
408 static void
409 intelDestroyBuffer(__DRIdrawablePrivate * driDrawPriv)
410 {
411 _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
412 }
413
414
415 /**
416 * Get information about previous buffer swaps.
417 */
418 static int
419 intelGetSwapInfo(__DRIdrawablePrivate * dPriv, __DRIswapInfo * sInfo)
420 {
421 struct intel_framebuffer *intel_fb;
422
423 if ((dPriv == NULL) || (dPriv->driverPrivate == NULL)
424 || (sInfo == NULL)) {
425 return -1;
426 }
427
428 intel_fb = dPriv->driverPrivate;
429 sInfo->swap_count = intel_fb->swap_count;
430 sInfo->swap_ust = intel_fb->swap_ust;
431 sInfo->swap_missed_count = intel_fb->swap_missed_count;
432
433 sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
434 ? driCalculateSwapUsage(dPriv, 0, intel_fb->swap_missed_ust)
435 : 0.0;
436
437 return 0;
438 }
439
440
441 /* There are probably better ways to do this, such as an
442 * init-designated function to register chipids and createcontext
443 * functions.
444 */
445 extern GLboolean i830CreateContext(const __GLcontextModes * mesaVis,
446 __DRIcontextPrivate * driContextPriv,
447 void *sharedContextPrivate);
448
449 extern GLboolean i915CreateContext(const __GLcontextModes * mesaVis,
450 __DRIcontextPrivate * driContextPriv,
451 void *sharedContextPrivate);
452 extern GLboolean brwCreateContext(const __GLcontextModes * mesaVis,
453 __DRIcontextPrivate * driContextPriv,
454 void *sharedContextPrivate);
455
456 static GLboolean
457 intelCreateContext(const __GLcontextModes * mesaVis,
458 __DRIcontextPrivate * driContextPriv,
459 void *sharedContextPrivate)
460 {
461 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
462 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
463
464 #ifdef I915
465 if (IS_9XX(intelScreen->deviceID)) {
466 if (!IS_965(intelScreen->deviceID)) {
467 return i915CreateContext(mesaVis, driContextPriv,
468 sharedContextPrivate);
469 }
470 } else {
471 return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
472 }
473 #else
474 if (IS_965(intelScreen->deviceID))
475 return brwCreateContext(mesaVis, driContextPriv, sharedContextPrivate);
476 #endif
477 fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID);
478 return GL_FALSE;
479 }
480
481
482 static __DRIconfig **
483 intelFillInModes(__DRIscreenPrivate *psp,
484 unsigned pixel_bits, unsigned depth_bits,
485 unsigned stencil_bits, GLboolean have_back_buffer)
486 {
487 __DRIconfig **configs;
488 __GLcontextModes *m;
489 unsigned depth_buffer_factor;
490 unsigned back_buffer_factor;
491 GLenum fb_format;
492 GLenum fb_type;
493 int i;
494
495 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
496 * support pageflipping at all.
497 */
498 static const GLenum back_buffer_modes[] = {
499 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
500 };
501
502 u_int8_t depth_bits_array[3];
503 u_int8_t stencil_bits_array[3];
504
505 depth_bits_array[0] = 0;
506 depth_bits_array[1] = depth_bits;
507 depth_bits_array[2] = depth_bits;
508
509 /* Just like with the accumulation buffer, always provide some modes
510 * with a stencil buffer. It will be a sw fallback, but some apps won't
511 * care about that.
512 */
513 stencil_bits_array[0] = 0;
514 stencil_bits_array[1] = 0;
515 if (depth_bits == 24)
516 stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
517
518 stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;
519
520 depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
521 back_buffer_factor = (have_back_buffer) ? 3 : 1;
522
523 if (pixel_bits == 16) {
524 fb_format = GL_RGB;
525 fb_type = GL_UNSIGNED_SHORT_5_6_5;
526 }
527 else {
528 fb_format = GL_BGRA;
529 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
530 }
531
532 configs = driCreateConfigs(fb_format, fb_type,
533 depth_bits_array, stencil_bits_array,
534 depth_buffer_factor, back_buffer_modes,
535 back_buffer_factor);
536 if (configs == NULL) {
537 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
538 __LINE__);
539 return NULL;
540 }
541
542 /* Mark the visual as slow if there are "fake" stencil bits.
543 */
544 for (i = 0; configs[i]; i++) {
545 m = &configs[i]->modes;
546 if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
547 m->visualRating = GLX_SLOW_CONFIG;
548 }
549 }
550
551 return configs;
552 }
553
554
555 /**
556 * This is the driver specific part of the createNewScreen entry point.
557 * Called when using legacy DRI.
558 *
559 * \todo maybe fold this into intelInitDriver
560 *
561 * \return the __GLcontextModes supported by this driver
562 */
563 static const __DRIconfig **intelInitScreen(__DRIscreenPrivate *psp)
564 {
565 #ifdef I915
566 static const __DRIversion ddx_expected = { 1, 5, 0 };
567 #else
568 static const __DRIversion ddx_expected = { 1, 6, 0 };
569 #endif
570 static const __DRIversion dri_expected = { 4, 0, 0 };
571 static const __DRIversion drm_expected = { 1, 5, 0 };
572 I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
573
574 if (!driCheckDriDdxDrmVersions2("i915",
575 &psp->dri_version, &dri_expected,
576 &psp->ddx_version, &ddx_expected,
577 &psp->drm_version, &drm_expected)) {
578 return NULL;
579 }
580
581 /* Calling driInitExtensions here, with a NULL context pointer,
582 * does not actually enable the extensions. It just makes sure
583 * that all the dispatch offsets for all the extensions that
584 * *might* be enables are known. This is needed because the
585 * dispatch offsets need to be known when _mesa_context_create is
586 * called, but we can't enable the extensions until we have a
587 * context pointer.
588 *
589 * Hello chicken. Hello egg. How are you two today?
590 */
591 intelInitExtensions(NULL, GL_TRUE);
592
593 if (!intelInitDriver(psp))
594 return NULL;
595
596 psp->extensions = intelScreenExtensions;
597
598 return (const __DRIconfig **)
599 intelFillInModes(psp, dri_priv->cpp * 8,
600 (dri_priv->cpp == 2) ? 16 : 24,
601 (dri_priv->cpp == 2) ? 0 : 8, 1);
602 }
603
604 struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen)
605 {
606 /*
607 * This should probably change to have the screen allocate a dummy
608 * context at screen creation. For now just use the current context.
609 */
610
611 GET_CURRENT_CONTEXT(ctx);
612 if (ctx == NULL) {
613 _mesa_problem(NULL, "No current context in intelScreenContext\n");
614 return NULL;
615 }
616 return intel_context(ctx);
617 }
618
619 /**
620 * This is the driver specific part of the createNewScreen entry point.
621 * Called when using DRI2.
622 *
623 * \return the __GLcontextModes supported by this driver
624 */
625 static const
626 __DRIconfig **intelInitScreen2(__DRIscreenPrivate *psp)
627 {
628 intelScreenPrivate *intelScreen;
629
630 /* Calling driInitExtensions here, with a NULL context pointer,
631 * does not actually enable the extensions. It just makes sure
632 * that all the dispatch offsets for all the extensions that
633 * *might* be enables are known. This is needed because the
634 * dispatch offsets need to be known when _mesa_context_create is
635 * called, but we can't enable the extensions until we have a
636 * context pointer.
637 *
638 * Hello chicken. Hello egg. How are you two today?
639 */
640 intelInitExtensions(NULL, GL_TRUE);
641
642 /* Allocate the private area */
643 intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
644 if (!intelScreen) {
645 fprintf(stderr, "\nERROR! Allocating private area failed\n");
646 return GL_FALSE;
647 }
648 /* parse information in __driConfigOptions */
649 driParseOptionInfo(&intelScreen->optionCache,
650 __driConfigOptions, __driNConfigOptions);
651
652 intelScreen->driScrnPriv = psp;
653 psp->private = (void *) intelScreen;
654
655 intelScreen->drmMinor = psp->drm_version.minor;
656
657 /* Determine chipset ID */
658 if (!intel_get_param(psp, I915_PARAM_CHIPSET_ID,
659 &intelScreen->deviceID))
660 return GL_FALSE;
661
662 intelScreen->irq_active = 1;
663 psp->extensions = intelScreenExtensions;
664
665 return driConcatConfigs(intelFillInModes(psp, 16, 16, 0, 1),
666 intelFillInModes(psp, 32, 24, 8, 1));
667 }
668
669 const struct __DriverAPIRec driDriverAPI = {
670 .InitScreen = intelInitScreen,
671 .DestroyScreen = intelDestroyScreen,
672 .CreateContext = intelCreateContext,
673 .DestroyContext = intelDestroyContext,
674 .CreateBuffer = intelCreateBuffer,
675 .DestroyBuffer = intelDestroyBuffer,
676 .SwapBuffers = intelSwapBuffers,
677 .MakeCurrent = intelMakeCurrent,
678 .UnbindContext = intelUnbindContext,
679 .GetSwapInfo = intelGetSwapInfo,
680 .GetDrawableMSC = driDrawableGetMSC32,
681 .WaitForMSC = driWaitForMSC32,
682 .CopySubBuffer = intelCopySubBuffer,
683
684 .InitScreen2 = intelInitScreen2,
685 };