midispcur.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. /*
  2. * midispcur.c
  3. *
  4. * machine independent cursor display routines
  5. */
  6. /*
  7. Copyright 1989, 1998 The Open Group
  8. Permission to use, copy, modify, distribute, and sell this software and its
  9. documentation for any purpose is hereby granted without fee, provided that
  10. the above copyright notice appear in all copies and that both that
  11. copyright notice and this permission notice appear in supporting
  12. documentation.
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  19. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. Except as contained in this notice, the name of The Open Group shall not be
  22. used in advertising or otherwise to promote the sale, use or other dealings
  23. in this Software without prior written authorization from The Open Group.
  24. */
  25. #ifdef HAVE_DIX_CONFIG_H
  26. #include <dix-config.h>
  27. #endif
  28. # include <X11/X.h>
  29. # include "misc.h"
  30. # include "input.h"
  31. # include "cursorstr.h"
  32. # include "windowstr.h"
  33. # include "regionstr.h"
  34. # include "dixstruct.h"
  35. # include "scrnintstr.h"
  36. # include "servermd.h"
  37. # include "mipointer.h"
  38. # include "misprite.h"
  39. # include "gcstruct.h"
  40. #ifdef ARGB_CURSOR
  41. # include "picturestr.h"
  42. #endif
  43. /* per-screen private data */
  44. static int miDCScreenIndex;
  45. static unsigned long miDCGeneration = 0;
  46. static Bool miDCCloseScreen(int index, ScreenPtr pScreen);
  47. typedef struct {
  48. GCPtr pSourceGC, pMaskGC;
  49. GCPtr pSaveGC, pRestoreGC;
  50. GCPtr pMoveGC;
  51. GCPtr pPixSourceGC, pPixMaskGC;
  52. CloseScreenProcPtr CloseScreen;
  53. PixmapPtr pSave, pTemp;
  54. #ifdef ARGB_CURSOR
  55. PicturePtr pRootPicture;
  56. PicturePtr pTempPicture;
  57. #endif
  58. } miDCScreenRec, *miDCScreenPtr;
  59. /* per-cursor per-screen private data */
  60. typedef struct {
  61. PixmapPtr sourceBits; /* source bits */
  62. PixmapPtr maskBits; /* mask bits */
  63. #ifdef ARGB_CURSOR
  64. PicturePtr pPicture;
  65. #endif
  66. } miDCCursorRec, *miDCCursorPtr;
  67. /*
  68. * sprite/cursor method table
  69. */
  70. static Bool miDCRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor);
  71. static Bool miDCUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor);
  72. static Bool miDCPutUpCursor(ScreenPtr pScreen, CursorPtr pCursor,
  73. int x, int y, unsigned long source,
  74. unsigned long mask);
  75. static Bool miDCSaveUnderCursor(ScreenPtr pScreen, int x, int y,
  76. int w, int h);
  77. static Bool miDCRestoreUnderCursor(ScreenPtr pScreen, int x, int y,
  78. int w, int h);
  79. static Bool miDCMoveCursor(ScreenPtr pScreen, CursorPtr pCursor,
  80. int x, int y, int w, int h, int dx, int dy,
  81. unsigned long source, unsigned long mask);
  82. static Bool miDCChangeSave(ScreenPtr pScreen, int x, int y, int w, int h,
  83. int dx, int dy);
  84. static const miSpriteCursorFuncRec miDCFuncs = {
  85. miDCRealizeCursor,
  86. miDCUnrealizeCursor,
  87. miDCPutUpCursor,
  88. miDCSaveUnderCursor,
  89. miDCRestoreUnderCursor,
  90. miDCMoveCursor,
  91. miDCChangeSave,
  92. };
  93. _X_EXPORT Bool
  94. miDCInitialize (pScreen, screenFuncs)
  95. ScreenPtr pScreen;
  96. miPointerScreenFuncRec * screenFuncs;
  97. {
  98. miDCScreenPtr pScreenPriv;
  99. if (miDCGeneration != serverGeneration)
  100. {
  101. miDCScreenIndex = AllocateScreenPrivateIndex ();
  102. if (miDCScreenIndex < 0)
  103. return FALSE;
  104. miDCGeneration = serverGeneration;
  105. }
  106. pScreenPriv = malloc(sizeof (miDCScreenRec));
  107. if (!pScreenPriv)
  108. return FALSE;
  109. /*
  110. * initialize the entire private structure to zeros
  111. */
  112. pScreenPriv->pSourceGC =
  113. pScreenPriv->pMaskGC =
  114. pScreenPriv->pSaveGC =
  115. pScreenPriv->pRestoreGC =
  116. pScreenPriv->pMoveGC =
  117. pScreenPriv->pPixSourceGC =
  118. pScreenPriv->pPixMaskGC = NULL;
  119. #ifdef ARGB_CURSOR
  120. pScreenPriv->pRootPicture = NULL;
  121. pScreenPriv->pTempPicture = NULL;
  122. #endif
  123. pScreenPriv->pSave = pScreenPriv->pTemp = NULL;
  124. pScreenPriv->CloseScreen = pScreen->CloseScreen;
  125. pScreen->CloseScreen = miDCCloseScreen;
  126. pScreen->devPrivates[miDCScreenIndex].ptr = (pointer) pScreenPriv;
  127. if (!miSpriteInitialize (pScreen, &miDCFuncs, screenFuncs))
  128. {
  129. free((pointer) pScreenPriv);
  130. return FALSE;
  131. }
  132. return TRUE;
  133. }
  134. #define tossGC(gc) (gc ? FreeGC (gc, (GContext) 0) : 0)
  135. #define tossPix(pix) (pix ? (*pScreen->DestroyPixmap) (pix) : TRUE)
  136. #define tossPict(pict) (pict ? FreePicture (pict, 0) : 0)
  137. static Bool
  138. miDCCloseScreen (index, pScreen)
  139. int index;
  140. ScreenPtr pScreen;
  141. {
  142. miDCScreenPtr pScreenPriv;
  143. pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
  144. pScreen->CloseScreen = pScreenPriv->CloseScreen;
  145. tossGC (pScreenPriv->pSourceGC);
  146. tossGC (pScreenPriv->pMaskGC);
  147. tossGC (pScreenPriv->pSaveGC);
  148. tossGC (pScreenPriv->pRestoreGC);
  149. tossGC (pScreenPriv->pMoveGC);
  150. tossGC (pScreenPriv->pPixSourceGC);
  151. tossGC (pScreenPriv->pPixMaskGC);
  152. tossPix (pScreenPriv->pSave);
  153. tossPix (pScreenPriv->pTemp);
  154. #ifdef ARGB_CURSOR
  155. #if 0 /* This has been free()d before */
  156. tossPict (pScreenPriv->pRootPicture);
  157. #endif
  158. tossPict (pScreenPriv->pTempPicture);
  159. #endif
  160. free((pointer) pScreenPriv);
  161. return (*pScreen->CloseScreen) (index, pScreen);
  162. }
  163. static Bool
  164. miDCRealizeCursor (pScreen, pCursor)
  165. ScreenPtr pScreen;
  166. CursorPtr pCursor;
  167. {
  168. if (pCursor->bits->refcnt <= 1)
  169. pCursor->bits->devPriv[pScreen->myNum] = (pointer)NULL;
  170. return TRUE;
  171. }
  172. #ifdef ARGB_CURSOR
  173. #define EnsurePicture(picture,draw,win) (picture || miDCMakePicture(&picture,draw,win))
  174. static VisualPtr
  175. miDCGetWindowVisual (WindowPtr pWin)
  176. {
  177. ScreenPtr pScreen = pWin->drawable.pScreen;
  178. VisualID vid = wVisual (pWin);
  179. int i;
  180. for (i = 0; i < pScreen->numVisuals; i++)
  181. if (pScreen->visuals[i].vid == vid)
  182. return &pScreen->visuals[i];
  183. return 0;
  184. }
  185. static PicturePtr
  186. miDCMakePicture (PicturePtr *ppPicture, DrawablePtr pDraw, WindowPtr pWin)
  187. {
  188. ScreenPtr pScreen = pDraw->pScreen;
  189. VisualPtr pVisual;
  190. PictFormatPtr pFormat;
  191. XID subwindow_mode = IncludeInferiors;
  192. PicturePtr pPicture;
  193. int error;
  194. pVisual = miDCGetWindowVisual (pWin);
  195. if (!pVisual)
  196. return 0;
  197. pFormat = PictureMatchVisual (pScreen, pDraw->depth, pVisual);
  198. if (!pFormat)
  199. return 0;
  200. pPicture = CreatePicture (0, pDraw, pFormat,
  201. CPSubwindowMode, &subwindow_mode,
  202. serverClient, &error);
  203. *ppPicture = pPicture;
  204. return pPicture;
  205. }
  206. #endif
  207. static miDCCursorPtr
  208. miDCRealize (
  209. ScreenPtr pScreen,
  210. CursorPtr pCursor)
  211. {
  212. miDCCursorPtr pPriv;
  213. GCPtr pGC;
  214. XID gcvals[3];
  215. pPriv = malloc(sizeof (miDCCursorRec));
  216. if (!pPriv)
  217. return (miDCCursorPtr)NULL;
  218. #ifdef ARGB_CURSOR
  219. if (pCursor->bits->argb)
  220. {
  221. PixmapPtr pPixmap;
  222. PictFormatPtr pFormat;
  223. int error;
  224. pFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8);
  225. if (!pFormat)
  226. {
  227. free((pointer) pPriv);
  228. return (miDCCursorPtr)NULL;
  229. }
  230. pPriv->sourceBits = 0;
  231. pPriv->maskBits = 0;
  232. pPixmap = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width,
  233. pCursor->bits->height, 32);
  234. if (!pPixmap)
  235. {
  236. free((pointer) pPriv);
  237. return (miDCCursorPtr)NULL;
  238. }
  239. pGC = GetScratchGC (32, pScreen);
  240. if (!pGC)
  241. {
  242. (*pScreen->DestroyPixmap) (pPixmap);
  243. free((pointer) pPriv);
  244. return (miDCCursorPtr)NULL;
  245. }
  246. ValidateGC (&pPixmap->drawable, pGC);
  247. (*pGC->ops->PutImage) (&pPixmap->drawable, pGC, 32,
  248. 0, 0, pCursor->bits->width,
  249. pCursor->bits->height,
  250. 0, ZPixmap, (char *) pCursor->bits->argb);
  251. FreeScratchGC (pGC);
  252. pPriv->pPicture = CreatePicture (0, &pPixmap->drawable,
  253. pFormat, 0, 0, serverClient, &error);
  254. (*pScreen->DestroyPixmap) (pPixmap);
  255. if (!pPriv->pPicture)
  256. {
  257. free((pointer) pPriv);
  258. return (miDCCursorPtr)NULL;
  259. }
  260. pCursor->bits->devPriv[pScreen->myNum] = (pointer) pPriv;
  261. return pPriv;
  262. }
  263. pPriv->pPicture = 0;
  264. #endif
  265. pPriv->sourceBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width, pCursor->bits->height, 1);
  266. if (!pPriv->sourceBits)
  267. {
  268. free((pointer) pPriv);
  269. return (miDCCursorPtr)NULL;
  270. }
  271. pPriv->maskBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width, pCursor->bits->height, 1);
  272. if (!pPriv->maskBits)
  273. {
  274. (*pScreen->DestroyPixmap) (pPriv->sourceBits);
  275. free((pointer) pPriv);
  276. return (miDCCursorPtr)NULL;
  277. }
  278. pCursor->bits->devPriv[pScreen->myNum] = (pointer) pPriv;
  279. /* create the two sets of bits, clipping as appropriate */
  280. pGC = GetScratchGC (1, pScreen);
  281. if (!pGC)
  282. {
  283. (void) miDCUnrealizeCursor (pScreen, pCursor);
  284. return (miDCCursorPtr)NULL;
  285. }
  286. ValidateGC ((DrawablePtr)pPriv->sourceBits, pGC);
  287. (*pGC->ops->PutImage) ((DrawablePtr)pPriv->sourceBits, pGC, 1,
  288. 0, 0, pCursor->bits->width, pCursor->bits->height,
  289. 0, XYPixmap, (char *)pCursor->bits->source);
  290. gcvals[0] = GXand;
  291. ChangeGC (pGC, GCFunction, gcvals);
  292. ValidateGC ((DrawablePtr)pPriv->sourceBits, pGC);
  293. (*pGC->ops->PutImage) ((DrawablePtr)pPriv->sourceBits, pGC, 1,
  294. 0, 0, pCursor->bits->width, pCursor->bits->height,
  295. 0, XYPixmap, (char *)pCursor->bits->mask);
  296. /* mask bits -- pCursor->mask & ~pCursor->source */
  297. gcvals[0] = GXcopy;
  298. ChangeGC (pGC, GCFunction, gcvals);
  299. ValidateGC ((DrawablePtr)pPriv->maskBits, pGC);
  300. (*pGC->ops->PutImage) ((DrawablePtr)pPriv->maskBits, pGC, 1,
  301. 0, 0, pCursor->bits->width, pCursor->bits->height,
  302. 0, XYPixmap, (char *)pCursor->bits->mask);
  303. gcvals[0] = GXandInverted;
  304. ChangeGC (pGC, GCFunction, gcvals);
  305. ValidateGC ((DrawablePtr)pPriv->maskBits, pGC);
  306. (*pGC->ops->PutImage) ((DrawablePtr)pPriv->maskBits, pGC, 1,
  307. 0, 0, pCursor->bits->width, pCursor->bits->height,
  308. 0, XYPixmap, (char *)pCursor->bits->source);
  309. FreeScratchGC (pGC);
  310. return pPriv;
  311. }
  312. static Bool
  313. miDCUnrealizeCursor (pScreen, pCursor)
  314. ScreenPtr pScreen;
  315. CursorPtr pCursor;
  316. {
  317. miDCCursorPtr pPriv;
  318. pPriv = (miDCCursorPtr) pCursor->bits->devPriv[pScreen->myNum];
  319. if (pPriv && (pCursor->bits->refcnt <= 1))
  320. {
  321. if (pPriv->sourceBits)
  322. (*pScreen->DestroyPixmap) (pPriv->sourceBits);
  323. if (pPriv->maskBits)
  324. (*pScreen->DestroyPixmap) (pPriv->maskBits);
  325. #ifdef ARGB_CURSOR
  326. if (pPriv->pPicture)
  327. FreePicture (pPriv->pPicture, 0);
  328. #endif
  329. free((pointer) pPriv);
  330. pCursor->bits->devPriv[pScreen->myNum] = (pointer)NULL;
  331. }
  332. return TRUE;
  333. }
  334. static void
  335. miDCPutBits (
  336. DrawablePtr pDrawable,
  337. miDCCursorPtr pPriv,
  338. GCPtr sourceGC,
  339. GCPtr maskGC,
  340. int x_org,
  341. int y_org,
  342. unsigned w,
  343. unsigned h,
  344. unsigned long source,
  345. unsigned long mask)
  346. {
  347. XID gcvals[1];
  348. int x, y;
  349. if (sourceGC->fgPixel != source)
  350. {
  351. gcvals[0] = source;
  352. DoChangeGC (sourceGC, GCForeground, gcvals, 0);
  353. }
  354. if (sourceGC->serialNumber != pDrawable->serialNumber)
  355. ValidateGC (pDrawable, sourceGC);
  356. if(sourceGC->miTranslate)
  357. {
  358. x = pDrawable->x + x_org;
  359. y = pDrawable->y + y_org;
  360. }
  361. else
  362. {
  363. x = x_org;
  364. y = y_org;
  365. }
  366. (*sourceGC->ops->PushPixels) (sourceGC, pPriv->sourceBits, pDrawable, w, h, x, y);
  367. if (maskGC->fgPixel != mask)
  368. {
  369. gcvals[0] = mask;
  370. DoChangeGC (maskGC, GCForeground, gcvals, 0);
  371. }
  372. if (maskGC->serialNumber != pDrawable->serialNumber)
  373. ValidateGC (pDrawable, maskGC);
  374. if(maskGC->miTranslate)
  375. {
  376. x = pDrawable->x + x_org;
  377. y = pDrawable->y + y_org;
  378. }
  379. else
  380. {
  381. x = x_org;
  382. y = y_org;
  383. }
  384. (*maskGC->ops->PushPixels) (maskGC, pPriv->maskBits, pDrawable, w, h, x, y);
  385. }
  386. #define EnsureGC(gc,win) (gc || miDCMakeGC(&gc, win))
  387. static GCPtr
  388. miDCMakeGC(
  389. GCPtr *ppGC,
  390. WindowPtr pWin)
  391. {
  392. GCPtr pGC;
  393. int status;
  394. XID gcvals[2];
  395. gcvals[0] = IncludeInferiors;
  396. gcvals[1] = FALSE;
  397. pGC = CreateGC((DrawablePtr)pWin,
  398. GCSubwindowMode|GCGraphicsExposures, gcvals, &status);
  399. *ppGC = pGC;
  400. return pGC;
  401. }
  402. static Bool
  403. miDCPutUpCursor (pScreen, pCursor, x, y, source, mask)
  404. ScreenPtr pScreen;
  405. CursorPtr pCursor;
  406. int x, y;
  407. unsigned long source, mask;
  408. {
  409. miDCScreenPtr pScreenPriv;
  410. miDCCursorPtr pPriv;
  411. WindowPtr pWin;
  412. pPriv = (miDCCursorPtr) pCursor->bits->devPriv[pScreen->myNum];
  413. if (!pPriv)
  414. {
  415. pPriv = miDCRealize(pScreen, pCursor);
  416. if (!pPriv)
  417. return FALSE;
  418. }
  419. pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
  420. pWin = WindowTable[pScreen->myNum];
  421. #ifdef ARGB_CURSOR
  422. if (pPriv->pPicture)
  423. {
  424. if (!EnsurePicture(pScreenPriv->pRootPicture, &pWin->drawable, pWin))
  425. return FALSE;
  426. CompositePicture (PictOpOver,
  427. pPriv->pPicture,
  428. NULL,
  429. pScreenPriv->pRootPicture,
  430. 0, 0, 0, 0,
  431. x, y,
  432. pCursor->bits->width,
  433. pCursor->bits->height);
  434. }
  435. else
  436. #endif
  437. {
  438. if (!EnsureGC(pScreenPriv->pSourceGC, pWin))
  439. return FALSE;
  440. if (!EnsureGC(pScreenPriv->pMaskGC, pWin))
  441. {
  442. FreeGC (pScreenPriv->pSourceGC, (GContext) 0);
  443. pScreenPriv->pSourceGC = 0;
  444. return FALSE;
  445. }
  446. miDCPutBits ((DrawablePtr)pWin, pPriv,
  447. pScreenPriv->pSourceGC, pScreenPriv->pMaskGC,
  448. x, y, pCursor->bits->width, pCursor->bits->height,
  449. source, mask);
  450. }
  451. return TRUE;
  452. }
  453. static Bool
  454. miDCSaveUnderCursor (pScreen, x, y, w, h)
  455. ScreenPtr pScreen;
  456. int x, y, w, h;
  457. {
  458. miDCScreenPtr pScreenPriv;
  459. PixmapPtr pSave;
  460. WindowPtr pWin;
  461. GCPtr pGC;
  462. pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
  463. pSave = pScreenPriv->pSave;
  464. pWin = WindowTable[pScreen->myNum];
  465. if (!pSave || pSave->drawable.width < w || pSave->drawable.height < h)
  466. {
  467. if (pSave)
  468. (*pScreen->DestroyPixmap) (pSave);
  469. pScreenPriv->pSave = pSave =
  470. (*pScreen->CreatePixmap) (pScreen, w, h, pScreen->rootDepth);
  471. if (!pSave)
  472. return FALSE;
  473. }
  474. if (!EnsureGC(pScreenPriv->pSaveGC, pWin))
  475. return FALSE;
  476. pGC = pScreenPriv->pSaveGC;
  477. if (pSave->drawable.serialNumber != pGC->serialNumber)
  478. ValidateGC ((DrawablePtr) pSave, pGC);
  479. (*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC,
  480. x, y, w, h, 0, 0);
  481. return TRUE;
  482. }
  483. static Bool
  484. miDCRestoreUnderCursor (pScreen, x, y, w, h)
  485. ScreenPtr pScreen;
  486. int x, y, w, h;
  487. {
  488. miDCScreenPtr pScreenPriv;
  489. PixmapPtr pSave;
  490. WindowPtr pWin;
  491. GCPtr pGC;
  492. pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
  493. pSave = pScreenPriv->pSave;
  494. pWin = WindowTable[pScreen->myNum];
  495. if (!pSave)
  496. return FALSE;
  497. if (!EnsureGC(pScreenPriv->pRestoreGC, pWin))
  498. return FALSE;
  499. pGC = pScreenPriv->pRestoreGC;
  500. if (pWin->drawable.serialNumber != pGC->serialNumber)
  501. ValidateGC ((DrawablePtr) pWin, pGC);
  502. (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC,
  503. 0, 0, w, h, x, y);
  504. return TRUE;
  505. }
  506. static Bool
  507. miDCChangeSave (pScreen, x, y, w, h, dx, dy)
  508. ScreenPtr pScreen;
  509. int x, y, w, h, dx, dy;
  510. {
  511. miDCScreenPtr pScreenPriv;
  512. PixmapPtr pSave;
  513. WindowPtr pWin;
  514. GCPtr pGC;
  515. int sourcex, sourcey, destx, desty, copyw, copyh;
  516. pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
  517. pSave = pScreenPriv->pSave;
  518. pWin = WindowTable[pScreen->myNum];
  519. /*
  520. * restore the bits which are about to get trashed
  521. */
  522. if (!pSave)
  523. return FALSE;
  524. if (!EnsureGC(pScreenPriv->pRestoreGC, pWin))
  525. return FALSE;
  526. pGC = pScreenPriv->pRestoreGC;
  527. if (pWin->drawable.serialNumber != pGC->serialNumber)
  528. ValidateGC ((DrawablePtr) pWin, pGC);
  529. /*
  530. * copy the old bits to the screen.
  531. */
  532. if (dy > 0)
  533. {
  534. (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC,
  535. 0, h - dy, w, dy, x + dx, y + h);
  536. }
  537. else if (dy < 0)
  538. {
  539. (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC,
  540. 0, 0, w, -dy, x + dx, y + dy);
  541. }
  542. if (dy >= 0)
  543. {
  544. desty = y + dy;
  545. sourcey = 0;
  546. copyh = h - dy;
  547. }
  548. else
  549. {
  550. desty = y;
  551. sourcey = - dy;
  552. copyh = h + dy;
  553. }
  554. if (dx > 0)
  555. {
  556. (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC,
  557. w - dx, sourcey, dx, copyh, x + w, desty);
  558. }
  559. else if (dx < 0)
  560. {
  561. (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC,
  562. 0, sourcey, -dx, copyh, x + dx, desty);
  563. }
  564. if (!EnsureGC(pScreenPriv->pSaveGC, pWin))
  565. return FALSE;
  566. pGC = pScreenPriv->pSaveGC;
  567. if (pSave->drawable.serialNumber != pGC->serialNumber)
  568. ValidateGC ((DrawablePtr) pSave, pGC);
  569. /*
  570. * move the bits that are still valid within the pixmap
  571. */
  572. if (dx >= 0)
  573. {
  574. sourcex = 0;
  575. destx = dx;
  576. copyw = w - dx;
  577. }
  578. else
  579. {
  580. destx = 0;
  581. sourcex = - dx;
  582. copyw = w + dx;
  583. }
  584. if (dy >= 0)
  585. {
  586. sourcey = 0;
  587. desty = dy;
  588. copyh = h - dy;
  589. }
  590. else
  591. {
  592. desty = 0;
  593. sourcey = -dy;
  594. copyh = h + dy;
  595. }
  596. (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pSave, pGC,
  597. sourcex, sourcey, copyw, copyh, destx, desty);
  598. /*
  599. * copy the new bits from the screen into the remaining areas of the
  600. * pixmap
  601. */
  602. if (dy > 0)
  603. {
  604. (*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC,
  605. x, y, w, dy, 0, 0);
  606. }
  607. else if (dy < 0)
  608. {
  609. (*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC,
  610. x, y + h + dy, w, -dy, 0, h + dy);
  611. }
  612. if (dy >= 0)
  613. {
  614. desty = dy;
  615. sourcey = y + dy;
  616. copyh = h - dy;
  617. }
  618. else
  619. {
  620. desty = 0;
  621. sourcey = y;
  622. copyh = h + dy;
  623. }
  624. if (dx > 0)
  625. {
  626. (*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC,
  627. x, sourcey, dx, copyh, 0, desty);
  628. }
  629. else if (dx < 0)
  630. {
  631. (*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC,
  632. x + w + dx, sourcey, -dx, copyh, w + dx, desty);
  633. }
  634. return TRUE;
  635. }
  636. static Bool
  637. miDCMoveCursor (pScreen, pCursor, x, y, w, h, dx, dy, source, mask)
  638. ScreenPtr pScreen;
  639. CursorPtr pCursor;
  640. int x, y, w, h, dx, dy;
  641. unsigned long source, mask;
  642. {
  643. miDCCursorPtr pPriv;
  644. miDCScreenPtr pScreenPriv;
  645. int status;
  646. WindowPtr pWin;
  647. GCPtr pGC;
  648. XID gcval = FALSE;
  649. PixmapPtr pTemp;
  650. pPriv = (miDCCursorPtr) pCursor->bits->devPriv[pScreen->myNum];
  651. if (!pPriv)
  652. {
  653. pPriv = miDCRealize(pScreen, pCursor);
  654. if (!pPriv)
  655. return FALSE;
  656. }
  657. pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
  658. pWin = WindowTable[pScreen->myNum];
  659. pTemp = pScreenPriv->pTemp;
  660. if (!pTemp ||
  661. pTemp->drawable.width != pScreenPriv->pSave->drawable.width ||
  662. pTemp->drawable.height != pScreenPriv->pSave->drawable.height)
  663. {
  664. if (pTemp)
  665. (*pScreen->DestroyPixmap) (pTemp);
  666. #ifdef ARGB_CURSOR
  667. if (pScreenPriv->pTempPicture)
  668. {
  669. FreePicture (pScreenPriv->pTempPicture, 0);
  670. pScreenPriv->pTempPicture = 0;
  671. }
  672. #endif
  673. pScreenPriv->pTemp = pTemp = (*pScreen->CreatePixmap)
  674. (pScreen, w, h, pScreenPriv->pSave->drawable.depth);
  675. if (!pTemp)
  676. return FALSE;
  677. }
  678. if (!pScreenPriv->pMoveGC)
  679. {
  680. pScreenPriv->pMoveGC = CreateGC ((DrawablePtr)pTemp,
  681. GCGraphicsExposures, &gcval, &status);
  682. if (!pScreenPriv->pMoveGC)
  683. return FALSE;
  684. }
  685. /*
  686. * copy the saved area to a temporary pixmap
  687. */
  688. pGC = pScreenPriv->pMoveGC;
  689. if (pGC->serialNumber != pTemp->drawable.serialNumber)
  690. ValidateGC ((DrawablePtr) pTemp, pGC);
  691. (*pGC->ops->CopyArea)((DrawablePtr)pScreenPriv->pSave,
  692. (DrawablePtr)pTemp, pGC, 0, 0, w, h, 0, 0);
  693. /*
  694. * draw the cursor in the temporary pixmap
  695. */
  696. #ifdef ARGB_CURSOR
  697. if (pPriv->pPicture)
  698. {
  699. if (!EnsurePicture(pScreenPriv->pTempPicture, &pTemp->drawable, pWin))
  700. return FALSE;
  701. CompositePicture (PictOpOver,
  702. pPriv->pPicture,
  703. NULL,
  704. pScreenPriv->pTempPicture,
  705. 0, 0, 0, 0,
  706. dx, dy,
  707. pCursor->bits->width,
  708. pCursor->bits->height);
  709. }
  710. else
  711. #endif
  712. {
  713. if (!pScreenPriv->pPixSourceGC)
  714. {
  715. pScreenPriv->pPixSourceGC = CreateGC ((DrawablePtr)pTemp,
  716. GCGraphicsExposures, &gcval, &status);
  717. if (!pScreenPriv->pPixSourceGC)
  718. return FALSE;
  719. }
  720. if (!pScreenPriv->pPixMaskGC)
  721. {
  722. pScreenPriv->pPixMaskGC = CreateGC ((DrawablePtr)pTemp,
  723. GCGraphicsExposures, &gcval, &status);
  724. if (!pScreenPriv->pPixMaskGC)
  725. return FALSE;
  726. }
  727. miDCPutBits ((DrawablePtr)pTemp, pPriv,
  728. pScreenPriv->pPixSourceGC, pScreenPriv->pPixMaskGC,
  729. dx, dy, pCursor->bits->width, pCursor->bits->height,
  730. source, mask);
  731. }
  732. /*
  733. * copy the temporary pixmap onto the screen
  734. */
  735. if (!EnsureGC(pScreenPriv->pRestoreGC, pWin))
  736. return FALSE;
  737. pGC = pScreenPriv->pRestoreGC;
  738. if (pWin->drawable.serialNumber != pGC->serialNumber)
  739. ValidateGC ((DrawablePtr) pWin, pGC);
  740. (*pGC->ops->CopyArea) ((DrawablePtr) pTemp, (DrawablePtr) pWin,
  741. pGC,
  742. 0, 0, w, h, x, y);
  743. return TRUE;
  744. }