intel_screen.c 19.6 KB
Newer Older
1
/**************************************************************************
2
 *
3 4
 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
5
 *
6 7 8 9 10 11 12
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
13
 *
14 15 16
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
17
 *
18 19 20 21 22 23 24
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
 *
26 27 28 29 30 31
 **************************************************************************/

#include "utils.h"
#include "vblank.h"
#include "xmlpool.h"

32
#include "intel_context.h"
33
#include "intel_screen.h"
34
#include "intel_batchbuffer.h"
35
#include "intel_swapbuffers.h"
36 37

#include "i830_dri.h"
38
#include "intel_drm/ws_dri_bufpool.h"
39 40

#include "pipe/p_context.h"
41 42
#include "pipe/p_screen.h"
#include "pipe/p_inlines.h"
Brian's avatar
Brian committed
43
#include "state_tracker/st_public.h"
Brian's avatar
Brian committed
44
#include "state_tracker/st_cb_fbo.h"
45

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
static void
intelCreateSurface(struct intel_screen *intelScreen, struct pipe_winsys *winsys, unsigned handle);

static void
intelCreateSurface(struct intel_screen *intelScreen, struct pipe_winsys *winsys, unsigned handle)
{
   struct intel_be_buffer *be_buf = malloc(sizeof(*be_buf));
   struct pipe_screen *screen = intelScreen->base.screen;
   struct pipe_texture *texture;
   struct pipe_texture templat;
   struct pipe_surface *surface;
   struct pipe_buffer *buffer = &be_buf->base;
   unsigned pitch;

   assert(intelScreen->front.cpp == 4);

   /* XXX create a intel_be function for this */
   {
      driGenBuffers(intelScreen->base.staticPool, "front", 1, &intelScreen->front.buffer, 0, 0, 0);
      driBOSetReferenced(intelScreen->front.buffer, handle);

      memset(be_buf, 0, sizeof(*be_buf));
      buffer->refcount = 1;
      buffer->alignment = 0;
      buffer->usage = 0;
      buffer->size = driBOSize(intelScreen->front.buffer);
      be_buf->driBO = intelScreen->front.buffer;
   }
74

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
   memset(&templat, 0, sizeof(templat));
   templat.tex_usage |= PIPE_TEXTURE_USAGE_DISPLAY_TARGET;
   templat.target = PIPE_TEXTURE_2D;
   templat.last_level = 0;
   templat.depth[0] = 1;
   templat.format = PIPE_FORMAT_A8R8G8B8_UNORM;
   templat.cpp = intelScreen->front.cpp;
   templat.width[0] = intelScreen->front.width;
   templat.height[0] = intelScreen->front.height;
   pitch = intelScreen->front.pitch / intelScreen->front.cpp;

   texture = screen->texture_blanket(screen,
                                     &templat,
                                     &pitch,
                                     buffer);

   /* Unref the buffer we don't need it anyways */
   pipe_buffer_reference(screen->winsys, &buffer, NULL);

   surface = screen->get_tex_surface(screen,
                                     texture,
                                     0,
                                     0,
                                     0,
                                     PIPE_BUFFER_USAGE_GPU_WRITE);

   intelScreen->front.texture = texture;
   intelScreen->front.surface = surface;
}
104 105 106 107 108 109

PUBLIC const char __driConfigOptions[] =
   DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE
   DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
   DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
   DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY
110
//   DRI_CONF_FORCE_S3TC_ENABLE(false)
111 112
   DRI_CONF_ALLOW_LARGE_TEXTURES(1)
   DRI_CONF_SECTION_END DRI_CONF_END;
Brian's avatar
Brian committed
113

114
const uint __driNConfigOptions = 3;
115 116

#ifdef USE_NEW_INTERFACE
Brian's avatar
Brian committed
117
static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
118 119
#endif /*USE_NEW_INTERFACE */

Brian's avatar
Brian committed
120
extern const struct dri_extension card_extensions[];
121

