~ubuntu-branches/ubuntu/quantal/mesa-glw/quantal

« back to all changes in this revision

Viewing changes to src/mesa/drivers/dri/i915tex/intel_screen.c

  • Committer: Bazaar Package Importer
  • Author(s): Morten Kjeldgaard
  • Date: 2008-05-06 16:19:15 UTC
  • Revision ID: james.westby@ubuntu.com-20080506161915-uynz7nftmfixu6bq
Tags: upstream-7.0.3
ImportĀ upstreamĀ versionĀ 7.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include "glheader.h"
 
29
#include "context.h"
 
30
#include "framebuffer.h"
 
31
#include "matrix.h"
 
32
#include "renderbuffer.h"
 
33
#include "simple_list.h"
 
34
#include "utils.h"
 
35
#include "vblank.h"
 
36
#include "xmlpool.h"
 
37
 
 
38
 
 
39
#include "intel_screen.h"
 
40
 
 
41
#include "intel_buffers.h"
 
42
#include "intel_tex.h"
 
43
#include "intel_span.h"
 
44
#include "intel_tris.h"
 
45
#include "intel_ioctl.h"
 
46
#include "intel_fbo.h"
 
47
 
 
48
#include "i830_dri.h"
 
49
#include "dri_bufpool.h"
 
50
#include "intel_regions.h"
 
51
#include "intel_batchbuffer.h"
 
52
 
 
53
PUBLIC const char __driConfigOptions[] =
 
54
   DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE
 
55
   DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
 
56
   DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
 
57
   DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY
 
58
   DRI_CONF_FORCE_S3TC_ENABLE(false)
 
59
   DRI_CONF_ALLOW_LARGE_TEXTURES(1)
 
60
   DRI_CONF_SECTION_END DRI_CONF_END;
 
61
     const GLuint __driNConfigOptions = 4;
 
62
 
 
63
#ifdef USE_NEW_INTERFACE
 
64
     static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
 
65
#endif /*USE_NEW_INTERFACE */
 
66
 
 
67
     extern const struct dri_extension card_extensions[];
 
68
 
 
69
/**
 
70
 * Map all the memory regions described by the screen.
 
71
 * \return GL_TRUE if success, GL_FALSE if error.
 
72
 */
 
73
GLboolean
 
74
intelMapScreenRegions(__DRIscreenPrivate * sPriv)
 
75
{
 
76
   intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
 
77
 
 
78
   if (intelScreen->front.handle) {
 
79
      if (drmMap(sPriv->fd,
 
80
                 intelScreen->front.handle,
 
81
                 intelScreen->front.size,
 
82
                 (drmAddress *) & intelScreen->front.map) != 0) {
 
83
         _mesa_problem(NULL, "drmMap(frontbuffer) failed!");
 
84
         return GL_FALSE;
 
85
      }
 
86
   }
 
87
   else {
 
88
      _mesa_warning(NULL, "no front buffer handle in intelMapScreenRegions!");
 
89
   }
 
90
 
 
91
   if (0)
 
92
      _mesa_printf("Back 0x%08x ", intelScreen->back.handle);
 
93
   if (drmMap(sPriv->fd,
 
94
              intelScreen->back.handle,
 
95
              intelScreen->back.size,
 
96
              (drmAddress *) & intelScreen->back.map) != 0) {
 
97
      intelUnmapScreenRegions(intelScreen);
 
98
      return GL_FALSE;
 
99
   }
 
100
 
 
101
   if (intelScreen->third.handle) {
 
102
      if (0)
 
103
         _mesa_printf("Third 0x%08x ", intelScreen->third.handle);
 
104
      if (drmMap(sPriv->fd,
 
105
                 intelScreen->third.handle,
 
106
                 intelScreen->third.size,
 
107
                 (drmAddress *) & intelScreen->third.map) != 0) {
 
108
         intelUnmapScreenRegions(intelScreen);
 
109
         return GL_FALSE;
 
110
      }
 
111
   }
 
112
 
 
113
   if (0)
 
114
      _mesa_printf("Depth 0x%08x ", intelScreen->depth.handle);
 
115
   if (drmMap(sPriv->fd,
 
116
              intelScreen->depth.handle,
 
117
              intelScreen->depth.size,
 
118
              (drmAddress *) & intelScreen->depth.map) != 0) {
 
119
      intelUnmapScreenRegions(intelScreen);
 
120
      return GL_FALSE;
 
121
   }
 
122
 
 
123
#if 0
 
124
   _mesa_printf("TEX 0x%08x ", intelScreen->tex.handle);
 
125
   if (drmMap(sPriv->fd,
 
126
              intelScreen->tex.handle,
 
127
              intelScreen->tex.size,
 
128
              (drmAddress *) & intelScreen->tex.map) != 0) {
 
129
      intelUnmapScreenRegions(intelScreen);
 
130
      return GL_FALSE;
 
131
   }
 
132
#endif
 
133
   if (0)
 
134
      printf("Mappings:  front: %p  back: %p  third: %p  depth: %p  tex: %p\n",
 
135
             intelScreen->front.map,
 
136
             intelScreen->back.map, intelScreen->third.map,
 
137
             intelScreen->depth.map, intelScreen->tex.map);
 
138
   return GL_TRUE;
 
139
}
 
