os: Add CryptoAPI as a choice of SHA1 implementation
[xserver/hramrach.git] / composite / compext.c
blob1d4d8bf973130756b84a0471687334244628c259
1 /*
2 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
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:
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.
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.
23 * Copyright © 2003 Keith Packard
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.
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.
44 #ifdef HAVE_DIX_CONFIG_H
45 #include <dix-config.h>
46 #endif
48 #include "compint.h"
49 #include "xace.h"
50 #include "protocol-versions.h"
52 static CARD8 CompositeReqCode;
53 static DevPrivateKeyRec CompositeClientPrivateKeyRec;
55 #define CompositeClientPrivateKey (&CompositeClientPrivateKeyRec)
56 RESTYPE CompositeClientWindowType;
57 RESTYPE CompositeClientSubwindowsType;
58 RESTYPE CompositeClientOverlayType;
60 typedef struct _CompositeClient {
61 int major_version;
62 int minor_version;
63 } CompositeClientRec, *CompositeClientPtr;
65 #define GetCompositeClient(pClient) ((CompositeClientPtr) \
66 dixLookupPrivate(&(pClient)->devPrivates, CompositeClientPrivateKey))
68 static void
69 CompositeClientCallback(CallbackListPtr *list, pointer closure, pointer data)
71 NewClientInfoRec *clientinfo = (NewClientInfoRec *) data;
72 ClientPtr pClient = clientinfo->client;
73 CompositeClientPtr pCompositeClient = GetCompositeClient(pClient);
75 pCompositeClient->major_version = 0;
76 pCompositeClient->minor_version = 0;
79 static int
80 FreeCompositeClientWindow(pointer value, XID ccwid)
82 WindowPtr pWin = value;
84 compFreeClientWindow(pWin, ccwid);
85 return Success;
88 static int
89 FreeCompositeClientSubwindows(pointer value, XID ccwid)
91 WindowPtr pWin = value;
93 compFreeClientSubwindows(pWin, ccwid);
94 return Success;
97 static int
98 FreeCompositeClientOverlay(pointer value, XID ccwid)
100 CompOverlayClientPtr pOc = (CompOverlayClientPtr) value;
102 compFreeOverlayClient(pOc);
103 return Success;
106 static int
107 ProcCompositeQueryVersion(ClientPtr client)
109 CompositeClientPtr pCompositeClient = GetCompositeClient(client);
110 xCompositeQueryVersionReply rep;
112 REQUEST(xCompositeQueryVersionReq);
114 REQUEST_SIZE_MATCH(xCompositeQueryVersionReq);
115 rep.type = X_Reply;
116 rep.length = 0;
117 rep.sequenceNumber = client->sequence;
118 if (stuff->majorVersion < SERVER_COMPOSITE_MAJOR_VERSION) {
119 rep.majorVersion = stuff->majorVersion;
120 rep.minorVersion = stuff->minorVersion;
122 else {
123 rep.majorVersion = SERVER_COMPOSITE_MAJOR_VERSION;
124 rep.minorVersion = SERVER_COMPOSITE_MINOR_VERSION;
126 pCompositeClient->major_version = rep.majorVersion;
127 pCompositeClient->minor_version = rep.minorVersion;
128 if (client->swapped) {
129 swaps(&rep.sequenceNumber);
130 swapl(&rep.length);
131 swapl(&rep.majorVersion);
132 swapl(&rep.minorVersion);
134 WriteToClient(client, sizeof(xCompositeQueryVersionReply), (char *) &rep);
135 return Success;
138 #define VERIFY_WINDOW(pWindow, wid, client, mode) \
139 do { \
140 int err; \
141 err = dixLookupResourceByType((pointer *) &pWindow, wid, \
142 RT_WINDOW, client, mode); \
143 if (err != Success) { \
144 client->errorValue = wid; \
145 return err; \
147 } while (0)
149 static int
150 ProcCompositeRedirectWindow(ClientPtr client)
152 WindowPtr pWin;
154 REQUEST(xCompositeRedirectWindowReq);
156 REQUEST_SIZE_MATCH(xCompositeRedirectWindowReq);
157 VERIFY_WINDOW(pWin, stuff->window, client,
158 DixSetAttrAccess | DixManageAccess | DixBlendAccess);
160 return compRedirectWindow(client, pWin, stuff->update);
163 static int
164 ProcCompositeRedirectSubwindows(ClientPtr client)
166 WindowPtr pWin;
168 REQUEST(xCompositeRedirectSubwindowsReq);
170 REQUEST_SIZE_MATCH(xCompositeRedirectSubwindowsReq);
171 VERIFY_WINDOW(pWin, stuff->window, client,
172 DixSetAttrAccess | DixManageAccess | DixBlendAccess);
174 return compRedirectSubwindows(client, pWin, stuff->update);
177 static int
178 ProcCompositeUnredirectWindow(ClientPtr client)
180 WindowPtr pWin;
182 REQUEST(xCompositeUnredirectWindowReq);
184 REQUEST_SIZE_MATCH(xCompositeUnredirectWindowReq);
185 VERIFY_WINDOW(pWin, stuff->window, client,
186 DixSetAttrAccess | DixManageAccess | DixBlendAccess);
188 return compUnredirectWindow(client, pWin, stuff->update);
191 static int
192 ProcCompositeUnredirectSubwindows(ClientPtr client)
194 WindowPtr pWin;
196 REQUEST(xCompositeUnredirectSubwindowsReq);
198 REQUEST_SIZE_MATCH(xCompositeUnredirectSubwindowsReq);
199 VERIFY_WINDOW(pWin, stuff->window, client,
200 DixSetAttrAccess | DixManageAccess | DixBlendAccess);
202 return compUnredirectSubwindows(client, pWin, stuff->update);
205 static int
206 ProcCompositeCreateRegionFromBorderClip(ClientPtr client)
208 WindowPtr pWin;
209 CompWindowPtr cw;
210 RegionPtr pBorderClip, pRegion;
212 REQUEST(xCompositeCreateRegionFromBorderClipReq);
214 REQUEST_SIZE_MATCH(xCompositeCreateRegionFromBorderClipReq);
215 VERIFY_WINDOW(pWin, stuff->window, client, DixGetAttrAccess);
216 LEGAL_NEW_RESOURCE(stuff->region, client);
218 cw = GetCompWindow(pWin);
219 if (cw)
220 pBorderClip = &cw->borderClip;
221 else
222 pBorderClip = &pWin->borderClip;
223 pRegion = XFixesRegionCopy(pBorderClip);
224 if (!pRegion)
225 return BadAlloc;
226 RegionTranslate(pRegion, -pWin->drawable.x, -pWin->drawable.y);
228 if (!AddResource(stuff->region, RegionResType, (pointer) pRegion))
229 return BadAlloc;
231 return Success;
234 static int
235 ProcCompositeNameWindowPixmap(ClientPtr client)
237 WindowPtr pWin;
238 CompWindowPtr cw;
239 PixmapPtr pPixmap;
240 int rc;
242 REQUEST(xCompositeNameWindowPixmapReq);
244 REQUEST_SIZE_MATCH(xCompositeNameWindowPixmapReq);
245 VERIFY_WINDOW(pWin, stuff->window, client, DixGetAttrAccess);
247 if (!pWin->viewable)
248 return BadMatch;
250 LEGAL_NEW_RESOURCE(stuff->pixmap, client);
252 cw = GetCompWindow(pWin);
253 if (!cw)
254 return BadMatch;
256 pPixmap = (*pWin->drawable.pScreen->GetWindowPixmap) (pWin);
257 if (!pPixmap)
258 return BadMatch;
260 /* security creation/labeling check */
261 rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pixmap, RT_PIXMAP,
262 pPixmap, RT_WINDOW, pWin, DixCreateAccess);
263 if (rc != Success)
264 return rc;
266 ++pPixmap->refcnt;
268 if (!AddResource(stuff->pixmap, RT_PIXMAP, (pointer) pPixmap))
269 return BadAlloc;
271 return Success;
274 static int
275 ProcCompositeGetOverlayWindow(ClientPtr client)
277 REQUEST(xCompositeGetOverlayWindowReq);
278 xCompositeGetOverlayWindowReply rep;
279 WindowPtr pWin;
280 ScreenPtr pScreen;
281 CompScreenPtr cs;
282 CompOverlayClientPtr pOc;
283 int rc;
285 REQUEST_SIZE_MATCH(xCompositeGetOverlayWindowReq);
286 VERIFY_WINDOW(pWin, stuff->window, client, DixGetAttrAccess);
287 pScreen = pWin->drawable.pScreen;
290 * Create an OverlayClient structure to mark this client's
291 * interest in the overlay window
293 pOc = compCreateOverlayClient(pScreen, client);
294 if (pOc == NULL)
295 return BadAlloc;
298 * Make sure the overlay window exists
300 cs = GetCompScreen(pScreen);
301 if (cs->pOverlayWin == NULL)
302 if (!compCreateOverlayWindow(pScreen)) {
303 FreeResource(pOc->resource, RT_NONE);
304 return BadAlloc;
307 rc = XaceHook(XACE_RESOURCE_ACCESS, client, cs->pOverlayWin->drawable.id,
308 RT_WINDOW, cs->pOverlayWin, RT_NONE, NULL, DixGetAttrAccess);
309 if (rc != Success) {
310 FreeResource(pOc->resource, RT_NONE);
311 return rc;
314 rep.type = X_Reply;
315 rep.sequenceNumber = client->sequence;
316 rep.length = 0;
317 rep.overlayWin = cs->pOverlayWin->drawable.id;
319 if (client->swapped) {
320 swaps(&rep.sequenceNumber);
321 swapl(&rep.length);
322 swapl(&rep.overlayWin);
324 (void) WriteToClient(client, sz_xCompositeGetOverlayWindowReply,
325 (char *) &rep);
327 return Success;
330 static int
331 ProcCompositeReleaseOverlayWindow(ClientPtr client)
333 REQUEST(xCompositeReleaseOverlayWindowReq);
334 WindowPtr pWin;
335 ScreenPtr pScreen;
336 CompOverlayClientPtr pOc;
338 REQUEST_SIZE_MATCH(xCompositeReleaseOverlayWindowReq);
339 VERIFY_WINDOW(pWin, stuff->window, client, DixGetAttrAccess);
340 pScreen = pWin->drawable.pScreen;
343 * Has client queried a reference to the overlay window
344 * on this screen? If not, generate an error.
346 pOc = compFindOverlayClient(pWin->drawable.pScreen, client);
347 if (pOc == NULL)
348 return BadMatch;
350 /* The delete function will free the client structure */
351 FreeResource(pOc->resource, RT_NONE);
353 return Success;
356 static int (*ProcCompositeVector[CompositeNumberRequests]) (ClientPtr) = {
357 ProcCompositeQueryVersion,
358 ProcCompositeRedirectWindow,
359 ProcCompositeRedirectSubwindows,
360 ProcCompositeUnredirectWindow,
361 ProcCompositeUnredirectSubwindows,
362 ProcCompositeCreateRegionFromBorderClip,
363 ProcCompositeNameWindowPixmap,
364 ProcCompositeGetOverlayWindow, ProcCompositeReleaseOverlayWindow,};
366 static int
367 ProcCompositeDispatch(ClientPtr client)
369 REQUEST(xReq);
371 if (stuff->data < CompositeNumberRequests)
372 return (*ProcCompositeVector[stuff->data]) (client);
373 else
374 return BadRequest;
377 static int
378 SProcCompositeQueryVersion(ClientPtr client)
380 REQUEST(xCompositeQueryVersionReq);
382 swaps(&stuff->length);
383 REQUEST_SIZE_MATCH(xCompositeQueryVersionReq);
384 swapl(&stuff->majorVersion);
385 swapl(&stuff->minorVersion);
386 return (*ProcCompositeVector[stuff->compositeReqType]) (client);
389 static int
390 SProcCompositeRedirectWindow(ClientPtr client)
392 REQUEST(xCompositeRedirectWindowReq);
394 swaps(&stuff->length);
395 REQUEST_SIZE_MATCH(xCompositeRedirectWindowReq);
396 swapl(&stuff->window);
397 return (*ProcCompositeVector[stuff->compositeReqType]) (client);
400 static int
401 SProcCompositeRedirectSubwindows(ClientPtr client)
403 REQUEST(xCompositeRedirectSubwindowsReq);
405 swaps(&stuff->length);
406 REQUEST_SIZE_MATCH(xCompositeRedirectSubwindowsReq);
407 swapl(&stuff->window);
408 return (*ProcCompositeVector[stuff->compositeReqType]) (client);
411 static int
412 SProcCompositeUnredirectWindow(ClientPtr client)
414 REQUEST(xCompositeUnredirectWindowReq);
416 swaps(&stuff->length);
417 REQUEST_SIZE_MATCH(xCompositeUnredirectWindowReq);
418 swapl(&stuff->window);
419 return (*ProcCompositeVector[stuff->compositeReqType]) (client);
422 static int
423 SProcCompositeUnredirectSubwindows(ClientPtr client)
425 REQUEST(xCompositeUnredirectSubwindowsReq);
427 swaps(&stuff->length);
428 REQUEST_SIZE_MATCH(xCompositeUnredirectSubwindowsReq);
429 swapl(&stuff->window);
430 return (*ProcCompositeVector[stuff->compositeReqType]) (client);
433 static int
434 SProcCompositeCreateRegionFromBorderClip(ClientPtr client)
436 REQUEST(xCompositeCreateRegionFromBorderClipReq);
438 swaps(&stuff->length);
439 REQUEST_SIZE_MATCH(xCompositeCreateRegionFromBorderClipReq);
440 swapl(&stuff->region);
441 swapl(&stuff->window);
442 return (*ProcCompositeVector[stuff->compositeReqType]) (client);
445 static int
446 SProcCompositeNameWindowPixmap(ClientPtr client)
448 REQUEST(xCompositeNameWindowPixmapReq);
450 swaps(&stuff->length);
451 REQUEST_SIZE_MATCH(xCompositeNameWindowPixmapReq);
452 swapl(&stuff->window);
453 swapl(&stuff->pixmap);
454 return (*ProcCompositeVector[stuff->compositeReqType]) (client);
457 static int
458 SProcCompositeGetOverlayWindow(ClientPtr client)
460 REQUEST(xCompositeGetOverlayWindowReq);
462 swaps(&stuff->length);
463 REQUEST_SIZE_MATCH(xCompositeGetOverlayWindowReq);
464 swapl(&stuff->window);
465 return (*ProcCompositeVector[stuff->compositeReqType]) (client);
468 static int
469 SProcCompositeReleaseOverlayWindow(ClientPtr client)
471 REQUEST(xCompositeReleaseOverlayWindowReq);
473 swaps(&stuff->length);
474 REQUEST_SIZE_MATCH(xCompositeReleaseOverlayWindowReq);
475 swapl(&stuff->window);
476 return (*ProcCompositeVector[stuff->compositeReqType]) (client);
479 static int (*SProcCompositeVector[CompositeNumberRequests]) (ClientPtr) = {
480 SProcCompositeQueryVersion,
481 SProcCompositeRedirectWindow,
482 SProcCompositeRedirectSubwindows,
483 SProcCompositeUnredirectWindow,
484 SProcCompositeUnredirectSubwindows,
485 SProcCompositeCreateRegionFromBorderClip,
486 SProcCompositeNameWindowPixmap,
487 SProcCompositeGetOverlayWindow, SProcCompositeReleaseOverlayWindow,};
489 static int
490 SProcCompositeDispatch(ClientPtr client)
492 REQUEST(xReq);
494 if (stuff->data < CompositeNumberRequests)
495 return (*SProcCompositeVector[stuff->data]) (client);
496 else
497 return BadRequest;
500 /** @see GetDefaultBytes */
501 static void
502 GetCompositeClientWindowBytes(pointer value, XID id, ResourceSizePtr size)
504 WindowPtr window = value;
506 /* Currently only pixmap bytes are reported to clients. */
507 size->resourceSize = 0;
509 /* Calculate pixmap reference sizes. */
510 size->pixmapRefSize = 0;
511 if (window->redirectDraw != RedirectDrawNone)
513 SizeType pixmapSizeFunc = GetResourceTypeSizeFunc(RT_PIXMAP);
514 ResourceSizeRec pixmapSize = { 0, 0 };
515 ScreenPtr screen = window->drawable.pScreen;
516 PixmapPtr pixmap = screen->GetWindowPixmap(window);
517 pixmapSizeFunc(pixmap, pixmap->drawable.id, &pixmapSize);
518 size->pixmapRefSize += pixmapSize.pixmapRefSize;
522 void
523 CompositeExtensionInit(void)
525 ExtensionEntry *extEntry;
526 int s;
528 /* Assume initialization is going to fail */
529 noCompositeExtension = TRUE;
531 for (s = 0; s < screenInfo.numScreens; s++) {
532 ScreenPtr pScreen = screenInfo.screens[s];
533 VisualPtr vis;
535 /* Composite on 8bpp pseudocolor root windows appears to fail, so
536 * just disable it on anything pseudocolor for safety.
538 for (vis = pScreen->visuals; vis->vid != pScreen->rootVisual; vis++);
539 if ((vis->class | DynamicClass) == PseudoColor)
540 return;
542 /* Ensure that Render is initialized, which is required for automatic
543 * compositing.
545 if (GetPictureScreenIfSet(pScreen) == NULL)
546 return;
549 CompositeClientWindowType = CreateNewResourceType
550 (FreeCompositeClientWindow, "CompositeClientWindow");
551 if (!CompositeClientWindowType)
552 return;
554 SetResourceTypeSizeFunc(CompositeClientWindowType,
555 GetCompositeClientWindowBytes);
557 CompositeClientSubwindowsType = CreateNewResourceType
558 (FreeCompositeClientSubwindows, "CompositeClientSubwindows");
559 if (!CompositeClientSubwindowsType)
560 return;
562 CompositeClientOverlayType = CreateNewResourceType
563 (FreeCompositeClientOverlay, "CompositeClientOverlay");
564 if (!CompositeClientOverlayType)
565 return;
567 if (!dixRegisterPrivateKey(&CompositeClientPrivateKeyRec, PRIVATE_CLIENT,
568 sizeof(CompositeClientRec)))
569 return;
571 if (!AddCallback(&ClientStateCallback, CompositeClientCallback, 0))
572 return;
574 for (s = 0; s < screenInfo.numScreens; s++)
575 if (!compScreenInit(screenInfo.screens[s]))
576 return;
578 extEntry = AddExtension(COMPOSITE_NAME, 0, 0,
579 ProcCompositeDispatch, SProcCompositeDispatch,
580 NULL, StandardMinorOpcode);
581 if (!extEntry)
582 return;
583 CompositeReqCode = (CARD8) extEntry->base;
585 miRegisterRedirectBorderClipProc(compSetRedirectBorderClip,
586 compGetRedirectBorderClip);
588 /* Initialization succeeded */
589 noCompositeExtension = FALSE;
592 #ifdef PANORAMIX
593 #include "panoramiXsrv.h"
595 int (*PanoramiXSaveCompositeVector[CompositeNumberRequests]) (ClientPtr);
597 static int
598 PanoramiXCompositeRedirectWindow(ClientPtr client)
600 PanoramiXRes *win;
601 int rc = 0, j;
603 REQUEST(xCompositeRedirectWindowReq);
605 REQUEST_SIZE_MATCH(xCompositeRedirectWindowReq);
607 if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW,
608 client, DixUnknownAccess))) {
609 client->errorValue = stuff->window;
610 return rc;
613 FOR_NSCREENS_FORWARD(j) {
614 stuff->window = win->info[j].id;
615 rc = (*PanoramiXSaveCompositeVector[stuff->compositeReqType]) (client);
616 if (rc != Success)
617 break;
620 return rc;
623 static int
624 PanoramiXCompositeRedirectSubwindows(ClientPtr client)
626 PanoramiXRes *win;
627 int rc = 0, j;
629 REQUEST(xCompositeRedirectSubwindowsReq);
631 REQUEST_SIZE_MATCH(xCompositeRedirectSubwindowsReq);
633 if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW,
634 client, DixUnknownAccess))) {
635 client->errorValue = stuff->window;
636 return rc;
639 FOR_NSCREENS_FORWARD(j) {
640 stuff->window = win->info[j].id;
641 rc = (*PanoramiXSaveCompositeVector[stuff->compositeReqType]) (client);
642 if (rc != Success)
643 break;
646 return rc;
649 static int
650 PanoramiXCompositeUnredirectWindow(ClientPtr client)
652 PanoramiXRes *win;
653 int rc = 0, j;
655 REQUEST(xCompositeUnredirectWindowReq);
657 REQUEST_SIZE_MATCH(xCompositeUnredirectWindowReq);
659 if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW,
660 client, DixUnknownAccess))) {
661 client->errorValue = stuff->window;
662 return rc;
665 FOR_NSCREENS_FORWARD(j) {
666 stuff->window = win->info[j].id;
667 rc = (*PanoramiXSaveCompositeVector[stuff->compositeReqType]) (client);
668 if (rc != Success)
669 break;
672 return rc;
675 static int
676 PanoramiXCompositeUnredirectSubwindows(ClientPtr client)
678 PanoramiXRes *win;
679 int rc = 0, j;
681 REQUEST(xCompositeUnredirectSubwindowsReq);
683 REQUEST_SIZE_MATCH(xCompositeUnredirectSubwindowsReq);
685 if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW,
686 client, DixUnknownAccess))) {
687 client->errorValue = stuff->window;
688 return rc;
691 FOR_NSCREENS_FORWARD(j) {
692 stuff->window = win->info[j].id;
693 rc = (*PanoramiXSaveCompositeVector[stuff->compositeReqType]) (client);
694 if (rc != Success)
695 break;
698 return rc;
701 static int
702 PanoramiXCompositeNameWindowPixmap(ClientPtr client)
704 WindowPtr pWin;
705 CompWindowPtr cw;
706 PixmapPtr pPixmap;
707 int rc;
708 PanoramiXRes *win, *newPix;
709 int i;
711 REQUEST(xCompositeNameWindowPixmapReq);
713 REQUEST_SIZE_MATCH(xCompositeNameWindowPixmapReq);
715 if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW,
716 client, DixUnknownAccess))) {
717 client->errorValue = stuff->window;
718 return rc;
721 LEGAL_NEW_RESOURCE(stuff->pixmap, client);
723 if (!(newPix = malloc(sizeof(PanoramiXRes))))
724 return BadAlloc;
726 newPix->type = XRT_PIXMAP;
727 newPix->u.pix.shared = FALSE;
728 panoramix_setup_ids(newPix, client, stuff->pixmap);
730 FOR_NSCREENS(i) {
731 rc = dixLookupResourceByType((void **) &pWin, win->info[i].id,
732 RT_WINDOW, client, DixGetAttrAccess);
733 if (rc != Success) {
734 client->errorValue = stuff->window;
735 free(newPix);
736 return rc;
739 if (!pWin->viewable) {
740 free(newPix);
741 return BadMatch;
744 cw = GetCompWindow(pWin);
745 if (!cw) {
746 free(newPix);
747 return BadMatch;
750 pPixmap = (*pWin->drawable.pScreen->GetWindowPixmap) (pWin);
751 if (!pPixmap) {
752 free(newPix);
753 return BadMatch;
756 if (!AddResource(newPix->info[i].id, RT_PIXMAP, (pointer) pPixmap))
757 return BadAlloc;
759 ++pPixmap->refcnt;
762 if (!AddResource(stuff->pixmap, XRT_PIXMAP, (pointer) newPix))
763 return BadAlloc;
765 return Success;
768 static int
769 PanoramiXCompositeGetOverlayWindow(ClientPtr client)
771 REQUEST(xCompositeGetOverlayWindowReq);
772 xCompositeGetOverlayWindowReply rep;
773 WindowPtr pWin;
774 ScreenPtr pScreen;
775 CompScreenPtr cs;
776 CompOverlayClientPtr pOc;
777 int rc;
778 PanoramiXRes *win, *overlayWin = NULL;
779 int i;
781 REQUEST_SIZE_MATCH(xCompositeGetOverlayWindowReq);
783 if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW,
784 client, DixUnknownAccess))) {
785 client->errorValue = stuff->window;
786 return rc;
789 cs = GetCompScreen(screenInfo.screens[0]);
790 if (!cs->pOverlayWin) {
791 if (!(overlayWin = malloc(sizeof(PanoramiXRes))))
792 return BadAlloc;
794 overlayWin->type = XRT_WINDOW;
795 overlayWin->u.win.root = FALSE;
798 FOR_NSCREENS_BACKWARD(i) {
799 rc = dixLookupResourceByType((pointer *) &pWin, win->info[i].id,
800 RT_WINDOW, client, DixGetAttrAccess);
801 if (rc != Success) {
802 client->errorValue = stuff->window;
803 return rc;
805 pScreen = pWin->drawable.pScreen;
808 * Create an OverlayClient structure to mark this client's
809 * interest in the overlay window
811 pOc = compCreateOverlayClient(pScreen, client);
812 if (pOc == NULL)
813 return BadAlloc;
816 * Make sure the overlay window exists
818 cs = GetCompScreen(pScreen);
819 if (cs->pOverlayWin == NULL)
820 if (!compCreateOverlayWindow(pScreen)) {
821 FreeResource(pOc->resource, RT_NONE);
822 return BadAlloc;
825 rc = XaceHook(XACE_RESOURCE_ACCESS, client,
826 cs->pOverlayWin->drawable.id,
827 RT_WINDOW, cs->pOverlayWin, RT_NONE, NULL,
828 DixGetAttrAccess);
829 if (rc != Success) {
830 FreeResource(pOc->resource, RT_NONE);
831 return rc;
835 if (overlayWin) {
836 FOR_NSCREENS(i) {
837 cs = GetCompScreen(screenInfo.screens[i]);
838 overlayWin->info[i].id = cs->pOverlayWin->drawable.id;
841 AddResource(overlayWin->info[0].id, XRT_WINDOW, overlayWin);
844 cs = GetCompScreen(screenInfo.screens[0]);
846 rep.type = X_Reply;
847 rep.sequenceNumber = client->sequence;
848 rep.length = 0;
849 rep.overlayWin = cs->pOverlayWin->drawable.id;
851 if (client->swapped) {
852 swaps(&rep.sequenceNumber);
853 swapl(&rep.length);
854 swapl(&rep.overlayWin);
856 (void) WriteToClient(client, sz_xCompositeGetOverlayWindowReply,
857 (char *) &rep);
859 return Success;
862 static int
863 PanoramiXCompositeReleaseOverlayWindow(ClientPtr client)
865 REQUEST(xCompositeReleaseOverlayWindowReq);
866 WindowPtr pWin;
867 ScreenPtr pScreen;
868 CompOverlayClientPtr pOc;
869 PanoramiXRes *win;
870 int i, rc;
872 REQUEST_SIZE_MATCH(xCompositeReleaseOverlayWindowReq);
874 if ((rc = dixLookupResourceByType((void **) &win, stuff->window, XRT_WINDOW,
875 client, DixUnknownAccess))) {
876 client->errorValue = stuff->window;
877 return rc;
880 FOR_NSCREENS_BACKWARD(i) {
881 if ((rc = dixLookupResourceByType((void **) &pWin, win->info[i].id,
882 XRT_WINDOW, client,
883 DixUnknownAccess))) {
884 client->errorValue = stuff->window;
885 return rc;
887 pScreen = pWin->drawable.pScreen;
890 * Has client queried a reference to the overlay window
891 * on this screen? If not, generate an error.
893 pOc = compFindOverlayClient(pWin->drawable.pScreen, client);
894 if (pOc == NULL)
895 return BadMatch;
897 /* The delete function will free the client structure */
898 FreeResource(pOc->resource, RT_NONE);
901 return Success;
904 void
905 PanoramiXCompositeInit(void)
907 int i;
909 for (i = 0; i < CompositeNumberRequests; i++)
910 PanoramiXSaveCompositeVector[i] = ProcCompositeVector[i];
912 * Stuff in Xinerama aware request processing hooks
914 ProcCompositeVector[X_CompositeRedirectWindow] =
915 PanoramiXCompositeRedirectWindow;
916 ProcCompositeVector[X_CompositeRedirectSubwindows] =
917 PanoramiXCompositeRedirectSubwindows;
918 ProcCompositeVector[X_CompositeUnredirectWindow] =
919 PanoramiXCompositeUnredirectWindow;
920 ProcCompositeVector[X_CompositeUnredirectSubwindows] =
921 PanoramiXCompositeUnredirectSubwindows;
922 ProcCompositeVector[X_CompositeNameWindowPixmap] =
923 PanoramiXCompositeNameWindowPixmap;
924 ProcCompositeVector[X_CompositeGetOverlayWindow] =
925 PanoramiXCompositeGetOverlayWindow;
926 ProcCompositeVector[X_CompositeReleaseOverlayWindow] =
927 PanoramiXCompositeReleaseOverlayWindow;
930 void
931 PanoramiXCompositeReset(void)
933 int i;
935 for (i = 0; i < CompositeNumberRequests; i++)
936 ProcCompositeVector[i] = PanoramiXSaveCompositeVector[i];
939 #endif