~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/lib/GL/mesa/src/drv/i830/i830_context.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
 * 
 
3
 * Copyright 1998-1999 Precision Insight, 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 PRECISION INSIGHT 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
/* $XFree86: xc/lib/GL/mesa/src/drv/i830/i830_context.c,v 1.9 2003/02/06 04:18:00 dawes Exp $ */
 
28
 
 
29
/*
 
30
 * Authors:
 
31
 *   Jeff Hartmann <jhartmann@2d3d.com>
 
32
 *   Graeme Fisher <graeme@2d3d.co.za>
 
33
 *   Abraham vd Merwe <abraham@2d3d.co.za>
 
34
 *
 
35
 * Heavily Based on I810 driver written by:
 
36
 *   Keith Whitwell <keith@tungstengraphics.com>
 
37
 */
 
38
 
 
39
#include "glheader.h"
 
40
#include "context.h"
 
41
#include "matrix.h"
 
42
#include "simple_list.h"
 
43
#include "extensions.h"
 
44
#include "mem.h"
 
45
 
 
46
#include "swrast/swrast.h"
 
47
#include "swrast_setup/swrast_setup.h"
 
48
#include "tnl/tnl.h"
 
49
#include "array_cache/acache.h"
 
50
 
 
51
#include "tnl/t_pipeline.h"
 
52
 
 
53
#include "i830_screen.h"
 
54
#include "i830_dri.h"
 
55
 
 
56
#include "i830_state.h"
 
57
#include "i830_tex.h"
 
58
#include "i830_span.h"
 
59
#include "i830_tris.h"
 
60
#include "i830_vb.h"
 
61
#include "i830_ioctl.h"
 
62
 
 
63
#include <X11/Xlibint.h>
 
64
#include <stdio.h>
 
65
 
 
66
 
 
67
#ifndef I830_DEBUG
 
68
int I830_DEBUG = (0);
 
69
#endif
 
70
 
 
71
/***************************************
 
72
 * Mesa's Driver Functions
 
73
 ***************************************/
 
74
 
 
75
#define DRIVER_DATE                     "20021115"
 
76
 
 
77
static const GLubyte *i830DDGetString( GLcontext *ctx, GLenum name )
 
78
{
 
79
   switch (I830_CONTEXT(ctx)->i830Screen->deviceID) {
 
80
   case PCI_CHIP_845_G:
 
81
      switch (name) {
 
82
      case GL_VENDOR:
 
83
         return (GLubyte *)"2d3D, Inc";
 
84
      case GL_RENDERER:
 
85
         return (GLubyte *)"Mesa DRI Intel(R) 845G " DRIVER_DATE;
 
86
      default:
 
87
         return 0;
 
88
      }
 
89
      break;
 
90
   case PCI_CHIP_I830_M:
 
91
      switch (name) {
 
92
      case GL_VENDOR:
 
93
         return (GLubyte *)"VA Linux, Inc";
 
94
      case GL_RENDERER:
 
95
         return (GLubyte *)"Mesa DRI Intel(R) 830M " DRIVER_DATE;
 
96
      default:
 
97
         return 0;
 
98
      }
 
99
      break;
 
100
   case PCI_CHIP_I855_GM:
 
101
      switch (name) {
 
102
      case GL_VENDOR:
 
103
         return (GLubyte *)"Tungsten Graphics, Inc";
 
104
      case GL_RENDERER:
 
105
         return (GLubyte *)"Mesa DRI Intel(R) 852GM/855GM " DRIVER_DATE;
 
106
      default:
 
107
         return 0;
 
108
      }
 
109
      break;
 
110
   case PCI_CHIP_I865_G:
 
111
      switch (name) {
 
112
      case GL_VENDOR:
 
113
         return (GLubyte *)"Tungsten Graphics, Inc";
 
114
      case GL_RENDERER:
 
115
         return (GLubyte *)"Mesa DRI Intel(R) 865G " DRIVER_DATE;
 
116
      default:
 
117
         return 0;
 
118
      }
 
119
      break;
 
120
   default:
 
121
      switch (name) {
 
122
      case GL_VENDOR:
 
123
         return (GLubyte *)"Tungsten Graphics, Inc";
 
124
      case GL_RENDERER:
 
125
         return (GLubyte *)"Mesa DRI Unknown Intel Chipset " DRIVER_DATE;
 
126
      default:
 
127
         return 0;
 
128
      }
 
129
      break;
 
130
   }
 
131
}
 
