You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vncHooks.c 65KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2009-2017 Pierre Ossman for Cendio AB
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. #ifdef HAVE_DIX_CONFIG_H
  20. #include <dix-config.h>
  21. #endif
  22. #include <stdio.h>
  23. #include "vncHooks.h"
  24. #include "vncExtInit.h"
  25. #include "xorg-version.h"
  26. #include "scrnintstr.h"
  27. #include "windowstr.h"
  28. #include "cursorstr.h"
  29. #include "gcstruct.h"
  30. #include "regionstr.h"
  31. #include "dixfontstr.h"
  32. #include "colormapst.h"
  33. #include "picturestr.h"
  34. #include "randrstr.h"
  35. #define DBGPRINT(x) //(fprintf x)
  36. // MAX_RECTS_PER_OP is the maximum number of rectangles we generate from
  37. // operations like Polylines and PolySegment. If the operation is more complex
  38. // than this, we simply use the bounding box. Ideally it would be a
  39. // command-line option, but that would involve an extra malloc each time, so we
  40. // fix it here.
  41. #define MAX_RECTS_PER_OP 5
  42. // vncHooksScreenRec and vncHooksGCRec contain pointers to the original
  43. // functions which we "wrap" in order to hook the screen changes. The screen
  44. // functions are each wrapped individually, while the GC "funcs" and "ops" are
  45. // wrapped as a unit.
  46. typedef struct _vncHooksScreenRec {
  47. int ignoreHooks;
  48. CloseScreenProcPtr CloseScreen;
  49. CreateGCProcPtr CreateGC;
  50. CopyWindowProcPtr CopyWindow;
  51. ClearToBackgroundProcPtr ClearToBackground;
  52. DisplayCursorProcPtr DisplayCursor;
  53. #if XORG_AT_LEAST(1, 19, 0)
  54. CursorWarpedToProcPtr CursorWarpedTo;
  55. #endif
  56. ScreenBlockHandlerProcPtr BlockHandler;
  57. CompositeProcPtr Composite;
  58. GlyphsProcPtr Glyphs;
  59. CompositeRectsProcPtr CompositeRects;
  60. TrapezoidsProcPtr Trapezoids;
  61. TrianglesProcPtr Triangles;
  62. TriStripProcPtr TriStrip;
  63. TriFanProcPtr TriFan;
  64. RRSetConfigProcPtr rrSetConfig;
  65. RRScreenSetSizeProcPtr rrScreenSetSize;
  66. RRCrtcSetProcPtr rrCrtcSet;
  67. } vncHooksScreenRec, *vncHooksScreenPtr;
  68. typedef struct _vncHooksGCRec {
  69. const GCFuncs *funcs;
  70. const GCOps *ops;
  71. } vncHooksGCRec, *vncHooksGCPtr;
  72. #define wrap(priv, real, mem, func) {\
  73. priv->mem = real->mem; \
  74. real->mem = func; \
  75. }
  76. #define unwrap(priv, real, mem) {\
  77. real->mem = priv->mem; \
  78. }
  79. static DevPrivateKeyRec vncHooksScreenKeyRec;
  80. static DevPrivateKeyRec vncHooksGCKeyRec;
  81. #define vncHooksScreenPrivateKey (&vncHooksScreenKeyRec)
  82. #define vncHooksGCPrivateKey (&vncHooksGCKeyRec)
  83. #define vncHooksScreenPrivate(pScreen) \
  84. (vncHooksScreenPtr) dixLookupPrivate(&(pScreen)->devPrivates, \
  85. vncHooksScreenPrivateKey)
  86. #define vncHooksGCPrivate(pGC) \
  87. (vncHooksGCPtr) dixLookupPrivate(&(pGC)->devPrivates, \
  88. vncHooksGCPrivateKey)
  89. // screen functions
  90. static Bool vncHooksCloseScreen(ScreenPtr pScreen);
  91. static Bool vncHooksCreateGC(GCPtr pGC);
  92. static void vncHooksCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
  93. RegionPtr pOldRegion);
  94. static void vncHooksClearToBackground(WindowPtr pWin, int x, int y, int w,
  95. int h, Bool generateExposures);
  96. static Bool vncHooksDisplayCursor(DeviceIntPtr pDev,
  97. ScreenPtr pScreen, CursorPtr cursor);
  98. #if XORG_AT_LEAST(1, 19, 0)
  99. static void vncHooksCursorWarpedTo(DeviceIntPtr pDev,
  100. ScreenPtr pScreen_, ClientPtr pClient,
  101. WindowPtr pWindow, SpritePtr pSprite,
  102. int x, int y);
  103. #endif
  104. #if XORG_AT_LEAST(1, 19, 0)
  105. static void vncHooksBlockHandler(ScreenPtr pScreen, void * pTimeout);
  106. #else
  107. static void vncHooksBlockHandler(ScreenPtr pScreen, void * pTimeout,
  108. void * pReadmask);
  109. #endif
  110. static void vncHooksComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask,
  111. PicturePtr pDst, INT16 xSrc, INT16 ySrc, INT16 xMask,
  112. INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
  113. static void vncHooksGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  114. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlists,
  115. GlyphListPtr lists, GlyphPtr * glyphs);
  116. static void vncHooksCompositeRects(CARD8 op, PicturePtr pDst,
  117. xRenderColor * color, int nRect, xRectangle *rects);
  118. static void vncHooksTrapezoids(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  119. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  120. int ntrap, xTrapezoid * traps);
  121. static void vncHooksTriangles(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  122. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  123. int ntri, xTriangle * tris);
  124. static void vncHooksTriStrip(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  125. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  126. int npoint, xPointFixed * points);
  127. static void vncHooksTriFan(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  128. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  129. int npoint, xPointFixed * points);
  130. static Bool vncHooksRandRSetConfig(ScreenPtr pScreen, Rotation rotation,
  131. int rate, RRScreenSizePtr pSize);
  132. static Bool vncHooksRandRScreenSetSize(ScreenPtr pScreen,
  133. CARD16 width, CARD16 height,
  134. CARD32 mmWidth, CARD32 mmHeight);
  135. static Bool vncHooksRandRCrtcSet(ScreenPtr pScreen, RRCrtcPtr crtc,
  136. RRModePtr mode, int x, int y,
  137. Rotation rotation, int numOutputs,
  138. RROutputPtr *outputs);
  139. // GC "funcs"
  140. static void vncHooksValidateGC(GCPtr pGC, unsigned long changes,
  141. DrawablePtr pDrawable);
  142. static void vncHooksChangeGC(GCPtr pGC, unsigned long mask);
  143. static void vncHooksCopyGC(GCPtr src, unsigned long mask, GCPtr dst);
  144. static void vncHooksDestroyGC(GCPtr pGC);
  145. static void vncHooksChangeClip(GCPtr pGC, int type, void * pValue,int nrects);
  146. static void vncHooksDestroyClip(GCPtr pGC);
  147. static void vncHooksCopyClip(GCPtr dst, GCPtr src);
  148. static GCFuncs vncHooksGCFuncs = {
  149. vncHooksValidateGC, vncHooksChangeGC, vncHooksCopyGC, vncHooksDestroyGC,
  150. vncHooksChangeClip, vncHooksDestroyClip, vncHooksCopyClip,
  151. };
  152. // GC "ops"
  153. static void vncHooksFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nInit,
  154. DDXPointPtr pptInit, int *pwidthInit,
  155. int fSorted);
  156. static void vncHooksSetSpans(DrawablePtr pDrawable, GCPtr pGC, char *psrc,
  157. DDXPointPtr ppt, int *pwidth, int nspans,
  158. int fSorted);
  159. static void vncHooksPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
  160. int x, int y, int w, int h, int leftPad,
  161. int format, char *pBits);
  162. static RegionPtr vncHooksCopyArea(DrawablePtr pSrc, DrawablePtr pDst,
  163. GCPtr pGC, int srcx, int srcy, int w, int h,
  164. int dstx, int dsty);
  165. static RegionPtr vncHooksCopyPlane(DrawablePtr pSrc, DrawablePtr pDst,
  166. GCPtr pGC, int srcx, int srcy, int w, int h,
  167. int dstx, int dsty, unsigned long plane);
  168. static void vncHooksPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode,
  169. int npt, xPoint *pts);
  170. static void vncHooksPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode,
  171. int npt, DDXPointPtr ppts);
  172. static void vncHooksPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg,
  173. xSegment *segs);
  174. static void vncHooksPolyRectangle(DrawablePtr pDrawable, GCPtr pGC, int nrects,
  175. xRectangle *rects);
  176. static void vncHooksPolyArc(DrawablePtr pDrawable, GCPtr pGC, int narcs,
  177. xArc *arcs);
  178. static void vncHooksFillPolygon(DrawablePtr pDrawable, GCPtr pGC, int shape,
  179. int mode, int count, DDXPointPtr pts);
  180. static void vncHooksPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nrects,
  181. xRectangle *rects);
  182. static void vncHooksPolyFillArc(DrawablePtr pDrawable, GCPtr pGC, int narcs,
  183. xArc *arcs);
  184. static int vncHooksPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  185. int count, char *chars);
  186. static int vncHooksPolyText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  187. int count, unsigned short *chars);
  188. static void vncHooksImageText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  189. int count, char *chars);
  190. static void vncHooksImageText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  191. int count, unsigned short *chars);
  192. static void vncHooksImageGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x,
  193. int y, unsigned int nglyph,
  194. CharInfoPtr *ppci, void * pglyphBase);
  195. static void vncHooksPolyGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x,
  196. int y, unsigned int nglyph,
  197. CharInfoPtr *ppci, void * pglyphBase);
  198. static void vncHooksPushPixels(GCPtr pGC, PixmapPtr pBitMap,
  199. DrawablePtr pDrawable, int w, int h, int x,
  200. int y);
  201. static GCOps vncHooksGCOps = {
  202. vncHooksFillSpans, vncHooksSetSpans, vncHooksPutImage, vncHooksCopyArea,
  203. vncHooksCopyPlane, vncHooksPolyPoint, vncHooksPolylines, vncHooksPolySegment,
  204. vncHooksPolyRectangle, vncHooksPolyArc, vncHooksFillPolygon,
  205. vncHooksPolyFillRect, vncHooksPolyFillArc, vncHooksPolyText8,
  206. vncHooksPolyText16, vncHooksImageText8, vncHooksImageText16,
  207. vncHooksImageGlyphBlt, vncHooksPolyGlyphBlt, vncHooksPushPixels
  208. };
  209. /////////////////////////////////////////////////////////////////////////////
  210. // vncHooksInit() is called at initialisation time and every time the server
  211. // resets. It is called once for each screen, but the indexes are only
  212. // allocated once for each server generation.
  213. int vncHooksInit(int scrIdx)
  214. {
  215. ScreenPtr pScreen;
  216. vncHooksScreenPtr vncHooksScreen;
  217. PictureScreenPtr ps;
  218. rrScrPrivPtr rp;
  219. pScreen = screenInfo.screens[scrIdx];
  220. if (sizeof(BoxRec) != sizeof(struct UpdateRect)) {
  221. ErrorF("vncHooksInit: Incompatible BoxRec size\n");
  222. return FALSE;
  223. }
  224. if (!dixRegisterPrivateKey(&vncHooksScreenKeyRec, PRIVATE_SCREEN,
  225. sizeof(vncHooksScreenRec))) {
  226. ErrorF("vncHooksInit: Allocation of vncHooksScreen failed\n");
  227. return FALSE;
  228. }
  229. if (!dixRegisterPrivateKey(&vncHooksGCKeyRec, PRIVATE_GC,
  230. sizeof(vncHooksGCRec))) {
  231. ErrorF("vncHooksInit: Allocation of vncHooksGCRec failed\n");
  232. return FALSE;
  233. }
  234. vncHooksScreen = vncHooksScreenPrivate(pScreen);
  235. vncHooksScreen->ignoreHooks = 0;
  236. wrap(vncHooksScreen, pScreen, CloseScreen, vncHooksCloseScreen);
  237. wrap(vncHooksScreen, pScreen, CreateGC, vncHooksCreateGC);
  238. wrap(vncHooksScreen, pScreen, CopyWindow, vncHooksCopyWindow);
  239. wrap(vncHooksScreen, pScreen, ClearToBackground, vncHooksClearToBackground);
  240. wrap(vncHooksScreen, pScreen, DisplayCursor, vncHooksDisplayCursor);
  241. #if XORG_AT_LEAST(1, 19, 0)
  242. wrap(vncHooksScreen, pScreen, CursorWarpedTo, vncHooksCursorWarpedTo);
  243. #endif
  244. wrap(vncHooksScreen, pScreen, BlockHandler, vncHooksBlockHandler);
  245. ps = GetPictureScreenIfSet(pScreen);
  246. if (ps) {
  247. wrap(vncHooksScreen, ps, Composite, vncHooksComposite);
  248. wrap(vncHooksScreen, ps, Glyphs, vncHooksGlyphs);
  249. wrap(vncHooksScreen, ps, CompositeRects, vncHooksCompositeRects);
  250. wrap(vncHooksScreen, ps, Trapezoids, vncHooksTrapezoids);
  251. wrap(vncHooksScreen, ps, Triangles, vncHooksTriangles);
  252. wrap(vncHooksScreen, ps, TriStrip, vncHooksTriStrip);
  253. wrap(vncHooksScreen, ps, TriFan, vncHooksTriFan);
  254. }
  255. rp = rrGetScrPriv(pScreen);
  256. if (rp) {
  257. /* Some RandR callbacks are optional */
  258. if (rp->rrSetConfig)
  259. wrap(vncHooksScreen, rp, rrSetConfig, vncHooksRandRSetConfig);
  260. if (rp->rrScreenSetSize)
  261. wrap(vncHooksScreen, rp, rrScreenSetSize, vncHooksRandRScreenSetSize);
  262. if (rp->rrCrtcSet)
  263. wrap(vncHooksScreen, rp, rrCrtcSet, vncHooksRandRCrtcSet);
  264. }
  265. return TRUE;
  266. }
  267. /////////////////////////////////////////////////////////////////////////////
  268. // vncGetScreenImage() grabs a chunk of data from the main screen into the
  269. // provided buffer. It lives here rather than in XorgGlue.c because it
  270. // temporarily pauses the hooks.
  271. void vncGetScreenImage(int scrIdx, int x, int y, int width, int height,
  272. char *buffer, int strideBytes)
  273. {
  274. ScreenPtr pScreen = screenInfo.screens[scrIdx];
  275. vncHooksScreenPtr vncHooksScreen = vncHooksScreenPrivate(pScreen);
  276. int i;
  277. vncHooksScreen->ignoreHooks++;
  278. // We do one line at a time since GetImage() cannot handle stride
  279. for (i = y; i < y + height; i++) {
  280. DrawablePtr pDrawable;
  281. pDrawable = (DrawablePtr) pScreen->root;
  282. (*pScreen->GetImage) (pDrawable, x, i, width, 1,
  283. ZPixmap, (unsigned long)~0L, buffer);
  284. buffer += strideBytes;
  285. }
  286. vncHooksScreen->ignoreHooks--;
  287. }
  288. /////////////////////////////////////////////////////////////////////////////
  289. //
  290. // Helper functions
  291. //
  292. static inline void add_changed(ScreenPtr pScreen, RegionPtr reg)
  293. {
  294. vncHooksScreenPtr vncHooksScreen = vncHooksScreenPrivate(pScreen);
  295. if (vncHooksScreen->ignoreHooks)
  296. return;
  297. if (RegionNil(reg))
  298. return;
  299. vncAddChanged(pScreen->myNum,
  300. RegionNumRects(reg),
  301. (const struct UpdateRect*)RegionRects(reg));
  302. }
  303. static inline void add_copied(ScreenPtr pScreen, RegionPtr dst,
  304. int dx, int dy)
  305. {
  306. vncHooksScreenPtr vncHooksScreen = vncHooksScreenPrivate(pScreen);
  307. if (vncHooksScreen->ignoreHooks)
  308. return;
  309. if (RegionNil(dst))
  310. return;
  311. vncAddCopied(pScreen->myNum,
  312. RegionNumRects(dst),
  313. (const struct UpdateRect*)RegionRects(dst), dx, dy);
  314. }
  315. static inline Bool is_visible(DrawablePtr drawable)
  316. {
  317. PixmapPtr scrPixmap;
  318. scrPixmap = drawable->pScreen->GetScreenPixmap(drawable->pScreen);
  319. if (drawable->type == DRAWABLE_WINDOW) {
  320. WindowPtr window;
  321. PixmapPtr winPixmap;
  322. window = (WindowPtr)drawable;
  323. winPixmap = drawable->pScreen->GetWindowPixmap(window);
  324. if (!window->viewable)
  325. return FALSE;
  326. if (winPixmap != scrPixmap)
  327. return FALSE;
  328. return TRUE;
  329. }
  330. if (drawable != &scrPixmap->drawable)
  331. return FALSE;
  332. return TRUE;
  333. }
  334. /////////////////////////////////////////////////////////////////////////////
  335. //
  336. // screen functions
  337. //
  338. // Unwrap and rewrap helpers
  339. #define SCREEN_PROLOGUE(scrn,field) \
  340. ScreenPtr pScreen = scrn; \
  341. vncHooksScreenPtr vncHooksScreen = vncHooksScreenPrivate(pScreen); \
  342. unwrap(vncHooksScreen, pScreen, field); \
  343. DBGPRINT((stderr,"vncHooks" #field " called\n"));
  344. #define SCREEN_EPILOGUE(field) \
  345. wrap(vncHooksScreen, pScreen, field, vncHooks##field); \
  346. // CloseScreen - unwrap the screen functions and call the original CloseScreen
  347. // function
  348. static Bool vncHooksCloseScreen(ScreenPtr pScreen_)
  349. {
  350. PictureScreenPtr ps;
  351. rrScrPrivPtr rp;
  352. SCREEN_PROLOGUE(pScreen_, CloseScreen);
  353. unwrap(vncHooksScreen, pScreen, CreateGC);
  354. unwrap(vncHooksScreen, pScreen, CopyWindow);
  355. unwrap(vncHooksScreen, pScreen, ClearToBackground);
  356. unwrap(vncHooksScreen, pScreen, DisplayCursor);
  357. unwrap(vncHooksScreen, pScreen, BlockHandler);
  358. ps = GetPictureScreenIfSet(pScreen);
  359. if (ps) {
  360. unwrap(vncHooksScreen, ps, Composite);
  361. unwrap(vncHooksScreen, ps, Glyphs);
  362. unwrap(vncHooksScreen, ps, CompositeRects);
  363. unwrap(vncHooksScreen, ps, Trapezoids);
  364. unwrap(vncHooksScreen, ps, Triangles);
  365. unwrap(vncHooksScreen, ps, TriStrip);
  366. unwrap(vncHooksScreen, ps, TriFan);
  367. }
  368. rp = rrGetScrPriv(pScreen);
  369. if (rp) {
  370. unwrap(vncHooksScreen, rp, rrSetConfig);
  371. unwrap(vncHooksScreen, rp, rrScreenSetSize);
  372. unwrap(vncHooksScreen, rp, rrCrtcSet);
  373. }
  374. DBGPRINT((stderr,"vncHooksCloseScreen: unwrapped screen functions\n"));
  375. return (*pScreen->CloseScreen)(pScreen);
  376. }
  377. // CreateGC - wrap the "GC funcs"
  378. static Bool vncHooksCreateGC(GCPtr pGC)
  379. {
  380. vncHooksGCPtr vncHooksGC = vncHooksGCPrivate(pGC);
  381. Bool ret;
  382. SCREEN_PROLOGUE(pGC->pScreen, CreateGC);
  383. ret = (*pScreen->CreateGC) (pGC);
  384. vncHooksGC->ops = NULL;
  385. vncHooksGC->funcs = pGC->funcs;
  386. pGC->funcs = &vncHooksGCFuncs;
  387. SCREEN_EPILOGUE(CreateGC);
  388. return ret;
  389. }
  390. // CopyWindow - destination of the copy is the old region, clipped by
  391. // borderClip, translated by the delta. This call only does the copy - it
  392. // doesn't affect any other bits.
  393. static void vncHooksCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
  394. RegionPtr pOldRegion)
  395. {
  396. int dx, dy;
  397. BoxRec screen_box;
  398. RegionRec copied, screen_rgn;
  399. SCREEN_PROLOGUE(pWin->drawable.pScreen, CopyWindow);
  400. RegionNull(&copied);
  401. RegionCopy(&copied, pOldRegion);
  402. screen_box.x1 = 0;
  403. screen_box.y1 = 0;
  404. screen_box.x2 = pScreen->width;
  405. screen_box.y2 = pScreen->height;
  406. RegionInitBoxes(&screen_rgn, &screen_box, 1);
  407. dx = pWin->drawable.x - ptOldOrg.x;
  408. dy = pWin->drawable.y - ptOldOrg.y;
  409. // RFB tracks copies in terms of destination rectangle, not source.
  410. // We also need to copy with changes to the Window's clipping region.
  411. // Finally, make sure we don't get copies to or from regions outside
  412. // the framebuffer.
  413. RegionIntersect(&copied, &copied, &screen_rgn);
  414. RegionTranslate(&copied, dx, dy);
  415. RegionIntersect(&copied, &copied, &screen_rgn);
  416. RegionIntersect(&copied, &copied, &pWin->borderClip);
  417. (*pScreen->CopyWindow) (pWin, ptOldOrg, pOldRegion);
  418. add_copied(pScreen, &copied, dx, dy);
  419. RegionUninit(&copied);
  420. RegionUninit(&screen_rgn);
  421. SCREEN_EPILOGUE(CopyWindow);
  422. }
  423. // ClearToBackground - changed region is the given rectangle, clipped by
  424. // clipList, but only if generateExposures is false.
  425. static void vncHooksClearToBackground(WindowPtr pWin, int x, int y, int w,
  426. int h, Bool generateExposures)
  427. {
  428. BoxRec box;
  429. RegionRec reg;
  430. SCREEN_PROLOGUE(pWin->drawable.pScreen, ClearToBackground);
  431. box.x1 = x + pWin->drawable.x;
  432. box.y1 = y + pWin->drawable.y;
  433. box.x2 = w ? (box.x1 + w) : (pWin->drawable.x + pWin->drawable.width);
  434. box.y2 = h ? (box.y1 + h) : (pWin->drawable.y + pWin->drawable.height);
  435. RegionInitBoxes(&reg, &box, 1);
  436. RegionIntersect(&reg, &reg, &pWin->clipList);
  437. (*pScreen->ClearToBackground) (pWin, x, y, w, h, generateExposures);
  438. if (!generateExposures) {
  439. add_changed(pScreen, &reg);
  440. }
  441. RegionUninit(&reg);
  442. SCREEN_EPILOGUE(ClearToBackground);
  443. }
  444. // DisplayCursor - get the cursor shape
  445. static Bool vncHooksDisplayCursor(DeviceIntPtr pDev,
  446. ScreenPtr pScreen_, CursorPtr cursor)
  447. {
  448. Bool ret;
  449. SCREEN_PROLOGUE(pScreen_, DisplayCursor);
  450. ret = (*pScreen->DisplayCursor) (pDev, pScreen, cursor);
  451. /*
  452. * XXX DIX calls this function with NULL argument to remove cursor sprite from
  453. * screen. Should we handle this in setCursor as well?
  454. */
  455. if (cursor != NullCursor) {
  456. int width, height;
  457. int hotX, hotY;
  458. unsigned char *rgbaData;
  459. width = cursor->bits->width;
  460. height = cursor->bits->height;
  461. hotX = cursor->bits->xhot;
  462. hotY = cursor->bits->yhot;
  463. rgbaData = malloc(width * height * 4);
  464. if (rgbaData == NULL)
  465. goto out;
  466. if (cursor->bits->argb) {
  467. unsigned char *out;
  468. CARD32 *in;
  469. int i;
  470. in = cursor->bits->argb;
  471. out = rgbaData;
  472. for (i = 0; i < width*height; i++) {
  473. out[0] = (*in >> 16) & 0xff;
  474. out[1] = (*in >> 8) & 0xff;
  475. out[2] = (*in >> 0) & 0xff;
  476. out[3] = (*in >> 24) & 0xff;
  477. out += 4;
  478. in++;
  479. }
  480. } else {
  481. unsigned char *out;
  482. int xMaskBytesPerRow;
  483. xMaskBytesPerRow = BitmapBytePad(width);
  484. out = rgbaData;
  485. for (int y = 0; y < height; y++) {
  486. for (int x = 0; x < width; x++) {
  487. int byte = y * xMaskBytesPerRow + x / 8;
  488. #if (BITMAP_BIT_ORDER == MSBFirst)
  489. int bit = 7 - x % 8;
  490. #else
  491. int bit = x % 8;
  492. #endif
  493. if (cursor->bits->source[byte] & (1 << bit)) {
  494. out[0] = cursor->foreRed;
  495. out[1] = cursor->foreGreen;
  496. out[2] = cursor->foreBlue;
  497. } else {
  498. out[0] = cursor->backRed;
  499. out[1] = cursor->backGreen;
  500. out[2] = cursor->backBlue;
  501. }
  502. if (cursor->bits->mask[byte] & (1 << bit))
  503. out[3] = 0xff;
  504. else
  505. out[3] = 0x00;
  506. out += 4;
  507. }
  508. }
  509. }
  510. vncSetCursorSprite(width, height, hotX, hotY, rgbaData);
  511. free(rgbaData);
  512. }
  513. out:
  514. SCREEN_EPILOGUE(DisplayCursor);
  515. return ret;
  516. }
  517. // CursorWarpedTo - notify that the cursor was warped
  518. #if XORG_AT_LEAST(1, 19, 0)
  519. static void vncHooksCursorWarpedTo(DeviceIntPtr pDev,
  520. ScreenPtr pScreen_, ClientPtr pClient,
  521. WindowPtr pWindow, SpritePtr pSprite,
  522. int x, int y)
  523. {
  524. SCREEN_PROLOGUE(pScreen_, CursorWarpedTo);
  525. vncSetCursorPos(pScreen->myNum, x, y);
  526. SCREEN_EPILOGUE(CursorWarpedTo);
  527. }
  528. #endif
  529. // BlockHandler - ignore any changes during the block handler - it's likely
  530. // these are just drawing the cursor.
  531. #if XORG_AT_LEAST(1, 19, 0)
  532. static void vncHooksBlockHandler(ScreenPtr pScreen_, void * pTimeout)
  533. #else
  534. static void vncHooksBlockHandler(ScreenPtr pScreen_, void * pTimeout,
  535. void * pReadmask)
  536. #endif
  537. {
  538. SCREEN_PROLOGUE(pScreen_, BlockHandler);
  539. vncHooksScreen->ignoreHooks++;
  540. #if XORG_AT_LEAST(1, 19, 0)
  541. (*pScreen->BlockHandler) (pScreen, pTimeout);
  542. #else
  543. (*pScreen->BlockHandler) (pScreen, pTimeout, pReadmask);
  544. #endif
  545. vncHooksScreen->ignoreHooks--;
  546. SCREEN_EPILOGUE(BlockHandler);
  547. }
  548. // Unwrap and rewrap helpers
  549. #define RENDER_PROLOGUE(scrn,field) \
  550. ScreenPtr pScreen = scrn; \
  551. PictureScreenPtr ps = GetPictureScreen(pScreen); \
  552. vncHooksScreenPtr vncHooksScreen = vncHooksScreenPrivate(pScreen); \
  553. unwrap(vncHooksScreen, ps, field); \
  554. DBGPRINT((stderr,"vncHooks" #field " called\n"));
  555. #define RENDER_EPILOGUE(field) \
  556. wrap(vncHooksScreen, ps, field, vncHooks##field); \
  557. // Composite - The core of XRENDER
  558. static void vncHooksComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask,
  559. PicturePtr pDst, INT16 xSrc, INT16 ySrc, INT16 xMask,
  560. INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
  561. {
  562. RegionRec changed;
  563. RENDER_PROLOGUE(pDst->pDrawable->pScreen, Composite);
  564. if (is_visible(pDst->pDrawable)) {
  565. BoxRec box;
  566. RegionRec fbreg;
  567. box.x1 = max(pDst->pDrawable->x + xDst, 0);
  568. box.y1 = max(pDst->pDrawable->y + yDst, 0);
  569. box.x2 = box.x1 + width;
  570. box.y2 = box.y1 + height;
  571. RegionInitBoxes(&changed, &box, 1);
  572. box.x1 = 0;
  573. box.y1 = 0;
  574. box.x2 = pScreen->width;
  575. box.y2 = pScreen->height;
  576. RegionInitBoxes(&fbreg, &box, 1);
  577. RegionIntersect(&changed, &changed, &fbreg);
  578. RegionUninit(&fbreg);
  579. } else {
  580. RegionNull(&changed);
  581. }
  582. (*ps->Composite)(op, pSrc, pMask, pDst, xSrc, ySrc,
  583. xMask, yMask, xDst, yDst, width, height);
  584. add_changed(pScreen, &changed);
  585. RegionUninit(&changed);
  586. RENDER_EPILOGUE(Composite);
  587. }
  588. static RegionPtr
  589. GlyphsToRegion(ScreenPtr pScreen, int nlist, GlyphListPtr list, GlyphPtr *glyphs)
  590. {
  591. int n;
  592. GlyphPtr glyph;
  593. int x, y;
  594. int nrects = nlist;
  595. xRectangle rects[nrects];
  596. xRectanglePtr rect;
  597. x = 0;
  598. y = 0;
  599. rect = &rects[0];
  600. while (nlist--) {
  601. int left, right, top, bottom;
  602. x += list->xOff;
  603. y += list->yOff;
  604. n = list->len;
  605. list++;
  606. left = INT_MAX;
  607. top = INT_MAX;
  608. right = -INT_MAX;
  609. bottom = -INT_MAX;
  610. while (n--) {
  611. int gx, gy, gw, gh;
  612. glyph = *glyphs++;
  613. gx = x - glyph->info.x;
  614. gy = y - glyph->info.y;
  615. gw = glyph->info.width;
  616. gh = glyph->info.height;
  617. x += glyph->info.xOff;
  618. y += glyph->info.yOff;
  619. if (gx < left)
  620. left = gx;
  621. if (gy < top)
  622. top = gy;
  623. if (gx + gw > right)
  624. right = gx + gw;
  625. if (gy + gh > bottom)
  626. bottom = gy + gh;
  627. }
  628. rect->x = left;
  629. rect->y = top;
  630. if ((right > left) && (bottom > top)) {
  631. rect->width = right - left;
  632. rect->height = bottom - top;
  633. } else {
  634. rect->width = 0;
  635. rect->height = 0;
  636. }
  637. rect++;
  638. }
  639. return RECTS_TO_REGION(pScreen, nrects, rects, CT_NONE);
  640. }
  641. // Glyphs - Glyph specific version of Composite (caches and whatnot)
  642. static void vncHooksGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  643. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlists,
  644. GlyphListPtr lists, GlyphPtr * glyphs)
  645. {
  646. RegionPtr changed;
  647. RENDER_PROLOGUE(pDst->pDrawable->pScreen, Glyphs);
  648. if (is_visible(pDst->pDrawable)) {
  649. BoxRec fbbox;
  650. RegionRec fbreg;
  651. changed = GlyphsToRegion(pScreen, nlists, lists, glyphs);
  652. RegionTranslate(changed,
  653. pDst->pDrawable->x, pDst->pDrawable->y);
  654. fbbox.x1 = 0;
  655. fbbox.y1 = 0;
  656. fbbox.x2 = pScreen->width;
  657. fbbox.y2 = pScreen->height;
  658. RegionInitBoxes(&fbreg, &fbbox, 1);
  659. RegionIntersect(changed, changed, &fbreg);
  660. RegionUninit(&fbreg);
  661. } else {
  662. changed = RegionCreate(NullBox, 0);
  663. }
  664. (*ps->Glyphs)(op, pSrc, pDst, maskFormat, xSrc, ySrc, nlists, lists, glyphs);
  665. add_changed(pScreen, changed);
  666. RegionDestroy(changed);
  667. RENDER_EPILOGUE(Glyphs);
  668. }
  669. static void vncHooksCompositeRects(CARD8 op, PicturePtr pDst,
  670. xRenderColor * color, int nRect, xRectangle *rects)
  671. {
  672. RegionPtr changed;
  673. RENDER_PROLOGUE(pDst->pDrawable->pScreen, CompositeRects);
  674. if (is_visible(pDst->pDrawable)) {
  675. changed = RECTS_TO_REGION(pScreen, nRect, rects, CT_NONE);
  676. } else {
  677. changed = RegionCreate(NullBox, 0);
  678. }
  679. (*ps->CompositeRects)(op, pDst, color, nRect, rects);
  680. add_changed(pScreen, changed);
  681. RegionDestroy(changed);
  682. RENDER_EPILOGUE(CompositeRects);
  683. }
  684. static inline short FixedToShort(xFixed fixed)
  685. {
  686. return (fixed + 0x8000) >> 16;
  687. }
  688. static void vncHooksTrapezoids(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  689. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  690. int ntrap, xTrapezoid * traps)
  691. {
  692. RegionRec changed;
  693. RENDER_PROLOGUE(pDst->pDrawable->pScreen, Trapezoids);
  694. if (is_visible(pDst->pDrawable)) {
  695. BoxRec box;
  696. RegionRec fbreg;
  697. // FIXME: We do a very crude bounding box around everything.
  698. // Might not be worth optimizing since this call is rarely
  699. // used.
  700. box.x1 = SHRT_MAX;
  701. box.y1 = SHRT_MAX;
  702. box.x2 = 0;
  703. box.y2 = 0;
  704. for (int i = 0;i < ntrap;i++) {
  705. if (FixedToShort(traps[i].left.p1.x) < box.x1)
  706. box.x1 = FixedToShort(traps[i].left.p1.x);
  707. if (FixedToShort(traps[i].left.p2.x) < box.x1)
  708. box.x1 = FixedToShort(traps[i].left.p2.x);
  709. if (FixedToShort(traps[i].top) < box.y1)
  710. box.y1 = FixedToShort(traps[i].top);
  711. if (FixedToShort(traps[i].right.p1.x) > box.x2)
  712. box.x2 = FixedToShort(traps[i].right.p1.x);
  713. if (FixedToShort(traps[i].right.p2.x) > box.x2)
  714. box.x2 = FixedToShort(traps[i].right.p2.x);
  715. if (FixedToShort(traps[i].bottom) > box.y2)
  716. box.y2 = FixedToShort(traps[i].bottom);
  717. }
  718. box.x1 += pDst->pDrawable->x;
  719. box.y1 += pDst->pDrawable->y;
  720. box.x2 += pDst->pDrawable->x;
  721. box.y2 += pDst->pDrawable->y;
  722. RegionInitBoxes(&changed, &box, 1);
  723. box.x1 = 0;
  724. box.y1 = 0;
  725. box.x2 = pScreen->width;
  726. box.y2 = pScreen->height;
  727. RegionInitBoxes(&fbreg, &box, 1);
  728. RegionIntersect(&changed, &changed, &fbreg);
  729. RegionUninit(&fbreg);
  730. } else {
  731. RegionNull(&changed);
  732. }
  733. (*ps->Trapezoids)(op, pSrc, pDst, maskFormat, xSrc, ySrc, ntrap, traps);
  734. add_changed(pScreen, &changed);
  735. RegionUninit(&changed);
  736. RENDER_EPILOGUE(Trapezoids);
  737. }
  738. static void vncHooksTriangles(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  739. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  740. int ntri, xTriangle * tris)
  741. {
  742. RegionRec changed;
  743. RENDER_PROLOGUE(pDst->pDrawable->pScreen, Triangles);
  744. if (is_visible(pDst->pDrawable)) {
  745. BoxRec box;
  746. RegionRec fbreg;
  747. // FIXME: We do a very crude bounding box around everything.
  748. // Might not be worth optimizing since this call is rarely
  749. // used.
  750. box.x1 = SHRT_MAX;
  751. box.y1 = SHRT_MAX;
  752. box.x2 = 0;
  753. box.y2 = 0;
  754. for (int i = 0;i < ntri;i++) {
  755. xFixed left, right, top, bottom;
  756. left = min(min(tris[i].p1.x, tris[i].p2.x), tris[i].p3.x);
  757. right = max(max(tris[i].p1.x, tris[i].p2.x), tris[i].p3.x);
  758. top = min(min(tris[i].p1.y, tris[i].p2.y), tris[i].p3.y);
  759. bottom = max(max(tris[i].p1.y, tris[i].p2.y), tris[i].p3.y);
  760. if (FixedToShort(left) < box.x1)
  761. box.x1 = FixedToShort(left);
  762. if (FixedToShort(top) < box.y1)
  763. box.y1 = FixedToShort(top);
  764. if (FixedToShort(right) > box.x2)
  765. box.x2 = FixedToShort(right);
  766. if (FixedToShort(bottom) > box.y2)
  767. box.y2 = FixedToShort(bottom);
  768. }
  769. box.x1 += pDst->pDrawable->x;
  770. box.y1 += pDst->pDrawable->y;
  771. box.x2 += pDst->pDrawable->x;
  772. box.y2 += pDst->pDrawable->y;
  773. RegionInitBoxes(&changed, &box, 1);
  774. box.x1 = 0;
  775. box.y1 = 0;
  776. box.x2 = pScreen->width;
  777. box.y2 = pScreen->height;
  778. RegionInitBoxes(&fbreg, &box, 1);
  779. RegionIntersect(&changed, &changed, &fbreg);
  780. RegionUninit(&fbreg);
  781. } else {
  782. RegionNull(&changed);
  783. }
  784. (*ps->Triangles)(op, pSrc, pDst, maskFormat, xSrc, ySrc, ntri, tris);
  785. add_changed(pScreen, &changed);
  786. RegionUninit(&changed);
  787. RENDER_EPILOGUE(Triangles);
  788. }
  789. static void vncHooksTriStrip(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  790. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  791. int npoint, xPointFixed * points)
  792. {
  793. RegionRec changed;
  794. RENDER_PROLOGUE(pDst->pDrawable->pScreen, TriStrip);
  795. if (is_visible(pDst->pDrawable)) {
  796. BoxRec box;
  797. RegionRec fbreg;
  798. // FIXME: We do a very crude bounding box around everything.
  799. // Might not be worth optimizing since this call is rarely
  800. // used.
  801. box.x1 = SHRT_MAX;
  802. box.y1 = SHRT_MAX;
  803. box.x2 = 0;
  804. box.y2 = 0;
  805. for (int i = 0;i < npoint;i++) {
  806. if (FixedToShort(points[i].x) < box.x1)
  807. box.x1 = FixedToShort(points[i].x);
  808. if (FixedToShort(points[i].y) < box.y1)
  809. box.y1 = FixedToShort(points[i].y);
  810. if (FixedToShort(points[i].x) > box.x2)
  811. box.x2 = FixedToShort(points[i].x);
  812. if (FixedToShort(points[i].y) > box.y2)
  813. box.y2 = FixedToShort(points[i].y);
  814. }
  815. box.x1 += pDst->pDrawable->x;
  816. box.y1 += pDst->pDrawable->y;
  817. box.x2 += pDst->pDrawable->x;
  818. box.y2 += pDst->pDrawable->y;
  819. RegionInitBoxes(&changed, &box, 1);
  820. box.x1 = 0;
  821. box.y1 = 0;
  822. box.x2 = pScreen->width;
  823. box.y2 = pScreen->height;
  824. RegionInitBoxes(&fbreg, &box, 1);
  825. RegionIntersect(&changed, &changed, &fbreg);
  826. RegionUninit(&fbreg);
  827. } else {
  828. RegionNull(&changed);
  829. }
  830. (*ps->TriStrip)(op, pSrc, pDst, maskFormat, xSrc, ySrc, npoint, points);
  831. add_changed(pScreen, &changed);
  832. RegionUninit(&changed);
  833. RENDER_EPILOGUE(TriStrip);
  834. }
  835. static void vncHooksTriFan(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  836. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  837. int npoint, xPointFixed * points)
  838. {
  839. RegionRec changed;
  840. RENDER_PROLOGUE(pDst->pDrawable->pScreen, TriFan);
  841. if (is_visible(pDst->pDrawable)) {
  842. BoxRec box;
  843. RegionRec fbreg;
  844. // FIXME: We do a very crude bounding box around everything.
  845. // Might not be worth optimizing since this call is rarely
  846. // used.
  847. box.x1 = SHRT_MAX;
  848. box.y1 = SHRT_MAX;
  849. box.x2 = 0;
  850. box.y2 = 0;
  851. for (int i = 0;i < npoint;i++) {
  852. if (FixedToShort(points[i].x) < box.x1)
  853. box.x1 = FixedToShort(points[i].x);
  854. if (FixedToShort(points[i].y) < box.y1)
  855. box.y1 = FixedToShort(points[i].y);
  856. if (FixedToShort(points[i].x) > box.x2)
  857. box.x2 = FixedToShort(points[i].x);
  858. if (FixedToShort(points[i].y) > box.y2)
  859. box.y2 = FixedToShort(points[i].y);
  860. }
  861. box.x1 += pDst->pDrawable->x;
  862. box.y1 += pDst->pDrawable->y;
  863. box.x2 += pDst->pDrawable->x;
  864. box.y2 += pDst->pDrawable->y;
  865. RegionInitBoxes(&changed, &box, 1);
  866. box.x1 = 0;
  867. box.y1 = 0;
  868. box.x2 = pScreen->width;
  869. box.y2 = pScreen->height;
  870. RegionInitBoxes(&fbreg, &box, 1);
  871. RegionIntersect(&changed, &changed, &fbreg);
  872. RegionUninit(&fbreg);
  873. } else {
  874. RegionNull(&changed);
  875. }
  876. (*ps->TriFan)(op, pSrc, pDst, maskFormat, xSrc, ySrc, npoint, points);
  877. add_changed(pScreen, &changed);
  878. RegionUninit(&changed);
  879. RENDER_EPILOGUE(TriFan);
  880. }
  881. // Unwrap and rewrap helpers
  882. #define RANDR_PROLOGUE(field) \
  883. rrScrPrivPtr rp = rrGetScrPriv(pScreen); \
  884. vncHooksScreenPtr vncHooksScreen = vncHooksScreenPrivate(pScreen); \
  885. unwrap(vncHooksScreen, rp, rr##field); \
  886. DBGPRINT((stderr,"vncHooksRandR" #field " called\n"));
  887. #define RANDR_EPILOGUE(field) \
  888. wrap(vncHooksScreen, rp, rr##field, vncHooksRandR##field); \
  889. // RandRSetConfig - follow any framebuffer changes
  890. static Bool vncHooksRandRSetConfig(ScreenPtr pScreen, Rotation rotation,
  891. int rate, RRScreenSizePtr pSize)
  892. {
  893. Bool ret;
  894. RANDR_PROLOGUE(SetConfig);
  895. vncPreScreenResize(pScreen->myNum);
  896. ret = (*rp->rrSetConfig)(pScreen, rotation, rate, pSize);
  897. vncPostScreenResize(pScreen->myNum, ret, pScreen->width, pScreen->height);
  898. RANDR_EPILOGUE(SetConfig);
  899. if (!ret)
  900. return FALSE;
  901. return TRUE;
  902. }
  903. static Bool vncHooksRandRScreenSetSize(ScreenPtr pScreen,
  904. CARD16 width, CARD16 height,
  905. CARD32 mmWidth, CARD32 mmHeight)
  906. {
  907. Bool ret;
  908. RANDR_PROLOGUE(ScreenSetSize);
  909. vncPreScreenResize(pScreen->myNum);
  910. ret = (*rp->rrScreenSetSize)(pScreen, width, height, mmWidth, mmHeight);
  911. vncPostScreenResize(pScreen->myNum, ret, pScreen->width, pScreen->height);
  912. RANDR_EPILOGUE(ScreenSetSize);
  913. if (!ret)
  914. return FALSE;
  915. return TRUE;
  916. }
  917. static Bool vncHooksRandRCrtcSet(ScreenPtr pScreen, RRCrtcPtr crtc,
  918. RRModePtr mode, int x, int y,
  919. Rotation rotation, int num_outputs,
  920. RROutputPtr *outputs)
  921. {
  922. Bool ret;
  923. RANDR_PROLOGUE(CrtcSet);
  924. ret = (*rp->rrCrtcSet)(pScreen, crtc, mode, x, y, rotation,
  925. num_outputs, outputs);
  926. RANDR_EPILOGUE(CrtcSet);
  927. if (!ret)
  928. return FALSE;
  929. vncRefreshScreenLayout(pScreen->myNum);
  930. return TRUE;
  931. }
  932. /////////////////////////////////////////////////////////////////////////////
  933. //
  934. // GC "funcs"
  935. //
  936. // Unwrap and rewrap helpers
  937. #define GC_FUNC_PROLOGUE(pGC, name)\
  938. vncHooksGCPtr pGCPriv = vncHooksGCPrivate(pGC);\
  939. unwrap(pGCPriv, pGC, funcs);\
  940. if (pGCPriv->ops) unwrap(pGCPriv, pGC, ops)\
  941. DBGPRINT((stderr,"vncHooks" #name " called\n"))
  942. #define GC_FUNC_EPILOGUE(pGC)\
  943. wrap(pGCPriv, pGC, funcs, &vncHooksGCFuncs);\
  944. if (pGCPriv->ops) wrap(pGCPriv, pGC, ops, &vncHooksGCOps)
  945. // ValidateGC - wrap the "ops" if the drawable is on screen
  946. static void vncHooksValidateGC(GCPtr pGC, unsigned long changes,
  947. DrawablePtr pDrawable)
  948. {
  949. GC_FUNC_PROLOGUE(pGC, ValidateGC);
  950. (*pGC->funcs->ValidateGC) (pGC, changes, pDrawable);
  951. if (is_visible(pDrawable)) {
  952. pGCPriv->ops = pGC->ops;
  953. DBGPRINT((stderr,"vncHooksValidateGC: wrapped GC ops\n"));
  954. } else {
  955. pGCPriv->ops = NULL;
  956. }
  957. GC_FUNC_EPILOGUE(pGC);
  958. }
  959. // Other GC funcs - just unwrap and call on
  960. static void vncHooksChangeGC(GCPtr pGC, unsigned long mask) {
  961. GC_FUNC_PROLOGUE(pGC, ChangeGC);
  962. (*pGC->funcs->ChangeGC) (pGC, mask);
  963. GC_FUNC_EPILOGUE(pGC);
  964. }
  965. static void vncHooksCopyGC(GCPtr src, unsigned long mask, GCPtr dst) {
  966. GC_FUNC_PROLOGUE(dst, CopyGC);
  967. (*dst->funcs->CopyGC) (src, mask, dst);
  968. GC_FUNC_EPILOGUE(dst);
  969. }
  970. static void vncHooksDestroyGC(GCPtr pGC) {
  971. GC_FUNC_PROLOGUE(pGC, DestroyGC);
  972. (*pGC->funcs->DestroyGC) (pGC);
  973. GC_FUNC_EPILOGUE(pGC);
  974. }
  975. static void vncHooksChangeClip(GCPtr pGC, int type, void * pValue, int nrects)
  976. {
  977. GC_FUNC_PROLOGUE(pGC, ChangeClip);
  978. (*pGC->funcs->ChangeClip) (pGC, type, pValue, nrects);
  979. GC_FUNC_EPILOGUE(pGC);
  980. }
  981. static void vncHooksDestroyClip(GCPtr pGC) {
  982. GC_FUNC_PROLOGUE(pGC, DestroyClip);
  983. (*pGC->funcs->DestroyClip) (pGC);
  984. GC_FUNC_EPILOGUE(pGC);
  985. }
  986. static void vncHooksCopyClip(GCPtr dst, GCPtr src) {
  987. GC_FUNC_PROLOGUE(dst, CopyClip);
  988. (*dst->funcs->CopyClip) (dst, src);
  989. GC_FUNC_EPILOGUE(dst);
  990. }
  991. /////////////////////////////////////////////////////////////////////////////
  992. //
  993. // GC "ops"
  994. //
  995. // Unwrap and rewrap helpers
  996. #define GC_OP_PROLOGUE(pGC, name)\
  997. vncHooksGCPtr pGCPriv = vncHooksGCPrivate(pGC);\
  998. const GCFuncs *oldFuncs = pGC->funcs;\
  999. unwrap(pGCPriv, pGC, funcs);\
  1000. unwrap(pGCPriv, pGC, ops);\
  1001. DBGPRINT((stderr,"vncHooks" #name " called\n"))
  1002. #define GC_OP_EPILOGUE(pGC)\
  1003. wrap(pGCPriv, pGC, funcs, oldFuncs); \
  1004. wrap(pGCPriv, pGC, ops, &vncHooksGCOps)
  1005. // FillSpans - assume the entire clip region is damaged. This is pessimistic,
  1006. // but I believe this function is rarely used so it doesn't matter.
  1007. static void vncHooksFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nInit,
  1008. DDXPointPtr pptInit, int *pwidthInit,
  1009. int fSorted)
  1010. {
  1011. RegionRec reg;
  1012. GC_OP_PROLOGUE(pGC, FillSpans);
  1013. RegionNull(&reg);
  1014. RegionCopy(&reg, pGC->pCompositeClip);
  1015. if (pDrawable->type == DRAWABLE_WINDOW)
  1016. RegionIntersect(&reg, &reg, &((WindowPtr)pDrawable)->borderClip);
  1017. (*pGC->ops->FillSpans) (pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted);
  1018. add_changed(pGC->pScreen, &reg);
  1019. RegionUninit(&reg);
  1020. GC_OP_EPILOGUE(pGC);
  1021. }
  1022. // SetSpans - assume the entire clip region is damaged. This is pessimistic,
  1023. // but I believe this function is rarely used so it doesn't matter.
  1024. static void vncHooksSetSpans(DrawablePtr pDrawable, GCPtr pGC, char *psrc,
  1025. DDXPointPtr ppt, int *pwidth, int nspans,
  1026. int fSorted)
  1027. {
  1028. RegionRec reg;
  1029. GC_OP_PROLOGUE(pGC, SetSpans);
  1030. RegionNull(&reg);
  1031. RegionCopy(&reg, pGC->pCompositeClip);
  1032. if (pDrawable->type == DRAWABLE_WINDOW)
  1033. RegionIntersect(&reg, &reg, &((WindowPtr)pDrawable)->borderClip);
  1034. (*pGC->ops->SetSpans) (pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted);
  1035. add_changed(pGC->pScreen, &reg);
  1036. RegionUninit(&reg);
  1037. GC_OP_EPILOGUE(pGC);
  1038. }
  1039. // PutImage - changed region is the given rectangle, clipped by pCompositeClip
  1040. static void vncHooksPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
  1041. int x, int y, int w, int h, int leftPad,
  1042. int format, char *pBits)
  1043. {
  1044. BoxRec box;
  1045. RegionRec reg;
  1046. GC_OP_PROLOGUE(pGC, PutImage);
  1047. box.x1 = x + pDrawable->x;
  1048. box.y1 = y + pDrawable->y;
  1049. box.x2 = box.x1 + w;
  1050. box.y2 = box.y1 + h;
  1051. RegionInitBoxes(&reg, &box, 1);
  1052. RegionIntersect(&reg, &reg, pGC->pCompositeClip);
  1053. (*pGC->ops->PutImage) (pDrawable, pGC, depth, x, y, w, h, leftPad, format,
  1054. pBits);
  1055. add_changed(pGC->pScreen, &reg);
  1056. RegionUninit(&reg);
  1057. GC_OP_EPILOGUE(pGC);
  1058. }
  1059. // CopyArea - destination of the copy is the dest rectangle, clipped by
  1060. // pCompositeClip. Any parts of the destination which cannot be copied from
  1061. // the source (could be all of it) go into the changed region.
  1062. static RegionPtr vncHooksCopyArea(DrawablePtr pSrc, DrawablePtr pDst,
  1063. GCPtr pGC, int srcx, int srcy, int w, int h,
  1064. int dstx, int dsty)
  1065. {
  1066. RegionRec dst, src, changed;
  1067. RegionPtr ret;
  1068. GC_OP_PROLOGUE(pGC, CopyArea);
  1069. // Apparently this happens now and then...
  1070. if ((w == 0) || (h == 0))
  1071. RegionNull(&dst);
  1072. else {
  1073. BoxRec box;
  1074. box.x1 = dstx + pDst->x;
  1075. box.y1 = dsty + pDst->y;
  1076. box.x2 = box.x1 + w;
  1077. box.y2 = box.y1 + h;
  1078. RegionInitBoxes(&dst, &box, 1);
  1079. }
  1080. RegionIntersect(&dst, &dst, pGC->pCompositeClip);
  1081. // The source of the data has to be something that's on screen.
  1082. if (is_visible(pSrc)) {
  1083. BoxRec box;
  1084. box.x1 = srcx + pSrc->x;
  1085. box.y1 = srcy + pSrc->y;
  1086. box.x2 = box.x1 + w;
  1087. box.y2 = box.y1 + h;
  1088. RegionInitBoxes(&src, &box, 1);
  1089. if ((pSrc->type == DRAWABLE_WINDOW) &&
  1090. RegionNotEmpty(&((WindowPtr)pSrc)->clipList)) {
  1091. RegionIntersect(&src, &src, &((WindowPtr)pSrc)->clipList);
  1092. }
  1093. RegionTranslate(&src,
  1094. dstx + pDst->x - srcx - pSrc->x,
  1095. dsty + pDst->y - srcy - pSrc->y);
  1096. } else {
  1097. RegionNull(&src);
  1098. }
  1099. RegionNull(&changed);
  1100. RegionSubtract(&changed, &dst, &src);
  1101. RegionIntersect(&dst, &dst, &src);
  1102. ret = (*pGC->ops->CopyArea) (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty);
  1103. add_copied(pGC->pScreen, &dst,
  1104. dstx + pDst->x - srcx - pSrc->x,
  1105. dsty + pDst->y - srcy - pSrc->y);
  1106. add_changed(pGC->pScreen, &changed);
  1107. RegionUninit(&dst);
  1108. RegionUninit(&src);
  1109. RegionUninit(&changed);
  1110. GC_OP_EPILOGUE(pGC);
  1111. return ret;
  1112. }
  1113. // CopyPlane - changed region is the destination rectangle, clipped by
  1114. // pCompositeClip
  1115. static RegionPtr vncHooksCopyPlane(DrawablePtr pSrc, DrawablePtr pDst,
  1116. GCPtr pGC, int srcx, int srcy, int w, int h,
  1117. int dstx, int dsty, unsigned long plane)
  1118. {
  1119. BoxRec box;
  1120. RegionRec reg;
  1121. RegionPtr ret;
  1122. GC_OP_PROLOGUE(pGC, CopyPlane);
  1123. box.x1 = dstx + pDst->x;
  1124. box.y1 = dsty + pDst->y;
  1125. box.x2 = box.x1 + w;
  1126. box.y2 = box.y1 + h;
  1127. RegionInitBoxes(&reg, &box, 1);
  1128. RegionIntersect(&reg, &reg, pGC->pCompositeClip);
  1129. ret = (*pGC->ops->CopyPlane) (pSrc, pDst, pGC, srcx, srcy, w, h,
  1130. dstx, dsty, plane);
  1131. add_changed(pGC->pScreen, &reg);
  1132. RegionUninit(&reg);
  1133. GC_OP_EPILOGUE(pGC);
  1134. return ret;
  1135. }
  1136. // PolyPoint - changed region is the bounding rect, clipped by pCompositeClip
  1137. static void vncHooksPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode,
  1138. int npt, xPoint *pts)
  1139. {
  1140. int minX, minY, maxX, maxY;
  1141. int i;
  1142. BoxRec box;
  1143. RegionRec reg;
  1144. GC_OP_PROLOGUE(pGC, PolyPoint);
  1145. if (npt == 0) {
  1146. (*pGC->ops->PolyPoint) (pDrawable, pGC, mode, npt, pts);
  1147. goto out;
  1148. }
  1149. minX = pts[0].x;
  1150. maxX = pts[0].x;
  1151. minY = pts[0].y;
  1152. maxY = pts[0].y;
  1153. if (mode == CoordModePrevious) {
  1154. int x = pts[0].x;
  1155. int y = pts[0].y;
  1156. for (i = 1; i < npt; i++) {
  1157. x += pts[i].x;
  1158. y += pts[i].y;
  1159. if (x < minX) minX = x;
  1160. if (x > maxX) maxX = x;
  1161. if (y < minY) minY = y;
  1162. if (y > maxY) maxY = y;
  1163. }
  1164. } else {
  1165. for (i = 1; i < npt; i++) {
  1166. if (pts[i].x < minX) minX = pts[i].x;
  1167. if (pts[i].x > maxX) maxX = pts[i].x;
  1168. if (pts[i].y < minY) minY = pts[i].y;
  1169. if (pts[i].y > maxY) maxY = pts[i].y;
  1170. }
  1171. }
  1172. box.x1 = minX + pDrawable->x;
  1173. box.y1 = minY + pDrawable->y;
  1174. box.x2 = maxX + 1 + pDrawable->x;
  1175. box.y2 = maxY + 1 + pDrawable->y;
  1176. RegionInitBoxes(&reg, &box, 1);
  1177. RegionIntersect(&reg, &reg, pGC->pCompositeClip);
  1178. (*pGC->ops->PolyPoint) (pDrawable, pGC, mode, npt, pts);
  1179. add_changed(pGC->pScreen, &reg);
  1180. RegionUninit(&reg);
  1181. out:
  1182. GC_OP_EPILOGUE(pGC);
  1183. }
  1184. // Polylines - changed region is the union of the bounding rects of each line,
  1185. // clipped by pCompositeClip. If there are more than MAX_RECTS_PER_OP lines,
  1186. // just use the bounding rect of all the lines.
  1187. static void vncHooksPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode,
  1188. int npt, DDXPointPtr ppts)
  1189. {
  1190. int nRegRects;
  1191. xRectangle regRects[MAX_RECTS_PER_OP];
  1192. int lw;
  1193. RegionPtr reg;
  1194. GC_OP_PROLOGUE(pGC, Polylines);
  1195. if (npt == 0) {
  1196. (*pGC->ops->Polylines) (pDrawable, pGC, mode, npt, ppts);
  1197. goto out;
  1198. }
  1199. nRegRects = npt - 1;
  1200. lw = pGC->lineWidth;
  1201. if (lw == 0)
  1202. lw = 1;
  1203. if (npt == 1)
  1204. {
  1205. // a single point
  1206. nRegRects = 1;
  1207. regRects[0].x = pDrawable->x + ppts[0].x - lw;
  1208. regRects[0].y = pDrawable->y + ppts[0].y - lw;
  1209. regRects[0].width = 2*lw;
  1210. regRects[0].height = 2*lw;
  1211. }
  1212. else
  1213. {
  1214. /*
  1215. * mitered joins can project quite a way from
  1216. * the line end; the 11 degree miter limit limits
  1217. * this extension to lw / (2 * tan(11/2)), rounded up
  1218. * and converted to int yields 6 * lw
  1219. */
  1220. int extra;
  1221. int prevX, prevY, curX, curY;
  1222. int rectX1, rectY1, rectX2, rectY2;
  1223. int minX, minY, maxX, maxY;
  1224. int i;
  1225. extra = lw / 2;
  1226. if (pGC->joinStyle == JoinMiter) {
  1227. extra = 6 * lw;
  1228. }
  1229. prevX = ppts[0].x + pDrawable->x;
  1230. prevY = ppts[0].y + pDrawable->y;
  1231. minX = maxX = prevX;
  1232. minY = maxY = prevY;
  1233. for (i = 0; i < nRegRects; i++) {
  1234. if (mode == CoordModeOrigin) {
  1235. curX = pDrawable->x + ppts[i+1].x;
  1236. curY = pDrawable->y + ppts[i+1].y;
  1237. } else {
  1238. curX = prevX + ppts[i+1].x;
  1239. curY = prevY + ppts[i+1].y;
  1240. }
  1241. if (prevX > curX) {
  1242. rectX1 = curX - extra;
  1243. rectX2 = prevX + extra + 1;
  1244. } else {
  1245. rectX1 = prevX - extra;
  1246. rectX2 = curX + extra + 1;
  1247. }
  1248. if (prevY > curY) {
  1249. rectY1 = curY - extra;
  1250. rectY2 = prevY + extra + 1;
  1251. } else {
  1252. rectY1 = prevY - extra;
  1253. rectY2 = curY + extra + 1;
  1254. }
  1255. if (nRegRects <= MAX_RECTS_PER_OP) {
  1256. regRects[i].x = rectX1;
  1257. regRects[i].y = rectY1;
  1258. regRects[i].width = rectX2 - rectX1;
  1259. regRects[i].height = rectY2 - rectY1;
  1260. } else {
  1261. if (rectX1 < minX) minX = rectX1;
  1262. if (rectY1 < minY) minY = rectY1;
  1263. if (rectX2 > maxX) maxX = rectX2;
  1264. if (rectY2 > maxY) maxY = rectY2;
  1265. }
  1266. prevX = curX;
  1267. prevY = curY;
  1268. }
  1269. if (nRegRects > MAX_RECTS_PER_OP) {
  1270. regRects[0].x = minX;
  1271. regRects[0].y = minY;
  1272. regRects[0].width = maxX - minX;
  1273. regRects[0].height = maxY - minY;
  1274. nRegRects = 1;
  1275. }
  1276. }
  1277. reg = RECTS_TO_REGION(pGC->pScreen, nRegRects, regRects, CT_NONE);
  1278. RegionIntersect(reg, reg, pGC->pCompositeClip);
  1279. (*pGC->ops->Polylines) (pDrawable, pGC, mode, npt, ppts);
  1280. add_changed(pGC->pScreen, reg);
  1281. RegionDestroy(reg);
  1282. out:
  1283. GC_OP_EPILOGUE(pGC);
  1284. }
  1285. // PolySegment - changed region is the union of the bounding rects of each
  1286. // segment, clipped by pCompositeClip. If there are more than MAX_RECTS_PER_OP
  1287. // segments, just use the bounding rect of all the segments.
  1288. static void vncHooksPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg,
  1289. xSegment *segs)
  1290. {
  1291. xRectangle regRects[MAX_RECTS_PER_OP];
  1292. int nRegRects;
  1293. int lw, extra;
  1294. int rectX1, rectY1, rectX2, rectY2;
  1295. int minX, minY, maxX, maxY;
  1296. int i;
  1297. RegionPtr reg;
  1298. GC_OP_PROLOGUE(pGC, PolySegment);
  1299. if (nseg == 0) {
  1300. (*pGC->ops->PolySegment) (pDrawable, pGC, nseg, segs);
  1301. goto out;
  1302. }
  1303. nRegRects = nseg;
  1304. lw = pGC->lineWidth;
  1305. extra = lw / 2;
  1306. minX = maxX = segs[0].x1;
  1307. minY = maxY = segs[0].y1;
  1308. for (i = 0; i < nseg; i++) {
  1309. if (segs[i].x1 > segs[i].x2) {
  1310. rectX1 = pDrawable->x + segs[i].x2 - extra;
  1311. rectX2 = pDrawable->x + segs[i].x1 + extra + 1;
  1312. } else {
  1313. rectX1 = pDrawable->x + segs[i].x1 - extra;
  1314. rectX2 = pDrawable->x + segs[i].x2 + extra + 1;
  1315. }
  1316. if (segs[i].y1 > segs[i].y2) {
  1317. rectY1 = pDrawable->y + segs[i].y2 - extra;
  1318. rectY2 = pDrawable->y + segs[i].y1 + extra + 1;
  1319. } else {
  1320. rectY1 = pDrawable->y + segs[i].y1 - extra;
  1321. rectY2 = pDrawable->y + segs[i].y2 + extra + 1;
  1322. }
  1323. if (nseg <= MAX_RECTS_PER_OP) {
  1324. regRects[i].x = rectX1;
  1325. regRects[i].y = rectY1;
  1326. regRects[i].width = rectX2 - rectX1;
  1327. regRects[i].height = rectY2 - rectY1;
  1328. } else {
  1329. if (rectX1 < minX) minX = rectX1;
  1330. if (rectY1 < minY) minY = rectY1;
  1331. if (rectX2 > maxX) maxX = rectX2;
  1332. if (rectY2 > maxY) maxY = rectY2;
  1333. }
  1334. }
  1335. if (nseg > MAX_RECTS_PER_OP) {
  1336. regRects[0].x = minX;
  1337. regRects[0].y = minY;
  1338. regRects[0].width = maxX - minX;
  1339. regRects[0].height = maxY - minY;
  1340. nRegRects = 1;
  1341. }
  1342. reg = RECTS_TO_REGION(pGC->pScreen, nRegRects, regRects, CT_NONE);
  1343. RegionIntersect(reg, reg, pGC->pCompositeClip);
  1344. (*pGC->ops->PolySegment) (pDrawable, pGC, nseg, segs);
  1345. add_changed(pGC->pScreen, reg);
  1346. RegionDestroy(reg);
  1347. out:
  1348. GC_OP_EPILOGUE(pGC);
  1349. }
  1350. // PolyRectangle - changed region is the union of the bounding rects around
  1351. // each side of the outline rectangles, clipped by pCompositeClip. If there
  1352. // are more than MAX_RECTS_PER_OP rectangles, just use the bounding rect of all
  1353. // the rectangles.
  1354. static void vncHooksPolyRectangle(DrawablePtr pDrawable, GCPtr pGC, int nrects,
  1355. xRectangle *rects)
  1356. {
  1357. xRectangle regRects[MAX_RECTS_PER_OP*4];
  1358. int nRegRects;
  1359. int lw, extra;
  1360. int rectX1, rectY1, rectX2, rectY2;
  1361. int minX, minY, maxX, maxY;
  1362. int i;
  1363. RegionPtr reg;
  1364. GC_OP_PROLOGUE(pGC, PolyRectangle);
  1365. if (nrects == 0) {
  1366. (*pGC->ops->PolyRectangle) (pDrawable, pGC, nrects, rects);
  1367. goto out;
  1368. }
  1369. nRegRects = nrects * 4;
  1370. lw = pGC->lineWidth;
  1371. extra = lw / 2;
  1372. minX = maxX = rects[0].x;
  1373. minY = maxY = rects[0].y;
  1374. for (i = 0; i < nrects; i++) {
  1375. if (nrects <= MAX_RECTS_PER_OP) {
  1376. regRects[i*4].x = rects[i].x - extra + pDrawable->x;
  1377. regRects[i*4].y = rects[i].y - extra + pDrawable->y;
  1378. regRects[i*4].width = rects[i].width + 1 + 2 * extra;
  1379. regRects[i*4].height = 1 + 2 * extra;
  1380. regRects[i*4+1].x = rects[i].x - extra + pDrawable->x;
  1381. regRects[i*4+1].y = rects[i].y - extra + pDrawable->y;
  1382. regRects[i*4+1].width = 1 + 2 * extra;
  1383. regRects[i*4+1].height = rects[i].height + 1 + 2 * extra;
  1384. regRects[i*4+2].x = rects[i].x + rects[i].width - extra + pDrawable->x;
  1385. regRects[i*4+2].y = rects[i].y - extra + pDrawable->y;
  1386. regRects[i*4+2].width = 1 + 2 * extra;
  1387. regRects[i*4+2].height = rects[i].height + 1 + 2 * extra;
  1388. regRects[i*4+3].x = rects[i].x - extra + pDrawable->x;
  1389. regRects[i*4+3].y = rects[i].y + rects[i].height - extra + pDrawable->y;
  1390. regRects[i*4+3].width = rects[i].width + 1 + 2 * extra;
  1391. regRects[i*4+3].height = 1 + 2 * extra;
  1392. } else {
  1393. rectX1 = pDrawable->x + rects[i].x - extra;
  1394. rectY1 = pDrawable->y + rects[i].y - extra;
  1395. rectX2 = pDrawable->x + rects[i].x + rects[i].width + extra+1;
  1396. rectY2 = pDrawable->y + rects[i].y + rects[i].height + extra+1;
  1397. if (rectX1 < minX) minX = rectX1;
  1398. if (rectY1 < minY) minY = rectY1;
  1399. if (rectX2 > maxX) maxX = rectX2;
  1400. if (rectY2 > maxY) maxY = rectY2;
  1401. }
  1402. }
  1403. if (nrects > MAX_RECTS_PER_OP) {
  1404. regRects[0].x = minX;
  1405. regRects[0].y = minY;
  1406. regRects[0].width = maxX - minX;
  1407. regRects[0].height = maxY - minY;
  1408. nRegRects = 1;
  1409. }
  1410. reg = RECTS_TO_REGION(pGC->pScreen, nRegRects, regRects, CT_NONE);
  1411. RegionIntersect(reg, reg, pGC->pCompositeClip);
  1412. (*pGC->ops->PolyRectangle) (pDrawable, pGC, nrects, rects);
  1413. add_changed(pGC->pScreen, reg);
  1414. RegionDestroy(reg);
  1415. out:
  1416. GC_OP_EPILOGUE(pGC);
  1417. }
  1418. // PolyArc - changed region is the union of bounding rects around each arc,
  1419. // clipped by pCompositeClip. If there are more than MAX_RECTS_PER_OP
  1420. // arcs, just use the bounding rect of all the arcs.
  1421. static void vncHooksPolyArc(DrawablePtr pDrawable, GCPtr pGC, int narcs,
  1422. xArc *arcs)
  1423. {
  1424. xRectangle regRects[MAX_RECTS_PER_OP];
  1425. int nRegRects;
  1426. int lw, extra;
  1427. int rectX1, rectY1, rectX2, rectY2;
  1428. int minX, minY, maxX, maxY;
  1429. int i;
  1430. RegionPtr reg;
  1431. GC_OP_PROLOGUE(pGC, PolyArc);
  1432. if (narcs == 0) {
  1433. (*pGC->ops->PolyArc) (pDrawable, pGC, narcs, arcs);
  1434. goto out;
  1435. }
  1436. nRegRects = narcs;
  1437. lw = pGC->lineWidth;
  1438. if (lw == 0)
  1439. lw = 1;
  1440. extra = lw / 2;
  1441. minX = maxX = arcs[0].x;
  1442. minY = maxY = arcs[0].y;
  1443. for (i = 0; i < narcs; i++) {
  1444. if (narcs <= MAX_RECTS_PER_OP) {
  1445. regRects[i].x = arcs[i].x - extra + pDrawable->x;
  1446. regRects[i].y = arcs[i].y - extra + pDrawable->y;
  1447. regRects[i].width = arcs[i].width + lw;
  1448. regRects[i].height = arcs[i].height + lw;
  1449. } else {
  1450. rectX1 = pDrawable->x + arcs[i].x - extra;
  1451. rectY1 = pDrawable->y + arcs[i].y - extra;
  1452. rectX2 = pDrawable->x + arcs[i].x + arcs[i].width + lw;
  1453. rectY2 = pDrawable->y + arcs[i].y + arcs[i].height + lw;
  1454. if (rectX1 < minX) minX = rectX1;
  1455. if (rectY1 < minY) minY = rectY1;
  1456. if (rectX2 > maxX) maxX = rectX2;
  1457. if (rectY2 > maxY) maxY = rectY2;
  1458. }
  1459. }
  1460. if (narcs > MAX_RECTS_PER_OP) {
  1461. regRects[0].x = minX;
  1462. regRects[0].y = minY;
  1463. regRects[0].width = maxX - minX;
  1464. regRects[0].height = maxY - minY;
  1465. nRegRects = 1;
  1466. }
  1467. reg = RECTS_TO_REGION(pGC->pScreen, nRegRects, regRects, CT_NONE);
  1468. RegionIntersect(reg, reg, pGC->pCompositeClip);
  1469. (*pGC->ops->PolyArc) (pDrawable, pGC, narcs, arcs);
  1470. add_changed(pGC->pScreen, reg);
  1471. RegionDestroy(reg);
  1472. out:
  1473. GC_OP_EPILOGUE(pGC);
  1474. }
  1475. // FillPolygon - changed region is the bounding rect around the polygon,
  1476. // clipped by pCompositeClip
  1477. static void vncHooksFillPolygon(DrawablePtr pDrawable, GCPtr pGC, int shape,
  1478. int mode, int count, DDXPointPtr pts)
  1479. {
  1480. int minX, minY, maxX, maxY;
  1481. int i;
  1482. BoxRec box;
  1483. RegionRec reg;
  1484. GC_OP_PROLOGUE(pGC, FillPolygon);
  1485. if (count == 0) {
  1486. (*pGC->ops->FillPolygon) (pDrawable, pGC, shape, mode, count, pts);
  1487. goto out;
  1488. }
  1489. minX = pts[0].x;
  1490. maxX = pts[0].x;
  1491. minY = pts[0].y;
  1492. maxY = pts[0].y;
  1493. if (mode == CoordModePrevious) {
  1494. int x = pts[0].x;
  1495. int y = pts[0].y;
  1496. for (i = 1; i < count; i++) {
  1497. x += pts[i].x;
  1498. y += pts[i].y;
  1499. if (x < minX) minX = x;
  1500. if (x > maxX) maxX = x;
  1501. if (y < minY) minY = y;
  1502. if (y > maxY) maxY = y;
  1503. }
  1504. } else {
  1505. for (i = 1; i < count; i++) {
  1506. if (pts[i].x < minX) minX = pts[i].x;
  1507. if (pts[i].x > maxX) maxX = pts[i].x;
  1508. if (pts[i].y < minY) minY = pts[i].y;
  1509. if (pts[i].y > maxY) maxY = pts[i].y;
  1510. }
  1511. }
  1512. box.x1 = minX + pDrawable->x;
  1513. box.y1 = minY + pDrawable->y;
  1514. box.x2 = maxX + 1 + pDrawable->x;
  1515. box.y2 = maxY + 1 + pDrawable->y;
  1516. RegionInitBoxes(&reg, &box, 1);
  1517. RegionIntersect(&reg, &reg, pGC->pCompositeClip);
  1518. (*pGC->ops->FillPolygon) (pDrawable, pGC, shape, mode, count, pts);
  1519. add_changed(pGC->pScreen, &reg);
  1520. RegionUninit(&reg);
  1521. out:
  1522. GC_OP_EPILOGUE(pGC);
  1523. }
  1524. // PolyFillRect - changed region is the union of the rectangles, clipped by
  1525. // pCompositeClip. If there are more than MAX_RECTS_PER_OP rectangles, just
  1526. // use the bounding rect of all the rectangles.
  1527. static void vncHooksPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nrects,
  1528. xRectangle *rects)
  1529. {
  1530. xRectangle regRects[MAX_RECTS_PER_OP];
  1531. int nRegRects;
  1532. int rectX1, rectY1, rectX2, rectY2;
  1533. int minX, minY, maxX, maxY;
  1534. int i;
  1535. RegionPtr reg;
  1536. GC_OP_PROLOGUE(pGC, PolyFillRect);
  1537. if (nrects == 0) {
  1538. (*pGC->ops->PolyFillRect) (pDrawable, pGC, nrects, rects);
  1539. goto out;
  1540. }
  1541. nRegRects = nrects;
  1542. minX = maxX = rects[0].x;
  1543. minY = maxY = rects[0].y;
  1544. for (i = 0; i < nrects; i++) {
  1545. if (nrects <= MAX_RECTS_PER_OP) {
  1546. regRects[i].x = rects[i].x + pDrawable->x;
  1547. regRects[i].y = rects[i].y + pDrawable->y;
  1548. regRects[i].width = rects[i].width;
  1549. regRects[i].height = rects[i].height;
  1550. } else {
  1551. rectX1 = pDrawable->x + rects[i].x;
  1552. rectY1 = pDrawable->y + rects[i].y;
  1553. rectX2 = pDrawable->x + rects[i].x + rects[i].width;
  1554. rectY2 = pDrawable->y + rects[i].y + rects[i].height;
  1555. if (rectX1 < minX) minX = rectX1;
  1556. if (rectY1 < minY) minY = rectY1;
  1557. if (rectX2 > maxX) maxX = rectX2;
  1558. if (rectY2 > maxY) maxY = rectY2;
  1559. }
  1560. }
  1561. if (nrects > MAX_RECTS_PER_OP) {
  1562. regRects[0].x = minX;
  1563. regRects[0].y = minY;
  1564. regRects[0].width = maxX - minX;
  1565. regRects[0].height = maxY - minY;
  1566. nRegRects = 1;
  1567. }
  1568. reg = RECTS_TO_REGION(pGC->pScreen, nRegRects, regRects, CT_NONE);
  1569. RegionIntersect(reg, reg, pGC->pCompositeClip);
  1570. (*pGC->ops->PolyFillRect) (pDrawable, pGC, nrects, rects);
  1571. add_changed(pGC->pScreen, reg);
  1572. RegionDestroy(reg);
  1573. out:
  1574. GC_OP_EPILOGUE(pGC);
  1575. }
  1576. // PolyFillArc - changed region is the union of bounding rects around each arc,
  1577. // clipped by pCompositeClip. If there are more than MAX_RECTS_PER_OP arcs,
  1578. // just use the bounding rect of all the arcs.
  1579. static void vncHooksPolyFillArc(DrawablePtr pDrawable, GCPtr pGC, int narcs,
  1580. xArc *arcs)
  1581. {
  1582. xRectangle regRects[MAX_RECTS_PER_OP];
  1583. int nRegRects;
  1584. int lw, extra;
  1585. int rectX1, rectY1, rectX2, rectY2;
  1586. int minX, minY, maxX, maxY;
  1587. int i;
  1588. RegionPtr reg;
  1589. GC_OP_PROLOGUE(pGC, PolyFillArc);
  1590. if (narcs == 0) {
  1591. (*pGC->ops->PolyFillArc) (pDrawable, pGC, narcs, arcs);
  1592. goto out;
  1593. }
  1594. nRegRects = narcs;
  1595. lw = pGC->lineWidth;
  1596. if (lw == 0)
  1597. lw = 1;
  1598. extra = lw / 2;
  1599. minX = maxX = arcs[0].x;
  1600. minY = maxY = arcs[0].y;
  1601. for (i = 0; i < narcs; i++) {
  1602. if (narcs <= MAX_RECTS_PER_OP) {
  1603. regRects[i].x = arcs[i].x - extra + pDrawable->x;
  1604. regRects[i].y = arcs[i].y - extra + pDrawable->y;
  1605. regRects[i].width = arcs[i].width + lw;
  1606. regRects[i].height = arcs[i].height + lw;
  1607. } else {
  1608. rectX1 = pDrawable->x + arcs[i].x - extra;
  1609. rectY1 = pDrawable->y + arcs[i].y - extra;
  1610. rectX2 = pDrawable->x + arcs[i].x + arcs[i].width + lw;
  1611. rectY2 = pDrawable->y + arcs[i].y + arcs[i].height + lw;
  1612. if (rectX1 < minX) minX = rectX1;
  1613. if (rectY1 < minY) minY = rectY1;
  1614. if (rectX2 > maxX) maxX = rectX2;
  1615. if (rectY2 > maxY) maxY = rectY2;
  1616. }
  1617. }
  1618. if (narcs > MAX_RECTS_PER_OP) {
  1619. regRects[0].x = minX;
  1620. regRects[0].y = minY;
  1621. regRects[0].width = maxX - minX;
  1622. regRects[0].height = maxY - minY;
  1623. nRegRects = 1;
  1624. }
  1625. reg = RECTS_TO_REGION(pGC->pScreen, nRegRects, regRects, CT_NONE);
  1626. RegionIntersect(reg, reg, pGC->pCompositeClip);
  1627. (*pGC->ops->PolyFillArc) (pDrawable, pGC, narcs, arcs);
  1628. add_changed(pGC->pScreen, reg);
  1629. RegionDestroy(reg);
  1630. out:
  1631. GC_OP_EPILOGUE(pGC);
  1632. }
  1633. // GetTextBoundingRect - calculate a bounding rectangle around n chars of a
  1634. // font. Not particularly accurate, but good enough.
  1635. static void GetTextBoundingRect(DrawablePtr pDrawable, FontPtr font, int x,
  1636. int y, int nchars, BoxPtr box)
  1637. {
  1638. int ascent = max(FONTASCENT(font), FONTMAXBOUNDS(font, ascent));
  1639. int descent = max(FONTDESCENT(font), FONTMAXBOUNDS(font, descent));
  1640. int charWidth = max(FONTMAXBOUNDS(font,rightSideBearing),
  1641. FONTMAXBOUNDS(font,characterWidth));
  1642. box->x1 = pDrawable->x + x;
  1643. box->y1 = pDrawable->y + y - ascent;
  1644. box->x2 = box->x1 + charWidth * nchars;
  1645. box->y2 = box->y1 + ascent + descent;
  1646. if (FONTMINBOUNDS(font,leftSideBearing) < 0)
  1647. box->x1 += FONTMINBOUNDS(font,leftSideBearing);
  1648. }
  1649. // PolyText8 - changed region is bounding rect around count chars, clipped by
  1650. // pCompositeClip
  1651. static int vncHooksPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  1652. int count, char *chars)
  1653. {
  1654. int ret;
  1655. BoxRec box;
  1656. RegionRec reg;
  1657. GC_OP_PROLOGUE(pGC, PolyText8);
  1658. if (count == 0) {
  1659. ret = (*pGC->ops->PolyText8) (pDrawable, pGC, x, y, count, chars);
  1660. goto out;
  1661. }
  1662. GetTextBoundingRect(pDrawable, pGC->font, x, y, count, &box);
  1663. RegionInitBoxes(&reg, &box, 1);
  1664. RegionIntersect(&reg, &reg, pGC->pCompositeClip);
  1665. ret = (*pGC->ops->PolyText8) (pDrawable, pGC, x, y, count, chars);
  1666. add_changed(pGC->pScreen, &reg);
  1667. RegionUninit(&reg);
  1668. out:
  1669. GC_OP_EPILOGUE(pGC);
  1670. return ret;
  1671. }
  1672. // PolyText16 - changed region is bounding rect around count chars, clipped by
  1673. // pCompositeClip
  1674. static int vncHooksPolyText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  1675. int count, unsigned short *chars)
  1676. {
  1677. int ret;
  1678. BoxRec box;
  1679. RegionRec reg;
  1680. GC_OP_PROLOGUE(pGC, PolyText16);
  1681. if (count == 0) {
  1682. ret = (*pGC->ops->PolyText16) (pDrawable, pGC, x, y, count, chars);
  1683. goto out;
  1684. }
  1685. GetTextBoundingRect(pDrawable, pGC->font, x, y, count, &box);
  1686. RegionInitBoxes(&reg, &box, 1);
  1687. RegionIntersect(&reg, &reg, pGC->pCompositeClip);
  1688. ret = (*pGC->ops->PolyText16) (pDrawable, pGC, x, y, count, chars);
  1689. add_changed(pGC->pScreen, &reg);
  1690. RegionUninit(&reg);
  1691. out:
  1692. GC_OP_EPILOGUE(pGC);
  1693. return ret;
  1694. }
  1695. // ImageText8 - changed region is bounding rect around count chars, clipped by
  1696. // pCompositeClip
  1697. static void vncHooksImageText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  1698. int count, char *chars)
  1699. {
  1700. BoxRec box;
  1701. RegionRec reg;
  1702. GC_OP_PROLOGUE(pGC, ImageText8);
  1703. if (count == 0) {
  1704. (*pGC->ops->ImageText8) (pDrawable, pGC, x, y, count, chars);
  1705. goto out;
  1706. }
  1707. GetTextBoundingRect(pDrawable, pGC->font, x, y, count, &box);
  1708. RegionInitBoxes(&reg, &box, 1);
  1709. RegionIntersect(&reg, &reg, pGC->pCompositeClip);
  1710. (*pGC->ops->ImageText8) (pDrawable, pGC, x, y, count, chars);
  1711. add_changed(pGC->pScreen, &reg);
  1712. RegionUninit(&reg);
  1713. out:
  1714. GC_OP_EPILOGUE(pGC);
  1715. }
  1716. // ImageText16 - changed region is bounding rect around count chars, clipped by
  1717. // pCompositeClip
  1718. static void vncHooksImageText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  1719. int count, unsigned short *chars)
  1720. {
  1721. BoxRec box;
  1722. RegionRec reg;
  1723. GC_OP_PROLOGUE(pGC, ImageText16);
  1724. if (count == 0) {
  1725. (*pGC->ops->ImageText16) (pDrawable, pGC, x, y, count, chars);
  1726. goto out;
  1727. }
  1728. GetTextBoundingRect(pDrawable, pGC->font, x, y, count, &box);
  1729. RegionInitBoxes(&reg, &box, 1);
  1730. RegionIntersect(&reg, &reg, pGC->pCompositeClip);
  1731. (*pGC->ops->ImageText16) (pDrawable, pGC, x, y, count, chars);
  1732. add_changed(pGC->pScreen, &reg);
  1733. RegionUninit(&reg);
  1734. out:
  1735. GC_OP_EPILOGUE(pGC);
  1736. }
  1737. // ImageGlyphBlt - changed region is bounding rect around nglyph chars, clipped
  1738. // by pCompositeClip
  1739. static void vncHooksImageGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x,
  1740. int y, unsigned int nglyph,
  1741. CharInfoPtr *ppci, void * pglyphBase)
  1742. {
  1743. BoxRec box;
  1744. RegionRec reg;
  1745. GC_OP_PROLOGUE(pGC, ImageGlyphBlt);
  1746. if (nglyph == 0) {
  1747. (*pGC->ops->ImageGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci,pglyphBase);
  1748. goto out;
  1749. }
  1750. GetTextBoundingRect(pDrawable, pGC->font, x, y, nglyph, &box);
  1751. RegionInitBoxes(&reg, &box, 1);
  1752. RegionIntersect(&reg, &reg, pGC->pCompositeClip);
  1753. (*pGC->ops->ImageGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
  1754. add_changed(pGC->pScreen, &reg);
  1755. RegionUninit(&reg);
  1756. out:
  1757. GC_OP_EPILOGUE(pGC);
  1758. }
  1759. // PolyGlyphBlt - changed region is bounding rect around nglyph chars, clipped
  1760. // by pCompositeClip
  1761. static void vncHooksPolyGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x,
  1762. int y, unsigned int nglyph,
  1763. CharInfoPtr *ppci, void * pglyphBase)
  1764. {
  1765. BoxRec box;
  1766. RegionRec reg;
  1767. GC_OP_PROLOGUE(pGC, PolyGlyphBlt);
  1768. if (nglyph == 0) {
  1769. (*pGC->ops->PolyGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci,pglyphBase);
  1770. goto out;
  1771. }
  1772. GetTextBoundingRect(pDrawable, pGC->font, x, y, nglyph, &box);
  1773. RegionInitBoxes(&reg, &box, 1);
  1774. RegionIntersect(&reg, &reg, pGC->pCompositeClip);
  1775. (*pGC->ops->PolyGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
  1776. add_changed(pGC->pScreen, &reg);
  1777. RegionUninit(&reg);
  1778. out:
  1779. GC_OP_EPILOGUE(pGC);
  1780. }
  1781. // PushPixels - changed region is the given rectangle, clipped by
  1782. // pCompositeClip
  1783. static void vncHooksPushPixels(GCPtr pGC, PixmapPtr pBitMap,
  1784. DrawablePtr pDrawable, int w, int h, int x,
  1785. int y)
  1786. {
  1787. BoxRec box;
  1788. RegionRec reg;
  1789. GC_OP_PROLOGUE(pGC, PushPixels);
  1790. box.x1 = x + pDrawable->x;
  1791. box.y1 = y + pDrawable->y;
  1792. box.x2 = box.x1 + w;
  1793. box.y2 = box.y1 + h;
  1794. RegionInitBoxes(&reg, &box, 1);
  1795. RegionIntersect(&reg, &reg, pGC->pCompositeClip);
  1796. (*pGC->ops->PushPixels) (pGC, pBitMap, pDrawable, w, h, x, y);
  1797. add_changed(pGC->pScreen, &reg);
  1798. RegionUninit(&reg);
  1799. GC_OP_EPILOGUE(pGC);
  1800. }