Alan Hourihane's avatar
Alan Hourihane committed
122

123 124 125


static void
126
intelPrintDRIInfo(struct intel_screen * intelScreen,
127 128 129 130 131 132 133 134
                  __DRIscreenPrivate * sPriv, I830DRIPtr gDRIPriv)
{
   fprintf(stderr, "*** Front size:   0x%x  offset: 0x%x  pitch: %d\n",
           intelScreen->front.size, intelScreen->front.offset,
           intelScreen->front.pitch);
   fprintf(stderr, "*** Memory : 0x%x\n", gDRIPriv->mem);
}

135

Keith Whitwell's avatar
Keith Whitwell committed
136
#if 0
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
static void
intelPrintSAREA(const drmI830Sarea * sarea)
{
   fprintf(stderr, "SAREA: sarea width %d  height %d\n", sarea->width,
           sarea->height);
   fprintf(stderr, "SAREA: pitch: %d\n", sarea->pitch);
   fprintf(stderr,
           "SAREA: front offset: 0x%08x  size: 0x%x  handle: 0x%x\n",
           sarea->front_offset, sarea->front_size,
           (unsigned) sarea->front_handle);
   fprintf(stderr,
           "SAREA: back  offset: 0x%08x  size: 0x%x  handle: 0x%x\n",
           sarea->back_offset, sarea->back_size,
           (unsigned) sarea->back_handle);
   fprintf(stderr, "SAREA: depth offset: 0x%08x  size: 0x%x  handle: 0x%x\n",
           sarea->depth_offset, sarea->depth_size,
           (unsigned) sarea->depth_handle);
   fprintf(stderr, "SAREA: tex   offset: 0x%08x  size: 0x%x  handle: 0x%x\n",
           sarea->tex_offset, sarea->tex_size, (unsigned) sarea->tex_handle);
   fprintf(stderr, "SAREA: rotation: %d\n", sarea->rotation);
   fprintf(stderr,
           "SAREA: rotated offset: 0x%08x  size: 0x%x\n",
           sarea->rotated_offset, sarea->rotated_size);
   fprintf(stderr, "SAREA: rotated pitch: %d\n", sarea->rotated_pitch);
}
Keith Whitwell's avatar
Keith Whitwell committed
162
#endif
163 164 165


/**
166 167
 * Use the information in the sarea to update the screen parameters
 * related to screen rotation. Needs to be called locked.
168 169
 */
void
170
intelUpdateScreenRotation(__DRIscreenPrivate * sPriv, drmI830Sarea * sarea)
171
{
172
   struct intel_screen *intelScreen = intel_screen(sPriv);
173

174 175 176 177 178 179 180 181 182 183
   if (intelScreen->front.map) {
      drmUnmap(intelScreen->front.map, intelScreen->front.size);
      intelScreen->front.map = NULL;
   }

   if (intelScreen->front.buffer)
      driDeleteBuffers(1, &intelScreen->front.buffer);

   intelScreen->front.width = sarea->width;
   intelScreen->front.height = sarea->height;
184
   intelScreen->front.offset = sarea->front_offset;
185
   intelScreen->front.pitch = sarea->pitch * intelScreen->front.cpp;
186
   intelScreen->front.size = sarea->front_size;
187
   intelScreen->front.handle = sarea->front_handle;
188

189 190 191
   assert( sarea->front_size >=
	   intelScreen->front.pitch * intelScreen->front.height );

192
#if 0 /* JB not important */
193 194 195 196 197 198 199
   if (!sarea->front_handle)
      return;

   if (drmMap(sPriv->fd,
	      sarea->front_handle,
	      intelScreen->front.size,
	      (drmAddress *) & intelScreen->front.map) != 0) {
200
      fprintf(stderr, "drmMap(frontbuffer) failed!\n");
201 202
      return;
   }
203
#endif
204

205
#if 0 /* JB */
206 207 208 209 210
   if (intelScreen->staticPool) {
      driGenBuffers(intelScreen->staticPool, "static region", 1,
		    &intelScreen->front.buffer, 64,
		    DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_NO_MOVE |
		    DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0);
211

212 213 214
      driBOSetStatic(intelScreen->front.buffer,
		     intelScreen->front.offset,
		     intelScreen->front.pitch * intelScreen->front.height,
215 216
		     intelScreen->front.map, 0);
   }
217
#else
218
   if (intelScreen->base.staticPool) {
219
      if (intelScreen->front.buffer) {
220
	 driBOUnReference(intelScreen->front.buffer);
221 222 223 224
	 pipe_surface_reference(&intelScreen->front.surface, NULL);
	 pipe_texture_reference(&intelScreen->front.texture, NULL);
      }
      intelCreateSurface(intelScreen, &intelScreen->base.base, sarea->front_bo_handle);
225 226
   }
#endif
227 228
}