132
 
 
133
static void i830BufferSize(GLframebuffer *buffer,
 
134
                           GLuint *width, GLuint *height)
 
135
{
 
136
   GET_CURRENT_CONTEXT(ctx);
 
137
   i830ContextPtr imesa = I830_CONTEXT(ctx);
 
138
   /* Need to lock to make sure the driDrawable is uptodate.  This
 
139
    * information is used to resize Mesa's software buffers, so it has
 
140
    * to be correct.
 
141
    */
 
142
   LOCK_HARDWARE(imesa);
 
143
   *width = imesa->driDrawable->w;
 
144
   *height = imesa->driDrawable->h;
 
145
   UNLOCK_HARDWARE(imesa);
 
146
}
 
147
 
 
148
/* Enable all the extensions we need */
 
149
static void i830InitExtensions( GLcontext *ctx )
 
150
{
 
151
   _mesa_enable_imaging_extensions( ctx );
 
152
   _mesa_enable_extension( ctx, "GL_ARB_multitexture" );
 
153
   _mesa_enable_extension( ctx, "GL_ARB_texture_env_add" );
 
154
   _mesa_enable_extension( ctx, "GL_EXT_texture_env_add" );
 
155
   _mesa_enable_extension( ctx, "GL_ARB_texture_env_combine" ); 
 
156
   _mesa_enable_extension( ctx, "GL_EXT_texture_env_combine" ); 
 
157
   _mesa_enable_extension( ctx, "GL_EXT_blend_color" );
 
158
   _mesa_enable_extension( ctx, "GL_EXT_blend_minmax" );
 
159
   _mesa_enable_extension( ctx, "GL_EXT_blend_subtract" );
 
160
   _mesa_enable_extension( ctx, "GL_EXT_blend_func_separate" );
 
161
   _mesa_enable_extension( ctx, "GL_EXT_texture_lod_bias" );
 
162
   _mesa_enable_extension( ctx, "GL_EXT_secondary_color" );
 
163
   _mesa_enable_extension( ctx, "GL_EXT_fog_coord" );
 
164
 
 
165
   /* Leave this for later */
 
166
#if 0
 
167
   _mesa_enable_extension( ctx, "GL_EXT_stencil_wrap" );
 
168
#endif
 
169
}
 
170
 
 
171
extern const struct gl_pipeline_stage _i830_render_stage;
 
172
 
 
173
static const struct gl_pipeline_stage *i830_pipeline[] = {
 
174
   &_tnl_vertex_transform_stage,
 
175
   &_tnl_normal_transform_stage,
 
176
   &_tnl_lighting_stage,
 
177
   &_tnl_fog_coordinate_stage,
 
178
   &_tnl_texgen_stage,
 
179
   &_tnl_texture_transform_stage,
 
180
                                /* REMOVE: point attenuation stage */
 
181
#if 1
 
182
   &_i830_render_stage,     /* ADD: unclipped rastersetup-to-dma */
 
183
#endif
 
184
   &_tnl_render_stage,
 
185
   0,
 
186
};
 
187
 
 
188
 
 
189
#if DO_DEBUG
 
190
static void add_debug_flags( const char *debug )
 
