Remove last of core Mesa dependencies in intel_swapbuffers.c
[mesa.git] / src / mesa / drivers / dri / i915tex / intel_context.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
29 #include "glheader.h"
30 #include "context.h"
31 #include "matrix.h"
32 #include "simple_list.h"
33 #include "extensions.h"
34 #include "framebuffer.h"
35 #include "imports.h"
36 #include "points.h"
37
38 #include "swrast/swrast.h"
39 #include "swrast_setup/swrast_setup.h"
40 #include "tnl/tnl.h"
41
42 #include "tnl/t_pipeline.h"
43 #include "tnl/t_vertex.h"
44
45 #include "drivers/common/driverfuncs.h"
46
47 #include "intel_screen.h"
48
49 #include "i830_dri.h"
50
51 #include "intel_buffers.h"
52 #include "intel_tex.h"
53 #include "intel_span.h"
54 #include "intel_tris.h"
55 #include "intel_ioctl.h"
56 #include "intel_batchbuffer.h"
57 #include "intel_blit.h"
58 #include "intel_pixel.h"
59 #include "intel_regions.h"
60 #include "intel_buffer_objects.h"
61 #include "intel_fbo.h"
62
63 #include "pipe/softpipe/sp_context.h"
64 #include "state_tracker/st_public.h"
65
66
67 #include "drirenderbuffer.h"
68 #include "vblank.h"
69 #include "utils.h"
70 #include "xmlpool.h" /* for symbolic values of enum-type options */
71 #ifndef INTEL_DEBUG
72 int INTEL_DEBUG = (0);
73 #endif
74
75 #define need_GL_ARB_multisample
76 #define need_GL_ARB_point_parameters
77 #define need_GL_ARB_texture_compression
78 #define need_GL_ARB_vertex_buffer_object
79 #define need_GL_ARB_vertex_program
80 #define need_GL_ARB_window_pos
81 #define need_GL_EXT_blend_color
82 #define need_GL_EXT_blend_equation_separate
83 #define need_GL_EXT_blend_func_separate
84 #define need_GL_EXT_blend_minmax
85 #define need_GL_EXT_cull_vertex
86 #define need_GL_EXT_fog_coord
87 #define need_GL_EXT_framebuffer_object
88 #define need_GL_EXT_multi_draw_arrays
89 #define need_GL_EXT_secondary_color
90 #define need_GL_NV_vertex_program
91 #include "extension_helper.h"
92
93
94 #define DRIVER_DATE "20061102"
95
96 _glthread_Mutex lockMutex;
97 static GLboolean lockMutexInit = GL_FALSE;
98
99
100 static const GLubyte *
101 intelGetString(GLcontext * ctx, GLenum name)
102 {
103 const char *chipset;
104 static char buffer[128];
105
106 switch (name) {
107 case GL_VENDOR:
108 return (GLubyte *) "Tungsten Graphics, Inc";
109 break;
110
111 case GL_RENDERER:
112 switch (intel_context(ctx)->intelScreen->deviceID) {
113 case PCI_CHIP_845_G:
114 chipset = "Intel(R) 845G";
115 break;
116 case PCI_CHIP_I830_M:
117 chipset = "Intel(R) 830M";
118 break;
119 case PCI_CHIP_I855_GM:
120 chipset = "Intel(R) 852GM/855GM";
121 break;
122 case PCI_CHIP_I865_G:
123 chipset = "Intel(R) 865G";
124 break;
125 case PCI_CHIP_I915_G:
126 chipset = "Intel(R) 915G";
127 break;
128 case PCI_CHIP_I915_GM:
129 chipset = "Intel(R) 915GM";
130 break;
131 case PCI_CHIP_I945_G:
132 chipset = "Intel(R) 945G";
133 break;
134 case PCI_CHIP_I945_GM:
135 chipset = "Intel(R) 945GM";
136 break;
137 case PCI_CHIP_I945_GME:
138 chipset = "Intel(R) 945GME";
139 break;
140 case PCI_CHIP_G33_G:
141 chipset = "Intel(R) G33";
142 break;
143 case PCI_CHIP_Q35_G:
144 chipset = "Intel(R) Q35";
145 break;
146 case PCI_CHIP_Q33_G:
147 chipset = "Intel(R) Q33";
148 break;
149 default:
150 chipset = "Unknown Intel Chipset";
151 break;
152 }
153
154 (void) driGetRendererString(buffer, chipset, DRIVER_DATE, 0);
155 return (GLubyte *) buffer;
156
157 default:
158 return NULL;
159 }
160 }
161
162
163 /**
164 * Extension strings exported by the intel driver.
165 *
166 * \note
167 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
168 * old i830-specific driver.
169 */
170 const struct dri_extension card_extensions[] = {
171 {"GL_ARB_multisample", GL_ARB_multisample_functions},
172 {"GL_ARB_multitexture", NULL},
173 {"GL_ARB_point_parameters", GL_ARB_point_parameters_functions},
174 {"GL_ARB_texture_border_clamp", NULL},
175 {"GL_ARB_texture_compression", GL_ARB_texture_compression_functions},
176 {"GL_ARB_texture_cube_map", NULL},
177 {"GL_ARB_texture_env_add", NULL},
178 {"GL_ARB_texture_env_combine", NULL},
179 {"GL_ARB_texture_env_dot3", NULL},
180 {"GL_ARB_texture_mirrored_repeat", NULL},
181 {"GL_ARB_texture_rectangle", NULL},
182 {"GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions},
183 {"GL_ARB_pixel_buffer_object", NULL},
184 {"GL_ARB_vertex_program", GL_ARB_vertex_program_functions},
185 {"GL_ARB_window_pos", GL_ARB_window_pos_functions},
186 {"GL_EXT_blend_color", GL_EXT_blend_color_functions},
187 {"GL_EXT_blend_equation_separate",
188 GL_EXT_blend_equation_separate_functions},
189 {"GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions},
190 {"GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions},
191 {"GL_EXT_blend_subtract", NULL},
192 {"GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions},
193 {"GL_EXT_fog_coord", GL_EXT_fog_coord_functions},
194 {"GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions},
195 {"GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions},
196 #if 1 /* XXX FBO temporary? */
197 {"GL_EXT_packed_depth_stencil", NULL},
198 #endif
199 {"GL_EXT_pixel_buffer_object", NULL},
200 {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions},
201 {"GL_EXT_stencil_wrap", NULL},
202 {"GL_EXT_texture_edge_clamp", NULL},
203 {"GL_EXT_texture_env_combine", NULL},
204 {"GL_EXT_texture_env_dot3", NULL},
205 {"GL_EXT_texture_filter_anisotropic", NULL},
206 {"GL_EXT_texture_lod_bias", NULL},
207 {"GL_3DFX_texture_compression_FXT1", NULL},
208 {"GL_APPLE_client_storage", NULL},
209 {"GL_MESA_pack_invert", NULL},
210 {"GL_MESA_ycbcr_texture", NULL},
211 {"GL_NV_blend_square", NULL},
212 {"GL_NV_vertex_program", GL_NV_vertex_program_functions},
213 {"GL_NV_vertex_program1_1", NULL},
214 /* { "GL_SGIS_generate_mipmap", NULL }, */
215 {NULL, NULL}
216 };
217
218 extern const struct tnl_pipeline_stage _intel_render_stage;
219
220 static const struct tnl_pipeline_stage *intel_pipeline[] = {
221 &_tnl_vertex_transform_stage,
222 &_tnl_vertex_cull_stage,
223 &_tnl_normal_transform_stage,
224 &_tnl_lighting_stage,
225 &_tnl_fog_coordinate_stage,
226 &_tnl_texgen_stage,
227 &_tnl_texture_transform_stage,
228 &_tnl_point_attenuation_stage,
229 &_tnl_vertex_program_stage,
230 #if 1
231 &_intel_render_stage, /* ADD: unclipped rastersetup-to-dma */
232 #endif
233 &_tnl_render_stage,
234 0,
235 };
236
237
238 static const struct dri_debug_control debug_control[] = {
239 {"tex", DEBUG_TEXTURE},
240 {"state", DEBUG_STATE},
241 {"ioctl", DEBUG_IOCTL},
242 {"blit", DEBUG_BLIT},
243 {"mip", DEBUG_MIPTREE},
244 {"fall", DEBUG_FALLBACKS},
245 {"verb", DEBUG_VERBOSE},
246 {"bat", DEBUG_BATCH},
247 {"pix", DEBUG_PIXEL},
248 {"buf", DEBUG_BUFMGR},
249 {"reg", DEBUG_REGION},
250 {"fbo", DEBUG_FBO},
251 {"lock", DEBUG_LOCK},
252 {NULL, 0}
253 };
254
255
256 static void
257 intelInvalidateState(GLcontext * ctx, GLuint new_state)
258 {
259 _swrast_InvalidateState(ctx, new_state);
260 _swsetup_InvalidateState(ctx, new_state);
261 _vbo_InvalidateState(ctx, new_state);
262 _tnl_InvalidateState(ctx, new_state);
263 _tnl_invalidate_vertex_state(ctx, new_state);
264
265 st_invalidate_state( ctx, new_state );
266
267 intel_context(ctx)->NewGLState |= new_state;
268 }
269
270
271 void
272 intelFlush(GLcontext * ctx)
273 {
274 struct intel_context *intel = intel_context(ctx);
275
276 if (intel->Fallback)
277 _swrast_flush(ctx);
278
279 INTEL_FIREVERTICES(intel);
280
281 if (intel->batch->map != intel->batch->ptr)
282 intel_batchbuffer_flush(intel->batch);
283
284 /* XXX: Need to do an MI_FLUSH here.
285 */
286 }
287
288
289 /**
290 * Check if we need to rotate/warp the front color buffer to the
291 * rotated screen. We generally need to do this when we get a glFlush
292 * or glFinish after drawing to the front color buffer.
293 * If no rotation, just copy the private fake front buffer to the real one.
294 */
295 static void
296 intelCheckFrontUpdate(GLcontext * ctx)
297 {
298 struct intel_context *intel = intel_context(ctx);
299 /* rely on _ColorDrawBufferMask being kept up to date by mesa
300 even for window-fbos. */
301 /* not sure. Might need that for all masks including
302 BUFFER_BIT_FRONT_LEFT maybe? */
303 if (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0] ==
304 BUFFER_BIT_FRONT_LEFT) {
305 __DRIdrawablePrivate *dPriv = intel->driDrawable;
306 intelCopyBuffer(dPriv, NULL);
307 }
308 }
309
310
311 /**
312 * Called via glFlush.
313 */
314 static void
315 intelglFlush(GLcontext * ctx)
316 {
317 intelFlush(ctx);
318 intelCheckFrontUpdate(ctx);
319 }
320
321 void
322 intelFinish(GLcontext * ctx)
323 {
324 struct intel_context *intel = intel_context(ctx);
325 intelFlush(ctx);
326 if (intel->batch->last_fence) {
327 driFenceFinish(intel->batch->last_fence,
328 0, GL_FALSE);
329 driFenceUnReference(intel->batch->last_fence);
330 intel->batch->last_fence = NULL;
331 }
332 intelCheckFrontUpdate(ctx);
333 }
334
335
336 void
337 intelInitDriverFunctions(struct dd_function_table *functions)
338 {
339 _mesa_init_driver_functions(functions);
340
341 functions->Flush = intelglFlush;
342 functions->Finish = intelFinish;
343 functions->GetString = intelGetString;
344 functions->UpdateState = intelInvalidateState;
345 functions->CopyColorTable = _swrast_CopyColorTable;
346 functions->CopyColorSubTable = _swrast_CopyColorSubTable;
347 functions->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
348 functions->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
349
350 intelInitTextureFuncs(functions);
351 intelInitPixelFuncs(functions);
352 intelInitStateFuncs(functions);
353 intelInitBufferFuncs(functions);
354 }
355
356
357 GLboolean
358 intelInitContext(struct intel_context *intel,
359 const __GLcontextModes * mesaVis,
360 __DRIcontextPrivate * driContextPriv,
361 void *sharedContextPrivate,
362 struct dd_function_table *functions)
363 {
364 GLcontext *ctx = &intel->ctx;
365 GLcontext *shareCtx = (GLcontext *) sharedContextPrivate;
366 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
367 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
368 drmI830Sarea *saPriv = (drmI830Sarea *)
369 (((GLubyte *) sPriv->pSAREA) + intelScreen->sarea_priv_offset);
370 int fthrottle_mode;
371 GLboolean havePools;
372
373 DRM_LIGHT_LOCK(sPriv->fd, &sPriv->pSAREA->lock, driContextPriv->hHWContext);
374 havePools = intelCreatePools(intelScreen);
375 DRM_UNLOCK(sPriv->fd, &sPriv->pSAREA->lock, driContextPriv->hHWContext);
376
377 if (!havePools)
378 return GL_FALSE;
379
380 if (!_mesa_initialize_context(&intel->ctx,
381 mesaVis, shareCtx,
382 functions, (void *) intel))
383 return GL_FALSE;
384
385 driContextPriv->driverPrivate = intel;
386 intel->intelScreen = intelScreen;
387 intel->driScreen = sPriv;
388 intel->sarea = saPriv;
389
390 if (!lockMutexInit) {
391 lockMutexInit = GL_TRUE;
392 _glthread_INIT_MUTEX(lockMutex);
393 }
394
395 driParseConfigFiles(&intel->optionCache, &intelScreen->optionCache,
396 intel->driScreen->myNum, "i915");
397
398 ctx->Const.MaxTextureMaxAnisotropy = 2.0;
399
400 /* This doesn't yet catch all non-conformant rendering, but it's a
401 * start.
402 */
403 if (getenv("INTEL_STRICT_CONFORMANCE")) {
404 intel->strict_conformance = 1;
405 }
406
407 ctx->Const.MinLineWidth = 1.0;
408 ctx->Const.MinLineWidthAA = 1.0;
409 ctx->Const.MaxLineWidth = 3.0;
410 ctx->Const.MaxLineWidthAA = 3.0;
411 ctx->Const.LineWidthGranularity = 1.0;
412
413 ctx->Const.MinPointSize = 1.0;
414 ctx->Const.MinPointSizeAA = 1.0;
415 ctx->Const.MaxPointSize = 255.0;
416 ctx->Const.MaxPointSizeAA = 3.0;
417 ctx->Const.PointSizeGranularity = 1.0;
418
419 /* reinitialize the context point state.
420 * It depend on constants in __GLcontextRec::Const
421 */
422 _mesa_init_point(ctx);
423
424 ctx->Const.MaxColorAttachments = 4; /* XXX FBO: review this */
425
426 /* Initialize the software rasterizer and helper modules. */
427 _swrast_CreateContext(ctx);
428 _vbo_CreateContext(ctx);
429 _tnl_CreateContext(ctx);
430 _swsetup_CreateContext(ctx);
431
432 /* Install the customized pipeline: */
433 _tnl_destroy_pipeline(ctx);
434 _tnl_install_pipeline(ctx, intel_pipeline);
435
436 /* Configure swrast to match hardware characteristics: */
437 _swrast_allow_pixel_fog(ctx, GL_FALSE);
438 _swrast_allow_vertex_fog(ctx, GL_TRUE);
439
440 /* Dri stuff */
441 intel->hHWContext = driContextPriv->hHWContext;
442 intel->driFd = sPriv->fd;
443 intel->driHwLock = (drmLock *) & sPriv->pSAREA->lock;
444
445 intel->hw_stipple = 1;
446
447 /* XXX FBO: this doesn't seem to be used anywhere */
448 switch (mesaVis->depthBits) {
449 case 0: /* what to do in this case? */
450 case 16:
451 intel->polygon_offset_scale = 1.0 / 0xffff;
452 break;
453 case 24:
454 intel->polygon_offset_scale = 2.0 / 0xffffff; /* req'd to pass glean */
455 break;
456 default:
457 assert(0);
458 break;
459 }
460
461 /* Initialize swrast, tnl driver tables: */
462 intelInitSpanFuncs(ctx);
463 intelInitTriFuncs(ctx);
464
465
466 intel->RenderIndex = ~0;
467
468 fthrottle_mode = driQueryOptioni(&intel->optionCache, "fthrottle_mode");
469 intel->iw.irq_seq = -1;
470 intel->irqsEmitted = 0;
471
472 intel->do_irqs = (intel->intelScreen->irq_active &&
473 fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS);
474
475 intel->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
476
477 _math_matrix_ctr(&intel->ViewportMatrix);
478
479 /* Disable imaging extension until convolution is working in
480 * teximage paths:
481 */
482 driInitExtensions(ctx, card_extensions,
483 /* GL_TRUE, */
484 GL_FALSE);
485
486
487 intel->batch = intel_batchbuffer_alloc(intel);
488 intel->last_swap_fence = NULL;
489 intel->first_swap_fence = NULL;
490
491 intel_bufferobj_init(intel);
492 intel_fbo_init(intel);
493
494 if (intel->ctx.Mesa_DXTn) {
495 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
496 _mesa_enable_extension(ctx, "GL_S3_s3tc");
497 }
498 else if (driQueryOptionb(&intel->optionCache, "force_s3tc_enable")) {
499 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
500 }
501
502 intel->prim.primitive = ~0;
503
504
505 #if DO_DEBUG
506 INTEL_DEBUG = driParseDebugString(getenv("INTEL_DEBUG"), debug_control);
507 #endif
508
509 if (getenv("INTEL_NO_RAST")) {
510 fprintf(stderr, "disabling 3D rasterization\n");
511 FALLBACK(intel, INTEL_FALLBACK_USER, 1);
512 }
513
514
515 st_create_context( &intel->ctx,
516 softpipe_create() );
517
518
519 return GL_TRUE;
520 }
521
522 void
523 intelDestroyContext(__DRIcontextPrivate * driContextPriv)
524 {
525 struct intel_context *intel =
526 (struct intel_context *) driContextPriv->driverPrivate;
527
528 assert(intel); /* should never be null */
529 if (intel) {
530 GLboolean release_texture_heaps;
531
532 INTEL_FIREVERTICES(intel);
533
534 intel->vtbl.destroy(intel);
535
536 release_texture_heaps = (intel->ctx.Shared->RefCount == 1);
537 _swsetup_DestroyContext(&intel->ctx);
538 _tnl_DestroyContext(&intel->ctx);
539 _vbo_DestroyContext(&intel->ctx);
540
541 _swrast_DestroyContext(&intel->ctx);
542 intel->Fallback = 0; /* don't call _swrast_Flush later */
543
544 intel_batchbuffer_free(intel->batch);
545
546 if (intel->last_swap_fence) {
547 driFenceFinish(intel->last_swap_fence, DRM_FENCE_TYPE_EXE, GL_TRUE);
548 driFenceUnReference(intel->last_swap_fence);
549 intel->last_swap_fence = NULL;
550 }
551 if (intel->first_swap_fence) {
552 driFenceFinish(intel->first_swap_fence, DRM_FENCE_TYPE_EXE, GL_TRUE);
553 driFenceUnReference(intel->first_swap_fence);
554 intel->first_swap_fence = NULL;
555 }
556
557
558 if (release_texture_heaps) {
559 /* This share group is about to go away, free our private
560 * texture object data.
561 */
562 if (INTEL_DEBUG & DEBUG_TEXTURE)
563 fprintf(stderr, "do something to free texture heaps\n");
564 }
565
566 /* free the Mesa context */
567 _mesa_free_context_data(&intel->ctx);
568 }
569 }
570
571 GLboolean
572 intelUnbindContext(__DRIcontextPrivate * driContextPriv)
573 {
574 struct intel_context *intel = (struct intel_context *) driContextPriv->driverPrivate;
575 /* XXX UnbindContext is called AFTER the new context is made current.
576 Hopefully shouldn't be a problem ? */
577 FLUSH_VERTICES((&intel->ctx), 0);
578 intelFlush(&intel->ctx);
579 return GL_TRUE;
580 }
581
582 GLboolean
583 intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
584 __DRIdrawablePrivate * driDrawPriv,
585 __DRIdrawablePrivate * driReadPriv)
586 {
587
588 #if 0
589 if (driDrawPriv) {
590 fprintf(stderr, "x %d, y %d, width %d, height %d\n",
591 driDrawPriv->x, driDrawPriv->y, driDrawPriv->w, driDrawPriv->h);
592 }
593 #endif
594
595 if (driContextPriv) {
596 struct intel_context *intel =
597 (struct intel_context *) driContextPriv->driverPrivate;
598 struct intel_framebuffer *intel_fb =
599 (struct intel_framebuffer *) driDrawPriv->driverPrivate;
600 GLframebuffer *readFb = (GLframebuffer *) driReadPriv->driverPrivate;
601
602 /* this is a hack so we have a valid context when the region allocation
603 is done. Need a per-screen context? */
604 intel->intelScreen->dummyctxptr = intel;
605
606 /* update GLframebuffer size to match window if needed */
607 driUpdateFramebufferSize(&intel->ctx, driDrawPriv);
608
609 if (driReadPriv != driDrawPriv) {
610 driUpdateFramebufferSize(&intel->ctx, driReadPriv);
611 }
612
613 _mesa_make_current(&intel->ctx, &intel_fb->Base, readFb);
614
615 /* The drawbuffer won't always be updated by _mesa_make_current:
616 */
617 if (intel->ctx.DrawBuffer == &intel_fb->Base) {
618
619 if (intel->driDrawable != driDrawPriv) {
620 if (driDrawPriv->pdraw->swap_interval == (unsigned)-1) {
621 int i;
622
623 intel_fb->vblank_flags = (intel->intelScreen->irq_active != 0)
624 ? driGetDefaultVBlankFlags(&intel->optionCache)
625 : VBLANK_FLAG_NO_IRQ;
626
627 (*dri_interface->getUST) (&intel_fb->swap_ust);
628 driDrawableInitVBlank(driDrawPriv, intel_fb->vblank_flags,
629 &intel_fb->vbl_seq);
630 intel_fb->vbl_waited = intel_fb->vbl_seq;
631
632 for (i = 0; i < 2; i++) {
633 if (intel_fb->color_rb[i])
634 intel_fb->color_rb[i]->vbl_pending = intel_fb->vbl_seq;
635 }
636 }
637 }
638 }
639
640 if ((intel->driDrawable != driDrawPriv) ||
641 (intel->lastStamp != driDrawPriv->lastStamp)) {
642 intel->driDrawable = driDrawPriv;
643 intelWindowMoved(intel);
644 intel->lastStamp = driDrawPriv->lastStamp;
645 }
646
647 }
648 else {
649 _mesa_make_current(NULL, NULL, NULL);
650 }
651
652 return GL_TRUE;
653 }
654
655 static void
656 intelContendedLock(struct intel_context *intel, GLuint flags)
657 {
658 __DRIdrawablePrivate *dPriv = intel->driDrawable;
659 __DRIscreenPrivate *sPriv = intel->driScreen;
660 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
661 drmI830Sarea *sarea = intel->sarea;
662
663 drmGetLock(intel->driFd, intel->hHWContext, flags);
664
665 if (INTEL_DEBUG & DEBUG_LOCK)
666 _mesa_printf("%s - got contended lock\n", __progname);
667
668 /* If the window moved, may need to set a new cliprect now.
669 *
670 * NOTE: This releases and regains the hw lock, so all state
671 * checking must be done *after* this call:
672 */
673 if (dPriv)
674 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
675
676 if (sarea->width != intelScreen->width ||
677 sarea->height != intelScreen->height) {
678
679 intelUpdateScreenRotation(sPriv, sarea);
680 }
681
682 #if 0
683 if (sarea->width != intel->width ||
684 sarea->height != intel->height ||
685 sarea->rotation != intel->current_rotation) {
686 int numClipRects = intel->numClipRects;
687
688 /*
689 * FIXME: Really only need to do this when drawing to a
690 * common back- or front buffer.
691 */
692
693 /*
694 * This will essentially drop the outstanding batchbuffer on the floor.
695 */
696 intel->numClipRects = 0;
697
698 if (intel->Fallback)
699 _swrast_flush(&intel->ctx);
700
701 INTEL_FIREVERTICES(intel);
702
703 if (intel->batch->map != intel->batch->ptr)
704 intel_batchbuffer_flush(intel->batch);
705
706 intel->numClipRects = numClipRects;
707
708 /* force window update */
709 intel->lastStamp = 0;
710
711 intel->width = sarea->width;
712 intel->height = sarea->height;
713 intel->current_rotation = sarea->rotation;
714 }
715 #endif
716 }
717
718
719 /* Lock the hardware and validate our state.
720 */
721 void LOCK_HARDWARE( struct intel_context *intel )
722 {
723 char __ret=0;
724 struct intel_framebuffer *intel_fb = NULL;
725 struct intel_renderbuffer *intel_rb = NULL;
726 _glthread_LOCK_MUTEX(lockMutex);
727 assert(!intel->locked);
728
729 if (intel->driDrawable) {
730 intel_fb = intel->driDrawable->driverPrivate;
731
732 if (intel_fb)
733 intel_rb =
734 intel_get_renderbuffer(&intel_fb->Base,
735 intel_fb->Base._ColorDrawBufferMask[0] ==
736 BUFFER_BIT_FRONT_LEFT ? BUFFER_FRONT_LEFT :
737 BUFFER_BACK_LEFT);
738 }
739
740 if (intel_rb && intel_fb->vblank_flags &&
741 !(intel_fb->vblank_flags & VBLANK_FLAG_NO_IRQ) &&
742 (intel_fb->vbl_waited - intel_rb->vbl_pending) > (1<<23)) {
743 drmVBlank vbl;
744
745 vbl.request.type = DRM_VBLANK_ABSOLUTE;
746
747 if ( intel_fb->vblank_flags & VBLANK_FLAG_SECONDARY ) {
748 vbl.request.type |= DRM_VBLANK_SECONDARY;
749 }
750
751 vbl.request.sequence = intel_rb->vbl_pending;
752 drmWaitVBlank(intel->driFd, &vbl);
753 intel_fb->vbl_waited = vbl.reply.sequence;
754 }
755
756 DRM_CAS(intel->driHwLock, intel->hHWContext,
757 (DRM_LOCK_HELD|intel->hHWContext), __ret);
758
759 if (__ret)
760 intelContendedLock( intel, 0 );
761
762 if (INTEL_DEBUG & DEBUG_LOCK)
763 _mesa_printf("%s - locked\n", __progname);
764
765 intel->locked = 1;
766 }
767
768
769 /* Unlock the hardware using the global current context
770 */
771 void UNLOCK_HARDWARE( struct intel_context *intel )
772 {
773 intel->locked = 0;
774
775 DRM_UNLOCK(intel->driFd, intel->driHwLock, intel->hHWContext);
776
777 _glthread_UNLOCK_MUTEX(lockMutex);
778
779 if (INTEL_DEBUG & DEBUG_LOCK)
780 _mesa_printf("%s - unlocked\n", __progname);
781 }
782