229

230
boolean
231
intelCreatePools(__DRIscreenPrivate * sPriv)
232
{
233
   //unsigned batchPoolSize = 1024*1024;
234
   struct intel_screen *intelScreen = intel_screen(sPriv);
235 236 237 238 239 240

   if (intelScreen->havePools)
      return GL_TRUE;

   intelScreen->havePools = GL_TRUE;

Alan Hourihane's avatar
Alan Hourihane committed
241
   intelUpdateScreenRotation(sPriv, intelScreen->sarea);
242

243 244 245
   return GL_TRUE;
}

246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
static const char *
intel_get_name( struct pipe_winsys *winsys )
{
   return "Intel/DRI/ttm";
}

/*
 * The state tracker (should!) keep track of whether the fake
 * frontbuffer has been touched by any rendering since the last time
 * we copied its contents to the real frontbuffer.  Our task is easy:
 */
static void
intel_flush_frontbuffer( struct pipe_winsys *winsys,
                         struct pipe_surface *surf,
                         void *context_private)
{
262 263
   //struct intel_context *intel = (struct intel_context *) context_private;
   //__DRIdrawablePrivate *dPriv = intel->driDrawable;
264

265 266 267
   assert((int)"Doesn't work currently" & 0);

   //intelDisplaySurface(dPriv, surf, NULL);
268
}
269

270
static boolean
271 272
intelInitDriver(__DRIscreenPrivate * sPriv)
{
273
   struct intel_screen *intelScreen;
274 275
   I830DRIPtr gDRIPriv = (I830DRIPtr) sPriv->pDevPriv;

Alan Hourihane's avatar
Alan Hourihane committed
276 277 278 279 280
   PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension =
      (PFNGLXSCRENABLEEXTENSIONPROC) (*dri_interface->
                                      getProcAddress("glxEnableExtension"));
   void *const psc = sPriv->psc->screenConfigs;

281 282 283 284 285 286 287
   if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
      fprintf(stderr,
              "\nERROR!  sizeof(I830DRIRec) does not match passed size from device driver\n");
      return GL_FALSE;
   }

   /* Allocate the private area */
288
   intelScreen = CALLOC_STRUCT(intel_screen);
289
   if (!intelScreen)
290
      return GL_FALSE;
291

292 293 294 295 296 297
   /* parse information in __driConfigOptions */
   driParseOptionInfo(&intelScreen->optionCache,
                      __driConfigOptions, __driNConfigOptions);

   sPriv->private = (void *) intelScreen;

Alan Hourihane's avatar
Alan Hourihane committed
298 299
   intelScreen->sarea = (drmI830Sarea *) (((GLubyte *) sPriv->pSAREA) +
					  gDRIPriv->sarea_priv_offset);
Alan Hourihane's avatar
Alan Hourihane committed
300
   intelScreen->deviceID = gDRIPriv->deviceID;
Alan Hourihane's avatar
Alan Hourihane committed
301
   intelScreen->front.cpp = gDRIPriv->cpp;
