TransOvl.c revision 366
366N/A/* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
366N/A *
366N/A * Permission is hereby granted, free of charge, to any person obtaining a
366N/A * copy of this software and associated documentation files (the
366N/A * "Software"), to deal in the Software without restriction, including
366N/A * without limitation the rights to use, copy, modify, merge, publish,
366N/A * distribute, and/or sell copies of the Software, and to permit persons
366N/A * to whom the Software is furnished to do so, provided that the above
366N/A * copyright notice(s) and this permission notice appear in all copies of
366N/A * the Software and that both the above copyright notice(s) and this
366N/A * permission notice appear in supporting documentation.
366N/A *
366N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
366N/A * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
366N/A * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
366N/A * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
366N/A * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
366N/A * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
366N/A * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
366N/A * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
366N/A * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
366N/A *
366N/A * Except as contained in this notice, the name of a copyright holder
366N/A * shall not be used in advertising or otherwise to promote the sale, use
366N/A * or other dealings in this Software without prior written authorization
366N/A * of the copyright holder.
366N/A */
366N/A
366N/A#pragma ident "@(#)TransOvl.c 1.6 08/03/12 SMI"
366N/A
366N/A/*
366N/A * TransOvl.c - the client side interface to the Transparent Overlays
366N/A * extension.
366N/A */
366N/A
366N/A#define NEED_EVENTS
366N/A#define NEED_REPLIES
366N/A#include <X11/Xlibint.h>
366N/A#include <X11/Xutil.h>
366N/A#include <X11/extensions/extutil.h>
366N/A#include <X11/extensions/transovlstr.h>
366N/A#include <X11/extensions/multibuf.h>
366N/A
366N/Atypedef struct {
366N/A XExtData extdata;
366N/A int numVisPairs;
366N/A Bool pairsRestricted;
366N/A int visdatatypes;
366N/A} XOvlScrExtData;
366N/A
366N/Atypedef struct {
366N/A VisualID vid;
366N/A Visual *vis;
366N/A int depth;
366N/A} XOvlVisInfo;
366N/A
366N/Atypedef struct {
366N/A XOvlVisInfo overlay;
366N/A XOvlVisInfo underlay;
366N/A} XOvlVisPair;
366N/A
366N/A#ifdef _LP64
366N/A#define XOvlMBXBuffers (1L << 0)
366N/A#define XOvlSharedPixels (1L << 1)
366N/A#define XOvlSharedColors (1L << 2)
366N/A
366N/A#define XOVL_MAX_BUFFERS (~0L)
366N/A#define XOVL_ALL_PLANES (~0L)
366N/A#define XOVL_ANY_POOL (~0L)
366N/A#else /* _LP64 */
366N/A#define XOvlMBXBuffers (1 << 0)
366N/A#define XOvlSharedPixels (1 << 1)
366N/A#define XOvlSharedColors (1 << 2)
366N/A
366N/A#define XOVL_MAX_BUFFERS (~0)
366N/A#define XOVL_ALL_PLANES (~0)
366N/A#define XOVL_ANY_POOL (~0)
366N/A#endif /* _LP64 */
366N/A
366N/Atypedef struct {
366N/A XExtData extdata;
366N/A int datatypes;
366N/A int numBuffers;
366N/A unsigned long ovplanes;
366N/A unsigned long unplanes;
366N/A unsigned long clutpool;
366N/A int clutcount;
366N/A} XOvlVisExtData;
366N/A
366N/Atypedef struct {
366N/A XExtData extdata;
366N/A XSolarisOvlPaintType paintType;
366N/A} XOvlGCExtData;
366N/A
366N/Atypedef struct {
366N/A int screen;
366N/A XOvlVisInfo candidate;
366N/A XOvlVisInfo partner;
366N/A Bool partnerpreferred;
366N/A XSolarisOvlSelectType searchtype;
366N/A unsigned long hardfailures;
366N/A unsigned long softfailures;
366N/A int numhardfailures;
366N/A int numsoftfailures;
366N/A} XOvlVisualMatch;
366N/A
366N/Atypedef struct {
366N/A int nDepths;
366N/A Depth *pDepths;
366N/A int depth;
366N/A int nVisuals;
366N/A Visual *pVisuals;
366N/A} XOvlVisEnumData;
366N/A
366N/Astatic int close_display();
366N/A
366N/Astatic XExtensionInfo *ext_info;
366N/Astatic char *ext_name = OVLNAME;
366N/Astatic XExtensionHooks ext_hooks = {
366N/A NULL, /* create_gc */
366N/A NULL, /* copy_gc */
366N/A NULL, /* flush_gc */
366N/A NULL, /* free_gc */
366N/A NULL, /* create_font */
366N/A NULL, /* free_font */
366N/A close_display, /* close_display */
366N/A NULL, /* wire_to_event */
366N/A NULL, /* event_to_wire */
366N/A NULL, /* error */
366N/A NULL, /* error_string */
366N/A};
366N/A
366N/Astatic
366N/AXEXT_GENERATE_CLOSE_DISPLAY(close_display,
366N/A ext_info)
366N/A
366N/Astatic
366N/AXEXT_GENERATE_FIND_DISPLAY(find_display,
366N/A ext_info, ext_name, &ext_hooks,
366N/A OvlNumberEvents, NULL)
366N/A
366N/A#define OvlCheckExtension(dpy,i,val) \
366N/A XextCheckExtension (dpy, i, ext_name, val)
366N/A#define OvlSimpleCheckExtension(dpy,i) \
366N/A XextSimpleCheckExtension (dpy, i, ext_name)
366N/A
366N/A
366N/A/**********************************************************************/
366N/A
366N/A/*
366N/A * The utility function _XVIDtoVisual could be used, but we already
366N/A * know the screen structure where the visual is to be found, so there
366N/A * is no need to scan all the screens on the display. This procedure
366N/A * performs a more direct scan for the visual.
366N/A */
366N/Astatic Bool
366N/Afind_visual(
366N/A Screen *scr,
366N/A VisualID vid,
366N/A Visual **visReturn,
366N/A int *depthReturn
366N/A)
366N/A{
366N/A Depth *depth;
366N/A Visual *vis;
366N/A
366N/A for (depth = scr->depths; depth < (scr->depths + scr->ndepths); depth++) {
366N/A if (depth->visuals) {
366N/A for (vis = depth->visuals;
366N/A vis < (depth->visuals + depth->nvisuals);
366N/A vis++)
366N/A {
366N/A if (vis->visualid == vid) {
366N/A *visReturn = vis;
366N/A *depthReturn = depth->depth;
366N/A return True;
366N/A }
366N/A }
366N/A }
366N/A }
366N/A return False;
366N/A}
366N/A
366N/A
366N/Astatic void
366N/Avis_enum_init(
366N/A Screen *scr,
366N/A XOvlVisEnumData *visEnumData
366N/A)
366N/A{
366N/A visEnumData->nDepths = scr->ndepths;
366N/A visEnumData->pDepths = scr->depths;
366N/A visEnumData->depth = 0;
366N/A visEnumData->nVisuals = 0;
366N/A visEnumData->pVisuals = NULL;
366N/A}
366N/A
366N/A
366N/Astatic Bool
366N/Avis_enum_next(
366N/A XOvlVisEnumData *visEnumData,
366N/A Visual **visReturn,
366N/A int *depthReturn
366N/A)
366N/A{
366N/A int ndepths;
366N/A Depth *depth;
366N/A
366N/A if (!visEnumData->nVisuals) {
366N/A ndepths = visEnumData->nDepths;
366N/A depth = visEnumData->pDepths;
366N/A while (ndepths) {
366N/A if (depth->visuals) {
366N/A break;
366N/A }
366N/A ndepths--;
366N/A depth++;
366N/A }
366N/A if (!ndepths) {
366N/A return False;
366N/A }
366N/A visEnumData->nDepths = ndepths - 1;
366N/A visEnumData->pDepths = depth + 1;
366N/A visEnumData->depth = depth->depth;
366N/A visEnumData->nVisuals = depth->nvisuals;
366N/A visEnumData->pVisuals = depth->visuals;
366N/A }
366N/A visEnumData->nVisuals--;
366N/A *visReturn = visEnumData->pVisuals++;
366N/A *depthReturn = visEnumData->depth;
366N/A return True;
366N/A}
366N/A
366N/A
366N/Astatic XOvlScrExtData *
366N/Afind_screendata(
366N/A Display *dpy,
366N/A int screen,
366N/A XExtDisplayInfo *info
366N/A)
366N/A{
366N/A XOvlScrExtData *scrextdata;
366N/A Screen *scr;
366N/A xOvlGetPartnersReq *req;
366N/A xOvlGetPartnersReply rep;
366N/A unsigned long nbytes;
366N/A unsigned long numPairs;
366N/A XOvlVisPair *vispairs,
366N/A *vispair;
366N/A XOvlVidPair vidpair;
366N/A XEDataObject obj;
366N/A
366N/A obj.screen = scr = ScreenOfDisplay(dpy, screen);
366N/A scrextdata = (XOvlScrExtData *)
366N/A XFindOnExtensionList(XEHeadOfExtensionList(obj),
366N/A info->codes->extension);
366N/A if (!scrextdata) {
366N/A GetReq(OvlGetPartners, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->ovlReqType = X_OvlGetPartners;
366N/A req->screen = screen;
366N/A if (_XReply(dpy, (xReply *)(&rep), 0, xFalse)) {
366N/A numPairs = rep.numPairs;
366N/A nbytes = numPairs * sizeof(XOvlVisPair);
366N/A scrextdata = Xmalloc(sizeof(XOvlScrExtData));
366N/A vispairs = (XOvlVisPair *)Xmalloc(nbytes);
366N/A if (scrextdata && vispairs) {
366N/A scrextdata->extdata.number = info->codes->extension;
366N/A scrextdata->extdata.free_private = NULL;
366N/A scrextdata->extdata.private_data = (char *)vispairs;
366N/A scrextdata->numVisPairs = rep.numPairs;
366N/A scrextdata->pairsRestricted = rep.restricted;
366N/A /* BugId: 4126680 - Purify detects reads in uninitialized
366N/A memory generating random results. culprit was id'd to
366N/A be the uninitialized field visdatatypes */
366N/A scrextdata->visdatatypes = 0;
366N/A vispair = vispairs;
366N/A while (numPairs--) {
366N/A _XRead(dpy, (char *)(&vidpair), sizeof(vidpair));
366N/A vispair->overlay.vid = vidpair.overlayVid;
366N/A vispair->underlay.vid = vidpair.underlayVid;
366N/A if ( !find_visual(scr, vidpair.overlayVid,
366N/A &vispair->overlay.vis,
366N/A &vispair->overlay.depth)
366N/A || !find_visual(scr, vidpair.underlayVid,
366N/A &vispair->underlay.vis,
366N/A &vispair->underlay.depth))
366N/A {
366N/A Xfree(vispairs);
366N/A Xfree(scrextdata);
366N/A scrextdata = NULL;
366N/A if (numPairs) {
366N/A nbytes = numPairs * sizeof(XOvlVidPair);
366N/A _XEatData(dpy, nbytes);
366N/A }
366N/A break;
366N/A }
366N/A vispair++;
366N/A }
366N/A if (scrextdata) {
366N/A XAddToExtensionList(XEHeadOfExtensionList(obj),
366N/A &(scrextdata->extdata));
366N/A }
366N/A } else {
366N/A Xfree(scrextdata);
366N/A Xfree(vispairs);
366N/A nbytes = numPairs * sizeof(XOvlVidPair);
366N/A _XEatData(dpy, nbytes);
366N/A scrextdata = NULL;
366N/A }
366N/A }
366N/A }
366N/A return scrextdata;
366N/A}
366N/A
366N/A
366N/Astatic XOvlVisExtData *
366N/Afind_visdata(
366N/A Visual *vis,
366N/A XExtDisplayInfo *info
366N/A)
366N/A{
366N/A XOvlVisExtData *visextdata;
366N/A XEDataObject obj;
366N/A
366N/A obj.visual = vis;
366N/A visextdata = (XOvlVisExtData *)
366N/A XFindOnExtensionList(XEHeadOfExtensionList(obj),
366N/A info->codes->extension);
366N/A if (!visextdata) {
366N/A visextdata = Xmalloc(sizeof(XOvlVisExtData));
366N/A if (visextdata) {
366N/A visextdata->extdata.number = info->codes->extension;
366N/A visextdata->extdata.free_private = NULL;
366N/A visextdata->extdata.private_data = NULL;
366N/A visextdata->datatypes = 0;
366N/A XAddToExtensionList(XEHeadOfExtensionList(obj),
366N/A &(visextdata->extdata));
366N/A }
366N/A }
366N/A
366N/A return visextdata;
366N/A}
366N/A
366N/A
366N/Astatic int
366N/Abitcount(
366N/A unsigned long mask
366N/A)
366N/A{
366N/A int count;
366N/A
366N/A count = 0;
366N/A while (mask) {
366N/A count++;
366N/A mask &= (mask - 1);
366N/A }
366N/A return count;
366N/A}
366N/A
366N/A
366N/Astatic int
366N/AGetNumMBXBuffers(
366N/A Display *dpy,
366N/A int screen,
366N/A Visual *candidateVis,
366N/A XExtDisplayInfo *info)
366N/A{
366N/A XOvlVisExtData *candidateData;
366N/A XOvlScrExtData *scrextdata;
366N/A int i,
366N/A nmono,
366N/A nstereo;
366N/A XmbufBufferInfo *mono_info,
366N/A *stereo_info;
366N/A Visual *vis;
366N/A int depth;
366N/A XOvlVisExtData *visextdata;
366N/A Screen *scr;
366N/A
366N/A candidateData = find_visdata(candidateVis, info);
366N/A if (!candidateData) {
366N/A /*
366N/A * Cannot store data for this visual, assume the worst case.
366N/A */
366N/A return 0;
366N/A }
366N/A if (!(candidateData->datatypes & XOvlMBXBuffers)) {
366N/A scrextdata = find_screendata(dpy, screen, info);
366N/A if (!(scrextdata->visdatatypes & XOvlMBXBuffers)) {
366N/A /*
366N/A * We haven't queried the MBX extension for the buffer
366N/A * data on this screen yet. Call XmbufGetScreenInfo
366N/A * and fill in the data for all the returned visuals.
366N/A */
366N/A scr = ScreenOfDisplay(dpy, screen);
366N/A scrextdata->visdatatypes |= XOvlMBXBuffers;
366N/A XmbufGetScreenInfo(dpy, RootWindow(dpy, screen),
366N/A &nmono, &mono_info,
366N/A &nstereo, &stereo_info);
366N/A for (i = 0; i < nmono; i++) {
366N/A if (find_visual(scr, mono_info[i].visualid, &vis, &depth)) {
366N/A visextdata = find_visdata(vis, info);
366N/A if (visextdata) {
366N/A visextdata->numBuffers = mono_info[i].max_buffers;
366N/A if (!visextdata->numBuffers) {
366N/A visextdata->numBuffers = XOVL_MAX_BUFFERS;
366N/A }
366N/A visextdata->datatypes |= XOvlMBXBuffers;
366N/A } else {
366N/A /*
366N/A * We were unable to finish the query, so mark
366N/A * the data as unqueried so we can try again later.
366N/A */
366N/A scrextdata->visdatatypes &= ~XOvlMBXBuffers;
366N/A }
366N/A }
366N/A }
366N/A XFree(mono_info);
366N/A XFree(stereo_info);
366N/A }
366N/A if (!(candidateData->datatypes & XOvlMBXBuffers)) {
366N/A /*
366N/A * No data was returned from MBX for this visual,
366N/A * so fill in a default value. Only mark the
366N/A * data valid if the server query completed.
366N/A */
366N/A candidateData->numBuffers = 0;
366N/A if (scrextdata->visdatatypes & XOvlMBXBuffers) {
366N/A candidateData->datatypes |= XOvlMBXBuffers;
366N/A }
366N/A }
366N/A }
366N/A
366N/A return candidateData->numBuffers;
366N/A}
366N/A
366N/A
366N/Astatic Bool
366N/ACheckSharedPixels(
366N/A Display *dpy,
366N/A int screen,
366N/A XSolarisOvlSelectType searchtype,
366N/A Visual *candidateVis,
366N/A Visual *partnerVis,
366N/A XExtDisplayInfo *info)
366N/A{
366N/A XOvlVisExtData *candidateData,
366N/A *partnerData;
366N/A XOvlScrExtData *scrextdata;
366N/A Screen *scr;
366N/A xOvlGetSharedPixelsReq *req;
366N/A xOvlGetSharedPixelsReply rep;
366N/A unsigned int i;
366N/A XOvlPGInfo pginfo;
366N/A Visual *vis;
366N/A int depth;
366N/A XOvlVisExtData *visextdata;
366N/A unsigned long commonplanes;
366N/A
366N/A candidateData = find_visdata(candidateVis, info);
366N/A partnerData = find_visdata(partnerVis, info);
366N/A if (!candidateData || !partnerData) {
366N/A /*
366N/A * Cannot store data for these visuals, assume the worst case.
366N/A */
366N/A return True;
366N/A }
366N/A if ( !(candidateData->datatypes & XOvlSharedPixels)
366N/A || !( partnerData->datatypes & XOvlSharedPixels))
366N/A {
366N/A scrextdata = find_screendata(dpy, screen, info);
366N/A if (!(scrextdata->visdatatypes & XOvlSharedPixels)) {
366N/A /*
366N/A * We haven't queried the server for plane group data
366N/A * on this screen yet. Send the query and fill in
366N/A * the data for the visuals indicated in the reply.
366N/A */
366N/A scr = ScreenOfDisplay(dpy, screen);
366N/A scrextdata->visdatatypes |= XOvlSharedPixels;
366N/A GetReq(OvlGetSharedPixels, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->ovlReqType = X_OvlGetSharedPixels;
366N/A req->screen = screen;
366N/A if (_XReply(dpy, (xReply *)(&rep), 0, xFalse)) {
366N/A for (i = 0; i < rep.numPGInfos; i++) {
366N/A _XRead(dpy, (char *)(&pginfo), sizeof(pginfo));
366N/A if (find_visual(scr, pginfo.vid, &vis, &depth)) {
366N/A visextdata = find_visdata(vis, info);
366N/A if (visextdata) {
366N/A visextdata->ovplanes = pginfo.ovplanes;
366N/A visextdata->unplanes = pginfo.unplanes;
366N/A visextdata->datatypes |= XOvlSharedPixels;
366N/A } else {
366N/A /*
366N/A * We were unable to finish the query, so mark
366N/A * the data as unqueried so we can try again later.
366N/A */
366N/A scrextdata->visdatatypes &= ~XOvlSharedPixels;
366N/A }
366N/A }
366N/A }
366N/A }
366N/A }
366N/A if (!(candidateData->datatypes & XOvlSharedPixels)) {
366N/A /*
366N/A * No data was returned from the server for this
366N/A * visual, so fill in a default value. Only mark
366N/A * the data valid if the server query completed.
366N/A */
366N/A candidateData->ovplanes = XOVL_ALL_PLANES;
366N/A candidateData->unplanes = XOVL_ALL_PLANES;
366N/A if (scrextdata->visdatatypes & XOvlSharedPixels) {
366N/A candidateData->datatypes |= XOvlSharedPixels;
366N/A }
366N/A }
366N/A if (!(partnerData->datatypes & XOvlSharedPixels)) {
366N/A /*
366N/A * No data was returned from the server for this
366N/A * visual, so fill in a default value. Only mark
366N/A * the data valid if the server query completed.
366N/A */
366N/A partnerData->ovplanes = XOVL_ALL_PLANES;
366N/A partnerData->unplanes = XOVL_ALL_PLANES;
366N/A if (scrextdata->visdatatypes & XOvlSharedPixels) {
366N/A partnerData->datatypes |= XOvlSharedPixels;
366N/A }
366N/A }
366N/A }
366N/A
366N/A if (searchtype == XSolarisOvlSelectBestOverlay) {
366N/A commonplanes = candidateData->ovplanes & partnerData->unplanes;
366N/A } else {
366N/A commonplanes = candidateData->unplanes & partnerData->ovplanes;
366N/A }
366N/A return commonplanes ? True : False;
366N/A}
366N/A
366N/A
366N/Astatic Bool
366N/ACheckSharedColors(
366N/A Display *dpy,
366N/A int screen,
366N/A Visual *candidateVis,
366N/A Visual *partnerVis,
366N/A XExtDisplayInfo *info)
366N/A{
366N/A XOvlVisExtData *candidateData,
366N/A *partnerData;
366N/A XOvlScrExtData *scrextdata;
366N/A Screen *scr;
366N/A xOvlGetSharedColorsReq *req;
366N/A xOvlGetSharedColorsReply rep;
366N/A unsigned int i;
366N/A XOvlClutInfo clutinfo;
366N/A Visual *vis;
366N/A int depth;
366N/A XOvlVisExtData *visextdata;
366N/A
366N/A candidateData = find_visdata(candidateVis, info);
366N/A partnerData = find_visdata(partnerVis, info);
366N/A if (!candidateData || !partnerData) {
366N/A /*
366N/A * Cannot store data for these visuals, assume the worst case.
366N/A */
366N/A return True;
366N/A }
366N/A if ( !(candidateData->datatypes & XOvlSharedColors)
366N/A || !( partnerData->datatypes & XOvlSharedColors))
366N/A {
366N/A scrextdata = find_screendata(dpy, screen, info);
366N/A if (!(scrextdata->visdatatypes & XOvlSharedColors)) {
366N/A /*
366N/A * We haven't queried the server for clut pool data
366N/A * on this screen yet. Send the query and fill in
366N/A * the data for the visuals indicated in the reply.
366N/A */
366N/A scr = ScreenOfDisplay(dpy, screen);
366N/A scrextdata->visdatatypes |= XOvlSharedColors;
366N/A GetReq(OvlGetSharedColors, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->ovlReqType = X_OvlGetSharedColors;
366N/A req->screen = screen;
366N/A if (_XReply(dpy, (xReply *)(&rep), 0, xFalse)) {
366N/A for (i = 0; i < rep.numClutInfos; i++) {
366N/A _XRead(dpy, (char *)(&clutinfo), sizeof(clutinfo));
366N/A if (find_visual(scr, clutinfo.vid, &vis, &depth)) {
366N/A visextdata = find_visdata(vis, info);
366N/A if (visextdata) {
366N/A visextdata->clutpool = (1 << clutinfo.pool);
366N/A visextdata->clutcount = clutinfo.count;
366N/A visextdata->datatypes |= XOvlSharedColors;
366N/A } else {
366N/A /*
366N/A * We were unable to finish the query, so mark
366N/A * the data as unqueried so we can try again later.
366N/A */
366N/A scrextdata->visdatatypes &= ~XOvlSharedColors;
366N/A }
366N/A }
366N/A }
366N/A }
366N/A }
366N/A if (!(candidateData->datatypes & XOvlSharedColors)) {
366N/A /*
366N/A * No data was returned from the server for this
366N/A * visual, so fill in a default value. Only mark
366N/A * the data valid if the server query completed.
366N/A */
366N/A candidateData->clutpool = XOVL_ANY_POOL;
366N/A candidateData->clutcount = 1;
366N/A if (scrextdata->visdatatypes & XOvlSharedColors) {
366N/A candidateData->datatypes |= XOvlSharedColors;
366N/A }
366N/A }
366N/A if (!(partnerData->datatypes & XOvlSharedColors)) {
366N/A /*
366N/A * No data was returned from the server for this
366N/A * visual, so fill in a default value. Only mark
366N/A * the data valid if the server query completed.
366N/A */
366N/A partnerData->clutpool = XOVL_ANY_POOL;
366N/A partnerData->clutcount = 1;
366N/A if (scrextdata->visdatatypes & XOvlSharedColors) {
366N/A partnerData->datatypes |= XOvlSharedColors;
366N/A }
366N/A }
366N/A }
366N/A
366N/A return ( (candidateData->clutpool & partnerData->clutpool)
366N/A && candidateData->clutcount <= 1)
366N/A ? True
366N/A : False;
366N/A}
366N/A
366N/A
366N/Astatic void
366N/AComputeVisualMatch(
366N/A Display *dpy,
366N/A XOvlVisualMatch *match,
366N/A XSolarisOvlVisualCriteria *pCriteria,
366N/A XExtDisplayInfo *info)
366N/A{
366N/A Visual *vis = match->candidate.vis;
366N/A unsigned long hardmask,
366N/A softmask,
366N/A mask;
366N/A unsigned long hardfailures,
366N/A softfailures;
366N/A
366N/A hardmask = pCriteria->hardCriteriaMask;
366N/A softmask = pCriteria->softCriteriaMask;
366N/A mask = hardmask | softmask;
366N/A hardfailures = 0;
366N/A softfailures = 0;
366N/A
366N/A if ( (mask & XSolarisOvlVisualClass)
366N/A && (vis->class != pCriteria->c_class))
366N/A {
366N/A hardfailures |= hardmask & XSolarisOvlVisualClass;
366N/A softfailures |= softmask & XSolarisOvlVisualClass;
366N/A }
366N/A if ( (mask & XSolarisOvlDepth)
366N/A && (match->candidate.depth != pCriteria->depth))
366N/A {
366N/A hardfailures |= hardmask & XSolarisOvlDepth;
366N/A softfailures |= softmask & XSolarisOvlDepth;
366N/A }
366N/A if ( (mask & XSolarisOvlMinColors)
366N/A && (vis->map_entries < pCriteria->minColors))
366N/A {
366N/A hardfailures |= hardmask & XSolarisOvlMinColors;
366N/A softfailures |= softmask & XSolarisOvlMinColors;
366N/A }
366N/A if ( (mask & XSolarisOvlMinRed)
366N/A && ((1 << bitcount(vis->red_mask)) < pCriteria->minRed))
366N/A {
366N/A hardfailures |= hardmask & XSolarisOvlMinRed;
366N/A softfailures |= softmask & XSolarisOvlMinRed;
366N/A }
366N/A if ( (mask & XSolarisOvlMinGreen)
366N/A && ((1 << bitcount(vis->green_mask)) < pCriteria->minGreen))
366N/A {
366N/A hardfailures |= hardmask & XSolarisOvlMinGreen;
366N/A softfailures |= softmask & XSolarisOvlMinGreen;
366N/A }
366N/A if ( (mask & XSolarisOvlMinBlue)
366N/A && ((1 << bitcount(vis->blue_mask)) < pCriteria->minBlue))
366N/A {
366N/A hardfailures |= hardmask & XSolarisOvlMinBlue;
366N/A softfailures |= softmask & XSolarisOvlMinBlue;
366N/A }
366N/A if ( (mask & XSolarisOvlMinBitsPerRGB)
366N/A && (vis->bits_per_rgb < pCriteria->minBitsPerRGB))
366N/A {
366N/A hardfailures |= hardmask & XSolarisOvlMinBitsPerRGB;
366N/A softfailures |= softmask & XSolarisOvlMinBitsPerRGB;
366N/A }
366N/A if ( (mask & XSolarisOvlMinBuffers)
366N/A && ( GetNumMBXBuffers(dpy, match->screen, vis, info)
366N/A < pCriteria->minBuffers))
366N/A {
366N/A hardfailures |= hardmask & XSolarisOvlMinBuffers;
366N/A softfailures |= softmask & XSolarisOvlMinBuffers;
366N/A }
366N/A if ( (mask & XSolarisOvlUnsharedPixels)
366N/A && CheckSharedPixels(dpy, match->screen, match->searchtype,
366N/A vis, match->partner.vis, info))
366N/A {
366N/A hardfailures |= hardmask & XSolarisOvlUnsharedPixels;
366N/A softfailures |= softmask & XSolarisOvlUnsharedPixels;
366N/A }
366N/A if ( (mask & XSolarisOvlUnsharedColors)
366N/A && CheckSharedColors(dpy, match->screen,
366N/A vis, match->partner.vis, info))
366N/A {
366N/A hardfailures |= hardmask & XSolarisOvlUnsharedColors;
366N/A softfailures |= softmask & XSolarisOvlUnsharedColors;
366N/A }
366N/A if ( (mask & XSolarisOvlPreferredPartner)
366N/A && (!match->partnerpreferred))
366N/A {
366N/A hardfailures |= hardmask & XSolarisOvlPreferredPartner;
366N/A softfailures |= softmask & XSolarisOvlPreferredPartner;
366N/A }
366N/A match->hardfailures = hardfailures;
366N/A match->numhardfailures = bitcount(hardfailures);
366N/A match->softfailures = softfailures;
366N/A match->numsoftfailures = bitcount(softfailures);
366N/A}
366N/A
366N/A
366N/A#define XSolarisOvlAllCriteria \
366N/A (XSolarisOvlVisualClass | \
366N/A XSolarisOvlDepth | \
366N/A XSolarisOvlMinColors | \
366N/A XSolarisOvlMinRed | \
366N/A XSolarisOvlMinGreen | \
366N/A XSolarisOvlMinBlue | \
366N/A XSolarisOvlMinBitsPerRGB | \
366N/A XSolarisOvlMinBuffers | \
366N/A XSolarisOvlUnsharedPixels | \
366N/A XSolarisOvlUnsharedColors | \
366N/A XSolarisOvlPreferredPartner)
366N/A
366N/Astatic void
366N/ASetWorstMatch(
366N/A XOvlVisualMatch *match
366N/A)
366N/A{
366N/A match->hardfailures = XSolarisOvlAllCriteria;
366N/A match->softfailures = XSolarisOvlAllCriteria;
366N/A match->numhardfailures =
366N/A match->numsoftfailures =
366N/A bitcount(XSolarisOvlAllCriteria);
366N/A}
366N/A
366N/A
366N/A#define IsPerfectMatch(pm) (!((pm)->hardfailures | (pm)->softfailures))
366N/A
366N/A#define IsQualifiedMatch(pm) (!(pm)->hardfailures)
366N/A
366N/A#define IsBetterMatch(pm1, pm2) \
366N/A ( ((pm1)->numhardfailures < (pm2)->numhardfailures) \
366N/A || ( ((pm1)->numhardfailures == (pm2)->numhardfailures) \
366N/A && ((pm1)->numsoftfailures < (pm2)->numsoftfailures)))
366N/A
366N/A
366N/A#define IsPerfectPair(povm, punm) \
366N/A (IsPerfectMatch(povm) && IsPerfectMatch(punm))
366N/A
366N/A#define IsQualifiedPair(povm, punm) \
366N/A (IsQualifiedMatch(povm) && IsQualifiedMatch(punm))
366N/A
366N/A#define IsBetterPair(povm1, punm1, povm2, punm2) \
366N/A ( ( ((povm1)->numhardfailures + (punm1)->numhardfailures) \
366N/A < ((povm2)->numhardfailures + (punm2)->numhardfailures)) \
366N/A || ( ( ((povm1)->numhardfailures + (punm1)->numhardfailures) \
366N/A == ((povm2)->numhardfailures + (punm2)->numhardfailures)) \
366N/A && ( ((povm1)->numsoftfailures + (punm1)->numsoftfailures) \
366N/A < ((povm2)->numsoftfailures + (punm2)->numsoftfailures))))
366N/A
366N/A
366N/Astatic void
366N/Aset_visinfo(
366N/A XVisualInfo *visinfoReturn,
366N/A XOvlVisualMatch *match
366N/A)
366N/A{
366N/A Visual *vis = match->candidate.vis;
366N/A
366N/A visinfoReturn->visual = vis;
366N/A visinfoReturn->visualid = match->candidate.vid;
366N/A visinfoReturn->screen = match->screen;
366N/A visinfoReturn->depth = match->candidate.depth;
366N/A visinfoReturn->class = vis->class;
366N/A visinfoReturn->red_mask = vis->red_mask;
366N/A visinfoReturn->green_mask = vis->green_mask;
366N/A visinfoReturn->blue_mask = vis->blue_mask;
366N/A visinfoReturn->colormap_size = vis->map_entries;
366N/A visinfoReturn->bits_per_rgb = vis->bits_per_rgb;
366N/A}
366N/A
366N/A/**********************************************************************/
366N/A
366N/ABool
366N/AXSolarisOvlQueryExtension(
366N/A Display *dpy,
366N/A int *event_basep,
366N/A int *error_basep
366N/A)
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A
366N/A if (XextHasExtension(info)) {
366N/A *event_basep = info->codes->first_event;
366N/A *error_basep = info->codes->first_error;
366N/A return True;
366N/A } else {
366N/A return False;
366N/A }
366N/A}
366N/A
366N/A
366N/AStatus
366N/AXSolarisOvlQueryVersion(
366N/A Display *dpy,
366N/A int *major_versionp,
366N/A int *minor_versionp)
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A xOvlQueryVersionReply rep;
366N/A xOvlQueryVersionReq *req;
366N/A
366N/A OvlCheckExtension(dpy, info, 0);
366N/A
366N/A LockDisplay(dpy);
366N/A GetReq(OvlQueryVersion, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->ovlReqType = X_OvlQueryVersion;
366N/A if (!_XReply(dpy, (xReply *)(&rep), 0, xTrue)) {
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return 0;
366N/A }
366N/A *major_versionp = rep.majorVersion;
366N/A *minor_versionp = rep.minorVersion;
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return 1;
366N/A}
366N/A
366N/A
366N/AWindow
366N/AXSolarisOvlCreateWindow(
366N/A Display *dpy,
366N/A Window parent,
366N/A int x,
366N/A int y,
366N/A unsigned int width,
366N/A unsigned int height,
366N/A unsigned int border_width,
366N/A int depth,
366N/A unsigned int class,
366N/A Visual *visual,
366N/A unsigned long valuemask,
366N/A XSetWindowAttributes *attr
366N/A)
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A Window wid;
366N/A xOvlCreateWindowReq *req;
366N/A
366N/A /*
366N/A * REMIND: Is there a proper return value to indicate error?
366N/A */
366N/A OvlCheckExtension(dpy, info, (Window) 0);
366N/A
366N/A LockDisplay(dpy);
366N/A GetReq(OvlCreateWindow, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->ovlReqType = X_OvlCreateWindow;
366N/A req->parent = parent;
366N/A req->x = x;
366N/A req->y = y;
366N/A req->width = width;
366N/A req->height = height;
366N/A req->borderWidth = border_width;
366N/A req->depth = depth;
366N/A req->class = class;
366N/A if (visual == CopyFromParent) {
366N/A req->visual = CopyFromParent;
366N/A } else {
366N/A req->visual = visual->visualid;
366N/A }
366N/A wid = req->wid = XAllocID(dpy);
366N/A valuemask &= AllMaskBits;
366N/A if (req->mask = valuemask) {
366N/A
366N/A/* BugId 4130905 - There were only 3 args to this call instead of 4 -
366N/Athe last argument attr was missing - causing Bad Xerror Request. When
366N/Athe client lin libXext was recompiled, the bus error caused the
366N/Aclient code to fail. Big change between 2.6 and 2.7 file. */
366N/A
366N/A _XProcessWindowAttributes(dpy, (xChangeWindowAttributesReq *)req,
366N/A valuemask, attr);
366N/A }
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return wid;
366N/A}
366N/A
366N/A
366N/ABool
366N/AXSolarisOvlIsOverlayWindow(
366N/A Display *dpy,
366N/A Window w
366N/A)
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A xOvlIsOverlayWindowReq *req;
366N/A xOvlIsOverlayWindowReply rep;
366N/A
366N/A OvlCheckExtension(dpy, info, False);
366N/A
366N/A LockDisplay(dpy);
366N/A GetReq(OvlIsOverlayWindow, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->ovlReqType = X_OvlIsOverlayWindow;
366N/A req->wid = w;
366N/A if (_XReply (dpy, (xReply *)(&rep), 0, xTrue) == 0) {
366N/A rep.isoverlay = False;
366N/A }
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return rep.isoverlay;
366N/A}
366N/A
366N/A
366N/Avoid
366N/AXSolarisOvlSetWindowTransparent(
366N/A Display *dpy,
366N/A Window w)
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A xOvlSetWindowTransparentReq *req;
366N/A
366N/A OvlSimpleCheckExtension(dpy, info);
366N/A
366N/A LockDisplay(dpy);
366N/A GetReq(OvlSetWindowTransparent, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->ovlReqType = X_OvlSetWindowTransparent;
366N/A req->wid = w;
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return;
366N/A}
366N/A
366N/A
366N/AStatus
366N/AXSolarisOvlSetPaintType(
366N/A Display *dpy,
366N/A GC gc,
366N/A XSolarisOvlPaintType paintType
366N/A)
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A XOvlGCExtData *gcextdata;
366N/A xOvlSetPaintTypeReq *req;
366N/A XEDataObject obj;
366N/A
366N/A OvlCheckExtension(dpy, info, 0);
366N/A
366N/A LockDisplay(dpy);
366N/A obj.gc = gc;
366N/A gcextdata = (XOvlGCExtData *)
366N/A XFindOnExtensionList(XEHeadOfExtensionList(obj),
366N/A info->codes->extension);
366N/A if (!gcextdata) {
366N/A if (paintType == XSolarisOvlPaintOpaque) {
366N/A /*
366N/A * No use creating an extension structure just to hold
366N/A * the default value.
366N/A */
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return 1;
366N/A }
366N/A gcextdata = Xmalloc(sizeof(XOvlGCExtData));
366N/A if (!gcextdata) {
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return 0;
366N/A }
366N/A gcextdata->extdata.number = info->codes->extension;
366N/A gcextdata->extdata.free_private = NULL;
366N/A gcextdata->extdata.private_data = NULL;
366N/A gcextdata->paintType = XSolarisOvlPaintOpaque;
366N/A XAddToExtensionList(XEHeadOfExtensionList(obj), &(gcextdata->extdata));
366N/A }
366N/A if (gcextdata->paintType != paintType) {
366N/A gcextdata->paintType = paintType;
366N/A FlushGC(dpy, gc);
366N/A GetReq(OvlSetPaintType, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->ovlReqType = X_OvlSetPaintType;
366N/A req->gc = gc->gid;
366N/A req->paintType = paintType;
366N/A }
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return 1;
366N/A}
366N/A
366N/A
366N/AXSolarisOvlPaintType
366N/AXSolarisOvlGetPaintType(
366N/A Display *dpy,
366N/A GC gc
366N/A)
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A XOvlGCExtData *gcextdata;
366N/A XSolarisOvlPaintType paintType;
366N/A XEDataObject obj;
366N/A
366N/A OvlCheckExtension(dpy, info, XSolarisOvlPaintOpaque);
366N/A
366N/A LockDisplay(dpy);
366N/A obj.gc = gc;
366N/A gcextdata = (XOvlGCExtData *)
366N/A XFindOnExtensionList(XEHeadOfExtensionList(obj),
366N/A info->codes->extension);
366N/A paintType = (gcextdata) ? gcextdata->paintType : XSolarisOvlPaintOpaque;
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return paintType;
366N/A}
366N/A
366N/A
366N/AStatus
366N/AXSolarisOvlCopyPaintType(
366N/A Display *dpy,
366N/A Drawable src,
366N/A Drawable dst,
366N/A GC gc,
366N/A int src_x,
366N/A int src_y,
366N/A unsigned int width,
366N/A unsigned int height,
366N/A int dest_x,
366N/A int dest_y,
366N/A unsigned long action_mask,
366N/A unsigned long planemask
366N/A)
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A xOvlCopyPaintTypeReq *req;
366N/A
366N/A OvlCheckExtension(dpy, info, 0);
366N/A
366N/A LockDisplay(dpy);
366N/A FlushGC(dpy, gc);
366N/A GetReq(OvlCopyPaintType, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->ovlReqType = X_OvlCopyPaintType;
366N/A req->srcDrawable = src;
366N/A req->dstDrawable = dst;
366N/A req->gc = gc->gid;
366N/A req->srcX = src_x;
366N/A req->srcY = src_y;
366N/A req->destX = dest_x;
366N/A req->destY = dest_y;
366N/A req->width = width;
366N/A req->height = height;
366N/A req->action_mask = action_mask;
366N/A req->bitPlane = planemask;
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return 1;
366N/A}
366N/A
366N/A
366N/AStatus
366N/AXSolarisOvlCopyAreaAndPaintType(
366N/A Display *dpy,
366N/A Drawable colorSrc,
366N/A Drawable paintTypeSrc,
366N/A Drawable colorDst,
366N/A Drawable paintTypeDst,
366N/A GC colorGC,
366N/A GC paintTypeGC,
366N/A int colorSrcX,
366N/A int colorSrcY,
366N/A int paintTypeSrcX,
366N/A int paintTypeSrcY,
366N/A unsigned int width,
366N/A unsigned int height,
366N/A int colorDstX,
366N/A int colorDstY,
366N/A int paintTypeDstX,
366N/A int paintTypeDstY,
366N/A unsigned long action_mask,
366N/A unsigned long planemask)
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A xOvlCopyAreaAndPaintTypeReq *req;
366N/A
366N/A OvlCheckExtension(dpy, info, 0);
366N/A
366N/A LockDisplay(dpy);
366N/A FlushGC(dpy, colorGC);
366N/A if (paintTypeGC && (paintTypeGC != colorGC))
366N/A FlushGC(dpy, paintTypeGC);
366N/A GetReq(OvlCopyAreaAndPaintType, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->ovlReqType = X_OvlCopyAreaAndPaintType;
366N/A req->colorSrc = colorSrc;
366N/A req->paintTypeSrc = paintTypeSrc;
366N/A req->colorDst = colorDst;
366N/A req->paintTypeDst = paintTypeDst;
366N/A req->colorGC = colorGC->gid;
366N/A req->paintTypeGC = (paintTypeGC) ? paintTypeGC->gid : None;
366N/A req->colorSrcX = colorSrcX;
366N/A req->colorSrcY = colorSrcY;
366N/A req->paintTypeSrcX = paintTypeSrcX;
366N/A req->paintTypeSrcY = paintTypeSrcY;
366N/A req->colorDstX = colorDstX;
366N/A req->colorDstY = colorDstY;
366N/A req->paintTypeDstX = paintTypeDstX;
366N/A req->paintTypeDstY = paintTypeDstY;
366N/A req->width = width;
366N/A req->height = height;
366N/A req->action_mask = action_mask;
366N/A req->bitPlane = planemask;
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return 1;
366N/A}
366N/A
366N/A
366N/AXImage *
366N/AXReadScreen(
366N/A Display *dpy,
366N/A Window w,
366N/A int x,
366N/A int y,
366N/A unsigned int width,
366N/A unsigned int height,
366N/A Bool includeCursor
366N/A)
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A xOvlReadScreenReq *req;
366N/A xOvlReadScreenReply rep;
366N/A char *data;
366N/A long nbytes;
366N/A XImage *image;
366N/A
366N/A OvlCheckExtension(dpy, info, NULL);
366N/A
366N/A LockDisplay(dpy);
366N/A GetReq (OvlReadScreen, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->ovlReqType = X_OvlReadScreen;
366N/A req->window = w;
366N/A req->x = x;
366N/A req->y = y;
366N/A req->width = width;
366N/A req->height = height;
366N/A req->includeCursor = includeCursor;
366N/A
366N/A if ( (_XReply(dpy, (xReply *)(&rep), 0, xFalse) == 0)
366N/A || (rep.length == 0))
366N/A {
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return NULL;
366N/A }
366N/A nbytes = (long)rep.length << 2;
366N/A data = (char *)Xmalloc((size_t)nbytes);
366N/A if (!data) {
366N/A _XEatData(dpy, (unsigned long)nbytes);
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return NULL;
366N/A }
366N/A _XReadPad (dpy, data, nbytes);
366N/A image = XCreateImage(dpy, None,
366N/A 24, ZPixmap, 0, data, width, height,
366N/A dpy->bitmap_pad, 0);
366N/A if (image) {
366N/A image->red_mask = READSCREEN_REDMASK;
366N/A image->green_mask = READSCREEN_GREENMASK;
366N/A image->blue_mask = READSCREEN_BLUEMASK;
366N/A } else {
366N/A Xfree(data);
366N/A }
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return image;
366N/A}
366N/A
366N/A
366N/AXSolarisOvlSelectStatus
366N/AXSolarisOvlSelectPartner(
366N/A Display *dpy,
366N/A int screen,
366N/A VisualID vid,
366N/A XSolarisOvlSelectType vistype,
366N/A int numCriteria,
366N/A XSolarisOvlVisualCriteria *pCriteria,
366N/A XVisualInfo *visinfoReturn,
366N/A unsigned long *unmetCriteriaReturn
366N/A)
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A Screen *scr;
366N/A XOvlScrExtData *scrextdata;
366N/A XOvlVisPair *vispair;
366N/A int i,
366N/A j;
366N/A Depth *depth;
366N/A XOvlVisInfo partner;
366N/A XOvlVisualMatch curMatch,
366N/A betterMatch,
366N/A bestMatch;
366N/A XOvlVisEnumData visEnumData;
366N/A unsigned long hardpreferred,
366N/A softpreferred;
366N/A
366N/A OvlCheckExtension(dpy, info, XSolarisOvlFailure);
366N/A
366N/A LockDisplay(dpy);
366N/A scr = ScreenOfDisplay(dpy, screen);
366N/A scrextdata = find_screendata(dpy, screen, info);
366N/A if (!scrextdata) {
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return XSolarisOvlFailure;
366N/A }
366N/A curMatch.screen = screen;
366N/A curMatch.partner.vid = vid;
366N/A if (!find_visual(scr, vid, &curMatch.partner.vis, &curMatch.partner.depth))
366N/A {
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return XSolarisOvlFailure;
366N/A }
366N/A curMatch.searchtype = vistype;
366N/A SetWorstMatch(&bestMatch);
366N/A for (i = numCriteria; i > 0; --i) {
366N/A SetWorstMatch(&betterMatch);
366N/A curMatch.partnerpreferred = True;
366N/A vispair = (XOvlVisPair *)(scrextdata->extdata.private_data);
366N/A for (j = scrextdata->numVisPairs; j > 0; --j) {
366N/A if (vid ==
366N/A ((vistype == XSolarisOvlSelectBestOverlay)
366N/A ? (vispair->underlay.vid)
366N/A : (vispair->overlay.vid)))
366N/A {
366N/A curMatch.candidate = (vistype == XSolarisOvlSelectBestOverlay)
366N/A ? vispair->overlay
366N/A : vispair->underlay;
366N/A ComputeVisualMatch(dpy, &curMatch, pCriteria, info);
366N/A if (IsPerfectMatch(&curMatch)) {
366N/A set_visinfo(visinfoReturn, &curMatch);
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return XSolarisOvlSuccess;
366N/A }
366N/A if (IsBetterMatch(&curMatch, &betterMatch)) {
366N/A betterMatch = curMatch;
366N/A }
366N/A }
366N/A vispair++;
366N/A }
366N/A if (!scrextdata->pairsRestricted) {
366N/A curMatch.partnerpreferred = False;
366N/A vis_enum_init(scr, &visEnumData);
366N/A while (vis_enum_next(&visEnumData,
366N/A &curMatch.candidate.vis,
366N/A &curMatch.candidate.depth))
366N/A {
366N/A curMatch.candidate.vid = curMatch.candidate.vis->visualid;
366N/A ComputeVisualMatch(dpy, &curMatch, pCriteria, info);
366N/A if (IsPerfectMatch(&curMatch)) {
366N/A set_visinfo(visinfoReturn, &curMatch);
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return XSolarisOvlSuccess;
366N/A }
366N/A if (IsBetterMatch(&curMatch, &betterMatch)) {
366N/A betterMatch = curMatch;
366N/A }
366N/A }
366N/A }
366N/A if (IsQualifiedMatch(&betterMatch)) {
366N/A set_visinfo(visinfoReturn, &betterMatch);
366N/A *unmetCriteriaReturn = betterMatch.softfailures;
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return XSolarisOvlQualifiedSuccess;
366N/A }
366N/A if (IsBetterMatch(&betterMatch, &bestMatch)) {
366N/A bestMatch = betterMatch;
366N/A }
366N/A pCriteria++;
366N/A }
366N/A *unmetCriteriaReturn = bestMatch.hardfailures | bestMatch.softfailures;
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return XSolarisOvlCriteriaFailure;
366N/A}
366N/A
366N/A
366N/AXSolarisOvlSelectStatus
366N/AXSolarisOvlSelectPair(
366N/A Display *dpy,
366N/A int screen,
366N/A int numCriteria,
366N/A XSolarisOvlPairCriteria *pCriteria,
366N/A XVisualInfo *ovVisinfoReturn,
366N/A XVisualInfo *unVisinfoReturn,
366N/A unsigned long *unmetOvCriteriaReturn,
366N/A unsigned long *unmetUnCriteriaReturn)
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A Screen *scr;
366N/A XOvlScrExtData *scrextdata;
366N/A XOvlVisPair *vispair;
366N/A int i,
366N/A j;
366N/A XOvlVisualMatch curOvMatch, curUnMatch,
366N/A betterOvMatch, betterUnMatch,
366N/A bestOvMatch, bestUnMatch;
366N/A XOvlVisEnumData ovVisEnumData, unVisEnumData;
366N/A
366N/A OvlCheckExtension(dpy, info, XSolarisOvlFailure);
366N/A LockDisplay(dpy);
366N/A scr = ScreenOfDisplay(dpy, screen);
366N/A scrextdata = find_screendata(dpy, screen, info);
366N/A if (!scrextdata) {
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return XSolarisOvlFailure;
366N/A }
366N/A curOvMatch.screen = curUnMatch.screen = screen;
366N/A curOvMatch.searchtype = XSolarisOvlSelectBestUnderlay;
366N/A curUnMatch.searchtype = XSolarisOvlSelectBestOverlay;
366N/A SetWorstMatch(&bestOvMatch);
366N/A SetWorstMatch(&bestUnMatch);
366N/A for (i = numCriteria; i > 0; --i) {
366N/A SetWorstMatch(&betterOvMatch);
366N/A SetWorstMatch(&betterUnMatch);
366N/A curOvMatch.partnerpreferred = curUnMatch.partnerpreferred = True;
366N/A vispair = (XOvlVisPair *)(scrextdata->extdata.private_data);
366N/A for (j = scrextdata->numVisPairs; j > 0; --j) {
366N/A curOvMatch.candidate = curUnMatch.partner = vispair->overlay;
366N/A curOvMatch.partner = curUnMatch.candidate = vispair->underlay;
366N/A ComputeVisualMatch(dpy, &curOvMatch,
366N/A &pCriteria->overlayCriteria, info);
366N/A ComputeVisualMatch(dpy, &curUnMatch,
366N/A &pCriteria->underlayCriteria, info);
366N/A if (IsPerfectPair(&curOvMatch, &curUnMatch)) {
366N/A set_visinfo(unVisinfoReturn, &curUnMatch);
366N/A set_visinfo(ovVisinfoReturn, &curOvMatch);
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return XSolarisOvlSuccess;
366N/A }
366N/A if (IsBetterPair(&curOvMatch, &curUnMatch,
366N/A &betterOvMatch, &betterUnMatch))
366N/A {
366N/A betterOvMatch = curOvMatch;
366N/A betterUnMatch = curUnMatch;
366N/A }
366N/A vispair++;
366N/A }
366N/A if (!scrextdata->pairsRestricted) {
366N/A curOvMatch.partnerpreferred = False;
366N/A curUnMatch.partnerpreferred = False;
366N/A vis_enum_init(scr, &ovVisEnumData);
366N/A while (vis_enum_next(&ovVisEnumData,
366N/A &curOvMatch.candidate.vis,
366N/A &curOvMatch.candidate.depth))
366N/A {
366N/A curOvMatch.candidate.vid = curOvMatch.candidate.vis->visualid;
366N/A curUnMatch.partner = curOvMatch.candidate;
366N/A vis_enum_init(scr, &unVisEnumData);
366N/A while (vis_enum_next(&unVisEnumData,
366N/A &curUnMatch.candidate.vis,
366N/A &curUnMatch.candidate.depth))
366N/A {
366N/A curUnMatch.candidate.vid =
366N/A curUnMatch.candidate.vis->visualid;
366N/A curOvMatch.partner = curUnMatch.candidate;
366N/A ComputeVisualMatch(dpy, &curOvMatch,
366N/A &pCriteria->overlayCriteria, info);
366N/A ComputeVisualMatch(dpy, &curUnMatch,
366N/A &pCriteria->underlayCriteria, info);
366N/A if (IsPerfectPair(&curOvMatch, &curUnMatch)) {
366N/A set_visinfo(unVisinfoReturn, &curUnMatch);
366N/A set_visinfo(ovVisinfoReturn, &curOvMatch);
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return XSolarisOvlSuccess;
366N/A }
366N/A if (IsBetterPair(&curOvMatch, &curUnMatch,
366N/A &betterOvMatch, &betterUnMatch))
366N/A {
366N/A betterOvMatch = curOvMatch;
366N/A betterUnMatch = curUnMatch;
366N/A }
366N/A }
366N/A }
366N/A }
366N/A if (IsQualifiedPair(&betterOvMatch, &betterUnMatch)) {
366N/A set_visinfo(ovVisinfoReturn, &betterOvMatch);
366N/A set_visinfo(unVisinfoReturn, &betterUnMatch);
366N/A *unmetOvCriteriaReturn = betterOvMatch.softfailures;
366N/A *unmetUnCriteriaReturn = betterUnMatch.softfailures;
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return XSolarisOvlQualifiedSuccess;
366N/A }
366N/A if (IsBetterPair(&betterOvMatch, &betterUnMatch,
366N/A &bestOvMatch, &bestUnMatch))
366N/A {
366N/A bestOvMatch = betterOvMatch;
366N/A bestUnMatch = betterUnMatch;
366N/A }
366N/A pCriteria++;
366N/A }
366N/A *unmetOvCriteriaReturn = bestOvMatch.hardfailures|bestOvMatch.softfailures;
366N/A *unmetUnCriteriaReturn = bestUnMatch.hardfailures|bestUnMatch.softfailures;
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return XSolarisOvlCriteriaFailure;
366N/A}