render.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698
  1. /*
  2. *
  3. * Copyright © 2000 SuSE, Inc.
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and its
  6. * documentation for any purpose is hereby granted without fee, provided that
  7. * the above copyright notice appear in all copies and that both that
  8. * copyright notice and this permission notice appear in supporting
  9. * documentation, and that the name of SuSE not be used in advertising or
  10. * publicity pertaining to distribution of the software without specific,
  11. * written prior permission. SuSE makes no representations about the
  12. * suitability of this software for any purpose. It is provided "as is"
  13. * without express or implied warranty.
  14. *
  15. * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
  17. * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  18. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  19. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  20. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21. *
  22. * Author: Keith Packard, SuSE, Inc.
  23. */
  24. #ifdef HAVE_DIX_CONFIG_H
  25. #include <dix-config.h>
  26. #endif
  27. #include <X11/X.h>
  28. #include <X11/Xproto.h>
  29. #include "misc.h"
  30. #include "os.h"
  31. #include "dixstruct.h"
  32. #include "resource.h"
  33. #include "scrnintstr.h"
  34. #include "windowstr.h"
  35. #include "pixmapstr.h"
  36. #include "colormapst.h"
  37. #include "extnsionst.h"
  38. #include "servermd.h"
  39. #include <X11/extensions/render.h>
  40. #include <X11/extensions/renderproto.h>
  41. #include "picturestr.h"
  42. #include "glyphstr.h"
  43. #include <X11/Xfuncproto.h>
  44. #include "cursorstr.h"
  45. #if HAVE_STDINT_H
  46. #include <stdint.h>
  47. #elif !defined(UINT32_MAX)
  48. #define UINT32_MAX 0xffffffffU
  49. #endif
  50. static int ProcRenderQueryVersion(ClientPtr pClient);
  51. static int ProcRenderQueryPictFormats(ClientPtr pClient);
  52. static int ProcRenderQueryPictIndexValues(ClientPtr pClient);
  53. static int ProcRenderQueryDithers(ClientPtr pClient);
  54. static int ProcRenderCreatePicture(ClientPtr pClient);
  55. static int ProcRenderChangePicture(ClientPtr pClient);
  56. static int ProcRenderSetPictureClipRectangles(ClientPtr pClient);
  57. static int ProcRenderFreePicture(ClientPtr pClient);
  58. static int ProcRenderComposite(ClientPtr pClient);
  59. static int ProcRenderScale(ClientPtr pClient);
  60. static int ProcRenderTrapezoids(ClientPtr pClient);
  61. static int ProcRenderTriangles(ClientPtr pClient);
  62. static int ProcRenderTriStrip(ClientPtr pClient);
  63. static int ProcRenderTriFan(ClientPtr pClient);
  64. static int ProcRenderColorTrapezoids(ClientPtr pClient);
  65. static int ProcRenderColorTriangles(ClientPtr pClient);
  66. static int ProcRenderTransform(ClientPtr pClient);
  67. static int ProcRenderCreateGlyphSet(ClientPtr pClient);
  68. static int ProcRenderReferenceGlyphSet(ClientPtr pClient);
  69. static int ProcRenderFreeGlyphSet(ClientPtr pClient);
  70. static int ProcRenderAddGlyphs(ClientPtr pClient);
  71. static int ProcRenderAddGlyphsFromPicture(ClientPtr pClient);
  72. static int ProcRenderFreeGlyphs(ClientPtr pClient);
  73. static int ProcRenderCompositeGlyphs(ClientPtr pClient);
  74. static int ProcRenderFillRectangles(ClientPtr pClient);
  75. static int ProcRenderCreateCursor(ClientPtr pClient);
  76. static int ProcRenderSetPictureTransform(ClientPtr pClient);
  77. static int ProcRenderQueryFilters(ClientPtr pClient);
  78. static int ProcRenderSetPictureFilter(ClientPtr pClient);
  79. static int ProcRenderCreateAnimCursor(ClientPtr pClient);
  80. static int ProcRenderAddTraps(ClientPtr pClient);
  81. static int ProcRenderCreateSolidFill(ClientPtr pClient);
  82. static int ProcRenderCreateLinearGradient(ClientPtr pClient);
  83. static int ProcRenderCreateRadialGradient(ClientPtr pClient);
  84. static int ProcRenderCreateConicalGradient(ClientPtr pClient);
  85. static int ProcRenderDispatch(ClientPtr pClient);
  86. static int SProcRenderQueryVersion(ClientPtr pClient);
  87. static int SProcRenderQueryPictFormats(ClientPtr pClient);
  88. static int SProcRenderQueryPictIndexValues(ClientPtr pClient);
  89. static int SProcRenderQueryDithers(ClientPtr pClient);
  90. static int SProcRenderCreatePicture(ClientPtr pClient);
  91. static int SProcRenderChangePicture(ClientPtr pClient);
  92. static int SProcRenderSetPictureClipRectangles(ClientPtr pClient);
  93. static int SProcRenderFreePicture(ClientPtr pClient);
  94. static int SProcRenderComposite(ClientPtr pClient);
  95. static int SProcRenderScale(ClientPtr pClient);
  96. static int SProcRenderTrapezoids(ClientPtr pClient);
  97. static int SProcRenderTriangles(ClientPtr pClient);
  98. static int SProcRenderTriStrip(ClientPtr pClient);
  99. static int SProcRenderTriFan(ClientPtr pClient);
  100. static int SProcRenderColorTrapezoids(ClientPtr pClient);
  101. static int SProcRenderColorTriangles(ClientPtr pClient);
  102. static int SProcRenderTransform(ClientPtr pClient);
  103. static int SProcRenderCreateGlyphSet(ClientPtr pClient);
  104. static int SProcRenderReferenceGlyphSet(ClientPtr pClient);
  105. static int SProcRenderFreeGlyphSet(ClientPtr pClient);
  106. static int SProcRenderAddGlyphs(ClientPtr pClient);
  107. static int SProcRenderAddGlyphsFromPicture(ClientPtr pClient);
  108. static int SProcRenderFreeGlyphs(ClientPtr pClient);
  109. static int SProcRenderCompositeGlyphs(ClientPtr pClient);
  110. static int SProcRenderFillRectangles(ClientPtr pClient);
  111. static int SProcRenderCreateCursor(ClientPtr pClient);
  112. static int SProcRenderSetPictureTransform(ClientPtr pClient);
  113. static int SProcRenderQueryFilters(ClientPtr pClient);
  114. static int SProcRenderSetPictureFilter(ClientPtr pClient);
  115. static int SProcRenderCreateAnimCursor(ClientPtr pClient);
  116. static int SProcRenderAddTraps(ClientPtr pClient);
  117. static int SProcRenderCreateSolidFill(ClientPtr pClient);
  118. static int SProcRenderCreateLinearGradient(ClientPtr pClient);
  119. static int SProcRenderCreateRadialGradient(ClientPtr pClient);
  120. static int SProcRenderCreateConicalGradient(ClientPtr pClient);
  121. static int SProcRenderDispatch(ClientPtr pClient);
  122. static int (*ProcRenderVector[RenderNumberRequests]) (ClientPtr) = {
  123. ProcRenderQueryVersion,
  124. ProcRenderQueryPictFormats,
  125. ProcRenderQueryPictIndexValues,
  126. ProcRenderQueryDithers,
  127. ProcRenderCreatePicture,
  128. ProcRenderChangePicture,
  129. ProcRenderSetPictureClipRectangles,
  130. ProcRenderFreePicture,
  131. ProcRenderComposite,
  132. ProcRenderScale,
  133. ProcRenderTrapezoids,
  134. ProcRenderTriangles,
  135. ProcRenderTriStrip,
  136. ProcRenderTriFan,
  137. ProcRenderColorTrapezoids,
  138. ProcRenderColorTriangles,
  139. ProcRenderTransform,
  140. ProcRenderCreateGlyphSet,
  141. ProcRenderReferenceGlyphSet,
  142. ProcRenderFreeGlyphSet,
  143. ProcRenderAddGlyphs,
  144. ProcRenderAddGlyphsFromPicture,
  145. ProcRenderFreeGlyphs,
  146. ProcRenderCompositeGlyphs,
  147. ProcRenderCompositeGlyphs,
  148. ProcRenderCompositeGlyphs,
  149. ProcRenderFillRectangles,
  150. ProcRenderCreateCursor,
  151. ProcRenderSetPictureTransform,
  152. ProcRenderQueryFilters,
  153. ProcRenderSetPictureFilter,
  154. ProcRenderCreateAnimCursor,
  155. ProcRenderAddTraps,
  156. ProcRenderCreateSolidFill,
  157. ProcRenderCreateLinearGradient,
  158. ProcRenderCreateRadialGradient, ProcRenderCreateConicalGradient};
  159. static int (*SProcRenderVector[RenderNumberRequests]) (ClientPtr) = {
  160. SProcRenderQueryVersion,
  161. SProcRenderQueryPictFormats,
  162. SProcRenderQueryPictIndexValues,
  163. SProcRenderQueryDithers,
  164. SProcRenderCreatePicture,
  165. SProcRenderChangePicture,
  166. SProcRenderSetPictureClipRectangles,
  167. SProcRenderFreePicture,
  168. SProcRenderComposite,
  169. SProcRenderScale,
  170. SProcRenderTrapezoids,
  171. SProcRenderTriangles,
  172. SProcRenderTriStrip,
  173. SProcRenderTriFan,
  174. SProcRenderColorTrapezoids,
  175. SProcRenderColorTriangles,
  176. SProcRenderTransform,
  177. SProcRenderCreateGlyphSet,
  178. SProcRenderReferenceGlyphSet,
  179. SProcRenderFreeGlyphSet,
  180. SProcRenderAddGlyphs,
  181. SProcRenderAddGlyphsFromPicture,
  182. SProcRenderFreeGlyphs,
  183. SProcRenderCompositeGlyphs,
  184. SProcRenderCompositeGlyphs,
  185. SProcRenderCompositeGlyphs,
  186. SProcRenderFillRectangles,
  187. SProcRenderCreateCursor,
  188. SProcRenderSetPictureTransform,
  189. SProcRenderQueryFilters,
  190. SProcRenderSetPictureFilter,
  191. SProcRenderCreateAnimCursor,
  192. SProcRenderAddTraps,
  193. SProcRenderCreateSolidFill,
  194. SProcRenderCreateLinearGradient,
  195. SProcRenderCreateRadialGradient, SProcRenderCreateConicalGradient};
  196. static void
  197. RenderResetProc(ExtensionEntry * extEntry);
  198. #if 0
  199. static CARD8 RenderReqCode;
  200. #endif
  201. int RenderErrBase;
  202. int RenderClientPrivateIndex;
  203. typedef struct _RenderClient {
  204. int major_version;
  205. int minor_version;
  206. } RenderClientRec, *RenderClientPtr;
  207. #define GetRenderClient(pClient) ((RenderClientPtr) (pClient)->devPrivates[RenderClientPrivateIndex].ptr)
  208. static void
  209. RenderClientCallback(CallbackListPtr *list, pointer closure, pointer data)
  210. {
  211. NewClientInfoRec *clientinfo = (NewClientInfoRec *) data;
  212. ClientPtr pClient = clientinfo->client;
  213. RenderClientPtr pRenderClient = GetRenderClient(pClient);
  214. pRenderClient->major_version = 0;
  215. pRenderClient->minor_version = 0;
  216. }
  217. void
  218. RenderExtensionInit(void)
  219. {
  220. ExtensionEntry *extEntry;
  221. if (!PictureType)
  222. return;
  223. if (!PictureFinishInit())
  224. return;
  225. RenderClientPrivateIndex = AllocateClientPrivateIndex();
  226. if (!AllocateClientPrivate(RenderClientPrivateIndex,
  227. sizeof(RenderClientRec)))
  228. return;
  229. if (!AddCallback(&ClientStateCallback, RenderClientCallback, 0))
  230. return;
  231. extEntry = AddExtension(RENDER_NAME, 0, RenderNumberErrors,
  232. ProcRenderDispatch, SProcRenderDispatch,
  233. RenderResetProc, StandardMinorOpcode);
  234. if (!extEntry)
  235. return;
  236. #if 0
  237. RenderReqCode = (CARD8) extEntry->base;
  238. #endif
  239. RenderErrBase = extEntry->errorBase;
  240. }
  241. static void
  242. RenderResetProc(ExtensionEntry * extEntry)
  243. {
  244. ResetPicturePrivateIndex();
  245. ResetGlyphSetPrivateIndex();
  246. }
  247. static int
  248. ProcRenderQueryVersion(ClientPtr client)
  249. {
  250. RenderClientPtr pRenderClient = GetRenderClient(client);
  251. xRenderQueryVersionReply rep = {0};
  252. REQUEST(xRenderQueryVersionReq);
  253. pRenderClient->major_version = stuff->majorVersion;
  254. pRenderClient->minor_version = stuff->minorVersion;
  255. REQUEST_SIZE_MATCH(xRenderQueryVersionReq);
  256. rep.type = X_Reply;
  257. rep.length = 0;
  258. rep.sequenceNumber = client->sequence;
  259. rep.majorVersion = RENDER_MAJOR;
  260. rep.minorVersion = RENDER_MINOR;
  261. if (client->swapped) {
  262. swaps(&rep.sequenceNumber);
  263. swapl(&rep.length);
  264. swapl(&rep.majorVersion);
  265. swapl(&rep.minorVersion);
  266. }
  267. WriteToClient(client, sizeof(xRenderQueryVersionReply), (char *) &rep);
  268. return (client->noClientException);
  269. }
  270. static VisualPtr
  271. findVisual(ScreenPtr pScreen, VisualID vid)
  272. {
  273. VisualPtr pVisual;
  274. int v;
  275. for (v = 0; v < pScreen->numVisuals; v++) {
  276. pVisual = pScreen->visuals + v;
  277. if (pVisual->vid == vid)
  278. return pVisual;
  279. }
  280. return 0;
  281. }
  282. extern char *ConnectionInfo;
  283. static int
  284. ProcRenderQueryPictFormats(ClientPtr client)
  285. {
  286. RenderClientPtr pRenderClient = GetRenderClient(client);
  287. xRenderQueryPictFormatsReply *reply;
  288. xPictScreen *pictScreen;
  289. xPictDepth *pictDepth;
  290. xPictVisual *pictVisual;
  291. xPictFormInfo *pictForm;
  292. CARD32 *pictSubpixel;
  293. ScreenPtr pScreen;
  294. VisualPtr pVisual;
  295. DepthPtr pDepth;
  296. int v, d;
  297. PictureScreenPtr ps;
  298. PictFormatPtr pFormat;
  299. int nformat;
  300. int ndepth;
  301. int nvisual;
  302. int rlength;
  303. int s;
  304. int numScreens;
  305. int numSubpixel;
  306. /* REQUEST(xRenderQueryPictFormatsReq); */
  307. REQUEST_SIZE_MATCH(xRenderQueryPictFormatsReq);
  308. numScreens = screenInfo.numScreens;
  309. ndepth = nformat = nvisual = 0;
  310. for (s = 0; s < numScreens; s++) {
  311. pScreen = screenInfo.screens[s];
  312. for (d = 0; d < pScreen->numDepths; d++) {
  313. pDepth = pScreen->allowedDepths + d;
  314. ++ndepth;
  315. for (v = 0; v < pDepth->numVids; v++) {
  316. pVisual = findVisual(pScreen, pDepth->vids[v]);
  317. if (pVisual &&
  318. PictureMatchVisual(pScreen, pDepth->depth, pVisual))
  319. ++nvisual;
  320. }
  321. }
  322. ps = GetPictureScreenIfSet(pScreen);
  323. if (ps)
  324. nformat += ps->nformats;
  325. }
  326. if (pRenderClient->major_version == 0 && pRenderClient->minor_version < 6)
  327. numSubpixel = 0;
  328. else
  329. numSubpixel = numScreens;
  330. rlength = (sizeof(xRenderQueryPictFormatsReply) +
  331. nformat * sizeof(xPictFormInfo) +
  332. numScreens * sizeof(xPictScreen) +
  333. ndepth * sizeof(xPictDepth) +
  334. nvisual * sizeof(xPictVisual) + numSubpixel * sizeof(CARD32));
  335. reply = malloc(rlength);
  336. if (!reply)
  337. return BadAlloc;
  338. reply->type = X_Reply;
  339. reply->sequenceNumber = client->sequence;
  340. reply->length = (rlength - sizeof(xGenericReply)) >> 2;
  341. reply->numFormats = nformat;
  342. reply->numScreens = numScreens;
  343. reply->numDepths = ndepth;
  344. reply->numVisuals = nvisual;
  345. reply->numSubpixel = numSubpixel;
  346. pictForm = (xPictFormInfo *) (reply + 1);
  347. for (s = 0; s < numScreens; s++) {
  348. pScreen = screenInfo.screens[s];
  349. ps = GetPictureScreenIfSet(pScreen);
  350. if (ps) {
  351. for (nformat = 0, pFormat = ps->formats;
  352. nformat < ps->nformats; nformat++, pFormat++) {
  353. pictForm->id = pFormat->id;
  354. pictForm->type = pFormat->type;
  355. pictForm->depth = pFormat->depth;
  356. pictForm->direct.red = pFormat->direct.red;
  357. pictForm->direct.redMask = pFormat->direct.redMask;
  358. pictForm->direct.green = pFormat->direct.green;
  359. pictForm->direct.greenMask = pFormat->direct.greenMask;
  360. pictForm->direct.blue = pFormat->direct.blue;
  361. pictForm->direct.blueMask = pFormat->direct.blueMask;
  362. pictForm->direct.alpha = pFormat->direct.alpha;
  363. pictForm->direct.alphaMask = pFormat->direct.alphaMask;
  364. if (pFormat->type == PictTypeIndexed &&
  365. pFormat->index.pColormap)
  366. pictForm->colormap = pFormat->index.pColormap->mid;
  367. else
  368. pictForm->colormap = None;
  369. if (client->swapped) {
  370. swapl(&pictForm->id);
  371. swaps(&pictForm->direct.red);
  372. swaps(&pictForm->direct.redMask);
  373. swaps(&pictForm->direct.green);
  374. swaps(&pictForm->direct.greenMask);
  375. swaps(&pictForm->direct.blue);
  376. swaps(&pictForm->direct.blueMask);
  377. swaps(&pictForm->direct.alpha);
  378. swaps(&pictForm->direct.alphaMask);
  379. swapl(&pictForm->colormap);
  380. }
  381. pictForm++;
  382. }
  383. }
  384. }
  385. pictScreen = (xPictScreen *) pictForm;
  386. for (s = 0; s < numScreens; s++) {
  387. pScreen = screenInfo.screens[s];
  388. pictDepth = (xPictDepth *) (pictScreen + 1);
  389. ndepth = 0;
  390. for (d = 0; d < pScreen->numDepths; d++) {
  391. pictVisual = (xPictVisual *) (pictDepth + 1);
  392. pDepth = pScreen->allowedDepths + d;
  393. nvisual = 0;
  394. for (v = 0; v < pDepth->numVids; v++) {
  395. pVisual = findVisual(pScreen, pDepth->vids[v]);
  396. if (pVisual && (pFormat = PictureMatchVisual(pScreen,
  397. pDepth->depth,
  398. pVisual))) {
  399. pictVisual->visual = pVisual->vid;
  400. pictVisual->format = pFormat->id;
  401. if (client->swapped) {
  402. swapl(&pictVisual->visual);
  403. swapl(&pictVisual->format);
  404. }
  405. pictVisual++;
  406. nvisual++;
  407. }
  408. }
  409. pictDepth->depth = pDepth->depth;
  410. pictDepth->nPictVisuals = nvisual;
  411. if (client->swapped) {
  412. swaps(&pictDepth->nPictVisuals);
  413. }
  414. ndepth++;
  415. pictDepth = (xPictDepth *) pictVisual;
  416. }
  417. pictScreen->nDepth = ndepth;
  418. ps = GetPictureScreenIfSet(pScreen);
  419. if (ps)
  420. pictScreen->fallback = ps->fallback->id;
  421. else
  422. pictScreen->fallback = 0;
  423. if (client->swapped) {
  424. swapl(&pictScreen->nDepth);
  425. swapl(&pictScreen->fallback);
  426. }
  427. pictScreen = (xPictScreen *) pictDepth;
  428. }
  429. pictSubpixel = (CARD32 *) pictScreen;
  430. for (s = 0; s < numSubpixel; s++) {
  431. pScreen = screenInfo.screens[s];
  432. ps = GetPictureScreenIfSet(pScreen);
  433. if (ps)
  434. *pictSubpixel = ps->subpixel;
  435. else
  436. *pictSubpixel = SubPixelUnknown;
  437. if (client->swapped) {
  438. swapl(pictSubpixel);
  439. }
  440. ++pictSubpixel;
  441. }
  442. if (client->swapped) {
  443. swaps(&reply->sequenceNumber);
  444. swapl(&reply->length);
  445. swapl(&reply->numFormats);
  446. swapl(&reply->numScreens);
  447. swapl(&reply->numDepths);
  448. swapl(&reply->numVisuals);
  449. swapl(&reply->numSubpixel);
  450. }
  451. WriteToClient(client, rlength, (char *) reply);
  452. free(reply);
  453. return client->noClientException;
  454. }
  455. static int
  456. ProcRenderQueryPictIndexValues(ClientPtr client)
  457. {
  458. PictFormatPtr pFormat;
  459. int num;
  460. int rlength;
  461. int i;
  462. REQUEST(xRenderQueryPictIndexValuesReq);
  463. xRenderQueryPictIndexValuesReply *reply;
  464. xIndexValue *values;
  465. REQUEST_AT_LEAST_SIZE(xRenderQueryPictIndexValuesReq);
  466. pFormat = (PictFormatPtr) SecurityLookupIDByType(client,
  467. stuff->format,
  468. PictFormatType,
  469. SecurityReadAccess);
  470. if (!pFormat) {
  471. client->errorValue = stuff->format;
  472. return RenderErrBase + BadPictFormat;
  473. }
  474. if (pFormat->type != PictTypeIndexed) {
  475. client->errorValue = stuff->format;
  476. return BadMatch;
  477. }
  478. num = pFormat->index.nvalues;
  479. rlength = (sizeof(xRenderQueryPictIndexValuesReply) +
  480. num * sizeof(xIndexValue));
  481. reply = calloc(1, rlength);
  482. if (!reply)
  483. return BadAlloc;
  484. reply->type = X_Reply;
  485. reply->sequenceNumber = client->sequence;
  486. reply->length = (rlength - sizeof(xGenericReply)) >> 2;
  487. reply->numIndexValues = num;
  488. values = (xIndexValue *) (reply + 1);
  489. memcpy(reply + 1, pFormat->index.pValues, num * sizeof(xIndexValue));
  490. if (client->swapped) {
  491. for (i = 0; i < num; i++) {
  492. swapl(&values[i].pixel);
  493. swaps(&values[i].red);
  494. swaps(&values[i].green);
  495. swaps(&values[i].blue);
  496. swaps(&values[i].alpha);
  497. }
  498. swaps(&reply->sequenceNumber);
  499. swapl(&reply->length);
  500. swapl(&reply->numIndexValues);
  501. }
  502. WriteToClient(client, rlength, (char *) reply);
  503. free(reply);
  504. return (client->noClientException);
  505. }
  506. static int
  507. ProcRenderQueryDithers(ClientPtr client)
  508. {
  509. return BadImplementation;
  510. }
  511. static int
  512. ProcRenderCreatePicture(ClientPtr client)
  513. {
  514. PicturePtr pPicture;
  515. DrawablePtr pDrawable;
  516. PictFormatPtr pFormat;
  517. int len;
  518. int error;
  519. REQUEST(xRenderCreatePictureReq);
  520. REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq);
  521. LEGAL_NEW_RESOURCE(stuff->pid, client);
  522. SECURITY_VERIFY_DRAWABLE(pDrawable, stuff->drawable, client,
  523. SecurityWriteAccess);
  524. pFormat = (PictFormatPtr) SecurityLookupIDByType(client,
  525. stuff->format,
  526. PictFormatType,
  527. SecurityReadAccess);
  528. if (!pFormat) {
  529. client->errorValue = stuff->format;
  530. return RenderErrBase + BadPictFormat;
  531. }
  532. if (pFormat->depth != pDrawable->depth)
  533. return BadMatch;
  534. len = client->req_len - (sizeof(xRenderCreatePictureReq) >> 2);
  535. if (Ones(stuff->mask) != len)
  536. return BadLength;
  537. pPicture = CreatePicture(stuff->pid,
  538. pDrawable,
  539. pFormat,
  540. stuff->mask, (XID *) (stuff + 1), client, &error);
  541. if (!pPicture)
  542. return error;
  543. if (!AddResource(stuff->pid, PictureType, (pointer) pPicture))
  544. return BadAlloc;
  545. return Success;
  546. }
  547. static int
  548. ProcRenderChangePicture(ClientPtr client)
  549. {
  550. PicturePtr pPicture;
  551. REQUEST(xRenderChangePictureReq);
  552. int len;
  553. REQUEST_AT_LEAST_SIZE(xRenderChangePictureReq);
  554. VERIFY_PICTURE(pPicture, stuff->picture, client, SecurityWriteAccess,
  555. RenderErrBase + BadPicture);
  556. len = client->req_len - (sizeof(xRenderChangePictureReq) >> 2);
  557. if (Ones(stuff->mask) != len)
  558. return BadLength;
  559. return ChangePicture(pPicture, stuff->mask, (XID *) (stuff + 1),
  560. (DevUnion *) 0, client);
  561. }
  562. static int
  563. ProcRenderSetPictureClipRectangles(ClientPtr client)
  564. {
  565. REQUEST(xRenderSetPictureClipRectanglesReq);
  566. PicturePtr pPicture;
  567. int nr;
  568. int result;
  569. REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq);
  570. VERIFY_PICTURE(pPicture, stuff->picture, client, SecurityWriteAccess,
  571. RenderErrBase + BadPicture);
  572. if (!pPicture->pDrawable)
  573. return BadDrawable;
  574. nr = (client->req_len << 2) - sizeof(xRenderChangePictureReq);
  575. if (nr & 4)
  576. return BadLength;
  577. nr >>= 3;
  578. result = SetPictureClipRects(pPicture,
  579. stuff->xOrigin, stuff->yOrigin,
  580. nr, (xRectangle *) &stuff[1]);
  581. if (client->noClientException != Success)
  582. return (client->noClientException);
  583. else
  584. return (result);
  585. }
  586. static int
  587. ProcRenderFreePicture(ClientPtr client)
  588. {
  589. PicturePtr pPicture;
  590. REQUEST(xRenderFreePictureReq);
  591. REQUEST_SIZE_MATCH(xRenderFreePictureReq);
  592. VERIFY_PICTURE(pPicture, stuff->picture, client, SecurityDestroyAccess,
  593. RenderErrBase + BadPicture);
  594. FreeResource(stuff->picture, RT_NONE);
  595. return (client->noClientException);
  596. }
  597. static Bool
  598. PictOpValid(CARD8 op)
  599. {
  600. if ( /*PictOpMinimum <= op && */ op <= PictOpMaximum)
  601. return TRUE;
  602. if (PictOpDisjointMinimum <= op && op <= PictOpDisjointMaximum)
  603. return TRUE;
  604. if (PictOpConjointMinimum <= op && op <= PictOpConjointMaximum)
  605. return TRUE;
  606. return FALSE;
  607. }
  608. static int
  609. ProcRenderComposite(ClientPtr client)
  610. {
  611. PicturePtr pSrc, pMask, pDst;
  612. REQUEST(xRenderCompositeReq);
  613. REQUEST_SIZE_MATCH(xRenderCompositeReq);
  614. if (!PictOpValid(stuff->op)) {
  615. client->errorValue = stuff->op;
  616. return BadValue;
  617. }
  618. VERIFY_PICTURE(pDst, stuff->dst, client, SecurityWriteAccess,
  619. RenderErrBase + BadPicture);
  620. if (!pDst->pDrawable)
  621. return BadDrawable;
  622. VERIFY_PICTURE(pSrc, stuff->src, client, SecurityReadAccess,
  623. RenderErrBase + BadPicture);
  624. VERIFY_ALPHA(pMask, stuff->mask, client, SecurityReadAccess,
  625. RenderErrBase + BadPicture);
  626. if ((pSrc->pDrawable &&
  627. pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) || (pMask &&
  628. pMask->
  629. pDrawable &&
  630. pDst->
  631. pDrawable->
  632. pScreen !=
  633. pMask->
  634. pDrawable->
  635. pScreen))
  636. return BadMatch;
  637. CompositePicture(stuff->op,
  638. pSrc,
  639. pMask,
  640. pDst,
  641. stuff->xSrc,
  642. stuff->ySrc,
  643. stuff->xMask,
  644. stuff->yMask,
  645. stuff->xDst, stuff->yDst, stuff->width, stuff->height);
  646. return Success;
  647. }
  648. static int
  649. ProcRenderScale(ClientPtr client)
  650. {
  651. return BadImplementation;
  652. }
  653. static int
  654. ProcRenderTrapezoids(ClientPtr client)
  655. {
  656. int ntraps;
  657. PicturePtr pSrc, pDst;
  658. PictFormatPtr pFormat;
  659. REQUEST(xRenderTrapezoidsReq);
  660. REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq);
  661. if (!PictOpValid(stuff->op)) {
  662. client->errorValue = stuff->op;
  663. return BadValue;
  664. }
  665. VERIFY_PICTURE(pSrc, stuff->src, client, SecurityReadAccess,
  666. RenderErrBase + BadPicture);
  667. VERIFY_PICTURE(pDst, stuff->dst, client, SecurityWriteAccess,
  668. RenderErrBase + BadPicture);
  669. if (!pDst->pDrawable)
  670. return BadDrawable;
  671. if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
  672. return BadMatch;
  673. if (stuff->maskFormat) {
  674. pFormat = (PictFormatPtr) SecurityLookupIDByType(client,
  675. stuff->maskFormat,
  676. PictFormatType,
  677. SecurityReadAccess);
  678. if (!pFormat) {
  679. client->errorValue = stuff->maskFormat;
  680. return RenderErrBase + BadPictFormat;
  681. }
  682. }
  683. else
  684. pFormat = 0;
  685. ntraps = (client->req_len << 2) - sizeof(xRenderTrapezoidsReq);
  686. if (ntraps % sizeof(xTrapezoid))
  687. return BadLength;
  688. ntraps /= sizeof(xTrapezoid);
  689. if (ntraps)
  690. CompositeTrapezoids(stuff->op, pSrc, pDst, pFormat,
  691. stuff->xSrc, stuff->ySrc,
  692. ntraps, (xTrapezoid *) & stuff[1]);
  693. return client->noClientException;
  694. }
  695. static int
  696. ProcRenderTriangles(ClientPtr client)
  697. {
  698. int ntris;
  699. PicturePtr pSrc, pDst;
  700. PictFormatPtr pFormat;
  701. REQUEST(xRenderTrianglesReq);
  702. REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq);
  703. if (!PictOpValid(stuff->op)) {
  704. client->errorValue = stuff->op;
  705. return BadValue;
  706. }
  707. VERIFY_PICTURE(pSrc, stuff->src, client, SecurityReadAccess,
  708. RenderErrBase + BadPicture);
  709. VERIFY_PICTURE(pDst, stuff->dst, client, SecurityWriteAccess,
  710. RenderErrBase + BadPicture);
  711. if (!pDst->pDrawable)
  712. return BadDrawable;
  713. if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
  714. return BadMatch;
  715. if (stuff->maskFormat) {
  716. pFormat = (PictFormatPtr) SecurityLookupIDByType(client,
  717. stuff->maskFormat,
  718. PictFormatType,
  719. SecurityReadAccess);
  720. if (!pFormat) {
  721. client->errorValue = stuff->maskFormat;
  722. return RenderErrBase + BadPictFormat;
  723. }
  724. }
  725. else
  726. pFormat = 0;
  727. ntris = (client->req_len << 2) - sizeof(xRenderTrianglesReq);
  728. if (ntris % sizeof(xTriangle))
  729. return BadLength;
  730. ntris /= sizeof(xTriangle);
  731. if (ntris)
  732. CompositeTriangles(stuff->op, pSrc, pDst, pFormat,
  733. stuff->xSrc, stuff->ySrc,
  734. ntris, (xTriangle *) & stuff[1]);
  735. return client->noClientException;
  736. }
  737. static int
  738. ProcRenderTriStrip(ClientPtr client)
  739. {
  740. int npoints;
  741. PicturePtr pSrc, pDst;
  742. PictFormatPtr pFormat;
  743. REQUEST(xRenderTrianglesReq);
  744. REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq);
  745. if (!PictOpValid(stuff->op)) {
  746. client->errorValue = stuff->op;
  747. return BadValue;
  748. }
  749. VERIFY_PICTURE(pSrc, stuff->src, client, SecurityReadAccess,
  750. RenderErrBase + BadPicture);
  751. VERIFY_PICTURE(pDst, stuff->dst, client, SecurityWriteAccess,
  752. RenderErrBase + BadPicture);
  753. if (!pDst->pDrawable)
  754. return BadDrawable;
  755. if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
  756. return BadMatch;
  757. if (stuff->maskFormat) {
  758. pFormat = (PictFormatPtr) SecurityLookupIDByType(client,
  759. stuff->maskFormat,
  760. PictFormatType,
  761. SecurityReadAccess);
  762. if (!pFormat) {
  763. client->errorValue = stuff->maskFormat;
  764. return RenderErrBase + BadPictFormat;
  765. }
  766. }
  767. else
  768. pFormat = 0;
  769. npoints = ((client->req_len << 2) - sizeof(xRenderTriStripReq));
  770. if (npoints & 4)
  771. return (BadLength);
  772. npoints >>= 3;
  773. if (npoints >= 3)
  774. CompositeTriStrip(stuff->op, pSrc, pDst, pFormat,
  775. stuff->xSrc, stuff->ySrc,
  776. npoints, (xPointFixed *) & stuff[1]);
  777. return client->noClientException;
  778. }
  779. static int
  780. ProcRenderTriFan(ClientPtr client)
  781. {
  782. int npoints;
  783. PicturePtr pSrc, pDst;
  784. PictFormatPtr pFormat;
  785. REQUEST(xRenderTrianglesReq);
  786. REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq);
  787. if (!PictOpValid(stuff->op)) {
  788. client->errorValue = stuff->op;
  789. return BadValue;
  790. }
  791. VERIFY_PICTURE(pSrc, stuff->src, client, SecurityReadAccess,
  792. RenderErrBase + BadPicture);
  793. VERIFY_PICTURE(pDst, stuff->dst, client, SecurityWriteAccess,
  794. RenderErrBase + BadPicture);
  795. if (!pDst->pDrawable)
  796. return BadDrawable;
  797. if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
  798. return BadMatch;
  799. if (stuff->maskFormat) {
  800. pFormat = (PictFormatPtr) SecurityLookupIDByType(client,
  801. stuff->maskFormat,
  802. PictFormatType,
  803. SecurityReadAccess);
  804. if (!pFormat) {
  805. client->errorValue = stuff->maskFormat;
  806. return RenderErrBase + BadPictFormat;
  807. }
  808. }
  809. else
  810. pFormat = 0;
  811. npoints = ((client->req_len << 2) - sizeof(xRenderTriStripReq));
  812. if (npoints & 4)
  813. return (BadLength);
  814. npoints >>= 3;
  815. if (npoints >= 3)
  816. CompositeTriFan(stuff->op, pSrc, pDst, pFormat,
  817. stuff->xSrc, stuff->ySrc,
  818. npoints, (xPointFixed *) & stuff[1]);
  819. return client->noClientException;
  820. }
  821. static int
  822. ProcRenderColorTrapezoids(ClientPtr client)
  823. {
  824. return BadImplementation;
  825. }
  826. static int
  827. ProcRenderColorTriangles(ClientPtr client)
  828. {
  829. return BadImplementation;
  830. }
  831. static int
  832. ProcRenderTransform(ClientPtr client)
  833. {
  834. return BadImplementation;
  835. }
  836. static int
  837. ProcRenderCreateGlyphSet(ClientPtr client)
  838. {
  839. GlyphSetPtr glyphSet;
  840. PictFormatPtr format;
  841. int f;
  842. REQUEST(xRenderCreateGlyphSetReq);
  843. REQUEST_SIZE_MATCH(xRenderCreateGlyphSetReq);
  844. LEGAL_NEW_RESOURCE(stuff->gsid, client);
  845. format = (PictFormatPtr) SecurityLookupIDByType(client,
  846. stuff->format,
  847. PictFormatType,
  848. SecurityReadAccess);
  849. if (!format) {
  850. client->errorValue = stuff->format;
  851. return RenderErrBase + BadPictFormat;
  852. }
  853. switch (format->depth) {
  854. case 1:
  855. f = GlyphFormat1;
  856. break;
  857. case 4:
  858. f = GlyphFormat4;
  859. break;
  860. case 8:
  861. f = GlyphFormat8;
  862. break;
  863. case 16:
  864. f = GlyphFormat16;
  865. break;
  866. case 32:
  867. f = GlyphFormat32;
  868. break;
  869. default:
  870. return BadMatch;
  871. }
  872. if (format->type != PictTypeDirect)
  873. return BadMatch;
  874. glyphSet = AllocateGlyphSet(f, format);
  875. if (!glyphSet)
  876. return BadAlloc;
  877. if (!AddResource(stuff->gsid, GlyphSetType, (pointer) glyphSet))
  878. return BadAlloc;
  879. return Success;
  880. }
  881. static int
  882. ProcRenderReferenceGlyphSet(ClientPtr client)
  883. {
  884. GlyphSetPtr glyphSet;
  885. REQUEST(xRenderReferenceGlyphSetReq);
  886. REQUEST_SIZE_MATCH(xRenderReferenceGlyphSetReq);
  887. LEGAL_NEW_RESOURCE(stuff->gsid, client);
  888. glyphSet = (GlyphSetPtr) SecurityLookupIDByType(client,
  889. stuff->existing,
  890. GlyphSetType,
  891. SecurityWriteAccess);
  892. if (!glyphSet) {
  893. client->errorValue = stuff->existing;
  894. return RenderErrBase + BadGlyphSet;
  895. }
  896. glyphSet->refcnt++;
  897. if (!AddResource(stuff->gsid, GlyphSetType, (pointer) glyphSet))
  898. return BadAlloc;
  899. return client->noClientException;
  900. }
  901. #define NLOCALDELTA 64
  902. #define NLOCALGLYPH 256
  903. static int
  904. ProcRenderFreeGlyphSet(ClientPtr client)
  905. {
  906. GlyphSetPtr glyphSet;
  907. REQUEST(xRenderFreeGlyphSetReq);
  908. REQUEST_SIZE_MATCH(xRenderFreeGlyphSetReq);
  909. glyphSet = (GlyphSetPtr) SecurityLookupIDByType(client,
  910. stuff->glyphset,
  911. GlyphSetType,
  912. SecurityDestroyAccess);
  913. if (!glyphSet) {
  914. client->errorValue = stuff->glyphset;
  915. return RenderErrBase + BadGlyphSet;
  916. }
  917. FreeResource(stuff->glyphset, RT_NONE);
  918. return client->noClientException;
  919. }
  920. typedef struct _GlyphNew {
  921. Glyph id;
  922. GlyphPtr glyph;
  923. } GlyphNewRec, *GlyphNewPtr;
  924. static int
  925. ProcRenderAddGlyphs(ClientPtr client)
  926. {
  927. GlyphSetPtr glyphSet;
  928. REQUEST(xRenderAddGlyphsReq);
  929. GlyphNewRec glyphsLocal[NLOCALGLYPH];
  930. GlyphNewPtr glyphsBase, glyphs;
  931. GlyphPtr glyph;
  932. int remain, nglyphs;
  933. CARD32 *gids;
  934. xGlyphInfo *gi;
  935. CARD8 *bits;
  936. int size;
  937. int err = BadAlloc;
  938. REQUEST_AT_LEAST_SIZE(xRenderAddGlyphsReq);
  939. glyphSet = (GlyphSetPtr) SecurityLookupIDByType(client,
  940. stuff->glyphset,
  941. GlyphSetType,
  942. SecurityWriteAccess);
  943. if (!glyphSet) {
  944. client->errorValue = stuff->glyphset;
  945. return RenderErrBase + BadGlyphSet;
  946. }
  947. nglyphs = stuff->nglyphs;
  948. if (nglyphs > UINT32_MAX / sizeof(GlyphNewRec))
  949. return BadAlloc;
  950. if (nglyphs <= NLOCALGLYPH)
  951. glyphsBase = glyphsLocal;
  952. else {
  953. glyphsBase = malloc(nglyphs * sizeof(GlyphNewRec));
  954. if (!glyphsBase)
  955. return BadAlloc;
  956. }
  957. remain = (client->req_len << 2) - sizeof(xRenderAddGlyphsReq);
  958. glyphs = glyphsBase;
  959. gids = (CARD32 *) (stuff + 1);
  960. gi = (xGlyphInfo *) (gids + nglyphs);
  961. bits = (CARD8 *) (gi + nglyphs);
  962. remain -= (sizeof(CARD32) + sizeof(xGlyphInfo)) * nglyphs;
  963. while (remain >= 0 && nglyphs) {
  964. glyph = AllocateGlyph(gi, glyphSet->fdepth);
  965. if (!glyph) {
  966. err = BadAlloc;
  967. goto bail;
  968. }
  969. glyphs->glyph = glyph;
  970. glyphs->id = *gids;
  971. size = glyph->size - sizeof(xGlyphInfo);
  972. if (remain < size)
  973. break;
  974. memcpy((CARD8 *) (glyph + 1), bits, size);
  975. if (size & 3)
  976. size += 4 - (size & 3);
  977. bits += size;
  978. remain -= size;
  979. gi++;
  980. gids++;
  981. glyphs++;
  982. nglyphs--;
  983. }
  984. if (nglyphs || remain) {
  985. err = BadLength;
  986. goto bail;
  987. }
  988. nglyphs = stuff->nglyphs;
  989. if (!ResizeGlyphSet(glyphSet, nglyphs)) {
  990. err = BadAlloc;
  991. goto bail;
  992. }
  993. glyphs = glyphsBase;
  994. while (nglyphs--) {
  995. AddGlyph(glyphSet, glyphs->glyph, glyphs->id);
  996. glyphs++;
  997. }
  998. if (glyphsBase != glyphsLocal)
  999. free(glyphsBase);
  1000. return client->noClientException;
  1001. bail:
  1002. while (glyphs != glyphsBase) {
  1003. --glyphs;
  1004. free(glyphs->glyph);
  1005. }
  1006. if (glyphsBase != glyphsLocal)
  1007. free(glyphsBase);
  1008. return err;
  1009. }
  1010. static int
  1011. ProcRenderAddGlyphsFromPicture(ClientPtr client)
  1012. {
  1013. return BadImplementation;
  1014. }
  1015. static int
  1016. ProcRenderFreeGlyphs(ClientPtr client)
  1017. {
  1018. REQUEST(xRenderFreeGlyphsReq);
  1019. GlyphSetPtr glyphSet;
  1020. int nglyph;
  1021. CARD32 *gids;
  1022. CARD32 glyph;
  1023. REQUEST_AT_LEAST_SIZE(xRenderFreeGlyphsReq);
  1024. glyphSet = (GlyphSetPtr) SecurityLookupIDByType(client,
  1025. stuff->glyphset,
  1026. GlyphSetType,
  1027. SecurityWriteAccess);
  1028. if (!glyphSet) {
  1029. client->errorValue = stuff->glyphset;
  1030. return RenderErrBase + BadGlyphSet;
  1031. }
  1032. nglyph = ((client->req_len << 2) - sizeof(xRenderFreeGlyphsReq)) >> 2;
  1033. gids = (CARD32 *) (stuff + 1);
  1034. while (nglyph-- > 0) {
  1035. glyph = *gids++;
  1036. if (!DeleteGlyph(glyphSet, glyph)) {
  1037. client->errorValue = glyph;
  1038. return RenderErrBase + BadGlyph;
  1039. }
  1040. }
  1041. return client->noClientException;
  1042. }
  1043. static int
  1044. ProcRenderCompositeGlyphs(ClientPtr client)
  1045. {
  1046. GlyphSetPtr glyphSet;
  1047. GlyphSet gs;
  1048. PicturePtr pSrc, pDst;
  1049. PictFormatPtr pFormat;
  1050. GlyphListRec listsLocal[NLOCALDELTA];
  1051. GlyphListPtr lists, listsBase;
  1052. GlyphPtr glyphsLocal[NLOCALGLYPH];
  1053. Glyph glyph;
  1054. GlyphPtr *glyphs, *glyphsBase;
  1055. xGlyphElt *elt;
  1056. CARD8 *buffer, *end;
  1057. int nglyph;
  1058. int nlist;
  1059. int space;
  1060. int size;
  1061. int n;
  1062. REQUEST(xRenderCompositeGlyphsReq);
  1063. REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq);
  1064. switch (stuff->renderReqType) {
  1065. default:
  1066. size = 1;
  1067. break;
  1068. case X_RenderCompositeGlyphs16:
  1069. size = 2;
  1070. break;
  1071. case X_RenderCompositeGlyphs32:
  1072. size = 4;
  1073. break;
  1074. }
  1075. if (!PictOpValid(stuff->op)) {
  1076. client->errorValue = stuff->op;
  1077. return BadValue;
  1078. }
  1079. VERIFY_PICTURE(pSrc, stuff->src, client, SecurityReadAccess,
  1080. RenderErrBase + BadPicture);
  1081. VERIFY_PICTURE(pDst, stuff->dst, client, SecurityWriteAccess,
  1082. RenderErrBase + BadPicture);
  1083. if (!pDst->pDrawable)
  1084. return BadDrawable;
  1085. if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
  1086. return BadMatch;
  1087. if (stuff->maskFormat) {
  1088. pFormat = (PictFormatPtr) SecurityLookupIDByType(client,
  1089. stuff->maskFormat,
  1090. PictFormatType,
  1091. SecurityReadAccess);
  1092. if (!pFormat) {
  1093. client->errorValue = stuff->maskFormat;
  1094. return RenderErrBase + BadPictFormat;
  1095. }
  1096. }
  1097. else
  1098. pFormat = 0;
  1099. glyphSet = (GlyphSetPtr) SecurityLookupIDByType(client,
  1100. stuff->glyphset,
  1101. GlyphSetType,
  1102. SecurityReadAccess);
  1103. if (!glyphSet) {
  1104. client->errorValue = stuff->glyphset;
  1105. return RenderErrBase + BadGlyphSet;
  1106. }
  1107. buffer = (CARD8 *) (stuff + 1);
  1108. end = (CARD8 *) stuff + (client->req_len << 2);
  1109. nglyph = 0;
  1110. nlist = 0;
  1111. while (buffer + sizeof(xGlyphElt) < end) {
  1112. elt = (xGlyphElt *) buffer;
  1113. buffer += sizeof(xGlyphElt);
  1114. if (elt->len == 0xff) {
  1115. buffer += 4;
  1116. }
  1117. else {
  1118. nlist++;
  1119. nglyph += elt->len;
  1120. space = size * elt->len;
  1121. if (space & 3)
  1122. space += 4 - (space & 3);
  1123. buffer += space;
  1124. }
  1125. }
  1126. if (nglyph <= NLOCALGLYPH)
  1127. glyphsBase = glyphsLocal;
  1128. else {
  1129. glyphsBase = (GlyphPtr *) ALLOCATE_LOCAL(nglyph * sizeof(GlyphPtr));
  1130. if (!glyphsBase)
  1131. return BadAlloc;
  1132. }
  1133. if (nlist <= NLOCALDELTA)
  1134. listsBase = listsLocal;
  1135. else {
  1136. listsBase = (GlyphListPtr) ALLOCATE_LOCAL(nlist * sizeof(GlyphListRec));
  1137. if (!listsBase)
  1138. return BadAlloc;
  1139. }
  1140. buffer = (CARD8 *) (stuff + 1);
  1141. glyphs = glyphsBase;
  1142. lists = listsBase;
  1143. while (buffer + sizeof(xGlyphElt) < end) {
  1144. elt = (xGlyphElt *) buffer;
  1145. buffer += sizeof(xGlyphElt);
  1146. if (elt->len == 0xff) {
  1147. if (buffer + sizeof(GlyphSet) < end) {
  1148. memcpy(&gs, buffer, sizeof(GlyphSet));
  1149. glyphSet = (GlyphSetPtr) SecurityLookupIDByType(client,
  1150. gs,
  1151. GlyphSetType,
  1152. SecurityReadAccess);
  1153. if (!glyphSet) {
  1154. client->errorValue = gs;
  1155. if (glyphsBase != glyphsLocal)
  1156. DEALLOCATE_LOCAL(glyphsBase);
  1157. if (listsBase != listsLocal)
  1158. DEALLOCATE_LOCAL(listsBase);
  1159. return RenderErrBase + BadGlyphSet;
  1160. }
  1161. }
  1162. buffer += 4;
  1163. }
  1164. else {
  1165. lists->xOff = elt->deltax;
  1166. lists->yOff = elt->deltay;
  1167. lists->format = glyphSet->format;
  1168. lists->len = 0;
  1169. n = elt->len;
  1170. while (n--) {
  1171. if (buffer + size <= end) {
  1172. switch (size) {
  1173. case 1:
  1174. glyph = *((CARD8 *) buffer);
  1175. break;
  1176. case 2:
  1177. glyph = *((CARD16 *) buffer);
  1178. break;
  1179. case 4:
  1180. default:
  1181. glyph = *((CARD32 *) buffer);
  1182. break;
  1183. }
  1184. if ((*glyphs = FindGlyph(glyphSet, glyph))) {
  1185. lists->len++;
  1186. glyphs++;
  1187. }
  1188. }
  1189. buffer += size;
  1190. }
  1191. space = size * elt->len;
  1192. if (space & 3)
  1193. buffer += 4 - (space & 3);
  1194. lists++;
  1195. }
  1196. }
  1197. if (buffer > end)
  1198. return BadLength;
  1199. CompositeGlyphs(stuff->op,
  1200. pSrc,
  1201. pDst,
  1202. pFormat,
  1203. stuff->xSrc, stuff->ySrc, nlist, listsBase, glyphsBase);
  1204. if (glyphsBase != glyphsLocal)
  1205. DEALLOCATE_LOCAL(glyphsBase);
  1206. if (listsBase != listsLocal)
  1207. DEALLOCATE_LOCAL(listsBase);
  1208. return client->noClientException;
  1209. }
  1210. static int
  1211. ProcRenderFillRectangles(ClientPtr client)
  1212. {
  1213. PicturePtr pDst;
  1214. int things;
  1215. REQUEST(xRenderFillRectanglesReq);
  1216. REQUEST_AT_LEAST_SIZE(xRenderFillRectanglesReq);
  1217. if (!PictOpValid(stuff->op)) {
  1218. client->errorValue = stuff->op;
  1219. return BadValue;
  1220. }
  1221. VERIFY_PICTURE(pDst, stuff->dst, client, SecurityWriteAccess,
  1222. RenderErrBase + BadPicture);
  1223. if (!pDst->pDrawable)
  1224. return BadDrawable;
  1225. things = (client->req_len << 2) - sizeof(xRenderFillRectanglesReq);
  1226. if (things & 4)
  1227. return (BadLength);
  1228. things >>= 3;
  1229. CompositeRects(stuff->op,
  1230. pDst, &stuff->color, things, (xRectangle *) &stuff[1]);
  1231. return client->noClientException;
  1232. }
  1233. static void
  1234. SetBit(unsigned char *line, int x, int bit)
  1235. {
  1236. unsigned char mask;
  1237. if (screenInfo.bitmapBitOrder == LSBFirst)
  1238. mask = (1 << (x & 7));
  1239. else
  1240. mask = (0x80 >> (x & 7));
  1241. /* XXX assumes byte order is host byte order */
  1242. line += (x >> 3);
  1243. if (bit)
  1244. *line |= mask;
  1245. else
  1246. *line &= ~mask;
  1247. }
  1248. #define DITHER_DIM 2
  1249. static CARD32 orderedDither[DITHER_DIM][DITHER_DIM] = {
  1250. {1, 3,},
  1251. {4, 2,},
  1252. };
  1253. #define DITHER_SIZE ((sizeof orderedDither / sizeof orderedDither[0][0]) + 1)
  1254. static int
  1255. ProcRenderCreateCursor(ClientPtr client)
  1256. {
  1257. REQUEST(xRenderCreateCursorReq);
  1258. PicturePtr pSrc;
  1259. ScreenPtr pScreen;
  1260. unsigned short width, height;
  1261. CARD32 *argbbits, *argb;
  1262. unsigned char *srcbits, *srcline;
  1263. unsigned char *mskbits, *mskline;
  1264. int stride;
  1265. int x, y;
  1266. int nbytes_mono;
  1267. CursorMetricRec cm;
  1268. CursorPtr pCursor;
  1269. CARD32 twocolor[3];
  1270. int ncolor;
  1271. REQUEST_SIZE_MATCH(xRenderCreateCursorReq);
  1272. LEGAL_NEW_RESOURCE(stuff->cid, client);
  1273. VERIFY_PICTURE(pSrc, stuff->src, client, SecurityReadAccess,
  1274. RenderErrBase + BadPicture);
  1275. if (!pSrc->pDrawable)
  1276. return BadDrawable;
  1277. pScreen = pSrc->pDrawable->pScreen;
  1278. width = pSrc->pDrawable->width;
  1279. height = pSrc->pDrawable->height;
  1280. if (stuff->x > width || stuff->y > height)
  1281. return (BadMatch);
  1282. argbbits = malloc(width * height * sizeof(CARD32));
  1283. if (!argbbits)
  1284. return (BadAlloc);
  1285. stride = BitmapBytePad(width);
  1286. nbytes_mono = stride * height;
  1287. srcbits = malloc(nbytes_mono);
  1288. if (!srcbits) {
  1289. free(argbbits);
  1290. return (BadAlloc);
  1291. }
  1292. mskbits = malloc(nbytes_mono);
  1293. if (!mskbits) {
  1294. free(argbbits);
  1295. free(srcbits);
  1296. return (BadAlloc);
  1297. }
  1298. bzero((char *) mskbits, nbytes_mono);
  1299. bzero((char *) srcbits, nbytes_mono);
  1300. if (pSrc->format == PICT_a8r8g8b8) {
  1301. (*pScreen->GetImage) (pSrc->pDrawable,
  1302. 0, 0, width, height, ZPixmap,
  1303. 0xffffffff, (pointer) argbbits);
  1304. }
  1305. else {
  1306. PixmapPtr pPixmap;
  1307. PicturePtr pPicture;
  1308. PictFormatPtr pFormat;
  1309. int error;
  1310. pFormat = PictureMatchFormat(pScreen, 32, PICT_a8r8g8b8);
  1311. if (!pFormat) {
  1312. free(argbbits);
  1313. free(srcbits);
  1314. free(mskbits);
  1315. return (BadImplementation);
  1316. }
  1317. pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, 32);
  1318. if (!pPixmap) {
  1319. free(argbbits);
  1320. free(srcbits);
  1321. free(mskbits);
  1322. return (BadAlloc);
  1323. }
  1324. pPicture = CreatePicture(0, &pPixmap->drawable, pFormat, 0, 0,
  1325. client, &error);
  1326. if (!pPicture) {
  1327. free(argbbits);
  1328. free(srcbits);
  1329. free(mskbits);
  1330. return error;
  1331. }
  1332. (*pScreen->DestroyPixmap) (pPixmap);
  1333. CompositePicture(PictOpSrc,
  1334. pSrc, 0, pPicture, 0, 0, 0, 0, 0, 0, width, height);
  1335. (*pScreen->GetImage) (pPicture->pDrawable,
  1336. 0, 0, width, height, ZPixmap,
  1337. 0xffffffff, (pointer) argbbits);
  1338. FreePicture(pPicture, 0);
  1339. }
  1340. /*
  1341. * Check whether the cursor can be directly supported by
  1342. * the core cursor code
  1343. */
  1344. ncolor = 0;
  1345. argb = argbbits;
  1346. for (y = 0; ncolor <= 2 && y < height; y++) {
  1347. for (x = 0; ncolor <= 2 && x < width; x++) {
  1348. CARD32 p = *argb++;
  1349. CARD32 a = (p >> 24);
  1350. if (a == 0) /* transparent */
  1351. continue;
  1352. if (a == 0xff) { /* opaque */
  1353. int n;
  1354. for (n = 0; n < ncolor; n++)
  1355. if (p == twocolor[n])
  1356. break;
  1357. if (n == ncolor)
  1358. twocolor[ncolor++] = p;
  1359. }
  1360. else
  1361. ncolor = 3;
  1362. }
  1363. }
  1364. /*
  1365. * Convert argb image to two plane cursor
  1366. */
  1367. srcline = srcbits;
  1368. mskline = mskbits;
  1369. argb = argbbits;
  1370. for (y = 0; y < height; y++) {
  1371. for (x = 0; x < width; x++) {
  1372. CARD32 p = *argb++;
  1373. if (ncolor <= 2) {
  1374. CARD32 a = ((p >> 24));
  1375. SetBit(mskline, x, a != 0);
  1376. SetBit(srcline, x, a != 0 && p == twocolor[0]);
  1377. }
  1378. else {
  1379. CARD32 a = ((p >> 24) * DITHER_SIZE + 127) / 255;
  1380. CARD32 i = ((CvtR8G8B8toY15(p) >> 7) * DITHER_SIZE + 127) / 255;
  1381. CARD32 d =
  1382. orderedDither[y & (DITHER_DIM - 1)][x & (DITHER_DIM - 1)];
  1383. /* Set mask from dithered alpha value */
  1384. SetBit(mskline, x, a > d);
  1385. /* Set src from dithered intensity value */
  1386. SetBit(srcline, x, a > d && i <= d);
  1387. }
  1388. }
  1389. srcline += stride;
  1390. mskline += stride;
  1391. }
  1392. /*
  1393. * Dither to white and black if the cursor has more than two colors
  1394. */
  1395. if (ncolor > 2) {
  1396. twocolor[0] = 0xff000000;
  1397. twocolor[1] = 0xffffffff;
  1398. }
  1399. else {
  1400. free(argbbits);
  1401. argbbits = 0;
  1402. }
  1403. #define GetByte(p,s) (((p) >> (s)) & 0xff)
  1404. #define GetColor(p,s) (GetByte(p,s) | (GetByte(p,s) << 8))
  1405. cm.width = width;
  1406. cm.height = height;
  1407. cm.xhot = stuff->x;
  1408. cm.yhot = stuff->y;
  1409. pCursor = AllocCursorARGB(srcbits, mskbits, argbbits, &cm,
  1410. GetColor(twocolor[0], 16),
  1411. GetColor(twocolor[0], 8),
  1412. GetColor(twocolor[0], 0),
  1413. GetColor(twocolor[1], 16),
  1414. GetColor(twocolor[1], 8),
  1415. GetColor(twocolor[1], 0));
  1416. if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer) pCursor))
  1417. return (client->noClientException);
  1418. return BadAlloc;
  1419. }
  1420. static int
  1421. ProcRenderSetPictureTransform(ClientPtr client)
  1422. {
  1423. REQUEST(xRenderSetPictureTransformReq);
  1424. PicturePtr pPicture;
  1425. int result;
  1426. REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq);
  1427. VERIFY_PICTURE(pPicture, stuff->picture, client, SecurityWriteAccess,
  1428. RenderErrBase + BadPicture);
  1429. result =
  1430. SetPictureTransform(pPicture, (PictTransform *) & stuff->transform);
  1431. if (client->noClientException != Success)
  1432. return (client->noClientException);
  1433. else
  1434. return (result);
  1435. }
  1436. static int
  1437. ProcRenderQueryFilters(ClientPtr client)
  1438. {
  1439. REQUEST(xRenderQueryFiltersReq);
  1440. DrawablePtr pDrawable;
  1441. xRenderQueryFiltersReply *reply;
  1442. int nbytesName;
  1443. int nnames;
  1444. ScreenPtr pScreen;
  1445. PictureScreenPtr ps;
  1446. int i, j;
  1447. int len;
  1448. int total_bytes;
  1449. INT16 *aliases;
  1450. char *names;
  1451. REQUEST_SIZE_MATCH(xRenderQueryFiltersReq);
  1452. SECURITY_VERIFY_DRAWABLE(pDrawable, stuff->drawable, client,
  1453. SecurityReadAccess);
  1454. pScreen = pDrawable->pScreen;
  1455. nbytesName = 0;
  1456. nnames = 0;
  1457. ps = GetPictureScreenIfSet(pScreen);
  1458. if (ps) {
  1459. for (i = 0; i < ps->nfilters; i++)
  1460. nbytesName += 1 + strlen(ps->filters[i].name);
  1461. for (i = 0; i < ps->nfilterAliases; i++)
  1462. nbytesName += 1 + strlen(ps->filterAliases[i].alias);
  1463. nnames = ps->nfilters + ps->nfilterAliases;
  1464. }
  1465. len = ((nnames + 1) >> 1) + ((nbytesName + 3) >> 2);
  1466. total_bytes = sizeof(xRenderQueryFiltersReply) + (len << 2);
  1467. reply = malloc(total_bytes);
  1468. if (!reply)
  1469. return BadAlloc;
  1470. aliases = (INT16 *) (reply + 1);
  1471. names = (char *) (aliases + ((nnames + 1) & ~1));
  1472. reply->type = X_Reply;
  1473. reply->sequenceNumber = client->sequence;
  1474. reply->length = len;
  1475. reply->numAliases = nnames;
  1476. reply->numFilters = nnames;
  1477. if (ps) {
  1478. /* fill in alias values */
  1479. for (i = 0; i < ps->nfilters; i++)
  1480. aliases[i] = FilterAliasNone;
  1481. for (i = 0; i < ps->nfilterAliases; i++) {
  1482. for (j = 0; j < ps->nfilters; j++)
  1483. if (ps->filterAliases[i].filter_id == ps->filters[j].id)
  1484. break;
  1485. if (j == ps->nfilters) {
  1486. for (j = 0; j < ps->nfilterAliases; j++)
  1487. if (ps->filterAliases[i].filter_id ==
  1488. ps->filterAliases[j].alias_id) {
  1489. break;
  1490. }
  1491. if (j == ps->nfilterAliases)
  1492. j = FilterAliasNone;
  1493. else
  1494. j = j + ps->nfilters;
  1495. }
  1496. aliases[i + ps->nfilters] = j;
  1497. }
  1498. /* fill in filter names */
  1499. for (i = 0; i < ps->nfilters; i++) {
  1500. j = strlen(ps->filters[i].name);
  1501. *names++ = j;
  1502. strncpy(names, ps->filters[i].name, j);
  1503. names += j;
  1504. }
  1505. /* fill in filter alias names */
  1506. for (i = 0; i < ps->nfilterAliases; i++) {
  1507. j = strlen(ps->filterAliases[i].alias);
  1508. *names++ = j;
  1509. strncpy(names, ps->filterAliases[i].alias, j);
  1510. names += j;
  1511. }
  1512. }
  1513. if (client->swapped) {
  1514. for (i = 0; i < reply->numAliases; i++) {
  1515. swaps(&aliases[i]);
  1516. }
  1517. swaps(&reply->sequenceNumber);
  1518. swapl(&reply->length);
  1519. swapl(&reply->numAliases);
  1520. swapl(&reply->numFilters);
  1521. }
  1522. WriteToClient(client, total_bytes, (char *) reply);
  1523. free(reply);
  1524. return (client->noClientException);
  1525. }
  1526. static int
  1527. ProcRenderSetPictureFilter(ClientPtr client)
  1528. {
  1529. REQUEST(xRenderSetPictureFilterReq);
  1530. PicturePtr pPicture;
  1531. int result;
  1532. xFixed *params;
  1533. int nparams;
  1534. char *name;
  1535. REQUEST_AT_LEAST_SIZE(xRenderSetPictureFilterReq);
  1536. VERIFY_PICTURE(pPicture, stuff->picture, client, SecurityWriteAccess,
  1537. RenderErrBase + BadPicture);
  1538. name = (char *) (stuff + 1);
  1539. params = (xFixed *) (name + ((stuff->nbytes + 3) & ~3));
  1540. nparams = ((xFixed *) stuff + client->req_len) - params;
  1541. result = SetPictureFilter(pPicture, name, stuff->nbytes, params, nparams);
  1542. return result;
  1543. }
  1544. static int
  1545. ProcRenderCreateAnimCursor(ClientPtr client)
  1546. {
  1547. REQUEST(xRenderCreateAnimCursorReq);
  1548. CursorPtr *cursors;
  1549. CARD32 *deltas;
  1550. CursorPtr pCursor;
  1551. int ncursor;
  1552. xAnimCursorElt *elt;
  1553. int i;
  1554. int ret;
  1555. REQUEST_AT_LEAST_SIZE(xRenderCreateAnimCursorReq);
  1556. LEGAL_NEW_RESOURCE(stuff->cid, client);
  1557. if (client->req_len & 1)
  1558. return BadLength;
  1559. ncursor =
  1560. (client->req_len - (SIZEOF(xRenderCreateAnimCursorReq) >> 2)) >> 1;
  1561. cursors = malloc(ncursor * (sizeof(CursorPtr) + sizeof(CARD32)));
  1562. if (!cursors)
  1563. return BadAlloc;
  1564. deltas = (CARD32 *) (cursors + ncursor);
  1565. elt = (xAnimCursorElt *) (stuff + 1);
  1566. for (i = 0; i < ncursor; i++) {
  1567. cursors[i] = (CursorPtr) SecurityLookupIDByType(client, elt->cursor,
  1568. RT_CURSOR,
  1569. SecurityReadAccess);
  1570. if (!cursors[i]) {
  1571. free(cursors);
  1572. client->errorValue = elt->cursor;
  1573. return BadCursor;
  1574. }
  1575. deltas[i] = elt->delay;
  1576. elt++;
  1577. }
  1578. ret = AnimCursorCreate(cursors, deltas, ncursor, &pCursor);
  1579. free(cursors);
  1580. if (ret != Success)
  1581. return ret;
  1582. if (AddResource(stuff->cid, RT_CURSOR, (pointer) pCursor))
  1583. return client->noClientException;
  1584. return BadAlloc;
  1585. }
  1586. static int
  1587. ProcRenderAddTraps(ClientPtr client)
  1588. {
  1589. int ntraps;
  1590. PicturePtr pPicture;
  1591. REQUEST(xRenderAddTrapsReq);
  1592. REQUEST_AT_LEAST_SIZE(xRenderAddTrapsReq);
  1593. VERIFY_PICTURE(pPicture, stuff->picture, client, SecurityWriteAccess,
  1594. RenderErrBase + BadPicture);
  1595. if (!pPicture->pDrawable)
  1596. return BadDrawable;
  1597. ntraps = (client->req_len << 2) - sizeof(xRenderAddTrapsReq);
  1598. if (ntraps % sizeof(xTrap))
  1599. return BadLength;
  1600. ntraps /= sizeof(xTrap);
  1601. if (ntraps)
  1602. AddTraps(pPicture,
  1603. stuff->xOff, stuff->yOff, ntraps, (xTrap *) & stuff[1]);
  1604. return client->noClientException;
  1605. }
  1606. static int
  1607. ProcRenderCreateSolidFill(ClientPtr client)
  1608. {
  1609. PicturePtr pPicture;
  1610. int error = 0;
  1611. REQUEST(xRenderCreateSolidFillReq);
  1612. REQUEST_AT_LEAST_SIZE(xRenderCreateSolidFillReq);
  1613. LEGAL_NEW_RESOURCE(stuff->pid, client);
  1614. pPicture = CreateSolidPicture(stuff->pid, &stuff->color, &error);
  1615. if (!pPicture)
  1616. return error;
  1617. if (!AddResource(stuff->pid, PictureType, (pointer) pPicture))
  1618. return BadAlloc;
  1619. return Success;
  1620. }
  1621. static int
  1622. ProcRenderCreateLinearGradient(ClientPtr client)
  1623. {
  1624. PicturePtr pPicture;
  1625. int len;
  1626. int error = 0;
  1627. xFixed *stops;
  1628. xRenderColor *colors;
  1629. REQUEST(xRenderCreateLinearGradientReq);
  1630. REQUEST_AT_LEAST_SIZE(xRenderCreateLinearGradientReq);
  1631. LEGAL_NEW_RESOURCE(stuff->pid, client);
  1632. len = (client->req_len << 2) - sizeof(xRenderCreateLinearGradientReq);
  1633. if (len != stuff->nStops * (sizeof(xFixed) + sizeof(xRenderColor)))
  1634. return BadLength;
  1635. stops = (xFixed *) (stuff + 1);
  1636. colors = (xRenderColor *) (stops + stuff->nStops);
  1637. pPicture = CreateLinearGradientPicture(stuff->pid, &stuff->p1, &stuff->p2,
  1638. stuff->nStops, stops, colors,
  1639. &error);
  1640. if (!pPicture)
  1641. return error;
  1642. if (!AddResource(stuff->pid, PictureType, (pointer) pPicture))
  1643. return BadAlloc;
  1644. return Success;
  1645. }
  1646. static int
  1647. ProcRenderCreateRadialGradient(ClientPtr client)
  1648. {
  1649. PicturePtr pPicture;
  1650. int len;
  1651. int error = 0;
  1652. xFixed *stops;
  1653. xRenderColor *colors;
  1654. REQUEST(xRenderCreateRadialGradientReq);
  1655. REQUEST_AT_LEAST_SIZE(xRenderCreateRadialGradientReq);
  1656. LEGAL_NEW_RESOURCE(stuff->pid, client);
  1657. len = (client->req_len << 2) - sizeof(xRenderCreateRadialGradientReq);
  1658. if (len != stuff->nStops * (sizeof(xFixed) + sizeof(xRenderColor)))
  1659. return BadLength;
  1660. stops = (xFixed *) (stuff + 1);
  1661. colors = (xRenderColor *) (stops + stuff->nStops);
  1662. pPicture =
  1663. CreateRadialGradientPicture(stuff->pid, &stuff->inner, &stuff->outer,
  1664. stuff->inner_radius, stuff->outer_radius,
  1665. stuff->nStops, stops, colors, &error);
  1666. if (!pPicture)
  1667. return error;
  1668. if (!AddResource(stuff->pid, PictureType, (pointer) pPicture))
  1669. return BadAlloc;
  1670. return Success;
  1671. }
  1672. static int
  1673. ProcRenderCreateConicalGradient(ClientPtr client)
  1674. {
  1675. PicturePtr pPicture;
  1676. int len;
  1677. int error = 0;
  1678. xFixed *stops;
  1679. xRenderColor *colors;
  1680. REQUEST(xRenderCreateConicalGradientReq);
  1681. REQUEST_AT_LEAST_SIZE(xRenderCreateConicalGradientReq);
  1682. LEGAL_NEW_RESOURCE(stuff->pid, client);
  1683. len = (client->req_len << 2) - sizeof(xRenderCreateConicalGradientReq);
  1684. if (len != stuff->nStops * (sizeof(xFixed) + sizeof(xRenderColor)))
  1685. return BadLength;
  1686. stops = (xFixed *) (stuff + 1);
  1687. colors = (xRenderColor *) (stops + stuff->nStops);
  1688. pPicture =
  1689. CreateConicalGradientPicture(stuff->pid, &stuff->center, stuff->angle,
  1690. stuff->nStops, stops, colors, &error);
  1691. if (!pPicture)
  1692. return error;
  1693. if (!AddResource(stuff->pid, PictureType, (pointer) pPicture))
  1694. return BadAlloc;
  1695. return Success;
  1696. }
  1697. static int
  1698. ProcRenderDispatch(ClientPtr client)
  1699. {
  1700. REQUEST(xReq);
  1701. if (stuff->data < RenderNumberRequests)
  1702. return (*ProcRenderVector[stuff->data]) (client);
  1703. else
  1704. return BadRequest;
  1705. }
  1706. static int
  1707. SProcRenderQueryVersion(ClientPtr client)
  1708. {
  1709. REQUEST(xRenderQueryVersionReq);
  1710. swaps(&stuff->length);
  1711. swapl(&stuff->majorVersion);
  1712. swapl(&stuff->minorVersion);
  1713. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1714. }
  1715. static int
  1716. SProcRenderQueryPictFormats(ClientPtr client)
  1717. {
  1718. REQUEST(xRenderQueryPictFormatsReq);
  1719. swaps(&stuff->length);
  1720. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1721. }
  1722. static int
  1723. SProcRenderQueryPictIndexValues(ClientPtr client)
  1724. {
  1725. REQUEST(xRenderQueryPictIndexValuesReq);
  1726. swaps(&stuff->length);
  1727. swapl(&stuff->format);
  1728. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1729. }
  1730. static int
  1731. SProcRenderQueryDithers(ClientPtr client)
  1732. {
  1733. return BadImplementation;
  1734. }
  1735. static int
  1736. SProcRenderCreatePicture(ClientPtr client)
  1737. {
  1738. REQUEST(xRenderCreatePictureReq);
  1739. swaps(&stuff->length);
  1740. swapl(&stuff->pid);
  1741. swapl(&stuff->drawable);
  1742. swapl(&stuff->format);
  1743. swapl(&stuff->mask);
  1744. SwapRestL(stuff);
  1745. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1746. }
  1747. static int
  1748. SProcRenderChangePicture(ClientPtr client)
  1749. {
  1750. REQUEST(xRenderChangePictureReq);
  1751. swaps(&stuff->length);
  1752. swapl(&stuff->picture);
  1753. swapl(&stuff->mask);
  1754. SwapRestL(stuff);
  1755. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1756. }
  1757. static int
  1758. SProcRenderSetPictureClipRectangles(ClientPtr client)
  1759. {
  1760. REQUEST(xRenderSetPictureClipRectanglesReq);
  1761. swaps(&stuff->length);
  1762. swapl(&stuff->picture);
  1763. SwapRestS(stuff);
  1764. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1765. }
  1766. static int
  1767. SProcRenderFreePicture(ClientPtr client)
  1768. {
  1769. REQUEST(xRenderFreePictureReq);
  1770. swaps(&stuff->length);
  1771. swapl(&stuff->picture);
  1772. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1773. }
  1774. static int
  1775. SProcRenderComposite(ClientPtr client)
  1776. {
  1777. REQUEST(xRenderCompositeReq);
  1778. swaps(&stuff->length);
  1779. swapl(&stuff->src);
  1780. swapl(&stuff->mask);
  1781. swapl(&stuff->dst);
  1782. swaps(&stuff->xSrc);
  1783. swaps(&stuff->ySrc);
  1784. swaps(&stuff->xMask);
  1785. swaps(&stuff->yMask);
  1786. swaps(&stuff->xDst);
  1787. swaps(&stuff->yDst);
  1788. swaps(&stuff->width);
  1789. swaps(&stuff->height);
  1790. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1791. }
  1792. static int
  1793. SProcRenderScale(ClientPtr client)
  1794. {
  1795. REQUEST(xRenderScaleReq);
  1796. swaps(&stuff->length);
  1797. swapl(&stuff->src);
  1798. swapl(&stuff->dst);
  1799. swapl(&stuff->colorScale);
  1800. swapl(&stuff->alphaScale);
  1801. swaps(&stuff->xSrc);
  1802. swaps(&stuff->ySrc);
  1803. swaps(&stuff->xDst);
  1804. swaps(&stuff->yDst);
  1805. swaps(&stuff->width);
  1806. swaps(&stuff->height);
  1807. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1808. }
  1809. static int
  1810. SProcRenderTrapezoids(ClientPtr client)
  1811. {
  1812. REQUEST(xRenderTrapezoidsReq);
  1813. REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq);
  1814. swaps(&stuff->length);
  1815. swapl(&stuff->src);
  1816. swapl(&stuff->dst);
  1817. swapl(&stuff->maskFormat);
  1818. swaps(&stuff->xSrc);
  1819. swaps(&stuff->ySrc);
  1820. SwapRestL(stuff);
  1821. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1822. }
  1823. static int
  1824. SProcRenderTriangles(ClientPtr client)
  1825. {
  1826. REQUEST(xRenderTrianglesReq);
  1827. REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq);
  1828. swaps(&stuff->length);
  1829. swapl(&stuff->src);
  1830. swapl(&stuff->dst);
  1831. swapl(&stuff->maskFormat);
  1832. swaps(&stuff->xSrc);
  1833. swaps(&stuff->ySrc);
  1834. SwapRestL(stuff);
  1835. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1836. }
  1837. static int
  1838. SProcRenderTriStrip(ClientPtr client)
  1839. {
  1840. REQUEST(xRenderTriStripReq);
  1841. REQUEST_AT_LEAST_SIZE(xRenderTriStripReq);
  1842. swaps(&stuff->length);
  1843. swapl(&stuff->src);
  1844. swapl(&stuff->dst);
  1845. swapl(&stuff->maskFormat);
  1846. swaps(&stuff->xSrc);
  1847. swaps(&stuff->ySrc);
  1848. SwapRestL(stuff);
  1849. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1850. }
  1851. static int
  1852. SProcRenderTriFan(ClientPtr client)
  1853. {
  1854. REQUEST(xRenderTriFanReq);
  1855. REQUEST_AT_LEAST_SIZE(xRenderTriFanReq);
  1856. swaps(&stuff->length);
  1857. swapl(&stuff->src);
  1858. swapl(&stuff->dst);
  1859. swapl(&stuff->maskFormat);
  1860. swaps(&stuff->xSrc);
  1861. swaps(&stuff->ySrc);
  1862. SwapRestL(stuff);
  1863. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1864. }
  1865. static int
  1866. SProcRenderColorTrapezoids(ClientPtr client)
  1867. {
  1868. return BadImplementation;
  1869. }
  1870. static int
  1871. SProcRenderColorTriangles(ClientPtr client)
  1872. {
  1873. return BadImplementation;
  1874. }
  1875. static int
  1876. SProcRenderTransform(ClientPtr client)
  1877. {
  1878. return BadImplementation;
  1879. }
  1880. static int
  1881. SProcRenderCreateGlyphSet(ClientPtr client)
  1882. {
  1883. REQUEST(xRenderCreateGlyphSetReq);
  1884. swaps(&stuff->length);
  1885. swapl(&stuff->gsid);
  1886. swapl(&stuff->format);
  1887. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1888. }
  1889. static int
  1890. SProcRenderReferenceGlyphSet(ClientPtr client)
  1891. {
  1892. REQUEST(xRenderReferenceGlyphSetReq);
  1893. swaps(&stuff->length);
  1894. swapl(&stuff->gsid);
  1895. swapl(&stuff->existing);
  1896. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1897. }
  1898. static int
  1899. SProcRenderFreeGlyphSet(ClientPtr client)
  1900. {
  1901. REQUEST(xRenderFreeGlyphSetReq);
  1902. swaps(&stuff->length);
  1903. swapl(&stuff->glyphset);
  1904. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1905. }
  1906. static int
  1907. SProcRenderAddGlyphs(ClientPtr client)
  1908. {
  1909. int i;
  1910. CARD32 *gids;
  1911. void *end;
  1912. xGlyphInfo *gi;
  1913. REQUEST(xRenderAddGlyphsReq);
  1914. swaps(&stuff->length);
  1915. swapl(&stuff->glyphset);
  1916. swapl(&stuff->nglyphs);
  1917. if (stuff->nglyphs & 0xe0000000)
  1918. return BadLength;
  1919. end = (CARD8 *) stuff + (client->req_len << 2);
  1920. gids = (CARD32 *) (stuff + 1);
  1921. gi = (xGlyphInfo *) (gids + stuff->nglyphs);
  1922. if ((char *) end - (char *) (gids + stuff->nglyphs) < 0)
  1923. return BadLength;
  1924. if ((char *) end - (char *) (gi + stuff->nglyphs) < 0)
  1925. return BadLength;
  1926. for (i = 0; i < stuff->nglyphs; i++) {
  1927. swapl(&gids[i]);
  1928. swaps(&gi[i].width);
  1929. swaps(&gi[i].height);
  1930. swaps(&gi[i].x);
  1931. swaps(&gi[i].y);
  1932. swaps(&gi[i].xOff);
  1933. swaps(&gi[i].yOff);
  1934. }
  1935. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1936. }
  1937. static int
  1938. SProcRenderAddGlyphsFromPicture(ClientPtr client)
  1939. {
  1940. return BadImplementation;
  1941. }
  1942. static int
  1943. SProcRenderFreeGlyphs(ClientPtr client)
  1944. {
  1945. REQUEST(xRenderFreeGlyphsReq);
  1946. swaps(&stuff->length);
  1947. swapl(&stuff->glyphset);
  1948. SwapRestL(stuff);
  1949. return (*ProcRenderVector[stuff->renderReqType]) (client);
  1950. }
  1951. static int
  1952. SProcRenderCompositeGlyphs(ClientPtr client)
  1953. {
  1954. xGlyphElt *elt;
  1955. CARD8 *buffer;
  1956. CARD8 *end;
  1957. int space;
  1958. int i;
  1959. int size;
  1960. REQUEST(xRenderCompositeGlyphsReq);
  1961. switch (stuff->renderReqType) {
  1962. default:
  1963. size = 1;
  1964. break;
  1965. case X_RenderCompositeGlyphs16:
  1966. size = 2;
  1967. break;
  1968. case X_RenderCompositeGlyphs32:
  1969. size = 4;
  1970. break;
  1971. }
  1972. swaps(&stuff->length);
  1973. swapl(&stuff->src);
  1974. swapl(&stuff->dst);
  1975. swapl(&stuff->maskFormat);
  1976. swapl(&stuff->glyphset);
  1977. swaps(&stuff->xSrc);
  1978. swaps(&stuff->ySrc);
  1979. buffer = (CARD8 *) (stuff + 1);
  1980. end = (CARD8 *) stuff + (client->req_len << 2);
  1981. while (buffer + sizeof(xGlyphElt) < end) {
  1982. elt = (xGlyphElt *) buffer;
  1983. buffer += sizeof(xGlyphElt);
  1984. swaps(&elt->deltax);
  1985. swaps(&elt->deltay);
  1986. i = elt->len;
  1987. if (i == 0xff) {
  1988. swapl((int *) buffer);
  1989. buffer += 4;
  1990. }
  1991. else {
  1992. space = size * i;
  1993. switch (size) {
  1994. case 1:
  1995. buffer += i;
  1996. break;
  1997. case 2:
  1998. while (i--) {
  1999. swaps((short *) buffer);
  2000. buffer += 2;
  2001. }
  2002. break;
  2003. case 4:
  2004. while (i--) {
  2005. swapl((int *) buffer);
  2006. buffer += 4;
  2007. }
  2008. break;
  2009. }
  2010. if (space & 3)
  2011. buffer += 4 - (space & 3);
  2012. }
  2013. }
  2014. return (*ProcRenderVector[stuff->renderReqType]) (client);
  2015. }
  2016. static int
  2017. SProcRenderFillRectangles(ClientPtr client)
  2018. {
  2019. REQUEST(xRenderFillRectanglesReq);
  2020. REQUEST_AT_LEAST_SIZE(xRenderFillRectanglesReq);
  2021. swaps(&stuff->length);
  2022. swapl(&stuff->dst);
  2023. swaps(&stuff->color.red);
  2024. swaps(&stuff->color.green);
  2025. swaps(&stuff->color.blue);
  2026. swaps(&stuff->color.alpha);
  2027. SwapRestS(stuff);
  2028. return (*ProcRenderVector[stuff->renderReqType]) (client);
  2029. }
  2030. static int
  2031. SProcRenderCreateCursor(ClientPtr client)
  2032. {
  2033. REQUEST(xRenderCreateCursorReq);
  2034. REQUEST_SIZE_MATCH(xRenderCreateCursorReq);
  2035. swaps(&stuff->length);
  2036. swapl(&stuff->cid);
  2037. swapl(&stuff->src);
  2038. swaps(&stuff->x);
  2039. swaps(&stuff->y);
  2040. return (*ProcRenderVector[stuff->renderReqType]) (client);
  2041. }
  2042. static int
  2043. SProcRenderSetPictureTransform(ClientPtr client)
  2044. {
  2045. REQUEST(xRenderSetPictureTransformReq);
  2046. REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq);
  2047. swaps(&stuff->length);
  2048. swapl(&stuff->picture);
  2049. swapl(&stuff->transform.matrix11);
  2050. swapl(&stuff->transform.matrix12);
  2051. swapl(&stuff->transform.matrix13);
  2052. swapl(&stuff->transform.matrix21);
  2053. swapl(&stuff->transform.matrix22);
  2054. swapl(&stuff->transform.matrix23);
  2055. swapl(&stuff->transform.matrix31);
  2056. swapl(&stuff->transform.matrix32);
  2057. swapl(&stuff->transform.matrix33);
  2058. return (*ProcRenderVector[stuff->renderReqType]) (client);
  2059. }
  2060. static int
  2061. SProcRenderQueryFilters(ClientPtr client)
  2062. {
  2063. REQUEST(xRenderQueryFiltersReq);
  2064. REQUEST_SIZE_MATCH(xRenderQueryFiltersReq);
  2065. swaps(&stuff->length);
  2066. swapl(&stuff->drawable);
  2067. return (*ProcRenderVector[stuff->renderReqType]) (client);
  2068. }
  2069. static int
  2070. SProcRenderSetPictureFilter(ClientPtr client)
  2071. {
  2072. REQUEST(xRenderSetPictureFilterReq);
  2073. REQUEST_AT_LEAST_SIZE(xRenderSetPictureFilterReq);
  2074. swaps(&stuff->length);
  2075. swapl(&stuff->picture);
  2076. swaps(&stuff->nbytes);
  2077. return (*ProcRenderVector[stuff->renderReqType]) (client);
  2078. }
  2079. static int
  2080. SProcRenderCreateAnimCursor(ClientPtr client)
  2081. {
  2082. REQUEST(xRenderCreateAnimCursorReq);
  2083. REQUEST_AT_LEAST_SIZE(xRenderCreateAnimCursorReq);
  2084. swaps(&stuff->length);
  2085. swapl(&stuff->cid);
  2086. SwapRestL(stuff);
  2087. return (*ProcRenderVector[stuff->renderReqType]) (client);
  2088. }
  2089. static int
  2090. SProcRenderAddTraps(ClientPtr client)
  2091. {
  2092. REQUEST(xRenderAddTrapsReq);
  2093. REQUEST_AT_LEAST_SIZE(xRenderAddTrapsReq);
  2094. swaps(&stuff->length);
  2095. swapl(&stuff->picture);
  2096. swaps(&stuff->xOff);
  2097. swaps(&stuff->yOff);
  2098. SwapRestL(stuff);
  2099. return (*ProcRenderVector[stuff->renderReqType]) (client);
  2100. }
  2101. static int
  2102. SProcRenderCreateSolidFill(ClientPtr client)
  2103. {
  2104. REQUEST(xRenderCreateSolidFillReq);
  2105. REQUEST_AT_LEAST_SIZE(xRenderCreateSolidFillReq);
  2106. swaps(&stuff->length);
  2107. swapl(&stuff->pid);
  2108. swaps(&stuff->color.alpha);
  2109. swaps(&stuff->color.red);
  2110. swaps(&stuff->color.green);
  2111. swaps(&stuff->color.blue);
  2112. return (*ProcRenderVector[stuff->renderReqType]) (client);
  2113. }
  2114. static void
  2115. swapStops(void *stuff, int n)
  2116. {
  2117. int i;
  2118. CARD32 *stops;
  2119. CARD16 *colors;
  2120. stops = (CARD32 *) (stuff);
  2121. for (i = 0; i < n; ++i) {
  2122. swapl(stops);
  2123. ++stops;
  2124. }
  2125. colors = (CARD16 *) (stops);
  2126. for (i = 0; i < 4 * n; ++i) {
  2127. swaps(colors);
  2128. ++colors;
  2129. }
  2130. }
  2131. static int
  2132. SProcRenderCreateLinearGradient(ClientPtr client)
  2133. {
  2134. int len;
  2135. REQUEST(xRenderCreateLinearGradientReq);
  2136. REQUEST_AT_LEAST_SIZE(xRenderCreateLinearGradientReq);
  2137. swaps(&stuff->length);
  2138. swapl(&stuff->pid);
  2139. swapl(&stuff->p1.x);
  2140. swapl(&stuff->p1.y);
  2141. swapl(&stuff->p2.x);
  2142. swapl(&stuff->p2.y);
  2143. swapl(&stuff->nStops);
  2144. len = (client->req_len << 2) - sizeof(xRenderCreateLinearGradientReq);
  2145. if (len != stuff->nStops * (sizeof(xFixed) + sizeof(xRenderColor)))
  2146. return BadLength;
  2147. swapStops(stuff + 1, stuff->nStops);
  2148. return (*ProcRenderVector[stuff->renderReqType]) (client);
  2149. }
  2150. static int
  2151. SProcRenderCreateRadialGradient(ClientPtr client)
  2152. {
  2153. int len;
  2154. REQUEST(xRenderCreateRadialGradientReq);
  2155. REQUEST_AT_LEAST_SIZE(xRenderCreateRadialGradientReq);
  2156. swaps(&stuff->length);
  2157. swapl(&stuff->pid);
  2158. swapl(&stuff->inner.x);
  2159. swapl(&stuff->inner.y);
  2160. swapl(&stuff->outer.x);
  2161. swapl(&stuff->outer.y);
  2162. swapl(&stuff->inner_radius);
  2163. swapl(&stuff->outer_radius);
  2164. swapl(&stuff->nStops);
  2165. len = (client->req_len << 2) - sizeof(xRenderCreateRadialGradientReq);
  2166. if (len != stuff->nStops * (sizeof(xFixed) + sizeof(xRenderColor)))
  2167. return BadLength;
  2168. swapStops(stuff + 1, stuff->nStops);
  2169. return (*ProcRenderVector[stuff->renderReqType]) (client);
  2170. }
  2171. static int
  2172. SProcRenderCreateConicalGradient(ClientPtr client)
  2173. {
  2174. int len;
  2175. REQUEST(xRenderCreateConicalGradientReq);
  2176. REQUEST_AT_LEAST_SIZE(xRenderCreateConicalGradientReq);
  2177. swaps(&stuff->length);
  2178. swapl(&stuff->pid);
  2179. swapl(&stuff->center.x);
  2180. swapl(&stuff->center.y);
  2181. swapl(&stuff->angle);
  2182. swapl(&stuff->nStops);
  2183. len = (client->req_len << 2) - sizeof(xRenderCreateConicalGradientReq);
  2184. if (len != stuff->nStops * (sizeof(xFixed) + sizeof(xRenderColor)))
  2185. return BadLength;
  2186. swapStops(stuff + 1, stuff->nStops);
  2187. return (*ProcRenderVector[stuff->renderReqType]) (client);
  2188. }
  2189. static int
  2190. SProcRenderDispatch(ClientPtr client)
  2191. {
  2192. REQUEST(xReq);
  2193. if (stuff->data < RenderNumberRequests)
  2194. return (*SProcRenderVector[stuff->data]) (client);
  2195. else
  2196. return BadRequest;
  2197. }