Alan Hourihane's avatar
Alan Hourihane committed
302 303 304 305 306
   intelScreen->drmMinor = sPriv->drmMinor;

   assert(gDRIPriv->bitsPerPixel == 16 ||
	  gDRIPriv->bitsPerPixel == 32);

307
   intelUpdateScreenRotation(sPriv, intelScreen->sarea);
308 309 310 311

   if (0)
      intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv);

Alan Hourihane's avatar
Alan Hourihane committed
312 313 314 315 316 317 318
   if (glx_enable_extension != NULL) {
      (*glx_enable_extension) (psc, "GLX_SGI_swap_control");
      (*glx_enable_extension) (psc, "GLX_SGI_video_sync");
      (*glx_enable_extension) (psc, "GLX_MESA_swap_control");
      (*glx_enable_extension) (psc, "GLX_MESA_swap_frame_usage");
      (*glx_enable_extension) (psc, "GLX_SGI_make_current_read");
   }
319

320 321
   intelScreen->base.base.flush_frontbuffer = intel_flush_frontbuffer;
   intelScreen->base.base.get_name = intel_get_name;
322
   intel_be_init_device(&intelScreen->base, sPriv->fd, intelScreen->deviceID);
323

324 325 326 327 328 329 330
   return GL_TRUE;
}


static void
intelDestroyScreen(__DRIscreenPrivate * sPriv)
{
331
   struct intel_screen *intelScreen = intel_screen(sPriv);
332

333
   intel_be_destroy_device(&intelScreen->base);
Brian's avatar
Brian committed
334
   /*  intelUnmapScreenRegions(intelScreen); */
335 336 337 338 339 340 341 342 343

   FREE(intelScreen);
   sPriv->private = NULL;
}


/**
 * This is called when we need to set up GL rendering to a new X window.
 */
344
static boolean
345 346
intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
                  __DRIdrawablePrivate * driDrawPriv,
347
                  const __GLcontextModes * visual, boolean isPixmap)
348 349 350 351 352
{
   if (isPixmap) {
      return GL_FALSE;          /* not implemented */
   }
   else {
353
      enum pipe_format colorFormat, depthFormat, stencilFormat;
354
      struct intel_framebuffer *intelfb = CALLOC_STRUCT(intel_framebuffer);
355

356 357 358
      if (!intelfb)
         return GL_FALSE;

359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
      if (visual->redBits == 5)
         colorFormat = PIPE_FORMAT_R5G6B5_UNORM;
      else
         colorFormat = PIPE_FORMAT_A8R8G8B8_UNORM;

      if (visual->depthBits == 16)
         depthFormat = PIPE_FORMAT_Z16_UNORM;
      else if (visual->depthBits == 24)
         depthFormat = PIPE_FORMAT_S8Z24_UNORM;
      else
         depthFormat = PIPE_FORMAT_NONE;

      if (visual->stencilBits == 8)
         stencilFormat = PIPE_FORMAT_S8Z24_UNORM;
      else
         stencilFormat = PIPE_FORMAT_NONE;

376
      intelfb->stfb = st_create_framebuffer(visual,
377 378 379
                                            colorFormat,
                                            depthFormat,
                                            stencilFormat,
380 381
                                            driDrawPriv->w,
                                            driDrawPriv->h,
382
                                            (void*) intelfb);
383 384 385 386 387 388
      if (!intelfb->stfb) {
         free(intelfb);
         return GL_FALSE;
      }

      driDrawPriv->driverPrivate = (void *) intelfb;
389 390 391 392 393 394 395
      return GL_TRUE;
   }
}

static void
intelDestroyBuffer(__DRIdrawablePrivate * driDrawPriv)
{
396 397 398 399
   struct intel_framebuffer *intelfb = intel_framebuffer(driDrawPriv);
   assert(intelfb->stfb);
   st_unreference_framebuffer(&intelfb->stfb);
   free(intelfb);
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
}


/**
 * Get information about previous buffer swaps.
 */
