pulseaudio: fix dependencies for openssl-3
[oi-userland.git] / components / x11 / libXext / srcs / src / TransOvl.c
blobb6133d3d42a6121dc0cf88884dccf5a7277c0514
1 /* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
12 * Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
25 * TransOvl.c - the client side interface to the Transparent Overlays
26 * extension.
29 #define NEED_EVENTS
30 #define NEED_REPLIES
31 #include <X11/Xlibint.h>
32 #include <X11/Xutil.h>
33 #include <X11/extensions/extutil.h>
34 #include <X11/extensions/transovlstr.h>
35 #include <X11/extensions/multibuf.h>
36 #include <limits.h>
38 typedef struct {
39 XExtData extdata;
40 int numVisPairs;
41 Bool pairsRestricted;
42 int visdatatypes;
43 } XOvlScrExtData;
45 typedef struct {
46 VisualID vid;
47 Visual *vis;
48 int depth;
49 } XOvlVisInfo;
51 typedef struct {
52 XOvlVisInfo overlay;
53 XOvlVisInfo underlay;
54 } XOvlVisPair;
56 #ifdef _LP64
57 #define XOvlMBXBuffers (1L << 0)
58 #define XOvlSharedPixels (1L << 1)
59 #define XOvlSharedColors (1L << 2)
61 #define XOVL_MAX_BUFFERS (~0L)
62 #define XOVL_ALL_PLANES (~0L)
63 #define XOVL_ANY_POOL (~0L)
64 #else /* _LP64 */
65 #define XOvlMBXBuffers (1 << 0)
66 #define XOvlSharedPixels (1 << 1)
67 #define XOvlSharedColors (1 << 2)
69 #define XOVL_MAX_BUFFERS (~0)
70 #define XOVL_ALL_PLANES (~0)
71 #define XOVL_ANY_POOL (~0)
72 #endif /* _LP64 */
74 typedef struct {
75 XExtData extdata;
76 int datatypes;
77 int numBuffers;
78 unsigned long ovplanes;
79 unsigned long unplanes;
80 unsigned long clutpool;
81 int clutcount;
82 } XOvlVisExtData;
84 typedef struct {
85 XExtData extdata;
86 XSolarisOvlPaintType paintType;
87 } XOvlGCExtData;
89 typedef struct {
90 int screen;
91 XOvlVisInfo candidate;
92 XOvlVisInfo partner;
93 Bool partnerpreferred;
94 XSolarisOvlSelectType searchtype;
95 unsigned long hardfailures;
96 unsigned long softfailures;
97 int numhardfailures;
98 int numsoftfailures;
99 } XOvlVisualMatch;
101 typedef struct {
102 int nDepths;
103 Depth *pDepths;
104 int depth;
105 int nVisuals;
106 Visual *pVisuals;
107 } XOvlVisEnumData;
109 static int close_display(Display *dpy, XExtCodes *codes);
111 static XExtensionInfo *ext_info;
112 static char *ext_name = OVLNAME;
113 static XExtensionHooks ext_hooks = {
114 NULL, /* create_gc */
115 NULL, /* copy_gc */
116 NULL, /* flush_gc */
117 NULL, /* free_gc */
118 NULL, /* create_font */
119 NULL, /* free_font */
120 close_display, /* close_display */
121 NULL, /* wire_to_event */
122 NULL, /* event_to_wire */
123 NULL, /* error */
124 NULL, /* error_string */
127 static
128 XEXT_GENERATE_CLOSE_DISPLAY(close_display,
129 ext_info)
131 static
132 XEXT_GENERATE_FIND_DISPLAY(find_display,
133 ext_info, ext_name, &ext_hooks,
134 OvlNumberEvents, NULL)
136 #define OvlCheckExtension(dpy,i,val) \
137 XextCheckExtension (dpy, i, ext_name, val)
138 #define OvlSimpleCheckExtension(dpy,i) \
139 XextSimpleCheckExtension (dpy, i, ext_name)
142 /**********************************************************************/
145 * The utility function _XVIDtoVisual could be used, but we already
146 * know the screen structure where the visual is to be found, so there
147 * is no need to scan all the screens on the display. This procedure
148 * performs a more direct scan for the visual.
150 static Bool
151 find_visual(
152 Screen *scr,
153 VisualID vid,
154 Visual **visReturn,
155 int *depthReturn
158 Depth *depth;
159 Visual *vis;
161 for (depth = scr->depths; depth < (scr->depths + scr->ndepths); depth++) {
162 if (depth->visuals) {
163 for (vis = depth->visuals;
164 vis < (depth->visuals + depth->nvisuals);
165 vis++)
167 if (vis->visualid == vid) {
168 *visReturn = vis;
169 *depthReturn = depth->depth;
170 return True;
175 return False;
179 static void
180 vis_enum_init(
181 Screen *scr,
182 XOvlVisEnumData *visEnumData
185 visEnumData->nDepths = scr->ndepths;
186 visEnumData->pDepths = scr->depths;
187 visEnumData->depth = 0;
188 visEnumData->nVisuals = 0;
189 visEnumData->pVisuals = NULL;
193 static Bool
194 vis_enum_next(
195 XOvlVisEnumData *visEnumData,
196 Visual **visReturn,
197 int *depthReturn
200 int ndepths;
201 Depth *depth;
203 if (!visEnumData->nVisuals) {
204 ndepths = visEnumData->nDepths;
205 depth = visEnumData->pDepths;
206 while (ndepths) {
207 if (depth->visuals) {
208 break;
210 ndepths--;
211 depth++;
213 if (!ndepths) {
214 return False;
216 visEnumData->nDepths = ndepths - 1;
217 visEnumData->pDepths = depth + 1;
218 visEnumData->depth = depth->depth;
219 visEnumData->nVisuals = depth->nvisuals;
220 visEnumData->pVisuals = depth->visuals;
222 visEnumData->nVisuals--;
223 *visReturn = visEnumData->pVisuals++;
224 *depthReturn = visEnumData->depth;
225 return True;
229 static XOvlScrExtData *
230 find_screendata(
231 Display *dpy,
232 int screen,
233 XExtDisplayInfo *info
236 XOvlScrExtData *scrextdata;
237 Screen *scr;
238 xOvlGetPartnersReq *req;
239 xOvlGetPartnersReply rep;
240 unsigned long nbytes;
241 unsigned long numPairs;
242 XOvlVisPair *vispairs,
243 *vispair;
244 XOvlVidPair vidpair;
245 XEDataObject obj;
247 obj.screen = scr = ScreenOfDisplay(dpy, screen);
248 scrextdata = (XOvlScrExtData *)
249 XFindOnExtensionList(XEHeadOfExtensionList(obj),
250 info->codes->extension);
251 if (!scrextdata) {
252 GetReq(OvlGetPartners, req);
253 req->reqType = info->codes->major_opcode;
254 req->ovlReqType = X_OvlGetPartners;
255 req->screen = screen;
256 if (_XReply(dpy, (xReply *)(&rep), 0, xFalse)) {
257 numPairs = rep.numPairs;
258 nbytes = numPairs * sizeof(XOvlVisPair);
259 scrextdata = Xmalloc(sizeof(XOvlScrExtData));
260 vispairs = (XOvlVisPair *)Xmalloc(nbytes);
261 if (scrextdata && vispairs) {
262 scrextdata->extdata.number = info->codes->extension;
263 scrextdata->extdata.free_private = NULL;
264 scrextdata->extdata.private_data = (char *)vispairs;
265 scrextdata->numVisPairs = rep.numPairs;
266 scrextdata->pairsRestricted = rep.restricted;
267 /* BugId: 4126680 - Purify detects reads in uninitialized
268 memory generating random results. culprit was id'd to
269 be the uninitialized field visdatatypes */
270 scrextdata->visdatatypes = 0;
271 vispair = vispairs;
272 while (numPairs--) {
273 _XRead(dpy, (char *)(&vidpair), sizeof(vidpair));
274 vispair->overlay.vid = vidpair.overlayVid;
275 vispair->underlay.vid = vidpair.underlayVid;
276 if ( !find_visual(scr, vidpair.overlayVid,
277 &vispair->overlay.vis,
278 &vispair->overlay.depth)
279 || !find_visual(scr, vidpair.underlayVid,
280 &vispair->underlay.vis,
281 &vispair->underlay.depth))
283 Xfree(vispairs);
284 Xfree(scrextdata);
285 scrextdata = NULL;
286 if (numPairs) {
287 nbytes = numPairs * sizeof(XOvlVidPair);
288 _XEatData(dpy, nbytes);
290 break;
292 vispair++;
294 if (scrextdata) {
295 XAddToExtensionList(XEHeadOfExtensionList(obj),
296 &(scrextdata->extdata));
298 } else {
299 Xfree(scrextdata);
300 Xfree(vispairs);
301 nbytes = numPairs * sizeof(XOvlVidPair);
302 _XEatData(dpy, nbytes);
303 scrextdata = NULL;
307 return scrextdata;
311 static XOvlVisExtData *
312 find_visdata(
313 Visual *vis,
314 XExtDisplayInfo *info
317 XOvlVisExtData *visextdata;
318 XEDataObject obj;
320 obj.visual = vis;
321 visextdata = (XOvlVisExtData *)
322 XFindOnExtensionList(XEHeadOfExtensionList(obj),
323 info->codes->extension);
324 if (!visextdata) {
325 visextdata = Xmalloc(sizeof(XOvlVisExtData));
326 if (visextdata) {
327 visextdata->extdata.number = info->codes->extension;
328 visextdata->extdata.free_private = NULL;
329 visextdata->extdata.private_data = NULL;
330 visextdata->datatypes = 0;
331 XAddToExtensionList(XEHeadOfExtensionList(obj),
332 &(visextdata->extdata));
336 return visextdata;
340 static int
341 bitcount(
342 unsigned long mask
345 int count;
347 count = 0;
348 while (mask) {
349 count++;
350 mask &= (mask - 1);
352 return count;
356 static int
357 GetNumMBXBuffers(
358 Display *dpy,
359 int screen,
360 Visual *candidateVis,
361 XExtDisplayInfo *info)
363 XOvlVisExtData *candidateData;
364 XOvlScrExtData *scrextdata;
365 int i,
366 nmono,
367 nstereo;
368 XmbufBufferInfo *mono_info,
369 *stereo_info;
370 Visual *vis;
371 int depth;
372 XOvlVisExtData *visextdata;
373 Screen *scr;
375 candidateData = find_visdata(candidateVis, info);
376 if (!candidateData) {
378 * Cannot store data for this visual, assume the worst case.
380 return 0;
382 if (!(candidateData->datatypes & XOvlMBXBuffers)) {
383 scrextdata = find_screendata(dpy, screen, info);
384 if (!(scrextdata->visdatatypes & XOvlMBXBuffers)) {
386 * We haven't queried the MBX extension for the buffer
387 * data on this screen yet. Call XmbufGetScreenInfo
388 * and fill in the data for all the returned visuals.
390 scr = ScreenOfDisplay(dpy, screen);
391 scrextdata->visdatatypes |= XOvlMBXBuffers;
392 XmbufGetScreenInfo(dpy, RootWindow(dpy, screen),
393 &nmono, &mono_info,
394 &nstereo, &stereo_info);
395 for (i = 0; i < nmono; i++) {
396 if (find_visual(scr, mono_info[i].visualid, &vis, &depth)) {
397 visextdata = find_visdata(vis, info);
398 if (visextdata) {
399 visextdata->numBuffers = mono_info[i].max_buffers;
400 if (!visextdata->numBuffers) {
401 visextdata->numBuffers = XOVL_MAX_BUFFERS;
403 visextdata->datatypes |= XOvlMBXBuffers;
404 } else {
406 * We were unable to finish the query, so mark
407 * the data as unqueried so we can try again later.
409 scrextdata->visdatatypes &= ~XOvlMBXBuffers;
413 XFree(mono_info);
414 XFree(stereo_info);
416 if (!(candidateData->datatypes & XOvlMBXBuffers)) {
418 * No data was returned from MBX for this visual,
419 * so fill in a default value. Only mark the
420 * data valid if the server query completed.
422 candidateData->numBuffers = 0;
423 if (scrextdata->visdatatypes & XOvlMBXBuffers) {
424 candidateData->datatypes |= XOvlMBXBuffers;
429 return candidateData->numBuffers;
433 static Bool
434 CheckSharedPixels(
435 Display *dpy,
436 int screen,
437 XSolarisOvlSelectType searchtype,
438 Visual *candidateVis,
439 Visual *partnerVis,
440 XExtDisplayInfo *info)
442 XOvlVisExtData *candidateData,
443 *partnerData;
444 XOvlScrExtData *scrextdata;
445 Screen *scr;
446 xOvlGetSharedPixelsReq *req;
447 xOvlGetSharedPixelsReply rep;
448 unsigned int i;
449 XOvlPGInfo pginfo;
450 Visual *vis;
451 int depth;
452 XOvlVisExtData *visextdata;
453 unsigned long commonplanes;
455 candidateData = find_visdata(candidateVis, info);
456 partnerData = find_visdata(partnerVis, info);
457 if (!candidateData || !partnerData) {
459 * Cannot store data for these visuals, assume the worst case.
461 return True;
463 if ( !(candidateData->datatypes & XOvlSharedPixels)
464 || !( partnerData->datatypes & XOvlSharedPixels))
466 scrextdata = find_screendata(dpy, screen, info);
467 if (!(scrextdata->visdatatypes & XOvlSharedPixels)) {
469 * We haven't queried the server for plane group data
470 * on this screen yet. Send the query and fill in
471 * the data for the visuals indicated in the reply.
473 scr = ScreenOfDisplay(dpy, screen);
474 scrextdata->visdatatypes |= XOvlSharedPixels;
475 GetReq(OvlGetSharedPixels, req);
476 req->reqType = info->codes->major_opcode;
477 req->ovlReqType = X_OvlGetSharedPixels;
478 req->screen = screen;
479 if (_XReply(dpy, (xReply *)(&rep), 0, xFalse)) {
480 for (i = 0; i < rep.numPGInfos; i++) {
481 _XRead(dpy, (char *)(&pginfo), sizeof(pginfo));
482 if (find_visual(scr, pginfo.vid, &vis, &depth)) {
483 visextdata = find_visdata(vis, info);
484 if (visextdata) {
485 visextdata->ovplanes = pginfo.ovplanes;
486 visextdata->unplanes = pginfo.unplanes;
487 visextdata->datatypes |= XOvlSharedPixels;
488 } else {
490 * We were unable to finish the query, so mark
491 * the data as unqueried so we can try again later.
493 scrextdata->visdatatypes &= ~XOvlSharedPixels;
499 if (!(candidateData->datatypes & XOvlSharedPixels)) {
501 * No data was returned from the server for this
502 * visual, so fill in a default value. Only mark
503 * the data valid if the server query completed.
505 candidateData->ovplanes = XOVL_ALL_PLANES;
506 candidateData->unplanes = XOVL_ALL_PLANES;
507 if (scrextdata->visdatatypes & XOvlSharedPixels) {
508 candidateData->datatypes |= XOvlSharedPixels;
511 if (!(partnerData->datatypes & XOvlSharedPixels)) {
513 * No data was returned from the server for this
514 * visual, so fill in a default value. Only mark
515 * the data valid if the server query completed.
517 partnerData->ovplanes = XOVL_ALL_PLANES;
518 partnerData->unplanes = XOVL_ALL_PLANES;
519 if (scrextdata->visdatatypes & XOvlSharedPixels) {
520 partnerData->datatypes |= XOvlSharedPixels;
525 if (searchtype == XSolarisOvlSelectBestOverlay) {
526 commonplanes = candidateData->ovplanes & partnerData->unplanes;
527 } else {
528 commonplanes = candidateData->unplanes & partnerData->ovplanes;
530 return commonplanes ? True : False;
534 static Bool
535 CheckSharedColors(
536 Display *dpy,
537 int screen,
538 Visual *candidateVis,
539 Visual *partnerVis,
540 XExtDisplayInfo *info)
542 XOvlVisExtData *candidateData,
543 *partnerData;
544 XOvlScrExtData *scrextdata;
545 Screen *scr;
546 xOvlGetSharedColorsReq *req;
547 xOvlGetSharedColorsReply rep;
548 unsigned int i;
549 XOvlClutInfo clutinfo;
550 Visual *vis;
551 int depth;
552 XOvlVisExtData *visextdata;
554 candidateData = find_visdata(candidateVis, info);
555 partnerData = find_visdata(partnerVis, info);
556 if (!candidateData || !partnerData) {
558 * Cannot store data for these visuals, assume the worst case.
560 return True;
562 if ( !(candidateData->datatypes & XOvlSharedColors)
563 || !( partnerData->datatypes & XOvlSharedColors))
565 scrextdata = find_screendata(dpy, screen, info);
566 if (!(scrextdata->visdatatypes & XOvlSharedColors)) {
568 * We haven't queried the server for clut pool data
569 * on this screen yet. Send the query and fill in
570 * the data for the visuals indicated in the reply.
572 scr = ScreenOfDisplay(dpy, screen);
573 scrextdata->visdatatypes |= XOvlSharedColors;
574 GetReq(OvlGetSharedColors, req);
575 req->reqType = info->codes->major_opcode;
576 req->ovlReqType = X_OvlGetSharedColors;
577 req->screen = screen;
578 if (_XReply(dpy, (xReply *)(&rep), 0, xFalse)) {
579 for (i = 0; i < rep.numClutInfos; i++) {
580 _XRead(dpy, (char *)(&clutinfo), sizeof(clutinfo));
581 if (find_visual(scr, clutinfo.vid, &vis, &depth)) {
582 visextdata = find_visdata(vis, info);
583 if (visextdata) {
584 visextdata->clutpool = (1 << clutinfo.pool);
585 visextdata->clutcount = clutinfo.count;
586 visextdata->datatypes |= XOvlSharedColors;
587 } else {
589 * We were unable to finish the query, so mark
590 * the data as unqueried so we can try again later.
592 scrextdata->visdatatypes &= ~XOvlSharedColors;
598 if (!(candidateData->datatypes & XOvlSharedColors)) {
600 * No data was returned from the server for this
601 * visual, so fill in a default value. Only mark
602 * the data valid if the server query completed.
604 candidateData->clutpool = XOVL_ANY_POOL;
605 candidateData->clutcount = 1;
606 if (scrextdata->visdatatypes & XOvlSharedColors) {
607 candidateData->datatypes |= XOvlSharedColors;
610 if (!(partnerData->datatypes & XOvlSharedColors)) {
612 * No data was returned from the server for this
613 * visual, so fill in a default value. Only mark
614 * the data valid if the server query completed.
616 partnerData->clutpool = XOVL_ANY_POOL;
617 partnerData->clutcount = 1;
618 if (scrextdata->visdatatypes & XOvlSharedColors) {
619 partnerData->datatypes |= XOvlSharedColors;
624 return ( (candidateData->clutpool & partnerData->clutpool)
625 && candidateData->clutcount <= 1)
626 ? True
627 : False;
631 static void
632 ComputeVisualMatch(
633 Display *dpy,
634 XOvlVisualMatch *match,
635 XSolarisOvlVisualCriteria *pCriteria,
636 XExtDisplayInfo *info)
638 Visual *vis = match->candidate.vis;
639 unsigned long hardmask,
640 softmask,
641 mask;
642 unsigned long hardfailures,
643 softfailures;
645 hardmask = pCriteria->hardCriteriaMask;
646 softmask = pCriteria->softCriteriaMask;
647 mask = hardmask | softmask;
648 hardfailures = 0;
649 softfailures = 0;
651 if ( (mask & XSolarisOvlVisualClass)
652 && (vis->class != pCriteria->c_class))
654 hardfailures |= hardmask & XSolarisOvlVisualClass;
655 softfailures |= softmask & XSolarisOvlVisualClass;
657 if ( (mask & XSolarisOvlDepth)
658 && (match->candidate.depth != pCriteria->depth))
660 hardfailures |= hardmask & XSolarisOvlDepth;
661 softfailures |= softmask & XSolarisOvlDepth;
663 if ( (mask & XSolarisOvlMinColors)
664 && (vis->map_entries < pCriteria->minColors))
666 hardfailures |= hardmask & XSolarisOvlMinColors;
667 softfailures |= softmask & XSolarisOvlMinColors;
669 if ( (mask & XSolarisOvlMinRed)
670 && ((1 << bitcount(vis->red_mask)) < pCriteria->minRed))
672 hardfailures |= hardmask & XSolarisOvlMinRed;
673 softfailures |= softmask & XSolarisOvlMinRed;
675 if ( (mask & XSolarisOvlMinGreen)
676 && ((1 << bitcount(vis->green_mask)) < pCriteria->minGreen))
678 hardfailures |= hardmask & XSolarisOvlMinGreen;
679 softfailures |= softmask & XSolarisOvlMinGreen;
681 if ( (mask & XSolarisOvlMinBlue)
682 && ((1 << bitcount(vis->blue_mask)) < pCriteria->minBlue))
684 hardfailures |= hardmask & XSolarisOvlMinBlue;
685 softfailures |= softmask & XSolarisOvlMinBlue;
687 if ( (mask & XSolarisOvlMinBitsPerRGB)
688 && (vis->bits_per_rgb < pCriteria->minBitsPerRGB))
690 hardfailures |= hardmask & XSolarisOvlMinBitsPerRGB;
691 softfailures |= softmask & XSolarisOvlMinBitsPerRGB;
693 if ( (mask & XSolarisOvlMinBuffers)
694 && ( GetNumMBXBuffers(dpy, match->screen, vis, info)
695 < pCriteria->minBuffers))
697 hardfailures |= hardmask & XSolarisOvlMinBuffers;
698 softfailures |= softmask & XSolarisOvlMinBuffers;
700 if ( (mask & XSolarisOvlUnsharedPixels)
701 && CheckSharedPixels(dpy, match->screen, match->searchtype,
702 vis, match->partner.vis, info))
704 hardfailures |= hardmask & XSolarisOvlUnsharedPixels;
705 softfailures |= softmask & XSolarisOvlUnsharedPixels;
707 if ( (mask & XSolarisOvlUnsharedColors)
708 && CheckSharedColors(dpy, match->screen,
709 vis, match->partner.vis, info))
711 hardfailures |= hardmask & XSolarisOvlUnsharedColors;
712 softfailures |= softmask & XSolarisOvlUnsharedColors;
714 if ( (mask & XSolarisOvlPreferredPartner)
715 && (!match->partnerpreferred))
717 hardfailures |= hardmask & XSolarisOvlPreferredPartner;
718 softfailures |= softmask & XSolarisOvlPreferredPartner;
720 match->hardfailures = hardfailures;
721 match->numhardfailures = bitcount(hardfailures);
722 match->softfailures = softfailures;
723 match->numsoftfailures = bitcount(softfailures);
727 #define XSolarisOvlAllCriteria \
728 (XSolarisOvlVisualClass | \
729 XSolarisOvlDepth | \
730 XSolarisOvlMinColors | \
731 XSolarisOvlMinRed | \
732 XSolarisOvlMinGreen | \
733 XSolarisOvlMinBlue | \
734 XSolarisOvlMinBitsPerRGB | \
735 XSolarisOvlMinBuffers | \
736 XSolarisOvlUnsharedPixels | \
737 XSolarisOvlUnsharedColors | \
738 XSolarisOvlPreferredPartner)
740 static void
741 SetWorstMatch(
742 XOvlVisualMatch *match
745 match->hardfailures = XSolarisOvlAllCriteria;
746 match->softfailures = XSolarisOvlAllCriteria;
747 match->numhardfailures =
748 match->numsoftfailures =
749 bitcount(XSolarisOvlAllCriteria);
753 #define IsPerfectMatch(pm) (!((pm)->hardfailures | (pm)->softfailures))
755 #define IsQualifiedMatch(pm) (!(pm)->hardfailures)
757 #define IsBetterMatch(pm1, pm2) \
758 ( ((pm1)->numhardfailures < (pm2)->numhardfailures) \
759 || ( ((pm1)->numhardfailures == (pm2)->numhardfailures) \
760 && ((pm1)->numsoftfailures < (pm2)->numsoftfailures)))
763 #define IsPerfectPair(povm, punm) \
764 (IsPerfectMatch(povm) && IsPerfectMatch(punm))
766 #define IsQualifiedPair(povm, punm) \
767 (IsQualifiedMatch(povm) && IsQualifiedMatch(punm))
769 #define IsBetterPair(povm1, punm1, povm2, punm2) \
770 ( ( ((povm1)->numhardfailures + (punm1)->numhardfailures) \
771 < ((povm2)->numhardfailures + (punm2)->numhardfailures)) \
772 || ( ( ((povm1)->numhardfailures + (punm1)->numhardfailures) \
773 == ((povm2)->numhardfailures + (punm2)->numhardfailures)) \
774 && ( ((povm1)->numsoftfailures + (punm1)->numsoftfailures) \
775 < ((povm2)->numsoftfailures + (punm2)->numsoftfailures))))
778 static void
779 set_visinfo(
780 XVisualInfo *visinfoReturn,
781 XOvlVisualMatch *match
784 Visual *vis = match->candidate.vis;
786 visinfoReturn->visual = vis;
787 visinfoReturn->visualid = match->candidate.vid;
788 visinfoReturn->screen = match->screen;
789 visinfoReturn->depth = match->candidate.depth;
790 visinfoReturn->class = vis->class;
791 visinfoReturn->red_mask = vis->red_mask;
792 visinfoReturn->green_mask = vis->green_mask;
793 visinfoReturn->blue_mask = vis->blue_mask;
794 visinfoReturn->colormap_size = vis->map_entries;
795 visinfoReturn->bits_per_rgb = vis->bits_per_rgb;
798 /**********************************************************************/
800 Bool
801 XSolarisOvlQueryExtension(
802 Display *dpy,
803 int *event_basep,
804 int *error_basep
807 XExtDisplayInfo *info = find_display(dpy);
809 if (XextHasExtension(info)) {
810 *event_basep = info->codes->first_event;
811 *error_basep = info->codes->first_error;
812 return True;
813 } else {
814 return False;
819 Status
820 XSolarisOvlQueryVersion(
821 Display *dpy,
822 int *major_versionp,
823 int *minor_versionp)
825 XExtDisplayInfo *info = find_display(dpy);
826 xOvlQueryVersionReply rep;
827 xOvlQueryVersionReq *req;
829 OvlCheckExtension(dpy, info, 0);
831 LockDisplay(dpy);
832 GetReq(OvlQueryVersion, req);
833 req->reqType = info->codes->major_opcode;
834 req->ovlReqType = X_OvlQueryVersion;
835 if (!_XReply(dpy, (xReply *)(&rep), 0, xTrue)) {
836 UnlockDisplay(dpy);
837 SyncHandle();
838 return 0;
840 *major_versionp = rep.majorVersion;
841 *minor_versionp = rep.minorVersion;
842 UnlockDisplay(dpy);
843 SyncHandle();
844 return 1;
848 Window
849 XSolarisOvlCreateWindow(
850 Display *dpy,
851 Window parent,
852 int x,
853 int y,
854 unsigned int width,
855 unsigned int height,
856 unsigned int border_width,
857 int depth,
858 unsigned int class,
859 Visual *visual,
860 unsigned long valuemask,
861 XSetWindowAttributes *attr
864 XExtDisplayInfo *info = find_display(dpy);
865 Window wid;
866 xOvlCreateWindowReq *req;
869 * REMIND: Is there a proper return value to indicate error?
871 OvlCheckExtension(dpy, info, (Window) 0);
873 LockDisplay(dpy);
874 GetReq(OvlCreateWindow, req);
875 req->reqType = info->codes->major_opcode;
876 req->ovlReqType = X_OvlCreateWindow;
877 req->parent = parent;
878 req->x = x;
879 req->y = y;
880 req->width = width;
881 req->height = height;
882 req->borderWidth = border_width;
883 req->depth = depth;
884 req->class = class;
885 if (visual == CopyFromParent) {
886 req->visual = CopyFromParent;
887 } else {
888 req->visual = visual->visualid;
890 wid = req->wid = XAllocID(dpy);
891 valuemask &= AllMaskBits;
892 if (req->mask = valuemask) {
894 /* BugId 4130905 - There were only 3 args to this call instead of 4 -
895 the last argument attr was missing - causing Bad Xerror Request. When
896 the client lin libXext was recompiled, the bus error caused the
897 client code to fail. Big change between 2.6 and 2.7 file. */
899 _XProcessWindowAttributes(dpy, (xChangeWindowAttributesReq *)req,
900 valuemask, attr);
902 UnlockDisplay(dpy);
903 SyncHandle();
904 return wid;
908 Bool
909 XSolarisOvlIsOverlayWindow(
910 Display *dpy,
911 Window w
914 XExtDisplayInfo *info = find_display(dpy);
915 xOvlIsOverlayWindowReq *req;
916 xOvlIsOverlayWindowReply rep;
918 OvlCheckExtension(dpy, info, False);
920 LockDisplay(dpy);
921 GetReq(OvlIsOverlayWindow, req);
922 req->reqType = info->codes->major_opcode;
923 req->ovlReqType = X_OvlIsOverlayWindow;
924 req->wid = w;
925 if (_XReply (dpy, (xReply *)(&rep), 0, xTrue) == 0) {
926 rep.isoverlay = False;
928 UnlockDisplay(dpy);
929 SyncHandle();
930 return rep.isoverlay;
934 void
935 XSolarisOvlSetWindowTransparent(
936 Display *dpy,
937 Window w)
939 XExtDisplayInfo *info = find_display(dpy);
940 xOvlSetWindowTransparentReq *req;
942 OvlSimpleCheckExtension(dpy, info);
944 LockDisplay(dpy);
945 GetReq(OvlSetWindowTransparent, req);
946 req->reqType = info->codes->major_opcode;
947 req->ovlReqType = X_OvlSetWindowTransparent;
948 req->wid = w;
949 UnlockDisplay(dpy);
950 SyncHandle();
951 return;
955 Status
956 XSolarisOvlSetPaintType(
957 Display *dpy,
958 GC gc,
959 XSolarisOvlPaintType paintType
962 XExtDisplayInfo *info = find_display(dpy);
963 XOvlGCExtData *gcextdata;
964 xOvlSetPaintTypeReq *req;
965 XEDataObject obj;
967 OvlCheckExtension(dpy, info, 0);
969 LockDisplay(dpy);
970 obj.gc = gc;
971 gcextdata = (XOvlGCExtData *)
972 XFindOnExtensionList(XEHeadOfExtensionList(obj),
973 info->codes->extension);
974 if (!gcextdata) {
975 if (paintType == XSolarisOvlPaintOpaque) {
977 * No use creating an extension structure just to hold
978 * the default value.
980 UnlockDisplay(dpy);
981 SyncHandle();
982 return 1;
984 gcextdata = Xmalloc(sizeof(XOvlGCExtData));
985 if (!gcextdata) {
986 UnlockDisplay(dpy);
987 SyncHandle();
988 return 0;
990 gcextdata->extdata.number = info->codes->extension;
991 gcextdata->extdata.free_private = NULL;
992 gcextdata->extdata.private_data = NULL;
993 gcextdata->paintType = XSolarisOvlPaintOpaque;
994 XAddToExtensionList(XEHeadOfExtensionList(obj), &(gcextdata->extdata));
996 if (gcextdata->paintType != paintType) {
997 gcextdata->paintType = paintType;
998 FlushGC(dpy, gc);
999 GetReq(OvlSetPaintType, req);
1000 req->reqType = info->codes->major_opcode;
1001 req->ovlReqType = X_OvlSetPaintType;
1002 req->gc = gc->gid;
1003 req->paintType = paintType;
1005 UnlockDisplay(dpy);
1006 SyncHandle();
1007 return 1;
1011 XSolarisOvlPaintType
1012 XSolarisOvlGetPaintType(
1013 Display *dpy,
1014 GC gc
1017 XExtDisplayInfo *info = find_display(dpy);
1018 XOvlGCExtData *gcextdata;
1019 XSolarisOvlPaintType paintType;
1020 XEDataObject obj;
1022 OvlCheckExtension(dpy, info, XSolarisOvlPaintOpaque);
1024 LockDisplay(dpy);
1025 obj.gc = gc;
1026 gcextdata = (XOvlGCExtData *)
1027 XFindOnExtensionList(XEHeadOfExtensionList(obj),
1028 info->codes->extension);
1029 paintType = (gcextdata) ? gcextdata->paintType : XSolarisOvlPaintOpaque;
1030 UnlockDisplay(dpy);
1031 SyncHandle();
1032 return paintType;
1036 Status
1037 XSolarisOvlCopyPaintType(
1038 Display *dpy,
1039 Drawable src,
1040 Drawable dst,
1041 GC gc,
1042 int src_x,
1043 int src_y,
1044 unsigned int width,
1045 unsigned int height,
1046 int dest_x,
1047 int dest_y,
1048 unsigned long action_mask,
1049 unsigned long planemask
1052 XExtDisplayInfo *info = find_display(dpy);
1053 xOvlCopyPaintTypeReq *req;
1055 OvlCheckExtension(dpy, info, 0);
1057 LockDisplay(dpy);
1058 FlushGC(dpy, gc);
1059 GetReq(OvlCopyPaintType, req);
1060 req->reqType = info->codes->major_opcode;
1061 req->ovlReqType = X_OvlCopyPaintType;
1062 req->srcDrawable = src;
1063 req->dstDrawable = dst;
1064 req->gc = gc->gid;
1065 req->srcX = src_x;
1066 req->srcY = src_y;
1067 req->destX = dest_x;
1068 req->destY = dest_y;
1069 req->width = width;
1070 req->height = height;
1071 req->action_mask = action_mask;
1072 req->bitPlane = planemask;
1073 UnlockDisplay(dpy);
1074 SyncHandle();
1075 return 1;
1079 Status
1080 XSolarisOvlCopyAreaAndPaintType(
1081 Display *dpy,
1082 Drawable colorSrc,
1083 Drawable paintTypeSrc,
1084 Drawable colorDst,
1085 Drawable paintTypeDst,
1086 GC colorGC,
1087 GC paintTypeGC,
1088 int colorSrcX,
1089 int colorSrcY,
1090 int paintTypeSrcX,
1091 int paintTypeSrcY,
1092 unsigned int width,
1093 unsigned int height,
1094 int colorDstX,
1095 int colorDstY,
1096 int paintTypeDstX,
1097 int paintTypeDstY,
1098 unsigned long action_mask,
1099 unsigned long planemask)
1101 XExtDisplayInfo *info = find_display(dpy);
1102 xOvlCopyAreaAndPaintTypeReq *req;
1104 OvlCheckExtension(dpy, info, 0);
1106 LockDisplay(dpy);
1107 FlushGC(dpy, colorGC);
1108 if (paintTypeGC && (paintTypeGC != colorGC))
1109 FlushGC(dpy, paintTypeGC);
1110 GetReq(OvlCopyAreaAndPaintType, req);
1111 req->reqType = info->codes->major_opcode;
1112 req->ovlReqType = X_OvlCopyAreaAndPaintType;
1113 req->colorSrc = colorSrc;
1114 req->paintTypeSrc = paintTypeSrc;
1115 req->colorDst = colorDst;
1116 req->paintTypeDst = paintTypeDst;
1117 req->colorGC = colorGC->gid;
1118 req->paintTypeGC = (paintTypeGC) ? paintTypeGC->gid : None;
1119 req->colorSrcX = colorSrcX;
1120 req->colorSrcY = colorSrcY;
1121 req->paintTypeSrcX = paintTypeSrcX;
1122 req->paintTypeSrcY = paintTypeSrcY;
1123 req->colorDstX = colorDstX;
1124 req->colorDstY = colorDstY;
1125 req->paintTypeDstX = paintTypeDstX;
1126 req->paintTypeDstY = paintTypeDstY;
1127 req->width = width;
1128 req->height = height;
1129 req->action_mask = action_mask;
1130 req->bitPlane = planemask;
1131 UnlockDisplay(dpy);
1132 SyncHandle();
1133 return 1;
1137 XImage *
1138 XReadScreen(
1139 Display *dpy,
1140 Window w,
1141 int x,
1142 int y,
1143 unsigned int width,
1144 unsigned int height,
1145 Bool includeCursor
1148 XExtDisplayInfo *info = find_display(dpy);
1149 xOvlReadScreenReq *req;
1150 xOvlReadScreenReply rep;
1151 char *data;
1152 long nbytes;
1153 XImage *image;
1155 OvlCheckExtension(dpy, info, NULL);
1157 LockDisplay(dpy);
1158 GetReq (OvlReadScreen, req);
1159 req->reqType = info->codes->major_opcode;
1160 req->ovlReqType = X_OvlReadScreen;
1161 req->window = w;
1162 req->x = x;
1163 req->y = y;
1164 req->width = width;
1165 req->height = height;
1166 req->includeCursor = includeCursor;
1168 if ( (_XReply(dpy, (xReply *)(&rep), 0, xFalse) == 0)
1169 || (rep.length == 0))
1171 UnlockDisplay(dpy);
1172 SyncHandle();
1173 return NULL;
1175 if (rep.length < (INT_MAX >> 2)) {
1176 nbytes = (long)rep.length << 2;
1177 data = Xmalloc((size_t)nbytes);
1178 } else {
1179 data = NULL;
1181 if (!data) {
1182 _XEatDataWords(dpy, rep.length);
1183 UnlockDisplay(dpy);
1184 SyncHandle();
1185 return NULL;
1187 _XReadPad (dpy, data, nbytes);
1188 image = XCreateImage(dpy, None,
1189 24, ZPixmap, 0, data, width, height,
1190 dpy->bitmap_pad, 0);
1191 if (image) {
1192 image->red_mask = READSCREEN_REDMASK;
1193 image->green_mask = READSCREEN_GREENMASK;
1194 image->blue_mask = READSCREEN_BLUEMASK;
1195 } else {
1196 Xfree(data);
1198 UnlockDisplay(dpy);
1199 SyncHandle();
1200 return image;
1204 XSolarisOvlSelectStatus
1205 XSolarisOvlSelectPartner(
1206 Display *dpy,
1207 int screen,
1208 VisualID vid,
1209 XSolarisOvlSelectType vistype,
1210 int numCriteria,
1211 XSolarisOvlVisualCriteria *pCriteria,
1212 XVisualInfo *visinfoReturn,
1213 unsigned long *unmetCriteriaReturn
1216 XExtDisplayInfo *info = find_display(dpy);
1217 Screen *scr;
1218 XOvlScrExtData *scrextdata;
1219 XOvlVisPair *vispair;
1220 int i,
1222 Depth *depth;
1223 XOvlVisInfo partner;
1224 XOvlVisualMatch curMatch,
1225 betterMatch,
1226 bestMatch;
1227 XOvlVisEnumData visEnumData;
1228 unsigned long hardpreferred,
1229 softpreferred;
1231 OvlCheckExtension(dpy, info, XSolarisOvlFailure);
1233 LockDisplay(dpy);
1234 scr = ScreenOfDisplay(dpy, screen);
1235 scrextdata = find_screendata(dpy, screen, info);
1236 if (!scrextdata) {
1237 UnlockDisplay(dpy);
1238 SyncHandle();
1239 return XSolarisOvlFailure;
1241 curMatch.screen = screen;
1242 curMatch.partner.vid = vid;
1243 if (!find_visual(scr, vid, &curMatch.partner.vis, &curMatch.partner.depth))
1245 UnlockDisplay(dpy);
1246 SyncHandle();
1247 return XSolarisOvlFailure;
1249 curMatch.searchtype = vistype;
1250 SetWorstMatch(&bestMatch);
1251 for (i = numCriteria; i > 0; --i) {
1252 SetWorstMatch(&betterMatch);
1253 curMatch.partnerpreferred = True;
1254 vispair = (XOvlVisPair *)(scrextdata->extdata.private_data);
1255 for (j = scrextdata->numVisPairs; j > 0; --j) {
1256 if (vid ==
1257 ((vistype == XSolarisOvlSelectBestOverlay)
1258 ? (vispair->underlay.vid)
1259 : (vispair->overlay.vid)))
1261 curMatch.candidate = (vistype == XSolarisOvlSelectBestOverlay)
1262 ? vispair->overlay
1263 : vispair->underlay;
1264 ComputeVisualMatch(dpy, &curMatch, pCriteria, info);
1265 if (IsPerfectMatch(&curMatch)) {
1266 set_visinfo(visinfoReturn, &curMatch);
1267 UnlockDisplay(dpy);
1268 SyncHandle();
1269 return XSolarisOvlSuccess;
1271 if (IsBetterMatch(&curMatch, &betterMatch)) {
1272 betterMatch = curMatch;
1275 vispair++;
1277 if (!scrextdata->pairsRestricted) {
1278 curMatch.partnerpreferred = False;
1279 vis_enum_init(scr, &visEnumData);
1280 while (vis_enum_next(&visEnumData,
1281 &curMatch.candidate.vis,
1282 &curMatch.candidate.depth))
1284 curMatch.candidate.vid = curMatch.candidate.vis->visualid;
1285 ComputeVisualMatch(dpy, &curMatch, pCriteria, info);
1286 if (IsPerfectMatch(&curMatch)) {
1287 set_visinfo(visinfoReturn, &curMatch);
1288 UnlockDisplay(dpy);
1289 SyncHandle();
1290 return XSolarisOvlSuccess;
1292 if (IsBetterMatch(&curMatch, &betterMatch)) {
1293 betterMatch = curMatch;
1297 if (IsQualifiedMatch(&betterMatch)) {
1298 set_visinfo(visinfoReturn, &betterMatch);
1299 *unmetCriteriaReturn = betterMatch.softfailures;
1300 UnlockDisplay(dpy);
1301 SyncHandle();
1302 return XSolarisOvlQualifiedSuccess;
1304 if (IsBetterMatch(&betterMatch, &bestMatch)) {
1305 bestMatch = betterMatch;
1307 pCriteria++;
1309 *unmetCriteriaReturn = bestMatch.hardfailures | bestMatch.softfailures;
1310 UnlockDisplay(dpy);
1311 SyncHandle();
1312 return XSolarisOvlCriteriaFailure;
1316 XSolarisOvlSelectStatus
1317 XSolarisOvlSelectPair(
1318 Display *dpy,
1319 int screen,
1320 int numCriteria,
1321 XSolarisOvlPairCriteria *pCriteria,
1322 XVisualInfo *ovVisinfoReturn,
1323 XVisualInfo *unVisinfoReturn,
1324 unsigned long *unmetOvCriteriaReturn,
1325 unsigned long *unmetUnCriteriaReturn)
1327 XExtDisplayInfo *info = find_display(dpy);
1328 Screen *scr;
1329 XOvlScrExtData *scrextdata;
1330 XOvlVisPair *vispair;
1331 int i,
1333 XOvlVisualMatch curOvMatch, curUnMatch,
1334 betterOvMatch, betterUnMatch,
1335 bestOvMatch, bestUnMatch;
1336 XOvlVisEnumData ovVisEnumData, unVisEnumData;
1338 OvlCheckExtension(dpy, info, XSolarisOvlFailure);
1339 LockDisplay(dpy);
1340 scr = ScreenOfDisplay(dpy, screen);
1341 scrextdata = find_screendata(dpy, screen, info);
1342 if (!scrextdata) {
1343 UnlockDisplay(dpy);
1344 SyncHandle();
1345 return XSolarisOvlFailure;
1347 curOvMatch.screen = curUnMatch.screen = screen;
1348 curOvMatch.searchtype = XSolarisOvlSelectBestUnderlay;
1349 curUnMatch.searchtype = XSolarisOvlSelectBestOverlay;
1350 SetWorstMatch(&bestOvMatch);
1351 SetWorstMatch(&bestUnMatch);
1352 for (i = numCriteria; i > 0; --i) {
1353 SetWorstMatch(&betterOvMatch);
1354 SetWorstMatch(&betterUnMatch);
1355 curOvMatch.partnerpreferred = curUnMatch.partnerpreferred = True;
1356 vispair = (XOvlVisPair *)(scrextdata->extdata.private_data);
1357 for (j = scrextdata->numVisPairs; j > 0; --j) {
1358 curOvMatch.candidate = curUnMatch.partner = vispair->overlay;
1359 curOvMatch.partner = curUnMatch.candidate = vispair->underlay;
1360 ComputeVisualMatch(dpy, &curOvMatch,
1361 &pCriteria->overlayCriteria, info);
1362 ComputeVisualMatch(dpy, &curUnMatch,
1363 &pCriteria->underlayCriteria, info);
1364 if (IsPerfectPair(&curOvMatch, &curUnMatch)) {
1365 set_visinfo(unVisinfoReturn, &curUnMatch);
1366 set_visinfo(ovVisinfoReturn, &curOvMatch);
1367 UnlockDisplay(dpy);
1368 SyncHandle();
1369 return XSolarisOvlSuccess;
1371 if (IsBetterPair(&curOvMatch, &curUnMatch,
1372 &betterOvMatch, &betterUnMatch))
1374 betterOvMatch = curOvMatch;
1375 betterUnMatch = curUnMatch;
1377 vispair++;
1379 if (!scrextdata->pairsRestricted) {
1380 curOvMatch.partnerpreferred = False;
1381 curUnMatch.partnerpreferred = False;
1382 vis_enum_init(scr, &ovVisEnumData);
1383 while (vis_enum_next(&ovVisEnumData,
1384 &curOvMatch.candidate.vis,
1385 &curOvMatch.candidate.depth))
1387 curOvMatch.candidate.vid = curOvMatch.candidate.vis->visualid;
1388 curUnMatch.partner = curOvMatch.candidate;
1389 vis_enum_init(scr, &unVisEnumData);
1390 while (vis_enum_next(&unVisEnumData,
1391 &curUnMatch.candidate.vis,
1392 &curUnMatch.candidate.depth))
1394 curUnMatch.candidate.vid =
1395 curUnMatch.candidate.vis->visualid;
1396 curOvMatch.partner = curUnMatch.candidate;
1397 ComputeVisualMatch(dpy, &curOvMatch,
1398 &pCriteria->overlayCriteria, info);
1399 ComputeVisualMatch(dpy, &curUnMatch,
1400 &pCriteria->underlayCriteria, info);
1401 if (IsPerfectPair(&curOvMatch, &curUnMatch)) {
1402 set_visinfo(unVisinfoReturn, &curUnMatch);
1403 set_visinfo(ovVisinfoReturn, &curOvMatch);
1404 UnlockDisplay(dpy);
1405 SyncHandle();
1406 return XSolarisOvlSuccess;
1408 if (IsBetterPair(&curOvMatch, &curUnMatch,
1409 &betterOvMatch, &betterUnMatch))
1411 betterOvMatch = curOvMatch;
1412 betterUnMatch = curUnMatch;
1417 if (IsQualifiedPair(&betterOvMatch, &betterUnMatch)) {
1418 set_visinfo(ovVisinfoReturn, &betterOvMatch);
1419 set_visinfo(unVisinfoReturn, &betterUnMatch);
1420 *unmetOvCriteriaReturn = betterOvMatch.softfailures;
1421 *unmetUnCriteriaReturn = betterUnMatch.softfailures;
1422 UnlockDisplay(dpy);
1423 SyncHandle();
1424 return XSolarisOvlQualifiedSuccess;
1426 if (IsBetterPair(&betterOvMatch, &betterUnMatch,
1427 &bestOvMatch, &bestUnMatch))
1429 bestOvMatch = betterOvMatch;
1430 bestUnMatch = betterUnMatch;
1432 pCriteria++;
1434 *unmetOvCriteriaReturn = bestOvMatch.hardfailures|bestOvMatch.softfailures;
1435 *unmetUnCriteriaReturn = bestUnMatch.hardfailures|bestUnMatch.softfailures;
1436 UnlockDisplay(dpy);
1437 SyncHandle();
1438 return XSolarisOvlCriteriaFailure;