191
{
 
192
   if (strstr(debug, "fall")) 
 
193
      I830_DEBUG |= DEBUG_FALLBACKS;
 
194
 
 
195
   if (strstr(debug, "tex")) 
 
196
      I830_DEBUG |= DEBUG_TEXTURE;
 
197
 
 
198
   if (strstr(debug, "ioctl")) 
 
199
      I830_DEBUG |= DEBUG_IOCTL;
 
200
 
 
201
   if (strstr(debug, "prim")) 
 
202
      I830_DEBUG |= DEBUG_PRIMS;
 
203
 
 
204
   if (strstr(debug, "vert")) 
 
205
      I830_DEBUG |= DEBUG_VERTS;
 
206
 
 
207
   if (strstr(debug, "state")) 
 
208
      I830_DEBUG |= DEBUG_STATE;
 
209
 
 
210
   if (strstr(debug, "verb")) 
 
211
      I830_DEBUG |= DEBUG_VERBOSE;
 
212
 
 
213
   if (strstr(debug, "dri")) 
 
214
      I830_DEBUG |= DEBUG_DRI;
 
215
 
 
216
   if (strstr(debug, "dma")) 
 
217
      I830_DEBUG |= DEBUG_DMA;
 
218
 
 
219
   if (strstr(debug, "san")) 
 
220
      I830_DEBUG |= DEBUG_SANITY;
 
221
 
 
222
   if (strstr(debug, "sync")) 
 
223
      I830_DEBUG |= DEBUG_SYNC;
 
224
 
 
225
   if (strstr(debug, "sleep")) 
 
226
      I830_DEBUG |= DEBUG_SLEEP;
 
227
}
 
228
#endif
 
229
 
 
230
GLboolean i830CreateContext( Display *dpy, const __GLcontextModes *mesaVis,
 
231
                            __DRIcontextPrivate *driContextPriv,
 
232
                            void *sharedContextPrivate)
 
