summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/hw/dmx/dmxpict.c
blob: 507d361607ae4a29fe14414c1e0e80e1cbfaff3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
/* $XFree86$ */
/*
 * Copyright 2001,2002 Red Hat Inc., Durham, North Carolina.
 *
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation on the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/*
 * Authors:
 *   Kevin E. Martin <kem@redhat.com>
 *
 */

#include "dmx.h"
#include "dmxsync.h"
#include "dmxpict.h"
#include "dmxwindow.h"
#include "dmxpixmap.h"

#include "fb.h"
#include "pixmapstr.h"
#include "picture.h"
#include "picturestr.h"
#include "mipict.h"
#include "fbpict.h"

#if 0
#include "dmxgc.h"
#include "dmxgcops.h"
#include "dmxpixmap.h"
#include "dmxfont.h"

#include "gcstruct.h"
#include "migc.h"
#endif

Bool dmxPictureInit(ScreenPtr pScreen, PictFormatPtr formats, int nformats)
{
    DMXScreenInfo    *dmxScreen = &dmxScreens[pScreen->myNum];
    PictureScreenPtr  ps;

    /* The shadow framebuffer only relies on FB to be initialized */
    if (dmxShadowFB) return fbPictureInit(pScreen, formats, nformats);

    if (!miPictureInit(pScreen, formats, nformats))
	return FALSE;

    if (!AllocatePicturePrivate(pScreen, dmxPictPrivateIndex,
				sizeof(dmxPictPrivRec)))
	return FALSE;

    ps = GetPictureScreen(pScreen);

    DMX_WRAP(CreatePicture,  dmxCreatePicture,  dmxScreen, ps);
    DMX_WRAP(DestroyPicture, dmxDestroyPicture, dmxScreen, ps);

    DMX_WRAP(Composite,      dmxComposite,      dmxScreen, ps);
    DMX_WRAP(Glyphs,         dmxGlyphs,         dmxScreen, ps);
    DMX_WRAP(CompositeRects, dmxCompositeRects, dmxScreen, ps);

    return TRUE;
}

static Picture dmxDoCreatePicture(PicturePtr pPicture)
{
    DrawablePtr               pDraw     = pPicture->pDrawable;
    PictFormatPtr             pFmt      = pPicture->pFormat;
    ScreenPtr                 pScreen   = pDraw->pScreen;
    DMXScreenInfo            *dmxScreen = &dmxScreens[pScreen->myNum];
    XRenderPictFormat        *pFormat;
    Drawable                  draw;
    int                       i         = 0;

    if (pPicture->pDrawable->type == DRAWABLE_WINDOW) {
	dmxWinPrivPtr  pWinPriv = DMX_GET_WINDOW_PRIV((WindowPtr)(pDraw));

	if (!(draw = pWinPriv->window)) {
	    /* Window has not been created yet due to the window
	     * optimization.  Delay picture creation until window is
	     * mapped.
	     */
	    pWinPriv->hasPict = TRUE;
	    return 0;
	}
    } else {
	dmxPixPrivPtr  pPixPriv = DMX_GET_PIXMAP_PRIV((PixmapPtr)(pDraw));

	if (!(draw = pPixPriv->pixmap)) {
	    /* FIXME: Zero width/height pixmap?? */
	    return 0;
	}
    }

    while (++i) {
	pFormat = XRenderFindFormat(dmxScreen->display, 0, 0, i);
	if (!pFormat) break;

	if (pFormat->type             != pFmt->type)             continue;
	if (pFormat->depth            != pFmt->depth)            continue;
	if (pFormat->direct.red       != pFmt->direct.red)       continue;
	if (pFormat->direct.redMask   != pFmt->direct.redMask)   continue;
	if (pFormat->direct.green     != pFmt->direct.green)     continue;
	if (pFormat->direct.greenMask != pFmt->direct.greenMask) continue;
	if (pFormat->direct.blue      != pFmt->direct.blue)      continue;
	if (pFormat->direct.blueMask  != pFmt->direct.blueMask)  continue;
	if (pFormat->direct.alpha     != pFmt->direct.alpha)     continue;
	if (pFormat->direct.alphaMask != pFmt->direct.alphaMask) continue;

	/* We have a match! */
	break;
    }

    return XRenderCreatePicture(dmxScreen->display, draw, pFormat, 0, 0);
}

