| 1 |
/* |
| 2 |
* Copyright © 2003 Keith Packard |
| 3 |
* |
| 4 |
* Permission to use, copy, modify, distribute, and sell this software and its |
| 5 |
* documentation for any purpose is hereby granted without fee, provided that |
| 6 |
* the above copyright notice appear in all copies and that both that |
| 7 |
* copyright notice and this permission notice appear in supporting |
| 8 |
* documentation, and that the name of Keith Packard not be used in |
| 9 |
* advertising or publicity pertaining to distribution of the software without |
| 10 |
* specific, written prior permission. Keith Packard makes no |
| 11 |
* representations about the suitability of this software for any purpose. It |
| 12 |
* is provided "as is" without express or implied warranty. |
| 13 |
* |
| 14 |
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 15 |
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 16 |
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 17 |
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 18 |
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 19 |
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 20 |
* PERFORMANCE OF THIS SOFTWARE. |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifdef HAVE_DIX_CONFIG_H |
| 24 |
#include <dix-config.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#include <stdlib.h> |
| 28 |
|
| 29 |
#include <X11/X.h> |
| 30 |
#include "scrnintstr.h" |
| 31 |
#include "windowstr.h" |
| 32 |
#include <X11/fonts/font.h> |
| 33 |
#include "dixfontstr.h" |
| 34 |
#include <X11/fonts/fontstruct.h> |
| 35 |
#include <X11/fonts/libxfont2.h> |
| 36 |
#include "mi.h" |
| 37 |
#include "mipict.h" |
| 38 |
#include "regionstr.h" |
| 39 |
#include "globals.h" |
| 40 |
#include "gcstruct.h" |
| 41 |
#include "damage.h" |
| 42 |
#include "damagestr.h" |
| 43 |
#include "glyphstr_priv.h" |
| 44 |
|
| 45 |
#define wrap(priv, real, mem, func) {\ |
| 46 |
priv->mem = real->mem; \ |
| 47 |
real->mem = func; \ |
| 48 |
} |
| 49 |
|
| 50 |
#define unwrap(priv, real, mem) {\ |
| 51 |
real->mem = priv->mem; \ |
| 52 |
} |
| 53 |
|
| 54 |
#define BOX_SAME(a,b) \ |
| 55 |
((a)->x1 == (b)->x1 && \ |
| 56 |
(a)->y1 == (b)->y1 && \ |
| 57 |
(a)->x2 == (b)->x2 && \ |
| 58 |
(a)->y2 == (b)->y2) |
| 59 |
|
| 60 |
#define DAMAGE_VALIDATE_ENABLE 0 |
| 61 |
#define DAMAGE_DEBUG_ENABLE 0 |
| 62 |
#if DAMAGE_DEBUG_ENABLE |
| 63 |
#define DAMAGE_DEBUG(x) ErrorF x |
| 64 |
#else |
| 65 |
#define DAMAGE_DEBUG(x) |
| 66 |
#endif |
| 67 |
|
| 68 |
#define getPixmapDamageRef(pPixmap) ((DamagePtr *) \ |
| 69 |
dixLookupPrivateAddr(&(pPixmap)->devPrivates, damagePixPrivateKey)) |
| 70 |
|
| 71 |
#define pixmapDamage(pPixmap) damagePixPriv(pPixmap) |
| 72 |
|
| 73 |
static DevPrivateKeyRec damageScrPrivateKeyRec; |
| 74 |
|
| 75 |
#define damageScrPrivateKey (&damageScrPrivateKeyRec) |
| 76 |
static DevPrivateKeyRec damagePixPrivateKeyRec; |
| 77 |
|
| 78 |
#define damagePixPrivateKey (&damagePixPrivateKeyRec) |
| 79 |
static DevPrivateKeyRec damageGCPrivateKeyRec; |
| 80 |
|
| 81 |
#define damageGCPrivateKey (&damageGCPrivateKeyRec) |
| 82 |
static DevPrivateKeyRec damageWinPrivateKeyRec; |
| 83 |
|
| 84 |
#define damageWinPrivateKey (&damageWinPrivateKeyRec) |
| 85 |
|
| 86 |
static DamagePtr * |
| 87 |
getDrawableDamageRef(DrawablePtr pDrawable) |
| 88 |
{ |
| 89 |
PixmapPtr pPixmap; |
| 90 |
|
| 91 |
if (WindowDrawable(pDrawable->type)) { |
| 92 |
ScreenPtr pScreen = pDrawable->pScreen; |
| 93 |
|
| 94 |
pPixmap = 0; |
| 95 |
if (pScreen->GetWindowPixmap |
| 96 |
#ifdef ROOTLESS_WORKAROUND |
| 97 |
&& ((WindowPtr) pDrawable)->viewable |
| 98 |
#endif |
| 99 |
) |
| 100 |
pPixmap = (*pScreen->GetWindowPixmap) ((WindowPtr) pDrawable); |
| 101 |
|
| 102 |
if (!pPixmap) { |
| 103 |
damageScrPriv(pScreen); |
| 104 |
|
| 105 |
return &pScrPriv->pScreenDamage; |
| 106 |
} |
| 107 |
} |
| 108 |
else |
| 109 |
pPixmap = (PixmapPtr) pDrawable; |
| 110 |
return getPixmapDamageRef(pPixmap); |
| 111 |
} |
| 112 |
|
| 113 |
#define getDrawableDamage(pDrawable) (*getDrawableDamageRef (pDrawable)) |
| 114 |
#define getWindowDamage(pWin) getDrawableDamage(&(pWin)->drawable) |
| 115 |
|
| 116 |
#define drawableDamage(pDrawable) \ |
| 117 |
DamagePtr pDamage = getDrawableDamage(pDrawable) |
| 118 |
|
| 119 |
#define windowDamage(pWin) drawableDamage(&(pWin)->drawable) |
| 120 |
|
| 121 |
#define winDamageRef(pWindow) \ |
| 122 |
DamagePtr *pPrev = (DamagePtr *) \ |
| 123 |
dixLookupPrivateAddr(&(pWindow)->devPrivates, damageWinPrivateKey) |
| 124 |
|
| 125 |
#if DAMAGE_DEBUG_ENABLE |
| 126 |
static void |
| 127 |
_damageRegionAppend(DrawablePtr pDrawable, RegionPtr pRegion, Bool clip, |
| 128 |
int subWindowMode, const char *where) |
| 129 |
#define damageRegionAppend(d,r,c,m) _damageRegionAppend(d,r,c,m,__FUNCTION__) |
| 130 |
#else |
| 131 |
static void |
| 132 |
damageRegionAppend(DrawablePtr pDrawable, RegionPtr pRegion, Bool clip, |
| 133 |
int subWindowMode) |
| 134 |
#endif |
| 135 |
{ |
| 136 |
ScreenPtr pScreen = pDrawable->pScreen; |
| 137 |
|
| 138 |
damageScrPriv(pScreen); |
| 139 |
drawableDamage(pDrawable); |
| 140 |
DamagePtr pNext; |
| 141 |
RegionRec clippedRec; |
| 142 |
RegionPtr pDamageRegion; |
| 143 |
RegionRec pixClip; |
| 144 |
int draw_x, draw_y; |
| 145 |
|
| 146 |
#if defined(COMPOSITE) || defined(ROOTLESS) |
| 147 |
int screen_x = 0, screen_y = 0; |
| 148 |
#endif |
| 149 |
|
| 150 |
/* short circuit for empty regions */ |
| 151 |
if (!RegionNotEmpty(pRegion)) |
| 152 |
return; |
| 153 |
|
| 154 |
#if defined(COMPOSITE) || defined(ROOTLESS) |
| 155 |
/* |
| 156 |
* When drawing to a pixmap which is storing window contents, |
| 157 |
* the region presented is in pixmap relative coordinates which |
| 158 |
* need to be converted to screen relative coordinates |
| 159 |
*/ |
| 160 |
if (pDrawable->type != DRAWABLE_WINDOW) { |
| 161 |
screen_x = ((PixmapPtr) pDrawable)->screen_x - pDrawable->x; |
| 162 |
screen_y = ((PixmapPtr) pDrawable)->screen_y - pDrawable->y; |
| 163 |
} |
| 164 |
if (screen_x || screen_y) |
| 165 |
RegionTranslate(pRegion, screen_x, screen_y); |
| 166 |
#endif |
| 167 |
|
| 168 |
if (pDrawable->type == DRAWABLE_WINDOW && |
| 169 |
((WindowPtr) (pDrawable))->backingStore == NotUseful) { |
| 170 |
if (subWindowMode == ClipByChildren) { |
| 171 |
RegionIntersect(pRegion, pRegion, |
| 172 |
&((WindowPtr) (pDrawable))->clipList); |
| 173 |
} |
| 174 |
else if (subWindowMode == IncludeInferiors) { |
| 175 |
RegionPtr pTempRegion = |
| 176 |
NotClippedByChildren((WindowPtr) (pDrawable)); |
| 177 |
RegionIntersect(pRegion, pRegion, pTempRegion); |
| 178 |
RegionDestroy(pTempRegion); |
| 179 |
} |
| 180 |
/* If subWindowMode is set to an invalid value, don't perform |
| 181 |
* any drawable-based clipping. */ |
| 182 |
} |
| 183 |
|
| 184 |
RegionNull(&clippedRec); |
| 185 |
for (; pDamage; pDamage = pNext) { |
| 186 |
pNext = pDamage->pNext; |
| 187 |
/* |
| 188 |
* Check for internal damage and don't send events |
| 189 |
*/ |
| 190 |
if (pScrPriv->internalLevel > 0 && !pDamage->isInternal) { |
| 191 |
DAMAGE_DEBUG(("non internal damage, skipping at %d\n", |
| 192 |
pScrPriv->internalLevel)); |
| 193 |
continue; |
| 194 |
} |
| 195 |
/* |
| 196 |
* Check for unrealized windows |
| 197 |
*/ |
| 198 |
if (pDamage->pDrawable->type == DRAWABLE_WINDOW && |
| 199 |
!((WindowPtr) (pDamage->pDrawable))->realized) { |
| 200 |
continue; |
| 201 |
} |
| 202 |
|
| 203 |
draw_x = pDamage->pDrawable->x; |
| 204 |
draw_y = pDamage->pDrawable->y; |
| 205 |
#if defined(COMPOSITE) || defined(ROOTLESS) |
| 206 |
/* |
| 207 |
* Need to move everyone to screen coordinates |
| 208 |
* XXX what about off-screen pixmaps with non-zero x/y? |
| 209 |
*/ |
| 210 |
if (!WindowDrawable(pDamage->pDrawable->type)) { |
| 211 |
draw_x += ((PixmapPtr) pDamage->pDrawable)->screen_x; |
| 212 |
draw_y += ((PixmapPtr) pDamage->pDrawable)->screen_y; |
| 213 |
} |
| 214 |
#endif |
| 215 |
|
| 216 |
/* |
| 217 |
* Clip against border or pixmap bounds |
| 218 |
*/ |
| 219 |
|
| 220 |
pDamageRegion = pRegion; |
| 221 |
if (clip || pDamage->pDrawable != pDrawable) { |
| 222 |
pDamageRegion = &clippedRec; |
| 223 |
if (pDamage->pDrawable->type == DRAWABLE_WINDOW) { |
| 224 |
RegionIntersect(pDamageRegion, pRegion, |
| 225 |
&((WindowPtr) (pDamage->pDrawable))-> |
| 226 |
borderClip); |
| 227 |
} |
| 228 |
else { |
| 229 |
BoxRec box; |
| 230 |
|
| 231 |
box.x1 = draw_x; |
| 232 |
box.y1 = draw_y; |
| 233 |
box.x2 = draw_x + pDamage->pDrawable->width; |
| 234 |
box.y2 = draw_y + pDamage->pDrawable->height; |
| 235 |
RegionInit(&pixClip, &box, 1); |
| 236 |
RegionIntersect(pDamageRegion, pRegion, &pixClip); |
| 237 |
RegionUninit(&pixClip); |
| 238 |
} |
| 239 |
/* |
| 240 |
* Short circuit empty results |
| 241 |
*/ |
| 242 |
if (!RegionNotEmpty(pDamageRegion)) |
| 243 |
continue; |
| 244 |
} |
| 245 |
|
| 246 |
DAMAGE_DEBUG(("%s %d x %d +%d +%d (target 0x%lx monitor 0x%lx)\n", |
| 247 |
where, |
| 248 |
pDamageRegion->extents.x2 - pDamageRegion->extents.x1, |
| 249 |
pDamageRegion->extents.y2 - pDamageRegion->extents.y1, |
| 250 |
pDamageRegion->extents.x1, pDamageRegion->extents.y1, |
| 251 |
pDrawable->id, pDamage->pDrawable->id)); |
| 252 |
|
| 253 |
/* |
| 254 |
* Move region to target coordinate space |
| 255 |
*/ |
| 256 |
if (draw_x || draw_y) |
| 257 |
RegionTranslate(pDamageRegion, -draw_x, -draw_y); |
| 258 |
|
| 259 |
/* Store damage region if needed after submission. */ |
| 260 |
if (pDamage->reportAfter) |
| 261 |
RegionUnion(&pDamage->pendingDamage, |
| 262 |
&pDamage->pendingDamage, pDamageRegion); |
| 263 |
|
| 264 |
/* Report damage now, if desired. */ |
| 265 |
if (!pDamage->reportAfter) { |
| 266 |
if (pDamage->damageReport) |
| 267 |
DamageReportDamage(pDamage, pDamageRegion); |
| 268 |
else |
| 269 |
RegionUnion(&pDamage->damage, &pDamage->damage, pDamageRegion); |
| 270 |
} |
| 271 |
|
| 272 |
/* |
| 273 |
* translate original region back |
| 274 |
*/ |
| 275 |
if (pDamageRegion == pRegion && (draw_x || draw_y)) |
| 276 |
RegionTranslate(pDamageRegion, draw_x, draw_y); |
| 277 |
} |
| 278 |
#if defined(COMPOSITE) || defined(ROOTLESS) |
| 279 |
if (screen_x || screen_y) |
| 280 |
RegionTranslate(pRegion, -screen_x, -screen_y); |
| 281 |
#endif |
| 282 |
|
| 283 |
RegionUninit(&clippedRec); |
| 284 |
} |
| 285 |
|
| 286 |
static void |
| 287 |
damageRegionProcessPending(DrawablePtr pDrawable) |
| 288 |
{ |
| 289 |
drawableDamage(pDrawable); |
| 290 |
|
| 291 |
for (; pDamage != NULL; pDamage = pDamage->pNext) { |
| 292 |
if (pDamage->reportAfter) { |
| 293 |
/* It's possible that there is only interest in postRendering reporting. */ |
| 294 |
if (pDamage->damageReport) |
| 295 |
DamageReportDamage(pDamage, &pDamage->pendingDamage); |
| 296 |
else |
| 297 |
RegionUnion(&pDamage->damage, &pDamage->damage, |
| 298 |
&pDamage->pendingDamage); |
| 299 |
} |
| 300 |
|
| 301 |
if (pDamage->reportAfter) |
| 302 |
RegionEmpty(&pDamage->pendingDamage); |
| 303 |
} |
| 304 |
|
| 305 |
} |
| 306 |
|
| 307 |
#if DAMAGE_DEBUG_ENABLE |
| 308 |
#define damageDamageBox(d,b,m) _damageDamageBox(d,b,m,__FUNCTION__) |
| 309 |
static void |
| 310 |
_damageDamageBox(DrawablePtr pDrawable, BoxPtr pBox, int subWindowMode, |
| 311 |
const char *where) |
| 312 |
#else |
| 313 |
static void |
| 314 |
damageDamageBox(DrawablePtr pDrawable, BoxPtr pBox, int subWindowMode) |
| 315 |
#endif |
| 316 |
{ |
| 317 |
RegionRec region; |
| 318 |
|
| 319 |
RegionInit(®ion, pBox, 1); |
| 320 |
#if DAMAGE_DEBUG_ENABLE |
| 321 |
_damageRegionAppend(pDrawable, ®ion, TRUE, subWindowMode, where); |
| 322 |
#else |
| 323 |
damageRegionAppend(pDrawable, ®ion, TRUE, subWindowMode); |
| 324 |
#endif |
| 325 |
RegionUninit(®ion); |
| 326 |
} |
| 327 |
|
| 328 |
static void damageValidateGC(GCPtr, unsigned long, DrawablePtr); |
| 329 |
static void damageChangeGC(GCPtr, unsigned long); |
| 330 |
static void damageCopyGC(GCPtr, unsigned long, GCPtr); |
| 331 |
static void damageDestroyGC(GCPtr); |
| 332 |
static void damageChangeClip(GCPtr, int, void *, int); |
| 333 |
static void damageDestroyClip(GCPtr); |
| 334 |
static void damageCopyClip(GCPtr, GCPtr); |
| 335 |
|
| 336 |
static GCFuncs damageGCFuncs = { |
| 337 |
damageValidateGC, damageChangeGC, damageCopyGC, damageDestroyGC, |
| 338 |
damageChangeClip, damageDestroyClip, damageCopyClip |
| 339 |
}; |
| 340 |
|
| 341 |
static GCOps damageGCOps; |
| 342 |
|
| 343 |
static Bool |
| 344 |
damageCreateGC(GCPtr pGC) |
| 345 |
{ |
| 346 |
ScreenPtr pScreen = pGC->pScreen; |
| 347 |
|
| 348 |
damageScrPriv(pScreen); |
| 349 |
damageGCPriv(pGC); |
| 350 |
Bool ret; |
| 351 |
|
| 352 |
unwrap(pScrPriv, pScreen, CreateGC); |
| 353 |
if ((ret = (*pScreen->CreateGC) (pGC))) { |
| 354 |
pGCPriv->ops = NULL; |
| 355 |
pGCPriv->funcs = pGC->funcs; |
| 356 |
pGC->funcs = &damageGCFuncs; |
| 357 |
} |
| 358 |
wrap(pScrPriv, pScreen, CreateGC, damageCreateGC); |
| 359 |
|
| 360 |
return ret; |
| 361 |
} |
| 362 |
|
| 363 |
#define DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable) \ |
| 364 |
damageGCPriv(pGC); \ |
| 365 |
const GCFuncs *oldFuncs = pGC->funcs; \ |
| 366 |
unwrap(pGCPriv, pGC, funcs); \ |
| 367 |
unwrap(pGCPriv, pGC, ops); \ |
| 368 |
|
| 369 |
#define DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable) \ |
| 370 |
wrap(pGCPriv, pGC, funcs, oldFuncs); \ |
| 371 |
wrap(pGCPriv, pGC, ops, &damageGCOps) |
| 372 |
|
| 373 |
#define DAMAGE_GC_FUNC_PROLOGUE(pGC) \ |
| 374 |
damageGCPriv(pGC); \ |
| 375 |
unwrap(pGCPriv, pGC, funcs); \ |
| 376 |
if (pGCPriv->ops) unwrap(pGCPriv, pGC, ops) |
| 377 |
|
| 378 |
#define DAMAGE_GC_FUNC_EPILOGUE(pGC) \ |
| 379 |
wrap(pGCPriv, pGC, funcs, &damageGCFuncs); \ |
| 380 |
if (pGCPriv->ops) wrap(pGCPriv, pGC, ops, &damageGCOps) |
| 381 |
|
| 382 |
static void |
| 383 |
damageValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable) |
| 384 |
{ |
| 385 |
DAMAGE_GC_FUNC_PROLOGUE(pGC); |
| 386 |
(*pGC->funcs->ValidateGC) (pGC, changes, pDrawable); |
| 387 |
pGCPriv->ops = pGC->ops; /* just so it's not NULL */ |
| 388 |
DAMAGE_GC_FUNC_EPILOGUE(pGC); |
| 389 |
} |
| 390 |
|
| 391 |
static void |
| 392 |
damageDestroyGC(GCPtr pGC) |
| 393 |
{ |
| 394 |
DAMAGE_GC_FUNC_PROLOGUE(pGC); |
| 395 |
(*pGC->funcs->DestroyGC) (pGC); |
| 396 |
DAMAGE_GC_FUNC_EPILOGUE(pGC); |
| 397 |
} |
| 398 |
|
| 399 |
static void |
| 400 |
damageChangeGC(GCPtr pGC, unsigned long mask) |
| 401 |
{ |
| 402 |
DAMAGE_GC_FUNC_PROLOGUE(pGC); |
| 403 |
(*pGC->funcs->ChangeGC) (pGC, mask); |
| 404 |
DAMAGE_GC_FUNC_EPILOGUE(pGC); |
| 405 |
} |
| 406 |
|
| 407 |
static void |
| 408 |
damageCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst) |
| 409 |
{ |
| 410 |
DAMAGE_GC_FUNC_PROLOGUE(pGCDst); |
| 411 |
(*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst); |
| 412 |
DAMAGE_GC_FUNC_EPILOGUE(pGCDst); |
| 413 |
} |
| 414 |
|
| 415 |
static void |
| 416 |
damageChangeClip(GCPtr pGC, int type, void *pvalue, int nrects) |
| 417 |
{ |
| 418 |
DAMAGE_GC_FUNC_PROLOGUE(pGC); |
| 419 |
(*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects); |
| 420 |
DAMAGE_GC_FUNC_EPILOGUE(pGC); |
| 421 |
} |
| 422 |
|
| 423 |
static void |
| 424 |
damageCopyClip(GCPtr pgcDst, GCPtr pgcSrc) |
| 425 |
{ |
| 426 |
DAMAGE_GC_FUNC_PROLOGUE(pgcDst); |
| 427 |
(*pgcDst->funcs->CopyClip) (pgcDst, pgcSrc); |
| 428 |
DAMAGE_GC_FUNC_EPILOGUE(pgcDst); |
| 429 |
} |
| 430 |
|
| 431 |
static void |
| 432 |
damageDestroyClip(GCPtr pGC) |
| 433 |
{ |
| 434 |
DAMAGE_GC_FUNC_PROLOGUE(pGC); |
| 435 |
(*pGC->funcs->DestroyClip) (pGC); |
| 436 |
DAMAGE_GC_FUNC_EPILOGUE(pGC); |
| 437 |
} |
| 438 |
|
| 439 |
#define TRIM_BOX(box, pGC) if (pGC->pCompositeClip) { \ |
| 440 |
BoxPtr extents = &pGC->pCompositeClip->extents;\ |
| 441 |
if(box.x1 < extents->x1) box.x1 = extents->x1; \ |
| 442 |
if(box.x2 > extents->x2) box.x2 = extents->x2; \ |
| 443 |
if(box.y1 < extents->y1) box.y1 = extents->y1; \ |
| 444 |
if(box.y2 > extents->y2) box.y2 = extents->y2; \ |
| 445 |
} |
| 446 |
|
| 447 |
#define TRANSLATE_BOX(box, pDrawable) { \ |
| 448 |
box.x1 += pDrawable->x; \ |
| 449 |
box.x2 += pDrawable->x; \ |
| 450 |
box.y1 += pDrawable->y; \ |
| 451 |
box.y2 += pDrawable->y; \ |
| 452 |
} |
| 453 |
|
| 454 |
#define TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC) { \ |
| 455 |
TRANSLATE_BOX(box, pDrawable); \ |
| 456 |
TRIM_BOX(box, pGC); \ |
| 457 |
} |
| 458 |
|
| 459 |
#define BOX_NOT_EMPTY(box) \ |
| 460 |
(((box.x2 - box.x1) > 0) && ((box.y2 - box.y1) > 0)) |
| 461 |
|
| 462 |
#define checkGCDamage(d,g) (getDrawableDamage(d) && \ |
| 463 |
(!g->pCompositeClip ||\ |
| 464 |
RegionNotEmpty(g->pCompositeClip))) |
| 465 |
|
| 466 |
#define TRIM_PICTURE_BOX(box, pDst) { \ |
| 467 |
BoxPtr extents = &pDst->pCompositeClip->extents;\ |
| 468 |
if(box.x1 < extents->x1) box.x1 = extents->x1; \ |
| 469 |
if(box.x2 > extents->x2) box.x2 = extents->x2; \ |
| 470 |
if(box.y1 < extents->y1) box.y1 = extents->y1; \ |
| 471 |
if(box.y2 > extents->y2) box.y2 = extents->y2; \ |
| 472 |
} |
| 473 |
|
| 474 |
#define checkPictureDamage(p) (getDrawableDamage(p->pDrawable) && \ |
| 475 |
RegionNotEmpty(p->pCompositeClip)) |
| 476 |
|
| 477 |
static void |
| 478 |
damageComposite(CARD8 op, |
| 479 |
PicturePtr pSrc, |
| 480 |
PicturePtr pMask, |
| 481 |
PicturePtr pDst, |
| 482 |
INT16 xSrc, |
| 483 |
INT16 ySrc, |
| 484 |
INT16 xMask, |
| 485 |
INT16 yMask, |
| 486 |
INT16 xDst, INT16 yDst, CARD16 width, CARD16 height) |
| 487 |
{ |
| 488 |
ScreenPtr pScreen = pDst->pDrawable->pScreen; |
| 489 |
PictureScreenPtr ps = GetPictureScreen(pScreen); |
| 490 |
|
| 491 |
damageScrPriv(pScreen); |
| 492 |
|
| 493 |
if (checkPictureDamage(pDst)) { |
| 494 |
BoxRec box; |
| 495 |
|
| 496 |
box.x1 = xDst + pDst->pDrawable->x; |
| 497 |
box.y1 = yDst + pDst->pDrawable->y; |
| 498 |
box.x2 = box.x1 + width; |
| 499 |
box.y2 = box.y1 + height; |
| 500 |
TRIM_PICTURE_BOX(box, pDst); |
| 501 |
if (BOX_NOT_EMPTY(box)) |
| 502 |
damageDamageBox(pDst->pDrawable, &box, pDst->subWindowMode); |
| 503 |
} |
| 504 |
/* |
| 505 |
* Validating a source picture bound to a window may trigger other |
| 506 |
* composite operations. Do it before unwrapping to make sure damage |
| 507 |
* is reported correctly. |
| 508 |
*/ |
| 509 |
if (pSrc->pDrawable && WindowDrawable(pSrc->pDrawable->type)) |
| 510 |
miCompositeSourceValidate(pSrc); |
| 511 |
if (pMask && pMask->pDrawable && WindowDrawable(pMask->pDrawable->type)) |
| 512 |
miCompositeSourceValidate(pMask); |
| 513 |
unwrap(pScrPriv, ps, Composite); |
| 514 |
(*ps->Composite) (op, |
| 515 |
pSrc, |
| 516 |
pMask, |
| 517 |
pDst, |
| 518 |
xSrc, ySrc, xMask, yMask, xDst, yDst, width, height); |
| 519 |
damageRegionProcessPending(pDst->pDrawable); |
| 520 |
wrap(pScrPriv, ps, Composite, damageComposite); |
| 521 |
} |
| 522 |
|
| 523 |
static void |
| 524 |
damageGlyphs(CARD8 op, |
| 525 |
PicturePtr pSrc, |
| 526 |
PicturePtr pDst, |
| 527 |
PictFormatPtr maskFormat, |
| 528 |
INT16 xSrc, |
| 529 |
INT16 ySrc, int nlist, GlyphListPtr list, GlyphPtr * glyphs) |
| 530 |
{ |
| 531 |
ScreenPtr pScreen = pDst->pDrawable->pScreen; |
| 532 |
PictureScreenPtr ps = GetPictureScreen(pScreen); |
| 533 |
|
| 534 |
damageScrPriv(pScreen); |
| 535 |
|
| 536 |
if (checkPictureDamage(pDst)) { |
| 537 |
int nlistTmp = nlist; |
| 538 |
GlyphListPtr listTmp = list; |
| 539 |
GlyphPtr *glyphsTmp = glyphs; |
| 540 |
int x, y; |
| 541 |
int n; |
| 542 |
GlyphPtr glyph; |
| 543 |
BoxRec box; |
| 544 |
int x1, y1, x2, y2; |
| 545 |
|
| 546 |
box.x1 = 32767; |
| 547 |
box.y1 = 32767; |
| 548 |
box.x2 = -32767; |
| 549 |
box.y2 = -32767; |
| 550 |
x = pDst->pDrawable->x; |
| 551 |
y = pDst->pDrawable->y; |
| 552 |
while (nlistTmp--) { |
| 553 |
x += listTmp->xOff; |
| 554 |
y += listTmp->yOff; |
| 555 |
n = listTmp->len; |
| 556 |
while (n--) { |
| 557 |
glyph = *glyphsTmp++; |
| 558 |
x1 = x - glyph->info.x; |
| 559 |
y1 = y - glyph->info.y; |
| 560 |
x2 = x1 + glyph->info.width; |
| 561 |
y2 = y1 + glyph->info.height; |
| 562 |
if (x1 < box.x1) |
| 563 |
box.x1 = x1; |
| 564 |
if (y1 < box.y1) |
| 565 |
box.y1 = y1; |
| 566 |
if (x2 > box.x2) |
| 567 |
box.x2 = x2; |
| 568 |
if (y2 > box.y2) |
| 569 |
box.y2 = y2; |
| 570 |
x += glyph->info.xOff; |
| 571 |
y += glyph->info.yOff; |
| 572 |
} |
| 573 |
listTmp++; |
| 574 |
} |
| 575 |
TRIM_PICTURE_BOX(box, pDst); |
| 576 |
if (BOX_NOT_EMPTY(box)) |
| 577 |
damageDamageBox(pDst->pDrawable, &box, pDst->subWindowMode); |
| 578 |
} |
| 579 |
unwrap(pScrPriv, ps, Glyphs); |
| 580 |
(*ps->Glyphs) (op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, list, glyphs); |
| 581 |
damageRegionProcessPending(pDst->pDrawable); |
| 582 |
wrap(pScrPriv, ps, Glyphs, damageGlyphs); |
| 583 |
} |
| 584 |
|
| 585 |
static void |
| 586 |
damageAddTraps(PicturePtr pPicture, |
| 587 |
INT16 x_off, INT16 y_off, int ntrap, xTrap * traps) |
| 588 |
{ |
| 589 |
ScreenPtr pScreen = pPicture->pDrawable->pScreen; |
| 590 |
PictureScreenPtr ps = GetPictureScreen(pScreen); |
| 591 |
|
| 592 |
damageScrPriv(pScreen); |
| 593 |
|
| 594 |
if (checkPictureDamage(pPicture)) { |
| 595 |
BoxRec box; |
| 596 |
int i; |
| 597 |
int x, y; |
| 598 |
xTrap *t = traps; |
| 599 |
|
| 600 |
box.x1 = 32767; |
| 601 |
box.y1 = 32767; |
| 602 |
box.x2 = -32767; |
| 603 |
box.y2 = -32767; |
| 604 |
x = pPicture->pDrawable->x + x_off; |
| 605 |
y = pPicture->pDrawable->y + y_off; |
| 606 |
for (i = 0; i < ntrap; i++) { |
| 607 |
pixman_fixed_t l = min(t->top.l, t->bot.l); |
| 608 |
pixman_fixed_t r = max(t->top.r, t->bot.r); |
| 609 |
int x1 = x + pixman_fixed_to_int(l); |
| 610 |
int x2 = x + pixman_fixed_to_int(pixman_fixed_ceil(r)); |
| 611 |
int y1 = y + pixman_fixed_to_int(t->top.y); |
| 612 |
int y2 = y + pixman_fixed_to_int(pixman_fixed_ceil(t->bot.y)); |
| 613 |
|
| 614 |
if (x1 < box.x1) |
| 615 |
box.x1 = x1; |
| 616 |
if (x2 > box.x2) |
| 617 |
box.x2 = x2; |
| 618 |
if (y1 < box.y1) |
| 619 |
box.y1 = y1; |
| 620 |
if (y2 > box.y2) |
| 621 |
box.y2 = y2; |
| 622 |
} |
| 623 |
TRIM_PICTURE_BOX(box, pPicture); |
| 624 |
if (BOX_NOT_EMPTY(box)) |
| 625 |
damageDamageBox(pPicture->pDrawable, &box, pPicture->subWindowMode); |
| 626 |
} |
| 627 |
unwrap(pScrPriv, ps, AddTraps); |
| 628 |
(*ps->AddTraps) (pPicture, x_off, y_off, ntrap, traps); |
| 629 |
damageRegionProcessPending(pPicture->pDrawable); |
| 630 |
wrap(pScrPriv, ps, AddTraps, damageAddTraps); |
| 631 |
} |
| 632 |
|
| 633 |
/**********************************************************/ |
| 634 |
|
| 635 |
static void |
| 636 |
damageFillSpans(DrawablePtr pDrawable, |
| 637 |
GC * pGC, int npt, DDXPointPtr ppt, int *pwidth, int fSorted) |
| 638 |
{ |
| 639 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 640 |
|
| 641 |
if (npt && checkGCDamage(pDrawable, pGC)) { |
| 642 |
int nptTmp = npt; |
| 643 |
DDXPointPtr pptTmp = ppt; |
| 644 |
int *pwidthTmp = pwidth; |
| 645 |
BoxRec box; |
| 646 |
|
| 647 |
box.x1 = pptTmp->x; |
| 648 |
box.x2 = box.x1 + *pwidthTmp; |
| 649 |
box.y2 = box.y1 = pptTmp->y; |
| 650 |
|
| 651 |
while (--nptTmp) { |
| 652 |
pptTmp++; |
| 653 |
pwidthTmp++; |
| 654 |
if (box.x1 > pptTmp->x) |
| 655 |
box.x1 = pptTmp->x; |
| 656 |
if (box.x2 < (pptTmp->x + *pwidthTmp)) |
| 657 |
box.x2 = pptTmp->x + *pwidthTmp; |
| 658 |
if (box.y1 > pptTmp->y) |
| 659 |
box.y1 = pptTmp->y; |
| 660 |
else if (box.y2 < pptTmp->y) |
| 661 |
box.y2 = pptTmp->y; |
| 662 |
} |
| 663 |
|
| 664 |
box.y2++; |
| 665 |
|
| 666 |
if (!pGC->miTranslate) { |
| 667 |
TRANSLATE_BOX(box, pDrawable); |
| 668 |
} |
| 669 |
TRIM_BOX(box, pGC); |
| 670 |
|
| 671 |
if (BOX_NOT_EMPTY(box)) |
| 672 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 673 |
} |
| 674 |
|
| 675 |
(*pGC->ops->FillSpans) (pDrawable, pGC, npt, ppt, pwidth, fSorted); |
| 676 |
|
| 677 |
damageRegionProcessPending(pDrawable); |
| 678 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 679 |
} |
| 680 |
|
| 681 |
static void |
| 682 |
damageSetSpans(DrawablePtr pDrawable, |
| 683 |
GCPtr pGC, |
| 684 |
char *pcharsrc, |
| 685 |
DDXPointPtr ppt, int *pwidth, int npt, int fSorted) |
| 686 |
{ |
| 687 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 688 |
|
| 689 |
if (npt && checkGCDamage(pDrawable, pGC)) { |
| 690 |
DDXPointPtr pptTmp = ppt; |
| 691 |
int *pwidthTmp = pwidth; |
| 692 |
int nptTmp = npt; |
| 693 |
BoxRec box; |
| 694 |
|
| 695 |
box.x1 = pptTmp->x; |
| 696 |
box.x2 = box.x1 + *pwidthTmp; |
| 697 |
box.y2 = box.y1 = pptTmp->y; |
| 698 |
|
| 699 |
while (--nptTmp) { |
| 700 |
pptTmp++; |
| 701 |
pwidthTmp++; |
| 702 |
if (box.x1 > pptTmp->x) |
| 703 |
box.x1 = pptTmp->x; |
| 704 |
if (box.x2 < (pptTmp->x + *pwidthTmp)) |
| 705 |
box.x2 = pptTmp->x + *pwidthTmp; |
| 706 |
if (box.y1 > pptTmp->y) |
| 707 |
box.y1 = pptTmp->y; |
| 708 |
else if (box.y2 < pptTmp->y) |
| 709 |
box.y2 = pptTmp->y; |
| 710 |
} |
| 711 |
|
| 712 |
box.y2++; |
| 713 |
|
| 714 |
if (!pGC->miTranslate) { |
| 715 |
TRANSLATE_BOX(box, pDrawable); |
| 716 |
} |
| 717 |
TRIM_BOX(box, pGC); |
| 718 |
|
| 719 |
if (BOX_NOT_EMPTY(box)) |
| 720 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 721 |
} |
| 722 |
(*pGC->ops->SetSpans) (pDrawable, pGC, pcharsrc, ppt, pwidth, npt, fSorted); |
| 723 |
damageRegionProcessPending(pDrawable); |
| 724 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 725 |
} |
| 726 |
|
| 727 |
static void |
| 728 |
damagePutImage(DrawablePtr pDrawable, |
| 729 |
GCPtr pGC, |
| 730 |
int depth, |
| 731 |
int x, |
| 732 |
int y, int w, int h, int leftPad, int format, char *pImage) |
| 733 |
{ |
| 734 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 735 |
if (checkGCDamage(pDrawable, pGC)) { |
| 736 |
BoxRec box; |
| 737 |
|
| 738 |
box.x1 = x + pDrawable->x; |
| 739 |
box.x2 = box.x1 + w; |
| 740 |
box.y1 = y + pDrawable->y; |
| 741 |
box.y2 = box.y1 + h; |
| 742 |
|
| 743 |
TRIM_BOX(box, pGC); |
| 744 |
if (BOX_NOT_EMPTY(box)) |
| 745 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 746 |
} |
| 747 |
(*pGC->ops->PutImage) (pDrawable, pGC, depth, x, y, w, h, |
| 748 |
leftPad, format, pImage); |
| 749 |
damageRegionProcessPending(pDrawable); |
| 750 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 751 |
} |
| 752 |
|
| 753 |
static RegionPtr |
| 754 |
damageCopyArea(DrawablePtr pSrc, |
| 755 |
DrawablePtr pDst, |
| 756 |
GC * pGC, |
| 757 |
int srcx, int srcy, int width, int height, int dstx, int dsty) |
| 758 |
{ |
| 759 |
RegionPtr ret; |
| 760 |
|
| 761 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDst); |
| 762 |
|
| 763 |
if (checkGCDamage(pDst, pGC)) { |
| 764 |
BoxRec box; |
| 765 |
|
| 766 |
box.x1 = dstx + pDst->x; |
| 767 |
box.x2 = box.x1 + width; |
| 768 |
box.y1 = dsty + pDst->y; |
| 769 |
box.y2 = box.y1 + height; |
| 770 |
|
| 771 |
TRIM_BOX(box, pGC); |
| 772 |
if (BOX_NOT_EMPTY(box)) |
| 773 |
damageDamageBox(pDst, &box, pGC->subWindowMode); |
| 774 |
} |
| 775 |
|
| 776 |
ret = (*pGC->ops->CopyArea) (pSrc, pDst, |
| 777 |
pGC, srcx, srcy, width, height, dstx, dsty); |
| 778 |
damageRegionProcessPending(pDst); |
| 779 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDst); |
| 780 |
return ret; |
| 781 |
} |
| 782 |
|
| 783 |
static RegionPtr |
| 784 |
damageCopyPlane(DrawablePtr pSrc, |
| 785 |
DrawablePtr pDst, |
| 786 |
GCPtr pGC, |
| 787 |
int srcx, |
| 788 |
int srcy, |
| 789 |
int width, |
| 790 |
int height, int dstx, int dsty, unsigned long bitPlane) |
| 791 |
{ |
| 792 |
RegionPtr ret; |
| 793 |
|
| 794 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDst); |
| 795 |
|
| 796 |
if (checkGCDamage(pDst, pGC)) { |
| 797 |
BoxRec box; |
| 798 |
|
| 799 |
box.x1 = dstx + pDst->x; |
| 800 |
box.x2 = box.x1 + width; |
| 801 |
box.y1 = dsty + pDst->y; |
| 802 |
box.y2 = box.y1 + height; |
| 803 |
|
| 804 |
TRIM_BOX(box, pGC); |
| 805 |
if (BOX_NOT_EMPTY(box)) |
| 806 |
damageDamageBox(pDst, &box, pGC->subWindowMode); |
| 807 |
} |
| 808 |
|
| 809 |
ret = (*pGC->ops->CopyPlane) (pSrc, pDst, |
| 810 |
pGC, srcx, srcy, width, height, dstx, dsty, |
| 811 |
bitPlane); |
| 812 |
damageRegionProcessPending(pDst); |
| 813 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDst); |
| 814 |
return ret; |
| 815 |
} |
| 816 |
|
| 817 |
static void |
| 818 |
damagePolyPoint(DrawablePtr pDrawable, |
| 819 |
GCPtr pGC, int mode, int npt, xPoint * ppt) |
| 820 |
{ |
| 821 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 822 |
|
| 823 |
if (npt && checkGCDamage(pDrawable, pGC)) { |
| 824 |
BoxRec box; |
| 825 |
int nptTmp = npt; |
| 826 |
xPoint *pptTmp = ppt; |
| 827 |
|
| 828 |
box.x2 = box.x1 = pptTmp->x; |
| 829 |
box.y2 = box.y1 = pptTmp->y; |
| 830 |
|
| 831 |
/* this could be slow if the points were spread out */ |
| 832 |
|
| 833 |
if (mode == CoordModePrevious) { |
| 834 |
int x = box.x1; |
| 835 |
int y = box.y1; |
| 836 |
|
| 837 |
while (--nptTmp) { |
| 838 |
pptTmp++; |
| 839 |
x += pptTmp->x; |
| 840 |
y += pptTmp->y; |
| 841 |
if (box.x1 > x) |
| 842 |
box.x1 = x; |
| 843 |
else if (box.x2 < x) |
| 844 |
box.x2 = x; |
| 845 |
if (box.y1 > y) |
| 846 |
box.y1 = y; |
| 847 |
else if (box.y2 < y) |
| 848 |
box.y2 = y; |
| 849 |
} |
| 850 |
} |
| 851 |
else { |
| 852 |
while (--nptTmp) { |
| 853 |
pptTmp++; |
| 854 |
if (box.x1 > pptTmp->x) |
| 855 |
box.x1 = pptTmp->x; |
| 856 |
else if (box.x2 < pptTmp->x) |
| 857 |
box.x2 = pptTmp->x; |
| 858 |
if (box.y1 > pptTmp->y) |
| 859 |
box.y1 = pptTmp->y; |
| 860 |
else if (box.y2 < pptTmp->y) |
| 861 |
box.y2 = pptTmp->y; |
| 862 |
} |
| 863 |
} |
| 864 |
|
| 865 |
box.x2++; |
| 866 |
box.y2++; |
| 867 |
|
| 868 |
TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); |
| 869 |
if (BOX_NOT_EMPTY(box)) |
| 870 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 871 |
} |
| 872 |
(*pGC->ops->PolyPoint) (pDrawable, pGC, mode, npt, ppt); |
| 873 |
damageRegionProcessPending(pDrawable); |
| 874 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 875 |
} |
| 876 |
|
| 877 |
static void |
| 878 |
damagePolylines(DrawablePtr pDrawable, |
| 879 |
GCPtr pGC, int mode, int npt, DDXPointPtr ppt) |
| 880 |
{ |
| 881 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 882 |
|
| 883 |
if (npt && checkGCDamage(pDrawable, pGC)) { |
| 884 |
int nptTmp = npt; |
| 885 |
DDXPointPtr pptTmp = ppt; |
| 886 |
BoxRec box; |
| 887 |
int extra = pGC->lineWidth >> 1; |
| 888 |
|
| 889 |
box.x2 = box.x1 = pptTmp->x; |
| 890 |
box.y2 = box.y1 = pptTmp->y; |
| 891 |
|
| 892 |
if (nptTmp > 1) { |
| 893 |
if (pGC->joinStyle == JoinMiter) |
| 894 |
extra = 6 * pGC->lineWidth; |
| 895 |
else if (pGC->capStyle == CapProjecting) |
| 896 |
extra = pGC->lineWidth; |
| 897 |
} |
| 898 |
|
| 899 |
if (mode == CoordModePrevious) { |
| 900 |
int x = box.x1; |
| 901 |
int y = box.y1; |
| 902 |
|
| 903 |
while (--nptTmp) { |
| 904 |
pptTmp++; |
| 905 |
x += pptTmp->x; |
| 906 |
y += pptTmp->y; |
| 907 |
if (box.x1 > x) |
| 908 |
box.x1 = x; |
| 909 |
else if (box.x2 < x) |
| 910 |
box.x2 = x; |
| 911 |
if (box.y1 > y) |
| 912 |
box.y1 = y; |
| 913 |
else if (box.y2 < y) |
| 914 |
box.y2 = y; |
| 915 |
} |
| 916 |
} |
| 917 |
else { |
| 918 |
while (--nptTmp) { |
| 919 |
pptTmp++; |
| 920 |
if (box.x1 > pptTmp->x) |
| 921 |
box.x1 = pptTmp->x; |
| 922 |
else if (box.x2 < pptTmp->x) |
| 923 |
box.x2 = pptTmp->x; |
| 924 |
if (box.y1 > pptTmp->y) |
| 925 |
box.y1 = pptTmp->y; |
| 926 |
else if (box.y2 < pptTmp->y) |
| 927 |
box.y2 = pptTmp->y; |
| 928 |
} |
| 929 |
} |
| 930 |
|
| 931 |
box.x2++; |
| 932 |
box.y2++; |
| 933 |
|
| 934 |
if (extra) { |
| 935 |
box.x1 -= extra; |
| 936 |
box.x2 += extra; |
| 937 |
box.y1 -= extra; |
| 938 |
box.y2 += extra; |
| 939 |
} |
| 940 |
|
| 941 |
TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); |
| 942 |
if (BOX_NOT_EMPTY(box)) |
| 943 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 944 |
} |
| 945 |
(*pGC->ops->Polylines) (pDrawable, pGC, mode, npt, ppt); |
| 946 |
damageRegionProcessPending(pDrawable); |
| 947 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 948 |
} |
| 949 |
|
| 950 |
static void |
| 951 |
damagePolySegment(DrawablePtr pDrawable, GCPtr pGC, int nSeg, xSegment * pSeg) |
| 952 |
{ |
| 953 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 954 |
|
| 955 |
if (nSeg && checkGCDamage(pDrawable, pGC)) { |
| 956 |
BoxRec box; |
| 957 |
int extra = pGC->lineWidth; |
| 958 |
int nsegTmp = nSeg; |
| 959 |
xSegment *pSegTmp = pSeg; |
| 960 |
|
| 961 |
if (pGC->capStyle != CapProjecting) |
| 962 |
extra >>= 1; |
| 963 |
|
| 964 |
if (pSegTmp->x2 > pSegTmp->x1) { |
| 965 |
box.x1 = pSegTmp->x1; |
| 966 |
box.x2 = pSegTmp->x2; |
| 967 |
} |
| 968 |
else { |
| 969 |
box.x2 = pSegTmp->x1; |
| 970 |
box.x1 = pSegTmp->x2; |
| 971 |
} |
| 972 |
|
| 973 |
if (pSegTmp->y2 > pSegTmp->y1) { |
| 974 |
box.y1 = pSegTmp->y1; |
| 975 |
box.y2 = pSegTmp->y2; |
| 976 |
} |
| 977 |
else { |
| 978 |
box.y2 = pSegTmp->y1; |
| 979 |
box.y1 = pSegTmp->y2; |
| 980 |
} |
| 981 |
|
| 982 |
while (--nsegTmp) { |
| 983 |
pSegTmp++; |
| 984 |
if (pSegTmp->x2 > pSegTmp->x1) { |
| 985 |
if (pSegTmp->x1 < box.x1) |
| 986 |
box.x1 = pSegTmp->x1; |
| 987 |
if (pSegTmp->x2 > box.x2) |
| 988 |
box.x2 = pSegTmp->x2; |
| 989 |
} |
| 990 |
else { |
| 991 |
if (pSegTmp->x2 < box.x1) |
| 992 |
box.x1 = pSegTmp->x2; |
| 993 |
if (pSegTmp->x1 > box.x2) |
| 994 |
box.x2 = pSegTmp->x1; |
| 995 |
} |
| 996 |
if (pSegTmp->y2 > pSegTmp->y1) { |
| 997 |
if (pSegTmp->y1 < box.y1) |
| 998 |
box.y1 = pSegTmp->y1; |
| 999 |
if (pSegTmp->y2 > box.y2) |
| 1000 |
box.y2 = pSegTmp->y2; |
| 1001 |
} |
| 1002 |
else { |
| 1003 |
if (pSegTmp->y2 < box.y1) |
| 1004 |
box.y1 = pSegTmp->y2; |
| 1005 |
if (pSegTmp->y1 > box.y2) |
| 1006 |
box.y2 = pSegTmp->y1; |
| 1007 |
} |
| 1008 |
} |
| 1009 |
|
| 1010 |
box.x2++; |
| 1011 |
box.y2++; |
| 1012 |
|
| 1013 |
if (extra) { |
| 1014 |
box.x1 -= extra; |
| 1015 |
box.x2 += extra; |
| 1016 |
box.y1 -= extra; |
| 1017 |
box.y2 += extra; |
| 1018 |
} |
| 1019 |
|
| 1020 |
TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); |
| 1021 |
if (BOX_NOT_EMPTY(box)) |
| 1022 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 1023 |
} |
| 1024 |
(*pGC->ops->PolySegment) (pDrawable, pGC, nSeg, pSeg); |
| 1025 |
damageRegionProcessPending(pDrawable); |
| 1026 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 1027 |
} |
| 1028 |
|
| 1029 |
static void |
| 1030 |
damagePolyRectangle(DrawablePtr pDrawable, |
| 1031 |
GCPtr pGC, int nRects, xRectangle *pRects) |
| 1032 |
{ |
| 1033 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 1034 |
|
| 1035 |
if (nRects && checkGCDamage(pDrawable, pGC)) { |
| 1036 |
BoxRec box; |
| 1037 |
int offset1, offset2, offset3; |
| 1038 |
int nRectsTmp = nRects; |
| 1039 |
xRectangle *pRectsTmp = pRects; |
| 1040 |
|
| 1041 |
offset2 = pGC->lineWidth; |
| 1042 |
if (!offset2) |
| 1043 |
offset2 = 1; |
| 1044 |
offset1 = offset2 >> 1; |
| 1045 |
offset3 = offset2 - offset1; |
| 1046 |
|
| 1047 |
while (nRectsTmp--) { |
| 1048 |
box.x1 = pRectsTmp->x - offset1; |
| 1049 |
box.y1 = pRectsTmp->y - offset1; |
| 1050 |
box.x2 = box.x1 + pRectsTmp->width + offset2; |
| 1051 |
box.y2 = box.y1 + offset2; |
| 1052 |
TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); |
| 1053 |
if (BOX_NOT_EMPTY(box)) |
| 1054 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 1055 |
|
| 1056 |
box.x1 = pRectsTmp->x - offset1; |
| 1057 |
box.y1 = pRectsTmp->y + offset3; |
| 1058 |
box.x2 = box.x1 + offset2; |
| 1059 |
box.y2 = box.y1 + pRectsTmp->height - offset2; |
| 1060 |
TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); |
| 1061 |
if (BOX_NOT_EMPTY(box)) |
| 1062 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 1063 |
|
| 1064 |
box.x1 = pRectsTmp->x + pRectsTmp->width - offset1; |
| 1065 |
box.y1 = pRectsTmp->y + offset3; |
| 1066 |
box.x2 = box.x1 + offset2; |
| 1067 |
box.y2 = box.y1 + pRectsTmp->height - offset2; |
| 1068 |
TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); |
| 1069 |
if (BOX_NOT_EMPTY(box)) |
| 1070 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 1071 |
|
| 1072 |
box.x1 = pRectsTmp->x - offset1; |
| 1073 |
box.y1 = pRectsTmp->y + pRectsTmp->height - offset1; |
| 1074 |
box.x2 = box.x1 + pRectsTmp->width + offset2; |
| 1075 |
box.y2 = box.y1 + offset2; |
| 1076 |
TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); |
| 1077 |
if (BOX_NOT_EMPTY(box)) |
| 1078 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 1079 |
|
| 1080 |
pRectsTmp++; |
| 1081 |
} |
| 1082 |
} |
| 1083 |
(*pGC->ops->PolyRectangle) (pDrawable, pGC, nRects, pRects); |
| 1084 |
damageRegionProcessPending(pDrawable); |
| 1085 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 1086 |
} |
| 1087 |
|
| 1088 |
static void |
| 1089 |
damagePolyArc(DrawablePtr pDrawable, GCPtr pGC, int nArcs, xArc * pArcs) |
| 1090 |
{ |
| 1091 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 1092 |
|
| 1093 |
if (nArcs && checkGCDamage(pDrawable, pGC)) { |
| 1094 |
int extra = pGC->lineWidth >> 1; |
| 1095 |
BoxRec box; |
| 1096 |
int nArcsTmp = nArcs; |
| 1097 |
xArc *pArcsTmp = pArcs; |
| 1098 |
|
| 1099 |
box.x1 = pArcsTmp->x; |
| 1100 |
box.x2 = box.x1 + pArcsTmp->width; |
| 1101 |
box.y1 = pArcsTmp->y; |
| 1102 |
box.y2 = box.y1 + pArcsTmp->height; |
| 1103 |
|
| 1104 |
while (--nArcsTmp) { |
| 1105 |
pArcsTmp++; |
| 1106 |
if (box.x1 > pArcsTmp->x) |
| 1107 |
box.x1 = pArcsTmp->x; |
| 1108 |
if (box.x2 < (pArcsTmp->x + pArcsTmp->width)) |
| 1109 |
box.x2 = pArcsTmp->x + pArcsTmp->width; |
| 1110 |
if (box.y1 > pArcsTmp->y) |
| 1111 |
box.y1 = pArcsTmp->y; |
| 1112 |
if (box.y2 < (pArcsTmp->y + pArcsTmp->height)) |
| 1113 |
box.y2 = pArcsTmp->y + pArcsTmp->height; |
| 1114 |
} |
| 1115 |
|
| 1116 |
if (extra) { |
| 1117 |
box.x1 -= extra; |
| 1118 |
box.x2 += extra; |
| 1119 |
box.y1 -= extra; |
| 1120 |
box.y2 += extra; |
| 1121 |
} |
| 1122 |
|
| 1123 |
box.x2++; |
| 1124 |
box.y2++; |
| 1125 |
|
| 1126 |
TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); |
| 1127 |
if (BOX_NOT_EMPTY(box)) |
| 1128 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 1129 |
} |
| 1130 |
(*pGC->ops->PolyArc) (pDrawable, pGC, nArcs, pArcs); |
| 1131 |
damageRegionProcessPending(pDrawable); |
| 1132 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 1133 |
} |
| 1134 |
|
| 1135 |
static void |
| 1136 |
damageFillPolygon(DrawablePtr pDrawable, |
| 1137 |
GCPtr pGC, int shape, int mode, int npt, DDXPointPtr ppt) |
| 1138 |
{ |
| 1139 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 1140 |
|
| 1141 |
if (npt > 2 && checkGCDamage(pDrawable, pGC)) { |
| 1142 |
DDXPointPtr pptTmp = ppt; |
| 1143 |
int nptTmp = npt; |
| 1144 |
BoxRec box; |
| 1145 |
|
| 1146 |
box.x2 = box.x1 = pptTmp->x; |
| 1147 |
box.y2 = box.y1 = pptTmp->y; |
| 1148 |
|
| 1149 |
if (mode != CoordModeOrigin) { |
| 1150 |
int x = box.x1; |
| 1151 |
int y = box.y1; |
| 1152 |
|
| 1153 |
while (--nptTmp) { |
| 1154 |
pptTmp++; |
| 1155 |
x += pptTmp->x; |
| 1156 |
y += pptTmp->y; |
| 1157 |
if (box.x1 > x) |
| 1158 |
box.x1 = x; |
| 1159 |
else if (box.x2 < x) |
| 1160 |
box.x2 = x; |
| 1161 |
if (box.y1 > y) |
| 1162 |
box.y1 = y; |
| 1163 |
else if (box.y2 < y) |
| 1164 |
box.y2 = y; |
| 1165 |
} |
| 1166 |
} |
| 1167 |
else { |
| 1168 |
while (--nptTmp) { |
| 1169 |
pptTmp++; |
| 1170 |
if (box.x1 > pptTmp->x) |
| 1171 |
box.x1 = pptTmp->x; |
| 1172 |
else if (box.x2 < pptTmp->x) |
| 1173 |
box.x2 = pptTmp->x; |
| 1174 |
if (box.y1 > pptTmp->y) |
| 1175 |
box.y1 = pptTmp->y; |
| 1176 |
else if (box.y2 < pptTmp->y) |
| 1177 |
box.y2 = pptTmp->y; |
| 1178 |
} |
| 1179 |
} |
| 1180 |
|
| 1181 |
box.x2++; |
| 1182 |
box.y2++; |
| 1183 |
|
| 1184 |
TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); |
| 1185 |
if (BOX_NOT_EMPTY(box)) |
| 1186 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 1187 |
} |
| 1188 |
|
| 1189 |
(*pGC->ops->FillPolygon) (pDrawable, pGC, shape, mode, npt, ppt); |
| 1190 |
damageRegionProcessPending(pDrawable); |
| 1191 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 1192 |
} |
| 1193 |
|
| 1194 |
static void |
| 1195 |
damagePolyFillRect(DrawablePtr pDrawable, |
| 1196 |
GCPtr pGC, int nRects, xRectangle *pRects) |
| 1197 |
{ |
| 1198 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 1199 |
if (nRects && checkGCDamage(pDrawable, pGC)) { |
| 1200 |
BoxRec box; |
| 1201 |
xRectangle *pRectsTmp = pRects; |
| 1202 |
int nRectsTmp = nRects; |
| 1203 |
|
| 1204 |
box.x1 = pRectsTmp->x; |
| 1205 |
box.x2 = box.x1 + pRectsTmp->width; |
| 1206 |
box.y1 = pRectsTmp->y; |
| 1207 |
box.y2 = box.y1 + pRectsTmp->height; |
| 1208 |
|
| 1209 |
while (--nRectsTmp) { |
| 1210 |
pRectsTmp++; |
| 1211 |
if (box.x1 > pRectsTmp->x) |
| 1212 |
box.x1 = pRectsTmp->x; |
| 1213 |
if (box.x2 < (pRectsTmp->x + pRectsTmp->width)) |
| 1214 |
box.x2 = pRectsTmp->x + pRectsTmp->width; |
| 1215 |
if (box.y1 > pRectsTmp->y) |
| 1216 |
box.y1 = pRectsTmp->y; |
| 1217 |
if (box.y2 < (pRectsTmp->y + pRectsTmp->height)) |
| 1218 |
box.y2 = pRectsTmp->y + pRectsTmp->height; |
| 1219 |
} |
| 1220 |
|
| 1221 |
TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); |
| 1222 |
if (BOX_NOT_EMPTY(box)) |
| 1223 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 1224 |
} |
| 1225 |
(*pGC->ops->PolyFillRect) (pDrawable, pGC, nRects, pRects); |
| 1226 |
damageRegionProcessPending(pDrawable); |
| 1227 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 1228 |
} |
| 1229 |
|
| 1230 |
static void |
| 1231 |
damagePolyFillArc(DrawablePtr pDrawable, GCPtr pGC, int nArcs, xArc * pArcs) |
| 1232 |
{ |
| 1233 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 1234 |
|
| 1235 |
if (nArcs && checkGCDamage(pDrawable, pGC)) { |
| 1236 |
BoxRec box; |
| 1237 |
int nArcsTmp = nArcs; |
| 1238 |
xArc *pArcsTmp = pArcs; |
| 1239 |
|
| 1240 |
box.x1 = pArcsTmp->x; |
| 1241 |
box.x2 = box.x1 + pArcsTmp->width; |
| 1242 |
box.y1 = pArcsTmp->y; |
| 1243 |
box.y2 = box.y1 + pArcsTmp->height; |
| 1244 |
|
| 1245 |
while (--nArcsTmp) { |
| 1246 |
pArcsTmp++; |
| 1247 |
if (box.x1 > pArcsTmp->x) |
| 1248 |
box.x1 = pArcsTmp->x; |
| 1249 |
if (box.x2 < (pArcsTmp->x + pArcsTmp->width)) |
| 1250 |
box.x2 = pArcsTmp->x + pArcsTmp->width; |
| 1251 |
if (box.y1 > pArcsTmp->y) |
| 1252 |
box.y1 = pArcsTmp->y; |
| 1253 |
if (box.y2 < (pArcsTmp->y + pArcsTmp->height)) |
| 1254 |
box.y2 = pArcsTmp->y + pArcsTmp->height; |
| 1255 |
} |
| 1256 |
|
| 1257 |
TRIM_AND_TRANSLATE_BOX(box, pDrawable, pGC); |
| 1258 |
if (BOX_NOT_EMPTY(box)) |
| 1259 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 1260 |
} |
| 1261 |
(*pGC->ops->PolyFillArc) (pDrawable, pGC, nArcs, pArcs); |
| 1262 |
damageRegionProcessPending(pDrawable); |
| 1263 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 1264 |
} |
| 1265 |
|
| 1266 |
/* |
| 1267 |
* general Poly/Image text function. Extract glyph information, |
| 1268 |
* compute bounding box and remove cursor if it is overlapped. |
| 1269 |
*/ |
| 1270 |
|
| 1271 |
static void |
| 1272 |
damageDamageChars(DrawablePtr pDrawable, |
| 1273 |
FontPtr font, |
| 1274 |
int x, |
| 1275 |
int y, |
| 1276 |
unsigned int n, |
| 1277 |
CharInfoPtr * charinfo, Bool imageblt, int subWindowMode) |
| 1278 |
{ |
| 1279 |
ExtentInfoRec extents; |
| 1280 |
BoxRec box; |
| 1281 |
|
| 1282 |
xfont2_query_glyph_extents(font, charinfo, n, &extents); |
| 1283 |
if (imageblt) { |
| 1284 |
if (extents.overallWidth > extents.overallRight) |
| 1285 |
extents.overallRight = extents.overallWidth; |
| 1286 |
if (extents.overallWidth < extents.overallLeft) |
| 1287 |
extents.overallLeft = extents.overallWidth; |
| 1288 |
if (extents.overallLeft > 0) |
| 1289 |
extents.overallLeft = 0; |
| 1290 |
if (extents.fontAscent > extents.overallAscent) |
| 1291 |
extents.overallAscent = extents.fontAscent; |
| 1292 |
if (extents.fontDescent > extents.overallDescent) |
| 1293 |
extents.overallDescent = extents.fontDescent; |
| 1294 |
} |
| 1295 |
box.x1 = x + extents.overallLeft; |
| 1296 |
box.y1 = y - extents.overallAscent; |
| 1297 |
box.x2 = x + extents.overallRight; |
| 1298 |
box.y2 = y + extents.overallDescent; |
| 1299 |
damageDamageBox(pDrawable, &box, subWindowMode); |
| 1300 |
} |
| 1301 |
|
| 1302 |
/* |
| 1303 |
* values for textType: |
| 1304 |
*/ |
| 1305 |
#define TT_POLY8 0 |
| 1306 |
#define TT_IMAGE8 1 |
| 1307 |
#define TT_POLY16 2 |
| 1308 |
#define TT_IMAGE16 3 |
| 1309 |
|
| 1310 |
static void |
| 1311 |
damageText(DrawablePtr pDrawable, |
| 1312 |
GCPtr pGC, |
| 1313 |
int x, |
| 1314 |
int y, |
| 1315 |
unsigned long count, |
| 1316 |
char *chars, FontEncoding fontEncoding, Bool textType) |
| 1317 |
{ |
| 1318 |
CharInfoPtr *charinfo; |
| 1319 |
unsigned long i; |
| 1320 |
unsigned int n; |
| 1321 |
Bool imageblt; |
| 1322 |
|
| 1323 |
imageblt = (textType == TT_IMAGE8) || (textType == TT_IMAGE16); |
| 1324 |
|
| 1325 |
if (!checkGCDamage(pDrawable, pGC)) |
| 1326 |
return; |
| 1327 |
|
| 1328 |
charinfo = xallocarray(count, sizeof(CharInfoPtr)); |
| 1329 |
if (!charinfo) |
| 1330 |
return; |
| 1331 |
|
| 1332 |
GetGlyphs(pGC->font, count, (unsigned char *) chars, |
| 1333 |
fontEncoding, &i, charinfo); |
| 1334 |
n = (unsigned int) i; |
| 1335 |
|
| 1336 |
if (n != 0) { |
| 1337 |
damageDamageChars(pDrawable, pGC->font, x + pDrawable->x, |
| 1338 |
y + pDrawable->y, n, charinfo, imageblt, |
| 1339 |
pGC->subWindowMode); |
| 1340 |
} |
| 1341 |
free(charinfo); |
| 1342 |
} |
| 1343 |
|
| 1344 |
static int |
| 1345 |
damagePolyText8(DrawablePtr pDrawable, |
| 1346 |
GCPtr pGC, int x, int y, int count, char *chars) |
| 1347 |
{ |
| 1348 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 1349 |
damageText(pDrawable, pGC, x, y, (unsigned long) count, chars, Linear8Bit, |
| 1350 |
TT_POLY8); |
| 1351 |
x = (*pGC->ops->PolyText8) (pDrawable, pGC, x, y, count, chars); |
| 1352 |
damageRegionProcessPending(pDrawable); |
| 1353 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 1354 |
return x; |
| 1355 |
} |
| 1356 |
|
| 1357 |
static int |
| 1358 |
damagePolyText16(DrawablePtr pDrawable, |
| 1359 |
GCPtr pGC, int x, int y, int count, unsigned short *chars) |
| 1360 |
{ |
| 1361 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 1362 |
damageText(pDrawable, pGC, x, y, (unsigned long) count, (char *) chars, |
| 1363 |
FONTLASTROW(pGC->font) == 0 ? Linear16Bit : TwoD16Bit, |
| 1364 |
TT_POLY16); |
| 1365 |
x = (*pGC->ops->PolyText16) (pDrawable, pGC, x, y, count, chars); |
| 1366 |
damageRegionProcessPending(pDrawable); |
| 1367 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 1368 |
return x; |
| 1369 |
} |
| 1370 |
|
| 1371 |
static void |
| 1372 |
damageImageText8(DrawablePtr pDrawable, |
| 1373 |
GCPtr pGC, int x, int y, int count, char *chars) |
| 1374 |
{ |
| 1375 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 1376 |
damageText(pDrawable, pGC, x, y, (unsigned long) count, chars, Linear8Bit, |
| 1377 |
TT_IMAGE8); |
| 1378 |
(*pGC->ops->ImageText8) (pDrawable, pGC, x, y, count, chars); |
| 1379 |
damageRegionProcessPending(pDrawable); |
| 1380 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 1381 |
} |
| 1382 |
|
| 1383 |
static void |
| 1384 |
damageImageText16(DrawablePtr pDrawable, |
| 1385 |
GCPtr pGC, int x, int y, int count, unsigned short *chars) |
| 1386 |
{ |
| 1387 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 1388 |
damageText(pDrawable, pGC, x, y, (unsigned long) count, (char *) chars, |
| 1389 |
FONTLASTROW(pGC->font) == 0 ? Linear16Bit : TwoD16Bit, |
| 1390 |
TT_IMAGE16); |
| 1391 |
(*pGC->ops->ImageText16) (pDrawable, pGC, x, y, count, chars); |
| 1392 |
damageRegionProcessPending(pDrawable); |
| 1393 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 1394 |
} |
| 1395 |
|
| 1396 |
static void |
| 1397 |
damageImageGlyphBlt(DrawablePtr pDrawable, |
| 1398 |
GCPtr pGC, |
| 1399 |
int x, |
| 1400 |
int y, |
| 1401 |
unsigned int nglyph, CharInfoPtr * ppci, void *pglyphBase) |
| 1402 |
{ |
| 1403 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 1404 |
damageDamageChars(pDrawable, pGC->font, x + pDrawable->x, y + pDrawable->y, |
| 1405 |
nglyph, ppci, TRUE, pGC->subWindowMode); |
| 1406 |
(*pGC->ops->ImageGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase); |
| 1407 |
damageRegionProcessPending(pDrawable); |
| 1408 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 1409 |
} |
| 1410 |
|
| 1411 |
static void |
| 1412 |
damagePolyGlyphBlt(DrawablePtr pDrawable, |
| 1413 |
GCPtr pGC, |
| 1414 |
int x, |
| 1415 |
int y, |
| 1416 |
unsigned int nglyph, CharInfoPtr * ppci, void *pglyphBase) |
| 1417 |
{ |
| 1418 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 1419 |
damageDamageChars(pDrawable, pGC->font, x + pDrawable->x, y + pDrawable->y, |
| 1420 |
nglyph, ppci, FALSE, pGC->subWindowMode); |
| 1421 |
(*pGC->ops->PolyGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase); |
| 1422 |
damageRegionProcessPending(pDrawable); |
| 1423 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 1424 |
} |
| 1425 |
|
| 1426 |
static void |
| 1427 |
damagePushPixels(GCPtr pGC, |
| 1428 |
PixmapPtr pBitMap, |
| 1429 |
DrawablePtr pDrawable, int dx, int dy, int xOrg, int yOrg) |
| 1430 |
{ |
| 1431 |
DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable); |
| 1432 |
if (checkGCDamage(pDrawable, pGC)) { |
| 1433 |
BoxRec box; |
| 1434 |
|
| 1435 |
box.x1 = xOrg; |
| 1436 |
box.y1 = yOrg; |
| 1437 |
|
| 1438 |
if (!pGC->miTranslate) { |
| 1439 |
box.x1 += pDrawable->x; |
| 1440 |
box.y1 += pDrawable->y; |
| 1441 |
} |
| 1442 |
|
| 1443 |
box.x2 = box.x1 + dx; |
| 1444 |
box.y2 = box.y1 + dy; |
| 1445 |
|
| 1446 |
TRIM_BOX(box, pGC); |
| 1447 |
if (BOX_NOT_EMPTY(box)) |
| 1448 |
damageDamageBox(pDrawable, &box, pGC->subWindowMode); |
| 1449 |
} |
| 1450 |
(*pGC->ops->PushPixels) (pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg); |
| 1451 |
damageRegionProcessPending(pDrawable); |
| 1452 |
DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable); |
| 1453 |
} |
| 1454 |
|
| 1455 |
static void |
| 1456 |
damageRemoveDamage(DamagePtr * pPrev, DamagePtr pDamage) |
| 1457 |
{ |
| 1458 |
while (*pPrev) { |
| 1459 |
if (*pPrev == pDamage) { |
| 1460 |
*pPrev = pDamage->pNext; |
| 1461 |
return; |
| 1462 |
} |
| 1463 |
pPrev = &(*pPrev)->pNext; |
| 1464 |
} |
| 1465 |
#if DAMAGE_VALIDATE_ENABLE |
| 1466 |
ErrorF("Damage not on list\n"); |
| 1467 |
OsAbort(); |
| 1468 |
#endif |
| 1469 |
} |
| 1470 |
|
| 1471 |
static void |
| 1472 |
damageInsertDamage(DamagePtr * pPrev, DamagePtr pDamage) |
| 1473 |
{ |
| 1474 |
#if DAMAGE_VALIDATE_ENABLE |
| 1475 |
DamagePtr pOld; |
| 1476 |
|
| 1477 |
for (pOld = *pPrev; pOld; pOld = pOld->pNext) |
| 1478 |
if (pOld == pDamage) { |
| 1479 |
ErrorF("Damage already on list\n"); |
| 1480 |
OsAbort(); |
| 1481 |
} |
| 1482 |
#endif |
| 1483 |
pDamage->pNext = *pPrev; |
| 1484 |
*pPrev = pDamage; |
| 1485 |
} |
| 1486 |
|
| 1487 |
static Bool |
| 1488 |
damageDestroyPixmap(PixmapPtr pPixmap) |
| 1489 |
{ |
| 1490 |
ScreenPtr pScreen = pPixmap->drawable.pScreen; |
| 1491 |
|
| 1492 |
damageScrPriv(pScreen); |
| 1493 |
|
| 1494 |
if (pPixmap->refcnt == 1) { |
| 1495 |
DamagePtr *pPrev = getPixmapDamageRef(pPixmap); |
| 1496 |
DamagePtr pDamage; |
| 1497 |
|
| 1498 |
while ((pDamage = *pPrev)) { |
| 1499 |
damageRemoveDamage(pPrev, pDamage); |
| 1500 |
if (!pDamage->isWindow) |
| 1501 |
DamageDestroy(pDamage); |
| 1502 |
} |
| 1503 |
} |
| 1504 |
unwrap(pScrPriv, pScreen, DestroyPixmap); |
| 1505 |
(*pScreen->DestroyPixmap) (pPixmap); |
| 1506 |
wrap(pScrPriv, pScreen, DestroyPixmap, damageDestroyPixmap); |
| 1507 |
return TRUE; |
| 1508 |
} |
| 1509 |
|
| 1510 |
static void |
| 1511 |
damageCopyWindow(WindowPtr pWindow, DDXPointRec ptOldOrg, RegionPtr prgnSrc) |
| 1512 |
{ |
| 1513 |
ScreenPtr pScreen = pWindow->drawable.pScreen; |
| 1514 |
|
| 1515 |
damageScrPriv(pScreen); |
| 1516 |
|
| 1517 |
if (getWindowDamage(pWindow)) { |
| 1518 |
int dx = pWindow->drawable.x - ptOldOrg.x; |
| 1519 |
int dy = pWindow->drawable.y - ptOldOrg.y; |
| 1520 |
|
| 1521 |
/* |
| 1522 |
* The region comes in source relative, but the damage occurs |
| 1523 |
* at the destination location. Translate back and forth. |
| 1524 |
*/ |
| 1525 |
RegionTranslate(prgnSrc, dx, dy); |
| 1526 |
damageRegionAppend(&pWindow->drawable, prgnSrc, FALSE, -1); |
| 1527 |
RegionTranslate(prgnSrc, -dx, -dy); |
| 1528 |
} |
| 1529 |
unwrap(pScrPriv, pScreen, CopyWindow); |
| 1530 |
(*pScreen->CopyWindow) (pWindow, ptOldOrg, prgnSrc); |
| 1531 |
damageRegionProcessPending(&pWindow->drawable); |
| 1532 |
wrap(pScrPriv, pScreen, CopyWindow, damageCopyWindow); |
| 1533 |
} |
| 1534 |
|
| 1535 |
static GCOps damageGCOps = { |
| 1536 |
damageFillSpans, damageSetSpans, |
| 1537 |
damagePutImage, damageCopyArea, |
| 1538 |
damageCopyPlane, damagePolyPoint, |
| 1539 |
damagePolylines, damagePolySegment, |
| 1540 |
damagePolyRectangle, damagePolyArc, |
| 1541 |
damageFillPolygon, damagePolyFillRect, |
| 1542 |
damagePolyFillArc, damagePolyText8, |
| 1543 |
damagePolyText16, damageImageText8, |
| 1544 |
damageImageText16, damageImageGlyphBlt, |
| 1545 |
damagePolyGlyphBlt, damagePushPixels, |
| 1546 |
}; |
| 1547 |
|
| 1548 |
static void |
| 1549 |
damageSetWindowPixmap(WindowPtr pWindow, PixmapPtr pPixmap) |
| 1550 |
{ |
| 1551 |
DamagePtr pDamage; |
| 1552 |
ScreenPtr pScreen = pWindow->drawable.pScreen; |
| 1553 |
|
| 1554 |
damageScrPriv(pScreen); |
| 1555 |
|
| 1556 |
if ((pDamage = damageGetWinPriv(pWindow))) { |
| 1557 |
PixmapPtr pOldPixmap = (*pScreen->GetWindowPixmap) (pWindow); |
| 1558 |
DamagePtr *pPrev = getPixmapDamageRef(pOldPixmap); |
| 1559 |
|
| 1560 |
while (pDamage) { |
| 1561 |
damageRemoveDamage(pPrev, pDamage); |
| 1562 |
pDamage = pDamage->pNextWin; |
| 1563 |
} |
| 1564 |
} |
| 1565 |
unwrap(pScrPriv, pScreen, SetWindowPixmap); |
| 1566 |
(*pScreen->SetWindowPixmap) (pWindow, pPixmap); |
| 1567 |
wrap(pScrPriv, pScreen, SetWindowPixmap, damageSetWindowPixmap); |
| 1568 |
if ((pDamage = damageGetWinPriv(pWindow))) { |
| 1569 |
DamagePtr *pPrev = getPixmapDamageRef(pPixmap); |
| 1570 |
|
| 1571 |
while (pDamage) { |
| 1572 |
damageInsertDamage(pPrev, pDamage); |
| 1573 |
pDamage = pDamage->pNextWin; |
| 1574 |
} |
| 1575 |
} |
| 1576 |
} |
| 1577 |
|
| 1578 |
static Bool |
| 1579 |
damageDestroyWindow(WindowPtr pWindow) |
| 1580 |
{ |
| 1581 |
DamagePtr pDamage; |
| 1582 |
ScreenPtr pScreen = pWindow->drawable.pScreen; |
| 1583 |
Bool ret; |
| 1584 |
|
| 1585 |
damageScrPriv(pScreen); |
| 1586 |
|
| 1587 |
while ((pDamage = damageGetWinPriv(pWindow))) { |
| 1588 |
DamageDestroy(pDamage); |
| 1589 |
} |
| 1590 |
unwrap(pScrPriv, pScreen, DestroyWindow); |
| 1591 |
ret = (*pScreen->DestroyWindow) (pWindow); |
| 1592 |
wrap(pScrPriv, pScreen, DestroyWindow, damageDestroyWindow); |
| 1593 |
return ret; |
| 1594 |
} |
| 1595 |
|
| 1596 |
static Bool |
| 1597 |
damageCloseScreen(ScreenPtr pScreen) |
| 1598 |
{ |
| 1599 |
damageScrPriv(pScreen); |
| 1600 |
|
| 1601 |
unwrap(pScrPriv, pScreen, DestroyPixmap); |
| 1602 |
unwrap(pScrPriv, pScreen, CreateGC); |
| 1603 |
unwrap(pScrPriv, pScreen, CopyWindow); |
| 1604 |
unwrap(pScrPriv, pScreen, CloseScreen); |
| 1605 |
free(pScrPriv); |
| 1606 |
return (*pScreen->CloseScreen) (pScreen); |
| 1607 |
} |
| 1608 |
|
| 1609 |
/** |
| 1610 |
* Default implementations of the damage management functions. |
| 1611 |
*/ |
| 1612 |
void |
| 1613 |
miDamageCreate(DamagePtr pDamage) |
| 1614 |
{ |
| 1615 |
} |
| 1616 |
|
| 1617 |
/* |
| 1618 |
* We only wrap into the GC when there's a registered listener. For windows, |
| 1619 |
* damage includes damage to children. So if there's a GC validated against |
| 1620 |
* a subwindow and we then register a damage on the parent, we need to bump |
| 1621 |
* the serial numbers of the children to re-trigger validation. |
| 1622 |
* |
| 1623 |
* Since we can't know if a GC has been validated against one of the affected |
| 1624 |
* children, just bump them all to be safe. |
| 1625 |
*/ |
| 1626 |
static int |
| 1627 |
damageRegisterVisit(WindowPtr pWin, void *data) |
| 1628 |
{ |
| 1629 |
pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; |
| 1630 |
return WT_WALKCHILDREN; |
| 1631 |
} |
| 1632 |
|
| 1633 |
void |
| 1634 |
miDamageRegister(DrawablePtr pDrawable, DamagePtr pDamage) |
| 1635 |
{ |
| 1636 |
if (pDrawable->type == DRAWABLE_WINDOW) |
| 1637 |
TraverseTree((WindowPtr)pDrawable, damageRegisterVisit, NULL); |
| 1638 |
else |
| 1639 |
pDrawable->serialNumber = NEXT_SERIAL_NUMBER; |
| 1640 |
} |
| 1641 |
|
| 1642 |
void |
| 1643 |
miDamageUnregister(DrawablePtr pDrawable, DamagePtr pDamage) |
| 1644 |
{ |
| 1645 |
if (pDrawable->type == DRAWABLE_WINDOW) |
| 1646 |
TraverseTree((WindowPtr)pDrawable, damageRegisterVisit, NULL); |
| 1647 |
else |
| 1648 |
pDrawable->serialNumber = NEXT_SERIAL_NUMBER; |
| 1649 |
} |
| 1650 |
|
| 1651 |
void |
| 1652 |
miDamageDestroy(DamagePtr pDamage) |
| 1653 |
{ |
| 1654 |
} |
| 1655 |
|
| 1656 |
/** |
| 1657 |
* Public functions for consumption outside this file. |
| 1658 |
*/ |
| 1659 |
|
| 1660 |
Bool |
| 1661 |
DamageSetup(ScreenPtr pScreen) |
| 1662 |
{ |
| 1663 |
DamageScrPrivPtr pScrPriv; |
| 1664 |
PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); |
| 1665 |
|
| 1666 |
const DamageScreenFuncsRec miFuncs = { |
| 1667 |
miDamageCreate, miDamageRegister, miDamageUnregister, miDamageDestroy |
| 1668 |
}; |
| 1669 |
|
| 1670 |
if (!dixRegisterPrivateKey(&damageScrPrivateKeyRec, PRIVATE_SCREEN, 0)) |
| 1671 |
return FALSE; |
| 1672 |
|
| 1673 |
if (dixLookupPrivate(&pScreen->devPrivates, damageScrPrivateKey)) |
| 1674 |
return TRUE; |
| 1675 |
|
| 1676 |
if (!dixRegisterPrivateKey |
| 1677 |
(&damageGCPrivateKeyRec, PRIVATE_GC, sizeof(DamageGCPrivRec))) |
| 1678 |
return FALSE; |
| 1679 |
|
| 1680 |
if (!dixRegisterPrivateKey(&damagePixPrivateKeyRec, PRIVATE_PIXMAP, 0)) |
| 1681 |
return FALSE; |
| 1682 |
|
| 1683 |
if (!dixRegisterPrivateKey(&damageWinPrivateKeyRec, PRIVATE_WINDOW, 0)) |
| 1684 |
return FALSE; |
| 1685 |
|
| 1686 |
pScrPriv = malloc(sizeof(DamageScrPrivRec)); |
| 1687 |
if (!pScrPriv) |
| 1688 |
return FALSE; |
| 1689 |
|
| 1690 |
pScrPriv->internalLevel = 0; |
| 1691 |
pScrPriv->pScreenDamage = 0; |
| 1692 |
|
| 1693 |
wrap(pScrPriv, pScreen, DestroyPixmap, damageDestroyPixmap); |
| 1694 |
wrap(pScrPriv, pScreen, CreateGC, damageCreateGC); |
| 1695 |
wrap(pScrPriv, pScreen, DestroyWindow, damageDestroyWindow); |
| 1696 |
wrap(pScrPriv, pScreen, SetWindowPixmap, damageSetWindowPixmap); |
| 1697 |
wrap(pScrPriv, pScreen, CopyWindow, damageCopyWindow); |
| 1698 |
wrap(pScrPriv, pScreen, CloseScreen, damageCloseScreen); |
| 1699 |
if (ps) { |
| 1700 |
wrap(pScrPriv, ps, Glyphs, damageGlyphs); |
| 1701 |
wrap(pScrPriv, ps, Composite, damageComposite); |
| 1702 |
wrap(pScrPriv, ps, AddTraps, damageAddTraps); |
| 1703 |
} |
| 1704 |
|
| 1705 |
pScrPriv->funcs = miFuncs; |
| 1706 |
|
| 1707 |
dixSetPrivate(&pScreen->devPrivates, damageScrPrivateKey, pScrPriv); |
| 1708 |
return TRUE; |
| 1709 |
} |
| 1710 |
|
| 1711 |
DamagePtr |
| 1712 |
DamageCreate(DamageReportFunc damageReport, |
| 1713 |
DamageDestroyFunc damageDestroy, |
| 1714 |
DamageReportLevel damageLevel, |
| 1715 |
Bool isInternal, ScreenPtr pScreen, void *closure) |
| 1716 |
{ |
| 1717 |
damageScrPriv(pScreen); |
| 1718 |
DamagePtr pDamage; |
| 1719 |
|
| 1720 |
pDamage = calloc(1, sizeof(DamageRec)); |
| 1721 |
if (!pDamage) |
| 1722 |
return 0; |
| 1723 |
pDamage->pNext = 0; |
| 1724 |
pDamage->pNextWin = 0; |
| 1725 |
RegionNull(&pDamage->damage); |
| 1726 |
RegionNull(&pDamage->pendingDamage); |
| 1727 |
|
| 1728 |
pDamage->damageLevel = damageLevel; |
| 1729 |
pDamage->isInternal = isInternal; |
| 1730 |
pDamage->closure = closure; |
| 1731 |
pDamage->isWindow = FALSE; |
| 1732 |
pDamage->pDrawable = 0; |
| 1733 |
pDamage->reportAfter = FALSE; |
| 1734 |
|
| 1735 |
pDamage->damageReport = damageReport; |
| 1736 |
pDamage->damageDestroy = damageDestroy; |
| 1737 |
pDamage->pScreen = pScreen; |
| 1738 |
|
| 1739 |
(*pScrPriv->funcs.Create) (pDamage); |
| 1740 |
|
| 1741 |
return pDamage; |
| 1742 |
} |
| 1743 |
|
| 1744 |
void |
| 1745 |
DamageRegister(DrawablePtr pDrawable, DamagePtr pDamage) |
| 1746 |
{ |
| 1747 |
ScreenPtr pScreen = pDrawable->pScreen; |
| 1748 |
|
| 1749 |
damageScrPriv(pScreen); |
| 1750 |
|
| 1751 |
#if DAMAGE_VALIDATE_ENABLE |
| 1752 |
if (pDrawable->pScreen != pDamage->pScreen) { |
| 1753 |
ErrorF("DamageRegister called with mismatched screens\n"); |
| 1754 |
OsAbort(); |
| 1755 |
} |
| 1756 |
#endif |
| 1757 |
|
| 1758 |
if (pDrawable->type == DRAWABLE_WINDOW) { |
| 1759 |
WindowPtr pWindow = (WindowPtr) pDrawable; |
| 1760 |
|
| 1761 |
winDamageRef(pWindow); |
| 1762 |
|
| 1763 |
#if DAMAGE_VALIDATE_ENABLE |
| 1764 |
DamagePtr pOld; |
| 1765 |
|
| 1766 |
for (pOld = *pPrev; pOld; pOld = pOld->pNextWin) |
| 1767 |
if (pOld == pDamage) { |
| 1768 |
ErrorF("Damage already on window list\n"); |
| 1769 |
OsAbort(); |
| 1770 |
} |
| 1771 |
#endif |
| 1772 |
pDamage->pNextWin = *pPrev; |
| 1773 |
*pPrev = pDamage; |
| 1774 |
pDamage->isWindow = TRUE; |
| 1775 |
} |
| 1776 |
else |
| 1777 |
pDamage->isWindow = FALSE; |
| 1778 |
pDamage->pDrawable = pDrawable; |
| 1779 |
damageInsertDamage(getDrawableDamageRef(pDrawable), pDamage); |
| 1780 |
(*pScrPriv->funcs.Register) (pDrawable, pDamage); |
| 1781 |
} |
| 1782 |
|
| 1783 |
void |
| 1784 |
DamageDrawInternal(ScreenPtr pScreen, Bool enable) |
| 1785 |
{ |
| 1786 |
damageScrPriv(pScreen); |
| 1787 |
|
| 1788 |
pScrPriv->internalLevel += enable ? 1 : -1; |
| 1789 |
} |
| 1790 |
|
| 1791 |
void |
| 1792 |
DamageUnregister(DamagePtr pDamage) |
| 1793 |
{ |
| 1794 |
DrawablePtr pDrawable = pDamage->pDrawable; |
| 1795 |
ScreenPtr pScreen = pDrawable->pScreen; |
| 1796 |
|
| 1797 |
damageScrPriv(pScreen); |
| 1798 |
|
| 1799 |
(*pScrPriv->funcs.Unregister) (pDrawable, pDamage); |
| 1800 |
|
| 1801 |
if (pDrawable->type == DRAWABLE_WINDOW) { |
| 1802 |
WindowPtr pWindow = (WindowPtr) pDrawable; |
| 1803 |
|
| 1804 |
winDamageRef(pWindow); |
| 1805 |
#if DAMAGE_VALIDATE_ENABLE |
| 1806 |
int found = 0; |
| 1807 |
#endif |
| 1808 |
|
| 1809 |
while (*pPrev) { |
| 1810 |
if (*pPrev == pDamage) { |
| 1811 |
*pPrev = pDamage->pNextWin; |
| 1812 |
#if DAMAGE_VALIDATE_ENABLE |
| 1813 |
found = 1; |
| 1814 |
#endif |
| 1815 |
break; |
| 1816 |
} |
| 1817 |
pPrev = &(*pPrev)->pNextWin; |
| 1818 |
} |
| 1819 |
#if DAMAGE_VALIDATE_ENABLE |
| 1820 |
if (!found) { |
| 1821 |
ErrorF("Damage not on window list\n"); |
| 1822 |
OsAbort(); |
| 1823 |
} |
| 1824 |
#endif |
| 1825 |
} |
| 1826 |
pDamage->pDrawable = 0; |
| 1827 |
damageRemoveDamage(getDrawableDamageRef(pDrawable), pDamage); |
| 1828 |
} |
| 1829 |
|
| 1830 |
void |
| 1831 |
DamageDestroy(DamagePtr pDamage) |
| 1832 |
{ |
| 1833 |
ScreenPtr pScreen = pDamage->pScreen; |
| 1834 |
|
| 1835 |
damageScrPriv(pScreen); |
| 1836 |
|
| 1837 |
if (pDamage->pDrawable) |
| 1838 |
DamageUnregister(pDamage); |
| 1839 |
|
| 1840 |
if (pDamage->damageDestroy) |
| 1841 |
(*pDamage->damageDestroy) (pDamage, pDamage->closure); |
| 1842 |
(*pScrPriv->funcs.Destroy) (pDamage); |
| 1843 |
RegionUninit(&pDamage->damage); |
| 1844 |
RegionUninit(&pDamage->pendingDamage); |
| 1845 |
free(pDamage); |
| 1846 |
} |
| 1847 |
|
| 1848 |
Bool |
| 1849 |
DamageSubtract(DamagePtr pDamage, const RegionPtr pRegion) |
| 1850 |
{ |
| 1851 |
RegionPtr pClip; |
| 1852 |
RegionRec pixmapClip; |
| 1853 |
DrawablePtr pDrawable = pDamage->pDrawable; |
| 1854 |
|
| 1855 |
RegionSubtract(&pDamage->damage, &pDamage->damage, pRegion); |
| 1856 |
if (pDrawable) { |
| 1857 |
if (pDrawable->type == DRAWABLE_WINDOW) |
| 1858 |
pClip = &((WindowPtr) pDrawable)->borderClip; |
| 1859 |
else { |
| 1860 |
BoxRec box; |
| 1861 |
|
| 1862 |
box.x1 = pDrawable->x; |
| 1863 |
box.y1 = pDrawable->y; |
| 1864 |
box.x2 = pDrawable->x + pDrawable->width; |
| 1865 |
box.y2 = pDrawable->y + pDrawable->height; |
| 1866 |
RegionInit(&pixmapClip, &box, 1); |
| 1867 |
pClip = &pixmapClip; |
| 1868 |
} |
| 1869 |
RegionTranslate(&pDamage->damage, pDrawable->x, pDrawable->y); |
| 1870 |
RegionIntersect(&pDamage->damage, &pDamage->damage, pClip); |
| 1871 |
RegionTranslate(&pDamage->damage, -pDrawable->x, -pDrawable->y); |
| 1872 |
if (pDrawable->type != DRAWABLE_WINDOW) |
| 1873 |
RegionUninit(&pixmapClip); |
| 1874 |
} |
| 1875 |
return RegionNotEmpty(&pDamage->damage); |
| 1876 |
} |
| 1877 |
|
| 1878 |
void |
| 1879 |
DamageEmpty(DamagePtr pDamage) |
| 1880 |
{ |
| 1881 |
RegionEmpty(&pDamage->damage); |
| 1882 |
} |
| 1883 |
|
| 1884 |
RegionPtr |
| 1885 |
DamageRegion(DamagePtr pDamage) |
| 1886 |
{ |
| 1887 |
return &pDamage->damage; |
| 1888 |
} |
| 1889 |
|
| 1890 |
RegionPtr |
| 1891 |
DamagePendingRegion(DamagePtr pDamage) |
| 1892 |
{ |
| 1893 |
return &pDamage->pendingDamage; |
| 1894 |
} |
| 1895 |
|
| 1896 |
void |
| 1897 |
DamageRegionAppend(DrawablePtr pDrawable, RegionPtr pRegion) |
| 1898 |
{ |
| 1899 |
damageRegionAppend(pDrawable, pRegion, FALSE, -1); |
| 1900 |
} |
| 1901 |
|
| 1902 |
void |
| 1903 |
DamageRegionProcessPending(DrawablePtr pDrawable) |
| 1904 |
{ |
| 1905 |
damageRegionProcessPending(pDrawable); |
| 1906 |
} |
| 1907 |
|
| 1908 |
/* This call is very odd, i'm leaving it intact for API sake, but please don't use it. */ |
| 1909 |
void |
| 1910 |
DamageDamageRegion(DrawablePtr pDrawable, RegionPtr pRegion) |
| 1911 |
{ |
| 1912 |
damageRegionAppend(pDrawable, pRegion, FALSE, -1); |
| 1913 |
|
| 1914 |
/* Go back and report this damage for DamagePtrs with reportAfter set, since |
| 1915 |
* this call isn't part of an in-progress drawing op in the call chain and |
| 1916 |
* the DDX probably just wants to know about it right away. |
| 1917 |
*/ |
| 1918 |
damageRegionProcessPending(pDrawable); |
| 1919 |
} |
| 1920 |
|
| 1921 |
void |
| 1922 |
DamageSetReportAfterOp(DamagePtr pDamage, Bool reportAfter) |
| 1923 |
{ |
| 1924 |
pDamage->reportAfter = reportAfter; |
| 1925 |
} |
| 1926 |
|
| 1927 |
DamageScreenFuncsPtr |
| 1928 |
DamageGetScreenFuncs(ScreenPtr pScreen) |
| 1929 |
{ |
| 1930 |
damageScrPriv(pScreen); |
| 1931 |
return &pScrPriv->funcs; |
| 1932 |
} |
| 1933 |
|
| 1934 |
void |
| 1935 |
DamageReportDamage(DamagePtr pDamage, RegionPtr pDamageRegion) |
| 1936 |
{ |
| 1937 |
BoxRec tmpBox; |
| 1938 |
RegionRec tmpRegion; |
| 1939 |
Bool was_empty; |
| 1940 |
|
| 1941 |
switch (pDamage->damageLevel) { |
| 1942 |
case DamageReportRawRegion: |
| 1943 |
RegionUnion(&pDamage->damage, &pDamage->damage, pDamageRegion); |
| 1944 |
(*pDamage->damageReport) (pDamage, pDamageRegion, pDamage->closure); |
| 1945 |
break; |
| 1946 |
case DamageReportDeltaRegion: |
| 1947 |
RegionNull(&tmpRegion); |
| 1948 |
RegionSubtract(&tmpRegion, pDamageRegion, &pDamage->damage); |
| 1949 |
if (RegionNotEmpty(&tmpRegion)) { |
| 1950 |
RegionUnion(&pDamage->damage, &pDamage->damage, pDamageRegion); |
| 1951 |
(*pDamage->damageReport) (pDamage, &tmpRegion, pDamage->closure); |
| 1952 |
} |
| 1953 |
RegionUninit(&tmpRegion); |
| 1954 |
break; |
| 1955 |
case DamageReportBoundingBox: |
| 1956 |
tmpBox = *RegionExtents(&pDamage->damage); |
| 1957 |
RegionUnion(&pDamage->damage, &pDamage->damage, pDamageRegion); |
| 1958 |
if (!BOX_SAME(&tmpBox, RegionExtents(&pDamage->damage))) { |
| 1959 |
(*pDamage->damageReport) (pDamage, &pDamage->damage, |
| 1960 |
pDamage->closure); |
| 1961 |
} |
| 1962 |
break; |
| 1963 |
case DamageReportNonEmpty: |
| 1964 |
was_empty = !RegionNotEmpty(&pDamage->damage); |
| 1965 |
RegionUnion(&pDamage->damage, &pDamage->damage, pDamageRegion); |
| 1966 |
if (was_empty && RegionNotEmpty(&pDamage->damage)) { |
| 1967 |
(*pDamage->damageReport) (pDamage, &pDamage->damage, |
| 1968 |
pDamage->closure); |
| 1969 |
} |
| 1970 |
break; |
| 1971 |
case DamageReportNone: |
| 1972 |
RegionUnion(&pDamage->damage, &pDamage->damage, pDamageRegion); |
| 1973 |
break; |
| 1974 |
} |
| 1975 |
} |