140
 
 
141
 
 
142
static struct intel_region *
 
143
intel_recreate_static(intelScreenPrivate *intelScreen,
 
144
                      struct intel_region *region,
 
145
                      GLuint mem_type,
 
146
                      GLuint offset,
 
147
                      void *virtual,
 
148
                      GLuint cpp, GLuint pitch, GLuint height)
 
149
{
 
150
  if (region) {
 
151
    intel_region_update_static(intelScreen, region, mem_type, offset,
 
152
                               virtual, cpp, pitch, height);
 
153
  } else {
 
154
    region = intel_region_create_static(intelScreen, mem_type, offset,
 
155
                                        virtual, cpp, pitch, height);
 
156
  }
 
157
  return region;
 
158
}
 
159
    
 
160
 
 
161
/* Create intel_region structs to describe the static front,back,depth
 
162
 * buffers created by the xserver. 
 
163
 *
 
164
 * Although FBO's mean we now no longer use these as render targets in
 
165
 * all circumstances, they won't go away until the back and depth
 
166
 * buffers become private, and the front and rotated buffers will
 
167
 * remain even then.
 
168
 *
 
169
 * Note that these don't allocate video memory, just describe
 
170
 * allocations alread made by the X server.
 
171
 */
 
172
static void
 
173
intel_recreate_static_regions(intelScreenPrivate *intelScreen)
 
174
{
 
175
   intelScreen->front_region =
 
176
      intel_recreate_static(intelScreen,
 
177
                            intelScreen->front_region,
 
178
                            DRM_BO_FLAG_MEM_TT,
 
179
                            intelScreen->front.offset,
 
180
                            intelScreen->front.map,
 
181
                            intelScreen->cpp,
 
182
                            intelScreen->front.pitch / intelScreen->cpp,
 
183
                            intelScreen->height);
 
184
 
 
185
   intelScreen->rotated_region =
 
186
      intel_recreate_static(intelScreen,
 
187
                            intelScreen->rotated_region,
 
188
                            DRM_BO_FLAG_MEM_TT,
 
189
                            intelScreen->rotated.offset,
 
190
                            intelScreen->rotated.map,
 
191
                            intelScreen->cpp,
 
192
                            intelScreen->rotated.pitch /
 
193
                            intelScreen->cpp, intelScreen->height);
 
194
 
 
195
 
 
196
   intelScreen->back_region =
 
197
      intel_recreate_static(intelScreen,
 
198
                            intelScreen->back_region,
 
199
                            DRM_BO_FLAG_MEM_TT,
 
200
                            intelScreen->back.offset,
 
201
                            intelScreen->back.map,
 
202
                            intelScreen->cpp,
 
203
                            intelScreen->back.pitch / intelScreen->cpp,
 
204
                            intelScreen->height);
 
205
 
 
206
   if (intelScreen->third.handle) {
 
207
      intelScreen->third_region =
 
208
         intel_recreate_static(intelScreen,
 
209
                               intelScreen->third_region,
 
210
                               DRM_BO_FLAG_MEM_TT,
 
211
                               intelScreen->third.offset,
 
212
                               intelScreen->third.map,
 
213
                               intelScreen->cpp,
 
214
                               intelScreen->third.pitch / intelScreen->cpp,
 
215
                               intelScreen->height);
 
216
   }
 
217
 
 
218
   /* Still assuming front.cpp == depth.cpp
 
219
    */
 
220
   intelScreen->depth_region =
 
221
      intel_recreate_static(intelScreen,
 
222
                            intelScreen->depth_region,
 
223
                            DRM_BO_FLAG_MEM_TT,
 
224
                            intelScreen->depth.offset,
 
225
                            intelScreen->depth.map,
 
226
                            intelScreen->cpp,
 
227
                            intelScreen->depth.pitch / intelScreen->cpp,
 
228
                            intelScreen->height);
 
229
}
 
230
 
 
231
/**
 
232
 * Use the information in the sarea to update the screen parameters
 
233
 * related to screen rotation. Needs to be called locked.
 
234
 */
 
235
void
 
236
intelUpdateScreenRotation(__DRIscreenPrivate * sPriv, drmI830Sarea * sarea)
 
237
{
 
238
   intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
 
239
 
 
240
   intelUnmapScreenRegions(intelScreen);
 
241
   intelUpdateScreenFromSAREA(intelScreen, sarea);
 
242
   if (!intelMapScreenRegions(sPriv)) {
 
243
      fprintf(stderr, "ERROR Remapping screen regions!!!\n");
 
244
   }
 
245
   intel_recreate_static_regions(intelScreen);
 
246
}
 
247
 
 
248
 
 
249
void
 
250
intelUnmapScreenRegions(intelScreenPrivate * intelScreen)
 
