c6c66e26caea6816c1a3ee1b659c55ce147342a3
[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 "drirenderbuffer.h"
64 #include "vblank.h"
65 #include "utils.h"
66 #include "xmlpool.h" /* for symbolic values of enum-type options */
67 #ifndef INTEL_DEBUG
68 int INTEL_DEBUG = (0);
69 #endif
70
71 #define need_GL_ARB_multisample
72 #define need_GL_ARB_point_parameters
73 #define need_GL_ARB_texture_compression
74 #define need_GL_ARB_vertex_buffer_object
75 #define need_GL_ARB_vertex_program
76 #define need_GL_ARB_window_pos
77 #define need_GL_EXT_blend_color
78 #define need_GL_EXT_blend_equation_separate
79 #define need_GL_EXT_blend_func_separate
80 #define need_GL_EXT_blend_minmax
81 #define need_GL_EXT_cull_vertex
82 #define need_GL_EXT_fog_coord
83 #define need_GL_EXT_framebuffer_object
84 #define need_GL_EXT_multi_draw_arrays
85 #define need_GL_EXT_secondary_color
86 #define need_GL_NV_vertex_program
87 #include "extension_helper.h"
88
89
90 #define DRIVER_DATE "20061102"
91
92 _glthread_Mutex lockMutex;
93 static GLboolean lockMutexInit = GL_FALSE;
94
95
96 static const GLubyte *
97 intelGetString(GLcontext * ctx, GLenum name)
98 {
99 const char *chipset;
100 static char buffer[128];
101
102 switch (name) {
103 case GL_VENDOR:
104 return (GLubyte *) "Tungsten Graphics, Inc";
105 break;
106
107 case GL_RENDERER:
108 switch (intel_context(ctx)->intelScreen->deviceID) {
109 case PCI_CHIP_845_G:
110 chipset = "Intel(R) 845G";
111 break;
112 case PCI_CHIP_I830_M:
113 chipset = "Intel(R) 830M";
114 break;
115 case PCI_CHIP_I855_GM:
116 chipset = "Intel(R) 852GM/855GM";
117 break;
118 case PCI_CHIP_I865_G:
119 chipset = "Intel(R) 865G";
120 break;
121 case PCI_CHIP_I915_G:
122 chipset = "Intel(R) 915G";
123 break;
124 case PCI_CHIP_I915_GM:
125 chipset = "Intel(R) 915GM";
126 break;
127 case PCI_CHIP_I945_G:
128 chipset = "Intel(R) 945G";
129 break;
130 case PCI_CHIP_I945_GM:
131 chipset = "Intel(R) 945GM";
132 break;
133 default:
134 chipset = "Unknown Intel Chipset";
135 break;
136 }
137
138 (void) driGetRendererString(buffer, chipset, DRIVER_DATE, 0);
139 return (GLubyte *) buffer;
140
141 default:
142 return NULL;
143 }
144 }
145
146
147 /**
148 * Extension strings exported by the intel driver.
149 *
150 * \note
151 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
152 * old i830-specific driver.
153 */
154 const struct dri_extension card_extensions[] = {
155 {"GL_ARB_multisample", GL_ARB_multisample_functions},
156 {"GL_ARB_multitexture", NULL},
157 {"GL_ARB_point_parameters", GL_ARB_point_parameters_functions},
158 {"GL_ARB_texture_border_clamp", NULL},
159 {"GL_ARB_texture_compression", GL_ARB_texture_compression_functions},
160 {"GL_ARB_texture_cube_map", NULL},
161 {"GL_ARB_texture_env_add", NULL},
162 {"GL_ARB_texture_env_combine", NULL},
163 {"GL_ARB_texture_env_dot3", NULL},
164 {"GL_ARB_texture_mirrored_repeat", NULL},
165 {"GL_ARB_texture_rectangle", NULL},
166 {"GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions},
167 {"GL_ARB_pixel_buffer_object", NULL},
168 {"GL_ARB_vertex_program", GL_ARB_vertex_program_functions},
169 {"GL_ARB_window_pos", GL_ARB_window_pos_functions},
170 {"GL_EXT_blend_color", GL_EXT_blend_color_functions},
171 {"GL_EXT_blend_equation_separate",
172 GL_EXT_blend_equation_separate_functions},
173 {"GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions},
174 {"GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions},
175 {"GL_EXT_blend_subtract", NULL},
176 {"GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions},
177 {"GL_EXT_fog_coord", GL_EXT_fog_coord_functions},
178 {"GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions},
179 {"GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions},
180 #if 1 /* XXX FBO temporary? */
181 {"GL_EXT_packed_depth_stencil", NULL},
182 #endif
183 {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions},
184 {"GL_EXT_stencil_wrap", NULL},
185 {"GL_EXT_texture_edge_clamp", NULL},
186 {"GL_EXT_texture_env_combine", NULL},
187 {"GL_EXT_texture_env_dot3", NULL},
188 {"GL_EXT_texture_filter_anisotropic", NULL},
189 {"GL_EXT_texture_lod_bias", NULL},
190 {"GL_3DFX_texture_compression_FXT1", NULL},
191 {"GL_APPLE_client_storage", NULL},
192 {"GL_MESA_pack_invert", NULL},
193 {"GL_MESA_ycbcr_texture", NULL},
194 {"GL_NV_blend_square", NULL},
195 {"GL_NV_vertex_program", GL_NV_vertex_program_functions},
196 {"GL_NV_vertex_program1_1", NULL},
197 /* { "GL_SGIS_generate_mipmap", NULL }, */
198 {NULL, NULL}
199 };
200
201 extern const struct tnl_pipeline_stage _intel_render_stage;
202
203 static const struct tnl_pipeline_stage *intel_pipeline[] = {
204 &_tnl_vertex_transform_stage,
205 &_tnl_vertex_cull_stage,
206 &_tnl_normal_transform_stage,
207 &_tnl_lighting_stage,
208 &_tnl_fog_coordinate_stage,
209 &_tnl_texgen_stage,
210 &_tnl_texture_transform_stage,
211 &_tnl_point_attenuation_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 /* reinitialize the context point state.
394 * It depend on constants in __GLcontextRec::Const
395 */
396 _mesa_init_point(ctx);
397
398 ctx->Const.MaxColorAttachments = 4; /* XXX FBO: review this */
399
400 /* Initialize the software rasterizer and helper modules. */
401 _swrast_CreateContext(ctx);
402 _vbo_CreateContext(ctx);
403 _tnl_CreateContext(ctx);
404 _swsetup_CreateContext(ctx);
405
406 /* Install the customized pipeline: */
407 _tnl_destroy_pipeline(ctx);
408 _tnl_install_pipeline(ctx, intel_pipeline);
409
410 /* Configure swrast to match hardware characteristics: */
411 _swrast_allow_pixel_fog(ctx, GL_FALSE);
412 _swrast_allow_vertex_fog(ctx, GL_TRUE);
413
414 /* Dri stuff */
415 intel->hHWContext = driContextPriv->hHWContext;
416 intel->driFd = sPriv->fd;
417 intel->driHwLock = (drmLock *) & sPriv->pSAREA->lock;
418
419 intel->hw_stipple = 1;
420
421 /* XXX FBO: this doesn't seem to be used anywhere */
422 switch (mesaVis->depthBits) {
423 case 0: /* what to do in this case? */
424 case 16:
425 intel->polygon_offset_scale = 1.0 / 0xffff;
426 break;
427 case 24:
428 intel->polygon_offset_scale = 2.0 / 0xffffff; /* req'd to pass glean */
429 break;
430 default:
431 assert(0);
432 break;
433 }
434
435 /* Initialize swrast, tnl driver tables: */
436 intelInitSpanFuncs(ctx);
437 intelInitTriFuncs(ctx);
438
439
440 intel->RenderIndex = ~0;
441
442 fthrottle_mode = driQueryOptioni(&intel->optionCache, "fthrottle_mode");
443 intel->iw.irq_seq = -1;
444 intel->irqsEmitted = 0;
445
446 intel->do_irqs = (intel->intelScreen->irq_active &&
447 fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS);
448
449 intel->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
450
451 _math_matrix_ctr(&intel->ViewportMatrix);
452
453 /* Disable imaging extension until convolution is working in
454 * teximage paths:
455 */
456 driInitExtensions(ctx, card_extensions,
457 /* GL_TRUE, */
458 GL_FALSE);
459
460
461 intel->batch = intel_batchbuffer_alloc(intel);
462 intel->last_swap_fence = NULL;
463 intel->first_swap_fence = NULL;
464
465 intel_bufferobj_init(intel);
466 intel_fbo_init(intel);
467
468 if (intel->ctx.Mesa_DXTn) {
469 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
470 _mesa_enable_extension(ctx, "GL_S3_s3tc");
471 }
472 else if (driQueryOptionb(&intel->optionCache, "force_s3tc_enable")) {
473 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
474 }
475
476 intel->prim.primitive = ~0;
477
478
479 #if DO_DEBUG
480 INTEL_DEBUG = driParseDebugString(getenv("INTEL_DEBUG"), debug_control);
481 #endif
482
483 if (getenv("INTEL_NO_RAST")) {
484 fprintf(stderr, "disabling 3D rasterization\n");
485 FALLBACK(intel, INTEL_FALLBACK_USER, 1);
486 }
487
488 return GL_TRUE;
489 }
490
491 void
492 intelDestroyContext(__DRIcontextPrivate * driContextPriv)
493 {
494 struct intel_context *intel =
495 (struct intel_context *) driContextPriv->driverPrivate;
496
497 assert(intel); /* should never be null */
498 if (intel) {
499 GLboolean release_texture_heaps;
500
501 INTEL_FIREVERTICES(intel);
502
503 intel->vtbl.destroy(intel);
504
505 release_texture_heaps = (intel->ctx.Shared->RefCount == 1);
506 _swsetup_DestroyContext(&intel->ctx);
507 _tnl_DestroyContext(&intel->ctx);
508 _vbo_DestroyContext(&intel->ctx);
509
510 _swrast_DestroyContext(&intel->ctx);
511 intel->Fallback = 0; /* don't call _swrast_Flush later */
512
513 intel_batchbuffer_free(intel->batch);
514
515 if (intel->last_swap_fence) {
516 driFenceFinish(intel->last_swap_fence, DRM_FENCE_TYPE_EXE, GL_TRUE);
517 driFenceUnReference(intel->last_swap_fence);
518 intel->last_swap_fence = NULL;
519 }
520 if (intel->first_swap_fence) {
521 driFenceFinish(intel->first_swap_fence, DRM_FENCE_TYPE_EXE, GL_TRUE);
522 driFenceUnReference(intel->first_swap_fence);
523 intel->first_swap_fence = NULL;
524 }
525
526
527 if (release_texture_heaps) {
528 /* This share group is about to go away, free our private
529 * texture object data.
530 */
531 if (INTEL_DEBUG & DEBUG_TEXTURE)
532 fprintf(stderr, "do something to free texture heaps\n");
533 }
534
535 /* free the Mesa context */
536 _mesa_free_context_data(&intel->ctx);
537 }
538 }
539
540 GLboolean
541 intelUnbindContext(__DRIcontextPrivate * driContextPriv)
542 {
543 return GL_TRUE;
544 }
545
546 GLboolean
547 intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
548 __DRIdrawablePrivate * driDrawPriv,
549 __DRIdrawablePrivate * driReadPriv)
550 {
551
552 if (driContextPriv) {
553 struct intel_context *intel =
554 (struct intel_context *) driContextPriv->driverPrivate;
555 struct intel_framebuffer *intel_fb =
556 (struct intel_framebuffer *) driDrawPriv->driverPrivate;
557 GLframebuffer *readFb = (GLframebuffer *) driReadPriv->driverPrivate;
558
559
560 /* XXX FBO temporary fix-ups! */
561 /* if the renderbuffers don't have regions, init them from the context */
562 {
563 struct intel_renderbuffer *irbDepth
564 = intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH);
565 struct intel_renderbuffer *irbStencil
566 = intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL);
567
568 if (intel_fb->color_rb[0] && !intel_fb->color_rb[0]->region) {
569 intel_region_reference(&intel_fb->color_rb[0]->region,
570 intel->intelScreen->front_region);
571 }
572 if (intel_fb->color_rb[1] && !intel_fb->color_rb[1]->region) {
573 intel_region_reference(&intel_fb->color_rb[1]->region,
574 intel->intelScreen->back_region);
575 }
576 if (intel_fb->color_rb[2] && !intel_fb->color_rb[2]->region) {
577 intel_region_reference(&intel_fb->color_rb[2]->region,
578 intel->intelScreen->third_region);
579 }
580 if (irbDepth && !irbDepth->region) {
581 intel_region_reference(&irbDepth->region, intel->intelScreen->depth_region);
582 }
583 if (irbStencil && !irbStencil->region) {
584 intel_region_reference(&irbStencil->region, intel->intelScreen->depth_region);
585 }
586 }
587
588 /* set GLframebuffer size to match window, if needed */
589 driUpdateFramebufferSize(&intel->ctx, driDrawPriv);
590
591 if (driReadPriv != driDrawPriv) {
592 driUpdateFramebufferSize(&intel->ctx, driReadPriv);
593 }
594
595 _mesa_make_current(&intel->ctx, &intel_fb->Base, readFb);
596
597 /* The drawbuffer won't always be updated by _mesa_make_current:
598 */
599 if (intel->ctx.DrawBuffer == &intel_fb->Base) {
600
601 if (intel->driDrawable != driDrawPriv) {
602 intel_fb->vblank_flags = (intel->intelScreen->irq_active != 0)
603 ? driGetDefaultVBlankFlags(&intel->optionCache)
604 : VBLANK_FLAG_NO_IRQ;
605 (*dri_interface->getUST) (&intel_fb->swap_ust);
606 driDrawableInitVBlank(driDrawPriv, intel_fb->vblank_flags,
607 &intel_fb->vbl_seq);
608 intel->driDrawable = driDrawPriv;
609 intelWindowMoved(intel);
610 }
611
612 intel_draw_buffer(&intel->ctx, &intel_fb->Base);
613 }
614 }
615 else {
616 _mesa_make_current(NULL, NULL, NULL);
617 }
618
619 return GL_TRUE;
620 }
621
622 static void
623 intelContendedLock(struct intel_context *intel, GLuint flags)
624 {
625 __DRIdrawablePrivate *dPriv = intel->driDrawable;
626 __DRIscreenPrivate *sPriv = intel->driScreen;
627 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
628 drmI830Sarea *sarea = intel->sarea;
629
630 drmGetLock(intel->driFd, intel->hHWContext, flags);
631
632 if (INTEL_DEBUG & DEBUG_LOCK)
633 _mesa_printf("%s - got contended lock\n", __progname);
634
635 /* If the window moved, may need to set a new cliprect now.
636 *
637 * NOTE: This releases and regains the hw lock, so all state
638 * checking must be done *after* this call:
639 */
640 if (dPriv)
641 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
642
643 if (sarea->width != intelScreen->width ||
644 sarea->height != intelScreen->height ||
645 sarea->rotation != intelScreen->current_rotation) {
646
647 intelUpdateScreenRotation(sPriv, sarea);
648 }
649
650 if (sarea->width != intel->width ||
651 sarea->height != intel->height ||
652 sarea->rotation != intel->current_rotation) {
653
654 void *batchMap = intel->batch->map;
655
656 /*
657 * FIXME: Really only need to do this when drawing to a
658 * common back- or front buffer.
659 */
660
661 /*
662 * This will drop the outstanding batchbuffer on the floor
663 */
664
665 if (batchMap != NULL) {
666 driBOUnmap(intel->batch->buffer);
667 intel->batch->map = NULL;
668 }
669
670 intel_batchbuffer_reset(intel->batch);
671
672 if (batchMap == NULL) {
673 driBOUnmap(intel->batch->buffer);
674 intel->batch->map = NULL;
675 }
676
677 /* lose all primitives */
678 intel->prim.primitive = ~0;
679 intel->prim.start_ptr = 0;
680 intel->prim.flush = 0;
681
682 /* re-emit all state */
683 intel->vtbl.lost_hardware(intel);
684
685 /* force window update */
686 intel->lastStamp = 0;
687
688 intel->width = sarea->width;
689 intel->height = sarea->height;
690 intel->current_rotation = sarea->rotation;
691 }
692
693 /* Drawable changed?
694 */
695 if (dPriv && intel->lastStamp != dPriv->lastStamp) {
696 intelWindowMoved(intel);
697 intel->lastStamp = dPriv->lastStamp;
698 }
699 }
700
701
702
703 /* Lock the hardware and validate our state.
704 */
705 void LOCK_HARDWARE( struct intel_context *intel )
706 {
707 char __ret=0;
708 struct intel_framebuffer *intel_fb = NULL;
709 struct intel_renderbuffer *intel_rb = NULL;
710 _glthread_LOCK_MUTEX(lockMutex);
711 assert(!intel->locked);
712
713 if (intel->driDrawable) {
714 intel_fb = intel->driDrawable->driverPrivate;
715
716 if (intel_fb)
717 intel_rb =
718 intel_get_renderbuffer(&intel_fb->Base,
719 intel_fb->Base._ColorDrawBufferMask[0] ==
720 BUFFER_BIT_FRONT_LEFT ? BUFFER_FRONT_LEFT :
721 BUFFER_BACK_LEFT);
722 }
723
724 if (intel_rb && (intel_fb->vbl_waited - intel_rb->vbl_pending) > (1<<23)) {
725 drmVBlank vbl;
726
727 vbl.request.type = DRM_VBLANK_ABSOLUTE;
728
729 if ( intel_fb->vblank_flags & VBLANK_FLAG_SECONDARY ) {
730 vbl.request.type |= DRM_VBLANK_SECONDARY;
731 }
732
733 vbl.request.sequence = intel_rb->vbl_pending;
734 drmWaitVBlank(intel->driFd, &vbl);
735 intel_fb->vbl_waited = vbl.reply.sequence;
736 }
737
738 DRM_CAS(intel->driHwLock, intel->hHWContext,
739 (DRM_LOCK_HELD|intel->hHWContext), __ret);
740
741 if (__ret)
742 intelContendedLock( intel, 0 );
743
744 if (INTEL_DEBUG & DEBUG_LOCK)
745 _mesa_printf("%s - locked\n", __progname);
746
747 intel->locked = 1;
748 }
749
750
751 /* Unlock the hardware using the global current context
752 */
753 void UNLOCK_HARDWARE( struct intel_context *intel )
754 {
755 intel->locked = 0;
756
757 DRM_UNLOCK(intel->driFd, intel->driHwLock, intel->hHWContext);
758
759 _glthread_UNLOCK_MUTEX(lockMutex);
760
761 if (INTEL_DEBUG & DEBUG_LOCK)
762 _mesa_printf("%s - unlocked\n", __progname);
763 }
764