480b442211df84bed8067db1a16e54418a7f4b18
[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 }
283
284
285
286 GLboolean intelInitContext( intelContextPtr intel,
287 const __GLcontextModes *mesaVis,
288 __DRIcontextPrivate *driContextPriv,
289 void *sharedContextPrivate,
290 struct dd_function_table *functions )
291 {
292 GLcontext *ctx = &intel->ctx;
293 GLcontext *shareCtx = (GLcontext *) sharedContextPrivate;
294 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
295 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
296 drmI830Sarea *saPriv = (drmI830Sarea *)
297 (((GLubyte *)sPriv->pSAREA)+intelScreen->sarea_priv_offset);
298 int fthrottle_mode;
299
300 if (!_mesa_initialize_context(&intel->ctx,
301 mesaVis, shareCtx,
302 functions,
303 (void*) intel))
304 return GL_FALSE;
305
306 driContextPriv->driverPrivate = intel;
307 intel->intelScreen = intelScreen;
308 intel->driScreen = sPriv;
309 intel->sarea = saPriv;
310
311
312 (void) memset( intel->texture_heaps, 0, sizeof( intel->texture_heaps ) );
313 make_empty_list( & intel->swapped );
314
315 driParseConfigFiles (&intel->optionCache, &intelScreen->optionCache,
316 intel->driScreen->myNum, "i915");
317
318 ctx->Const.MaxTextureMaxAnisotropy = 2.0;
319
320 ctx->Const.MinLineWidth = 1.0;
321 ctx->Const.MinLineWidthAA = 1.0;
322 ctx->Const.MaxLineWidth = 3.0;
323 ctx->Const.MaxLineWidthAA = 3.0;
324 ctx->Const.LineWidthGranularity = 1.0;
325
326 ctx->Const.MinPointSize = 1.0;
327 ctx->Const.MinPointSizeAA = 1.0;
328 ctx->Const.MaxPointSize = 255.0;
329 ctx->Const.MaxPointSizeAA = 3.0;
330 ctx->Const.PointSizeGranularity = 1.0;
331
332 /* Initialize the software rasterizer and helper modules. */
333 _swrast_CreateContext( ctx );
334 _ac_CreateContext( ctx );
335 _tnl_CreateContext( ctx );
336 _swsetup_CreateContext( ctx );
337
338 /* Install the customized pipeline: */
339 _tnl_destroy_pipeline( ctx );
340 _tnl_install_pipeline( ctx, intel_pipeline );
341
342 /* Configure swrast to match hardware characteristics: */
343 _swrast_allow_pixel_fog( ctx, GL_FALSE );
344 _swrast_allow_vertex_fog( ctx, GL_TRUE );
345
346 /* Dri stuff */
347 intel->hHWContext = driContextPriv->hHWContext;
348 intel->driFd = sPriv->fd;
349 intel->driHwLock = (drmLock *) &sPriv->pSAREA->lock;
350
351 intel->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
352 intel->hw_stipple = 1;
353
354 switch(mesaVis->depthBits) {
355 case 0: /* what to do in this case? */
356 case 16:
357 intel->depth_scale = 1.0/0xffff;
358 intel->polygon_offset_scale = 1.0/0xffff;
359 intel->depth_clear_mask = ~0;
360 intel->ClearDepth = 0xffff;
361 break;
362 case 24:
363 intel->depth_scale = 1.0/0xffffff;
364 intel->polygon_offset_scale = 2.0/0xffffff; /* req'd to pass glean */
365 intel->depth_clear_mask = 0x00ffffff;
366 intel->stencil_clear_mask = 0xff000000;
367 intel->ClearDepth = 0x00ffffff;
368 break;
369 default:
370 assert(0);
371 break;
372 }
373
374 /* Initialize swrast, tnl driver tables: */
375 intelInitSpanFuncs( ctx );
376 intelInitTriFuncs( ctx );
377
378
379 intel->RenderIndex = ~0;
380
381 fthrottle_mode = driQueryOptioni(&intel->optionCache, "fthrottle_mode");
382 intel->iw.irq_seq = -1;
383 intel->irqsEmitted = 0;
384
385 intel->do_irqs = (intel->intelScreen->irq_active &&
386 fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS);
387
388 intel->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
389
390 intel->vblank_flags = (intel->intelScreen->irq_active != 0)
391 ? driGetDefaultVBlankFlags(&intel->optionCache) : VBLANK_FLAG_NO_IRQ;
392
393 (*dri_interface->getUST)(&intel->swap_ust);
394 _math_matrix_ctr (&intel->ViewportMatrix);
395
396 driInitExtensions( ctx, card_extensions, GL_TRUE );
397
398 if (intel->ctx.Mesa_DXTn) {
399 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
400 _mesa_enable_extension( ctx, "GL_S3_s3tc" );
401 }
402 else if (driQueryOptionb (&intel->optionCache, "force_s3tc_enable")) {
403 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
404 }
405
406 /* driInitTextureObjects( ctx, & intel->swapped, */
407 /* DRI_TEXMGR_DO_TEXTURE_1D | */
408 /* DRI_TEXMGR_DO_TEXTURE_2D | */
409 /* DRI_TEXMGR_DO_TEXTURE_RECT ); */
410
411
412 intelInitBatchBuffer(&intel->ctx);
413 intel->prim.flush = intel_emit_invarient_state;
414 intel->prim.primitive = ~0;
415
416
417 #if DO_DEBUG
418 INTEL_DEBUG = driParseDebugString( getenv( "INTEL_DEBUG" ),
419 debug_control );
420 INTEL_DEBUG |= driParseDebugString( getenv( "INTEL_DEBUG" ),
421 debug_control );
422 #endif
423
424 #ifndef VERBOSE
425 if (getenv("INTEL_VERBOSE"))
426 VERBOSE=1;
427 #endif
428
429 if (getenv("INTEL_NO_RAST") ||
430 getenv("INTEL_NO_RAST")) {
431 fprintf(stderr, "disabling 3D rasterization\n");
432 FALLBACK(intel, INTEL_FALLBACK_USER, 1);
433 }
434
435 return GL_TRUE;
436 }
437
438 void intelDestroyContext(__DRIcontextPrivate *driContextPriv)
439 {
440 intelContextPtr intel = (intelContextPtr) driContextPriv->driverPrivate;
441
442 assert(intel); /* should never be null */
443 if (intel) {
444 GLboolean release_texture_heaps;
445
446 INTEL_FIREVERTICES( intel );
447
448 intel->vtbl.destroy( intel );
449
450 release_texture_heaps = (intel->ctx.Shared->RefCount == 1);
451 _swsetup_DestroyContext (&intel->ctx);
452 _tnl_DestroyContext (&intel->ctx);
453 _ac_DestroyContext (&intel->ctx);
454
455 _swrast_DestroyContext (&intel->ctx);
456 intel->Fallback = 0; /* don't call _swrast_Flush later */
457
458 intelDestroyBatchBuffer(&intel->ctx);
459
460
461 if ( release_texture_heaps ) {
462 /* This share group is about to go away, free our private
463 * texture object data.
464 */
465 int i;
466
467 for ( i = 0 ; i < intel->nr_heaps ; i++ ) {
468 driDestroyTextureHeap( intel->texture_heaps[ i ] );
469 intel->texture_heaps[ i ] = NULL;
470 }
471
472 assert( is_empty_list( & intel->swapped ) );
473 }
474
475 /* free the Mesa context */
476 _mesa_destroy_context(&intel->ctx);
477 }
478 }
479
480 void intelSetFrontClipRects( intelContextPtr intel )
481 {
482 __DRIdrawablePrivate *dPriv = intel->driDrawable;
483
484 if (!dPriv) return;
485
486 intel->numClipRects = dPriv->numClipRects;
487 intel->pClipRects = dPriv->pClipRects;
488 intel->drawX = dPriv->x;
489 intel->drawY = dPriv->y;
490 }
491
492
493 void intelSetBackClipRects( intelContextPtr intel )
494 {
495 __DRIdrawablePrivate *dPriv = intel->driDrawable;
496
497 if (!dPriv) return;
498
499 if (intel->sarea->pf_enabled == 0 && dPriv->numBackClipRects == 0) {
500 intel->numClipRects = dPriv->numClipRects;
501 intel->pClipRects = dPriv->pClipRects;
502 intel->drawX = dPriv->x;
503 intel->drawY = dPriv->y;
504 } else {
505 intel->numClipRects = dPriv->numBackClipRects;
506 intel->pClipRects = dPriv->pBackClipRects;
507 intel->drawX = dPriv->backX;
508 intel->drawY = dPriv->backY;
509
510 if (dPriv->numBackClipRects == 1 &&
511 dPriv->x == dPriv->backX &&
512 dPriv->y == dPriv->backY) {
513
514 /* Repeat the calculation of the back cliprect dimensions here
515 * as early versions of dri.a in the Xserver are incorrect. Try
516 * very hard not to restrict future versions of dri.a which
517 * might eg. allocate truly private back buffers.
518 */
519 int x1, y1;
520 int x2, y2;
521
522 x1 = dPriv->x;
523 y1 = dPriv->y;
524 x2 = dPriv->x + dPriv->w;
525 y2 = dPriv->y + dPriv->h;
526
527 if (x1 < 0) x1 = 0;
528 if (y1 < 0) y1 = 0;
529 if (x2 > intel->intelScreen->width) x2 = intel->intelScreen->width;
530 if (y2 > intel->intelScreen->height) y2 = intel->intelScreen->height;
531
532 if (x1 == dPriv->pBackClipRects[0].x1 &&
533 y1 == dPriv->pBackClipRects[0].y1) {
534
535 dPriv->pBackClipRects[0].x2 = x2;
536 dPriv->pBackClipRects[0].y2 = y2;
537 }
538 }
539 }
540 }
541
542
543 void intelWindowMoved( intelContextPtr intel )
544 {
545 __DRIdrawablePrivate *dPriv = intel->driDrawable;
546
547 if (!intel->ctx.DrawBuffer) {
548 intelSetFrontClipRects( intel );
549 }
550 else {
551 driUpdateFramebufferSize(&intel->ctx, intel->driDrawable);
552
553 switch (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0]) {
554 case BUFFER_BIT_FRONT_LEFT:
555 intelSetFrontClipRects( intel );
556 break;
557 case BUFFER_BIT_BACK_LEFT:
558 intelSetBackClipRects( intel );
559 break;
560 default:
561 /* glDrawBuffer(GL_NONE or GL_FRONT_AND_BACK): software fallback */
562 intelSetFrontClipRects( intel );
563 }
564 }
565
566 _mesa_resize_framebuffer(&intel->ctx,
567 (GLframebuffer*)dPriv->driverPrivate,
568 dPriv->w, dPriv->h);
569
570 /* Set state we know depends on drawable parameters:
571 */
572 {
573 GLcontext *ctx = &intel->ctx;
574
575 if (intel->intelScreen->driScrnPriv->ddxMinor >= 7) {
576 drmI830Sarea *sarea = intel->sarea;
577 drm_clip_rect_t drw_rect = { .x1 = dPriv->x, .x2 = dPriv->x + dPriv->w,
578 .y1 = dPriv->y, .y2 = dPriv->y + dPriv->h };
579 drm_clip_rect_t pipeA_rect = { .x1 = sarea->pipeA_x,
580 .x2 = sarea->pipeA_x + sarea->pipeA_w,
581 .y1 = sarea->pipeA_y,
582 .y2 = sarea->pipeA_y + sarea->pipeA_h };
583 drm_clip_rect_t pipeB_rect = { .x1 = sarea->pipeB_x,
584 .x2 = sarea->pipeB_x + sarea->pipeB_w,
585 .y1 = sarea->pipeB_y,
586 .y2 = sarea->pipeB_y + sarea->pipeB_h };
587 GLint areaA = driIntersectArea( drw_rect, pipeA_rect );
588 GLint areaB = driIntersectArea( drw_rect, pipeB_rect );
589 GLuint flags = intel->vblank_flags;
590
591 if (areaB > areaA || (areaA > 0 && areaB > 0)) {
592 flags = intel->vblank_flags | VBLANK_FLAG_SECONDARY;
593 } else {
594 flags = intel->vblank_flags & ~VBLANK_FLAG_SECONDARY;
595 }
596
597 if (flags != intel->vblank_flags) {
598 intel->vblank_flags = flags;
599 driGetCurrentVBlank(dPriv, intel->vblank_flags, &intel->vbl_seq);
600 }
601 } else {
602 intel->vblank_flags &= ~VBLANK_FLAG_SECONDARY;
603 }
604
605 ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y,
606 ctx->Scissor.Width, ctx->Scissor.Height );
607
608 ctx->Driver.DepthRange( ctx,
609 ctx->Viewport.Near,
610 ctx->Viewport.Far );
611 }
612 }
613
614 GLboolean intelUnbindContext(__DRIcontextPrivate *driContextPriv)
615 {
616 return GL_TRUE;
617 }
618
619 GLboolean intelMakeCurrent(__DRIcontextPrivate *driContextPriv,
620 __DRIdrawablePrivate *driDrawPriv,
621 __DRIdrawablePrivate *driReadPriv)
622 {
623
624 if (driContextPriv) {
625 intelContextPtr intel = (intelContextPtr) driContextPriv->driverPrivate;
626
627 if ( intel->driDrawable != driDrawPriv ) {
628 /* Shouldn't the readbuffer be stored also? */
629 driDrawableInitVBlank( driDrawPriv, intel->vblank_flags,
630 &intel->vbl_seq );
631
632 intel->driDrawable = driDrawPriv;
633 intelWindowMoved( intel );
634 }
635
636 _mesa_make_current(&intel->ctx,
637 (GLframebuffer *) driDrawPriv->driverPrivate,
638 (GLframebuffer *) driReadPriv->driverPrivate);
639
640 intel->ctx.Driver.DrawBuffer( &intel->ctx, intel->ctx.Color.DrawBuffer[0] );
641 } else {
642 _mesa_make_current(NULL, NULL, NULL);
643 }
644
645 return GL_TRUE;
646 }
647
648 /**
649 * Use the information in the sarea to update the screen parameters
650 * related to screen rotation.
651 */
652 static void
653 intelUpdateScreenRotation(intelContextPtr intel,
654 __DRIscreenPrivate *sPriv,
655 drmI830Sarea *sarea)
656 {
657 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
658 intelRegion *colorBuf;
659
660 intelUnmapScreenRegions(intelScreen);
661
662 intelUpdateScreenFromSAREA(intelScreen, sarea);
663
664 /* update the current hw offsets for the color and depth buffers */
665 if (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT)
666 colorBuf = &intelScreen->back;
667 else
668 colorBuf = &intelScreen->front;
669 intel->vtbl.update_color_z_regions(intel, colorBuf, &intelScreen->depth);
670
671 if (!intelMapScreenRegions(sPriv)) {
672 fprintf(stderr, "ERROR Remapping screen regions!!!\n");
673 }
674 }
675
676 void intelGetLock( intelContextPtr intel, GLuint flags )
677 {
678 __DRIdrawablePrivate *dPriv = intel->driDrawable;
679 __DRIscreenPrivate *sPriv = intel->driScreen;
680 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
681 drmI830Sarea * sarea = intel->sarea;
682 unsigned i;
683
684 drmGetLock(intel->driFd, intel->hHWContext, flags);
685
686 /* If the window moved, may need to set a new cliprect now.
687 *
688 * NOTE: This releases and regains the hw lock, so all state
689 * checking must be done *after* this call:
690 */
691 if (dPriv)
692 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
693
694 if (dPriv && intel->lastStamp != dPriv->lastStamp) {
695 intelWindowMoved( intel );
696 intel->lastStamp = dPriv->lastStamp;
697 }
698
699 /* If we lost context, need to dump all registers to hardware.
700 * Note that we don't care about 2d contexts, even if they perform
701 * accelerated commands, so the DRI locking in the X server is even
702 * more broken than usual.
703 */
704
705 if (sarea->width != intelScreen->width ||
706 sarea->height != intelScreen->height ||
707 sarea->rotation != intelScreen->current_rotation) {
708 intelUpdateScreenRotation(intel, sPriv, sarea);
709
710 /* This will drop the outstanding batchbuffer on the floor */
711 intel->batch.ptr -= (intel->batch.size - intel->batch.space);
712 intel->batch.space = intel->batch.size;
713 /* lose all primitives */
714 intel->prim.primitive = ~0;
715 intel->prim.start_ptr = 0;
716 intel->prim.flush = 0;
717 intel->vtbl.lost_hardware( intel );
718
719 intel->lastStamp = 0; /* force window update */
720
721 /* Release batch buffer
722 */
723 intelDestroyBatchBuffer(&intel->ctx);
724 intelInitBatchBuffer(&intel->ctx);
725 intel->prim.flush = intel_emit_invarient_state;
726
727 /* Still need to reset the global LRU?
728 */
729 intel_driReinitTextureHeap( intel->texture_heaps[0], intel->intelScreen->tex.size );
730 }
731
732 /* Shared texture managment - if another client has played with
733 * texture space, figure out which if any of our textures have been
734 * ejected, and update our global LRU.
735 */
736 for ( i = 0 ; i < intel->nr_heaps ; i++ ) {
737 DRI_AGE_TEXTURES( intel->texture_heaps[ i ] );
738 }
739 }
740
741
742 void intelSwapBuffers( __DRIdrawablePrivate *dPriv )
743 {
744 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
745 intelContextPtr intel;
746 GLcontext *ctx;
747 intel = (intelContextPtr) dPriv->driContextPriv->driverPrivate;
748 ctx = &intel->ctx;
749 if (ctx->Visual.doubleBufferMode) {
750 intelScreenPrivate *screen = intel->intelScreen;
751 _mesa_notifySwapBuffers( ctx ); /* flush pending rendering comands */
752 if ( 0 /*intel->doPageFlip*/ ) { /* doPageFlip is never set !!! */
753 intelPageFlip( dPriv );
754 } else {
755 intelCopyBuffer( dPriv, NULL );
756 }
757 if (screen->current_rotation != 0) {
758 intelRotateWindow(intel, dPriv, BUFFER_BIT_FRONT_LEFT);
759 }
760 }
761 } else {
762 /* XXX this shouldn't be an error but we can't handle it for now */
763 fprintf(stderr, "%s: drawable has no context!\n", __FUNCTION__);
764 }
765 }
766
767 void intelCopySubBuffer( __DRIdrawablePrivate *dPriv,
768 int x, int y, int w, int h )
769 {
770 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
771 intelContextPtr intel;
772 GLcontext *ctx;
773 intel = (intelContextPtr) dPriv->driContextPriv->driverPrivate;
774 ctx = &intel->ctx;
775 if (ctx->Visual.doubleBufferMode) {
776 drm_clip_rect_t rect;
777 rect.x1 = x + dPriv->x;
778 rect.y1 = (dPriv->h - y - h) + dPriv->y;
779 rect.x2 = rect.x1 + w;
780 rect.y2 = rect.y1 + h;
781 _mesa_notifySwapBuffers( ctx ); /* flush pending rendering comands */
782 intelCopyBuffer( dPriv, &rect );
783 }
784 } else {
785 /* XXX this shouldn't be an error but we can't handle it for now */
786 fprintf(stderr, "%s: drawable has no context!\n", __FUNCTION__);
787 }
788 }
789
790 void intelInitState( GLcontext *ctx )
791 {
792 /* Mesa should do this for us:
793 */
794 ctx->Driver.AlphaFunc( ctx,
795 ctx->Color.AlphaFunc,
796 ctx->Color.AlphaRef);
797
798 ctx->Driver.BlendColor( ctx,
799 ctx->Color.BlendColor );
800
801 ctx->Driver.BlendEquationSeparate( ctx,
802 ctx->Color.BlendEquationRGB,
803 ctx->Color.BlendEquationA);
804
805 ctx->Driver.BlendFuncSeparate( ctx,
806 ctx->Color.BlendSrcRGB,
807 ctx->Color.BlendDstRGB,
808 ctx->Color.BlendSrcA,
809 ctx->Color.BlendDstA);
810
811 ctx->Driver.ColorMask( ctx,
812 ctx->Color.ColorMask[RCOMP],
813 ctx->Color.ColorMask[GCOMP],
814 ctx->Color.ColorMask[BCOMP],
815 ctx->Color.ColorMask[ACOMP]);
816
817 ctx->Driver.CullFace( ctx, ctx->Polygon.CullFaceMode );
818 ctx->Driver.DepthFunc( ctx, ctx->Depth.Func );
819 ctx->Driver.DepthMask( ctx, ctx->Depth.Mask );
820
821 ctx->Driver.Enable( ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled );
822 ctx->Driver.Enable( ctx, GL_BLEND, ctx->Color.BlendEnabled );
823 ctx->Driver.Enable( ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled );
824 ctx->Driver.Enable( ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled );
825 ctx->Driver.Enable( ctx, GL_CULL_FACE, ctx->Polygon.CullFlag );
826 ctx->Driver.Enable( ctx, GL_DEPTH_TEST, ctx->Depth.Test );
827 ctx->Driver.Enable( ctx, GL_DITHER, ctx->Color.DitherFlag );
828 ctx->Driver.Enable( ctx, GL_FOG, ctx->Fog.Enabled );
829 ctx->Driver.Enable( ctx, GL_LIGHTING, ctx->Light.Enabled );
830 ctx->Driver.Enable( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag );
831 ctx->Driver.Enable( ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag );
832 ctx->Driver.Enable( ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled );
833 ctx->Driver.Enable( ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled );
834 ctx->Driver.Enable( ctx, GL_TEXTURE_1D, GL_FALSE );
835 ctx->Driver.Enable( ctx, GL_TEXTURE_2D, GL_FALSE );
836 ctx->Driver.Enable( ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE );
837 ctx->Driver.Enable( ctx, GL_TEXTURE_3D, GL_FALSE );
838 ctx->Driver.Enable( ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE );
839
840 ctx->Driver.Fogfv( ctx, GL_FOG_COLOR, ctx->Fog.Color );
841 ctx->Driver.Fogfv( ctx, GL_FOG_MODE, 0 );
842 ctx->Driver.Fogfv( ctx, GL_FOG_DENSITY, &ctx->Fog.Density );
843 ctx->Driver.Fogfv( ctx, GL_FOG_START, &ctx->Fog.Start );
844 ctx->Driver.Fogfv( ctx, GL_FOG_END, &ctx->Fog.End );
845
846 ctx->Driver.FrontFace( ctx, ctx->Polygon.FrontFace );
847
848 {
849 GLfloat f = (GLfloat)ctx->Light.Model.ColorControl;
850 ctx->Driver.LightModelfv( ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f );
851 }
852
853 ctx->Driver.LineWidth( ctx, ctx->Line.Width );
854 ctx->Driver.LogicOpcode( ctx, ctx->Color.LogicOp );
855 ctx->Driver.PointSize( ctx, ctx->Point.Size );
856 ctx->Driver.PolygonStipple( ctx, (const GLubyte *)ctx->PolygonStipple );
857 ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y,
858 ctx->Scissor.Width, ctx->Scissor.Height );
859 ctx->Driver.ShadeModel( ctx, ctx->Light.ShadeModel );
860 ctx->Driver.StencilFuncSeparate( ctx, GL_FRONT,
861 ctx->Stencil.Function[0],
862 ctx->Stencil.Ref[0],
863 ctx->Stencil.ValueMask[0] );
864 ctx->Driver.StencilFuncSeparate( ctx, GL_BACK,
865 ctx->Stencil.Function[1],
866 ctx->Stencil.Ref[1],
867 ctx->Stencil.ValueMask[1] );
868 ctx->Driver.StencilMaskSeparate( ctx, GL_FRONT, ctx->Stencil.WriteMask[0] );
869 ctx->Driver.StencilMaskSeparate( ctx, GL_BACK, ctx->Stencil.WriteMask[1] );
870 ctx->Driver.StencilOpSeparate( ctx, GL_FRONT,
871 ctx->Stencil.FailFunc[0],
872 ctx->Stencil.ZFailFunc[0],
873 ctx->Stencil.ZPassFunc[0]);
874 ctx->Driver.StencilOpSeparate( ctx, GL_BACK,
875 ctx->Stencil.FailFunc[1],
876 ctx->Stencil.ZFailFunc[1],
877 ctx->Stencil.ZPassFunc[1]);
878
879
880 ctx->Driver.DrawBuffer( ctx, ctx->Color.DrawBuffer[0] );
881 }
882
883