void dmxCreatePictureList(WindowPtr pWindow)
{
    PicturePtr  pPicture = GetPictureWindow(pWindow);

    while (pPicture) {
	dmxPictPrivPtr  pPictPriv = DMX_GET_PICT_PRIV(pPicture);

	/* Create the picture for this window */
	pPictPriv->pict = dmxDoCreatePicture(pPicture);
	/* FIXME: Does ValidatePicture take care of the state changes?? */

	pPicture = pPicture->pNext;
    }
}

int dmxCreatePicture(PicturePtr pPicture)
{
    ScreenPtr         pScreen   = pPicture->pDrawable->pScreen;
    DMXScreenInfo    *dmxScreen = &dmxScreens[pScreen->myNum];
    PictureScreenPtr  ps        = GetPictureScreen(pScreen);
    dmxPictPrivPtr    pPictPriv = DMX_GET_PICT_PRIV(pPicture);
    int               ret       = Success;

    DMX_UNWRAP(CreatePicture, dmxScreen, ps);
#if 1
    if (ps->CreatePicture)
	ret = ps->CreatePicture(pPicture);
#endif

    /* Create picture on back-end server */
    pPictPriv->pict      = dmxDoCreatePicture(pPicture);
    pPictPriv->savedMask = 0;

    DMX_WRAP(CreatePicture, dmxCreatePicture, dmxScreen, ps);

    return ret;
}

void dmxDestroyPictureList(WindowPtr pWindow)
{
    ScreenPtr      pScreen   = pWindow->drawable.pScreen;
    DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
    PicturePtr     pPicture = GetPictureWindow(pWindow);

    while (pPicture) {
	dmxPictPrivPtr  pPictPriv = DMX_GET_PICT_PRIV(pPicture);
	if (pPictPriv->pict) {
	    XRenderFreePicture(dmxScreen->display, pPictPriv->pict);
	    pPictPriv->pict = (Picture)0;
	}

	pPicture = pPicture->pNext;
    }
}

void dmxDestroyPicture(PicturePtr pPicture)
{
    ScreenPtr         pScreen   = pPicture->pDrawable->pScreen;
    DMXScreenInfo    *dmxScreen = &dmxScreens[pScreen->myNum];
    PictureScreenPtr  ps        = GetPictureScreen(pScreen);
    dmxPictPrivPtr    pPictPriv = DMX_GET_PICT_PRIV(pPicture);

    DMX_UNWRAP(DestroyPicture, dmxScreen, ps);

    /* Destroy picture on back-end server */
    if (pPictPriv->pict) {
	XRenderFreePicture(dmxScreen->display, pPictPriv->pict);
	dmxSync(dmxScreen, False);
	pPictPriv->pict = (Picture)0;
    }

#if 1
    if (ps->DestroyPicture)
	ps->DestroyPicture(pPicture);
#endif
    DMX_WRAP(DestroyPicture, dmxDestroyPicture, dmxScreen, ps);
}

int dmxChangePictureClip(PicturePtr pPicture, int clipType,
			 pointer value, int n)
{
    ScreenPtr         pScreen   = pPicture->pDrawable->pScreen;
    DMXScreenInfo    *dmxScreen = &dmxScreens[pScreen->myNum];
    PictureScreenPtr  ps        = GetPictureScreen(pScreen);
    dmxPictPrivPtr    pPictPriv = DMX_GET_PICT_PRIV(pPicture);

    DMX_UNWRAP(ChangePictureClip, dmxScreen, ps);
#if 1
    if (ps->ChangePictureClip)
	ps->ChangePictureClip(pPicture, clipType, value, n);
#endif

    /* Change picture clip rects on back-end server */
    if (pPictPriv->pict) {
	/* The clip has already been changed into a region by the mi
	 * routine called above.
	 */
	if (pPicture->clientClip) {
	    RegionPtr   pClip = pPicture->clientClip;
	    BoxPtr      pBox  = REGION_RECTS(pClip);
	    int         nBox  = REGION_NUM_RECTS(pClip);
	    XRectangle *pRects;
	    XRectangle *pRect;
	    int         nRects;

	    nRects = nBox;
	    pRects = pRect = xalloc(nRects * sizeof(*pRect));

	    while (nBox--) {
		pRect->x      = pBox->x1;
		pRect->y      = pBox->y1;
		pRect->width  = pBox->x2 - pBox->x1;
		pRect->height = pBox->y2 - pBox->y1;
		pBox++;
		pRect++;
	    }

	    XRenderSetPictureClipRectangles(dmxScreen->display,
					    pPictPriv->pict,
					    0, 0,
					    pRects,
					    nRects);
	    xfree(pRects);
	} else {
	    XRenderSetPictureClipRectangles(dmxScreen->display,
					    pPictPriv->pict,
					    0, 0, NULL, 0);
	}
	dmxSync(dmxScreen, False);
    } else {
	/* FIXME: Handle saving clip region when offscreen */
    }

    DMX_WRAP(ChangePictureClip, dmxChangePictureClip, dmxScreen, ps);
    
    return Success;
}

