~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xgl/xglscreen.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright Ā© 2004 David Reveman
 
3
 *
 
4
 * Permission to use, copy, modify, distribute, and sell this software
 
5
 * and its documentation for any purpose is hereby granted without
 
6
 * fee, provided that the above copyright notice appear in all copies
 
7
 * and that both that copyright notice and this permission notice
 
8
 * appear in supporting documentation, and that the name of
 
9
 * David Reveman not be used in advertising or publicity pertaining to
 
10
 * distribution of the software without specific, written prior permission.
 
11
 * David Reveman makes no representations about the suitability of this
 
12
 * software for any purpose. It is provided "as is" without express or
 
13
 * implied warranty.
 
14
 *
 
15
 * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
16
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 
17
 * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
18
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 
19
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
20
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 
21
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
22
 *
 
23
 * Author: David Reveman <davidr@novell.com>
 
24
 */
 
25
 
 
26
#include "xgl.h"
 
27
#include "inputstr.h"
 
28
#include "mipointer.h"
 
29
#include "damage.h"
 
30
#include "fb.h"
 
31
#ifdef MITSHM
 
32
#include "shmint.h"
 
33
static ShmFuncs shmFuncs = { NULL, xglShmPutImage };
 
34
#endif
 
35
#ifdef RENDER
 
36
#include "glyphstr.h"
 
37
#endif
 
38
#ifdef COMPOSITE
 
39
#include "compint.h"
 
40
#endif
 
41
 
 
42
int xglScreenGeneration = -1;
 
43
int xglScreenPrivateIndex;
 
44
int xglGCPrivateIndex;
 
45
int xglPixmapPrivateIndex;
 
46
int xglWinPrivateIndex;
 
47
 
 
48
#ifdef RENDER
 
49
int xglGlyphPrivateIndex;
 
50
#endif
 
51
 
 
52
#define xglQueryBestSize          (void *) NoopDDA
 
53
#define xglSaveScreen             (void *) NoopDDA
 
54
 
 
55
#define xglConstrainCursor        (void *) NoopDDA
 
56
#define xglCursorLimits           (void *) NoopDDA
 
57
#define xglDisplayCursor          (void *) NoopDDA
 
58
#define xglRealizeCursor          (void *) NoopDDA
 
59
#define xglUnrealizeCursor        (void *) NoopDDA
 
60
#define xglRecolorCursor          (void *) NoopDDA
 
61
#define xglSetCursorPosition      (void *) NoopDDA
 
62
 
 
63
static Bool
 
64
xglAllocatePrivates (ScreenPtr pScreen)
 
65
{
 
66
    xglScreenPtr pScreenPriv;
 
67
 
 
68
    if (xglScreenGeneration != serverGeneration)
 
69
    {
 
70
        xglScreenPrivateIndex = AllocateScreenPrivateIndex ();
 
71
        if (xglScreenPrivateIndex < 0)
 
72
            return FALSE;
 
73
 
 
74
        xglGCPrivateIndex = AllocateGCPrivateIndex ();
 
75
        if (xglGCPrivateIndex < 0)
 
76
            return FALSE;
 
77
 
 
78
        xglPixmapPrivateIndex = AllocatePixmapPrivateIndex ();
 
79
        if (xglPixmapPrivateIndex < 0)
 
80
            return FALSE;
 
81
 
 
82
        xglWinPrivateIndex = AllocateWindowPrivateIndex ();
 
83
        if (xglWinPrivateIndex < 0)
 
84
            return FALSE;
 
85
 
 
86
#ifdef RENDER
 
87
        xglGlyphPrivateIndex = AllocateGlyphPrivateIndex ();
 
88
        if (xglGlyphPrivateIndex < 0)
 
89
            return FALSE;
 
90
#endif
 
91
 
 
92
        xglScreenGeneration = serverGeneration;
 
93
    }
 
94
 
 
95
    if (!AllocateGCPrivate (pScreen, xglGCPrivateIndex, sizeof (xglGCRec)))
 
96
        return FALSE;
 
97
 
 
98
    if (!AllocatePixmapPrivate (pScreen, xglPixmapPrivateIndex,
 
99
                                sizeof (xglPixmapRec)))
 
100
        return FALSE;
 
101
 
 
102
    if (!AllocateWindowPrivate (pScreen, xglWinPrivateIndex,
 
103
                                sizeof (xglWinRec)))
 
104
        return FALSE;
 
105
 
 
106
    pScreenPriv = xalloc (sizeof (xglScreenRec));
 
107
    if (!pScreenPriv)
 
108
        return FALSE;
 
109
 
 
110
    XGL_SET_SCREEN_PRIV (pScreen, pScreenPriv);
 
111
 
 
112
    return TRUE;
 
113
}
 
