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>
29
xglSyncBits (DrawablePtr pDrawable,
35
XGL_DRAWABLE_PIXMAP (pDrawable);
36
XGL_PIXMAP_PRIV (pPixmap);
38
if (pPixmapPriv->allBits)
39
return xglMapPixmapBits (pPixmap);
41
if (pPixmapPriv->target == xglPixmapTargetIn && pExtents)
45
box.x2 = pPixmap->drawable.width;
46
box.y2 = pPixmap->drawable.height;
47
if (pExtents->x1 > box.x1)
48
box.x1 = pExtents->x1;
49
if (pExtents->y1 > box.y1)
50
box.y1 = pExtents->y1;
51
if (pExtents->x2 < box.x2)
52
box.x2 = pExtents->x2;
53
if (pExtents->y2 < box.y2)
54
box.y2 = pExtents->y2;
56
if (box.x2 <= box.x1 || box.y2 <= box.y1)
57
return xglMapPixmapBits (pPixmap);
59
if (REGION_NOTEMPTY (pDrawable->pScreen, &pPixmapPriv->bitRegion))
61
switch (RECT_IN_REGION (pDrawable->pScreen,
62
&pPixmapPriv->bitRegion,
65
REGION_INIT (pDrawable->pScreen, ®ion, NullBox, 0);
68
REGION_INIT (pDrawable->pScreen, ®ion, &box, 1);
69
REGION_UNION (pDrawable->pScreen,
70
&pPixmapPriv->bitRegion, &pPixmapPriv->bitRegion,
74
REGION_INIT (pDrawable->pScreen, ®ion, &box, 1);
75
REGION_SUBTRACT (pDrawable->pScreen, ®ion, ®ion,
76
&pPixmapPriv->bitRegion);
77
REGION_UNION (pDrawable->pScreen,
78
&pPixmapPriv->bitRegion, &pPixmapPriv->bitRegion,
85
REGION_INIT (pDrawable->pScreen, ®ion, &box, 1);
86
REGION_SUBTRACT (pDrawable->pScreen, &pPixmapPriv->bitRegion,
87
®ion, &pPixmapPriv->bitRegion);
90
if (REGION_NUM_RECTS (&pPixmapPriv->bitRegion) == 1)
94
pBox = REGION_RECTS (&pPixmapPriv->bitRegion);
98
pBox->x2 >= pPixmap->drawable.width &&
99
pBox->y2 >= pPixmap->drawable.height)
100
pPixmapPriv->allBits = TRUE;
107
box.x2 = pPixmap->drawable.width;
108
box.y2 = pPixmap->drawable.height;
110
REGION_INIT (pDrawable->pScreen, ®ion, &box, 1);
111
REGION_SUBTRACT (pDrawable->pScreen, ®ion, ®ion,
112
&pPixmapPriv->bitRegion);
114
pPixmapPriv->allBits = TRUE;
117
if (!pPixmapPriv->buffer)
118
if (!xglAllocatePixmapBits (pPixmap, XGL_PIXMAP_USAGE_HINT_DEFAULT))
121
if (REGION_NOTEMPTY (pDrawable->pScreen, ®ion) && pPixmapPriv->surface)
123
glitz_pixel_format_t format;
128
if (!xglSyncSurface (pDrawable))
129
FatalError (XGL_SW_FAILURE_STRING);
131
xglUnmapPixmapBits (pPixmap);
133
pBox = REGION_RECTS (®ion);
134
nBox = REGION_NUM_RECTS (®ion);
135
pExt = REGION_EXTENTS (pDrawable->pScreen, ®ion);
137
format.fourcc = GLITZ_FOURCC_RGB;
138
format.masks = pPixmapPriv->pVisual->pPixel->masks;
139
format.xoffset = pExt->x1;
141
if (pPixmapPriv->stride < 0)
143
format.skip_lines = pPixmap->drawable.height - pExt->y2;
144
format.bytes_per_line = -pPixmapPriv->stride;
145
format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP;
149
format.skip_lines = pExt->y1;
150
format.bytes_per_line = pPixmapPriv->stride;
151
format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN;
154
glitz_surface_set_clip_region (pPixmapPriv->surface,
155
0, 0, (glitz_box_t *) pBox, nBox);
157
glitz_get_pixels (pPixmapPriv->surface,
163
pPixmapPriv->buffer);
165
glitz_surface_set_clip_region (pPixmapPriv->surface, 0, 0, NULL, 0);
168
REGION_UNINIT (pDrawable->pScreen, ®ion);
170
if (pPixmapPriv->allBits)
174
box.x2 = pPixmap->drawable.width;
175
box.y2 = pPixmap->drawable.height;
177
REGION_UNINIT (pDrawable->pScreen, &pPixmapPriv->bitRegion);
178
REGION_INIT (pDrawable->pScreen, &pPixmapPriv->bitRegion, &box, 1);
181
return xglMapPixmapBits (pPixmap);
185
xglSyncDamageBoxBits (DrawablePtr pDrawable)
187
XGL_DRAWABLE_PIXMAP_PRIV (pDrawable);
189
if (!xglSyncBits (pDrawable, &pPixmapPriv->damageBox))
190
FatalError (XGL_SW_FAILURE_STRING);
194
xglSyncSurface (DrawablePtr pDrawable)
198
XGL_DRAWABLE_PIXMAP (pDrawable);
199
XGL_PIXMAP_PRIV (pPixmap);
201
if (!pPixmapPriv->surface)
203
if (!xglCreatePixmapSurface (pPixmap))
207
pRegion = DamageRegion (pPixmapPriv->pDamage);
209
if (REGION_NOTEMPTY (pDrawable->pScreen, pRegion))
211
glitz_pixel_format_t format;
216
xglUnmapPixmapBits (pPixmap);
218
nBox = REGION_NUM_RECTS (pRegion);
219
pBox = REGION_RECTS (pRegion);
220
pExt = REGION_EXTENTS (pDrawable->pScreen, pRegion);
222
format.fourcc = pPixmapPriv->pVisual->format.surface->color.fourcc;
223
format.masks = pPixmapPriv->pVisual->pPixel->masks;
224
format.xoffset = pExt->x1;
226
if (pPixmapPriv->stride < 0)
228
format.skip_lines = pPixmap->drawable.height - pExt->y2;
229
format.bytes_per_line = -pPixmapPriv->stride;
230
format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP;
234
format.skip_lines = pExt->y1;
235
format.bytes_per_line = pPixmapPriv->stride;
236
format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN;
239
glitz_surface_set_clip_region (pPixmapPriv->surface,
240
0, 0, (glitz_box_t *) pBox, nBox);
242
glitz_set_pixels (pPixmapPriv->surface,
248
pPixmapPriv->buffer);
250
glitz_surface_set_clip_region (pPixmapPriv->surface, 0, 0, NULL, 0);
252
REGION_EMPTY (pDrawable->pScreen, pRegion);
259
xglPrepareTarget (DrawablePtr pDrawable)
261
XGL_DRAWABLE_PIXMAP (pDrawable);
262
XGL_PIXMAP_PRIV (pPixmap);
264
switch (pPixmapPriv->target) {
265
case xglPixmapTargetNo:
267
case xglPixmapTargetOut:
268
if (xglSyncSurface (pDrawable))
270
glitz_drawable_format_t *format;
272
XGL_SCREEN_PRIV (pDrawable->pScreen);
274
if (!pPixmapPriv->drawable)
276
unsigned int width, height;
278
format = pPixmapPriv->pVisual->format.drawable;
279
width = pPixmap->drawable.width;
280
height = pPixmap->drawable.height;
282
if (pPixmapPriv->pVisual->pbuffer)
284
pPixmapPriv->drawable =
285
glitz_create_pbuffer_drawable (pScreenPriv->drawable,
286
format, width, height);
290
pPixmapPriv->drawable =
291
glitz_create_drawable (pScreenPriv->drawable,
292
format, width, height);
296
if (pPixmapPriv->drawable)
298
glitz_surface_attach (pPixmapPriv->surface,
299
pPixmapPriv->drawable,
300
GLITZ_DRAWABLE_BUFFER_FRONT_COLOR);
302
pPixmapPriv->target = xglPixmapTargetIn;
307
pPixmapPriv->target = xglPixmapTargetNo;
309
case xglPixmapTargetIn:
310
if (xglSyncSurface (pDrawable))
319
xglAddSurfaceDamage (DrawablePtr pDrawable,
322
glitz_surface_t *surface;
325
XGL_DRAWABLE_PIXMAP_PRIV (pDrawable);
327
pPixmapPriv->damageBox = miEmptyBox;
329
XGL_GET_DRAWABLE (pDrawable, surface, xOff, yOff);
332
REGION_TRANSLATE (pDrawable->pScreen, pRegion, xOff, yOff);
334
if (pPixmapPriv->pDamage)
336
RegionPtr pDamageRegion;
338
pDamageRegion = DamageRegion (pPixmapPriv->pDamage);
340
REGION_UNION (pDrawable->pScreen,
341
pDamageRegion, pDamageRegion,
345
REGION_UNION (pDrawable->pScreen,
346
&pPixmapPriv->bitRegion, &pPixmapPriv->bitRegion,
350
REGION_TRANSLATE (pDrawable->pScreen, pRegion, -xOff, -yOff);
354
xglAddCurrentSurfaceDamage (DrawablePtr pDrawable)
356
XGL_DRAWABLE_PIXMAP_PRIV (pDrawable);
358
if (BOX_NOTEMPTY (&pPixmapPriv->damageBox))
362
REGION_INIT (pDrawable->pScreen, ®ion, &pPixmapPriv->damageBox, 1);
364
if (pPixmapPriv->pDamage)
366
RegionPtr pDamageRegion;
368
pDamageRegion = DamageRegion (pPixmapPriv->pDamage);
370
REGION_UNION (pDrawable->pScreen,
371
pDamageRegion, pDamageRegion,
375
REGION_UNION (pDrawable->pScreen,
376
&pPixmapPriv->bitRegion, &pPixmapPriv->bitRegion,
379
REGION_UNINIT (pDrawable->pScreen, ®ion);
381
pPixmapPriv->damageBox = miEmptyBox;
386
xglAddBitDamage (DrawablePtr pDrawable,
389
XGL_DRAWABLE_PIXMAP_PRIV (pDrawable);
391
if (REGION_NOTEMPTY (pDrawable->pScreen, &pPixmapPriv->bitRegion))
394
BoxPtr pExt, pBitExt;
397
pBox = REGION_RECTS (pRegion);
398
pExt = REGION_EXTENTS (pDrawable->pScreen, pRegion);
399
nBox = REGION_NUM_RECTS (pRegion);
401
pBitExt = REGION_EXTENTS (pDrawable->pScreen, &pPixmapPriv->bitRegion);
403
if (pExt->x1 < pBitExt->x2 &&
404
pExt->y1 < pBitExt->y2 &&
405
pExt->x2 > pBitExt->x1 &&
406
pExt->y2 > pBitExt->y1)
410
if (pBox->x1 < pBitExt->x2 &&
411
pBox->y1 < pBitExt->y2 &&
412
pBox->x2 > pBitExt->x1 &&
413
pBox->y2 > pBitExt->y1)
415
REGION_UNINIT (pDrawable->pScreen,
416
&pPixmapPriv->bitRegion);
417
REGION_INIT (pDrawable->pScreen, &pPixmapPriv->bitRegion,
419
pPixmapPriv->allBits = FALSE;
430
xglAddCurrentBitDamage (DrawablePtr pDrawable)
432
XGL_DRAWABLE_PIXMAP_PRIV (pDrawable);
434
if (REGION_NOTEMPTY (pDrawable->pScreen, &pPixmapPriv->bitRegion))
438
pBitExt = REGION_EXTENTS (pDrawable->pScreen, &pPixmapPriv->bitRegion);
440
if (pPixmapPriv->damageBox.x1 < pBitExt->x2 &&
441
pPixmapPriv->damageBox.y1 < pBitExt->y2 &&
442
pPixmapPriv->damageBox.x2 > pBitExt->x1 &&
443
pPixmapPriv->damageBox.y2 > pBitExt->y1)
445
REGION_UNINIT (pDrawable->pScreen, &pPixmapPriv->bitRegion);
446
REGION_INIT (pDrawable->pScreen, &pPixmapPriv->bitRegion,
448
pPixmapPriv->allBits = FALSE;
452
pPixmapPriv->damageBox = miEmptyBox;