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