void dmxDestroyPictureClip(PicturePtr pPicture)
{
    ScreenPtr         pScreen   = pPicture->pDrawable->pScreen;
    DMXScreenInfo    *dmxScreen = &dmxScreens[pScreen->myNum];
    PictureScreenPtr  ps        = GetPictureScreen(pScreen);
    dmxPictPrivPtr    pPictPriv = DMX_GET_PICT_PRIV(pPicture);

    DMX_UNWRAP(DestroyPictureClip, dmxScreen, ps);
#if 1
    if (ps->DestroyPictureClip)
	ps->DestroyPictureClip(pPicture);
#endif

    /* Destroy picture clip rects on back-end server */
    if (pPictPriv->pict) {
	XRenderSetPictureClipRectangles(dmxScreen->display,
					pPictPriv->pict,
					0, 0, NULL, 0);
	dmxSync(dmxScreen, False);
    } else {
	/* FIXME: Handle destroying clip region when offscreen */
    }

    DMX_WRAP(DestroyPictureClip, dmxDestroyPictureClip, dmxScreen, ps);
}

void dmxChangePicture(PicturePtr pPicture, Mask mask)
{
    ScreenPtr         pScreen   = pPicture->pDrawable->pScreen;
    DMXScreenInfo    *dmxScreen = &dmxScreens[pScreen->myNum];
    PictureScreenPtr  ps        = GetPictureScreen(pScreen);
    dmxPictPrivPtr    pPictPriv = DMX_GET_PICT_PRIV(pPicture);

    DMX_UNWRAP(ChangePicture, dmxScreen, ps);
#if 1
    if (ps->ChangePicture)
	ps->ChangePicture(pPicture, mask);
#endif

    /* Picture attribute changes are handled in ValidatePicture */
    pPictPriv->savedMask |= mask;

    DMX_WRAP(ChangePicture, dmxChangePicture, dmxScreen, ps);
}

void dmxValidatePicture(PicturePtr pPicture, Mask mask)
{
    ScreenPtr         pScreen   = pPicture->pDrawable->pScreen;
    DMXScreenInfo    *dmxScreen = &dmxScreens[pScreen->myNum];
    PictureScreenPtr  ps        = GetPictureScreen(pScreen);
    dmxPictPrivPtr    pPictPriv = DMX_GET_PICT_PRIV(pPicture);

    DMX_UNWRAP(ValidatePicture, dmxScreen, ps);

    /* Change picture attributes on back-end server */
    if (pPictPriv->pict) {
	XRenderPictureAttributes  attribs;

	if (mask & CPRepeat)
	    attribs.repeat = pPicture->repeat;
	if (mask & CPAlphaMap) {
	    dmxPictPrivPtr  pAlphaPriv = DMX_GET_PICT_PRIV(pPicture->alphaMap);
	    if (pAlphaPriv->pict) {
		attribs.alpha_map = pAlphaPriv->pict;
	    } else {
		/* FIXME: alpha picture window/pixmap has not been created?? */
		return;
	    }
	}
	if (mask & CPAlphaXOrigin)
	    attribs.alpha_x_origin = pPicture->alphaOrigin.x;
	if (mask & CPAlphaYOrigin)
	    attribs.alpha_y_origin = pPicture->alphaOrigin.y;
	if (mask & CPClipXOrigin)
	    attribs.clip_x_origin = pPicture->clipOrigin.x;
	if (mask & CPClipYOrigin)
	    attribs.clip_y_origin = pPicture->clipOrigin.y;
	if (mask & CPClipMask)
	    mask &= ~CPClipMask; /* Handled in ChangePictureClip (FIXME??) */
	if (mask & CPGraphicsExposure)
	    attribs.graphics_exposures = pPicture->graphicsExposures;
	if (mask & CPSubwindowMode)
	    attribs.subwindow_mode = pPicture->subWindowMode;
	if (mask & CPPolyEdge)
	    attribs.poly_edge = pPicture->polyEdge;
	if (mask & CPPolyMode)
	    attribs.poly_mode = pPicture->polyMode;
	if (mask & CPDither)
	    attribs.dither = pPicture->dither;
	if (mask & CPComponentAlpha)
	    attribs.component_alpha = pPicture->componentAlpha;

	XRenderChangePicture(dmxScreen->display, pPictPriv->pict,
			     mask, &attribs);
	dmxSync(dmxScreen, False);
    } else {
	/* FIXME: ERROR?!?! */
	pPictPriv->savedMask |= mask;
    }

#if 1
    if (ps->ValidatePicture)
	ps->ValidatePicture(pPicture, mask);
#endif

    DMX_WRAP(ValidatePicture, dmxValidatePicture, dmxScreen, ps);
}

