2
* Copyright Ā© 2004 David Reveman
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
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.
23
* Author: David Reveman <davidr@novell.com>
28
#include "mipointer.h"
33
static ShmFuncs shmFuncs = { NULL, xglShmPutImage };
42
int xglScreenGeneration = -1;
43
int xglScreenPrivateIndex;
44
int xglGCPrivateIndex;
45
int xglPixmapPrivateIndex;
46
int xglWinPrivateIndex;
49
int xglGlyphPrivateIndex;
52
#define xglQueryBestSize (void *) NoopDDA
53
#define xglSaveScreen (void *) NoopDDA
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
64
xglAllocatePrivates (ScreenPtr pScreen)
66
xglScreenPtr pScreenPriv;
68
if (xglScreenGeneration != serverGeneration)
70
xglScreenPrivateIndex = AllocateScreenPrivateIndex ();
71
if (xglScreenPrivateIndex < 0)
74
xglGCPrivateIndex = AllocateGCPrivateIndex ();
75
if (xglGCPrivateIndex < 0)
78
xglPixmapPrivateIndex = AllocatePixmapPrivateIndex ();
79
if (xglPixmapPrivateIndex < 0)
82
xglWinPrivateIndex = AllocateWindowPrivateIndex ();
83
if (xglWinPrivateIndex < 0)
87
xglGlyphPrivateIndex = AllocateGlyphPrivateIndex ();
88
if (xglGlyphPrivateIndex < 0)
92
xglScreenGeneration = serverGeneration;
95
if (!AllocateGCPrivate (pScreen, xglGCPrivateIndex, sizeof (xglGCRec)))
98
if (!AllocatePixmapPrivate (pScreen, xglPixmapPrivateIndex,
99
sizeof (xglPixmapRec)))
102
if (!AllocateWindowPrivate (pScreen, xglWinPrivateIndex,
106
pScreenPriv = xalloc (sizeof (xglScreenRec));
110
XGL_SET_SCREEN_PRIV (pScreen, pScreenPriv);
116
xglScreenInit (ScreenPtr pScreen)
118
xglScreenPtr pScreenPriv;
120
int i, depth, bpp = 0;
123
PictureScreenPtr pPictureScreen;
126
depth = xglScreenInfo.depth;
128
for (v = xglVisuals; v; v = v->next)
130
if (v->pPixel->depth == depth)
132
bpp = v->pPixel->masks.bpp;
140
if (!xglAllocatePrivates (pScreen))
143
pScreenPriv = XGL_GET_SCREEN_PRIV (pScreen);
145
pScreenPriv->pScreenPixmap = NULL;
147
/* Add any unlisted depths from the pixmap formats */
148
for (i = 0; i < screenInfo.numPixmapFormats; i++)
150
if (!xglHasVisualTypes (xglVisuals, screenInfo.formats[i].depth))
151
xglSetVisualTypes (screenInfo.formats[i].depth, 0, 0, 0, 0);
154
pScreenPriv->pVisual = 0;
157
pScreenPriv->pGlxVisual = 0;
160
pScreenPriv->rootVisual = 0;
162
pScreenPriv->drawable = xglScreenInfo.drawable;
163
pScreenPriv->features =
164
glitz_drawable_get_features (xglScreenInfo.drawable);
166
GEOMETRY_INIT (pScreen, &pScreenPriv->scratchGeometry,
167
GLITZ_GEOMETRY_TYPE_VERTEX,
168
pScreenPriv->geometryUsage, 0);
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;
177
if (monitorResolution == 0)
178
monitorResolution = XGL_DEFAULT_DPI;
180
if (!fbSetupScreen (pScreen, NULL,
181
xglScreenInfo.width, xglScreenInfo.height,
182
monitorResolution, monitorResolution,
183
xglScreenInfo.width, bpp))
186
pScreen->SaveScreen = xglSaveScreen;
188
pScreen->CreatePixmap = xglCreatePixmap;
189
pScreen->DestroyPixmap = xglDestroyPixmap;
191
if (!fbFinishScreenInit (pScreen, NULL,
192
xglScreenInfo.width, xglScreenInfo.height,
193
monitorResolution, monitorResolution,
194
xglScreenInfo.width, bpp))
198
ShmRegisterFuncs (pScreen, &shmFuncs);
202
if (!xglPictureInit (pScreen))
206
XGL_SCREEN_WRAP (GetImage, xglGetImage);
207
XGL_SCREEN_WRAP (GetSpans, xglGetSpans);
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);
216
XGL_SCREEN_WRAP (CreateGC, xglCreateGC);
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;
226
pScreen->ModifyPixmapHeader = xglModifyPixmapHeader;
228
XGL_SCREEN_WRAP (BitmapToRegion, xglPixmapToRegion);
230
pScreen->GetWindowPixmap = xglGetWindowPixmap;
232
XGL_SCREEN_WRAP (SetWindowPixmap, xglSetWindowPixmap);
235
pPictureScreen = GetPictureScreenIfSet (pScreen);
238
if (!AllocateGlyphPrivate (pScreen, xglGlyphPrivateIndex,
239
sizeof (xglGlyphRec)))
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);
256
XGL_SCREEN_WRAP (BackingStoreFuncs.SaveAreas, xglSaveAreas);
257
XGL_SCREEN_WRAP (BackingStoreFuncs.RestoreAreas, xglRestoreAreas);
259
if (!fbCreateDefColormap (pScreen))
263
if (!compScreenInit (pScreen))
267
/* Damage is required */
268
DamageSetup (pScreen);
270
XGL_SCREEN_WRAP (CloseScreen, xglCloseScreen);
276
xglFinishScreenInit (ScreenPtr pScreen)
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 };
287
XGL_SCREEN_PRIV (pScreen);
289
xglInitVisuals (pScreen);
291
for (v = pScreenPriv->pVisual; v; v = v->next)
293
if (v->vid == pScreen->rootVisual)
294
pScreenPriv->rootVisual = v;
297
if (!pScreenPriv->rootVisual || !pScreenPriv->rootVisual->format.surface)
300
pScreenPriv->surface =
301
glitz_surface_create (pScreenPriv->drawable,
302
pScreenPriv->rootVisual->format.surface,
303
xglScreenInfo.width, xglScreenInfo.height,
305
if (!pScreenPriv->surface)
308
glitz_surface_attach (pScreenPriv->surface,
309
pScreenPriv->drawable,
310
GLITZ_DRAWABLE_BUFFER_FRONT_COLOR);
313
for (i = 0; i < 33; i++)
314
pScreenPriv->glyphCache[i].pScreen = NULL;
316
for (v = pScreenPriv->pVisual; v; v = v->next)
318
if (v->pPixel->depth == 8)
322
pScreenPriv->pSolidAlpha = 0;
323
pScreenPriv->trapInfo.pMask = 0;
325
/* An accelerated alpha only Xgl visual is required for trapezoid
327
if (v && v->format.surface)
329
glitz_surface_t *mask;
331
mask = glitz_surface_create (pScreenPriv->drawable,
336
glitz_set_rectangle (mask, &clearBlack, 0, 0, 1, 1);
337
glitz_set_rectangle (mask, &solidWhite, 1, 0, 1, 1);
339
glitz_surface_set_fill (mask, GLITZ_FILL_NEAREST);
340
glitz_surface_set_filter (mask, GLITZ_FILTER_BILINEAR, NULL, 0);
342
pScreenPriv->trapInfo.pMask = xglCreateDevicePicture (mask);
343
if (!pScreenPriv->trapInfo.pMask)
348
format = &pScreenPriv->trapInfo.format.vertex;
349
format->primitive = GLITZ_PRIMITIVE_QUADS;
350
format->attributes = GLITZ_VERTEX_ATTRIBUTE_MASK_COORD_MASK;
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);
356
if (pScreenPriv->geometryDataType)
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);
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);
371
if (!xglXvScreenInit (pScreen))
379
xglCloseScreen (int index,
384
XGL_SCREEN_PRIV (pScreen);
385
XGL_PIXMAP_PRIV (pScreenPriv->pScreenPixmap);
390
for (i = 0; i < 33; i++)
391
xglFiniGlyphCache (&pScreenPriv->glyphCache[i]);
393
if (pScreenPriv->pSolidAlpha)
394
FreePicture ((pointer) pScreenPriv->pSolidAlpha, 0);
396
if (pScreenPriv->trapInfo.pMask)
397
FreePicture ((pointer) pScreenPriv->trapInfo.pMask, 0);
400
xglFiniPixmap (pScreenPriv->pScreenPixmap);
401
if (pPixmapPriv->pDamage)
402
DamageDestroy (pPixmapPriv->pDamage);
404
if (pScreenPriv->surface)
405
glitz_surface_destroy (pScreenPriv->surface);
407
GEOMETRY_UNINIT (&pScreenPriv->scratchGeometry);
409
while (pScreenPriv->pVisual)
411
v = pScreenPriv->pVisual;
412
pScreenPriv->pVisual = v->next;
417
while (pScreenPriv->pGlxVisual)
419
v = pScreenPriv->pGlxVisual;
420
pScreenPriv->pGlxVisual = v->next;
425
XGL_SCREEN_UNWRAP (CloseScreen);
428
return (*pScreen->CloseScreen) (index, pScreen);
433
xglCreateSolidAlphaPicture (ScreenPtr pScreen)
435
static xRenderColor solidWhite = { 0xffff, 0xffff, 0xffff, 0xffff };
436
static xRectangle one = { 0, 0, 1, 1 };
438
PictFormatPtr pFormat;
444
XGL_SCREEN_PRIV (pScreen);
446
pFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8);
450
pGC = GetScratchGC (pFormat->depth, pScreen);
454
pPixmap = (*pScreen->CreatePixmap) (pScreen, 1, 1, pFormat->depth);
458
miRenderColorToPixel (pFormat, &solidWhite, &pixel);
463
ChangeGC (pGC, GCFunction | GCForeground, tmpval);
464
ValidateGC (&pPixmap->drawable, pGC);
465
(*pGC->ops->PolyFillRect) (&pPixmap->drawable, pGC, 1, &one);
469
pScreenPriv->pSolidAlpha = CreatePicture (0, &pPixmap->drawable, pFormat,
470
CPRepeat, tmpval, 0, &error);
471
(*pScreen->DestroyPixmap) (pPixmap);
473
if (pScreenPriv->pSolidAlpha)
474
ValidatePicture (pScreenPriv->pSolidAlpha);