Dave Reveman's patch for GLX_MESA_copy_sub_buffer support
[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
37 #include "swrast/swrast.h"
38 #include "swrast_setup/swrast_setup.h"
39 #include "tnl/tnl.h"
40 #include "array_cache/acache.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 #include "i830_common.h"
51
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
58 #include "vblank.h"
59 #include "utils.h"
60 #include "xmlpool.h" /* for symbolic values of enum-type options */
61 #ifndef INTEL_DEBUG
62 int INTEL_DEBUG = (0);
63 #endif
64
65 #define need_GL_ARB_multisample
66 #define need_GL_ARB_point_parameters
67 #define need_GL_ARB_texture_compression
68 #define need_GL_ARB_vertex_buffer_object
69 #define need_GL_ARB_vertex_program
70 #define need_GL_ARB_window_pos
71 #define need_GL_EXT_blend_color
72 #define need_GL_EXT_blend_equation_separate
73 #define need_GL_EXT_blend_func_separate
74 #define need_GL_EXT_blend_minmax
75 #define need_GL_EXT_cull_vertex
76 #define need_GL_EXT_fog_coord
77 #define need_GL_EXT_multi_draw_arrays
78 #define need_GL_EXT_secondary_color
79 #define need_GL_NV_vertex_program
80 #include "extension_helper.h"
81
82 #ifndef VERBOSE
83 int VERBOSE = 0;
84 #endif
85
86 #if DEBUG_LOCKING
87 char *prevLockFile;
88 int prevLockLine;
89 #endif
90
91 /***************************************
92 * Mesa's Driver Functions
93 ***************************************/
94
95 #define DRIVER_DATE "20050225"
96
97 const GLubyte *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"; break;
111 case PCI_CHIP_I830_M:
112 chipset = "Intel(R) 830M"; break;
113 case PCI_CHIP_I855_GM:
114 chipset = "Intel(R) 852GM/855GM"; break;
115 case PCI_CHIP_I865_G:
116 chipset = "Intel(R) 865G"; break;
117 case PCI_CHIP_I915_G:
118 chipset = "Intel(R) 915G"; break;
119 case PCI_CHIP_I915_GM:
120 chipset = "Intel(R) 915GM"; break;
121 case PCI_CHIP_I945_G:
122 chipset = "Intel(R) 945G"; break;
123 case PCI_CHIP_I945_GM:
124 chipset = "Intel(R) 945GM"; break;
125 default:
126 chipset = "Unknown Intel Chipset"; break;
127 }
128
129 (void) driGetRendererString( buffer, chipset, DRIVER_DATE, 0 );
130 return (GLubyte *) buffer;
131
132 default:
133 return NULL;
134 }
135 }
136
137 static void intelBufferSize(GLframebuffer *buffer,
138 GLuint *width, GLuint *height)
139 {
140 GET_CURRENT_CONTEXT(ctx);
141 intelContextPtr intel = INTEL_CONTEXT(ctx);
142 /* Need to lock to make sure the driDrawable is uptodate. This
143 * information is used to resize Mesa's software buffers, so it has
144 * to be correct.
145 */
146 LOCK_HARDWARE(intel);
147 if (intel->driDrawable) {
148 *width = intel->driDrawable->w;
149 *height = intel->driDrawable->h;
150 }
151 else {
152 *width = 0;
153 *height = 0;
154 }
155 UNLOCK_HARDWARE(intel);
156 }
157
158
159 /**
160 * Extension strings exported by the intel driver.
161 *
162 * \note
163 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
164 * old i830-specific driver.
165 */
166 const struct dri_extension card_extensions[] =
167 {
168 { "GL_ARB_multisample", GL_ARB_multisample_functions },
169 { "GL_ARB_multitexture", NULL },
170 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions },
171 { "GL_ARB_texture_border_clamp", NULL },
172 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions },
173 { "GL_ARB_texture_cube_map", NULL },
174 { "GL_ARB_texture_env_add", NULL },
175 { "GL_ARB_texture_env_combine", NULL },
176 { "GL_ARB_texture_env_dot3", NULL },
177 { "GL_ARB_texture_mirrored_repeat", NULL },
178 { "GL_ARB_texture_rectangle", NULL },
179 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions },
180 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions },
181 { "GL_ARB_window_pos", GL_ARB_window_pos_functions },
182 { "GL_EXT_blend_color", GL_EXT_blend_color_functions },
183 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions },
184 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions },
185 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions },
186 { "GL_EXT_blend_subtract", NULL },
187 { "GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions },
188 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions },
189 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions },
190 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions },
191 { "GL_EXT_stencil_wrap", NULL },
192 { "GL_EXT_texture_edge_clamp", NULL },
193 { "GL_EXT_texture_env_combine", NULL },
194 { "GL_EXT_texture_env_dot3", NULL },
195 { "GL_EXT_texture_filter_anisotropic", NULL },
196 { "GL_EXT_texture_lod_bias", NULL },
197 { "GL_3DFX_texture_compression_FXT1", NULL },
198 { "GL_APPLE_client_storage", NULL },
199 { "GL_MESA_pack_invert", NULL },
200 { "GL_MESA_ycbcr_texture", NULL },
201 { "GL_NV_blend_square", NULL },
202 { "GL_NV_vertex_program", GL_NV_vertex_program_functions },
203 { "GL_NV_vertex_program1_1", NULL },
204 { "GL_SGIS_generate_mipmap", NULL },
205 { NULL, NULL }
206 };
207
208 extern const struct tnl_pipeline_stage _intel_render_stage;
209
210 static const struct tnl_pipeline_stage *intel_pipeline[] = {
211 &_tnl_vertex_transform_stage,
212 &_tnl_vertex_cull_stage,
213 &_tnl_normal_transform_stage,
214 &_tnl_lighting_stage,
215 &_tnl_fog_coordinate_stage,
216 &_tnl_texgen_stage,
217 &_tnl_texture_transform_stage,
218 &_tnl_point_attenuation_stage,
219 &_tnl_arb_vertex_program_stage,
220 &_tnl_vertex_program_stage,
221 #if 1
222 &_intel_render_stage, /* ADD: unclipped rastersetup-to-dma */
223 #endif
224 &_tnl_render_stage,
225 0,
226 };
227
228
229 static const struct dri_debug_control debug_control[] =
230 {
231 { "fall", DEBUG_FALLBACKS },
232 { "tex", DEBUG_TEXTURE },
233 { "ioctl", DEBUG_IOCTL },
234 { "prim", DEBUG_PRIMS },
235 { "vert", DEBUG_VERTS },
236 { "state", DEBUG_STATE },
237 { "verb", DEBUG_VERBOSE },
238 { "dri", DEBUG_DRI },
239 { "dma", DEBUG_DMA },
240 { "san", DEBUG_SANITY },
241 { "sync", DEBUG_SYNC },
242 { "sleep", DEBUG_SLEEP },
243 { "pix", DEBUG_PIXEL },
244 { NULL, 0 }
245 };
246
247
248 static void intelInvalidateState( GLcontext *ctx, GLuint new_state )
249 {
250 _swrast_InvalidateState( ctx, new_state );
251 _swsetup_InvalidateState( ctx, new_state );
252 _ac_InvalidateState( ctx, new_state );
253 _tnl_InvalidateState( ctx, new_state );
254 _tnl_invalidate_vertex_state( ctx, new_state );
255 INTEL_CONTEXT(ctx)->NewGLState |= new_state;
256 }
257
258
259 void intelInitDriverFunctions( struct dd_function_table *functions )
260 {
261 _mesa_init_driver_functions( functions );
262
263 functions->Clear = intelClear;
264 functions->Flush = intelglFlush;
265 functions->Finish = intelFinish;
266 functions->GetBufferSize = intelBufferSize;
267 functions->ResizeBuffers = _mesa_resize_framebuffer;
268 functions->GetString = intelGetString;
269 functions->UpdateState = intelInvalidateState;
270 functions->CopyColorTable = _swrast_CopyColorTable;
271 functions->CopyColorSubTable = _swrast_CopyColorSubTable;
272 functions->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
273 functions->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
274
275 intelInitTextureFuncs( functions );
276 intelInitPixelFuncs( functions );
277 intelInitStateFuncs( functions );
278 }
279
280 static void intel_emit_invarient_state( GLcontext *ctx )
281 {
282 intelContextPtr intel = INTEL_CONTEXT(ctx);
283
284 intel->vtbl.emit_invarient_state( intel );
285 intel->prim.flush = 0;
286
287 /* Make sure this gets to the hardware, even if we have no cliprects:
288 */
289 LOCK_HARDWARE( intel );
290 intelFlushBatchLocked( intel, GL_TRUE, GL_FALSE, GL_TRUE );
291 UNLOCK_HARDWARE( intel );
292 }
293
294
295
296 GLboolean intelInitContext( intelContextPtr intel,
297 const __GLcontextModes *mesaVis,
298 __DRIcontextPrivate *driContextPriv,
299 void *sharedContextPrivate,
300 struct dd_function_table *functions )
301 {
302 GLcontext *ctx = &intel->ctx;
303 GLcontext *shareCtx = (GLcontext *) sharedContextPrivate;
304 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
305 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
306 drmI830Sarea *saPriv = (drmI830Sarea *)
307 (((GLubyte *)sPriv->pSAREA)+intelScreen->sarea_priv_offset);
308 int fthrottle_mode;
309
310 if (!_mesa_initialize_context(&intel->ctx,
311 mesaVis, shareCtx,
312 functions,
313 (void*) intel))
314 return GL_FALSE;
315
316 driContextPriv->driverPrivate = intel;
317 intel->intelScreen = intelScreen;
318 intel->driScreen = sPriv;
319 intel->sarea = saPriv;
320
321
322 (void) memset( intel->texture_heaps, 0, sizeof( intel->texture_heaps ) );
323 make_empty_list( & intel->swapped );
324
325 driParseConfigFiles (&intel->optionCache, &intelScreen->optionCache,
326 intel->driScreen->myNum, "i915");
327
328 ctx->Const.MaxTextureMaxAnisotropy = 2.0;
329
330 ctx->Const.MinLineWidth = 1.0;
331 ctx->Const.MinLineWidthAA = 1.0;
332 ctx->Const.MaxLineWidth = 3.0;
333 ctx->Const.MaxLineWidthAA = 3.0;
334 ctx->Const.LineWidthGranularity = 1.0;
335
336 ctx->Const.MinPointSize = 1.0;
337 ctx->Const.MinPointSizeAA = 1.0;
338 ctx->Const.MaxPointSize = 255.0;
339 ctx->Const.MaxPointSizeAA = 3.0;
340 ctx->Const.PointSizeGranularity = 1.0;
341
342 /* Initialize the software rasterizer and helper modules. */
343 _swrast_CreateContext( ctx );
344 _ac_CreateContext( ctx );
345 _tnl_CreateContext( ctx );
346 _swsetup_CreateContext( ctx );
347
348 /* Install the customized pipeline: */
349 _tnl_destroy_pipeline( ctx );
350 _tnl_install_pipeline( ctx, intel_pipeline );
351
352 /* Configure swrast to match hardware characteristics: */
353 _swrast_allow_pixel_fog( ctx, GL_FALSE );
354 _swrast_allow_vertex_fog( ctx, GL_TRUE );
355
356 /* Dri stuff */
357 intel->hHWContext = driContextPriv->hHWContext;
358 intel->driFd = sPriv->fd;
359 intel->driHwLock = (drmLock *) &sPriv->pSAREA->lock;
360
361 intel->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
362 intel->hw_stipple = 1;
363
364 switch(mesaVis->depthBits) {
365 case 0: /* what to do in this case? */
366 case 16:
367 intel->depth_scale = 1.0/0xffff;
368 intel->polygon_offset_scale = 1.0/0xffff;
369 intel->depth_clear_mask = ~0;
370 intel->ClearDepth = 0xffff;
371 break;
372 case 24:
373 intel->depth_scale = 1.0/0xffffff;
374 intel->polygon_offset_scale = 2.0/0xffffff; /* req'd to pass glean */
375 intel->depth_clear_mask = 0x00ffffff;
376 intel->stencil_clear_mask = 0xff000000;
377 intel->ClearDepth = 0x00ffffff;
378 break;
379 default:
380 assert(0);
381 break;
382 }
383
384 /* Initialize swrast, tnl driver tables: */
385 intelInitSpanFuncs( ctx );
386 intelInitTriFuncs( ctx );
387
388
389 intel->RenderIndex = ~0;
390
391 fthrottle_mode = driQueryOptioni(&intel->optionCache, "fthrottle_mode");
392 intel->iw.irq_seq = -1;
393 intel->irqsEmitted = 0;
394
395 intel->do_irqs = (intel->intelScreen->irq_active &&
396 fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS);
397
398 intel->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
399
400 intel->vblank_flags = (intel->intelScreen->irq_active != 0)
401 ? driGetDefaultVBlankFlags(&intelScreen->optionCache) : VBLANK_FLAG_NO_IRQ;
402
403 (*dri_interface->getUST)(&intel->swap_ust);
404 _math_matrix_ctr (&intel->ViewportMatrix);
405
406 driInitExtensions( ctx, card_extensions, GL_TRUE );
407
408 if (intel->ctx.Mesa_DXTn) {
409 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
410 _mesa_enable_extension( ctx, "GL_S3_s3tc" );
411 }
412 else if (driQueryOptionb (&intelScreen->optionCache, "force_s3tc_enable")) {
413 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
414 }
415
416 /* driInitTextureObjects( ctx, & intel->swapped, */
417 /* DRI_TEXMGR_DO_TEXTURE_1D | */
418 /* DRI_TEXMGR_DO_TEXTURE_2D | */
419 /* DRI_TEXMGR_DO_TEXTURE_RECT ); */
420
421
422 intelInitBatchBuffer(&intel->ctx);
423 intel->prim.flush = intel_emit_invarient_state;
424 intel->prim.primitive = ~0;
425
426
427 #if DO_DEBUG
428 INTEL_DEBUG = driParseDebugString( getenv( "INTEL_DEBUG" ),
429 debug_control );
430 INTEL_DEBUG |= driParseDebugString( getenv( "INTEL_DEBUG" ),
431 debug_control );
432 #endif
433
434 #ifndef VERBOSE
435 if (getenv("INTEL_VERBOSE"))
436 VERBOSE=1;
437 #endif
438
439 if (getenv("INTEL_NO_RAST") ||
440 getenv("INTEL_NO_RAST")) {
441 fprintf(stderr, "disabling 3D rasterization\n");
442 FALLBACK(intel, INTEL_FALLBACK_USER, 1);
443 }
444
445 return GL_TRUE;
446 }
447
448 void intelDestroyContext(__DRIcontextPrivate *driContextPriv)
449 {
450 intelContextPtr intel = (intelContextPtr) driContextPriv->driverPrivate;
451
452 assert(intel); /* should never be null */
453 if (intel) {
454 GLboolean release_texture_heaps;
455
456
457 intel->vtbl.destroy( intel );
458
459 release_texture_heaps = (intel->ctx.Shared->RefCount == 1);
460 _swsetup_DestroyContext (&intel->ctx);
461 _tnl_DestroyContext (&intel->ctx);
462 _ac_DestroyContext (&intel->ctx);
463
464 _swrast_DestroyContext (&intel->ctx);
465 intel->Fallback = 0; /* don't call _swrast_Flush later */
466
467 intelDestroyBatchBuffer(&intel->ctx);
468
469
470 if ( release_texture_heaps ) {
471 /* This share group is about to go away, free our private
472 * texture object data.
473 */
474 int i;
475
476 for ( i = 0 ; i < intel->nr_heaps ; i++ ) {
477 driDestroyTextureHeap( intel->texture_heaps[ i ] );
478 intel->texture_heaps[ i ] = NULL;
479 }
480
481 assert( is_empty_list( & intel->swapped ) );
482 }
483
484 /* free the Mesa context */
485 _mesa_destroy_context(&intel->ctx);
486 }
487 }
488
489 void intelSetFrontClipRects( intelContextPtr intel )
490 {
491 __DRIdrawablePrivate *dPriv = intel->driDrawable;
492
493 if (!dPriv) return;
494
495 intel->numClipRects = dPriv->numClipRects;
496 intel->pClipRects = dPriv->pClipRects;
497 intel->drawX = dPriv->x;
498 intel->drawY = dPriv->y;
499 }
500
501
502 void intelSetBackClipRects( intelContextPtr intel )
503 {
504 __DRIdrawablePrivate *dPriv = intel->driDrawable;
505
506 if (!dPriv) return;
507
508 if (intel->sarea->pf_enabled == 0 && dPriv->numBackClipRects == 0) {
509 intel->numClipRects = dPriv->numClipRects;
510 intel->pClipRects = dPriv->pClipRects;
511 intel->drawX = dPriv->x;
512 intel->drawY = dPriv->y;
513 } else {
514 intel->numClipRects = dPriv->numBackClipRects;
515 intel->pClipRects = dPriv->pBackClipRects;
516 intel->drawX = dPriv->backX;
517 intel->drawY = dPriv->backY;
518
519 if (dPriv->numBackClipRects == 1 &&
520 dPriv->x == dPriv->backX &&
521 dPriv->y == dPriv->backY) {
522
523 /* Repeat the calculation of the back cliprect dimensions here
524 * as early versions of dri.a in the Xserver are incorrect. Try
525 * very hard not to restrict future versions of dri.a which
526 * might eg. allocate truly private back buffers.
527 */
528 int x1, y1;
529 int x2, y2;
530
531 x1 = dPriv->x;
532 y1 = dPriv->y;
533 x2 = dPriv->x + dPriv->w;
534 y2 = dPriv->y + dPriv->h;
535
536 if (x1 < 0) x1 = 0;
537 if (y1 < 0) y1 = 0;
538 if (x2 > intel->intelScreen->width) x2 = intel->intelScreen->width;
539 if (y2 > intel->intelScreen->height) y2 = intel->intelScreen->height;
540
541 if (x1 == dPriv->pBackClipRects[0].x1 &&
542 y1 == dPriv->pBackClipRects[0].y1) {
543
544 dPriv->pBackClipRects[0].x2 = x2;
545 dPriv->pBackClipRects[0].y2 = y2;
546 }
547 }
548 }
549 }
550
551
552 void intelWindowMoved( intelContextPtr intel )
553 {
554 if (!intel->ctx.DrawBuffer) {
555 intelSetFrontClipRects( intel );
556 }
557 else {
558 switch (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0]) {
559 case BUFFER_BIT_FRONT_LEFT:
560 intelSetFrontClipRects( intel );
561 break;
562 case BUFFER_BIT_BACK_LEFT:
563 intelSetBackClipRects( intel );
564 break;
565 default:
566 /* glDrawBuffer(GL_NONE or GL_FRONT_AND_BACK): software fallback */
567 intelSetFrontClipRects( intel );
568 }
569 }
570
571 /* Set state we know depends on drawable parameters:
572 */
573 {
574 GLcontext *ctx = &intel->ctx;
575
576 ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y,
577 ctx->Scissor.Width, ctx->Scissor.Height );
578
579 ctx->Driver.DepthRange( ctx,
580 ctx->Viewport.Near,
581 ctx->Viewport.Far );
582 }
583 }
584
585 GLboolean intelUnbindContext(__DRIcontextPrivate *driContextPriv)
586 {
587 return GL_TRUE;
588 }
589
590 GLboolean intelMakeCurrent(__DRIcontextPrivate *driContextPriv,
591 __DRIdrawablePrivate *driDrawPriv,
592 __DRIdrawablePrivate *driReadPriv)
593 {
594
595 if (driContextPriv) {
596 intelContextPtr intel = (intelContextPtr) driContextPriv->driverPrivate;
597
598 if ( intel->driDrawable != driDrawPriv ) {
599 /* Shouldn't the readbuffer be stored also? */
600 driDrawableInitVBlank( driDrawPriv, intel->vblank_flags );
601
602 intel->driDrawable = driDrawPriv;
603 intelWindowMoved( intel );
604 }
605
606 _mesa_make_current(&intel->ctx,
607 (GLframebuffer *) driDrawPriv->driverPrivate,
608 (GLframebuffer *) driReadPriv->driverPrivate);
609
610 intel->ctx.Driver.DrawBuffer( &intel->ctx, intel->ctx.Color.DrawBuffer[0] );
611 } else {
612 _mesa_make_current(NULL, NULL, NULL);
613 }
614
615 return GL_TRUE;
616 }
617
618 /**
619 * Use the information in the sarea to update the screen parameters
620 * related to screen rotation.
621 */
622 static void
623 intelUpdateScreenRotation(intelContextPtr intel,
624 __DRIscreenPrivate *sPriv,
625 drmI830Sarea *sarea)
626 {
627 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
628 intelRegion *colorBuf;
629
630 intelUnmapScreenRegions(intelScreen);
631
632 intelUpdateScreenFromSAREA(intelScreen, sarea);
633
634 /* update the current hw offsets for the color and depth buffers */
635 if (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT)
636 colorBuf = &intelScreen->back;
637 else
638 colorBuf = &intelScreen->front;
639 intel->vtbl.update_color_z_regions(intel, colorBuf, &intelScreen->depth);
640
641 if (!intelMapScreenRegions(sPriv)) {
642 fprintf(stderr, "ERROR Remapping screen regions!!!\n");
643 }
644 }
645
646 void intelGetLock( intelContextPtr intel, GLuint flags )
647 {
648 __DRIdrawablePrivate *dPriv = intel->driDrawable;
649 __DRIscreenPrivate *sPriv = intel->driScreen;
650 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
651 drmI830Sarea * sarea = intel->sarea;
652 unsigned i;
653
654 drmGetLock(intel->driFd, intel->hHWContext, flags);
655
656 /* If the window moved, may need to set a new cliprect now.
657 *
658 * NOTE: This releases and regains the hw lock, so all state
659 * checking must be done *after* this call:
660 */
661 if (dPriv)
662 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
663
664 if (dPriv && intel->lastStamp != dPriv->lastStamp) {
665 intelWindowMoved( intel );
666 intel->lastStamp = dPriv->lastStamp;
667 }
668
669 /* If we lost context, need to dump all registers to hardware.
670 * Note that we don't care about 2d contexts, even if they perform
671 * accelerated commands, so the DRI locking in the X server is even
672 * more broken than usual.
673 */
674
675 if (sarea->width != intelScreen->width ||
676 sarea->height != intelScreen->height ||
677 sarea->rotation != intelScreen->current_rotation) {
678 intelUpdateScreenRotation(intel, sPriv, sarea);
679
680 /* This will drop the outstanding batchbuffer on the floor */
681 intel->batch.ptr -= (intel->batch.size - intel->batch.space);
682 intel->batch.space = intel->batch.size;
683 /* lose all primitives */
684 intel->prim.primitive = ~0;
685 intel->prim.start_ptr = 0;
686 intel->prim.flush = 0;
687 intel->vtbl.lost_hardware( intel );
688
689 intel->lastStamp = 0; /* force window update */
690
691 /* Release batch buffer
692 */
693 intelDestroyBatchBuffer(&intel->ctx);
694 intelInitBatchBuffer(&intel->ctx);
695 intel->prim.flush = intel_emit_invarient_state;
696
697 /* Still need to reset the global LRU?
698 */
699 intel_driReinitTextureHeap( intel->texture_heaps[0], intel->intelScreen->tex.size );
700 }
701
702 /* Shared texture managment - if another client has played with
703 * texture space, figure out which if any of our textures have been
704 * ejected, and update our global LRU.
705 */
706 for ( i = 0 ; i < intel->nr_heaps ; i++ ) {
707 DRI_AGE_TEXTURES( intel->texture_heaps[ i ] );
708 }
709 }
710
711
712 void intelSwapBuffers( __DRIdrawablePrivate *dPriv )
713 {
714 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
715 intelContextPtr intel;
716 GLcontext *ctx;
717 intel = (intelContextPtr) dPriv->driContextPriv->driverPrivate;
718 ctx = &intel->ctx;
719 if (ctx->Visual.doubleBufferMode) {
720 intelScreenPrivate *screen = intel->intelScreen;
721 _mesa_notifySwapBuffers( ctx ); /* flush pending rendering comands */
722 if ( 0 /*intel->doPageFlip*/ ) { /* doPageFlip is never set !!! */
723 intelPageFlip( dPriv );
724 } else {
725 intelCopyBuffer( dPriv, NULL );
726 }
727 if (screen->current_rotation != 0) {
728 intelRotateWindow(intel, dPriv, BUFFER_BIT_FRONT_LEFT);
729 }
730 }
731 } else {
732 /* XXX this shouldn't be an error but we can't handle it for now */
733 fprintf(stderr, "%s: drawable has no context!\n", __FUNCTION__);
734 }
735 }
736
737 void intelCopySubBuffer( __DRIdrawablePrivate *dPriv,
738 int x, int y, int w, int h )
739 {
740 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
741 intelContextPtr intel;
742 GLcontext *ctx;
743 intel = (intelContextPtr) dPriv->driContextPriv->driverPrivate;
744 ctx = &intel->ctx;
745 if (ctx->Visual.doubleBufferMode) {
746 intelScreenPrivate *screen = intel->intelScreen;
747 drm_clip_rect_t rect;
748 rect.x1 = x + dPriv->x;
749 rect.y1 = (dPriv->h - y - h) + dPriv->y;
750 rect.x2 = rect.x1 + w;
751 rect.y2 = rect.y1 + h;
752 _mesa_notifySwapBuffers( ctx ); /* flush pending rendering comands */
753 intelCopyBuffer( dPriv, &rect );
754 }
755 } else {
756 /* XXX this shouldn't be an error but we can't handle it for now */
757 fprintf(stderr, "%s: drawable has no context!\n", __FUNCTION__);
758 }
759 }
760
761 void intelInitState( GLcontext *ctx )
762 {
763 /* Mesa should do this for us:
764 */
765 ctx->Driver.AlphaFunc( ctx,
766 ctx->Color.AlphaFunc,
767 ctx->Color.AlphaRef);
768
769 ctx->Driver.BlendColor( ctx,
770 ctx->Color.BlendColor );
771
772 ctx->Driver.BlendEquationSeparate( ctx,
773 ctx->Color.BlendEquationRGB,
774 ctx->Color.BlendEquationA);
775
776 ctx->Driver.BlendFuncSeparate( ctx,
777 ctx->Color.BlendSrcRGB,
778 ctx->Color.BlendDstRGB,
779 ctx->Color.BlendSrcA,
780 ctx->Color.BlendDstA);
781
782 ctx->Driver.ColorMask( ctx,
783 ctx->Color.ColorMask[RCOMP],
784 ctx->Color.ColorMask[GCOMP],
785 ctx->Color.ColorMask[BCOMP],
786 ctx->Color.ColorMask[ACOMP]);
787
788 ctx->Driver.CullFace( ctx, ctx->Polygon.CullFaceMode );
789 ctx->Driver.DepthFunc( ctx, ctx->Depth.Func );
790 ctx->Driver.DepthMask( ctx, ctx->Depth.Mask );
791
792 ctx->Driver.Enable( ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled );
793 ctx->Driver.Enable( ctx, GL_BLEND, ctx->Color.BlendEnabled );
794 ctx->Driver.Enable( ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled );
795 ctx->Driver.Enable( ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled );
796 ctx->Driver.Enable( ctx, GL_CULL_FACE, ctx->Polygon.CullFlag );
797 ctx->Driver.Enable( ctx, GL_DEPTH_TEST, ctx->Depth.Test );
798 ctx->Driver.Enable( ctx, GL_DITHER, ctx->Color.DitherFlag );
799 ctx->Driver.Enable( ctx, GL_FOG, ctx->Fog.Enabled );
800 ctx->Driver.Enable( ctx, GL_LIGHTING, ctx->Light.Enabled );
801 ctx->Driver.Enable( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag );
802 ctx->Driver.Enable( ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag );
803 ctx->Driver.Enable( ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled );
804 ctx->Driver.Enable( ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled );
805 ctx->Driver.Enable( ctx, GL_TEXTURE_1D, GL_FALSE );
806 ctx->Driver.Enable( ctx, GL_TEXTURE_2D, GL_FALSE );
807 ctx->Driver.Enable( ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE );
808 ctx->Driver.Enable( ctx, GL_TEXTURE_3D, GL_FALSE );
809 ctx->Driver.Enable( ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE );
810
811 ctx->Driver.Fogfv( ctx, GL_FOG_COLOR, ctx->Fog.Color );
812 ctx->Driver.Fogfv( ctx, GL_FOG_MODE, 0 );
813 ctx->Driver.Fogfv( ctx, GL_FOG_DENSITY, &ctx->Fog.Density );
814 ctx->Driver.Fogfv( ctx, GL_FOG_START, &ctx->Fog.Start );
815 ctx->Driver.Fogfv( ctx, GL_FOG_END, &ctx->Fog.End );
816
817 ctx->Driver.FrontFace( ctx, ctx->Polygon.FrontFace );
818
819 {
820 GLfloat f = (GLfloat)ctx->Light.Model.ColorControl;
821 ctx->Driver.LightModelfv( ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f );
822 }
823
824 ctx->Driver.LineWidth( ctx, ctx->Line.Width );
825 ctx->Driver.LogicOpcode( ctx, ctx->Color.LogicOp );
826 ctx->Driver.PointSize( ctx, ctx->Point.Size );
827 ctx->Driver.PolygonStipple( ctx, (const GLubyte *)ctx->PolygonStipple );
828 ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y,
829 ctx->Scissor.Width, ctx->Scissor.Height );
830 ctx->Driver.ShadeModel( ctx, ctx->Light.ShadeModel );
831 ctx->Driver.StencilFuncSeparate( ctx, GL_FRONT,
832 ctx->Stencil.Function[0],
833 ctx->Stencil.Ref[0],
834 ctx->Stencil.ValueMask[0] );
835 ctx->Driver.StencilFuncSeparate( ctx, GL_BACK,
836 ctx->Stencil.Function[1],
837 ctx->Stencil.Ref[1],
838 ctx->Stencil.ValueMask[1] );
839 ctx->Driver.StencilMaskSeparate( ctx, GL_FRONT, ctx->Stencil.WriteMask[0] );
840 ctx->Driver.StencilMaskSeparate( ctx, GL_BACK, ctx->Stencil.WriteMask[1] );
841 ctx->Driver.StencilOpSeparate( ctx, GL_FRONT,
842 ctx->Stencil.FailFunc[0],
843 ctx->Stencil.ZFailFunc[0],
844 ctx->Stencil.ZPassFunc[0]);
845 ctx->Driver.StencilOpSeparate( ctx, GL_BACK,
846 ctx->Stencil.FailFunc[1],
847 ctx->Stencil.ZFailFunc[1],
848 ctx->Stencil.ZPassFunc[1]);
849
850
851 ctx->Driver.DrawBuffer( ctx, ctx->Color.DrawBuffer[0] );
852 }
853
854