114
 
 
115
Bool
 
116
xglScreenInit (ScreenPtr pScreen)
 
117
{
 
118
    xglScreenPtr pScreenPriv;
 
119
    xglVisualPtr v;
 
120
    int          i, depth, bpp = 0;
 
121
 
 
122
#ifdef RENDER
 
123
    PictureScreenPtr pPictureScreen;
 
124
#endif
 
125
 
 
126
    depth = xglScreenInfo.depth;
 
127
 
 
128
    for (v = xglVisuals; v; v = v->next)
 
129
    {
 
130
        if (v->pPixel->depth == depth)
 
131
        {
 
132
            bpp = v->pPixel->masks.bpp;
 
133
            break;
 
134
        }
 
135
    }
 
136
 
 
137
    if (!bpp)
 
138
        return FALSE;
 
139
 
 
140
    if (!xglAllocatePrivates (pScreen))
 
141
        return FALSE;
 
142
 
 
143
    pScreenPriv = XGL_GET_SCREEN_PRIV (pScreen);
 
144
 
 
145
    pScreenPriv->pScreenPixmap = NULL;
 
146
 
 
147
    /* Add any unlisted depths from the pixmap formats */
 
148
    for (i = 0; i < screenInfo.numPixmapFormats; i++)
 
149
    {
 
150
        if (!xglHasVisualTypes (xglVisuals, screenInfo.formats[i].depth))
 
151
            xglSetVisualTypes (screenInfo.formats[i].depth, 0, 0, 0, 0);
 
152
    }
 
153
 
 
154
    pScreenPriv->pVisual = 0;
 
155
 
 
156
#ifdef GLXEXT
 
157
    pScreenPriv->pGlxVisual = 0;
 
158
#endif
 
159
 
 
160
    pScreenPriv->rootVisual = 0;
 
161
 
 
162
    pScreenPriv->drawable = xglScreenInfo.drawable;
 
163
    pScreenPriv->features =
 
164
        glitz_drawable_get_features (xglScreenInfo.drawable);
 
165
 
 
166
    GEOMETRY_INIT (pScreen, &pScreenPriv->scratchGeometry,
 
167
                   GLITZ_GEOMETRY_TYPE_VERTEX,
 
168
                   pScreenPriv->geometryUsage, 0);
 
169
 
 
170
    pScreenPriv->geometryDataType = xglScreenInfo.geometryDataType;
 
171
    pScreenPriv->geometryUsage    = xglScreenInfo.geometryUsage;
 
172
    pScreenPriv->yInverted        = xglScreenInfo.yInverted;
 
173
    pScreenPriv->pboMask          = xglScreenInfo.pboMask;
 
174
    pScreenPriv->lines            = xglScreenInfo.lines;
 
175
    pScreenPriv->accel            = xglScreenInfo.accel;
 
176
 
 
177
    if (monitorResolution == 0)
 
178
        monitorResolution = XGL_DEFAULT_DPI;
 
179
 
 
180
    if (!fbSetupScreen (pScreen, NULL,
 
181
                        xglScreenInfo.width, xglScreenInfo.height,
 
182
                        monitorResolution, monitorResolution,
 
183
                        xglScreenInfo.width, bpp))
 
184
        return FALSE;
 
185
 
 
186
    pScreen->SaveScreen = xglSaveScreen;
 
187
 
 
188
    pScreen->CreatePixmap  = xglCreatePixmap;
 
189
    pScreen->DestroyPixmap = xglDestroyPixmap;
 
190
 
 
191
    if (!fbFinishScreenInit (pScreen, NULL,
 
192
                             xglScreenInfo.width, xglScreenInfo.height,
 
193
                             monitorResolution, monitorResolution,
 
194
                             xglScreenInfo.width, bpp))
 
195
        return FALSE;
 
196
 
 
197
#ifdef MITSHM
 
198
    ShmRegisterFuncs (pScreen, &shmFuncs);
 
199
#endif
 
200
 
 
201
#ifdef RENDER
 
202
    if (!xglPictureInit (pScreen))
 
203
        return FALSE;
 
204
#endif
 
205
 
 
206
    XGL_SCREEN_WRAP (GetImage, xglGetImage);
 
207
    XGL_SCREEN_WRAP (GetSpans, xglGetSpans);
 
208
 
 
209
    XGL_SCREEN_WRAP (CopyWindow, xglCopyWindow);
 
210
    XGL_SCREEN_WRAP (CreateWindow, xglCreateWindow);
 
211
    XGL_SCREEN_WRAP (DestroyWindow, xglDestroyWindow);
 
212
    XGL_SCREEN_WRAP (ChangeWindowAttributes, xglChangeWindowAttributes);
 
213
    XGL_SCREEN_WRAP (PaintWindowBackground, xglPaintWindowBackground);
 
214
    XGL_SCREEN_WRAP (PaintWindowBorder, xglPaintWindowBorder);
 
215
 
 
216
    XGL_SCREEN_WRAP (CreateGC, xglCreateGC);
 
217
 
 
218
    pScreen->ConstrainCursor   = xglConstrainCursor;
 
219
    pScreen->CursorLimits      = xglCursorLimits;
 
220
    pScreen->DisplayCursor     = xglDisplayCursor;
 
221
    pScreen->RealizeCursor     = xglRealizeCursor;
 
222
    pScreen->UnrealizeCursor   = xglUnrealizeCursor;
 
223
    pScreen->RecolorCursor     = xglRecolorCursor;
 
224
    pScreen->SetCursorPosition = xglSetCursorPosition;
 
225
 
 
226
    pScreen->ModifyPixmapHeader = xglModifyPixmapHeader;
 
227
 
 
228
    XGL_SCREEN_WRAP (BitmapToRegion, xglPixmapToRegion);
 
229
 
 
230
    pScreen->GetWindowPixmap = xglGetWindowPixmap;
 
231
 
 
232
    XGL_SCREEN_WRAP (SetWindowPixmap, xglSetWindowPixmap);
 
233
 
 
234
#ifdef RENDER
 
235
    pPictureScreen = GetPictureScreenIfSet (pScreen);
 
236
    if (pPictureScreen)
 
237
    {
 
238
        if (!AllocateGlyphPrivate (pScreen, xglGlyphPrivateIndex,
 
239
                                   sizeof (xglGlyphRec)))
 
240
            return FALSE;
 
241
 
 
242
        XGL_PICTURE_SCREEN_WRAP (RealizeGlyph, xglRealizeGlyph);
 
243
        XGL_PICTURE_SCREEN_WRAP (UnrealizeGlyph, xglUnrealizeGlyph);
 
244
        XGL_PICTURE_SCREEN_WRAP (Composite, xglComposite);
 
245
        XGL_PICTURE_SCREEN_WRAP (Glyphs, xglGlyphs);
 
246
        XGL_PICTURE_SCREEN_WRAP (Trapezoids, xglTrapezoids);
 
247
        XGL_PICTURE_SCREEN_WRAP (AddTraps, xglAddTraps);
 
248
        XGL_PICTURE_SCREEN_WRAP (AddTriangles, xglAddTriangles);
 
249
        XGL_PICTURE_SCREEN_WRAP (ChangePicture, xglChangePicture);
 
250
        XGL_PICTURE_SCREEN_WRAP (ChangePictureTransform,
 
251
                                 xglChangePictureTransform);
 
252
        XGL_PICTURE_SCREEN_WRAP (ChangePictureFilter, xglChangePictureFilter);
 
253
    }
 
254
#endif
 
255
 
 
256
    XGL_SCREEN_WRAP (BackingStoreFuncs.SaveAreas, xglSaveAreas);
 
257
    XGL_SCREEN_WRAP (BackingStoreFuncs.RestoreAreas, xglRestoreAreas);
 
258
 
 
259
    if (!fbCreateDefColormap (pScreen))
 
260
        return FALSE;
 
261
 
 
262
#ifdef COMPOSITE
 
263
    if (!compScreenInit (pScreen))
 
264
        return FALSE;
 
265
#endif
 
266
 
 
267
    /* Damage is required */
 
268
    DamageSetup (pScreen);
 
269
 
 
270
    XGL_SCREEN_WRAP (CloseScreen, xglCloseScreen);
 
271
 
 
272
    return TRUE;
 
273
}
 