251
{
 
252
#define REALLY_UNMAP 1
 
253
   if (intelScreen->front.map) {
 
254
#if REALLY_UNMAP
 
255
      if (drmUnmap(intelScreen->front.map, intelScreen->front.size) != 0)
 
256
         printf("drmUnmap front failed!\n");
 
257
#endif
 
258
      intelScreen->front.map = NULL;
 
259
   }
 
260
   if (intelScreen->back.map) {
 
261
#if REALLY_UNMAP
 
262
      if (drmUnmap(intelScreen->back.map, intelScreen->back.size) != 0)
 
263
         printf("drmUnmap back failed!\n");
 
264
#endif
 
265
      intelScreen->back.map = NULL;
 
266
   }
 
267
   if (intelScreen->third.map) {
 
268
#if REALLY_UNMAP
 
269
      if (drmUnmap(intelScreen->third.map, intelScreen->third.size) != 0)
 
270
         printf("drmUnmap third failed!\n");
 
271
#endif
 
272
      intelScreen->third.map = NULL;
 
273
   }
 
274
   if (intelScreen->depth.map) {
 
275
#if REALLY_UNMAP
 
276
      drmUnmap(intelScreen->depth.map, intelScreen->depth.size);
 
277
      intelScreen->depth.map = NULL;
 
278
#endif
 
279
   }
 
280
   if (intelScreen->tex.map) {
 
281
#if REALLY_UNMAP
 
282
      drmUnmap(intelScreen->tex.map, intelScreen->tex.size);
 
283
      intelScreen->tex.map = NULL;
 
284
#endif
 
285
   }
 
286
}
 
287
 
 
288
 
 
289
static void
 
290
intelPrintDRIInfo(intelScreenPrivate * intelScreen,
 
291
                  __DRIscreenPrivate * sPriv, I830DRIPtr gDRIPriv)
 
292
{
 
293
   fprintf(stderr, "*** Front size:   0x%x  offset: 0x%x  pitch: %d\n",
 
294
           intelScreen->front.size, intelScreen->front.offset,
 
295
           intelScreen->front.pitch);
 
296
   fprintf(stderr, "*** Back size:    0x%x  offset: 0x%x  pitch: %d\n",
 
297
           intelScreen->back.size, intelScreen->back.offset,
 
298
           intelScreen->back.pitch);
 
299
   fprintf(stderr, "*** Depth size:   0x%x  offset: 0x%x  pitch: %d\n",
 
300
           intelScreen->depth.size, intelScreen->depth.offset,
 
301
           intelScreen->depth.pitch);
 
302
   fprintf(stderr, "*** Rotated size: 0x%x  offset: 0x%x  pitch: %d\n",
 
303
           intelScreen->rotated.size, intelScreen->rotated.offset,
 
304
           intelScreen->rotated.pitch);
 
305
   fprintf(stderr, "*** Texture size: 0x%x  offset: 0x%x\n",
 
306
           intelScreen->tex.size, intelScreen->tex.offset);
 
307
   fprintf(stderr, "*** Memory : 0x%x\n", gDRIPriv->mem);
 
308
}
 
309
 
 
310
 
 
311
static void
 
312
intelPrintSAREA(const drmI830Sarea * sarea)
 
313
{
 
314
   fprintf(stderr, "SAREA: sarea width %d  height %d\n", sarea->width,
 
315
           sarea->height);
 
316
   fprintf(stderr, "SAREA: pitch: %d\n", sarea->pitch);
 
317
   fprintf(stderr,
 
318
           "SAREA: front offset: 0x%08x  size: 0x%x  handle: 0x%x\n",
 
319
           sarea->front_offset, sarea->front_size,
 
320
           (unsigned) sarea->front_handle);
 
321
   fprintf(stderr,
 
322
           "SAREA: back  offset: 0x%08x  size: 0x%x  handle: 0x%x\n",
 
323
           sarea->back_offset, sarea->back_size,
 
324
           (unsigned) sarea->back_handle);
 
325
   fprintf(stderr, "SAREA: depth offset: 0x%08x  size: 0x%x  handle: 0x%x\n",
 
326
           sarea->depth_offset, sarea->depth_size,
 
327
           (unsigned) sarea->depth_handle);
 
328
   fprintf(stderr, "SAREA: tex   offset: 0x%08x  size: 0x%x  handle: 0x%x\n",
 
329
           sarea->tex_offset, sarea->tex_size, (unsigned) sarea->tex_handle);
 
330
   fprintf(stderr, "SAREA: rotation: %d\n", sarea->rotation);
 
331
   fprintf(stderr,
 
332
           "SAREA: rotated offset: 0x%08x  size: 0x%x\n",
 
333
           sarea->rotated_offset, sarea->rotated_size);
 
334
   fprintf(stderr, "SAREA: rotated pitch: %d\n", sarea->rotated_pitch);
 
335
}
 
336
 
 
337
 
 
338
/**
 
339
 * A number of the screen parameters are obtained/computed from
 
340
 * information in the SAREA.  This function updates those parameters.
 
341
 */
 
342
void
 
343
intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen,
 
344
                           drmI830Sarea * sarea)
 