233
{
 
234
   GLcontext *ctx , *shareCtx;
 
235
   i830ContextPtr imesa;
 
236
   __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
 
237
   i830ScreenPrivate *i830Screen = (i830ScreenPrivate *)sPriv->private;
 
238
   I830SAREAPtr saPriv=(I830SAREAPtr)
 
239
       (((GLubyte *)sPriv->pSAREA)+i830Screen->sarea_priv_offset);
 
240
 
 
241
   /* Allocate i830 context */
 
242
   imesa = (i830ContextPtr) CALLOC_STRUCT(i830_context_t);
 
243
   if (!imesa) return GL_FALSE;
 
244
 
 
245
   /* Allocate the Mesa context */
 
246
   if (sharedContextPrivate)
 
247
     shareCtx = ((i830ContextPtr) sharedContextPrivate)->glCtx;
 
248
   else
 
249
     shareCtx = NULL;
 
250
   
 
251
   imesa->glCtx = _mesa_create_context(mesaVis, shareCtx, imesa, GL_TRUE);
 
252
   if (!imesa->glCtx) {
 
253
      FREE(imesa);
 
254
      return GL_FALSE;
 
255
   }
 
256
   driContextPriv->driverPrivate = imesa;
 
257
 
 
258
   /* Set the maximum texture size small enough that we can guarentee
 
259
    * that both texture units can bind a maximal texture and have them
 
260
    * in memory at once.
 
261
    */
 
262
   ctx = imesa->glCtx;
 
263
   if (i830Screen->textureSize < 2*1024*1024) {
 
264
      ctx->Const.MaxTextureLevels = 9;
 
265
   } else if (i830Screen->textureSize < 8*1024*1024) {
 
266
      ctx->Const.MaxTextureLevels = 10;
 
267
   } else {
 
268
      ctx->Const.MaxTextureLevels = 11;
 
269
   }
 
270
   ctx->Const.MaxTextureUnits = 2;
 
271
 
 
272
   ctx->Const.MinLineWidth = 1.0;
 
273
   ctx->Const.MinLineWidthAA = 1.0;
 
274
   ctx->Const.MaxLineWidth = 3.0;
 
275
   ctx->Const.MaxLineWidthAA = 3.0;
 
276
   ctx->Const.LineWidthGranularity = 1.0;
 
277
 
 
278
   ctx->Const.MinPointSize = 1.0;
 
279
   ctx->Const.MinPointSizeAA = 1.0;
 
280
   ctx->Const.MaxPointSize = 255.0;
 
281
   ctx->Const.MaxPointSizeAA = 3.0;
 
282
   ctx->Const.PointSizeGranularity = 1.0;
 
283
 
 
284
   ctx->Driver.GetBufferSize = i830BufferSize;
 
285
   ctx->Driver.ResizeBuffers = _swrast_alloc_buffers;
 
286
   ctx->Driver.GetString = i830DDGetString;
 
287
 
 
288
   /* Who owns who? */
 
289
   ctx->DriverCtx = (void *) imesa;
 
290
   imesa->glCtx = ctx;
 
291
 
 
292
   /* Initialize the software rasterizer and helper modules. */
 
293
   _swrast_CreateContext( ctx );
 
294
   _ac_CreateContext( ctx );
 
295
   _tnl_CreateContext( ctx );
 
296
   _swsetup_CreateContext( ctx );
 
297
 
 
298
   /* Install the customized pipeline: */
 
299
   _tnl_destroy_pipeline( ctx );
 
300
   _tnl_install_pipeline( ctx, i830_pipeline );
 
301
 
 
302
   /* Configure swrast to match hardware characteristics: */
 
303
   _swrast_allow_pixel_fog( ctx, GL_FALSE );
 
304
   _swrast_allow_vertex_fog( ctx, GL_TRUE );
 
305
 
 
306
   /* Dri stuff */
 
307
   imesa->display = dpy;
 
308
   imesa->hHWContext = driContextPriv->hHWContext;
 
309
   imesa->driFd = sPriv->fd;
 
310
   imesa->driHwLock = &sPriv->pSAREA->lock;
 
311
   imesa->vertex_format = 0;
 
312
 
 
313
   imesa->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
 
314
 
 
315
   switch(mesaVis->depthBits) {
 
316
   case 16:
 
317
      imesa->depth_scale = 1.0/0xffff;
 
318
      imesa->depth_clear_mask = ~0;
 
319
      imesa->ClearDepth = 0xffff;
 
320
      break;
 
321
   case 24:
 
322
      imesa->depth_scale = 1.0/0xffffff;
 
323
      imesa->depth_clear_mask = 0x00ffffff;
 
324
      imesa->stencil_clear_mask = 0xff000000;
 
325
      imesa->ClearDepth = 0x00ffffff;
 
326
      break;
 
327
   case 32: /* Not supported */
 
328
   default:
 
329
      break;
 
330
   }
 
331
   /* Completely disable stenciling for now, there are some serious issues
 
332
    * with stencil.
 
333
    */
 
334
#if 1
 
335
   imesa->hw_stencil = 0;
 
336
#endif
 
337
 
 
338
   imesa->i830Screen = i830Screen;
 
339
   imesa->driScreen = sPriv;
 
340
   imesa->sarea = saPriv;
 
341
   imesa->glBuffer = NULL;
 
342
 
 
343
   imesa->texHeap = mmInit( 0, i830Screen->textureSize );
 
344
   imesa->RenderIndex = ~0;
 
345
   imesa->dirty = ~0;
 
346
   imesa->upload_cliprects = GL_TRUE;
 
347
 
 
348
   make_empty_list(&imesa->TexObjList);
 
349
   make_empty_list(&imesa->SwappedOut);
 
350
 
 
351
   imesa->CurrentTexObj[0] = 0;
 
352
   imesa->CurrentTexObj[1] = 0;
 
353
 
 
354
   imesa->do_irqs = (imesa->i830Screen->irq_active &&
 
355
                     !getenv("I830_NO_IRQS"));
 
356
 
 
357
   _math_matrix_ctr (&imesa->ViewportMatrix);
 
358
 
 
359
   i830InitExtensions (ctx);
 
360
   i830DDInitStateFuncs( ctx );
 
361
   i830DDInitTextureFuncs( ctx );
 
362
   i830InitTriFuncs (ctx);
 
363
   i830DDInitSpanFuncs( ctx );
 
364
   i830DDInitIoctlFuncs( ctx );
 
365
   i830InitVB (ctx);
 
366
   i830DDInitState (ctx);
 
367
 
 
368
#if DO_DEBUG
 
369
   if (getenv("INTEL_DEBUG"))
 
370
      add_debug_flags( getenv("INTEL_DEBUG") );
 
371
   if (getenv("I830_DEBUG"))
 
372
      add_debug_flags( getenv("I830_DEBUG") );
 
373
#endif
 
374
 
 
375
   if (getenv("I830_NO_RAST") || 
 
376
       getenv("INTEL_NO_RAST")) {
 
377
      fprintf(stderr, "disabling 3D rasterization\n");
 
378
      FALLBACK(imesa, I830_FALLBACK_USER, 1); 
 
379
   }
 
380
 
 
381
 
 
382
   return GL_TRUE;
 
383
}
 
