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