274
 
 
275
Bool
 
276
xglFinishScreenInit (ScreenPtr pScreen)
 
277
{
 
278
    xglVisualPtr v;
 
279
 
 
280
#ifdef RENDER
 
281
    glitz_vertex_format_t *format;
 
282
    static glitz_color_t  clearBlack = { 0x0, 0x0, 0x0, 0x0 };
 
283
    static glitz_color_t  solidWhite = { 0xffff, 0xffff, 0xffff, 0xffff };
 
284
    int                   i;
 
285
#endif
 
286
 
 
287
    XGL_SCREEN_PRIV (pScreen);
 
288
 
 
289
    xglInitVisuals (pScreen);
 
290
 
 
291
    for (v = pScreenPriv->pVisual; v; v = v->next)
 
292
    {
 
293
        if (v->vid == pScreen->rootVisual)
 
294
            pScreenPriv->rootVisual = v;
 
295
    }
 
296
 
 
297
    if (!pScreenPriv->rootVisual || !pScreenPriv->rootVisual->format.surface)
 
298
        return FALSE;
 
299
 
 
300
    pScreenPriv->surface =
 
301
        glitz_surface_create (pScreenPriv->drawable,
 
302
                              pScreenPriv->rootVisual->format.surface,
 
303
                              xglScreenInfo.width, xglScreenInfo.height,
 
304
                              0, NULL);
 
305
    if (!pScreenPriv->surface)
 
306
        return FALSE;
 
307
 
 
308
    glitz_surface_attach (pScreenPriv->surface,
 
309
                          pScreenPriv->drawable,
 
310
                          GLITZ_DRAWABLE_BUFFER_FRONT_COLOR);
 
311
 
 
312
#ifdef RENDER
 
313
    for (i = 0; i < 33; i++)
 
314
        pScreenPriv->glyphCache[i].pScreen = NULL;
 
315
 
 
316
    for (v = pScreenPriv->pVisual; v; v = v->next)
 
317
    {
 
318
        if (v->pPixel->depth == 8)
 
319
            break;
 
320
    }
 
321
 
 
322
    pScreenPriv->pSolidAlpha    = 0;
 
323
    pScreenPriv->trapInfo.pMask = 0;
 
324
 
 
325
    /* An accelerated alpha only Xgl visual is required for trapezoid
 
326
       acceleration */
 
327
    if (v && v->format.surface)
 
328
    {
 
329
        glitz_surface_t *mask;
 
330
 
 
331
        mask = glitz_surface_create (pScreenPriv->drawable,
 
332
                                     v->format.surface,
 
333
                                     2, 1, 0, NULL);
 
334
        if (mask)
 
335
        {
 
336
            glitz_set_rectangle (mask, &clearBlack, 0, 0, 1, 1);
 
337
            glitz_set_rectangle (mask, &solidWhite, 1, 0, 1, 1);
 
338
 
 
339
            glitz_surface_set_fill (mask, GLITZ_FILL_NEAREST);
 
340
            glitz_surface_set_filter (mask, GLITZ_FILTER_BILINEAR, NULL, 0);
 
341
 
 
342
            pScreenPriv->trapInfo.pMask = xglCreateDevicePicture (mask);
 
343
            if (!pScreenPriv->trapInfo.pMask)
 
344
                return FALSE;
 
345
        }
 
346
    }
 
347
 
 
348
    format = &pScreenPriv->trapInfo.format.vertex;
 
349
    format->primitive  = GLITZ_PRIMITIVE_QUADS;
 
350
    format->attributes = GLITZ_VERTEX_ATTRIBUTE_MASK_COORD_MASK;
 
351
 
 
352
    format->mask.type        = GLITZ_DATA_TYPE_FLOAT;
 
353
    format->mask.size        = GLITZ_COORDINATE_SIZE_X;
 
354
    format->bytes_per_vertex = sizeof (glitz_float_t);
 
355
 
 
356
    if (pScreenPriv->geometryDataType)
 
357
    {
 
358
        format->type              = GLITZ_DATA_TYPE_FLOAT;
 
359
        format->bytes_per_vertex += 2 * sizeof (glitz_float_t);
 
360
        format->mask.offset       = 2 * sizeof (glitz_float_t);
 
361
    }
 
362
    else
 
363
    {
 
364
        format->type              = GLITZ_DATA_TYPE_SHORT;
 
365
        format->bytes_per_vertex += 2 * sizeof (glitz_short_t);
 
366
        format->mask.offset       = 2 * sizeof (glitz_short_t);
 
367
    }
 
368
#endif
 
369
 
 
370
#ifdef XV
 
371
    if (!xglXvScreenInit (pScreen))
 
372
       return FALSE;
 
373
#endif
 
374
 
 
375
    return TRUE;
 
376
}
 