384
 
 
385
void i830DestroyContext(__DRIcontextPrivate *driContextPriv)
 
386
{
 
387
   i830ContextPtr imesa = (i830ContextPtr) driContextPriv->driverPrivate;
 
388
 
 
389
   assert(imesa); /* should never be null */
 
390
   if (imesa) {
 
391
      _swsetup_DestroyContext (imesa->glCtx);
 
392
      _tnl_DestroyContext (imesa->glCtx);
 
393
      _ac_DestroyContext (imesa->glCtx);
 
394
      _swrast_DestroyContext (imesa->glCtx);
 
395
 
 
396
      i830FreeVB (imesa->glCtx);
 
397
 
 
398
      /* free the Mesa context */
 
399
      imesa->glCtx->DriverCtx = NULL;
 
400
      _mesa_destroy_context(imesa->glCtx);
 
401
 
 
402
      Xfree (imesa);
 
403
   }
 
404
}
 
405
 
 
406
void i830XMesaSetFrontClipRects( i830ContextPtr imesa )
 
407
{
 
408
   __DRIdrawablePrivate *dPriv = imesa->driDrawable;
 
409
 
 
410
   imesa->numClipRects = dPriv->numClipRects;
 
411
   imesa->pClipRects = dPriv->pClipRects;
 
412
   imesa->drawX = dPriv->x;
 
413
   imesa->drawY = dPriv->y;
 
414
 
 
415
   i830EmitDrawingRectangle( imesa );
 
416
   imesa->upload_cliprects = GL_TRUE;
 
417
}
 
418
 
 
419
void i830XMesaSetBackClipRects( i830ContextPtr imesa )
 
420
{
 
421
   __DRIdrawablePrivate *dPriv = imesa->driDrawable;
 
422
 
 
423
   if (imesa->sarea->pf_enabled == 0 && dPriv->numBackClipRects == 0) {
 
424
      imesa->numClipRects = dPriv->numClipRects;
 
425
      imesa->pClipRects = dPriv->pClipRects;
 
426
      imesa->drawX = dPriv->x;
 
427
      imesa->drawY = dPriv->y;
 
428
   } else {
 
429
      imesa->numClipRects = dPriv->numBackClipRects;
 
430
      imesa->pClipRects = dPriv->pBackClipRects;
 
431
      imesa->drawX = dPriv->backX;
 
432
      imesa->drawY = dPriv->backY;
 
433
   }
 
434
 
 
435
   i830EmitDrawingRectangle( imesa );
 
436
   imesa->upload_cliprects = GL_TRUE;
 
437
}
 
438
 
 
439
static void i830XMesaWindowMoved( i830ContextPtr imesa )
 
440
{
 
441
   switch (imesa->glCtx->Color.DriverDrawBuffer) {
 
442
   case GL_FRONT_LEFT:
 
443
      i830XMesaSetFrontClipRects( imesa );
 
444
      break;
 
445
   case GL_BACK_LEFT:
 
446
      i830XMesaSetBackClipRects( imesa );
 
447
      break;
 
448
   default:
 
449
      break;
 
450
   }
 
451
}
 
452
 
 
453
GLboolean i830UnbindContext(__DRIcontextPrivate *driContextPriv)
 
454
{
 
455
   i830ContextPtr imesa = (i830ContextPtr) driContextPriv->driverPrivate;
 
456
   if (imesa) {
 
457
      /* Might want to change this so texblend isn't always updated */
 
458
      imesa->dirty |= (I830_UPLOAD_CTX |
 
459
                       I830_UPLOAD_BUFFERS |
 
460
                       I830_UPLOAD_STIPPLE |
 
461
                       I830_UPLOAD_TEXBLEND0 |
 
462
                       I830_UPLOAD_TEXBLEND1);
 
463
 
 
464
      if (imesa->CurrentTexObj[0]) imesa->dirty |= I830_UPLOAD_TEX0;
 
465
      if (imesa->CurrentTexObj[1]) imesa->dirty |= I830_UPLOAD_TEX1;
 
466
   }
 
467
   return GL_TRUE;
 
468
}
 