345
{
 
346
   intelScreen->width = sarea->width;
 
347
   intelScreen->height = sarea->height;
 
348
 
 
349
   intelScreen->front.offset = sarea->front_offset;
 
350
   intelScreen->front.pitch = sarea->pitch * intelScreen->cpp;
 
351
   intelScreen->front.handle = sarea->front_handle;
 
352
   intelScreen->front.size = sarea->front_size;
 
353
 
 
354
   intelScreen->back.offset = sarea->back_offset;
 
355
   intelScreen->back.pitch = sarea->pitch * intelScreen->cpp;
 
356
   intelScreen->back.handle = sarea->back_handle;
 
357
   intelScreen->back.size = sarea->back_size;
 
358
 
 
359
   if (intelScreen->driScrnPriv->ddxMinor >= 8) {
 
360
      intelScreen->third.offset = sarea->third_offset;
 
361
      intelScreen->third.pitch = sarea->pitch * intelScreen->cpp;
 
362
      intelScreen->third.handle = sarea->third_handle;
 
363
      intelScreen->third.size = sarea->third_size;
 
364
   }
 
365
 
 
366
   intelScreen->depth.offset = sarea->depth_offset;
 
367
   intelScreen->depth.pitch = sarea->pitch * intelScreen->cpp;
 
368
   intelScreen->depth.handle = sarea->depth_handle;
 
369
   intelScreen->depth.size = sarea->depth_size;
 
370
 
 
371
   intelScreen->tex.offset = sarea->tex_offset;
 
372
   intelScreen->logTextureGranularity = sarea->log_tex_granularity;
 
373
   intelScreen->tex.handle = sarea->tex_handle;
 
374
   intelScreen->tex.size = sarea->tex_size;
 
375
 
 
376
   intelScreen->rotated.offset = sarea->rotated_offset;
 
377
   intelScreen->rotated.pitch = sarea->rotated_pitch * intelScreen->cpp;
 
378
   intelScreen->rotated.size = sarea->rotated_size;
 
379
   intelScreen->current_rotation = sarea->rotation;
 
380
   matrix23Rotate(&intelScreen->rotMatrix,
 
381
                  sarea->width, sarea->height, sarea->rotation);
 
382
   intelScreen->rotatedWidth = sarea->virtualX;
 
383
   intelScreen->rotatedHeight = sarea->virtualY;
 
384
 
 
385
   if (0)
 
386
      intelPrintSAREA(sarea);
 
387
}
 
388
 
 
389
GLboolean
 
390
intelCreatePools(intelScreenPrivate *intelScreen)
 
391
{
 
392
   unsigned batchPoolSize = 1024*1024;
 
393
   __DRIscreenPrivate * sPriv = intelScreen->driScrnPriv;
 
394
 
 
395
   if (intelScreen->havePools)
 
396
      return GL_TRUE;
 
397
 
 
398
   batchPoolSize /= intelScreen->maxBatchSize;
 
399
   intelScreen->regionPool = driDRMPoolInit(sPriv->fd);
 
400
 
 
401
   if (!intelScreen->regionPool)
 
402
      return GL_FALSE;
 
403
 
 
404
   intelScreen->staticPool = driDRMStaticPoolInit(sPriv->fd);
 
405
 
 
406
   if (!intelScreen->staticPool)
 
407
      return GL_FALSE;
 
408
 
 
409
   intelScreen->texPool = intelScreen->regionPool;
 
410
 
 
411
   intelScreen->batchPool = driBatchPoolInit(sPriv->fd,
 
412
                                             DRM_BO_FLAG_EXE |
 
413
                                             DRM_BO_FLAG_MEM_TT |
 
414
                                             DRM_BO_FLAG_MEM_LOCAL,
 
415
                                             intelScreen->maxBatchSize, 
 
416
                                             batchPoolSize, 5);
 
417
   if (!intelScreen->batchPool) {
 
418
      fprintf(stderr, "Failed to initialize batch pool - possible incorrect agpgart installed\n");
 
419
      return GL_FALSE;
 
420
   }
 
421
   
 
422
   intel_recreate_static_regions(intelScreen);
 
423
   intelScreen->havePools = GL_TRUE;
 
424
 
 
425
   return GL_TRUE;
 
426
}
 
427
 
 
428
 
 
429
static GLboolean
 
430
intelInitDriver(__DRIscreenPrivate * sPriv)
 
431
{
 
432
   intelScreenPrivate *intelScreen;
 
433
   I830DRIPtr gDRIPriv = (I830DRIPtr) sPriv->pDevPriv;
 
434
   drmI830Sarea *sarea;
 
435
 
 
436
   PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension =
 
437
      (PFNGLXSCRENABLEEXTENSIONPROC) (*dri_interface->
 
438
                                      getProcAddress("glxEnableExtension"));
 
439
   void *const psc = sPriv->psc->screenConfigs;
 
440
 
 
441
   if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
 
442
      fprintf(stderr,
 
443
              "\nERROR!  sizeof(I830DRIRec) does not match passed size from device driver\n");
 
444
      return GL_FALSE;
 
445
   }
 
446
 
 
447
   /* Allocate the private area */
 
448
   intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
 
449
   if (!intelScreen) {
 
450
      fprintf(stderr, "\nERROR!  Allocating private area failed\n");
 
451
      return GL_FALSE;
 
452
   }
 
453
   /* parse information in __driConfigOptions */
 
454
   driParseOptionInfo(&intelScreen->optionCache,
 
455
                      __driConfigOptions, __driNConfigOptions);
 
456
 
 
457
   intelScreen->driScrnPriv = sPriv;
 
458
   sPriv->private = (void *) intelScreen;
 
459
   intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
 
460
   sarea = (drmI830Sarea *)
 
461
      (((GLubyte *) sPriv->pSAREA) + intelScreen->sarea_priv_offset);
 
