fix fd.o bug #12217, recalcuate urb when clip plane size change
[mesa.git] / src / mesa / drivers / dri / i915 / 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 #include "vbo/vbo.h"
42
43 #include "tnl/t_pipeline.h"
44 #include "tnl/t_vertex.h"
45
46 #include "drivers/common/driverfuncs.h"
47
48 #include "intel_screen.h"
49
50 #include "i830_dri.h"
51 #include "i830_common.h"
52
53 #include "intel_tex.h"
54 #include "intel_span.h"
55 #include "intel_tris.h"
56 #include "intel_ioctl.h"
57 #include "intel_batchbuffer.h"
58
59 #include "vblank.h"
60 #include "utils.h"
61 #include "xmlpool.h" /* for symbolic values of enum-type options */
62 #ifndef INTEL_DEBUG
63 int INTEL_DEBUG = (0);
64 #endif
65
66 #define need_GL_ARB_multisample
67 #define need_GL_ARB_point_parameters
68 #define need_GL_ARB_texture_compression
69 #define need_GL_ARB_vertex_buffer_object
70 #define need_GL_ARB_vertex_program
71 #define need_GL_ARB_window_pos
72 #define need_GL_EXT_blend_color
73 #define need_GL_EXT_blend_equation_separate
74 #define need_GL_EXT_blend_func_separate
75 #define need_GL_EXT_blend_minmax
76 #define need_GL_EXT_cull_vertex
77 #define need_GL_EXT_fog_coord
78 #define need_GL_EXT_multi_draw_arrays
79 #define need_GL_EXT_secondary_color
80 #define need_GL_NV_vertex_program
81 #include "extension_helper.h"
82
83 #ifndef VERBOSE
84 int VERBOSE = 0;
85 #endif
86
87 #if DEBUG_LOCKING
88 char *prevLockFile;
89 int prevLockLine;
90 #endif
91
92 /***************************************
93 * Mesa's Driver Functions
94 ***************************************/
95
96 #define DRIVER_DATE "20061017"
97
98 const GLubyte *intelGetString( GLcontext *ctx, GLenum name )
99 {
100 const char * chipset;
101 static char buffer[128];
102
103 switch (name) {
104 case GL_VENDOR:
105 return (GLubyte *)"Tungsten Graphics, Inc";
106 break;
107
108 case GL_RENDERER:
109 switch (INTEL_CONTEXT(ctx)->intelScreen->deviceID) {
110 case PCI_CHIP_845_G:
111 chipset = "Intel(R) 845G"; break;
112 case PCI_CHIP_I830_M:
113 chipset = "Intel(R) 830M"; break;
114 case PCI_CHIP_I855_GM:
115 chipset = "Intel(R) 852GM/855GM"; break;
116 case PCI_CHIP_I865_G:
117 chipset = "Intel(R) 865G"; break;
118 case PCI_CHIP_I915_G:
119 chipset = "Intel(R) 915G"; break;
120 case PCI_CHIP_I915_GM:
121 chipset = "Intel(R) 915GM"; break;
122 case PCI_CHIP_I945_G:
123 chipset = "Intel(R) 945G"; break;
124 case PCI_CHIP_I945_GM:
125 chipset = "Intel(R) 945GM"; break;
126 case PCI_CHIP_I945_GME:
127 chipset = "Intel(R) 945GME"; break;
128 case PCI_CHIP_G33_G:
129 chipset = "Intel(R) G33"; break;
130 case PCI_CHIP_Q35_G:
131 chipset = "Intel(R) Q35"; break;
132 case PCI_CHIP_Q33_G:
133 chipset = "Intel(R) Q33"; break;
134 default:
135 chipset = "Unknown Intel Chipset"; 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 {
156 { "GL_ARB_multisample", GL_ARB_multisample_functions },
157 { "GL_ARB_multitexture", NULL },
158 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions },
159 { "GL_ARB_texture_border_clamp", NULL },
160 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions },
161 { "GL_ARB_texture_cube_map", NULL },
162 { "GL_ARB_texture_env_add", NULL },
163 { "GL_ARB_texture_env_combine", NULL },
164 { "GL_ARB_texture_env_dot3", NULL },
165 { "GL_ARB_texture_mirrored_repeat", NULL },
166 { "GL_ARB_texture_rectangle", NULL },
167 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions },
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", 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_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions },
178 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions },
179 { "GL_EXT_stencil_wrap", NULL },
180 { "GL_EXT_texture_edge_clamp", NULL },
181 { "GL_EXT_texture_env_combine", NULL },
182 { "GL_EXT_texture_env_dot3", NULL },
183 { "GL_EXT_texture_filter_anisotropic", NULL },
184 { "GL_EXT_texture_lod_bias", NULL },
185 { "GL_3DFX_texture_compression_FXT1", NULL },
186 { "GL_APPLE_client_storage", NULL },
187 { "GL_MESA_pack_invert", NULL },
188 { "GL_MESA_ycbcr_texture", NULL },
189 { "GL_NV_blend_square", NULL },
190 { "GL_NV_vertex_program", GL_NV_vertex_program_functions },
191 { "GL_NV_vertex_program1_1", NULL },
192 { "GL_SGIS_generate_mipmap", NULL },
193 { NULL, NULL }
194 };
195
196 extern const struct tnl_pipeline_stage _intel_render_stage;
197
198 static const struct tnl_pipeline_stage *intel_pipeline[] = {
199 &_tnl_vertex_transform_stage,
200 &_tnl_vertex_cull_stage,
201 &_tnl_normal_transform_stage,
202 &_tnl_lighting_stage,
203 &_tnl_fog_coordinate_stage,
204 &_tnl_texgen_stage,
205 &_tnl_texture_transform_stage,
206 &_tnl_point_attenuation_stage,
207 &_tnl_vertex_program_stage,
208 #if 1
209 &_intel_render_stage, /* ADD: unclipped rastersetup-to-dma */
210 #endif
211 &_tnl_render_stage,
212 0,
213 };
214
215
216 static const struct dri_debug_control debug_control[] =
217 {
218 { "fall", DEBUG_FALLBACKS },
219 { "tex", DEBUG_TEXTURE },
220 { "ioctl", DEBUG_IOCTL },
221 { "prim", DEBUG_PRIMS },
222 { "vert", DEBUG_VERTS },
223 { "state", DEBUG_STATE },
224 { "verb", DEBUG_VERBOSE },
225 { "dri", DEBUG_DRI },
226 { "dma", DEBUG_DMA },
227 { "san", DEBUG_SANITY },
228 { "sync", DEBUG_SYNC },
229 { "sleep", DEBUG_SLEEP },
230 { "pix", DEBUG_PIXEL },
231 { NULL, 0 }
232 };
233
234
235 static void intelInvalidateState( GLcontext *ctx, GLuint new_state )
236 {
237 _swrast_InvalidateState( ctx, new_state );
238 _swsetup_InvalidateState( ctx, new_state );
239 _vbo_InvalidateState( ctx, new_state );
240 _tnl_InvalidateState( ctx, new_state );
241 _tnl_invalidate_vertex_state( ctx, new_state );
242 INTEL_CONTEXT(ctx)->NewGLState |= new_state;
243 }
244
245
246 void intelInitDriverFunctions( struct dd_function_table *functions )
247 {
248 _mesa_init_driver_functions( functions );
249
250 functions->Clear = intelClear;
251 functions->Flush = intelglFlush;
252 functions->Finish = intelFinish;
253 functions->GetString = intelGetString;
254 functions->UpdateState = intelInvalidateState;
255
256 intelInitTextureFuncs( functions );
257 intelInitPixelFuncs( functions );
258 intelInitStateFuncs( functions );
259 }
260
261 static void intel_emit_invarient_state( GLcontext *ctx )
262 {
263 }
264
265
266
267 GLboolean intelInitContext( intelContextPtr intel,
268 const __GLcontextModes *mesaVis,
269 __DRIcontextPrivate *driContextPriv,
270 void *sharedContextPrivate,
271 struct dd_function_table *functions )
272 {
273 GLcontext *ctx = &intel->ctx;
274 GLcontext *shareCtx = (GLcontext *) sharedContextPrivate;
275 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
276 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
277 drmI830Sarea *saPriv = (drmI830Sarea *)
278 (((GLubyte *)sPriv->pSAREA)+intelScreen->sarea_priv_offset);
279 int fthrottle_mode;
280
281 if (!_mesa_initialize_context(&intel->ctx,
282 mesaVis, shareCtx,
283 functions,
284 (void*) intel))
285 return GL_FALSE;
286
287 driContextPriv->driverPrivate = intel;
288 intel->intelScreen = intelScreen;
289 intel->driScreen = sPriv;
290 intel->sarea = saPriv;
291
292
293 (void) memset( intel->texture_heaps, 0, sizeof( intel->texture_heaps ) );
294 make_empty_list( & intel->swapped );
295
296 driParseConfigFiles (&intel->optionCache, &intelScreen->optionCache,
297 intel->driScreen->myNum, "i915");
298
299 ctx->Const.MaxTextureMaxAnisotropy = 2.0;
300
301 ctx->Const.MinLineWidth = 1.0;
302 ctx->Const.MinLineWidthAA = 1.0;
303 ctx->Const.MaxLineWidth = 3.0;
304 ctx->Const.MaxLineWidthAA = 3.0;
305 ctx->Const.LineWidthGranularity = 1.0;
306
307 ctx->Const.MinPointSize = 1.0;
308 ctx->Const.MinPointSizeAA = 1.0;
309 ctx->Const.MaxPointSize = 255.0;
310 ctx->Const.MaxPointSizeAA = 3.0;
311 ctx->Const.PointSizeGranularity = 1.0;
312
313 /* reinitialize the context point state.
314 * It depend on constants in __GLcontextRec::Const
315 */
316 _mesa_init_point(ctx);
317
318 /* Initialize the software rasterizer and helper modules. */
319 _swrast_CreateContext( ctx );
320 _vbo_CreateContext( ctx );
321 _tnl_CreateContext( ctx );
322 _swsetup_CreateContext( ctx );
323
324 /* Install the customized pipeline: */
325 _tnl_destroy_pipeline( ctx );
326 _tnl_install_pipeline( ctx, intel_pipeline );
327
328 /* Configure swrast to match hardware characteristics: */
329 _swrast_allow_pixel_fog( ctx, GL_FALSE );
330 _swrast_allow_vertex_fog( ctx, GL_TRUE );
331
332 /* Dri stuff */
333 intel->hHWContext = driContextPriv->hHWContext;
334 intel->driFd = sPriv->fd;
335 intel->driHwLock = (drmLock *) &sPriv->pSAREA->lock;
336
337 intel->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
338 intel->hw_stipple = 1;
339
340 switch(mesaVis->depthBits) {
341 case 0: /* what to do in this case? */
342 case 16:
343 intel->depth_scale = 1.0/0xffff;
344 intel->polygon_offset_scale = 1.0/0xffff;
345 intel->depth_clear_mask = ~0;
346 intel->ClearDepth = 0xffff;
347 break;
348 case 24:
349 intel->depth_scale = 1.0/0xffffff;
350 intel->polygon_offset_scale = 2.0/0xffffff; /* req'd to pass glean */
351 intel->depth_clear_mask = 0x00ffffff;
352 intel->stencil_clear_mask = 0xff000000;
353 intel->ClearDepth = 0x00ffffff;
354 break;
355 default:
356 assert(0);
357 break;
358 }
359
360 /* Initialize swrast, tnl driver tables: */
361 intelInitSpanFuncs( ctx );
362 intelInitTriFuncs( ctx );
363
364
365 intel->RenderIndex = ~0;
366
367 fthrottle_mode = driQueryOptioni(&intel->optionCache, "fthrottle_mode");
368 intel->iw.irq_seq = -1;
369 intel->irqsEmitted = 0;
370
371 intel->do_irqs = (intel->intelScreen->irq_active &&
372 fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS);
373
374 intel->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
375
376 intel->vblank_flags = (intel->intelScreen->irq_active != 0)
377 ? driGetDefaultVBlankFlags(&intel->optionCache) : VBLANK_FLAG_NO_IRQ;
378
379 (*dri_interface->getUST)(&intel->swap_ust);
380 _math_matrix_ctr (&intel->ViewportMatrix);
381
382 driInitExtensions( ctx, card_extensions, GL_TRUE );
383
384 if (intel->ctx.Mesa_DXTn) {
385 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
386 _mesa_enable_extension( ctx, "GL_S3_s3tc" );
387 }
388 else if (driQueryOptionb (&intel->optionCache, "force_s3tc_enable")) {
389 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
390 }
391
392 /* driInitTextureObjects( ctx, & intel->swapped, */
393 /* DRI_TEXMGR_DO_TEXTURE_1D | */
394 /* DRI_TEXMGR_DO_TEXTURE_2D | */
395 /* DRI_TEXMGR_DO_TEXTURE_RECT ); */
396
397
398 intelInitBatchBuffer(&intel->ctx);
399 intel->prim.flush = intel_emit_invarient_state;
400 intel->prim.primitive = ~0;
401
402
403 #if DO_DEBUG
404 INTEL_DEBUG = driParseDebugString( getenv( "INTEL_DEBUG" ),
405 debug_control );
406 INTEL_DEBUG |= driParseDebugString( getenv( "INTEL_DEBUG" ),
407 debug_control );
408 #endif
409
410 #ifndef VERBOSE
411 if (getenv("INTEL_VERBOSE"))
412 VERBOSE=1;
413 #endif
414
415 if (getenv("INTEL_NO_RAST") ||
416 getenv("INTEL_NO_RAST")) {
417 fprintf(stderr, "disabling 3D rasterization\n");
418 FALLBACK(intel, INTEL_FALLBACK_USER, 1);
419 }
420
421 return GL_TRUE;
422 }
423
424 void intelDestroyContext(__DRIcontextPrivate *driContextPriv)
425 {
426 intelContextPtr intel = (intelContextPtr) driContextPriv->driverPrivate;
427
428 assert(intel); /* should never be null */
429 if (intel) {
430 GLboolean release_texture_heaps;
431
432 INTEL_FIREVERTICES( intel );
433
434 intel->vtbl.destroy( intel );
435
436 release_texture_heaps = (intel->ctx.Shared->RefCount == 1);
437 _swsetup_DestroyContext (&intel->ctx);
438 _tnl_DestroyContext (&intel->ctx);
439 _vbo_DestroyContext (&intel->ctx);
440
441 _swrast_DestroyContext (&intel->ctx);
442 intel->Fallback = 0; /* don't call _swrast_Flush later */
443
444 intelDestroyBatchBuffer(&intel->ctx);
445
446
447 if ( release_texture_heaps ) {
448 /* This share group is about to go away, free our private
449 * texture object data.
450 */
451 int i;
452
453 for ( i = 0 ; i < intel->nr_heaps ; i++ ) {
454 driDestroyTextureHeap( intel->texture_heaps[ i ] );
455 intel->texture_heaps[ i ] = NULL;
456 }
457
458 assert( is_empty_list( & intel->swapped ) );
459 }
460
461 /* free the Mesa context */
462 _mesa_destroy_context(&intel->ctx);
463 }
464 }
465
466 void intelSetFrontClipRects( intelContextPtr intel )
467 {
468 __DRIdrawablePrivate *dPriv = intel->driDrawable;
469
470 if (!dPriv) return;
471
472 intel->numClipRects = dPriv->numClipRects;
473 intel->pClipRects = dPriv->pClipRects;
474 intel->drawX = dPriv->x;
475 intel->drawY = dPriv->y;
476 }
477
478
479 void intelSetBackClipRects( intelContextPtr intel )
480 {
481 __DRIdrawablePrivate *dPriv = intel->driDrawable;
482
483 if (!dPriv) return;
484
485 if (intel->sarea->pf_enabled == 0 && dPriv->numBackClipRects == 0) {
486 intel->numClipRects = dPriv->numClipRects;
487 intel->pClipRects = dPriv->pClipRects;
488 intel->drawX = dPriv->x;
489 intel->drawY = dPriv->y;
490 } else {
491 intel->numClipRects = dPriv->numBackClipRects;
492 intel->pClipRects = dPriv->pBackClipRects;
493 intel->drawX = dPriv->backX;
494 intel->drawY = dPriv->backY;
495
496 if (dPriv->numBackClipRects == 1 &&
497 dPriv->x == dPriv->backX &&
498 dPriv->y == dPriv->backY) {
499
500 /* Repeat the calculation of the back cliprect dimensions here
501 * as early versions of dri.a in the Xserver are incorrect. Try
502 * very hard not to restrict future versions of dri.a which
503 * might eg. allocate truly private back buffers.
504 */
505 int x1, y1;
506 int x2, y2;
507
508 x1 = dPriv->x;
509 y1 = dPriv->y;
510 x2 = dPriv->x + dPriv->w;
511 y2 = dPriv->y + dPriv->h;
512
513 if (x1 < 0) x1 = 0;
514 if (y1 < 0) y1 = 0;
515 if (x2 > intel->intelScreen->width) x2 = intel->intelScreen->width;
516 if (y2 > intel->intelScreen->height) y2 = intel->intelScreen->height;
517
518 if (x1 == dPriv->pBackClipRects[0].x1 &&
519 y1 == dPriv->pBackClipRects[0].y1) {
520
521 dPriv->pBackClipRects[0].x2 = x2;
522 dPriv->pBackClipRects[0].y2 = y2;
523 }
524 }
525 }
526 }
527
528
529 void intelWindowMoved( intelContextPtr intel )
530 {
531 __DRIdrawablePrivate *dPriv = intel->driDrawable;
532 GLframebuffer *drawFb = (GLframebuffer *) dPriv->driverPrivate;
533
534 if (!intel->ctx.DrawBuffer) {
535 intelSetFrontClipRects( intel );
536 }
537 else {
538 driUpdateFramebufferSize(&intel->ctx, dPriv);
539 switch (drawFb->_ColorDrawBufferMask[0]) {
540 case BUFFER_BIT_FRONT_LEFT:
541 intelSetFrontClipRects( intel );
542 break;
543 case BUFFER_BIT_BACK_LEFT:
544 intelSetBackClipRects( intel );
545 break;
546 default:
547 /* glDrawBuffer(GL_NONE or GL_FRONT_AND_BACK): software fallback */
548 intelSetFrontClipRects( intel );
549 }
550 }
551
552 if (drawFb->Width != dPriv->w || drawFb->Height != dPriv->h) {
553 /* update Mesa's notion of framebuffer/window size */
554 _mesa_resize_framebuffer(&intel->ctx, drawFb, dPriv->w, dPriv->h);
555 drawFb->Initialized = GL_TRUE; /* XXX remove someday */
556 }
557
558 /* Set state we know depends on drawable parameters:
559 */
560 {
561 GLcontext *ctx = &intel->ctx;
562
563 if (intel->intelScreen->driScrnPriv->ddxMinor >= 7) {
564 drmI830Sarea *sarea = intel->sarea;
565 drm_clip_rect_t drw_rect = { .x1 = dPriv->x, .x2 = dPriv->x + dPriv->w,
566 .y1 = dPriv->y, .y2 = dPriv->y + dPriv->h };
567 drm_clip_rect_t planeA_rect = { .x1 = sarea->planeA_x,
568 .x2 = sarea->planeA_x + sarea->planeA_w,
569 .y1 = sarea->planeA_y,
570 .y2 = sarea->planeA_y + sarea->planeA_h };
571 drm_clip_rect_t planeB_rect = { .x1 = sarea->planeB_x,
572 .x2 = sarea->planeB_x + sarea->planeB_w,
573 .y1 = sarea->planeB_y,
574 .y2 = sarea->planeB_y + sarea->planeB_h };
575 GLint areaA = driIntersectArea( drw_rect, planeA_rect );
576 GLint areaB = driIntersectArea( drw_rect, planeB_rect );
577 GLuint flags = intel->vblank_flags;
578
579 if (areaB > areaA || (areaA == areaB && areaB > 0)) {
580 flags = intel->vblank_flags | VBLANK_FLAG_SECONDARY;
581 } else {
582 flags = intel->vblank_flags & ~VBLANK_FLAG_SECONDARY;
583 }
584
585 if (flags != intel->vblank_flags) {
586 intel->vblank_flags = flags;
587 driGetCurrentVBlank(dPriv, intel->vblank_flags, &intel->vbl_seq);
588 }
589 } else {
590 intel->vblank_flags &= ~VBLANK_FLAG_SECONDARY;
591 }
592
593 ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y,
594 ctx->Scissor.Width, ctx->Scissor.Height );
595
596 ctx->Driver.DepthRange( ctx,
597 ctx->Viewport.Near,
598 ctx->Viewport.Far );
599 }
600 }
601
602 GLboolean intelUnbindContext(__DRIcontextPrivate *driContextPriv)
603 {
604 return GL_TRUE;
605 }
606
607 GLboolean intelMakeCurrent(__DRIcontextPrivate *driContextPriv,
608 __DRIdrawablePrivate *driDrawPriv,
609 __DRIdrawablePrivate *driReadPriv)
610 {
611
612 if (driContextPriv) {
613 intelContextPtr intel = (intelContextPtr) driContextPriv->driverPrivate;
614
615 if ( intel->driDrawable != driDrawPriv ) {
616 /* Shouldn't the readbuffer be stored also? */
617 driDrawableInitVBlank( driDrawPriv, intel->vblank_flags,
618 &intel->vbl_seq );
619
620 intel->driDrawable = driDrawPriv;
621 intelWindowMoved( intel );
622 }
623
624 _mesa_make_current(&intel->ctx,
625 (GLframebuffer *) driDrawPriv->driverPrivate,
626 (GLframebuffer *) driReadPriv->driverPrivate);
627
628 intel->ctx.Driver.DrawBuffer( &intel->ctx, intel->ctx.Color.DrawBuffer[0] );
629 } else {
630 _mesa_make_current(NULL, NULL, NULL);
631 }
632
633 return GL_TRUE;
634 }
635
636 /**
637 * Use the information in the sarea to update the screen parameters
638 * related to screen rotation.
639 */
640 static void
641 intelUpdateScreenRotation(intelContextPtr intel,
642 __DRIscreenPrivate *sPriv,
643 drmI830Sarea *sarea)
644 {
645 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
646 intelRegion *colorBuf;
647
648 intelUnmapScreenRegions(intelScreen);
649
650 intelUpdateScreenFromSAREA(intelScreen, sarea);
651
652 /* update the current hw offsets for the color and depth buffers */
653 if (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT)
654 colorBuf = &intelScreen->back;
655 else
656 colorBuf = &intelScreen->front;
657 intel->vtbl.update_color_z_regions(intel, colorBuf, &intelScreen->depth);
658
659 if (!intelMapScreenRegions(sPriv)) {
660 fprintf(stderr, "ERROR Remapping screen regions!!!\n");
661 }
662 }
663
664 void intelGetLock( intelContextPtr intel, GLuint flags )
665 {
666 __DRIdrawablePrivate *dPriv = intel->driDrawable;
667 __DRIscreenPrivate *sPriv = intel->driScreen;
668 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
669 drmI830Sarea * sarea = intel->sarea;
670 unsigned i;
671
672 drmGetLock(intel->driFd, intel->hHWContext, flags);
673
674 /* If the window moved, may need to set a new cliprect now.
675 *
676 * NOTE: This releases and regains the hw lock, so all state
677 * checking must be done *after* this call:
678 */
679 if (dPriv)
680 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
681
682 if (dPriv && intel->lastStamp != dPriv->lastStamp) {
683 intelWindowMoved( intel );
684 intel->lastStamp = dPriv->lastStamp;
685 }
686
687 /* If we lost context, need to dump all registers to hardware.
688 * Note that we don't care about 2d contexts, even if they perform
689 * accelerated commands, so the DRI locking in the X server is even
690 * more broken than usual.
691 */
692
693 if (sarea->width != intelScreen->width ||
694 sarea->height != intelScreen->height ||
695 sarea->rotation != intelScreen->current_rotation) {
696 intelUpdateScreenRotation(intel, sPriv, sarea);
697
698 /* This will drop the outstanding batchbuffer on the floor */
699 intel->batch.ptr -= (intel->batch.size - intel->batch.space);
700 intel->batch.space = intel->batch.size;
701 /* lose all primitives */
702 intel->prim.primitive = ~0;
703 intel->prim.start_ptr = 0;
704 intel->prim.flush = 0;
705 intel->vtbl.lost_hardware( intel );
706
707 intel->lastStamp = 0; /* force window update */
708
709 /* Release batch buffer
710 */
711 intelDestroyBatchBuffer(&intel->ctx);
712 intelInitBatchBuffer(&intel->ctx);
713 intel->prim.flush = intel_emit_invarient_state;
714
715 /* Still need to reset the global LRU?
716 */
717 intel_driReinitTextureHeap( intel->texture_heaps[0], intel->intelScreen->tex.size );
718 }
719
720 /* Shared texture managment - if another client has played with
721 * texture space, figure out which if any of our textures have been
722 * ejected, and update our global LRU.
723 */
724 for ( i = 0 ; i < intel->nr_heaps ; i++ ) {
725 DRI_AGE_TEXTURES( intel->texture_heaps[ i ] );
726 }
727 }
728
729
730 void intelSwapBuffers( __DRIdrawablePrivate *dPriv )
731 {
732 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
733 intelContextPtr intel;
734 GLcontext *ctx;
735 intel = (intelContextPtr) dPriv->driContextPriv->driverPrivate;
736 ctx = &intel->ctx;
737 if (ctx->Visual.doubleBufferMode) {
738 intelScreenPrivate *screen = intel->intelScreen;
739 _mesa_notifySwapBuffers( ctx ); /* flush pending rendering comands */
740 if ( 0 /*intel->doPageFlip*/ ) { /* doPageFlip is never set !!! */
741 intelPageFlip( dPriv );
742 } else {
743 intelCopyBuffer( dPriv, NULL );
744 }
745 if (screen->current_rotation != 0) {
746 intelRotateWindow(intel, dPriv, BUFFER_BIT_FRONT_LEFT);
747 }
748 }
749 } else {
750 /* XXX this shouldn't be an error but we can't handle it for now */
751 fprintf(stderr, "%s: drawable has no context!\n", __FUNCTION__);
752 }
753 }
754
755 void intelCopySubBuffer( __DRIdrawablePrivate *dPriv,
756 int x, int y, int w, int h )
757 {
758 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
759 intelContextPtr intel;
760 GLcontext *ctx;
761 intel = (intelContextPtr) dPriv->driContextPriv->driverPrivate;
762 ctx = &intel->ctx;
763 if (ctx->Visual.doubleBufferMode) {
764 drm_clip_rect_t rect;
765 rect.x1 = x + dPriv->x;
766 rect.y1 = (dPriv->h - y - h) + dPriv->y;
767 rect.x2 = rect.x1 + w;
768 rect.y2 = rect.y1 + h;
769 _mesa_notifySwapBuffers( ctx ); /* flush pending rendering comands */
770 intelCopyBuffer( dPriv, &rect );
771 }
772 } else {
773 /* XXX this shouldn't be an error but we can't handle it for now */
774 fprintf(stderr, "%s: drawable has no context!\n", __FUNCTION__);
775 }
776 }