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

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