469
 
 
470
GLboolean i830MakeCurrent(__DRIcontextPrivate *driContextPriv,
 
471
                          __DRIdrawablePrivate *driDrawPriv,
 
472
                          __DRIdrawablePrivate *driReadPriv)
 
473
{
 
474
 
 
475
   if (driContextPriv) {
 
476
      i830ContextPtr imesa = (i830ContextPtr) driContextPriv->driverPrivate;
 
477
 
 
478
      if ( imesa->driDrawable != driDrawPriv ) {
 
479
         /* Shouldn't the readbuffer be stored also? */
 
480
         imesa->driDrawable = driDrawPriv;
 
481
         i830XMesaWindowMoved( imesa );
 
482
      }
 
483
 
 
484
      _mesa_make_current2(imesa->glCtx,
 
485
                          (GLframebuffer *) driDrawPriv->driverPrivate,
 
486
                          (GLframebuffer *) driReadPriv->driverPrivate);
 
487
 
 
488
      if (!imesa->glCtx->Viewport.Width)
 
489
         _mesa_set_viewport(imesa->glCtx, 0, 0,
 
490
                            driDrawPriv->w, driDrawPriv->h);
 
491
   } else {
 
492
      _mesa_make_current(0,0);
 
493
   }
 
494
 
 
495
   return GL_TRUE;
 
496
}
 
497
 
 
498
/* Turn on/off page flipping according to the flags in the sarea:
 
499
 */
 
500
static void
 
501
i830UpdatePageFlipping( i830ContextPtr imesa )
 
502
{
 
503
   GLcontext *ctx = imesa->glCtx;
 
504
   int front = 0;
 
505
 
 
506
   switch (ctx->Color.DriverDrawBuffer) {
 
507
   case GL_FRONT_LEFT:
 
508
      front = 1;
 
509
      break;
 
510
   case GL_BACK_LEFT:
 
511
      front = 0;
 
512
      break;
 
513
   default:
 
514
      return;
 
515
   }
 
516
 
 
517
   if ( imesa->sarea->pf_current_page == 1 ) 
 
518
      front ^= 1;
 
519
   
 
520
   if (front) {
 
521
      imesa->BufferSetup[I830_DESTREG_CBUFADDR] = imesa->i830Screen->fbOffset;
 
522
      imesa->drawMap = (char *)imesa->driScreen->pFB;
 
523
      imesa->readMap = (char *)imesa->driScreen->pFB;
 
524
   } else {
 
525
      imesa->BufferSetup[I830_DESTREG_CBUFADDR] = imesa->i830Screen->backOffset;
 
526
      imesa->drawMap = imesa->i830Screen->back.map;
 
527
      imesa->readMap = imesa->i830Screen->back.map;
 
528
   }
 
529
 
 
530
   imesa->dirty |= I830_UPLOAD_BUFFERS;
 
531
}
 
532
 
 
533
void i830GetLock( i830ContextPtr imesa, GLuint flags )
 