462
 
 
463
   intelScreen->maxBatchSize = BATCH_SZ;
 
464
   intelScreen->deviceID = gDRIPriv->deviceID;
 
465
   if (intelScreen->deviceID == PCI_CHIP_I865_G)
 
466
      intelScreen->maxBatchSize = 4096;
 
467
 
 
468
   intelScreen->mem = gDRIPriv->mem;
 
469
   intelScreen->cpp = gDRIPriv->cpp;
 
470
 
 
471
   switch (gDRIPriv->bitsPerPixel) {
 
472
   case 16:
 
473
      intelScreen->fbFormat = DV_PF_565;
 
474
      break;
 
475
   case 32:
 
476
      intelScreen->fbFormat = DV_PF_8888;
 
477
      break;
 
478
   default:
 
479
      exit(1);
 
480
      break;
 
481
   }
 
482
 
 
483
   intelUpdateScreenFromSAREA(intelScreen, sarea);
 
484
 
 
485
   if (!intelMapScreenRegions(sPriv)) {
 
486
      fprintf(stderr, "\nERROR!  mapping regions\n");
 
487
      _mesa_free(intelScreen);
 
488
      sPriv->private = NULL;
 
489
      return GL_FALSE;
 
490
   }
 
491
 
 
492
#if 0
 
493
 
 
494
   /*
 
495
    * FIXME: Remove this code and its references.
 
496
    */
 
497
 
 
498
   intelScreen->tex.offset = gDRIPriv->textureOffset;
 
499
   intelScreen->logTextureGranularity = gDRIPriv->logTextureGranularity;
 
500
   intelScreen->tex.handle = gDRIPriv->textures;
 
501
   intelScreen->tex.size = gDRIPriv->textureSize;
 
502
 
 
503
#else
 
504
   intelScreen->tex.offset = 0;
 
505
   intelScreen->logTextureGranularity = 0;
 
506
   intelScreen->tex.handle = 0;
 
507
   intelScreen->tex.size = 0;
 
508
#endif
 
509
 
 
510
   intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
 
511
 
 
512
   if (0)
 
513
      intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv);
 
514
 
 
515
   intelScreen->drmMinor = sPriv->drmMinor;
 
516
 
 
517
   /* Determine if IRQs are active? */
 
518
   {
 
519
      int ret;
 
520
      drmI830GetParam gp;
 
521
 
 
522
      gp.param = I830_PARAM_IRQ_ACTIVE;
 
523
      gp.value = &intelScreen->irq_active;
 
524
 
 
525
      ret = drmCommandWriteRead(sPriv->fd, DRM_I830_GETPARAM,
 
526
                                &gp, sizeof(gp));
 
527
      if (ret) {
 
528
         fprintf(stderr, "drmI830GetParam: %d\n", ret);
 
529
         return GL_FALSE;
 
530
      }
 
531
   }
 
532
 
 
533
   /* Determine if batchbuffers are allowed */
 
534
   {
 
535
      int ret;
 
536
      drmI830GetParam gp;
 
537
 
 
538
      gp.param = I830_PARAM_ALLOW_BATCHBUFFER;
 
539
      gp.value = &intelScreen->allow_batchbuffer;
 
540
 
 
541
      ret = drmCommandWriteRead(sPriv->fd, DRM_I830_GETPARAM,
 
542
                                &gp, sizeof(gp));
 
543
      if (ret) {
 
544
         fprintf(stderr, "drmI830GetParam: (%d) %d\n", gp.param, ret);
 
545
         return GL_FALSE;
 
546
      }
 
547
   }
 
548
 
 
549
   if (glx_enable_extension != NULL) {
 
550
      (*glx_enable_extension) (psc, "GLX_SGI_swap_control");
 
551
      (*glx_enable_extension) (psc, "GLX_SGI_video_sync");
 
552
      (*glx_enable_extension) (psc, "GLX_MESA_swap_control");
 
553
      (*glx_enable_extension) (psc, "GLX_MESA_swap_frame_usage");
 
554
      (*glx_enable_extension) (psc, "GLX_SGI_make_current_read");
 
555
   }
 
556
 
 
557
   return GL_TRUE;
 
558
}
 
559
 
 
560
 
 
561
static void
 
562
intelDestroyScreen(__DRIscreenPrivate * sPriv)
 
563
{
 
564
   intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
 
565
 
 
566
   intelUnmapScreenRegions(intelScreen);
 
567
 
 
568
   if (intelScreen->havePools) {
 
569
      driPoolTakeDown(intelScreen->regionPool);
 
570
      driPoolTakeDown(intelScreen->staticPool);
 
571
      driPoolTakeDown(intelScreen->batchPool);
 
572
   }
 
573
   FREE(intelScreen);
 
574
   sPriv->private = NULL;
 
575
}
 
576
 
 
577
 
 
578
/**
 
579
 * This is called when we need to set up GL rendering to a new X window.
 
580
 */
 
581
static GLboolean
 
582
intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
 
583
                  __DRIdrawablePrivate * driDrawPriv,
 
584
                  const __GLcontextModes * mesaVis, GLboolean isPixmap)
 