void dmxComposite(CARD8 op,
		  PicturePtr pSrc, PicturePtr pMask, PicturePtr pDst,
		  INT16 xSrc, INT16 ySrc,
		  INT16 xMask, INT16 yMask,
		  INT16 xDst, INT16 yDst,
		  CARD16 width, CARD16 height)
{
    ScreenPtr         pScreen   = pDst->pDrawable->pScreen;
    DMXScreenInfo    *dmxScreen = &dmxScreens[pScreen->myNum];
    PictureScreenPtr  ps        = GetPictureScreen(pScreen);
    dmxPictPrivPtr    pSrcPriv  = DMX_GET_PICT_PRIV(pSrc);
    dmxPictPrivPtr    pMaskPriv = NULL;
    dmxPictPrivPtr    pDstPriv  = DMX_GET_PICT_PRIV(pDst);

    if (pMask) pMaskPriv = DMX_GET_PICT_PRIV(pMask);

    DMX_UNWRAP(Composite, dmxScreen, ps);
#if 0
    if (ps->Composite)
	ps->Composite(op, pSrc, pMask, pDst,
		      xSrc, ySrc, xMask, yMask, xDst, yDst,
		      width, height);
#endif

    /* Composite on back-end server */
    if (pSrcPriv->pict && pDstPriv->pict &&
	((pMaskPriv && pMaskPriv->pict) || !pMaskPriv)) {
	XRenderComposite(dmxScreen->display,
			 op,
			 pSrcPriv->pict,
			 pMaskPriv ? pMaskPriv->pict : None,
			 pDstPriv->pict,
			 xSrc, ySrc,
			 xMask, yMask,
			 xDst, yDst,
			 width, height);
	dmxSync(dmxScreen, False);
    }


    DMX_WRAP(Composite, dmxComposite, dmxScreen, ps);
}

void dmxGlyphs(CARD8 op,
	       PicturePtr pSrc, PicturePtr pDst,
	       PictFormatPtr maskFormat,
	       INT16 xSrc, INT16 ySrc,
	       int nlists, GlyphListPtr lists, GlyphPtr *glyphs)
{
}

void dmxCompositeRects(CARD8 op,
		       PicturePtr pDst,
		       xRenderColor *color,
		       int nRect, xRectangle *rects)
{
    ScreenPtr         pScreen   = pDst->pDrawable->pScreen;
    DMXScreenInfo    *dmxScreen = &dmxScreens[pScreen->myNum];
    PictureScreenPtr  ps        = GetPictureScreen(pScreen);
    dmxPictPrivPtr    pPictPriv = DMX_GET_PICT_PRIV(pDst);

    DMX_UNWRAP(CompositeRects, dmxScreen, ps);
#if 0
    if (ps->CompositeRects)
	ps->CompositeRects(op, pDst, color, nRect, rects);
#endif

    /* CompositeRects on back-end server */
    if (pPictPriv->pict) {
	XRenderFillRectangles(dmxScreen->display,
			      op,
			      pPictPriv->pict,
			      (XRenderColor *)color,
			      (XRectangle *)rects,
			      nRect);
	dmxSync(dmxScreen, False);
    }

    DMX_WRAP(CompositeRects, dmxCompositeRects, dmxScreen, ps);
}

Bool dmxInitIndexed(ScreenPtr pScreen, PictFormatPtr pFormat)
{
    return TRUE;
}

void dmxCloseIndexed(ScreenPtr pScreen, PictFormatPtr pFormat)
{
}

void dmxUpdateIndexed(ScreenPtr pScreen, PictFormatPtr pFormat,
		      int ndef, xColorItem *pdef)
{
}