534
{
 
535
   __DRIdrawablePrivate *dPriv = imesa->driDrawable;
 
536
   __DRIscreenPrivate *sPriv = imesa->driScreen;
 
537
   I830SAREAPtr sarea = imesa->sarea;
 
538
   int me = imesa->hHWContext;
 
539
 
 
540
   drmGetLock(imesa->driFd, imesa->hHWContext, flags);
 
541
 
 
542
   /* If the window moved, may need to set a new cliprect now.
 
543
    *
 
544
    * NOTE: This releases and regains the hw lock, so all state
 
545
    * checking must be done *after* this call:
 
546
    */
 
547
   DRI_VALIDATE_DRAWABLE_INFO(imesa->display, sPriv, dPriv);
 
548
 
 
549
   /* If we lost context, need to dump all registers to hardware.
 
550
    * Note that we don't care about 2d contexts, even if they perform
 
551
    * accelerated commands, so the DRI locking in the X server is even
 
552
    * more broken than usual.
 
553
    */
 
554
 
 
555
   if (sarea->ctxOwner != me) {
 
556
      imesa->upload_cliprects = GL_TRUE;
 
557
      imesa->dirty |= (I830_UPLOAD_CTX |
 
558
                       I830_UPLOAD_BUFFERS | 
 
559
                       I830_UPLOAD_STIPPLE);
 
560
 
 
561
      if(imesa->CurrentTexObj[0]) imesa->dirty |= I830_UPLOAD_TEX0;
 
562
      if(imesa->CurrentTexObj[1]) imesa->dirty |= I830_UPLOAD_TEX1;
 
563
      if(imesa->TexBlendWordsUsed[0]) imesa->dirty |= I830_UPLOAD_TEXBLEND0;
 
564
      if(imesa->TexBlendWordsUsed[1]) imesa->dirty |= I830_UPLOAD_TEXBLEND1;
 
565
 
 
566
      sarea->perf_boxes = imesa->perf_boxes | I830_BOX_LOST_CONTEXT;
 
567
      sarea->ctxOwner = me;
 
568
   }
 
569
 
 
570
   /* Shared texture managment - if another client has played with
 
571
    * texture space, figure out which if any of our textures have been
 
572
    * ejected, and update our global LRU.
 
573
    */
 
574
   if (sarea->texAge != imesa->texAge) {
 
575
      int sz = 1 << (imesa->i830Screen->logTextureGranularity);
 
576
      int idx, nr = 0;
 
577
 
 
578
      /* Have to go right round from the back to ensure stuff ends up
 
579
       * LRU in our local list...
 
580
       */
 
581
      for (idx = sarea->texList[I830_NR_TEX_REGIONS].prev ;
 
582
           idx != I830_NR_TEX_REGIONS && nr < I830_NR_TEX_REGIONS ;
 
583
           idx = sarea->texList[idx].prev, nr++) {
 
584
         if (sarea->texList[idx].age > imesa->texAge)
 
585
           i830TexturesGone(imesa, idx * sz, sz, sarea->texList[idx].in_use);
 
586
      }
 
587
 
 
588
      if (nr == I830_NR_TEX_REGIONS) {
 
589
         i830TexturesGone(imesa, 0, imesa->i830Screen->textureSize, 0);
 
590
         i830ResetGlobalLRU( imesa );
 
591
      }
 
592
 
 
593
      imesa->texAge = sarea->texAge;
 
594
   }
 
595
 
 
596
   if (imesa->lastStamp != dPriv->lastStamp) {
 
597
      i830UpdatePageFlipping( imesa );
 
598
      i830XMesaWindowMoved( imesa );
 
599
      imesa->lastStamp = dPriv->lastStamp;
 
600
   }
 
601
 
 
602
   sarea->last_quiescent = -1;  /* just kill it for now */
 
603
}
 
604
 
 
605
void i830SwapBuffers(Display *dpy, void *drawablePrivate)
 
606
{
 
607
   __DRIdrawablePrivate *dPriv = (__DRIdrawablePrivate *) drawablePrivate;
 
608
 
 
609
   if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
 
610
      i830ContextPtr imesa;
 
611
      GLcontext *ctx;
 
612
      imesa = (i830ContextPtr) dPriv->driContextPriv->driverPrivate;
 
613
      ctx = imesa->glCtx;
 
614
      if (ctx->Visual.doubleBufferMode) {
 
615
         /* flush pending rendering comands */
 
616
         _mesa_swapbuffers( ctx );
 
617
         if ( imesa->sarea->pf_active && 
 
618
              (dPriv->w * dPriv->h * imesa->i830Screen->cpp) > (300*300*4) ) {
 
619
            i830PageFlip( dPriv );
 
620
         } else {
 
621
            i830CopyBuffer( dPriv );
 
622
         }
 
623
      }
 
624
   } else {
 
625
      /* XXX this shouldn't be an error but we can't handle it for now */
 
626
      _mesa_problem(NULL, "i830SwapBuffers: drawable has no context!\n");
 
627
   }
 
628
}