585
{
 
586
   intelScreenPrivate *screen = (intelScreenPrivate *) driScrnPriv->private;
 
587
 
 
588
   if (isPixmap) {
 
589
      return GL_FALSE;          /* not implemented */
 
590
   }
 
591
   else {
 
592
      GLboolean swStencil = (mesaVis->stencilBits > 0 &&
 
593
                             mesaVis->depthBits != 24);
 
594
      GLenum rgbFormat = (mesaVis->redBits == 5 ? GL_RGB5 : GL_RGBA8);
 
595
 
 
596
      struct intel_framebuffer *intel_fb = CALLOC_STRUCT(intel_framebuffer);
 
597
 
 
598
      if (!intel_fb)
 
599
         return GL_FALSE;
 
600
 
 
601
      _mesa_initialize_framebuffer(&intel_fb->Base, mesaVis);
 
602
 
 
603
      /* setup the hardware-based renderbuffers */
 
604
      {
 
605
         intel_fb->color_rb[0]
 
606
            = intel_create_renderbuffer(rgbFormat,
 
607
                                        screen->width, screen->height,
 
608
                                        screen->front.offset,
 
609
                                        screen->front.pitch,
 
610
                                        screen->cpp,
 
611
                                        screen->front.map);
 
612
         intel_set_span_functions(&intel_fb->color_rb[0]->Base);
 
613
         _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_FRONT_LEFT,
 
614
                                &intel_fb->color_rb[0]->Base);
 
615
      }
 
616
 
 
617
      if (mesaVis->doubleBufferMode) {
 
618
         intel_fb->color_rb[1]
 
619
            = intel_create_renderbuffer(rgbFormat,
 
620
                                        screen->width, screen->height,
 
621
                                        screen->back.offset,
 
622
                                        screen->back.pitch,
 
623
                                        screen->cpp,
 
624
                                        screen->back.map);
 
625
         intel_set_span_functions(&intel_fb->color_rb[1]->Base);
 
626
         _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT,
 
627
                                &intel_fb->color_rb[1]->Base);
 
628
 
 
629
         if (screen->third.handle) {
 
630
            struct gl_renderbuffer *tmp_rb = NULL;
 
631
 
 
632
            intel_fb->color_rb[2]
 
633
               = intel_create_renderbuffer(rgbFormat,
 
634
                                           screen->width, screen->height,
 
635
                                           screen->third.offset,
 
636
                                           screen->third.pitch,
 
637
                                           screen->cpp,
 
638
                                           screen->third.map);
 
639
            intel_set_span_functions(&intel_fb->color_rb[2]->Base);
 
640
            _mesa_reference_renderbuffer(&tmp_rb, &intel_fb->color_rb[2]->Base);
 
641
         }
 
642
      }
 
643
 
 
644
      if (mesaVis->depthBits == 24 && mesaVis->stencilBits == 8) {
 
645
         /* combined depth/stencil buffer */
 
646
         struct intel_renderbuffer *depthStencilRb
 
647
            = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT,
 
648
                                        screen->width, screen->height,
 
649
                                        screen->depth.offset,
 
650
                                        screen->depth.pitch,
 
651
                                        screen->cpp,    /* 4! */
 
652
                                        screen->depth.map);
 
653
         intel_set_span_functions(&depthStencilRb->Base);
 
654
         /* note: bind RB to two attachment points */
 
655
         _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
 
656
                                &depthStencilRb->Base);
 
657
         _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_STENCIL,
 
658
                                &depthStencilRb->Base);
 
659
      }
 
660
      else if (mesaVis->depthBits == 16) {
 
661
         /* just 16-bit depth buffer, no hw stencil */
 
662
         struct intel_renderbuffer *depthRb
 
663
            = intel_create_renderbuffer(GL_DEPTH_COMPONENT16,
 
664
                                        screen->width, screen->height,
 
665
                                        screen->depth.offset,
 
666
                                        screen->depth.pitch,
 
667
                                        screen->cpp,    /* 2! */
 
668
                                        screen->depth.map);
 
669
         intel_set_span_functions(&depthRb->Base);
 
670
         _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, &depthRb->Base);
 
671
      }
 
672
 
 
673
      /* now add any/all software-based renderbuffers we may need */
 
674
      _mesa_add_soft_renderbuffers(&intel_fb->Base,
 
675
                                   GL_FALSE, /* never sw color */
 
676
                                   GL_FALSE, /* never sw depth */
 
677
                                   swStencil, mesaVis->accumRedBits > 0,
 
678
                                   GL_FALSE, /* never sw alpha */
 
679
                                   GL_FALSE  /* never sw aux */ );
 
680
      driDrawPriv->driverPrivate = (void *) intel_fb;
 
681
 
 
682
      return GL_TRUE;
 
683
   }
 
684
}
 
685
 
 
686
static void
 
687
intelDestroyBuffer(__DRIdrawablePrivate * driDrawPriv)
 
688
{
 
689
   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 
690
}
 
691
 
 
692
 
 
693
/**
 
694
 * Get information about previous buffer swaps.
 
695
 */
 
696
static int
 
697
intelGetSwapInfo(__DRIdrawablePrivate * dPriv, __DRIswapInfo * sInfo)
 