377
 
 
378
Bool
 
379
xglCloseScreen (int       index,
 
380
                ScreenPtr pScreen)
 
381
{
 
382
    xglVisualPtr v;
 
383
 
 
384
    XGL_SCREEN_PRIV (pScreen);
 
385
    XGL_PIXMAP_PRIV (pScreenPriv->pScreenPixmap);
 
386
 
 
387
#ifdef RENDER
 
388
    int i;
 
389
 
 
390
    for (i = 0; i < 33; i++)
 
391
        xglFiniGlyphCache (&pScreenPriv->glyphCache[i]);
 
392
 
 
393
    if (pScreenPriv->pSolidAlpha)
 
394
        FreePicture ((pointer) pScreenPriv->pSolidAlpha, 0);
 
395
 
 
396
    if (pScreenPriv->trapInfo.pMask)
 
397
        FreePicture ((pointer) pScreenPriv->trapInfo.pMask, 0);
 
398
#endif
 
399
 
 
400
    xglFiniPixmap (pScreenPriv->pScreenPixmap);
 
401
    if (pPixmapPriv->pDamage)
 
402
        DamageDestroy (pPixmapPriv->pDamage);
 
403
 
 
404
    if (pScreenPriv->surface)
 
405
        glitz_surface_destroy (pScreenPriv->surface);
 
406
 
 
407
    GEOMETRY_UNINIT (&pScreenPriv->scratchGeometry);
 
408
 
 
409
    while (pScreenPriv->pVisual)
 
410
    {
 
411
        v = pScreenPriv->pVisual;
 
412
        pScreenPriv->pVisual = v->next;
 
413
        xfree (v);
 
414
    }
 
415
 
 
416
#ifdef GLXEXT
 
417
    while (pScreenPriv->pGlxVisual)
 
418
    {
 
419
        v = pScreenPriv->pGlxVisual;
 
420
        pScreenPriv->pGlxVisual = v->next;
 
421
        xfree (v);
 
422
    }
 
423
#endif
 
424
 
 
425
    XGL_SCREEN_UNWRAP (CloseScreen);
 
426
    xfree (pScreenPriv);
 
427
 
 
428
    return (*pScreen->CloseScreen) (index, pScreen);
 
429
}
 
