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