Merge branch 'i915tex_privbuffers' into softpipe_0_1_branch
[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_secondary_color", GL_EXT_secondary_color_functions},
200 {"GL_EXT_stencil_wrap", NULL},
201 {"GL_EXT_texture_edge_clamp", NULL},
202 {"GL_EXT_texture_env_combine", NULL},
203 {"GL_EXT_texture_env_dot3", NULL},
204 {"GL_EXT_texture_filter_anisotropic", NULL},
205 {"GL_EXT_texture_lod_bias", NULL},
206 {"GL_3DFX_texture_compression_FXT1", NULL},
207 {"GL_APPLE_client_storage", NULL},
208 {"GL_MESA_pack_invert", NULL},
209 {"GL_MESA_ycbcr_texture", NULL},
210 {"GL_NV_blend_square", NULL},
211 {"GL_NV_vertex_program", GL_NV_vertex_program_functions},
212 {"GL_NV_vertex_program1_1", NULL},
213 /* { "GL_SGIS_generate_mipmap", NULL }, */
214 {NULL, NULL}
215 };
216
217 extern const struct tnl_pipeline_stage _intel_render_stage;
218
219 static const struct tnl_pipeline_stage *intel_pipeline[] = {
220 &_tnl_vertex_transform_stage,
221 &_tnl_vertex_cull_stage,
222 &_tnl_normal_transform_stage,
223 &_tnl_lighting_stage,
224 &_tnl_fog_coordinate_stage,
225 &_tnl_texgen_stage,
226 &_tnl_texture_transform_stage,
227 &_tnl_point_attenuation_stage,
228 &_tnl_vertex_program_stage,
229 #if 1
230 &_intel_render_stage, /* ADD: unclipped rastersetup-to-dma */
231 #endif
232 &_tnl_render_stage,
233 0,
234 };
235
236
237 static const struct dri_debug_control debug_control[] = {
238 {"tex", DEBUG_TEXTURE},
239 {"state", DEBUG_STATE},
240 {"ioctl", DEBUG_IOCTL},
241 {"blit", DEBUG_BLIT},
242 {"mip", DEBUG_MIPTREE},
243 {"fall", DEBUG_FALLBACKS},
244 {"verb", DEBUG_VERBOSE},
245 {"bat", DEBUG_BATCH},
246 {"pix", DEBUG_PIXEL},
247 {"buf", DEBUG_BUFMGR},
248 {"reg", DEBUG_REGION},
249 {"fbo", DEBUG_FBO},
250 {"lock", DEBUG_LOCK},
251 {NULL, 0}
252 };
253
254
255 static void
256 intelInvalidateState(GLcontext * ctx, GLuint new_state)
257 {
258 _swrast_InvalidateState(ctx, new_state);
259 _swsetup_InvalidateState(ctx, new_state);
260 _vbo_InvalidateState(ctx, new_state);
261 _tnl_InvalidateState(ctx, new_state);
262 _tnl_invalidate_vertex_state(ctx, new_state);
263
264 st_invalidate_state( ctx, new_state );
265
266 intel_context(ctx)->NewGLState |= new_state;
267 }
268
269
270 void
271 intelFlush(GLcontext * ctx)
272 {
273 struct intel_context *intel = intel_context(ctx);
274
275 if (intel->Fallback)
276 _swrast_flush(ctx);
277
278 INTEL_FIREVERTICES(intel);
279
280 if (intel->batch->map != intel->batch->ptr)
281 intel_batchbuffer_flush(intel->batch);
282
283 /* XXX: Need to do an MI_FLUSH here.
284 */
285 }
286
287
288 /**
289 * Check if we need to rotate/warp the front color buffer to the
290 * rotated screen. We generally need to do this when we get a glFlush
291 * or glFinish after drawing to the front color buffer.
292 * If no rotation, just copy the private fake front buffer to the real one.
293 */
294 static void
295 intelCheckFrontUpdate(GLcontext * ctx)
296 {
297 struct intel_context *intel = intel_context(ctx);
298 if (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0] ==
299 BUFFER_BIT_FRONT_LEFT) {
300 intelScreenPrivate *screen = intel->intelScreen;
301 __DRIdrawablePrivate *dPriv = intel->driDrawable;
302 if (screen->current_rotation != 0) {
303 intelRotateWindow(intel, dPriv, BUFFER_BIT_FRONT_LEFT);
304 }
305 else {
306 intelCopyBuffer(dPriv, NULL);
307 }
308 }
309 }
310
311
312 /**
313 * Called via glFlush.
314 */
315 static void
316 intelglFlush(GLcontext * ctx)
317 {
318 intelFlush(ctx);
319 intelCheckFrontUpdate(ctx);
320 }
321
322 void
323 intelFinish(GLcontext * ctx)
324 {
325 struct intel_context *intel = intel_context(ctx);
326 intelFlush(ctx);
327 if (intel->batch->last_fence) {
328 driFenceFinish(intel->batch->last_fence,
329 0, GL_FALSE);
330 driFenceUnReference(intel->batch->last_fence);
331 intel->batch->last_fence = NULL;
332 }
333 intelCheckFrontUpdate(ctx);
334 }
335
336
337 void
338 intelInitDriverFunctions(struct dd_function_table *functions)
339 {
340 _mesa_init_driver_functions(functions);
341
342 functions->Flush = intelglFlush;
343 functions->Finish = intelFinish;
344 functions->GetString = intelGetString;
345 functions->UpdateState = intelInvalidateState;
346 functions->CopyColorTable = _swrast_CopyColorTable;
347 functions->CopyColorSubTable = _swrast_CopyColorSubTable;
348 functions->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
349 functions->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
350
351 intelInitTextureFuncs(functions);
352 intelInitPixelFuncs(functions);
353 intelInitStateFuncs(functions);
354 intelInitBufferFuncs(functions);
355 }
356
357
358 GLboolean
359 intelInitContext(struct intel_context *intel,
360 const __GLcontextModes * mesaVis,
361 __DRIcontextPrivate * driContextPriv,
362 void *sharedContextPrivate,
363 struct dd_function_table *functions)
364 {
365 GLcontext *ctx = &intel->ctx;
366 GLcontext *shareCtx = (GLcontext *) sharedContextPrivate;
367 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
368 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
369 drmI830Sarea *saPriv = (drmI830Sarea *)
370 (((GLubyte *) sPriv->pSAREA) + intelScreen->sarea_priv_offset);
371 int fthrottle_mode;
372 GLboolean havePools;
373
374 DRM_LIGHT_LOCK(sPriv->fd, &sPriv->pSAREA->lock, driContextPriv->hHWContext);
375 havePools = intelCreatePools(intelScreen);
376 DRM_UNLOCK(sPriv->fd, &sPriv->pSAREA->lock, driContextPriv->hHWContext);
377
378 if (!havePools)
379 return GL_FALSE;
380
381 if (!_mesa_initialize_context(&intel->ctx,
382 mesaVis, shareCtx,
383 functions, (void *) intel))
384 return GL_FALSE;
385
386 driContextPriv->driverPrivate = intel;
387 intel->intelScreen = intelScreen;
388 intel->driScreen = sPriv;
389 intel->sarea = saPriv;
390
391 intel->width = intelScreen->width;
392 intel->height = intelScreen->height;
393 intel->current_rotation = intelScreen->current_rotation;
394
395 if (!lockMutexInit) {
396 lockMutexInit = GL_TRUE;
397 _glthread_INIT_MUTEX(lockMutex);
398 }
399
400 driParseConfigFiles(&intel->optionCache, &intelScreen->optionCache,
401 intel->driScreen->myNum, "i915");
402
403 ctx->Const.MaxTextureMaxAnisotropy = 2.0;
404
405 /* This doesn't yet catch all non-conformant rendering, but it's a
406 * start.
407 */
408 if (getenv("INTEL_STRICT_CONFORMANCE")) {
409 intel->strict_conformance = 1;
410 }
411
412 ctx->Const.MinLineWidth = 1.0;
413 ctx->Const.MinLineWidthAA = 1.0;
414 ctx->Const.MaxLineWidth = 3.0;
415 ctx->Const.MaxLineWidthAA = 3.0;
416 ctx->Const.LineWidthGranularity = 1.0;
417
418 ctx->Const.MinPointSize = 1.0;
419 ctx->Const.MinPointSizeAA = 1.0;
420 ctx->Const.MaxPointSize = 255.0;
421 ctx->Const.MaxPointSizeAA = 3.0;
422 ctx->Const.PointSizeGranularity = 1.0;
423
424 /* reinitialize the context point state.
425 * It depend on constants in __GLcontextRec::Const
426 */
427 _mesa_init_point(ctx);
428
429 ctx->Const.MaxColorAttachments = 4; /* XXX FBO: review this */
430
431 /* Initialize the software rasterizer and helper modules. */
432 _swrast_CreateContext(ctx);
433 _vbo_CreateContext(ctx);
434 _tnl_CreateContext(ctx);
435 _swsetup_CreateContext(ctx);
436
437 /* Install the customized pipeline: */
438 _tnl_destroy_pipeline(ctx);
439 _tnl_install_pipeline(ctx, intel_pipeline);
440
441 /* Configure swrast to match hardware characteristics: */
442 _swrast_allow_pixel_fog(ctx, GL_FALSE);
443 _swrast_allow_vertex_fog(ctx, GL_TRUE);
444
445 /* Dri stuff */
446 intel->hHWContext = driContextPriv->hHWContext;
447 intel->driFd = sPriv->fd;
448 intel->driHwLock = (drmLock *) & sPriv->pSAREA->lock;
449
450 intel->hw_stipple = 1;
451
452 /* XXX FBO: this doesn't seem to be used anywhere */
453 switch (mesaVis->depthBits) {
454 case 0: /* what to do in this case? */
455 case 16:
456 intel->polygon_offset_scale = 1.0 / 0xffff;
457 break;
458 case 24:
459 intel->polygon_offset_scale = 2.0 / 0xffffff; /* req'd to pass glean */
460 break;
461 default:
462 assert(0);
463 break;
464 }
465
466 /* Initialize swrast, tnl driver tables: */
467 intelInitSpanFuncs(ctx);
468 intelInitTriFuncs(ctx);
469
470
471 intel->RenderIndex = ~0;
472
473 fthrottle_mode = driQueryOptioni(&intel->optionCache, "fthrottle_mode");
474 intel->iw.irq_seq = -1;
475 intel->irqsEmitted = 0;
476
477 intel->do_irqs = (intel->intelScreen->irq_active &&
478 fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS);
479
480 intel->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
481
482 _math_matrix_ctr(&intel->ViewportMatrix);
483
484 /* Disable imaging extension until convolution is working in
485 * teximage paths:
486 */
487 driInitExtensions(ctx, card_extensions,
488 /* GL_TRUE, */
489 GL_FALSE);
490
491
492 intel->batch = intel_batchbuffer_alloc(intel);
493 intel->last_swap_fence = NULL;
494 intel->first_swap_fence = NULL;
495
496 intel_bufferobj_init(intel);
497 intel_fbo_init(intel);
498
499 if (intel->ctx.Mesa_DXTn) {
500 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
501 _mesa_enable_extension(ctx, "GL_S3_s3tc");
502 }
503 else if (driQueryOptionb(&intel->optionCache, "force_s3tc_enable")) {
504 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
505 }
506
507 intel->prim.primitive = ~0;
508
509
510 #if DO_DEBUG
511 INTEL_DEBUG = driParseDebugString(getenv("INTEL_DEBUG"), debug_control);
512 #endif
513
514 if (getenv("INTEL_NO_RAST")) {
515 fprintf(stderr, "disabling 3D rasterization\n");
516 FALLBACK(intel, INTEL_FALLBACK_USER, 1);
517 }
518
519
520 st_create_context( &intel->ctx,
521 softpipe_create() );
522
523
524 return GL_TRUE;
525 }
526
527 void
528 intelDestroyContext(__DRIcontextPrivate * driContextPriv)
529 {
530 struct intel_context *intel =
531 (struct intel_context *) driContextPriv->driverPrivate;
532
533 assert(intel); /* should never be null */
534 if (intel) {
535 GLboolean release_texture_heaps;
536
537 INTEL_FIREVERTICES(intel);
538
539 intel->vtbl.destroy(intel);
540
541 release_texture_heaps = (intel->ctx.Shared->RefCount == 1);
542 _swsetup_DestroyContext(&intel->ctx);
543 _tnl_DestroyContext(&intel->ctx);
544 _vbo_DestroyContext(&intel->ctx);
545
546 _swrast_DestroyContext(&intel->ctx);
547 intel->Fallback = 0; /* don't call _swrast_Flush later */
548
549 intel_batchbuffer_free(intel->batch);
550
551 if (intel->last_swap_fence) {
552 driFenceFinish(intel->last_swap_fence, DRM_FENCE_TYPE_EXE, GL_TRUE);
553 driFenceUnReference(intel->last_swap_fence);
554 intel->last_swap_fence = NULL;
555 }
556 if (intel->first_swap_fence) {
557 driFenceFinish(intel->first_swap_fence, DRM_FENCE_TYPE_EXE, GL_TRUE);
558 driFenceUnReference(intel->first_swap_fence);
559 intel->first_swap_fence = NULL;
560 }
561
562
563 if (release_texture_heaps) {
564 /* This share group is about to go away, free our private
565 * texture object data.
566 */
567 if (INTEL_DEBUG & DEBUG_TEXTURE)
568 fprintf(stderr, "do something to free texture heaps\n");
569 }
570
571 /* free the Mesa context */
572 _mesa_free_context_data(&intel->ctx);
573 }
574 }
575
576 GLboolean
577 intelUnbindContext(__DRIcontextPrivate * driContextPriv)
578 {
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 /* XXX FBO temporary fix-ups! */
607 /* if the renderbuffers don't have regions, init them from the context */
608 {
609 struct intel_renderbuffer *irbDepth
610 = intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH);
611 struct intel_renderbuffer *irbStencil
612 = intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL);
613
614 if (intel_fb->color_rb[0] && !intel_fb->color_rb[0]->region) {
615 intel_region_reference(&intel_fb->color_rb[0]->region,
616 intel->intelScreen->front_region);
617 }
618 if (intel_fb->color_rb[1] && !intel_fb->color_rb[1]->region) {
619 intel_region_reference(&intel_fb->color_rb[1]->region,
620 intel->intelScreen->back_region);
621 }
622 if (intel_fb->color_rb[2] && !intel_fb->color_rb[2]->region) {
623 intel_region_reference(&intel_fb->color_rb[2]->region,
624 intel->intelScreen->third_region);
625 }
626 if (irbDepth && !irbDepth->region) {
627 intel_region_reference(&irbDepth->region, intel->intelScreen->depth_region);
628 }
629 if (irbStencil && !irbStencil->region) {
630 intel_region_reference(&irbStencil->region, intel->intelScreen->depth_region);
631 }
632 }
633
634 /* set GLframebuffer size to match window, if needed */
635 driUpdateFramebufferSize(&intel->ctx, driDrawPriv);
636
637 if (driReadPriv != driDrawPriv) {
638 driUpdateFramebufferSize(&intel->ctx, driReadPriv);
639 }
640
641 _mesa_make_current(&intel->ctx, &intel_fb->Base, readFb);
642 intel->intelScreen->dummyctxptr = &intel->ctx;
643
644 /* The drawbuffer won't always be updated by _mesa_make_current:
645 */
646 if (intel->ctx.DrawBuffer == &intel_fb->Base) {
647
648 if (intel->driDrawable != driDrawPriv) {
649 intel_fb->vblank_flags = (intel->intelScreen->irq_active != 0)
650 ? driGetDefaultVBlankFlags(&intel->optionCache)
651 : VBLANK_FLAG_NO_IRQ;
652 (*dri_interface->getUST) (&intel_fb->swap_ust);
653 driDrawableInitVBlank(driDrawPriv, intel_fb->vblank_flags,
654 &intel_fb->vbl_seq);
655 intel->driDrawable = driDrawPriv;
656 intelWindowMoved(intel);
657 }
658
659 intel_draw_buffer(&intel->ctx, &intel_fb->Base);
660 }
661 }
662 else {
663 _mesa_make_current(NULL, NULL, NULL);
664 }
665
666 return GL_TRUE;
667 }
668
669 static void
670 intelContendedLock(struct intel_context *intel, GLuint flags)
671 {
672 __DRIdrawablePrivate *dPriv = intel->driDrawable;
673 __DRIscreenPrivate *sPriv = intel->driScreen;
674 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
675 drmI830Sarea *sarea = intel->sarea;
676
677 drmGetLock(intel->driFd, intel->hHWContext, flags);
678
679 if (INTEL_DEBUG & DEBUG_LOCK)
680 _mesa_printf("%s - got contended lock\n", __progname);
681
682 /* If the window moved, may need to set a new cliprect now.
683 *
684 * NOTE: This releases and regains the hw lock, so all state
685 * checking must be done *after* this call:
686 */
687 if (dPriv)
688 intel->revalidateDrawable = GL_TRUE;
689 // DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
690
691 if (sarea->width != intelScreen->width ||
692 sarea->height != intelScreen->height ||
693 sarea->rotation != intelScreen->current_rotation) {
694
695 intelUpdateScreenRotation(sPriv, sarea);
696 }
697
698 #if 0
699 if (sarea->width != intel->width ||
700 sarea->height != intel->height ||
701 sarea->rotation != intel->current_rotation) {
702
703 void *batchMap = intel->batch->map;
704
705 /*
706 * FIXME: Really only need to do this when drawing to a
707 * common back- or front buffer.
708 */
709
710 /*
711 * This will drop the outstanding batchbuffer on the floor
712 */
713
714 if (batchMap != NULL) {
715 driBOUnmap(intel->batch->buffer);
716 intel->batch->map = NULL;
717 }
718
719 intel_batchbuffer_reset(intel->batch);
720
721 if (batchMap == NULL) {
722 driBOUnmap(intel->batch->buffer);
723 intel->batch->map = NULL;
724 }
725
726 /* lose all primitives */
727 intel->prim.primitive = ~0;
728 intel->prim.start_ptr = 0;
729 intel->prim.flush = 0;
730
731 /* re-emit all state */
732 intel->vtbl.lost_hardware(intel);
733
734 /* force window update */
735 intel->lastStamp = 0;
736
737 intel->width = sarea->width;
738 intel->height = sarea->height;
739 intel->current_rotation = sarea->rotation;
740 }
741 #endif
742 }
743
744
745
746 /* Lock the hardware and validate our state.
747 */
748 void LOCK_HARDWARE( struct intel_context *intel )
749 {
750 char __ret=0;
751 struct intel_framebuffer *intel_fb = NULL;
752 struct intel_renderbuffer *intel_rb = NULL;
753 _glthread_LOCK_MUTEX(lockMutex);
754 assert(!intel->locked);
755
756 if (intel->driDrawable) {
757 intel_fb = intel->driDrawable->driverPrivate;
758
759 if (intel_fb)
760 intel_rb =
761 intel_get_renderbuffer(&intel_fb->Base,
762 intel_fb->Base._ColorDrawBufferMask[0] ==
763 BUFFER_BIT_FRONT_LEFT ? BUFFER_FRONT_LEFT :
764 BUFFER_BACK_LEFT);
765 }
766
767 if (intel_rb && (intel_fb->vbl_waited - intel_rb->vbl_pending) > (1<<23)) {
768 drmVBlank vbl;
769
770 vbl.request.type = DRM_VBLANK_ABSOLUTE;
771
772 if ( intel_fb->vblank_flags & VBLANK_FLAG_SECONDARY ) {
773 vbl.request.type |= DRM_VBLANK_SECONDARY;
774 }
775
776 vbl.request.sequence = intel_rb->vbl_pending;
777 drmWaitVBlank(intel->driFd, &vbl);
778 intel_fb->vbl_waited = vbl.reply.sequence;
779 }
780
781 DRM_CAS(intel->driHwLock, intel->hHWContext,
782 (DRM_LOCK_HELD|intel->hHWContext), __ret);
783
784 if (__ret)
785 intelContendedLock( intel, 0 );
786
787 if (INTEL_DEBUG & DEBUG_LOCK)
788 _mesa_printf("%s - locked\n", __progname);
789
790 intel->locked = 1;
791 }
792
793
794 /* Unlock the hardware using the global current context
795 */
796 void UNLOCK_HARDWARE( struct intel_context *intel )
797 {
798 intel->locked = 0;
799
800 DRM_UNLOCK(intel->driFd, intel->driHwLock, intel->hHWContext);
801
802 _glthread_UNLOCK_MUTEX(lockMutex);
803
804 if (INTEL_DEBUG & DEBUG_LOCK)
805 _mesa_printf("%s - unlocked\n", __progname);
806 }
807