430
 
 
431
#ifdef RENDER
 
432
void
 
433
xglCreateSolidAlphaPicture (ScreenPtr pScreen)
 
434
{
 
435
    static xRenderColor solidWhite = { 0xffff, 0xffff, 0xffff, 0xffff };
 
436
    static xRectangle   one = { 0, 0, 1, 1 };
 
437
    PixmapPtr           pPixmap;
 
438
    PictFormatPtr       pFormat;
 
439
    int                 error;
 
440
    Pixel               pixel;
 
441
    GCPtr               pGC;
 
442
    XID                 tmpval[2];
 
443
 
 
444
    XGL_SCREEN_PRIV (pScreen);
 
445
 
 
446
    pFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8);
 
447
    if (!pFormat)
 
448
        return;
 
449
 
 
450
    pGC = GetScratchGC (pFormat->depth, pScreen);
 
451
    if (!pGC)
 
452
        return;
 
453
 
 
454
    pPixmap = (*pScreen->CreatePixmap) (pScreen, 1, 1, pFormat->depth);
 
455
    if (!pPixmap)
 
456
        return;
 
457
 
 
458
    miRenderColorToPixel (pFormat, &solidWhite, &pixel);
 
459
 
 
460
    tmpval[0] = GXcopy;
 
461
    tmpval[1] = pixel;
 
462
 
 
463
    ChangeGC (pGC, GCFunction | GCForeground, tmpval);
 
464
    ValidateGC (&pPixmap->drawable, pGC);
 
465
    (*pGC->ops->PolyFillRect) (&pPixmap->drawable, pGC, 1, &one);
 
466
    FreeScratchGC (pGC);
 
467
 
 
468
    tmpval[0] = xTrue;
 
469
    pScreenPriv->pSolidAlpha = CreatePicture (0, &pPixmap->drawable, pFormat,
 
470
                                              CPRepeat, tmpval, 0, &error);
 
471
    (*pScreen->DestroyPixmap) (pPixmap);
 
472
 
 
473
    if (pScreenPriv->pSolidAlpha)
 
474
        ValidatePicture (pScreenPriv->pSolidAlpha);
 
475
}
 
476
#endif