698
{
 
699
   struct intel_framebuffer *intel_fb;
 
700
 
 
701
   if ((dPriv == NULL) || (dPriv->driverPrivate == NULL)
 
702
       || (sInfo == NULL)) {
 
703
      return -1;
 
704
   }
 
705
 
 
706
   intel_fb = dPriv->driverPrivate;
 
707
   sInfo->swap_count = intel_fb->swap_count;
 
708
   sInfo->swap_ust = intel_fb->swap_ust;
 
709
   sInfo->swap_missed_count = intel_fb->swap_missed_count;
 
710
 
 
711
   sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
 
712
      ? driCalculateSwapUsage(dPriv, 0, intel_fb->swap_missed_ust)
 
713
      : 0.0;
 
714
 
 
715
   return 0;
 
716
}
 
717
 
 
718
 
 
719
/* There are probably better ways to do this, such as an
 
720
 * init-designated function to register chipids and createcontext
 
721
 * functions.
 
722
 */
 
723
extern GLboolean i830CreateContext(const __GLcontextModes * mesaVis,
 
724
                                   __DRIcontextPrivate * driContextPriv,
 
725
                                   void *sharedContextPrivate);
 
726
 
 
727
extern GLboolean i915CreateContext(const __GLcontextModes * mesaVis,
 
728
                                   __DRIcontextPrivate * driContextPriv,
 
729
                                   void *sharedContextPrivate);
 
730
 
 
731
 
 
732
 
 
733
 
 
734
static GLboolean
 
735
intelCreateContext(const __GLcontextModes * mesaVis,
 
736
                   __DRIcontextPrivate * driContextPriv,
 
737
                   void *sharedContextPrivate)
 
738
{
 
739
   __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
 
740
   intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
 
741
 
 
742
   switch (intelScreen->deviceID) {
 
743
      /* Don't deal with i830 until texture work complete:
 
744
       */
 
745
   case PCI_CHIP_845_G:
 
746
   case PCI_CHIP_I830_M:
 
747
   case PCI_CHIP_I855_GM:
 
748
   case PCI_CHIP_I865_G:
 
749
      return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
 
750
 
 
751
   case PCI_CHIP_I915_G:
 
752
   case PCI_CHIP_I915_GM:
 
753
   case PCI_CHIP_I945_G:
 
754
   case PCI_CHIP_I945_GM:
 
755
   case PCI_CHIP_I945_GME:
 
756
   case PCI_CHIP_G33_G:
 
757
   case PCI_CHIP_Q35_G:
 
758
   case PCI_CHIP_Q33_G:
 
759
      return i915CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
 
760
 
 
761
   default:
 
762
      fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID);
 
763
      return GL_FALSE;
 
764
   }
 
765
}
 
766
 
 
767
 
 
768
static const struct __DriverAPIRec intelAPI = {
 
769
   .InitDriver = intelInitDriver,
 
770
   .DestroyScreen = intelDestroyScreen,
 
771
   .CreateContext = intelCreateContext,
 
772
   .DestroyContext = intelDestroyContext,
 
773
   .CreateBuffer = intelCreateBuffer,
 
774
   .DestroyBuffer = intelDestroyBuffer,
 
775
   .SwapBuffers = intelSwapBuffers,
 
776
   .MakeCurrent = intelMakeCurrent,
 
777
   .UnbindContext = intelUnbindContext,
 
778
   .GetSwapInfo = intelGetSwapInfo,
 
779
   .GetMSC = driGetMSC32,
 
780
   .WaitForMSC = driWaitForMSC32,
 
781
   .WaitForSBC = NULL,
 
782
   .SwapBuffersMSC = NULL,
 
783
   .CopySubBuffer = intelCopySubBuffer,
 
784
   .setTexOffset = intelSetTexOffset,
 
785
};
 
786
 
 
787
 
 
788
static __GLcontextModes *
 
789
intelFillInModes(unsigned pixel_bits, unsigned depth_bits,
 
790
                 unsigned stencil_bits, GLboolean have_back_buffer)
 
791
{
 
792
   __GLcontextModes *modes;
 
793
   __GLcontextModes *m;
 
794
   unsigned num_modes;
 
795
   unsigned depth_buffer_factor;
 
796
   unsigned back_buffer_factor;
 
797
   GLenum fb_format;
 
798
   GLenum fb_type;
 
799
 
 
800
   /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
 
801
    * support pageflipping at all.
 
802
    */
 
803
   static const GLenum back_buffer_modes[] = {
 
804
      GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
 
805
   };
 
806
 
 
807
   u_int8_t depth_bits_array[3];
 
808
   u_int8_t stencil_bits_array[3];
 
809
 
 
810
 
 
811
   depth_bits_array[0] = 0;
 
812
   depth_bits_array[1] = depth_bits;
 
813
   depth_bits_array[2] = depth_bits;
 
814
 
 
815
   /* Just like with the accumulation buffer, always provide some modes
 
816
    * with a stencil buffer.  It will be a sw fallback, but some apps won't
 
817
    * care about that.
 
818
    */
 
819
   stencil_bits_array[0] = 0;
 
820
   stencil_bits_array[1] = 0;
 
821
   if (depth_bits == 24)
 
822
      stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
 
823
 
 
824
   stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;
 
825
 
 
826
   depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
 
827
   back_buffer_factor = (have_back_buffer) ? 3 : 1;
 
828
 
 
829
   num_modes = depth_buffer_factor * back_buffer_factor * 4;
 
830
 
 
831
   if (pixel_bits == 16) {
 
832
      fb_format = GL_RGB;
 
833
      fb_type = GL_UNSIGNED_SHORT_5_6_5;
 
834
   }
 
835
   else {
 
836
      fb_format = GL_BGRA;
 
837
      fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
 
838
   }
 
839
 
 
840
   modes =
 
841
      (*dri_interface->createContextModes) (num_modes,
 
842
                                            sizeof(__GLcontextModes));
 
843
   m = modes;
 
844
   if (!driFillInModes(&m, fb_format, fb_type,
 
845
                       depth_bits_array, stencil_bits_array,
 
846
                       depth_buffer_factor, back_buffer_modes,
 
847
                       back_buffer_factor, GLX_TRUE_COLOR)) {
 
848
      fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
 
849
              __LINE__);
 
850
      return NULL;
 
851
   }
 
