File: | composite/compext.c |
Location: | line 752, column 20 |
Description: | Potential leak of memory pointed to by 'newPix' |
1 | /* | |||||
2 | * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. | |||||
3 | * | |||||
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |||||
5 | * copy of this software and associated documentation files (the "Software"), | |||||
6 | * to deal in the Software without restriction, including without limitation | |||||
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||||
8 | * and/or sell copies of the Software, and to permit persons to whom the | |||||
9 | * Software is furnished to do so, subject to the following conditions: | |||||
10 | * | |||||
11 | * The above copyright notice and this permission notice (including the next | |||||
12 | * paragraph) shall be included in all copies or substantial portions of the | |||||
13 | * Software. | |||||
14 | * | |||||
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||||
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||||
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||||
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||||
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||||
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||||
21 | * DEALINGS IN THE SOFTWARE. | |||||
22 | * | |||||
23 | * Copyright © 2003 Keith Packard | |||||
24 | * | |||||
25 | * Permission to use, copy, modify, distribute, and sell this software and its | |||||
26 | * documentation for any purpose is hereby granted without fee, provided that | |||||
27 | * the above copyright notice appear in all copies and that both that | |||||
28 | * copyright notice and this permission notice appear in supporting | |||||
29 | * documentation, and that the name of Keith Packard not be used in | |||||
30 | * advertising or publicity pertaining to distribution of the software without | |||||
31 | * specific, written prior permission. Keith Packard makes no | |||||
32 | * representations about the suitability of this software for any purpose. It | |||||
33 | * is provided "as is" without express or implied warranty. | |||||
34 | * | |||||
35 | * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | |||||
36 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | |||||
37 | * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR | |||||
38 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | |||||
39 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | |||||
40 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | |||||
41 | * PERFORMANCE OF THIS SOFTWARE. | |||||
42 | */ | |||||
43 | ||||||
44 | #ifdef HAVE_DIX_CONFIG_H1 | |||||
45 | #include <dix-config.h> | |||||
46 | #endif | |||||
47 | ||||||
48 | #include "compint.h" | |||||
49 | #include "xace.h" | |||||
50 | #include "protocol-versions.h" | |||||
51 | #include "extinit.h" | |||||
52 | ||||||
53 | static CARD8 CompositeReqCode; | |||||
54 | static DevPrivateKeyRec CompositeClientPrivateKeyRec; | |||||
55 | ||||||
56 | #define CompositeClientPrivateKey(&CompositeClientPrivateKeyRec) (&CompositeClientPrivateKeyRec) | |||||
57 | RESTYPE CompositeClientWindowType; | |||||
58 | RESTYPE CompositeClientSubwindowsType; | |||||
59 | RESTYPE CompositeClientOverlayType; | |||||
60 | ||||||
61 | typedef struct _CompositeClient { | |||||
62 | int major_version; | |||||
63 | int minor_version; | |||||
64 | } CompositeClientRec, *CompositeClientPtr; | |||||
65 | ||||||
66 | #define GetCompositeClient(pClient)((CompositeClientPtr) dixLookupPrivate(&(pClient)->devPrivates , (&CompositeClientPrivateKeyRec))) ((CompositeClientPtr) \ | |||||
67 | dixLookupPrivate(&(pClient)->devPrivates, CompositeClientPrivateKey(&CompositeClientPrivateKeyRec))) | |||||
68 | ||||||
69 | static int | |||||
70 | FreeCompositeClientWindow(void *value, XID ccwid) | |||||
71 | { | |||||
72 | WindowPtr pWin = value; | |||||
73 | ||||||
74 | compFreeClientWindow(pWin, ccwid); | |||||
75 | return Success0; | |||||
76 | } | |||||
77 | ||||||
78 | static int | |||||
79 | FreeCompositeClientSubwindows(void *value, XID ccwid) | |||||
80 | { | |||||
81 | WindowPtr pWin = value; | |||||
82 | ||||||
83 | compFreeClientSubwindows(pWin, ccwid); | |||||
84 | return Success0; | |||||
85 | } | |||||
86 | ||||||
87 | static int | |||||
88 | FreeCompositeClientOverlay(void *value, XID ccwid) | |||||
89 | { | |||||
90 | CompOverlayClientPtr pOc = (CompOverlayClientPtr) value; | |||||
91 | ||||||
92 | compFreeOverlayClient(pOc); | |||||
93 | return Success0; | |||||
94 | } | |||||
95 | ||||||
96 | static int | |||||
97 | ProcCompositeQueryVersion(ClientPtr client) | |||||
98 | { | |||||
99 | CompositeClientPtr pCompositeClient = GetCompositeClient(client)((CompositeClientPtr) dixLookupPrivate(&(client)->devPrivates , (&CompositeClientPrivateKeyRec))); | |||||
100 | xCompositeQueryVersionReply rep = { | |||||
101 | .type = X_Reply1, | |||||
102 | .sequenceNumber = client->sequence, | |||||
103 | .length = 0 | |||||
104 | }; | |||||
105 | ||||||
106 | REQUEST(xCompositeQueryVersionReq)xCompositeQueryVersionReq *stuff = (xCompositeQueryVersionReq *)client->requestBuffer; | |||||
107 | ||||||
108 | REQUEST_SIZE_MATCH(xCompositeQueryVersionReq)if ((sizeof(xCompositeQueryVersionReq) >> 2) != client-> req_len) return(16); | |||||
109 | if (stuff->majorVersion < SERVER_COMPOSITE_MAJOR_VERSION0) { | |||||
110 | rep.majorVersion = stuff->majorVersion; | |||||
111 | rep.minorVersion = stuff->minorVersion; | |||||
112 | } | |||||
113 | else { | |||||
114 | rep.majorVersion = SERVER_COMPOSITE_MAJOR_VERSION0; | |||||
115 | rep.minorVersion = SERVER_COMPOSITE_MINOR_VERSION4; | |||||
116 | } | |||||
117 | pCompositeClient->major_version = rep.majorVersion; | |||||
118 | pCompositeClient->minor_version = rep.minorVersion; | |||||
119 | if (client->swapped) { | |||||
120 | swaps(&rep.sequenceNumber)do { if (sizeof(*(&rep.sequenceNumber)) != 2) wrong_size( ); if (__builtin_constant_p((uintptr_t)(&rep.sequenceNumber ) & 1) && ((uintptr_t)(&rep.sequenceNumber) & 1) == 0) *(&rep.sequenceNumber) = lswaps(*(&rep.sequenceNumber )); else swap_uint16((uint16_t *)(&rep.sequenceNumber)); } while (0); | |||||
121 | swapl(&rep.length)do { if (sizeof(*(&rep.length)) != 4) wrong_size(); if (__builtin_constant_p ((uintptr_t)(&rep.length) & 3) && ((uintptr_t )(&rep.length) & 3) == 0) *(&rep.length) = lswapl (*(&rep.length)); else swap_uint32((uint32_t *)(&rep. length)); } while (0); | |||||
122 | swapl(&rep.majorVersion)do { if (sizeof(*(&rep.majorVersion)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&rep.majorVersion) & 3) && ((uintptr_t)(&rep.majorVersion) & 3) == 0) *(&rep.majorVersion) = lswapl(*(&rep.majorVersion )); else swap_uint32((uint32_t *)(&rep.majorVersion)); } while (0); | |||||
123 | swapl(&rep.minorVersion)do { if (sizeof(*(&rep.minorVersion)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&rep.minorVersion) & 3) && ((uintptr_t)(&rep.minorVersion) & 3) == 0) *(&rep.minorVersion) = lswapl(*(&rep.minorVersion )); else swap_uint32((uint32_t *)(&rep.minorVersion)); } while (0); | |||||
124 | } | |||||
125 | WriteToClient(client, sizeof(xCompositeQueryVersionReply), &rep); | |||||
126 | return Success0; | |||||
127 | } | |||||
128 | ||||||
129 | #define VERIFY_WINDOW(pWindow, wid, client, mode)do { int err; err = dixLookupResourceByType((void **) &pWindow , wid, ((RESTYPE)1|((RESTYPE)1<<30)), client, mode); if (err != 0) { client->errorValue = wid; return err; } } while (0) \ | |||||
130 | do { \ | |||||
131 | int err; \ | |||||
132 | err = dixLookupResourceByType((void **) &pWindow, wid, \ | |||||
133 | RT_WINDOW((RESTYPE)1|((RESTYPE)1<<30)), client, mode); \ | |||||
134 | if (err != Success0) { \ | |||||
135 | client->errorValue = wid; \ | |||||
136 | return err; \ | |||||
137 | } \ | |||||
138 | } while (0) | |||||
139 | ||||||
140 | static int | |||||
141 | ProcCompositeRedirectWindow(ClientPtr client) | |||||
142 | { | |||||
143 | WindowPtr pWin; | |||||
144 | ||||||
145 | REQUEST(xCompositeRedirectWindowReq)xCompositeRedirectWindowReq *stuff = (xCompositeRedirectWindowReq *)client->requestBuffer; | |||||
146 | ||||||
147 | REQUEST_SIZE_MATCH(xCompositeRedirectWindowReq)if ((sizeof(xCompositeRedirectWindowReq) >> 2) != client ->req_len) return(16); | |||||
148 | VERIFY_WINDOW(pWin, stuff->window, client,do { int err; err = dixLookupResourceByType((void **) &pWin , stuff->window, ((RESTYPE)1|((RESTYPE)1<<30)), client , (1<<5) | (1<<25) | (1<<16)); if (err != 0 ) { client->errorValue = stuff->window; return err; } } while (0) | |||||
149 | DixSetAttrAccess | DixManageAccess | DixBlendAccess)do { int err; err = dixLookupResourceByType((void **) &pWin , stuff->window, ((RESTYPE)1|((RESTYPE)1<<30)), client , (1<<5) | (1<<25) | (1<<16)); if (err != 0 ) { client->errorValue = stuff->window; return err; } } while (0); | |||||
150 | ||||||
151 | return compRedirectWindow(client, pWin, stuff->update); | |||||
152 | } | |||||
153 | ||||||
154 | static int | |||||
155 | ProcCompositeRedirectSubwindows(ClientPtr client) | |||||
156 | { | |||||
157 | WindowPtr pWin; | |||||
158 | ||||||
159 | REQUEST(xCompositeRedirectSubwindowsReq)xCompositeRedirectSubwindowsReq *stuff = (xCompositeRedirectSubwindowsReq *)client->requestBuffer; | |||||
160 | ||||||
161 | REQUEST_SIZE_MATCH(xCompositeRedirectSubwindowsReq)if ((sizeof(xCompositeRedirectSubwindowsReq) >> 2) != client ->req_len) return(16); | |||||
162 | VERIFY_WINDOW(pWin, stuff->window, client,do { int err; err = dixLookupResourceByType((void **) &pWin , stuff->window, ((RESTYPE)1|((RESTYPE)1<<30)), client , (1<<5) | (1<<25) | (1<<16)); if (err != 0 ) { client->errorValue = stuff->window; return err; } } while (0) | |||||
163 | DixSetAttrAccess | DixManageAccess | DixBlendAccess)do { int err; err = dixLookupResourceByType((void **) &pWin , stuff->window, ((RESTYPE)1|((RESTYPE)1<<30)), client , (1<<5) | (1<<25) | (1<<16)); if (err != 0 ) { client->errorValue = stuff->window; return err; } } while (0); | |||||
164 | ||||||
165 | return compRedirectSubwindows(client, pWin, stuff->update); | |||||
166 | } | |||||
167 | ||||||
168 | static int | |||||
169 | ProcCompositeUnredirectWindow(ClientPtr client) | |||||
170 | { | |||||
171 | WindowPtr pWin; | |||||
172 | ||||||
173 | REQUEST(xCompositeUnredirectWindowReq)xCompositeUnredirectWindowReq *stuff = (xCompositeUnredirectWindowReq *)client->requestBuffer; | |||||
174 | ||||||
175 | REQUEST_SIZE_MATCH(xCompositeUnredirectWindowReq)if ((sizeof(xCompositeUnredirectWindowReq) >> 2) != client ->req_len) return(16); | |||||
176 | VERIFY_WINDOW(pWin, stuff->window, client,do { int err; err = dixLookupResourceByType((void **) &pWin , stuff->window, ((RESTYPE)1|((RESTYPE)1<<30)), client , (1<<5) | (1<<25) | (1<<16)); if (err != 0 ) { client->errorValue = stuff->window; return err; } } while (0) | |||||
177 | DixSetAttrAccess | DixManageAccess | DixBlendAccess)do { int err; err = dixLookupResourceByType((void **) &pWin , stuff->window, ((RESTYPE)1|((RESTYPE)1<<30)), client , (1<<5) | (1<<25) | (1<<16)); if (err != 0 ) { client->errorValue = stuff->window; return err; } } while (0); | |||||
178 | ||||||
179 | return compUnredirectWindow(client, pWin, stuff->update); | |||||
180 | } | |||||
181 | ||||||
182 | static int | |||||
183 | ProcCompositeUnredirectSubwindows(ClientPtr client) | |||||
184 | { | |||||
185 | WindowPtr pWin; | |||||
186 | ||||||
187 | REQUEST(xCompositeUnredirectSubwindowsReq)xCompositeUnredirectSubwindowsReq *stuff = (xCompositeUnredirectSubwindowsReq *)client->requestBuffer; | |||||
188 | ||||||
189 | REQUEST_SIZE_MATCH(xCompositeUnredirectSubwindowsReq)if ((sizeof(xCompositeUnredirectSubwindowsReq) >> 2) != client->req_len) return(16); | |||||
190 | VERIFY_WINDOW(pWin, stuff->window, client,do { int err; err = dixLookupResourceByType((void **) &pWin , stuff->window, ((RESTYPE)1|((RESTYPE)1<<30)), client , (1<<5) | (1<<25) | (1<<16)); if (err != 0 ) { client->errorValue = stuff->window; return err; } } while (0) | |||||
191 | DixSetAttrAccess | DixManageAccess | DixBlendAccess)do { int err; err = dixLookupResourceByType((void **) &pWin , stuff->window, ((RESTYPE)1|((RESTYPE)1<<30)), client , (1<<5) | (1<<25) | (1<<16)); if (err != 0 ) { client->errorValue = stuff->window; return err; } } while (0); | |||||
192 | ||||||
193 | return compUnredirectSubwindows(client, pWin, stuff->update); | |||||
194 | } | |||||
195 | ||||||
196 | static int | |||||
197 | ProcCompositeCreateRegionFromBorderClip(ClientPtr client) | |||||
198 | { | |||||
199 | WindowPtr pWin; | |||||
200 | CompWindowPtr cw; | |||||
201 | RegionPtr pBorderClip, pRegion; | |||||
202 | ||||||
203 | REQUEST(xCompositeCreateRegionFromBorderClipReq)xCompositeCreateRegionFromBorderClipReq *stuff = (xCompositeCreateRegionFromBorderClipReq *)client->requestBuffer; | |||||
204 | ||||||
205 | REQUEST_SIZE_MATCH(xCompositeCreateRegionFromBorderClipReq)if ((sizeof(xCompositeCreateRegionFromBorderClipReq) >> 2) != client->req_len) return(16); | |||||
206 | VERIFY_WINDOW(pWin, stuff->window, client, DixGetAttrAccess)do { int err; err = dixLookupResourceByType((void **) &pWin , stuff->window, ((RESTYPE)1|((RESTYPE)1<<30)), client , (1<<4)); if (err != 0) { client->errorValue = stuff ->window; return err; } } while (0); | |||||
207 | LEGAL_NEW_RESOURCE(stuff->region, client)if (!LegalNewID(stuff->region,client)) { client->errorValue = stuff->region; return 14; }; | |||||
208 | ||||||
209 | cw = GetCompWindow(pWin)((CompWindowPtr) dixLookupPrivate(&(pWin)->devPrivates , (&CompWindowPrivateKeyRec))); | |||||
210 | if (cw) | |||||
211 | pBorderClip = &cw->borderClip; | |||||
212 | else | |||||
213 | pBorderClip = &pWin->borderClip; | |||||
214 | pRegion = XFixesRegionCopy(pBorderClip); | |||||
215 | if (!pRegion) | |||||
216 | return BadAlloc11; | |||||
217 | RegionTranslate(pRegion, -pWin->drawable.x, -pWin->drawable.y); | |||||
218 | ||||||
219 | if (!AddResourceDarwin_X_AddResource(stuff->region, RegionResType, (void *) pRegion)) | |||||
220 | return BadAlloc11; | |||||
221 | ||||||
222 | return Success0; | |||||
223 | } | |||||
224 | ||||||
225 | static int | |||||
226 | ProcCompositeNameWindowPixmap(ClientPtr client) | |||||
227 | { | |||||
228 | WindowPtr pWin; | |||||
229 | CompWindowPtr cw; | |||||
230 | PixmapPtr pPixmap; | |||||
231 | ScreenPtr pScreen; | |||||
232 | int rc; | |||||
233 | ||||||
234 | REQUEST(xCompositeNameWindowPixmapReq)xCompositeNameWindowPixmapReq *stuff = (xCompositeNameWindowPixmapReq *)client->requestBuffer; | |||||
235 | ||||||
236 | REQUEST_SIZE_MATCH(xCompositeNameWindowPixmapReq)if ((sizeof(xCompositeNameWindowPixmapReq) >> 2) != client ->req_len) return(16); | |||||
237 | VERIFY_WINDOW(pWin, stuff->window, client, DixGetAttrAccess)do { int err; err = dixLookupResourceByType((void **) &pWin , stuff->window, ((RESTYPE)1|((RESTYPE)1<<30)), client , (1<<4)); if (err != 0) { client->errorValue = stuff ->window; return err; } } while (0); | |||||
238 | ||||||
239 | pScreen = pWin->drawable.pScreen; | |||||
240 | ||||||
241 | if (!pWin->viewable) | |||||
242 | return BadMatch8; | |||||
243 | ||||||
244 | LEGAL_NEW_RESOURCE(stuff->pixmap, client)if (!LegalNewID(stuff->pixmap,client)) { client->errorValue = stuff->pixmap; return 14; }; | |||||
245 | ||||||
246 | cw = GetCompWindow(pWin)((CompWindowPtr) dixLookupPrivate(&(pWin)->devPrivates , (&CompWindowPrivateKeyRec))); | |||||
247 | if (!cw) | |||||
248 | return BadMatch8; | |||||
249 | ||||||
250 | pPixmap = (*pScreen->GetWindowPixmap) (pWin); | |||||
251 | if (!pPixmap) | |||||
252 | return BadMatch8; | |||||
253 | ||||||
254 | /* security creation/labeling check */ | |||||
255 | rc = XaceHook(XACE_RESOURCE_ACCESS2, client, stuff->pixmap, RT_PIXMAP((RESTYPE)2|((RESTYPE)1<<30)), | |||||
256 | pPixmap, RT_WINDOW((RESTYPE)1|((RESTYPE)1<<30)), pWin, DixCreateAccess(1<<3)); | |||||
257 | if (rc != Success0) | |||||
258 | return rc; | |||||
259 | ||||||
260 | ++pPixmap->refcnt; | |||||
261 | ||||||
262 | if (!AddResourceDarwin_X_AddResource(stuff->pixmap, RT_PIXMAP((RESTYPE)2|((RESTYPE)1<<30)), (void *) pPixmap)) | |||||
263 | return BadAlloc11; | |||||
264 | ||||||
265 | if (pScreen->NameWindowPixmap) { | |||||
266 | rc = pScreen->NameWindowPixmap(pWin, pPixmap, stuff->pixmap); | |||||
267 | if (rc != Success0) { | |||||
268 | FreeResource(stuff->pixmap, RT_NONE((RESTYPE)0)); | |||||
269 | return rc; | |||||
270 | } | |||||
271 | } | |||||
272 | ||||||
273 | return Success0; | |||||
274 | } | |||||
275 | ||||||
276 | static int | |||||
277 | ProcCompositeGetOverlayWindow(ClientPtr client) | |||||
278 | { | |||||
279 | REQUEST(xCompositeGetOverlayWindowReq)xCompositeGetOverlayWindowReq *stuff = (xCompositeGetOverlayWindowReq *)client->requestBuffer; | |||||
280 | xCompositeGetOverlayWindowReply rep; | |||||
281 | WindowPtr pWin; | |||||
282 | ScreenPtr pScreen; | |||||
283 | CompScreenPtr cs; | |||||
284 | CompOverlayClientPtr pOc; | |||||
285 | int rc; | |||||
286 | ||||||
287 | REQUEST_SIZE_MATCH(xCompositeGetOverlayWindowReq)if ((sizeof(xCompositeGetOverlayWindowReq) >> 2) != client ->req_len) return(16); | |||||
288 | VERIFY_WINDOW(pWin, stuff->window, client, DixGetAttrAccess)do { int err; err = dixLookupResourceByType((void **) &pWin , stuff->window, ((RESTYPE)1|((RESTYPE)1<<30)), client , (1<<4)); if (err != 0) { client->errorValue = stuff ->window; return err; } } while (0); | |||||
289 | pScreen = pWin->drawable.pScreen; | |||||
290 | ||||||
291 | /* | |||||
292 | * Create an OverlayClient structure to mark this client's | |||||
293 | * interest in the overlay window | |||||
294 | */ | |||||
295 | pOc = compCreateOverlayClient(pScreen, client); | |||||
296 | if (pOc == NULL((void*)0)) | |||||
297 | return BadAlloc11; | |||||
298 | ||||||
299 | /* | |||||
300 | * Make sure the overlay window exists | |||||
301 | */ | |||||
302 | cs = GetCompScreen(pScreen)((CompScreenPtr) dixLookupPrivate(&(pScreen)->devPrivates , (&CompScreenPrivateKeyRec))); | |||||
303 | if (cs->pOverlayWin == NULL((void*)0)) | |||||
304 | if (!compCreateOverlayWindow(pScreen)) { | |||||
305 | FreeResource(pOc->resource, RT_NONE((RESTYPE)0)); | |||||
306 | return BadAlloc11; | |||||
307 | } | |||||
308 | ||||||
309 | rc = XaceHook(XACE_RESOURCE_ACCESS2, client, cs->pOverlayWin->drawable.id, | |||||
310 | RT_WINDOW((RESTYPE)1|((RESTYPE)1<<30)), cs->pOverlayWin, RT_NONE((RESTYPE)0), NULL((void*)0), DixGetAttrAccess(1<<4)); | |||||
311 | if (rc != Success0) { | |||||
312 | FreeResource(pOc->resource, RT_NONE((RESTYPE)0)); | |||||
313 | return rc; | |||||
314 | } | |||||
315 | ||||||
316 | rep = (xCompositeGetOverlayWindowReply) { | |||||
317 | .type = X_Reply1, | |||||
318 | .sequenceNumber = client->sequence, | |||||
319 | .length = 0, | |||||
320 | .overlayWin = cs->pOverlayWin->drawable.id | |||||
321 | }; | |||||
322 | ||||||
323 | if (client->swapped) { | |||||
324 | swaps(&rep.sequenceNumber)do { if (sizeof(*(&rep.sequenceNumber)) != 2) wrong_size( ); if (__builtin_constant_p((uintptr_t)(&rep.sequenceNumber ) & 1) && ((uintptr_t)(&rep.sequenceNumber) & 1) == 0) *(&rep.sequenceNumber) = lswaps(*(&rep.sequenceNumber )); else swap_uint16((uint16_t *)(&rep.sequenceNumber)); } while (0); | |||||
325 | swapl(&rep.length)do { if (sizeof(*(&rep.length)) != 4) wrong_size(); if (__builtin_constant_p ((uintptr_t)(&rep.length) & 3) && ((uintptr_t )(&rep.length) & 3) == 0) *(&rep.length) = lswapl (*(&rep.length)); else swap_uint32((uint32_t *)(&rep. length)); } while (0); | |||||
326 | swapl(&rep.overlayWin)do { if (sizeof(*(&rep.overlayWin)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&rep.overlayWin) & 3) && ((uintptr_t)(&rep.overlayWin) & 3) == 0 ) *(&rep.overlayWin) = lswapl(*(&rep.overlayWin)); else swap_uint32((uint32_t *)(&rep.overlayWin)); } while (0); | |||||
327 | } | |||||
328 | WriteToClient(client, sz_xCompositeGetOverlayWindowReplysizeof(xCompositeGetOverlayWindowReply), &rep); | |||||
329 | ||||||
330 | return Success0; | |||||
331 | } | |||||
332 | ||||||
333 | static int | |||||
334 | ProcCompositeReleaseOverlayWindow(ClientPtr client) | |||||
335 | { | |||||
336 | REQUEST(xCompositeReleaseOverlayWindowReq)xCompositeReleaseOverlayWindowReq *stuff = (xCompositeReleaseOverlayWindowReq *)client->requestBuffer; | |||||
337 | WindowPtr pWin; | |||||
338 | CompOverlayClientPtr pOc; | |||||
339 | ||||||
340 | REQUEST_SIZE_MATCH(xCompositeReleaseOverlayWindowReq)if ((sizeof(xCompositeReleaseOverlayWindowReq) >> 2) != client->req_len) return(16); | |||||
341 | VERIFY_WINDOW(pWin, stuff->window, client, DixGetAttrAccess)do { int err; err = dixLookupResourceByType((void **) &pWin , stuff->window, ((RESTYPE)1|((RESTYPE)1<<30)), client , (1<<4)); if (err != 0) { client->errorValue = stuff ->window; return err; } } while (0); | |||||
342 | ||||||
343 | /* | |||||
344 | * Has client queried a reference to the overlay window | |||||
345 | * on this screen? If not, generate an error. | |||||
346 | */ | |||||
347 | pOc = compFindOverlayClient(pWin->drawable.pScreen, client); | |||||
348 | if (pOc == NULL((void*)0)) | |||||
349 | return BadMatch8; | |||||
350 | ||||||
351 | /* The delete function will free the client structure */ | |||||
352 | FreeResource(pOc->resource, RT_NONE((RESTYPE)0)); | |||||
353 | ||||||
354 | return Success0; | |||||
355 | } | |||||
356 | ||||||
357 | static int (*ProcCompositeVector[CompositeNumberRequests(8 + 1)]) (ClientPtr) = { | |||||
358 | ProcCompositeQueryVersion, | |||||
359 | ProcCompositeRedirectWindow, | |||||
360 | ProcCompositeRedirectSubwindows, | |||||
361 | ProcCompositeUnredirectWindow, | |||||
362 | ProcCompositeUnredirectSubwindows, | |||||
363 | ProcCompositeCreateRegionFromBorderClip, | |||||
364 | ProcCompositeNameWindowPixmap, | |||||
365 | ProcCompositeGetOverlayWindow, ProcCompositeReleaseOverlayWindow,}; | |||||
366 | ||||||
367 | static int | |||||
368 | ProcCompositeDispatch(ClientPtr client) | |||||
369 | { | |||||
370 | REQUEST(xReq)xReq *stuff = (xReq *)client->requestBuffer; | |||||
371 | ||||||
372 | if (stuff->data < CompositeNumberRequests(8 + 1)) | |||||
373 | return (*ProcCompositeVector[stuff->data]) (client); | |||||
374 | else | |||||
375 | return BadRequest1; | |||||
376 | } | |||||
377 | ||||||
378 | static int | |||||
379 | SProcCompositeQueryVersion(ClientPtr client) | |||||
380 | { | |||||
381 | REQUEST(xCompositeQueryVersionReq)xCompositeQueryVersionReq *stuff = (xCompositeQueryVersionReq *)client->requestBuffer; | |||||
382 | ||||||
383 | swaps(&stuff->length)do { if (sizeof(*(&stuff->length)) != 2) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->length) & 1) && ((uintptr_t)(&stuff->length) & 1) == 0) *(&stuff->length) = lswaps(*(&stuff->length )); else swap_uint16((uint16_t *)(&stuff->length)); } while (0); | |||||
384 | REQUEST_SIZE_MATCH(xCompositeQueryVersionReq)if ((sizeof(xCompositeQueryVersionReq) >> 2) != client-> req_len) return(16); | |||||
385 | swapl(&stuff->majorVersion)do { if (sizeof(*(&stuff->majorVersion)) != 4) wrong_size (); if (__builtin_constant_p((uintptr_t)(&stuff->majorVersion ) & 3) && ((uintptr_t)(&stuff->majorVersion ) & 3) == 0) *(&stuff->majorVersion) = lswapl(*(& stuff->majorVersion)); else swap_uint32((uint32_t *)(& stuff->majorVersion)); } while (0); | |||||
386 | swapl(&stuff->minorVersion)do { if (sizeof(*(&stuff->minorVersion)) != 4) wrong_size (); if (__builtin_constant_p((uintptr_t)(&stuff->minorVersion ) & 3) && ((uintptr_t)(&stuff->minorVersion ) & 3) == 0) *(&stuff->minorVersion) = lswapl(*(& stuff->minorVersion)); else swap_uint32((uint32_t *)(& stuff->minorVersion)); } while (0); | |||||
387 | return (*ProcCompositeVector[stuff->compositeReqType]) (client); | |||||
388 | } | |||||
389 | ||||||
390 | static int | |||||
391 | SProcCompositeRedirectWindow(ClientPtr client) | |||||
392 | { | |||||
393 | REQUEST(xCompositeRedirectWindowReq)xCompositeRedirectWindowReq *stuff = (xCompositeRedirectWindowReq *)client->requestBuffer; | |||||
394 | ||||||
395 | swaps(&stuff->length)do { if (sizeof(*(&stuff->length)) != 2) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->length) & 1) && ((uintptr_t)(&stuff->length) & 1) == 0) *(&stuff->length) = lswaps(*(&stuff->length )); else swap_uint16((uint16_t *)(&stuff->length)); } while (0); | |||||
396 | REQUEST_SIZE_MATCH(xCompositeRedirectWindowReq)if ((sizeof(xCompositeRedirectWindowReq) >> 2) != client ->req_len) return(16); | |||||
397 | swapl(&stuff->window)do { if (sizeof(*(&stuff->window)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->window) & 3) && ((uintptr_t)(&stuff->window) & 3) == 0) *(&stuff->window) = lswapl(*(&stuff->window )); else swap_uint32((uint32_t *)(&stuff->window)); } while (0); | |||||
398 | return (*ProcCompositeVector[stuff->compositeReqType]) (client); | |||||
399 | } | |||||
400 | ||||||
401 | static int | |||||
402 | SProcCompositeRedirectSubwindows(ClientPtr client) | |||||
403 | { | |||||
404 | REQUEST(xCompositeRedirectSubwindowsReq)xCompositeRedirectSubwindowsReq *stuff = (xCompositeRedirectSubwindowsReq *)client->requestBuffer; | |||||
405 | ||||||
406 | swaps(&stuff->length)do { if (sizeof(*(&stuff->length)) != 2) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->length) & 1) && ((uintptr_t)(&stuff->length) & 1) == 0) *(&stuff->length) = lswaps(*(&stuff->length )); else swap_uint16((uint16_t *)(&stuff->length)); } while (0); | |||||
407 | REQUEST_SIZE_MATCH(xCompositeRedirectSubwindowsReq)if ((sizeof(xCompositeRedirectSubwindowsReq) >> 2) != client ->req_len) return(16); | |||||
408 | swapl(&stuff->window)do { if (sizeof(*(&stuff->window)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->window) & 3) && ((uintptr_t)(&stuff->window) & 3) == 0) *(&stuff->window) = lswapl(*(&stuff->window )); else swap_uint32((uint32_t *)(&stuff->window)); } while (0); | |||||
409 | return (*ProcCompositeVector[stuff->compositeReqType]) (client); | |||||
410 | } | |||||
411 | ||||||
412 | static int | |||||
413 | SProcCompositeUnredirectWindow(ClientPtr client) | |||||
414 | { | |||||
415 | REQUEST(xCompositeUnredirectWindowReq)xCompositeUnredirectWindowReq *stuff = (xCompositeUnredirectWindowReq *)client->requestBuffer; | |||||
416 | ||||||
417 | swaps(&stuff->length)do { if (sizeof(*(&stuff->length)) != 2) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->length) & 1) && ((uintptr_t)(&stuff->length) & 1) == 0) *(&stuff->length) = lswaps(*(&stuff->length )); else swap_uint16((uint16_t *)(&stuff->length)); } while (0); | |||||
418 | REQUEST_SIZE_MATCH(xCompositeUnredirectWindowReq)if ((sizeof(xCompositeUnredirectWindowReq) >> 2) != client ->req_len) return(16); | |||||
419 | swapl(&stuff->window)do { if (sizeof(*(&stuff->window)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->window) & 3) && ((uintptr_t)(&stuff->window) & 3) == 0) *(&stuff->window) = lswapl(*(&stuff->window )); else swap_uint32((uint32_t *)(&stuff->window)); } while (0); | |||||
420 | return (*ProcCompositeVector[stuff->compositeReqType]) (client); | |||||
421 | } | |||||
422 | ||||||
423 | static int | |||||
424 | SProcCompositeUnredirectSubwindows(ClientPtr client) | |||||
425 | { | |||||
426 | REQUEST(xCompositeUnredirectSubwindowsReq)xCompositeUnredirectSubwindowsReq *stuff = (xCompositeUnredirectSubwindowsReq *)client->requestBuffer; | |||||
427 | ||||||
428 | swaps(&stuff->length)do { if (sizeof(*(&stuff->length)) != 2) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->length) & 1) && ((uintptr_t)(&stuff->length) & 1) == 0) *(&stuff->length) = lswaps(*(&stuff->length )); else swap_uint16((uint16_t *)(&stuff->length)); } while (0); | |||||
429 | REQUEST_SIZE_MATCH(xCompositeUnredirectSubwindowsReq)if ((sizeof(xCompositeUnredirectSubwindowsReq) >> 2) != client->req_len) return(16); | |||||
430 | swapl(&stuff->window)do { if (sizeof(*(&stuff->window)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->window) & 3) && ((uintptr_t)(&stuff->window) & 3) == 0) *(&stuff->window) = lswapl(*(&stuff->window )); else swap_uint32((uint32_t *)(&stuff->window)); } while (0); | |||||
431 | return (*ProcCompositeVector[stuff->compositeReqType]) (client); | |||||
432 | } | |||||
433 | ||||||
434 | static int | |||||
435 | SProcCompositeCreateRegionFromBorderClip(ClientPtr client) | |||||
436 | { | |||||
437 | REQUEST(xCompositeCreateRegionFromBorderClipReq)xCompositeCreateRegionFromBorderClipReq *stuff = (xCompositeCreateRegionFromBorderClipReq *)client->requestBuffer; | |||||
438 | ||||||
439 | swaps(&stuff->length)do { if (sizeof(*(&stuff->length)) != 2) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->length) & 1) && ((uintptr_t)(&stuff->length) & 1) == 0) *(&stuff->length) = lswaps(*(&stuff->length )); else swap_uint16((uint16_t *)(&stuff->length)); } while (0); | |||||
440 | REQUEST_SIZE_MATCH(xCompositeCreateRegionFromBorderClipReq)if ((sizeof(xCompositeCreateRegionFromBorderClipReq) >> 2) != client->req_len) return(16); | |||||
441 | swapl(&stuff->region)do { if (sizeof(*(&stuff->region)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->region) & 3) && ((uintptr_t)(&stuff->region) & 3) == 0) *(&stuff->region) = lswapl(*(&stuff->region )); else swap_uint32((uint32_t *)(&stuff->region)); } while (0); | |||||
442 | swapl(&stuff->window)do { if (sizeof(*(&stuff->window)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->window) & 3) && ((uintptr_t)(&stuff->window) & 3) == 0) *(&stuff->window) = lswapl(*(&stuff->window )); else swap_uint32((uint32_t *)(&stuff->window)); } while (0); | |||||
443 | return (*ProcCompositeVector[stuff->compositeReqType]) (client); | |||||
444 | } | |||||
445 | ||||||
446 | static int | |||||
447 | SProcCompositeNameWindowPixmap(ClientPtr client) | |||||
448 | { | |||||
449 | REQUEST(xCompositeNameWindowPixmapReq)xCompositeNameWindowPixmapReq *stuff = (xCompositeNameWindowPixmapReq *)client->requestBuffer; | |||||
450 | ||||||
451 | swaps(&stuff->length)do { if (sizeof(*(&stuff->length)) != 2) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->length) & 1) && ((uintptr_t)(&stuff->length) & 1) == 0) *(&stuff->length) = lswaps(*(&stuff->length )); else swap_uint16((uint16_t *)(&stuff->length)); } while (0); | |||||
452 | REQUEST_SIZE_MATCH(xCompositeNameWindowPixmapReq)if ((sizeof(xCompositeNameWindowPixmapReq) >> 2) != client ->req_len) return(16); | |||||
453 | swapl(&stuff->window)do { if (sizeof(*(&stuff->window)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->window) & 3) && ((uintptr_t)(&stuff->window) & 3) == 0) *(&stuff->window) = lswapl(*(&stuff->window )); else swap_uint32((uint32_t *)(&stuff->window)); } while (0); | |||||
454 | swapl(&stuff->pixmap)do { if (sizeof(*(&stuff->pixmap)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->pixmap) & 3) && ((uintptr_t)(&stuff->pixmap) & 3) == 0) *(&stuff->pixmap) = lswapl(*(&stuff->pixmap )); else swap_uint32((uint32_t *)(&stuff->pixmap)); } while (0); | |||||
455 | return (*ProcCompositeVector[stuff->compositeReqType]) (client); | |||||
456 | } | |||||
457 | ||||||
458 | static int | |||||
459 | SProcCompositeGetOverlayWindow(ClientPtr client) | |||||
460 | { | |||||
461 | REQUEST(xCompositeGetOverlayWindowReq)xCompositeGetOverlayWindowReq *stuff = (xCompositeGetOverlayWindowReq *)client->requestBuffer; | |||||
462 | ||||||
463 | swaps(&stuff->length)do { if (sizeof(*(&stuff->length)) != 2) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->length) & 1) && ((uintptr_t)(&stuff->length) & 1) == 0) *(&stuff->length) = lswaps(*(&stuff->length )); else swap_uint16((uint16_t *)(&stuff->length)); } while (0); | |||||
464 | REQUEST_SIZE_MATCH(xCompositeGetOverlayWindowReq)if ((sizeof(xCompositeGetOverlayWindowReq) >> 2) != client ->req_len) return(16); | |||||
465 | swapl(&stuff->window)do { if (sizeof(*(&stuff->window)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->window) & 3) && ((uintptr_t)(&stuff->window) & 3) == 0) *(&stuff->window) = lswapl(*(&stuff->window )); else swap_uint32((uint32_t *)(&stuff->window)); } while (0); | |||||
466 | return (*ProcCompositeVector[stuff->compositeReqType]) (client); | |||||
467 | } | |||||
468 | ||||||
469 | static int | |||||
470 | SProcCompositeReleaseOverlayWindow(ClientPtr client) | |||||
471 | { | |||||
472 | REQUEST(xCompositeReleaseOverlayWindowReq)xCompositeReleaseOverlayWindowReq *stuff = (xCompositeReleaseOverlayWindowReq *)client->requestBuffer; | |||||
473 | ||||||
474 | swaps(&stuff->length)do { if (sizeof(*(&stuff->length)) != 2) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->length) & 1) && ((uintptr_t)(&stuff->length) & 1) == 0) *(&stuff->length) = lswaps(*(&stuff->length )); else swap_uint16((uint16_t *)(&stuff->length)); } while (0); | |||||
475 | REQUEST_SIZE_MATCH(xCompositeReleaseOverlayWindowReq)if ((sizeof(xCompositeReleaseOverlayWindowReq) >> 2) != client->req_len) return(16); | |||||
476 | swapl(&stuff->window)do { if (sizeof(*(&stuff->window)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&stuff->window) & 3) && ((uintptr_t)(&stuff->window) & 3) == 0) *(&stuff->window) = lswapl(*(&stuff->window )); else swap_uint32((uint32_t *)(&stuff->window)); } while (0); | |||||
477 | return (*ProcCompositeVector[stuff->compositeReqType]) (client); | |||||
478 | } | |||||
479 | ||||||
480 | static int (*SProcCompositeVector[CompositeNumberRequests(8 + 1)]) (ClientPtr) = { | |||||
481 | SProcCompositeQueryVersion, | |||||
482 | SProcCompositeRedirectWindow, | |||||
483 | SProcCompositeRedirectSubwindows, | |||||
484 | SProcCompositeUnredirectWindow, | |||||
485 | SProcCompositeUnredirectSubwindows, | |||||
486 | SProcCompositeCreateRegionFromBorderClip, | |||||
487 | SProcCompositeNameWindowPixmap, | |||||
488 | SProcCompositeGetOverlayWindow, SProcCompositeReleaseOverlayWindow,}; | |||||
489 | ||||||
490 | static int | |||||
491 | SProcCompositeDispatch(ClientPtr client) | |||||
492 | { | |||||
493 | REQUEST(xReq)xReq *stuff = (xReq *)client->requestBuffer; | |||||
494 | ||||||
495 | if (stuff->data < CompositeNumberRequests(8 + 1)) | |||||
496 | return (*SProcCompositeVector[stuff->data]) (client); | |||||
497 | else | |||||
498 | return BadRequest1; | |||||
499 | } | |||||
500 | ||||||
501 | /** @see GetDefaultBytes */ | |||||
502 | static void | |||||
503 | GetCompositeClientWindowBytes(void *value, XID id, ResourceSizePtr size) | |||||
504 | { | |||||
505 | WindowPtr window = value; | |||||
506 | ||||||
507 | /* Currently only pixmap bytes are reported to clients. */ | |||||
508 | size->resourceSize = 0; | |||||
509 | ||||||
510 | /* Calculate pixmap reference sizes. */ | |||||
511 | size->pixmapRefSize = 0; | |||||
512 | if (window->redirectDraw != RedirectDrawNone0) | |||||
513 | { | |||||
514 | SizeType pixmapSizeFunc = GetResourceTypeSizeFunc(RT_PIXMAP((RESTYPE)2|((RESTYPE)1<<30))); | |||||
515 | ResourceSizeRec pixmapSize = { 0, 0 }; | |||||
516 | ScreenPtr screen = window->drawable.pScreen; | |||||
517 | PixmapPtr pixmap = screen->GetWindowPixmap(window); | |||||
518 | pixmapSizeFunc(pixmap, pixmap->drawable.id, &pixmapSize); | |||||
519 | size->pixmapRefSize += pixmapSize.pixmapRefSize; | |||||
520 | } | |||||
521 | } | |||||
522 | ||||||
523 | void | |||||
524 | CompositeExtensionInit(void) | |||||
525 | { | |||||
526 | ExtensionEntry *extEntry; | |||||
527 | int s; | |||||
528 | ||||||
529 | /* Assume initialization is going to fail */ | |||||
530 | noCompositeExtension = TRUE1; | |||||
531 | ||||||
532 | for (s = 0; s < screenInfo.numScreens; s++) { | |||||
533 | ScreenPtr pScreen = screenInfo.screens[s]; | |||||
534 | VisualPtr vis; | |||||
535 | ||||||
536 | /* Composite on 8bpp pseudocolor root windows appears to fail, so | |||||
537 | * just disable it on anything pseudocolor for safety. | |||||
538 | */ | |||||
539 | for (vis = pScreen->visuals; vis->vid != pScreen->rootVisual; vis++); | |||||
540 | if ((vis->class | DynamicClass1) == PseudoColor3) | |||||
541 | return; | |||||
542 | ||||||
543 | /* Ensure that Render is initialized, which is required for automatic | |||||
544 | * compositing. | |||||
545 | */ | |||||
546 | if (GetPictureScreenIfSet(pScreen)(dixPrivateKeyRegistered((&PictureScreenPrivateKeyRec)) ? ((PictureScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates , (&PictureScreenPrivateKeyRec))) : ((void*)0)) == NULL((void*)0)) | |||||
547 | return; | |||||
548 | } | |||||
549 | ||||||
550 | CompositeClientWindowType = CreateNewResourceType | |||||
551 | (FreeCompositeClientWindow, "CompositeClientWindow"); | |||||
552 | if (!CompositeClientWindowType) | |||||
553 | return; | |||||
554 | ||||||
555 | SetResourceTypeSizeFunc(CompositeClientWindowType, | |||||
556 | GetCompositeClientWindowBytes); | |||||
557 | ||||||
558 | CompositeClientSubwindowsType = CreateNewResourceType | |||||
559 | (FreeCompositeClientSubwindows, "CompositeClientSubwindows"); | |||||
560 | if (!CompositeClientSubwindowsType) | |||||
561 | return; | |||||
562 | ||||||
563 | CompositeClientOverlayType = CreateNewResourceType | |||||
564 | (FreeCompositeClientOverlay, "CompositeClientOverlay"); | |||||
565 | if (!CompositeClientOverlayType) | |||||
566 | return; | |||||
567 | ||||||
568 | if (!dixRegisterPrivateKey(&CompositeClientPrivateKeyRec, PRIVATE_CLIENT, | |||||
569 | sizeof(CompositeClientRec))) | |||||
570 | return; | |||||
571 | ||||||
572 | for (s = 0; s < screenInfo.numScreens; s++) | |||||
573 | if (!compScreenInit(screenInfo.screens[s])) | |||||
574 | return; | |||||
575 | ||||||
576 | extEntry = AddExtension(COMPOSITE_NAME"Composite", 0, 0, | |||||
577 | ProcCompositeDispatch, SProcCompositeDispatch, | |||||
578 | NULL((void*)0), StandardMinorOpcode); | |||||
579 | if (!extEntry) | |||||
580 | return; | |||||
581 | CompositeReqCode = (CARD8) extEntry->base; | |||||
582 | ||||||
583 | /* Initialization succeeded */ | |||||
584 | noCompositeExtension = FALSE0; | |||||
585 | } | |||||
586 | ||||||
587 | #ifdef PANORAMIX1 | |||||
588 | #include "panoramiXsrv.h" | |||||
589 | ||||||
590 | int (*PanoramiXSaveCompositeVector[CompositeNumberRequests(8 + 1)]) (ClientPtr); | |||||
591 | ||||||
592 | static int | |||||
593 | PanoramiXCompositeRedirectWindow(ClientPtr client) | |||||
594 | { | |||||
595 | PanoramiXRes *win; | |||||
596 | int rc = 0, j; | |||||
597 | ||||||
598 | REQUEST(xCompositeRedirectWindowReq)xCompositeRedirectWindowReq *stuff = (xCompositeRedirectWindowReq *)client->requestBuffer; | |||||
599 | ||||||
600 | REQUEST_SIZE_MATCH(xCompositeRedirectWindowReq)if ((sizeof(xCompositeRedirectWindowReq) >> 2) != client ->req_len) return(16); | |||||
601 | ||||||
602 | if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW, | |||||
603 | client, DixUnknownAccess0))) { | |||||
604 | client->errorValue = stuff->window; | |||||
605 | return rc; | |||||
606 | } | |||||
607 | ||||||
608 | FOR_NSCREENS_FORWARD(j)for(j = 0; j < PanoramiXNumScreens; j++) { | |||||
609 | stuff->window = win->info[j].id; | |||||
610 | rc = (*PanoramiXSaveCompositeVector[stuff->compositeReqType]) (client); | |||||
611 | if (rc != Success0) | |||||
612 | break; | |||||
613 | } | |||||
614 | ||||||
615 | return rc; | |||||
616 | } | |||||
617 | ||||||
618 | static int | |||||
619 | PanoramiXCompositeRedirectSubwindows(ClientPtr client) | |||||
620 | { | |||||
621 | PanoramiXRes *win; | |||||
622 | int rc = 0, j; | |||||
623 | ||||||
624 | REQUEST(xCompositeRedirectSubwindowsReq)xCompositeRedirectSubwindowsReq *stuff = (xCompositeRedirectSubwindowsReq *)client->requestBuffer; | |||||
625 | ||||||
626 | REQUEST_SIZE_MATCH(xCompositeRedirectSubwindowsReq)if ((sizeof(xCompositeRedirectSubwindowsReq) >> 2) != client ->req_len) return(16); | |||||
627 | ||||||
628 | if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW, | |||||
629 | client, DixUnknownAccess0))) { | |||||
630 | client->errorValue = stuff->window; | |||||
631 | return rc; | |||||
632 | } | |||||
633 | ||||||
634 | FOR_NSCREENS_FORWARD(j)for(j = 0; j < PanoramiXNumScreens; j++) { | |||||
635 | stuff->window = win->info[j].id; | |||||
636 | rc = (*PanoramiXSaveCompositeVector[stuff->compositeReqType]) (client); | |||||
637 | if (rc != Success0) | |||||
638 | break; | |||||
639 | } | |||||
640 | ||||||
641 | return rc; | |||||
642 | } | |||||
643 | ||||||
644 | static int | |||||
645 | PanoramiXCompositeUnredirectWindow(ClientPtr client) | |||||
646 | { | |||||
647 | PanoramiXRes *win; | |||||
648 | int rc = 0, j; | |||||
649 | ||||||
650 | REQUEST(xCompositeUnredirectWindowReq)xCompositeUnredirectWindowReq *stuff = (xCompositeUnredirectWindowReq *)client->requestBuffer; | |||||
651 | ||||||
652 | REQUEST_SIZE_MATCH(xCompositeUnredirectWindowReq)if ((sizeof(xCompositeUnredirectWindowReq) >> 2) != client ->req_len) return(16); | |||||
653 | ||||||
654 | if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW, | |||||
655 | client, DixUnknownAccess0))) { | |||||
656 | client->errorValue = stuff->window; | |||||
657 | return rc; | |||||
658 | } | |||||
659 | ||||||
660 | FOR_NSCREENS_FORWARD(j)for(j = 0; j < PanoramiXNumScreens; j++) { | |||||
661 | stuff->window = win->info[j].id; | |||||
662 | rc = (*PanoramiXSaveCompositeVector[stuff->compositeReqType]) (client); | |||||
663 | if (rc != Success0) | |||||
664 | break; | |||||
665 | } | |||||
666 | ||||||
667 | return rc; | |||||
668 | } | |||||
669 | ||||||
670 | static int | |||||
671 | PanoramiXCompositeUnredirectSubwindows(ClientPtr client) | |||||
672 | { | |||||
673 | PanoramiXRes *win; | |||||
674 | int rc = 0, j; | |||||
675 | ||||||
676 | REQUEST(xCompositeUnredirectSubwindowsReq)xCompositeUnredirectSubwindowsReq *stuff = (xCompositeUnredirectSubwindowsReq *)client->requestBuffer; | |||||
677 | ||||||
678 | REQUEST_SIZE_MATCH(xCompositeUnredirectSubwindowsReq)if ((sizeof(xCompositeUnredirectSubwindowsReq) >> 2) != client->req_len) return(16); | |||||
679 | ||||||
680 | if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW, | |||||
681 | client, DixUnknownAccess0))) { | |||||
682 | client->errorValue = stuff->window; | |||||
683 | return rc; | |||||
684 | } | |||||
685 | ||||||
686 | FOR_NSCREENS_FORWARD(j)for(j = 0; j < PanoramiXNumScreens; j++) { | |||||
687 | stuff->window = win->info[j].id; | |||||
688 | rc = (*PanoramiXSaveCompositeVector[stuff->compositeReqType]) (client); | |||||
689 | if (rc != Success0) | |||||
690 | break; | |||||
691 | } | |||||
692 | ||||||
693 | return rc; | |||||
694 | } | |||||
695 | ||||||
696 | static int | |||||
697 | PanoramiXCompositeNameWindowPixmap(ClientPtr client) | |||||
698 | { | |||||
699 | WindowPtr pWin; | |||||
700 | CompWindowPtr cw; | |||||
701 | PixmapPtr pPixmap; | |||||
702 | int rc; | |||||
703 | PanoramiXRes *win, *newPix; | |||||
704 | int i; | |||||
705 | ||||||
706 | REQUEST(xCompositeNameWindowPixmapReq)xCompositeNameWindowPixmapReq *stuff = (xCompositeNameWindowPixmapReq *)client->requestBuffer; | |||||
707 | ||||||
708 | REQUEST_SIZE_MATCH(xCompositeNameWindowPixmapReq)if ((sizeof(xCompositeNameWindowPixmapReq) >> 2) != client ->req_len) return(16); | |||||
709 | ||||||
710 | if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW, | |||||
| ||||||
711 | client, DixUnknownAccess0))) { | |||||
712 | client->errorValue = stuff->window; | |||||
713 | return rc; | |||||
714 | } | |||||
715 | ||||||
716 | LEGAL_NEW_RESOURCE(stuff->pixmap, client)if (!LegalNewID(stuff->pixmap,client)) { client->errorValue = stuff->pixmap; return 14; }; | |||||
717 | ||||||
718 | if (!(newPix = malloc(sizeof(PanoramiXRes)))) | |||||
719 | return BadAlloc11; | |||||
720 | ||||||
721 | newPix->type = XRT_PIXMAP; | |||||
722 | newPix->u.pix.shared = FALSE0; | |||||
723 | panoramix_setup_ids(newPix, client, stuff->pixmap); | |||||
724 | ||||||
725 | FOR_NSCREENS(i)for(i = 0; i < PanoramiXNumScreens; i++) { | |||||
726 | rc = dixLookupResourceByType((void **) &pWin, win->info[i].id, | |||||
727 | RT_WINDOW((RESTYPE)1|((RESTYPE)1<<30)), client, DixGetAttrAccess(1<<4)); | |||||
728 | if (rc != Success0) { | |||||
729 | client->errorValue = stuff->window; | |||||
730 | free(newPix); | |||||
731 | return rc; | |||||
732 | } | |||||
733 | ||||||
734 | if (!pWin->viewable) { | |||||
735 | free(newPix); | |||||
736 | return BadMatch8; | |||||
737 | } | |||||
738 | ||||||
739 | cw = GetCompWindow(pWin)((CompWindowPtr) dixLookupPrivate(&(pWin)->devPrivates , (&CompWindowPrivateKeyRec))); | |||||
740 | if (!cw) { | |||||
741 | free(newPix); | |||||
742 | return BadMatch8; | |||||
743 | } | |||||
744 | ||||||
745 | pPixmap = (*pWin->drawable.pScreen->GetWindowPixmap) (pWin); | |||||
746 | if (!pPixmap) { | |||||
747 | free(newPix); | |||||
748 | return BadMatch8; | |||||
749 | } | |||||
750 | ||||||
751 | if (!AddResourceDarwin_X_AddResource(newPix->info[i].id, RT_PIXMAP((RESTYPE)2|((RESTYPE)1<<30)), (void *) pPixmap)) | |||||
752 | return BadAlloc11; | |||||
| ||||||
753 | ||||||
754 | ++pPixmap->refcnt; | |||||
755 | } | |||||
756 | ||||||
757 | if (!AddResourceDarwin_X_AddResource(stuff->pixmap, XRT_PIXMAP, (void *) newPix)) | |||||
758 | return BadAlloc11; | |||||
759 | ||||||
760 | return Success0; | |||||
761 | } | |||||
762 | ||||||
763 | static int | |||||
764 | PanoramiXCompositeGetOverlayWindow(ClientPtr client) | |||||
765 | { | |||||
766 | REQUEST(xCompositeGetOverlayWindowReq)xCompositeGetOverlayWindowReq *stuff = (xCompositeGetOverlayWindowReq *)client->requestBuffer; | |||||
767 | xCompositeGetOverlayWindowReply rep; | |||||
768 | WindowPtr pWin; | |||||
769 | ScreenPtr pScreen; | |||||
770 | CompScreenPtr cs; | |||||
771 | CompOverlayClientPtr pOc; | |||||
772 | int rc; | |||||
773 | PanoramiXRes *win, *overlayWin = NULL((void*)0); | |||||
774 | int i; | |||||
775 | ||||||
776 | REQUEST_SIZE_MATCH(xCompositeGetOverlayWindowReq)if ((sizeof(xCompositeGetOverlayWindowReq) >> 2) != client ->req_len) return(16); | |||||
777 | ||||||
778 | if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW, | |||||
779 | client, DixUnknownAccess0))) { | |||||
780 | client->errorValue = stuff->window; | |||||
781 | return rc; | |||||
782 | } | |||||
783 | ||||||
784 | cs = GetCompScreen(screenInfo.screens[0])((CompScreenPtr) dixLookupPrivate(&(screenInfo.screens[0] )->devPrivates, (&CompScreenPrivateKeyRec))); | |||||
785 | if (!cs->pOverlayWin) { | |||||
786 | if (!(overlayWin = malloc(sizeof(PanoramiXRes)))) | |||||
787 | return BadAlloc11; | |||||
788 | ||||||
789 | overlayWin->type = XRT_WINDOW; | |||||
790 | overlayWin->u.win.root = FALSE0; | |||||
791 | } | |||||
792 | ||||||
793 | FOR_NSCREENS_BACKWARD(i)for(i = PanoramiXNumScreens - 1; i >= 0; i--) { | |||||
794 | rc = dixLookupResourceByType((void **) &pWin, win->info[i].id, | |||||
795 | RT_WINDOW((RESTYPE)1|((RESTYPE)1<<30)), client, DixGetAttrAccess(1<<4)); | |||||
796 | if (rc != Success0) { | |||||
797 | client->errorValue = stuff->window; | |||||
798 | free(overlayWin); | |||||
799 | return rc; | |||||
800 | } | |||||
801 | pScreen = pWin->drawable.pScreen; | |||||
802 | ||||||
803 | /* | |||||
804 | * Create an OverlayClient structure to mark this client's | |||||
805 | * interest in the overlay window | |||||
806 | */ | |||||
807 | pOc = compCreateOverlayClient(pScreen, client); | |||||
808 | if (pOc == NULL((void*)0)) { | |||||
809 | free(overlayWin); | |||||
810 | return BadAlloc11; | |||||
811 | } | |||||
812 | ||||||
813 | /* | |||||
814 | * Make sure the overlay window exists | |||||
815 | */ | |||||
816 | cs = GetCompScreen(pScreen)((CompScreenPtr) dixLookupPrivate(&(pScreen)->devPrivates , (&CompScreenPrivateKeyRec))); | |||||
817 | if (cs->pOverlayWin == NULL((void*)0)) | |||||
818 | if (!compCreateOverlayWindow(pScreen)) { | |||||
819 | FreeResource(pOc->resource, RT_NONE((RESTYPE)0)); | |||||
820 | free(overlayWin); | |||||
821 | return BadAlloc11; | |||||
822 | } | |||||
823 | ||||||
824 | rc = XaceHook(XACE_RESOURCE_ACCESS2, client, | |||||
825 | cs->pOverlayWin->drawable.id, | |||||
826 | RT_WINDOW((RESTYPE)1|((RESTYPE)1<<30)), cs->pOverlayWin, RT_NONE((RESTYPE)0), NULL((void*)0), | |||||
827 | DixGetAttrAccess(1<<4)); | |||||
828 | if (rc != Success0) { | |||||
829 | FreeResource(pOc->resource, RT_NONE((RESTYPE)0)); | |||||
830 | free(overlayWin); | |||||
831 | return rc; | |||||
832 | } | |||||
833 | } | |||||
834 | ||||||
835 | if (overlayWin) { | |||||
836 | FOR_NSCREENS(i)for(i = 0; i < PanoramiXNumScreens; i++) { | |||||
837 | cs = GetCompScreen(screenInfo.screens[i])((CompScreenPtr) dixLookupPrivate(&(screenInfo.screens[i] )->devPrivates, (&CompScreenPrivateKeyRec))); | |||||
838 | overlayWin->info[i].id = cs->pOverlayWin->drawable.id; | |||||
839 | } | |||||
840 | ||||||
841 | AddResourceDarwin_X_AddResource(overlayWin->info[0].id, XRT_WINDOW, overlayWin); | |||||
842 | } | |||||
843 | ||||||
844 | cs = GetCompScreen(screenInfo.screens[0])((CompScreenPtr) dixLookupPrivate(&(screenInfo.screens[0] )->devPrivates, (&CompScreenPrivateKeyRec))); | |||||
845 | ||||||
846 | rep = (xCompositeGetOverlayWindowReply) { | |||||
847 | .type = X_Reply1, | |||||
848 | .sequenceNumber = client->sequence, | |||||
849 | .length = 0, | |||||
850 | .overlayWin = cs->pOverlayWin->drawable.id | |||||
851 | }; | |||||
852 | ||||||
853 | if (client->swapped) { | |||||
854 | swaps(&rep.sequenceNumber)do { if (sizeof(*(&rep.sequenceNumber)) != 2) wrong_size( ); if (__builtin_constant_p((uintptr_t)(&rep.sequenceNumber ) & 1) && ((uintptr_t)(&rep.sequenceNumber) & 1) == 0) *(&rep.sequenceNumber) = lswaps(*(&rep.sequenceNumber )); else swap_uint16((uint16_t *)(&rep.sequenceNumber)); } while (0); | |||||
855 | swapl(&rep.length)do { if (sizeof(*(&rep.length)) != 4) wrong_size(); if (__builtin_constant_p ((uintptr_t)(&rep.length) & 3) && ((uintptr_t )(&rep.length) & 3) == 0) *(&rep.length) = lswapl (*(&rep.length)); else swap_uint32((uint32_t *)(&rep. length)); } while (0); | |||||
856 | swapl(&rep.overlayWin)do { if (sizeof(*(&rep.overlayWin)) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(&rep.overlayWin) & 3) && ((uintptr_t)(&rep.overlayWin) & 3) == 0 ) *(&rep.overlayWin) = lswapl(*(&rep.overlayWin)); else swap_uint32((uint32_t *)(&rep.overlayWin)); } while (0); | |||||
857 | } | |||||
858 | WriteToClient(client, sz_xCompositeGetOverlayWindowReplysizeof(xCompositeGetOverlayWindowReply), &rep); | |||||
859 | ||||||
860 | return Success0; | |||||
861 | } | |||||
862 | ||||||
863 | static int | |||||
864 | PanoramiXCompositeReleaseOverlayWindow(ClientPtr client) | |||||
865 | { | |||||
866 | REQUEST(xCompositeReleaseOverlayWindowReq)xCompositeReleaseOverlayWindowReq *stuff = (xCompositeReleaseOverlayWindowReq *)client->requestBuffer; | |||||
867 | WindowPtr pWin; | |||||
868 | CompOverlayClientPtr pOc; | |||||
869 | PanoramiXRes *win; | |||||
870 | int i, rc; | |||||
871 | ||||||
872 | REQUEST_SIZE_MATCH(xCompositeReleaseOverlayWindowReq)if ((sizeof(xCompositeReleaseOverlayWindowReq) >> 2) != client->req_len) return(16); | |||||
873 | ||||||
874 | if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW, | |||||
875 | client, DixUnknownAccess0))) { | |||||
876 | client->errorValue = stuff->window; | |||||
877 | return rc; | |||||
878 | } | |||||
879 | ||||||
880 | FOR_NSCREENS_BACKWARD(i)for(i = PanoramiXNumScreens - 1; i >= 0; i--) { | |||||
881 | if ((rc = dixLookupResourceByType((void **) &pWin, win->info[i].id, | |||||
882 | XRT_WINDOW, client, | |||||
883 | DixUnknownAccess0))) { | |||||
884 | client->errorValue = stuff->window; | |||||
885 | return rc; | |||||
886 | } | |||||
887 | ||||||
888 | /* | |||||
889 | * Has client queried a reference to the overlay window | |||||
890 | * on this screen? If not, generate an error. | |||||
891 | */ | |||||
892 | pOc = compFindOverlayClient(pWin->drawable.pScreen, client); | |||||
893 | if (pOc == NULL((void*)0)) | |||||
894 | return BadMatch8; | |||||
895 | ||||||
896 | /* The delete function will free the client structure */ | |||||
897 | FreeResource(pOc->resource, RT_NONE((RESTYPE)0)); | |||||
898 | } | |||||
899 | ||||||
900 | return Success0; | |||||
901 | } | |||||
902 | ||||||
903 | void | |||||
904 | PanoramiXCompositeInit(void) | |||||
905 | { | |||||
906 | int i; | |||||
907 | ||||||
908 | for (i = 0; i < CompositeNumberRequests(8 + 1); i++) | |||||
909 | PanoramiXSaveCompositeVector[i] = ProcCompositeVector[i]; | |||||
910 | /* | |||||
911 | * Stuff in Xinerama aware request processing hooks | |||||
912 | */ | |||||
913 | ProcCompositeVector[X_CompositeRedirectWindow1] = | |||||
914 | PanoramiXCompositeRedirectWindow; | |||||
915 | ProcCompositeVector[X_CompositeRedirectSubwindows2] = | |||||
916 | PanoramiXCompositeRedirectSubwindows; | |||||
917 | ProcCompositeVector[X_CompositeUnredirectWindow3] = | |||||
918 | PanoramiXCompositeUnredirectWindow; | |||||
919 | ProcCompositeVector[X_CompositeUnredirectSubwindows4] = | |||||
920 | PanoramiXCompositeUnredirectSubwindows; | |||||
921 | ProcCompositeVector[X_CompositeNameWindowPixmap6] = | |||||
922 | PanoramiXCompositeNameWindowPixmap; | |||||
923 | ProcCompositeVector[X_CompositeGetOverlayWindow7] = | |||||
924 | PanoramiXCompositeGetOverlayWindow; | |||||
925 | ProcCompositeVector[X_CompositeReleaseOverlayWindow8] = | |||||
926 | PanoramiXCompositeReleaseOverlayWindow; | |||||
927 | } | |||||
928 | ||||||
929 | void | |||||
930 | PanoramiXCompositeReset(void) | |||||
931 | { | |||||
932 | int i; | |||||
933 | ||||||
934 | for (i = 0; i < CompositeNumberRequests(8 + 1); i++) | |||||
935 | ProcCompositeVector[i] = PanoramiXSaveCompositeVector[i]; | |||||
936 | } | |||||
937 | ||||||
938 | #endif |