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 66KB

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. #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. ScreenBlockHandlerProcPtr BlockHandler;
  56. #ifdef RENDER
  57. CompositeProcPtr Composite;
  58. GlyphsProcPtr Glyphs;
  59. CompositeRectsProcPtr CompositeRects;
  60. TrapezoidsProcPtr Trapezoids;
  61. TrianglesProcPtr Triangles;
  62. TriStripProcPtr TriStrip;
  63. TriFanProcPtr TriFan;
  64. #endif
  65. RRSetConfigProcPtr rrSetConfig;
  66. RRScreenSetSizeProcPtr rrScreenSetSize;
  67. RRCrtcSetProcPtr rrCrtcSet;
  68. } vncHooksScreenRec, *vncHooksScreenPtr;
  69. typedef struct _vncHooksGCRec {
  70. const GCFuncs *funcs;
  71. const GCOps *ops;
  72. } vncHooksGCRec, *vncHooksGCPtr;
  73. #define wrap(priv, real, mem, func) {\
  74. priv->mem = real->mem; \
  75. real->mem = func; \
  76. }
  77. #define unwrap(priv, real, mem) {\
  78. real->mem = priv->mem; \
  79. }
  80. static DevPrivateKeyRec vncHooksScreenKeyRec;
  81. static DevPrivateKeyRec vncHooksGCKeyRec;
  82. #define vncHooksScreenPrivateKey (&vncHooksScreenKeyRec)
  83. #define vncHooksGCPrivateKey (&vncHooksGCKeyRec)
  84. #define vncHooksScreenPrivate(pScreen) \
  85. (vncHooksScreenPtr) dixLookupPrivate(&(pScreen)->devPrivates, \
  86. vncHooksScreenPrivateKey)
  87. #define vncHooksGCPrivate(pGC) \
  88. (vncHooksGCPtr) dixLookupPrivate(&(pGC)->devPrivates, \
  89. vncHooksGCPrivateKey)
  90. // screen functions
  91. static Bool vncHooksCloseScreen(ScreenPtr pScreen);
  92. static Bool vncHooksCreateGC(GCPtr pGC);
  93. static void vncHooksCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
  94. RegionPtr pOldRegion);
  95. static void vncHooksClearToBackground(WindowPtr pWin, int x, int y, int w,
  96. int h, Bool generateExposures);
  97. static Bool vncHooksDisplayCursor(DeviceIntPtr pDev,
  98. ScreenPtr pScreen, CursorPtr cursor);
  99. #if XORG <= 118
  100. static void vncHooksBlockHandler(ScreenPtr pScreen, void * pTimeout,
  101. void * pReadmask);
  102. #else
  103. static void vncHooksBlockHandler(ScreenPtr pScreen, void * pTimeout);
  104. #endif
  105. #ifdef RENDER
  106. static void vncHooksComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask,
  107. PicturePtr pDst, INT16 xSrc, INT16 ySrc, INT16 xMask,
  108. INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
  109. static void vncHooksGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  110. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlists,
  111. GlyphListPtr lists, GlyphPtr * glyphs);
  112. static void vncHooksCompositeRects(CARD8 op, PicturePtr pDst,
  113. xRenderColor * color, int nRect, xRectangle *rects);
  114. static void vncHooksTrapezoids(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  115. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  116. int ntrap, xTrapezoid * traps);
  117. static void vncHooksTriangles(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  118. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  119. int ntri, xTriangle * tris);
  120. static void vncHooksTriStrip(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  121. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  122. int npoint, xPointFixed * points);
  123. static void vncHooksTriFan(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  124. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  125. int npoint, xPointFixed * points);
  126. #endif
  127. static Bool vncHooksRandRSetConfig(ScreenPtr pScreen, Rotation rotation,
  128. int rate, RRScreenSizePtr pSize);
  129. static Bool vncHooksRandRScreenSetSize(ScreenPtr pScreen,
  130. CARD16 width, CARD16 height,
  131. CARD32 mmWidth, CARD32 mmHeight);
  132. static Bool vncHooksRandRCrtcSet(ScreenPtr pScreen, RRCrtcPtr crtc,
  133. RRModePtr mode, int x, int y,
  134. Rotation rotation, int numOutputs,
  135. RROutputPtr *outputs);
  136. // GC "funcs"
  137. static void vncHooksValidateGC(GCPtr pGC, unsigned long changes,
  138. DrawablePtr pDrawable);
  139. static void vncHooksChangeGC(GCPtr pGC, unsigned long mask);
  140. static void vncHooksCopyGC(GCPtr src, unsigned long mask, GCPtr dst);
  141. static void vncHooksDestroyGC(GCPtr pGC);
  142. static void vncHooksChangeClip(GCPtr pGC, int type, void * pValue,int nrects);
  143. static void vncHooksDestroyClip(GCPtr pGC);
  144. static void vncHooksCopyClip(GCPtr dst, GCPtr src);
  145. static GCFuncs vncHooksGCFuncs = {
  146. vncHooksValidateGC, vncHooksChangeGC, vncHooksCopyGC, vncHooksDestroyGC,
  147. vncHooksChangeClip, vncHooksDestroyClip, vncHooksCopyClip,
  148. };
  149. // GC "ops"
  150. static void vncHooksFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nInit,
  151. DDXPointPtr pptInit, int *pwidthInit,
  152. int fSorted);
  153. static void vncHooksSetSpans(DrawablePtr pDrawable, GCPtr pGC, char *psrc,
  154. DDXPointPtr ppt, int *pwidth, int nspans,
  155. int fSorted);
  156. static void vncHooksPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
  157. int x, int y, int w, int h, int leftPad,
  158. int format, char *pBits);
  159. static RegionPtr vncHooksCopyArea(DrawablePtr pSrc, DrawablePtr pDst,
  160. GCPtr pGC, int srcx, int srcy, int w, int h,
  161. int dstx, int dsty);
  162. static RegionPtr vncHooksCopyPlane(DrawablePtr pSrc, DrawablePtr pDst,
  163. GCPtr pGC, int srcx, int srcy, int w, int h,
  164. int dstx, int dsty, unsigned long plane);
  165. static void vncHooksPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode,
  166. int npt, xPoint *pts);
  167. static void vncHooksPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode,
  168. int npt, DDXPointPtr ppts);
  169. static void vncHooksPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg,
  170. xSegment *segs);
  171. static void vncHooksPolyRectangle(DrawablePtr pDrawable, GCPtr pGC, int nrects,
  172. xRectangle *rects);
  173. static void vncHooksPolyArc(DrawablePtr pDrawable, GCPtr pGC, int narcs,
  174. xArc *arcs);
  175. static void vncHooksFillPolygon(DrawablePtr pDrawable, GCPtr pGC, int shape,
  176. int mode, int count, DDXPointPtr pts);
  177. static void vncHooksPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nrects,
  178. xRectangle *rects);
  179. static void vncHooksPolyFillArc(DrawablePtr pDrawable, GCPtr pGC, int narcs,
  180. xArc *arcs);
  181. static int vncHooksPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  182. int count, char *chars);
  183. static int vncHooksPolyText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  184. int count, unsigned short *chars);
  185. static void vncHooksImageText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  186. int count, char *chars);
  187. static void vncHooksImageText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  188. int count, unsigned short *chars);
  189. static void vncHooksImageGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x,
  190. int y, unsigned int nglyph,
  191. CharInfoPtr *ppci, void * pglyphBase);
  192. static void vncHooksPolyGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x,
  193. int y, unsigned int nglyph,
  194. CharInfoPtr *ppci, void * pglyphBase);
  195. static void vncHooksPushPixels(GCPtr pGC, PixmapPtr pBitMap,
  196. DrawablePtr pDrawable, int w, int h, int x,
  197. int y);
  198. static GCOps vncHooksGCOps = {
  199. vncHooksFillSpans, vncHooksSetSpans, vncHooksPutImage, vncHooksCopyArea,
  200. vncHooksCopyPlane, vncHooksPolyPoint, vncHooksPolylines, vncHooksPolySegment,
  201. vncHooksPolyRectangle, vncHooksPolyArc, vncHooksFillPolygon,
  202. vncHooksPolyFillRect, vncHooksPolyFillArc, vncHooksPolyText8,
  203. vncHooksPolyText16, vncHooksImageText8, vncHooksImageText16,
  204. vncHooksImageGlyphBlt, vncHooksPolyGlyphBlt, vncHooksPushPixels
  205. };
  206. /////////////////////////////////////////////////////////////////////////////
  207. // vncHooksInit() is called at initialisation time and every time the server
  208. // resets. It is called once for each screen, but the indexes are only
  209. // allocated once for each server generation.
  210. int vncHooksInit(int scrIdx)
  211. {
  212. ScreenPtr pScreen;
  213. vncHooksScreenPtr vncHooksScreen;
  214. #ifdef RENDER
  215. PictureScreenPtr ps;
  216. #endif
  217. rrScrPrivPtr rp;
  218. pScreen = screenInfo.screens[scrIdx];
  219. if (sizeof(BoxRec) != sizeof(struct UpdateRect)) {
  220. ErrorF("vncHooksInit: Incompatible BoxRec size\n");
  221. return FALSE;
  222. }
  223. if (!dixRegisterPrivateKey(&vncHooksScreenKeyRec, PRIVATE_SCREEN,
  224. sizeof(vncHooksScreenRec))) {
  225. ErrorF("vncHooksInit: Allocation of vncHooksScreen failed\n");
  226. return FALSE;
  227. }
  228. if (!dixRegisterPrivateKey(&vncHooksGCKeyRec, PRIVATE_GC,
  229. sizeof(vncHooksGCRec))) {
  230. ErrorF("vncHooksInit: Allocation of vncHooksGCRec failed\n");
  231. return FALSE;
  232. }
  233. vncHooksScreen = vncHooksScreenPrivate(pScreen);
  234. vncHooksScreen->ignoreHooks = 0;
  235. wrap(vncHooksScreen, pScreen, CloseScreen, vncHooksCloseScreen);
  236. wrap(vncHooksScreen, pScreen, CreateGC, vncHooksCreateGC);
  237. wrap(vncHooksScreen, pScreen, CopyWindow, vncHooksCopyWindow);
  238. wrap(vncHooksScreen, pScreen, ClearToBackground, vncHooksClearToBackground);
  239. wrap(vncHooksScreen, pScreen, DisplayCursor, vncHooksDisplayCursor);
  240. wrap(vncHooksScreen, pScreen, BlockHandler, vncHooksBlockHandler);
  241. #ifdef RENDER
  242. ps = GetPictureScreenIfSet(pScreen);
  243. if (ps) {
  244. wrap(vncHooksScreen, ps, Composite, vncHooksComposite);
  245. wrap(vncHooksScreen, ps, Glyphs, vncHooksGlyphs);
  246. wrap(vncHooksScreen, ps, CompositeRects, vncHooksCompositeRects);
  247. wrap(vncHooksScreen, ps, Trapezoids, vncHooksTrapezoids);
  248. wrap(vncHooksScreen, ps, Triangles, vncHooksTriangles);
  249. wrap(vncHooksScreen, ps, TriStrip, vncHooksTriStrip);
  250. wrap(vncHooksScreen, ps, TriFan, vncHooksTriFan);
  251. }
  252. #endif
  253. rp = rrGetScrPriv(pScreen);
  254. if (rp) {
  255. /* Some RandR callbacks are optional */
  256. if (rp->rrSetConfig)
  257. wrap(vncHooksScreen, rp, rrSetConfig, vncHooksRandRSetConfig);
  258. if (rp->rrScreenSetSize)
  259. wrap(vncHooksScreen, rp, rrScreenSetSize, vncHooksRandRScreenSetSize);
  260. if (rp->rrCrtcSet)
  261. wrap(vncHooksScreen, rp, rrCrtcSet, vncHooksRandRCrtcSet);
  262. }
  263. return TRUE;
  264. }
  265. /////////////////////////////////////////////////////////////////////////////
  266. // vncGetScreenImage() grabs a chunk of data from the main screen into the
  267. // provided buffer. It lives here rather than in XorgGlue.c because it
  268. // temporarily pauses the hooks.
  269. void vncGetScreenImage(int scrIdx, int x, int y, int width, int height,
  270. char *buffer, int strideBytes)
  271. {
  272. ScreenPtr pScreen = screenInfo.screens[scrIdx];
  273. vncHooksScreenPtr vncHooksScreen = vncHooksScreenPrivate(pScreen);
  274. int i;
  275. vncHooksScreen->ignoreHooks++;
  276. // We do one line at a time since GetImage() cannot handle stride
  277. for (i = y; i < y + height; i++) {
  278. DrawablePtr pDrawable;
  279. pDrawable = (DrawablePtr) pScreen->root;
  280. (*pScreen->GetImage) (pDrawable, x, i, width, 1,
  281. ZPixmap, (unsigned long)~0L, buffer);
  282. buffer += strideBytes;
  283. }
  284. vncHooksScreen->ignoreHooks--;
  285. }
  286. /////////////////////////////////////////////////////////////////////////////
  287. //
  288. // Helper functions
  289. //
  290. static inline void add_changed(ScreenPtr pScreen, RegionPtr reg)
  291. {
  292. vncHooksScreenPtr vncHooksScreen = vncHooksScreenPrivate(pScreen);
  293. if (vncHooksScreen->ignoreHooks)
  294. return;
  295. vncAddChanged(pScreen->myNum,
  296. (const struct UpdateRect*)REGION_EXTENTS(pScreen, reg),
  297. REGION_NUM_RECTS(reg),
  298. (const struct UpdateRect*)REGION_RECTS(reg));
  299. }
  300. static inline void add_copied(ScreenPtr pScreen, RegionPtr dst,
  301. int dx, int dy)
  302. {
  303. vncHooksScreenPtr vncHooksScreen = vncHooksScreenPrivate(pScreen);
  304. if (vncHooksScreen->ignoreHooks)
  305. return;
  306. vncAddCopied(pScreen->myNum,
  307. (const struct UpdateRect*)REGION_EXTENTS(pScreen, dst),
  308. REGION_NUM_RECTS(dst),
  309. (const struct UpdateRect*)REGION_RECTS(dst), dx, dy);
  310. }
  311. static inline Bool is_visible(DrawablePtr drawable)
  312. {
  313. PixmapPtr scrPixmap;
  314. scrPixmap = drawable->pScreen->GetScreenPixmap(drawable->pScreen);
  315. if (drawable->type == DRAWABLE_WINDOW) {
  316. WindowPtr window;
  317. PixmapPtr winPixmap;
  318. window = (WindowPtr)drawable;
  319. winPixmap = drawable->pScreen->GetWindowPixmap(window);
  320. if (!window->viewable)
  321. return FALSE;
  322. if (winPixmap != scrPixmap)
  323. return FALSE;
  324. return TRUE;
  325. }
  326. if (drawable != &scrPixmap->drawable)
  327. return FALSE;
  328. return TRUE;
  329. }
  330. /////////////////////////////////////////////////////////////////////////////
  331. //
  332. // screen functions
  333. //
  334. // Unwrap and rewrap helpers
  335. #define SCREEN_PROLOGUE(scrn,field) \
  336. ScreenPtr pScreen = scrn; \
  337. vncHooksScreenPtr vncHooksScreen = vncHooksScreenPrivate(pScreen); \
  338. unwrap(vncHooksScreen, pScreen, field); \
  339. DBGPRINT((stderr,"vncHooks" #field " called\n"));
  340. #define SCREEN_EPILOGUE(field) \
  341. wrap(vncHooksScreen, pScreen, field, vncHooks##field); \
  342. // CloseScreen - unwrap the screen functions and call the original CloseScreen
  343. // function
  344. static Bool vncHooksCloseScreen(ScreenPtr pScreen_)
  345. {
  346. #ifdef RENDER
  347. PictureScreenPtr ps;
  348. #endif
  349. rrScrPrivPtr rp;
  350. SCREEN_PROLOGUE(pScreen_, CloseScreen);
  351. unwrap(vncHooksScreen, pScreen, CreateGC);
  352. unwrap(vncHooksScreen, pScreen, CopyWindow);
  353. unwrap(vncHooksScreen, pScreen, ClearToBackground);
  354. unwrap(vncHooksScreen, pScreen, DisplayCursor);
  355. unwrap(vncHooksScreen, pScreen, BlockHandler);
  356. #ifdef RENDER
  357. ps = GetPictureScreenIfSet(pScreen);
  358. if (ps) {
  359. unwrap(vncHooksScreen, ps, Composite);
  360. unwrap(vncHooksScreen, ps, Glyphs);
  361. unwrap(vncHooksScreen, ps, CompositeRects);
  362. unwrap(vncHooksScreen, ps, Trapezoids);
  363. unwrap(vncHooksScreen, ps, Triangles);
  364. unwrap(vncHooksScreen, ps, TriStrip);
  365. unwrap(vncHooksScreen, ps, TriFan);
  366. }
  367. #endif
  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. REGION_NULL(pScreen, &copied);
  401. REGION_COPY(pScreen, &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. REGION_INIT(pScreen, &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. REGION_INTERSECT(pScreen, &copied, &copied, &screen_rgn);
  414. REGION_TRANSLATE(pScreen, &copied, dx, dy);
  415. REGION_INTERSECT(pScreen, &copied, &copied, &screen_rgn);
  416. REGION_INTERSECT(pScreen, &copied, &copied, &pWin->borderClip);
  417. (*pScreen->CopyWindow) (pWin, ptOldOrg, pOldRegion);
  418. if (REGION_NOTEMPTY(pScreen, &copied))
  419. add_copied(pScreen, &copied, dx, dy);
  420. REGION_UNINIT(pScreen, &copied);
  421. REGION_UNINIT(pScreen, &screen_rgn);
  422. SCREEN_EPILOGUE(CopyWindow);
  423. }
  424. // ClearToBackground - changed region is the given rectangle, clipped by
  425. // clipList, but only if generateExposures is false.
  426. static void vncHooksClearToBackground(WindowPtr pWin, int x, int y, int w,
  427. int h, Bool generateExposures)
  428. {
  429. BoxRec box;
  430. RegionRec reg;
  431. SCREEN_PROLOGUE(pWin->drawable.pScreen, ClearToBackground);
  432. box.x1 = x + pWin->drawable.x;
  433. box.y1 = y + pWin->drawable.y;
  434. box.x2 = w ? (box.x1 + w) : (pWin->drawable.x + pWin->drawable.width);
  435. box.y2 = h ? (box.y1 + h) : (pWin->drawable.y + pWin->drawable.height);
  436. REGION_INIT(pScreen, &reg, &box, 0);
  437. REGION_INTERSECT(pScreen, &reg, &reg, &pWin->clipList);
  438. (*pScreen->ClearToBackground) (pWin, x, y, w, h, generateExposures);
  439. if (!generateExposures) {
  440. add_changed(pScreen, &reg);
  441. }
  442. REGION_UNINIT(pScreen, &reg);
  443. SCREEN_EPILOGUE(ClearToBackground);
  444. }
  445. // DisplayCursor - get the cursor shape
  446. static Bool vncHooksDisplayCursor(DeviceIntPtr pDev,
  447. ScreenPtr pScreen_, CursorPtr cursor)
  448. {
  449. Bool ret;
  450. SCREEN_PROLOGUE(pScreen_, DisplayCursor);
  451. ret = (*pScreen->DisplayCursor) (pDev, pScreen, cursor);
  452. /*
  453. * XXX DIX calls this function with NULL argument to remove cursor sprite from
  454. * screen. Should we handle this in setCursor as well?
  455. */
  456. if (cursor != NullCursor) {
  457. int width, height;
  458. int hotX, hotY;
  459. unsigned char *rgbaData;
  460. width = cursor->bits->width;
  461. height = cursor->bits->height;
  462. hotX = cursor->bits->xhot;
  463. hotY = cursor->bits->yhot;
  464. rgbaData = malloc(width * height * 4);
  465. if (rgbaData == NULL)
  466. goto out;
  467. if (cursor->bits->argb) {
  468. unsigned char *out;
  469. CARD32 *in;
  470. int i;
  471. in = cursor->bits->argb;
  472. out = rgbaData;
  473. for (i = 0; i < width*height; i++) {
  474. out[0] = (*in >> 16) & 0xff;
  475. out[1] = (*in >> 8) & 0xff;
  476. out[2] = (*in >> 0) & 0xff;
  477. out[3] = (*in >> 24) & 0xff;
  478. out += 4;
  479. in++;
  480. }
  481. } else {
  482. unsigned char *out;
  483. int xMaskBytesPerRow;
  484. xMaskBytesPerRow = BitmapBytePad(width);
  485. out = rgbaData;
  486. for (int y = 0; y < height; y++) {
  487. for (int x = 0; x < width; x++) {
  488. int byte = y * xMaskBytesPerRow + x / 8;
  489. #if (BITMAP_BIT_ORDER == MSBFirst)
  490. int bit = 7 - x % 8;
  491. #else
  492. int bit = x % 8;
  493. #endif
  494. if (cursor->bits->source[byte] & (1 << bit)) {
  495. out[0] = cursor->foreRed;
  496. out[1] = cursor->foreGreen;
  497. out[2] = cursor->foreBlue;
  498. } else {
  499. out[0] = cursor->backRed;
  500. out[1] = cursor->backGreen;
  501. out[2] = cursor->backBlue;
  502. }
  503. if (cursor->bits->mask[byte] & (1 << bit))
  504. out[3] = 0xff;
  505. else
  506. out[3] = 0x00;
  507. out += 4;
  508. }
  509. }
  510. }
  511. vncSetCursor(width, height, hotX, hotY, rgbaData);
  512. free(rgbaData);
  513. }
  514. out:
  515. SCREEN_EPILOGUE(DisplayCursor);
  516. return ret;
  517. }
  518. // BlockHandler - ignore any changes during the block handler - it's likely
  519. // these are just drawing the cursor.
  520. #if XORG <= 118
  521. static void vncHooksBlockHandler(ScreenPtr pScreen_, void * pTimeout,
  522. void * pReadmask)
  523. #else
  524. static void vncHooksBlockHandler(ScreenPtr pScreen_, void * pTimeout)
  525. #endif
  526. {
  527. SCREEN_PROLOGUE(pScreen_, BlockHandler);
  528. vncHooksScreen->ignoreHooks++;
  529. #if XORG <= 118
  530. (*pScreen->BlockHandler) (pScreen, pTimeout, pReadmask);
  531. #else
  532. (*pScreen->BlockHandler) (pScreen, pTimeout);
  533. #endif
  534. vncHooksScreen->ignoreHooks--;
  535. SCREEN_EPILOGUE(BlockHandler);
  536. }
  537. #ifdef RENDER
  538. // Unwrap and rewrap helpers
  539. #define RENDER_PROLOGUE(scrn,field) \
  540. ScreenPtr pScreen = scrn; \
  541. PictureScreenPtr ps = GetPictureScreen(pScreen); \
  542. vncHooksScreenPtr vncHooksScreen = vncHooksScreenPrivate(pScreen); \
  543. unwrap(vncHooksScreen, ps, field); \
  544. DBGPRINT((stderr,"vncHooks" #field " called\n"));
  545. #define RENDER_EPILOGUE(field) \
  546. wrap(vncHooksScreen, ps, field, vncHooks##field); \
  547. // Composite - The core of XRENDER
  548. static void vncHooksComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask,
  549. PicturePtr pDst, INT16 xSrc, INT16 ySrc, INT16 xMask,
  550. INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
  551. {
  552. RegionRec changed;
  553. RENDER_PROLOGUE(pDst->pDrawable->pScreen, Composite);
  554. if (is_visible(pDst->pDrawable)) {
  555. BoxRec box;
  556. RegionRec fbreg;
  557. box.x1 = max(pDst->pDrawable->x + xDst, 0);
  558. box.y1 = max(pDst->pDrawable->y + yDst, 0);
  559. box.x2 = box.x1 + width;
  560. box.y2 = box.y1 + height;
  561. REGION_INIT(pScreen, &changed, &box, 0);
  562. box.x1 = 0;
  563. box.y1 = 0;
  564. box.x2 = pScreen->width;
  565. box.y2 = pScreen->height;
  566. REGION_INIT(pScreen, &fbreg, &box, 0);
  567. REGION_INTERSECT(pScreen, &changed, &changed, &fbreg);
  568. REGION_UNINIT(pScreen, &fbreg);
  569. } else {
  570. REGION_NULL(pScreen, &changed);
  571. }
  572. (*ps->Composite)(op, pSrc, pMask, pDst, xSrc, ySrc,
  573. xMask, yMask, xDst, yDst, width, height);
  574. if (REGION_NOTEMPTY(pScreen, &changed))
  575. add_changed(pScreen, &changed);
  576. REGION_UNINIT(pScreen, &changed);
  577. RENDER_EPILOGUE(Composite);
  578. }
  579. static RegionPtr
  580. GlyphsToRegion(ScreenPtr pScreen, int nlist, GlyphListPtr list, GlyphPtr *glyphs)
  581. {
  582. int n;
  583. GlyphPtr glyph;
  584. int x, y;
  585. int nrects = nlist;
  586. xRectangle rects[nrects];
  587. xRectanglePtr rect;
  588. x = 0;
  589. y = 0;
  590. rect = &rects[0];
  591. while (nlist--) {
  592. int left, right, top, bottom;
  593. x += list->xOff;
  594. y += list->yOff;
  595. n = list->len;
  596. list++;
  597. left = INT_MAX;
  598. top = INT_MAX;
  599. right = -INT_MAX;
  600. bottom = -INT_MAX;
  601. while (n--) {
  602. int gx, gy, gw, gh;
  603. glyph = *glyphs++;
  604. gx = x - glyph->info.x;
  605. gy = y - glyph->info.y;
  606. gw = glyph->info.width;
  607. gh = glyph->info.height;
  608. x += glyph->info.xOff;
  609. y += glyph->info.yOff;
  610. if (gx < left)
  611. left = gx;
  612. if (gy < top)
  613. top = gy;
  614. if (gx + gw > right)
  615. right = gx + gw;
  616. if (gy + gh > bottom)
  617. bottom = gy + gh;
  618. }
  619. rect->x = left;
  620. rect->y = top;
  621. if ((right > left) && (bottom > top)) {
  622. rect->width = right - left;
  623. rect->height = bottom - top;
  624. } else {
  625. rect->width = 0;
  626. rect->height = 0;
  627. }
  628. rect++;
  629. }
  630. return RECTS_TO_REGION(pScreen, nrects, rects, CT_NONE);
  631. }
  632. // Glyphs - Glyph specific version of Composite (caches and whatnot)
  633. static void vncHooksGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  634. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlists,
  635. GlyphListPtr lists, GlyphPtr * glyphs)
  636. {
  637. RegionPtr changed;
  638. RENDER_PROLOGUE(pDst->pDrawable->pScreen, Glyphs);
  639. if (is_visible(pDst->pDrawable)) {
  640. BoxRec fbbox;
  641. RegionRec fbreg;
  642. changed = GlyphsToRegion(pScreen, nlists, lists, glyphs);
  643. REGION_TRANSLATE(pScreen, changed,
  644. pDst->pDrawable->x, pDst->pDrawable->y);
  645. fbbox.x1 = 0;
  646. fbbox.y1 = 0;
  647. fbbox.x2 = pScreen->width;
  648. fbbox.y2 = pScreen->height;
  649. REGION_INIT(pScreen, &fbreg, &fbbox, 0);
  650. REGION_INTERSECT(pScreen, changed, changed, &fbreg);
  651. REGION_UNINIT(pScreen, &fbreg);
  652. } else {
  653. changed = REGION_CREATE(pScreen, NullBox, 0);
  654. }
  655. (*ps->Glyphs)(op, pSrc, pDst, maskFormat, xSrc, ySrc, nlists, lists, glyphs);
  656. if (REGION_NOTEMPTY(pScreen, changed))
  657. add_changed(pScreen, changed);
  658. REGION_DESTROY(pScreen, changed);
  659. RENDER_EPILOGUE(Glyphs);
  660. }
  661. static void vncHooksCompositeRects(CARD8 op, PicturePtr pDst,
  662. xRenderColor * color, int nRect, xRectangle *rects)
  663. {
  664. RegionPtr changed;
  665. RENDER_PROLOGUE(pDst->pDrawable->pScreen, CompositeRects);
  666. if (is_visible(pDst->pDrawable)) {
  667. changed = RECTS_TO_REGION(pScreen, nRect, rects, CT_NONE);
  668. } else {
  669. changed = REGION_CREATE(pScreen, NullBox, 0);
  670. }
  671. (*ps->CompositeRects)(op, pDst, color, nRect, rects);
  672. if (REGION_NOTEMPTY(pScreen, changed))
  673. add_changed(pScreen, changed);
  674. REGION_DESTROY(pScreen, changed);
  675. RENDER_EPILOGUE(CompositeRects);
  676. }
  677. static inline short FixedToShort(xFixed fixed)
  678. {
  679. return (fixed + 0x8000) >> 16;
  680. }
  681. static void vncHooksTrapezoids(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  682. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  683. int ntrap, xTrapezoid * traps)
  684. {
  685. RegionRec changed;
  686. RENDER_PROLOGUE(pDst->pDrawable->pScreen, Trapezoids);
  687. if (is_visible(pDst->pDrawable)) {
  688. BoxRec box;
  689. RegionRec fbreg;
  690. // FIXME: We do a very crude bounding box around everything.
  691. // Might not be worth optimizing since this call is rarely
  692. // used.
  693. box.x1 = SHRT_MAX;
  694. box.y1 = SHRT_MAX;
  695. box.x2 = 0;
  696. box.y2 = 0;
  697. for (int i = 0;i < ntrap;i++) {
  698. if (FixedToShort(traps[i].left.p1.x) < box.x1)
  699. box.x1 = FixedToShort(traps[i].left.p1.x);
  700. if (FixedToShort(traps[i].left.p2.x) < box.x1)
  701. box.x1 = FixedToShort(traps[i].left.p2.x);
  702. if (FixedToShort(traps[i].top) < box.y1)
  703. box.y1 = FixedToShort(traps[i].top);
  704. if (FixedToShort(traps[i].right.p1.x) > box.x2)
  705. box.x2 = FixedToShort(traps[i].right.p1.x);
  706. if (FixedToShort(traps[i].right.p2.x) > box.x2)
  707. box.x2 = FixedToShort(traps[i].right.p2.x);
  708. if (FixedToShort(traps[i].bottom) > box.y2)
  709. box.y2 = FixedToShort(traps[i].bottom);
  710. }
  711. box.x1 += pDst->pDrawable->x;
  712. box.y1 += pDst->pDrawable->y;
  713. box.x2 += pDst->pDrawable->x;
  714. box.y2 += pDst->pDrawable->y;
  715. REGION_INIT(pScreen, &changed, &box, 0);
  716. box.x1 = 0;
  717. box.y1 = 0;
  718. box.x2 = pScreen->width;
  719. box.y2 = pScreen->height;
  720. REGION_INIT(pScreen, &fbreg, &box, 0);
  721. REGION_INTERSECT(pScreen, &changed, &changed, &fbreg);
  722. REGION_UNINIT(pScreen, &fbreg);
  723. } else {
  724. REGION_NULL(pScreen, &changed);
  725. }
  726. (*ps->Trapezoids)(op, pSrc, pDst, maskFormat, xSrc, ySrc, ntrap, traps);
  727. if (REGION_NOTEMPTY(pScreen, &changed))
  728. add_changed(pScreen, &changed);
  729. REGION_UNINIT(pScreen, &changed);
  730. RENDER_EPILOGUE(Trapezoids);
  731. }
  732. static void vncHooksTriangles(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  733. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  734. int ntri, xTriangle * tris)
  735. {
  736. RegionRec changed;
  737. RENDER_PROLOGUE(pDst->pDrawable->pScreen, Triangles);
  738. if (is_visible(pDst->pDrawable)) {
  739. BoxRec box;
  740. RegionRec fbreg;
  741. // FIXME: We do a very crude bounding box around everything.
  742. // Might not be worth optimizing since this call is rarely
  743. // used.
  744. box.x1 = SHRT_MAX;
  745. box.y1 = SHRT_MAX;
  746. box.x2 = 0;
  747. box.y2 = 0;
  748. for (int i = 0;i < ntri;i++) {
  749. xFixed left, right, top, bottom;
  750. left = min(min(tris[i].p1.x, tris[i].p2.x), tris[i].p3.x);
  751. right = max(max(tris[i].p1.x, tris[i].p2.x), tris[i].p3.x);
  752. top = min(min(tris[i].p1.y, tris[i].p2.y), tris[i].p3.y);
  753. bottom = max(max(tris[i].p1.y, tris[i].p2.y), tris[i].p3.y);
  754. if (FixedToShort(left) < box.x1)
  755. box.x1 = FixedToShort(left);
  756. if (FixedToShort(top) < box.y1)
  757. box.y1 = FixedToShort(top);
  758. if (FixedToShort(right) > box.x2)
  759. box.x2 = FixedToShort(right);
  760. if (FixedToShort(bottom) > box.y2)
  761. box.y2 = FixedToShort(bottom);
  762. }
  763. box.x1 += pDst->pDrawable->x;
  764. box.y1 += pDst->pDrawable->y;
  765. box.x2 += pDst->pDrawable->x;
  766. box.y2 += pDst->pDrawable->y;
  767. REGION_INIT(pScreen, &changed, &box, 0);
  768. box.x1 = 0;
  769. box.y1 = 0;
  770. box.x2 = pScreen->width;
  771. box.y2 = pScreen->height;
  772. REGION_INIT(pScreen, &fbreg, &box, 0);
  773. REGION_INTERSECT(pScreen, &changed, &changed, &fbreg);
  774. REGION_UNINIT(pScreen, &fbreg);
  775. } else {
  776. REGION_NULL(pScreen, &changed);
  777. }
  778. (*ps->Triangles)(op, pSrc, pDst, maskFormat, xSrc, ySrc, ntri, tris);
  779. if (REGION_NOTEMPTY(pScreen, &changed))
  780. add_changed(pScreen, &changed);
  781. REGION_UNINIT(pScreen, &changed);
  782. RENDER_EPILOGUE(Triangles);
  783. }
  784. static void vncHooksTriStrip(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  785. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  786. int npoint, xPointFixed * points)
  787. {
  788. RegionRec changed;
  789. RENDER_PROLOGUE(pDst->pDrawable->pScreen, TriStrip);
  790. if (is_visible(pDst->pDrawable)) {
  791. BoxRec box;
  792. RegionRec fbreg;
  793. // FIXME: We do a very crude bounding box around everything.
  794. // Might not be worth optimizing since this call is rarely
  795. // used.
  796. box.x1 = SHRT_MAX;
  797. box.y1 = SHRT_MAX;
  798. box.x2 = 0;
  799. box.y2 = 0;
  800. for (int i = 0;i < npoint;i++) {
  801. if (FixedToShort(points[i].x) < box.x1)
  802. box.x1 = FixedToShort(points[i].x);
  803. if (FixedToShort(points[i].y) < box.y1)
  804. box.y1 = FixedToShort(points[i].y);
  805. if (FixedToShort(points[i].x) > box.x2)
  806. box.x2 = FixedToShort(points[i].x);
  807. if (FixedToShort(points[i].y) > box.y2)
  808. box.y2 = FixedToShort(points[i].y);
  809. }
  810. box.x1 += pDst->pDrawable->x;
  811. box.y1 += pDst->pDrawable->y;
  812. box.x2 += pDst->pDrawable->x;
  813. box.y2 += pDst->pDrawable->y;
  814. REGION_INIT(pScreen, &changed, &box, 0);
  815. box.x1 = 0;
  816. box.y1 = 0;
  817. box.x2 = pScreen->width;
  818. box.y2 = pScreen->height;
  819. REGION_INIT(pScreen, &fbreg, &box, 0);
  820. REGION_INTERSECT(pScreen, &changed, &changed, &fbreg);
  821. REGION_UNINIT(pScreen, &fbreg);
  822. } else {
  823. REGION_NULL(pScreen, &changed);
  824. }
  825. (*ps->TriStrip)(op, pSrc, pDst, maskFormat, xSrc, ySrc, npoint, points);
  826. if (REGION_NOTEMPTY(pScreen, &changed))
  827. add_changed(pScreen, &changed);
  828. REGION_UNINIT(pScreen, &changed);
  829. RENDER_EPILOGUE(TriStrip);
  830. }
  831. static void vncHooksTriFan(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
  832. PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
  833. int npoint, xPointFixed * points)
  834. {
  835. RegionRec changed;
  836. RENDER_PROLOGUE(pDst->pDrawable->pScreen, TriFan);
  837. if (is_visible(pDst->pDrawable)) {
  838. BoxRec box;
  839. RegionRec fbreg;
  840. // FIXME: We do a very crude bounding box around everything.
  841. // Might not be worth optimizing since this call is rarely
  842. // used.
  843. box.x1 = SHRT_MAX;
  844. box.y1 = SHRT_MAX;
  845. box.x2 = 0;
  846. box.y2 = 0;
  847. for (int i = 0;i < npoint;i++) {
  848. if (FixedToShort(points[i].x) < box.x1)
  849. box.x1 = FixedToShort(points[i].x);
  850. if (FixedToShort(points[i].y) < box.y1)
  851. box.y1 = FixedToShort(points[i].y);
  852. if (FixedToShort(points[i].x) > box.x2)
  853. box.x2 = FixedToShort(points[i].x);
  854. if (FixedToShort(points[i].y) > box.y2)
  855. box.y2 = FixedToShort(points[i].y);
  856. }
  857. box.x1 += pDst->pDrawable->x;
  858. box.y1 += pDst->pDrawable->y;
  859. box.x2 += pDst->pDrawable->x;
  860. box.y2 += pDst->pDrawable->y;
  861. REGION_INIT(pScreen, &changed, &box, 0);
  862. box.x1 = 0;
  863. box.y1 = 0;
  864. box.x2 = pScreen->width;
  865. box.y2 = pScreen->height;
  866. REGION_INIT(pScreen, &fbreg, &box, 0);
  867. REGION_INTERSECT(pScreen, &changed, &changed, &fbreg);
  868. REGION_UNINIT(pScreen, &fbreg);
  869. } else {
  870. REGION_NULL(pScreen, &changed);
  871. }
  872. (*ps->TriFan)(op, pSrc, pDst, maskFormat, xSrc, ySrc, npoint, points);
  873. if (REGION_NOTEMPTY(pScreen, &changed))
  874. add_changed(pScreen, &changed);
  875. REGION_UNINIT(pScreen, &changed);
  876. RENDER_EPILOGUE(TriFan);
  877. }
  878. #endif /* RENDER */
  879. // Unwrap and rewrap helpers
  880. #define RANDR_PROLOGUE(field) \
  881. rrScrPrivPtr rp = rrGetScrPriv(pScreen); \
  882. vncHooksScreenPtr vncHooksScreen = vncHooksScreenPrivate(pScreen); \
  883. unwrap(vncHooksScreen, rp, rr##field); \
  884. DBGPRINT((stderr,"vncHooksRandR" #field " called\n"));
  885. #define RANDR_EPILOGUE(field) \
  886. wrap(vncHooksScreen, rp, rr##field, vncHooksRandR##field); \
  887. // RandRSetConfig - follow any framebuffer changes
  888. static Bool vncHooksRandRSetConfig(ScreenPtr pScreen, Rotation rotation,
  889. int rate, RRScreenSizePtr pSize)
  890. {
  891. Bool ret;
  892. RANDR_PROLOGUE(SetConfig);
  893. vncPreScreenResize(pScreen->myNum);
  894. ret = (*rp->rrSetConfig)(pScreen, rotation, rate, pSize);
  895. vncPostScreenResize(pScreen->myNum, ret, pScreen->width, pScreen->height);
  896. RANDR_EPILOGUE(SetConfig);
  897. if (!ret)
  898. return FALSE;
  899. return TRUE;
  900. }
  901. static Bool vncHooksRandRScreenSetSize(ScreenPtr pScreen,
  902. CARD16 width, CARD16 height,
  903. CARD32 mmWidth, CARD32 mmHeight)
  904. {
  905. Bool ret;
  906. RANDR_PROLOGUE(ScreenSetSize);
  907. vncPreScreenResize(pScreen->myNum);
  908. ret = (*rp->rrScreenSetSize)(pScreen, width, height, mmWidth, mmHeight);
  909. vncPostScreenResize(pScreen->myNum, ret, pScreen->width, pScreen->height);
  910. RANDR_EPILOGUE(ScreenSetSize);
  911. if (!ret)
  912. return FALSE;
  913. return TRUE;
  914. }
  915. static Bool vncHooksRandRCrtcSet(ScreenPtr pScreen, RRCrtcPtr crtc,
  916. RRModePtr mode, int x, int y,
  917. Rotation rotation, int num_outputs,
  918. RROutputPtr *outputs)
  919. {
  920. Bool ret;
  921. RANDR_PROLOGUE(CrtcSet);
  922. ret = (*rp->rrCrtcSet)(pScreen, crtc, mode, x, y, rotation,
  923. num_outputs, outputs);
  924. RANDR_EPILOGUE(CrtcSet);
  925. if (!ret)
  926. return FALSE;
  927. vncRefreshScreenLayout(pScreen->myNum);
  928. return TRUE;
  929. }
  930. /////////////////////////////////////////////////////////////////////////////
  931. //
  932. // GC "funcs"
  933. //
  934. // Unwrap and rewrap helpers
  935. #define GC_FUNC_PROLOGUE(pGC, name)\
  936. vncHooksGCPtr pGCPriv = vncHooksGCPrivate(pGC);\
  937. unwrap(pGCPriv, pGC, funcs);\
  938. if (pGCPriv->ops) unwrap(pGCPriv, pGC, ops)\
  939. DBGPRINT((stderr,"vncHooks" #name " called\n"))
  940. #define GC_FUNC_EPILOGUE(pGC)\
  941. wrap(pGCPriv, pGC, funcs, &vncHooksGCFuncs);\
  942. if (pGCPriv->ops) wrap(pGCPriv, pGC, ops, &vncHooksGCOps)
  943. // ValidateGC - wrap the "ops" if the drawable is on screen
  944. static void vncHooksValidateGC(GCPtr pGC, unsigned long changes,
  945. DrawablePtr pDrawable)
  946. {
  947. GC_FUNC_PROLOGUE(pGC, ValidateGC);
  948. (*pGC->funcs->ValidateGC) (pGC, changes, pDrawable);
  949. if (is_visible(pDrawable)) {
  950. pGCPriv->ops = pGC->ops;
  951. DBGPRINT((stderr,"vncHooksValidateGC: wrapped GC ops\n"));
  952. } else {
  953. pGCPriv->ops = NULL;
  954. }
  955. GC_FUNC_EPILOGUE(pGC);
  956. }
  957. // Other GC funcs - just unwrap and call on
  958. static void vncHooksChangeGC(GCPtr pGC, unsigned long mask) {
  959. GC_FUNC_PROLOGUE(pGC, ChangeGC);
  960. (*pGC->funcs->ChangeGC) (pGC, mask);
  961. GC_FUNC_EPILOGUE(pGC);
  962. }
  963. static void vncHooksCopyGC(GCPtr src, unsigned long mask, GCPtr dst) {
  964. GC_FUNC_PROLOGUE(dst, CopyGC);
  965. (*dst->funcs->CopyGC) (src, mask, dst);
  966. GC_FUNC_EPILOGUE(dst);
  967. }
  968. static void vncHooksDestroyGC(GCPtr pGC) {
  969. GC_FUNC_PROLOGUE(pGC, DestroyGC);
  970. (*pGC->funcs->DestroyGC) (pGC);
  971. GC_FUNC_EPILOGUE(pGC);
  972. }
  973. static void vncHooksChangeClip(GCPtr pGC, int type, void * pValue, int nrects)
  974. {
  975. GC_FUNC_PROLOGUE(pGC, ChangeClip);
  976. (*pGC->funcs->ChangeClip) (pGC, type, pValue, nrects);
  977. GC_FUNC_EPILOGUE(pGC);
  978. }
  979. static void vncHooksDestroyClip(GCPtr pGC) {
  980. GC_FUNC_PROLOGUE(pGC, DestroyClip);
  981. (*pGC->funcs->DestroyClip) (pGC);
  982. GC_FUNC_EPILOGUE(pGC);
  983. }
  984. static void vncHooksCopyClip(GCPtr dst, GCPtr src) {
  985. GC_FUNC_PROLOGUE(dst, CopyClip);
  986. (*dst->funcs->CopyClip) (dst, src);
  987. GC_FUNC_EPILOGUE(dst);
  988. }
  989. /////////////////////////////////////////////////////////////////////////////
  990. //
  991. // GC "ops"
  992. //
  993. // Unwrap and rewrap helpers
  994. #define GC_OP_PROLOGUE(pGC, name)\
  995. vncHooksGCPtr pGCPriv = vncHooksGCPrivate(pGC);\
  996. const GCFuncs *oldFuncs = pGC->funcs;\
  997. unwrap(pGCPriv, pGC, funcs);\
  998. unwrap(pGCPriv, pGC, ops);\
  999. DBGPRINT((stderr,"vncHooks" #name " called\n"))
  1000. #define GC_OP_EPILOGUE(pGC)\
  1001. wrap(pGCPriv, pGC, funcs, oldFuncs); \
  1002. wrap(pGCPriv, pGC, ops, &vncHooksGCOps)
  1003. // FillSpans - assume the entire clip region is damaged. This is pessimistic,
  1004. // but I believe this function is rarely used so it doesn't matter.
  1005. static void vncHooksFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nInit,
  1006. DDXPointPtr pptInit, int *pwidthInit,
  1007. int fSorted)
  1008. {
  1009. RegionRec reg;
  1010. GC_OP_PROLOGUE(pGC, FillSpans);
  1011. REGION_NULL(pGC->pScreen, &reg);
  1012. REGION_COPY(pGC->pScreen, &reg, pGC->pCompositeClip);
  1013. if (pDrawable->type == DRAWABLE_WINDOW)
  1014. REGION_INTERSECT(pScreen, &reg, &reg, &((WindowPtr)pDrawable)->borderClip);
  1015. (*pGC->ops->FillSpans) (pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted);
  1016. add_changed(pGC->pScreen, &reg);
  1017. REGION_UNINIT(pGC->pScreen, &reg);
  1018. GC_OP_EPILOGUE(pGC);
  1019. }
  1020. // SetSpans - assume the entire clip region is damaged. This is pessimistic,
  1021. // but I believe this function is rarely used so it doesn't matter.
  1022. static void vncHooksSetSpans(DrawablePtr pDrawable, GCPtr pGC, char *psrc,
  1023. DDXPointPtr ppt, int *pwidth, int nspans,
  1024. int fSorted)
  1025. {
  1026. RegionRec reg;
  1027. GC_OP_PROLOGUE(pGC, SetSpans);
  1028. REGION_NULL(pGC->pScreen, &reg);
  1029. REGION_COPY(pGC->pScreen, &reg, pGC->pCompositeClip);
  1030. if (pDrawable->type == DRAWABLE_WINDOW)
  1031. REGION_INTERSECT(pScreen, &reg, &reg, &((WindowPtr)pDrawable)->borderClip);
  1032. (*pGC->ops->SetSpans) (pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted);
  1033. add_changed(pGC->pScreen, &reg);
  1034. REGION_UNINIT(pGC->pScreen, &reg);
  1035. GC_OP_EPILOGUE(pGC);
  1036. }
  1037. // PutImage - changed region is the given rectangle, clipped by pCompositeClip
  1038. static void vncHooksPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
  1039. int x, int y, int w, int h, int leftPad,
  1040. int format, char *pBits)
  1041. {
  1042. BoxRec box;
  1043. RegionRec reg;
  1044. GC_OP_PROLOGUE(pGC, PutImage);
  1045. box.x1 = x + pDrawable->x;
  1046. box.y1 = y + pDrawable->y;
  1047. box.x2 = box.x1 + w;
  1048. box.y2 = box.y1 + h;
  1049. REGION_INIT(pGC->pScreen, &reg, &box, 0);
  1050. REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
  1051. (*pGC->ops->PutImage) (pDrawable, pGC, depth, x, y, w, h, leftPad, format,
  1052. pBits);
  1053. add_changed(pGC->pScreen, &reg);
  1054. REGION_UNINIT(pGC->pScreen, &reg);
  1055. GC_OP_EPILOGUE(pGC);
  1056. }
  1057. // CopyArea - destination of the copy is the dest rectangle, clipped by
  1058. // pCompositeClip. Any parts of the destination which cannot be copied from
  1059. // the source (could be all of it) go into the changed region.
  1060. static RegionPtr vncHooksCopyArea(DrawablePtr pSrc, DrawablePtr pDst,
  1061. GCPtr pGC, int srcx, int srcy, int w, int h,
  1062. int dstx, int dsty)
  1063. {
  1064. RegionRec dst, src, changed;
  1065. RegionPtr ret;
  1066. GC_OP_PROLOGUE(pGC, CopyArea);
  1067. // Apparently this happens now and then...
  1068. if ((w == 0) || (h == 0))
  1069. REGION_NULL(pGC->pScreen, &dst);
  1070. else {
  1071. BoxRec box;
  1072. box.x1 = dstx + pDst->x;
  1073. box.y1 = dsty + pDst->y;
  1074. box.x2 = box.x1 + w;
  1075. box.y2 = box.y1 + h;
  1076. REGION_INIT(pGC->pScreen, &dst, &box, 0);
  1077. }
  1078. REGION_INTERSECT(pGC->pScreen, &dst, &dst, pGC->pCompositeClip);
  1079. // The source of the data has to be something that's on screen.
  1080. if (is_visible(pSrc)) {
  1081. BoxRec box;
  1082. box.x1 = srcx + pSrc->x;
  1083. box.y1 = srcy + pSrc->y;
  1084. box.x2 = box.x1 + w;
  1085. box.y2 = box.y1 + h;
  1086. REGION_INIT(pGC->pScreen, &src, &box, 0);
  1087. if ((pSrc->type == DRAWABLE_WINDOW) &&
  1088. REGION_NOTEMPTY(pScreen, &((WindowPtr)pSrc)->clipList)) {
  1089. REGION_INTERSECT(pScreen, &src, &src, &((WindowPtr)pSrc)->clipList);
  1090. }
  1091. REGION_TRANSLATE(pScreen, &src,
  1092. dstx + pDst->x - srcx - pSrc->x,
  1093. dsty + pDst->y - srcy - pSrc->y);
  1094. } else {
  1095. REGION_NULL(pGC->pScreen, &src);
  1096. }
  1097. REGION_NULL(pGC->pScreen, &changed);
  1098. REGION_SUBTRACT(pScreen, &changed, &dst, &src);
  1099. REGION_INTERSECT(pScreen, &dst, &dst, &src);
  1100. ret = (*pGC->ops->CopyArea) (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty);
  1101. if (REGION_NOTEMPTY(pScreen, &dst))
  1102. add_copied(pGC->pScreen, &dst,
  1103. dstx + pDst->x - srcx - pSrc->x,
  1104. dsty + pDst->y - srcy - pSrc->y);
  1105. if (REGION_NOTEMPTY(pScreen, &changed))
  1106. add_changed(pGC->pScreen, &changed);
  1107. REGION_UNINIT(pGC->pScreen, &dst);
  1108. REGION_UNINIT(pGC->pScreen, &src);
  1109. REGION_UNINIT(pGC->pScreen, &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. REGION_INIT(pGC->pScreen, &reg, &box, 0);
  1128. REGION_INTERSECT(pGC->pScreen, &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. REGION_UNINIT(pGC->pScreen, &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. REGION_INIT(pGC->pScreen, &reg, &box, 0);
  1177. REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
  1178. (*pGC->ops->PolyPoint) (pDrawable, pGC, mode, npt, pts);
  1179. add_changed(pGC->pScreen, &reg);
  1180. REGION_UNINIT(pGC->pScreen, &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. REGION_INTERSECT(pGC->pScreen, reg, reg, pGC->pCompositeClip);
  1279. (*pGC->ops->Polylines) (pDrawable, pGC, mode, npt, ppts);
  1280. add_changed(pGC->pScreen, reg);
  1281. REGION_DESTROY(pGC->pScreen, 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. REGION_INTERSECT(pGC->pScreen, reg, reg, pGC->pCompositeClip);
  1344. (*pGC->ops->PolySegment) (pDrawable, pGC, nseg, segs);
  1345. add_changed(pGC->pScreen, reg);
  1346. REGION_DESTROY(pGC->pScreen, 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. REGION_INTERSECT(pGC->pScreen, reg, reg, pGC->pCompositeClip);
  1412. (*pGC->ops->PolyRectangle) (pDrawable, pGC, nrects, rects);
  1413. add_changed(pGC->pScreen, reg);
  1414. REGION_DESTROY(pGC->pScreen, 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. REGION_INTERSECT(pGC->pScreen, reg, reg, pGC->pCompositeClip);
  1469. (*pGC->ops->PolyArc) (pDrawable, pGC, narcs, arcs);
  1470. add_changed(pGC->pScreen, reg);
  1471. REGION_DESTROY(pGC->pScreen, 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. REGION_INIT(pGC->pScreen, &reg, &box, 0);
  1517. REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
  1518. (*pGC->ops->FillPolygon) (pDrawable, pGC, shape, mode, count, pts);
  1519. add_changed(pGC->pScreen, &reg);
  1520. REGION_UNINIT(pGC->pScreen, &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. REGION_INTERSECT(pGC->pScreen, reg, reg, pGC->pCompositeClip);
  1570. (*pGC->ops->PolyFillRect) (pDrawable, pGC, nrects, rects);
  1571. add_changed(pGC->pScreen, reg);
  1572. REGION_DESTROY(pGC->pScreen, 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. REGION_INTERSECT(pGC->pScreen, reg, reg, pGC->pCompositeClip);
  1627. (*pGC->ops->PolyFillArc) (pDrawable, pGC, narcs, arcs);
  1628. add_changed(pGC->pScreen, reg);
  1629. REGION_DESTROY(pGC->pScreen, 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. REGION_INIT(pGC->pScreen, &reg, &box, 0);
  1664. REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
  1665. ret = (*pGC->ops->PolyText8) (pDrawable, pGC, x, y, count, chars);
  1666. add_changed(pGC->pScreen, &reg);
  1667. REGION_UNINIT(pGC->pScreen, &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. REGION_INIT(pGC->pScreen, &reg, &box, 0);
  1687. REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
  1688. ret = (*pGC->ops->PolyText16) (pDrawable, pGC, x, y, count, chars);
  1689. add_changed(pGC->pScreen, &reg);
  1690. REGION_UNINIT(pGC->pScreen, &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. REGION_INIT(pGC->pScreen, &reg, &box, 0);
  1709. REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
  1710. (*pGC->ops->ImageText8) (pDrawable, pGC, x, y, count, chars);
  1711. add_changed(pGC->pScreen, &reg);
  1712. REGION_UNINIT(pGC->pScreen, &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. REGION_INIT(pGC->pScreen, &reg, &box, 0);
  1730. REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
  1731. (*pGC->ops->ImageText16) (pDrawable, pGC, x, y, count, chars);
  1732. add_changed(pGC->pScreen, &reg);
  1733. REGION_UNINIT(pGC->pScreen, &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. REGION_INIT(pGC->pScreen, &reg, &box, 0);
  1752. REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
  1753. (*pGC->ops->ImageGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
  1754. add_changed(pGC->pScreen, &reg);
  1755. REGION_UNINIT(pGC->pScreen, &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. REGION_INIT(pGC->pScreen, &reg, &box, 0);
  1774. REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
  1775. (*pGC->ops->PolyGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
  1776. add_changed(pGC->pScreen, &reg);
  1777. REGION_UNINIT(pGC->pScreen, &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. REGION_INIT(pGC->pScreen, &reg, &box, 0);
  1795. REGION_INTERSECT(pGC->pScreen, &reg, &reg, pGC->pCompositeClip);
  1796. (*pGC->ops->PushPixels) (pGC, pBitMap, pDrawable, w, h, x, y);
  1797. add_changed(pGC->pScreen, &reg);
  1798. REGION_UNINIT(pGC->pScreen, &reg);
  1799. GC_OP_EPILOGUE(pGC);
  1800. }