852
   if (!driFillInModes(&m, fb_format, fb_type,
 
853
                       depth_bits_array, stencil_bits_array,
 
854
                       depth_buffer_factor, back_buffer_modes,
 
855
                       back_buffer_factor, GLX_DIRECT_COLOR)) {
 
856
      fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
 
857
              __LINE__);
 
858
      return NULL;
 
859
   }
 
860
 
 
861
   /* Mark the visual as slow if there are "fake" stencil bits.
 
862
    */
 
863
   for (m = modes; m != NULL; m = m->next) {
 
864
      if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
 
865
         m->visualRating = GLX_SLOW_CONFIG;
 
866
      }
 
867
   }
 
868
 
 
869
   return modes;
 
870
}
 
871
 
 
872
 
 
873
/**
 
874
 * This is the bootstrap function for the driver.  libGL supplies all of the
 
875
 * requisite information about the system, and the driver initializes itself.
 
876
 * This routine also fills in the linked list pointed to by \c driver_modes
 
877
 * with the \c __GLcontextModes that the driver can support for windows or
 
878
 * pbuffers.
 
879
 * 
 
880
 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on 
 
881
 *         failure.
 
882
 */
 
883
PUBLIC void *
 
884
__driCreateNewScreen_20050727(__DRInativeDisplay * dpy, int scrn,
 
885
                              __DRIscreen * psc,
 
886
                              const __GLcontextModes * modes,
 
887
                              const __DRIversion * ddx_version,
 
888
                              const __DRIversion * dri_version,
 
889
                              const __DRIversion * drm_version,
 
890
                              const __DRIframebuffer * frame_buffer,
 
891
                              drmAddress pSAREA, int fd,
 
892
                              int internal_api_version,
 
893
                              const __DRIinterfaceMethods * interface,
 
894
                              __GLcontextModes ** driver_modes)
 
895
{
 
896
   __DRIscreenPrivate *psp;
 
897
   static const __DRIversion ddx_expected = { 1, 5, 0 };
 
898
   static const __DRIversion dri_expected = { 4, 0, 0 };
 
899
   static const __DRIversion drm_expected = { 1, 7, 0 };
 
900
 
 
901
   dri_interface = interface;
 
902
 
 
903
   if (!driCheckDriDdxDrmVersions2("i915",
 
904
                                   dri_version, &dri_expected,
 
905
                                   ddx_version, &ddx_expected,
 
906
                                   drm_version, &drm_expected)) {
 
907
      return NULL;
 
908
   }
 
909
 
 
910
   psp = __driUtilCreateNewScreen(dpy, scrn, psc, NULL,
 
911
                                  ddx_version, dri_version, drm_version,
 
912
                                  frame_buffer, pSAREA, fd,
 
913
                                  internal_api_version, &intelAPI);
 
914
 
 
915
   if (psp != NULL) {
 
916
      I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
 
917
      *driver_modes = intelFillInModes(dri_priv->cpp * 8,
 
918
                                       (dri_priv->cpp == 2) ? 16 : 24,
 
919
                                       (dri_priv->cpp == 2) ? 0 : 8, 1);
 
920
 
 
921
      /* Calling driInitExtensions here, with a NULL context pointer, does not actually
 
922
       * enable the extensions.  It just makes sure that all the dispatch offsets for all
 
923
       * the extensions that *might* be enables are known.  This is needed because the
 
924
       * dispatch offsets need to be known when _mesa_context_create is called, but we can't
 
925
       * enable the extensions until we have a context pointer.
 
926
       *
 
927
       * Hello chicken.  Hello egg.  How are you two today?
 
928
       */
 
929
      driInitExtensions(NULL, card_extensions, GL_FALSE);
 
930
   }
 
931
 
 
932
   return (void *) psp;
 
933
}
 
934
 
 
935
struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen)
 
936
{
 
937
  /*
 
938
   * This should probably change to have the screen allocate a dummy
 
939
   * context at screen creation. For now just use the current context.
 
940
   */
 
941
 
 
942
  GET_CURRENT_CONTEXT(ctx);
 
943
  if (ctx == NULL) {
 
944
     _mesa_problem(NULL, "No current context in intelScreenContext\n");
 
945
     return NULL;
 
946
  }
 
947
  return intel_context(ctx);
 
948
}
 
949