static int
intelGetSwapInfo(__DRIdrawablePrivate * dPriv, __DRIswapInfo * sInfo)
{
   if ((dPriv == NULL) || (dPriv->driverPrivate == NULL)
       || (sInfo == NULL)) {
      return -1;
   }

   return 0;
}

Alan Hourihane's avatar
Alan Hourihane committed
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467

static void
intelSetTexOffset(__DRIcontext *pDRICtx, int texname,
		  unsigned long long offset, int depth, uint pitch)
{
   abort();
#if 0
   struct intel_context *intel = (struct intel_context*)
      ((__DRIcontextPrivate*)pDRICtx->private)->driverPrivate;
   struct gl_texture_object *tObj = _mesa_lookup_texture(&intel->ctx, texname);
   struct st_texture_object *stObj = st_texture_object(tObj);

   if (!stObj)
      return;

   if (stObj->pt)
      st->pipe->texture_release(intel->st->pipe, &stObj->pt);

   stObj->imageOverride = GL_TRUE;
   stObj->depthOverride = depth;
   stObj->pitchOverride = pitch;

   if (offset)
      stObj->textureOffset = offset;
#endif
}


static const struct __DriverAPIRec intelAPI = {
   .InitDriver = intelInitDriver,
   .DestroyScreen = intelDestroyScreen,
   .CreateContext = intelCreateContext,
   .DestroyContext = intelDestroyContext,
   .CreateBuffer = intelCreateBuffer,
   .DestroyBuffer = intelDestroyBuffer,
   .SwapBuffers = intelSwapBuffers,
   .MakeCurrent = intelMakeCurrent,
   .UnbindContext = intelUnbindContext,
   .GetSwapInfo = intelGetSwapInfo,
   .GetMSC = driGetMSC32,
   .WaitForMSC = driWaitForMSC32,
   .WaitForSBC = NULL,
   .SwapBuffersMSC = NULL,
   .CopySubBuffer = intelCopySubBuffer,
   .setTexOffset = intelSetTexOffset,
};


static __GLcontextModes *
intelFillInModes(unsigned pixel_bits, unsigned depth_bits,
                 unsigned stencil_bits, boolean have_back_buffer)
468
{
Alan Hourihane's avatar
Alan Hourihane committed
469
   __GLcontextModes *modes;
470 471 472 473 474 475 476 477 478 479 480 481 482 483
   __GLcontextModes *m;
   unsigned num_modes;
   unsigned depth_buffer_factor;
   unsigned back_buffer_factor;
   GLenum fb_format;
   GLenum fb_type;

   /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
    * support pageflipping at all.
    */
   static const GLenum back_buffer_modes[] = {
      GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
   };

484 485
   uint8_t depth_bits_array[3];
   uint8_t stencil_bits_array[3];
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516


   depth_bits_array[0] = 0;
   depth_bits_array[1] = depth_bits;
   depth_bits_array[2] = depth_bits;

   /* Just like with the accumulation buffer, always provide some modes
    * with a stencil buffer.  It will be a sw fallback, but some apps won't
    * care about that.
    */
   stencil_bits_array[0] = 0;
   stencil_bits_array[1] = 0;
   if (depth_bits == 24)
      stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;

   stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;

   depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
   back_buffer_factor = (have_back_buffer) ? 3 : 1;

   num_modes = depth_buffer_factor * back_buffer_factor * 4;

   if (pixel_bits == 16) {
      fb_format = GL_RGB;
      fb_type = GL_UNSIGNED_SHORT_5_6_5;
   }
   else {
      fb_format = GL_BGRA;
      fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
   }

Alan Hourihane's avatar
Alan Hourihane committed
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
   modes =
      (*dri_interface->createContextModes) (num_modes,
                                            sizeof(__GLcontextModes));
   m = modes;
   if (!driFillInModes(&m, fb_format, fb_type,
                       depth_bits_array, stencil_bits_array,
                       depth_buffer_factor, back_buffer_modes,
                       back_buffer_factor, GLX_TRUE_COLOR)) {
      fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
              __LINE__);
      return NULL;
   }
   if (!driFillInModes(&m, fb_format, fb_type,
                       depth_bits_array, stencil_bits_array,
                       depth_buffer_factor, back_buffer_modes,
                       back_buffer_factor, GLX_DIRECT_COLOR)) {
      fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
534 535 536 537 538 539
              __LINE__);
      return NULL;
   }

   /* Mark the visual as slow if there are "fake" stencil bits.
    */
