fix compiler warnings
[mesa.git] / src / mesa / drivers / dri / i915tex / 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_tris.h"
45 #include "intel_ioctl.h"
46 #include "intel_fbo.h"
47
48 #include "i830_dri.h"
49 #include "dri_bufpool.h"
50 #include "intel_regions.h"
51 #include "intel_batchbuffer.h"
52
53 PUBLIC const char __driConfigOptions[] =
54 DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE
55 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
56 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
57 DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY
58 DRI_CONF_FORCE_S3TC_ENABLE(false)
59 DRI_CONF_ALLOW_LARGE_TEXTURES(1)
60 DRI_CONF_SECTION_END DRI_CONF_END;
61 const GLuint __driNConfigOptions = 4;
62
63 #ifdef USE_NEW_INTERFACE
64 static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
65 #endif /*USE_NEW_INTERFACE */
66
67 extern const struct dri_extension card_extensions[];
68
69 /**
70 * Map all the memory regions described by the screen.
71 * \return GL_TRUE if success, GL_FALSE if error.
72 */
73 GLboolean
74 intelMapScreenRegions(__DRIscreenPrivate * sPriv)
75 {
76 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
77
78 if (intelScreen->front.handle) {
79 if (drmMap(sPriv->fd,
80 intelScreen->front.handle,
81 intelScreen->front.size,
82 (drmAddress *) & intelScreen->front.map) != 0) {
83 _mesa_problem(NULL, "drmMap(frontbuffer) failed!");
84 return GL_FALSE;
85 }
86 }
87 else {
88 _mesa_warning(NULL, "no front buffer handle in intelMapScreenRegions!");
89 }
90
91 _mesa_printf("Back 0x%08x ", intelScreen->back.handle);
92 if (drmMap(sPriv->fd,
93 intelScreen->back.handle,
94 intelScreen->back.size,
95 (drmAddress *) & intelScreen->back.map) != 0) {
96 intelUnmapScreenRegions(intelScreen);
97 return GL_FALSE;
98 }
99
100 _mesa_printf("Depth 0x%08x ", intelScreen->depth.handle);
101 if (drmMap(sPriv->fd,
102 intelScreen->depth.handle,
103 intelScreen->depth.size,
104 (drmAddress *) & intelScreen->depth.map) != 0) {
105 intelUnmapScreenRegions(intelScreen);
106 return GL_FALSE;
107 }
108
109 #if 0
110 _mesa_printf("TEX 0x%08x ", intelScreen->tex.handle);
111 if (drmMap(sPriv->fd,
112 intelScreen->tex.handle,
113 intelScreen->tex.size,
114 (drmAddress *) & intelScreen->tex.map) != 0) {
115 intelUnmapScreenRegions(intelScreen);
116 return GL_FALSE;
117 }
118 #endif
119 if (0)
120 printf("Mappings: front: %p back: %p depth: %p tex: %p\n",
121 intelScreen->front.map,
122 intelScreen->back.map,
123 intelScreen->depth.map, intelScreen->tex.map);
124 return GL_TRUE;
125 }
126
127
128 static struct intel_region *
129 intel_recreate_static(intelScreenPrivate *intelScreen,
130 struct intel_region *region,
131 GLuint mem_type,
132 GLuint offset,
133 void *virtual,
134 GLuint cpp, GLuint pitch, GLuint height)
135 {
136 if (region) {
137 intel_region_update_static(intelScreen, region, mem_type, offset,
138 virtual, cpp, pitch, height);
139 } else {
140 region = intel_region_create_static(intelScreen, mem_type, offset,
141 virtual, cpp, pitch, height);
142 }
143 return region;
144 }
145
146
147 /* Create intel_region structs to describe the static front,back,depth
148 * buffers created by the xserver.
149 *
150 * Although FBO's mean we now no longer use these as render targets in
151 * all circumstances, they won't go away until the back and depth
152 * buffers become private, and the front and rotated buffers will
153 * remain even then.
154 *
155 * Note that these don't allocate video memory, just describe
156 * allocations alread made by the X server.
157 */
158 static void
159 intel_recreate_static_regions(intelScreenPrivate *intelScreen)
160 {
161 intelScreen->front_region =
162 intel_recreate_static(intelScreen,
163 intelScreen->front_region,
164 DRM_BO_FLAG_MEM_TT,
165 intelScreen->front.offset,
166 intelScreen->front.map,
167 intelScreen->cpp,
168 intelScreen->front.pitch / intelScreen->cpp,
169 intelScreen->height);
170
171 intelScreen->rotated_region =
172 intel_recreate_static(intelScreen,
173 intelScreen->rotated_region,
174 DRM_BO_FLAG_MEM_TT,
175 intelScreen->rotated.offset,
176 intelScreen->rotated.map,
177 intelScreen->cpp,
178 intelScreen->rotated.pitch /
179 intelScreen->cpp, intelScreen->height);
180
181
182 intelScreen->back_region =
183 intel_recreate_static(intelScreen,
184 intelScreen->back_region,
185 DRM_BO_FLAG_MEM_TT,
186 intelScreen->back.offset,
187 intelScreen->back.map,
188 intelScreen->cpp,
189 intelScreen->back.pitch / intelScreen->cpp,
190 intelScreen->height);
191
192 /* Still assuming front.cpp == depth.cpp
193 */
194 intelScreen->depth_region =
195 intel_recreate_static(intelScreen,
196 intelScreen->depth_region,
197 DRM_BO_FLAG_MEM_TT,
198 intelScreen->depth.offset,
199 intelScreen->depth.map,
200 intelScreen->cpp,
201 intelScreen->depth.pitch / intelScreen->cpp,
202 intelScreen->height);
203 }
204
205 /**
206 * Use the information in the sarea to update the screen parameters
207 * related to screen rotation. Needs to be called locked.
208 */
209 void
210 intelUpdateScreenRotation(__DRIscreenPrivate * sPriv, drmI830Sarea * sarea)
211 {
212 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
213
214 intelUnmapScreenRegions(intelScreen);
215 intelUpdateScreenFromSAREA(intelScreen, sarea);
216 if (!intelMapScreenRegions(sPriv)) {
217 fprintf(stderr, "ERROR Remapping screen regions!!!\n");
218 }
219 intel_recreate_static_regions(intelScreen);
220 }
221
222
223 void
224 intelUnmapScreenRegions(intelScreenPrivate * intelScreen)
225 {
226 #define REALLY_UNMAP 1
227 if (intelScreen->front.map) {
228 #if REALLY_UNMAP
229 if (drmUnmap(intelScreen->front.map, intelScreen->front.size) != 0)
230 printf("drmUnmap front failed!\n");
231 #endif
232 intelScreen->front.map = NULL;
233 }
234 if (intelScreen->back.map) {
235 #if REALLY_UNMAP
236 if (drmUnmap(intelScreen->back.map, intelScreen->back.size) != 0)
237 printf("drmUnmap back failed!\n");
238 #endif
239 intelScreen->back.map = NULL;
240 }
241 if (intelScreen->depth.map) {
242 #if REALLY_UNMAP
243 drmUnmap(intelScreen->depth.map, intelScreen->depth.size);
244 intelScreen->depth.map = NULL;
245 #endif
246 }
247 if (intelScreen->tex.map) {
248 #if REALLY_UNMAP
249 drmUnmap(intelScreen->tex.map, intelScreen->tex.size);
250 intelScreen->tex.map = NULL;
251 #endif
252 }
253 }
254
255
256 static void
257 intelPrintDRIInfo(intelScreenPrivate * intelScreen,
258 __DRIscreenPrivate * sPriv, I830DRIPtr gDRIPriv)
259 {
260 fprintf(stderr, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
261 intelScreen->front.size, intelScreen->front.offset,
262 intelScreen->front.pitch);
263 fprintf(stderr, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
264 intelScreen->back.size, intelScreen->back.offset,
265 intelScreen->back.pitch);
266 fprintf(stderr, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
267 intelScreen->depth.size, intelScreen->depth.offset,
268 intelScreen->depth.pitch);
269 fprintf(stderr, "*** Rotated size: 0x%x offset: 0x%x pitch: %d\n",
270 intelScreen->rotated.size, intelScreen->rotated.offset,
271 intelScreen->rotated.pitch);
272 fprintf(stderr, "*** Texture size: 0x%x offset: 0x%x\n",
273 intelScreen->tex.size, intelScreen->tex.offset);
274 fprintf(stderr, "*** Memory : 0x%x\n", gDRIPriv->mem);
275 }
276
277
278 static void
279 intelPrintSAREA(const drmI830Sarea * sarea)
280 {
281 fprintf(stderr, "SAREA: sarea width %d height %d\n", sarea->width,
282 sarea->height);
283 fprintf(stderr, "SAREA: pitch: %d\n", sarea->pitch);
284 fprintf(stderr,
285 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x\n",
286 sarea->front_offset, sarea->front_size,
287 (unsigned) sarea->front_handle);
288 fprintf(stderr,
289 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x\n",
290 sarea->back_offset, sarea->back_size,
291 (unsigned) sarea->back_handle);
292 fprintf(stderr, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x\n",
293 sarea->depth_offset, sarea->depth_size,
294 (unsigned) sarea->depth_handle);
295 fprintf(stderr, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
296 sarea->tex_offset, sarea->tex_size, (unsigned) sarea->tex_handle);
297 fprintf(stderr, "SAREA: rotation: %d\n", sarea->rotation);
298 fprintf(stderr,
299 "SAREA: rotated offset: 0x%08x size: 0x%x\n",
300 sarea->rotated_offset, sarea->rotated_size);
301 fprintf(stderr, "SAREA: rotated pitch: %d\n", sarea->rotated_pitch);
302 }
303
304
305 /**
306 * A number of the screen parameters are obtained/computed from
307 * information in the SAREA. This function updates those parameters.
308 */
309 void
310 intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen,
311 drmI830Sarea * sarea)
312 {
313 intelScreen->width = sarea->width;
314 intelScreen->height = sarea->height;
315
316 intelScreen->front.offset = sarea->front_offset;
317 intelScreen->front.pitch = sarea->pitch * intelScreen->cpp;
318 intelScreen->front.handle = sarea->front_handle;
319 intelScreen->front.size = sarea->front_size;
320
321 intelScreen->back.offset = sarea->back_offset;
322 intelScreen->back.pitch = sarea->pitch * intelScreen->cpp;
323 intelScreen->back.handle = sarea->back_handle;
324 intelScreen->back.size = sarea->back_size;
325
326 intelScreen->depth.offset = sarea->depth_offset;
327 intelScreen->depth.pitch = sarea->pitch * intelScreen->cpp;
328 intelScreen->depth.handle = sarea->depth_handle;
329 intelScreen->depth.size = sarea->depth_size;
330
331 intelScreen->tex.offset = sarea->tex_offset;
332 intelScreen->logTextureGranularity = sarea->log_tex_granularity;
333 intelScreen->tex.handle = sarea->tex_handle;
334 intelScreen->tex.size = sarea->tex_size;
335
336 intelScreen->rotated.offset = sarea->rotated_offset;
337 intelScreen->rotated.pitch = sarea->rotated_pitch * intelScreen->cpp;
338 intelScreen->rotated.size = sarea->rotated_size;
339 intelScreen->current_rotation = sarea->rotation;
340 matrix23Rotate(&intelScreen->rotMatrix,
341 sarea->width, sarea->height, sarea->rotation);
342 intelScreen->rotatedWidth = sarea->virtualX;
343 intelScreen->rotatedHeight = sarea->virtualY;
344
345 if (0)
346 intelPrintSAREA(sarea);
347 }
348
349
350 static GLboolean
351 intelInitDriver(__DRIscreenPrivate * sPriv)
352 {
353 intelScreenPrivate *intelScreen;
354 I830DRIPtr gDRIPriv = (I830DRIPtr) sPriv->pDevPriv;
355 drmI830Sarea *sarea;
356 unsigned batchPoolSize = 1024*1024;
357
358 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension =
359 (PFNGLXSCRENABLEEXTENSIONPROC) (*dri_interface->
360 getProcAddress("glxEnableExtension"));
361 void *const psc = sPriv->psc->screenConfigs;
362
363 if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
364 fprintf(stderr,
365 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
366 return GL_FALSE;
367 }
368
369 /* Allocate the private area */
370 intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
371 if (!intelScreen) {
372 fprintf(stderr, "\nERROR! Allocating private area failed\n");
373 return GL_FALSE;
374 }
375 /* parse information in __driConfigOptions */
376 driParseOptionInfo(&intelScreen->optionCache,
377 __driConfigOptions, __driNConfigOptions);
378
379 intelScreen->driScrnPriv = sPriv;
380 sPriv->private = (void *) intelScreen;
381 intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
382 sarea = (drmI830Sarea *)
383 (((GLubyte *) sPriv->pSAREA) + intelScreen->sarea_priv_offset);
384
385 intelScreen->maxBatchSize = BATCH_SZ;
386 intelScreen->deviceID = gDRIPriv->deviceID;
387 if (intelScreen->deviceID == PCI_CHIP_I865_G)
388 intelScreen->maxBatchSize = 4096;
389 batchPoolSize /= intelScreen->maxBatchSize;
390
391 intelScreen->mem = gDRIPriv->mem;
392 intelScreen->cpp = gDRIPriv->cpp;
393
394 switch (gDRIPriv->bitsPerPixel) {
395 case 16:
396 intelScreen->fbFormat = DV_PF_565;
397 break;
398 case 32:
399 intelScreen->fbFormat = DV_PF_8888;
400 break;
401 default:
402 exit(1);
403 break;
404 }
405
406 intelUpdateScreenFromSAREA(intelScreen, sarea);
407
408 if (!intelMapScreenRegions(sPriv)) {
409 fprintf(stderr, "\nERROR! mapping regions\n");
410 _mesa_free(intelScreen);
411 sPriv->private = NULL;
412 return GL_FALSE;
413 }
414
415 #if 0
416
417 /*
418 * FIXME: Remove this code and its references.
419 */
420
421 intelScreen->tex.offset = gDRIPriv->textureOffset;
422 intelScreen->logTextureGranularity = gDRIPriv->logTextureGranularity;
423 intelScreen->tex.handle = gDRIPriv->textures;
424 intelScreen->tex.size = gDRIPriv->textureSize;
425
426 #else
427 intelScreen->tex.offset = 0;
428 intelScreen->logTextureGranularity = 0;
429 intelScreen->tex.handle = 0;
430 intelScreen->tex.size = 0;
431 #endif
432
433 intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
434
435 if (1)
436 intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv);
437
438 intelScreen->drmMinor = sPriv->drmMinor;
439
440 /* Determine if IRQs are active? */
441 {
442 int ret;
443 drmI830GetParam gp;
444
445 gp.param = I830_PARAM_IRQ_ACTIVE;
446 gp.value = &intelScreen->irq_active;
447
448 ret = drmCommandWriteRead(sPriv->fd, DRM_I830_GETPARAM,
449 &gp, sizeof(gp));
450 if (ret) {
451 fprintf(stderr, "drmI830GetParam: %d\n", ret);
452 return GL_FALSE;
453 }
454 }
455
456 /* Determine if batchbuffers are allowed */
457 {
458 int ret;
459 drmI830GetParam gp;
460
461 gp.param = I830_PARAM_ALLOW_BATCHBUFFER;
462 gp.value = &intelScreen->allow_batchbuffer;
463
464 ret = drmCommandWriteRead(sPriv->fd, DRM_I830_GETPARAM,
465 &gp, sizeof(gp));
466 if (ret) {
467 fprintf(stderr, "drmI830GetParam: (%d) %d\n", gp.param, ret);
468 return GL_FALSE;
469 }
470 }
471
472 if (glx_enable_extension != NULL) {
473 (*glx_enable_extension) (psc, "GLX_SGI_swap_control");
474 (*glx_enable_extension) (psc, "GLX_SGI_video_sync");
475 (*glx_enable_extension) (psc, "GLX_MESA_swap_control");
476 (*glx_enable_extension) (psc, "GLX_MESA_swap_frame_usage");
477 (*glx_enable_extension) (psc, "GLX_SGI_make_current_read");
478 }
479
480 intelScreen->regionPool = driDRMPoolInit(sPriv->fd);
481
482 if (!intelScreen->regionPool)
483 return GL_FALSE;
484
485 intelScreen->staticPool = driDRMStaticPoolInit(sPriv->fd);
486
487 if (!intelScreen->staticPool)
488 return GL_FALSE;
489
490 intelScreen->texPool = intelScreen->regionPool;
491
492 intelScreen->batchPool = driBatchPoolInit(sPriv->fd,
493 DRM_BO_FLAG_EXE |
494 DRM_BO_FLAG_MEM_TT |
495 DRM_BO_FLAG_MEM_LOCAL,
496 intelScreen->maxBatchSize,
497 batchPoolSize, 5);
498 if (!intelScreen->batchPool) {
499 fprintf(stderr, "Failed to initialize batch pool - possible incorrect agpgart installed\n");
500 return GL_FALSE;
501 }
502
503 intel_recreate_static_regions(intelScreen);
504
505 return GL_TRUE;
506 }
507
508
509 static void
510 intelDestroyScreen(__DRIscreenPrivate * sPriv)
511 {
512 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
513
514 intelUnmapScreenRegions(intelScreen);
515
516 driPoolTakeDown(intelScreen->regionPool);
517 driPoolTakeDown(intelScreen->staticPool);
518 driPoolTakeDown(intelScreen->batchPool);
519 FREE(intelScreen);
520 sPriv->private = NULL;
521 }
522
523
524 /**
525 * This is called when we need to set up GL rendering to a new X window.
526 */
527 static GLboolean
528 intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
529 __DRIdrawablePrivate * driDrawPriv,
530 const __GLcontextModes * mesaVis, GLboolean isPixmap)
531 {
532 intelScreenPrivate *screen = (intelScreenPrivate *) driScrnPriv->private;
533
534 if (isPixmap) {
535 return GL_FALSE; /* not implemented */
536 }
537 else {
538 GLboolean swStencil = (mesaVis->stencilBits > 0 &&
539 mesaVis->depthBits != 24);
540 GLenum rgbFormat = (mesaVis->redBits == 5 ? GL_RGB5 : GL_RGBA8);
541
542 struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis);
543
544 /* setup the hardware-based renderbuffers */
545 {
546 struct intel_renderbuffer *frontRb
547 = intel_create_renderbuffer(rgbFormat,
548 screen->width, screen->height,
549 screen->front.offset,
550 screen->front.pitch,
551 screen->cpp,
552 screen->front.map);
553 intel_set_span_functions(&frontRb->Base);
554 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base);
555 }
556
557 if (mesaVis->doubleBufferMode) {
558 struct intel_renderbuffer *backRb
559 = intel_create_renderbuffer(rgbFormat,
560 screen->width, screen->height,
561 screen->back.offset,
562 screen->back.pitch,
563 screen->cpp,
564 screen->back.map);
565 intel_set_span_functions(&backRb->Base);
566 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backRb->Base);
567 }
568
569 if (mesaVis->depthBits == 24 && mesaVis->stencilBits == 8) {
570 /* combined depth/stencil buffer */
571 struct intel_renderbuffer *depthStencilRb
572 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT,
573 screen->width, screen->height,
574 screen->depth.offset,
575 screen->depth.pitch,
576 screen->cpp, /* 4! */
577 screen->depth.map);
578 intel_set_span_functions(&depthStencilRb->Base);
579 /* note: bind RB to two attachment points */
580 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthStencilRb->Base);
581 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &depthStencilRb->Base);
582 }
583 else if (mesaVis->depthBits == 16) {
584 /* just 16-bit depth buffer, no hw stencil */
585 struct intel_renderbuffer *depthRb
586 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16,
587 screen->width, screen->height,
588 screen->depth.offset,
589 screen->depth.pitch,
590 screen->cpp, /* 2! */
591 screen->depth.map);
592 intel_set_span_functions(&depthRb->Base);
593 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
594 }
595
596 /* now add any/all software-based renderbuffers we may need */
597 _mesa_add_soft_renderbuffers(fb, GL_FALSE, /* never sw color */
598 GL_FALSE, /* never sw depth */
599 swStencil, mesaVis->accumRedBits > 0, GL_FALSE, /* never sw alpha */
600 GL_FALSE /* never sw aux */ );
601 driDrawPriv->driverPrivate = (void *) fb;
602
603 return (driDrawPriv->driverPrivate != NULL);
604 }
605 }
606
607 static void
608 intelDestroyBuffer(__DRIdrawablePrivate * driDrawPriv)
609 {
610 _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
611 }
612
613
614 /**
615 * Get information about previous buffer swaps.
616 */
617 static int
618 intelGetSwapInfo(__DRIdrawablePrivate * dPriv, __DRIswapInfo * sInfo)
619 {
620 struct intel_context *intel;
621
622 if ((dPriv == NULL) || (dPriv->driContextPriv == NULL)
623 || (dPriv->driContextPriv->driverPrivate == NULL)
624 || (sInfo == NULL)) {
625 return -1;
626 }
627
628 intel = dPriv->driContextPriv->driverPrivate;
629 sInfo->swap_count = intel->swap_count;
630 sInfo->swap_ust = intel->swap_ust;
631 sInfo->swap_missed_count = intel->swap_missed_count;
632
633 sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
634 ? driCalculateSwapUsage(dPriv, 0, intel->swap_missed_ust)
635 : 0.0;
636
637 return 0;
638 }
639
640
641 /* There are probably better ways to do this, such as an
642 * init-designated function to register chipids and createcontext
643 * functions.
644 */
645 extern GLboolean i830CreateContext(const __GLcontextModes * mesaVis,
646 __DRIcontextPrivate * driContextPriv,
647 void *sharedContextPrivate);
648
649 extern GLboolean i915CreateContext(const __GLcontextModes * mesaVis,
650 __DRIcontextPrivate * driContextPriv,
651 void *sharedContextPrivate);
652
653
654
655
656 static GLboolean
657 intelCreateContext(const __GLcontextModes * mesaVis,
658 __DRIcontextPrivate * driContextPriv,
659 void *sharedContextPrivate)
660 {
661 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
662 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
663
664 switch (intelScreen->deviceID) {
665 /* Don't deal with i830 until texture work complete:
666 */
667 case PCI_CHIP_845_G:
668 case PCI_CHIP_I830_M:
669 case PCI_CHIP_I855_GM:
670 case PCI_CHIP_I865_G:
671 return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
672
673 case PCI_CHIP_I915_G:
674 case PCI_CHIP_I915_GM:
675 case PCI_CHIP_I945_G:
676 case PCI_CHIP_I945_GM:
677 return i915CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
678
679 default:
680 fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID);
681 return GL_FALSE;
682 }
683 }
684
685
686 static const struct __DriverAPIRec intelAPI = {
687 .InitDriver = intelInitDriver,
688 .DestroyScreen = intelDestroyScreen,
689 .CreateContext = intelCreateContext,
690 .DestroyContext = intelDestroyContext,
691 .CreateBuffer = intelCreateBuffer,
692 .DestroyBuffer = intelDestroyBuffer,
693 .SwapBuffers = intelSwapBuffers,
694 .MakeCurrent = intelMakeCurrent,
695 .UnbindContext = intelUnbindContext,
696 .GetSwapInfo = intelGetSwapInfo,
697 .GetMSC = driGetMSC32,
698 .WaitForMSC = driWaitForMSC32,
699 .WaitForSBC = NULL,
700 .SwapBuffersMSC = NULL,
701 .CopySubBuffer = intelCopySubBuffer
702 };
703
704
705 static __GLcontextModes *
706 intelFillInModes(unsigned pixel_bits, unsigned depth_bits,
707 unsigned stencil_bits, GLboolean have_back_buffer)
708 {
709 __GLcontextModes *modes;
710 __GLcontextModes *m;
711 unsigned num_modes;
712 unsigned depth_buffer_factor;
713 unsigned back_buffer_factor;
714 GLenum fb_format;
715 GLenum fb_type;
716
717 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
718 * support pageflipping at all.
719 */
720 static const GLenum back_buffer_modes[] = {
721 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
722 };
723
724 u_int8_t depth_bits_array[3];
725 u_int8_t stencil_bits_array[3];
726
727
728 depth_bits_array[0] = 0;
729 depth_bits_array[1] = depth_bits;
730 depth_bits_array[2] = depth_bits;
731
732 /* Just like with the accumulation buffer, always provide some modes
733 * with a stencil buffer. It will be a sw fallback, but some apps won't
734 * care about that.
735 */
736 stencil_bits_array[0] = 0;
737 stencil_bits_array[1] = 0;
738 stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;
739
740 depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
741 back_buffer_factor = (have_back_buffer) ? 3 : 1;
742
743 num_modes = depth_buffer_factor * back_buffer_factor * 4;
744
745 if (pixel_bits == 16) {
746 fb_format = GL_RGB;
747 fb_type = GL_UNSIGNED_SHORT_5_6_5;
748 }
749 else {
750 fb_format = GL_BGRA;
751 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
752 }
753
754 modes =
755 (*dri_interface->createContextModes) (num_modes,
756 sizeof(__GLcontextModes));
757 m = modes;
758 if (!driFillInModes(&m, fb_format, fb_type,
759 depth_bits_array, stencil_bits_array,
760 depth_buffer_factor, back_buffer_modes,
761 back_buffer_factor, GLX_TRUE_COLOR)) {
762 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
763 __LINE__);
764 return NULL;
765 }
766 if (!driFillInModes(&m, fb_format, fb_type,
767 depth_bits_array, stencil_bits_array,
768 depth_buffer_factor, back_buffer_modes,
769 back_buffer_factor, GLX_DIRECT_COLOR)) {
770 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
771 __LINE__);
772 return NULL;
773 }
774
775 /* Mark the visual as slow if there are "fake" stencil bits.
776 */
777 for (m = modes; m != NULL; m = m->next) {
778 if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
779 m->visualRating = GLX_SLOW_CONFIG;
780 }
781 }
782
783 return modes;
784 }
785
786
787 /**
788 * This is the bootstrap function for the driver. libGL supplies all of the
789 * requisite information about the system, and the driver initializes itself.
790 * This routine also fills in the linked list pointed to by \c driver_modes
791 * with the \c __GLcontextModes that the driver can support for windows or
792 * pbuffers.
793 *
794 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
795 * failure.
796 */
797 PUBLIC void *
798 __driCreateNewScreen_20050727(__DRInativeDisplay * dpy, int scrn,
799 __DRIscreen * psc,
800 const __GLcontextModes * modes,
801 const __DRIversion * ddx_version,
802 const __DRIversion * dri_version,
803 const __DRIversion * drm_version,
804 const __DRIframebuffer * frame_buffer,
805 drmAddress pSAREA, int fd,
806 int internal_api_version,
807 const __DRIinterfaceMethods * interface,
808 __GLcontextModes ** driver_modes)
809 {
810 __DRIscreenPrivate *psp;
811 static const __DRIversion ddx_expected = { 1, 5, 0 };
812 static const __DRIversion dri_expected = { 4, 0, 0 };
813 static const __DRIversion drm_expected = { 1, 7, 0 };
814
815 dri_interface = interface;
816
817 if (!driCheckDriDdxDrmVersions2("i915",
818 dri_version, &dri_expected,
819 ddx_version, &ddx_expected,
820 drm_version, &drm_expected)) {
821 return NULL;
822 }
823
824 psp = __driUtilCreateNewScreen(dpy, scrn, psc, NULL,
825 ddx_version, dri_version, drm_version,
826 frame_buffer, pSAREA, fd,
827 internal_api_version, &intelAPI);
828 if (psp != NULL) {
829 I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
830 *driver_modes = intelFillInModes(dri_priv->cpp * 8,
831 (dri_priv->cpp == 2) ? 16 : 24,
832 (dri_priv->cpp == 2) ? 0 : 8, 1);
833
834 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
835 * enable the extensions. It just makes sure that all the dispatch offsets for all
836 * the extensions that *might* be enables are known. This is needed because the
837 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
838 * enable the extensions until we have a context pointer.
839 *
840 * Hello chicken. Hello egg. How are you two today?
841 */
842 driInitExtensions(NULL, card_extensions, GL_FALSE);
843 }
844
845 return (void *) psp;
846 }
847
848 struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen)
849 {
850 /*
851 * This should probably change to have the screen allocate a dummy
852 * context at screen creation. For now just use the current context.
853 */
854
855 GET_CURRENT_CONTEXT(ctx);
856 if (ctx == NULL) {
857 _mesa_problem(NULL, "No current context in intelScreenContext\n");
858 return NULL;
859 }
860 return intel_context(ctx);
861 }
862