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