Alan Hourihane's avatar
Alan Hourihane committed
540
   for (m = modes; m != NULL; m = m->next) {
541 542 543 544 545
      if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
         m->visualRating = GLX_SLOW_CONFIG;
      }
   }

Alan Hourihane's avatar
Alan Hourihane committed
546
   return modes;
547 548
}

Alan Hourihane's avatar
Alan Hourihane committed
549

550
/**
Alan Hourihane's avatar
Alan Hourihane committed
551 552 553 554 555
 * This is the bootstrap function for the driver.  libGL supplies all of the
 * requisite information about the system, and the driver initializes itself.
 * This routine also fills in the linked list pointed to by \c driver_modes
 * with the \c __GLcontextModes that the driver can support for windows or
 * pbuffers.
556
 *
Alan Hourihane's avatar
Alan Hourihane committed
557 558
 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
 *         failure.
559
 */
Alan Hourihane's avatar
Alan Hourihane committed
560 561 562 563 564 565 566 567 568 569 570 571
PUBLIC void *
__driCreateNewScreen_20050727(__DRInativeDisplay * dpy, int scrn,
                              __DRIscreen * psc,
                              const __GLcontextModes * modes,
                              const __DRIversion * ddx_version,
                              const __DRIversion * dri_version,
                              const __DRIversion * drm_version,
                              const __DRIframebuffer * frame_buffer,
                              drmAddress pSAREA, int fd,
                              int internal_api_version,
                              const __DRIinterfaceMethods * interface,
                              __GLcontextModes ** driver_modes)
572
{
Alan Hourihane's avatar
Alan Hourihane committed
573 574
   __DRIscreenPrivate *psp;
   static const __DRIversion ddx_expected = { 1, 7, 0 };
575
   static const __DRIversion dri_expected = { 4, 0, 0 };
Alan Hourihane's avatar
Alan Hourihane committed
576 577 578
   static const __DRIversion drm_expected = { 1, 7, 0 };

   dri_interface = interface;
579 580

   if (!driCheckDriDdxDrmVersions2("i915",
Alan Hourihane's avatar
Alan Hourihane committed
581 582 583
                                   dri_version, &dri_expected,
                                   ddx_version, &ddx_expected,
                                   drm_version, &drm_expected)) {
584 585 586
      return NULL;
   }

Alan Hourihane's avatar
Alan Hourihane committed
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
   psp = __driUtilCreateNewScreen(dpy, scrn, psc, NULL,
                                  ddx_version, dri_version, drm_version,
                                  frame_buffer, pSAREA, fd,
                                  internal_api_version, &intelAPI);

   if (psp != NULL) {
      I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
      *driver_modes = intelFillInModes(dri_priv->cpp * 8,
                                       (dri_priv->cpp == 2) ? 16 : 24,
                                       (dri_priv->cpp == 2) ? 0 : 8, 1);

      /* Calling driInitExtensions here, with a NULL context pointer,
       * does not actually enable the extensions.  It just makes sure
       * that all the dispatch offsets for all the extensions that
       * *might* be enables are known.  This is needed because the
       * dispatch offsets need to be known when _mesa_context_create
       * is called, but we can't enable the extensions until we have a
       * context pointer.
       *
       * Hello chicken.  Hello egg.  How are you two today?
       */
      driInitExtensions(NULL, card_extensions, GL_FALSE);
609
   }
Alan Hourihane's avatar
Alan Hourihane committed
610

Alan Hourihane's avatar
Alan Hourihane committed
611
   return (void *) psp;
612 613
}