diff options
author | marha <marha@users.sourceforge.net> | 2012-03-26 14:23:28 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2012-03-26 14:23:28 +0200 |
commit | 76bcc36ed305418a3ddc5752d287ede894243e1b (patch) | |
tree | bacb320c825768471ce56f058f17ce863d592376 /xorg-server/Xext | |
parent | 7d894e32566b710952c44cbc71939ad1d9e2fa8d (diff) | |
parent | 0f834b91a4768673833ab4917e87d86c237bb1a6 (diff) | |
download | vcxsrv-76bcc36ed305418a3ddc5752d287ede894243e1b.tar.gz vcxsrv-76bcc36ed305418a3ddc5752d287ede894243e1b.tar.bz2 vcxsrv-76bcc36ed305418a3ddc5752d287ede894243e1b.zip |
Merge remote-tracking branch 'origin/released'
Conflicts:
pixman/pixman/pixman-mmx.c
xorg-server/Xext/shm.c
xorg-server/Xext/syncsrv.h
xorg-server/Xext/xvmain.c
xorg-server/Xi/exevents.c
xorg-server/Xi/opendev.c
xorg-server/composite/compalloc.c
xorg-server/composite/compoverlay.c
xorg-server/dix/colormap.c
xorg-server/dix/devices.c
xorg-server/dix/dispatch.c
xorg-server/dix/dixfonts.c
xorg-server/dix/eventconvert.c
xorg-server/dix/events.c
xorg-server/dix/gc.c
xorg-server/dix/getevents.c
xorg-server/dix/main.c
xorg-server/dix/privates.c
xorg-server/dix/registry.c
xorg-server/dix/resource.c
xorg-server/exa/exa_accel.c
xorg-server/exa/exa_migration_classic.c
xorg-server/exa/exa_unaccel.c
xorg-server/fb/fb.h
xorg-server/fb/fbcopy.c
xorg-server/fb/fbpixmap.c
xorg-server/glx/dispatch.h
xorg-server/glx/glapi.h
xorg-server/glx/glapi_gentable.c
xorg-server/glx/glapitable.h
xorg-server/glx/glprocs.h
xorg-server/glx/glxcmds.c
xorg-server/glx/glxcmdsswap.c
xorg-server/glx/glxdricommon.c
xorg-server/glx/glxdriswrast.c
xorg-server/glx/glxext.c
xorg-server/glx/indirect_dispatch.c
xorg-server/glx/indirect_dispatch.h
xorg-server/glx/indirect_dispatch_swap.c
xorg-server/glx/indirect_size.h
xorg-server/glx/indirect_size_get.h
xorg-server/glx/indirect_table.c
xorg-server/glx/indirect_util.c
xorg-server/glx/rensize.c
xorg-server/glx/single2swap.c
xorg-server/glx/singlepix.c
xorg-server/glx/singlepixswap.c
xorg-server/glx/singlesize.c
xorg-server/hw/dmx/dmxinit.c
xorg-server/hw/kdrive/ephyr/ephyr.c
xorg-server/hw/kdrive/ephyr/hostx.c
xorg-server/hw/kdrive/ephyr/hostx.h
xorg-server/hw/kdrive/src/kinput.c
xorg-server/hw/xfree86/common/compiler.h
xorg-server/hw/xwin/InitInput.c
xorg-server/hw/xwin/InitOutput.c
xorg-server/hw/xwin/ddraw.h
xorg-server/hw/xwin/glx/glwrap.c
xorg-server/hw/xwin/glx/indirect.c
xorg-server/hw/xwin/glx/wgl_ext_api.h
xorg-server/hw/xwin/glx/winpriv.c
xorg-server/hw/xwin/win.h
xorg-server/hw/xwin/winallpriv.c
xorg-server/hw/xwin/winauth.c
xorg-server/hw/xwin/winclipboard.h
xorg-server/hw/xwin/winclipboardinit.c
xorg-server/hw/xwin/winclipboardthread.c
xorg-server/hw/xwin/winclipboardunicode.c
xorg-server/hw/xwin/winclipboardwndproc.c
xorg-server/hw/xwin/winclipboardwrappers.c
xorg-server/hw/xwin/winclipboardxevents.c
xorg-server/hw/xwin/wincmap.c
xorg-server/hw/xwin/winconfig.c
xorg-server/hw/xwin/wincreatewnd.c
xorg-server/hw/xwin/wincursor.c
xorg-server/hw/xwin/windialogs.c
xorg-server/hw/xwin/winengine.c
xorg-server/hw/xwin/winerror.c
xorg-server/hw/xwin/wingc.c
xorg-server/hw/xwin/wingetsp.c
xorg-server/hw/xwin/winkeybd.c
xorg-server/hw/xwin/winkeybd.h
xorg-server/hw/xwin/winlayouts.h
xorg-server/hw/xwin/winmisc.c
xorg-server/hw/xwin/winmonitors.c
xorg-server/hw/xwin/winmouse.c
xorg-server/hw/xwin/winmsg.c
xorg-server/hw/xwin/winmsg.h
xorg-server/hw/xwin/winmultiwindowclass.c
xorg-server/hw/xwin/winmultiwindowicons.c
xorg-server/hw/xwin/winmultiwindowshape.c
xorg-server/hw/xwin/winmultiwindowwindow.c
xorg-server/hw/xwin/winmultiwindowwm.c
xorg-server/hw/xwin/winmultiwindowwndproc.c
xorg-server/hw/xwin/winnativegdi.c
xorg-server/hw/xwin/winpfbdd.c
xorg-server/hw/xwin/winpixmap.c
xorg-server/hw/xwin/winpolyline.c
xorg-server/hw/xwin/winprefs.c
xorg-server/hw/xwin/winprocarg.c
xorg-server/hw/xwin/winregistry.c
xorg-server/hw/xwin/winscrinit.c
xorg-server/hw/xwin/winsetsp.c
xorg-server/hw/xwin/winshaddd.c
xorg-server/hw/xwin/winshadddnl.c
xorg-server/hw/xwin/winshadgdi.c
xorg-server/hw/xwin/wintrayicon.c
xorg-server/hw/xwin/winwin32rootless.c
xorg-server/hw/xwin/winwin32rootlesswindow.c
xorg-server/hw/xwin/winwin32rootlesswndproc.c
xorg-server/hw/xwin/winwindow.c
xorg-server/hw/xwin/winwindow.h
xorg-server/hw/xwin/winwindowswm.c
xorg-server/hw/xwin/winwndproc.c
xorg-server/include/callback.h
xorg-server/include/dixstruct.h
xorg-server/include/misc.h
xorg-server/include/os.h
xorg-server/include/scrnintstr.h
xorg-server/mi/micmap.c
xorg-server/mi/miinitext.c
xorg-server/mi/mioverlay.c
xorg-server/mi/misprite.c
xorg-server/mi/mivaltree.c
xorg-server/mi/miwindow.c
xorg-server/miext/damage/damage.c
xorg-server/miext/rootless/rootlessGC.c
xorg-server/miext/rootless/rootlessWindow.c
xorg-server/os/WaitFor.c
xorg-server/os/access.c
xorg-server/os/connection.c
xorg-server/os/io.c
xorg-server/os/log.c
xorg-server/os/osinit.c
xorg-server/os/utils.c
xorg-server/os/xdmcp.c
xorg-server/os/xprintf.c
xorg-server/os/xstrans.c
xorg-server/render/mipict.c
xorg-server/xkb/xkbActions.c
xorg-server/xkb/xkbInit.c
xorg-server/xkeyboard-config/compat/default.in
Diffstat (limited to 'xorg-server/Xext')
30 files changed, 10457 insertions, 10755 deletions
diff --git a/xorg-server/Xext/dpms.c b/xorg-server/Xext/dpms.c index e82f495aa..bf01c8905 100644 --- a/xorg-server/Xext/dpms.c +++ b/xorg-server/Xext/dpms.c @@ -57,11 +57,11 @@ ProcDPMSGetVersion(ClientPtr client) rep.majorVersion = DPMSMajorVersion; rep.minorVersion = DPMSMinorVersion; if (client->swapped) { - swaps(&rep.sequenceNumber); - swaps(&rep.majorVersion); - swaps(&rep.minorVersion); + swaps(&rep.sequenceNumber); + swaps(&rep.majorVersion); + swaps(&rep.minorVersion); } - WriteToClient(client, sizeof(xDPMSGetVersionReply), (char *)&rep); + WriteToClient(client, sizeof(xDPMSGetVersionReply), (char *) &rep); return Success; } @@ -79,9 +79,9 @@ ProcDPMSCapable(ClientPtr client) rep.capable = DPMSCapableFlag; if (client->swapped) { - swaps(&rep.sequenceNumber); + swaps(&rep.sequenceNumber); } - WriteToClient(client, sizeof(xDPMSCapableReply), (char *)&rep); + WriteToClient(client, sizeof(xDPMSCapableReply), (char *) &rep); return Success; } @@ -101,12 +101,12 @@ ProcDPMSGetTimeouts(ClientPtr client) rep.off = DPMSOffTime / MILLI_PER_SECOND; if (client->swapped) { - swaps(&rep.sequenceNumber); - swaps(&rep.standby); - swaps(&rep.suspend); - swaps(&rep.off); + swaps(&rep.sequenceNumber); + swaps(&rep.standby); + swaps(&rep.suspend); + swaps(&rep.off); } - WriteToClient(client, sizeof(xDPMSGetTimeoutsReply), (char *)&rep); + WriteToClient(client, sizeof(xDPMSGetTimeoutsReply), (char *) &rep); return Success; } @@ -117,16 +117,14 @@ ProcDPMSSetTimeouts(ClientPtr client) REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq); - if ((stuff->off != 0)&&(stuff->off < stuff->suspend)) - { - client->errorValue = stuff->off; - return BadValue; + if ((stuff->off != 0) && (stuff->off < stuff->suspend)) { + client->errorValue = stuff->off; + return BadValue; + } + if ((stuff->suspend != 0) && (stuff->suspend < stuff->standby)) { + client->errorValue = stuff->suspend; + return BadValue; } - if ((stuff->suspend != 0)&&(stuff->suspend < stuff->standby)) - { - client->errorValue = stuff->suspend; - return BadValue; - } DPMSStandbyTime = stuff->standby * MILLI_PER_SECOND; DPMSSuspendTime = stuff->suspend * MILLI_PER_SECOND; @@ -144,9 +142,9 @@ ProcDPMSEnable(ClientPtr client) REQUEST_SIZE_MATCH(xDPMSEnableReq); if (DPMSCapableFlag) { - DPMSEnabled = TRUE; - if (!was_enabled) - SetScreenSaverTimer(); + DPMSEnabled = TRUE; + if (!was_enabled) + SetScreenSaverTimer(); } return Success; @@ -174,14 +172,13 @@ ProcDPMSForceLevel(ClientPtr client) REQUEST_SIZE_MATCH(xDPMSForceLevelReq); if (!DPMSEnabled) - return BadMatch; + return BadMatch; if (stuff->level != DPMSModeOn && stuff->level != DPMSModeStandby && - stuff->level != DPMSModeSuspend && - stuff->level != DPMSModeOff) { - client->errorValue = stuff->level; - return BadValue; + stuff->level != DPMSModeSuspend && stuff->level != DPMSModeOff) { + client->errorValue = stuff->level; + return BadValue; } DPMSSet(client, stuff->level); @@ -204,38 +201,37 @@ ProcDPMSInfo(ClientPtr client) rep.state = DPMSEnabled; if (client->swapped) { - swaps(&rep.sequenceNumber); - swaps(&rep.power_level); + swaps(&rep.sequenceNumber); + swaps(&rep.power_level); } - WriteToClient(client, sizeof(xDPMSInfoReply), (char *)&rep); + WriteToClient(client, sizeof(xDPMSInfoReply), (char *) &rep); return Success; } static int -ProcDPMSDispatch (ClientPtr client) +ProcDPMSDispatch(ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { + switch (stuff->data) { case X_DPMSGetVersion: - return ProcDPMSGetVersion(client); + return ProcDPMSGetVersion(client); case X_DPMSCapable: - return ProcDPMSCapable(client); + return ProcDPMSCapable(client); case X_DPMSGetTimeouts: - return ProcDPMSGetTimeouts(client); + return ProcDPMSGetTimeouts(client); case X_DPMSSetTimeouts: - return ProcDPMSSetTimeouts(client); + return ProcDPMSSetTimeouts(client); case X_DPMSEnable: - return ProcDPMSEnable(client); + return ProcDPMSEnable(client); case X_DPMSDisable: - return ProcDPMSDisable(client); + return ProcDPMSDisable(client); case X_DPMSForceLevel: - return ProcDPMSForceLevel(client); + return ProcDPMSForceLevel(client); case X_DPMSInfo: - return ProcDPMSInfo(client); + return ProcDPMSInfo(client); default: - return BadRequest; + return BadRequest; } } @@ -334,29 +330,28 @@ SProcDPMSInfo(ClientPtr client) } static int -SProcDPMSDispatch (ClientPtr client) +SProcDPMSDispatch(ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { + switch (stuff->data) { case X_DPMSGetVersion: - return SProcDPMSGetVersion(client); + return SProcDPMSGetVersion(client); case X_DPMSCapable: - return SProcDPMSCapable(client); + return SProcDPMSCapable(client); case X_DPMSGetTimeouts: - return SProcDPMSGetTimeouts(client); + return SProcDPMSGetTimeouts(client); case X_DPMSSetTimeouts: - return SProcDPMSSetTimeouts(client); + return SProcDPMSSetTimeouts(client); case X_DPMSEnable: - return SProcDPMSEnable(client); + return SProcDPMSEnable(client); case X_DPMSDisable: - return SProcDPMSDisable(client); + return SProcDPMSDisable(client); case X_DPMSForceLevel: - return SProcDPMSForceLevel(client); + return SProcDPMSForceLevel(client); case X_DPMSInfo: - return SProcDPMSInfo(client); + return SProcDPMSInfo(client); default: - return BadRequest; + return BadRequest; } } @@ -364,6 +359,6 @@ void DPMSExtensionInit(INITARGS) { AddExtension(DPMSExtensionName, 0, 0, - ProcDPMSDispatch, SProcDPMSDispatch, - NULL, StandardMinorOpcode); + ProcDPMSDispatch, SProcDPMSDispatch, + NULL, StandardMinorOpcode); } diff --git a/xorg-server/Xext/dpmsstubs.c b/xorg-server/Xext/dpmsstubs.c index f0f54d293..80f13f5df 100644 --- a/xorg-server/Xext/dpmsstubs.c +++ b/xorg-server/Xext/dpmsstubs.c @@ -34,12 +34,14 @@ Equipment Corporation. #define FALSE 0 -Bool DPMSSupported(void) +Bool +DPMSSupported(void) { return FALSE; } -int DPMSSet(ClientPtr client, int level) +int +DPMSSet(ClientPtr client, int level) { return Success; } diff --git a/xorg-server/Xext/geext.c b/xorg-server/Xext/geext.c index a8718ccbd..07028238e 100644 --- a/xorg-server/Xext/geext.c +++ b/xorg-server/Xext/geext.c @@ -35,18 +35,18 @@ DevPrivateKeyRec GEClientPrivateKeyRec; -int RT_GECLIENT = 0; +int RT_GECLIENT = 0; GEExtension GEExtensions[MAXEXTENSIONS]; /* Major available requests */ static const int version_requests[] = { - X_GEQueryVersion, /* before client sends QueryVersion */ - X_GEQueryVersion, /* must be set to last request in version 1 */ + X_GEQueryVersion, /* before client sends QueryVersion */ + X_GEQueryVersion, /* must be set to last request in version 1 */ }; /* Forward declarations */ -static void SGEGenericEvent(xEvent* from, xEvent* to); +static void SGEGenericEvent(xEvent *from, xEvent *to); #define NUM_VERSION_REQUESTS (sizeof (version_requests) / sizeof (version_requests[0])) #define EXT_MASK(ext) ((ext) & 0x7F) @@ -60,6 +60,7 @@ ProcGEQueryVersion(ClientPtr client) { GEClientInfoPtr pGEClient = GEGetClient(client); xGEQueryVersionReply rep; + REQUEST(xGEQueryVersionReq); REQUEST_SIZE_MATCH(xGEQueryVersionReq); @@ -77,22 +78,20 @@ ProcGEQueryVersion(ClientPtr client) pGEClient->major_version = stuff->majorVersion; pGEClient->minor_version = stuff->minorVersion; - if (client->swapped) - { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swaps(&rep.majorVersion); - swaps(&rep.minorVersion); + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swaps(&rep.majorVersion); + swaps(&rep.minorVersion); } - WriteToClient(client, sizeof(xGEQueryVersionReply), (char*)&rep); + WriteToClient(client, sizeof(xGEQueryVersionReply), (char *) &rep); return Success; } -int (*ProcGEVector[GENumberRequests])(ClientPtr) = { +int (*ProcGEVector[GENumberRequests]) (ClientPtr) = { /* Version 1.0 */ - ProcGEQueryVersion -}; +ProcGEQueryVersion}; /************************************************************/ /* swapped request handlers */ @@ -106,14 +105,12 @@ SProcGEQueryVersion(ClientPtr client) REQUEST_SIZE_MATCH(xGEQueryVersionReq); swaps(&stuff->majorVersion); swaps(&stuff->minorVersion); - return(*ProcGEVector[stuff->ReqType])(client); + return (*ProcGEVector[stuff->ReqType]) (client); } -int (*SProcGEVector[GENumberRequests])(ClientPtr) = { +int (*SProcGEVector[GENumberRequests]) (ClientPtr) = { /* Version 1.0 */ - SProcGEQueryVersion -}; - +SProcGEQueryVersion}; /************************************************************/ /* callbacks */ @@ -124,6 +121,7 @@ static int ProcGEDispatch(ClientPtr client) { GEClientInfoPtr pGEClient = GEGetClient(client); + REQUEST(xGEReq); if (pGEClient->major_version >= NUM_VERSION_REQUESTS) @@ -131,7 +129,7 @@ ProcGEDispatch(ClientPtr client) if (stuff->ReqType > version_requests[pGEClient->major_version]) return BadRequest; - return (ProcGEVector[stuff->ReqType])(client); + return (ProcGEVector[stuff->ReqType]) (client); } /* dispatch swapped requests */ @@ -141,7 +139,7 @@ SProcGEDispatch(ClientPtr client) REQUEST(xGEReq); if (stuff->ReqType >= GENumberRequests) return BadRequest; - return (*SProcGEVector[stuff->ReqType])(client); + return (*SProcGEVector[stuff->ReqType]) (client); } /** @@ -151,13 +149,11 @@ SProcGEDispatch(ClientPtr client) * used in the furture for versioning support. */ static void -GEClientCallback(CallbackListPtr *list, - pointer closure, - pointer data) +GEClientCallback(CallbackListPtr *list, pointer closure, pointer data) { - NewClientInfoRec *clientinfo = (NewClientInfoRec *) data; - ClientPtr pClient = clientinfo->client; - GEClientInfoPtr pGEClient = GEGetClient(pClient); + NewClientInfoRec *clientinfo = (NewClientInfoRec *) data; + ClientPtr pClient = clientinfo->client; + GEClientInfoPtr pGEClient = GEGetClient(pClient); pGEClient->major_version = 0; pGEClient->minor_version = 0; @@ -165,7 +161,7 @@ GEClientCallback(CallbackListPtr *list, /* Reset extension. Called on server shutdown. */ static void -GEResetProc(ExtensionEntry *extEntry) +GEResetProc(ExtensionEntry * extEntry) { DeleteCallback(&ClientStateCallback, GEClientCallback, 0); EventSwapVector[GenericEvent] = NotImplemented; @@ -179,13 +175,12 @@ GEResetProc(ExtensionEntry *extEntry) * work. */ static void -SGEGenericEvent(xEvent* from, xEvent* to) +SGEGenericEvent(xEvent *from, xEvent *to) { - xGenericEvent* gefrom = (xGenericEvent*)from; - xGenericEvent* geto = (xGenericEvent*)to; + xGenericEvent *gefrom = (xGenericEvent *) from; + xGenericEvent *geto = (xGenericEvent *) to; - if ((gefrom->extension & 0x7f) > MAXEXTENSIONS) - { + if ((gefrom->extension & 0x7f) > MAXEXTENSIONS) { ErrorF("GE: Invalid extension offset for event.\n"); return; } @@ -203,23 +198,23 @@ GEExtensionInit(void) { ExtensionEntry *extEntry; - if (!dixRegisterPrivateKey(&GEClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(GEClientInfoRec))) + if (!dixRegisterPrivateKey + (&GEClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(GEClientInfoRec))) FatalError("GEExtensionInit: GE private request failed.\n"); - if(!AddCallback(&ClientStateCallback, GEClientCallback, 0)) - { + if (!AddCallback(&ClientStateCallback, GEClientCallback, 0)) { FatalError("GEExtensionInit: register client callback failed.\n"); } - if((extEntry = AddExtension(GE_NAME, - 0, GENumberErrors, - ProcGEDispatch, SProcGEDispatch, - GEResetProc, StandardMinorOpcode)) != 0) - { + if ((extEntry = AddExtension(GE_NAME, + 0, GENumberErrors, + ProcGEDispatch, SProcGEDispatch, + GEResetProc, StandardMinorOpcode)) != 0) { memset(GEExtensions, 0, sizeof(GEExtensions)); EventSwapVector[GenericEvent] = (EventSwapPtr) SGEGenericEvent; - } else { + } + else { FatalError("GEInit: AddExtensions failed.\n"); } @@ -238,24 +233,22 @@ GEExtensionInit(void) */ void GERegisterExtension(int extension, - void (*ev_swap)(xGenericEvent* from, xGenericEvent* to)) + void (*ev_swap) (xGenericEvent *from, xGenericEvent *to)) { - if (EXT_MASK(extension) >= MAXEXTENSIONS) + if (EXT_MASK(extension) >= MAXEXTENSIONS) FatalError("GE: extension > MAXEXTENSIONS. This should not happen.\n"); /* extension opcodes are > 128, might as well save some space here */ GEExtensions[EXT_MASK(extension)].evswap = ev_swap; } - /* Sets type and extension field for a generic event. This is just an * auxiliary function, extensions could do it manually too. */ void -GEInitEvent(xGenericEvent* ev, int extension) +GEInitEvent(xGenericEvent *ev, int extension) { ev->type = GenericEvent; ev->extension = extension; ev->length = 0; } - diff --git a/xorg-server/Xext/geext.h b/xorg-server/Xext/geext.h index 8e6dbeb24..d2a15dcb9 100644 --- a/xorg-server/Xext/geext.h +++ b/xorg-server/Xext/geext.h @@ -37,10 +37,9 @@ from the author. /** Struct to keep information about registered extensions */ typedef struct _GEExtension { /** Event swapping routine */ - void (*evswap)(xGenericEvent* from, xGenericEvent* to); + void (*evswap) (xGenericEvent *from, xGenericEvent *to); } GEExtension, *GEExtensionPtr; - /* All registered extensions and their handling functions. */ extern _X_EXPORT GEExtension GEExtensions[MAXEXTENSIONS]; @@ -70,14 +69,15 @@ extern _X_EXPORT GEExtension GEExtensions[MAXEXTENSIONS]; GEEXT(ev) == (ext) && \ GEV(ev)->evtype == (ev_type)) - /* Interface for other extensions */ -extern _X_EXPORT void GERegisterExtension( - int extension, - void (*ev_dispatch)(xGenericEvent* from, xGenericEvent* to)); +extern _X_EXPORT void GERegisterExtension(int extension, + void (*ev_dispatch) (xGenericEvent + *from, + xGenericEvent + *to)); -extern _X_EXPORT void GEInitEvent(xGenericEvent* ev, int extension); +extern _X_EXPORT void GEInitEvent(xGenericEvent *ev, int extension); extern _X_EXPORT void GEExtensionInit(void); -#endif /* _GEEXT_H_ */ +#endif /* _GEEXT_H_ */ diff --git a/xorg-server/Xext/panoramiX.c b/xorg-server/Xext/panoramiX.c index fae7c81c9..98d327f26 100644 --- a/xorg-server/Xext/panoramiX.c +++ b/xorg-server/Xext/panoramiX.c @@ -64,24 +64,23 @@ Equipment Corporation. #ifdef GLXPROXY extern VisualPtr glxMatchVisual(ScreenPtr pScreen, - VisualPtr pVisual, - ScreenPtr pMatchScreen); + VisualPtr pVisual, ScreenPtr pMatchScreen); #endif /* * PanoramiX data declarations */ -int PanoramiXPixWidth = 0; -int PanoramiXPixHeight = 0; -int PanoramiXNumScreens = 0; +int PanoramiXPixWidth = 0; +int PanoramiXPixHeight = 0; +int PanoramiXNumScreens = 0; -static RegionRec PanoramiXScreenRegion = {{0, 0, 0, 0}, NULL}; +static RegionRec PanoramiXScreenRegion = { {0, 0, 0, 0}, NULL }; -static int PanoramiXNumDepths; -static DepthPtr PanoramiXDepths; -static int PanoramiXNumVisuals; -static VisualPtr PanoramiXVisuals; +static int PanoramiXNumDepths; +static DepthPtr PanoramiXDepths; +static int PanoramiXNumVisuals; +static VisualPtr PanoramiXVisuals; RESTYPE XRC_DRAWABLE; RESTYPE XRT_WINDOW; @@ -97,9 +96,9 @@ XineramaVisualsEqualProcPtr XineramaVisualsEqualPtr = &VisualsEqual; */ static int panoramiXGeneration; -static int ProcPanoramiXDispatch(ClientPtr client); +static int ProcPanoramiXDispatch(ClientPtr client); -static void PanoramiXResetProc(ExtensionEntry*); +static void PanoramiXResetProc(ExtensionEntry *); /* * External references for functions and data variables @@ -107,22 +106,25 @@ static void PanoramiXResetProc(ExtensionEntry*); #include "panoramiXh.h" -int (* SavedProcVector[256]) (ClientPtr client) = { NULL, }; +int (*SavedProcVector[256]) (ClientPtr client) = { +NULL,}; static DevPrivateKeyRec PanoramiXGCKeyRec; + #define PanoramiXGCKey (&PanoramiXGCKeyRec) static DevPrivateKeyRec PanoramiXScreenKeyRec; + #define PanoramiXScreenKey (&PanoramiXScreenKeyRec) typedef struct { - DDXPointRec clipOrg; - DDXPointRec patOrg; - GCFuncs *wrapFuncs; + DDXPointRec clipOrg; + DDXPointRec patOrg; + GCFuncs *wrapFuncs; } PanoramiXGCRec, *PanoramiXGCPtr; typedef struct { - CreateGCProcPtr CreateGC; - CloseScreenProcPtr CloseScreen; + CreateGCProcPtr CreateGC; + CloseScreenProcPtr CloseScreen; } PanoramiXScreenRec, *PanoramiXScreenPtr; static void XineramaValidateGC(GCPtr, unsigned long, DrawablePtr); @@ -147,18 +149,17 @@ static GCFuncs XineramaGCFuncs = { pGCPriv->wrapFuncs = (pGC)->funcs;\ (pGC)->funcs = &XineramaGCFuncs; - static Bool -XineramaCloseScreen (int i, ScreenPtr pScreen) +XineramaCloseScreen(int i, ScreenPtr pScreen) { PanoramiXScreenPtr pScreenPriv = (PanoramiXScreenPtr) - dixLookupPrivate(&pScreen->devPrivates, PanoramiXScreenKey); + dixLookupPrivate(&pScreen->devPrivates, PanoramiXScreenKey); pScreen->CloseScreen = pScreenPriv->CloseScreen; pScreen->CreateGC = pScreenPriv->CreateGC; if (pScreen->myNum == 0) - RegionUninit(&PanoramiXScreenRegion); + RegionUninit(&PanoramiXScreenRegion); free((pointer) pScreenPriv); @@ -170,21 +171,21 @@ XineramaCreateGC(GCPtr pGC) { ScreenPtr pScreen = pGC->pScreen; PanoramiXScreenPtr pScreenPriv = (PanoramiXScreenPtr) - dixLookupPrivate(&pScreen->devPrivates, PanoramiXScreenKey); + dixLookupPrivate(&pScreen->devPrivates, PanoramiXScreenKey); Bool ret; pScreen->CreateGC = pScreenPriv->CreateGC; - if((ret = (*pScreen->CreateGC)(pGC))) { - PanoramiXGCPtr pGCPriv = (PanoramiXGCPtr) - dixLookupPrivate(&pGC->devPrivates, PanoramiXGCKey); + if ((ret = (*pScreen->CreateGC) (pGC))) { + PanoramiXGCPtr pGCPriv = (PanoramiXGCPtr) + dixLookupPrivate(&pGC->devPrivates, PanoramiXGCKey); - pGCPriv->wrapFuncs = pGC->funcs; + pGCPriv->wrapFuncs = pGC->funcs; pGC->funcs = &XineramaGCFuncs; - pGCPriv->clipOrg.x = pGC->clipOrg.x; - pGCPriv->clipOrg.y = pGC->clipOrg.y; - pGCPriv->patOrg.x = pGC->patOrg.x; - pGCPriv->patOrg.y = pGC->patOrg.y; + pGCPriv->clipOrg.x = pGC->clipOrg.x; + pGCPriv->clipOrg.y = pGC->clipOrg.y; + pGCPriv->patOrg.x = pGC->patOrg.x; + pGCPriv->patOrg.y = pGC->patOrg.y; } pScreen->CreateGC = XineramaCreateGC; @@ -192,139 +193,129 @@ XineramaCreateGC(GCPtr pGC) } static void -XineramaValidateGC( - GCPtr pGC, - unsigned long changes, - DrawablePtr pDraw -){ - Xinerama_GC_FUNC_PROLOGUE (pGC); - - if((pDraw->type == DRAWABLE_WINDOW) && !(((WindowPtr)pDraw)->parent)) { - /* the root window */ - int x_off = pGC->pScreen->x; - int y_off = pGC->pScreen->y; - int new_val; - - new_val = pGCPriv->clipOrg.x - x_off; - if(pGC->clipOrg.x != new_val) { - pGC->clipOrg.x = new_val; - changes |= GCClipXOrigin; - } - new_val = pGCPriv->clipOrg.y - y_off; - if(pGC->clipOrg.y != new_val) { - pGC->clipOrg.y = new_val; - changes |= GCClipYOrigin; - } - new_val = pGCPriv->patOrg.x - x_off; - if(pGC->patOrg.x != new_val) { - pGC->patOrg.x = new_val; - changes |= GCTileStipXOrigin; - } - new_val = pGCPriv->patOrg.y - y_off; - if(pGC->patOrg.y != new_val) { - pGC->patOrg.y = new_val; - changes |= GCTileStipYOrigin; - } - } else { - if(pGC->clipOrg.x != pGCPriv->clipOrg.x) { - pGC->clipOrg.x = pGCPriv->clipOrg.x; - changes |= GCClipXOrigin; - } - if(pGC->clipOrg.y != pGCPriv->clipOrg.y) { - pGC->clipOrg.y = pGCPriv->clipOrg.y; - changes |= GCClipYOrigin; - } - if(pGC->patOrg.x != pGCPriv->patOrg.x) { - pGC->patOrg.x = pGCPriv->patOrg.x; - changes |= GCTileStipXOrigin; - } - if(pGC->patOrg.y != pGCPriv->patOrg.y) { - pGC->patOrg.y = pGCPriv->patOrg.y; - changes |= GCTileStipYOrigin; - } +XineramaValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDraw) +{ + Xinerama_GC_FUNC_PROLOGUE(pGC); + + if ((pDraw->type == DRAWABLE_WINDOW) && !(((WindowPtr) pDraw)->parent)) { + /* the root window */ + int x_off = pGC->pScreen->x; + int y_off = pGC->pScreen->y; + int new_val; + + new_val = pGCPriv->clipOrg.x - x_off; + if (pGC->clipOrg.x != new_val) { + pGC->clipOrg.x = new_val; + changes |= GCClipXOrigin; + } + new_val = pGCPriv->clipOrg.y - y_off; + if (pGC->clipOrg.y != new_val) { + pGC->clipOrg.y = new_val; + changes |= GCClipYOrigin; + } + new_val = pGCPriv->patOrg.x - x_off; + if (pGC->patOrg.x != new_val) { + pGC->patOrg.x = new_val; + changes |= GCTileStipXOrigin; + } + new_val = pGCPriv->patOrg.y - y_off; + if (pGC->patOrg.y != new_val) { + pGC->patOrg.y = new_val; + changes |= GCTileStipYOrigin; + } + } + else { + if (pGC->clipOrg.x != pGCPriv->clipOrg.x) { + pGC->clipOrg.x = pGCPriv->clipOrg.x; + changes |= GCClipXOrigin; + } + if (pGC->clipOrg.y != pGCPriv->clipOrg.y) { + pGC->clipOrg.y = pGCPriv->clipOrg.y; + changes |= GCClipYOrigin; + } + if (pGC->patOrg.x != pGCPriv->patOrg.x) { + pGC->patOrg.x = pGCPriv->patOrg.x; + changes |= GCTileStipXOrigin; + } + if (pGC->patOrg.y != pGCPriv->patOrg.y) { + pGC->patOrg.y = pGCPriv->patOrg.y; + changes |= GCTileStipYOrigin; + } } - - (*pGC->funcs->ValidateGC)(pGC, changes, pDraw); - Xinerama_GC_FUNC_EPILOGUE (pGC); + + (*pGC->funcs->ValidateGC) (pGC, changes, pDraw); + Xinerama_GC_FUNC_EPILOGUE(pGC); } static void XineramaDestroyGC(GCPtr pGC) { - Xinerama_GC_FUNC_PROLOGUE (pGC); - (*pGC->funcs->DestroyGC)(pGC); - Xinerama_GC_FUNC_EPILOGUE (pGC); + Xinerama_GC_FUNC_PROLOGUE(pGC); + (*pGC->funcs->DestroyGC) (pGC); + Xinerama_GC_FUNC_EPILOGUE(pGC); } static void -XineramaChangeGC ( - GCPtr pGC, - unsigned long mask -){ - Xinerama_GC_FUNC_PROLOGUE (pGC); - - if(mask & GCTileStipXOrigin) - pGCPriv->patOrg.x = pGC->patOrg.x; - if(mask & GCTileStipYOrigin) - pGCPriv->patOrg.y = pGC->patOrg.y; - if(mask & GCClipXOrigin) - pGCPriv->clipOrg.x = pGC->clipOrg.x; - if(mask & GCClipYOrigin) - pGCPriv->clipOrg.y = pGC->clipOrg.y; +XineramaChangeGC(GCPtr pGC, unsigned long mask) +{ + Xinerama_GC_FUNC_PROLOGUE(pGC); + + if (mask & GCTileStipXOrigin) + pGCPriv->patOrg.x = pGC->patOrg.x; + if (mask & GCTileStipYOrigin) + pGCPriv->patOrg.y = pGC->patOrg.y; + if (mask & GCClipXOrigin) + pGCPriv->clipOrg.x = pGC->clipOrg.x; + if (mask & GCClipYOrigin) + pGCPriv->clipOrg.y = pGC->clipOrg.y; (*pGC->funcs->ChangeGC) (pGC, mask); - Xinerama_GC_FUNC_EPILOGUE (pGC); + Xinerama_GC_FUNC_EPILOGUE(pGC); } static void -XineramaCopyGC ( - GCPtr pGCSrc, - unsigned long mask, - GCPtr pGCDst -){ +XineramaCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst) +{ PanoramiXGCPtr pSrcPriv = (PanoramiXGCPtr) - dixLookupPrivate(&pGCSrc->devPrivates, PanoramiXGCKey); - Xinerama_GC_FUNC_PROLOGUE (pGCDst); + dixLookupPrivate(&pGCSrc->devPrivates, PanoramiXGCKey); - if(mask & GCTileStipXOrigin) + Xinerama_GC_FUNC_PROLOGUE(pGCDst); + + if (mask & GCTileStipXOrigin) pGCPriv->patOrg.x = pSrcPriv->patOrg.x; - if(mask & GCTileStipYOrigin) + if (mask & GCTileStipYOrigin) pGCPriv->patOrg.y = pSrcPriv->patOrg.y; - if(mask & GCClipXOrigin) + if (mask & GCClipXOrigin) pGCPriv->clipOrg.x = pSrcPriv->clipOrg.x; - if(mask & GCClipYOrigin) + if (mask & GCClipYOrigin) pGCPriv->clipOrg.y = pSrcPriv->clipOrg.y; (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst); - Xinerama_GC_FUNC_EPILOGUE (pGCDst); + Xinerama_GC_FUNC_EPILOGUE(pGCDst); } static void -XineramaChangeClip ( - GCPtr pGC, - int type, - pointer pvalue, - int nrects -){ - Xinerama_GC_FUNC_PROLOGUE (pGC); +XineramaChangeClip(GCPtr pGC, int type, pointer pvalue, int nrects) +{ + Xinerama_GC_FUNC_PROLOGUE(pGC); (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects); - Xinerama_GC_FUNC_EPILOGUE (pGC); + Xinerama_GC_FUNC_EPILOGUE(pGC); } static void XineramaCopyClip(GCPtr pgcDst, GCPtr pgcSrc) { - Xinerama_GC_FUNC_PROLOGUE (pgcDst); - (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc); - Xinerama_GC_FUNC_EPILOGUE (pgcDst); + Xinerama_GC_FUNC_PROLOGUE(pgcDst); + (*pgcDst->funcs->CopyClip) (pgcDst, pgcSrc); + Xinerama_GC_FUNC_EPILOGUE(pgcDst); } static void XineramaDestroyClip(GCPtr pGC) { - Xinerama_GC_FUNC_PROLOGUE (pGC); - (* pGC->funcs->DestroyClip)(pGC); - Xinerama_GC_FUNC_EPILOGUE (pGC); + Xinerama_GC_FUNC_PROLOGUE(pGC); + (*pGC->funcs->DestroyClip) (pGC); + Xinerama_GC_FUNC_EPILOGUE(pGC); } int @@ -335,16 +326,16 @@ XineramaDeleteResource(pointer data, XID id) } typedef struct { - int screen; - int id; -} PanoramiXSearchData; + int screen; + int id; +} PanoramiXSearchData; -static Bool +static Bool XineramaFindIDByScrnum(pointer resource, XID id, pointer privdata) { - PanoramiXRes *res = (PanoramiXRes*)resource; - PanoramiXSearchData *data = (PanoramiXSearchData*)privdata; - + PanoramiXRes *res = (PanoramiXRes *) resource; + PanoramiXSearchData *data = (PanoramiXSearchData *) privdata; + return res->info[data->screen].id == data->id; } @@ -354,32 +345,32 @@ PanoramiXFindIDByScrnum(RESTYPE type, XID id, int screen) PanoramiXSearchData data; pointer val; - if(!screen) { - dixLookupResourceByType(&val, id, type, serverClient, DixReadAccess); - return val; + if (!screen) { + dixLookupResourceByType(&val, id, type, serverClient, DixReadAccess); + return val; } data.screen = screen; data.id = id; return LookupClientResourceComplex(clients[CLIENT_ID(id)], type, - XineramaFindIDByScrnum, &data); + XineramaFindIDByScrnum, &data); } typedef struct _connect_callback_list { - void (*func)(void); + void (*func) (void); struct _connect_callback_list *next; } XineramaConnectionCallbackList; static XineramaConnectionCallbackList *ConnectionCallbackList = NULL; Bool -XineramaRegisterConnectionBlockCallback(void (*func)(void)) +XineramaRegisterConnectionBlockCallback(void (*func) (void)) { XineramaConnectionCallbackList *newlist; - if(!(newlist = malloc(sizeof(XineramaConnectionCallbackList)))) - return FALSE; + if (!(newlist = malloc(sizeof(XineramaConnectionCallbackList)))) + return FALSE; newlist->next = ConnectionCallbackList; newlist->func = func; @@ -388,44 +379,48 @@ XineramaRegisterConnectionBlockCallback(void (*func)(void)) return TRUE; } -static void XineramaInitData(void) +static void +XineramaInitData(void) { int i, w, h; RegionNull(&PanoramiXScreenRegion); FOR_NSCREENS(i) { - BoxRec TheBox; - RegionRec ScreenRegion; + BoxRec TheBox; + RegionRec ScreenRegion; - ScreenPtr pScreen = screenInfo.screens[i]; + ScreenPtr pScreen = screenInfo.screens[i]; - TheBox.x1 = pScreen->x; - TheBox.x2 = TheBox.x1 + pScreen->width; - TheBox.y1 = pScreen->y; - TheBox.y2 = TheBox.y1 + pScreen->height; + TheBox.x1 = pScreen->x; + TheBox.x2 = TheBox.x1 + pScreen->width; + TheBox.y1 = pScreen->y; + TheBox.y2 = TheBox.y1 + pScreen->height; - RegionInit(&ScreenRegion, &TheBox, 1); - RegionUnion(&PanoramiXScreenRegion, &PanoramiXScreenRegion, - &ScreenRegion); - RegionUninit(&ScreenRegion); + RegionInit(&ScreenRegion, &TheBox, 1); + RegionUnion(&PanoramiXScreenRegion, &PanoramiXScreenRegion, + &ScreenRegion); + RegionUninit(&ScreenRegion); } PanoramiXPixWidth = screenInfo.screens[0]->x + screenInfo.screens[0]->width; - PanoramiXPixHeight = screenInfo.screens[0]->y + screenInfo.screens[0]->height; + PanoramiXPixHeight = + screenInfo.screens[0]->y + screenInfo.screens[0]->height; FOR_NSCREENS_FORWARD_SKIP(i) { - ScreenPtr pScreen = screenInfo.screens[i]; - w = pScreen->x + pScreen->width; - h = pScreen->y + pScreen->height; - - if (PanoramiXPixWidth < w) - PanoramiXPixWidth = w; - if (PanoramiXPixHeight < h) - PanoramiXPixHeight = h; + ScreenPtr pScreen = screenInfo.screens[i]; + + w = pScreen->x + pScreen->width; + h = pScreen->y + pScreen->height; + + if (PanoramiXPixWidth < w) + PanoramiXPixWidth = w; + if (PanoramiXPixHeight < h) + PanoramiXPixHeight = h; } } -void XineramaReinitData(void) +void +XineramaReinitData(void) { RegionUninit(&PanoramiXScreenRegion); XineramaInitData(); @@ -436,103 +431,104 @@ void XineramaReinitData(void) * Called from InitExtensions in main(). * Register PanoramiXeen Extension * Initialize global variables. - */ + */ -void PanoramiXExtensionInit(int argc, char *argv[]) +void +PanoramiXExtensionInit(int argc, char *argv[]) { - int i; - Bool success = FALSE; - ExtensionEntry *extEntry; - ScreenPtr pScreen = screenInfo.screens[0]; - PanoramiXScreenPtr pScreenPriv; + int i; + Bool success = FALSE; + ExtensionEntry *extEntry; + ScreenPtr pScreen = screenInfo.screens[0]; + PanoramiXScreenPtr pScreenPriv; - if (noPanoramiXExtension) - return; + if (noPanoramiXExtension) + return; if (!dixRegisterPrivateKey(&PanoramiXScreenKeyRec, PRIVATE_SCREEN, 0)) { - noPanoramiXExtension = TRUE; - return; + noPanoramiXExtension = TRUE; + return; } - if (!dixRegisterPrivateKey(&PanoramiXGCKeyRec, PRIVATE_GC, sizeof(PanoramiXGCRec))) { - noPanoramiXExtension = TRUE; - return; + if (!dixRegisterPrivateKey + (&PanoramiXGCKeyRec, PRIVATE_GC, sizeof(PanoramiXGCRec))) { + noPanoramiXExtension = TRUE; + return; } PanoramiXNumScreens = screenInfo.numScreens; - if (PanoramiXNumScreens == 1) { /* Only 1 screen */ - noPanoramiXExtension = TRUE; - return; + if (PanoramiXNumScreens == 1) { /* Only 1 screen */ + noPanoramiXExtension = TRUE; + return; } while (panoramiXGeneration != serverGeneration) { - extEntry = AddExtension(PANORAMIX_PROTOCOL_NAME, 0,0, - ProcPanoramiXDispatch, - SProcPanoramiXDispatch, PanoramiXResetProc, - StandardMinorOpcode); - if (!extEntry) - break; - - /* - * First make sure all the basic allocations succeed. If not, - * run in non-PanoramiXeen mode. - */ - - FOR_NSCREENS(i) { - pScreen = screenInfo.screens[i]; - pScreenPriv = malloc(sizeof(PanoramiXScreenRec)); - dixSetPrivate(&pScreen->devPrivates, PanoramiXScreenKey, - pScreenPriv); - if(!pScreenPriv) { - noPanoramiXExtension = TRUE; - return; - } - - pScreenPriv->CreateGC = pScreen->CreateGC; - pScreenPriv->CloseScreen = pScreen->CloseScreen; - - pScreen->CreateGC = XineramaCreateGC; - pScreen->CloseScreen = XineramaCloseScreen; - } - - XRC_DRAWABLE = CreateNewResourceClass(); - XRT_WINDOW = CreateNewResourceType(XineramaDeleteResource, - "XineramaWindow"); - if (XRT_WINDOW) - XRT_WINDOW |= XRC_DRAWABLE; - XRT_PIXMAP = CreateNewResourceType(XineramaDeleteResource, - "XineramaPixmap"); - if (XRT_PIXMAP) - XRT_PIXMAP |= XRC_DRAWABLE; - XRT_GC = CreateNewResourceType(XineramaDeleteResource, - "XineramaGC"); - XRT_COLORMAP = CreateNewResourceType(XineramaDeleteResource, - "XineramaColormap"); - - if (XRT_WINDOW && XRT_PIXMAP && XRT_GC && XRT_COLORMAP) { - panoramiXGeneration = serverGeneration; - success = TRUE; - } - SetResourceTypeErrorValue(XRT_WINDOW, BadWindow); - SetResourceTypeErrorValue(XRT_PIXMAP, BadPixmap); - SetResourceTypeErrorValue(XRT_GC, BadGC); - SetResourceTypeErrorValue(XRT_COLORMAP, BadColor); + extEntry = AddExtension(PANORAMIX_PROTOCOL_NAME, 0, 0, + ProcPanoramiXDispatch, + SProcPanoramiXDispatch, PanoramiXResetProc, + StandardMinorOpcode); + if (!extEntry) + break; + + /* + * First make sure all the basic allocations succeed. If not, + * run in non-PanoramiXeen mode. + */ + + FOR_NSCREENS(i) { + pScreen = screenInfo.screens[i]; + pScreenPriv = malloc(sizeof(PanoramiXScreenRec)); + dixSetPrivate(&pScreen->devPrivates, PanoramiXScreenKey, + pScreenPriv); + if (!pScreenPriv) { + noPanoramiXExtension = TRUE; + return; + } + + pScreenPriv->CreateGC = pScreen->CreateGC; + pScreenPriv->CloseScreen = pScreen->CloseScreen; + + pScreen->CreateGC = XineramaCreateGC; + pScreen->CloseScreen = XineramaCloseScreen; + } + + XRC_DRAWABLE = CreateNewResourceClass(); + XRT_WINDOW = CreateNewResourceType(XineramaDeleteResource, + "XineramaWindow"); + if (XRT_WINDOW) + XRT_WINDOW |= XRC_DRAWABLE; + XRT_PIXMAP = CreateNewResourceType(XineramaDeleteResource, + "XineramaPixmap"); + if (XRT_PIXMAP) + XRT_PIXMAP |= XRC_DRAWABLE; + XRT_GC = CreateNewResourceType(XineramaDeleteResource, "XineramaGC"); + XRT_COLORMAP = CreateNewResourceType(XineramaDeleteResource, + "XineramaColormap"); + + if (XRT_WINDOW && XRT_PIXMAP && XRT_GC && XRT_COLORMAP) { + panoramiXGeneration = serverGeneration; + success = TRUE; + } + SetResourceTypeErrorValue(XRT_WINDOW, BadWindow); + SetResourceTypeErrorValue(XRT_PIXMAP, BadPixmap); + SetResourceTypeErrorValue(XRT_GC, BadGC); + SetResourceTypeErrorValue(XRT_COLORMAP, BadColor); } if (!success) { - noPanoramiXExtension = TRUE; - ErrorF(PANORAMIX_PROTOCOL_NAME " extension failed to initialize\n"); - return; + noPanoramiXExtension = TRUE; + ErrorF(PANORAMIX_PROTOCOL_NAME " extension failed to initialize\n"); + return; } - + XineramaInitData(); /* - * Put our processes into the ProcVector + * Put our processes into the ProcVector */ - for (i = 256; i--; ) - SavedProcVector[i] = ProcVector[i]; + for (i = 256; i--;) + SavedProcVector[i] = ProcVector[i]; ProcVector[X_CreateWindow] = PanoramiXCreateWindow; ProcVector[X_ChangeWindowAttributes] = PanoramiXChangeWindowAttributes; @@ -586,19 +582,20 @@ void PanoramiXExtensionInit(int argc, char *argv[]) ProcVector[X_StoreColors] = PanoramiXStoreColors; ProcVector[X_StoreNamedColor] = PanoramiXStoreNamedColor; - PanoramiXRenderInit (); + PanoramiXRenderInit(); #ifdef XFIXES - PanoramiXFixesInit (); + PanoramiXFixesInit(); #endif #ifdef COMPOSITE - PanoramiXCompositeInit (); + PanoramiXCompositeInit(); #endif } extern Bool CreateConnectionBlock(void); -Bool PanoramiXCreateConnectionBlock(void) +Bool +PanoramiXCreateConnectionBlock(void) { int i, j, length; Bool disableBackingStore = FALSE; @@ -611,40 +608,41 @@ Bool PanoramiXCreateConnectionBlock(void) ScreenPtr pScreen; /* - * Do normal CreateConnectionBlock but faking it for only one screen + * Do normal CreateConnectionBlock but faking it for only one screen */ - if(!PanoramiXNumDepths) { - ErrorF("Xinerama error: No common visuals\n"); - return FALSE; + if (!PanoramiXNumDepths) { + ErrorF("Xinerama error: No common visuals\n"); + return FALSE; } - for(i = 1; i < screenInfo.numScreens; i++) { - pScreen = screenInfo.screens[i]; - if(pScreen->rootDepth != screenInfo.screens[0]->rootDepth) { - ErrorF("Xinerama error: Root window depths differ\n"); - return FALSE; - } - if(pScreen->backingStoreSupport != screenInfo.screens[0]->backingStoreSupport) - disableBackingStore = TRUE; + for (i = 1; i < screenInfo.numScreens; i++) { + pScreen = screenInfo.screens[i]; + if (pScreen->rootDepth != screenInfo.screens[0]->rootDepth) { + ErrorF("Xinerama error: Root window depths differ\n"); + return FALSE; + } + if (pScreen->backingStoreSupport != + screenInfo.screens[0]->backingStoreSupport) + disableBackingStore = TRUE; } if (disableBackingStore) { - for (i = 0; i < screenInfo.numScreens; i++) { - pScreen = screenInfo.screens[i]; - pScreen->backingStoreSupport = NotUseful; - } + for (i = 0; i < screenInfo.numScreens; i++) { + pScreen = screenInfo.screens[i]; + pScreen->backingStoreSupport = NotUseful; + } } i = screenInfo.numScreens; screenInfo.numScreens = 1; if (!CreateConnectionBlock()) { - screenInfo.numScreens = i; - return FALSE; + screenInfo.numScreens = i; + return FALSE; } screenInfo.numScreens = i; - + root = (xWindowRoot *) (ConnectionInfo + connBlockScreenStart); length = connBlockScreenStart + sizeof(xWindowRoot); @@ -652,42 +650,40 @@ Bool PanoramiXCreateConnectionBlock(void) root->nDepths = PanoramiXNumDepths; for (i = 0; i < PanoramiXNumDepths; i++) { - depth = (xDepth *) (ConnectionInfo + length); - depth->depth = PanoramiXDepths[i].depth; - depth->nVisuals = PanoramiXDepths[i].numVids; - length += sizeof(xDepth); - visual = (xVisualType *)(ConnectionInfo + length); - - for (j = 0; j < depth->nVisuals; j++, visual++) { - visual->visualID = PanoramiXDepths[i].vids[j]; - - for (pVisual = PanoramiXVisuals; - pVisual->vid != visual->visualID; - pVisual++) - ; - - visual->class = pVisual->class; - visual->bitsPerRGB = pVisual->bitsPerRGBValue; - visual->colormapEntries = pVisual->ColormapEntries; - visual->redMask = pVisual->redMask; - visual->greenMask = pVisual->greenMask; - visual->blueMask = pVisual->blueMask; - } - - length += (depth->nVisuals * sizeof(xVisualType)); + depth = (xDepth *) (ConnectionInfo + length); + depth->depth = PanoramiXDepths[i].depth; + depth->nVisuals = PanoramiXDepths[i].numVids; + length += sizeof(xDepth); + visual = (xVisualType *) (ConnectionInfo + length); + + for (j = 0; j < depth->nVisuals; j++, visual++) { + visual->visualID = PanoramiXDepths[i].vids[j]; + + for (pVisual = PanoramiXVisuals; + pVisual->vid != visual->visualID; pVisual++); + + visual->class = pVisual->class; + visual->bitsPerRGB = pVisual->bitsPerRGBValue; + visual->colormapEntries = pVisual->ColormapEntries; + visual->redMask = pVisual->redMask; + visual->greenMask = pVisual->greenMask; + visual->blueMask = pVisual->blueMask; + } + + length += (depth->nVisuals * sizeof(xVisualType)); } connSetupPrefix.length = bytes_to_int32(length); for (i = 0; i < PanoramiXNumDepths; i++) - free(PanoramiXDepths[i].vids); + free(PanoramiXDepths[i].vids); free(PanoramiXDepths); PanoramiXDepths = NULL; /* * OK, change some dimensions so it looks as if it were one big screen */ - + old_width = root->pixWidth; old_height = root->pixHeight; @@ -698,13 +694,13 @@ Bool PanoramiXCreateConnectionBlock(void) root->mmWidth *= width_mult; root->mmHeight *= height_mult; - while(ConnectionCallbackList) { - pointer tmp; + while (ConnectionCallbackList) { + pointer tmp; - tmp = (pointer)ConnectionCallbackList; - (*ConnectionCallbackList->func)(); - ConnectionCallbackList = ConnectionCallbackList->next; - free(tmp); + tmp = (pointer) ConnectionCallbackList; + (*ConnectionCallbackList->func) (); + ConnectionCallbackList = ConnectionCallbackList->next; + free(tmp); } return TRUE; @@ -723,14 +719,14 @@ static Bool VisualsEqual(VisualPtr a, ScreenPtr pScreenB, VisualPtr b) { return ((a->class == b->class) && - (a->ColormapEntries == b->ColormapEntries) && - (a->nplanes == b->nplanes) && - (a->redMask == b->redMask) && - (a->greenMask == b->greenMask) && - (a->blueMask == b->blueMask) && - (a->offsetRed == b->offsetRed) && - (a->offsetGreen == b->offsetGreen) && - (a->offsetBlue == b->offsetBlue)); + (a->ColormapEntries == b->ColormapEntries) && + (a->nplanes == b->nplanes) && + (a->redMask == b->redMask) && + (a->greenMask == b->greenMask) && + (a->blueMask == b->blueMask) && + (a->offsetRed == b->offsetRed) && + (a->offsetGreen == b->offsetGreen) && + (a->offsetBlue == b->offsetBlue)); } static void @@ -741,29 +737,29 @@ PanoramiXMaybeAddDepth(DepthPtr pDepth) Bool found = FALSE; FOR_NSCREENS_FORWARD_SKIP(j) { - pScreen = screenInfo.screens[j]; - for (k = 0; k < pScreen->numDepths; k++) { - if (pScreen->allowedDepths[k].depth == pDepth->depth) { - found = TRUE; - break; - } - } + pScreen = screenInfo.screens[j]; + for (k = 0; k < pScreen->numDepths; k++) { + if (pScreen->allowedDepths[k].depth == pDepth->depth) { + found = TRUE; + break; + } + } } if (!found) - return; + return; j = PanoramiXNumDepths; PanoramiXNumDepths++; PanoramiXDepths = realloc(PanoramiXDepths, - PanoramiXNumDepths * sizeof(DepthRec)); + PanoramiXNumDepths * sizeof(DepthRec)); PanoramiXDepths[j].depth = pDepth->depth; PanoramiXDepths[j].numVids = 0; /* XXX suboptimal, should grow these dynamically */ - if(pDepth->numVids) - PanoramiXDepths[j].vids = malloc(sizeof(VisualID) * pDepth->numVids); + if (pDepth->numVids) + PanoramiXDepths[j].vids = malloc(sizeof(VisualID) * pDepth->numVids); else - PanoramiXDepths[j].vids = NULL; + PanoramiXDepths[j].vids = NULL; } static void @@ -774,60 +770,60 @@ PanoramiXMaybeAddVisual(VisualPtr pVisual) Bool found = FALSE; FOR_NSCREENS_FORWARD_SKIP(j) { - pScreen = screenInfo.screens[j]; - found = FALSE; + pScreen = screenInfo.screens[j]; + found = FALSE; - for (k = 0; k < pScreen->numVisuals; k++) { - VisualPtr candidate = &pScreen->visuals[k]; + for (k = 0; k < pScreen->numVisuals; k++) { + VisualPtr candidate = &pScreen->visuals[k]; - if ((*XineramaVisualsEqualPtr)(pVisual, pScreen, candidate) + if ((*XineramaVisualsEqualPtr) (pVisual, pScreen, candidate) #ifdef GLXPROXY - && glxMatchVisual(screenInfo.screens[0], pVisual, pScreen) + && glxMatchVisual(screenInfo.screens[0], pVisual, pScreen) #endif - ) { - found = TRUE; - break; - } - } - - if (!found) - return; + ) { + found = TRUE; + break; + } + } + + if (!found) + return; } /* found a matching visual on all screens, add it to the subset list */ j = PanoramiXNumVisuals; PanoramiXNumVisuals++; PanoramiXVisuals = realloc(PanoramiXVisuals, - PanoramiXNumVisuals * sizeof(VisualRec)); + PanoramiXNumVisuals * sizeof(VisualRec)); memcpy(&PanoramiXVisuals[j], pVisual, sizeof(VisualRec)); for (k = 0; k < PanoramiXNumDepths; k++) { - if (PanoramiXDepths[k].depth == pVisual->nplanes) { - PanoramiXDepths[k].vids[PanoramiXDepths[k].numVids] = pVisual->vid; - PanoramiXDepths[k].numVids++; - break; - } - } + if (PanoramiXDepths[k].depth == pVisual->nplanes) { + PanoramiXDepths[k].vids[PanoramiXDepths[k].numVids] = pVisual->vid; + PanoramiXDepths[k].numVids++; + break; + } + } } extern void PanoramiXConsolidate(void) { - int i; + int i; PanoramiXRes *root, *defmap, *saver; - ScreenPtr pScreen = screenInfo.screens[0]; - DepthPtr pDepth = pScreen->allowedDepths; - VisualPtr pVisual = pScreen->visuals; + ScreenPtr pScreen = screenInfo.screens[0]; + DepthPtr pDepth = pScreen->allowedDepths; + VisualPtr pVisual = pScreen->visuals; PanoramiXNumDepths = 0; PanoramiXNumVisuals = 0; for (i = 0; i < pScreen->numDepths; i++) - PanoramiXMaybeAddDepth(pDepth++); + PanoramiXMaybeAddDepth(pDepth++); for (i = 0; i < pScreen->numVisuals; i++) - PanoramiXMaybeAddVisual(pVisual++); + PanoramiXMaybeAddVisual(pVisual++); root = malloc(sizeof(PanoramiXRes)); root->type = XRT_WINDOW; @@ -837,14 +833,15 @@ PanoramiXConsolidate(void) saver->type = XRT_WINDOW; FOR_NSCREENS(i) { - ScreenPtr pScreen = screenInfo.screens[i]; - root->info[i].id = pScreen->root->drawable.id; - root->u.win.class = InputOutput; + ScreenPtr pScreen = screenInfo.screens[i]; + + root->info[i].id = pScreen->root->drawable.id; + root->u.win.class = InputOutput; root->u.win.root = TRUE; saver->info[i].id = pScreen->screensaver.wid; saver->u.win.class = InputOutput; saver->u.win.root = TRUE; - defmap->info[i].id = pScreen->defColormap; + defmap->info[i].id = pScreen->defColormap; } AddResource(root->info[0].id, XRT_WINDOW, root); @@ -860,169 +857,167 @@ PanoramiXTranslateVisualID(int screen, VisualID orig) int i; for (i = 0; i < PanoramiXNumVisuals; i++) { - if (orig == PanoramiXVisuals[i].vid) { - pVisual = &PanoramiXVisuals[i]; - break; - } + if (orig == PanoramiXVisuals[i].vid) { + pVisual = &PanoramiXVisuals[i]; + break; + } } if (!pVisual) - return 0; + return 0; /* if screen is 0, orig is already the correct visual ID */ if (screen == 0) - return orig; + return orig; /* found the original, now translate it relative to the backend screen */ for (i = 0; i < pOtherScreen->numVisuals; i++) { - VisualPtr pOtherVisual = &pOtherScreen->visuals[i]; + VisualPtr pOtherVisual = &pOtherScreen->visuals[i]; - if ((*XineramaVisualsEqualPtr)(pVisual, pOtherScreen, pOtherVisual)) - return pOtherVisual->vid; + if ((*XineramaVisualsEqualPtr) (pVisual, pOtherScreen, pOtherVisual)) + return pOtherVisual->vid; } return 0; } - /* * PanoramiXResetProc() * Exit, deallocating as needed. */ -static void PanoramiXResetProc(ExtensionEntry* extEntry) +static void +PanoramiXResetProc(ExtensionEntry * extEntry) { - int i; + int i; - PanoramiXRenderReset (); + PanoramiXRenderReset(); #ifdef XFIXES - PanoramiXFixesReset (); + PanoramiXFixesReset(); #endif screenInfo.numScreens = PanoramiXNumScreens; - for (i = 256; i--; ) - ProcVector[i] = SavedProcVector[i]; + for (i = 256; i--;) + ProcVector[i] = SavedProcVector[i]; } - int -ProcPanoramiXQueryVersion (ClientPtr client) +ProcPanoramiXQueryVersion(ClientPtr client) { /* REQUEST(xPanoramiXQueryVersionReq); */ - xPanoramiXQueryVersionReply rep; + xPanoramiXQueryVersionReply rep; - REQUEST_SIZE_MATCH (xPanoramiXQueryVersionReq); + REQUEST_SIZE_MATCH(xPanoramiXQueryVersionReq); rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; rep.majorVersion = SERVER_PANORAMIX_MAJOR_VERSION; rep.minorVersion = SERVER_PANORAMIX_MINOR_VERSION; - if (client->swapped) { + if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); swaps(&rep.majorVersion); swaps(&rep.minorVersion); } - WriteToClient(client, sizeof (xPanoramiXQueryVersionReply), (char *)&rep); + WriteToClient(client, sizeof(xPanoramiXQueryVersionReply), (char *) &rep); return Success; } int ProcPanoramiXGetState(ClientPtr client) { - REQUEST(xPanoramiXGetStateReq); - WindowPtr pWin; - xPanoramiXGetStateReply rep; - int rc; - - REQUEST_SIZE_MATCH(xPanoramiXGetStateReq); - rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); - if (rc != Success) - return rc; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.state = !noPanoramiXExtension; - rep.window = stuff->window; - if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.window); - } - WriteToClient (client, sizeof (xPanoramiXGetStateReply), (char *) &rep); - return Success; + REQUEST(xPanoramiXGetStateReq); + WindowPtr pWin; + xPanoramiXGetStateReply rep; + int rc; + + REQUEST_SIZE_MATCH(xPanoramiXGetStateReq); + rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); + if (rc != Success) + return rc; + + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + rep.state = !noPanoramiXExtension; + rep.window = stuff->window; + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.window); + } + WriteToClient(client, sizeof(xPanoramiXGetStateReply), (char *) &rep); + return Success; } -int +int ProcPanoramiXGetScreenCount(ClientPtr client) { - REQUEST(xPanoramiXGetScreenCountReq); - WindowPtr pWin; - xPanoramiXGetScreenCountReply rep; - int rc; - - REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq); - rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); - if (rc != Success) - return rc; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.ScreenCount = PanoramiXNumScreens; - rep.window = stuff->window; - if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.window); - } - WriteToClient (client, sizeof (xPanoramiXGetScreenCountReply), (char *) &rep); - return Success; + REQUEST(xPanoramiXGetScreenCountReq); + WindowPtr pWin; + xPanoramiXGetScreenCountReply rep; + int rc; + + REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq); + rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); + if (rc != Success) + return rc; + + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + rep.ScreenCount = PanoramiXNumScreens; + rep.window = stuff->window; + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.window); + } + WriteToClient(client, sizeof(xPanoramiXGetScreenCountReply), (char *) &rep); + return Success; } -int +int ProcPanoramiXGetScreenSize(ClientPtr client) { - REQUEST(xPanoramiXGetScreenSizeReq); - WindowPtr pWin; - xPanoramiXGetScreenSizeReply rep; - int rc; - - if (stuff->screen >= PanoramiXNumScreens) - return BadMatch; - - REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq); - rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); - if (rc != Success) - return rc; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - /* screen dimensions */ - rep.width = screenInfo.screens[stuff->screen]->width; - rep.height = screenInfo.screens[stuff->screen]->height; - rep.window = stuff->window; - rep.screen = stuff->screen; - if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.width); - swapl(&rep.height); - swapl(&rep.window); - swapl(&rep.screen); - } - WriteToClient (client, sizeof (xPanoramiXGetScreenSizeReply), (char *) &rep); - return Success; -} + REQUEST(xPanoramiXGetScreenSizeReq); + WindowPtr pWin; + xPanoramiXGetScreenSizeReply rep; + int rc; + if (stuff->screen >= PanoramiXNumScreens) + return BadMatch; + + REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq); + rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); + if (rc != Success) + return rc; + + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + /* screen dimensions */ + rep.width = screenInfo.screens[stuff->screen]->width; + rep.height = screenInfo.screens[stuff->screen]->height; + rep.window = stuff->window; + rep.screen = stuff->screen; + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.width); + swapl(&rep.height); + swapl(&rep.window); + swapl(&rep.screen); + } + WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply), (char *) &rep); + return Success; +} int ProcXineramaIsActive(ClientPtr client) { /* REQUEST(xXineramaIsActiveReq); */ - xXineramaIsActiveReply rep; + xXineramaIsActiveReply rep; REQUEST_SIZE_MATCH(xXineramaIsActiveReq); @@ -1031,28 +1026,27 @@ ProcXineramaIsActive(ClientPtr client) rep.sequenceNumber = client->sequence; #if 1 { - /* The following hack fools clients into thinking that Xinerama - * is disabled even though it is not. */ - rep.state = !noPanoramiXExtension && !PanoramiXExtensionDisabledHack; + /* The following hack fools clients into thinking that Xinerama + * is disabled even though it is not. */ + rep.state = !noPanoramiXExtension && !PanoramiXExtensionDisabledHack; } #else rep.state = !noPanoramiXExtension; #endif if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.state); - } - WriteToClient (client, sizeof (xXineramaIsActiveReply), (char *) &rep); + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.state); + } + WriteToClient(client, sizeof(xXineramaIsActiveReply), (char *) &rep); return Success; } - int ProcXineramaQueryScreens(ClientPtr client) { /* REQUEST(xXineramaQueryScreensReq); */ - xXineramaQueryScreensReply rep; + xXineramaQueryScreensReply rep; REQUEST_SIZE_MATCH(xXineramaQueryScreensReq); @@ -1061,58 +1055,56 @@ ProcXineramaQueryScreens(ClientPtr client) rep.number = (noPanoramiXExtension) ? 0 : PanoramiXNumScreens; rep.length = bytes_to_int32(rep.number * sz_XineramaScreenInfo); if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.number); - } - WriteToClient (client, sizeof (xXineramaQueryScreensReply), (char *) &rep); - - if(!noPanoramiXExtension) { - xXineramaScreenInfo scratch; - int i; - - FOR_NSCREENS(i) { - scratch.x_org = screenInfo.screens[i]->x; - scratch.y_org = screenInfo.screens[i]->y; - scratch.width = screenInfo.screens[i]->width; - scratch.height = screenInfo.screens[i]->height; - - if(client->swapped) { - swaps(&scratch.x_org); - swaps(&scratch.y_org); - swaps(&scratch.width); - swaps(&scratch.height); - } - WriteToClient (client, sz_XineramaScreenInfo, (char *) &scratch); - } + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.number); + } + WriteToClient(client, sizeof(xXineramaQueryScreensReply), (char *) &rep); + + if (!noPanoramiXExtension) { + xXineramaScreenInfo scratch; + int i; + + FOR_NSCREENS(i) { + scratch.x_org = screenInfo.screens[i]->x; + scratch.y_org = screenInfo.screens[i]->y; + scratch.width = screenInfo.screens[i]->width; + scratch.height = screenInfo.screens[i]->height; + + if (client->swapped) { + swaps(&scratch.x_org); + swaps(&scratch.y_org); + swaps(&scratch.width); + swaps(&scratch.height); + } + WriteToClient(client, sz_XineramaScreenInfo, (char *) &scratch); + } } return Success; } - static int -ProcPanoramiXDispatch (ClientPtr client) -{ REQUEST(xReq); - switch (stuff->data) - { - case X_PanoramiXQueryVersion: - return ProcPanoramiXQueryVersion(client); - case X_PanoramiXGetState: - return ProcPanoramiXGetState(client); - case X_PanoramiXGetScreenCount: - return ProcPanoramiXGetScreenCount(client); - case X_PanoramiXGetScreenSize: - return ProcPanoramiXGetScreenSize(client); - case X_XineramaIsActive: - return ProcXineramaIsActive(client); - case X_XineramaQueryScreens: - return ProcXineramaQueryScreens(client); +ProcPanoramiXDispatch(ClientPtr client) +{ + REQUEST(xReq); + switch (stuff->data) { + case X_PanoramiXQueryVersion: + return ProcPanoramiXQueryVersion(client); + case X_PanoramiXGetState: + return ProcPanoramiXGetState(client); + case X_PanoramiXGetScreenCount: + return ProcPanoramiXGetScreenCount(client); + case X_PanoramiXGetScreenSize: + return ProcPanoramiXGetScreenSize(client); + case X_XineramaIsActive: + return ProcXineramaIsActive(client); + case X_XineramaQueryScreens: + return ProcXineramaQueryScreens(client); } return BadRequest; } - #if X_BYTE_ORDER == X_LITTLE_ENDIAN #define SHIFT_L(v,s) (v) << (s) #define SHIFT_R(v,s) (v) >> (s) @@ -1124,34 +1116,31 @@ ProcPanoramiXDispatch (ClientPtr client) static void CopyBits(char *dst, int shiftL, char *src, int bytes) { - /* Just get it to work. Worry about speed later */ + /* Just get it to work. Worry about speed later */ int shiftR = 8 - shiftL; - while(bytes--) { - *dst |= SHIFT_L(*src, shiftL); - *(dst + 1) |= SHIFT_R(*src, shiftR); - dst++; src++; - } + while (bytes--) { + *dst |= SHIFT_L(*src, shiftL); + *(dst + 1) |= SHIFT_R(*src, shiftR); + dst++; + src++; + } } - /* Caution. This doesn't support 2 and 4 bpp formats. We expect 1 bpp and planar data to be already cleared when presented to this function */ void -XineramaGetImageData( - DrawablePtr *pDrawables, - int left, - int top, - int width, - int height, - unsigned int format, - unsigned long planemask, - char *data, - int pitch, - Bool isRoot -){ +XineramaGetImageData(DrawablePtr *pDrawables, + int left, + int top, + int width, + int height, + unsigned int format, + unsigned long planemask, + char *data, int pitch, Bool isRoot) +{ RegionRec SrcRegion, ScreenRegion, GrabRegion; BoxRec SrcBox, *pbox; int x, y, w, h, i, j, nbox, size, sizeNeeded, ScratchPitch, inOut, depth; @@ -1163,129 +1152,136 @@ XineramaGetImageData( /* find box in logical screen space */ SrcBox.x1 = left; SrcBox.y1 = top; - if(!isRoot) { - SrcBox.x1 += pDraw->x + screenInfo.screens[0]->x; - SrcBox.y1 += pDraw->y + screenInfo.screens[0]->y; + if (!isRoot) { + SrcBox.x1 += pDraw->x + screenInfo.screens[0]->x; + SrcBox.y1 += pDraw->y + screenInfo.screens[0]->y; } SrcBox.x2 = SrcBox.x1 + width; SrcBox.y2 = SrcBox.y1 + height; - + RegionInit(&SrcRegion, &SrcBox, 1); RegionNull(&GrabRegion); depth = (format == XYPixmap) ? 1 : pDraw->depth; FOR_NSCREENS(i) { - BoxRec TheBox; - ScreenPtr pScreen; - pDraw = pDrawables[i]; - pScreen = pDraw->pScreen; - - TheBox.x1 = pScreen->x; - TheBox.x2 = TheBox.x1 + pScreen->width; - TheBox.y1 = pScreen->y; - TheBox.y2 = TheBox.y1 + pScreen->height; - - RegionInit(&ScreenRegion, &TheBox, 1); - inOut = RegionContainsRect(&ScreenRegion, &SrcBox); - if(inOut == rgnPART) - RegionIntersect(&GrabRegion, &SrcRegion, &ScreenRegion); - RegionUninit(&ScreenRegion); - - if(inOut == rgnIN) { - (*pScreen->GetImage)(pDraw, - SrcBox.x1 - pDraw->x - screenInfo.screens[i]->x, - SrcBox.y1 - pDraw->y - screenInfo.screens[i]->y, - width, height, format, planemask, data); - break; - } else if (inOut == rgnOUT) - continue; - - nbox = RegionNumRects(&GrabRegion); - - if(nbox) { - pbox = RegionRects(&GrabRegion); - - while(nbox--) { - w = pbox->x2 - pbox->x1; - h = pbox->y2 - pbox->y1; - ScratchPitch = PixmapBytePad(w, depth); - sizeNeeded = ScratchPitch * h; - - if(sizeNeeded > size) { - char *tmpdata = ScratchMem; - ScratchMem = realloc(ScratchMem, sizeNeeded); - if(ScratchMem) - size = sizeNeeded; - else { - ScratchMem = tmpdata; - break; - } - } - - x = pbox->x1 - pDraw->x - screenInfo.screens[i]->x; - y = pbox->y1 - pDraw->y - screenInfo.screens[i]->y; - - (*pScreen->GetImage)(pDraw, x, y, w, h, - format, planemask, ScratchMem); - - /* copy the memory over */ - - if(depth == 1) { - int k, shift, leftover, index, index2; - - x = pbox->x1 - SrcBox.x1; - y = pbox->y1 - SrcBox.y1; - shift = x & 7; - x >>= 3; - leftover = w & 7; - w >>= 3; - - /* clean up the edge */ - if(leftover) { - int mask = (1 << leftover) - 1; - for(j = h, k = w; j--; k += ScratchPitch) - ScratchMem[k] &= mask; - } - - for(j = 0, index = (pitch * y) + x, index2 = 0; j < h; - j++, index += pitch, index2 += ScratchPitch) - { - if(w) { - if(!shift) - memcpy(data + index, ScratchMem + index2, w); - else - CopyBits(data + index, shift, - ScratchMem + index2, w); - } - - if(leftover) { - data[index + w] |= - SHIFT_L(ScratchMem[index2 + w], shift); - if((shift + leftover) > 8) - data[index + w + 1] |= - SHIFT_R(ScratchMem[index2 + w],(8 - shift)); - } - } - } else { - j = BitsPerPixel(depth) >> 3; - x = (pbox->x1 - SrcBox.x1) * j; - y = pbox->y1 - SrcBox.y1; - w *= j; - - for(j = 0; j < h; j++) { - memcpy(data + (pitch * (y + j)) + x, - ScratchMem + (ScratchPitch * j), w); - } - } - pbox++; - } - - RegionSubtract(&SrcRegion, &SrcRegion, &GrabRegion); - if(!RegionNotEmpty(&SrcRegion)) - break; - } - + BoxRec TheBox; + ScreenPtr pScreen; + + pDraw = pDrawables[i]; + pScreen = pDraw->pScreen; + + TheBox.x1 = pScreen->x; + TheBox.x2 = TheBox.x1 + pScreen->width; + TheBox.y1 = pScreen->y; + TheBox.y2 = TheBox.y1 + pScreen->height; + + RegionInit(&ScreenRegion, &TheBox, 1); + inOut = RegionContainsRect(&ScreenRegion, &SrcBox); + if (inOut == rgnPART) + RegionIntersect(&GrabRegion, &SrcRegion, &ScreenRegion); + RegionUninit(&ScreenRegion); + + if (inOut == rgnIN) { + (*pScreen->GetImage) (pDraw, + SrcBox.x1 - pDraw->x - + screenInfo.screens[i]->x, + SrcBox.y1 - pDraw->y - + screenInfo.screens[i]->y, width, height, + format, planemask, data); + break; + } + else if (inOut == rgnOUT) + continue; + + nbox = RegionNumRects(&GrabRegion); + + if (nbox) { + pbox = RegionRects(&GrabRegion); + + while (nbox--) { + w = pbox->x2 - pbox->x1; + h = pbox->y2 - pbox->y1; + ScratchPitch = PixmapBytePad(w, depth); + sizeNeeded = ScratchPitch * h; + + if (sizeNeeded > size) { + char *tmpdata = ScratchMem; + + ScratchMem = realloc(ScratchMem, sizeNeeded); + if (ScratchMem) + size = sizeNeeded; + else { + ScratchMem = tmpdata; + break; + } + } + + x = pbox->x1 - pDraw->x - screenInfo.screens[i]->x; + y = pbox->y1 - pDraw->y - screenInfo.screens[i]->y; + + (*pScreen->GetImage) (pDraw, x, y, w, h, + format, planemask, ScratchMem); + + /* copy the memory over */ + + if (depth == 1) { + int k, shift, leftover, index, index2; + + x = pbox->x1 - SrcBox.x1; + y = pbox->y1 - SrcBox.y1; + shift = x & 7; + x >>= 3; + leftover = w & 7; + w >>= 3; + + /* clean up the edge */ + if (leftover) { + int mask = (1 << leftover) - 1; + + for (j = h, k = w; j--; k += ScratchPitch) + ScratchMem[k] &= mask; + } + + for (j = 0, index = (pitch * y) + x, index2 = 0; j < h; + j++, index += pitch, index2 += ScratchPitch) { + if (w) { + if (!shift) + memcpy(data + index, ScratchMem + index2, w); + else + CopyBits(data + index, shift, + ScratchMem + index2, w); + } + + if (leftover) { + data[index + w] |= + SHIFT_L(ScratchMem[index2 + w], shift); + if ((shift + leftover) > 8) + data[index + w + 1] |= + SHIFT_R(ScratchMem[index2 + w], + (8 - shift)); + } + } + } + else { + j = BitsPerPixel(depth) >> 3; + x = (pbox->x1 - SrcBox.x1) * j; + y = pbox->y1 - SrcBox.y1; + w *= j; + + for (j = 0; j < h; j++) { + memcpy(data + (pitch * (y + j)) + x, + ScratchMem + (ScratchPitch * j), w); + } + } + pbox++; + } + + RegionSubtract(&SrcRegion, &SrcRegion, &GrabRegion); + if (!RegionNotEmpty(&SrcRegion)) + break; + } + } free(ScratchMem); diff --git a/xorg-server/Xext/panoramiXSwap.c b/xorg-server/Xext/panoramiXSwap.c index 79277021a..b6ff6f918 100644 --- a/xorg-server/Xext/panoramiXSwap.c +++ b/xorg-server/Xext/panoramiXSwap.c @@ -48,89 +48,86 @@ Equipment Corporation. #include "panoramiXh.h" static int -SProcPanoramiXQueryVersion (ClientPtr client) +SProcPanoramiXQueryVersion(ClientPtr client) { - REQUEST(xPanoramiXQueryVersionReq); + REQUEST(xPanoramiXQueryVersionReq); - swaps(&stuff->length); - REQUEST_SIZE_MATCH (xPanoramiXQueryVersionReq); - return ProcPanoramiXQueryVersion(client); + swaps(&stuff->length); + REQUEST_SIZE_MATCH(xPanoramiXQueryVersionReq); + return ProcPanoramiXQueryVersion(client); } static int SProcPanoramiXGetState(ClientPtr client) { - REQUEST(xPanoramiXGetStateReq); + REQUEST(xPanoramiXGetStateReq); - swaps(&stuff->length); - REQUEST_SIZE_MATCH(xPanoramiXGetStateReq); - swapl(&stuff->window); - return ProcPanoramiXGetState(client); + swaps(&stuff->length); + REQUEST_SIZE_MATCH(xPanoramiXGetStateReq); + swapl(&stuff->window); + return ProcPanoramiXGetState(client); } -static int +static int SProcPanoramiXGetScreenCount(ClientPtr client) { - REQUEST(xPanoramiXGetScreenCountReq); + REQUEST(xPanoramiXGetScreenCountReq); - swaps(&stuff->length); - REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq); - swapl(&stuff->window); - return ProcPanoramiXGetScreenCount(client); + swaps(&stuff->length); + REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq); + swapl(&stuff->window); + return ProcPanoramiXGetScreenCount(client); } -static int +static int SProcPanoramiXGetScreenSize(ClientPtr client) { - REQUEST(xPanoramiXGetScreenSizeReq); + REQUEST(xPanoramiXGetScreenSizeReq); - swaps(&stuff->length); - REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq); - swapl(&stuff->window); - swapl(&stuff->screen); - return ProcPanoramiXGetScreenSize(client); + swaps(&stuff->length); + REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq); + swapl(&stuff->window); + swapl(&stuff->screen); + return ProcPanoramiXGetScreenSize(client); } - -static int +static int SProcXineramaIsActive(ClientPtr client) { - REQUEST(xXineramaIsActiveReq); + REQUEST(xXineramaIsActiveReq); - swaps(&stuff->length); - REQUEST_SIZE_MATCH(xXineramaIsActiveReq); - return ProcXineramaIsActive(client); + swaps(&stuff->length); + REQUEST_SIZE_MATCH(xXineramaIsActiveReq); + return ProcXineramaIsActive(client); } - -static int +static int SProcXineramaQueryScreens(ClientPtr client) { - REQUEST(xXineramaQueryScreensReq); + REQUEST(xXineramaQueryScreensReq); - swaps(&stuff->length); - REQUEST_SIZE_MATCH(xXineramaQueryScreensReq); - return ProcXineramaQueryScreens(client); + swaps(&stuff->length); + REQUEST_SIZE_MATCH(xXineramaQueryScreensReq); + return ProcXineramaQueryScreens(client); } - int -SProcPanoramiXDispatch (ClientPtr client) -{ REQUEST(xReq); - switch (stuff->data) - { - case X_PanoramiXQueryVersion: - return SProcPanoramiXQueryVersion(client); - case X_PanoramiXGetState: - return SProcPanoramiXGetState(client); - case X_PanoramiXGetScreenCount: - return SProcPanoramiXGetScreenCount(client); - case X_PanoramiXGetScreenSize: - return SProcPanoramiXGetScreenSize(client); - case X_XineramaIsActive: - return SProcXineramaIsActive(client); - case X_XineramaQueryScreens: - return SProcXineramaQueryScreens(client); +SProcPanoramiXDispatch(ClientPtr client) +{ + REQUEST(xReq); + switch (stuff->data) { + case X_PanoramiXQueryVersion: + return SProcPanoramiXQueryVersion(client); + case X_PanoramiXGetState: + return SProcPanoramiXGetState(client); + case X_PanoramiXGetScreenCount: + return SProcPanoramiXGetScreenCount(client); + case X_PanoramiXGetScreenSize: + return SProcPanoramiXGetScreenSize(client); + case X_XineramaIsActive: + return SProcXineramaIsActive(client); + case X_XineramaQueryScreens: + return SProcXineramaQueryScreens(client); } return BadRequest; } diff --git a/xorg-server/Xext/panoramiXprocs.c b/xorg-server/Xext/panoramiXprocs.c index 9ea461173..12d6163bb 100644 --- a/xorg-server/Xext/panoramiXprocs.c +++ b/xorg-server/Xext/panoramiXprocs.c @@ -25,7 +25,6 @@ Equipment Corporation. /* Massively rewritten by Mark Vojkovich <markv@valinux.com> */ - #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> #endif @@ -52,12 +51,14 @@ Equipment Corporation. #define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \ CWDontPropagate | CWOverrideRedirect | CWCursor ) -int PanoramiXCreateWindow(ClientPtr client) +int +PanoramiXCreateWindow(ClientPtr client) { PanoramiXRes *parent, *newWin; PanoramiXRes *backPix = NULL; PanoramiXRes *bordPix = NULL; - PanoramiXRes *cmap = NULL; + PanoramiXRes *cmap = NULL; + REQUEST(xCreateWindowReq); int pback_offset = 0, pbord_offset = 0, cmap_offset = 0; int result, len, j; @@ -66,54 +67,55 @@ int PanoramiXCreateWindow(ClientPtr client) Bool parentIsRoot; REQUEST_AT_LEAST_SIZE(xCreateWindowReq); - + len = client->req_len - bytes_to_int32(sizeof(xCreateWindowReq)); if (Ones(stuff->mask) != len) return BadLength; - result = dixLookupResourceByType((pointer *)&parent, stuff->parent, - XRT_WINDOW, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &parent, stuff->parent, + XRT_WINDOW, client, DixWriteAccess); if (result != Success) return result; - if(stuff->class == CopyFromParent) - stuff->class = parent->u.win.class; + if (stuff->class == CopyFromParent) + stuff->class = parent->u.win.class; - if((stuff->class == InputOnly) && (stuff->mask & (~INPUTONLY_LEGAL_MASK))) + if ((stuff->class == InputOnly) && (stuff->mask & (~INPUTONLY_LEGAL_MASK))) return BadMatch; - if ((Mask)stuff->mask & CWBackPixmap) { - pback_offset = Ones((Mask)stuff->mask & (CWBackPixmap - 1)); - tmp = *((CARD32 *) &stuff[1] + pback_offset); - if ((tmp != None) && (tmp != ParentRelative)) { - result = dixLookupResourceByType((pointer *)&backPix, tmp, - XRT_PIXMAP, client, DixReadAccess); - if (result != Success) - return result; - } - } - if ((Mask)stuff->mask & CWBorderPixmap) { - pbord_offset = Ones((Mask)stuff->mask & (CWBorderPixmap - 1)); - tmp = *((CARD32 *) &stuff[1] + pbord_offset); - if (tmp != CopyFromParent) { - result = dixLookupResourceByType((pointer *)&bordPix, tmp, - XRT_PIXMAP, client, DixReadAccess); - if (result != Success) - return result; - } - } - if ((Mask)stuff->mask & CWColormap) { - cmap_offset = Ones((Mask)stuff->mask & (CWColormap - 1)); - tmp = *((CARD32 *) &stuff[1] + cmap_offset); - if ((tmp != CopyFromParent) && (tmp != None)) { - result = dixLookupResourceByType((pointer *)&cmap, tmp, - XRT_COLORMAP, client, DixReadAccess); - if (result != Success) - return result; - } - } - - if(!(newWin = malloc(sizeof(PanoramiXRes)))) + if ((Mask) stuff->mask & CWBackPixmap) { + pback_offset = Ones((Mask) stuff->mask & (CWBackPixmap - 1)); + tmp = *((CARD32 *) &stuff[1] + pback_offset); + if ((tmp != None) && (tmp != ParentRelative)) { + result = dixLookupResourceByType((pointer *) &backPix, tmp, + XRT_PIXMAP, client, DixReadAccess); + if (result != Success) + return result; + } + } + if ((Mask) stuff->mask & CWBorderPixmap) { + pbord_offset = Ones((Mask) stuff->mask & (CWBorderPixmap - 1)); + tmp = *((CARD32 *) &stuff[1] + pbord_offset); + if (tmp != CopyFromParent) { + result = dixLookupResourceByType((pointer *) &bordPix, tmp, + XRT_PIXMAP, client, DixReadAccess); + if (result != Success) + return result; + } + } + if ((Mask) stuff->mask & CWColormap) { + cmap_offset = Ones((Mask) stuff->mask & (CWColormap - 1)); + tmp = *((CARD32 *) &stuff[1] + cmap_offset); + if ((tmp != CopyFromParent) && (tmp != None)) { + result = dixLookupResourceByType((pointer *) &cmap, tmp, + XRT_COLORMAP, client, + DixReadAccess); + if (result != Success) + return result; + } + } + + if (!(newWin = malloc(sizeof(PanoramiXRes)))) return BadAlloc; newWin->type = XRT_WINDOW; @@ -123,326 +125,346 @@ int PanoramiXCreateWindow(ClientPtr client) panoramix_setup_ids(newWin, client, stuff->wid); if (stuff->class == InputOnly) - stuff->visual = CopyFromParent; + stuff->visual = CopyFromParent; orig_visual = stuff->visual; orig_x = stuff->x; orig_y = stuff->y; - parentIsRoot = (stuff->parent == screenInfo.screens[0]->root->drawable.id) || - (stuff->parent == screenInfo.screens[0]->screensaver.wid); + parentIsRoot = (stuff->parent == screenInfo.screens[0]->root->drawable.id) + || (stuff->parent == screenInfo.screens[0]->screensaver.wid); FOR_NSCREENS_BACKWARD(j) { stuff->wid = newWin->info[j].id; stuff->parent = parent->info[j].id; - if (parentIsRoot) { - stuff->x = orig_x - screenInfo.screens[j]->x; - stuff->y = orig_y - screenInfo.screens[j]->y; - } - if (backPix) - *((CARD32 *) &stuff[1] + pback_offset) = backPix->info[j].id; - if (bordPix) - *((CARD32 *) &stuff[1] + pbord_offset) = bordPix->info[j].id; - if (cmap) - *((CARD32 *) &stuff[1] + cmap_offset) = cmap->info[j].id; - if ( orig_visual != CopyFromParent ) - stuff->visual = PanoramiXTranslateVisualID(j, orig_visual); - result = (*SavedProcVector[X_CreateWindow])(client); - if(result != Success) break; + if (parentIsRoot) { + stuff->x = orig_x - screenInfo.screens[j]->x; + stuff->y = orig_y - screenInfo.screens[j]->y; + } + if (backPix) + *((CARD32 *) &stuff[1] + pback_offset) = backPix->info[j].id; + if (bordPix) + *((CARD32 *) &stuff[1] + pbord_offset) = bordPix->info[j].id; + if (cmap) + *((CARD32 *) &stuff[1] + cmap_offset) = cmap->info[j].id; + if (orig_visual != CopyFromParent) + stuff->visual = PanoramiXTranslateVisualID(j, orig_visual); + result = (*SavedProcVector[X_CreateWindow]) (client); + if (result != Success) + break; } if (result == Success) AddResource(newWin->info[0].id, XRT_WINDOW, newWin); - else + else free(newWin); return result; } - -int PanoramiXChangeWindowAttributes(ClientPtr client) +int +PanoramiXChangeWindowAttributes(ClientPtr client) { PanoramiXRes *win; PanoramiXRes *backPix = NULL; PanoramiXRes *bordPix = NULL; - PanoramiXRes *cmap = NULL; + PanoramiXRes *cmap = NULL; + REQUEST(xChangeWindowAttributesReq); int pback_offset = 0, pbord_offset = 0, cmap_offset = 0; int result, len, j; XID tmp; REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq); - + len = client->req_len - bytes_to_int32(sizeof(xChangeWindowAttributesReq)); if (Ones(stuff->valueMask) != len) return BadLength; - result = dixLookupResourceByType((pointer *)&win, stuff->window, - XRT_WINDOW, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->window, + XRT_WINDOW, client, DixWriteAccess); if (result != Success) return result; - if((win->u.win.class == InputOnly) && - (stuff->valueMask & (~INPUTONLY_LEGAL_MASK))) + if ((win->u.win.class == InputOnly) && + (stuff->valueMask & (~INPUTONLY_LEGAL_MASK))) return BadMatch; - if ((Mask)stuff->valueMask & CWBackPixmap) { - pback_offset = Ones((Mask)stuff->valueMask & (CWBackPixmap - 1)); - tmp = *((CARD32 *) &stuff[1] + pback_offset); - if ((tmp != None) && (tmp != ParentRelative)) { - result = dixLookupResourceByType((pointer *)&backPix, tmp, - XRT_PIXMAP, client, DixReadAccess); - if (result != Success) - return result; - } - } - if ((Mask)stuff->valueMask & CWBorderPixmap) { - pbord_offset = Ones((Mask)stuff->valueMask & (CWBorderPixmap - 1)); - tmp = *((CARD32 *) &stuff[1] + pbord_offset); - if (tmp != CopyFromParent) { - result = dixLookupResourceByType((pointer *)&bordPix, tmp, - XRT_PIXMAP, client, DixReadAccess); - if (result != Success) - return result; - } - } - if ((Mask)stuff->valueMask & CWColormap) { - cmap_offset = Ones((Mask)stuff->valueMask & (CWColormap - 1)); - tmp = *((CARD32 *) &stuff[1] + cmap_offset); - if ((tmp != CopyFromParent) && (tmp != None)) { - result = dixLookupResourceByType((pointer *)&cmap, tmp, - XRT_COLORMAP, client, DixReadAccess); - if (result != Success) - return result; - } + if ((Mask) stuff->valueMask & CWBackPixmap) { + pback_offset = Ones((Mask) stuff->valueMask & (CWBackPixmap - 1)); + tmp = *((CARD32 *) &stuff[1] + pback_offset); + if ((tmp != None) && (tmp != ParentRelative)) { + result = dixLookupResourceByType((pointer *) &backPix, tmp, + XRT_PIXMAP, client, DixReadAccess); + if (result != Success) + return result; + } + } + if ((Mask) stuff->valueMask & CWBorderPixmap) { + pbord_offset = Ones((Mask) stuff->valueMask & (CWBorderPixmap - 1)); + tmp = *((CARD32 *) &stuff[1] + pbord_offset); + if (tmp != CopyFromParent) { + result = dixLookupResourceByType((pointer *) &bordPix, tmp, + XRT_PIXMAP, client, DixReadAccess); + if (result != Success) + return result; + } + } + if ((Mask) stuff->valueMask & CWColormap) { + cmap_offset = Ones((Mask) stuff->valueMask & (CWColormap - 1)); + tmp = *((CARD32 *) &stuff[1] + cmap_offset); + if ((tmp != CopyFromParent) && (tmp != None)) { + result = dixLookupResourceByType((pointer *) &cmap, tmp, + XRT_COLORMAP, client, + DixReadAccess); + if (result != Success) + return result; + } } FOR_NSCREENS_BACKWARD(j) { stuff->window = win->info[j].id; - if (backPix) - *((CARD32 *) &stuff[1] + pback_offset) = backPix->info[j].id; - if (bordPix) - *((CARD32 *) &stuff[1] + pbord_offset) = bordPix->info[j].id; - if (cmap) - *((CARD32 *) &stuff[1] + cmap_offset) = cmap->info[j].id; - result = (*SavedProcVector[X_ChangeWindowAttributes])(client); + if (backPix) + *((CARD32 *) &stuff[1] + pback_offset) = backPix->info[j].id; + if (bordPix) + *((CARD32 *) &stuff[1] + pbord_offset) = bordPix->info[j].id; + if (cmap) + *((CARD32 *) &stuff[1] + cmap_offset) = cmap->info[j].id; + result = (*SavedProcVector[X_ChangeWindowAttributes]) (client); } return result; } - -int PanoramiXDestroyWindow(ClientPtr client) +int +PanoramiXDestroyWindow(ClientPtr client) { PanoramiXRes *win; - int result, j; + int result, j; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - result = dixLookupResourceByType((pointer *)&win, stuff->id, XRT_WINDOW, - client, DixDestroyAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->id, XRT_WINDOW, + client, DixDestroyAccess); if (result != Success) - return result; + return result; FOR_NSCREENS_BACKWARD(j) { - stuff->id = win->info[j].id; - result = (*SavedProcVector[X_DestroyWindow])(client); - if(result != Success) break; + stuff->id = win->info[j].id; + result = (*SavedProcVector[X_DestroyWindow]) (client); + if (result != Success) + break; } /* Since ProcDestroyWindow is using FreeResource, it will free - our resource for us on the last pass through the loop above */ - + our resource for us on the last pass through the loop above */ + return result; } - -int PanoramiXDestroySubwindows(ClientPtr client) +int +PanoramiXDestroySubwindows(ClientPtr client) { PanoramiXRes *win; - int result, j; + int result, j; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - result = dixLookupResourceByType((pointer *)&win, stuff->id, XRT_WINDOW, - client, DixDestroyAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->id, XRT_WINDOW, + client, DixDestroyAccess); if (result != Success) - return result; + return result; FOR_NSCREENS_BACKWARD(j) { - stuff->id = win->info[j].id; - result = (*SavedProcVector[X_DestroySubwindows])(client); - if(result != Success) break; + stuff->id = win->info[j].id; + result = (*SavedProcVector[X_DestroySubwindows]) (client); + if (result != Success) + break; } /* DestroySubwindows is using FreeResource which will free - our resources for us on the last pass through the loop above */ + our resources for us on the last pass through the loop above */ return result; } - -int PanoramiXChangeSaveSet(ClientPtr client) +int +PanoramiXChangeSaveSet(ClientPtr client) { PanoramiXRes *win; - int result, j; + int result, j; + REQUEST(xChangeSaveSetReq); REQUEST_SIZE_MATCH(xChangeSaveSetReq); - result = dixLookupResourceByType((pointer *)&win, stuff->window, - XRT_WINDOW, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->window, + XRT_WINDOW, client, DixReadAccess); if (result != Success) - return result; + return result; FOR_NSCREENS_BACKWARD(j) { - stuff->window = win->info[j].id; - result = (*SavedProcVector[X_ChangeSaveSet])(client); - if(result != Success) break; + stuff->window = win->info[j].id; + result = (*SavedProcVector[X_ChangeSaveSet]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXReparentWindow(ClientPtr client) +int +PanoramiXReparentWindow(ClientPtr client) { PanoramiXRes *win, *parent; - int result, j; - int x, y; - Bool parentIsRoot; + int result, j; + int x, y; + Bool parentIsRoot; + REQUEST(xReparentWindowReq); REQUEST_SIZE_MATCH(xReparentWindowReq); - result = dixLookupResourceByType((pointer *)&win, stuff->window, - XRT_WINDOW, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->window, + XRT_WINDOW, client, DixWriteAccess); if (result != Success) - return result; + return result; - result = dixLookupResourceByType((pointer *)&parent, stuff->parent, - XRT_WINDOW, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &parent, stuff->parent, + XRT_WINDOW, client, DixWriteAccess); if (result != Success) - return result; + return result; x = stuff->x; y = stuff->y; - parentIsRoot = (stuff->parent == screenInfo.screens[0]->root->drawable.id) || - (stuff->parent == screenInfo.screens[0]->screensaver.wid); + parentIsRoot = (stuff->parent == screenInfo.screens[0]->root->drawable.id) + || (stuff->parent == screenInfo.screens[0]->screensaver.wid); FOR_NSCREENS_BACKWARD(j) { - stuff->window = win->info[j].id; - stuff->parent = parent->info[j].id; - if(parentIsRoot) { - stuff->x = x - screenInfo.screens[j]->x; - stuff->y = y - screenInfo.screens[j]->y; - } - result = (*SavedProcVector[X_ReparentWindow])(client); - if(result != Success) break; + stuff->window = win->info[j].id; + stuff->parent = parent->info[j].id; + if (parentIsRoot) { + stuff->x = x - screenInfo.screens[j]->x; + stuff->y = y - screenInfo.screens[j]->y; + } + result = (*SavedProcVector[X_ReparentWindow]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXMapWindow(ClientPtr client) +int +PanoramiXMapWindow(ClientPtr client) { PanoramiXRes *win; - int result, j; + int result, j; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - result = dixLookupResourceByType((pointer *)&win, stuff->id, - XRT_WINDOW, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->id, + XRT_WINDOW, client, DixReadAccess); if (result != Success) - return result; + return result; FOR_NSCREENS_FORWARD(j) { - stuff->id = win->info[j].id; - result = (*SavedProcVector[X_MapWindow])(client); - if(result != Success) break; + stuff->id = win->info[j].id; + result = (*SavedProcVector[X_MapWindow]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXMapSubwindows(ClientPtr client) +int +PanoramiXMapSubwindows(ClientPtr client) { PanoramiXRes *win; - int result, j; + int result, j; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - result = dixLookupResourceByType((pointer *)&win, stuff->id, - XRT_WINDOW, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->id, + XRT_WINDOW, client, DixReadAccess); if (result != Success) - return result; + return result; FOR_NSCREENS_FORWARD(j) { - stuff->id = win->info[j].id; - result = (*SavedProcVector[X_MapSubwindows])(client); - if(result != Success) break; + stuff->id = win->info[j].id; + result = (*SavedProcVector[X_MapSubwindows]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXUnmapWindow(ClientPtr client) +int +PanoramiXUnmapWindow(ClientPtr client) { PanoramiXRes *win; - int result, j; + int result, j; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - result = dixLookupResourceByType((pointer *)&win, stuff->id, - XRT_WINDOW, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->id, + XRT_WINDOW, client, DixReadAccess); if (result != Success) - return result; + return result; FOR_NSCREENS_FORWARD(j) { - stuff->id = win->info[j].id; - result = (*SavedProcVector[X_UnmapWindow])(client); - if(result != Success) break; + stuff->id = win->info[j].id; + result = (*SavedProcVector[X_UnmapWindow]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXUnmapSubwindows(ClientPtr client) +int +PanoramiXUnmapSubwindows(ClientPtr client) { PanoramiXRes *win; - int result, j; + int result, j; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - result = dixLookupResourceByType((pointer *)&win, stuff->id, - XRT_WINDOW, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->id, + XRT_WINDOW, client, DixReadAccess); if (result != Success) - return result; + return result; FOR_NSCREENS_FORWARD(j) { - stuff->id = win->info[j].id; - result = (*SavedProcVector[X_UnmapSubwindows])(client); - if(result != Success) break; + stuff->id = win->info[j].id; + result = (*SavedProcVector[X_UnmapSubwindows]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXConfigureWindow(ClientPtr client) +int +PanoramiXConfigureWindow(ClientPtr client) { PanoramiXRes *win; PanoramiXRes *sib = NULL; - WindowPtr pWin; - int result, j, len, sib_offset = 0, x = 0, y = 0; - int x_offset = -1; - int y_offset = -1; + WindowPtr pWin; + int result, j, len, sib_offset = 0, x = 0, y = 0; + int x_offset = -1; + int y_offset = -1; + REQUEST(xConfigureWindowReq); REQUEST_AT_LEAST_SIZE(xConfigureWindowReq); @@ -452,92 +474,97 @@ int PanoramiXConfigureWindow(ClientPtr client) return BadLength; /* because we need the parent */ - result = dixLookupResourceByType((pointer *)&pWin, stuff->window, - RT_WINDOW, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &pWin, stuff->window, + RT_WINDOW, client, DixWriteAccess); if (result != Success) - return result; + return result; - result = dixLookupResourceByType((pointer *)&win, stuff->window, - XRT_WINDOW, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->window, + XRT_WINDOW, client, DixWriteAccess); if (result != Success) - return result; + return result; + + if ((Mask) stuff->mask & CWSibling) { + XID tmp; - if ((Mask)stuff->mask & CWSibling) { - XID tmp; - sib_offset = Ones((Mask)stuff->mask & (CWSibling - 1)); - if ((tmp = *((CARD32 *) &stuff[1] + sib_offset))) { - result = dixLookupResourceByType((pointer *)&sib, tmp, XRT_WINDOW, - client, DixReadAccess); - if (result != Success) - return result; - } + sib_offset = Ones((Mask) stuff->mask & (CWSibling - 1)); + if ((tmp = *((CARD32 *) &stuff[1] + sib_offset))) { + result = dixLookupResourceByType((pointer *) &sib, tmp, XRT_WINDOW, + client, DixReadAccess); + if (result != Success) + return result; + } } - if(pWin->parent && ((pWin->parent == screenInfo.screens[0]->root) || - (pWin->parent->drawable.id == screenInfo.screens[0]->screensaver.wid))) - { - if ((Mask)stuff->mask & CWX) { - x_offset = 0; - x = *((CARD32 *)&stuff[1]); - } - if ((Mask)stuff->mask & CWY) { - y_offset = (x_offset == -1) ? 0 : 1; - y = *((CARD32 *) &stuff[1] + y_offset); - } + if (pWin->parent && ((pWin->parent == screenInfo.screens[0]->root) || + (pWin->parent->drawable.id == + screenInfo.screens[0]->screensaver.wid))) { + if ((Mask) stuff->mask & CWX) { + x_offset = 0; + x = *((CARD32 *) &stuff[1]); + } + if ((Mask) stuff->mask & CWY) { + y_offset = (x_offset == -1) ? 0 : 1; + y = *((CARD32 *) &stuff[1] + y_offset); + } } /* have to go forward or you get expose events before - ConfigureNotify events */ + ConfigureNotify events */ FOR_NSCREENS_FORWARD(j) { - stuff->window = win->info[j].id; - if(sib) - *((CARD32 *) &stuff[1] + sib_offset) = sib->info[j].id; - if(x_offset >= 0) - *((CARD32 *) &stuff[1] + x_offset) = x - screenInfo.screens[j]->x; - if(y_offset >= 0) - *((CARD32 *) &stuff[1] + y_offset) = y - screenInfo.screens[j]->y; - result = (*SavedProcVector[X_ConfigureWindow])(client); - if(result != Success) break; + stuff->window = win->info[j].id; + if (sib) + *((CARD32 *) &stuff[1] + sib_offset) = sib->info[j].id; + if (x_offset >= 0) + *((CARD32 *) &stuff[1] + x_offset) = x - screenInfo.screens[j]->x; + if (y_offset >= 0) + *((CARD32 *) &stuff[1] + y_offset) = y - screenInfo.screens[j]->y; + result = (*SavedProcVector[X_ConfigureWindow]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXCirculateWindow(ClientPtr client) +int +PanoramiXCirculateWindow(ClientPtr client) { PanoramiXRes *win; - int result, j; + int result, j; + REQUEST(xCirculateWindowReq); REQUEST_SIZE_MATCH(xCirculateWindowReq); - result = dixLookupResourceByType((pointer *)&win, stuff->window, - XRT_WINDOW, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->window, + XRT_WINDOW, client, DixWriteAccess); if (result != Success) - return result; + return result; FOR_NSCREENS_FORWARD(j) { - stuff->window = win->info[j].id; - result = (*SavedProcVector[X_CirculateWindow])(client); - if(result != Success) break; + stuff->window = win->info[j].id; + result = (*SavedProcVector[X_CirculateWindow]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXGetGeometry(ClientPtr client) +int +PanoramiXGetGeometry(ClientPtr client) { - xGetGeometryReply rep; + xGetGeometryReply rep; DrawablePtr pDraw; int rc; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupDrawable(&pDraw, stuff->id, client, M_ANY, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; rep.type = X_Reply; rep.length = 0; @@ -549,33 +576,35 @@ int PanoramiXGetGeometry(ClientPtr client) rep.x = rep.y = rep.borderWidth = 0; if (stuff->id == rep.root) { - xWindowRoot *root = (xWindowRoot *) - (ConnectionInfo + connBlockScreenStart); - - rep.width = root->pixWidth; - rep.height = root->pixHeight; - } else - if (WindowDrawable(pDraw->type)) - { - WindowPtr pWin = (WindowPtr)pDraw; - rep.x = pWin->origin.x - wBorderWidth (pWin); - rep.y = pWin->origin.y - wBorderWidth (pWin); - if((pWin->parent == screenInfo.screens[0]->root) || - (pWin->parent->drawable.id == screenInfo.screens[0]->screensaver.wid)) - { - rep.x += screenInfo.screens[0]->x; - rep.y += screenInfo.screens[0]->y; - } - rep.borderWidth = pWin->borderWidth; + xWindowRoot *root = (xWindowRoot *) + (ConnectionInfo + connBlockScreenStart); + + rep.width = root->pixWidth; + rep.height = root->pixHeight; + } + else if (WindowDrawable(pDraw->type)) { + WindowPtr pWin = (WindowPtr) pDraw; + + rep.x = pWin->origin.x - wBorderWidth(pWin); + rep.y = pWin->origin.y - wBorderWidth(pWin); + if ((pWin->parent == screenInfo.screens[0]->root) || + (pWin->parent->drawable.id == + screenInfo.screens[0]->screensaver.wid)) { + rep.x += screenInfo.screens[0]->x; + rep.y += screenInfo.screens[0]->y; + } + rep.borderWidth = pWin->borderWidth; } WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep); return Success; } -int PanoramiXTranslateCoords(ClientPtr client) +int +PanoramiXTranslateCoords(ClientPtr client) { INT16 x, y; + REQUEST(xTranslateCoordsReq); int rc; WindowPtr pWin, pDst; @@ -594,172 +623,177 @@ int PanoramiXTranslateCoords(ClientPtr client) rep.sameScreen = xTrue; rep.child = None; - if((pWin == screenInfo.screens[0]->root) || - (pWin->drawable.id == screenInfo.screens[0]->screensaver.wid)) - { - x = stuff->srcX - screenInfo.screens[0]->x; - y = stuff->srcY - screenInfo.screens[0]->y; - } else { - x = pWin->drawable.x + stuff->srcX; - y = pWin->drawable.y + stuff->srcY; + if ((pWin == screenInfo.screens[0]->root) || + (pWin->drawable.id == screenInfo.screens[0]->screensaver.wid)) { + x = stuff->srcX - screenInfo.screens[0]->x; + y = stuff->srcY - screenInfo.screens[0]->y; + } + else { + x = pWin->drawable.x + stuff->srcX; + y = pWin->drawable.y + stuff->srcY; } pWin = pDst->firstChild; while (pWin) { - BoxRec box; - if ((pWin->mapped) && - (x >= pWin->drawable.x - wBorderWidth (pWin)) && - (x < pWin->drawable.x + (int)pWin->drawable.width + - wBorderWidth (pWin)) && - (y >= pWin->drawable.y - wBorderWidth (pWin)) && - (y < pWin->drawable.y + (int)pWin->drawable.height + - wBorderWidth (pWin)) - /* When a window is shaped, a further check - * is made to see if the point is inside - * borderSize - */ - && (!wBoundingShape(pWin) || - RegionContainsPoint(wBoundingShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box)) - ) - { - rep.child = pWin->drawable.id; - pWin = (WindowPtr) NULL; - } - else - pWin = pWin->nextSib; + BoxRec box; + + if ((pWin->mapped) && + (x >= pWin->drawable.x - wBorderWidth(pWin)) && + (x < pWin->drawable.x + (int) pWin->drawable.width + + wBorderWidth(pWin)) && + (y >= pWin->drawable.y - wBorderWidth(pWin)) && + (y < pWin->drawable.y + (int) pWin->drawable.height + + wBorderWidth(pWin)) + /* When a window is shaped, a further check + * is made to see if the point is inside + * borderSize + */ + && (!wBoundingShape(pWin) || + RegionContainsPoint(wBoundingShape(pWin), + x - pWin->drawable.x, + y - pWin->drawable.y, &box)) + ) { + rep.child = pWin->drawable.id; + pWin = (WindowPtr) NULL; + } + else + pWin = pWin->nextSib; } rep.dstX = x - pDst->drawable.x; rep.dstY = y - pDst->drawable.y; - if((pDst == screenInfo.screens[0]->root) || - (pDst->drawable.id == screenInfo.screens[0]->screensaver.wid)) - { - rep.dstX += screenInfo.screens[0]->x; - rep.dstY += screenInfo.screens[0]->y; + if ((pDst == screenInfo.screens[0]->root) || + (pDst->drawable.id == screenInfo.screens[0]->screensaver.wid)) { + rep.dstX += screenInfo.screens[0]->x; + rep.dstY += screenInfo.screens[0]->y; } WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep); return Success; } -int PanoramiXCreatePixmap(ClientPtr client) +int +PanoramiXCreatePixmap(ClientPtr client) { PanoramiXRes *refDraw, *newPix; int result, j; + REQUEST(xCreatePixmapReq); REQUEST_SIZE_MATCH(xCreatePixmapReq); client->errorValue = stuff->pid; - result = dixLookupResourceByClass((pointer *)&refDraw, stuff->drawable, - XRC_DRAWABLE, client, DixReadAccess); + result = dixLookupResourceByClass((pointer *) &refDraw, stuff->drawable, + XRC_DRAWABLE, client, DixReadAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(!(newPix = malloc(sizeof(PanoramiXRes)))) - return BadAlloc; + if (!(newPix = malloc(sizeof(PanoramiXRes)))) + return BadAlloc; newPix->type = XRT_PIXMAP; newPix->u.pix.shared = FALSE; panoramix_setup_ids(newPix, client, stuff->pid); - + FOR_NSCREENS_BACKWARD(j) { - stuff->pid = newPix->info[j].id; - stuff->drawable = refDraw->info[j].id; - result = (*SavedProcVector[X_CreatePixmap])(client); - if(result != Success) break; + stuff->pid = newPix->info[j].id; + stuff->drawable = refDraw->info[j].id; + result = (*SavedProcVector[X_CreatePixmap]) (client); + if (result != Success) + break; } if (result == Success) - AddResource(newPix->info[0].id, XRT_PIXMAP, newPix); - else - free(newPix); + AddResource(newPix->info[0].id, XRT_PIXMAP, newPix); + else + free(newPix); return result; } - -int PanoramiXFreePixmap(ClientPtr client) +int +PanoramiXFreePixmap(ClientPtr client) { PanoramiXRes *pix; - int result, j; + int result, j; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); client->errorValue = stuff->id; - result = dixLookupResourceByType((pointer *)&pix, stuff->id, XRT_PIXMAP, - client, DixDestroyAccess); + result = dixLookupResourceByType((pointer *) &pix, stuff->id, XRT_PIXMAP, + client, DixDestroyAccess); if (result != Success) - return result; + return result; FOR_NSCREENS_BACKWARD(j) { - stuff->id = pix->info[j].id; - result = (*SavedProcVector[X_FreePixmap])(client); - if(result != Success) break; + stuff->id = pix->info[j].id; + result = (*SavedProcVector[X_FreePixmap]) (client); + if (result != Success) + break; } /* Since ProcFreePixmap is using FreeResource, it will free - our resource for us on the last pass through the loop above */ - + our resource for us on the last pass through the loop above */ + return result; } - -int PanoramiXCreateGC(ClientPtr client) +int +PanoramiXCreateGC(ClientPtr client) { PanoramiXRes *refDraw; PanoramiXRes *newGC; PanoramiXRes *stip = NULL; PanoramiXRes *tile = NULL; PanoramiXRes *clip = NULL; + REQUEST(xCreateGCReq); int tile_offset = 0, stip_offset = 0, clip_offset = 0; int result, len, j; XID tmp; REQUEST_AT_LEAST_SIZE(xCreateGCReq); - + client->errorValue = stuff->gc; len = client->req_len - bytes_to_int32(sizeof(xCreateGCReq)); if (Ones(stuff->mask) != len) return BadLength; - result = dixLookupResourceByClass((pointer *)&refDraw, stuff->drawable, - XRC_DRAWABLE, client, DixReadAccess); - if (result != Success) - return (result == BadValue) ? BadDrawable : result; - - if ((Mask)stuff->mask & GCTile) { - tile_offset = Ones((Mask)stuff->mask & (GCTile - 1)); - if ((tmp = *((CARD32 *) &stuff[1] + tile_offset))) { - result = dixLookupResourceByType((pointer *)&tile, tmp, XRT_PIXMAP, - client, DixReadAccess); - if (result != Success) - return result; - } - } - if ((Mask)stuff->mask & GCStipple) { - stip_offset = Ones((Mask)stuff->mask & (GCStipple - 1)); - if ((tmp = *((CARD32 *) &stuff[1] + stip_offset))) { - result = dixLookupResourceByType((pointer *)&stip, tmp, XRT_PIXMAP, - client, DixReadAccess); - if (result != Success) - return result; - } - } - if ((Mask)stuff->mask & GCClipMask) { - clip_offset = Ones((Mask)stuff->mask & (GCClipMask - 1)); - if ((tmp = *((CARD32 *) &stuff[1] + clip_offset))) { - result = dixLookupResourceByType((pointer *)&clip, tmp, XRT_PIXMAP, - client, DixReadAccess); - if (result != Success) - return result; - } - } - - if(!(newGC = malloc(sizeof(PanoramiXRes)))) + result = dixLookupResourceByClass((pointer *) &refDraw, stuff->drawable, + XRC_DRAWABLE, client, DixReadAccess); + if (result != Success) + return (result == BadValue) ? BadDrawable : result; + + if ((Mask) stuff->mask & GCTile) { + tile_offset = Ones((Mask) stuff->mask & (GCTile - 1)); + if ((tmp = *((CARD32 *) &stuff[1] + tile_offset))) { + result = dixLookupResourceByType((pointer *) &tile, tmp, XRT_PIXMAP, + client, DixReadAccess); + if (result != Success) + return result; + } + } + if ((Mask) stuff->mask & GCStipple) { + stip_offset = Ones((Mask) stuff->mask & (GCStipple - 1)); + if ((tmp = *((CARD32 *) &stuff[1] + stip_offset))) { + result = dixLookupResourceByType((pointer *) &stip, tmp, XRT_PIXMAP, + client, DixReadAccess); + if (result != Success) + return result; + } + } + if ((Mask) stuff->mask & GCClipMask) { + clip_offset = Ones((Mask) stuff->mask & (GCClipMask - 1)); + if ((tmp = *((CARD32 *) &stuff[1] + clip_offset))) { + result = dixLookupResourceByType((pointer *) &clip, tmp, XRT_PIXMAP, + client, DixReadAccess); + if (result != Success) + return result; + } + } + + if (!(newGC = malloc(sizeof(PanoramiXRes)))) return BadAlloc; newGC->type = XRT_GC; @@ -768,223 +802,235 @@ int PanoramiXCreateGC(ClientPtr client) FOR_NSCREENS_BACKWARD(j) { stuff->gc = newGC->info[j].id; stuff->drawable = refDraw->info[j].id; - if (tile) - *((CARD32 *) &stuff[1] + tile_offset) = tile->info[j].id; - if (stip) - *((CARD32 *) &stuff[1] + stip_offset) = stip->info[j].id; - if (clip) - *((CARD32 *) &stuff[1] + clip_offset) = clip->info[j].id; - result = (*SavedProcVector[X_CreateGC])(client); - if(result != Success) break; + if (tile) + *((CARD32 *) &stuff[1] + tile_offset) = tile->info[j].id; + if (stip) + *((CARD32 *) &stuff[1] + stip_offset) = stip->info[j].id; + if (clip) + *((CARD32 *) &stuff[1] + clip_offset) = clip->info[j].id; + result = (*SavedProcVector[X_CreateGC]) (client); + if (result != Success) + break; } if (result == Success) AddResource(newGC->info[0].id, XRT_GC, newGC); - else + else free(newGC); return result; } -int PanoramiXChangeGC(ClientPtr client) +int +PanoramiXChangeGC(ClientPtr client) { PanoramiXRes *gc; PanoramiXRes *stip = NULL; PanoramiXRes *tile = NULL; PanoramiXRes *clip = NULL; + REQUEST(xChangeGCReq); int tile_offset = 0, stip_offset = 0, clip_offset = 0; int result, len, j; XID tmp; REQUEST_AT_LEAST_SIZE(xChangeGCReq); - + len = client->req_len - bytes_to_int32(sizeof(xChangeGCReq)); if (Ones(stuff->mask) != len) return BadLength; - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; - if ((Mask)stuff->mask & GCTile) { - tile_offset = Ones((Mask)stuff->mask & (GCTile - 1)); - if ((tmp = *((CARD32 *) &stuff[1] + tile_offset))) { - result = dixLookupResourceByType((pointer *)&tile, tmp, XRT_PIXMAP, - client, DixReadAccess); - if (result != Success) - return result; - } + if ((Mask) stuff->mask & GCTile) { + tile_offset = Ones((Mask) stuff->mask & (GCTile - 1)); + if ((tmp = *((CARD32 *) &stuff[1] + tile_offset))) { + result = dixLookupResourceByType((pointer *) &tile, tmp, XRT_PIXMAP, + client, DixReadAccess); + if (result != Success) + return result; + } } - if ((Mask)stuff->mask & GCStipple) { - stip_offset = Ones((Mask)stuff->mask & (GCStipple - 1)); - if ((tmp = *((CARD32 *) &stuff[1] + stip_offset))) { - result = dixLookupResourceByType((pointer *)&stip, tmp, XRT_PIXMAP, - client, DixReadAccess); - if (result != Success) - return result; - } + if ((Mask) stuff->mask & GCStipple) { + stip_offset = Ones((Mask) stuff->mask & (GCStipple - 1)); + if ((tmp = *((CARD32 *) &stuff[1] + stip_offset))) { + result = dixLookupResourceByType((pointer *) &stip, tmp, XRT_PIXMAP, + client, DixReadAccess); + if (result != Success) + return result; + } } - if ((Mask)stuff->mask & GCClipMask) { - clip_offset = Ones((Mask)stuff->mask & (GCClipMask - 1)); - if ((tmp = *((CARD32 *) &stuff[1] + clip_offset))) { - result = dixLookupResourceByType((pointer *)&clip, tmp, XRT_PIXMAP, - client, DixReadAccess); - if (result != Success) - return result; - } + if ((Mask) stuff->mask & GCClipMask) { + clip_offset = Ones((Mask) stuff->mask & (GCClipMask - 1)); + if ((tmp = *((CARD32 *) &stuff[1] + clip_offset))) { + result = dixLookupResourceByType((pointer *) &clip, tmp, XRT_PIXMAP, + client, DixReadAccess); + if (result != Success) + return result; + } } - FOR_NSCREENS_BACKWARD(j) { stuff->gc = gc->info[j].id; - if (tile) - *((CARD32 *) &stuff[1] + tile_offset) = tile->info[j].id; - if (stip) - *((CARD32 *) &stuff[1] + stip_offset) = stip->info[j].id; - if (clip) - *((CARD32 *) &stuff[1] + clip_offset) = clip->info[j].id; - result = (*SavedProcVector[X_ChangeGC])(client); - if(result != Success) break; + if (tile) + *((CARD32 *) &stuff[1] + tile_offset) = tile->info[j].id; + if (stip) + *((CARD32 *) &stuff[1] + stip_offset) = stip->info[j].id; + if (clip) + *((CARD32 *) &stuff[1] + clip_offset) = clip->info[j].id; + result = (*SavedProcVector[X_ChangeGC]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXCopyGC(ClientPtr client) +int +PanoramiXCopyGC(ClientPtr client) { PanoramiXRes *srcGC, *dstGC; - int result, j; + int result, j; + REQUEST(xCopyGCReq); REQUEST_SIZE_MATCH(xCopyGCReq); - result = dixLookupResourceByType((pointer *)&srcGC, stuff->srcGC, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &srcGC, stuff->srcGC, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; - result = dixLookupResourceByType((pointer *)&dstGC, stuff->dstGC, XRT_GC, - client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &dstGC, stuff->dstGC, XRT_GC, + client, DixWriteAccess); if (result != Success) - return result; + return result; FOR_NSCREENS(j) { - stuff->srcGC = srcGC->info[j].id; - stuff->dstGC = dstGC->info[j].id; - result = (*SavedProcVector[X_CopyGC])(client); - if(result != Success) break; + stuff->srcGC = srcGC->info[j].id; + stuff->dstGC = dstGC->info[j].id; + result = (*SavedProcVector[X_CopyGC]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXSetDashes(ClientPtr client) +int +PanoramiXSetDashes(ClientPtr client) { PanoramiXRes *gc; - int result, j; + int result, j; + REQUEST(xSetDashesReq); REQUEST_FIXED_SIZE(xSetDashesReq, stuff->nDashes); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixWriteAccess); if (result != Success) - return result; + return result; FOR_NSCREENS_BACKWARD(j) { - stuff->gc = gc->info[j].id; - result = (*SavedProcVector[X_SetDashes])(client); - if(result != Success) break; + stuff->gc = gc->info[j].id; + result = (*SavedProcVector[X_SetDashes]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXSetClipRectangles(ClientPtr client) +int +PanoramiXSetClipRectangles(ClientPtr client) { PanoramiXRes *gc; - int result, j; + int result, j; + REQUEST(xSetClipRectanglesReq); REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixWriteAccess); if (result != Success) - return result; + return result; FOR_NSCREENS_BACKWARD(j) { - stuff->gc = gc->info[j].id; - result = (*SavedProcVector[X_SetClipRectangles])(client); - if(result != Success) break; + stuff->gc = gc->info[j].id; + result = (*SavedProcVector[X_SetClipRectangles]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXFreeGC(ClientPtr client) +int +PanoramiXFreeGC(ClientPtr client) { PanoramiXRes *gc; - int result, j; + int result, j; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - result = dixLookupResourceByType((pointer *)&gc, stuff->id, XRT_GC, - client, DixDestroyAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->id, XRT_GC, + client, DixDestroyAccess); if (result != Success) - return result; + return result; FOR_NSCREENS_BACKWARD(j) { - stuff->id = gc->info[j].id; - result = (*SavedProcVector[X_FreeGC])(client); - if(result != Success) break; + stuff->id = gc->info[j].id; + result = (*SavedProcVector[X_FreeGC]) (client); + if (result != Success) + break; } /* Since ProcFreeGC is using FreeResource, it will free - our resource for us on the last pass through the loop above */ - + our resource for us on the last pass through the loop above */ + return result; } - -int PanoramiXClearToBackground(ClientPtr client) +int +PanoramiXClearToBackground(ClientPtr client) { PanoramiXRes *win; - int result, j, x, y; - Bool isRoot; + int result, j, x, y; + Bool isRoot; + REQUEST(xClearAreaReq); REQUEST_SIZE_MATCH(xClearAreaReq); - result = dixLookupResourceByType((pointer *)&win, stuff->window, - XRT_WINDOW, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->window, + XRT_WINDOW, client, DixWriteAccess); if (result != Success) - return result; + return result; x = stuff->x; y = stuff->y; isRoot = win->u.win.root; FOR_NSCREENS_BACKWARD(j) { - stuff->window = win->info[j].id; - if(isRoot) { - stuff->x = x - screenInfo.screens[j]->x; - stuff->y = y - screenInfo.screens[j]->y; - } - result = (*SavedProcVector[X_ClearArea])(client); - if(result != Success) break; - } - + stuff->window = win->info[j].id; + if (isRoot) { + stuff->x = x - screenInfo.screens[j]->x; + stuff->y = y - screenInfo.screens[j]->y; + } + result = (*SavedProcVector[X_ClearArea]) (client); + if (result != Success) + break; + } + return result; } - /* For Window to Pixmap copies you're screwed since each screen's pixmap will look like what it sees on its screen. Unless the @@ -995,821 +1041,882 @@ int PanoramiXClearToBackground(ClientPtr client) have to fix this later. (MArk). */ -int PanoramiXCopyArea(ClientPtr client) +int +PanoramiXCopyArea(ClientPtr client) { - int j, result, srcx, srcy, dstx, dsty; - PanoramiXRes *gc, *src, *dst; - Bool srcIsRoot = FALSE; - Bool dstIsRoot = FALSE; - Bool srcShared, dstShared; + int j, result, srcx, srcy, dstx, dsty; + PanoramiXRes *gc, *src, *dst; + Bool srcIsRoot = FALSE; + Bool dstIsRoot = FALSE; + Bool srcShared, dstShared; + REQUEST(xCopyAreaReq); REQUEST_SIZE_MATCH(xCopyAreaReq); - result = dixLookupResourceByClass((pointer *)&src, stuff->srcDrawable, - XRC_DRAWABLE, client, DixReadAccess); + result = dixLookupResourceByClass((pointer *) &src, stuff->srcDrawable, + XRC_DRAWABLE, client, DixReadAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; srcShared = IS_SHARED_PIXMAP(src); - result = dixLookupResourceByClass((pointer *)&dst, stuff->dstDrawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &dst, stuff->dstDrawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; dstShared = IS_SHARED_PIXMAP(dst); - if(dstShared && srcShared) - return (* SavedProcVector[X_CopyArea])(client); + if (dstShared && srcShared) + return (*SavedProcVector[X_CopyArea]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; - - if((dst->type == XRT_WINDOW) && dst->u.win.root) - dstIsRoot = TRUE; - if((src->type == XRT_WINDOW) && src->u.win.root) - srcIsRoot = TRUE; + return result; - srcx = stuff->srcX; srcy = stuff->srcY; - dstx = stuff->dstX; dsty = stuff->dstY; - if((dst->type == XRT_PIXMAP) && (src->type == XRT_WINDOW)) { - DrawablePtr drawables[MAXSCREENS]; - DrawablePtr pDst; - GCPtr pGC; + if ((dst->type == XRT_WINDOW) && dst->u.win.root) + dstIsRoot = TRUE; + if ((src->type == XRT_WINDOW) && src->u.win.root) + srcIsRoot = TRUE; + + srcx = stuff->srcX; + srcy = stuff->srcY; + dstx = stuff->dstX; + dsty = stuff->dstY; + if ((dst->type == XRT_PIXMAP) && (src->type == XRT_WINDOW)) { + DrawablePtr drawables[MAXSCREENS]; + DrawablePtr pDst; + GCPtr pGC; char *data; - int pitch, rc; - - FOR_NSCREENS(j) { - rc = dixLookupDrawable(drawables+j, src->info[j].id, client, 0, - DixGetAttrAccess); - if (rc != Success) - return rc; - } - - pitch = PixmapBytePad(stuff->width, drawables[0]->depth); - if(!(data = calloc(1, stuff->height * pitch))) - return BadAlloc; - - XineramaGetImageData(drawables, srcx, srcy, - stuff->width, stuff->height, ZPixmap, ~0, data, pitch, - srcIsRoot); - - FOR_NSCREENS_BACKWARD(j) { - stuff->gc = gc->info[j].id; - VALIDATE_DRAWABLE_AND_GC(dst->info[j].id, pDst, DixWriteAccess); - if(drawables[0]->depth != pDst->depth) { - client->errorValue = stuff->dstDrawable; - free(data); - return BadMatch; - } - - (*pGC->ops->PutImage) (pDst, pGC, pDst->depth, dstx, dsty, - stuff->width, stuff->height, - 0, ZPixmap, data); - - if(dstShared) break; - } - - free(data); - } else { - DrawablePtr pDst = NULL, pSrc = NULL; - GCPtr pGC = NULL; - RegionRec totalReg; - int rc; - - RegionNull(&totalReg); - FOR_NSCREENS_BACKWARD(j) { - RegionPtr pRgn; - stuff->dstDrawable = dst->info[j].id; - stuff->srcDrawable = src->info[j].id; - stuff->gc = gc->info[j].id; - if (srcIsRoot) { - stuff->srcX = srcx - screenInfo.screens[j]->x; - stuff->srcY = srcy - screenInfo.screens[j]->y; - } - if (dstIsRoot) { - stuff->dstX = dstx - screenInfo.screens[j]->x; - stuff->dstY = dsty - screenInfo.screens[j]->y; - } - - VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, DixWriteAccess); - - if (stuff->dstDrawable != stuff->srcDrawable) { - rc = dixLookupDrawable(&pSrc, stuff->srcDrawable, client, 0, - DixReadAccess); - if (rc != Success) - return rc; - - if ((pDst->pScreen != pSrc->pScreen) || - (pDst->depth != pSrc->depth)) { - client->errorValue = stuff->dstDrawable; - return BadMatch; - } - } else - pSrc = pDst; - - pRgn = (*pGC->ops->CopyArea)(pSrc, pDst, pGC, - stuff->srcX, stuff->srcY, - stuff->width, stuff->height, - stuff->dstX, stuff->dstY); - if(pGC->graphicsExposures && pRgn) { - if(srcIsRoot) { - RegionTranslate(pRgn, - screenInfo.screens[j]->x, screenInfo.screens[j]->y); - } - RegionAppend(&totalReg, pRgn); - RegionDestroy(pRgn); - } - - if(dstShared) - break; - } - - if(pGC->graphicsExposures) { - Bool overlap; - RegionValidate(&totalReg, &overlap); - (*pDst->pScreen->SendGraphicsExpose)( - client, &totalReg, stuff->dstDrawable, X_CopyArea, 0); - RegionUninit(&totalReg); - } + int pitch, rc; + + FOR_NSCREENS(j) { + rc = dixLookupDrawable(drawables + j, src->info[j].id, client, 0, + DixGetAttrAccess); + if (rc != Success) + return rc; + } + + pitch = PixmapBytePad(stuff->width, drawables[0]->depth); + if (!(data = calloc(1, stuff->height * pitch))) + return BadAlloc; + + XineramaGetImageData(drawables, srcx, srcy, + stuff->width, stuff->height, ZPixmap, ~0, data, + pitch, srcIsRoot); + + FOR_NSCREENS_BACKWARD(j) { + stuff->gc = gc->info[j].id; + VALIDATE_DRAWABLE_AND_GC(dst->info[j].id, pDst, DixWriteAccess); + if (drawables[0]->depth != pDst->depth) { + client->errorValue = stuff->dstDrawable; + free(data); + return BadMatch; + } + + (*pGC->ops->PutImage) (pDst, pGC, pDst->depth, dstx, dsty, + stuff->width, stuff->height, + 0, ZPixmap, data); + + if (dstShared) + break; + } + + free(data); + } + else { + DrawablePtr pDst = NULL, pSrc = NULL; + GCPtr pGC = NULL; + RegionRec totalReg; + int rc; + + RegionNull(&totalReg); + FOR_NSCREENS_BACKWARD(j) { + RegionPtr pRgn; + + stuff->dstDrawable = dst->info[j].id; + stuff->srcDrawable = src->info[j].id; + stuff->gc = gc->info[j].id; + if (srcIsRoot) { + stuff->srcX = srcx - screenInfo.screens[j]->x; + stuff->srcY = srcy - screenInfo.screens[j]->y; + } + if (dstIsRoot) { + stuff->dstX = dstx - screenInfo.screens[j]->x; + stuff->dstY = dsty - screenInfo.screens[j]->y; + } + + VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, DixWriteAccess); + + if (stuff->dstDrawable != stuff->srcDrawable) { + rc = dixLookupDrawable(&pSrc, stuff->srcDrawable, client, 0, + DixReadAccess); + if (rc != Success) + return rc; + + if ((pDst->pScreen != pSrc->pScreen) || + (pDst->depth != pSrc->depth)) { + client->errorValue = stuff->dstDrawable; + return BadMatch; + } + } + else + pSrc = pDst; + + pRgn = (*pGC->ops->CopyArea) (pSrc, pDst, pGC, + stuff->srcX, stuff->srcY, + stuff->width, stuff->height, + stuff->dstX, stuff->dstY); + if (pGC->graphicsExposures && pRgn) { + if (srcIsRoot) { + RegionTranslate(pRgn, + screenInfo.screens[j]->x, + screenInfo.screens[j]->y); + } + RegionAppend(&totalReg, pRgn); + RegionDestroy(pRgn); + } + + if (dstShared) + break; + } + + if (pGC->graphicsExposures) { + Bool overlap; + + RegionValidate(&totalReg, &overlap); + (*pDst->pScreen->SendGraphicsExpose) (client, &totalReg, + stuff->dstDrawable, + X_CopyArea, 0); + RegionUninit(&totalReg); + } } return Success; } - -int PanoramiXCopyPlane(ClientPtr client) +int +PanoramiXCopyPlane(ClientPtr client) { - int j, srcx, srcy, dstx, dsty, rc; - PanoramiXRes *gc, *src, *dst; - Bool srcIsRoot = FALSE; - Bool dstIsRoot = FALSE; - Bool srcShared, dstShared; - DrawablePtr psrcDraw, pdstDraw = NULL; - GCPtr pGC = NULL; - RegionRec totalReg; + int j, srcx, srcy, dstx, dsty, rc; + PanoramiXRes *gc, *src, *dst; + Bool srcIsRoot = FALSE; + Bool dstIsRoot = FALSE; + Bool srcShared, dstShared; + DrawablePtr psrcDraw, pdstDraw = NULL; + GCPtr pGC = NULL; + RegionRec totalReg; + REQUEST(xCopyPlaneReq); REQUEST_SIZE_MATCH(xCopyPlaneReq); - rc = dixLookupResourceByClass((pointer *)&src, stuff->srcDrawable, - XRC_DRAWABLE, client, DixReadAccess); + rc = dixLookupResourceByClass((pointer *) &src, stuff->srcDrawable, + XRC_DRAWABLE, client, DixReadAccess); if (rc != Success) - return (rc == BadValue) ? BadDrawable : rc; + return (rc == BadValue) ? BadDrawable : rc; srcShared = IS_SHARED_PIXMAP(src); - rc = dixLookupResourceByClass((pointer *)&dst, stuff->dstDrawable, - XRC_DRAWABLE, client, DixWriteAccess); + rc = dixLookupResourceByClass((pointer *) &dst, stuff->dstDrawable, + XRC_DRAWABLE, client, DixWriteAccess); if (rc != Success) - return (rc == BadValue) ? BadDrawable : rc; + return (rc == BadValue) ? BadDrawable : rc; dstShared = IS_SHARED_PIXMAP(dst); - if(dstShared && srcShared) - return (* SavedProcVector[X_CopyPlane])(client); + if (dstShared && srcShared) + return (*SavedProcVector[X_CopyPlane]) (client); - rc = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + rc = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (rc != Success) - return rc; + return rc; - if((dst->type == XRT_WINDOW) && dst->u.win.root) - dstIsRoot = TRUE; - if((src->type == XRT_WINDOW) && src->u.win.root) - srcIsRoot = TRUE; + if ((dst->type == XRT_WINDOW) && dst->u.win.root) + dstIsRoot = TRUE; + if ((src->type == XRT_WINDOW) && src->u.win.root) + srcIsRoot = TRUE; + + srcx = stuff->srcX; + srcy = stuff->srcY; + dstx = stuff->dstX; + dsty = stuff->dstY; - srcx = stuff->srcX; srcy = stuff->srcY; - dstx = stuff->dstX; dsty = stuff->dstY; - RegionNull(&totalReg); FOR_NSCREENS_BACKWARD(j) { - RegionPtr pRgn; - stuff->dstDrawable = dst->info[j].id; - stuff->srcDrawable = src->info[j].id; - stuff->gc = gc->info[j].id; - if (srcIsRoot) { - stuff->srcX = srcx - screenInfo.screens[j]->x; - stuff->srcY = srcy - screenInfo.screens[j]->y; - } - if (dstIsRoot) { - stuff->dstX = dstx - screenInfo.screens[j]->x; - stuff->dstY = dsty - screenInfo.screens[j]->y; - } - - VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, DixWriteAccess); - if (stuff->dstDrawable != stuff->srcDrawable) { - rc = dixLookupDrawable(&psrcDraw, stuff->srcDrawable, client, 0, - DixReadAccess); - if (rc != Success) - return rc; + RegionPtr pRgn; + + stuff->dstDrawable = dst->info[j].id; + stuff->srcDrawable = src->info[j].id; + stuff->gc = gc->info[j].id; + if (srcIsRoot) { + stuff->srcX = srcx - screenInfo.screens[j]->x; + stuff->srcY = srcy - screenInfo.screens[j]->y; + } + if (dstIsRoot) { + stuff->dstX = dstx - screenInfo.screens[j]->x; + stuff->dstY = dsty - screenInfo.screens[j]->y; + } + + VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, DixWriteAccess); + if (stuff->dstDrawable != stuff->srcDrawable) { + rc = dixLookupDrawable(&psrcDraw, stuff->srcDrawable, client, 0, + DixReadAccess); + if (rc != Success) + return rc; if (pdstDraw->pScreen != psrcDraw->pScreen) { - client->errorValue = stuff->dstDrawable; - return BadMatch; - } - } else - psrcDraw = pdstDraw; - - if(stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) || - (stuff->bitPlane > (1L << (psrcDraw->depth - 1)))) { - client->errorValue = stuff->bitPlane; - return BadValue; - } - - pRgn = (*pGC->ops->CopyPlane)(psrcDraw, pdstDraw, pGC, - stuff->srcX, stuff->srcY, - stuff->width, stuff->height, - stuff->dstX, stuff->dstY, stuff->bitPlane); - if(pGC->graphicsExposures && pRgn) { - RegionAppend(&totalReg, pRgn); - RegionDestroy(pRgn); - } - - if(dstShared) - break; - } - - if(pGC->graphicsExposures) { - Bool overlap; - RegionValidate(&totalReg, &overlap); - (*pdstDraw->pScreen->SendGraphicsExpose)( - client, &totalReg, stuff->dstDrawable, X_CopyPlane, 0); - RegionUninit(&totalReg); + client->errorValue = stuff->dstDrawable; + return BadMatch; + } + } + else + psrcDraw = pdstDraw; + + if (stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) || + (stuff->bitPlane > (1L << (psrcDraw->depth - 1)))) { + client->errorValue = stuff->bitPlane; + return BadValue; + } + + pRgn = (*pGC->ops->CopyPlane) (psrcDraw, pdstDraw, pGC, + stuff->srcX, stuff->srcY, + stuff->width, stuff->height, + stuff->dstX, stuff->dstY, + stuff->bitPlane); + if (pGC->graphicsExposures && pRgn) { + RegionAppend(&totalReg, pRgn); + RegionDestroy(pRgn); + } + + if (dstShared) + break; + } + + if (pGC->graphicsExposures) { + Bool overlap; + + RegionValidate(&totalReg, &overlap); + (*pdstDraw->pScreen->SendGraphicsExpose) (client, &totalReg, + stuff->dstDrawable, + X_CopyPlane, 0); + RegionUninit(&totalReg); } return Success; } - -int PanoramiXPolyPoint(ClientPtr client) +int +PanoramiXPolyPoint(ClientPtr client) { PanoramiXRes *gc, *draw; - int result, npoint, j; - xPoint *origPts; - Bool isRoot; + int result, npoint, j; + xPoint *origPts; + Bool isRoot; + REQUEST(xPolyPointReq); REQUEST_AT_LEAST_SIZE(xPolyPointReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(IS_SHARED_PIXMAP(draw)) - return (*SavedProcVector[X_PolyPoint])(client); + if (IS_SHARED_PIXMAP(draw)) + return (*SavedProcVector[X_PolyPoint]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyPointReq)); if (npoint > 0) { origPts = malloc(npoint * sizeof(xPoint)); memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint)); - FOR_NSCREENS_FORWARD(j){ + FOR_NSCREENS_FORWARD(j) { - if(j) memcpy(&stuff[1], origPts, npoint * sizeof(xPoint)); + if (j) + memcpy(&stuff[1], origPts, npoint * sizeof(xPoint)); if (isRoot) { int x_off = screenInfo.screens[j]->x; int y_off = screenInfo.screens[j]->y; - if(x_off || y_off) { - xPoint *pnts = (xPoint*)&stuff[1]; - int i = (stuff->coordMode==CoordModePrevious) ? 1 : npoint; + if (x_off || y_off) { + xPoint *pnts = (xPoint *) &stuff[1]; + int i = + (stuff->coordMode == CoordModePrevious) ? 1 : npoint; - while(i--) { - pnts->x -= x_off; - pnts->y -= y_off; - pnts++; + while (i--) { + pnts->x -= x_off; + pnts->y -= y_off; + pnts++; } - } + } } - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - result = (* SavedProcVector[X_PolyPoint])(client); - if(result != Success) break; + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + result = (*SavedProcVector[X_PolyPoint]) (client); + if (result != Success) + break; } free(origPts); return result; - } else - return Success; + } + else + return Success; } - -int PanoramiXPolyLine(ClientPtr client) +int +PanoramiXPolyLine(ClientPtr client) { PanoramiXRes *gc, *draw; - int result, npoint, j; - xPoint *origPts; - Bool isRoot; + int result, npoint, j; + xPoint *origPts; + Bool isRoot; + REQUEST(xPolyLineReq); REQUEST_AT_LEAST_SIZE(xPolyLineReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(IS_SHARED_PIXMAP(draw)) - return (*SavedProcVector[X_PolyLine])(client); + if (IS_SHARED_PIXMAP(draw)) + return (*SavedProcVector[X_PolyLine]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = IS_ROOT_DRAWABLE(draw); npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyLineReq)); - if (npoint > 0){ + if (npoint > 0) { origPts = malloc(npoint * sizeof(xPoint)); memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint)); - FOR_NSCREENS_FORWARD(j){ + FOR_NSCREENS_FORWARD(j) { - if(j) memcpy(&stuff[1], origPts, npoint * sizeof(xPoint)); + if (j) + memcpy(&stuff[1], origPts, npoint * sizeof(xPoint)); if (isRoot) { int x_off = screenInfo.screens[j]->x; int y_off = screenInfo.screens[j]->y; - if(x_off || y_off) { - xPoint *pnts = (xPoint*)&stuff[1]; - int i = (stuff->coordMode==CoordModePrevious) ? 1 : npoint; + if (x_off || y_off) { + xPoint *pnts = (xPoint *) &stuff[1]; + int i = + (stuff->coordMode == CoordModePrevious) ? 1 : npoint; - while(i--) { - pnts->x -= x_off; - pnts->y -= y_off; - pnts++; - } - } + while (i--) { + pnts->x -= x_off; + pnts->y -= y_off; + pnts++; + } + } } - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - result = (* SavedProcVector[X_PolyLine])(client); - if(result != Success) break; + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + result = (*SavedProcVector[X_PolyLine]) (client); + if (result != Success) + break; } free(origPts); return result; - } else - return Success; + } + else + return Success; } - -int PanoramiXPolySegment(ClientPtr client) +int +PanoramiXPolySegment(ClientPtr client) { - int result, nsegs, i, j; + int result, nsegs, i, j; PanoramiXRes *gc, *draw; - xSegment *origSegs; - Bool isRoot; + xSegment *origSegs; + Bool isRoot; + REQUEST(xPolySegmentReq); REQUEST_AT_LEAST_SIZE(xPolySegmentReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(IS_SHARED_PIXMAP(draw)) - return (*SavedProcVector[X_PolySegment])(client); + if (IS_SHARED_PIXMAP(draw)) + return (*SavedProcVector[X_PolySegment]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = IS_ROOT_DRAWABLE(draw); nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq); - if(nsegs & 4) return BadLength; + if (nsegs & 4) + return BadLength; nsegs >>= 3; if (nsegs > 0) { - origSegs = malloc(nsegs * sizeof(xSegment)); + origSegs = malloc(nsegs * sizeof(xSegment)); memcpy((char *) origSegs, (char *) &stuff[1], nsegs * sizeof(xSegment)); - FOR_NSCREENS_FORWARD(j){ + FOR_NSCREENS_FORWARD(j) { - if(j) memcpy(&stuff[1], origSegs, nsegs * sizeof(xSegment)); + if (j) + memcpy(&stuff[1], origSegs, nsegs * sizeof(xSegment)); if (isRoot) { int x_off = screenInfo.screens[j]->x; int y_off = screenInfo.screens[j]->y; - if(x_off || y_off) { - xSegment *segs = (xSegment*)&stuff[1]; + if (x_off || y_off) { + xSegment *segs = (xSegment *) &stuff[1]; - for (i = nsegs; i--; segs++) { - segs->x1 -= x_off; - segs->x2 -= x_off; - segs->y1 -= y_off; - segs->y2 -= y_off; - } - } + for (i = nsegs; i--; segs++) { + segs->x1 -= x_off; + segs->x2 -= x_off; + segs->y1 -= y_off; + segs->y2 -= y_off; + } + } } - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - result = (* SavedProcVector[X_PolySegment])(client); - if(result != Success) break; - } - free(origSegs); - return result; - } else - return Success; + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + result = (*SavedProcVector[X_PolySegment]) (client); + if (result != Success) + break; + } + free(origSegs); + return result; + } + else + return Success; } - -int PanoramiXPolyRectangle(ClientPtr client) +int +PanoramiXPolyRectangle(ClientPtr client) { - int result, nrects, i, j; + int result, nrects, i, j; PanoramiXRes *gc, *draw; - Bool isRoot; - xRectangle *origRecs; + Bool isRoot; + xRectangle *origRecs; + REQUEST(xPolyRectangleReq); REQUEST_AT_LEAST_SIZE(xPolyRectangleReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(IS_SHARED_PIXMAP(draw)) - return (*SavedProcVector[X_PolyRectangle])(client); + if (IS_SHARED_PIXMAP(draw)) + return (*SavedProcVector[X_PolyRectangle]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = IS_ROOT_DRAWABLE(draw); nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq); - if(nrects & 4) return BadLength; + if (nrects & 4) + return BadLength; nrects >>= 3; - if (nrects > 0){ - origRecs = malloc(nrects * sizeof(xRectangle)); - memcpy((char *)origRecs,(char *)&stuff[1],nrects * sizeof(xRectangle)); - FOR_NSCREENS_FORWARD(j){ - - if(j) memcpy(&stuff[1], origRecs, nrects * sizeof(xRectangle)); - - if (isRoot) { - int x_off = screenInfo.screens[j]->x; - int y_off = screenInfo.screens[j]->y; - - - if(x_off || y_off) { - xRectangle *rects = (xRectangle *) &stuff[1]; - - for (i = nrects; i--; rects++) { - rects->x -= x_off; - rects->y -= y_off; - } - } - } - - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - result = (* SavedProcVector[X_PolyRectangle])(client); - if(result != Success) break; - } - free(origRecs); - return result; - } else - return Success; -} + if (nrects > 0) { + origRecs = malloc(nrects * sizeof(xRectangle)); + memcpy((char *) origRecs, (char *) &stuff[1], + nrects * sizeof(xRectangle)); + FOR_NSCREENS_FORWARD(j) { + + if (j) + memcpy(&stuff[1], origRecs, nrects * sizeof(xRectangle)); + + if (isRoot) { + int x_off = screenInfo.screens[j]->x; + int y_off = screenInfo.screens[j]->y; + if (x_off || y_off) { + xRectangle *rects = (xRectangle *) &stuff[1]; + + for (i = nrects; i--; rects++) { + rects->x -= x_off; + rects->y -= y_off; + } + } + } + + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + result = (*SavedProcVector[X_PolyRectangle]) (client); + if (result != Success) + break; + } + free(origRecs); + return result; + } + else + return Success; +} -int PanoramiXPolyArc(ClientPtr client) +int +PanoramiXPolyArc(ClientPtr client) { - int result, narcs, i, j; + int result, narcs, i, j; PanoramiXRes *gc, *draw; - Bool isRoot; - xArc *origArcs; + Bool isRoot; + xArc *origArcs; + REQUEST(xPolyArcReq); REQUEST_AT_LEAST_SIZE(xPolyArcReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(IS_SHARED_PIXMAP(draw)) - return (*SavedProcVector[X_PolyArc])(client); + if (IS_SHARED_PIXMAP(draw)) + return (*SavedProcVector[X_PolyArc]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = IS_ROOT_DRAWABLE(draw); narcs = (client->req_len << 2) - sizeof(xPolyArcReq); - if(narcs % sizeof(xArc)) return BadLength; + if (narcs % sizeof(xArc)) + return BadLength; narcs /= sizeof(xArc); - if (narcs > 0){ - origArcs = malloc(narcs * sizeof(xArc)); - memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc)); - FOR_NSCREENS_FORWARD(j){ - - if(j) memcpy(&stuff[1], origArcs, narcs * sizeof(xArc)); - - if (isRoot) { - int x_off = screenInfo.screens[j]->x; - int y_off = screenInfo.screens[j]->y; - - if(x_off || y_off) { - xArc *arcs = (xArc *) &stuff[1]; - - for (i = narcs; i--; arcs++) { - arcs->x -= x_off; - arcs->y -= y_off; - } - } + if (narcs > 0) { + origArcs = malloc(narcs * sizeof(xArc)); + memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc)); + FOR_NSCREENS_FORWARD(j) { + + if (j) + memcpy(&stuff[1], origArcs, narcs * sizeof(xArc)); + + if (isRoot) { + int x_off = screenInfo.screens[j]->x; + int y_off = screenInfo.screens[j]->y; + + if (x_off || y_off) { + xArc *arcs = (xArc *) &stuff[1]; + + for (i = narcs; i--; arcs++) { + arcs->x -= x_off; + arcs->y -= y_off; + } + } } - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - result = (* SavedProcVector[X_PolyArc])(client); - if(result != Success) break; + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + result = (*SavedProcVector[X_PolyArc]) (client); + if (result != Success) + break; } - free(origArcs); - return result; - } else - return Success; + free(origArcs); + return result; + } + else + return Success; } - -int PanoramiXFillPoly(ClientPtr client) +int +PanoramiXFillPoly(ClientPtr client) { - int result, count, j; + int result, count, j; PanoramiXRes *gc, *draw; - Bool isRoot; - DDXPointPtr locPts; + Bool isRoot; + DDXPointPtr locPts; + REQUEST(xFillPolyReq); REQUEST_AT_LEAST_SIZE(xFillPolyReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(IS_SHARED_PIXMAP(draw)) - return (*SavedProcVector[X_FillPoly])(client); + if (IS_SHARED_PIXMAP(draw)) + return (*SavedProcVector[X_FillPoly]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = IS_ROOT_DRAWABLE(draw); count = bytes_to_int32((client->req_len << 2) - sizeof(xFillPolyReq)); - if (count > 0){ - locPts = malloc(count * sizeof(DDXPointRec)); - memcpy((char *)locPts, (char *)&stuff[1], count * sizeof(DDXPointRec)); - FOR_NSCREENS_FORWARD(j){ - - if(j) memcpy(&stuff[1], locPts, count * sizeof(DDXPointRec)); - - if (isRoot) { - int x_off = screenInfo.screens[j]->x; - int y_off = screenInfo.screens[j]->y; - - if(x_off || y_off) { - DDXPointPtr pnts = (DDXPointPtr)&stuff[1]; - int i = (stuff->coordMode==CoordModePrevious) ? 1 : count; - - while(i--) { - pnts->x -= x_off; - pnts->y -= y_off; - pnts++; - } - } - } - - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - result = (* SavedProcVector[X_FillPoly])(client); - if(result != Success) break; - } - free(locPts); - return result; - } else - return Success; -} + if (count > 0) { + locPts = malloc(count * sizeof(DDXPointRec)); + memcpy((char *) locPts, (char *) &stuff[1], + count * sizeof(DDXPointRec)); + FOR_NSCREENS_FORWARD(j) { + + if (j) + memcpy(&stuff[1], locPts, count * sizeof(DDXPointRec)); + + if (isRoot) { + int x_off = screenInfo.screens[j]->x; + int y_off = screenInfo.screens[j]->y; + if (x_off || y_off) { + DDXPointPtr pnts = (DDXPointPtr) &stuff[1]; + int i = (stuff->coordMode == CoordModePrevious) ? 1 : count; -int PanoramiXPolyFillRectangle(ClientPtr client) + while (i--) { + pnts->x -= x_off; + pnts->y -= y_off; + pnts++; + } + } + } + + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + result = (*SavedProcVector[X_FillPoly]) (client); + if (result != Success) + break; + } + free(locPts); + return result; + } + else + return Success; +} + +int +PanoramiXPolyFillRectangle(ClientPtr client) { - int result, things, i, j; + int result, things, i, j; PanoramiXRes *gc, *draw; - Bool isRoot; - xRectangle *origRects; + Bool isRoot; + xRectangle *origRects; + REQUEST(xPolyFillRectangleReq); REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(IS_SHARED_PIXMAP(draw)) - return (*SavedProcVector[X_PolyFillRectangle])(client); + if (IS_SHARED_PIXMAP(draw)) + return (*SavedProcVector[X_PolyFillRectangle]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = IS_ROOT_DRAWABLE(draw); things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq); - if(things & 4) return BadLength; + if (things & 4) + return BadLength; things >>= 3; - if (things > 0){ - origRects = malloc(things * sizeof(xRectangle)); - memcpy((char*)origRects,(char*)&stuff[1], things * sizeof(xRectangle)); - FOR_NSCREENS_FORWARD(j){ - - if(j) memcpy(&stuff[1], origRects, things * sizeof(xRectangle)); - - if (isRoot) { - int x_off = screenInfo.screens[j]->x; - int y_off = screenInfo.screens[j]->y; - - if(x_off || y_off) { - xRectangle *rects = (xRectangle *) &stuff[1]; - - for (i = things; i--; rects++) { - rects->x -= x_off; - rects->y -= y_off; - } - } - } - - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - result = (* SavedProcVector[X_PolyFillRectangle])(client); - if(result != Success) break; - } - free(origRects); - return result; - } else - return Success; -} + if (things > 0) { + origRects = malloc(things * sizeof(xRectangle)); + memcpy((char *) origRects, (char *) &stuff[1], + things * sizeof(xRectangle)); + FOR_NSCREENS_FORWARD(j) { + + if (j) + memcpy(&stuff[1], origRects, things * sizeof(xRectangle)); + + if (isRoot) { + int x_off = screenInfo.screens[j]->x; + int y_off = screenInfo.screens[j]->y; + + if (x_off || y_off) { + xRectangle *rects = (xRectangle *) &stuff[1]; + + for (i = things; i--; rects++) { + rects->x -= x_off; + rects->y -= y_off; + } + } + } + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + result = (*SavedProcVector[X_PolyFillRectangle]) (client); + if (result != Success) + break; + } + free(origRects); + return result; + } + else + return Success; +} -int PanoramiXPolyFillArc(ClientPtr client) +int +PanoramiXPolyFillArc(ClientPtr client) { PanoramiXRes *gc, *draw; - Bool isRoot; - int result, narcs, i, j; - xArc *origArcs; + Bool isRoot; + int result, narcs, i, j; + xArc *origArcs; + REQUEST(xPolyFillArcReq); REQUEST_AT_LEAST_SIZE(xPolyFillArcReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(IS_SHARED_PIXMAP(draw)) - return (*SavedProcVector[X_PolyFillArc])(client); + if (IS_SHARED_PIXMAP(draw)) + return (*SavedProcVector[X_PolyFillArc]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = IS_ROOT_DRAWABLE(draw); narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq); - if (narcs % sizeof(xArc)) return BadLength; + if (narcs % sizeof(xArc)) + return BadLength; narcs /= sizeof(xArc); if (narcs > 0) { - origArcs = malloc(narcs * sizeof(xArc)); - memcpy((char *) origArcs, (char *)&stuff[1], narcs * sizeof(xArc)); - FOR_NSCREENS_FORWARD(j){ - - if(j) memcpy(&stuff[1], origArcs, narcs * sizeof(xArc)); - - if (isRoot) { - int x_off = screenInfo.screens[j]->x; - int y_off = screenInfo.screens[j]->y; - - if(x_off || y_off) { - xArc *arcs = (xArc *) &stuff[1]; - - for (i = narcs; i--; arcs++) { - arcs->x -= x_off; - arcs->y -= y_off; - } - } - } - - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - result = (* SavedProcVector[X_PolyFillArc])(client); - if(result != Success) break; - } - free(origArcs); - return result; - } else - return Success; -} + origArcs = malloc(narcs * sizeof(xArc)); + memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc)); + FOR_NSCREENS_FORWARD(j) { + + if (j) + memcpy(&stuff[1], origArcs, narcs * sizeof(xArc)); + if (isRoot) { + int x_off = screenInfo.screens[j]->x; + int y_off = screenInfo.screens[j]->y; -int PanoramiXPutImage(ClientPtr client) + if (x_off || y_off) { + xArc *arcs = (xArc *) &stuff[1]; + + for (i = narcs; i--; arcs++) { + arcs->x -= x_off; + arcs->y -= y_off; + } + } + } + + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + result = (*SavedProcVector[X_PolyFillArc]) (client); + if (result != Success) + break; + } + free(origArcs); + return result; + } + else + return Success; +} + +int +PanoramiXPutImage(ClientPtr client) { PanoramiXRes *gc, *draw; - Bool isRoot; - int j, result, orig_x, orig_y; + Bool isRoot; + int j, result, orig_x, orig_y; + REQUEST(xPutImageReq); REQUEST_AT_LEAST_SIZE(xPutImageReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(IS_SHARED_PIXMAP(draw)) - return (*SavedProcVector[X_PutImage])(client); + if (IS_SHARED_PIXMAP(draw)) + return (*SavedProcVector[X_PutImage]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = IS_ROOT_DRAWABLE(draw); orig_x = stuff->dstX; orig_y = stuff->dstY; - FOR_NSCREENS_BACKWARD(j){ - if (isRoot) { - stuff->dstX = orig_x - screenInfo.screens[j]->x; - stuff->dstY = orig_y - screenInfo.screens[j]->y; - } - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - result = (* SavedProcVector[X_PutImage])(client); - if(result != Success) break; + FOR_NSCREENS_BACKWARD(j) { + if (isRoot) { + stuff->dstX = orig_x - screenInfo.screens[j]->x; + stuff->dstY = orig_y - screenInfo.screens[j]->y; + } + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + result = (*SavedProcVector[X_PutImage]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXGetImage(ClientPtr client) +int +PanoramiXGetImage(ClientPtr client) { - DrawablePtr drawables[MAXSCREENS]; - DrawablePtr pDraw; - PanoramiXRes *draw; - xGetImageReply xgi; - Bool isRoot; - char *pBuf; - int i, x, y, w, h, format, rc; - Mask plane = 0, planemask; - int linesDone, nlines, linesPerBuf; - long widthBytesLine, length; + DrawablePtr drawables[MAXSCREENS]; + DrawablePtr pDraw; + PanoramiXRes *draw; + xGetImageReply xgi; + Bool isRoot; + char *pBuf; + int i, x, y, w, h, format, rc; + Mask plane = 0, planemask; + int linesDone, nlines, linesPerBuf; + long widthBytesLine, length; REQUEST(xGetImageReq); REQUEST_SIZE_MATCH(xGetImageReq); if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) { - client->errorValue = stuff->format; + client->errorValue = stuff->format; return BadValue; } - rc = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + rc = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (rc != Success) - return (rc == BadValue) ? BadDrawable : rc; + return (rc == BadValue) ? BadDrawable : rc; - if(draw->type == XRT_PIXMAP) - return (*SavedProcVector[X_GetImage])(client); + if (draw->type == XRT_PIXMAP) + return (*SavedProcVector[X_GetImage]) (client); - rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, - DixReadAccess); + rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixReadAccess); if (rc != Success) - return rc; + return rc; - if(!((WindowPtr)pDraw)->realized) - return BadMatch; + if (!((WindowPtr) pDraw)->realized) + return BadMatch; x = stuff->x; y = stuff->y; @@ -1820,367 +1927,375 @@ int PanoramiXGetImage(ClientPtr client) isRoot = IS_ROOT_DRAWABLE(draw); - if(isRoot) { - if( /* check for being onscreen */ - x < 0 || x + w > PanoramiXPixWidth || - y < 0 || y + h > PanoramiXPixHeight ) - return BadMatch; - } else { - if( /* check for being onscreen */ - screenInfo.screens[0]->x + pDraw->x + x < 0 || - screenInfo.screens[0]->x + pDraw->x + x + w > PanoramiXPixWidth || - screenInfo.screens[0]->y + pDraw->y + y < 0 || - screenInfo.screens[0]->y + pDraw->y + y + h > PanoramiXPixHeight || - /* check for being inside of border */ - x < - wBorderWidth((WindowPtr)pDraw) || - x + w > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - y < -wBorderWidth((WindowPtr)pDraw) || - y + h > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height) - return BadMatch; + if (isRoot) { + /* check for being onscreen */ + if (x < 0 || x + w > PanoramiXPixWidth || + y < 0 || y + h > PanoramiXPixHeight) + return BadMatch; + } + else { + /* check for being onscreen and inside of border */ + if (screenInfo.screens[0]->x + pDraw->x + x < 0 || + screenInfo.screens[0]->x + pDraw->x + x + w > PanoramiXPixWidth || + screenInfo.screens[0]->y + pDraw->y + y < 0 || + screenInfo.screens[0]->y + pDraw->y + y + h > PanoramiXPixHeight || + x < -wBorderWidth((WindowPtr) pDraw) || + x + w > wBorderWidth((WindowPtr) pDraw) + (int) pDraw->width || + y < -wBorderWidth((WindowPtr) pDraw) || + y + h > wBorderWidth((WindowPtr) pDraw) + (int) pDraw->height) + return BadMatch; } drawables[0] = pDraw; FOR_NSCREENS_FORWARD_SKIP(i) { - rc = dixLookupDrawable(drawables+i, draw->info[i].id, client, 0, - DixGetAttrAccess); - if (rc != Success) - return rc; + rc = dixLookupDrawable(drawables + i, draw->info[i].id, client, 0, + DixGetAttrAccess); + if (rc != Success) + return rc; } - xgi.visual = wVisual (((WindowPtr) pDraw)); + xgi.visual = wVisual(((WindowPtr) pDraw)); xgi.type = X_Reply; xgi.sequenceNumber = client->sequence; xgi.depth = pDraw->depth; - if(format == ZPixmap) { - widthBytesLine = PixmapBytePad(w, pDraw->depth); - length = widthBytesLine * h; - + if (format == ZPixmap) { + widthBytesLine = PixmapBytePad(w, pDraw->depth); + length = widthBytesLine * h; - } else { - widthBytesLine = BitmapBytePad(w); - plane = ((Mask)1) << (pDraw->depth - 1); - /* only planes asked for */ - length = widthBytesLine * h * - Ones(planemask & (plane | (plane - 1))); + } + else { + widthBytesLine = BitmapBytePad(w); + plane = ((Mask) 1) << (pDraw->depth - 1); + /* only planes asked for */ + length = widthBytesLine * h * Ones(planemask & (plane | (plane - 1))); } xgi.length = bytes_to_int32(length); if (widthBytesLine == 0 || h == 0) - linesPerBuf = 0; + linesPerBuf = 0; else if (widthBytesLine >= XINERAMA_IMAGE_BUFSIZE) - linesPerBuf = 1; + linesPerBuf = 1; else { - linesPerBuf = XINERAMA_IMAGE_BUFSIZE / widthBytesLine; - if (linesPerBuf > h) - linesPerBuf = h; + linesPerBuf = XINERAMA_IMAGE_BUFSIZE / widthBytesLine; + if (linesPerBuf > h) + linesPerBuf = h; } length = linesPerBuf * widthBytesLine; - if(!(pBuf = malloc(length))) - return BadAlloc; + if (!(pBuf = malloc(length))) + return BadAlloc; - WriteReplyToClient(client, sizeof (xGetImageReply), &xgi); + WriteReplyToClient(client, sizeof(xGetImageReply), &xgi); if (linesPerBuf == 0) { - /* nothing to do */ + /* nothing to do */ } else if (format == ZPixmap) { linesDone = 0; while (h - linesDone > 0) { - nlines = min(linesPerBuf, h - linesDone); + nlines = min(linesPerBuf, h - linesDone); - if(pDraw->depth == 1) - memset(pBuf, 0, nlines * widthBytesLine); + if (pDraw->depth == 1) + memset(pBuf, 0, nlines * widthBytesLine); - XineramaGetImageData(drawables, x, y + linesDone, w, nlines, - format, planemask, pBuf, widthBytesLine, isRoot); + XineramaGetImageData(drawables, x, y + linesDone, w, nlines, + format, planemask, pBuf, widthBytesLine, + isRoot); - (void)WriteToClient(client, - (int)(nlines * widthBytesLine), - pBuf); - linesDone += nlines; + (void) WriteToClient(client, (int) (nlines * widthBytesLine), pBuf); + linesDone += nlines; } - } else { /* XYPixmap */ + } + else { /* XYPixmap */ for (; plane; plane >>= 1) { - if (planemask & plane) { - linesDone = 0; - while (h - linesDone > 0) { - nlines = min(linesPerBuf, h - linesDone); + if (planemask & plane) { + linesDone = 0; + while (h - linesDone > 0) { + nlines = min(linesPerBuf, h - linesDone); - memset(pBuf, 0, nlines * widthBytesLine); + memset(pBuf, 0, nlines * widthBytesLine); - XineramaGetImageData(drawables, x, y + linesDone, w, - nlines, format, plane, pBuf, - widthBytesLine, isRoot); + XineramaGetImageData(drawables, x, y + linesDone, w, + nlines, format, plane, pBuf, + widthBytesLine, isRoot); - (void)WriteToClient(client, - (int)(nlines * widthBytesLine), - pBuf); + (void) WriteToClient(client, + (int) (nlines * widthBytesLine), pBuf); - linesDone += nlines; - } + linesDone += nlines; + } } - } + } } free(pBuf); return Success; } - /* The text stuff should be rewritten so that duplication happens at the GlyphBlt level. That is, loading the font and getting the glyphs should only happen once */ -int +int PanoramiXPolyText8(ClientPtr client) { PanoramiXRes *gc, *draw; - Bool isRoot; - int result, j; - int orig_x, orig_y; + Bool isRoot; + int result, j; + int orig_x, orig_y; + REQUEST(xPolyTextReq); REQUEST_AT_LEAST_SIZE(xPolyTextReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(IS_SHARED_PIXMAP(draw)) - return (*SavedProcVector[X_PolyText8])(client); + if (IS_SHARED_PIXMAP(draw)) + return (*SavedProcVector[X_PolyText8]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = IS_ROOT_DRAWABLE(draw); orig_x = stuff->x; orig_y = stuff->y; - FOR_NSCREENS_BACKWARD(j){ - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - if (isRoot) { - stuff->x = orig_x - screenInfo.screens[j]->x; - stuff->y = orig_y - screenInfo.screens[j]->y; - } - result = (*SavedProcVector[X_PolyText8])(client); - if(result != Success) break; + FOR_NSCREENS_BACKWARD(j) { + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + if (isRoot) { + stuff->x = orig_x - screenInfo.screens[j]->x; + stuff->y = orig_y - screenInfo.screens[j]->y; + } + result = (*SavedProcVector[X_PolyText8]) (client); + if (result != Success) + break; } return result; } -int +int PanoramiXPolyText16(ClientPtr client) { PanoramiXRes *gc, *draw; - Bool isRoot; - int result, j; - int orig_x, orig_y; + Bool isRoot; + int result, j; + int orig_x, orig_y; + REQUEST(xPolyTextReq); REQUEST_AT_LEAST_SIZE(xPolyTextReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(IS_SHARED_PIXMAP(draw)) - return (*SavedProcVector[X_PolyText16])(client); + if (IS_SHARED_PIXMAP(draw)) + return (*SavedProcVector[X_PolyText16]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = IS_ROOT_DRAWABLE(draw); orig_x = stuff->x; orig_y = stuff->y; - FOR_NSCREENS_BACKWARD(j){ - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - if (isRoot) { - stuff->x = orig_x - screenInfo.screens[j]->x; - stuff->y = orig_y - screenInfo.screens[j]->y; - } - result = (*SavedProcVector[X_PolyText16])(client); - if(result != Success) break; + FOR_NSCREENS_BACKWARD(j) { + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + if (isRoot) { + stuff->x = orig_x - screenInfo.screens[j]->x; + stuff->y = orig_y - screenInfo.screens[j]->y; + } + result = (*SavedProcVector[X_PolyText16]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXImageText8(ClientPtr client) +int +PanoramiXImageText8(ClientPtr client) { - int result, j; + int result, j; PanoramiXRes *gc, *draw; - Bool isRoot; - int orig_x, orig_y; + Bool isRoot; + int orig_x, orig_y; + REQUEST(xImageTextReq); REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(IS_SHARED_PIXMAP(draw)) - return (*SavedProcVector[X_ImageText8])(client); + if (IS_SHARED_PIXMAP(draw)) + return (*SavedProcVector[X_ImageText8]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = IS_ROOT_DRAWABLE(draw); orig_x = stuff->x; orig_y = stuff->y; - FOR_NSCREENS_BACKWARD(j){ - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - if (isRoot) { - stuff->x = orig_x - screenInfo.screens[j]->x; - stuff->y = orig_y - screenInfo.screens[j]->y; - } - result = (*SavedProcVector[X_ImageText8])(client); - if(result != Success) break; + FOR_NSCREENS_BACKWARD(j) { + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + if (isRoot) { + stuff->x = orig_x - screenInfo.screens[j]->x; + stuff->y = orig_y - screenInfo.screens[j]->y; + } + result = (*SavedProcVector[X_ImageText8]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXImageText16(ClientPtr client) +int +PanoramiXImageText16(ClientPtr client) { - int result, j; + int result, j; PanoramiXRes *gc, *draw; - Bool isRoot; - int orig_x, orig_y; + Bool isRoot; + int orig_x, orig_y; + REQUEST(xImageTextReq); REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars << 1); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - if(IS_SHARED_PIXMAP(draw)) - return (*SavedProcVector[X_ImageText16])(client); + if (IS_SHARED_PIXMAP(draw)) + return (*SavedProcVector[X_ImageText16]) (client); - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, XRT_GC, + client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = IS_ROOT_DRAWABLE(draw); orig_x = stuff->x; orig_y = stuff->y; - FOR_NSCREENS_BACKWARD(j){ - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - if (isRoot) { - stuff->x = orig_x - screenInfo.screens[j]->x; - stuff->y = orig_y - screenInfo.screens[j]->y; - } - result = (*SavedProcVector[X_ImageText16])(client); - if(result != Success) break; + FOR_NSCREENS_BACKWARD(j) { + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + if (isRoot) { + stuff->x = orig_x - screenInfo.screens[j]->x; + stuff->y = orig_y - screenInfo.screens[j]->y; + } + result = (*SavedProcVector[X_ImageText16]) (client); + if (result != Success) + break; } return result; } - - -int PanoramiXCreateColormap(ClientPtr client) +int +PanoramiXCreateColormap(ClientPtr client) { - PanoramiXRes *win, *newCmap; - int result, j, orig_visual; + PanoramiXRes *win, *newCmap; + int result, j, orig_visual; + REQUEST(xCreateColormapReq); REQUEST_SIZE_MATCH(xCreateColormapReq); - result = dixLookupResourceByType((pointer *)&win, stuff->window, - XRT_WINDOW, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->window, + XRT_WINDOW, client, DixReadAccess); if (result != Success) - return result; + return result; - if(!(newCmap = malloc(sizeof(PanoramiXRes)))) + if (!(newCmap = malloc(sizeof(PanoramiXRes)))) return BadAlloc; newCmap->type = XRT_COLORMAP; panoramix_setup_ids(newCmap, client, stuff->mid); orig_visual = stuff->visual; - FOR_NSCREENS_BACKWARD(j){ - stuff->mid = newCmap->info[j].id; - stuff->window = win->info[j].id; - stuff->visual = PanoramiXTranslateVisualID(j, orig_visual); - result = (* SavedProcVector[X_CreateColormap])(client); - if(result != Success) break; - } - + FOR_NSCREENS_BACKWARD(j) { + stuff->mid = newCmap->info[j].id; + stuff->window = win->info[j].id; + stuff->visual = PanoramiXTranslateVisualID(j, orig_visual); + result = (*SavedProcVector[X_CreateColormap]) (client); + if (result != Success) + break; + } + if (result == Success) AddResource(newCmap->info[0].id, XRT_COLORMAP, newCmap); - else + else free(newCmap); return result; } - -int PanoramiXFreeColormap(ClientPtr client) +int +PanoramiXFreeColormap(ClientPtr client) { PanoramiXRes *cmap; - int result, j; + int result, j; + REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); client->errorValue = stuff->id; - result = dixLookupResourceByType((pointer *)&cmap, stuff->id, XRT_COLORMAP, - client, DixDestroyAccess); + result = dixLookupResourceByType((pointer *) &cmap, stuff->id, XRT_COLORMAP, + client, DixDestroyAccess); if (result != Success) return result; FOR_NSCREENS_BACKWARD(j) { stuff->id = cmap->info[j].id; - result = (* SavedProcVector[X_FreeColormap])(client); - if(result != Success) break; + result = (*SavedProcVector[X_FreeColormap]) (client); + if (result != Success) + break; } /* Since ProcFreeColormap is using FreeResource, it will free - our resource for us on the last pass through the loop above */ + our resource for us on the last pass through the loop above */ return result; } - int PanoramiXCopyColormapAndFree(ClientPtr client) { PanoramiXRes *cmap, *newCmap; - int result, j; + int result, j; + REQUEST(xCopyColormapAndFreeReq); REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq); client->errorValue = stuff->srcCmap; - result = dixLookupResourceByType((pointer *)&cmap, stuff->srcCmap, - XRT_COLORMAP, client, - DixReadAccess | DixWriteAccess); + result = dixLookupResourceByType((pointer *) &cmap, stuff->srcCmap, + XRT_COLORMAP, client, + DixReadAccess | DixWriteAccess); if (result != Success) return result; - if(!(newCmap = malloc(sizeof(PanoramiXRes)))) + if (!(newCmap = malloc(sizeof(PanoramiXRes)))) return BadAlloc; newCmap->type = XRT_COLORMAP; @@ -2188,231 +2303,246 @@ PanoramiXCopyColormapAndFree(ClientPtr client) FOR_NSCREENS_BACKWARD(j) { stuff->srcCmap = cmap->info[j].id; - stuff->mid = newCmap->info[j].id; - result = (* SavedProcVector[X_CopyColormapAndFree])(client); - if(result != Success) break; + stuff->mid = newCmap->info[j].id; + result = (*SavedProcVector[X_CopyColormapAndFree]) (client); + if (result != Success) + break; } if (result == Success) AddResource(newCmap->info[0].id, XRT_COLORMAP, newCmap); - else + else free(newCmap); return result; } - -int PanoramiXInstallColormap(ClientPtr client) +int +PanoramiXInstallColormap(ClientPtr client) { REQUEST(xResourceReq); - int result, j; + int result, j; PanoramiXRes *cmap; REQUEST_SIZE_MATCH(xResourceReq); client->errorValue = stuff->id; - result = dixLookupResourceByType((pointer *)&cmap, stuff->id, XRT_COLORMAP, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &cmap, stuff->id, XRT_COLORMAP, + client, DixReadAccess); if (result != Success) return result; - FOR_NSCREENS_BACKWARD(j){ - stuff->id = cmap->info[j].id; - result = (* SavedProcVector[X_InstallColormap])(client); - if(result != Success) break; + FOR_NSCREENS_BACKWARD(j) { + stuff->id = cmap->info[j].id; + result = (*SavedProcVector[X_InstallColormap]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXUninstallColormap(ClientPtr client) +int +PanoramiXUninstallColormap(ClientPtr client) { REQUEST(xResourceReq); - int result, j; + int result, j; PanoramiXRes *cmap; REQUEST_SIZE_MATCH(xResourceReq); - + client->errorValue = stuff->id; - result = dixLookupResourceByType((pointer *)&cmap, stuff->id, XRT_COLORMAP, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &cmap, stuff->id, XRT_COLORMAP, + client, DixReadAccess); if (result != Success) return result; FOR_NSCREENS_BACKWARD(j) { - stuff->id = cmap->info[j].id; - result = (* SavedProcVector[X_UninstallColormap])(client); - if(result != Success) break; + stuff->id = cmap->info[j].id; + result = (*SavedProcVector[X_UninstallColormap]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXAllocColor(ClientPtr client) +int +PanoramiXAllocColor(ClientPtr client) { - int result, j; + int result, j; PanoramiXRes *cmap; + REQUEST(xAllocColorReq); REQUEST_SIZE_MATCH(xAllocColorReq); client->errorValue = stuff->cmap; - result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap, - XRT_COLORMAP, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &cmap, stuff->cmap, + XRT_COLORMAP, client, DixWriteAccess); if (result != Success) return result; - FOR_NSCREENS_BACKWARD(j){ - stuff->cmap = cmap->info[j].id; - result = (* SavedProcVector[X_AllocColor])(client); - if(result != Success) break; + FOR_NSCREENS_BACKWARD(j) { + stuff->cmap = cmap->info[j].id; + result = (*SavedProcVector[X_AllocColor]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXAllocNamedColor(ClientPtr client) +int +PanoramiXAllocNamedColor(ClientPtr client) { - int result, j; - PanoramiXRes *cmap; + int result, j; + PanoramiXRes *cmap; + REQUEST(xAllocNamedColorReq); REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes); client->errorValue = stuff->cmap; - result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap, - XRT_COLORMAP, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &cmap, stuff->cmap, + XRT_COLORMAP, client, DixWriteAccess); if (result != Success) return result; - FOR_NSCREENS_BACKWARD(j){ + FOR_NSCREENS_BACKWARD(j) { stuff->cmap = cmap->info[j].id; - result = (* SavedProcVector[X_AllocNamedColor])(client); - if(result != Success) break; + result = (*SavedProcVector[X_AllocNamedColor]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXAllocColorCells(ClientPtr client) +int +PanoramiXAllocColorCells(ClientPtr client) { - int result, j; - PanoramiXRes *cmap; + int result, j; + PanoramiXRes *cmap; + REQUEST(xAllocColorCellsReq); REQUEST_SIZE_MATCH(xAllocColorCellsReq); client->errorValue = stuff->cmap; - result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap, - XRT_COLORMAP, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &cmap, stuff->cmap, + XRT_COLORMAP, client, DixWriteAccess); if (result != Success) return result; - - FOR_NSCREENS_BACKWARD(j){ - stuff->cmap = cmap->info[j].id; - result = (* SavedProcVector[X_AllocColorCells])(client); - if(result != Success) break; + + FOR_NSCREENS_BACKWARD(j) { + stuff->cmap = cmap->info[j].id; + result = (*SavedProcVector[X_AllocColorCells]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXAllocColorPlanes(ClientPtr client) +int +PanoramiXAllocColorPlanes(ClientPtr client) { - int result, j; - PanoramiXRes *cmap; + int result, j; + PanoramiXRes *cmap; + REQUEST(xAllocColorPlanesReq); REQUEST_SIZE_MATCH(xAllocColorPlanesReq); client->errorValue = stuff->cmap; - result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap, - XRT_COLORMAP, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &cmap, stuff->cmap, + XRT_COLORMAP, client, DixWriteAccess); if (result != Success) return result; - - FOR_NSCREENS_BACKWARD(j){ - stuff->cmap = cmap->info[j].id; - result = (* SavedProcVector[X_AllocColorPlanes])(client); - if(result != Success) break; + + FOR_NSCREENS_BACKWARD(j) { + stuff->cmap = cmap->info[j].id; + result = (*SavedProcVector[X_AllocColorPlanes]) (client); + if (result != Success) + break; } return result; } - - -int PanoramiXFreeColors(ClientPtr client) +int +PanoramiXFreeColors(ClientPtr client) { - int result, j; - PanoramiXRes *cmap; + int result, j; + PanoramiXRes *cmap; + REQUEST(xFreeColorsReq); REQUEST_AT_LEAST_SIZE(xFreeColorsReq); client->errorValue = stuff->cmap; - result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap, - XRT_COLORMAP, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &cmap, stuff->cmap, + XRT_COLORMAP, client, DixWriteAccess); if (result != Success) return result; FOR_NSCREENS_BACKWARD(j) { stuff->cmap = cmap->info[j].id; - result = (* SavedProcVector[X_FreeColors])(client); + result = (*SavedProcVector[X_FreeColors]) (client); } return result; } - -int PanoramiXStoreColors(ClientPtr client) +int +PanoramiXStoreColors(ClientPtr client) { - int result, j; - PanoramiXRes *cmap; + int result, j; + PanoramiXRes *cmap; + REQUEST(xStoreColorsReq); REQUEST_AT_LEAST_SIZE(xStoreColorsReq); client->errorValue = stuff->cmap; - result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap, - XRT_COLORMAP, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &cmap, stuff->cmap, + XRT_COLORMAP, client, DixWriteAccess); if (result != Success) return result; - FOR_NSCREENS_BACKWARD(j){ - stuff->cmap = cmap->info[j].id; - result = (* SavedProcVector[X_StoreColors])(client); - if(result != Success) break; + FOR_NSCREENS_BACKWARD(j) { + stuff->cmap = cmap->info[j].id; + result = (*SavedProcVector[X_StoreColors]) (client); + if (result != Success) + break; } return result; } - -int PanoramiXStoreNamedColor(ClientPtr client) +int +PanoramiXStoreNamedColor(ClientPtr client) { - int result, j; - PanoramiXRes *cmap; + int result, j; + PanoramiXRes *cmap; + REQUEST(xStoreNamedColorReq); REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes); client->errorValue = stuff->cmap; - result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap, - XRT_COLORMAP, client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &cmap, stuff->cmap, + XRT_COLORMAP, client, DixWriteAccess); if (result != Success) return result; - FOR_NSCREENS_BACKWARD(j){ - stuff->cmap = cmap->info[j].id; - result = (* SavedProcVector[X_StoreNamedColor])(client); - if(result != Success) break; + FOR_NSCREENS_BACKWARD(j) { + stuff->cmap = cmap->info[j].id; + result = (*SavedProcVector[X_StoreNamedColor]) (client); + if (result != Success) + break; } return result; } diff --git a/xorg-server/Xext/panoramiXsrv.h b/xorg-server/Xext/panoramiXsrv.h index 39d495203..7c605fe66 100644 --- a/xorg-server/Xext/panoramiXsrv.h +++ b/xorg-server/Xext/panoramiXsrv.h @@ -15,8 +15,9 @@ extern _X_EXPORT int PanoramiXPixHeight; extern _X_EXPORT VisualID PanoramiXTranslateVisualID(int screen, VisualID orig); extern _X_EXPORT void PanoramiXConsolidate(void); extern _X_EXPORT Bool PanoramiXCreateConnectionBlock(void); -extern _X_EXPORT PanoramiXRes * PanoramiXFindIDByScrnum(RESTYPE, XID, int); -extern _X_EXPORT Bool XineramaRegisterConnectionBlockCallback(void (*func)(void)); +extern _X_EXPORT PanoramiXRes *PanoramiXFindIDByScrnum(RESTYPE, XID, int); +extern _X_EXPORT Bool +XineramaRegisterConnectionBlockCallback(void (*func) (void)); extern _X_EXPORT int XineramaDeleteResource(pointer, XID); extern _X_EXPORT void XineramaReinitData(void); @@ -35,24 +36,20 @@ extern _X_EXPORT RESTYPE XRT_PICTURE; * layers agree that the visuals are equal. The first visual is always from * screen 0. */ -typedef Bool (*XineramaVisualsEqualProcPtr)(VisualPtr, ScreenPtr, VisualPtr); +typedef Bool (*XineramaVisualsEqualProcPtr) (VisualPtr, ScreenPtr, VisualPtr); extern _X_EXPORT XineramaVisualsEqualProcPtr XineramaVisualsEqualPtr; -extern _X_EXPORT void XineramaGetImageData( - DrawablePtr *pDrawables, - int left, - int top, - int width, - int height, - unsigned int format, - unsigned long planemask, - char *data, - int pitch, - Bool isRoot -); - -static inline void panoramix_setup_ids(PanoramiXRes *resource, - ClientPtr client, XID base_id) +extern _X_EXPORT void XineramaGetImageData(DrawablePtr *pDrawables, + int left, + int top, + int width, + int height, + unsigned int format, + unsigned long planemask, + char *data, int pitch, Bool isRoot); + +static inline void +panoramix_setup_ids(PanoramiXRes * resource, ClientPtr client, XID base_id) { int j; @@ -62,4 +59,4 @@ static inline void panoramix_setup_ids(PanoramiXRes *resource, } } -#endif /* _PANORAMIXSRV_H_ */ +#endif /* _PANORAMIXSRV_H_ */ diff --git a/xorg-server/Xext/saver.c b/xorg-server/Xext/saver.c index 78f8efac3..6c8fc6e0b 100644 --- a/xorg-server/Xext/saver.c +++ b/xorg-server/Xext/saver.c @@ -26,7 +26,6 @@ in this Software without prior written authorization from the X Consortium. * Author: Keith Packard, MIT X Consortium */ - #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> #else @@ -53,6 +52,7 @@ in this Software without prior written authorization from the X Consortium. #include "cursorstr.h" #include "colormapst.h" #include "xace.h" +#include "inputstr.h" #ifdef PANORAMIX #include "panoramiX.h" #include "panoramiXsrv.h" @@ -68,39 +68,32 @@ in this Software without prior written authorization from the X Consortium. static int ScreenSaverEventBase = 0; - -static Bool ScreenSaverHandle ( - ScreenPtr /* pScreen */, - int /* xstate */, - Bool /* force */ - ); +static Bool ScreenSaverHandle(ScreenPtr /* pScreen */ , + int /* xstate */ , + Bool /* force */ + ); static Bool -CreateSaverWindow ( - ScreenPtr /* pScreen */ - ); + CreateSaverWindow(ScreenPtr /* pScreen */ + ); static Bool -DestroySaverWindow ( - ScreenPtr /* pScreen */ - ); + DestroySaverWindow(ScreenPtr /* pScreen */ + ); static void -UninstallSaverColormap ( - ScreenPtr /* pScreen */ - ); + UninstallSaverColormap(ScreenPtr /* pScreen */ + ); static void -CheckScreenPrivate ( - ScreenPtr /* pScreen */ - ); + CheckScreenPrivate(ScreenPtr /* pScreen */ + ); -static void SScreenSaverNotifyEvent ( - xScreenSaverNotifyEvent * /* from */, - xScreenSaverNotifyEvent * /* to */ - ); +static void SScreenSaverNotifyEvent(xScreenSaverNotifyEvent * /* from */ , + xScreenSaverNotifyEvent * /* to */ + ); -static RESTYPE SuspendType; /* resource type for suspension records */ +static RESTYPE SuspendType; /* resource type for suspension records */ typedef struct _ScreenSaverSuspension *ScreenSaverSuspensionPtr; @@ -113,18 +106,16 @@ static ScreenSaverSuspensionPtr suspendingClients = NULL; * the client disconnects. count is the number of times the client has * requested the screensaver be suspended. */ -typedef struct _ScreenSaverSuspension -{ - ScreenSaverSuspensionPtr next; - ClientPtr pClient; - XID clientResource; - int count; +typedef struct _ScreenSaverSuspension { + ScreenSaverSuspensionPtr next; + ClientPtr pClient; + XID clientResource; + int count; } ScreenSaverSuspensionRec; -static int ScreenSaverFreeSuspend( - pointer /*value */, - XID /* id */ -); +static int ScreenSaverFreeSuspend(pointer /*value */ , + XID /* id */ + ); /* * each screen has a list of clients requesting @@ -134,91 +125,83 @@ static int ScreenSaverFreeSuspend( * entry from the per-screen queue. */ -static RESTYPE SaverEventType; /* resource type for event masks */ +static RESTYPE SaverEventType; /* resource type for event masks */ typedef struct _ScreenSaverEvent *ScreenSaverEventPtr; typedef struct _ScreenSaverEvent { - ScreenSaverEventPtr next; - ClientPtr client; - ScreenPtr screen; - XID resource; - CARD32 mask; + ScreenSaverEventPtr next; + ClientPtr client; + ScreenPtr screen; + XID resource; + CARD32 mask; } ScreenSaverEventRec; -static int ScreenSaverFreeEvents( - pointer /* value */, - XID /* id */ -); +static int ScreenSaverFreeEvents(pointer /* value */ , + XID /* id */ + ); -static Bool setEventMask ( - ScreenPtr /* pScreen */, - ClientPtr /* client */, - unsigned long /* mask */ -); +static Bool setEventMask(ScreenPtr /* pScreen */ , + ClientPtr /* client */ , + unsigned long /* mask */ + ); -static unsigned long getEventMask ( - ScreenPtr /* pScreen */, - ClientPtr /* client */ -); +static unsigned long getEventMask(ScreenPtr /* pScreen */ , + ClientPtr /* client */ + ); /* * when a client sets the screen saver attributes, a resource is * kept to be freed when the client exits */ -static RESTYPE AttrType; /* resource type for attributes */ +static RESTYPE AttrType; /* resource type for attributes */ typedef struct _ScreenSaverAttr { - ScreenPtr screen; - ClientPtr client; - XID resource; - short x, y; - unsigned short width, height, borderWidth; - unsigned char class; - unsigned char depth; - VisualID visual; - CursorPtr pCursor; - PixmapPtr pBackgroundPixmap; - PixmapPtr pBorderPixmap; - Colormap colormap; - unsigned long mask; /* no pixmaps or cursors */ - unsigned long *values; + ScreenPtr screen; + ClientPtr client; + XID resource; + short x, y; + unsigned short width, height, borderWidth; + unsigned char class; + unsigned char depth; + VisualID visual; + CursorPtr pCursor; + PixmapPtr pBackgroundPixmap; + PixmapPtr pBorderPixmap; + Colormap colormap; + unsigned long mask; /* no pixmaps or cursors */ + unsigned long *values; } ScreenSaverAttrRec, *ScreenSaverAttrPtr; -static int ScreenSaverFreeAttr ( - pointer /* value */, - XID /* id */ -); +static int ScreenSaverFreeAttr(pointer /* value */ , + XID /* id */ + ); -static void FreeAttrs ( - ScreenSaverAttrPtr /* pAttr */ -); +static void FreeAttrs(ScreenSaverAttrPtr /* pAttr */ + ); -static void FreeScreenAttr ( - ScreenSaverAttrPtr /* pAttr */ -); +static void FreeScreenAttr(ScreenSaverAttrPtr /* pAttr */ + ); static void -SendScreenSaverNotify ( - ScreenPtr /* pScreen */, - int /* state */, - Bool /* forced */ -); + SendScreenSaverNotify(ScreenPtr /* pScreen */ , + int /* state */ , + Bool /* forced */ + ); typedef struct _ScreenSaverScreenPrivate { - ScreenSaverEventPtr events; - ScreenSaverAttrPtr attr; - Bool hasWindow; - Colormap installedMap; + ScreenSaverEventPtr events; + ScreenSaverAttrPtr attr; + Bool hasWindow; + Colormap installedMap; } ScreenSaverScreenPrivateRec, *ScreenSaverScreenPrivatePtr; -static ScreenSaverScreenPrivatePtr -MakeScreenPrivate ( - ScreenPtr /* pScreen */ - ); +static ScreenSaverScreenPrivatePtr MakeScreenPrivate(ScreenPtr /* pScreen */ + ); static DevPrivateKeyRec ScreenPrivateKeyRec; + #define ScreenPrivateKey (&ScreenPrivateKeyRec) #define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr) \ @@ -230,387 +213,372 @@ static DevPrivateKeyRec ScreenPrivateKeyRec; #define New(t) (malloc(sizeof (t))) static void -CheckScreenPrivate (ScreenPtr pScreen) +CheckScreenPrivate(ScreenPtr pScreen) { - SetupScreen (pScreen); + SetupScreen(pScreen); if (!pPriv) - return; + return; if (!pPriv->attr && !pPriv->events && - !pPriv->hasWindow && pPriv->installedMap == None) - { - free(pPriv); - SetScreenPrivate (pScreen, NULL); - pScreen->screensaver.ExternalScreenSaver = NULL; + !pPriv->hasWindow && pPriv->installedMap == None) { + free(pPriv); + SetScreenPrivate(pScreen, NULL); + pScreen->screensaver.ExternalScreenSaver = NULL; } } static ScreenSaverScreenPrivatePtr -MakeScreenPrivate (ScreenPtr pScreen) +MakeScreenPrivate(ScreenPtr pScreen) { - SetupScreen (pScreen); + SetupScreen(pScreen); if (pPriv) - return pPriv; - pPriv = New (ScreenSaverScreenPrivateRec); + return pPriv; + pPriv = New(ScreenSaverScreenPrivateRec); if (!pPriv) - return 0; + return 0; pPriv->events = 0; pPriv->attr = 0; pPriv->hasWindow = FALSE; pPriv->installedMap = None; - SetScreenPrivate (pScreen, pPriv); + SetScreenPrivate(pScreen, pPriv); pScreen->screensaver.ExternalScreenSaver = ScreenSaverHandle; return pPriv; } static unsigned long -getEventMask (ScreenPtr pScreen, ClientPtr client) +getEventMask(ScreenPtr pScreen, ClientPtr client) { SetupScreen(pScreen); - ScreenSaverEventPtr pEv; + ScreenSaverEventPtr pEv; if (!pPriv) - return 0; + return 0; for (pEv = pPriv->events; pEv; pEv = pEv->next) - if (pEv->client == client) - return pEv->mask; + if (pEv->client == client) + return pEv->mask; return 0; } static Bool -setEventMask (ScreenPtr pScreen, ClientPtr client, unsigned long mask) +setEventMask(ScreenPtr pScreen, ClientPtr client, unsigned long mask) { SetupScreen(pScreen); - ScreenSaverEventPtr pEv, *pPrev; - - if (getEventMask (pScreen, client) == mask) - return TRUE; - if (!pPriv) - { - pPriv = MakeScreenPrivate (pScreen); - if (!pPriv) - return FALSE; + ScreenSaverEventPtr pEv, *pPrev; + + if (getEventMask(pScreen, client) == mask) + return TRUE; + if (!pPriv) { + pPriv = MakeScreenPrivate(pScreen); + if (!pPriv) + return FALSE; } for (pPrev = &pPriv->events; (pEv = *pPrev) != 0; pPrev = &pEv->next) - if (pEv->client == client) - break; - if (mask == 0) - { - FreeResource (pEv->resource, SaverEventType); - *pPrev = pEv->next; - free(pEv); - CheckScreenPrivate (pScreen); + if (pEv->client == client) + break; + if (mask == 0) { + FreeResource(pEv->resource, SaverEventType); + *pPrev = pEv->next; + free(pEv); + CheckScreenPrivate(pScreen); } - else - { - if (!pEv) - { - pEv = New (ScreenSaverEventRec); - if (!pEv) - { - CheckScreenPrivate (pScreen); - return FALSE; - } - *pPrev = pEv; - pEv->next = NULL; - pEv->client = client; - pEv->screen = pScreen; - pEv->resource = FakeClientID (client->index); - if (!AddResource (pEv->resource, SaverEventType, (pointer) pEv)) - return FALSE; - } - pEv->mask = mask; + else { + if (!pEv) { + pEv = New(ScreenSaverEventRec); + if (!pEv) { + CheckScreenPrivate(pScreen); + return FALSE; + } + *pPrev = pEv; + pEv->next = NULL; + pEv->client = client; + pEv->screen = pScreen; + pEv->resource = FakeClientID(client->index); + if (!AddResource(pEv->resource, SaverEventType, (pointer) pEv)) + return FALSE; + } + pEv->mask = mask; } return TRUE; } static void -FreeAttrs (ScreenSaverAttrPtr pAttr) +FreeAttrs(ScreenSaverAttrPtr pAttr) { - PixmapPtr pPixmap; - CursorPtr pCursor; + PixmapPtr pPixmap; + CursorPtr pCursor; if ((pPixmap = pAttr->pBackgroundPixmap) != 0) - (*pPixmap->drawable.pScreen->DestroyPixmap)(pPixmap); + (*pPixmap->drawable.pScreen->DestroyPixmap) (pPixmap); if ((pPixmap = pAttr->pBorderPixmap) != 0) - (*pPixmap->drawable.pScreen->DestroyPixmap)(pPixmap); + (*pPixmap->drawable.pScreen->DestroyPixmap) (pPixmap); if ((pCursor = pAttr->pCursor) != 0) - FreeCursor (pCursor, (Cursor) 0); + FreeCursor(pCursor, (Cursor) 0); } static void -FreeScreenAttr (ScreenSaverAttrPtr pAttr) +FreeScreenAttr(ScreenSaverAttrPtr pAttr) { - FreeAttrs (pAttr); + FreeAttrs(pAttr); free(pAttr->values); free(pAttr); } static int -ScreenSaverFreeEvents (pointer value, XID id) +ScreenSaverFreeEvents(pointer value, XID id) { - ScreenSaverEventPtr pOld = (ScreenSaverEventPtr)value; + ScreenSaverEventPtr pOld = (ScreenSaverEventPtr) value; ScreenPtr pScreen = pOld->screen; - SetupScreen (pScreen); - ScreenSaverEventPtr pEv, *pPrev; + + SetupScreen(pScreen); + ScreenSaverEventPtr pEv, *pPrev; if (!pPriv) - return TRUE; + return TRUE; for (pPrev = &pPriv->events; (pEv = *pPrev) != 0; pPrev = &pEv->next) - if (pEv == pOld) - break; + if (pEv == pOld) + break; if (!pEv) - return TRUE; + return TRUE; *pPrev = pEv->next; free(pEv); - CheckScreenPrivate (pScreen); + CheckScreenPrivate(pScreen); return TRUE; } static int -ScreenSaverFreeAttr (pointer value, XID id) +ScreenSaverFreeAttr(pointer value, XID id) { - ScreenSaverAttrPtr pOldAttr = (ScreenSaverAttrPtr)value; - ScreenPtr pScreen = pOldAttr->screen; - SetupScreen (pScreen); + ScreenSaverAttrPtr pOldAttr = (ScreenSaverAttrPtr) value; + ScreenPtr pScreen = pOldAttr->screen; + + SetupScreen(pScreen); if (!pPriv) - return TRUE; + return TRUE; if (pPriv->attr != pOldAttr) - return TRUE; - FreeScreenAttr (pOldAttr); + return TRUE; + FreeScreenAttr(pOldAttr); pPriv->attr = NULL; - if (pPriv->hasWindow) - { - dixSaveScreens (serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); - dixSaveScreens (serverClient, SCREEN_SAVER_FORCER, ScreenSaverActive); + if (pPriv->hasWindow) { + dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); + dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverActive); } - CheckScreenPrivate (pScreen); + CheckScreenPrivate(pScreen); return TRUE; } static int -ScreenSaverFreeSuspend (pointer value, XID id) +ScreenSaverFreeSuspend(pointer value, XID id) { ScreenSaverSuspensionPtr data = (ScreenSaverSuspensionPtr) value; ScreenSaverSuspensionPtr *prev, this; /* Unlink and free the suspension record for the client */ - for (prev = &suspendingClients; (this = *prev); prev = &this->next) - { - if (this == data) - { - *prev = this->next; - free(this); - break; - } + for (prev = &suspendingClients; (this = *prev); prev = &this->next) { + if (this == data) { + *prev = this->next; + free(this); + break; + } } /* Reenable the screensaver if this was the last client suspending it. */ - if (screenSaverSuspended && suspendingClients == NULL) - { - screenSaverSuspended = FALSE; + if (screenSaverSuspended && suspendingClients == NULL) { + screenSaverSuspended = FALSE; - /* The screensaver could be active, since suspending it (by design) - doesn't prevent it from being forceably activated */ + /* The screensaver could be active, since suspending it (by design) + doesn't prevent it from being forceably activated */ #ifdef DPMSExtension - if (screenIsSaved != SCREEN_SAVER_ON && DPMSPowerLevel == DPMSModeOn) + if (screenIsSaved != SCREEN_SAVER_ON && DPMSPowerLevel == DPMSModeOn) #else - if (screenIsSaved != SCREEN_SAVER_ON) + if (screenIsSaved != SCREEN_SAVER_ON) #endif - { - UpdateCurrentTimeIf(); - lastDeviceEventTime = currentTime; - SetScreenSaverTimer(); - } + { + DeviceIntPtr dev; + UpdateCurrentTimeIf(); + nt_list_for_each_entry(dev, inputInfo.devices, next) + lastDeviceEventTime[dev->id] = currentTime; + SetScreenSaverTimer(); + } } return Success; } static void -SendScreenSaverNotify (ScreenPtr pScreen, int state, Bool forced) +SendScreenSaverNotify(ScreenPtr pScreen, int state, Bool forced) { - ScreenSaverScreenPrivatePtr pPriv; - ScreenSaverEventPtr pEv; - unsigned long mask; - xScreenSaverNotifyEvent ev; - int kind; + ScreenSaverScreenPrivatePtr pPriv; + ScreenSaverEventPtr pEv; + unsigned long mask; + xScreenSaverNotifyEvent ev; + int kind; - UpdateCurrentTimeIf (); + UpdateCurrentTimeIf(); mask = ScreenSaverNotifyMask; if (state == ScreenSaverCycle) - mask = ScreenSaverCycleMask; + mask = ScreenSaverCycleMask; pScreen = screenInfo.screens[pScreen->myNum]; pPriv = GetScreenPrivate(pScreen); if (!pPriv) - return; + return; if (pPriv->attr) - kind = ScreenSaverExternal; + kind = ScreenSaverExternal; else if (ScreenSaverBlanking != DontPreferBlanking) - kind = ScreenSaverBlanked; + kind = ScreenSaverBlanked; else - kind = ScreenSaverInternal; - for (pEv = pPriv->events; pEv; pEv = pEv->next) - { - if (!(pEv->mask & mask)) - continue; - ev.type = ScreenSaverNotify + ScreenSaverEventBase; - ev.state = state; - ev.timestamp = currentTime.milliseconds; - ev.root = pScreen->root->drawable.id; - ev.window = pScreen->screensaver.wid; - ev.kind = kind; - ev.forced = forced; - WriteEventsToClient (pEv->client, 1, (xEvent *) &ev); + kind = ScreenSaverInternal; + for (pEv = pPriv->events; pEv; pEv = pEv->next) { + if (!(pEv->mask & mask)) + continue; + ev.type = ScreenSaverNotify + ScreenSaverEventBase; + ev.state = state; + ev.timestamp = currentTime.milliseconds; + ev.root = pScreen->root->drawable.id; + ev.window = pScreen->screensaver.wid; + ev.kind = kind; + ev.forced = forced; + WriteEventsToClient(pEv->client, 1, (xEvent *) &ev); } } static void -SScreenSaverNotifyEvent (xScreenSaverNotifyEvent *from, - xScreenSaverNotifyEvent *to) +SScreenSaverNotifyEvent(xScreenSaverNotifyEvent * from, + xScreenSaverNotifyEvent * to) { to->type = from->type; to->state = from->state; - cpswaps (from->sequenceNumber, to->sequenceNumber); - cpswapl (from->timestamp, to->timestamp); - cpswapl (from->root, to->root); - cpswapl (from->window, to->window); + cpswaps(from->sequenceNumber, to->sequenceNumber); + cpswapl(from->timestamp, to->timestamp); + cpswapl(from->root, to->root); + cpswapl(from->window, to->window); to->kind = from->kind; to->forced = from->forced; } static void -UninstallSaverColormap (ScreenPtr pScreen) +UninstallSaverColormap(ScreenPtr pScreen) { SetupScreen(pScreen); - ColormapPtr pCmap; + ColormapPtr pCmap; int rc; - if (pPriv && pPriv->installedMap != None) - { - rc = dixLookupResourceByType((pointer *)&pCmap, pPriv->installedMap, - RT_COLORMAP, serverClient, - DixUninstallAccess); - if (rc == Success) - (*pCmap->pScreen->UninstallColormap) (pCmap); - pPriv->installedMap = None; - CheckScreenPrivate (pScreen); + if (pPriv && pPriv->installedMap != None) { + rc = dixLookupResourceByType((pointer *) &pCmap, pPriv->installedMap, + RT_COLORMAP, serverClient, + DixUninstallAccess); + if (rc == Success) + (*pCmap->pScreen->UninstallColormap) (pCmap); + pPriv->installedMap = None; + CheckScreenPrivate(pScreen); } } static Bool -CreateSaverWindow (ScreenPtr pScreen) +CreateSaverWindow(ScreenPtr pScreen) { - SetupScreen (pScreen); - ScreenSaverStuffPtr pSaver; - ScreenSaverAttrPtr pAttr; - WindowPtr pWin; - int result; - unsigned long mask; - Colormap *installedMaps; - int numInstalled; - int i; - Colormap wantMap; - ColormapPtr pCmap; + SetupScreen(pScreen); + ScreenSaverStuffPtr pSaver; + ScreenSaverAttrPtr pAttr; + WindowPtr pWin; + int result; + unsigned long mask; + Colormap *installedMaps; + int numInstalled; + int i; + Colormap wantMap; + ColormapPtr pCmap; pSaver = &pScreen->screensaver; - if (pSaver->pWindow) - { - pSaver->pWindow = NullWindow; - FreeResource (pSaver->wid, RT_NONE); - if (pPriv) - { - UninstallSaverColormap (pScreen); - pPriv->hasWindow = FALSE; - CheckScreenPrivate (pScreen); - } + if (pSaver->pWindow) { + pSaver->pWindow = NullWindow; + FreeResource(pSaver->wid, RT_NONE); + if (pPriv) { + UninstallSaverColormap(pScreen); + pPriv->hasWindow = FALSE; + CheckScreenPrivate(pScreen); + } } if (!pPriv || !(pAttr = pPriv->attr)) - return FALSE; + return FALSE; pPriv->installedMap = None; if (GrabInProgress && GrabInProgress != pAttr->client->index) - return FALSE; - - pWin = CreateWindow (pSaver->wid, pScreen->root, - pAttr->x, pAttr->y, pAttr->width, pAttr->height, - pAttr->borderWidth, pAttr->class, - pAttr->mask, (XID *)pAttr->values, - pAttr->depth, serverClient, pAttr->visual, - &result); + return FALSE; + + pWin = CreateWindow(pSaver->wid, pScreen->root, + pAttr->x, pAttr->y, pAttr->width, pAttr->height, + pAttr->borderWidth, pAttr->class, + pAttr->mask, (XID *) pAttr->values, + pAttr->depth, serverClient, pAttr->visual, &result); if (!pWin) - return FALSE; + return FALSE; if (!AddResource(pWin->drawable.id, RT_WINDOW, pWin)) - return FALSE; + return FALSE; mask = 0; - if (pAttr->pBackgroundPixmap) - { - pWin->backgroundState = BackgroundPixmap; - pWin->background.pixmap = pAttr->pBackgroundPixmap; - pAttr->pBackgroundPixmap->refcnt++; - mask |= CWBackPixmap; + if (pAttr->pBackgroundPixmap) { + pWin->backgroundState = BackgroundPixmap; + pWin->background.pixmap = pAttr->pBackgroundPixmap; + pAttr->pBackgroundPixmap->refcnt++; + mask |= CWBackPixmap; } - if (pAttr->pBorderPixmap) - { - pWin->borderIsPixel = FALSE; - pWin->border.pixmap = pAttr->pBorderPixmap; - pAttr->pBorderPixmap->refcnt++; - mask |= CWBorderPixmap; + if (pAttr->pBorderPixmap) { + pWin->borderIsPixel = FALSE; + pWin->border.pixmap = pAttr->pBorderPixmap; + pAttr->pBorderPixmap->refcnt++; + mask |= CWBorderPixmap; } - if (pAttr->pCursor) - { - if (!pWin->optional) - if (!MakeWindowOptional (pWin)) - { - FreeResource (pWin->drawable.id, RT_NONE); - return FALSE; - } - pAttr->pCursor->refcnt++; - if (pWin->optional->cursor) - FreeCursor (pWin->optional->cursor, (Cursor)0); - pWin->optional->cursor = pAttr->pCursor; - pWin->cursorIsNone = FALSE; - CheckWindowOptionalNeed (pWin); - mask |= CWCursor; + if (pAttr->pCursor) { + if (!pWin->optional) + if (!MakeWindowOptional(pWin)) { + FreeResource(pWin->drawable.id, RT_NONE); + return FALSE; + } + pAttr->pCursor->refcnt++; + if (pWin->optional->cursor) + FreeCursor(pWin->optional->cursor, (Cursor) 0); + pWin->optional->cursor = pAttr->pCursor; + pWin->cursorIsNone = FALSE; + CheckWindowOptionalNeed(pWin); + mask |= CWCursor; } if (mask) - (*pScreen->ChangeWindowAttributes) (pWin, mask); + (*pScreen->ChangeWindowAttributes) (pWin, mask); if (pAttr->colormap != None) - (void) ChangeWindowAttributes (pWin, CWColormap, &pAttr->colormap, - serverClient); + (void) ChangeWindowAttributes(pWin, CWColormap, &pAttr->colormap, + serverClient); - MapWindow (pWin, serverClient); + MapWindow(pWin, serverClient); pPriv->hasWindow = TRUE; pSaver->pWindow = pWin; /* check and install our own colormap if it isn't installed now */ - wantMap = wColormap (pWin); + wantMap = wColormap(pWin); if (wantMap == None) - return TRUE; - installedMaps = malloc(pScreen->maxInstalledCmaps * sizeof (Colormap)); + return TRUE; + installedMaps = malloc(pScreen->maxInstalledCmaps * sizeof(Colormap)); numInstalled = (*pWin->drawable.pScreen->ListInstalledColormaps) - (pScreen, installedMaps); - for (i = 0; i < numInstalled; i++) - if (installedMaps[i] == wantMap) - break; + (pScreen, installedMaps); + for (i = 0; i < numInstalled; i++) + if (installedMaps[i] == wantMap) + break; free((char *) installedMaps); if (i < numInstalled) - return TRUE; + return TRUE; - result = dixLookupResourceByType((pointer *)&pCmap, wantMap, RT_COLORMAP, - serverClient, DixInstallAccess); + result = dixLookupResourceByType((pointer *) &pCmap, wantMap, RT_COLORMAP, + serverClient, DixInstallAccess); if (result != Success) - return TRUE; + return TRUE; pPriv->installedMap = wantMap; @@ -620,229 +588,221 @@ CreateSaverWindow (ScreenPtr pScreen) } static Bool -DestroySaverWindow (ScreenPtr pScreen) +DestroySaverWindow(ScreenPtr pScreen) { SetupScreen(pScreen); - ScreenSaverStuffPtr pSaver; + ScreenSaverStuffPtr pSaver; if (!pPriv || !pPriv->hasWindow) - return FALSE; + return FALSE; pSaver = &pScreen->screensaver; - if (pSaver->pWindow) - { - pSaver->pWindow = NullWindow; - FreeResource (pSaver->wid, RT_NONE); + if (pSaver->pWindow) { + pSaver->pWindow = NullWindow; + FreeResource(pSaver->wid, RT_NONE); } pPriv->hasWindow = FALSE; - CheckScreenPrivate (pScreen); - UninstallSaverColormap (pScreen); + CheckScreenPrivate(pScreen); + UninstallSaverColormap(pScreen); return TRUE; } static Bool -ScreenSaverHandle (ScreenPtr pScreen, int xstate, Bool force) +ScreenSaverHandle(ScreenPtr pScreen, int xstate, Bool force) { - int state = 0; - Bool ret = FALSE; - ScreenSaverScreenPrivatePtr pPriv; - - switch (xstate) - { - case SCREEN_SAVER_ON: - state = ScreenSaverOn; - ret = CreateSaverWindow (pScreen); - break; - case SCREEN_SAVER_OFF: - state = ScreenSaverOff; - ret = DestroySaverWindow (pScreen); - break; - case SCREEN_SAVER_CYCLE: - state = ScreenSaverCycle; - pPriv = GetScreenPrivate (pScreen); - if (pPriv && pPriv->hasWindow) - ret = TRUE; - + int state = 0; + Bool ret = FALSE; + ScreenSaverScreenPrivatePtr pPriv; + + switch (xstate) { + case SCREEN_SAVER_ON: + state = ScreenSaverOn; + ret = CreateSaverWindow(pScreen); + break; + case SCREEN_SAVER_OFF: + state = ScreenSaverOff; + ret = DestroySaverWindow(pScreen); + break; + case SCREEN_SAVER_CYCLE: + state = ScreenSaverCycle; + pPriv = GetScreenPrivate(pScreen); + if (pPriv && pPriv->hasWindow) + ret = TRUE; + } #ifdef PANORAMIX - if(noPanoramiXExtension || !pScreen->myNum) + if (noPanoramiXExtension || !pScreen->myNum) #endif - SendScreenSaverNotify (pScreen, state, force); + SendScreenSaverNotify(pScreen, state, force); return ret; } static int -ProcScreenSaverQueryVersion (ClientPtr client) +ProcScreenSaverQueryVersion(ClientPtr client) { - xScreenSaverQueryVersionReply rep; - REQUEST_SIZE_MATCH (xScreenSaverQueryVersionReq); + xScreenSaverQueryVersionReply rep; + + REQUEST_SIZE_MATCH(xScreenSaverQueryVersionReq); rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; rep.majorVersion = SERVER_SAVER_MAJOR_VERSION; rep.minorVersion = SERVER_SAVER_MINOR_VERSION; if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); + swaps(&rep.sequenceNumber); + swapl(&rep.length); } - WriteToClient(client, sizeof (xScreenSaverQueryVersionReply), (char *)&rep); + WriteToClient(client, sizeof(xScreenSaverQueryVersionReply), (char *) &rep); return Success; } static int -ProcScreenSaverQueryInfo (ClientPtr client) +ProcScreenSaverQueryInfo(ClientPtr client) { REQUEST(xScreenSaverQueryInfoReq); - xScreenSaverQueryInfoReply rep; - int rc; - ScreenSaverStuffPtr pSaver; - DrawablePtr pDraw; - CARD32 lastInput; - ScreenSaverScreenPrivatePtr pPriv; - - REQUEST_SIZE_MATCH (xScreenSaverQueryInfoReq); + xScreenSaverQueryInfoReply rep; + int rc; + ScreenSaverStuffPtr pSaver; + DrawablePtr pDraw; + CARD32 lastInput; + ScreenSaverScreenPrivatePtr pPriv; + + REQUEST_SIZE_MATCH(xScreenSaverQueryInfoReq); rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, - DixGetAttrAccess); + DixGetAttrAccess); if (rc != Success) - return rc; + return rc; rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, pDraw->pScreen, - DixGetAttrAccess); + DixGetAttrAccess); if (rc != Success) - return rc; + return rc; pSaver = &pDraw->pScreen->screensaver; - pPriv = GetScreenPrivate (pDraw->pScreen); + pPriv = GetScreenPrivate(pDraw->pScreen); - UpdateCurrentTime (); - lastInput = GetTimeInMillis() - lastDeviceEventTime.milliseconds; + UpdateCurrentTime(); + lastInput = GetTimeInMillis() - lastDeviceEventTime[XIAllDevices].milliseconds; rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; rep.window = pSaver->wid; - if (screenIsSaved != SCREEN_SAVER_OFF) - { - rep.state = ScreenSaverOn; - if (ScreenSaverTime) - rep.tilOrSince = lastInput - ScreenSaverTime; - else - rep.tilOrSince = 0; + if (screenIsSaved != SCREEN_SAVER_OFF) { + rep.state = ScreenSaverOn; + if (ScreenSaverTime) + rep.tilOrSince = lastInput - ScreenSaverTime; + else + rep.tilOrSince = 0; } - else - { - if (ScreenSaverTime) - { - rep.state = ScreenSaverOff; - if (ScreenSaverTime < lastInput) - rep.tilOrSince = 0; - else - rep.tilOrSince = ScreenSaverTime - lastInput; - } - else - { - rep.state = ScreenSaverDisabled; - rep.tilOrSince = 0; - } + else { + if (ScreenSaverTime) { + rep.state = ScreenSaverOff; + if (ScreenSaverTime < lastInput) + rep.tilOrSince = 0; + else + rep.tilOrSince = ScreenSaverTime - lastInput; + } + else { + rep.state = ScreenSaverDisabled; + rep.tilOrSince = 0; + } } rep.idle = lastInput; - rep.eventMask = getEventMask (pDraw->pScreen, client); + rep.eventMask = getEventMask(pDraw->pScreen, client); if (pPriv && pPriv->attr) - rep.kind = ScreenSaverExternal; + rep.kind = ScreenSaverExternal; else if (ScreenSaverBlanking != DontPreferBlanking) - rep.kind = ScreenSaverBlanked; + rep.kind = ScreenSaverBlanked; else - rep.kind = ScreenSaverInternal; - if (client->swapped) - { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.window); - swapl(&rep.tilOrSince); - swapl(&rep.idle); - swapl(&rep.eventMask); + rep.kind = ScreenSaverInternal; + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.window); + swapl(&rep.tilOrSince); + swapl(&rep.idle); + swapl(&rep.eventMask); } - WriteToClient(client, sizeof (xScreenSaverQueryInfoReply), (char *)&rep); + WriteToClient(client, sizeof(xScreenSaverQueryInfoReply), (char *) &rep); return Success; } static int -ProcScreenSaverSelectInput (ClientPtr client) +ProcScreenSaverSelectInput(ClientPtr client) { REQUEST(xScreenSaverSelectInputReq); - DrawablePtr pDraw; - int rc; + DrawablePtr pDraw; + int rc; - REQUEST_SIZE_MATCH (xScreenSaverSelectInputReq); - rc = dixLookupDrawable (&pDraw, stuff->drawable, client, 0, - DixGetAttrAccess); + REQUEST_SIZE_MATCH(xScreenSaverSelectInputReq); + rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, + DixGetAttrAccess); if (rc != Success) - return rc; + return rc; rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, pDraw->pScreen, - DixSetAttrAccess); + DixSetAttrAccess); if (rc != Success) - return rc; + return rc; - if (!setEventMask (pDraw->pScreen, client, stuff->eventMask)) - return BadAlloc; + if (!setEventMask(pDraw->pScreen, client, stuff->eventMask)) + return BadAlloc; return Success; } static int -ScreenSaverSetAttributes (ClientPtr client) +ScreenSaverSetAttributes(ClientPtr client) { REQUEST(xScreenSaverSetAttributesReq); - DrawablePtr pDraw; - WindowPtr pParent; - ScreenPtr pScreen; + DrawablePtr pDraw; + WindowPtr pParent; + ScreenPtr pScreen; ScreenSaverScreenPrivatePtr pPriv = 0; - ScreenSaverAttrPtr pAttr = 0; - int ret, len, class, bw, depth; - unsigned long visual; - int idepth, ivisual; - Bool fOK; - DepthPtr pDepth; - WindowOptPtr ancwopt; - unsigned int *pVlist; - unsigned long *values = 0; - unsigned long tmask, imask; - unsigned long val; - Pixmap pixID; - PixmapPtr pPixmap; - Cursor cursorID; - CursorPtr pCursor; - Colormap cmap; - ColormapPtr pCmap; - - REQUEST_AT_LEAST_SIZE (xScreenSaverSetAttributesReq); + ScreenSaverAttrPtr pAttr = 0; + int ret, len, class, bw, depth; + unsigned long visual; + int idepth, ivisual; + Bool fOK; + DepthPtr pDepth; + WindowOptPtr ancwopt; + unsigned int *pVlist; + unsigned long *values = 0; + unsigned long tmask, imask; + unsigned long val; + Pixmap pixID; + PixmapPtr pPixmap; + Cursor cursorID; + CursorPtr pCursor; + Colormap cmap; + ColormapPtr pCmap; + + REQUEST_AT_LEAST_SIZE(xScreenSaverSetAttributesReq); ret = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, - DixGetAttrAccess); + DixGetAttrAccess); if (ret != Success) - return ret; + return ret; pScreen = pDraw->pScreen; pParent = pScreen->root; ret = XaceHook(XACE_SCREENSAVER_ACCESS, client, pScreen, DixSetAttrAccess); if (ret != Success) - return ret; + return ret; - len = stuff->length - bytes_to_int32(sizeof(xScreenSaverSetAttributesReq)); + len = stuff->length - bytes_to_int32(sizeof(xScreenSaverSetAttributesReq)); if (Ones(stuff->mask) != len) return BadLength; - if (!stuff->width || !stuff->height) - { - client->errorValue = 0; + if (!stuff->width || !stuff->height) { + client->errorValue = 0; return BadValue; } - switch (class = stuff->c_class) - { + switch (class = stuff->c_class) { case CopyFromParent: case InputOnly: case InputOutput: - break; + break; default: - client->errorValue = class; - return BadValue; + client->errorValue = class; + return BadValue; } bw = stuff->borderWidth; depth = stuff->depth; @@ -851,12 +811,11 @@ ScreenSaverSetAttributes (ClientPtr client) /* copied directly from CreateWindow */ if (class == CopyFromParent) - class = pParent->drawable.class; + class = pParent->drawable.class; - if ((class != InputOutput) && (class != InputOnly)) - { - client->errorValue = class; - return BadValue; + if ((class != InputOutput) && (class != InputOnly)) { + client->errorValue = class; + return BadValue; } if ((class != InputOnly) && (pParent->drawable.class == InputOnly)) @@ -869,73 +828,61 @@ ScreenSaverSetAttributes (ClientPtr client) depth = pParent->drawable.depth; ancwopt = pParent->optional; if (!ancwopt) - ancwopt = FindWindowWithOptional(pParent)->optional; + ancwopt = FindWindowWithOptional(pParent)->optional; if (visual == CopyFromParent) - visual = ancwopt->visual; + visual = ancwopt->visual; /* Find out if the depth and visual are acceptable for this Screen */ - if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth)) - { - fOK = FALSE; - for(idepth = 0; idepth < pScreen->numDepths; idepth++) - { - pDepth = (DepthPtr) &pScreen->allowedDepths[idepth]; - if ((depth == pDepth->depth) || (depth == 0)) - { - for (ivisual = 0; ivisual < pDepth->numVids; ivisual++) - { - if (visual == pDepth->vids[ivisual]) - { - fOK = TRUE; - break; - } - } - } - } - if (fOK == FALSE) - return BadMatch; + if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth)) { + fOK = FALSE; + for (idepth = 0; idepth < pScreen->numDepths; idepth++) { + pDepth = (DepthPtr) & pScreen->allowedDepths[idepth]; + if ((depth == pDepth->depth) || (depth == 0)) { + for (ivisual = 0; ivisual < pDepth->numVids; ivisual++) { + if (visual == pDepth->vids[ivisual]) { + fOK = TRUE; + break; + } + } + } + } + if (fOK == FALSE) + return BadMatch; } if (((stuff->mask & (CWBorderPixmap | CWBorderPixel)) == 0) && - (class != InputOnly) && - (depth != pParent->drawable.depth)) - { + (class != InputOnly) && (depth != pParent->drawable.depth)) { return BadMatch; } if (((stuff->mask & CWColormap) == 0) && - (class != InputOnly) && - ((visual != ancwopt->visual) || (ancwopt->colormap == None))) - { - return BadMatch; + (class != InputOnly) && + ((visual != ancwopt->visual) || (ancwopt->colormap == None))) { + return BadMatch; } /* end of errors from CreateWindow */ - pPriv = GetScreenPrivate (pScreen); - if (pPriv && pPriv->attr) - { - if (pPriv->attr->client != client) - return BadAccess; + pPriv = GetScreenPrivate(pScreen); + if (pPriv && pPriv->attr) { + if (pPriv->attr->client != client) + return BadAccess; } - if (!pPriv) - { - pPriv = MakeScreenPrivate (pScreen); - if (!pPriv) - return FALSE; + if (!pPriv) { + pPriv = MakeScreenPrivate(pScreen); + if (!pPriv) + return FALSE; } - pAttr = New (ScreenSaverAttrRec); - if (!pAttr) - { - ret = BadAlloc; - goto bail; + pAttr = New(ScreenSaverAttrRec); + if (!pAttr) { + ret = BadAlloc; + goto bail; } /* over allocate for override redirect */ - pAttr->values = values = malloc((len + 1) * sizeof (unsigned long)); - if (!values) - { - ret = BadAlloc; - goto bail; + pAttr->values = values = malloc((len + 1) * sizeof(unsigned long)); + if (!values) { + ret = BadAlloc; + goto bail; } pAttr->screen = pScreen; pAttr->client = client; @@ -959,318 +906,297 @@ ScreenSaverSetAttributes (ClientPtr client) pAttr->mask = tmask = stuff->mask | CWOverrideRedirect; pVlist = (unsigned int *) (stuff + 1); while (tmask) { - imask = lowbit (tmask); - tmask &= ~imask; - switch (imask) - { - case CWBackPixmap: - pixID = (Pixmap )*pVlist; - if (pixID == None) - { - *values++ = None; - } - else if (pixID == ParentRelative) - { - if (depth != pParent->drawable.depth) - { - ret = BadMatch; - goto PatchUp; - } - *values++ = ParentRelative; - } - else - { - ret = dixLookupResourceByType((pointer *)&pPixmap, pixID, RT_PIXMAP, - client, DixReadAccess); - if (ret == Success) - { - if ((pPixmap->drawable.depth != depth) || - (pPixmap->drawable.pScreen != pScreen)) - { + imask = lowbit(tmask); + tmask &= ~imask; + switch (imask) { + case CWBackPixmap: + pixID = (Pixmap) * pVlist; + if (pixID == None) { + *values++ = None; + } + else if (pixID == ParentRelative) { + if (depth != pParent->drawable.depth) { + ret = BadMatch; + goto PatchUp; + } + *values++ = ParentRelative; + } + else { + ret = + dixLookupResourceByType((pointer *) &pPixmap, pixID, + RT_PIXMAP, client, DixReadAccess); + if (ret == Success) { + if ((pPixmap->drawable.depth != depth) || + (pPixmap->drawable.pScreen != pScreen)) { + ret = BadMatch; + goto PatchUp; + } + pAttr->pBackgroundPixmap = pPixmap; + pPixmap->refcnt++; + pAttr->mask &= ~CWBackPixmap; + } + else { + client->errorValue = pixID; + goto PatchUp; + } + } + break; + case CWBackPixel: + *values++ = (CARD32) *pVlist; + break; + case CWBorderPixmap: + pixID = (Pixmap) * pVlist; + if (pixID == CopyFromParent) { + if (depth != pParent->drawable.depth) { + ret = BadMatch; + goto PatchUp; + } + *values++ = CopyFromParent; + } + else { + ret = + dixLookupResourceByType((pointer *) &pPixmap, pixID, + RT_PIXMAP, client, DixReadAccess); + if (ret == Success) { + if ((pPixmap->drawable.depth != depth) || + (pPixmap->drawable.pScreen != pScreen)) { ret = BadMatch; - goto PatchUp; - } - pAttr->pBackgroundPixmap = pPixmap; - pPixmap->refcnt++; - pAttr->mask &= ~CWBackPixmap; - } - else - { - client->errorValue = pixID; - goto PatchUp; - } - } - break; - case CWBackPixel: - *values++ = (CARD32) *pVlist; - break; - case CWBorderPixmap: - pixID = (Pixmap ) *pVlist; - if (pixID == CopyFromParent) - { - if (depth != pParent->drawable.depth) - { - ret = BadMatch; - goto PatchUp; - } - *values++ = CopyFromParent; - } - else - { - ret = dixLookupResourceByType((pointer *)&pPixmap, pixID, RT_PIXMAP, - client, DixReadAccess); - if (ret == Success) - { - if ((pPixmap->drawable.depth != depth) || - (pPixmap->drawable.pScreen != pScreen)) - { - ret = BadMatch; - goto PatchUp; - } - pAttr->pBorderPixmap = pPixmap; - pPixmap->refcnt++; - pAttr->mask &= ~CWBorderPixmap; - } - else - { - client->errorValue = pixID; - goto PatchUp; - } - } - break; - case CWBorderPixel: + goto PatchUp; + } + pAttr->pBorderPixmap = pPixmap; + pPixmap->refcnt++; + pAttr->mask &= ~CWBorderPixmap; + } + else { + client->errorValue = pixID; + goto PatchUp; + } + } + break; + case CWBorderPixel: + *values++ = (CARD32) *pVlist; + break; + case CWBitGravity: + val = (CARD8) *pVlist; + if (val > StaticGravity) { + ret = BadValue; + client->errorValue = val; + goto PatchUp; + } + *values++ = val; + break; + case CWWinGravity: + val = (CARD8) *pVlist; + if (val > StaticGravity) { + ret = BadValue; + client->errorValue = val; + goto PatchUp; + } + *values++ = val; + break; + case CWBackingStore: + val = (CARD8) *pVlist; + if ((val != NotUseful) && (val != WhenMapped) && (val != Always)) { + ret = BadValue; + client->errorValue = val; + goto PatchUp; + } + *values++ = val; + break; + case CWBackingPlanes: *values++ = (CARD32) *pVlist; break; - case CWBitGravity: - val = (CARD8 )*pVlist; - if (val > StaticGravity) - { - ret = BadValue; - client->errorValue = val; - goto PatchUp; - } - *values++ = val; - break; - case CWWinGravity: - val = (CARD8 )*pVlist; - if (val > StaticGravity) - { - ret = BadValue; - client->errorValue = val; - goto PatchUp; - } - *values++ = val; - break; - case CWBackingStore: - val = (CARD8 )*pVlist; - if ((val != NotUseful) && (val != WhenMapped) && (val != Always)) - { - ret = BadValue; - client->errorValue = val; - goto PatchUp; - } - *values++ = val; - break; - case CWBackingPlanes: - *values++ = (CARD32) *pVlist; - break; - case CWBackingPixel: - *values++ = (CARD32) *pVlist; - break; - case CWSaveUnder: - val = (BOOL) *pVlist; - if ((val != xTrue) && (val != xFalse)) - { - ret = BadValue; - client->errorValue = val; - goto PatchUp; - } - *values++ = val; - break; - case CWEventMask: - *values++ = (CARD32) *pVlist; - break; - case CWDontPropagate: - *values++ = (CARD32) *pVlist; - break; - case CWOverrideRedirect: - if (!(stuff->mask & CWOverrideRedirect)) - pVlist--; - else - { - val = (BOOL ) *pVlist; - if ((val != xTrue) && (val != xFalse)) - { - ret = BadValue; - client->errorValue = val; - goto PatchUp; - } - } - *values++ = xTrue; - break; - case CWColormap: - cmap = (Colormap) *pVlist; - ret = dixLookupResourceByType((pointer *)&pCmap, cmap, RT_COLORMAP, - client, DixUseAccess); - if (ret != Success) - { - client->errorValue = cmap; - goto PatchUp; - } - if (pCmap->pVisual->vid != visual || pCmap->pScreen != pScreen) - { - ret = BadMatch; - goto PatchUp; - } - pAttr->colormap = cmap; - pAttr->mask &= ~CWColormap; - break; - case CWCursor: - cursorID = (Cursor ) *pVlist; - if ( cursorID == None) - { - *values++ = None; - } - else - { - ret = dixLookupResourceByType((pointer *)&pCursor, cursorID, - RT_CURSOR, client, DixUseAccess); - if (ret != Success) - { - client->errorValue = cursorID; - goto PatchUp; - } - pCursor->refcnt++; - pAttr->pCursor = pCursor; - pAttr->mask &= ~CWCursor; - } - break; - default: - ret = BadValue; - client->errorValue = stuff->mask; - goto PatchUp; - } - pVlist++; + case CWBackingPixel: + *values++ = (CARD32) *pVlist; + break; + case CWSaveUnder: + val = (BOOL) * pVlist; + if ((val != xTrue) && (val != xFalse)) { + ret = BadValue; + client->errorValue = val; + goto PatchUp; + } + *values++ = val; + break; + case CWEventMask: + *values++ = (CARD32) *pVlist; + break; + case CWDontPropagate: + *values++ = (CARD32) *pVlist; + break; + case CWOverrideRedirect: + if (!(stuff->mask & CWOverrideRedirect)) + pVlist--; + else { + val = (BOOL) * pVlist; + if ((val != xTrue) && (val != xFalse)) { + ret = BadValue; + client->errorValue = val; + goto PatchUp; + } + } + *values++ = xTrue; + break; + case CWColormap: + cmap = (Colormap) * pVlist; + ret = dixLookupResourceByType((pointer *) &pCmap, cmap, RT_COLORMAP, + client, DixUseAccess); + if (ret != Success) { + client->errorValue = cmap; + goto PatchUp; + } + if (pCmap->pVisual->vid != visual || pCmap->pScreen != pScreen) { + ret = BadMatch; + goto PatchUp; + } + pAttr->colormap = cmap; + pAttr->mask &= ~CWColormap; + break; + case CWCursor: + cursorID = (Cursor) * pVlist; + if (cursorID == None) { + *values++ = None; + } + else { + ret = dixLookupResourceByType((pointer *) &pCursor, cursorID, + RT_CURSOR, client, DixUseAccess); + if (ret != Success) { + client->errorValue = cursorID; + goto PatchUp; + } + pCursor->refcnt++; + pAttr->pCursor = pCursor; + pAttr->mask &= ~CWCursor; + } + break; + default: + ret = BadValue; + client->errorValue = stuff->mask; + goto PatchUp; + } + pVlist++; } if (pPriv->attr) - FreeScreenAttr (pPriv->attr); + FreeScreenAttr(pPriv->attr); pPriv->attr = pAttr; - pAttr->resource = FakeClientID (client->index); - if (!AddResource (pAttr->resource, AttrType, (pointer) pAttr)) - return BadAlloc; + pAttr->resource = FakeClientID(client->index); + if (!AddResource(pAttr->resource, AttrType, (pointer) pAttr)) + return BadAlloc; return Success; -PatchUp: - FreeAttrs (pAttr); -bail: - CheckScreenPrivate (pScreen); - if (pAttr) free(pAttr->values); + PatchUp: + FreeAttrs(pAttr); + bail: + CheckScreenPrivate(pScreen); + if (pAttr) + free(pAttr->values); free(pAttr); return ret; } static int -ScreenSaverUnsetAttributes (ClientPtr client) +ScreenSaverUnsetAttributes(ClientPtr client) { REQUEST(xScreenSaverSetAttributesReq); - DrawablePtr pDraw; - ScreenSaverScreenPrivatePtr pPriv; - int rc; + DrawablePtr pDraw; + ScreenSaverScreenPrivatePtr pPriv; + int rc; - REQUEST_SIZE_MATCH (xScreenSaverUnsetAttributesReq); + REQUEST_SIZE_MATCH(xScreenSaverUnsetAttributesReq); rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, - DixGetAttrAccess); + DixGetAttrAccess); if (rc != Success) - return rc; - pPriv = GetScreenPrivate (pDraw->pScreen); - if (pPriv && pPriv->attr && pPriv->attr->client == client) - { - FreeResource (pPriv->attr->resource, AttrType); - FreeScreenAttr (pPriv->attr); - pPriv->attr = NULL; - CheckScreenPrivate (pDraw->pScreen); + return rc; + pPriv = GetScreenPrivate(pDraw->pScreen); + if (pPriv && pPriv->attr && pPriv->attr->client == client) { + FreeResource(pPriv->attr->resource, AttrType); + FreeScreenAttr(pPriv->attr); + pPriv->attr = NULL; + CheckScreenPrivate(pDraw->pScreen); } return Success; } static int -ProcScreenSaverSetAttributes (ClientPtr client) +ProcScreenSaverSetAttributes(ClientPtr client) { #ifdef PANORAMIX - if(!noPanoramiXExtension) { - REQUEST(xScreenSaverSetAttributesReq); - PanoramiXRes *draw; - PanoramiXRes *backPix = NULL; - PanoramiXRes *bordPix = NULL; - PanoramiXRes *cmap = NULL; - int i, status, len; - int pback_offset = 0, pbord_offset = 0, cmap_offset = 0; - XID orig_visual, tmp; - - REQUEST_AT_LEAST_SIZE (xScreenSaverSetAttributesReq); - - status = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); - if (status != Success) - return (status == BadValue) ? BadDrawable : status; - - len = stuff->length - bytes_to_int32(sizeof(xScreenSaverSetAttributesReq)); - if (Ones(stuff->mask) != len) - return BadLength; - - if((Mask)stuff->mask & CWBackPixmap) { - pback_offset = Ones((Mask)stuff->mask & (CWBackPixmap - 1)); - tmp = *((CARD32 *) &stuff[1] + pback_offset); - if ((tmp != None) && (tmp != ParentRelative)) { - status = dixLookupResourceByType((pointer *)&backPix, tmp, - XRT_PIXMAP, client, - DixReadAccess); - if (status != Success) - return status; - } - } - - if ((Mask)stuff->mask & CWBorderPixmap) { - pbord_offset = Ones((Mask)stuff->mask & (CWBorderPixmap - 1)); - tmp = *((CARD32 *) &stuff[1] + pbord_offset); - if (tmp != CopyFromParent) { - status = dixLookupResourceByType((pointer *)&bordPix, tmp, - XRT_PIXMAP, client, - DixReadAccess); - if (status != Success) - return status; - } - } - - if ((Mask)stuff->mask & CWColormap) { - cmap_offset = Ones((Mask)stuff->mask & (CWColormap - 1)); - tmp = *((CARD32 *) &stuff[1] + cmap_offset); - if ((tmp != CopyFromParent) && (tmp != None)) { - status = dixLookupResourceByType((pointer *)&cmap, tmp, - XRT_COLORMAP, client, - DixReadAccess); - if (status != Success) - return status; - } - } - - orig_visual = stuff->visualID; - - FOR_NSCREENS_BACKWARD(i) { - stuff->drawable = draw->info[i].id; - if (backPix) - *((CARD32 *) &stuff[1] + pback_offset) = backPix->info[i].id; - if (bordPix) - *((CARD32 *) &stuff[1] + pbord_offset) = bordPix->info[i].id; - if (cmap) - *((CARD32 *) &stuff[1] + cmap_offset) = cmap->info[i].id; - - if (orig_visual != CopyFromParent) - stuff->visualID = PanoramiXTranslateVisualID(i, orig_visual); - - status = ScreenSaverSetAttributes(client); - } - - return status; + if (!noPanoramiXExtension) { + REQUEST(xScreenSaverSetAttributesReq); + PanoramiXRes *draw; + PanoramiXRes *backPix = NULL; + PanoramiXRes *bordPix = NULL; + PanoramiXRes *cmap = NULL; + int i, status, len; + int pback_offset = 0, pbord_offset = 0, cmap_offset = 0; + XID orig_visual, tmp; + + REQUEST_AT_LEAST_SIZE(xScreenSaverSetAttributesReq); + + status = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); + if (status != Success) + return (status == BadValue) ? BadDrawable : status; + + len = + stuff->length - + bytes_to_int32(sizeof(xScreenSaverSetAttributesReq)); + if (Ones(stuff->mask) != len) + return BadLength; + + if ((Mask) stuff->mask & CWBackPixmap) { + pback_offset = Ones((Mask) stuff->mask & (CWBackPixmap - 1)); + tmp = *((CARD32 *) &stuff[1] + pback_offset); + if ((tmp != None) && (tmp != ParentRelative)) { + status = dixLookupResourceByType((pointer *) &backPix, tmp, + XRT_PIXMAP, client, + DixReadAccess); + if (status != Success) + return status; + } + } + + if ((Mask) stuff->mask & CWBorderPixmap) { + pbord_offset = Ones((Mask) stuff->mask & (CWBorderPixmap - 1)); + tmp = *((CARD32 *) &stuff[1] + pbord_offset); + if (tmp != CopyFromParent) { + status = dixLookupResourceByType((pointer *) &bordPix, tmp, + XRT_PIXMAP, client, + DixReadAccess); + if (status != Success) + return status; + } + } + + if ((Mask) stuff->mask & CWColormap) { + cmap_offset = Ones((Mask) stuff->mask & (CWColormap - 1)); + tmp = *((CARD32 *) &stuff[1] + cmap_offset); + if ((tmp != CopyFromParent) && (tmp != None)) { + status = dixLookupResourceByType((pointer *) &cmap, tmp, + XRT_COLORMAP, client, + DixReadAccess); + if (status != Success) + return status; + } + } + + orig_visual = stuff->visualID; + + FOR_NSCREENS_BACKWARD(i) { + stuff->drawable = draw->info[i].id; + if (backPix) + *((CARD32 *) &stuff[1] + pback_offset) = backPix->info[i].id; + if (bordPix) + *((CARD32 *) &stuff[1] + pbord_offset) = bordPix->info[i].id; + if (cmap) + *((CARD32 *) &stuff[1] + cmap_offset) = cmap->info[i].id; + + if (orig_visual != CopyFromParent) + stuff->visualID = PanoramiXTranslateVisualID(i, orig_visual); + + status = ScreenSaverSetAttributes(client); + } + + return status; } #endif @@ -1278,25 +1204,25 @@ ProcScreenSaverSetAttributes (ClientPtr client) } static int -ProcScreenSaverUnsetAttributes (ClientPtr client) +ProcScreenSaverUnsetAttributes(ClientPtr client) { #ifdef PANORAMIX - if(!noPanoramiXExtension) { - REQUEST(xScreenSaverUnsetAttributesReq); - PanoramiXRes *draw; - int rc, i; + if (!noPanoramiXExtension) { + REQUEST(xScreenSaverUnsetAttributesReq); + PanoramiXRes *draw; + int rc, i; - rc = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); - if (rc != Success) - return (rc == BadValue) ? BadDrawable : rc; + rc = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); + if (rc != Success) + return (rc == BadValue) ? BadDrawable : rc; - for(i = PanoramiXNumScreens - 1; i > 0; i--) { + for (i = PanoramiXNumScreens - 1; i > 0; i--) { stuff->drawable = draw->info[i].id; ScreenSaverUnsetAttributes(client); - } + } - stuff->drawable = draw->info[0].id; + stuff->drawable = draw->info[0].id; } #endif @@ -1304,7 +1230,7 @@ ProcScreenSaverUnsetAttributes (ClientPtr client) } static int -ProcScreenSaverSuspend (ClientPtr client) +ProcScreenSaverSuspend(ClientPtr client) { ScreenSaverSuspensionPtr *prev, this; @@ -1313,22 +1239,21 @@ ProcScreenSaverSuspend (ClientPtr client) /* Check if this client is suspending the screensaver */ for (prev = &suspendingClients; (this = *prev); prev = &this->next) - if (this->pClient == client) - break; + if (this->pClient == client) + break; - if (this) - { - if (stuff->suspend == TRUE) - this->count++; - else if (--this->count == 0) - FreeResource (this->clientResource, RT_NONE); + if (this) { + if (stuff->suspend == TRUE) + this->count++; + else if (--this->count == 0) + FreeResource(this->clientResource, RT_NONE); - return Success; + return Success; } /* If we get to this point, this client isn't suspending the screensaver */ if (stuff->suspend == FALSE) - return Success; + return Success; /* * Allocate a suspension record for the client, and stop the screensaver @@ -1336,85 +1261,81 @@ ProcScreenSaverSuspend (ClientPtr client) * to the record, so the screensaver will be reenabled and the record freed * if the client disconnects without reenabling it first. */ - this = malloc(sizeof (ScreenSaverSuspensionRec)); + this = malloc(sizeof(ScreenSaverSuspensionRec)); if (!this) - return BadAlloc; + return BadAlloc; - this->next = NULL; - this->pClient = client; - this->count = 1; - this->clientResource = FakeClientID (client->index); + this->next = NULL; + this->pClient = client; + this->count = 1; + this->clientResource = FakeClientID(client->index); - if (!AddResource (this->clientResource, SuspendType, (pointer) this)) - { - free(this); - return BadAlloc; + if (!AddResource(this->clientResource, SuspendType, (pointer) this)) { + free(this); + return BadAlloc; } *prev = this; - if (!screenSaverSuspended) - { - screenSaverSuspended = TRUE; - FreeScreenSaverTimer(); + if (!screenSaverSuspended) { + screenSaverSuspended = TRUE; + FreeScreenSaverTimer(); } return Success; } -static int (*NormalVector[]) (ClientPtr /* client */) = { - ProcScreenSaverQueryVersion, - ProcScreenSaverQueryInfo, - ProcScreenSaverSelectInput, - ProcScreenSaverSetAttributes, - ProcScreenSaverUnsetAttributes, - ProcScreenSaverSuspend, -}; +static int (*NormalVector[]) (ClientPtr /* client */ ) = { +ProcScreenSaverQueryVersion, + ProcScreenSaverQueryInfo, + ProcScreenSaverSelectInput, + ProcScreenSaverSetAttributes, + ProcScreenSaverUnsetAttributes, ProcScreenSaverSuspend,}; #define NUM_REQUESTS ((sizeof NormalVector) / (sizeof NormalVector[0])) static int -ProcScreenSaverDispatch (ClientPtr client) +ProcScreenSaverDispatch(ClientPtr client) { REQUEST(xReq); if (stuff->data < NUM_REQUESTS) - return (*NormalVector[stuff->data])(client); + return (*NormalVector[stuff->data]) (client); return BadRequest; } static int -SProcScreenSaverQueryVersion (ClientPtr client) +SProcScreenSaverQueryVersion(ClientPtr client) { REQUEST(xScreenSaverQueryVersionReq); swaps(&stuff->length); REQUEST_SIZE_MATCH(xScreenSaverQueryVersionReq); - return ProcScreenSaverQueryVersion (client); + return ProcScreenSaverQueryVersion(client); } static int -SProcScreenSaverQueryInfo (ClientPtr client) +SProcScreenSaverQueryInfo(ClientPtr client) { REQUEST(xScreenSaverQueryInfoReq); swaps(&stuff->length); REQUEST_SIZE_MATCH(xScreenSaverQueryInfoReq); swapl(&stuff->drawable); - return ProcScreenSaverQueryInfo (client); + return ProcScreenSaverQueryInfo(client); } static int -SProcScreenSaverSelectInput (ClientPtr client) +SProcScreenSaverSelectInput(ClientPtr client) { REQUEST(xScreenSaverSelectInputReq); swaps(&stuff->length); REQUEST_SIZE_MATCH(xScreenSaverSelectInputReq); swapl(&stuff->drawable); swapl(&stuff->eventMask); - return ProcScreenSaverSelectInput (client); + return ProcScreenSaverSelectInput(client); } static int -SProcScreenSaverSetAttributes (ClientPtr client) +SProcScreenSaverSetAttributes(ClientPtr client) { REQUEST(xScreenSaverSetAttributesReq); swaps(&stuff->length); @@ -1428,45 +1349,43 @@ SProcScreenSaverSetAttributes (ClientPtr client) swapl(&stuff->visualID); swapl(&stuff->mask); SwapRestL(stuff); - return ProcScreenSaverSetAttributes (client); + return ProcScreenSaverSetAttributes(client); } static int -SProcScreenSaverUnsetAttributes (ClientPtr client) +SProcScreenSaverUnsetAttributes(ClientPtr client) { REQUEST(xScreenSaverUnsetAttributesReq); swaps(&stuff->length); REQUEST_SIZE_MATCH(xScreenSaverUnsetAttributesReq); swapl(&stuff->drawable); - return ProcScreenSaverUnsetAttributes (client); + return ProcScreenSaverUnsetAttributes(client); } static int -SProcScreenSaverSuspend (ClientPtr client) +SProcScreenSaverSuspend(ClientPtr client) { REQUEST(xScreenSaverSuspendReq); swaps(&stuff->length); REQUEST_SIZE_MATCH(xScreenSaverSuspendReq); - return ProcScreenSaverSuspend (client); + return ProcScreenSaverSuspend(client); } -static int (*SwappedVector[]) (ClientPtr /* client */) = { - SProcScreenSaverQueryVersion, - SProcScreenSaverQueryInfo, - SProcScreenSaverSelectInput, - SProcScreenSaverSetAttributes, - SProcScreenSaverUnsetAttributes, - SProcScreenSaverSuspend, -}; +static int (*SwappedVector[]) (ClientPtr /* client */ ) = { +SProcScreenSaverQueryVersion, + SProcScreenSaverQueryInfo, + SProcScreenSaverSelectInput, + SProcScreenSaverSetAttributes, + SProcScreenSaverUnsetAttributes, SProcScreenSaverSuspend,}; static int -SProcScreenSaverDispatch (ClientPtr client) +SProcScreenSaverDispatch(ClientPtr client) { REQUEST(xReq); if (stuff->data < NUM_REQUESTS) - return (*SwappedVector[stuff->data])(client); + return (*SwappedVector[stuff->data]) (client); return BadRequest; } @@ -1474,29 +1393,27 @@ void ScreenSaverExtensionInit(INITARGS) { ExtensionEntry *extEntry; - int i; - ScreenPtr pScreen; + int i; + ScreenPtr pScreen; if (!dixRegisterPrivateKey(&ScreenPrivateKeyRec, PRIVATE_SCREEN, 0)) - return; + return; AttrType = CreateNewResourceType(ScreenSaverFreeAttr, "SaverAttr"); - SaverEventType = CreateNewResourceType(ScreenSaverFreeEvents, - "SaverEvent"); - SuspendType = CreateNewResourceType(ScreenSaverFreeSuspend, - "SaverSuspend"); - - for (i = 0; i < screenInfo.numScreens; i++) - { - pScreen = screenInfo.screens[i]; - SetScreenPrivate (pScreen, NULL); + SaverEventType = CreateNewResourceType(ScreenSaverFreeEvents, "SaverEvent"); + SuspendType = CreateNewResourceType(ScreenSaverFreeSuspend, "SaverSuspend"); + + for (i = 0; i < screenInfo.numScreens; i++) { + pScreen = screenInfo.screens[i]; + SetScreenPrivate(pScreen, NULL); } if (AttrType && SaverEventType && SuspendType && - (extEntry = AddExtension(ScreenSaverName, ScreenSaverNumberEvents, 0, - ProcScreenSaverDispatch, SProcScreenSaverDispatch, - NULL, StandardMinorOpcode))) - { - ScreenSaverEventBase = extEntry->eventBase; - EventSwapVector[ScreenSaverEventBase] = (EventSwapPtr) SScreenSaverNotifyEvent; + (extEntry = AddExtension(ScreenSaverName, ScreenSaverNumberEvents, 0, + ProcScreenSaverDispatch, + SProcScreenSaverDispatch, NULL, + StandardMinorOpcode))) { + ScreenSaverEventBase = extEntry->eventBase; + EventSwapVector[ScreenSaverEventBase] = + (EventSwapPtr) SScreenSaverNotifyEvent; } } diff --git a/xorg-server/Xext/security.c b/xorg-server/Xext/security.c index bc2930ce7..1e0bfefb9 100644 --- a/xorg-server/Xext/security.c +++ b/xorg-server/Xext/security.c @@ -44,16 +44,17 @@ in this Software without prior written authorization from The Open Group. #include "protocol-versions.h" /* Extension stuff */ -static int SecurityErrorBase; /* first Security error number */ -static int SecurityEventBase; /* first Security event number */ +static int SecurityErrorBase; /* first Security error number */ +static int SecurityEventBase; /* first Security event number */ -RESTYPE SecurityAuthorizationResType; /* resource type for authorizations */ +RESTYPE SecurityAuthorizationResType; /* resource type for authorizations */ static RESTYPE RTEventClient; static CallbackListPtr SecurityValidateGroupCallback = NULL; /* Private state record */ static DevPrivateKeyRec stateKeyRec; + #define stateKey (&stateKeyRec) /* This is what we store as client security state */ @@ -86,7 +87,6 @@ static const Mask SecurityDeviceMask = static const Mask SecurityServerMask = DixGetAttrAccess | DixGrabAccess; static const Mask SecurityClientMask = DixGetAttrAccess; - /* SecurityAudit * * Arguments: @@ -99,33 +99,34 @@ static const Mask SecurityClientMask = DixGetAttrAccess; * Writes the message to the log file if security logging is on. */ -static void _X_ATTRIBUTE_PRINTF(1,2) +static void +_X_ATTRIBUTE_PRINTF(1, 2) SecurityAudit(const char *format, ...) { va_list args; if (auditTrailLevel < SECURITY_AUDIT_LEVEL) - return; + return; va_start(args, format); VAuditF(format, args); va_end(args); -} /* SecurityAudit */ +} /* SecurityAudit */ /* * Performs a Security permission check. */ static int -SecurityDoCheck(SecurityStateRec *subj, SecurityStateRec *obj, - Mask requested, Mask allowed) +SecurityDoCheck(SecurityStateRec * subj, SecurityStateRec * obj, + Mask requested, Mask allowed) { if (!subj->haveState || !obj->haveState) - return Success; + return Success; if (subj->trustLevel == XSecurityClientTrusted) - return Success; + return Success; if (obj->trustLevel != XSecurityClientTrusted) - return Success; + return Success; if ((requested | allowed) == allowed) - return Success; + return Success; return BadAccess; } @@ -153,7 +154,6 @@ SecurityLookupRequestName(ClientPtr client) return LookupRequestName(client->majorOp, client->minorOp); } - /* SecurityDeleteAuthorization * * Arguments: @@ -167,11 +167,9 @@ SecurityLookupRequestName(ClientPtr client) */ static int -SecurityDeleteAuthorization( - pointer value, - XID id) +SecurityDeleteAuthorization(pointer value, XID id) { - SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)value; + SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr) value; unsigned short name_len, data_len; const char *name; char *data; @@ -181,74 +179,67 @@ SecurityDeleteAuthorization( /* Remove the auth using the os layer auth manager */ - status = AuthorizationFromID(pAuth->id, &name_len, &name, - &data_len, &data); + status = AuthorizationFromID(pAuth->id, &name_len, &name, &data_len, &data); assert(status); status = RemoveAuthorization(name_len, name, data_len, data); assert(status); - (void)status; + (void) status; /* free the auth timer if there is one */ - if (pAuth->timer) TimerFree(pAuth->timer); + if (pAuth->timer) + TimerFree(pAuth->timer); /* send revoke events */ - while ((pEventClient = pAuth->eventClients)) - { - /* send revocation event event */ - xSecurityAuthorizationRevokedEvent are; - are.type = SecurityEventBase + XSecurityAuthorizationRevoked; - are.authId = pAuth->id; - WriteEventsToClient(rClient(pEventClient), 1, (xEvent *)&are); - FreeResource(pEventClient->resource, RT_NONE); + while ((pEventClient = pAuth->eventClients)) { + /* send revocation event event */ + xSecurityAuthorizationRevokedEvent are; + + are.type = SecurityEventBase + XSecurityAuthorizationRevoked; + are.authId = pAuth->id; + WriteEventsToClient(rClient(pEventClient), 1, (xEvent *) &are); + FreeResource(pEventClient->resource, RT_NONE); } /* kill all clients using this auth */ - for (i = 1; i<currentMaxClients; i++) - if (clients[i]) { - SecurityStateRec *state; - state = dixLookupPrivate(&clients[i]->devPrivates, stateKey); - if (state->haveState && state->authId == pAuth->id) - CloseDownClient(clients[i]); - } + for (i = 1; i < currentMaxClients; i++) + if (clients[i]) { + SecurityStateRec *state; + + state = dixLookupPrivate(&clients[i]->devPrivates, stateKey); + if (state->haveState && state->authId == pAuth->id) + CloseDownClient(clients[i]); + } SecurityAudit("revoked authorization ID %d\n", pAuth->id); free(pAuth); return Success; -} /* SecurityDeleteAuthorization */ - +} /* SecurityDeleteAuthorization */ /* resource delete function for RTEventClient */ static int -SecurityDeleteAuthorizationEventClient( - pointer value, - XID id) +SecurityDeleteAuthorizationEventClient(pointer value, XID id) { OtherClientsPtr pEventClient, prev = NULL; - SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)value; + SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr) value; for (pEventClient = pAuth->eventClients; - pEventClient; - pEventClient = pEventClient->next) - { - if (pEventClient->resource == id) - { - if (prev) - prev->next = pEventClient->next; - else - pAuth->eventClients = pEventClient->next; - free(pEventClient); - return Success; - } - prev = pEventClient; + pEventClient; pEventClient = pEventClient->next) { + if (pEventClient->resource == id) { + if (prev) + prev->next = pEventClient->next; + else + pAuth->eventClients = pEventClient->next; + free(pEventClient); + return Success; + } + prev = pEventClient; } - /*NOTREACHED*/ - return -1; /* make compiler happy */ -} /* SecurityDeleteAuthorizationEventClient */ - + /*NOTREACHED*/ return -1; /* make compiler happy */ +} /* SecurityDeleteAuthorizationEventClient */ /* SecurityComputeAuthorizationTimeout * @@ -265,26 +256,23 @@ SecurityDeleteAuthorizationEventClient( */ static CARD32 -SecurityComputeAuthorizationTimeout( - SecurityAuthorizationPtr pAuth, - unsigned int seconds) +SecurityComputeAuthorizationTimeout(SecurityAuthorizationPtr pAuth, + unsigned int seconds) { /* maxSecs is the number of full seconds that can be expressed in * 32 bits worth of milliseconds */ - CARD32 maxSecs = (CARD32)(~0) / (CARD32)MILLI_PER_SECOND; + CARD32 maxSecs = (CARD32) (~0) / (CARD32) MILLI_PER_SECOND; - if (seconds > maxSecs) - { /* only come here if we want to wait more than 49 days */ - pAuth->secondsRemaining = seconds - maxSecs; - return maxSecs * MILLI_PER_SECOND; + if (seconds > maxSecs) { /* only come here if we want to wait more than 49 days */ + pAuth->secondsRemaining = seconds - maxSecs; + return maxSecs * MILLI_PER_SECOND; } - else - { /* by far the common case */ - pAuth->secondsRemaining = 0; - return seconds * MILLI_PER_SECOND; + else { /* by far the common case */ + pAuth->secondsRemaining = 0; + return seconds * MILLI_PER_SECOND; } -} /* SecurityStartAuthorizationTimer */ +} /* SecurityStartAuthorizationTimer */ /* SecurityAuthorizationExpired * @@ -306,26 +294,21 @@ SecurityComputeAuthorizationTimeout( */ static CARD32 -SecurityAuthorizationExpired( - OsTimerPtr timer, - CARD32 time, - pointer pval) +SecurityAuthorizationExpired(OsTimerPtr timer, CARD32 time, pointer pval) { - SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)pval; + SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr) pval; assert(pAuth->timer == timer); - if (pAuth->secondsRemaining) - { - return SecurityComputeAuthorizationTimeout(pAuth, - pAuth->secondsRemaining); + if (pAuth->secondsRemaining) { + return SecurityComputeAuthorizationTimeout(pAuth, + pAuth->secondsRemaining); } - else - { - FreeResource(pAuth->id, RT_NONE); - return 0; + else { + FreeResource(pAuth->id, RT_NONE); + return 0; } -} /* SecurityAuthorizationExpired */ +} /* SecurityAuthorizationExpired */ /* SecurityStartAuthorizationTimer * @@ -341,104 +324,91 @@ SecurityAuthorizationExpired( */ static void -SecurityStartAuthorizationTimer( - SecurityAuthorizationPtr pAuth) +SecurityStartAuthorizationTimer(SecurityAuthorizationPtr pAuth) { pAuth->timer = TimerSet(pAuth->timer, 0, - SecurityComputeAuthorizationTimeout(pAuth, pAuth->timeout), - SecurityAuthorizationExpired, pAuth); -} /* SecurityStartAuthorizationTimer */ - + SecurityComputeAuthorizationTimeout(pAuth, + pAuth->timeout), + SecurityAuthorizationExpired, pAuth); +} /* SecurityStartAuthorizationTimer */ /* Proc functions all take a client argument, execute the request in * client->requestBuffer, and return a protocol error status. */ static int -ProcSecurityQueryVersion( - ClientPtr client) +ProcSecurityQueryVersion(ClientPtr client) { /* REQUEST(xSecurityQueryVersionReq); */ - xSecurityQueryVersionReply rep; + xSecurityQueryVersionReply rep; REQUEST_SIZE_MATCH(xSecurityQueryVersionReq); - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.majorVersion = SERVER_SECURITY_MAJOR_VERSION; - rep.minorVersion = SERVER_SECURITY_MINOR_VERSION; - if(client->swapped) - { - swaps(&rep.sequenceNumber); - swaps(&rep.majorVersion); - swaps(&rep.minorVersion); + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.length = 0; + rep.majorVersion = SERVER_SECURITY_MAJOR_VERSION; + rep.minorVersion = SERVER_SECURITY_MINOR_VERSION; + if (client->swapped) { + swaps(&rep.sequenceNumber); + swaps(&rep.majorVersion); + swaps(&rep.minorVersion); } - (void)WriteToClient(client, SIZEOF(xSecurityQueryVersionReply), - (char *)&rep); + (void) WriteToClient(client, SIZEOF(xSecurityQueryVersionReply), + (char *) &rep); return Success; -} /* ProcSecurityQueryVersion */ - +} /* ProcSecurityQueryVersion */ static int -SecurityEventSelectForAuthorization( - SecurityAuthorizationPtr pAuth, - ClientPtr client, - Mask mask) +SecurityEventSelectForAuthorization(SecurityAuthorizationPtr pAuth, + ClientPtr client, Mask mask) { OtherClients *pEventClient; for (pEventClient = pAuth->eventClients; - pEventClient; - pEventClient = pEventClient->next) - { - if (SameClient(pEventClient, client)) - { - if (mask == 0) - FreeResource(pEventClient->resource, RT_NONE); - else - pEventClient->mask = mask; - return Success; - } + pEventClient; pEventClient = pEventClient->next) { + if (SameClient(pEventClient, client)) { + if (mask == 0) + FreeResource(pEventClient->resource, RT_NONE); + else + pEventClient->mask = mask; + return Success; + } } - + pEventClient = malloc(sizeof(OtherClients)); if (!pEventClient) - return BadAlloc; + return BadAlloc; pEventClient->mask = mask; pEventClient->resource = FakeClientID(client->index); pEventClient->next = pAuth->eventClients; - if (!AddResource(pEventClient->resource, RTEventClient, - (pointer)pAuth)) - { - free(pEventClient); - return BadAlloc; + if (!AddResource(pEventClient->resource, RTEventClient, (pointer) pAuth)) { + free(pEventClient); + return BadAlloc; } pAuth->eventClients = pEventClient; return Success; -} /* SecurityEventSelectForAuthorization */ - +} /* SecurityEventSelectForAuthorization */ static int -ProcSecurityGenerateAuthorization( - ClientPtr client) +ProcSecurityGenerateAuthorization(ClientPtr client) { REQUEST(xSecurityGenerateAuthorizationReq); - int len; /* request length in CARD32s*/ - Bool removeAuth = FALSE; /* if bailout, call RemoveAuthorization? */ - SecurityAuthorizationPtr pAuth = NULL; /* auth we are creating */ - int err; /* error to return from this function */ - XID authId; /* authorization ID assigned by os layer */ - xSecurityGenerateAuthorizationReply rep; /* reply struct */ + int len; /* request length in CARD32s */ + Bool removeAuth = FALSE; /* if bailout, call RemoveAuthorization? */ + SecurityAuthorizationPtr pAuth = NULL; /* auth we are creating */ + int err; /* error to return from this function */ + XID authId; /* authorization ID assigned by os layer */ + xSecurityGenerateAuthorizationReply rep; /* reply struct */ unsigned int trustLevel; /* trust level of new auth */ - XID group; /* group of new auth */ - CARD32 timeout; /* timeout of new auth */ - CARD32 *values; /* list of supplied attributes */ - char *protoname; /* auth proto name sent in request */ - char *protodata; /* auth proto data sent in request */ + XID group; /* group of new auth */ + CARD32 timeout; /* timeout of new auth */ + CARD32 *values; /* list of supplied attributes */ + char *protoname; /* auth proto name sent in request */ + char *protodata; /* auth proto data sent in request */ unsigned int authdata_len; /* # bytes of generated auth data */ - char *pAuthdata; /* generated auth data */ - Mask eventMask; /* what events on this auth does client want */ + char *pAuthdata; /* generated auth data */ + Mask eventMask; /* what events on this auth does client want */ /* check request length */ @@ -446,84 +416,75 @@ ProcSecurityGenerateAuthorization( len = bytes_to_int32(SIZEOF(xSecurityGenerateAuthorizationReq)); len += bytes_to_int32(stuff->nbytesAuthProto); len += bytes_to_int32(stuff->nbytesAuthData); - values = ((CARD32 *)stuff) + len; + values = ((CARD32 *) stuff) + len; len += Ones(stuff->valueMask); if (client->req_len != len) - return BadLength; + return BadLength; /* check valuemask */ - if (stuff->valueMask & ~XSecurityAllAuthorizationAttributes) - { - client->errorValue = stuff->valueMask; - return BadValue; + if (stuff->valueMask & ~XSecurityAllAuthorizationAttributes) { + client->errorValue = stuff->valueMask; + return BadValue; } /* check timeout */ timeout = 60; - if (stuff->valueMask & XSecurityTimeout) - { - timeout = *values++; + if (stuff->valueMask & XSecurityTimeout) { + timeout = *values++; } /* check trustLevel */ trustLevel = XSecurityClientUntrusted; - if (stuff->valueMask & XSecurityTrustLevel) - { - trustLevel = *values++; - if (trustLevel != XSecurityClientTrusted && - trustLevel != XSecurityClientUntrusted) - { - client->errorValue = trustLevel; - return BadValue; - } + if (stuff->valueMask & XSecurityTrustLevel) { + trustLevel = *values++; + if (trustLevel != XSecurityClientTrusted && + trustLevel != XSecurityClientUntrusted) { + client->errorValue = trustLevel; + return BadValue; + } } /* check group */ group = None; - if (stuff->valueMask & XSecurityGroup) - { - group = *values++; - if (SecurityValidateGroupCallback) - { - SecurityValidateGroupInfoRec vgi; - vgi.group = group; - vgi.valid = FALSE; - CallCallbacks(&SecurityValidateGroupCallback, (pointer)&vgi); - - /* if nobody said they recognized it, it's an error */ - - if (!vgi.valid) - { - client->errorValue = group; - return BadValue; - } - } + if (stuff->valueMask & XSecurityGroup) { + group = *values++; + if (SecurityValidateGroupCallback) { + SecurityValidateGroupInfoRec vgi; + + vgi.group = group; + vgi.valid = FALSE; + CallCallbacks(&SecurityValidateGroupCallback, (pointer) &vgi); + + /* if nobody said they recognized it, it's an error */ + + if (!vgi.valid) { + client->errorValue = group; + return BadValue; + } + } } /* check event mask */ eventMask = 0; - if (stuff->valueMask & XSecurityEventMask) - { - eventMask = *values++; - if (eventMask & ~XSecurityAllEventMasks) - { - client->errorValue = eventMask; - return BadValue; - } + if (stuff->valueMask & XSecurityEventMask) { + eventMask = *values++; + if (eventMask & ~XSecurityAllEventMasks) { + client->errorValue = eventMask; + return BadValue; + } } - protoname = (char *)&stuff[1]; + protoname = (char *) &stuff[1]; protodata = protoname + bytes_to_int32(stuff->nbytesAuthProto); /* call os layer to generate the authorization */ authId = GenerateAuthorization(stuff->nbytesAuthProto, protoname, - stuff->nbytesAuthData, protodata, - &authdata_len, &pAuthdata); - if ((XID) ~0L == authId) - { - err = SecurityErrorBase + XSecurityBadAuthorizationProtocol; - goto bailout; + stuff->nbytesAuthData, protodata, + &authdata_len, &pAuthdata); + if ((XID) ~0L == authId) { + err = SecurityErrorBase + XSecurityBadAuthorizationProtocol; + goto bailout; } /* now that we've added the auth, remember to remove it if we have to @@ -534,10 +495,9 @@ ProcSecurityGenerateAuthorization( /* associate additional information with this auth ID */ pAuth = malloc(sizeof(SecurityAuthorizationRec)); - if (!pAuth) - { - err = BadAlloc; - goto bailout; + if (!pAuth) { + err = BadAlloc; + goto bailout; } /* fill in the auth fields */ @@ -546,29 +506,27 @@ ProcSecurityGenerateAuthorization( pAuth->timeout = timeout; pAuth->group = group; pAuth->trustLevel = trustLevel; - pAuth->refcnt = 0; /* the auth was just created; nobody's using it yet */ + pAuth->refcnt = 0; /* the auth was just created; nobody's using it yet */ pAuth->secondsRemaining = 0; pAuth->timer = NULL; pAuth->eventClients = NULL; /* handle event selection */ - if (eventMask) - { - err = SecurityEventSelectForAuthorization(pAuth, client, eventMask); - if (err != Success) - goto bailout; + if (eventMask) { + err = SecurityEventSelectForAuthorization(pAuth, client, eventMask); + if (err != Success) + goto bailout; } - if (!AddResource(authId, SecurityAuthorizationResType, pAuth)) - { - err = BadAlloc; - goto bailout; + if (!AddResource(authId, SecurityAuthorizationResType, pAuth)) { + err = BadAlloc; + goto bailout; } /* start the timer ticking */ if (pAuth->timeout != 0) - SecurityStartAuthorizationTimer(pAuth); + SecurityStartAuthorizationTimer(pAuth); /* tell client the auth id and data */ @@ -578,37 +536,36 @@ ProcSecurityGenerateAuthorization( rep.authId = authId; rep.dataLength = authdata_len; - if (client->swapped) - { - swapl(&rep.length); - swaps(&rep.sequenceNumber); - swapl(&rep.authId); - swaps(&rep.dataLength); + if (client->swapped) { + swapl(&rep.length); + swaps(&rep.sequenceNumber); + swapl(&rep.authId); + swaps(&rep.dataLength); } WriteToClient(client, SIZEOF(xSecurityGenerateAuthorizationReply), - (char *)&rep); + (char *) &rep); WriteToClient(client, authdata_len, pAuthdata); - SecurityAudit("client %d generated authorization %d trust %d timeout %d group %d events %d\n", - client->index, pAuth->id, pAuth->trustLevel, pAuth->timeout, - pAuth->group, eventMask); + SecurityAudit + ("client %d generated authorization %d trust %d timeout %d group %d events %d\n", + client->index, pAuth->id, pAuth->trustLevel, pAuth->timeout, + pAuth->group, eventMask); /* the request succeeded; don't call RemoveAuthorization or free pAuth */ return Success; -bailout: + bailout: if (removeAuth) - RemoveAuthorization(stuff->nbytesAuthProto, protoname, - authdata_len, pAuthdata); + RemoveAuthorization(stuff->nbytesAuthProto, protoname, + authdata_len, pAuthdata); free(pAuth); return err; -} /* ProcSecurityGenerateAuthorization */ +} /* ProcSecurityGenerateAuthorization */ static int -ProcSecurityRevokeAuthorization( - ClientPtr client) +ProcSecurityRevokeAuthorization(ClientPtr client) { REQUEST(xSecurityRevokeAuthorizationReq); SecurityAuthorizationPtr pAuth; @@ -616,39 +573,35 @@ ProcSecurityRevokeAuthorization( REQUEST_SIZE_MATCH(xSecurityRevokeAuthorizationReq); - rc = dixLookupResourceByType((pointer *)&pAuth, stuff->authId, - SecurityAuthorizationResType, client, - DixDestroyAccess); + rc = dixLookupResourceByType((pointer *) &pAuth, stuff->authId, + SecurityAuthorizationResType, client, + DixDestroyAccess); if (rc != Success) - return rc; + return rc; FreeResource(stuff->authId, RT_NONE); return Success; -} /* ProcSecurityRevokeAuthorization */ - +} /* ProcSecurityRevokeAuthorization */ static int -ProcSecurityDispatch( - ClientPtr client) +ProcSecurityDispatch(ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { - case X_SecurityQueryVersion: - return ProcSecurityQueryVersion(client); - case X_SecurityGenerateAuthorization: - return ProcSecurityGenerateAuthorization(client); - case X_SecurityRevokeAuthorization: - return ProcSecurityRevokeAuthorization(client); - default: - return BadRequest; + switch (stuff->data) { + case X_SecurityQueryVersion: + return ProcSecurityQueryVersion(client); + case X_SecurityGenerateAuthorization: + return ProcSecurityGenerateAuthorization(client); + case X_SecurityRevokeAuthorization: + return ProcSecurityRevokeAuthorization(client); + default: + return BadRequest; } -} /* ProcSecurityDispatch */ +} /* ProcSecurityDispatch */ static int -SProcSecurityQueryVersion( - ClientPtr client) +SProcSecurityQueryVersion(ClientPtr client) { REQUEST(xSecurityQueryVersionReq); @@ -657,12 +610,10 @@ SProcSecurityQueryVersion( swaps(&stuff->majorVersion); swaps(&stuff->minorVersion); return ProcSecurityQueryVersion(client); -} /* SProcSecurityQueryVersion */ - +} /* SProcSecurityQueryVersion */ static int -SProcSecurityGenerateAuthorization( - ClientPtr client) +SProcSecurityGenerateAuthorization(ClientPtr client) { REQUEST(xSecurityGenerateAuthorizationReq); CARD32 *values; @@ -675,20 +626,18 @@ SProcSecurityGenerateAuthorization( swaps(&stuff->nbytesAuthData); swapl(&stuff->valueMask); values_offset = bytes_to_int32(stuff->nbytesAuthProto) + - bytes_to_int32(stuff->nbytesAuthData); - if (values_offset > - stuff->length - bytes_to_int32(sz_xSecurityGenerateAuthorizationReq)) - return BadLength; - values = (CARD32 *)(&stuff[1]) + values_offset; - nvalues = (((CARD32 *)stuff) + stuff->length) - values; + bytes_to_int32(stuff->nbytesAuthData); + if (values_offset > + stuff->length - bytes_to_int32(sz_xSecurityGenerateAuthorizationReq)) + return BadLength; + values = (CARD32 *) (&stuff[1]) + values_offset; + nvalues = (((CARD32 *) stuff) + stuff->length) - values; SwapLongs(values, nvalues); return ProcSecurityGenerateAuthorization(client); -} /* SProcSecurityGenerateAuthorization */ - +} /* SProcSecurityGenerateAuthorization */ static int -SProcSecurityRevokeAuthorization( - ClientPtr client) +SProcSecurityRevokeAuthorization(ClientPtr client) { REQUEST(xSecurityRevokeAuthorizationReq); @@ -696,32 +645,28 @@ SProcSecurityRevokeAuthorization( REQUEST_SIZE_MATCH(xSecurityRevokeAuthorizationReq); swapl(&stuff->authId); return ProcSecurityRevokeAuthorization(client); -} /* SProcSecurityRevokeAuthorization */ - +} /* SProcSecurityRevokeAuthorization */ static int -SProcSecurityDispatch( - ClientPtr client) +SProcSecurityDispatch(ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { - case X_SecurityQueryVersion: - return SProcSecurityQueryVersion(client); - case X_SecurityGenerateAuthorization: - return SProcSecurityGenerateAuthorization(client); - case X_SecurityRevokeAuthorization: - return SProcSecurityRevokeAuthorization(client); - default: - return BadRequest; + switch (stuff->data) { + case X_SecurityQueryVersion: + return SProcSecurityQueryVersion(client); + case X_SecurityGenerateAuthorization: + return SProcSecurityGenerateAuthorization(client); + case X_SecurityRevokeAuthorization: + return SProcSecurityRevokeAuthorization(client); + default: + return BadRequest; } -} /* SProcSecurityDispatch */ +} /* SProcSecurityDispatch */ -static void -SwapSecurityAuthorizationRevokedEvent( - xSecurityAuthorizationRevokedEvent *from, - xSecurityAuthorizationRevokedEvent *to) +static void +SwapSecurityAuthorizationRevokedEvent(xSecurityAuthorizationRevokedEvent * from, + xSecurityAuthorizationRevokedEvent * to) { to->type = from->type; to->detail = from->detail; @@ -757,14 +702,14 @@ SecurityDevice(CallbackListPtr *pcbl, pointer unused, pointer calldata) obj = dixLookupPrivate(&serverClient->devPrivates, stateKey); if (rec->dev != inputInfo.keyboard) - /* this extension only supports the core keyboard */ - allowed = requested; + /* this extension only supports the core keyboard */ + allowed = requested; if (SecurityDoCheck(subj, obj, requested, allowed) != Success) { - SecurityAudit("Security denied client %d keyboard access on request " - "%s\n", rec->client->index, - SecurityLookupRequestName(rec->client)); - rec->status = BadAccess; + SecurityAudit("Security denied client %d keyboard access on request " + "%s\n", rec->client->index, + SecurityLookupRequestName(rec->client)); + rec->status = BadAccess; } } @@ -802,42 +747,41 @@ SecurityResource(CallbackListPtr *pcbl, pointer unused, pointer calldata) /* disable background None for untrusted windows */ if ((requested & DixCreateAccess) && (rec->rtype == RT_WINDOW)) - if (subj->haveState && subj->trustLevel != XSecurityClientTrusted) - ((WindowPtr)rec->res)->forcedBG = TRUE; + if (subj->haveState && subj->trustLevel != XSecurityClientTrusted) + ((WindowPtr) rec->res)->forcedBG = TRUE; /* additional permissions for specific resource types */ if (rec->rtype == RT_WINDOW) - allowed |= SecurityWindowExtraMask; + allowed |= SecurityWindowExtraMask; /* special checks for server-owned resources */ if (cid == 0) { - if (rec->rtype & RC_DRAWABLE) - /* additional operations allowed on root windows */ - allowed |= SecurityRootWindowExtraMask; + if (rec->rtype & RC_DRAWABLE) + /* additional operations allowed on root windows */ + allowed |= SecurityRootWindowExtraMask; - else if (rec->rtype == RT_COLORMAP) - /* allow access to default colormaps */ - allowed = requested; + else if (rec->rtype == RT_COLORMAP) + /* allow access to default colormaps */ + allowed = requested; - else - /* allow read access to other server-owned resources */ - allowed |= DixReadAccess; + else + /* allow read access to other server-owned resources */ + allowed |= DixReadAccess; } if (clients[cid] != NULL) { - obj = dixLookupPrivate(&clients[cid]->devPrivates, stateKey); - if (SecurityDoCheck(subj, obj, requested, allowed) == Success) - return; + obj = dixLookupPrivate(&clients[cid]->devPrivates, stateKey); + if (SecurityDoCheck(subj, obj, requested, allowed) == Success) + return; } SecurityAudit("Security: denied client %d access %x to resource 0x%x " - "of client %d on request %s\n", rec->client->index, - requested, rec->id, cid, - SecurityLookupRequestName(rec->client)); - rec->status = BadAccess; /* deny access */ + "of client %d on request %s\n", rec->client->index, + requested, rec->id, cid, + SecurityLookupRequestName(rec->client)); + rec->status = BadAccess; /* deny access */ } - static void SecurityExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata) { @@ -848,16 +792,16 @@ SecurityExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata) subj = dixLookupPrivate(&rec->client->devPrivates, stateKey); if (subj->haveState && subj->trustLevel == XSecurityClientTrusted) - return; + return; while (SecurityTrustedExtensions[i]) - if (!strcmp(SecurityTrustedExtensions[i++], rec->ext->name)) - return; + if (!strcmp(SecurityTrustedExtensions[i++], rec->ext->name)) + return; SecurityAudit("Security: denied client %d access to extension " - "%s on request %s\n", - rec->client->index, rec->ext->name, - SecurityLookupRequestName(rec->client)); + "%s on request %s\n", + rec->client->index, rec->ext->name, + SecurityLookupRequestName(rec->client)); rec->status = BadAccess; } @@ -871,12 +815,12 @@ SecurityServer(CallbackListPtr *pcbl, pointer unused, pointer calldata) subj = dixLookupPrivate(&rec->client->devPrivates, stateKey); obj = dixLookupPrivate(&serverClient->devPrivates, stateKey); - + if (SecurityDoCheck(subj, obj, requested, allowed) != Success) { - SecurityAudit("Security: denied client %d access to server " - "configuration request %s\n", rec->client->index, - SecurityLookupRequestName(rec->client)); - rec->status = BadAccess; + SecurityAudit("Security: denied client %d access to server " + "configuration request %s\n", rec->client->index, + SecurityLookupRequestName(rec->client)); + rec->status = BadAccess; } } @@ -892,16 +836,16 @@ SecurityClient(CallbackListPtr *pcbl, pointer unused, pointer calldata) obj = dixLookupPrivate(&rec->target->devPrivates, stateKey); if (SecurityDoCheck(subj, obj, requested, allowed) != Success) { - SecurityAudit("Security: denied client %d access to client %d on " - "request %s\n", rec->client->index, rec->target->index, - SecurityLookupRequestName(rec->client)); - rec->status = BadAccess; + SecurityAudit("Security: denied client %d access to client %d on " + "request %s\n", rec->client->index, rec->target->index, + SecurityLookupRequestName(rec->client)); + rec->status = BadAccess; } } static void SecurityProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata) -{ +{ XacePropertyAccessRec *rec = calldata; SecurityStateRec *subj, *obj; ATOM name = (*rec->ppProp)->propertyName; @@ -912,12 +856,12 @@ SecurityProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata) obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey); if (SecurityDoCheck(subj, obj, requested, allowed) != Success) { - SecurityAudit("Security: denied client %d access to property %s " - "(atom 0x%x) window 0x%x of client %d on request %s\n", - rec->client->index, NameForAtom(name), name, - rec->pWin->drawable.id, wClient(rec->pWin)->index, - SecurityLookupRequestName(rec->client)); - rec->status = BadAccess; + SecurityAudit("Security: denied client %d access to property %s " + "(atom 0x%x) window 0x%x of client %d on request %s\n", + rec->client->index, NameForAtom(name), name, + rec->pWin->drawable.id, wClient(rec->pWin)->index, + SecurityLookupRequestName(rec->client)); + rec->status = BadAccess; } } @@ -928,28 +872,28 @@ SecuritySend(CallbackListPtr *pcbl, pointer unused, pointer calldata) SecurityStateRec *subj, *obj; if (rec->client) { - int i; - - subj = dixLookupPrivate(&rec->client->devPrivates, stateKey); - obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey); - - if (SecurityDoCheck(subj, obj, DixSendAccess, 0) == Success) - return; - - for (i = 0; i < rec->count; i++) - if (rec->events[i].u.u.type != UnmapNotify && - rec->events[i].u.u.type != ConfigureRequest && - rec->events[i].u.u.type != ClientMessage) { - - SecurityAudit("Security: denied client %d from sending event " - "of type %s to window 0x%x of client %d\n", - rec->client->index, - LookupEventName(rec->events[i].u.u.type), - rec->pWin->drawable.id, - wClient(rec->pWin)->index); - rec->status = BadAccess; - return; - } + int i; + + subj = dixLookupPrivate(&rec->client->devPrivates, stateKey); + obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey); + + if (SecurityDoCheck(subj, obj, DixSendAccess, 0) == Success) + return; + + for (i = 0; i < rec->count; i++) + if (rec->events[i].u.u.type != UnmapNotify && + rec->events[i].u.u.type != ConfigureRequest && + rec->events[i].u.u.type != ClientMessage) { + + SecurityAudit("Security: denied client %d from sending event " + "of type %s to window 0x%x of client %d\n", + rec->client->index, + LookupEventName(rec->events[i].u.u.type), + rec->pWin->drawable.id, + wClient(rec->pWin)->index); + rec->status = BadAccess; + return; + } } } @@ -963,12 +907,12 @@ SecurityReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata) obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey); if (SecurityDoCheck(subj, obj, DixReceiveAccess, 0) == Success) - return; + return; SecurityAudit("Security: denied client %d from receiving an event " - "sent to window 0x%x of client %d\n", - rec->client->index, rec->pWin->drawable.id, - wClient(rec->pWin)->index); + "sent to window 0x%x of client %d\n", + rec->client->index, rec->pWin->drawable.id, + wClient(rec->pWin)->index); rec->status = BadAccess; } @@ -1006,41 +950,41 @@ SecurityClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata) switch (pci->client->clientState) { case ClientStateInitial: - state->trustLevel = XSecurityClientTrusted; - state->authId = None; - state->haveState = TRUE; - break; + state->trustLevel = XSecurityClientTrusted; + state->authId = None; + state->haveState = TRUE; + break; case ClientStateRunning: - state->authId = AuthorizationIDOfClient(pci->client); - rc = dixLookupResourceByType((pointer *)&pAuth, state->authId, - SecurityAuthorizationResType, serverClient, - DixGetAttrAccess); - if (rc == Success) { - /* it is a generated authorization */ - pAuth->refcnt++; - if (pAuth->refcnt == 1 && pAuth->timer) - TimerCancel(pAuth->timer); - - state->trustLevel = pAuth->trustLevel; - } - break; + state->authId = AuthorizationIDOfClient(pci->client); + rc = dixLookupResourceByType((pointer *) &pAuth, state->authId, + SecurityAuthorizationResType, serverClient, + DixGetAttrAccess); + if (rc == Success) { + /* it is a generated authorization */ + pAuth->refcnt++; + if (pAuth->refcnt == 1 && pAuth->timer) + TimerCancel(pAuth->timer); + + state->trustLevel = pAuth->trustLevel; + } + break; case ClientStateGone: case ClientStateRetained: - rc = dixLookupResourceByType((pointer *)&pAuth, state->authId, - SecurityAuthorizationResType, serverClient, - DixGetAttrAccess); - if (rc == Success) { - /* it is a generated authorization */ - pAuth->refcnt--; - if (pAuth->refcnt == 0) - SecurityStartAuthorizationTimer(pAuth); - } - break; + rc = dixLookupResourceByType((pointer *) &pAuth, state->authId, + SecurityAuthorizationResType, serverClient, + DixGetAttrAccess); + if (rc == Success) { + /* it is a generated authorization */ + pAuth->refcnt--; + if (pAuth->refcnt == 0) + SecurityStartAuthorizationTimer(pAuth); + } + break; default: - break; + break; } } @@ -1056,8 +1000,7 @@ SecurityClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata) */ static void -SecurityResetProc( - ExtensionEntry *extEntry) +SecurityResetProc(ExtensionEntry * extEntry) { /* Unregister callbacks */ DeleteCallback(&ClientStateCallback, SecurityClientState, NULL); @@ -1073,7 +1016,6 @@ SecurityResetProc( XaceDeleteCallback(XACE_SERVER_ACCESS, SecurityServer, NULL); } - /* SecurityExtensionInit * * Arguments: none. @@ -1087,25 +1029,26 @@ SecurityResetProc( void SecurityExtensionInit(INITARGS) { - ExtensionEntry *extEntry; + ExtensionEntry *extEntry; int ret = TRUE; SecurityAuthorizationResType = - CreateNewResourceType(SecurityDeleteAuthorization, - "SecurityAuthorization"); + CreateNewResourceType(SecurityDeleteAuthorization, + "SecurityAuthorization"); RTEventClient = - CreateNewResourceType(SecurityDeleteAuthorizationEventClient, - "SecurityEventClient"); + CreateNewResourceType(SecurityDeleteAuthorizationEventClient, + "SecurityEventClient"); if (!SecurityAuthorizationResType || !RTEventClient) - return; + return; RTEventClient |= RC_NEVERRETAIN; /* Allocate the private storage */ - if (!dixRegisterPrivateKey(stateKey, PRIVATE_CLIENT, sizeof(SecurityStateRec))) - FatalError("SecurityExtensionSetup: Can't allocate client private.\n"); + if (!dixRegisterPrivateKey + (stateKey, PRIVATE_CLIENT, sizeof(SecurityStateRec))) + FatalError("SecurityExtensionSetup: Can't allocate client private.\n"); /* Register callbacks */ ret &= AddCallback(&ClientStateCallback, SecurityClientState, NULL); @@ -1121,21 +1064,22 @@ SecurityExtensionInit(INITARGS) ret &= XaceRegisterCallback(XACE_SERVER_ACCESS, SecurityServer, NULL); if (!ret) - FatalError("SecurityExtensionSetup: Failed to register callbacks\n"); + FatalError("SecurityExtensionSetup: Failed to register callbacks\n"); /* Add extension to server */ extEntry = AddExtension(SECURITY_EXTENSION_NAME, - XSecurityNumberEvents, XSecurityNumberErrors, - ProcSecurityDispatch, SProcSecurityDispatch, + XSecurityNumberEvents, XSecurityNumberErrors, + ProcSecurityDispatch, SProcSecurityDispatch, SecurityResetProc, StandardMinorOpcode); SecurityErrorBase = extEntry->errorBase; SecurityEventBase = extEntry->eventBase; EventSwapVector[SecurityEventBase + XSecurityAuthorizationRevoked] = - (EventSwapPtr)SwapSecurityAuthorizationRevokedEvent; + (EventSwapPtr) SwapSecurityAuthorizationRevokedEvent; - SetResourceTypeErrorValue(SecurityAuthorizationResType, SecurityErrorBase + XSecurityBadAuthorization); + SetResourceTypeErrorValue(SecurityAuthorizationResType, + SecurityErrorBase + XSecurityBadAuthorization); /* Label objects that were created before we could register ourself */ SecurityLabelInitial(); diff --git a/xorg-server/Xext/shape.c b/xorg-server/Xext/shape.c index 3263c0224..d3859a51d 100644 --- a/xorg-server/Xext/shape.c +++ b/xorg-server/Xext/shape.c @@ -49,35 +49,30 @@ in this Software without prior written authorization from The Open Group. #include "modinit.h" #include "protocol-versions.h" -typedef RegionPtr (*CreateDftPtr)( - WindowPtr /* pWin */ - ); - -static int ShapeFreeClient( - pointer /* data */, - XID /* id */ - ); -static int ShapeFreeEvents( - pointer /* data */, - XID /* id */ - ); -static void SShapeNotifyEvent( - xShapeNotifyEvent * /* from */, - xShapeNotifyEvent * /* to */ - ); +typedef RegionPtr (*CreateDftPtr) (WindowPtr /* pWin */ + ); + +static int ShapeFreeClient(pointer /* data */ , + XID /* id */ + ); +static int ShapeFreeEvents(pointer /* data */ , + XID /* id */ + ); +static void SShapeNotifyEvent(xShapeNotifyEvent * /* from */ , + xShapeNotifyEvent * /* to */ + ); /* SendShapeNotify, CreateBoundingShape and CreateClipShape are used * externally by the Xfixes extension and are now defined in window.h */ - #ifdef PANORAMIX #include "panoramiX.h" #include "panoramiXsrv.h" #endif static int ShapeEventBase = 0; -static RESTYPE ClientType, ShapeEventType; /* resource types for event masks */ +static RESTYPE ClientType, ShapeEventType; /* resource types for event masks */ /* * each window has a list of clients requesting @@ -90,10 +85,10 @@ static RESTYPE ClientType, ShapeEventType; /* resource types for event masks */ typedef struct _ShapeEvent *ShapeEventPtr; typedef struct _ShapeEvent { - ShapeEventPtr next; - ClientPtr client; - WindowPtr window; - XID clientResource; + ShapeEventPtr next; + ClientPtr client; + WindowPtr window; + XID clientResource; } ShapeEventRec; /**************** @@ -105,23 +100,18 @@ typedef struct _ShapeEvent { ****************/ static int -RegionOperate ( - ClientPtr client, - WindowPtr pWin, - int kind, - RegionPtr *destRgnp, - RegionPtr srcRgn, - int op, - int xoff, int yoff, - CreateDftPtr create) +RegionOperate(ClientPtr client, + WindowPtr pWin, + int kind, + RegionPtr *destRgnp, + RegionPtr srcRgn, int op, int xoff, int yoff, CreateDftPtr create) { if (srcRgn && (xoff || yoff)) - RegionTranslate(srcRgn, xoff, yoff); - if (!pWin->parent) - { - if (srcRgn) - RegionDestroy(srcRgn); - return Success; + RegionTranslate(srcRgn, xoff, yoff); + if (!pWin->parent) { + if (srcRgn) + RegionDestroy(srcRgn); + return Success; } /* May/30/2001: @@ -130,80 +120,81 @@ RegionOperate ( * see shape.PS, page 3, ShapeMask. */ if (srcRgn == NULL) { - if (*destRgnp != NULL) { - RegionDestroy(*destRgnp); - *destRgnp = 0; - /* go on to remove shape and generate ShapeNotify */ - } - else { - /* May/30/2001: - * The target currently has no shape in effect, so nothing to - * do here. The specs say that ShapeNotify is generated whenever - * the client region is "modified"; since no modification is done - * here, we do not generate that event. The specs does not say - * "it is an error to request removal when there is no shape in - * effect", so we return good status. - */ - return Success; - } - } - else switch (op) { - case ShapeSet: - if (*destRgnp) - RegionDestroy(*destRgnp); - *destRgnp = srcRgn; - srcRgn = 0; - break; - case ShapeUnion: - if (*destRgnp) - RegionUnion(*destRgnp, *destRgnp, srcRgn); - break; - case ShapeIntersect: - if (*destRgnp) - RegionIntersect(*destRgnp, *destRgnp, srcRgn); - else { - *destRgnp = srcRgn; - srcRgn = 0; - } - break; - case ShapeSubtract: - if (!*destRgnp) - *destRgnp = (*create)(pWin); - RegionSubtract(*destRgnp, *destRgnp, srcRgn); - break; - case ShapeInvert: - if (!*destRgnp) - *destRgnp = RegionCreate((BoxPtr) 0, 0); - else - RegionSubtract(*destRgnp, srcRgn, *destRgnp); - break; - default: - client->errorValue = op; - return BadValue; + if (*destRgnp != NULL) { + RegionDestroy(*destRgnp); + *destRgnp = 0; + /* go on to remove shape and generate ShapeNotify */ + } + else { + /* May/30/2001: + * The target currently has no shape in effect, so nothing to + * do here. The specs say that ShapeNotify is generated whenever + * the client region is "modified"; since no modification is done + * here, we do not generate that event. The specs does not say + * "it is an error to request removal when there is no shape in + * effect", so we return good status. + */ + return Success; + } } + else + switch (op) { + case ShapeSet: + if (*destRgnp) + RegionDestroy(*destRgnp); + *destRgnp = srcRgn; + srcRgn = 0; + break; + case ShapeUnion: + if (*destRgnp) + RegionUnion(*destRgnp, *destRgnp, srcRgn); + break; + case ShapeIntersect: + if (*destRgnp) + RegionIntersect(*destRgnp, *destRgnp, srcRgn); + else { + *destRgnp = srcRgn; + srcRgn = 0; + } + break; + case ShapeSubtract: + if (!*destRgnp) + *destRgnp = (*create) (pWin); + RegionSubtract(*destRgnp, *destRgnp, srcRgn); + break; + case ShapeInvert: + if (!*destRgnp) + *destRgnp = RegionCreate((BoxPtr) 0, 0); + else + RegionSubtract(*destRgnp, srcRgn, *destRgnp); + break; + default: + client->errorValue = op; + return BadValue; + } if (srcRgn) - RegionDestroy(srcRgn); + RegionDestroy(srcRgn); (*pWin->drawable.pScreen->SetShape) (pWin, kind); - SendShapeNotify (pWin, kind); + SendShapeNotify(pWin, kind); return Success; } RegionPtr -CreateBoundingShape (WindowPtr pWin) +CreateBoundingShape(WindowPtr pWin) { - BoxRec extents; + BoxRec extents; - extents.x1 = -wBorderWidth (pWin); - extents.y1 = -wBorderWidth (pWin); - extents.x2 = pWin->drawable.width + wBorderWidth (pWin); - extents.y2 = pWin->drawable.height + wBorderWidth (pWin); + extents.x1 = -wBorderWidth(pWin); + extents.y1 = -wBorderWidth(pWin); + extents.x2 = pWin->drawable.width + wBorderWidth(pWin); + extents.y2 = pWin->drawable.height + wBorderWidth(pWin); return RegionCreate(&extents, 1); } RegionPtr -CreateClipShape (WindowPtr pWin) +CreateClipShape(WindowPtr pWin) { - BoxRec extents; + BoxRec extents; extents.x1 = 0; extents.y1 = 0; @@ -213,10 +204,11 @@ CreateClipShape (WindowPtr pWin) } static int -ProcShapeQueryVersion (ClientPtr client) +ProcShapeQueryVersion(ClientPtr client) { - xShapeQueryVersionReply rep; - REQUEST_SIZE_MATCH (xShapeQueryVersionReq); + xShapeQueryVersionReply rep; + + REQUEST_SIZE_MATCH(xShapeQueryVersionReq); memset(&rep, 0, sizeof(xShapeQueryVersionReply)); rep.type = X_Reply; rep.length = 0; @@ -224,12 +216,12 @@ ProcShapeQueryVersion (ClientPtr client) rep.majorVersion = SERVER_SHAPE_MAJOR_VERSION; rep.minorVersion = SERVER_SHAPE_MINOR_VERSION; if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swaps(&rep.majorVersion); - swaps(&rep.minorVersion); + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swaps(&rep.majorVersion); + swaps(&rep.minorVersion); } - WriteToClient(client, sizeof (xShapeQueryVersionReply), (char *)&rep); + WriteToClient(client, sizeof(xShapeQueryVersionReply), (char *) &rep); return Success; } @@ -239,325 +231,324 @@ ProcShapeQueryVersion (ClientPtr client) *****************/ static int -ProcShapeRectangles (ClientPtr client) +ProcShapeRectangles(ClientPtr client) { - WindowPtr pWin; + WindowPtr pWin; + REQUEST(xShapeRectanglesReq); - xRectangle *prects; - int nrects, ctype, rc; - RegionPtr srcRgn; - RegionPtr *destRgn; - CreateDftPtr createDefault; + xRectangle *prects; + int nrects, ctype, rc; + RegionPtr srcRgn; + RegionPtr *destRgn; + CreateDftPtr createDefault; - REQUEST_AT_LEAST_SIZE (xShapeRectanglesReq); + REQUEST_AT_LEAST_SIZE(xShapeRectanglesReq); UpdateCurrentTime(); rc = dixLookupWindow(&pWin, stuff->dest, client, DixSetAttrAccess); if (rc != Success) - return rc; + return rc; switch (stuff->destKind) { case ShapeBounding: - createDefault = CreateBoundingShape; - break; + createDefault = CreateBoundingShape; + break; case ShapeClip: - createDefault = CreateClipShape; - break; + createDefault = CreateClipShape; + break; case ShapeInput: - createDefault = CreateBoundingShape; - break; + createDefault = CreateBoundingShape; + break; default: - client->errorValue = stuff->destKind; - return BadValue; + client->errorValue = stuff->destKind; + return BadValue; } if ((stuff->ordering != Unsorted) && (stuff->ordering != YSorted) && - (stuff->ordering != YXSorted) && (stuff->ordering != YXBanded)) - { - client->errorValue = stuff->ordering; + (stuff->ordering != YXSorted) && (stuff->ordering != YXBanded)) { + client->errorValue = stuff->ordering; return BadValue; } - nrects = ((stuff->length << 2) - sizeof(xShapeRectanglesReq)); + nrects = ((stuff->length << 2) - sizeof(xShapeRectanglesReq)); if (nrects & 4) - return BadLength; + return BadLength; nrects >>= 3; prects = (xRectangle *) &stuff[1]; - ctype = VerifyRectOrder(nrects, prects, (int)stuff->ordering); + ctype = VerifyRectOrder(nrects, prects, (int) stuff->ordering); if (ctype < 0) - return BadMatch; + return BadMatch; srcRgn = RegionFromRects(nrects, prects, ctype); if (!pWin->optional) - MakeWindowOptional (pWin); + MakeWindowOptional(pWin); switch (stuff->destKind) { case ShapeBounding: - destRgn = &pWin->optional->boundingShape; - break; + destRgn = &pWin->optional->boundingShape; + break; case ShapeClip: - destRgn = &pWin->optional->clipShape; - break; + destRgn = &pWin->optional->clipShape; + break; case ShapeInput: - destRgn = &pWin->optional->inputShape; - break; + destRgn = &pWin->optional->inputShape; + break; default: - return BadValue; + return BadValue; } - return RegionOperate (client, pWin, (int)stuff->destKind, - destRgn, srcRgn, (int)stuff->op, - stuff->xOff, stuff->yOff, createDefault); + return RegionOperate(client, pWin, (int) stuff->destKind, + destRgn, srcRgn, (int) stuff->op, + stuff->xOff, stuff->yOff, createDefault); } #ifdef PANORAMIX static int -ProcPanoramiXShapeRectangles( - ClientPtr client) +ProcPanoramiXShapeRectangles(ClientPtr client) { REQUEST(xShapeRectanglesReq); - PanoramiXRes *win; - int j, result; + PanoramiXRes *win; + int j, result; - REQUEST_AT_LEAST_SIZE (xShapeRectanglesReq); + REQUEST_AT_LEAST_SIZE(xShapeRectanglesReq); - result = dixLookupResourceByType((pointer *)&win, stuff->dest, XRT_WINDOW, - client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->dest, XRT_WINDOW, + client, DixWriteAccess); if (result != Success) - return result; + return result; FOR_NSCREENS(j) { - stuff->dest = win->info[j].id; - result = ProcShapeRectangles (client); - if (result != Success) break; + stuff->dest = win->info[j].id; + result = ProcShapeRectangles(client); + if (result != Success) + break; } return result; } #endif - /************** * ProcShapeMask **************/ - static int -ProcShapeMask (ClientPtr client) +ProcShapeMask(ClientPtr client) { - WindowPtr pWin; - ScreenPtr pScreen; + WindowPtr pWin; + ScreenPtr pScreen; + REQUEST(xShapeMaskReq); - RegionPtr srcRgn; - RegionPtr *destRgn; - PixmapPtr pPixmap; - CreateDftPtr createDefault; - int rc; + RegionPtr srcRgn; + RegionPtr *destRgn; + PixmapPtr pPixmap; + CreateDftPtr createDefault; + int rc; - REQUEST_SIZE_MATCH (xShapeMaskReq); + REQUEST_SIZE_MATCH(xShapeMaskReq); UpdateCurrentTime(); rc = dixLookupWindow(&pWin, stuff->dest, client, DixSetAttrAccess); if (rc != Success) - return rc; + return rc; switch (stuff->destKind) { case ShapeBounding: - createDefault = CreateBoundingShape; - break; + createDefault = CreateBoundingShape; + break; case ShapeClip: - createDefault = CreateClipShape; - break; + createDefault = CreateClipShape; + break; case ShapeInput: - createDefault = CreateBoundingShape; - break; + createDefault = CreateBoundingShape; + break; default: - client->errorValue = stuff->destKind; - return BadValue; + client->errorValue = stuff->destKind; + return BadValue; } pScreen = pWin->drawable.pScreen; if (stuff->src == None) - srcRgn = 0; + srcRgn = 0; else { - rc = dixLookupResourceByType((pointer *)&pPixmap, stuff->src, RT_PIXMAP, - client, DixReadAccess); + rc = dixLookupResourceByType((pointer *) &pPixmap, stuff->src, + RT_PIXMAP, client, DixReadAccess); if (rc != Success) - return rc; - if (pPixmap->drawable.pScreen != pScreen || - pPixmap->drawable.depth != 1) - return BadMatch; - srcRgn = BitmapToRegion(pScreen, pPixmap); - if (!srcRgn) - return BadAlloc; + return rc; + if (pPixmap->drawable.pScreen != pScreen || + pPixmap->drawable.depth != 1) + return BadMatch; + srcRgn = BitmapToRegion(pScreen, pPixmap); + if (!srcRgn) + return BadAlloc; } if (!pWin->optional) - MakeWindowOptional (pWin); + MakeWindowOptional(pWin); switch (stuff->destKind) { case ShapeBounding: - destRgn = &pWin->optional->boundingShape; - break; + destRgn = &pWin->optional->boundingShape; + break; case ShapeClip: - destRgn = &pWin->optional->clipShape; - break; + destRgn = &pWin->optional->clipShape; + break; case ShapeInput: - destRgn = &pWin->optional->inputShape; - break; + destRgn = &pWin->optional->inputShape; + break; default: - return BadValue; + return BadValue; } - return RegionOperate (client, pWin, (int)stuff->destKind, - destRgn, srcRgn, (int)stuff->op, - stuff->xOff, stuff->yOff, createDefault); + return RegionOperate(client, pWin, (int) stuff->destKind, + destRgn, srcRgn, (int) stuff->op, + stuff->xOff, stuff->yOff, createDefault); } #ifdef PANORAMIX static int -ProcPanoramiXShapeMask( - ClientPtr client) +ProcPanoramiXShapeMask(ClientPtr client) { REQUEST(xShapeMaskReq); - PanoramiXRes *win, *pmap; - int j, result; + PanoramiXRes *win, *pmap; + int j, result; - REQUEST_SIZE_MATCH (xShapeMaskReq); + REQUEST_SIZE_MATCH(xShapeMaskReq); - result = dixLookupResourceByType((pointer *)&win, stuff->dest, XRT_WINDOW, - client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->dest, XRT_WINDOW, + client, DixWriteAccess); if (result != Success) - return result; + return result; - if(stuff->src != None) { - result = dixLookupResourceByType((pointer *)&pmap, stuff->src, - XRT_PIXMAP, client, DixReadAccess); - if (result != Success) - return result; - } else - pmap = NULL; + if (stuff->src != None) { + result = dixLookupResourceByType((pointer *) &pmap, stuff->src, + XRT_PIXMAP, client, DixReadAccess); + if (result != Success) + return result; + } + else + pmap = NULL; FOR_NSCREENS(j) { - stuff->dest = win->info[j].id; - if(pmap) - stuff->src = pmap->info[j].id; - result = ProcShapeMask (client); - if (result != Success) break; + stuff->dest = win->info[j].id; + if (pmap) + stuff->src = pmap->info[j].id; + result = ProcShapeMask(client); + if (result != Success) + break; } return result; } #endif - /************ * ProcShapeCombine ************/ static int -ProcShapeCombine (ClientPtr client) +ProcShapeCombine(ClientPtr client) { - WindowPtr pSrcWin, pDestWin; + WindowPtr pSrcWin, pDestWin; + REQUEST(xShapeCombineReq); - RegionPtr srcRgn; - RegionPtr *destRgn; - CreateDftPtr createDefault; - CreateDftPtr createSrc; - RegionPtr tmp; - int rc; - - REQUEST_SIZE_MATCH (xShapeCombineReq); + RegionPtr srcRgn; + RegionPtr *destRgn; + CreateDftPtr createDefault; + CreateDftPtr createSrc; + RegionPtr tmp; + int rc; + + REQUEST_SIZE_MATCH(xShapeCombineReq); UpdateCurrentTime(); rc = dixLookupWindow(&pDestWin, stuff->dest, client, DixSetAttrAccess); if (rc != Success) - return rc; + return rc; if (!pDestWin->optional) - MakeWindowOptional (pDestWin); + MakeWindowOptional(pDestWin); switch (stuff->destKind) { case ShapeBounding: - createDefault = CreateBoundingShape; - break; + createDefault = CreateBoundingShape; + break; case ShapeClip: - createDefault = CreateClipShape; - break; + createDefault = CreateClipShape; + break; case ShapeInput: - createDefault = CreateBoundingShape; - break; + createDefault = CreateBoundingShape; + break; default: - client->errorValue = stuff->destKind; - return BadValue; + client->errorValue = stuff->destKind; + return BadValue; } rc = dixLookupWindow(&pSrcWin, stuff->src, client, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; switch (stuff->srcKind) { case ShapeBounding: - srcRgn = wBoundingShape (pSrcWin); - createSrc = CreateBoundingShape; - break; + srcRgn = wBoundingShape(pSrcWin); + createSrc = CreateBoundingShape; + break; case ShapeClip: - srcRgn = wClipShape (pSrcWin); - createSrc = CreateClipShape; - break; + srcRgn = wClipShape(pSrcWin); + createSrc = CreateClipShape; + break; case ShapeInput: - srcRgn = wInputShape (pSrcWin); - createSrc = CreateBoundingShape; - break; + srcRgn = wInputShape(pSrcWin); + createSrc = CreateBoundingShape; + break; default: - client->errorValue = stuff->srcKind; - return BadValue; + client->errorValue = stuff->srcKind; + return BadValue; } - if (pSrcWin->drawable.pScreen != pDestWin->drawable.pScreen) - { - return BadMatch; + if (pSrcWin->drawable.pScreen != pDestWin->drawable.pScreen) { + return BadMatch; } if (srcRgn) { tmp = RegionCreate((BoxPtr) 0, 0); RegionCopy(tmp, srcRgn); srcRgn = tmp; - } else - srcRgn = (*createSrc) (pSrcWin); + } + else + srcRgn = (*createSrc) (pSrcWin); if (!pDestWin->optional) - MakeWindowOptional (pDestWin); + MakeWindowOptional(pDestWin); switch (stuff->destKind) { case ShapeBounding: - destRgn = &pDestWin->optional->boundingShape; - break; + destRgn = &pDestWin->optional->boundingShape; + break; case ShapeClip: - destRgn = &pDestWin->optional->clipShape; - break; + destRgn = &pDestWin->optional->clipShape; + break; case ShapeInput: - destRgn = &pDestWin->optional->inputShape; - break; + destRgn = &pDestWin->optional->inputShape; + break; default: - return BadValue; + return BadValue; } - return RegionOperate (client, pDestWin, (int)stuff->destKind, - destRgn, srcRgn, (int)stuff->op, - stuff->xOff, stuff->yOff, createDefault); + return RegionOperate(client, pDestWin, (int) stuff->destKind, + destRgn, srcRgn, (int) stuff->op, + stuff->xOff, stuff->yOff, createDefault); } - #ifdef PANORAMIX static int -ProcPanoramiXShapeCombine( - ClientPtr client) +ProcPanoramiXShapeCombine(ClientPtr client) { REQUEST(xShapeCombineReq); - PanoramiXRes *win, *win2; - int j, result; + PanoramiXRes *win, *win2; + int j, result; - REQUEST_AT_LEAST_SIZE (xShapeCombineReq); + REQUEST_AT_LEAST_SIZE(xShapeCombineReq); - result = dixLookupResourceByType((pointer *)&win, stuff->dest, XRT_WINDOW, - client, DixWriteAccess); + result = dixLookupResourceByType((pointer *) &win, stuff->dest, XRT_WINDOW, + client, DixWriteAccess); if (result != Success) - return result; + return result; - result = dixLookupResourceByType((pointer *)&win2, stuff->src, XRT_WINDOW, - client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &win2, stuff->src, XRT_WINDOW, + client, DixReadAccess); if (result != Success) - return result; + return result; FOR_NSCREENS(j) { - stuff->dest = win->info[j].id; - stuff->src = win2->info[j].id; - result = ProcShapeCombine (client); - if (result != Success) break; + stuff->dest = win->info[j].id; + stuff->src = win2->info[j].id; + result = ProcShapeCombine(client); + if (result != Success) + break; } return result; } @@ -568,82 +559,80 @@ ProcPanoramiXShapeCombine( *************/ static int -ProcShapeOffset (ClientPtr client) +ProcShapeOffset(ClientPtr client) { - WindowPtr pWin; + WindowPtr pWin; + REQUEST(xShapeOffsetReq); - RegionPtr srcRgn; - int rc; + RegionPtr srcRgn; + int rc; - REQUEST_SIZE_MATCH (xShapeOffsetReq); + REQUEST_SIZE_MATCH(xShapeOffsetReq); UpdateCurrentTime(); rc = dixLookupWindow(&pWin, stuff->dest, client, DixSetAttrAccess); if (rc != Success) - return rc; + return rc; switch (stuff->destKind) { case ShapeBounding: - srcRgn = wBoundingShape (pWin); - break; + srcRgn = wBoundingShape(pWin); + break; case ShapeClip: - srcRgn = wClipShape(pWin); - break; + srcRgn = wClipShape(pWin); + break; case ShapeInput: - srcRgn = wInputShape (pWin); - break; + srcRgn = wInputShape(pWin); + break; default: - client->errorValue = stuff->destKind; - return BadValue; + client->errorValue = stuff->destKind; + return BadValue; } - if (srcRgn) - { + if (srcRgn) { RegionTranslate(srcRgn, stuff->xOff, stuff->yOff); (*pWin->drawable.pScreen->SetShape) (pWin, stuff->destKind); } - SendShapeNotify (pWin, (int)stuff->destKind); + SendShapeNotify(pWin, (int) stuff->destKind); return Success; } - #ifdef PANORAMIX static int -ProcPanoramiXShapeOffset( - ClientPtr client) +ProcPanoramiXShapeOffset(ClientPtr client) { REQUEST(xShapeOffsetReq); PanoramiXRes *win; int j, result; - REQUEST_AT_LEAST_SIZE (xShapeOffsetReq); - - result = dixLookupResourceByType((pointer *)&win, stuff->dest, XRT_WINDOW, - client, DixWriteAccess); + REQUEST_AT_LEAST_SIZE(xShapeOffsetReq); + + result = dixLookupResourceByType((pointer *) &win, stuff->dest, XRT_WINDOW, + client, DixWriteAccess); if (result != Success) - return result; + return result; FOR_NSCREENS(j) { - stuff->dest = win->info[j].id; - result = ProcShapeOffset (client); - if(result != Success) break; + stuff->dest = win->info[j].id; + result = ProcShapeOffset(client); + if (result != Success) + break; } return result; } #endif - static int -ProcShapeQueryExtents (ClientPtr client) +ProcShapeQueryExtents(ClientPtr client) { REQUEST(xShapeQueryExtentsReq); - WindowPtr pWin; - xShapeQueryExtentsReply rep; - BoxRec extents, *pExtents; - int rc; - RegionPtr region; + WindowPtr pWin; + xShapeQueryExtentsReply rep; + BoxRec extents, *pExtents; + int rc; + RegionPtr region; - REQUEST_SIZE_MATCH (xShapeQueryExtentsReq); + REQUEST_SIZE_MATCH(xShapeQueryExtentsReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; memset(&rep, 0, sizeof(xShapeQueryExtentsReply)); rep.type = X_Reply; rep.length = 0; @@ -651,183 +640,180 @@ ProcShapeQueryExtents (ClientPtr client) rep.boundingShaped = (wBoundingShape(pWin) != 0); rep.clipShaped = (wClipShape(pWin) != 0); if ((region = wBoundingShape(pWin))) { - /* this is done in two steps because of a compiler bug on SunOS 4.1.3 */ - pExtents = RegionExtents(region); - extents = *pExtents; - } else { - extents.x1 = -wBorderWidth (pWin); - extents.y1 = -wBorderWidth (pWin); - extents.x2 = pWin->drawable.width + wBorderWidth (pWin); - extents.y2 = pWin->drawable.height + wBorderWidth (pWin); + /* this is done in two steps because of a compiler bug on SunOS 4.1.3 */ + pExtents = RegionExtents(region); + extents = *pExtents; + } + else { + extents.x1 = -wBorderWidth(pWin); + extents.y1 = -wBorderWidth(pWin); + extents.x2 = pWin->drawable.width + wBorderWidth(pWin); + extents.y2 = pWin->drawable.height + wBorderWidth(pWin); } rep.xBoundingShape = extents.x1; rep.yBoundingShape = extents.y1; rep.widthBoundingShape = extents.x2 - extents.x1; rep.heightBoundingShape = extents.y2 - extents.y1; if ((region = wClipShape(pWin))) { - /* this is done in two steps because of a compiler bug on SunOS 4.1.3 */ - pExtents = RegionExtents(region); - extents = *pExtents; - } else { - extents.x1 = 0; - extents.y1 = 0; - extents.x2 = pWin->drawable.width; - extents.y2 = pWin->drawable.height; + /* this is done in two steps because of a compiler bug on SunOS 4.1.3 */ + pExtents = RegionExtents(region); + extents = *pExtents; + } + else { + extents.x1 = 0; + extents.y1 = 0; + extents.x2 = pWin->drawable.width; + extents.y2 = pWin->drawable.height; } rep.xClipShape = extents.x1; rep.yClipShape = extents.y1; rep.widthClipShape = extents.x2 - extents.x1; rep.heightClipShape = extents.y2 - extents.y1; if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swaps(&rep.xBoundingShape); - swaps(&rep.yBoundingShape); - swaps(&rep.widthBoundingShape); - swaps(&rep.heightBoundingShape); - swaps(&rep.xClipShape); - swaps(&rep.yClipShape); - swaps(&rep.widthClipShape); - swaps(&rep.heightClipShape); + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swaps(&rep.xBoundingShape); + swaps(&rep.yBoundingShape); + swaps(&rep.widthBoundingShape); + swaps(&rep.heightBoundingShape); + swaps(&rep.xClipShape); + swaps(&rep.yClipShape); + swaps(&rep.widthClipShape); + swaps(&rep.heightClipShape); } - WriteToClient(client, sizeof (xShapeQueryExtentsReply), (char *)&rep); + WriteToClient(client, sizeof(xShapeQueryExtentsReply), (char *) &rep); return Success; } -/*ARGSUSED*/ -static int -ShapeFreeClient (pointer data, XID id) + /*ARGSUSED*/ static int +ShapeFreeClient(pointer data, XID id) { - ShapeEventPtr pShapeEvent; - WindowPtr pWin; - ShapeEventPtr *pHead, pCur, pPrev; + ShapeEventPtr pShapeEvent; + WindowPtr pWin; + ShapeEventPtr *pHead, pCur, pPrev; int rc; pShapeEvent = (ShapeEventPtr) data; pWin = pShapeEvent->window; - rc = dixLookupResourceByType((pointer *)&pHead, pWin->drawable.id, - ShapeEventType, serverClient, DixReadAccess); + rc = dixLookupResourceByType((pointer *) &pHead, pWin->drawable.id, + ShapeEventType, serverClient, DixReadAccess); if (rc == Success) { - pPrev = 0; - for (pCur = *pHead; pCur && pCur != pShapeEvent; pCur=pCur->next) - pPrev = pCur; - if (pCur) - { - if (pPrev) - pPrev->next = pShapeEvent->next; - else - *pHead = pShapeEvent->next; - } + pPrev = 0; + for (pCur = *pHead; pCur && pCur != pShapeEvent; pCur = pCur->next) + pPrev = pCur; + if (pCur) { + if (pPrev) + pPrev->next = pShapeEvent->next; + else + *pHead = pShapeEvent->next; + } } free((pointer) pShapeEvent); return 1; } -/*ARGSUSED*/ -static int -ShapeFreeEvents (pointer data, XID id) + /*ARGSUSED*/ static int +ShapeFreeEvents(pointer data, XID id) { - ShapeEventPtr *pHead, pCur, pNext; + ShapeEventPtr *pHead, pCur, pNext; pHead = (ShapeEventPtr *) data; for (pCur = *pHead; pCur; pCur = pNext) { - pNext = pCur->next; - FreeResource (pCur->clientResource, ClientType); - free((pointer) pCur); + pNext = pCur->next; + FreeResource(pCur->clientResource, ClientType); + free((pointer) pCur); } free((pointer) pHead); return 1; } static int -ProcShapeSelectInput (ClientPtr client) +ProcShapeSelectInput(ClientPtr client) { REQUEST(xShapeSelectInputReq); - WindowPtr pWin; - ShapeEventPtr pShapeEvent, pNewShapeEvent, *pHead; - XID clientResource; - int rc; + WindowPtr pWin; + ShapeEventPtr pShapeEvent, pNewShapeEvent, *pHead; + XID clientResource; + int rc; - REQUEST_SIZE_MATCH (xShapeSelectInputReq); + REQUEST_SIZE_MATCH(xShapeSelectInputReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixReceiveAccess); if (rc != Success) - return rc; - rc = dixLookupResourceByType((pointer *)&pHead, pWin->drawable.id, - ShapeEventType, client, DixWriteAccess); + return rc; + rc = dixLookupResourceByType((pointer *) &pHead, pWin->drawable.id, + ShapeEventType, client, DixWriteAccess); if (rc != Success && rc != BadValue) - return rc; + return rc; switch (stuff->enable) { case xTrue: - if (pHead) { - - /* check for existing entry. */ - for (pShapeEvent = *pHead; - pShapeEvent; - pShapeEvent = pShapeEvent->next) - { - if (pShapeEvent->client == client) - return Success; - } - } - - /* build the entry */ - pNewShapeEvent = malloc(sizeof (ShapeEventRec)); - if (!pNewShapeEvent) - return BadAlloc; - pNewShapeEvent->next = 0; - pNewShapeEvent->client = client; - pNewShapeEvent->window = pWin; - /* - * add a resource that will be deleted when - * the client goes away - */ - clientResource = FakeClientID (client->index); - pNewShapeEvent->clientResource = clientResource; - if (!AddResource (clientResource, ClientType, (pointer)pNewShapeEvent)) - return BadAlloc; - /* - * create a resource to contain a pointer to the list - * of clients selecting input. This must be indirect as - * the list may be arbitrarily rearranged which cannot be - * done through the resource database. - */ - if (!pHead) - { - pHead = malloc(sizeof (ShapeEventPtr)); - if (!pHead || - !AddResource (pWin->drawable.id, ShapeEventType, (pointer)pHead)) - { - FreeResource (clientResource, RT_NONE); - return BadAlloc; - } - *pHead = 0; - } - pNewShapeEvent->next = *pHead; - *pHead = pNewShapeEvent; - break; + if (pHead) { + + /* check for existing entry. */ + for (pShapeEvent = *pHead; + pShapeEvent; pShapeEvent = pShapeEvent->next) { + if (pShapeEvent->client == client) + return Success; + } + } + + /* build the entry */ + pNewShapeEvent = malloc(sizeof(ShapeEventRec)); + if (!pNewShapeEvent) + return BadAlloc; + pNewShapeEvent->next = 0; + pNewShapeEvent->client = client; + pNewShapeEvent->window = pWin; + /* + * add a resource that will be deleted when + * the client goes away + */ + clientResource = FakeClientID(client->index); + pNewShapeEvent->clientResource = clientResource; + if (!AddResource(clientResource, ClientType, (pointer) pNewShapeEvent)) + return BadAlloc; + /* + * create a resource to contain a pointer to the list + * of clients selecting input. This must be indirect as + * the list may be arbitrarily rearranged which cannot be + * done through the resource database. + */ + if (!pHead) { + pHead = malloc(sizeof(ShapeEventPtr)); + if (!pHead || + !AddResource(pWin->drawable.id, ShapeEventType, + (pointer) pHead)) { + FreeResource(clientResource, RT_NONE); + return BadAlloc; + } + *pHead = 0; + } + pNewShapeEvent->next = *pHead; + *pHead = pNewShapeEvent; + break; case xFalse: - /* delete the interest */ - if (pHead) { - pNewShapeEvent = 0; - for (pShapeEvent = *pHead; pShapeEvent; pShapeEvent = pShapeEvent->next) { - if (pShapeEvent->client == client) - break; - pNewShapeEvent = pShapeEvent; - } - if (pShapeEvent) { - FreeResource (pShapeEvent->clientResource, ClientType); - if (pNewShapeEvent) - pNewShapeEvent->next = pShapeEvent->next; - else - *pHead = pShapeEvent->next; - free(pShapeEvent); - } - } - break; + /* delete the interest */ + if (pHead) { + pNewShapeEvent = 0; + for (pShapeEvent = *pHead; pShapeEvent; + pShapeEvent = pShapeEvent->next) { + if (pShapeEvent->client == client) + break; + pNewShapeEvent = pShapeEvent; + } + if (pShapeEvent) { + FreeResource(pShapeEvent->clientResource, ClientType); + if (pNewShapeEvent) + pNewShapeEvent->next = pShapeEvent->next; + else + *pHead = pShapeEvent->next; + free(pShapeEvent); + } + } + break; default: - client->errorValue = stuff->enable; - return BadValue; + client->errorValue = stuff->enable; + return BadValue; } return Success; } @@ -837,394 +823,398 @@ ProcShapeSelectInput (ClientPtr client) */ void -SendShapeNotify (WindowPtr pWin, int which) +SendShapeNotify(WindowPtr pWin, int which) { - ShapeEventPtr *pHead, pShapeEvent; - xShapeNotifyEvent se; - BoxRec extents; - RegionPtr region; - BYTE shaped; + ShapeEventPtr *pHead, pShapeEvent; + xShapeNotifyEvent se; + BoxRec extents; + RegionPtr region; + BYTE shaped; int rc; - rc = dixLookupResourceByType((pointer *)&pHead, pWin->drawable.id, - ShapeEventType, serverClient, DixReadAccess); + rc = dixLookupResourceByType((pointer *) &pHead, pWin->drawable.id, + ShapeEventType, serverClient, DixReadAccess); if (rc != Success) - return; + return; switch (which) { case ShapeBounding: - region = wBoundingShape(pWin); - if (region) { - extents = *RegionExtents(region); - shaped = xTrue; - } else { - extents.x1 = -wBorderWidth (pWin); - extents.y1 = -wBorderWidth (pWin); - extents.x2 = pWin->drawable.width + wBorderWidth (pWin); - extents.y2 = pWin->drawable.height + wBorderWidth (pWin); - shaped = xFalse; - } - break; + region = wBoundingShape(pWin); + if (region) { + extents = *RegionExtents(region); + shaped = xTrue; + } + else { + extents.x1 = -wBorderWidth(pWin); + extents.y1 = -wBorderWidth(pWin); + extents.x2 = pWin->drawable.width + wBorderWidth(pWin); + extents.y2 = pWin->drawable.height + wBorderWidth(pWin); + shaped = xFalse; + } + break; case ShapeClip: - region = wClipShape(pWin); - if (region) { - extents = *RegionExtents(region); - shaped = xTrue; - } else { - extents.x1 = 0; - extents.y1 = 0; - extents.x2 = pWin->drawable.width; - extents.y2 = pWin->drawable.height; - shaped = xFalse; - } - break; + region = wClipShape(pWin); + if (region) { + extents = *RegionExtents(region); + shaped = xTrue; + } + else { + extents.x1 = 0; + extents.y1 = 0; + extents.x2 = pWin->drawable.width; + extents.y2 = pWin->drawable.height; + shaped = xFalse; + } + break; case ShapeInput: - region = wInputShape(pWin); - if (region) { - extents = *RegionExtents(region); - shaped = xTrue; - } else { - extents.x1 = -wBorderWidth (pWin); - extents.y1 = -wBorderWidth (pWin); - extents.x2 = pWin->drawable.width + wBorderWidth (pWin); - extents.y2 = pWin->drawable.height + wBorderWidth (pWin); - shaped = xFalse; - } - break; + region = wInputShape(pWin); + if (region) { + extents = *RegionExtents(region); + shaped = xTrue; + } + else { + extents.x1 = -wBorderWidth(pWin); + extents.y1 = -wBorderWidth(pWin); + extents.x2 = pWin->drawable.width + wBorderWidth(pWin); + extents.y2 = pWin->drawable.height + wBorderWidth(pWin); + shaped = xFalse; + } + break; default: - return; + return; } for (pShapeEvent = *pHead; pShapeEvent; pShapeEvent = pShapeEvent->next) { - se.type = ShapeNotify + ShapeEventBase; - se.kind = which; - se.window = pWin->drawable.id; - se.x = extents.x1; - se.y = extents.y1; - se.width = extents.x2 - extents.x1; - se.height = extents.y2 - extents.y1; - se.time = currentTime.milliseconds; - se.shaped = shaped; - WriteEventsToClient (pShapeEvent->client, 1, (xEvent *) &se); + se.type = ShapeNotify + ShapeEventBase; + se.kind = which; + se.window = pWin->drawable.id; + se.x = extents.x1; + se.y = extents.y1; + se.width = extents.x2 - extents.x1; + se.height = extents.y2 - extents.y1; + se.time = currentTime.milliseconds; + se.shaped = shaped; + WriteEventsToClient(pShapeEvent->client, 1, (xEvent *) &se); } } static int -ProcShapeInputSelected (ClientPtr client) +ProcShapeInputSelected(ClientPtr client) { REQUEST(xShapeInputSelectedReq); - WindowPtr pWin; - ShapeEventPtr pShapeEvent, *pHead; - int enabled, rc; - xShapeInputSelectedReply rep; - REQUEST_SIZE_MATCH (xShapeInputSelectedReq); + WindowPtr pWin; + ShapeEventPtr pShapeEvent, *pHead; + int enabled, rc; + xShapeInputSelectedReply rep; + + REQUEST_SIZE_MATCH(xShapeInputSelectedReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); if (rc != Success) - return rc; - rc = dixLookupResourceByType((pointer *)&pHead, pWin->drawable.id, - ShapeEventType, client, DixReadAccess); + return rc; + rc = dixLookupResourceByType((pointer *) &pHead, pWin->drawable.id, + ShapeEventType, client, DixReadAccess); if (rc != Success && rc != BadValue) - return rc; + return rc; enabled = xFalse; if (pHead) { - for (pShapeEvent = *pHead; - pShapeEvent; - pShapeEvent = pShapeEvent->next) - { - if (pShapeEvent->client == client) { - enabled = xTrue; - break; - } - } + for (pShapeEvent = *pHead; pShapeEvent; pShapeEvent = pShapeEvent->next) { + if (pShapeEvent->client == client) { + enabled = xTrue; + break; + } + } } rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; rep.enabled = enabled; if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); + swaps(&rep.sequenceNumber); + swapl(&rep.length); } - WriteToClient (client, sizeof (xShapeInputSelectedReply), (char *) &rep); + WriteToClient(client, sizeof(xShapeInputSelectedReply), (char *) &rep); return Success; } static int -ProcShapeGetRectangles (ClientPtr client) +ProcShapeGetRectangles(ClientPtr client) { REQUEST(xShapeGetRectanglesReq); - WindowPtr pWin; - xShapeGetRectanglesReply rep; - xRectangle *rects; - int nrects, i, rc; - RegionPtr region; + WindowPtr pWin; + xShapeGetRectanglesReply rep; + xRectangle *rects; + int nrects, i, rc; + RegionPtr region; + REQUEST_SIZE_MATCH(xShapeGetRectanglesReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; switch (stuff->kind) { case ShapeBounding: - region = wBoundingShape(pWin); - break; + region = wBoundingShape(pWin); + break; case ShapeClip: - region = wClipShape(pWin); - break; + region = wClipShape(pWin); + break; case ShapeInput: - region = wInputShape (pWin); - break; + region = wInputShape(pWin); + break; default: - client->errorValue = stuff->kind; - return BadValue; + client->errorValue = stuff->kind; + return BadValue; } if (!region) { - nrects = 1; - rects = malloc(sizeof (xRectangle)); - if (!rects) - return BadAlloc; - switch (stuff->kind) { - case ShapeBounding: - rects->x = - (int) wBorderWidth (pWin); - rects->y = - (int) wBorderWidth (pWin); - rects->width = pWin->drawable.width + wBorderWidth (pWin); - rects->height = pWin->drawable.height + wBorderWidth (pWin); - break; - case ShapeClip: - rects->x = 0; - rects->y = 0; - rects->width = pWin->drawable.width; - rects->height = pWin->drawable.height; - break; - case ShapeInput: - rects->x = - (int) wBorderWidth (pWin); - rects->y = - (int) wBorderWidth (pWin); - rects->width = pWin->drawable.width + wBorderWidth (pWin); - rects->height = pWin->drawable.height + wBorderWidth (pWin); - break; - } - } else { - BoxPtr box; - nrects = RegionNumRects(region); - box = RegionRects(region); - rects = malloc(nrects * sizeof (xRectangle)); - if (!rects && nrects) - return BadAlloc; - for (i = 0; i < nrects; i++, box++) { - rects[i].x = box->x1; - rects[i].y = box->y1; - rects[i].width = box->x2 - box->x1; - rects[i].height = box->y2 - box->y1; - } + nrects = 1; + rects = malloc(sizeof(xRectangle)); + if (!rects) + return BadAlloc; + switch (stuff->kind) { + case ShapeBounding: + rects->x = -(int) wBorderWidth(pWin); + rects->y = -(int) wBorderWidth(pWin); + rects->width = pWin->drawable.width + wBorderWidth(pWin); + rects->height = pWin->drawable.height + wBorderWidth(pWin); + break; + case ShapeClip: + rects->x = 0; + rects->y = 0; + rects->width = pWin->drawable.width; + rects->height = pWin->drawable.height; + break; + case ShapeInput: + rects->x = -(int) wBorderWidth(pWin); + rects->y = -(int) wBorderWidth(pWin); + rects->width = pWin->drawable.width + wBorderWidth(pWin); + rects->height = pWin->drawable.height + wBorderWidth(pWin); + break; + } + } + else { + BoxPtr box; + + nrects = RegionNumRects(region); + box = RegionRects(region); + rects = malloc(nrects * sizeof(xRectangle)); + if (!rects && nrects) + return BadAlloc; + for (i = 0; i < nrects; i++, box++) { + rects[i].x = box->x1; + rects[i].y = box->y1; + rects[i].width = box->x2 - box->x1; + rects[i].height = box->y2 - box->y1; + } } rep.type = X_Reply; rep.sequenceNumber = client->sequence; - rep.length = bytes_to_int32(nrects * sizeof (xRectangle)); + rep.length = bytes_to_int32(nrects * sizeof(xRectangle)); rep.ordering = YXBanded; rep.nrects = nrects; if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.nrects); - SwapShorts ((short *)rects, (unsigned long)nrects * 4); + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.nrects); + SwapShorts((short *) rects, (unsigned long) nrects * 4); } - WriteToClient (client, sizeof (rep), (char *) &rep); - WriteToClient (client, nrects * sizeof (xRectangle), (char *) rects); + WriteToClient(client, sizeof(rep), (char *) &rep); + WriteToClient(client, nrects * sizeof(xRectangle), (char *) rects); free(rects); return Success; } static int -ProcShapeDispatch (ClientPtr client) +ProcShapeDispatch(ClientPtr client) { REQUEST(xReq); switch (stuff->data) { case X_ShapeQueryVersion: - return ProcShapeQueryVersion (client); + return ProcShapeQueryVersion(client); case X_ShapeRectangles: #ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShapeRectangles (client); - else + if (!noPanoramiXExtension) + return ProcPanoramiXShapeRectangles(client); + else #endif - return ProcShapeRectangles (client); + return ProcShapeRectangles(client); case X_ShapeMask: #ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShapeMask (client); - else + if (!noPanoramiXExtension) + return ProcPanoramiXShapeMask(client); + else #endif - return ProcShapeMask (client); + return ProcShapeMask(client); case X_ShapeCombine: #ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShapeCombine (client); - else + if (!noPanoramiXExtension) + return ProcPanoramiXShapeCombine(client); + else #endif - return ProcShapeCombine (client); + return ProcShapeCombine(client); case X_ShapeOffset: #ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShapeOffset (client); - else + if (!noPanoramiXExtension) + return ProcPanoramiXShapeOffset(client); + else #endif - return ProcShapeOffset (client); + return ProcShapeOffset(client); case X_ShapeQueryExtents: - return ProcShapeQueryExtents (client); + return ProcShapeQueryExtents(client); case X_ShapeSelectInput: - return ProcShapeSelectInput (client); + return ProcShapeSelectInput(client); case X_ShapeInputSelected: - return ProcShapeInputSelected (client); + return ProcShapeInputSelected(client); case X_ShapeGetRectangles: - return ProcShapeGetRectangles (client); + return ProcShapeGetRectangles(client); default: - return BadRequest; + return BadRequest; } } static void -SShapeNotifyEvent(xShapeNotifyEvent *from, xShapeNotifyEvent *to) +SShapeNotifyEvent(xShapeNotifyEvent * from, xShapeNotifyEvent * to) { to->type = from->type; to->kind = from->kind; - cpswapl (from->window, to->window); - cpswaps (from->sequenceNumber, to->sequenceNumber); - cpswaps (from->x, to->x); - cpswaps (from->y, to->y); - cpswaps (from->width, to->width); - cpswaps (from->height, to->height); - cpswapl (from->time, to->time); + cpswapl(from->window, to->window); + cpswaps(from->sequenceNumber, to->sequenceNumber); + cpswaps(from->x, to->x); + cpswaps(from->y, to->y); + cpswaps(from->width, to->width); + cpswaps(from->height, to->height); + cpswapl(from->time, to->time); to->shaped = from->shaped; } static int -SProcShapeQueryVersion (ClientPtr client) +SProcShapeQueryVersion(ClientPtr client) { - REQUEST (xShapeQueryVersionReq); + REQUEST(xShapeQueryVersionReq); swaps(&stuff->length); - return ProcShapeQueryVersion (client); + return ProcShapeQueryVersion(client); } static int -SProcShapeRectangles (ClientPtr client) +SProcShapeRectangles(ClientPtr client) { - REQUEST (xShapeRectanglesReq); + REQUEST(xShapeRectanglesReq); swaps(&stuff->length); - REQUEST_AT_LEAST_SIZE (xShapeRectanglesReq); + REQUEST_AT_LEAST_SIZE(xShapeRectanglesReq); swapl(&stuff->dest); swaps(&stuff->xOff); swaps(&stuff->yOff); SwapRestS(stuff); - return ProcShapeRectangles (client); + return ProcShapeRectangles(client); } static int -SProcShapeMask (ClientPtr client) +SProcShapeMask(ClientPtr client) { - REQUEST (xShapeMaskReq); + REQUEST(xShapeMaskReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xShapeMaskReq); + REQUEST_SIZE_MATCH(xShapeMaskReq); swapl(&stuff->dest); swaps(&stuff->xOff); swaps(&stuff->yOff); swapl(&stuff->src); - return ProcShapeMask (client); + return ProcShapeMask(client); } static int -SProcShapeCombine (ClientPtr client) +SProcShapeCombine(ClientPtr client) { - REQUEST (xShapeCombineReq); + REQUEST(xShapeCombineReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xShapeCombineReq); + REQUEST_SIZE_MATCH(xShapeCombineReq); swapl(&stuff->dest); swaps(&stuff->xOff); swaps(&stuff->yOff); swapl(&stuff->src); - return ProcShapeCombine (client); + return ProcShapeCombine(client); } static int -SProcShapeOffset (ClientPtr client) +SProcShapeOffset(ClientPtr client) { - REQUEST (xShapeOffsetReq); + REQUEST(xShapeOffsetReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xShapeOffsetReq); + REQUEST_SIZE_MATCH(xShapeOffsetReq); swapl(&stuff->dest); swaps(&stuff->xOff); swaps(&stuff->yOff); - return ProcShapeOffset (client); + return ProcShapeOffset(client); } static int -SProcShapeQueryExtents (ClientPtr client) +SProcShapeQueryExtents(ClientPtr client) { - REQUEST (xShapeQueryExtentsReq); + REQUEST(xShapeQueryExtentsReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xShapeQueryExtentsReq); + REQUEST_SIZE_MATCH(xShapeQueryExtentsReq); swapl(&stuff->window); - return ProcShapeQueryExtents (client); + return ProcShapeQueryExtents(client); } static int -SProcShapeSelectInput (ClientPtr client) +SProcShapeSelectInput(ClientPtr client) { - REQUEST (xShapeSelectInputReq); + REQUEST(xShapeSelectInputReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xShapeSelectInputReq); + REQUEST_SIZE_MATCH(xShapeSelectInputReq); swapl(&stuff->window); - return ProcShapeSelectInput (client); + return ProcShapeSelectInput(client); } static int -SProcShapeInputSelected (ClientPtr client) +SProcShapeInputSelected(ClientPtr client) { - REQUEST (xShapeInputSelectedReq); + REQUEST(xShapeInputSelectedReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xShapeInputSelectedReq); + REQUEST_SIZE_MATCH(xShapeInputSelectedReq); swapl(&stuff->window); - return ProcShapeInputSelected (client); + return ProcShapeInputSelected(client); } static int -SProcShapeGetRectangles (ClientPtr client) +SProcShapeGetRectangles(ClientPtr client) { REQUEST(xShapeGetRectanglesReq); swaps(&stuff->length); REQUEST_SIZE_MATCH(xShapeGetRectanglesReq); swapl(&stuff->window); - return ProcShapeGetRectangles (client); + return ProcShapeGetRectangles(client); } static int -SProcShapeDispatch (ClientPtr client) +SProcShapeDispatch(ClientPtr client) { REQUEST(xReq); switch (stuff->data) { case X_ShapeQueryVersion: - return SProcShapeQueryVersion (client); + return SProcShapeQueryVersion(client); case X_ShapeRectangles: - return SProcShapeRectangles (client); + return SProcShapeRectangles(client); case X_ShapeMask: - return SProcShapeMask (client); + return SProcShapeMask(client); case X_ShapeCombine: - return SProcShapeCombine (client); + return SProcShapeCombine(client); case X_ShapeOffset: - return SProcShapeOffset (client); + return SProcShapeOffset(client); case X_ShapeQueryExtents: - return SProcShapeQueryExtents (client); + return SProcShapeQueryExtents(client); case X_ShapeSelectInput: - return SProcShapeSelectInput (client); + return SProcShapeSelectInput(client); case X_ShapeInputSelected: - return SProcShapeInputSelected (client); + return SProcShapeInputSelected(client); case X_ShapeGetRectangles: - return SProcShapeGetRectangles (client); + return SProcShapeGetRectangles(client); default: - return BadRequest; + return BadRequest; } } @@ -1236,11 +1226,10 @@ ShapeExtensionInit(void) ClientType = CreateNewResourceType(ShapeFreeClient, "ShapeClient"); ShapeEventType = CreateNewResourceType(ShapeFreeEvents, "ShapeEvent"); if (ClientType && ShapeEventType && - (extEntry = AddExtension(SHAPENAME, ShapeNumberEvents, 0, - ProcShapeDispatch, SProcShapeDispatch, - NULL, StandardMinorOpcode))) - { - ShapeEventBase = extEntry->eventBase; - EventSwapVector[ShapeEventBase] = (EventSwapPtr) SShapeNotifyEvent; + (extEntry = AddExtension(SHAPENAME, ShapeNumberEvents, 0, + ProcShapeDispatch, SProcShapeDispatch, + NULL, StandardMinorOpcode))) { + ShapeEventBase = extEntry->eventBase; + EventSwapVector[ShapeEventBase] = (EventSwapPtr) SShapeNotifyEvent; } } diff --git a/xorg-server/Xext/shm.c b/xorg-server/Xext/shm.c index 2127dee3e..7a73640dd 100644 --- a/xorg-server/Xext/shm.c +++ b/xorg-server/Xext/shm.c @@ -26,7 +26,6 @@ in this Software without prior written authorization from The Open Group. /* THIS IS NOT AN X CONSORTIUM STANDARD OR AN X PROJECT TEAM SPECIFICATION */ - #define SHM #ifdef HAVE_DIX_CONFIG_H @@ -108,20 +107,16 @@ typedef struct _ShmScrPrivateRec { } ShmScrPrivateRec; static PixmapPtr fbShmCreatePixmap(XSHM_CREATE_PIXMAP_ARGS); -static int ShmDetachSegment( - pointer /* value */, - XID /* shmseg */ +static int ShmDetachSegment(pointer /* value */ , + XID /* shmseg */ ); -static void ShmResetProc( - ExtensionEntry * /* extEntry */ +static void ShmResetProc(ExtensionEntry * /* extEntry */ ); -static void SShmCompletionEvent( - xShmCompletionEvent * /* from */, - xShmCompletionEvent * /* to */ +static void SShmCompletionEvent(xShmCompletionEvent * /* from */ , + xShmCompletionEvent * /* to */ ); -static Bool ShmDestroyPixmap (PixmapPtr pPixmap); - +static Bool ShmDestroyPixmap(PixmapPtr pPixmap); static unsigned char ShmReqCode; int ShmCompletionCode; @@ -130,11 +125,13 @@ RESTYPE ShmSegType; static ShmDescPtr Shmsegs; static Bool sharedPixmaps; static DevPrivateKeyRec shmScrPrivateKeyRec; + #define shmScrPrivateKey (&shmScrPrivateKeyRec) static DevPrivateKeyRec shmPixmapPrivateKeyRec; + #define shmPixmapPrivateKey (&shmPixmapPrivateKeyRec) -static ShmFuncs miFuncs = {NULL, NULL}; -static ShmFuncs fbFuncs = {fbShmCreatePixmap, NULL}; +static ShmFuncs miFuncs = { NULL, NULL }; +static ShmFuncs fbFuncs = { fbShmCreatePixmap, NULL }; #define ShmGetScreenPriv(s) ((ShmScrPrivateRec *)dixLookupPrivate(&(s)->devPrivates, shmScrPrivateKey)) @@ -167,7 +164,6 @@ static ShmFuncs fbFuncs = {fbShmCreatePixmap, NULL}; } \ } - #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) || defined(__DragonFly__) #include <sys/signal.h> @@ -179,9 +175,10 @@ SigSysHandler(int signo) badSysCall = TRUE; } -static Bool CheckForShmSyscall(void) +static Bool +CheckForShmSyscall(void) { - void (*oldHandler)(int); + void (*oldHandler) (int); int shmid = -1; /* If no SHM support in the kernel, the bad syscall will generate SIGSYS */ @@ -190,13 +187,11 @@ static Bool CheckForShmSyscall(void) badSysCall = FALSE; shmid = shmget(IPC_PRIVATE, 4096, IPC_CREAT); - if (shmid != -1) - { + if (shmid != -1) { /* Successful allocation - clean up */ - shmctl(shmid, IPC_RMID, NULL); + shmctl(shmid, IPC_RMID, NULL); } - else - { + else { /* Allocation failed */ badSysCall = TRUE; } @@ -212,6 +207,7 @@ static Bool ShmCloseScreen(int i, ScreenPtr pScreen) { ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(pScreen); + pScreen->CloseScreen = screen_priv->CloseScreen; dixSetPrivate(&pScreen->devPrivates, shmScrPrivateKey, NULL); free(screen_priv); @@ -222,12 +218,12 @@ static ShmScrPrivateRec * ShmInitScreenPriv(ScreenPtr pScreen) { ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(pScreen); - if (!screen_priv) - { - screen_priv = calloc(1, sizeof (ShmScrPrivateRec)); - screen_priv->CloseScreen = pScreen->CloseScreen; - dixSetPrivate(&pScreen->devPrivates, shmScrPrivateKey, screen_priv); - pScreen->CloseScreen = ShmCloseScreen; + + if (!screen_priv) { + screen_priv = calloc(1, sizeof(ShmScrPrivateRec)); + screen_priv->CloseScreen = pScreen->CloseScreen; + dixSetPrivate(&pScreen->devPrivates, shmScrPrivateKey, screen_priv); + pScreen->CloseScreen = ShmCloseScreen; } return screen_priv; } @@ -236,44 +232,45 @@ static Bool ShmRegisterPrivates(void) { if (!dixRegisterPrivateKey(&shmScrPrivateKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; + return FALSE; if (!dixRegisterPrivateKey(&shmPixmapPrivateKeyRec, PRIVATE_PIXMAP, 0)) - return FALSE; + return FALSE; return TRUE; } -/*ARGSUSED*/ -static void -ShmResetProc(ExtensionEntry *extEntry) + /*ARGSUSED*/ static void +ShmResetProc(ExtensionEntry * extEntry) { int i; + for (i = 0; i < screenInfo.numScreens; i++) - ShmRegisterFuncs(screenInfo.screens[i], NULL); + ShmRegisterFuncs(screenInfo.screens[i], NULL); } void ShmRegisterFuncs(ScreenPtr pScreen, ShmFuncsPtr funcs) { if (!ShmRegisterPrivates()) - return; + return; ShmInitScreenPriv(pScreen)->shmFuncs = funcs; } static Bool -ShmDestroyPixmap (PixmapPtr pPixmap) +ShmDestroyPixmap(PixmapPtr pPixmap) { - ScreenPtr pScreen = pPixmap->drawable.pScreen; + ScreenPtr pScreen = pPixmap->drawable.pScreen; ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(pScreen); - Bool ret; - if (pPixmap->refcnt == 1) - { - ShmDescPtr shmdesc; - shmdesc = (ShmDescPtr)dixLookupPrivate(&pPixmap->devPrivates, - shmPixmapPrivateKey); - if (shmdesc) - ShmDetachSegment ((pointer) shmdesc, pPixmap->drawable.id); + Bool ret; + + if (pPixmap->refcnt == 1) { + ShmDescPtr shmdesc; + + shmdesc = (ShmDescPtr) dixLookupPrivate(&pPixmap->devPrivates, + shmPixmapPrivateKey); + if (shmdesc) + ShmDetachSegment((pointer) shmdesc, pPixmap->drawable.id); } - + pScreen->DestroyPixmap = screen_priv->destroyPixmap; ret = (*pScreen->DestroyPixmap) (pPixmap); screen_priv->destroyPixmap = pScreen->DestroyPixmap; @@ -306,14 +303,14 @@ ProcShmQueryVersion(ClientPtr client) rep.gid = getegid(); #endif if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swaps(&rep.majorVersion); - swaps(&rep.minorVersion); - swaps(&rep.uid); - swaps(&rep.gid); + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swaps(&rep.majorVersion); + swaps(&rep.minorVersion); + swaps(&rep.uid); + swaps(&rep.gid); } - WriteToClient(client, sizeof(xShmQueryVersionReply), (char *)&rep); + WriteToClient(client, sizeof(xShmQueryVersionReply), (char *) &rep); return Success; } @@ -322,66 +319,66 @@ ProcShmQueryVersion(ClientPtr client) * using the credentials from the client if available */ static int -shm_access(ClientPtr client, SHMPERM_TYPE *perm, int readonly) +shm_access(ClientPtr client, SHMPERM_TYPE * perm, int readonly) { int uid, gid; mode_t mask; int uidset = 0, gidset = 0; LocalClientCredRec *lcc; - + if (GetLocalClientCreds(client, &lcc) != -1) { - if (lcc->fieldsSet & LCC_UID_SET) { - uid = lcc->euid; - uidset = 1; - } - if (lcc->fieldsSet & LCC_GID_SET) { - gid = lcc->egid; - gidset = 1; - } + if (lcc->fieldsSet & LCC_UID_SET) { + uid = lcc->euid; + uidset = 1; + } + if (lcc->fieldsSet & LCC_GID_SET) { + gid = lcc->egid; + gidset = 1; + } #if defined(HAVE_GETZONEID) && defined(SHMPERM_ZONEID) - if ( ((lcc->fieldsSet & LCC_ZID_SET) == 0) || (lcc->zoneid == -1) - || (lcc->zoneid != SHMPERM_ZONEID(perm))) { - uidset = 0; - gidset = 0; - } + if (((lcc->fieldsSet & LCC_ZID_SET) == 0) || (lcc->zoneid == -1) + || (lcc->zoneid != SHMPERM_ZONEID(perm))) { + uidset = 0; + gidset = 0; + } #endif - FreeLocalClientCreds(lcc); - - if (uidset) { - /* User id 0 always gets access */ - if (uid == 0) { - return 0; - } + FreeLocalClientCreds(lcc); + + if (uidset) { + /* User id 0 always gets access */ + if (uid == 0) { + return 0; + } #ifdef _MSC_VER __asm int 3; #else - /* Check the owner */ - if (SHMPERM_UID(perm) == uid || SHMPERM_CUID(perm) == uid) { - mask = S_IRUSR; - if (!readonly) { - mask |= S_IWUSR; - } - return (SHMPERM_MODE(perm) & mask) == mask ? 0 : -1; - } + /* Check the owner */ + if (SHMPERM_UID(perm) == uid || SHMPERM_CUID(perm) == uid) { + mask = S_IRUSR; + if (!readonly) { + mask |= S_IWUSR; + } + return (SHMPERM_MODE(perm) & mask) == mask ? 0 : -1; + } #endif - } + } - if (gidset) { - /* Check the group */ + if (gidset) { + /* Check the group */ #ifdef _MSC_VER __asm int 3; #else - if (SHMPERM_GID(perm) == gid || SHMPERM_CGID(perm) == gid) { - mask = S_IRGRP; - if (!readonly) { - mask |= S_IWGRP; - } - return (SHMPERM_MODE(perm) & mask) == mask ? 0 : -1; - } + if (SHMPERM_GID(perm) == gid || SHMPERM_CGID(perm) == gid) { + mask = S_IRGRP; + if (!readonly) { + mask |= S_IWGRP; + } + return (SHMPERM_MODE(perm) & mask) == mask ? 0 : -1; + } #endif - } + } } #ifdef _MSC_VER __asm int 3; @@ -390,7 +387,7 @@ shm_access(ClientPtr client, SHMPERM_TYPE *perm, int readonly) /* Otherwise, check everyone else */ mask = S_IROTH; if (!readonly) { - mask |= S_IWOTH; + mask |= S_IWOTH; } return (SHMPERM_MODE(perm) & mask) == mask ? 0 : -1; #endif @@ -401,76 +398,68 @@ ProcShmAttach(ClientPtr client) { SHMSTAT_TYPE buf; ShmDescPtr shmdesc; + REQUEST(xShmAttachReq); REQUEST_SIZE_MATCH(xShmAttachReq); LEGAL_NEW_RESOURCE(stuff->shmseg, client); - if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) - { - client->errorValue = stuff->readOnly; + if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) { + client->errorValue = stuff->readOnly; return BadValue; } for (shmdesc = Shmsegs; - shmdesc && (shmdesc->shmid != stuff->shmid); - shmdesc = shmdesc->next) - ; - if (shmdesc) - { - if (!stuff->readOnly && !shmdesc->writable) - return BadAccess; - shmdesc->refcnt++; + shmdesc && (shmdesc->shmid != stuff->shmid); shmdesc = shmdesc->next); + if (shmdesc) { + if (!stuff->readOnly && !shmdesc->writable) + return BadAccess; + shmdesc->refcnt++; } - else - { - shmdesc = malloc(sizeof(ShmDescRec)); - if (!shmdesc) - return BadAlloc; - shmdesc->addr = shmat(stuff->shmid, 0, - stuff->readOnly ? SHM_RDONLY : 0); - if ((shmdesc->addr == ((char *)-1)) || - SHMSTAT(stuff->shmid, &buf)) - { - free(shmdesc); - return BadAccess; - } - - /* The attach was performed with root privs. We must - * do manual checking of access rights for the credentials - * of the client */ - - if (shm_access(client, &(SHM_PERM(buf)), stuff->readOnly) == -1) { - shmdt(shmdesc->addr); - free(shmdesc); - return BadAccess; - } - - shmdesc->shmid = stuff->shmid; - shmdesc->refcnt = 1; - shmdesc->writable = !stuff->readOnly; - shmdesc->size = SHM_SEGSZ(buf); - shmdesc->next = Shmsegs; - Shmsegs = shmdesc; + else { + shmdesc = malloc(sizeof(ShmDescRec)); + if (!shmdesc) + return BadAlloc; + shmdesc->addr = shmat(stuff->shmid, 0, + stuff->readOnly ? SHM_RDONLY : 0); + if ((shmdesc->addr == ((char *) -1)) || SHMSTAT(stuff->shmid, &buf)) { + free(shmdesc); + return BadAccess; + } + + /* The attach was performed with root privs. We must + * do manual checking of access rights for the credentials + * of the client */ + + if (shm_access(client, &(SHM_PERM(buf)), stuff->readOnly) == -1) { + shmdt(shmdesc->addr); + free(shmdesc); + return BadAccess; + } + + shmdesc->shmid = stuff->shmid; + shmdesc->refcnt = 1; + shmdesc->writable = !stuff->readOnly; + shmdesc->size = SHM_SEGSZ(buf); + shmdesc->next = Shmsegs; + Shmsegs = shmdesc; } - if (!AddResource(stuff->shmseg, ShmSegType, (pointer)shmdesc)) - return BadAlloc; + if (!AddResource(stuff->shmseg, ShmSegType, (pointer) shmdesc)) + return BadAlloc; return Success; } -/*ARGSUSED*/ -static int + /*ARGSUSED*/ static int ShmDetachSegment(pointer value, /* must conform to DeleteType */ - XID shmseg) + XID shmseg) { - ShmDescPtr shmdesc = (ShmDescPtr)value; + ShmDescPtr shmdesc = (ShmDescPtr) value; ShmDescPtr *prev; if (--shmdesc->refcnt) - return TRUE; + return TRUE; #ifndef _MSC_VER shmdt(shmdesc->addr); #endif - for (prev = &Shmsegs; *prev != shmdesc; prev = &(*prev)->next) - ; + for (prev = &Shmsegs; *prev != shmdesc; prev = &(*prev)->next); *prev = shmdesc->next; free(shmdesc); return Success; @@ -480,6 +469,7 @@ static int ProcShmDetach(ClientPtr client) { ShmDescPtr shmdesc; + REQUEST(xShmDetachReq); REQUEST_SIZE_MATCH(xShmDetachReq); @@ -494,44 +484,47 @@ ProcShmDetach(ClientPtr client) */ static void doShmPutImage(DrawablePtr dst, GCPtr pGC, - int depth, unsigned int format, - int w, int h, int sx, int sy, int sw, int sh, int dx, int dy, - char *data) + int depth, unsigned int format, + int w, int h, int sx, int sy, int sw, int sh, int dx, int dy, + char *data) { PixmapPtr pPixmap; if (format == ZPixmap || (format == XYPixmap && depth == 1)) { - pPixmap = GetScratchPixmapHeader(dst->pScreen, w, h, depth, - BitsPerPixel(depth), - PixmapBytePad(w, depth), - data); - if (!pPixmap) - return; - pGC->ops->CopyArea((DrawablePtr)pPixmap, dst, pGC, sx, sy, sw, sh, dx, dy); - FreeScratchPixmapHeader(pPixmap); - } else { - GCPtr putGC = GetScratchGC(depth, dst->pScreen); - - if (!putGC) - return; - - pPixmap = (*dst->pScreen->CreatePixmap)(dst->pScreen, sw, sh, depth, - CREATE_PIXMAP_USAGE_SCRATCH); - if (!pPixmap) { - FreeScratchGC(putGC); - return; - } - ValidateGC(&pPixmap->drawable, putGC); - (*putGC->ops->PutImage)(&pPixmap->drawable, putGC, depth, -sx, -sy, w, h, 0, - (format == XYPixmap) ? XYPixmap : ZPixmap, data); - FreeScratchGC(putGC); - if (format == XYBitmap) - (void)(*pGC->ops->CopyPlane)(&pPixmap->drawable, dst, pGC, 0, 0, sw, sh, - dx, dy, 1L); - else - (void)(*pGC->ops->CopyArea)(&pPixmap->drawable, dst, pGC, 0, 0, sw, sh, - dx, dy); - (*pPixmap->drawable.pScreen->DestroyPixmap)(pPixmap); + pPixmap = GetScratchPixmapHeader(dst->pScreen, w, h, depth, + BitsPerPixel(depth), + PixmapBytePad(w, depth), data); + if (!pPixmap) + return; + pGC->ops->CopyArea((DrawablePtr) pPixmap, dst, pGC, sx, sy, sw, sh, dx, + dy); + FreeScratchPixmapHeader(pPixmap); + } + else { + GCPtr putGC = GetScratchGC(depth, dst->pScreen); + + if (!putGC) + return; + + pPixmap = (*dst->pScreen->CreatePixmap) (dst->pScreen, sw, sh, depth, + CREATE_PIXMAP_USAGE_SCRATCH); + if (!pPixmap) { + FreeScratchGC(putGC); + return; + } + ValidateGC(&pPixmap->drawable, putGC); + (*putGC->ops->PutImage) (&pPixmap->drawable, putGC, depth, -sx, -sy, w, + h, 0, + (format == XYPixmap) ? XYPixmap : ZPixmap, + data); + FreeScratchGC(putGC); + if (format == XYBitmap) + (void) (*pGC->ops->CopyPlane) (&pPixmap->drawable, dst, pGC, 0, 0, + sw, sh, dx, dy, 1L); + else + (void) (*pGC->ops->CopyArea) (&pPixmap->drawable, dst, pGC, 0, 0, + sw, sh, dx, dy); + (*pPixmap->drawable.pScreen->DestroyPixmap) (pPixmap); } } @@ -542,35 +535,32 @@ ProcShmPutImage(ClientPtr client) DrawablePtr pDraw; long length; ShmDescPtr shmdesc; + REQUEST(xShmPutImageReq); REQUEST_SIZE_MATCH(xShmPutImageReq); VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); VERIFY_SHMPTR(stuff->shmseg, stuff->offset, FALSE, shmdesc, client); if ((stuff->sendEvent != xTrue) && (stuff->sendEvent != xFalse)) - return BadValue; - if (stuff->format == XYBitmap) - { + return BadValue; + if (stuff->format == XYBitmap) { if (stuff->depth != 1) return BadMatch; length = PixmapBytePad(stuff->totalWidth, 1); } - else if (stuff->format == XYPixmap) - { + else if (stuff->format == XYPixmap) { if (pDraw->depth != stuff->depth) return BadMatch; length = PixmapBytePad(stuff->totalWidth, 1); - length *= stuff->depth; + length *= stuff->depth; } - else if (stuff->format == ZPixmap) - { + else if (stuff->format == ZPixmap) { if (pDraw->depth != stuff->depth) return BadMatch; length = PixmapBytePad(stuff->totalWidth, stuff->depth); } - else - { - client->errorValue = stuff->format; + else { + client->errorValue = stuff->format; return BadValue; } @@ -581,63 +571,57 @@ ProcShmPutImage(ClientPtr client) * the version below ought to avoid it */ if (stuff->totalHeight != 0 && - length > (shmdesc->size - stuff->offset)/stuff->totalHeight) { - client->errorValue = stuff->totalWidth; - return BadValue; + length > (shmdesc->size - stuff->offset) / stuff->totalHeight) { + client->errorValue = stuff->totalWidth; + return BadValue; } - if (stuff->srcX > stuff->totalWidth) - { - client->errorValue = stuff->srcX; - return BadValue; + if (stuff->srcX > stuff->totalWidth) { + client->errorValue = stuff->srcX; + return BadValue; } - if (stuff->srcY > stuff->totalHeight) - { - client->errorValue = stuff->srcY; - return BadValue; + if (stuff->srcY > stuff->totalHeight) { + client->errorValue = stuff->srcY; + return BadValue; } - if ((stuff->srcX + stuff->srcWidth) > stuff->totalWidth) - { - client->errorValue = stuff->srcWidth; - return BadValue; + if ((stuff->srcX + stuff->srcWidth) > stuff->totalWidth) { + client->errorValue = stuff->srcWidth; + return BadValue; } - if ((stuff->srcY + stuff->srcHeight) > stuff->totalHeight) - { - client->errorValue = stuff->srcHeight; - return BadValue; + if ((stuff->srcY + stuff->srcHeight) > stuff->totalHeight) { + client->errorValue = stuff->srcHeight; + return BadValue; } if ((((stuff->format == ZPixmap) && (stuff->srcX == 0)) || - ((stuff->format != ZPixmap) && - (stuff->srcX < screenInfo.bitmapScanlinePad) && - ((stuff->format == XYBitmap) || - ((stuff->srcY == 0) && - (stuff->srcHeight == stuff->totalHeight))))) && - ((stuff->srcX + stuff->srcWidth) == stuff->totalWidth)) - (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, - stuff->dstX, stuff->dstY, - stuff->totalWidth, stuff->srcHeight, - stuff->srcX, stuff->format, - shmdesc->addr + stuff->offset + - (stuff->srcY * length)); + ((stuff->format != ZPixmap) && + (stuff->srcX < screenInfo.bitmapScanlinePad) && + ((stuff->format == XYBitmap) || + ((stuff->srcY == 0) && + (stuff->srcHeight == stuff->totalHeight))))) && + ((stuff->srcX + stuff->srcWidth) == stuff->totalWidth)) + (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, + stuff->dstX, stuff->dstY, + stuff->totalWidth, stuff->srcHeight, + stuff->srcX, stuff->format, + shmdesc->addr + stuff->offset + + (stuff->srcY * length)); else - doShmPutImage(pDraw, pGC, stuff->depth, stuff->format, - stuff->totalWidth, stuff->totalHeight, - stuff->srcX, stuff->srcY, - stuff->srcWidth, stuff->srcHeight, - stuff->dstX, stuff->dstY, - shmdesc->addr + stuff->offset); - - if (stuff->sendEvent) - { - xShmCompletionEvent ev; - - ev.type = ShmCompletionCode; - ev.drawable = stuff->drawable; - ev.minorEvent = X_ShmPutImage; - ev.majorEvent = ShmReqCode; - ev.shmseg = stuff->shmseg; - ev.offset = stuff->offset; - WriteEventsToClient(client, 1, (xEvent *) &ev); + doShmPutImage(pDraw, pGC, stuff->depth, stuff->format, + stuff->totalWidth, stuff->totalHeight, + stuff->srcX, stuff->srcY, + stuff->srcWidth, stuff->srcHeight, + stuff->dstX, stuff->dstY, shmdesc->addr + stuff->offset); + + if (stuff->sendEvent) { + xShmCompletionEvent ev; + + ev.type = ShmCompletionCode; + ev.drawable = stuff->drawable; + ev.minorEvent = X_ShmPutImage; + ev.majorEvent = ShmReqCode; + ev.shmseg = stuff->shmseg; + ev.offset = stuff->offset; + WriteEventsToClient(client, 1, (xEvent *) &ev); } return Success; @@ -646,133 +630,120 @@ ProcShmPutImage(ClientPtr client) static int ProcShmGetImage(ClientPtr client) { - DrawablePtr pDraw; - long lenPer = 0, length; - Mask plane = 0; - xShmGetImageReply xgi; - ShmDescPtr shmdesc; - int rc; + DrawablePtr pDraw; + long lenPer = 0, length; + Mask plane = 0; + xShmGetImageReply xgi; + ShmDescPtr shmdesc; + int rc; REQUEST(xShmGetImageReq); REQUEST_SIZE_MATCH(xShmGetImageReq); - if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) - { - client->errorValue = stuff->format; + if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) { + client->errorValue = stuff->format; return BadValue; } - rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, - DixReadAccess); + rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixReadAccess); if (rc != Success) - return rc; + return rc; VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - if (pDraw->type == DRAWABLE_WINDOW) - { - if( /* check for being viewable */ - !((WindowPtr) pDraw)->realized || - /* check for being on screen */ - pDraw->x + stuff->x < 0 || - pDraw->x + stuff->x + (int)stuff->width > pDraw->pScreen->width || - pDraw->y + stuff->y < 0 || - pDraw->y + stuff->y + (int)stuff->height > pDraw->pScreen->height || - /* check for being inside of border */ - stuff->x < - wBorderWidth((WindowPtr)pDraw) || - stuff->x + (int)stuff->width > - wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - stuff->y < -wBorderWidth((WindowPtr)pDraw) || - stuff->y + (int)stuff->height > - wBorderWidth((WindowPtr)pDraw) + (int)pDraw->height - ) - return BadMatch; - xgi.visual = wVisual(((WindowPtr)pDraw)); + if (pDraw->type == DRAWABLE_WINDOW) { + if ( /* check for being viewable */ + !((WindowPtr) pDraw)->realized || + /* check for being on screen */ + pDraw->x + stuff->x < 0 || + pDraw->x + stuff->x + (int) stuff->width > pDraw->pScreen->width + || pDraw->y + stuff->y < 0 || + pDraw->y + stuff->y + (int) stuff->height > + pDraw->pScreen->height || + /* check for being inside of border */ + stuff->x < -wBorderWidth((WindowPtr) pDraw) || + stuff->x + (int) stuff->width > + wBorderWidth((WindowPtr) pDraw) + (int) pDraw->width || + stuff->y < -wBorderWidth((WindowPtr) pDraw) || + stuff->y + (int) stuff->height > + wBorderWidth((WindowPtr) pDraw) + (int) pDraw->height) + return BadMatch; + xgi.visual = wVisual(((WindowPtr) pDraw)); } - else - { - if (stuff->x < 0 || - stuff->x+(int)stuff->width > pDraw->width || - stuff->y < 0 || - stuff->y+(int)stuff->height > pDraw->height - ) - return BadMatch; - xgi.visual = None; + else { + if (stuff->x < 0 || + stuff->x + (int) stuff->width > pDraw->width || + stuff->y < 0 || stuff->y + (int) stuff->height > pDraw->height) + return BadMatch; + xgi.visual = None; } xgi.type = X_Reply; xgi.length = 0; xgi.sequenceNumber = client->sequence; xgi.depth = pDraw->depth; - if(stuff->format == ZPixmap) - { - length = PixmapBytePad(stuff->width, pDraw->depth) * stuff->height; + if (stuff->format == ZPixmap) { + length = PixmapBytePad(stuff->width, pDraw->depth) * stuff->height; } - else - { - lenPer = PixmapBytePad(stuff->width, 1) * stuff->height; - plane = ((Mask)1) << (pDraw->depth - 1); - /* only planes asked for */ - length = lenPer * Ones(stuff->planeMask & (plane | (plane - 1))); + else { + lenPer = PixmapBytePad(stuff->width, 1) * stuff->height; + plane = ((Mask) 1) << (pDraw->depth - 1); + /* only planes asked for */ + length = lenPer * Ones(stuff->planeMask & (plane | (plane - 1))); } VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); xgi.size = length; - if (length == 0) - { - /* nothing to do */ + if (length == 0) { + /* nothing to do */ } - else if (stuff->format == ZPixmap) - { - (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y, - stuff->width, stuff->height, - stuff->format, stuff->planeMask, - shmdesc->addr + stuff->offset); + else if (stuff->format == ZPixmap) { + (*pDraw->pScreen->GetImage) (pDraw, stuff->x, stuff->y, + stuff->width, stuff->height, + stuff->format, stuff->planeMask, + shmdesc->addr + stuff->offset); } - else - { + else { - length = stuff->offset; - for (; plane; plane >>= 1) - { - if (stuff->planeMask & plane) - { - (*pDraw->pScreen->GetImage)(pDraw, - stuff->x, stuff->y, - stuff->width, stuff->height, - stuff->format, plane, - shmdesc->addr + length); - length += lenPer; - } - } + length = stuff->offset; + for (; plane; plane >>= 1) { + if (stuff->planeMask & plane) { + (*pDraw->pScreen->GetImage) (pDraw, + stuff->x, stuff->y, + stuff->width, stuff->height, + stuff->format, plane, + shmdesc->addr + length); + length += lenPer; + } + } } if (client->swapped) { - swaps(&xgi.sequenceNumber); - swapl(&xgi.length); - swapl(&xgi.visual); - swapl(&xgi.size); + swaps(&xgi.sequenceNumber); + swapl(&xgi.length); + swapl(&xgi.visual); + swapl(&xgi.size); } - WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi); + WriteToClient(client, sizeof(xShmGetImageReply), (char *) &xgi); return Success; } #ifdef PANORAMIX -static int +static int ProcPanoramiXShmPutImage(ClientPtr client) { - int j, result, orig_x, orig_y; - PanoramiXRes *draw, *gc; - Bool sendEvent, isRoot; + int j, result, orig_x, orig_y; + PanoramiXRes *draw, *gc; + Bool sendEvent, isRoot; REQUEST(xShmPutImageReq); REQUEST_SIZE_MATCH(xShmPutImageReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) return (result == BadValue) ? BadDrawable : result; - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, - XRT_GC, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, + XRT_GC, client, DixReadAccess); if (result != Success) return result; @@ -783,53 +754,54 @@ ProcPanoramiXShmPutImage(ClientPtr client) sendEvent = stuff->sendEvent; stuff->sendEvent = 0; FOR_NSCREENS(j) { - if(!j) stuff->sendEvent = sendEvent; - stuff->drawable = draw->info[j].id; - stuff->gc = gc->info[j].id; - if (isRoot) { - stuff->dstX = orig_x - screenInfo.screens[j]->x; - stuff->dstY = orig_y - screenInfo.screens[j]->y; - } - result = ProcShmPutImage(client); - if(result != Success) break; + if (!j) + stuff->sendEvent = sendEvent; + stuff->drawable = draw->info[j].id; + stuff->gc = gc->info[j].id; + if (isRoot) { + stuff->dstX = orig_x - screenInfo.screens[j]->x; + stuff->dstY = orig_y - screenInfo.screens[j]->y; + } + result = ProcShmPutImage(client); + if (result != Success) + break; } return result; } -static int +static int ProcPanoramiXShmGetImage(ClientPtr client) { - PanoramiXRes *draw; - DrawablePtr *drawables; - DrawablePtr pDraw; - xShmGetImageReply xgi; - ShmDescPtr shmdesc; - int i, x, y, w, h, format, rc; - Mask plane = 0, planemask; - long lenPer = 0, length, widthBytesLine; - Bool isRoot; + PanoramiXRes *draw; + DrawablePtr *drawables; + DrawablePtr pDraw; + xShmGetImageReply xgi; + ShmDescPtr shmdesc; + int i, x, y, w, h, format, rc; + Mask plane = 0, planemask; + long lenPer = 0, length, widthBytesLine; + Bool isRoot; REQUEST(xShmGetImageReq); REQUEST_SIZE_MATCH(xShmGetImageReq); if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) { - client->errorValue = stuff->format; + client->errorValue = stuff->format; return BadValue; } - rc = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + rc = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (rc != Success) - return (rc == BadValue) ? BadDrawable : rc; + return (rc == BadValue) ? BadDrawable : rc; if (draw->type == XRT_PIXMAP) - return ProcShmGetImage(client); + return ProcShmGetImage(client); - rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, - DixReadAccess); + rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixReadAccess); if (rc != Success) - return rc; + return rc; VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); @@ -842,85 +814,89 @@ ProcPanoramiXShmGetImage(ClientPtr client) isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; - if(isRoot) { - if( /* check for being onscreen */ - x < 0 || x + w > PanoramiXPixWidth || - y < 0 || y + h > PanoramiXPixHeight ) - return BadMatch; - } else { - if( /* check for being onscreen */ - screenInfo.screens[0]->x + pDraw->x + x < 0 || - screenInfo.screens[0]->x + pDraw->x + x + w > PanoramiXPixWidth || - screenInfo.screens[0]->y + pDraw->y + y < 0 || - screenInfo.screens[0]->y + pDraw->y + y + h > PanoramiXPixHeight || - /* check for being inside of border */ - x < - wBorderWidth((WindowPtr)pDraw) || - x + w > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - y < -wBorderWidth((WindowPtr)pDraw) || - y + h > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height) - return BadMatch; + if (isRoot) { + if ( /* check for being onscreen */ + x < 0 || x + w > PanoramiXPixWidth || + y < 0 || y + h > PanoramiXPixHeight) + return BadMatch; + } + else { + if ( /* check for being onscreen */ + screenInfo.screens[0]->x + pDraw->x + x < 0 || + screenInfo.screens[0]->x + pDraw->x + x + w > PanoramiXPixWidth + || screenInfo.screens[0]->y + pDraw->y + y < 0 || + screenInfo.screens[0]->y + pDraw->y + y + h > PanoramiXPixHeight + || + /* check for being inside of border */ + x < -wBorderWidth((WindowPtr) pDraw) || + x + w > wBorderWidth((WindowPtr) pDraw) + (int) pDraw->width || + y < -wBorderWidth((WindowPtr) pDraw) || + y + h > wBorderWidth((WindowPtr) pDraw) + (int) pDraw->height) + return BadMatch; } drawables = calloc(PanoramiXNumScreens, sizeof(DrawablePtr)); - if(!drawables) - return BadAlloc; + if (!drawables) + return BadAlloc; drawables[0] = pDraw; FOR_NSCREENS_FORWARD_SKIP(i) { - rc = dixLookupDrawable(drawables+i, draw->info[i].id, client, 0, - DixReadAccess); - if (rc != Success) - { - free(drawables); - return rc; - } + rc = dixLookupDrawable(drawables + i, draw->info[i].id, client, 0, + DixReadAccess); + if (rc != Success) { + free(drawables); + return rc; + } } - xgi.visual = wVisual(((WindowPtr)pDraw)); + xgi.visual = wVisual(((WindowPtr) pDraw)); xgi.type = X_Reply; xgi.length = 0; xgi.sequenceNumber = client->sequence; xgi.depth = pDraw->depth; - if(format == ZPixmap) { - widthBytesLine = PixmapBytePad(w, pDraw->depth); - length = widthBytesLine * h; - } else { - widthBytesLine = PixmapBytePad(w, 1); - lenPer = widthBytesLine * h; - plane = ((Mask)1) << (pDraw->depth - 1); - length = lenPer * Ones(planemask & (plane | (plane - 1))); + if (format == ZPixmap) { + widthBytesLine = PixmapBytePad(w, pDraw->depth); + length = widthBytesLine * h; + } + else { + widthBytesLine = PixmapBytePad(w, 1); + lenPer = widthBytesLine * h; + plane = ((Mask) 1) << (pDraw->depth - 1); + length = lenPer * Ones(planemask & (plane | (plane - 1))); } VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); xgi.size = length; - if (length == 0) {/* nothing to do */ } + if (length == 0) { /* nothing to do */ + } else if (format == ZPixmap) { - XineramaGetImageData(drawables, x, y, w, h, format, planemask, - shmdesc->addr + stuff->offset, - widthBytesLine, isRoot); - } else { + XineramaGetImageData(drawables, x, y, w, h, format, planemask, + shmdesc->addr + stuff->offset, + widthBytesLine, isRoot); + } + else { - length = stuff->offset; + length = stuff->offset; for (; plane; plane >>= 1) { - if (planemask & plane) { - XineramaGetImageData(drawables, x, y, w, h, - format, plane, shmdesc->addr + length, - widthBytesLine, isRoot); - length += lenPer; - } - } + if (planemask & plane) { + XineramaGetImageData(drawables, x, y, w, h, + format, plane, shmdesc->addr + length, + widthBytesLine, isRoot); + length += lenPer; + } + } } free(drawables); - + if (client->swapped) { - swaps(&xgi.sequenceNumber); - swapl(&xgi.length); - swapl(&xgi.visual); - swapl(&xgi.size); + swaps(&xgi.sequenceNumber); + swapl(&xgi.length); + swapl(&xgi.visual); + swapl(&xgi.size); } - WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi); + WriteToClient(client, sizeof(xShmGetImageReply), (char *) &xgi); return Success; } @@ -934,6 +910,7 @@ ProcPanoramiXShmCreatePixmap(ClientPtr client) DepthPtr pDepth; int i, j, result, rc; ShmDescPtr shmdesc; + REQUEST(xShmCreatePixmapReq); unsigned int width, height, depth; unsigned long size; @@ -942,37 +919,35 @@ ProcPanoramiXShmCreatePixmap(ClientPtr client) REQUEST_SIZE_MATCH(xShmCreatePixmapReq); client->errorValue = stuff->pid; if (!sharedPixmaps) - return BadImplementation; + return BadImplementation; LEGAL_NEW_RESOURCE(stuff->pid, client); rc = dixLookupDrawable(&pDraw, stuff->drawable, client, M_ANY, - DixGetAttrAccess); + DixGetAttrAccess); if (rc != Success) - return rc; + return rc; VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); width = stuff->width; height = stuff->height; depth = stuff->depth; - if (!width || !height || !depth) - { - client->errorValue = 0; + if (!width || !height || !depth) { + client->errorValue = 0; return BadValue; } if (width > 32767 || height > 32767) return BadAlloc; - if (stuff->depth != 1) - { + if (stuff->depth != 1) { pDepth = pDraw->pScreen->allowedDepths; - for (i=0; i<pDraw->pScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; + for (i = 0; i < pDraw->pScreen->numDepths; i++, pDepth++) + if (pDepth->depth == stuff->depth) + goto CreatePmap; + client->errorValue = stuff->depth; return BadValue; } -CreatePmap: + CreatePmap: size = PixmapBytePad(width, depth) * height; if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) { if (size < width * height) @@ -980,12 +955,12 @@ CreatePmap: } /* thankfully, offset is unsigned */ if (stuff->offset + size < size) - return BadAlloc; + return BadAlloc; VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client); - if(!(newPix = malloc(sizeof(PanoramiXRes)))) - return BadAlloc; + if (!(newPix = malloc(sizeof(PanoramiXRes)))) + return BadAlloc; newPix->type = XRT_PIXMAP; newPix->u.pix.shared = TRUE; @@ -994,54 +969,62 @@ CreatePmap: result = Success; FOR_NSCREENS(j) { - ShmScrPrivateRec *screen_priv; - pScreen = screenInfo.screens[j]; + ShmScrPrivateRec *screen_priv; + + pScreen = screenInfo.screens[j]; - screen_priv = ShmGetScreenPriv(pScreen); - pMap = (*screen_priv->shmFuncs->CreatePixmap)(pScreen, - stuff->width, stuff->height, stuff->depth, - shmdesc->addr + stuff->offset); + screen_priv = ShmGetScreenPriv(pScreen); + pMap = (*screen_priv->shmFuncs->CreatePixmap) (pScreen, + stuff->width, + stuff->height, + stuff->depth, + shmdesc->addr + + stuff->offset); - if (pMap) { - dixSetPrivate(&pMap->devPrivates, shmPixmapPrivateKey, shmdesc); + if (pMap) { + dixSetPrivate(&pMap->devPrivates, shmPixmapPrivateKey, shmdesc); shmdesc->refcnt++; - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = newPix->info[j].id; - if (!AddResource(newPix->info[j].id, RT_PIXMAP, (pointer)pMap)) { - result = BadAlloc; - break; - } - } else { - result = BadAlloc; - break; - } + pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; + pMap->drawable.id = newPix->info[j].id; + if (!AddResource(newPix->info[j].id, RT_PIXMAP, (pointer) pMap)) { + result = BadAlloc; + break; + } + } + else { + result = BadAlloc; + break; + } } - if(result == BadAlloc) { - while(j--) - FreeResource(newPix->info[j].id, RT_NONE); - free(newPix); - } else - AddResource(stuff->pid, XRT_PIXMAP, newPix); + if (result == BadAlloc) { + while (j--) + FreeResource(newPix->info[j].id, RT_NONE); + free(newPix); + } + else + AddResource(stuff->pid, XRT_PIXMAP, newPix); return result; } #endif static PixmapPtr -fbShmCreatePixmap (ScreenPtr pScreen, - int width, int height, int depth, char *addr) +fbShmCreatePixmap(ScreenPtr pScreen, + int width, int height, int depth, char *addr) { PixmapPtr pPixmap; - pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScreen->rootDepth, 0); + pPixmap = (*pScreen->CreatePixmap) (pScreen, 0, 0, pScreen->rootDepth, 0); if (!pPixmap) - return NullPixmap; - - if (!(*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth, - BitsPerPixel(depth), PixmapBytePad(width, depth), (pointer)addr)) { - (*pScreen->DestroyPixmap)(pPixmap); - return NullPixmap; + return NullPixmap; + + if (!(*pScreen->ModifyPixmapHeader) (pPixmap, width, height, depth, + BitsPerPixel(depth), + PixmapBytePad(width, depth), + (pointer) addr)) { + (*pScreen->DestroyPixmap) (pPixmap); + return NullPixmap; } return pPixmap; } @@ -1055,6 +1038,7 @@ ProcShmCreatePixmap(ClientPtr client) int i, rc; ShmDescPtr shmdesc; ShmScrPrivateRec *screen_priv; + REQUEST(xShmCreatePixmapReq); unsigned int width, height, depth; unsigned long size; @@ -1062,109 +1046,104 @@ ProcShmCreatePixmap(ClientPtr client) REQUEST_SIZE_MATCH(xShmCreatePixmapReq); client->errorValue = stuff->pid; if (!sharedPixmaps) - return BadImplementation; + return BadImplementation; LEGAL_NEW_RESOURCE(stuff->pid, client); rc = dixLookupDrawable(&pDraw, stuff->drawable, client, M_ANY, - DixGetAttrAccess); + DixGetAttrAccess); if (rc != Success) - return rc; + return rc; VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); - + width = stuff->width; height = stuff->height; depth = stuff->depth; - if (!width || !height || !depth) - { - client->errorValue = 0; + if (!width || !height || !depth) { + client->errorValue = 0; return BadValue; } if (width > 32767 || height > 32767) - return BadAlloc; + return BadAlloc; - if (stuff->depth != 1) - { + if (stuff->depth != 1) { pDepth = pDraw->pScreen->allowedDepths; - for (i=0; i<pDraw->pScreen->numDepths; i++, pDepth++) - if (pDepth->depth == stuff->depth) - goto CreatePmap; - client->errorValue = stuff->depth; + for (i = 0; i < pDraw->pScreen->numDepths; i++, pDepth++) + if (pDepth->depth == stuff->depth) + goto CreatePmap; + client->errorValue = stuff->depth; return BadValue; } -CreatePmap: + CreatePmap: size = PixmapBytePad(width, depth) * height; if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) { - if (size < width * height) - return BadAlloc; + if (size < width * height) + return BadAlloc; } /* thankfully, offset is unsigned */ if (stuff->offset + size < size) - return BadAlloc; + return BadAlloc; VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client); screen_priv = ShmGetScreenPriv(pDraw->pScreen); - pMap = (*screen_priv->shmFuncs->CreatePixmap)( - pDraw->pScreen, stuff->width, - stuff->height, stuff->depth, - shmdesc->addr + stuff->offset); - if (pMap) - { - rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, RT_PIXMAP, - pMap, RT_NONE, NULL, DixCreateAccess); - if (rc != Success) { - pDraw->pScreen->DestroyPixmap(pMap); - return rc; - } - dixSetPrivate(&pMap->devPrivates, shmPixmapPrivateKey, shmdesc); - shmdesc->refcnt++; - pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pMap->drawable.id = stuff->pid; - if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap)) - { - return Success; - } + pMap = (*screen_priv->shmFuncs->CreatePixmap) (pDraw->pScreen, stuff->width, + stuff->height, stuff->depth, + shmdesc->addr + + stuff->offset); + if (pMap) { + rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, RT_PIXMAP, + pMap, RT_NONE, NULL, DixCreateAccess); + if (rc != Success) { + pDraw->pScreen->DestroyPixmap(pMap); + return rc; + } + dixSetPrivate(&pMap->devPrivates, shmPixmapPrivateKey, shmdesc); + shmdesc->refcnt++; + pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; + pMap->drawable.id = stuff->pid; + if (AddResource(stuff->pid, RT_PIXMAP, (pointer) pMap)) { + return Success; + } } return BadAlloc; } static int -ProcShmDispatch (ClientPtr client) +ProcShmDispatch(ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { + switch (stuff->data) { case X_ShmQueryVersion: - return ProcShmQueryVersion(client); + return ProcShmQueryVersion(client); case X_ShmAttach: - return ProcShmAttach(client); + return ProcShmAttach(client); case X_ShmDetach: - return ProcShmDetach(client); + return ProcShmDetach(client); case X_ShmPutImage: #ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShmPutImage(client); + if (!noPanoramiXExtension) + return ProcPanoramiXShmPutImage(client); #endif - return ProcShmPutImage(client); + return ProcShmPutImage(client); case X_ShmGetImage: #ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShmGetImage(client); + if (!noPanoramiXExtension) + return ProcPanoramiXShmGetImage(client); #endif - return ProcShmGetImage(client); + return ProcShmGetImage(client); case X_ShmCreatePixmap: #ifdef PANORAMIX - if ( !noPanoramiXExtension ) - return ProcPanoramiXShmCreatePixmap(client); + if (!noPanoramiXExtension) + return ProcPanoramiXShmCreatePixmap(client); #endif - return ProcShmCreatePixmap(client); + return ProcShmCreatePixmap(client); default: - return BadRequest; + return BadRequest; } } static void -SShmCompletionEvent(xShmCompletionEvent *from, xShmCompletionEvent *to) +SShmCompletionEvent(xShmCompletionEvent * from, xShmCompletionEvent * to) { to->type = from->type; cpswaps(from->sequenceNumber, to->sequenceNumber); @@ -1259,25 +1238,24 @@ SProcShmCreatePixmap(ClientPtr client) } static int -SProcShmDispatch (ClientPtr client) +SProcShmDispatch(ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { + switch (stuff->data) { case X_ShmQueryVersion: - return SProcShmQueryVersion(client); + return SProcShmQueryVersion(client); case X_ShmAttach: - return SProcShmAttach(client); + return SProcShmAttach(client); case X_ShmDetach: - return SProcShmDetach(client); + return SProcShmDetach(client); case X_ShmPutImage: - return SProcShmPutImage(client); + return SProcShmPutImage(client); case X_ShmGetImage: - return SProcShmGetImage(client); + return SProcShmGetImage(client); case X_ShmCreatePixmap: - return SProcShmCreatePixmap(client); + return SProcShmCreatePixmap(client); default: - return BadRequest; + return BadRequest; } } @@ -1288,45 +1266,44 @@ ShmExtensionInit(INITARGS) int i; #ifdef MUST_CHECK_FOR_SHM_SYSCALL - if (!CheckForShmSyscall()) - { - ErrorF("MIT-SHM extension disabled due to lack of kernel support\n"); - return; + if (!CheckForShmSyscall()) { + ErrorF("MIT-SHM extension disabled due to lack of kernel support\n"); + return; } #endif if (!ShmRegisterPrivates()) - return; + return; sharedPixmaps = xFalse; { - sharedPixmaps = xTrue; - for (i = 0; i < screenInfo.numScreens; i++) - { - ShmScrPrivateRec *screen_priv = ShmInitScreenPriv(screenInfo.screens[i]); - if (!screen_priv->shmFuncs) - screen_priv->shmFuncs = &miFuncs; - if (!screen_priv->shmFuncs->CreatePixmap) - sharedPixmaps = xFalse; - } - if (sharedPixmaps) - for (i = 0; i < screenInfo.numScreens; i++) - { - ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(screenInfo.screens[i]); - screen_priv->destroyPixmap = screenInfo.screens[i]->DestroyPixmap; - screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap; - } + sharedPixmaps = xTrue; + for (i = 0; i < screenInfo.numScreens; i++) { + ShmScrPrivateRec *screen_priv = + ShmInitScreenPriv(screenInfo.screens[i]); + if (!screen_priv->shmFuncs) + screen_priv->shmFuncs = &miFuncs; + if (!screen_priv->shmFuncs->CreatePixmap) + sharedPixmaps = xFalse; + } + if (sharedPixmaps) + for (i = 0; i < screenInfo.numScreens; i++) { + ShmScrPrivateRec *screen_priv = + ShmGetScreenPriv(screenInfo.screens[i]); + screen_priv->destroyPixmap = + screenInfo.screens[i]->DestroyPixmap; + screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap; + } } ShmSegType = CreateNewResourceType(ShmDetachSegment, "ShmSeg"); if (ShmSegType && - (extEntry = AddExtension(SHMNAME, ShmNumberEvents, ShmNumberErrors, - ProcShmDispatch, SProcShmDispatch, - ShmResetProc, StandardMinorOpcode))) - { - ShmReqCode = (unsigned char)extEntry->base; - ShmCompletionCode = extEntry->eventBase; - BadShmSegCode = extEntry->errorBase; - SetResourceTypeErrorValue(ShmSegType, BadShmSegCode); - EventSwapVector[ShmCompletionCode] = (EventSwapPtr) SShmCompletionEvent; + (extEntry = AddExtension(SHMNAME, ShmNumberEvents, ShmNumberErrors, + ProcShmDispatch, SProcShmDispatch, + ShmResetProc, StandardMinorOpcode))) { + ShmReqCode = (unsigned char) extEntry->base; + ShmCompletionCode = extEntry->eventBase; + BadShmSegCode = extEntry->errorBase; + SetResourceTypeErrorValue(ShmSegType, BadShmSegCode); + EventSwapVector[ShmCompletionCode] = (EventSwapPtr) SShmCompletionEvent; } } diff --git a/xorg-server/Xext/sleepuntil.c b/xorg-server/Xext/sleepuntil.c index 69945585d..52e22b4a6 100644 --- a/xorg-server/Xext/sleepuntil.c +++ b/xorg-server/Xext/sleepuntil.c @@ -1,225 +1,209 @@ -/*
- *
-Copyright 1992, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
- *
- * Author: Keith Packard, MIT X Consortium
- */
-
-/* dixsleep.c - implement millisecond timeouts for X clients */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "sleepuntil.h"
-#include <X11/X.h>
-#include <X11/Xmd.h>
-#include "misc.h"
-#include "windowstr.h"
-#include "dixstruct.h"
-#include "pixmapstr.h"
-#include "scrnintstr.h"
-
-typedef struct _Sertafied {
- struct _Sertafied *next;
- TimeStamp revive;
- ClientPtr pClient;
- XID id;
- void (*notifyFunc)(
- ClientPtr /* client */,
- pointer /* closure */
- );
-
- pointer closure;
-} SertafiedRec, *SertafiedPtr;
-
-static SertafiedPtr pPending;
-static RESTYPE SertafiedResType;
-static Bool BlockHandlerRegistered;
-static int SertafiedGeneration;
-
-static void ClientAwaken(
- ClientPtr /* client */,
- pointer /* closure */
-);
-static int SertafiedDelete(
- pointer /* value */,
- XID /* id */
-);
-static void SertafiedBlockHandler(
- pointer /* data */,
- OSTimePtr /* wt */,
- pointer /* LastSelectMask */
-);
-static void SertafiedWakeupHandler(
- pointer /* data */,
- int /* i */,
- pointer /* LastSelectMask */
-);
-
-int
-ClientSleepUntil (ClientPtr client,
- TimeStamp *revive,
- void (*notifyFunc)(ClientPtr, pointer),
- pointer closure)
-{
- SertafiedPtr pRequest, pReq, pPrev;
-
- if (SertafiedGeneration != serverGeneration)
- {
- SertafiedResType = CreateNewResourceType (SertafiedDelete,
- "ClientSleep");
- if (!SertafiedResType)
- return FALSE;
- SertafiedGeneration = serverGeneration;
- BlockHandlerRegistered = FALSE;
- }
- pRequest = malloc(sizeof (SertafiedRec));
- if (!pRequest)
- return FALSE;
- pRequest->pClient = client;
- pRequest->revive = *revive;
- pRequest->id = FakeClientID (client->index);
- pRequest->closure = closure;
- if (!BlockHandlerRegistered)
- {
- if (!RegisterBlockAndWakeupHandlers (SertafiedBlockHandler,
- SertafiedWakeupHandler,
- (pointer) 0))
- {
- free(pRequest);
- return FALSE;
- }
- BlockHandlerRegistered = TRUE;
- }
- pRequest->notifyFunc = 0;
- if (!AddResource (pRequest->id, SertafiedResType, (pointer) pRequest))
- return FALSE;
- if (!notifyFunc)
- notifyFunc = ClientAwaken;
- pRequest->notifyFunc = notifyFunc;
- /* Insert into time-ordered queue, with earliest activation time coming first. */
- pPrev = 0;
- for (pReq = pPending; pReq; pReq = pReq->next)
- {
- if (CompareTimeStamps (pReq->revive, *revive) == LATER)
- break;
- pPrev = pReq;
- }
- if (pPrev)
- pPrev->next = pRequest;
- else
- pPending = pRequest;
- pRequest->next = pReq;
- IgnoreClient (client);
- return TRUE;
-}
-
-static void
-ClientAwaken (ClientPtr client, pointer closure)
-{
- if (!client->clientGone)
- AttendClient (client);
-}
-
-
-static int
-SertafiedDelete (pointer value, XID id)
-{
- SertafiedPtr pRequest = (SertafiedPtr)value;
- SertafiedPtr pReq, pPrev;
-
- pPrev = 0;
- for (pReq = pPending; pReq; pPrev = pReq, pReq = pReq->next)
- if (pReq == pRequest)
- {
- if (pPrev)
- pPrev->next = pReq->next;
- else
- pPending = pReq->next;
- break;
- }
- if (pRequest->notifyFunc)
- (*pRequest->notifyFunc) (pRequest->pClient, pRequest->closure);
- free(pRequest);
- return TRUE;
-}
-
-static void
-SertafiedBlockHandler (pointer data, OSTimePtr wt, pointer LastSelectMask)
-{
- SertafiedPtr pReq, pNext;
- unsigned long delay;
- TimeStamp now;
-
- if (!pPending)
- return;
- now.milliseconds = GetTimeInMillis ();
- now.months = currentTime.months;
- if ((int) (now.milliseconds - currentTime.milliseconds) < 0)
- now.months++;
- for (pReq = pPending; pReq; pReq = pNext)
- {
- pNext = pReq->next;
- if (CompareTimeStamps (pReq->revive, now) == LATER)
- break;
- FreeResource (pReq->id, RT_NONE);
-
- /* AttendClient() may have been called via the resource delete
- * function so a client may have input to be processed and so
- * set delay to 0 to prevent blocking in WaitForSomething().
- */
- AdjustWaitForDelay (wt, 0);
- }
- pReq = pPending;
- if (!pReq)
- return;
- delay = pReq->revive.milliseconds - now.milliseconds;
- AdjustWaitForDelay (wt, delay);
-}
-
-static void
-SertafiedWakeupHandler (pointer data, int i, pointer LastSelectMask)
-{
- SertafiedPtr pReq, pNext;
- TimeStamp now;
-
- now.milliseconds = GetTimeInMillis ();
- now.months = currentTime.months;
- if ((int) (now.milliseconds - currentTime.milliseconds) < 0)
- now.months++;
- for (pReq = pPending; pReq; pReq = pNext)
- {
- pNext = pReq->next;
- if (CompareTimeStamps (pReq->revive, now) == LATER)
- break;
- FreeResource (pReq->id, RT_NONE);
- }
- if (!pPending)
- {
- RemoveBlockAndWakeupHandlers (SertafiedBlockHandler,
- SertafiedWakeupHandler,
- (pointer) 0);
- BlockHandlerRegistered = FALSE;
- }
-}
+/* + * +Copyright 1992, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + * + * Author: Keith Packard, MIT X Consortium + */ + +/* dixsleep.c - implement millisecond timeouts for X clients */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include "sleepuntil.h" +#include <X11/X.h> +#include <X11/Xmd.h> +#include "misc.h" +#include "windowstr.h" +#include "dixstruct.h" +#include "pixmapstr.h" +#include "scrnintstr.h" + +typedef struct _Sertafied { + struct _Sertafied *next; + TimeStamp revive; + ClientPtr pClient; + XID id; + void (*notifyFunc) (ClientPtr /* client */ , + pointer /* closure */ + ); + + pointer closure; +} SertafiedRec, *SertafiedPtr; + +static SertafiedPtr pPending; +static RESTYPE SertafiedResType; +static Bool BlockHandlerRegistered; +static int SertafiedGeneration; + +static void ClientAwaken(ClientPtr /* client */ , + pointer /* closure */ + ); +static int SertafiedDelete(pointer /* value */ , + XID /* id */ + ); +static void SertafiedBlockHandler(pointer /* data */ , + OSTimePtr /* wt */ , + pointer /* LastSelectMask */ + ); +static void SertafiedWakeupHandler(pointer /* data */ , + int /* i */ , + pointer /* LastSelectMask */ + ); + +int +ClientSleepUntil(ClientPtr client, + TimeStamp *revive, + void (*notifyFunc) (ClientPtr, pointer), pointer closure) +{ + SertafiedPtr pRequest, pReq, pPrev; + + if (SertafiedGeneration != serverGeneration) { + SertafiedResType = CreateNewResourceType(SertafiedDelete, + "ClientSleep"); + if (!SertafiedResType) + return FALSE; + SertafiedGeneration = serverGeneration; + BlockHandlerRegistered = FALSE; + } + pRequest = malloc(sizeof(SertafiedRec)); + if (!pRequest) + return FALSE; + pRequest->pClient = client; + pRequest->revive = *revive; + pRequest->id = FakeClientID(client->index); + pRequest->closure = closure; + if (!BlockHandlerRegistered) { + if (!RegisterBlockAndWakeupHandlers(SertafiedBlockHandler, + SertafiedWakeupHandler, + (pointer) 0)) { + free(pRequest); + return FALSE; + } + BlockHandlerRegistered = TRUE; + } + pRequest->notifyFunc = 0; + if (!AddResource(pRequest->id, SertafiedResType, (pointer) pRequest)) + return FALSE; + if (!notifyFunc) + notifyFunc = ClientAwaken; + pRequest->notifyFunc = notifyFunc; + /* Insert into time-ordered queue, with earliest activation time coming first. */ + pPrev = 0; + for (pReq = pPending; pReq; pReq = pReq->next) { + if (CompareTimeStamps(pReq->revive, *revive) == LATER) + break; + pPrev = pReq; + } + if (pPrev) + pPrev->next = pRequest; + else + pPending = pRequest; + pRequest->next = pReq; + IgnoreClient(client); + return TRUE; +} + +static void +ClientAwaken(ClientPtr client, pointer closure) +{ + if (!client->clientGone) + AttendClient(client); +} + +static int +SertafiedDelete(pointer value, XID id) +{ + SertafiedPtr pRequest = (SertafiedPtr) value; + SertafiedPtr pReq, pPrev; + + pPrev = 0; + for (pReq = pPending; pReq; pPrev = pReq, pReq = pReq->next) + if (pReq == pRequest) { + if (pPrev) + pPrev->next = pReq->next; + else + pPending = pReq->next; + break; + } + if (pRequest->notifyFunc) + (*pRequest->notifyFunc) (pRequest->pClient, pRequest->closure); + free(pRequest); + return TRUE; +} + +static void +SertafiedBlockHandler(pointer data, OSTimePtr wt, pointer LastSelectMask) +{ + SertafiedPtr pReq, pNext; + unsigned long delay; + TimeStamp now; + + if (!pPending) + return; + now.milliseconds = GetTimeInMillis(); + now.months = currentTime.months; + if ((int) (now.milliseconds - currentTime.milliseconds) < 0) + now.months++; + for (pReq = pPending; pReq; pReq = pNext) { + pNext = pReq->next; + if (CompareTimeStamps(pReq->revive, now) == LATER) + break; + FreeResource(pReq->id, RT_NONE); + + /* AttendClient() may have been called via the resource delete + * function so a client may have input to be processed and so + * set delay to 0 to prevent blocking in WaitForSomething(). + */ + AdjustWaitForDelay(wt, 0); + } + pReq = pPending; + if (!pReq) + return; + delay = pReq->revive.milliseconds - now.milliseconds; + AdjustWaitForDelay(wt, delay); +} + +static void +SertafiedWakeupHandler(pointer data, int i, pointer LastSelectMask) +{ + SertafiedPtr pReq, pNext; + TimeStamp now; + + now.milliseconds = GetTimeInMillis(); + now.months = currentTime.months; + if ((int) (now.milliseconds - currentTime.milliseconds) < 0) + now.months++; + for (pReq = pPending; pReq; pReq = pNext) { + pNext = pReq->next; + if (CompareTimeStamps(pReq->revive, now) == LATER) + break; + FreeResource(pReq->id, RT_NONE); + } + if (!pPending) { + RemoveBlockAndWakeupHandlers(SertafiedBlockHandler, + SertafiedWakeupHandler, (pointer) 0); + BlockHandlerRegistered = FALSE; + } +} diff --git a/xorg-server/Xext/sleepuntil.h b/xorg-server/Xext/sleepuntil.h index a3618d99c..5c7084842 100644 --- a/xorg-server/Xext/sleepuntil.h +++ b/xorg-server/Xext/sleepuntil.h @@ -33,14 +33,10 @@ #include "dix.h" -extern int ClientSleepUntil( - ClientPtr client, - TimeStamp *revive, - void (*notifyFunc)( - ClientPtr /* client */, - pointer /* closure */ - ), - pointer Closure -); +extern int ClientSleepUntil(ClientPtr client, + TimeStamp *revive, + void (*notifyFunc) (ClientPtr /* client */ , + pointer /* closure */ + ), pointer Closure); #endif diff --git a/xorg-server/Xext/sync.c b/xorg-server/Xext/sync.c index 830552381..44e2b12eb 100644 --- a/xorg-server/Xext/sync.c +++ b/xorg-server/Xext/sync.c @@ -24,7 +24,6 @@ not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. - Copyright 1991, 1993 by Digital Equipment Corporation, Maynard, Massachusetts, and Olivetti Research Limited, Cambridge, England. @@ -70,6 +69,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "syncsrv.h" #include "syncsdk.h" #include "protocol-versions.h" +#include "inputstr.h" #include <stdio.h> #if !defined(WIN32) @@ -81,25 +81,25 @@ PERFORMANCE OF THIS SOFTWARE. /* * Local Global Variables */ -static int SyncEventBase; -static int SyncErrorBase; -static RESTYPE RTCounter = 0; -static RESTYPE RTAwait; -static RESTYPE RTAlarm; -static RESTYPE RTAlarmClient; -static RESTYPE RTFence; -static int SyncNumSystemCounters = 0; -static SyncCounter **SysCounterList = NULL; +static int SyncEventBase; +static int SyncErrorBase; +static RESTYPE RTCounter = 0; +static RESTYPE RTAwait; +static RESTYPE RTAlarm; +static RESTYPE RTAlarmClient; +static RESTYPE RTFence; +static struct xorg_list SysCounterList; static int SyncNumInvalidCounterWarnings = 0; + #define MAX_INVALID_COUNTER_WARNINGS 5 static const char *WARN_INVALID_COUNTER_COMPARE = -"Warning: Non-counter XSync object using Counter-only\n" -" comparison. Result will never be true.\n"; + "Warning: Non-counter XSync object using Counter-only\n" + " comparison. Result will never be true.\n"; static const char *WARN_INVALID_COUNTER_ALARM = -"Warning: Non-counter XSync object used in alarm. This is\n" -" the result of a programming error in the X server.\n"; + "Warning: Non-counter XSync object used in alarm. This is\n" + " the result of a programming error in the X server.\n"; #define IsSystemCounter(pCounter) \ (pCounter && (pCounter->sync.client == NULL)) @@ -114,18 +114,24 @@ static void SyncInitServerTime(void); static void SyncInitIdleTime(void); +static inline void* +SysCounterGetPrivate(SyncCounter *counter) +{ + BUG_WARN(!IsSystemCounter(counter)); + + return counter->pSysCounterInfo ? counter->pSysCounterInfo->private : NULL; +} + static Bool -SyncCheckWarnIsCounter(const SyncObject* pSync, const char *warning) +SyncCheckWarnIsCounter(const SyncObject * pSync, const char *warning) { - if (pSync && (SYNC_COUNTER != pSync->type)) - { - if (SyncNumInvalidCounterWarnings++ < MAX_INVALID_COUNTER_WARNINGS) - { - ErrorF("%s", warning); - ErrorF(" Counter type: %d\n", pSync->type); - } + if (pSync && (SYNC_COUNTER != pSync->type)) { + if (SyncNumInvalidCounterWarnings++ < MAX_INVALID_COUNTER_WARNINGS) { + ErrorF("%s", warning); + ErrorF(" Counter type: %d\n", pSync->type); + } - return FALSE; + return FALSE; } return TRUE; @@ -136,7 +142,7 @@ SyncCheckWarnIsCounter(const SyncObject* pSync, const char *warning) * delete and add triggers on this list. */ static void -SyncDeleteTriggerFromSyncObject(SyncTrigger *pTrigger) +SyncDeleteTriggerFromSyncObject(SyncTrigger * pTrigger) { SyncTriggerList *pCur; SyncTriggerList *pPrev; @@ -145,79 +151,76 @@ SyncDeleteTriggerFromSyncObject(SyncTrigger *pTrigger) /* pSync needs to be stored in pTrigger before calling here. */ if (!pTrigger->pSync) - return; + return; pPrev = NULL; pCur = pTrigger->pSync->pTriglist; - while (pCur) - { - if (pCur->pTrigger == pTrigger) - { - if (pPrev) - pPrev->next = pCur->next; - else - pTrigger->pSync->pTriglist = pCur->next; + while (pCur) { + if (pCur->pTrigger == pTrigger) { + if (pPrev) + pPrev->next = pCur->next; + else + pTrigger->pSync->pTriglist = pCur->next; + + free(pCur); + break; + } - free(pCur); - break; - } - - pPrev = pCur; - pCur = pCur->next; + pPrev = pCur; + pCur = pCur->next; } - if (SYNC_COUNTER == pTrigger->pSync->type) - { - pCounter = (SyncCounter *)pTrigger->pSync; + if (SYNC_COUNTER == pTrigger->pSync->type) { + pCounter = (SyncCounter *) pTrigger->pSync; - if (IsSystemCounter(pCounter)) - SyncComputeBracketValues(pCounter); - } else if (SYNC_FENCE == pTrigger->pSync->type) { - SyncFence* pFence = (SyncFence*) pTrigger->pSync; - pFence->funcs.DeleteTrigger(pTrigger); + if (IsSystemCounter(pCounter)) + SyncComputeBracketValues(pCounter); } -} + else if (SYNC_FENCE == pTrigger->pSync->type) { + SyncFence *pFence = (SyncFence *) pTrigger->pSync; + pFence->funcs.DeleteTrigger(pTrigger); + } +} static int -SyncAddTriggerToSyncObject(SyncTrigger *pTrigger) +SyncAddTriggerToSyncObject(SyncTrigger * pTrigger) { SyncTriggerList *pCur; SyncCounter *pCounter; if (!pTrigger->pSync) - return Success; + return Success; /* don't do anything if it's already there */ - for (pCur = pTrigger->pSync->pTriglist; pCur; pCur = pCur->next) - { - if (pCur->pTrigger == pTrigger) - return Success; + for (pCur = pTrigger->pSync->pTriglist; pCur; pCur = pCur->next) { + if (pCur->pTrigger == pTrigger) + return Success; } if (!(pCur = malloc(sizeof(SyncTriggerList)))) - return BadAlloc; + return BadAlloc; pCur->pTrigger = pTrigger; pCur->next = pTrigger->pSync->pTriglist; pTrigger->pSync->pTriglist = pCur; - if (SYNC_COUNTER == pTrigger->pSync->type) - { - pCounter = (SyncCounter *)pTrigger->pSync; + if (SYNC_COUNTER == pTrigger->pSync->type) { + pCounter = (SyncCounter *) pTrigger->pSync; + + if (IsSystemCounter(pCounter)) + SyncComputeBracketValues(pCounter); + } + else if (SYNC_FENCE == pTrigger->pSync->type) { + SyncFence *pFence = (SyncFence *) pTrigger->pSync; - if (IsSystemCounter(pCounter)) - SyncComputeBracketValues(pCounter); - } else if (SYNC_FENCE == pTrigger->pSync->type) { - SyncFence* pFence = (SyncFence*) pTrigger->pSync; - pFence->funcs.AddTrigger(pTrigger); + pFence->funcs.AddTrigger(pTrigger); } return Success; } - /* Below are five possible functions that can be plugged into * pTrigger->CheckTrigger for counter sync objects, corresponding to * the four possible test-types, and the one possible function that @@ -234,194 +237,182 @@ SyncAddTriggerToSyncObject(SyncTrigger *pTrigger) */ static Bool -SyncCheckTriggerPositiveComparison(SyncTrigger *pTrigger, CARD64 oldval) +SyncCheckTriggerPositiveComparison(SyncTrigger * pTrigger, CARD64 oldval) { SyncCounter *pCounter; /* Non-counter sync objects should never get here because they * never trigger this comparison. */ if (!SyncCheckWarnIsCounter(pTrigger->pSync, WARN_INVALID_COUNTER_COMPARE)) - return FALSE; + return FALSE; - pCounter = (SyncCounter *)pTrigger->pSync; + pCounter = (SyncCounter *) pTrigger->pSync; return (pCounter == NULL || - XSyncValueGreaterOrEqual(pCounter->value, pTrigger->test_value)); + XSyncValueGreaterOrEqual(pCounter->value, pTrigger->test_value)); } static Bool -SyncCheckTriggerNegativeComparison(SyncTrigger *pTrigger, CARD64 oldval) +SyncCheckTriggerNegativeComparison(SyncTrigger * pTrigger, CARD64 oldval) { SyncCounter *pCounter; /* Non-counter sync objects should never get here because they * never trigger this comparison. */ if (!SyncCheckWarnIsCounter(pTrigger->pSync, WARN_INVALID_COUNTER_COMPARE)) - return FALSE; + return FALSE; - pCounter = (SyncCounter *)pTrigger->pSync; + pCounter = (SyncCounter *) pTrigger->pSync; return (pCounter == NULL || - XSyncValueLessOrEqual(pCounter->value, pTrigger->test_value)); + XSyncValueLessOrEqual(pCounter->value, pTrigger->test_value)); } static Bool -SyncCheckTriggerPositiveTransition(SyncTrigger *pTrigger, CARD64 oldval) +SyncCheckTriggerPositiveTransition(SyncTrigger * pTrigger, CARD64 oldval) { SyncCounter *pCounter; /* Non-counter sync objects should never get here because they * never trigger this comparison. */ if (!SyncCheckWarnIsCounter(pTrigger->pSync, WARN_INVALID_COUNTER_COMPARE)) - return FALSE; + return FALSE; - pCounter = (SyncCounter *)pTrigger->pSync; + pCounter = (SyncCounter *) pTrigger->pSync; return (pCounter == NULL || - (XSyncValueLessThan(oldval, pTrigger->test_value) && - XSyncValueGreaterOrEqual(pCounter->value, pTrigger->test_value))); + (XSyncValueLessThan(oldval, pTrigger->test_value) && + XSyncValueGreaterOrEqual(pCounter->value, pTrigger->test_value))); } static Bool -SyncCheckTriggerNegativeTransition(SyncTrigger *pTrigger, CARD64 oldval) +SyncCheckTriggerNegativeTransition(SyncTrigger * pTrigger, CARD64 oldval) { SyncCounter *pCounter; /* Non-counter sync objects should never get here because they * never trigger this comparison. */ if (!SyncCheckWarnIsCounter(pTrigger->pSync, WARN_INVALID_COUNTER_COMPARE)) - return FALSE; + return FALSE; - pCounter = (SyncCounter *)pTrigger->pSync; + pCounter = (SyncCounter *) pTrigger->pSync; return (pCounter == NULL || - (XSyncValueGreaterThan(oldval, pTrigger->test_value) && - XSyncValueLessOrEqual(pCounter->value, pTrigger->test_value))); + (XSyncValueGreaterThan(oldval, pTrigger->test_value) && + XSyncValueLessOrEqual(pCounter->value, pTrigger->test_value))); } static Bool -SyncCheckTriggerFence(SyncTrigger *pTrigger, CARD64 unused) +SyncCheckTriggerFence(SyncTrigger * pTrigger, CARD64 unused) { - SyncFence* pFence = (SyncFence*) pTrigger->pSync; - (void)unused; + SyncFence *pFence = (SyncFence *) pTrigger->pSync; + + (void) unused; - return (pFence == NULL || - pFence->funcs.CheckTriggered(pFence)); + return (pFence == NULL || pFence->funcs.CheckTriggered(pFence)); } static int -SyncInitTrigger(ClientPtr client, SyncTrigger *pTrigger, XID syncObject, - RESTYPE resType, Mask changes) +SyncInitTrigger(ClientPtr client, SyncTrigger * pTrigger, XID syncObject, + RESTYPE resType, Mask changes) { SyncObject *pSync = pTrigger->pSync; SyncCounter *pCounter = NULL; - int rc; - Bool newSyncObject = FALSE; - - if (changes & XSyncCACounter) - { - if (syncObject == None) - pSync = NULL; - else if (Success != (rc = dixLookupResourceByType ((pointer *)&pSync, - syncObject, resType, client, DixReadAccess))) - { - client->errorValue = syncObject; - return rc; - } - if (pSync != pTrigger->pSync) - { /* new counter for trigger */ - SyncDeleteTriggerFromSyncObject(pTrigger); - pTrigger->pSync = pSync; - newSyncObject = TRUE; - } + int rc; + Bool newSyncObject = FALSE; + + if (changes & XSyncCACounter) { + if (syncObject == None) + pSync = NULL; + else if (Success != (rc = dixLookupResourceByType((pointer *) &pSync, + syncObject, resType, + client, + DixReadAccess))) { + client->errorValue = syncObject; + return rc; + } + if (pSync != pTrigger->pSync) { /* new counter for trigger */ + SyncDeleteTriggerFromSyncObject(pTrigger); + pTrigger->pSync = pSync; + newSyncObject = TRUE; + } } /* if system counter, ask it what the current value is */ - if (pSync && SYNC_COUNTER == pSync->type) - { - pCounter = (SyncCounter *)pSync; - - if (IsSystemCounter(pCounter)) - { - (*pCounter->pSysCounterInfo->QueryValue) ((pointer) pCounter, - &pCounter->value); - } - } - - if (changes & XSyncCAValueType) - { - if (pTrigger->value_type != XSyncRelative && - pTrigger->value_type != XSyncAbsolute) - { - client->errorValue = pTrigger->value_type; - return BadValue; - } - } - - if (changes & XSyncCATestType) - { - - if (pSync && SYNC_FENCE == pSync->type) - { - pTrigger->CheckTrigger = SyncCheckTriggerFence; - } - else - { - /* select appropriate CheckTrigger function */ - - switch (pTrigger->test_type) - { - case XSyncPositiveTransition: - pTrigger->CheckTrigger = SyncCheckTriggerPositiveTransition; - break; - case XSyncNegativeTransition: - pTrigger->CheckTrigger = SyncCheckTriggerNegativeTransition; - break; - case XSyncPositiveComparison: - pTrigger->CheckTrigger = SyncCheckTriggerPositiveComparison; - break; - case XSyncNegativeComparison: - pTrigger->CheckTrigger = SyncCheckTriggerNegativeComparison; - break; - default: - client->errorValue = pTrigger->test_type; - return BadValue; - } - } - } - - if (changes & (XSyncCAValueType | XSyncCAValue)) - { - if (pTrigger->value_type == XSyncAbsolute) - pTrigger->test_value = pTrigger->wait_value; - else /* relative */ - { - Bool overflow; - if (pCounter == NULL) - return BadMatch; - - XSyncValueAdd(&pTrigger->test_value, pCounter->value, - pTrigger->wait_value, &overflow); - if (overflow) - { - client->errorValue = XSyncValueHigh32(pTrigger->wait_value); - return BadValue; - } - } + if (pSync && SYNC_COUNTER == pSync->type) { + pCounter = (SyncCounter *) pSync; + + if (IsSystemCounter(pCounter)) { + (*pCounter->pSysCounterInfo->QueryValue) ((pointer) pCounter, + &pCounter->value); + } + } + + if (changes & XSyncCAValueType) { + if (pTrigger->value_type != XSyncRelative && + pTrigger->value_type != XSyncAbsolute) { + client->errorValue = pTrigger->value_type; + return BadValue; + } + } + + if (changes & XSyncCATestType) { + + if (pSync && SYNC_FENCE == pSync->type) { + pTrigger->CheckTrigger = SyncCheckTriggerFence; + } + else { + /* select appropriate CheckTrigger function */ + + switch (pTrigger->test_type) { + case XSyncPositiveTransition: + pTrigger->CheckTrigger = SyncCheckTriggerPositiveTransition; + break; + case XSyncNegativeTransition: + pTrigger->CheckTrigger = SyncCheckTriggerNegativeTransition; + break; + case XSyncPositiveComparison: + pTrigger->CheckTrigger = SyncCheckTriggerPositiveComparison; + break; + case XSyncNegativeComparison: + pTrigger->CheckTrigger = SyncCheckTriggerNegativeComparison; + break; + default: + client->errorValue = pTrigger->test_type; + return BadValue; + } + } + } + + if (changes & (XSyncCAValueType | XSyncCAValue)) { + if (pTrigger->value_type == XSyncAbsolute) + pTrigger->test_value = pTrigger->wait_value; + else { /* relative */ + + Bool overflow; + + if (pCounter == NULL) + return BadMatch; + + XSyncValueAdd(&pTrigger->test_value, pCounter->value, + pTrigger->wait_value, &overflow); + if (overflow) { + client->errorValue = XSyncValueHigh32(pTrigger->wait_value); + return BadValue; + } + } } /* we wait until we're sure there are no errors before registering * a new counter on a trigger */ - if (newSyncObject) - { - if ((rc = SyncAddTriggerToSyncObject(pTrigger)) != Success) - return rc; + if (newSyncObject) { + if ((rc = SyncAddTriggerToSyncObject(pTrigger)) != Success) + return rc; } - else if (pCounter && IsSystemCounter(pCounter)) - { - SyncComputeBracketValues(pCounter); + else if (pCounter && IsSystemCounter(pCounter)) { + SyncComputeBracketValues(pCounter); } return Success; @@ -432,7 +423,7 @@ SyncInitTrigger(ClientPtr client, SyncTrigger *pTrigger, XID syncObject, * clients. The alarm maintains a list of clients interested in events. */ static void -SyncSendAlarmNotifyEvents(SyncAlarm *pAlarm) +SyncSendAlarmNotifyEvents(SyncAlarm * pAlarm) { SyncAlarmClientList *pcl; xSyncAlarmNotifyEvent ane; @@ -440,23 +431,21 @@ SyncSendAlarmNotifyEvents(SyncAlarm *pAlarm) SyncCounter *pCounter; if (!SyncCheckWarnIsCounter(pTrigger->pSync, WARN_INVALID_COUNTER_ALARM)) - return; + return; - pCounter = (SyncCounter *)pTrigger->pSync; + pCounter = (SyncCounter *) pTrigger->pSync; UpdateCurrentTime(); ane.type = SyncEventBase + XSyncAlarmNotify; ane.kind = XSyncAlarmNotify; ane.alarm = pAlarm->alarm_id; - if (pTrigger->pSync && SYNC_COUNTER == pTrigger->pSync->type) - { - ane.counter_value_hi = XSyncValueHigh32(pCounter->value); - ane.counter_value_lo = XSyncValueLow32(pCounter->value); + if (pTrigger->pSync && SYNC_COUNTER == pTrigger->pSync->type) { + ane.counter_value_hi = XSyncValueHigh32(pCounter->value); + ane.counter_value_lo = XSyncValueLow32(pCounter->value); } - else - { /* XXX what else can we do if there's no counter? */ - ane.counter_value_hi = ane.counter_value_lo = 0; + else { /* XXX what else can we do if there's no counter? */ + ane.counter_value_hi = ane.counter_value_lo = 0; } ane.alarm_value_hi = XSyncValueHigh32(pTrigger->test_value); @@ -466,149 +455,141 @@ SyncSendAlarmNotifyEvents(SyncAlarm *pAlarm) /* send to owner */ if (pAlarm->events) - WriteEventsToClient(pAlarm->client, 1, (xEvent *) &ane); + WriteEventsToClient(pAlarm->client, 1, (xEvent *) &ane); /* send to other interested clients */ for (pcl = pAlarm->pEventClients; pcl; pcl = pcl->next) - WriteEventsToClient(pcl->client, 1, (xEvent *) &ane); + WriteEventsToClient(pcl->client, 1, (xEvent *) &ane); } - /* CounterNotify events only occur in response to an Await. The events * go only to the Awaiting client. */ static void -SyncSendCounterNotifyEvents(ClientPtr client, SyncAwait **ppAwait, - int num_events) +SyncSendCounterNotifyEvents(ClientPtr client, SyncAwait ** ppAwait, + int num_events) { xSyncCounterNotifyEvent *pEvents, *pev; int i; if (client->clientGone) - return; + return; pev = pEvents = malloc(num_events * sizeof(xSyncCounterNotifyEvent)); if (!pEvents) - return; + return; UpdateCurrentTime(); - for (i = 0; i < num_events; i++, ppAwait++, pev++) - { - SyncTrigger *pTrigger = &(*ppAwait)->trigger; - pev->type = SyncEventBase + XSyncCounterNotify; - pev->kind = XSyncCounterNotify; - pev->counter = pTrigger->pSync->id; - pev->wait_value_lo = XSyncValueLow32(pTrigger->test_value); - pev->wait_value_hi = XSyncValueHigh32(pTrigger->test_value); - if (SYNC_COUNTER == pTrigger->pSync->type) - { - SyncCounter *pCounter = (SyncCounter *)pTrigger->pSync; - - pev->counter_value_lo = XSyncValueLow32(pCounter->value); - pev->counter_value_hi = XSyncValueHigh32(pCounter->value); - } - else - { - pev->counter_value_lo = 0; - pev->counter_value_hi = 0; - } - - pev->time = currentTime.milliseconds; - pev->count = num_events - i - 1; /* events remaining */ - pev->destroyed = pTrigger->pSync->beingDestroyed; + for (i = 0; i < num_events; i++, ppAwait++, pev++) { + SyncTrigger *pTrigger = &(*ppAwait)->trigger; + + pev->type = SyncEventBase + XSyncCounterNotify; + pev->kind = XSyncCounterNotify; + pev->counter = pTrigger->pSync->id; + pev->wait_value_lo = XSyncValueLow32(pTrigger->test_value); + pev->wait_value_hi = XSyncValueHigh32(pTrigger->test_value); + if (SYNC_COUNTER == pTrigger->pSync->type) { + SyncCounter *pCounter = (SyncCounter *) pTrigger->pSync; + + pev->counter_value_lo = XSyncValueLow32(pCounter->value); + pev->counter_value_hi = XSyncValueHigh32(pCounter->value); + } + else { + pev->counter_value_lo = 0; + pev->counter_value_hi = 0; + } + + pev->time = currentTime.milliseconds; + pev->count = num_events - i - 1; /* events remaining */ + pev->destroyed = pTrigger->pSync->beingDestroyed; } /* swapping will be taken care of by this */ - WriteEventsToClient(client, num_events, (xEvent *)pEvents); + WriteEventsToClient(client, num_events, (xEvent *) pEvents); free(pEvents); } - /* This function is called when an alarm's counter is destroyed. * It is plugged into pTrigger->CounterDestroyed (for alarm triggers). */ static void -SyncAlarmCounterDestroyed(SyncTrigger *pTrigger) +SyncAlarmCounterDestroyed(SyncTrigger * pTrigger) { - SyncAlarm *pAlarm = (SyncAlarm *)pTrigger; + SyncAlarm *pAlarm = (SyncAlarm *) pTrigger; pAlarm->state = XSyncAlarmInactive; SyncSendAlarmNotifyEvents(pAlarm); pTrigger->pSync = NULL; } - /* This function is called when an alarm "goes off." * It is plugged into pTrigger->TriggerFired (for alarm triggers). */ static void -SyncAlarmTriggerFired(SyncTrigger *pTrigger) +SyncAlarmTriggerFired(SyncTrigger * pTrigger) { - SyncAlarm *pAlarm = (SyncAlarm *)pTrigger; + SyncAlarm *pAlarm = (SyncAlarm *) pTrigger; SyncCounter *pCounter; CARD64 new_test_value; if (!SyncCheckWarnIsCounter(pTrigger->pSync, WARN_INVALID_COUNTER_ALARM)) - return; + return; - pCounter = (SyncCounter *)pTrigger->pSync; + pCounter = (SyncCounter *) pTrigger->pSync; /* no need to check alarm unless it's active */ if (pAlarm->state != XSyncAlarmActive) - return; + return; /* " if the counter value is None, or if the delta is 0 and * the test-type is PositiveComparison or NegativeComparison, * no change is made to value (test-value) and the alarm * state is changed to Inactive before the event is generated." */ - if (pCounter == NULL - || (XSyncValueIsZero(pAlarm->delta) - && (pAlarm->trigger.test_type == XSyncPositiveComparison - || pAlarm->trigger.test_type == XSyncNegativeComparison))) - pAlarm->state = XSyncAlarmInactive; + if (pCounter == NULL || (XSyncValueIsZero(pAlarm->delta) + && (pAlarm->trigger.test_type == + XSyncPositiveComparison || + pAlarm->trigger.test_type == + XSyncNegativeComparison))) + pAlarm->state = XSyncAlarmInactive; new_test_value = pAlarm->trigger.test_value; - if (pAlarm->state == XSyncAlarmActive) - { - Bool overflow; - CARD64 oldvalue; - SyncTrigger *paTrigger = &pAlarm->trigger; - SyncCounter *paCounter; - - if (!SyncCheckWarnIsCounter(paTrigger->pSync, - WARN_INVALID_COUNTER_ALARM)) - return; - - paCounter = (SyncCounter *)pTrigger->pSync; - - /* "The alarm is updated by repeatedly adding delta to the - * value of the trigger and re-initializing it until it - * becomes FALSE." - */ - oldvalue = paTrigger->test_value; - - /* XXX really should do something smarter here */ - - do - { - XSyncValueAdd(&paTrigger->test_value, paTrigger->test_value, - pAlarm->delta, &overflow); - } while (!overflow && - (*paTrigger->CheckTrigger)(paTrigger, - paCounter->value)); - - new_test_value = paTrigger->test_value; - paTrigger->test_value = oldvalue; - - /* "If this update would cause value to fall outside the range - * for an INT64...no change is made to value (test-value) and - * the alarm state is changed to Inactive before the event is - * generated." - */ - if (overflow) - { - new_test_value = oldvalue; - pAlarm->state = XSyncAlarmInactive; - } + if (pAlarm->state == XSyncAlarmActive) { + Bool overflow; + CARD64 oldvalue; + SyncTrigger *paTrigger = &pAlarm->trigger; + SyncCounter *paCounter; + + if (!SyncCheckWarnIsCounter(paTrigger->pSync, + WARN_INVALID_COUNTER_ALARM)) + return; + + paCounter = (SyncCounter *) pTrigger->pSync; + + /* "The alarm is updated by repeatedly adding delta to the + * value of the trigger and re-initializing it until it + * becomes FALSE." + */ + oldvalue = paTrigger->test_value; + + /* XXX really should do something smarter here */ + + do { + XSyncValueAdd(&paTrigger->test_value, paTrigger->test_value, + pAlarm->delta, &overflow); + } while (!overflow && + (*paTrigger->CheckTrigger) (paTrigger, paCounter->value)); + + new_test_value = paTrigger->test_value; + paTrigger->test_value = oldvalue; + + /* "If this update would cause value to fall outside the range + * for an INT64...no change is made to value (test-value) and + * the alarm state is changed to Inactive before the event is + * generated." + */ + if (overflow) { + new_test_value = oldvalue; + pAlarm->state = XSyncAlarmInactive; + } } /* The AlarmNotify event has to have the "new state of the alarm" * which we can't be sure of until this point. However, it has @@ -620,28 +601,27 @@ SyncAlarmTriggerFired(SyncTrigger *pTrigger) pTrigger->test_value = new_test_value; } - /* This function is called when an Await unblocks, either as a result * of the trigger firing OR the counter being destroyed. * It goes into pTrigger->TriggerFired AND pTrigger->CounterDestroyed * (for Await triggers). */ static void -SyncAwaitTriggerFired(SyncTrigger *pTrigger) +SyncAwaitTriggerFired(SyncTrigger * pTrigger) { - SyncAwait *pAwait = (SyncAwait *)pTrigger; + SyncAwait *pAwait = (SyncAwait *) pTrigger; int numwaits; SyncAwaitUnion *pAwaitUnion; SyncAwait **ppAwait; int num_events = 0; - pAwaitUnion = (SyncAwaitUnion *)pAwait->pHeader; + pAwaitUnion = (SyncAwaitUnion *) pAwait->pHeader; numwaits = pAwaitUnion->header.num_waitconditions; ppAwait = malloc(numwaits * sizeof(SyncAwait *)); if (!ppAwait) - goto bail; + goto bail; - pAwait = &(pAwaitUnion+1)->await; + pAwait = &(pAwaitUnion + 1)->await; /* "When a client is unblocked, all the CounterNotify events for * the Await request are generated contiguously. If count is 0 @@ -652,132 +632,119 @@ SyncAwaitTriggerFired(SyncTrigger *pTrigger) * need to be sent first, so that an accurate count field can * be stored in the events. */ - for ( ; numwaits; numwaits--, pAwait++) - { - CARD64 diff; - Bool overflow, diffgreater, diffequal; - - /* "A CounterNotify event with the destroyed flag set to TRUE is - * always generated if the counter for one of the triggers is - * destroyed." - */ - if (pAwait->trigger.pSync->beingDestroyed) - { - ppAwait[num_events++] = pAwait; - continue; - } - - if (SYNC_COUNTER == pAwait->trigger.pSync->type) - { - SyncCounter *pCounter = (SyncCounter *) pAwait->trigger.pSync; - - /* "The difference between the counter and the test value is - * calculated by subtracting the test value from the value of - * the counter." - */ - XSyncValueSubtract(&diff, pCounter->value, - pAwait->trigger.test_value, &overflow); - - /* "If the difference lies outside the range for an INT64, an - * event is not generated." - */ - if (overflow) - continue; - diffgreater = XSyncValueGreaterThan(diff, pAwait->event_threshold); - diffequal = XSyncValueEqual(diff, pAwait->event_threshold); - - /* "If the test-type is PositiveTransition or - * PositiveComparison, a CounterNotify event is generated if - * the difference is at least event-threshold. If the test-type - * is NegativeTransition or NegativeComparison, a CounterNotify - * event is generated if the difference is at most - * event-threshold." - */ - - if ( ((pAwait->trigger.test_type == XSyncPositiveComparison || - pAwait->trigger.test_type == XSyncPositiveTransition) - && (diffgreater || diffequal)) - || - ((pAwait->trigger.test_type == XSyncNegativeComparison || - pAwait->trigger.test_type == XSyncNegativeTransition) - && (!diffgreater) /* less or equal */ - ) - ) - { - ppAwait[num_events++] = pAwait; - } - } + for (; numwaits; numwaits--, pAwait++) { + CARD64 diff; + Bool overflow, diffgreater, diffequal; + + /* "A CounterNotify event with the destroyed flag set to TRUE is + * always generated if the counter for one of the triggers is + * destroyed." + */ + if (pAwait->trigger.pSync->beingDestroyed) { + ppAwait[num_events++] = pAwait; + continue; + } + + if (SYNC_COUNTER == pAwait->trigger.pSync->type) { + SyncCounter *pCounter = (SyncCounter *) pAwait->trigger.pSync; + + /* "The difference between the counter and the test value is + * calculated by subtracting the test value from the value of + * the counter." + */ + XSyncValueSubtract(&diff, pCounter->value, + pAwait->trigger.test_value, &overflow); + + /* "If the difference lies outside the range for an INT64, an + * event is not generated." + */ + if (overflow) + continue; + diffgreater = XSyncValueGreaterThan(diff, pAwait->event_threshold); + diffequal = XSyncValueEqual(diff, pAwait->event_threshold); + + /* "If the test-type is PositiveTransition or + * PositiveComparison, a CounterNotify event is generated if + * the difference is at least event-threshold. If the test-type + * is NegativeTransition or NegativeComparison, a CounterNotify + * event is generated if the difference is at most + * event-threshold." + */ + + if (((pAwait->trigger.test_type == XSyncPositiveComparison || + pAwait->trigger.test_type == XSyncPositiveTransition) + && (diffgreater || diffequal)) + || + ((pAwait->trigger.test_type == XSyncNegativeComparison || + pAwait->trigger.test_type == XSyncNegativeTransition) + && (!diffgreater) /* less or equal */ + ) + ) { + ppAwait[num_events++] = pAwait; + } + } } if (num_events) - SyncSendCounterNotifyEvents(pAwaitUnion->header.client, ppAwait, - num_events); + SyncSendCounterNotifyEvents(pAwaitUnion->header.client, ppAwait, + num_events); free(ppAwait); -bail: + bail: /* unblock the client */ AttendClient(pAwaitUnion->header.client); /* delete the await */ FreeResource(pAwaitUnion->header.delete_id, RT_NONE); } - /* This function should always be used to change a counter's value so that * any triggers depending on the counter will be checked. */ void -SyncChangeCounter(SyncCounter *pCounter, CARD64 newval) +SyncChangeCounter(SyncCounter * pCounter, CARD64 newval) { - SyncTriggerList *ptl, *pnext; + SyncTriggerList *ptl, *pnext; CARD64 oldval; oldval = pCounter->value; pCounter->value = newval; /* run through triggers to see if any become true */ - for (ptl = pCounter->sync.pTriglist; ptl; ptl = pnext) - { - pnext = ptl->next; - if ((*ptl->pTrigger->CheckTrigger)(ptl->pTrigger, oldval)) - (*ptl->pTrigger->TriggerFired)(ptl->pTrigger); + for (ptl = pCounter->sync.pTriglist; ptl; ptl = pnext) { + pnext = ptl->next; + if ((*ptl->pTrigger->CheckTrigger) (ptl->pTrigger, oldval)) + (*ptl->pTrigger->TriggerFired) (ptl->pTrigger); } - if (IsSystemCounter(pCounter)) - { - SyncComputeBracketValues(pCounter); + if (IsSystemCounter(pCounter)) { + SyncComputeBracketValues(pCounter); } } - /* loosely based on dix/events.c/EventSelectForWindow */ static Bool -SyncEventSelectForAlarm(SyncAlarm *pAlarm, ClientPtr client, Bool wantevents) +SyncEventSelectForAlarm(SyncAlarm * pAlarm, ClientPtr client, Bool wantevents) { SyncAlarmClientList *pClients; - if (client == pAlarm->client) /* alarm owner */ - { - pAlarm->events = wantevents; - return Success; + if (client == pAlarm->client) { /* alarm owner */ + pAlarm->events = wantevents; + return Success; } /* see if the client is already on the list (has events selected) */ - for (pClients = pAlarm->pEventClients; pClients; - pClients = pClients->next) - { - if (pClients->client == client) - { - /* client's presence on the list indicates desire for - * events. If the client doesn't want events, remove it - * from the list. If the client does want events, do - * nothing, since it's already got them. - */ - if (!wantevents) - { - FreeResource(pClients->delete_id, RT_NONE); - } - return Success; - } + for (pClients = pAlarm->pEventClients; pClients; pClients = pClients->next) { + if (pClients->client == client) { + /* client's presence on the list indicates desire for + * events. If the client doesn't want events, remove it + * from the list. If the client does want events, do + * nothing, since it's already got them. + */ + if (!wantevents) { + FreeResource(pClients->delete_id, RT_NONE); + } + return Success; + } } /* if we get here, this client does not currently have @@ -785,16 +752,16 @@ SyncEventSelectForAlarm(SyncAlarm *pAlarm, ClientPtr client, Bool wantevents) */ if (!wantevents) - /* client doesn't want events, and we just discovered that it - * doesn't have them, so there's nothing to do. - */ - return Success; + /* client doesn't want events, and we just discovered that it + * doesn't have them, so there's nothing to do. + */ + return Success; /* add new client to pAlarm->pEventClients */ pClients = malloc(sizeof(SyncAlarmClientList)); if (!pClients) - return BadAlloc; + return BadAlloc; /* register it as a resource so it will be cleaned up * if the client dies @@ -808,7 +775,7 @@ SyncEventSelectForAlarm(SyncAlarm *pAlarm, ClientPtr client, Bool wantevents) pClients->client = client; if (!AddResource(pClients->delete_id, RTAlarmClient, pAlarm)) - return BadAlloc; + return BadAlloc; return Success; } @@ -817,69 +784,66 @@ SyncEventSelectForAlarm(SyncAlarm *pAlarm, ClientPtr client, Bool wantevents) * ** SyncChangeAlarmAttributes ** This is used by CreateAlarm and ChangeAlarm */ static int -SyncChangeAlarmAttributes(ClientPtr client, SyncAlarm *pAlarm, Mask mask, - CARD32 *values) -{ - int status; - XSyncCounter counter; - Mask origmask = mask; - - counter = - pAlarm->trigger.pSync ? pAlarm->trigger.pSync->id : None; - - while (mask) - { - int index2 = lowbit(mask); - mask &= ~index2; - switch (index2) - { - case XSyncCACounter: - mask &= ~XSyncCACounter; - /* sanity check in SyncInitTrigger */ - counter = *values++; - break; - - case XSyncCAValueType: - mask &= ~XSyncCAValueType; - /* sanity check in SyncInitTrigger */ - pAlarm->trigger.value_type = *values++; - break; - - case XSyncCAValue: - mask &= ~XSyncCAValue; - XSyncIntsToValue(&pAlarm->trigger.wait_value, values[1], values[0]); - values += 2; - break; - - case XSyncCATestType: - mask &= ~XSyncCATestType; - /* sanity check in SyncInitTrigger */ - pAlarm->trigger.test_type = *values++; - break; - - case XSyncCADelta: - mask &= ~XSyncCADelta; - XSyncIntsToValue(&pAlarm->delta, values[1], values[0]); - values += 2; - break; - - case XSyncCAEvents: - mask &= ~XSyncCAEvents; - if ((*values != xTrue) && (*values != xFalse)) - { - client->errorValue = *values; - return BadValue; - } - status = SyncEventSelectForAlarm(pAlarm, client, - (Bool)(*values++)); - if (status != Success) - return status; - break; - - default: - client->errorValue = mask; - return BadValue; - } +SyncChangeAlarmAttributes(ClientPtr client, SyncAlarm * pAlarm, Mask mask, + CARD32 *values) +{ + int status; + XSyncCounter counter; + Mask origmask = mask; + + counter = pAlarm->trigger.pSync ? pAlarm->trigger.pSync->id : None; + + while (mask) { + int index2 = lowbit(mask); + + mask &= ~index2; + switch (index2) { + case XSyncCACounter: + mask &= ~XSyncCACounter; + /* sanity check in SyncInitTrigger */ + counter = *values++; + break; + + case XSyncCAValueType: + mask &= ~XSyncCAValueType; + /* sanity check in SyncInitTrigger */ + pAlarm->trigger.value_type = *values++; + break; + + case XSyncCAValue: + mask &= ~XSyncCAValue; + XSyncIntsToValue(&pAlarm->trigger.wait_value, values[1], values[0]); + values += 2; + break; + + case XSyncCATestType: + mask &= ~XSyncCATestType; + /* sanity check in SyncInitTrigger */ + pAlarm->trigger.test_type = *values++; + break; + + case XSyncCADelta: + mask &= ~XSyncCADelta; + XSyncIntsToValue(&pAlarm->delta, values[1], values[0]); + values += 2; + break; + + case XSyncCAEvents: + mask &= ~XSyncCAEvents; + if ((*values != xTrue) && (*values != xFalse)) { + client->errorValue = *values; + return BadValue; + } + status = SyncEventSelectForAlarm(pAlarm, client, + (Bool) (*values++)); + if (status != Success) + return status; + break; + + default: + client->errorValue = mask; + return BadValue; + } } /* "If the test-type is PositiveComparison or PositiveTransition @@ -887,27 +851,26 @@ SyncChangeAlarmAttributes(ClientPtr client, SyncAlarm *pAlarm, Mask mask, * NegativeComparison or NegativeTransition and delta is * greater than zero, a Match error is generated." */ - if (origmask & (XSyncCADelta|XSyncCATestType)) - { - CARD64 zero; - XSyncIntToValue(&zero, 0); - if ((((pAlarm->trigger.test_type == XSyncPositiveComparison) || - (pAlarm->trigger.test_type == XSyncPositiveTransition)) - && XSyncValueLessThan(pAlarm->delta, zero)) - || - (((pAlarm->trigger.test_type == XSyncNegativeComparison) || - (pAlarm->trigger.test_type == XSyncNegativeTransition)) - && XSyncValueGreaterThan(pAlarm->delta, zero)) - ) - { - return BadMatch; - } + if (origmask & (XSyncCADelta | XSyncCATestType)) { + CARD64 zero; + + XSyncIntToValue(&zero, 0); + if ((((pAlarm->trigger.test_type == XSyncPositiveComparison) || + (pAlarm->trigger.test_type == XSyncPositiveTransition)) + && XSyncValueLessThan(pAlarm->delta, zero)) + || + (((pAlarm->trigger.test_type == XSyncNegativeComparison) || + (pAlarm->trigger.test_type == XSyncNegativeTransition)) + && XSyncValueGreaterThan(pAlarm->delta, zero)) + ) { + return BadMatch; + } } /* postpone this until now, when we're sure nothing else can go wrong */ if ((status = SyncInitTrigger(client, &pAlarm->trigger, counter, RTCounter, - origmask & XSyncCAAllTrigger)) != Success) - return status; + origmask & XSyncCAAllTrigger)) != Success) + return status; /* XXX spec does not really say to do this - needs clarification */ pAlarm->state = XSyncAlarmActive; @@ -921,18 +884,18 @@ SyncCreate(ClientPtr client, XID id, unsigned char type) switch (type) { case SYNC_COUNTER: - pSync = malloc(sizeof(SyncCounter)); - break; + pSync = malloc(sizeof(SyncCounter)); + break; case SYNC_FENCE: - pSync = (SyncObject*)dixAllocateObjectWithPrivates(SyncFence, - PRIVATE_SYNC_FENCE); - break; + pSync = (SyncObject *) dixAllocateObjectWithPrivates(SyncFence, + PRIVATE_SYNC_FENCE); + break; default: - return NULL; + return NULL; } if (!pSync) - return NULL; + return NULL; pSync->client = client; pSync->id = id; @@ -943,22 +906,19 @@ SyncCreate(ClientPtr client, XID id, unsigned char type) return pSync; } - static SyncCounter * SyncCreateCounter(ClientPtr client, XSyncCounter id, CARD64 initialvalue) { SyncCounter *pCounter; - if (!(pCounter = (SyncCounter *)SyncCreate(client, - id, - SYNC_COUNTER))) - return NULL; + if (!(pCounter = (SyncCounter *) SyncCreate(client, id, SYNC_COUNTER))) + return NULL; pCounter->value = initialvalue; pCounter->pSysCounterInfo = NULL; if (!AddResource(id, RTCounter, (pointer) pCounter)) - return NULL; + return NULL; return pCounter; } @@ -969,59 +929,48 @@ static int FreeCounter(void *, XID); * ***** System Counter utilities */ -pointer -SyncCreateSystemCounter( - const char *name, - CARD64 initial, - CARD64 resolution, - SyncCounterType counterType, - void (*QueryValue)(pointer /* pCounter */, - CARD64 * /* pValue_return */), - void (*BracketValues)(pointer /* pCounter */, - CARD64 * /* pbracket_less */, - CARD64 * /* pbracket_greater */) - ) -{ - SyncCounter *pCounter; - - SysCounterList = realloc(SysCounterList, - (SyncNumSystemCounters+1)*sizeof(SyncCounter *)); - if (!SysCounterList) - return NULL; +SyncCounter* +SyncCreateSystemCounter(const char *name, + CARD64 initial, + CARD64 resolution, + SyncCounterType counterType, + SyncSystemCounterQueryValue QueryValue, + SyncSystemCounterBracketValues BracketValues + ) +{ + SyncCounter *pCounter; /* this function may be called before SYNC has been initialized, so we * have to make sure RTCounter is created. */ - if (RTCounter == 0) - { - RTCounter = CreateNewResourceType(FreeCounter, "SyncCounter"); - if (RTCounter == 0) - { - return NULL; - } + if (RTCounter == 0) { + RTCounter = CreateNewResourceType(FreeCounter, "SyncCounter"); + if (RTCounter == 0) { + return NULL; + } } pCounter = SyncCreateCounter(NULL, FakeClientID(0), initial); - if (pCounter) - { - SysCounterInfo *psci; - - psci = malloc(sizeof(SysCounterInfo)); - if (!psci) - { - FreeResource(pCounter->sync.id, RT_NONE); - return pCounter; - } - pCounter->pSysCounterInfo = psci; - psci->name = name; - psci->resolution = resolution; - psci->counterType = counterType; - psci->QueryValue = QueryValue; - psci->BracketValues = BracketValues; - XSyncMaxValue(&psci->bracket_greater); - XSyncMinValue(&psci->bracket_less); - SysCounterList[SyncNumSystemCounters++] = pCounter; + if (pCounter) { + SysCounterInfo *psci; + + psci = malloc(sizeof(SysCounterInfo)); + if (!psci) { + FreeResource(pCounter->sync.id, RT_NONE); + return pCounter; + } + pCounter->pSysCounterInfo = psci; + psci->pCounter = pCounter; + psci->name = strdup(name); + psci->resolution = resolution; + psci->counterType = counterType; + psci->QueryValue = QueryValue; + psci->BracketValues = BracketValues; + psci->private = NULL; + XSyncMaxValue(&psci->bracket_greater); + XSyncMinValue(&psci->bracket_less); + xorg_list_add(&psci->entry, &SysCounterList); } return pCounter; } @@ -1029,12 +978,13 @@ SyncCreateSystemCounter( void SyncDestroySystemCounter(pointer pSysCounter) { - SyncCounter *pCounter = (SyncCounter *)pSysCounter; + SyncCounter *pCounter = (SyncCounter *) pSysCounter; + FreeResource(pCounter->sync.id, RT_NONE); } static void -SyncComputeBracketValues(SyncCounter *pCounter) +SyncComputeBracketValues(SyncCounter * pCounter) { SyncTriggerList *pCur; SyncTrigger *pTrigger; @@ -1044,89 +994,81 @@ SyncComputeBracketValues(SyncCounter *pCounter) SyncCounterType ct; if (!pCounter) - return; + return; psci = pCounter->pSysCounterInfo; ct = pCounter->pSysCounterInfo->counterType; if (ct == XSyncCounterNeverChanges) - return; + return; XSyncMaxValue(&psci->bracket_greater); XSyncMinValue(&psci->bracket_less); - for (pCur = pCounter->sync.pTriglist; pCur; pCur = pCur->next) - { - pTrigger = pCur->pTrigger; - + for (pCur = pCounter->sync.pTriglist; pCur; pCur = pCur->next) { + pTrigger = pCur->pTrigger; + if (pTrigger->test_type == XSyncPositiveComparison && - ct != XSyncCounterNeverIncreases) - { - if (XSyncValueLessThan(pCounter->value, pTrigger->test_value) && - XSyncValueLessThan(pTrigger->test_value, - psci->bracket_greater)) - { - psci->bracket_greater = pTrigger->test_value; - pnewgtval = &psci->bracket_greater; - } - } - else if (pTrigger->test_type == XSyncNegativeComparison && - ct != XSyncCounterNeverDecreases) - { - if (XSyncValueGreaterThan(pCounter->value, pTrigger->test_value) && - XSyncValueGreaterThan(pTrigger->test_value, - psci->bracket_less)) - { - psci->bracket_less = pTrigger->test_value; - pnewltval = &psci->bracket_less; - } - } - else if (pTrigger->test_type == XSyncNegativeTransition && - ct != XSyncCounterNeverIncreases) - { - if (XSyncValueGreaterThan(pCounter->value, pTrigger->test_value) && - XSyncValueGreaterThan(pTrigger->test_value, psci->bracket_less)) - { - psci->bracket_less = pTrigger->test_value; - pnewltval = &psci->bracket_less; - } else if (XSyncValueEqual(pCounter->value, pTrigger->test_value) && - XSyncValueLessThan(pTrigger->test_value, - psci->bracket_greater)) - { - /* - * The value is exactly equal to our threshold. We want one - * more event in the positive direction to ensure we pick up - * when the value *exceeds* this threshold. - */ - psci->bracket_greater = pTrigger->test_value; - pnewgtval = &psci->bracket_greater; - } - } + ct != XSyncCounterNeverIncreases) { + if (XSyncValueLessThan(pCounter->value, pTrigger->test_value) && + XSyncValueLessThan(pTrigger->test_value, + psci->bracket_greater)) { + psci->bracket_greater = pTrigger->test_value; + pnewgtval = &psci->bracket_greater; + } + } + else if (pTrigger->test_type == XSyncNegativeComparison && + ct != XSyncCounterNeverDecreases) { + if (XSyncValueGreaterThan(pCounter->value, pTrigger->test_value) && + XSyncValueGreaterThan(pTrigger->test_value, + psci->bracket_less)) { + psci->bracket_less = pTrigger->test_value; + pnewltval = &psci->bracket_less; + } + } + else if (pTrigger->test_type == XSyncNegativeTransition && + ct != XSyncCounterNeverIncreases) { + if (XSyncValueGreaterThan(pCounter->value, pTrigger->test_value) && + XSyncValueGreaterThan(pTrigger->test_value, psci->bracket_less)) + { + psci->bracket_less = pTrigger->test_value; + pnewltval = &psci->bracket_less; + } + else if (XSyncValueEqual(pCounter->value, pTrigger->test_value) && + XSyncValueLessThan(pTrigger->test_value, + psci->bracket_greater)) { + /* + * The value is exactly equal to our threshold. We want one + * more event in the positive direction to ensure we pick up + * when the value *exceeds* this threshold. + */ + psci->bracket_greater = pTrigger->test_value; + pnewgtval = &psci->bracket_greater; + } + } else if (pTrigger->test_type == XSyncPositiveTransition && - ct != XSyncCounterNeverDecreases) - { - if (XSyncValueLessThan(pCounter->value, pTrigger->test_value) && - XSyncValueLessThan(pTrigger->test_value, psci->bracket_greater)) - { - psci->bracket_greater = pTrigger->test_value; - pnewgtval = &psci->bracket_greater; - } else if (XSyncValueEqual(pCounter->value, pTrigger->test_value) && - XSyncValueGreaterThan(pTrigger->test_value, - psci->bracket_less)) - { - /* - * The value is exactly equal to our threshold. We want one - * more event in the negative direction to ensure we pick up - * when the value is less than this threshold. - */ - psci->bracket_less = pTrigger->test_value; - pnewltval = &psci->bracket_less; - } - } - } /* end for each trigger */ - - if (pnewgtval || pnewltval) - { - (*psci->BracketValues)((pointer)pCounter, pnewltval, pnewgtval); + ct != XSyncCounterNeverDecreases) { + if (XSyncValueLessThan(pCounter->value, pTrigger->test_value) && + XSyncValueLessThan(pTrigger->test_value, psci->bracket_greater)) + { + psci->bracket_greater = pTrigger->test_value; + pnewgtval = &psci->bracket_greater; + } + else if (XSyncValueEqual(pCounter->value, pTrigger->test_value) && + XSyncValueGreaterThan(pTrigger->test_value, + psci->bracket_less)) { + /* + * The value is exactly equal to our threshold. We want one + * more event in the negative direction to ensure we pick up + * when the value is less than this threshold. + */ + psci->bracket_less = pTrigger->test_value; + pnewltval = &psci->bracket_less; + } + } + } /* end for each trigger */ + + if (pnewgtval || pnewltval) { + (*psci->BracketValues) ((pointer) pCounter, pnewltval, pnewgtval); } } @@ -1138,7 +1080,7 @@ SyncComputeBracketValues(SyncCounter *pCounter) static int FreeAlarm(void *addr, XID id) { - SyncAlarm *pAlarm = (SyncAlarm *) addr; + SyncAlarm *pAlarm = (SyncAlarm *) addr; pAlarm->state = XSyncAlarmDestroyed; @@ -1147,7 +1089,7 @@ FreeAlarm(void *addr, XID id) /* delete event selections */ while (pAlarm->pEventClients) - FreeResource(pAlarm->pEventClients->delete_id, RT_NONE); + FreeResource(pAlarm->pEventClients->delete_id, RT_NONE); SyncDeleteTriggerFromSyncObject(&pAlarm->trigger); @@ -1155,7 +1097,6 @@ FreeAlarm(void *addr, XID id) return Success; } - /* * ** Cleanup after the destruction of a Counter */ @@ -1163,44 +1104,21 @@ FreeAlarm(void *addr, XID id) static int FreeCounter(void *env, XID id) { - SyncCounter *pCounter = (SyncCounter *) env; + SyncCounter *pCounter = (SyncCounter *) env; SyncTriggerList *ptl, *pnext; pCounter->sync.beingDestroyed = TRUE; /* tell all the counter's triggers that the counter has been destroyed */ - for (ptl = pCounter->sync.pTriglist; ptl; ptl = pnext) - { - (*ptl->pTrigger->CounterDestroyed)(ptl->pTrigger); - pnext = ptl->next; - free(ptl); /* destroy the trigger list as we go */ - } - if (IsSystemCounter(pCounter)) - { - int i, found = 0; - - free(pCounter->pSysCounterInfo); - - /* find the counter in the list of system counters and remove it */ - - if (SysCounterList) - { - for (i = 0; i < SyncNumSystemCounters; i++) - { - if (SysCounterList[i] == pCounter) - { - found = i; - break; - } - } - if (found < (SyncNumSystemCounters-1)) - { - for (i = found; i < SyncNumSystemCounters-1; i++) - { - SysCounterList[i] = SysCounterList[i+1]; - } - } - } - SyncNumSystemCounters--; + for (ptl = pCounter->sync.pTriglist; ptl; ptl = pnext) { + (*ptl->pTrigger->CounterDestroyed) (ptl->pTrigger); + pnext = ptl->next; + free(ptl); /* destroy the trigger list as we go */ + } + if (IsSystemCounter(pCounter)) { + xorg_list_del(&pCounter->pSysCounterInfo->entry); + free(pCounter->pSysCounterInfo->name); + free(pCounter->pSysCounterInfo->private); + free(pCounter->pSysCounterInfo); } free(pCounter); return Success; @@ -1217,19 +1135,19 @@ FreeAwait(void *addr, XID id) SyncAwait *pAwait; int numwaits; - pAwait = &(pAwaitUnion+1)->await; /* first await on list */ + pAwait = &(pAwaitUnion + 1)->await; /* first await on list */ /* remove triggers from counters */ for (numwaits = pAwaitUnion->header.num_waitconditions; numwaits; - numwaits--, pAwait++) - { - /* If the counter is being destroyed, FreeCounter will delete - * the trigger list itself, so don't do it here. - */ - SyncObject *pSync = pAwait->trigger.pSync; - if (pSync && !pSync->beingDestroyed) - SyncDeleteTriggerFromSyncObject(&pAwait->trigger); + numwaits--, pAwait++) { + /* If the counter is being destroyed, FreeCounter will delete + * the trigger list itself, so don't do it here. + */ + SyncObject *pSync = pAwait->trigger.pSync; + + if (pSync && !pSync->beingDestroyed) + SyncDeleteTriggerFromSyncObject(&pAwait->trigger); } free(pAwaitUnion); return Success; @@ -1243,40 +1161,35 @@ FreeAwait(void *addr, XID id) static int FreeAlarmClient(void *value, XID id) { - SyncAlarm *pAlarm = (SyncAlarm *)value; + SyncAlarm *pAlarm = (SyncAlarm *) value; SyncAlarmClientList *pCur, *pPrev; for (pPrev = NULL, pCur = pAlarm->pEventClients; - pCur; - pPrev = pCur, pCur = pCur->next) - { - if (pCur->delete_id == id) - { - if (pPrev) - pPrev->next = pCur->next; - else - pAlarm->pEventClients = pCur->next; - free(pCur); - return Success; - } + pCur; pPrev = pCur, pCur = pCur->next) { + if (pCur->delete_id == id) { + if (pPrev) + pPrev->next = pCur->next; + else + pAlarm->pEventClients = pCur->next; + free(pCur); + return Success; + } } FatalError("alarm client not on event list"); - /*NOTREACHED*/ -} - + /*NOTREACHED*/} /* * ***** Proc functions */ - /* * ** Initialize the extension */ static int ProcSyncInitialize(ClientPtr client) { - xSyncInitializeReply rep; + xSyncInitializeReply rep; + REQUEST_SIZE_MATCH(xSyncInitializeReq); memset(&rep, 0, sizeof(xSyncInitializeReply)); @@ -1286,9 +1199,8 @@ ProcSyncInitialize(ClientPtr client) rep.minorVersion = SERVER_SYNC_MINOR_VERSION; rep.length = 0; - if (client->swapped) - { - swaps(&rep.sequenceNumber); + if (client->swapped) { + swaps(&rep.sequenceNumber); } WriteToClient(client, sizeof(rep), (char *) &rep); return Success; @@ -1300,70 +1212,65 @@ ProcSyncInitialize(ClientPtr client) static int ProcSyncListSystemCounters(ClientPtr client) { - xSyncListSystemCountersReply rep; - int i, len; + xSyncListSystemCountersReply rep; + SysCounterInfo *psci=NULL; + int len = 0; xSyncSystemCounter *list = NULL, *walklist = NULL; REQUEST_SIZE_MATCH(xSyncListSystemCountersReq); rep.type = X_Reply; rep.sequenceNumber = client->sequence; - rep.nCounters = SyncNumSystemCounters; + rep.nCounters = 0; - for (i = len = 0; i < SyncNumSystemCounters; i++) - { - const char *name = SysCounterList[i]->pSysCounterInfo->name; - /* pad to 4 byte boundary */ - len += pad_to_int32(sz_xSyncSystemCounter + strlen(name)); + xorg_list_for_each_entry(psci, &SysCounterList, entry) { + /* pad to 4 byte boundary */ + len += pad_to_int32(sz_xSyncSystemCounter + strlen(psci->name)); + ++rep.nCounters; } - if (len) - { - walklist = list = malloc(len); - if (!list) - return BadAlloc; + if (len) { + walklist = list = malloc(len); + if (!list) + return BadAlloc; } rep.length = bytes_to_int32(len); - if (client->swapped) - { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.nCounters); + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.nCounters); } - for (i = 0; i < SyncNumSystemCounters; i++) - { - int namelen; - char *pname_in_reply; - SysCounterInfo *psci = SysCounterList[i]->pSysCounterInfo; + xorg_list_for_each_entry(psci, &SysCounterList, entry) { + int namelen; + char *pname_in_reply; - walklist->counter = SysCounterList[i]->sync.id; - walklist->resolution_hi = XSyncValueHigh32(psci->resolution); - walklist->resolution_lo = XSyncValueLow32(psci->resolution); - namelen = strlen(psci->name); - walklist->name_length = namelen; + walklist->counter = psci->pCounter->sync.id; + walklist->resolution_hi = XSyncValueHigh32(psci->resolution); + walklist->resolution_lo = XSyncValueLow32(psci->resolution); + namelen = strlen(psci->name); + walklist->name_length = namelen; - if (client->swapped) - { - swapl(&walklist->counter); - swapl(&walklist->resolution_hi); - swapl(&walklist->resolution_lo); - swaps(&walklist->name_length); - } + if (client->swapped) { + swapl(&walklist->counter); + swapl(&walklist->resolution_hi); + swapl(&walklist->resolution_lo); + swaps(&walklist->name_length); + } - pname_in_reply = ((char *)walklist) + sz_xSyncSystemCounter; - strncpy(pname_in_reply, psci->name, namelen); - walklist = (xSyncSystemCounter *) (((char *)walklist) + - pad_to_int32(sz_xSyncSystemCounter + namelen)); + pname_in_reply = ((char *) walklist) + sz_xSyncSystemCounter; + strncpy(pname_in_reply, psci->name, namelen); + walklist = (xSyncSystemCounter *) (((char *) walklist) + + pad_to_int32(sz_xSyncSystemCounter + + namelen)); } WriteToClient(client, sizeof(rep), (char *) &rep); - if (len) - { - WriteToClient(client, len, (char *) list); - free(list); + if (len) { + WriteToClient(client, len, (char *) list); + free(list); } return Success; @@ -1382,24 +1289,23 @@ ProcSyncSetPriority(ClientPtr client) REQUEST_SIZE_MATCH(xSyncSetPriorityReq); if (stuff->id == None) - priorityclient = client; + priorityclient = client; else { - rc = dixLookupClient(&priorityclient, stuff->id, client, - DixSetAttrAccess); - if (rc != Success) - return rc; + rc = dixLookupClient(&priorityclient, stuff->id, client, + DixSetAttrAccess); + if (rc != Success) + return rc; } - if (priorityclient->priority != stuff->priority) - { - priorityclient->priority = stuff->priority; + if (priorityclient->priority != stuff->priority) { + priorityclient->priority = stuff->priority; - /* The following will force the server back into WaitForSomething - * so that the change in this client's priority is immediately - * reflected. - */ - isItTimeToYield = TRUE; - dispatchException |= DE_PRIORITYCHANGE; + /* The following will force the server back into WaitForSomething + * so that the change in this client's priority is immediately + * reflected. + */ + isItTimeToYield = TRUE; + dispatchException |= DE_PRIORITYCHANGE; } return Success; } @@ -1418,12 +1324,12 @@ ProcSyncGetPriority(ClientPtr client) REQUEST_SIZE_MATCH(xSyncGetPriorityReq); if (stuff->id == None) - priorityclient = client; + priorityclient = client; else { - rc = dixLookupClient(&priorityclient, stuff->id, client, - DixGetAttrAccess); - if (rc != Success) - return rc; + rc = dixLookupClient(&priorityclient, stuff->id, client, + DixGetAttrAccess); + if (rc != Success) + return rc; } rep.type = X_Reply; @@ -1431,10 +1337,9 @@ ProcSyncGetPriority(ClientPtr client) rep.sequenceNumber = client->sequence; rep.priority = priorityclient->priority; - if (client->swapped) - { - swaps(&rep.sequenceNumber); - swapl(&rep.priority); + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.priority); } WriteToClient(client, sizeof(xSyncGetPriorityReply), (char *) &rep); @@ -1449,15 +1354,16 @@ static int ProcSyncCreateCounter(ClientPtr client) { REQUEST(xSyncCreateCounterReq); - CARD64 initial; + CARD64 initial; REQUEST_SIZE_MATCH(xSyncCreateCounterReq); LEGAL_NEW_RESOURCE(stuff->cid, client); - XSyncIntsToValue(&initial, stuff->initial_value_lo, stuff->initial_value_hi); + XSyncIntsToValue(&initial, stuff->initial_value_lo, + stuff->initial_value_hi); if (!SyncCreateCounter(client, stuff->cid, initial)) - return BadAlloc; + return BadAlloc; return Success; } @@ -1469,21 +1375,20 @@ static int ProcSyncSetCounter(ClientPtr client) { REQUEST(xSyncSetCounterReq); - SyncCounter *pCounter; - CARD64 newvalue; - int rc; + SyncCounter *pCounter; + CARD64 newvalue; + int rc; REQUEST_SIZE_MATCH(xSyncSetCounterReq); - rc = dixLookupResourceByType((pointer *)&pCounter, stuff->cid, RTCounter, - client, DixWriteAccess); + rc = dixLookupResourceByType((pointer *) &pCounter, stuff->cid, RTCounter, + client, DixWriteAccess); if (rc != Success) - return rc; + return rc; - if (IsSystemCounter(pCounter)) - { - client->errorValue = stuff->cid; - return BadAccess; + if (IsSystemCounter(pCounter)) { + client->errorValue = stuff->cid; + return BadAccess; } XSyncIntsToValue(&newvalue, stuff->value_lo, stuff->value_hi); @@ -1498,31 +1403,29 @@ static int ProcSyncChangeCounter(ClientPtr client) { REQUEST(xSyncChangeCounterReq); - SyncCounter *pCounter; - CARD64 newvalue; - Bool overflow; - int rc; + SyncCounter *pCounter; + CARD64 newvalue; + Bool overflow; + int rc; REQUEST_SIZE_MATCH(xSyncChangeCounterReq); - rc = dixLookupResourceByType((pointer *)&pCounter, stuff->cid, RTCounter, - client, DixWriteAccess); + rc = dixLookupResourceByType((pointer *) &pCounter, stuff->cid, RTCounter, + client, DixWriteAccess); if (rc != Success) - return rc; + return rc; - if (IsSystemCounter(pCounter)) - { - client->errorValue = stuff->cid; - return BadAccess; + if (IsSystemCounter(pCounter)) { + client->errorValue = stuff->cid; + return BadAccess; } XSyncIntsToValue(&newvalue, stuff->value_lo, stuff->value_hi); XSyncValueAdd(&newvalue, pCounter->value, newvalue, &overflow); - if (overflow) - { - /* XXX 64 bit value can't fit in 32 bits; do the best we can */ - client->errorValue = stuff->value_hi; - return BadValue; + if (overflow) { + /* XXX 64 bit value can't fit in 32 bits; do the best we can */ + client->errorValue = stuff->value_hi; + return BadValue; } SyncChangeCounter(pCounter, newvalue); return Success; @@ -1535,26 +1438,25 @@ static int ProcSyncDestroyCounter(ClientPtr client) { REQUEST(xSyncDestroyCounterReq); - SyncCounter *pCounter; + SyncCounter *pCounter; int rc; REQUEST_SIZE_MATCH(xSyncDestroyCounterReq); - rc = dixLookupResourceByType((pointer *)&pCounter, stuff->counter, RTCounter, - client, DixDestroyAccess); + rc = dixLookupResourceByType((pointer *) &pCounter, stuff->counter, + RTCounter, client, DixDestroyAccess); if (rc != Success) - return rc; + return rc; - if (IsSystemCounter(pCounter)) - { - client->errorValue = stuff->counter; - return BadAccess; + if (IsSystemCounter(pCounter)) { + client->errorValue = stuff->counter; + return BadAccess; } FreeResource(pCounter->sync.id, RT_NONE); return Success; } -static SyncAwaitUnion* +static SyncAwaitUnion * SyncAwaitPrologue(ClientPtr client, int items) { SyncAwaitUnion *pAwaitUnion; @@ -1562,9 +1464,9 @@ SyncAwaitPrologue(ClientPtr client, int items) /* all the memory for the entire await list is allocated * here in one chunk */ - pAwaitUnion = malloc((items+1) * sizeof(SyncAwaitUnion)); + pAwaitUnion = malloc((items + 1) * sizeof(SyncAwaitUnion)); if (!pAwaitUnion) - return NULL; + return NULL; /* first item is the header, remainder are real wait conditions */ @@ -1573,13 +1475,13 @@ SyncAwaitPrologue(ClientPtr client, int items) pAwaitUnion->header.num_waitconditions = 0; if (!AddResource(pAwaitUnion->header.delete_id, RTAwait, pAwaitUnion)) - return NULL; + return NULL; return pAwaitUnion; } static void -SyncAwaitEpilogue(ClientPtr client, int items, SyncAwaitUnion *pAwaitUnion) +SyncAwaitEpilogue(ClientPtr client, int items, SyncAwaitUnion * pAwaitUnion) { SyncAwait *pAwait; int i; @@ -1588,27 +1490,25 @@ SyncAwaitEpilogue(ClientPtr client, int items, SyncAwaitUnion *pAwaitUnion) /* see if any of the triggers are already true */ - pAwait = &(pAwaitUnion+1)->await; /* skip over header */ - for (i = 0; i < items; i++, pAwait++) - { - CARD64 value; - - /* don't have to worry about NULL counters because the request - * errors before we get here out if they occur - */ - switch (pAwait->trigger.pSync->type) { - case SYNC_COUNTER: - value = ((SyncCounter *)pAwait->trigger.pSync)->value; - break; - default: - XSyncIntToValue(&value, 0); - } + pAwait = &(pAwaitUnion + 1)->await; /* skip over header */ + for (i = 0; i < items; i++, pAwait++) { + CARD64 value; + + /* don't have to worry about NULL counters because the request + * errors before we get here out if they occur + */ + switch (pAwait->trigger.pSync->type) { + case SYNC_COUNTER: + value = ((SyncCounter *) pAwait->trigger.pSync)->value; + break; + default: + XSyncIntToValue(&value, 0); + } - if ((*pAwait->trigger.CheckTrigger)(&pAwait->trigger, value)) - { - (*pAwait->trigger.TriggerFired)(&pAwait->trigger); - break; /* once is enough */ - } + if ((*pAwait->trigger.CheckTrigger) (&pAwait->trigger, value)) { + (*pAwait->trigger.TriggerFired) (&pAwait->trigger); + break; /* once is enough */ + } } } @@ -1619,12 +1519,12 @@ static int ProcSyncAwait(ClientPtr client) { REQUEST(xSyncAwaitReq); - int len, items; - int i; + int len, items; + int i; xSyncWaitCondition *pProtocolWaitConds; SyncAwaitUnion *pAwaitUnion; - SyncAwait *pAwait; - int status; + SyncAwait *pAwait; + int status; REQUEST_AT_LEAST_SIZE(xSyncAwaitReq); @@ -1632,63 +1532,58 @@ ProcSyncAwait(ClientPtr client) len -= sz_xSyncAwaitReq; items = len / sz_xSyncWaitCondition; - if (items * sz_xSyncWaitCondition != len) - { - return BadLength; + if (items * sz_xSyncWaitCondition != len) { + return BadLength; } - if (items == 0) - { - client->errorValue = items; /* XXX protocol change */ - return BadValue; + if (items == 0) { + client->errorValue = items; /* XXX protocol change */ + return BadValue; } if (!(pAwaitUnion = SyncAwaitPrologue(client, items))) - return BadAlloc; + return BadAlloc; /* don't need to do any more memory allocation for this request! */ - pProtocolWaitConds = (xSyncWaitCondition *) & stuff[1]; - - pAwait = &(pAwaitUnion+1)->await; /* skip over header */ - for (i = 0; i < items; i++, pProtocolWaitConds++, pAwait++) - { - if (pProtocolWaitConds->counter == None) /* XXX protocol change */ - { - /* this should take care of removing any triggers created by - * this request that have already been registered on sync objects - */ - FreeResource(pAwaitUnion->header.delete_id, RT_NONE); - client->errorValue = pProtocolWaitConds->counter; - return SyncErrorBase + XSyncBadCounter; - } - - /* sanity checks are in SyncInitTrigger */ - pAwait->trigger.pSync = NULL; - pAwait->trigger.value_type = pProtocolWaitConds->value_type; - XSyncIntsToValue(&pAwait->trigger.wait_value, - pProtocolWaitConds->wait_value_lo, - pProtocolWaitConds->wait_value_hi); - pAwait->trigger.test_type = pProtocolWaitConds->test_type; - - status = SyncInitTrigger(client, &pAwait->trigger, - pProtocolWaitConds->counter, RTCounter, - XSyncCAAllTrigger); - if (status != Success) - { - /* this should take care of removing any triggers created by - * this request that have already been registered on sync objects - */ - FreeResource(pAwaitUnion->header.delete_id, RT_NONE); - return status; - } - /* this is not a mistake -- same function works for both cases */ - pAwait->trigger.TriggerFired = SyncAwaitTriggerFired; - pAwait->trigger.CounterDestroyed = SyncAwaitTriggerFired; - XSyncIntsToValue(&pAwait->event_threshold, - pProtocolWaitConds->event_threshold_lo, - pProtocolWaitConds->event_threshold_hi); - pAwait->pHeader = &pAwaitUnion->header; - pAwaitUnion->header.num_waitconditions++; + pProtocolWaitConds = (xSyncWaitCondition *) &stuff[1]; + + pAwait = &(pAwaitUnion + 1)->await; /* skip over header */ + for (i = 0; i < items; i++, pProtocolWaitConds++, pAwait++) { + if (pProtocolWaitConds->counter == None) { /* XXX protocol change */ + /* this should take care of removing any triggers created by + * this request that have already been registered on sync objects + */ + FreeResource(pAwaitUnion->header.delete_id, RT_NONE); + client->errorValue = pProtocolWaitConds->counter; + return SyncErrorBase + XSyncBadCounter; + } + + /* sanity checks are in SyncInitTrigger */ + pAwait->trigger.pSync = NULL; + pAwait->trigger.value_type = pProtocolWaitConds->value_type; + XSyncIntsToValue(&pAwait->trigger.wait_value, + pProtocolWaitConds->wait_value_lo, + pProtocolWaitConds->wait_value_hi); + pAwait->trigger.test_type = pProtocolWaitConds->test_type; + + status = SyncInitTrigger(client, &pAwait->trigger, + pProtocolWaitConds->counter, RTCounter, + XSyncCAAllTrigger); + if (status != Success) { + /* this should take care of removing any triggers created by + * this request that have already been registered on sync objects + */ + FreeResource(pAwaitUnion->header.delete_id, RT_NONE); + return status; + } + /* this is not a mistake -- same function works for both cases */ + pAwait->trigger.TriggerFired = SyncAwaitTriggerFired; + pAwait->trigger.CounterDestroyed = SyncAwaitTriggerFired; + XSyncIntsToValue(&pAwait->event_threshold, + pProtocolWaitConds->event_threshold_lo, + pProtocolWaitConds->event_threshold_hi); + pAwait->pHeader = &pAwaitUnion->header; + pAwaitUnion->header.num_waitconditions++; } SyncAwaitEpilogue(client, items, pAwaitUnion); @@ -1696,7 +1591,6 @@ ProcSyncAwait(ClientPtr client) return Success; } - /* * ** Query a counter */ @@ -1705,15 +1599,15 @@ ProcSyncQueryCounter(ClientPtr client) { REQUEST(xSyncQueryCounterReq); xSyncQueryCounterReply rep; - SyncCounter *pCounter; + SyncCounter *pCounter; int rc; REQUEST_SIZE_MATCH(xSyncQueryCounterReq); - rc = dixLookupResourceByType((pointer *)&pCounter, stuff->counter, - RTCounter, client, DixReadAccess); + rc = dixLookupResourceByType((pointer *) &pCounter, stuff->counter, + RTCounter, client, DixReadAccess); if (rc != Success) - return rc; + return rc; rep.type = X_Reply; rep.length = 0; @@ -1721,26 +1615,23 @@ ProcSyncQueryCounter(ClientPtr client) /* if system counter, ask it what the current value is */ - if (IsSystemCounter(pCounter)) - { - (*pCounter->pSysCounterInfo->QueryValue) ((pointer) pCounter, - &pCounter->value); + if (IsSystemCounter(pCounter)) { + (*pCounter->pSysCounterInfo->QueryValue) ((pointer) pCounter, + &pCounter->value); } rep.value_hi = XSyncValueHigh32(pCounter->value); rep.value_lo = XSyncValueLow32(pCounter->value); - if (client->swapped) - { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.value_hi); - swapl(&rep.value_lo); + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.value_hi); + swapl(&rep.value_lo); } WriteToClient(client, sizeof(xSyncQueryCounterReply), (char *) &rep); return Success; } - /* * ** Create Alarm */ @@ -1748,10 +1639,10 @@ static int ProcSyncCreateAlarm(ClientPtr client) { REQUEST(xSyncCreateAlarmReq); - SyncAlarm *pAlarm; - int status; - unsigned long len, vmask; - SyncTrigger *pTrigger; + SyncAlarm *pAlarm; + int status; + unsigned long len, vmask; + SyncTrigger *pTrigger; REQUEST_AT_LEAST_SIZE(xSyncCreateAlarmReq); @@ -1760,12 +1651,11 @@ ProcSyncCreateAlarm(ClientPtr client) vmask = stuff->valueMask; len = client->req_len - bytes_to_int32(sizeof(xSyncCreateAlarmReq)); /* the "extra" call to Ones accounts for the presence of 64 bit values */ - if (len != (Ones(vmask) + Ones(vmask & (XSyncCAValue|XSyncCADelta)))) - return BadLength; + if (len != (Ones(vmask) + Ones(vmask & (XSyncCAValue | XSyncCADelta)))) + return BadLength; - if (!(pAlarm = malloc(sizeof(SyncAlarm)))) - { - return BadAlloc; + if (!(pAlarm = malloc(sizeof(SyncAlarm)))) { + return BadAlloc; } /* set up defaults */ @@ -1778,11 +1668,10 @@ ProcSyncCreateAlarm(ClientPtr client) pTrigger->TriggerFired = SyncAlarmTriggerFired; pTrigger->CounterDestroyed = SyncAlarmCounterDestroyed; status = SyncInitTrigger(client, pTrigger, None, RTCounter, - XSyncCAAllTrigger); - if (status != Success) - { - free(pAlarm); - return status; + XSyncCAAllTrigger); + if (status != Success) { + free(pAlarm); + return status; } pAlarm->client = client; @@ -1792,39 +1681,35 @@ ProcSyncCreateAlarm(ClientPtr client) pAlarm->state = XSyncAlarmInactive; pAlarm->pEventClients = NULL; status = SyncChangeAlarmAttributes(client, pAlarm, vmask, - (CARD32 *)&stuff[1]); - if (status != Success) - { - free(pAlarm); - return status; + (CARD32 *) &stuff[1]); + if (status != Success) { + free(pAlarm); + return status; } if (!AddResource(stuff->id, RTAlarm, pAlarm)) - return BadAlloc; + return BadAlloc; /* see if alarm already triggered. NULL counter will not trigger * in CreateAlarm and sets alarm state to Inactive. */ - if (!pTrigger->pSync) - { - pAlarm->state = XSyncAlarmInactive; /* XXX protocol change */ + if (!pTrigger->pSync) { + pAlarm->state = XSyncAlarmInactive; /* XXX protocol change */ } - else - { - SyncCounter *pCounter; + else { + SyncCounter *pCounter; - if (!SyncCheckWarnIsCounter(pTrigger->pSync, - WARN_INVALID_COUNTER_ALARM)) - { - FreeResource(stuff->id, RT_NONE); - return BadAlloc; - } + if (!SyncCheckWarnIsCounter(pTrigger->pSync, + WARN_INVALID_COUNTER_ALARM)) { + FreeResource(stuff->id, RT_NONE); + return BadAlloc; + } - pCounter = (SyncCounter *)pTrigger->pSync; + pCounter = (SyncCounter *) pTrigger->pSync; - if ((*pTrigger->CheckTrigger)(pTrigger, pCounter->value)) - (*pTrigger->TriggerFired)(pTrigger); + if ((*pTrigger->CheckTrigger) (pTrigger, pCounter->value)) + (*pTrigger->TriggerFired) (pTrigger); } return Success; @@ -1837,40 +1722,39 @@ static int ProcSyncChangeAlarm(ClientPtr client) { REQUEST(xSyncChangeAlarmReq); - SyncAlarm *pAlarm; + SyncAlarm *pAlarm; SyncCounter *pCounter = NULL; - long vmask; - int len, status; + long vmask; + int len, status; REQUEST_AT_LEAST_SIZE(xSyncChangeAlarmReq); - status = dixLookupResourceByType((pointer *)&pAlarm, stuff->alarm, RTAlarm, - client, DixWriteAccess); + status = dixLookupResourceByType((pointer *) &pAlarm, stuff->alarm, RTAlarm, + client, DixWriteAccess); if (status != Success) - return status; + return status; vmask = stuff->valueMask; len = client->req_len - bytes_to_int32(sizeof(xSyncChangeAlarmReq)); /* the "extra" call to Ones accounts for the presence of 64 bit values */ - if (len != (Ones(vmask) + Ones(vmask & (XSyncCAValue|XSyncCADelta)))) - return BadLength; + if (len != (Ones(vmask) + Ones(vmask & (XSyncCAValue | XSyncCADelta)))) + return BadLength; if ((status = SyncChangeAlarmAttributes(client, pAlarm, vmask, - (CARD32 *)&stuff[1])) != Success) - return status; + (CARD32 *) &stuff[1])) != Success) + return status; if (SyncCheckWarnIsCounter(pAlarm->trigger.pSync, - WARN_INVALID_COUNTER_ALARM)) - pCounter = (SyncCounter *)pAlarm->trigger.pSync; + WARN_INVALID_COUNTER_ALARM)) + pCounter = (SyncCounter *) pAlarm->trigger.pSync; /* see if alarm already triggered. NULL counter WILL trigger * in ChangeAlarm. */ if (!pCounter || - (*pAlarm->trigger.CheckTrigger)(&pAlarm->trigger, pCounter->value)) - { - (*pAlarm->trigger.TriggerFired)(&pAlarm->trigger); + (*pAlarm->trigger.CheckTrigger) (&pAlarm->trigger, pCounter->value)) { + (*pAlarm->trigger.TriggerFired) (&pAlarm->trigger); } return Success; } @@ -1879,29 +1763,30 @@ static int ProcSyncQueryAlarm(ClientPtr client) { REQUEST(xSyncQueryAlarmReq); - SyncAlarm *pAlarm; + SyncAlarm *pAlarm; xSyncQueryAlarmReply rep; - SyncTrigger *pTrigger; + SyncTrigger *pTrigger; int rc; REQUEST_SIZE_MATCH(xSyncQueryAlarmReq); - rc = dixLookupResourceByType((pointer *)&pAlarm, stuff->alarm, RTAlarm, - client, DixReadAccess); + rc = dixLookupResourceByType((pointer *) &pAlarm, stuff->alarm, RTAlarm, + client, DixReadAccess); if (rc != Success) - return rc; + return rc; rep.type = X_Reply; - rep.length = bytes_to_int32(sizeof(xSyncQueryAlarmReply) - sizeof(xGenericReply)); + rep.length = + bytes_to_int32(sizeof(xSyncQueryAlarmReply) - sizeof(xGenericReply)); rep.sequenceNumber = client->sequence; pTrigger = &pAlarm->trigger; rep.counter = (pTrigger->pSync) ? pTrigger->pSync->id : None; -#if 0 /* XXX unclear what to do, depends on whether relative value-types - * are "consumed" immediately and are considered absolute from then - * on. - */ +#if 0 /* XXX unclear what to do, depends on whether relative value-types + * are "consumed" immediately and are considered absolute from then + * on. + */ rep.value_type = pTrigger->value_type; rep.wait_value_hi = XSyncValueHigh32(pTrigger->wait_value); rep.wait_value_lo = XSyncValueLow32(pTrigger->wait_value); @@ -1917,16 +1802,15 @@ ProcSyncQueryAlarm(ClientPtr client) rep.events = pAlarm->events; rep.state = pAlarm->state; - if (client->swapped) - { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.counter); - swapl(&rep.wait_value_hi); - swapl(&rep.wait_value_lo); - swapl(&rep.test_type); - swapl(&rep.delta_hi); - swapl(&rep.delta_lo); + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.counter); + swapl(&rep.wait_value_hi); + swapl(&rep.wait_value_lo); + swapl(&rep.test_type); + swapl(&rep.delta_hi); + swapl(&rep.delta_lo); } WriteToClient(client, sizeof(xSyncQueryAlarmReply), (char *) &rep); @@ -1938,14 +1822,15 @@ ProcSyncDestroyAlarm(ClientPtr client) { SyncAlarm *pAlarm; int rc; + REQUEST(xSyncDestroyAlarmReq); REQUEST_SIZE_MATCH(xSyncDestroyAlarmReq); - rc = dixLookupResourceByType((pointer *)&pAlarm, stuff->alarm, RTAlarm, - client, DixDestroyAccess); + rc = dixLookupResourceByType((pointer *) &pAlarm, stuff->alarm, RTAlarm, + client, DixDestroyAccess); if (rc != Success) - return rc; + return rc; FreeResource(stuff->alarm, RT_NONE); return Success; @@ -1963,19 +1848,17 @@ ProcSyncCreateFence(ClientPtr client) rc = dixLookupDrawable(&pDraw, stuff->d, client, M_ANY, DixGetAttrAccess); if (rc != Success) - return rc; + return rc; LEGAL_NEW_RESOURCE(stuff->fid, client); - if (!(pFence = (SyncFence *)SyncCreate(client, - stuff->fid, - SYNC_FENCE))) - return BadAlloc; + if (!(pFence = (SyncFence *) SyncCreate(client, stuff->fid, SYNC_FENCE))) + return BadAlloc; miSyncInitFence(pDraw->pScreen, pFence, stuff->initially_triggered); if (!AddResource(stuff->fid, RTFence, (pointer) pFence)) - return BadAlloc; + return BadAlloc; return client->noClientException; } @@ -1990,14 +1873,14 @@ FreeFence(void *obj, XID id) return Success; } -int SyncVerifyFence(SyncFence **ppSyncFence, XID fid, - ClientPtr client, Mask mode) +int +SyncVerifyFence(SyncFence ** ppSyncFence, XID fid, ClientPtr client, Mask mode) { - int rc = dixLookupResourceByType((pointer *)ppSyncFence, fid, RTFence, - client, mode); + int rc = dixLookupResourceByType((pointer *) ppSyncFence, fid, RTFence, + client, mode); if (rc != Success) - client->errorValue = fid; + client->errorValue = fid; return rc; } @@ -2011,10 +1894,10 @@ ProcSyncTriggerFence(ClientPtr client) REQUEST_SIZE_MATCH(xSyncTriggerFenceReq); - rc = dixLookupResourceByType((pointer *)&pFence, stuff->fid, RTFence, - client, DixWriteAccess); + rc = dixLookupResourceByType((pointer *) &pFence, stuff->fid, RTFence, + client, DixWriteAccess); if (rc != Success) - return rc; + return rc; miSyncTriggerFence(pFence); @@ -2030,13 +1913,13 @@ ProcSyncResetFence(ClientPtr client) REQUEST_SIZE_MATCH(xSyncResetFenceReq); - rc = dixLookupResourceByType((pointer *)&pFence, stuff->fid, RTFence, - client, DixWriteAccess); + rc = dixLookupResourceByType((pointer *) &pFence, stuff->fid, RTFence, + client, DixWriteAccess); if (rc != Success) - return rc; + return rc; if (pFence->funcs.CheckTriggered(pFence) != TRUE) - return BadMatch; + return BadMatch; pFence->funcs.Reset(pFence); @@ -2052,10 +1935,10 @@ ProcSyncDestroyFence(ClientPtr client) REQUEST_SIZE_MATCH(xSyncDestroyFenceReq); - rc = dixLookupResourceByType((pointer *)&pFence, stuff->fid, RTFence, - client, DixDestroyAccess); + rc = dixLookupResourceByType((pointer *) &pFence, stuff->fid, RTFence, + client, DixDestroyAccess); if (rc != Success) - return rc; + return rc; FreeResource(stuff->fid, RT_NONE); return client->noClientException; @@ -2071,10 +1954,10 @@ ProcSyncQueryFence(ClientPtr client) REQUEST_SIZE_MATCH(xSyncQueryFenceReq); - rc = dixLookupResourceByType((pointer *)&pFence, stuff->fid, - RTFence, client, DixReadAccess); + rc = dixLookupResourceByType((pointer *) &pFence, stuff->fid, + RTFence, client, DixReadAccess); if (rc != Success) - return rc; + return rc; rep.type = X_Reply; rep.length = 0; @@ -2082,10 +1965,9 @@ ProcSyncQueryFence(ClientPtr client) rep.triggered = pFence->funcs.CheckTriggered(pFence); - if (client->swapped) - { - swaps(&rep.sequenceNumber); - swapl(&rep.length); + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.length); } WriteToClient(client, sizeof(xSyncQueryFenceReply), (char *) &rep); @@ -2098,6 +1980,7 @@ ProcSyncAwaitFence(ClientPtr client) REQUEST(xSyncAwaitFenceReq); SyncAwaitUnion *pAwaitUnion; SyncAwait *pAwait; + /* Use CARD32 rather than XSyncFence because XIDs are hard-coded to * CARD32 in protocol definitions */ CARD32 *pProtocolFences; @@ -2112,62 +1995,56 @@ ProcSyncAwaitFence(ClientPtr client) len -= sz_xSyncAwaitFenceReq; items = len / sizeof(CARD32); - if (items * sizeof(CARD32) != len) - { - return BadLength; + if (items * sizeof(CARD32) != len) { + return BadLength; } - if (items == 0) - { - client->errorValue = items; - return BadValue; + if (items == 0) { + client->errorValue = items; + return BadValue; } if (!(pAwaitUnion = SyncAwaitPrologue(client, items))) - return BadAlloc; + return BadAlloc; /* don't need to do any more memory allocation for this request! */ - pProtocolFences = (CARD32 *) & stuff[1]; - - pAwait = &(pAwaitUnion+1)->await; /* skip over header */ - for (i = 0; i < items; i++, pProtocolFences++, pAwait++) - { - if (*pProtocolFences == None) - { - /* this should take care of removing any triggers created by - * this request that have already been registered on sync objects - */ - FreeResource(pAwaitUnion->header.delete_id, RT_NONE); - client->errorValue = *pProtocolFences; - return SyncErrorBase + XSyncBadFence; - } - - pAwait->trigger.pSync = NULL; - /* Provide acceptable values for these unused fields to - * satisfy SyncInitTrigger's validation logic - */ - pAwait->trigger.value_type = XSyncAbsolute; - XSyncIntToValue(&pAwait->trigger.wait_value, 0); - pAwait->trigger.test_type = 0; - - status = SyncInitTrigger(client, &pAwait->trigger, - *pProtocolFences, RTFence, - XSyncCAAllTrigger); - if (status != Success) - { - /* this should take care of removing any triggers created by - * this request that have already been registered on sync objects - */ - FreeResource(pAwaitUnion->header.delete_id, RT_NONE); - return status; - } - /* this is not a mistake -- same function works for both cases */ - pAwait->trigger.TriggerFired = SyncAwaitTriggerFired; - pAwait->trigger.CounterDestroyed = SyncAwaitTriggerFired; - /* event_threshold is unused for fence syncs */ - XSyncIntToValue(&pAwait->event_threshold, 0); - pAwait->pHeader = &pAwaitUnion->header; - pAwaitUnion->header.num_waitconditions++; + pProtocolFences = (CARD32 *) &stuff[1]; + + pAwait = &(pAwaitUnion + 1)->await; /* skip over header */ + for (i = 0; i < items; i++, pProtocolFences++, pAwait++) { + if (*pProtocolFences == None) { + /* this should take care of removing any triggers created by + * this request that have already been registered on sync objects + */ + FreeResource(pAwaitUnion->header.delete_id, RT_NONE); + client->errorValue = *pProtocolFences; + return SyncErrorBase + XSyncBadFence; + } + + pAwait->trigger.pSync = NULL; + /* Provide acceptable values for these unused fields to + * satisfy SyncInitTrigger's validation logic + */ + pAwait->trigger.value_type = XSyncAbsolute; + XSyncIntToValue(&pAwait->trigger.wait_value, 0); + pAwait->trigger.test_type = 0; + + status = SyncInitTrigger(client, &pAwait->trigger, + *pProtocolFences, RTFence, XSyncCAAllTrigger); + if (status != Success) { + /* this should take care of removing any triggers created by + * this request that have already been registered on sync objects + */ + FreeResource(pAwaitUnion->header.delete_id, RT_NONE); + return status; + } + /* this is not a mistake -- same function works for both cases */ + pAwait->trigger.TriggerFired = SyncAwaitTriggerFired; + pAwait->trigger.CounterDestroyed = SyncAwaitTriggerFired; + /* event_threshold is unused for fence syncs */ + XSyncIntToValue(&pAwait->event_threshold, 0); + pAwait->pHeader = &pAwaitUnion->header; + pAwaitUnion->header.num_waitconditions++; } SyncAwaitEpilogue(client, items, pAwaitUnion); @@ -2183,50 +2060,49 @@ ProcSyncDispatch(ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { - case X_SyncInitialize: - return ProcSyncInitialize(client); - case X_SyncListSystemCounters: - return ProcSyncListSystemCounters(client); - case X_SyncCreateCounter: - return ProcSyncCreateCounter(client); - case X_SyncSetCounter: - return ProcSyncSetCounter(client); - case X_SyncChangeCounter: - return ProcSyncChangeCounter(client); - case X_SyncQueryCounter: - return ProcSyncQueryCounter(client); - case X_SyncDestroyCounter: - return ProcSyncDestroyCounter(client); - case X_SyncAwait: - return ProcSyncAwait(client); - case X_SyncCreateAlarm: - return ProcSyncCreateAlarm(client); - case X_SyncChangeAlarm: - return ProcSyncChangeAlarm(client); - case X_SyncQueryAlarm: - return ProcSyncQueryAlarm(client); - case X_SyncDestroyAlarm: - return ProcSyncDestroyAlarm(client); - case X_SyncSetPriority: - return ProcSyncSetPriority(client); - case X_SyncGetPriority: - return ProcSyncGetPriority(client); - case X_SyncCreateFence: - return ProcSyncCreateFence(client); - case X_SyncTriggerFence: - return ProcSyncTriggerFence(client); - case X_SyncResetFence: - return ProcSyncResetFence(client); - case X_SyncDestroyFence: - return ProcSyncDestroyFence(client); - case X_SyncQueryFence: - return ProcSyncQueryFence(client); - case X_SyncAwaitFence: - return ProcSyncAwaitFence(client); - default: - return BadRequest; + switch (stuff->data) { + case X_SyncInitialize: + return ProcSyncInitialize(client); + case X_SyncListSystemCounters: + return ProcSyncListSystemCounters(client); + case X_SyncCreateCounter: + return ProcSyncCreateCounter(client); + case X_SyncSetCounter: + return ProcSyncSetCounter(client); + case X_SyncChangeCounter: + return ProcSyncChangeCounter(client); + case X_SyncQueryCounter: + return ProcSyncQueryCounter(client); + case X_SyncDestroyCounter: + return ProcSyncDestroyCounter(client); + case X_SyncAwait: + return ProcSyncAwait(client); + case X_SyncCreateAlarm: + return ProcSyncCreateAlarm(client); + case X_SyncChangeAlarm: + return ProcSyncChangeAlarm(client); + case X_SyncQueryAlarm: + return ProcSyncQueryAlarm(client); + case X_SyncDestroyAlarm: + return ProcSyncDestroyAlarm(client); + case X_SyncSetPriority: + return ProcSyncSetPriority(client); + case X_SyncGetPriority: + return ProcSyncGetPriority(client); + case X_SyncCreateFence: + return ProcSyncCreateFence(client); + case X_SyncTriggerFence: + return ProcSyncTriggerFence(client); + case X_SyncResetFence: + return ProcSyncResetFence(client); + case X_SyncDestroyFence: + return ProcSyncDestroyFence(client); + case X_SyncQueryFence: + return ProcSyncQueryFence(client); + case X_SyncAwaitFence: + return ProcSyncAwaitFence(client); + default: + return BadRequest; } } @@ -2239,7 +2115,7 @@ SProcSyncInitialize(ClientPtr client) { REQUEST(xSyncInitializeReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncInitializeReq); + REQUEST_SIZE_MATCH(xSyncInitializeReq); return ProcSyncInitialize(client); } @@ -2249,7 +2125,7 @@ SProcSyncListSystemCounters(ClientPtr client) { REQUEST(xSyncListSystemCountersReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncListSystemCountersReq); + REQUEST_SIZE_MATCH(xSyncListSystemCountersReq); return ProcSyncListSystemCounters(client); } @@ -2259,7 +2135,7 @@ SProcSyncCreateCounter(ClientPtr client) { REQUEST(xSyncCreateCounterReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncCreateCounterReq); + REQUEST_SIZE_MATCH(xSyncCreateCounterReq); swapl(&stuff->cid); swapl(&stuff->initial_value_lo); swapl(&stuff->initial_value_hi); @@ -2272,7 +2148,7 @@ SProcSyncSetCounter(ClientPtr client) { REQUEST(xSyncSetCounterReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncSetCounterReq); + REQUEST_SIZE_MATCH(xSyncSetCounterReq); swapl(&stuff->cid); swapl(&stuff->value_lo); swapl(&stuff->value_hi); @@ -2285,7 +2161,7 @@ SProcSyncChangeCounter(ClientPtr client) { REQUEST(xSyncChangeCounterReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncChangeCounterReq); + REQUEST_SIZE_MATCH(xSyncChangeCounterReq); swapl(&stuff->cid); swapl(&stuff->value_lo); swapl(&stuff->value_hi); @@ -2298,7 +2174,7 @@ SProcSyncQueryCounter(ClientPtr client) { REQUEST(xSyncQueryCounterReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncQueryCounterReq); + REQUEST_SIZE_MATCH(xSyncQueryCounterReq); swapl(&stuff->counter); return ProcSyncQueryCounter(client); @@ -2309,7 +2185,7 @@ SProcSyncDestroyCounter(ClientPtr client) { REQUEST(xSyncDestroyCounterReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncDestroyCounterReq); + REQUEST_SIZE_MATCH(xSyncDestroyCounterReq); swapl(&stuff->counter); return ProcSyncDestroyCounter(client); @@ -2356,7 +2232,7 @@ SProcSyncQueryAlarm(ClientPtr client) { REQUEST(xSyncQueryAlarmReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncQueryAlarmReq); + REQUEST_SIZE_MATCH(xSyncQueryAlarmReq); swapl(&stuff->alarm); return ProcSyncQueryAlarm(client); @@ -2367,7 +2243,7 @@ SProcSyncDestroyAlarm(ClientPtr client) { REQUEST(xSyncDestroyAlarmReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncDestroyAlarmReq); + REQUEST_SIZE_MATCH(xSyncDestroyAlarmReq); swapl(&stuff->alarm); return ProcSyncDestroyAlarm(client); @@ -2378,7 +2254,7 @@ SProcSyncSetPriority(ClientPtr client) { REQUEST(xSyncSetPriorityReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncSetPriorityReq); + REQUEST_SIZE_MATCH(xSyncSetPriorityReq); swapl(&stuff->id); swapl(&stuff->priority); @@ -2390,7 +2266,7 @@ SProcSyncGetPriority(ClientPtr client) { REQUEST(xSyncGetPriorityReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncGetPriorityReq); + REQUEST_SIZE_MATCH(xSyncGetPriorityReq); swapl(&stuff->id); return ProcSyncGetPriority(client); @@ -2401,7 +2277,7 @@ SProcSyncCreateFence(ClientPtr client) { REQUEST(xSyncCreateFenceReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncCreateFenceReq); + REQUEST_SIZE_MATCH(xSyncCreateFenceReq); swapl(&stuff->fid); return ProcSyncCreateFence(client); @@ -2412,7 +2288,7 @@ SProcSyncTriggerFence(ClientPtr client) { REQUEST(xSyncTriggerFenceReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncTriggerFenceReq); + REQUEST_SIZE_MATCH(xSyncTriggerFenceReq); swapl(&stuff->fid); return ProcSyncTriggerFence(client); @@ -2423,7 +2299,7 @@ SProcSyncResetFence(ClientPtr client) { REQUEST(xSyncResetFenceReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncResetFenceReq); + REQUEST_SIZE_MATCH(xSyncResetFenceReq); swapl(&stuff->fid); return ProcSyncResetFence(client); @@ -2434,7 +2310,7 @@ SProcSyncDestroyFence(ClientPtr client) { REQUEST(xSyncDestroyFenceReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncDestroyFenceReq); + REQUEST_SIZE_MATCH(xSyncDestroyFenceReq); swapl(&stuff->fid); return ProcSyncDestroyFence(client); @@ -2445,7 +2321,7 @@ SProcSyncQueryFence(ClientPtr client) { REQUEST(xSyncQueryFenceReq); swaps(&stuff->length); - REQUEST_SIZE_MATCH (xSyncQueryFenceReq); + REQUEST_SIZE_MATCH(xSyncQueryFenceReq); swapl(&stuff->fid); return ProcSyncQueryFence(client); @@ -2467,50 +2343,49 @@ SProcSyncDispatch(ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { - case X_SyncInitialize: - return SProcSyncInitialize(client); - case X_SyncListSystemCounters: - return SProcSyncListSystemCounters(client); - case X_SyncCreateCounter: - return SProcSyncCreateCounter(client); - case X_SyncSetCounter: - return SProcSyncSetCounter(client); - case X_SyncChangeCounter: - return SProcSyncChangeCounter(client); - case X_SyncQueryCounter: - return SProcSyncQueryCounter(client); - case X_SyncDestroyCounter: - return SProcSyncDestroyCounter(client); - case X_SyncAwait: - return SProcSyncAwait(client); - case X_SyncCreateAlarm: - return SProcSyncCreateAlarm(client); - case X_SyncChangeAlarm: - return SProcSyncChangeAlarm(client); - case X_SyncQueryAlarm: - return SProcSyncQueryAlarm(client); - case X_SyncDestroyAlarm: - return SProcSyncDestroyAlarm(client); - case X_SyncSetPriority: - return SProcSyncSetPriority(client); - case X_SyncGetPriority: - return SProcSyncGetPriority(client); - case X_SyncCreateFence: - return SProcSyncCreateFence(client); - case X_SyncTriggerFence: - return SProcSyncTriggerFence(client); - case X_SyncResetFence: - return SProcSyncResetFence(client); - case X_SyncDestroyFence: - return SProcSyncDestroyFence(client); - case X_SyncQueryFence: - return SProcSyncQueryFence(client); - case X_SyncAwaitFence: - return SProcSyncAwaitFence(client); - default: - return BadRequest; + switch (stuff->data) { + case X_SyncInitialize: + return SProcSyncInitialize(client); + case X_SyncListSystemCounters: + return SProcSyncListSystemCounters(client); + case X_SyncCreateCounter: + return SProcSyncCreateCounter(client); + case X_SyncSetCounter: + return SProcSyncSetCounter(client); + case X_SyncChangeCounter: + return SProcSyncChangeCounter(client); + case X_SyncQueryCounter: + return SProcSyncQueryCounter(client); + case X_SyncDestroyCounter: + return SProcSyncDestroyCounter(client); + case X_SyncAwait: + return SProcSyncAwait(client); + case X_SyncCreateAlarm: + return SProcSyncCreateAlarm(client); + case X_SyncChangeAlarm: + return SProcSyncChangeAlarm(client); + case X_SyncQueryAlarm: + return SProcSyncQueryAlarm(client); + case X_SyncDestroyAlarm: + return SProcSyncDestroyAlarm(client); + case X_SyncSetPriority: + return SProcSyncSetPriority(client); + case X_SyncGetPriority: + return SProcSyncGetPriority(client); + case X_SyncCreateFence: + return SProcSyncCreateFence(client); + case X_SyncTriggerFence: + return SProcSyncTriggerFence(client); + case X_SyncResetFence: + return SProcSyncResetFence(client); + case X_SyncDestroyFence: + return SProcSyncDestroyFence(client); + case X_SyncQueryFence: + return SProcSyncQueryFence(client); + case X_SyncAwaitFence: + return SProcSyncAwaitFence(client); + default: + return BadRequest; } } @@ -2519,7 +2394,8 @@ SProcSyncDispatch(ClientPtr client) */ static void -SCounterNotifyEvent(xSyncCounterNotifyEvent *from, xSyncCounterNotifyEvent *to) +SCounterNotifyEvent(xSyncCounterNotifyEvent * from, + xSyncCounterNotifyEvent * to) { to->type = from->type; to->kind = from->kind; @@ -2534,9 +2410,8 @@ SCounterNotifyEvent(xSyncCounterNotifyEvent *from, xSyncCounterNotifyEvent *to) to->destroyed = from->destroyed; } - static void -SAlarmNotifyEvent(xSyncAlarmNotifyEvent *from, xSyncAlarmNotifyEvent *to) +SAlarmNotifyEvent(xSyncAlarmNotifyEvent * from, xSyncAlarmNotifyEvent * to) { to->type = from->type; to->kind = from->kind; @@ -2555,10 +2430,8 @@ SAlarmNotifyEvent(xSyncAlarmNotifyEvent *from, xSyncAlarmNotifyEvent *to) */ /* ARGSUSED */ static void -SyncResetProc(ExtensionEntry *extEntry) +SyncResetProc(ExtensionEntry * extEntry) { - free(SysCounterList); - SysCounterList = NULL; RTCounter = 0; } @@ -2569,41 +2442,42 @@ void SyncExtensionInit(void) { ExtensionEntry *extEntry; - int s; + int s; + + xorg_list_init(&SysCounterList); for (s = 0; s < screenInfo.numScreens; s++) - miSyncSetup(screenInfo.screens[s]); + miSyncSetup(screenInfo.screens[s]); - if (RTCounter == 0) - { - RTCounter = CreateNewResourceType(FreeCounter, "SyncCounter"); + if (RTCounter == 0) { + RTCounter = CreateNewResourceType(FreeCounter, "SyncCounter"); } RTAlarm = CreateNewResourceType(FreeAlarm, "SyncAlarm"); RTAwait = CreateNewResourceType(FreeAwait, "SyncAwait"); RTFence = CreateNewResourceType(FreeFence, "SyncFence"); if (RTAwait) - RTAwait |= RC_NEVERRETAIN; + RTAwait |= RC_NEVERRETAIN; RTAlarmClient = CreateNewResourceType(FreeAlarmClient, "SyncAlarmClient"); if (RTAlarmClient) - RTAlarmClient |= RC_NEVERRETAIN; + RTAlarmClient |= RC_NEVERRETAIN; if (RTCounter == 0 || RTAwait == 0 || RTAlarm == 0 || - RTAlarmClient == 0 || - (extEntry = AddExtension(SYNC_NAME, - XSyncNumberEvents, XSyncNumberErrors, - ProcSyncDispatch, SProcSyncDispatch, - SyncResetProc, - StandardMinorOpcode)) == NULL) - { - ErrorF("Sync Extension %d.%d failed to Initialise\n", - SYNC_MAJOR_VERSION, SYNC_MINOR_VERSION); - return; + RTAlarmClient == 0 || + (extEntry = AddExtension(SYNC_NAME, + XSyncNumberEvents, XSyncNumberErrors, + ProcSyncDispatch, SProcSyncDispatch, + SyncResetProc, StandardMinorOpcode)) == NULL) { + ErrorF("Sync Extension %d.%d failed to Initialise\n", + SYNC_MAJOR_VERSION, SYNC_MINOR_VERSION); + return; } SyncEventBase = extEntry->eventBase; SyncErrorBase = extEntry->errorBase; - EventSwapVector[SyncEventBase + XSyncCounterNotify] = (EventSwapPtr) SCounterNotifyEvent; - EventSwapVector[SyncEventBase + XSyncAlarmNotify] = (EventSwapPtr) SAlarmNotifyEvent; + EventSwapVector[SyncEventBase + XSyncCounterNotify] = + (EventSwapPtr) SCounterNotifyEvent; + EventSwapVector[SyncEventBase + XSyncAlarmNotify] = + (EventSwapPtr) SAlarmNotifyEvent; SetResourceTypeErrorValue(RTCounter, SyncErrorBase + XSyncBadCounter); SetResourceTypeErrorValue(RTAlarm, SyncErrorBase + XSyncBadAlarm); @@ -2620,17 +2494,14 @@ SyncExtensionInit(void) #ifdef DEBUG fprintf(stderr, "Sync Extension %d.%d\n", - SYNC_MAJOR_VERSION, SYNC_MINOR_VERSION); + SYNC_MAJOR_VERSION, SYNC_MINOR_VERSION); #endif } - /* * ***** SERVERTIME implementation - should go in its own file in OS directory? */ - - static pointer ServertimeCounter; static XSyncValue Now; static XSyncValue *pnext_time; @@ -2647,72 +2518,62 @@ static XSyncValue *pnext_time; *** Server Block Handler *** code inspired by multibuffer extension (now deprecated) */ -/*ARGSUSED*/ -static void + /*ARGSUSED*/ static void ServertimeBlockHandler(void *env, struct timeval **wt, void *LastSelectMask) { XSyncValue delay; unsigned long timeout; - if (pnext_time) - { + if (pnext_time) { GetTime(); - if (XSyncValueGreaterOrEqual(Now, *pnext_time)) - { + if (XSyncValueGreaterOrEqual(Now, *pnext_time)) { timeout = 0; } - else - { - Bool overflow; + else { + Bool overflow; + XSyncValueSubtract(&delay, *pnext_time, Now, &overflow); - (void)overflow; + (void) overflow; timeout = XSyncValueLow32(delay); } - AdjustWaitForDelay(wt, timeout); /* os/utils.c */ + AdjustWaitForDelay(wt, timeout); /* os/utils.c */ } } /* *** Wakeup Handler */ -/*ARGSUSED*/ -static void + /*ARGSUSED*/ static void ServertimeWakeupHandler(void *env, int rc, void *LastSelectMask) { - if (pnext_time) - { + if (pnext_time) { GetTime(); - if (XSyncValueGreaterOrEqual(Now, *pnext_time)) - { + if (XSyncValueGreaterOrEqual(Now, *pnext_time)) { SyncChangeCounter(ServertimeCounter, Now); } } } static void -ServertimeQueryValue(void *pCounter, CARD64 *pValue_return) +ServertimeQueryValue(void *pCounter, CARD64 * pValue_return) { GetTime(); *pValue_return = Now; } static void -ServertimeBracketValues(void *pCounter, CARD64 *pbracket_less, - CARD64 *pbracket_greater) +ServertimeBracketValues(void *pCounter, CARD64 * pbracket_less, + CARD64 * pbracket_greater) { - if (!pnext_time && pbracket_greater) - { - RegisterBlockAndWakeupHandlers(ServertimeBlockHandler, - ServertimeWakeupHandler, - NULL); + if (!pnext_time && pbracket_greater) { + RegisterBlockAndWakeupHandlers(ServertimeBlockHandler, + ServertimeWakeupHandler, NULL); } - else if (pnext_time && !pbracket_greater) - { - RemoveBlockAndWakeupHandlers(ServertimeBlockHandler, - ServertimeWakeupHandler, - NULL); + else if (pnext_time && !pbracket_greater) { + RemoveBlockAndWakeupHandlers(ServertimeBlockHandler, + ServertimeWakeupHandler, NULL); } pnext_time = pbracket_greater; } @@ -2725,157 +2586,202 @@ SyncInitServerTime(void) XSyncIntsToValue(&Now, GetTimeInMillis(), 0); XSyncIntToValue(&resolution, 4); ServertimeCounter = SyncCreateSystemCounter("SERVERTIME", Now, resolution, - XSyncCounterNeverDecreases, - ServertimeQueryValue, ServertimeBracketValues); + XSyncCounterNeverDecreases, + ServertimeQueryValue, + ServertimeBracketValues); pnext_time = NULL; } - - /* * IDLETIME implementation */ -static SyncCounter *IdleTimeCounter; -static XSyncValue *pIdleTimeValueLess; -static XSyncValue *pIdleTimeValueGreater; +typedef struct { + XSyncValue *value_less; + XSyncValue *value_greater; + int deviceid; +} IdleCounterPriv; static void -IdleTimeQueryValue (pointer pCounter, CARD64 *pValue_return) +IdleTimeQueryValue(pointer pCounter, CARD64 * pValue_return) { - CARD32 idle = GetTimeInMillis() - lastDeviceEventTime.milliseconds; - XSyncIntsToValue (pValue_return, idle, 0); + int deviceid; + CARD32 idle; + + if (pCounter) { + SyncCounter *counter = pCounter; + IdleCounterPriv *priv = SysCounterGetPrivate(counter); + deviceid = priv->deviceid; + } + else + deviceid = XIAllDevices; + idle = GetTimeInMillis() - lastDeviceEventTime[deviceid].milliseconds; + XSyncIntsToValue(pValue_return, idle, 0); } static void -IdleTimeBlockHandler(pointer env, struct timeval **wt, pointer LastSelectMask) +IdleTimeBlockHandler(pointer pCounter, struct timeval **wt, pointer LastSelectMask) { + SyncCounter *counter = pCounter; + IdleCounterPriv *priv = SysCounterGetPrivate(counter); + XSyncValue *less = priv->value_less, + *greater = priv->value_greater; XSyncValue idle, old_idle; - SyncTriggerList *list = IdleTimeCounter->sync.pTriglist; + SyncTriggerList *list = counter->sync.pTriglist; SyncTrigger *trig; - if (!pIdleTimeValueLess && !pIdleTimeValueGreater) - return; - - old_idle = IdleTimeCounter->value; - IdleTimeQueryValue (NULL, &idle); - IdleTimeCounter->value = idle; /* push, so CheckTrigger works */ - - if (pIdleTimeValueLess && - XSyncValueLessOrEqual (idle, *pIdleTimeValueLess)) - { - /* - * We've been idle for less than the threshold value, and someone - * wants to know about that, but now we need to know whether they - * want level or edge trigger. Check the trigger list against the - * current idle time, and if any succeed, bomb out of select() - * immediately so we can reschedule. - */ - - for (list = IdleTimeCounter->sync.pTriglist; list; list = list->next) { - trig = list->pTrigger; - if (trig->CheckTrigger(trig, old_idle)) { - AdjustWaitForDelay(wt, 0); - break; - } - } - /* - * We've been called exactly on the idle time, but we have a - * NegativeTransition trigger which requires a transition from an - * idle time greater than this. Schedule a wakeup for the next - * millisecond so we won't miss a transition. - */ - if (XSyncValueEqual (idle, *pIdleTimeValueLess)) - AdjustWaitForDelay(wt, 1); - } - else if (pIdleTimeValueGreater) - { - /* - * There's a threshold in the positive direction. If we've been - * idle less than it, schedule a wakeup for sometime in the future. - * If we've been idle more than it, and someone wants to know about - * that level-triggered, schedule an immediate wakeup. - */ - unsigned long timeout = -1; - - if (XSyncValueLessThan (idle, *pIdleTimeValueGreater)) { - XSyncValue value; - Bool overflow; - - XSyncValueSubtract (&value, *pIdleTimeValueGreater, - idle, &overflow); - timeout = min(timeout, XSyncValueLow32 (value)); - } else { - for (list = IdleTimeCounter->sync.pTriglist; list; list = list->next) { - trig = list->pTrigger; - if (trig->CheckTrigger(trig, old_idle)) { - timeout = min(timeout, 0); - break; - } - } - } - - AdjustWaitForDelay (wt, timeout); - } - - IdleTimeCounter->value = old_idle; /* pop */ + if (!less && !greater) + return; + + old_idle = counter->value; + IdleTimeQueryValue(NULL, &idle); + counter->value = idle; /* push, so CheckTrigger works */ + + if (less && XSyncValueLessOrEqual(idle, *less)) { + /* + * We've been idle for less than the threshold value, and someone + * wants to know about that, but now we need to know whether they + * want level or edge trigger. Check the trigger list against the + * current idle time, and if any succeed, bomb out of select() + * immediately so we can reschedule. + */ + + for (list = counter->sync.pTriglist; list; list = list->next) { + trig = list->pTrigger; + if (trig->CheckTrigger(trig, old_idle)) { + AdjustWaitForDelay(wt, 0); + break; + } + } + /* + * We've been called exactly on the idle time, but we have a + * NegativeTransition trigger which requires a transition from an + * idle time greater than this. Schedule a wakeup for the next + * millisecond so we won't miss a transition. + */ + if (XSyncValueEqual(idle, *less)) + AdjustWaitForDelay(wt, 1); + } + else if (greater) { + /* + * There's a threshold in the positive direction. If we've been + * idle less than it, schedule a wakeup for sometime in the future. + * If we've been idle more than it, and someone wants to know about + * that level-triggered, schedule an immediate wakeup. + */ + unsigned long timeout = -1; + + if (XSyncValueLessThan(idle, *greater)) { + XSyncValue value; + Bool overflow; + + XSyncValueSubtract(&value, *greater, idle, &overflow); + timeout = min(timeout, XSyncValueLow32(value)); + } + else { + for (list = counter->sync.pTriglist; list; + list = list->next) { + trig = list->pTrigger; + if (trig->CheckTrigger(trig, old_idle)) { + timeout = min(timeout, 0); + break; + } + } + } + + AdjustWaitForDelay(wt, timeout); + } + + counter->value = old_idle; /* pop */ } static void -IdleTimeWakeupHandler (pointer env, int rc, pointer LastSelectMask) +IdleTimeWakeupHandler(pointer pCounter, int rc, pointer LastSelectMask) { + SyncCounter *counter = pCounter; + IdleCounterPriv *priv = SysCounterGetPrivate(counter); + XSyncValue *less = priv->value_less, + *greater = priv->value_greater; XSyncValue idle; - if (!pIdleTimeValueLess && !pIdleTimeValueGreater) - return; + if (!less && !greater) + return; - IdleTimeQueryValue (NULL, &idle); + IdleTimeQueryValue(pCounter, &idle); - if ((pIdleTimeValueGreater && - XSyncValueGreaterOrEqual (idle, *pIdleTimeValueGreater)) || - (pIdleTimeValueLess && - XSyncValueLessOrEqual (idle, *pIdleTimeValueLess))) - { - SyncChangeCounter (IdleTimeCounter, idle); + if ((greater && XSyncValueGreaterOrEqual(idle, *greater)) || + (less && XSyncValueLessOrEqual(idle, *less))) { + SyncChangeCounter(counter, idle); } } static void -IdleTimeBracketValues (pointer pCounter, CARD64 *pbracket_less, - CARD64 *pbracket_greater) +IdleTimeBracketValues(pointer pCounter, CARD64 * pbracket_less, + CARD64 * pbracket_greater) { - Bool registered = (pIdleTimeValueLess || pIdleTimeValueGreater); + SyncCounter *counter = pCounter; + IdleCounterPriv *priv = SysCounterGetPrivate(counter); + XSyncValue *less = priv->value_less, + *greater = priv->value_greater; + Bool registered = (less || greater); - if (registered && !pbracket_less && !pbracket_greater) - { - RemoveBlockAndWakeupHandlers(IdleTimeBlockHandler, - IdleTimeWakeupHandler, - NULL); + if (registered && !pbracket_less && !pbracket_greater) { + RemoveBlockAndWakeupHandlers(IdleTimeBlockHandler, + IdleTimeWakeupHandler, pCounter); } - else if (!registered && (pbracket_less || pbracket_greater)) - { - RegisterBlockAndWakeupHandlers(IdleTimeBlockHandler, - IdleTimeWakeupHandler, - NULL); + else if (!registered && (pbracket_less || pbracket_greater)) { + RegisterBlockAndWakeupHandlers(IdleTimeBlockHandler, + IdleTimeWakeupHandler, pCounter); } - pIdleTimeValueGreater = pbracket_greater; - pIdleTimeValueLess = pbracket_less; + priv->value_greater = pbracket_greater; + priv->value_less = pbracket_less; } -static void -SyncInitIdleTime (void) +static SyncCounter* +init_system_idle_counter(const char *name, int deviceid) { CARD64 resolution; XSyncValue idle; + IdleCounterPriv *priv = malloc(sizeof(IdleCounterPriv)); + SyncCounter *idle_time_counter; + + IdleTimeQueryValue(NULL, &idle); + XSyncIntToValue(&resolution, 4); + + idle_time_counter = SyncCreateSystemCounter(name, idle, resolution, + XSyncCounterUnrestricted, + IdleTimeQueryValue, + IdleTimeBracketValues); + + priv->deviceid = deviceid; + priv->value_less = priv->value_greater = NULL; - IdleTimeQueryValue (NULL, &idle); - XSyncIntToValue (&resolution, 4); + idle_time_counter->pSysCounterInfo->private = priv; - IdleTimeCounter = SyncCreateSystemCounter ("IDLETIME", idle, resolution, - XSyncCounterUnrestricted, - IdleTimeQueryValue, - IdleTimeBracketValues); + return idle_time_counter; +} + +static void +SyncInitIdleTime(void) +{ + init_system_idle_counter("IDLETIME", XIAllDevices); +} - pIdleTimeValueLess = pIdleTimeValueGreater = NULL; +SyncCounter* +SyncInitDeviceIdleTime(DeviceIntPtr dev) +{ + char timer_name[64]; + sprintf(timer_name, "DEVICEIDLETIME %d", dev->id); + + return init_system_idle_counter(timer_name, dev->id); +} + +void SyncRemoveDeviceIdleTime(SyncCounter *counter) +{ + /* FreeAllResources() frees all system counters before the devices are + shut down, check if there are any left before freeing the device's + counter */ + if (!xorg_list_is_empty(&SysCounterList)) + xorg_list_del(&counter->pSysCounterInfo->entry); } diff --git a/xorg-server/Xext/syncsrv.h b/xorg-server/Xext/syncsrv.h index 46f25bdfc..dbed476f2 100644 --- a/xorg-server/Xext/syncsrv.h +++ b/xorg-server/Xext/syncsrv.h @@ -51,6 +51,7 @@ PERFORMANCE OF THIS SOFTWARE. #ifndef _SYNCSRV_H_ #define _SYNCSRV_H_ +#include "list.h" #include "misync.h" #include "misyncstr.h" @@ -65,82 +66,76 @@ typedef enum { XSyncCounterUnrestricted } SyncCounterType; +typedef void (*SyncSystemCounterQueryValue)(pointer counter, + CARD64 *value_return + ); +typedef void (*SyncSystemCounterBracketValues)(pointer counter, + CARD64 *pbracket_less, + CARD64 *pbracket_greater + ); + typedef struct _SysCounterInfo { - const char *name; - CARD64 resolution; - CARD64 bracket_greater; - CARD64 bracket_less; - SyncCounterType counterType; /* how can this counter change */ - void (*QueryValue)( - pointer /*pCounter*/, - CARD64 * /*freshvalue*/ -); - void (*BracketValues)( - pointer /*pCounter*/, - CARD64 * /*lessthan*/, - CARD64 * /*greaterthan*/ -); + SyncCounter *pCounter; + char *name; + CARD64 resolution; + CARD64 bracket_greater; + CARD64 bracket_less; + SyncCounterType counterType; /* how can this counter change */ + SyncSystemCounterQueryValue QueryValue; + SyncSystemCounterBracketValues BracketValues; + void *private; + struct xorg_list entry; } SysCounterInfo; - - typedef struct _SyncAlarmClientList { - ClientPtr client; - XID delete_id; + ClientPtr client; + XID delete_id; struct _SyncAlarmClientList *next; } SyncAlarmClientList; typedef struct _SyncAlarm { SyncTrigger trigger; - ClientPtr client; - XSyncAlarm alarm_id; - CARD64 delta; - int events; - int state; + ClientPtr client; + XSyncAlarm alarm_id; + CARD64 delta; + int events; + int state; SyncAlarmClientList *pEventClients; } SyncAlarm; typedef struct { - ClientPtr client; - CARD32 delete_id; - int num_waitconditions; + ClientPtr client; + CARD32 delete_id; + int num_waitconditions; } SyncAwaitHeader; typedef struct { SyncTrigger trigger; - CARD64 event_threshold; + CARD64 event_threshold; SyncAwaitHeader *pHeader; } SyncAwait; typedef union { SyncAwaitHeader header; - SyncAwait await; + SyncAwait await; } SyncAwaitUnion; -extern pointer SyncCreateSystemCounter( - const char * /* name */, - CARD64 /* inital_value */, - CARD64 /* resolution */, - SyncCounterType /* change characterization */, - void (* /*QueryValue*/ ) ( - pointer /* pCounter */, - CARD64 * /* pValue_return */), /* XXX prototype */ - void (* /*BracketValues*/) ( - pointer /* pCounter */, - CARD64 * /* pbracket_less */, - CARD64 * /* pbracket_greater */) -); - -extern void SyncChangeCounter( - SyncCounter * /* pCounter*/, - CARD64 /* new_value */ -); - -extern void SyncDestroySystemCounter( - pointer pCounter -); - -extern void InitServertime(void); +extern SyncCounter* SyncCreateSystemCounter(const char *name, + CARD64 initial_value, + CARD64 resolution, + SyncCounterType counterType, + SyncSystemCounterQueryValue QueryValue, + SyncSystemCounterBracketValues BracketValues + ); + +extern void SyncChangeCounter(SyncCounter *pCounter, + CARD64 new_value + ); + +extern void SyncDestroySystemCounter(pointer pCounter); extern void SyncExtensionInit(void); -#endif /* _SYNCSRV_H_ */ + +extern SyncCounter *SyncInitDeviceIdleTime(DeviceIntPtr dev); +extern void SyncRemoveDeviceIdleTime(SyncCounter *counter); +#endif /* _SYNCSRV_H_ */ diff --git a/xorg-server/Xext/xace.c b/xorg-server/Xext/xace.c index 69cb2bbdb..b4884fb6e 100644 --- a/xorg-server/Xext/xace.c +++ b/xorg-server/Xext/xace.c @@ -36,49 +36,53 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include <X11/Xtrans/Xtrans.h> #include "../os/osdep.h" -_X_EXPORT CallbackListPtr XaceHooks[XACE_NUM_HOOKS] = {0}; +_X_EXPORT CallbackListPtr XaceHooks[XACE_NUM_HOOKS] = { 0 }; /* Special-cased hook functions. Called by Xserver. */ -int XaceHookDispatch(ClientPtr client, int major) +int +XaceHookDispatch(ClientPtr client, int major) { /* Call the audit begin callback, there is no return value. */ XaceAuditRec rec = { client, 0 }; CallCallbacks(&XaceHooks[XACE_AUDIT_BEGIN], &rec); if (major < 128) { - /* Call the core dispatch hook */ - XaceCoreDispatchRec rec = { client, Success /* default allow */ }; - CallCallbacks(&XaceHooks[XACE_CORE_DISPATCH], &rec); - return rec.status; - } else { - /* Call the extension dispatch hook */ - ExtensionEntry *ext = GetExtensionEntry(major); - XaceExtAccessRec rec = { client, ext, DixUseAccess, Success }; - if (ext) - CallCallbacks(&XaceHooks[XACE_EXT_DISPATCH], &rec); - /* On error, pretend extension doesn't exist */ - return (rec.status == Success) ? Success : BadRequest; + /* Call the core dispatch hook */ + XaceCoreDispatchRec rec = { client, Success /* default allow */ }; + CallCallbacks(&XaceHooks[XACE_CORE_DISPATCH], &rec); + return rec.status; + } + else { + /* Call the extension dispatch hook */ + ExtensionEntry *ext = GetExtensionEntry(major); + XaceExtAccessRec rec = { client, ext, DixUseAccess, Success }; + if (ext) + CallCallbacks(&XaceHooks[XACE_EXT_DISPATCH], &rec); + /* On error, pretend extension doesn't exist */ + return (rec.status == Success) ? Success : BadRequest; } } -int XaceHookPropertyAccess(ClientPtr client, WindowPtr pWin, - PropertyPtr *ppProp, Mask access_mode) +int +XaceHookPropertyAccess(ClientPtr client, WindowPtr pWin, + PropertyPtr *ppProp, Mask access_mode) { XacePropertyAccessRec rec = { client, pWin, ppProp, access_mode, Success }; CallCallbacks(&XaceHooks[XACE_PROPERTY_ACCESS], &rec); return rec.status; } -int XaceHookSelectionAccess(ClientPtr client, - Selection **ppSel, Mask access_mode) +int +XaceHookSelectionAccess(ClientPtr client, Selection ** ppSel, Mask access_mode) { XaceSelectionAccessRec rec = { client, ppSel, access_mode, Success }; CallCallbacks(&XaceHooks[XACE_SELECTION_ACCESS], &rec); return rec.status; } -void XaceHookAuditEnd(ClientPtr ptr, int result) +void +XaceHookAuditEnd(ClientPtr ptr, int result) { XaceAuditRec rec = { ptr, result }; /* call callbacks, there is no return value. */ @@ -87,25 +91,26 @@ void XaceHookAuditEnd(ClientPtr ptr, int result) /* Entry point for hook functions. Called by Xserver. */ -int XaceHook(int hook, ...) +int +XaceHook(int hook, ...) { union { - XaceResourceAccessRec res; - XaceDeviceAccessRec dev; - XaceSendAccessRec send; - XaceReceiveAccessRec recv; - XaceClientAccessRec client; - XaceExtAccessRec ext; - XaceServerAccessRec server; - XaceScreenAccessRec screen; - XaceAuthAvailRec auth; - XaceKeyAvailRec key; + XaceResourceAccessRec res; + XaceDeviceAccessRec dev; + XaceSendAccessRec send; + XaceReceiveAccessRec recv; + XaceClientAccessRec client; + XaceExtAccessRec ext; + XaceServerAccessRec server; + XaceScreenAccessRec screen; + XaceAuthAvailRec auth; + XaceKeyAvailRec key; } u; - int *prv = NULL; /* points to return value from callback */ - va_list ap; /* argument list */ + int *prv = NULL; /* points to return value from callback */ + va_list ap; /* argument list */ if (!XaceHooks[hook]) - return Success; + return Success; va_start(ap, hook); @@ -114,86 +119,97 @@ int XaceHook(int hook, ...) * the arguments and integer return parameter, or in some cases just * sets calldata directly to a single argument (with no return result) */ - switch (hook) - { - case XACE_RESOURCE_ACCESS: - u.res.client = va_arg(ap, ClientPtr); - u.res.id = va_arg(ap, XID); - u.res.rtype = va_arg(ap, RESTYPE); - u.res.res = va_arg(ap, pointer); - u.res.ptype = va_arg(ap, RESTYPE); - u.res.parent = va_arg(ap, pointer); - u.res.access_mode = va_arg(ap, Mask); - u.res.status = Success; /* default allow */ - prv = &u.res.status; - break; - case XACE_DEVICE_ACCESS: - u.dev.client = va_arg(ap, ClientPtr); - u.dev.dev = va_arg(ap, DeviceIntPtr); - u.dev.access_mode = va_arg(ap, Mask); - u.dev.status = Success; /* default allow */ - prv = &u.dev.status; - break; - case XACE_SEND_ACCESS: - u.send.client = va_arg(ap, ClientPtr); - u.send.dev = va_arg(ap, DeviceIntPtr); - u.send.pWin = va_arg(ap, WindowPtr); - u.send.events = va_arg(ap, xEventPtr); - u.send.count = va_arg(ap, int); - u.send.status = Success; /* default allow */ - prv = &u.send.status; - break; - case XACE_RECEIVE_ACCESS: - u.recv.client = va_arg(ap, ClientPtr); - u.recv.pWin = va_arg(ap, WindowPtr); - u.recv.events = va_arg(ap, xEventPtr); - u.recv.count = va_arg(ap, int); - u.recv.status = Success; /* default allow */ - prv = &u.recv.status; - break; - case XACE_CLIENT_ACCESS: - u.client.client = va_arg(ap, ClientPtr); - u.client.target = va_arg(ap, ClientPtr); - u.client.access_mode = va_arg(ap, Mask); - u.client.status = Success; /* default allow */ - prv = &u.client.status; - break; - case XACE_EXT_ACCESS: - u.ext.client = va_arg(ap, ClientPtr); - u.ext.ext = va_arg(ap, ExtensionEntry*); - u.ext.access_mode = DixGetAttrAccess; - u.ext.status = Success; /* default allow */ - prv = &u.ext.status; - break; - case XACE_SERVER_ACCESS: - u.server.client = va_arg(ap, ClientPtr); - u.server.access_mode = va_arg(ap, Mask); - u.server.status = Success; /* default allow */ - prv = &u.server.status; - break; - case XACE_SCREEN_ACCESS: - case XACE_SCREENSAVER_ACCESS: - u.screen.client = va_arg(ap, ClientPtr); - u.screen.screen = va_arg(ap, ScreenPtr); - u.screen.access_mode = va_arg(ap, Mask); - u.screen.status = Success; /* default allow */ - prv = &u.screen.status; - break; - case XACE_AUTH_AVAIL: - u.auth.client = va_arg(ap, ClientPtr); - u.auth.authId = va_arg(ap, XID); - break; - case XACE_KEY_AVAIL: - u.key.event = va_arg(ap, xEventPtr); - u.key.keybd = va_arg(ap, DeviceIntPtr); - u.key.count = va_arg(ap, int); - break; - default: - va_end(ap); - return 0; /* unimplemented hook number */ + switch (hook) { + case XACE_RESOURCE_ACCESS: + u.res.client = va_arg(ap, ClientPtr); + u.res.id = va_arg(ap, XID); + u.res.rtype = va_arg(ap, RESTYPE); + u.res.res = va_arg(ap, pointer); + u.res.ptype = va_arg(ap, RESTYPE); + u.res.parent = va_arg(ap, pointer); + u.res.access_mode = va_arg(ap, Mask); + + u.res.status = Success; /* default allow */ + prv = &u.res.status; + break; + case XACE_DEVICE_ACCESS: + u.dev.client = va_arg(ap, ClientPtr); + u.dev.dev = va_arg(ap, DeviceIntPtr); + u.dev.access_mode = va_arg(ap, Mask); + + u.dev.status = Success; /* default allow */ + prv = &u.dev.status; + break; + case XACE_SEND_ACCESS: + u.send.client = va_arg(ap, ClientPtr); + u.send.dev = va_arg(ap, DeviceIntPtr); + u.send.pWin = va_arg(ap, WindowPtr); + + u.send.events = va_arg(ap, xEventPtr); + u.send.count = va_arg(ap, int); + + u.send.status = Success; /* default allow */ + prv = &u.send.status; + break; + case XACE_RECEIVE_ACCESS: + u.recv.client = va_arg(ap, ClientPtr); + u.recv.pWin = va_arg(ap, WindowPtr); + + u.recv.events = va_arg(ap, xEventPtr); + u.recv.count = va_arg(ap, int); + + u.recv.status = Success; /* default allow */ + prv = &u.recv.status; + break; + case XACE_CLIENT_ACCESS: + u.client.client = va_arg(ap, ClientPtr); + u.client.target = va_arg(ap, ClientPtr); + u.client.access_mode = va_arg(ap, Mask); + + u.client.status = Success; /* default allow */ + prv = &u.client.status; + break; + case XACE_EXT_ACCESS: + u.ext.client = va_arg(ap, ClientPtr); + + u.ext.ext = va_arg(ap, ExtensionEntry *); + u.ext.access_mode = DixGetAttrAccess; + u.ext.status = Success; /* default allow */ + prv = &u.ext.status; + break; + case XACE_SERVER_ACCESS: + u.server.client = va_arg(ap, ClientPtr); + u.server.access_mode = va_arg(ap, Mask); + + u.server.status = Success; /* default allow */ + prv = &u.server.status; + break; + case XACE_SCREEN_ACCESS: + case XACE_SCREENSAVER_ACCESS: + u.screen.client = va_arg(ap, ClientPtr); + u.screen.screen = va_arg(ap, ScreenPtr); + u.screen.access_mode = va_arg(ap, Mask); + + u.screen.status = Success; /* default allow */ + prv = &u.screen.status; + break; + case XACE_AUTH_AVAIL: + u.auth.client = va_arg(ap, ClientPtr); + u.auth.authId = va_arg(ap, XID); + + break; + case XACE_KEY_AVAIL: + u.key.event = va_arg(ap, xEventPtr); + u.key.keybd = va_arg(ap, DeviceIntPtr); + u.key.count = va_arg(ap, int); + + break; + default: + va_end(ap); + return 0; /* unimplemented hook number */ } va_end(ap); - + /* call callbacks and return result, if any. */ CallCallbacks(&XaceHooks[hook], &u); return prv ? *prv : Success; @@ -220,17 +236,14 @@ int XaceHook(int hook, ...) * region of the window will be destroyed (overwritten) in pBuf. */ void -XaceCensorImage( - ClientPtr client, - RegionPtr pVisibleRegion, - long widthBytesLine, - DrawablePtr pDraw, - int x, int y, int w, int h, - unsigned int format, - char *pBuf) +XaceCensorImage(ClientPtr client, + RegionPtr pVisibleRegion, + long widthBytesLine, + DrawablePtr pDraw, + int x, int y, int w, int h, unsigned int format, char *pBuf) { - RegionRec imageRegion; /* region representing x,y,w,h */ - RegionRec censorRegion; /* region to obliterate */ + RegionRec imageRegion; /* region representing x,y,w,h */ + RegionRec censorRegion; /* region to obliterate */ BoxRec imageBox; int nRects; @@ -244,90 +257,87 @@ XaceCensorImage( /* censorRegion = imageRegion - visibleRegion */ RegionSubtract(&censorRegion, &imageRegion, pVisibleRegion); nRects = RegionNumRects(&censorRegion); - if (nRects > 0) - { /* we have something to censor */ - GCPtr pScratchGC = NULL; - PixmapPtr pPix = NULL; - xRectangle *pRects = NULL; - Bool failed = FALSE; - int depth = 1; - int bitsPerPixel = 1; - int i; - BoxPtr pBox; - - /* convert region to list-of-rectangles for PolyFillRect */ - - pRects = malloc(nRects * sizeof(xRectangle)); - if (!pRects) - { - failed = TRUE; - goto failSafe; - } - for (pBox = RegionRects(&censorRegion), i = 0; - i < nRects; - i++, pBox++) - { - pRects[i].x = pBox->x1; - pRects[i].y = pBox->y1 - imageBox.y1; - pRects[i].width = pBox->x2 - pBox->x1; - pRects[i].height = pBox->y2 - pBox->y1; - } - - /* use pBuf as a fake pixmap */ - - if (format == ZPixmap) - { - depth = pDraw->depth; - bitsPerPixel = pDraw->bitsPerPixel; - } - - pPix = GetScratchPixmapHeader(pDraw->pScreen, w, h, - depth, bitsPerPixel, - widthBytesLine, (pointer)pBuf); - if (!pPix) - { - failed = TRUE; - goto failSafe; - } - - pScratchGC = GetScratchGC(depth, pPix->drawable.pScreen); - if (!pScratchGC) - { - failed = TRUE; - goto failSafe; - } - - ValidateGC(&pPix->drawable, pScratchGC); - (* pScratchGC->ops->PolyFillRect)(&pPix->drawable, - pScratchGC, nRects, pRects); - - failSafe: - if (failed) - { - /* Censoring was not completed above. To be safe, wipe out - * all the image data so that nothing trusted gets out. - */ - memset(pBuf, 0, (int)(widthBytesLine * h)); - } - free(pRects); - if (pScratchGC) FreeScratchGC(pScratchGC); - if (pPix) FreeScratchPixmapHeader(pPix); + if (nRects > 0) { /* we have something to censor */ + GCPtr pScratchGC = NULL; + PixmapPtr pPix = NULL; + xRectangle *pRects = NULL; + Bool failed = FALSE; + int depth = 1; + int bitsPerPixel = 1; + int i; + BoxPtr pBox; + + /* convert region to list-of-rectangles for PolyFillRect */ + + pRects = malloc(nRects * sizeof(xRectangle)); + if (!pRects) { + failed = TRUE; + goto failSafe; + } + for (pBox = RegionRects(&censorRegion), i = 0; i < nRects; i++, pBox++) { + pRects[i].x = pBox->x1; + pRects[i].y = pBox->y1 - imageBox.y1; + pRects[i].width = pBox->x2 - pBox->x1; + pRects[i].height = pBox->y2 - pBox->y1; + } + + /* use pBuf as a fake pixmap */ + + if (format == ZPixmap) { + depth = pDraw->depth; + bitsPerPixel = pDraw->bitsPerPixel; + } + + pPix = GetScratchPixmapHeader(pDraw->pScreen, w, h, + depth, bitsPerPixel, + widthBytesLine, (pointer) pBuf); + if (!pPix) { + failed = TRUE; + goto failSafe; + } + + pScratchGC = GetScratchGC(depth, pPix->drawable.pScreen); + if (!pScratchGC) { + failed = TRUE; + goto failSafe; + } + + ValidateGC(&pPix->drawable, pScratchGC); + (*pScratchGC->ops->PolyFillRect) (&pPix->drawable, + pScratchGC, nRects, pRects); + + failSafe: + if (failed) { + /* Censoring was not completed above. To be safe, wipe out + * all the image data so that nothing trusted gets out. + */ + memset(pBuf, 0, (int) (widthBytesLine * h)); + } + free(pRects); + if (pScratchGC) + FreeScratchGC(pScratchGC); + if (pPix) + FreeScratchPixmapHeader(pPix); } RegionUninit(&imageRegion); RegionUninit(&censorRegion); -} /* XaceCensorImage */ +} /* XaceCensorImage */ /* * Xtrans wrappers for use by modules */ -int XaceGetConnectionNumber(ClientPtr client) +int +XaceGetConnectionNumber(ClientPtr client) { - XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn; + XtransConnInfo ci = ((OsCommPtr) client->osPrivate)->trans_conn; + return _XSERVTransGetConnectionNumber(ci); } -int XaceIsLocal(ClientPtr client) +int +XaceIsLocal(ClientPtr client) { - XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn; + XtransConnInfo ci = ((OsCommPtr) client->osPrivate)->trans_conn; + return _XSERVTransIsLocal(ci); } diff --git a/xorg-server/Xext/xace.h b/xorg-server/Xext/xace.h index 6029d87d8..5e6cb0437 100644 --- a/xorg-server/Xext/xace.h +++ b/xorg-server/Xext/xace.h @@ -61,18 +61,18 @@ extern _X_EXPORT CallbackListPtr XaceHooks[XACE_NUM_HOOKS]; /* Entry point for hook functions. Called by Xserver. * Required by libdbe and libextmod */ -extern _X_EXPORT int XaceHook( - int /*hook*/, - ... /*appropriate args for hook*/ - ); +extern _X_EXPORT int XaceHook(int /*hook */ , + ... /*appropriate args for hook */ + ); /* Special-cased hook functions */ extern _X_EXPORT int XaceHookDispatch(ClientPtr ptr, int major); extern _X_EXPORT int XaceHookPropertyAccess(ClientPtr ptr, WindowPtr pWin, - PropertyPtr *ppProp, Mask access_mode); -extern _X_EXPORT int XaceHookSelectionAccess(ClientPtr ptr, - Selection **ppSel, Mask access_mode); + PropertyPtr *ppProp, + Mask access_mode); +extern _X_EXPORT int XaceHookSelectionAccess(ClientPtr ptr, Selection ** ppSel, + Mask access_mode); extern _X_EXPORT void XaceHookAuditEnd(ClientPtr ptr, int result); /* Register a callback for a given hook. @@ -93,17 +93,14 @@ extern _X_EXPORT int XaceIsLocal(ClientPtr ptr); /* From the original Security extension... */ -extern _X_EXPORT void XaceCensorImage( - ClientPtr client, - RegionPtr pVisibleRegion, - long widthBytesLine, - DrawablePtr pDraw, - int x, int y, int w, int h, - unsigned int format, - char * pBuf - ); +extern _X_EXPORT void XaceCensorImage(ClientPtr client, + RegionPtr pVisibleRegion, + long widthBytesLine, + DrawablePtr pDraw, + int x, int y, int w, int h, + unsigned int format, char *pBuf); -#else /* XACE */ +#else /* XACE */ /* Default window background */ #define XaceBackgroundNoneState(w) None @@ -126,6 +123,6 @@ extern _X_EXPORT void XaceCensorImage( #define XaceCensorImage(...) { ; } #endif -#endif /* XACE */ +#endif /* XACE */ -#endif /* _XACE_H */ +#endif /* _XACE_H */ diff --git a/xorg-server/Xext/xcmisc.c b/xorg-server/Xext/xcmisc.c index 745135ed5..99a6ece43 100644 --- a/xorg-server/Xext/xcmisc.c +++ b/xorg-server/Xext/xcmisc.c @@ -54,11 +54,11 @@ ProcXCMiscGetVersion(ClientPtr client) rep.majorVersion = XCMiscMajorVersion; rep.minorVersion = XCMiscMinorVersion; if (client->swapped) { - swaps(&rep.sequenceNumber); - swaps(&rep.majorVersion); - swaps(&rep.minorVersion); + swaps(&rep.sequenceNumber); + swaps(&rep.majorVersion); + swaps(&rep.minorVersion); } - WriteToClient(client, sizeof(xXCMiscGetVersionReply), (char *)&rep); + WriteToClient(client, sizeof(xXCMiscGetVersionReply), (char *) &rep); return Success; } @@ -76,11 +76,11 @@ ProcXCMiscGetXIDRange(ClientPtr client) rep.start_id = min_id; rep.count = max_id - min_id + 1; if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.start_id); - swapl(&rep.count); + swaps(&rep.sequenceNumber); + swapl(&rep.start_id); + swapl(&rep.count); } - WriteToClient(client, sizeof(xXCMiscGetXIDRangeReply), (char *)&rep); + WriteToClient(client, sizeof(xXCMiscGetXIDRangeReply), (char *) &rep); return Success; } @@ -95,12 +95,11 @@ ProcXCMiscGetXIDList(ClientPtr client) REQUEST_SIZE_MATCH(xXCMiscGetXIDListReq); if (stuff->count > UINT32_MAX / sizeof(XID)) - return BadAlloc; + return BadAlloc; - pids = (XID *)malloc(stuff->count * sizeof(XID)); - if (!pids) - { - return BadAlloc; + pids = (XID *) malloc(stuff->count * sizeof(XID)); + if (!pids) { + return BadAlloc; } count = GetXIDList(client, stuff->count, pids); rep.type = X_Reply; @@ -108,34 +107,32 @@ ProcXCMiscGetXIDList(ClientPtr client) rep.length = count; rep.count = count; if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.count); + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.count); } - WriteToClient(client, sizeof(xXCMiscGetXIDListReply), (char *)&rep); - if (count) - { - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, count * sizeof(XID), pids); + WriteToClient(client, sizeof(xXCMiscGetXIDListReply), (char *) &rep); + if (count) { + client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; + WriteSwappedDataToClient(client, count * sizeof(XID), pids); } free(pids); return Success; } static int -ProcXCMiscDispatch (ClientPtr client) +ProcXCMiscDispatch(ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { + switch (stuff->data) { case X_XCMiscGetVersion: - return ProcXCMiscGetVersion(client); + return ProcXCMiscGetVersion(client); case X_XCMiscGetXIDRange: - return ProcXCMiscGetXIDRange(client); + return ProcXCMiscGetXIDRange(client); case X_XCMiscGetXIDList: - return ProcXCMiscGetXIDList(client); + return ProcXCMiscGetXIDList(client); default: - return BadRequest; + return BadRequest; } } @@ -171,19 +168,18 @@ SProcXCMiscGetXIDList(ClientPtr client) } static int -SProcXCMiscDispatch (ClientPtr client) +SProcXCMiscDispatch(ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { + switch (stuff->data) { case X_XCMiscGetVersion: - return SProcXCMiscGetVersion(client); + return SProcXCMiscGetVersion(client); case X_XCMiscGetXIDRange: - return SProcXCMiscGetXIDRange(client); + return SProcXCMiscGetXIDRange(client); case X_XCMiscGetXIDList: - return SProcXCMiscGetXIDList(client); + return SProcXCMiscGetXIDList(client); default: - return BadRequest; + return BadRequest; } } @@ -191,6 +187,6 @@ void XCMiscExtensionInit(INITARGS) { AddExtension(XCMiscExtensionName, 0, 0, - ProcXCMiscDispatch, SProcXCMiscDispatch, - NULL, StandardMinorOpcode); + ProcXCMiscDispatch, SProcXCMiscDispatch, + NULL, StandardMinorOpcode); } diff --git a/xorg-server/Xext/xf86bigfont.c b/xorg-server/Xext/xf86bigfont.c index e56370152..d10a36eef 100644 --- a/xorg-server/Xext/xf86bigfont.c +++ b/xorg-server/Xext/xf86bigfont.c @@ -50,7 +50,7 @@ #ifdef SVR4 #include <sys/sysmacros.h> #endif -#if defined(__CYGWIN__) +#if defined(__CYGWIN__) #include <sys/param.h> #include <sys/sysmacros.h> #endif @@ -76,11 +76,9 @@ #include <X11/extensions/xf86bigfproto.h> #include "xf86bigfontsrv.h" -static void XF86BigfontResetProc( - ExtensionEntry * /* extEntry */ +static void XF86BigfontResetProc(ExtensionEntry * /* extEntry */ ); - #ifdef HAS_SHM /* A random signature, transmitted to the clients so they can verify that the @@ -100,8 +98,7 @@ static Bool badSysCall = FALSE; #include <sys/signal.h> static void -SigSysHandler( - int signo) +SigSysHandler(int signo) { badSysCall = TRUE; } @@ -109,7 +106,7 @@ SigSysHandler( static Bool CheckForShmSyscall(void) { - void (*oldHandler)(int); + void (*oldHandler) (int); int shmid = -1; /* If no SHM support in the kernel, the bad syscall will generate SIGSYS */ @@ -117,13 +114,11 @@ CheckForShmSyscall(void) badSysCall = FALSE; shmid = shmget(IPC_PRIVATE, 4096, IPC_CREAT); - if (shmid != -1) - { + if (shmid != -1) { /* Successful allocation - clean up */ - shmctl(shmid, IPC_RMID, NULL); + shmctl(shmid, IPC_RMID, NULL); } - else - { + else { /* Allocation failed */ badSysCall = TRUE; } @@ -158,8 +153,7 @@ typedef struct _ShmDesc { static ShmDescPtr ShmList = (ShmDescPtr) NULL; static ShmDescPtr -shmalloc( - unsigned int size) +shmalloc(unsigned int size) { ShmDescPtr pDesc; int shmid; @@ -167,7 +161,7 @@ shmalloc( #ifdef MUST_CHECK_FOR_SHM_SYSCALL if (pagesize == 0) - return (ShmDescPtr) NULL; + return (ShmDescPtr) NULL; #endif /* On some older Linux systems, the number of shared memory segments @@ -177,27 +171,27 @@ shmalloc( the glyph metrics on the other hand. If the glyph metrics size is small, we prefer the traditional way. */ if (size < 3500) - return (ShmDescPtr) NULL; + return (ShmDescPtr) NULL; pDesc = malloc(sizeof(ShmDescRec)); if (!pDesc) - return (ShmDescPtr) NULL; + return (ShmDescPtr) NULL; - size = (size + pagesize-1) & -pagesize; + size = (size + pagesize - 1) & -pagesize; shmid = shmget(IPC_PRIVATE, size, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); if (shmid == -1) { - ErrorF(XF86BIGFONTNAME " extension: shmget() failed, size = %u, %s\n", - size, strerror(errno)); - free(pDesc); - return (ShmDescPtr) NULL; + ErrorF(XF86BIGFONTNAME " extension: shmget() failed, size = %u, %s\n", + size, strerror(errno)); + free(pDesc); + return (ShmDescPtr) NULL; } - if ((addr = shmat(shmid, 0, 0)) == (char *)-1) { - ErrorF(XF86BIGFONTNAME " extension: shmat() failed, size = %u, %s\n", - size, strerror(errno)); - shmctl(shmid, IPC_RMID, (void *) 0); - free(pDesc); - return (ShmDescPtr) NULL; + if ((addr = shmat(shmid, 0, 0)) == (char *) -1) { + ErrorF(XF86BIGFONTNAME " extension: shmat() failed, size = %u, %s\n", + size, strerror(errno)); + shmctl(shmid, IPC_RMID, (void *) 0); + free(pDesc); + return (ShmDescPtr) NULL; } #ifdef EARLY_REMOVE @@ -206,7 +200,8 @@ shmalloc( pDesc->shmid = shmid; pDesc->attach_addr = addr; - if (ShmList) ShmList->prev = &pDesc->next; + if (ShmList) + ShmList->prev = &pDesc->next; pDesc->next = ShmList; pDesc->prev = &ShmList; ShmList = pDesc; @@ -215,15 +210,15 @@ shmalloc( } static void -shmdealloc( - ShmDescPtr pDesc) +shmdealloc(ShmDescPtr pDesc) { #ifndef EARLY_REMOVE shmctl(pDesc->shmid, IPC_RMID, (void *) 0); #endif shmdt(pDesc->attach_addr); - if (pDesc->next) pDesc->next->prev = pDesc->prev; + if (pDesc->next) + pDesc->next->prev = pDesc->prev; *pDesc->prev = pDesc->next; free(pDesc); } @@ -232,8 +227,7 @@ shmdealloc( /* Called when a font is closed. */ void -XF86BigfontFreeFontShm( - FontPtr pFont) +XF86BigfontFreeFontShm(FontPtr pFont) { #ifdef HAS_SHM ShmDescPtr pDesc; @@ -242,11 +236,11 @@ XF86BigfontFreeFontShm( * called shmdealloc() for all segments, we don't need to do it here. */ if (!ShmList) - return; + return; pDesc = (ShmDescPtr) FontGetPrivate(pFont, FontShmdescIndex); if (pDesc) - shmdealloc(pDesc); + shmdealloc(pDesc); #endif } @@ -256,14 +250,13 @@ XF86BigfontCleanup(void) { #ifdef HAS_SHM while (ShmList) - shmdealloc(ShmList); + shmdealloc(ShmList); #endif } /* Called when a server generation dies. */ static void -XF86BigfontResetProc( - ExtensionEntry* extEntry) +XF86BigfontResetProc(ExtensionEntry * extEntry) { /* This function is normally called from CloseDownExtensions(), called * from main(). It will be followed by a call to FreeAllResources(), @@ -276,12 +269,10 @@ XF86BigfontResetProc( XF86BigfontCleanup(); } - /* ========== Handling of extension specific requests ========== */ static int -ProcXF86BigfontQueryVersion( - ClientPtr client) +ProcXF86BigfontQueryVersion(ClientPtr client) { xXF86BigfontQueryVersionReply reply; @@ -301,33 +292,33 @@ ProcXF86BigfontQueryVersion( #ifdef HAS_SHM reply.signature = signature; #else - reply.signature = 0; /* This is redundant. Avoids uninitialized memory. */ + reply.signature = 0; /* This is redundant. Avoids uninitialized memory. */ #endif reply.capabilities = #ifdef HAS_SHM - (LocalClient(client) && !client->swapped ? XF86Bigfont_CAP_LocalShm : 0) + (LocalClient(client) && !client->swapped ? XF86Bigfont_CAP_LocalShm : 0) #else - 0 + 0 #endif - ; /* may add more bits here in future versions */ + ; /* may add more bits here in future versions */ if (client->swapped) { - char tmp; - swaps(&reply.sequenceNumber); - swapl(&reply.length); - swaps(&reply.majorVersion); - swaps(&reply.minorVersion); - swapl(&reply.uid); - swapl(&reply.gid); - swapl(&reply.signature); + char tmp; + + swaps(&reply.sequenceNumber); + swapl(&reply.length); + swaps(&reply.majorVersion); + swaps(&reply.minorVersion); + swapl(&reply.uid); + swapl(&reply.gid); + swapl(&reply.signature); } WriteToClient(client, - sizeof(xXF86BigfontQueryVersionReply), (char *)&reply); + sizeof(xXF86BigfontQueryVersionReply), (char *) &reply); return Success; } static void -swapCharInfo( - xCharInfo *pCI) +swapCharInfo(xCharInfo * pCI) { char tmp; @@ -347,52 +338,55 @@ swapCharInfo( (p->ascent << 11) + (p->descent << 6)) ^ p->attributes) static int -ProcXF86BigfontQueryFont( - ClientPtr client) +ProcXF86BigfontQueryFont(ClientPtr client) { FontPtr pFont; + REQUEST(xXF86BigfontQueryFontReq); CARD32 stuff_flags; - xCharInfo* pmax; - xCharInfo* pmin; + xCharInfo *pmax; + xCharInfo *pmin; int nCharInfos; int shmid; + #ifdef HAS_SHM ShmDescPtr pDesc = NULL; #else #define pDesc 0 #endif - xCharInfo* pCI; - CARD16* pIndex2UniqIndex; - CARD16* pUniqIndex2Index; + xCharInfo *pCI; + CARD16 *pIndex2UniqIndex; + CARD16 *pUniqIndex2Index; CARD32 nUniqCharInfos; #if 0 REQUEST_SIZE_MATCH(xXF86BigfontQueryFontReq); #else switch (client->req_len) { - case 2: /* client with version 1.0 libX11 */ - stuff_flags = (LocalClient(client) && !client->swapped ? XF86Bigfont_FLAGS_Shm : 0); - break; - case 3: /* client with version 1.1 libX11 */ - stuff_flags = stuff->flags; - break; - default: - return BadLength; + case 2: /* client with version 1.0 libX11 */ + stuff_flags = (LocalClient(client) && + !client->swapped ? XF86Bigfont_FLAGS_Shm : 0); + break; + case 3: /* client with version 1.1 libX11 */ + stuff_flags = stuff->flags; + break; + default: + return BadLength; } #endif - if (dixLookupFontable(&pFont, stuff->id, client, DixGetAttrAccess) != Success) - return BadFont; /* procotol spec says only error is BadFont */ + if (dixLookupFontable(&pFont, stuff->id, client, DixGetAttrAccess) != + Success) + return BadFont; /* procotol spec says only error is BadFont */ pmax = FONTINKMAX(pFont); pmin = FONTINKMIN(pFont); nCharInfos = - (pmax->rightSideBearing == pmin->rightSideBearing - && pmax->leftSideBearing == pmin->leftSideBearing - && pmax->descent == pmin->descent - && pmax->ascent == pmin->ascent - && pmax->characterWidth == pmin->characterWidth) - ? 0 : N2dChars(pFont); + (pmax->rightSideBearing == pmin->rightSideBearing + && pmax->leftSideBearing == pmin->leftSideBearing + && pmax->descent == pmin->descent + && pmax->ascent == pmin->ascent + && pmax->characterWidth == pmin->characterWidth) + ? 0 : N2dChars(pFont); shmid = -1; pCI = NULL; pIndex2UniqIndex = NULL; @@ -401,278 +395,289 @@ ProcXF86BigfontQueryFont( if (nCharInfos > 0) { #ifdef HAS_SHM - if (!badSysCall) - pDesc = (ShmDescPtr) FontGetPrivate(pFont, FontShmdescIndex); - if (pDesc) { - pCI = (xCharInfo *) pDesc->attach_addr; - if (stuff_flags & XF86Bigfont_FLAGS_Shm) - shmid = pDesc->shmid; - } else { - if (stuff_flags & XF86Bigfont_FLAGS_Shm && !badSysCall) - pDesc = shmalloc(nCharInfos * sizeof(xCharInfo) - + sizeof(CARD32)); - if (pDesc) { - pCI = (xCharInfo *) pDesc->attach_addr; - shmid = pDesc->shmid; - } else { + if (!badSysCall) + pDesc = (ShmDescPtr) FontGetPrivate(pFont, FontShmdescIndex); + if (pDesc) { + pCI = (xCharInfo *) pDesc->attach_addr; + if (stuff_flags & XF86Bigfont_FLAGS_Shm) + shmid = pDesc->shmid; + } + else { + if (stuff_flags & XF86Bigfont_FLAGS_Shm && !badSysCall) + pDesc = shmalloc(nCharInfos * sizeof(xCharInfo) + + sizeof(CARD32)); + if (pDesc) { + pCI = (xCharInfo *) pDesc->attach_addr; + shmid = pDesc->shmid; + } + else { #endif - pCI = malloc(nCharInfos * sizeof(xCharInfo)); - if (!pCI) - return BadAlloc; + pCI = malloc(nCharInfos * sizeof(xCharInfo)); + if (!pCI) + return BadAlloc; #ifdef HAS_SHM - } + } #endif - /* Fill nCharInfos starting at pCI. */ - { - xCharInfo* prCI = pCI; - int ninfos = 0; - int ncols = pFont->info.lastCol - pFont->info.firstCol + 1; - int row; - for (row = pFont->info.firstRow; - row <= pFont->info.lastRow && ninfos < nCharInfos; - row++) { - unsigned char chars[512]; - xCharInfo* tmpCharInfos[256]; - unsigned long count; - int col; - unsigned long i; - i = 0; - for (col = pFont->info.firstCol; - col <= pFont->info.lastCol; - col++) { - chars[i++] = row; - chars[i++] = col; - } - (*pFont->get_metrics) (pFont, ncols, chars, TwoD16Bit, - &count, tmpCharInfos); - for (i = 0; i < count && ninfos < nCharInfos; i++) { - *prCI++ = *tmpCharInfos[i]; - ninfos++; - } - } - } + /* Fill nCharInfos starting at pCI. */ + { + xCharInfo *prCI = pCI; + int ninfos = 0; + int ncols = pFont->info.lastCol - pFont->info.firstCol + 1; + int row; + + for (row = pFont->info.firstRow; + row <= pFont->info.lastRow && ninfos < nCharInfos; row++) { + unsigned char chars[512]; + xCharInfo *tmpCharInfos[256]; + unsigned long count; + int col; + unsigned long i; + + i = 0; + for (col = pFont->info.firstCol; + col <= pFont->info.lastCol; col++) { + chars[i++] = row; + chars[i++] = col; + } + (*pFont->get_metrics) (pFont, ncols, chars, TwoD16Bit, + &count, tmpCharInfos); + for (i = 0; i < count && ninfos < nCharInfos; i++) { + *prCI++ = *tmpCharInfos[i]; + ninfos++; + } + } + } #ifdef HAS_SHM - if (pDesc && !badSysCall) { - *(CARD32 *)(pCI + nCharInfos) = signature; - if (!FontSetPrivate(pFont, FontShmdescIndex, pDesc)) { - shmdealloc(pDesc); - return BadAlloc; - } - } - } + if (pDesc && !badSysCall) { + *(CARD32 *) (pCI + nCharInfos) = signature; + if (!FontSetPrivate(pFont, FontShmdescIndex, pDesc)) { + shmdealloc(pDesc); + return BadAlloc; + } + } + } #endif - if (shmid == -1) { - /* Cannot use shared memory, so remove-duplicates the xCharInfos - using a temporary hash table. */ - /* Note that CARD16 is suitable as index type, because - nCharInfos <= 0x10000. */ - CARD32 hashModulus; - CARD16* pHash2UniqIndex; - CARD16* pUniqIndex2NextUniqIndex; - CARD32 NextIndex; - CARD32 NextUniqIndex; - CARD16* tmp; - CARD32 i, j; - - hashModulus = 67; - if (hashModulus > nCharInfos+1) - hashModulus = nCharInfos+1; - - tmp = malloc((4*nCharInfos+1) * sizeof(CARD16)); - if (!tmp) { - if (!pDesc) free(pCI); - return BadAlloc; - } - pIndex2UniqIndex = tmp; - /* nCharInfos elements */ - pUniqIndex2Index = tmp + nCharInfos; - /* max. nCharInfos elements */ - pUniqIndex2NextUniqIndex = tmp + 2*nCharInfos; - /* max. nCharInfos elements */ - pHash2UniqIndex = tmp + 3*nCharInfos; - /* hashModulus (<= nCharInfos+1) elements */ - - /* Note that we can use 0xffff as end-of-list indicator, because - even if nCharInfos = 0x10000, 0xffff can not occur as valid - entry before the last element has been inserted. And once the - last element has been inserted, we don't need the hash table - any more. */ - for (j = 0; j < hashModulus; j++) - pHash2UniqIndex[j] = (CARD16)(-1); - - NextUniqIndex = 0; - for (NextIndex = 0; NextIndex < nCharInfos; NextIndex++) { - xCharInfo* p = &pCI[NextIndex]; - CARD32 hashCode = hashCI(p) % hashModulus; - for (i = pHash2UniqIndex[hashCode]; - i != (CARD16)(-1); - i = pUniqIndex2NextUniqIndex[i]) { - j = pUniqIndex2Index[i]; - if (pCI[j].leftSideBearing == p->leftSideBearing - && pCI[j].rightSideBearing == p->rightSideBearing - && pCI[j].characterWidth == p->characterWidth - && pCI[j].ascent == p->ascent - && pCI[j].descent == p->descent - && pCI[j].attributes == p->attributes) - break; - } - if (i != (CARD16)(-1)) { - /* Found *p at Index j, UniqIndex i */ - pIndex2UniqIndex[NextIndex] = i; - } else { - /* Allocate a new entry in the Uniq table */ - if (hashModulus <= 2*NextUniqIndex - && hashModulus < nCharInfos+1) { - /* Time to increate hash table size */ - hashModulus = 2*hashModulus+1; - if (hashModulus > nCharInfos+1) - hashModulus = nCharInfos+1; - for (j = 0; j < hashModulus; j++) - pHash2UniqIndex[j] = (CARD16)(-1); - for (i = 0; i < NextUniqIndex; i++) - pUniqIndex2NextUniqIndex[i] = (CARD16)(-1); - for (i = 0; i < NextUniqIndex; i++) { - j = pUniqIndex2Index[i]; - p = &pCI[j]; - hashCode = hashCI(p) % hashModulus; - pUniqIndex2NextUniqIndex[i] = pHash2UniqIndex[hashCode]; - pHash2UniqIndex[hashCode] = i; - } - p = &pCI[NextIndex]; - hashCode = hashCI(p) % hashModulus; - } - i = NextUniqIndex++; - pUniqIndex2NextUniqIndex[i] = pHash2UniqIndex[hashCode]; - pHash2UniqIndex[hashCode] = i; - pUniqIndex2Index[i] = NextIndex; - pIndex2UniqIndex[NextIndex] = i; - } - } - nUniqCharInfos = NextUniqIndex; - /* fprintf(stderr, "font metrics: nCharInfos = %d, nUniqCharInfos = %d, hashModulus = %d\n", nCharInfos, nUniqCharInfos, hashModulus); */ - } + if (shmid == -1) { + /* Cannot use shared memory, so remove-duplicates the xCharInfos + using a temporary hash table. */ + /* Note that CARD16 is suitable as index type, because + nCharInfos <= 0x10000. */ + CARD32 hashModulus; + CARD16 *pHash2UniqIndex; + CARD16 *pUniqIndex2NextUniqIndex; + CARD32 NextIndex; + CARD32 NextUniqIndex; + CARD16 *tmp; + CARD32 i, j; + + hashModulus = 67; + if (hashModulus > nCharInfos + 1) + hashModulus = nCharInfos + 1; + + tmp = malloc((4 * nCharInfos + 1) * sizeof(CARD16)); + if (!tmp) { + if (!pDesc) + free(pCI); + return BadAlloc; + } + pIndex2UniqIndex = tmp; + /* nCharInfos elements */ + pUniqIndex2Index = tmp + nCharInfos; + /* max. nCharInfos elements */ + pUniqIndex2NextUniqIndex = tmp + 2 * nCharInfos; + /* max. nCharInfos elements */ + pHash2UniqIndex = tmp + 3 * nCharInfos; + /* hashModulus (<= nCharInfos+1) elements */ + + /* Note that we can use 0xffff as end-of-list indicator, because + even if nCharInfos = 0x10000, 0xffff can not occur as valid + entry before the last element has been inserted. And once the + last element has been inserted, we don't need the hash table + any more. */ + for (j = 0; j < hashModulus; j++) + pHash2UniqIndex[j] = (CARD16) (-1); + + NextUniqIndex = 0; + for (NextIndex = 0; NextIndex < nCharInfos; NextIndex++) { + xCharInfo *p = &pCI[NextIndex]; + CARD32 hashCode = hashCI(p) % hashModulus; + + for (i = pHash2UniqIndex[hashCode]; + i != (CARD16) (-1); i = pUniqIndex2NextUniqIndex[i]) { + j = pUniqIndex2Index[i]; + if (pCI[j].leftSideBearing == p->leftSideBearing + && pCI[j].rightSideBearing == p->rightSideBearing + && pCI[j].characterWidth == p->characterWidth + && pCI[j].ascent == p->ascent + && pCI[j].descent == p->descent + && pCI[j].attributes == p->attributes) + break; + } + if (i != (CARD16) (-1)) { + /* Found *p at Index j, UniqIndex i */ + pIndex2UniqIndex[NextIndex] = i; + } + else { + /* Allocate a new entry in the Uniq table */ + if (hashModulus <= 2 * NextUniqIndex + && hashModulus < nCharInfos + 1) { + /* Time to increate hash table size */ + hashModulus = 2 * hashModulus + 1; + if (hashModulus > nCharInfos + 1) + hashModulus = nCharInfos + 1; + for (j = 0; j < hashModulus; j++) + pHash2UniqIndex[j] = (CARD16) (-1); + for (i = 0; i < NextUniqIndex; i++) + pUniqIndex2NextUniqIndex[i] = (CARD16) (-1); + for (i = 0; i < NextUniqIndex; i++) { + j = pUniqIndex2Index[i]; + p = &pCI[j]; + hashCode = hashCI(p) % hashModulus; + pUniqIndex2NextUniqIndex[i] = + pHash2UniqIndex[hashCode]; + pHash2UniqIndex[hashCode] = i; + } + p = &pCI[NextIndex]; + hashCode = hashCI(p) % hashModulus; + } + i = NextUniqIndex++; + pUniqIndex2NextUniqIndex[i] = pHash2UniqIndex[hashCode]; + pHash2UniqIndex[hashCode] = i; + pUniqIndex2Index[i] = NextIndex; + pIndex2UniqIndex[NextIndex] = i; + } + } + nUniqCharInfos = NextUniqIndex; + /* fprintf(stderr, "font metrics: nCharInfos = %d, nUniqCharInfos = %d, hashModulus = %d\n", nCharInfos, nUniqCharInfos, hashModulus); */ + } } { - int nfontprops = pFont->info.nprops; - int rlength = - sizeof(xXF86BigfontQueryFontReply) - + nfontprops * sizeof(xFontProp) - + (nCharInfos > 0 && shmid == -1 - ? nUniqCharInfos * sizeof(xCharInfo) - + (nCharInfos+1)/2 * 2 * sizeof(CARD16) - : 0); - xXF86BigfontQueryFontReply* reply = malloc(rlength); - char* p; - if (!reply) { - if (nCharInfos > 0) { - if (shmid == -1) free(pIndex2UniqIndex); - if (!pDesc) free(pCI); - } - return BadAlloc; - } - reply->type = X_Reply; - reply->length = bytes_to_int32(rlength - sizeof(xGenericReply)); - reply->sequenceNumber = client->sequence; - reply->minBounds = pFont->info.ink_minbounds; - reply->maxBounds = pFont->info.ink_maxbounds; - reply->minCharOrByte2 = pFont->info.firstCol; - reply->maxCharOrByte2 = pFont->info.lastCol; - reply->defaultChar = pFont->info.defaultCh; - reply->nFontProps = pFont->info.nprops; - reply->drawDirection = pFont->info.drawDirection; - reply->minByte1 = pFont->info.firstRow; - reply->maxByte1 = pFont->info.lastRow; - reply->allCharsExist = pFont->info.allExist; - reply->fontAscent = pFont->info.fontAscent; - reply->fontDescent = pFont->info.fontDescent; - reply->nCharInfos = nCharInfos; + int nfontprops = pFont->info.nprops; + int rlength = sizeof(xXF86BigfontQueryFontReply) + + nfontprops * sizeof(xFontProp) + + (nCharInfos > 0 && shmid == -1 + ? nUniqCharInfos * sizeof(xCharInfo) + + (nCharInfos + 1) / 2 * 2 * sizeof(CARD16) + : 0); + xXF86BigfontQueryFontReply *reply = malloc(rlength); + char *p; + + if (!reply) { + if (nCharInfos > 0) { + if (shmid == -1) + free(pIndex2UniqIndex); + if (!pDesc) + free(pCI); + } + return BadAlloc; + } + reply->type = X_Reply; + reply->length = bytes_to_int32(rlength - sizeof(xGenericReply)); + reply->sequenceNumber = client->sequence; + reply->minBounds = pFont->info.ink_minbounds; + reply->maxBounds = pFont->info.ink_maxbounds; + reply->minCharOrByte2 = pFont->info.firstCol; + reply->maxCharOrByte2 = pFont->info.lastCol; + reply->defaultChar = pFont->info.defaultCh; + reply->nFontProps = pFont->info.nprops; + reply->drawDirection = pFont->info.drawDirection; + reply->minByte1 = pFont->info.firstRow; + reply->maxByte1 = pFont->info.lastRow; + reply->allCharsExist = pFont->info.allExist; + reply->fontAscent = pFont->info.fontAscent; + reply->fontDescent = pFont->info.fontDescent; + reply->nCharInfos = nCharInfos; reply->nUniqCharInfos = nUniqCharInfos; - reply->shmid = shmid; - reply->shmsegoffset = 0; - if (client->swapped) { - char tmp; - swaps(&reply->sequenceNumber); - swapl(&reply->length); - swapCharInfo(&reply->minBounds); - swapCharInfo(&reply->maxBounds); - swaps(&reply->minCharOrByte2); - swaps(&reply->maxCharOrByte2); - swaps(&reply->defaultChar); - swaps(&reply->nFontProps); - swaps(&reply->fontAscent); - swaps(&reply->fontDescent); - swapl(&reply->nCharInfos); - swapl(&reply->nUniqCharInfos); - swapl(&reply->shmid); - swapl(&reply->shmsegoffset); - } - p = (char*) &reply[1]; - { - FontPropPtr pFP; - xFontProp* prFP; - int i; - for (i = 0, pFP = pFont->info.props, prFP = (xFontProp *) p; - i < nfontprops; - i++, pFP++, prFP++) { - prFP->name = pFP->name; - prFP->value = pFP->value; - if (client->swapped) { - char tmp; - swapl(&prFP->name); - swapl(&prFP->value); - } - } - p = (char*) prFP; - } - if (nCharInfos > 0 && shmid == -1) { - xCharInfo* pci; - CARD16* ps; - int i, j; - pci = (xCharInfo*) p; - for (i = 0; i < nUniqCharInfos; i++, pci++) { - *pci = pCI[pUniqIndex2Index[i]]; - if (client->swapped) - swapCharInfo(pci); - } - ps = (CARD16*) pci; - for (j = 0; j < nCharInfos; j++, ps++) { - *ps = pIndex2UniqIndex[j]; - if (client->swapped) { - char tmp; - swaps(ps); - } - } - } - WriteToClient(client, rlength, (char *)reply); - free(reply); - if (nCharInfos > 0) { - if (shmid == -1) free(pIndex2UniqIndex); - if (!pDesc) free(pCI); - } - return Success; + reply->shmid = shmid; + reply->shmsegoffset = 0; + if (client->swapped) { + char tmp; + + swaps(&reply->sequenceNumber); + swapl(&reply->length); + swapCharInfo(&reply->minBounds); + swapCharInfo(&reply->maxBounds); + swaps(&reply->minCharOrByte2); + swaps(&reply->maxCharOrByte2); + swaps(&reply->defaultChar); + swaps(&reply->nFontProps); + swaps(&reply->fontAscent); + swaps(&reply->fontDescent); + swapl(&reply->nCharInfos); + swapl(&reply->nUniqCharInfos); + swapl(&reply->shmid); + swapl(&reply->shmsegoffset); + } + p = (char *) &reply[1]; + { + FontPropPtr pFP; + xFontProp *prFP; + int i; + + for (i = 0, pFP = pFont->info.props, prFP = (xFontProp *) p; + i < nfontprops; i++, pFP++, prFP++) { + prFP->name = pFP->name; + prFP->value = pFP->value; + if (client->swapped) { + char tmp; + + swapl(&prFP->name); + swapl(&prFP->value); + } + } + p = (char *) prFP; + } + if (nCharInfos > 0 && shmid == -1) { + xCharInfo *pci; + CARD16 *ps; + int i, j; + + pci = (xCharInfo *) p; + for (i = 0; i < nUniqCharInfos; i++, pci++) { + *pci = pCI[pUniqIndex2Index[i]]; + if (client->swapped) + swapCharInfo(pci); + } + ps = (CARD16 *) pci; + for (j = 0; j < nCharInfos; j++, ps++) { + *ps = pIndex2UniqIndex[j]; + if (client->swapped) { + char tmp; + + swaps(ps); + } + } + } + WriteToClient(client, rlength, (char *) reply); + free(reply); + if (nCharInfos > 0) { + if (shmid == -1) + free(pIndex2UniqIndex); + if (!pDesc) + free(pCI); + } + return Success; } } static int -ProcXF86BigfontDispatch( - ClientPtr client) +ProcXF86BigfontDispatch(ClientPtr client) { REQUEST(xReq); switch (stuff->data) { - case X_XF86BigfontQueryVersion: - return ProcXF86BigfontQueryVersion(client); - case X_XF86BigfontQueryFont: - return ProcXF86BigfontQueryFont(client); - default: - return BadRequest; + case X_XF86BigfontQueryVersion: + return ProcXF86BigfontQueryVersion(client); + case X_XF86BigfontQueryFont: + return ProcXF86BigfontQueryFont(client); + default: + return BadRequest; } } static int -SProcXF86BigfontQueryVersion( - ClientPtr client) +SProcXF86BigfontQueryVersion(ClientPtr client) { REQUEST(xXF86BigfontQueryVersionReq); char tmp; @@ -682,8 +687,7 @@ SProcXF86BigfontQueryVersion( } static int -SProcXF86BigfontQueryFont( - ClientPtr client) +SProcXF86BigfontQueryFont(ClientPtr client) { REQUEST(xXF86BigfontQueryFontReq); char tmp; @@ -695,18 +699,17 @@ SProcXF86BigfontQueryFont( } static int -SProcXF86BigfontDispatch( - ClientPtr client) +SProcXF86BigfontDispatch(ClientPtr client) { REQUEST(xReq); switch (stuff->data) { - case X_XF86BigfontQueryVersion: - return SProcXF86BigfontQueryVersion(client); - case X_XF86BigfontQueryFont: - return SProcXF86BigfontQueryFont(client); - default: - return BadRequest; + case X_XF86BigfontQueryVersion: + return SProcXF86BigfontQueryVersion(client); + case X_XF86BigfontQueryFont: + return SProcXF86BigfontQueryFont(client); + default: + return BadRequest; } } @@ -714,41 +717,41 @@ void XFree86BigfontExtensionInit(void) { if (AddExtension(XF86BIGFONTNAME, - XF86BigfontNumberEvents, - XF86BigfontNumberErrors, - ProcXF86BigfontDispatch, - SProcXF86BigfontDispatch, - XF86BigfontResetProc, - StandardMinorOpcode)) { + XF86BigfontNumberEvents, + XF86BigfontNumberErrors, + ProcXF86BigfontDispatch, + SProcXF86BigfontDispatch, + XF86BigfontResetProc, StandardMinorOpcode)) { #ifdef HAS_SHM #ifdef MUST_CHECK_FOR_SHM_SYSCALL - /* - * Note: Local-clients will not be optimized without shared memory - * support. Remote-client optimization does not depend on shared - * memory support. Thus, the extension is still registered even - * when shared memory support is not functional. - */ - if (!CheckForShmSyscall()) { - ErrorF(XF86BIGFONTNAME " extension local-client optimization disabled due to lack of shared memory support in the kernel\n"); - return; - } + /* + * Note: Local-clients will not be optimized without shared memory + * support. Remote-client optimization does not depend on shared + * memory support. Thus, the extension is still registered even + * when shared memory support is not functional. + */ + if (!CheckForShmSyscall()) { + ErrorF(XF86BIGFONTNAME + " extension local-client optimization disabled due to lack of shared memory support in the kernel\n"); + return; + } #endif - srand((unsigned int) time(NULL)); - signature = ((unsigned int) (65536.0/(RAND_MAX+1.0) * rand()) << 16) - + (unsigned int) (65536.0/(RAND_MAX+1.0) * rand()); - /* fprintf(stderr, "signature = 0x%08X\n", signature); */ + srand((unsigned int) time(NULL)); + signature = ((unsigned int) (65536.0 / (RAND_MAX + 1.0) * rand()) << 16) + + (unsigned int) (65536.0 / (RAND_MAX + 1.0) * rand()); + /* fprintf(stderr, "signature = 0x%08X\n", signature); */ - FontShmdescIndex = AllocateFontPrivateIndex(); + FontShmdescIndex = AllocateFontPrivateIndex(); #if !defined(CSRG_BASED) && !defined(__CYGWIN__) - pagesize = SHMLBA; + pagesize = SHMLBA; #else -# ifdef _SC_PAGESIZE - pagesize = sysconf(_SC_PAGESIZE); -# else - pagesize = getpagesize(); -# endif +#ifdef _SC_PAGESIZE + pagesize = sysconf(_SC_PAGESIZE); +#else + pagesize = getpagesize(); +#endif #endif #endif } diff --git a/xorg-server/Xext/xres.c b/xorg-server/Xext/xres.c index 232fbab5b..9d89b6550 100644 --- a/xorg-server/Xext/xres.c +++ b/xorg-server/Xext/xres.c @@ -24,30 +24,30 @@ #include "protocol-versions.h" static int -ProcXResQueryVersion (ClientPtr client) +ProcXResQueryVersion(ClientPtr client) { REQUEST(xXResQueryVersionReq); xXResQueryVersionReply rep; - REQUEST_SIZE_MATCH (xXResQueryVersionReq); + REQUEST_SIZE_MATCH(xXResQueryVersionReq); rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; rep.server_major = SERVER_XRES_MAJOR_VERSION; rep.server_minor = SERVER_XRES_MINOR_VERSION; - if (client->swapped) { + if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); swaps(&rep.server_major); swaps(&rep.server_minor); } - WriteToClient(client, sizeof (xXResQueryVersionReply), (char *)&rep); + WriteToClient(client, sizeof(xXResQueryVersionReply), (char *) &rep); return Success; } static int -ProcXResQueryClients (ClientPtr client) +ProcXResQueryClients(ClientPtr client) { /* REQUEST(xXResQueryClientsReq); */ xXResQueryClientsReply rep; @@ -59,11 +59,11 @@ ProcXResQueryClients (ClientPtr client) current_clients = malloc(currentMaxClients * sizeof(int)); num_clients = 0; - for(i = 0; i < currentMaxClients; i++) { - if(clients[i]) { - current_clients[num_clients] = i; - num_clients++; - } + for (i = 0; i < currentMaxClients; i++) { + if (clients[i]) { + current_clients[num_clients] = i; + num_clients++; + } } rep.type = X_Reply; @@ -74,21 +74,21 @@ ProcXResQueryClients (ClientPtr client) swaps(&rep.sequenceNumber); swapl(&rep.length); swapl(&rep.num_clients); - } - WriteToClient (client, sizeof (xXResQueryClientsReply), (char *) &rep); + } + WriteToClient(client, sizeof(xXResQueryClientsReply), (char *) &rep); - if(num_clients) { + if (num_clients) { xXResClient scratch; - for(i = 0; i < num_clients; i++) { + for (i = 0; i < num_clients; i++) { scratch.resource_base = clients[current_clients[i]]->clientAsMask; scratch.resource_mask = RESOURCE_ID_MASK; - - if(client->swapped) { + + if (client->swapped) { swapl(&scratch.resource_base); swapl(&scratch.resource_mask); } - WriteToClient (client, sz_xXResClient, (char *) &scratch); + WriteToClient(client, sz_xXResClient, (char *) &scratch); } } @@ -97,17 +97,16 @@ ProcXResQueryClients (ClientPtr client) return Success; } - static void -ResFindAllRes (pointer value, XID id, RESTYPE type, pointer cdata) +ResFindAllRes(pointer value, XID id, RESTYPE type, pointer cdata) { - int *counts = (int *)cdata; + int *counts = (int *) cdata; counts[(type & TypeMask) - 1]++; } static int -ProcXResQueryClientResources (ClientPtr client) +ProcXResQueryClientResources(ClientPtr client) { REQUEST(xXResQueryClientResourcesReq); xXResQueryClientResourcesReply rep; @@ -118,7 +117,7 @@ ProcXResQueryClientResources (ClientPtr client) clientID = CLIENT_ID(stuff->xid); - if((clientID >= currentMaxClients) || !clients[clientID]) { + if ((clientID >= currentMaxClients) || !clients[clientID]) { client->errorValue = stuff->xid; return BadValue; } @@ -129,8 +128,9 @@ ProcXResQueryClientResources (ClientPtr client) num_types = 0; - for(i = 0; i <= lastResourceType; i++) { - if(counts[i]) num_types++; + for (i = 0; i <= lastResourceType; i++) { + if (counts[i]) + num_types++; } rep.type = X_Reply; @@ -141,93 +141,96 @@ ProcXResQueryClientResources (ClientPtr client) swaps(&rep.sequenceNumber); swapl(&rep.length); swapl(&rep.num_types); - } + } - WriteToClient (client,sizeof(xXResQueryClientResourcesReply),(char*)&rep); + WriteToClient(client, sizeof(xXResQueryClientResourcesReply), + (char *) &rep); - if(num_types) { + if (num_types) { xXResType scratch; - const char *name; + const char *name; - for(i = 0; i < lastResourceType; i++) { - if(!counts[i]) continue; + for (i = 0; i < lastResourceType; i++) { + if (!counts[i]) + continue; - name = LookupResourceName(i + 1); + name = LookupResourceName(i + 1); if (strcmp(name, XREGISTRY_UNKNOWN)) - scratch.resource_type = MakeAtom(name, strlen(name), TRUE); - else { + scratch.resource_type = MakeAtom(name, strlen(name), TRUE); + else { char buf[40]; + snprintf(buf, sizeof(buf), "Unregistered resource %i", i + 1); - scratch.resource_type = MakeAtom(buf, strlen(buf), TRUE); + scratch.resource_type = MakeAtom(buf, strlen(buf), TRUE); } scratch.count = counts[i]; - if(client->swapped) { + if (client->swapped) { swapl(&scratch.resource_type); swapl(&scratch.count); } - WriteToClient (client, sz_xXResType, (char *) &scratch); + WriteToClient(client, sz_xXResType, (char *) &scratch); } } free(counts); - + return Success; } static unsigned long -ResGetApproxPixmapBytes (PixmapPtr pix) +ResGetApproxPixmapBytes(PixmapPtr pix) { - unsigned long nPixels; - int bytesPerPixel; + unsigned long nPixels; + int bytesPerPixel; - bytesPerPixel = pix->drawable.bitsPerPixel>>3; - nPixels = pix->drawable.width * pix->drawable.height; + bytesPerPixel = pix->drawable.bitsPerPixel >> 3; + nPixels = pix->drawable.width * pix->drawable.height; - /* Divide by refcnt as pixmap could be shared between clients, - * so total pixmap mem is shared between these. - */ - return ( nPixels * bytesPerPixel ) / pix->refcnt; + /* Divide by refcnt as pixmap could be shared between clients, + * so total pixmap mem is shared between these. + */ + return (nPixels * bytesPerPixel) / pix->refcnt; } -static void -ResFindPixmaps (pointer value, XID id, pointer cdata) +static void +ResFindPixmaps(pointer value, XID id, pointer cdata) { - unsigned long *bytes = (unsigned long *)cdata; - PixmapPtr pix = (PixmapPtr)value; + unsigned long *bytes = (unsigned long *) cdata; + PixmapPtr pix = (PixmapPtr) value; - *bytes += ResGetApproxPixmapBytes(pix); + *bytes += ResGetApproxPixmapBytes(pix); } static void -ResFindWindowPixmaps (pointer value, XID id, pointer cdata) +ResFindWindowPixmaps(pointer value, XID id, pointer cdata) { - unsigned long *bytes = (unsigned long *)cdata; - WindowPtr pWin = (WindowPtr)value; + unsigned long *bytes = (unsigned long *) cdata; + WindowPtr pWin = (WindowPtr) value; - if (pWin->backgroundState == BackgroundPixmap) - *bytes += ResGetApproxPixmapBytes(pWin->background.pixmap); + if (pWin->backgroundState == BackgroundPixmap) + *bytes += ResGetApproxPixmapBytes(pWin->background.pixmap); - if (pWin->border.pixmap != NULL && !pWin->borderIsPixel) - *bytes += ResGetApproxPixmapBytes(pWin->border.pixmap); + if (pWin->border.pixmap != NULL && !pWin->borderIsPixel) + *bytes += ResGetApproxPixmapBytes(pWin->border.pixmap); } static void -ResFindGCPixmaps (pointer value, XID id, pointer cdata) +ResFindGCPixmaps(pointer value, XID id, pointer cdata) { - unsigned long *bytes = (unsigned long *)cdata; - GCPtr pGC = (GCPtr)value; + unsigned long *bytes = (unsigned long *) cdata; + GCPtr pGC = (GCPtr) value; - if (pGC->stipple != NULL) - *bytes += ResGetApproxPixmapBytes(pGC->stipple); + if (pGC->stipple != NULL) + *bytes += ResGetApproxPixmapBytes(pGC->stipple); - if (pGC->tile.pixmap != NULL && !pGC->tileIsPixel) - *bytes += ResGetApproxPixmapBytes(pGC->tile.pixmap); + if (pGC->tile.pixmap != NULL && !pGC->tileIsPixel) + *bytes += ResGetApproxPixmapBytes(pGC->tile.pixmap); } static int -ProcXResQueryClientPixmapBytes (ClientPtr client) +ProcXResQueryClientPixmapBytes(ClientPtr client) { REQUEST(xXResQueryClientPixmapBytesReq); xXResQueryClientPixmapBytesReply rep; @@ -238,29 +241,27 @@ ProcXResQueryClientPixmapBytes (ClientPtr client) clientID = CLIENT_ID(stuff->xid); - if((clientID >= currentMaxClients) || !clients[clientID]) { + if ((clientID >= currentMaxClients) || !clients[clientID]) { client->errorValue = stuff->xid; return BadValue; } bytes = 0; - FindClientResourcesByType(clients[clientID], RT_PIXMAP, ResFindPixmaps, - (pointer)(&bytes)); + FindClientResourcesByType(clients[clientID], RT_PIXMAP, ResFindPixmaps, + (pointer) (&bytes)); /* * Make sure win background pixmaps also held to account. */ - FindClientResourcesByType(clients[clientID], RT_WINDOW, - ResFindWindowPixmaps, - (pointer)(&bytes)); + FindClientResourcesByType(clients[clientID], RT_WINDOW, + ResFindWindowPixmaps, (pointer) (&bytes)); /* * GC Tile & Stipple pixmaps too. - */ - FindClientResourcesByType(clients[clientID], RT_GC, - ResFindGCPixmaps, - (pointer)(&bytes)); + */ + FindClientResourcesByType(clients[clientID], RT_GC, + ResFindGCPixmaps, (pointer) (&bytes)); #ifdef COMPOSITE /* FIXME: include composite pixmaps too */ @@ -281,13 +282,14 @@ ProcXResQueryClientPixmapBytes (ClientPtr client) swapl(&rep.bytes); swapl(&rep.bytes_overflow); } - WriteToClient (client,sizeof(xXResQueryClientPixmapBytesReply),(char*)&rep); + WriteToClient(client, sizeof(xXResQueryClientPixmapBytesReply), + (char *) &rep); return Success; } static int -ProcResDispatch (ClientPtr client) +ProcResDispatch(ClientPtr client) { REQUEST(xReq); switch (stuff->data) { @@ -299,40 +301,41 @@ ProcResDispatch (ClientPtr client) return ProcXResQueryClientResources(client); case X_XResQueryClientPixmapBytes: return ProcXResQueryClientPixmapBytes(client); - default: break; + default: + break; } return BadRequest; } static int -SProcXResQueryVersion (ClientPtr client) +SProcXResQueryVersion(ClientPtr client) { REQUEST(xXResQueryVersionReq); - REQUEST_SIZE_MATCH (xXResQueryVersionReq); + REQUEST_SIZE_MATCH(xXResQueryVersionReq); return ProcXResQueryVersion(client); } static int -SProcXResQueryClientResources (ClientPtr client) +SProcXResQueryClientResources(ClientPtr client) { REQUEST(xXResQueryClientResourcesReq); - REQUEST_SIZE_MATCH (xXResQueryClientResourcesReq); + REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq); swapl(&stuff->xid); return ProcXResQueryClientResources(client); } static int -SProcXResQueryClientPixmapBytes (ClientPtr client) +SProcXResQueryClientPixmapBytes(ClientPtr client) { REQUEST(xXResQueryClientPixmapBytesReq); - REQUEST_SIZE_MATCH (xXResQueryClientPixmapBytesReq); + REQUEST_SIZE_MATCH(xXResQueryClientPixmapBytesReq); swapl(&stuff->xid); return ProcXResQueryClientPixmapBytes(client); } static int -SProcResDispatch (ClientPtr client) +SProcResDispatch(ClientPtr client) { REQUEST(xReq); swaps(&stuff->length); @@ -340,13 +343,14 @@ SProcResDispatch (ClientPtr client) switch (stuff->data) { case X_XResQueryVersion: return SProcXResQueryVersion(client); - case X_XResQueryClients: /* nothing to swap */ + case X_XResQueryClients: /* nothing to swap */ return ProcXResQueryClients(client); case X_XResQueryClientResources: return SProcXResQueryClientResources(client); case X_XResQueryClientPixmapBytes: return SProcXResQueryClientPixmapBytes(client); - default: break; + default: + break; } return BadRequest; @@ -356,6 +360,6 @@ void ResExtensionInit(INITARGS) { (void) AddExtension(XRES_NAME, 0, 0, - ProcResDispatch, SProcResDispatch, - NULL, StandardMinorOpcode); + ProcResDispatch, SProcResDispatch, + NULL, StandardMinorOpcode); } diff --git a/xorg-server/Xext/xselinux_hooks.c b/xorg-server/Xext/xselinux_hooks.c index 0d4c9ab11..e9c7e93d7 100644 --- a/xorg-server/Xext/xselinux_hooks.c +++ b/xorg-server/Xext/xselinux_hooks.c @@ -45,18 +45,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define _XSELINUX_NEED_FLASK_MAP #include "xselinuxint.h" - /* structure passed to auditing callback */ typedef struct { - ClientPtr client; /* client */ - DeviceIntPtr dev; /* device */ - char *command; /* client's executable path */ - unsigned id; /* resource id, if any */ - int restype; /* resource type, if any */ - int event; /* event type, if any */ - Atom property; /* property name, if any */ - Atom selection; /* selection name, if any */ - char *extension; /* extension name, if any */ + ClientPtr client; /* client */ + DeviceIntPtr dev; /* device */ + char *command; /* client's executable path */ + unsigned id; /* resource id, if any */ + int restype; /* resource type, if any */ + int event; /* event type, if any */ + Atom property; /* property name, if any */ + Atom selection; /* selection name, if any */ + char *extension; /* extension name, if any */ } SELinuxAuditRec; /* private state keys */ @@ -78,31 +77,30 @@ static security_id_t unlabeled_sid; static void SELinuxScreen(CallbackListPtr *, pointer, pointer); /* "true" pointer value for use as callback data */ -static pointer truep = (pointer)1; - +static pointer truep = (pointer) 1; /* * Performs an SELinux permission check. */ static int -SELinuxDoCheck(SELinuxSubjectRec *subj, SELinuxObjectRec *obj, - security_class_t class, Mask mode, SELinuxAuditRec *auditdata) +SELinuxDoCheck(SELinuxSubjectRec * subj, SELinuxObjectRec * obj, + security_class_t class, Mask mode, SELinuxAuditRec * auditdata) { /* serverClient requests OK */ if (subj->privileged) - return Success; + return Success; auditdata->command = subj->command; errno = 0; if (avc_has_perm(subj->sid, obj->sid, class, mode, &subj->aeref, - auditdata) < 0) { - if (mode == DixUnknownAccess) - return Success; /* DixUnknownAccess requests OK ... for now */ - if (errno == EACCES) - return BadAccess; - ErrorF("SELinux: avc_has_perm: unexpected error %d\n", errno); - return BadValue; + auditdata) < 0) { + if (mode == DixUnknownAccess) + return Success; /* DixUnknownAccess requests OK ... for now */ + if (errno == EACCES) + return BadAccess; + ErrorF("SELinux: avc_has_perm: unexpected error %d\n", errno); + return BadValue; } return Success; @@ -124,38 +122,39 @@ SELinuxLabelClient(ClientPtr client) /* Try to get a context from the socket */ if (fd < 0 || getpeercon_raw(fd, &ctx) < 0) { - /* Otherwise, fall back to a default context */ - ctx = SELinuxDefaultClientLabel(); + /* Otherwise, fall back to a default context */ + ctx = SELinuxDefaultClientLabel(); } /* For local clients, try and determine the executable name */ if (XaceIsLocal(client)) { - /* Get cached command name if CLIENTIDS is enabled. */ - const char *cmdname = GetClientCmdName(client); - Bool cached = (cmdname != NULL); - /* If CLIENTIDS is disabled, figure out the command name from - * scratch. */ - if (!cmdname) - { - pid_t pid = DetermineClientPid(client); - if (pid != -1) - DetermineClientCmd(pid, &cmdname, NULL); - } - - if (!cmdname) - goto finish; - - strncpy(subj->command, cmdname, COMMAND_LEN - 1); - - if (!cached) - free((void *) cmdname); /* const char * */ + /* Get cached command name if CLIENTIDS is enabled. */ + const char *cmdname = GetClientCmdName(client); + Bool cached = (cmdname != NULL); + + /* If CLIENTIDS is disabled, figure out the command name from + * scratch. */ + if (!cmdname) { + pid_t pid = DetermineClientPid(client); + + if (pid != -1) + DetermineClientCmd(pid, &cmdname, NULL); + } + + if (!cmdname) + goto finish; + + strncpy(subj->command, cmdname, COMMAND_LEN - 1); + + if (!cached) + free((void *) cmdname); /* const char * */ } -finish: + finish: /* Get a SID from the context */ if (avc_context_to_sid_raw(ctx, &subj->sid) < 0) - FatalError("SELinux: client %d: context_to_sid_raw(%s) failed\n", - client->index, ctx); + FatalError("SELinux: client %d: context_to_sid_raw(%s) failed\n", + client->index, ctx); obj->sid = subj->sid; freecon(ctx); @@ -181,11 +180,11 @@ SELinuxLabelInitial(void) /* Use the context of the X server process for the serverClient */ if (getcon_raw(&ctx) < 0) - FatalError("SELinux: couldn't get context of X server process\n"); + FatalError("SELinux: couldn't get context of X server process\n"); /* Get a SID from the context */ if (avc_context_to_sid_raw(ctx, &subj->sid) < 0) - FatalError("SELinux: serverClient: context_to_sid(%s) failed\n", ctx); + FatalError("SELinux: serverClient: context_to_sid(%s) failed\n", ctx); obj->sid = subj->sid; freecon(ctx); @@ -195,13 +194,13 @@ SELinuxLabelInitial(void) srec.status = Success; for (i = 0; i < screenInfo.numScreens; i++) { - /* Do the screen object */ - srec.screen = screenInfo.screens[i]; - SELinuxScreen(NULL, NULL, &srec); + /* Do the screen object */ + srec.screen = screenInfo.screens[i]; + SELinuxScreen(NULL, NULL, &srec); - /* Do the default colormap */ - dixLookupResourceByType(&unused, screenInfo.screens[i]->defColormap, - RT_COLORMAP, serverClient, DixCreateAccess); + /* Do the default colormap */ + dixLookupResourceByType(&unused, screenInfo.screens[i]->defColormap, + RT_COLORMAP, serverClient, DixCreateAccess); } } @@ -209,50 +208,49 @@ SELinuxLabelInitial(void) * Labels new resource objects. */ static int -SELinuxLabelResource(XaceResourceAccessRec *rec, SELinuxSubjectRec *subj, - SELinuxObjectRec *obj, security_class_t class) +SELinuxLabelResource(XaceResourceAccessRec * rec, SELinuxSubjectRec * subj, + SELinuxObjectRec * obj, security_class_t class) { int offset; security_id_t tsid; /* Check for a create context */ if (rec->rtype & RC_DRAWABLE && subj->win_create_sid) { - obj->sid = subj->win_create_sid; - return Success; + obj->sid = subj->win_create_sid; + return Success; } if (rec->parent) - offset = dixLookupPrivateOffset(rec->ptype); + offset = dixLookupPrivateOffset(rec->ptype); if (rec->parent && offset >= 0) { - /* Use the SID of the parent object in the labeling operation */ - PrivateRec **privatePtr = DEVPRIV_AT(rec->parent, offset); - SELinuxObjectRec *pobj = dixLookupPrivate(privatePtr, objectKey); - tsid = pobj->sid; - } else { - /* Use the SID of the subject */ - tsid = subj->sid; + /* Use the SID of the parent object in the labeling operation */ + PrivateRec **privatePtr = DEVPRIV_AT(rec->parent, offset); + SELinuxObjectRec *pobj = dixLookupPrivate(privatePtr, objectKey); + + tsid = pobj->sid; + } + else { + /* Use the SID of the subject */ + tsid = subj->sid; } /* Perform a transition to obtain the final SID */ if (avc_compute_create(subj->sid, tsid, class, &obj->sid) < 0) { - ErrorF("SELinux: a compute_create call failed!\n"); - return BadValue; + ErrorF("SELinux: a compute_create call failed!\n"); + return BadValue; } return Success; } - /* * Libselinux Callbacks */ static int SELinuxAudit(void *auditdata, - security_class_t class, - char *msgbuf, - size_t msgbufsize) + security_class_t class, char *msgbuf, size_t msgbufsize) { SELinuxAuditRec *audit = auditdata; ClientPtr client = audit->client; @@ -261,39 +259,39 @@ SELinuxAudit(void *auditdata, int major = -1, minor = -1; if (client) { - REQUEST(xReq); - if (stuff) { - major = client->majorOp; - minor = client->minorOp; - } + REQUEST(xReq); + if (stuff) { + major = client->majorOp; + minor = client->minorOp; + } } if (audit->id) - snprintf(idNum, 16, "%x", audit->id); + snprintf(idNum, 16, "%x", audit->id); propertyName = audit->property ? NameForAtom(audit->property) : NULL; selectionName = audit->selection ? NameForAtom(audit->selection) : NULL; return snprintf(msgbuf, msgbufsize, - "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", - (major >= 0) ? "request=" : "", - (major >= 0) ? LookupRequestName(major, minor) : "", - audit->command ? " comm=" : "", - audit->command ? audit->command : "", - audit->dev ? " xdevice=\"" : "", - audit->dev ? audit->dev->name : "", - audit->dev ? "\"" : "", - audit->id ? " resid=" : "", - audit->id ? idNum : "", - audit->restype ? " restype=" : "", - audit->restype ? LookupResourceName(audit->restype) : "", - audit->event ? " event=" : "", - audit->event ? LookupEventName(audit->event & 127) : "", - audit->property ? " property=" : "", - audit->property ? propertyName : "", - audit->selection ? " selection=" : "", - audit->selection ? selectionName : "", - audit->extension ? " extension=" : "", - audit->extension ? audit->extension : ""); + "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", + (major >= 0) ? "request=" : "", + (major >= 0) ? LookupRequestName(major, minor) : "", + audit->command ? " comm=" : "", + audit->command ? audit->command : "", + audit->dev ? " xdevice=\"" : "", + audit->dev ? audit->dev->name : "", + audit->dev ? "\"" : "", + audit->id ? " resid=" : "", + audit->id ? idNum : "", + audit->restype ? " restype=" : "", + audit->restype ? LookupResourceName(audit->restype) : "", + audit->event ? " event=" : "", + audit->event ? LookupEventName(audit->event & 127) : "", + audit->property ? " property=" : "", + audit->property ? propertyName : "", + audit->selection ? " selection=" : "", + audit->selection ? selectionName : "", + audit->extension ? " extension=" : "", + audit->extension ? audit->extension : ""); } static int @@ -305,14 +303,14 @@ SELinuxLog(int type, const char *fmt, ...) switch (type) { case SELINUX_INFO: - aut = AUDIT_USER_MAC_POLICY_LOAD; - break; + aut = AUDIT_USER_MAC_POLICY_LOAD; + break; case SELINUX_AVC: - aut = AUDIT_USER_AVC; - break; + aut = AUDIT_USER_AVC; + break; default: - aut = AUDIT_USER_SELINUX_ERR; - break; + aut = AUDIT_USER_SELINUX_ERR; + break; } va_start(ap, fmt); @@ -333,7 +331,7 @@ SELinuxDevice(CallbackListPtr *pcbl, pointer unused, pointer calldata) XaceDeviceAccessRec *rec = calldata; SELinuxSubjectRec *subj; SELinuxObjectRec *obj; - SELinuxAuditRec auditdata = { .client = rec->client, .dev = rec->dev }; + SELinuxAuditRec auditdata = {.client = rec->client,.dev = rec->dev }; security_class_t cls; int rc; @@ -342,24 +340,26 @@ SELinuxDevice(CallbackListPtr *pcbl, pointer unused, pointer calldata) /* If this is a new object that needs labeling, do it now */ if (rec->access_mode & DixCreateAccess) { - SELinuxSubjectRec *dsubj; - dsubj = dixLookupPrivate(&rec->dev->devPrivates, subjectKey); - - if (subj->dev_create_sid) { - /* Label the device with the create context */ - obj->sid = subj->dev_create_sid; - dsubj->sid = subj->dev_create_sid; - } else { - /* Label the device directly with the process SID */ - obj->sid = subj->sid; - dsubj->sid = subj->sid; - } + SELinuxSubjectRec *dsubj; + + dsubj = dixLookupPrivate(&rec->dev->devPrivates, subjectKey); + + if (subj->dev_create_sid) { + /* Label the device with the create context */ + obj->sid = subj->dev_create_sid; + dsubj->sid = subj->dev_create_sid; + } + else { + /* Label the device directly with the process SID */ + obj->sid = subj->sid; + dsubj->sid = subj->sid; + } } cls = IsPointerDevice(rec->dev) ? SECCLASS_X_POINTER : SECCLASS_X_KEYBOARD; rc = SELinuxDoCheck(subj, obj, cls, rec->access_mode, &auditdata); if (rc != Success) - rec->status = rc; + rec->status = rc; } static void @@ -368,39 +368,39 @@ SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata) XaceSendAccessRec *rec = calldata; SELinuxSubjectRec *subj; SELinuxObjectRec *obj, ev_sid; - SELinuxAuditRec auditdata = { .client = rec->client, .dev = rec->dev }; + SELinuxAuditRec auditdata = {.client = rec->client,.dev = rec->dev }; security_class_t class; int rc, i, type; if (rec->dev) - subj = dixLookupPrivate(&rec->dev->devPrivates, subjectKey); + subj = dixLookupPrivate(&rec->dev->devPrivates, subjectKey); else - subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey); + subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey); obj = dixLookupPrivate(&rec->pWin->devPrivates, objectKey); /* Check send permission on window */ rc = SELinuxDoCheck(subj, obj, SECCLASS_X_DRAWABLE, DixSendAccess, - &auditdata); + &auditdata); if (rc != Success) - goto err; + goto err; /* Check send permission on specific event types */ for (i = 0; i < rec->count; i++) { - type = rec->events[i].u.u.type; - class = (type & 128) ? SECCLASS_X_FAKEEVENT : SECCLASS_X_EVENT; + type = rec->events[i].u.u.type; + class = (type & 128) ? SECCLASS_X_FAKEEVENT : SECCLASS_X_EVENT; - rc = SELinuxEventToSID(type, obj->sid, &ev_sid); - if (rc != Success) - goto err; + rc = SELinuxEventToSID(type, obj->sid, &ev_sid); + if (rc != Success) + goto err; - auditdata.event = type; - rc = SELinuxDoCheck(subj, &ev_sid, class, DixSendAccess, &auditdata); - if (rc != Success) - goto err; + auditdata.event = type; + rc = SELinuxDoCheck(subj, &ev_sid, class, DixSendAccess, &auditdata); + if (rc != Success) + goto err; } return; -err: + err: rec->status = rc; } @@ -410,7 +410,7 @@ SELinuxReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata) XaceReceiveAccessRec *rec = calldata; SELinuxSubjectRec *subj; SELinuxObjectRec *obj, ev_sid; - SELinuxAuditRec auditdata = { .client = NULL }; + SELinuxAuditRec auditdata = {.client = NULL }; security_class_t class; int rc, i, type; @@ -419,26 +419,26 @@ SELinuxReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata) /* Check receive permission on window */ rc = SELinuxDoCheck(subj, obj, SECCLASS_X_DRAWABLE, DixReceiveAccess, - &auditdata); + &auditdata); if (rc != Success) - goto err; + goto err; /* Check receive permission on specific event types */ for (i = 0; i < rec->count; i++) { - type = rec->events[i].u.u.type; - class = (type & 128) ? SECCLASS_X_FAKEEVENT : SECCLASS_X_EVENT; + type = rec->events[i].u.u.type; + class = (type & 128) ? SECCLASS_X_FAKEEVENT : SECCLASS_X_EVENT; - rc = SELinuxEventToSID(type, obj->sid, &ev_sid); - if (rc != Success) - goto err; + rc = SELinuxEventToSID(type, obj->sid, &ev_sid); + if (rc != Success) + goto err; - auditdata.event = type; - rc = SELinuxDoCheck(subj, &ev_sid, class, DixReceiveAccess, &auditdata); - if (rc != Success) - goto err; + auditdata.event = type; + rc = SELinuxDoCheck(subj, &ev_sid, class, DixReceiveAccess, &auditdata); + if (rc != Success) + goto err; } return; -err: + err: rec->status = rc; } @@ -448,7 +448,7 @@ SELinuxExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata) XaceExtAccessRec *rec = calldata; SELinuxSubjectRec *subj, *serv; SELinuxObjectRec *obj; - SELinuxAuditRec auditdata = { .client = rec->client }; + SELinuxAuditRec auditdata = {.client = rec->client }; int rc; subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey); @@ -457,30 +457,30 @@ SELinuxExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata) /* If this is a new object that needs labeling, do it now */ /* XXX there should be a separate callback for this */ if (obj->sid == NULL) { - security_id_t sid; - - serv = dixLookupPrivate(&serverClient->devPrivates, subjectKey); - rc = SELinuxExtensionToSID(rec->ext->name, &sid); - if (rc != Success) { - rec->status = rc; - return; - } - - /* Perform a transition to obtain the final SID */ - if (avc_compute_create(serv->sid, sid, SECCLASS_X_EXTENSION, - &obj->sid) < 0) { - ErrorF("SELinux: a SID transition call failed!\n"); - rec->status = BadValue; - return; - } + security_id_t sid; + + serv = dixLookupPrivate(&serverClient->devPrivates, subjectKey); + rc = SELinuxExtensionToSID(rec->ext->name, &sid); + if (rc != Success) { + rec->status = rc; + return; + } + + /* Perform a transition to obtain the final SID */ + if (avc_compute_create(serv->sid, sid, SECCLASS_X_EXTENSION, + &obj->sid) < 0) { + ErrorF("SELinux: a SID transition call failed!\n"); + rec->status = BadValue; + return; + } } /* Perform the security check */ auditdata.extension = rec->ext->name; rc = SELinuxDoCheck(subj, obj, SECCLASS_X_EXTENSION, rec->access_mode, - &auditdata); + &auditdata); if (rc != Success) - rec->status = rc; + rec->status = rc; } static void @@ -492,7 +492,7 @@ SELinuxSelection(CallbackListPtr *pcbl, pointer unused, pointer calldata) Selection *pSel = *rec->ppSel; Atom name = pSel->selection; Mask access_mode = rec->access_mode; - SELinuxAuditRec auditdata = { .client = rec->client, .selection = name }; + SELinuxAuditRec auditdata = {.client = rec->client,.selection = name }; security_id_t tsid; int rc; @@ -501,45 +501,45 @@ SELinuxSelection(CallbackListPtr *pcbl, pointer unused, pointer calldata) /* If this is a new object that needs labeling, do it now */ if (access_mode & DixCreateAccess) { - rc = SELinuxSelectionToSID(name, subj, &obj->sid, &obj->poly); - if (rc != Success) - obj->sid = unlabeled_sid; - access_mode = DixSetAttrAccess; + rc = SELinuxSelectionToSID(name, subj, &obj->sid, &obj->poly); + if (rc != Success) + obj->sid = unlabeled_sid; + access_mode = DixSetAttrAccess; } /* If this is a polyinstantiated object, find the right instance */ else if (obj->poly) { - rc = SELinuxSelectionToSID(name, subj, &tsid, NULL); - if (rc != Success) { - rec->status = rc; - return; - } - while (pSel->selection != name || obj->sid != tsid) { - if ((pSel = pSel->next) == NULL) - break; - obj = dixLookupPrivate(&pSel->devPrivates, objectKey); - } - - if (pSel) - *rec->ppSel = pSel; - else { - rec->status = BadMatch; - return; - } + rc = SELinuxSelectionToSID(name, subj, &tsid, NULL); + if (rc != Success) { + rec->status = rc; + return; + } + while (pSel->selection != name || obj->sid != tsid) { + if ((pSel = pSel->next) == NULL) + break; + obj = dixLookupPrivate(&pSel->devPrivates, objectKey); + } + + if (pSel) + *rec->ppSel = pSel; + else { + rec->status = BadMatch; + return; + } } /* Perform the security check */ rc = SELinuxDoCheck(subj, obj, SECCLASS_X_SELECTION, access_mode, - &auditdata); + &auditdata); if (rc != Success) - rec->status = rc; + rec->status = rc; /* Label the content (advisory only) */ if (access_mode & DixSetAttrAccess) { - data = dixLookupPrivate(&pSel->devPrivates, dataKey); - if (subj->sel_create_sid) - data->sid = subj->sel_create_sid; - else - data->sid = obj->sid; + data = dixLookupPrivate(&pSel->devPrivates, dataKey); + if (subj->sel_create_sid) + data->sid = subj->sel_create_sid; + else + data->sid = obj->sid; } } @@ -551,59 +551,59 @@ SELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata) SELinuxObjectRec *obj, *data; PropertyPtr pProp = *rec->ppProp; Atom name = pProp->propertyName; - SELinuxAuditRec auditdata = { .client = rec->client, .property = name }; + SELinuxAuditRec auditdata = {.client = rec->client,.property = name }; security_id_t tsid; int rc; /* Don't care about the new content check */ if (rec->access_mode & DixPostAccess) - return; + return; subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey); obj = dixLookupPrivate(&pProp->devPrivates, objectKey); /* If this is a new object that needs labeling, do it now */ if (rec->access_mode & DixCreateAccess) { - rc = SELinuxPropertyToSID(name, subj, &obj->sid, &obj->poly); - if (rc != Success) { - rec->status = rc; - return; - } + rc = SELinuxPropertyToSID(name, subj, &obj->sid, &obj->poly); + if (rc != Success) { + rec->status = rc; + return; + } } /* If this is a polyinstantiated object, find the right instance */ else if (obj->poly) { - rc = SELinuxPropertyToSID(name, subj, &tsid, NULL); - if (rc != Success) { - rec->status = rc; - return; - } - while (pProp->propertyName != name || obj->sid != tsid) { - if ((pProp = pProp->next) == NULL) - break; - obj = dixLookupPrivate(&pProp->devPrivates, objectKey); - } - - if (pProp) - *rec->ppProp = pProp; - else { - rec->status = BadMatch; - return; - } + rc = SELinuxPropertyToSID(name, subj, &tsid, NULL); + if (rc != Success) { + rec->status = rc; + return; + } + while (pProp->propertyName != name || obj->sid != tsid) { + if ((pProp = pProp->next) == NULL) + break; + obj = dixLookupPrivate(&pProp->devPrivates, objectKey); + } + + if (pProp) + *rec->ppProp = pProp; + else { + rec->status = BadMatch; + return; + } } /* Perform the security check */ rc = SELinuxDoCheck(subj, obj, SECCLASS_X_PROPERTY, rec->access_mode, - &auditdata); + &auditdata); if (rc != Success) - rec->status = rc; + rec->status = rc; /* Label the content (advisory only) */ if (rec->access_mode & DixWriteAccess) { - data = dixLookupPrivate(&pProp->devPrivates, dataKey); - if (subj->prp_create_sid) - data->sid = subj->prp_create_sid; - else - data->sid = obj->sid; + data = dixLookupPrivate(&pProp->devPrivates, dataKey); + if (subj->prp_create_sid) + data->sid = subj->prp_create_sid; + else + data->sid = obj->sid; } } @@ -613,7 +613,7 @@ SELinuxResource(CallbackListPtr *pcbl, pointer unused, pointer calldata) XaceResourceAccessRec *rec = calldata; SELinuxSubjectRec *subj; SELinuxObjectRec *obj; - SELinuxAuditRec auditdata = { .client = rec->client }; + SELinuxAuditRec auditdata = {.client = rec->client }; Mask access_mode = rec->access_mode; PrivateRec **privatePtr; security_class_t class; @@ -624,30 +624,31 @@ SELinuxResource(CallbackListPtr *pcbl, pointer unused, pointer calldata) /* Determine if the resource object has a devPrivates field */ offset = dixLookupPrivateOffset(rec->rtype); if (offset < 0) { - /* No: use the SID of the owning client */ - class = SECCLASS_X_RESOURCE; - privatePtr = &clients[CLIENT_ID(rec->id)]->devPrivates; - obj = dixLookupPrivate(privatePtr, objectKey); - } else { - /* Yes: use the SID from the resource object itself */ - class = SELinuxTypeToClass(rec->rtype); - privatePtr = DEVPRIV_AT(rec->res, offset); - obj = dixLookupPrivate(privatePtr, objectKey); + /* No: use the SID of the owning client */ + class = SECCLASS_X_RESOURCE; + privatePtr = &clients[CLIENT_ID(rec->id)]->devPrivates; + obj = dixLookupPrivate(privatePtr, objectKey); + } + else { + /* Yes: use the SID from the resource object itself */ + class = SELinuxTypeToClass(rec->rtype); + privatePtr = DEVPRIV_AT(rec->res, offset); + obj = dixLookupPrivate(privatePtr, objectKey); } /* If this is a new object that needs labeling, do it now */ if (access_mode & DixCreateAccess && offset >= 0) { - rc = SELinuxLabelResource(rec, subj, obj, class); - if (rc != Success) { - rec->status = rc; - return; - } + rc = SELinuxLabelResource(rec, subj, obj, class); + if (rc != Success) { + rec->status = rc; + return; + } } /* Collapse generic resource permissions down to read/write */ if (class == SECCLASS_X_RESOURCE) { - access_mode = !!(rec->access_mode & SELinuxReadMask); /* rd */ - access_mode |= !!(rec->access_mode & ~SELinuxReadMask) << 1; /* wr */ + access_mode = ! !(rec->access_mode & SELinuxReadMask); /* rd */ + access_mode |= ! !(rec->access_mode & ~SELinuxReadMask) << 1; /* wr */ } /* Perform the security check */ @@ -655,13 +656,13 @@ SELinuxResource(CallbackListPtr *pcbl, pointer unused, pointer calldata) auditdata.id = rec->id; rc = SELinuxDoCheck(subj, obj, class, access_mode, &auditdata); if (rc != Success) - rec->status = rc; + rec->status = rc; /* Perform the background none check on windows */ if (access_mode & DixCreateAccess && rec->rtype == RT_WINDOW) { - rc = SELinuxDoCheck(subj, obj, class, DixBlendAccess, &auditdata); - if (rc != Success) - ((WindowPtr)rec->res)->forcedBG = TRUE; + rc = SELinuxDoCheck(subj, obj, class, DixBlendAccess, &auditdata); + if (rc != Success) + ((WindowPtr) rec->res)->forcedBG = TRUE; } } @@ -671,7 +672,7 @@ SELinuxScreen(CallbackListPtr *pcbl, pointer is_saver, pointer calldata) XaceScreenAccessRec *rec = calldata; SELinuxSubjectRec *subj; SELinuxObjectRec *obj; - SELinuxAuditRec auditdata = { .client = rec->client }; + SELinuxAuditRec auditdata = {.client = rec->client }; Mask access_mode = rec->access_mode; int rc; @@ -680,21 +681,21 @@ SELinuxScreen(CallbackListPtr *pcbl, pointer is_saver, pointer calldata) /* If this is a new object that needs labeling, do it now */ if (access_mode & DixCreateAccess) { - /* Perform a transition to obtain the final SID */ - if (avc_compute_create(subj->sid, subj->sid, SECCLASS_X_SCREEN, - &obj->sid) < 0) { - ErrorF("SELinux: a compute_create call failed!\n"); - rec->status = BadValue; - return; - } + /* Perform a transition to obtain the final SID */ + if (avc_compute_create(subj->sid, subj->sid, SECCLASS_X_SCREEN, + &obj->sid) < 0) { + ErrorF("SELinux: a compute_create call failed!\n"); + rec->status = BadValue; + return; + } } if (is_saver) - access_mode <<= 2; + access_mode <<= 2; rc = SELinuxDoCheck(subj, obj, SECCLASS_X_SCREEN, access_mode, &auditdata); if (rc != Success) - rec->status = rc; + rec->status = rc; } static void @@ -703,16 +704,16 @@ SELinuxClient(CallbackListPtr *pcbl, pointer unused, pointer calldata) XaceClientAccessRec *rec = calldata; SELinuxSubjectRec *subj; SELinuxObjectRec *obj; - SELinuxAuditRec auditdata = { .client = rec->client }; + SELinuxAuditRec auditdata = {.client = rec->client }; int rc; subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey); obj = dixLookupPrivate(&rec->target->devPrivates, objectKey); rc = SELinuxDoCheck(subj, obj, SECCLASS_X_CLIENT, rec->access_mode, - &auditdata); + &auditdata); if (rc != Success) - rec->status = rc; + rec->status = rc; } static void @@ -721,19 +722,18 @@ SELinuxServer(CallbackListPtr *pcbl, pointer unused, pointer calldata) XaceServerAccessRec *rec = calldata; SELinuxSubjectRec *subj; SELinuxObjectRec *obj; - SELinuxAuditRec auditdata = { .client = rec->client }; + SELinuxAuditRec auditdata = {.client = rec->client }; int rc; subj = dixLookupPrivate(&rec->client->devPrivates, subjectKey); obj = dixLookupPrivate(&serverClient->devPrivates, objectKey); rc = SELinuxDoCheck(subj, obj, SECCLASS_X_SERVER, rec->access_mode, - &auditdata); + &auditdata); if (rc != Success) - rec->status = rc; + rec->status = rc; } - /* * DIX Callbacks */ @@ -745,11 +745,11 @@ SELinuxClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata) switch (pci->client->clientState) { case ClientStateInitial: - SELinuxLabelClient(pci->client); - break; + SELinuxLabelClient(pci->client); + break; default: - break; + break; } } @@ -762,45 +762,48 @@ SELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata) WindowPtr pWin; if (rec->type != RT_WINDOW) - return; + return; if (rec->state != ResourceStateAdding) - return; + return; - pWin = (WindowPtr)rec->value; + pWin = (WindowPtr) rec->value; subj = dixLookupPrivate(&wClient(pWin)->devPrivates, subjectKey); if (subj->sid) { - security_context_t ctx; - int rc = avc_sid_to_context_raw(subj->sid, &ctx); - if (rc < 0) - FatalError("SELinux: Failed to get security context!\n"); - rc = dixChangeWindowProperty(serverClient, - pWin, atom_client_ctx, XA_STRING, 8, - PropModeReplace, strlen(ctx), ctx, FALSE); - if (rc != Success) - FatalError("SELinux: Failed to set label property on window!\n"); - freecon(ctx); - } else - FatalError("SELinux: Unexpected unlabeled client found\n"); + security_context_t ctx; + int rc = avc_sid_to_context_raw(subj->sid, &ctx); + + if (rc < 0) + FatalError("SELinux: Failed to get security context!\n"); + rc = dixChangeWindowProperty(serverClient, + pWin, atom_client_ctx, XA_STRING, 8, + PropModeReplace, strlen(ctx), ctx, FALSE); + if (rc != Success) + FatalError("SELinux: Failed to set label property on window!\n"); + freecon(ctx); + } + else + FatalError("SELinux: Unexpected unlabeled client found\n"); obj = dixLookupPrivate(&pWin->devPrivates, objectKey); if (obj->sid) { - security_context_t ctx; - int rc = avc_sid_to_context_raw(obj->sid, &ctx); - if (rc < 0) - FatalError("SELinux: Failed to get security context!\n"); - rc = dixChangeWindowProperty(serverClient, - pWin, atom_ctx, XA_STRING, 8, - PropModeReplace, strlen(ctx), ctx, FALSE); - if (rc != Success) - FatalError("SELinux: Failed to set label property on window!\n"); - freecon(ctx); - } else - FatalError("SELinux: Unexpected unlabeled window found\n"); + security_context_t ctx; + int rc = avc_sid_to_context_raw(obj->sid, &ctx); + + if (rc < 0) + FatalError("SELinux: Failed to get security context!\n"); + rc = dixChangeWindowProperty(serverClient, + pWin, atom_ctx, XA_STRING, 8, + PropModeReplace, strlen(ctx), ctx, FALSE); + if (rc != Success) + FatalError("SELinux: Failed to set label property on window!\n"); + freecon(ctx); + } + else + FatalError("SELinux: Unexpected unlabeled window found\n"); } - static int netlink_fd; static void @@ -811,7 +814,7 @@ SELinuxBlockHandler(void *data, struct timeval **tv, void *read_mask) static void SELinuxWakeupHandler(void *data, int err, void *read_mask) { - if (FD_ISSET(netlink_fd, (fd_set *)read_mask)) + if (FD_ISSET(netlink_fd, (fd_set *) read_mask)) avc_netlink_check_nb(); } @@ -848,63 +851,68 @@ SELinuxFlaskReset(void) void SELinuxFlaskInit(void) { - struct selinux_opt avc_option = { AVC_OPT_SETENFORCE, (char *)0 }; + struct selinux_opt avc_option = { AVC_OPT_SETENFORCE, (char *) 0 }; security_context_t ctx; int ret = TRUE; - switch(selinuxEnforcingState) { + switch (selinuxEnforcingState) { case SELINUX_MODE_ENFORCING: - LogMessage(X_INFO, "SELinux: Configured in enforcing mode\n"); - avc_option.value = (char *)1; - break; + LogMessage(X_INFO, "SELinux: Configured in enforcing mode\n"); + avc_option.value = (char *) 1; + break; case SELINUX_MODE_PERMISSIVE: - LogMessage(X_INFO, "SELinux: Configured in permissive mode\n"); - avc_option.value = (char *)0; - break; + LogMessage(X_INFO, "SELinux: Configured in permissive mode\n"); + avc_option.value = (char *) 0; + break; default: - avc_option.type = AVC_OPT_UNUSED; - break; + avc_option.type = AVC_OPT_UNUSED; + break; } /* Set up SELinux stuff */ - selinux_set_callback(SELINUX_CB_LOG, (union selinux_callback)SELinuxLog); - selinux_set_callback(SELINUX_CB_AUDIT, (union selinux_callback)SELinuxAudit); + selinux_set_callback(SELINUX_CB_LOG, (union selinux_callback) SELinuxLog); + selinux_set_callback(SELINUX_CB_AUDIT, + (union selinux_callback) SELinuxAudit); if (selinux_set_mapping(map) < 0) { - if (errno == EINVAL) { - ErrorF("SELinux: Invalid object class mapping, disabling SELinux support.\n"); - return; - } - FatalError("SELinux: Failed to set up security class mapping\n"); + if (errno == EINVAL) { + ErrorF + ("SELinux: Invalid object class mapping, disabling SELinux support.\n"); + return; + } + FatalError("SELinux: Failed to set up security class mapping\n"); } if (avc_open(&avc_option, 1) < 0) - FatalError("SELinux: Couldn't initialize SELinux userspace AVC\n"); + FatalError("SELinux: Couldn't initialize SELinux userspace AVC\n"); if (security_get_initial_context_raw("unlabeled", &ctx) < 0) - FatalError("SELinux: Failed to look up unlabeled context\n"); + FatalError("SELinux: Failed to look up unlabeled context\n"); if (avc_context_to_sid_raw(ctx, &unlabeled_sid) < 0) - FatalError("SELinux: a context_to_SID call failed!\n"); + FatalError("SELinux: a context_to_SID call failed!\n"); freecon(ctx); /* Prepare for auditing */ audit_fd = audit_open(); if (audit_fd < 0) - FatalError("SELinux: Failed to open the system audit log\n"); + FatalError("SELinux: Failed to open the system audit log\n"); /* Allocate private storage */ - if (!dixRegisterPrivateKey(subjectKey, PRIVATE_XSELINUX, sizeof(SELinuxSubjectRec)) || - !dixRegisterPrivateKey(objectKey, PRIVATE_XSELINUX, sizeof(SELinuxObjectRec)) || - !dixRegisterPrivateKey(dataKey, PRIVATE_XSELINUX, sizeof(SELinuxObjectRec))) - FatalError("SELinux: Failed to allocate private storage.\n"); + if (!dixRegisterPrivateKey + (subjectKey, PRIVATE_XSELINUX, sizeof(SELinuxSubjectRec)) || + !dixRegisterPrivateKey(objectKey, PRIVATE_XSELINUX, + sizeof(SELinuxObjectRec)) || + !dixRegisterPrivateKey(dataKey, PRIVATE_XSELINUX, + sizeof(SELinuxObjectRec))) + FatalError("SELinux: Failed to allocate private storage.\n"); /* Create atoms for doing window labeling */ atom_ctx = MakeAtom("_SELINUX_CONTEXT", 16, TRUE); if (atom_ctx == BAD_RESOURCE) - FatalError("SELinux: Failed to create atom\n"); + FatalError("SELinux: Failed to create atom\n"); atom_client_ctx = MakeAtom("_SELINUX_CLIENT_CONTEXT", 23, TRUE); if (atom_client_ctx == BAD_RESOURCE) - FatalError("SELinux: Failed to create atom\n"); + FatalError("SELinux: Failed to create atom\n"); netlink_fd = avc_netlink_acquire_fd(); AddGeneralSocket(netlink_fd); @@ -928,7 +936,7 @@ SELinuxFlaskInit(void) ret &= XaceRegisterCallback(XACE_SCREEN_ACCESS, SELinuxScreen, NULL); ret &= XaceRegisterCallback(XACE_SCREENSAVER_ACCESS, SELinuxScreen, truep); if (!ret) - FatalError("SELinux: Failed to register one or more callbacks\n"); + FatalError("SELinux: Failed to register one or more callbacks\n"); /* Label objects that were created before we could register ourself */ SELinuxLabelInitial(); diff --git a/xorg-server/Xext/xselinux_label.c b/xorg-server/Xext/xselinux_label.c index 76e537abe..2c33d1cbf 100644 --- a/xorg-server/Xext/xselinux_label.c +++ b/xorg-server/Xext/xselinux_label.c @@ -1,374 +1,381 @@ -/************************************************************
-
-Author: Eamon Walsh <ewalsh@tycho.nsa.gov>
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-this permission notice appear in supporting documentation. This permission
-notice shall be included in all copies or substantial portions of the
-Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-********************************************************/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <selinux/label.h>
-
-#include "registry.h"
-#include "xselinuxint.h"
-
-/* selection and property atom cache */
-typedef struct {
- SELinuxObjectRec prp;
- SELinuxObjectRec sel;
-} SELinuxAtomRec;
-
-/* dynamic array */
-typedef struct {
- unsigned size;
- void **array;
-} SELinuxArrayRec;
-
-/* labeling handle */
-static struct selabel_handle *label_hnd;
-
-/* Array of object classes indexed by resource type */
-SELinuxArrayRec arr_types;
-/* Array of event SIDs indexed by event type */
-SELinuxArrayRec arr_events;
-/* Array of property and selection SID structures */
-SELinuxArrayRec arr_atoms;
-
-/*
- * Dynamic array helpers
- */
-static void *
-SELinuxArrayGet(SELinuxArrayRec *rec, unsigned key)
-{
- return (rec->size > key) ? rec->array[key] : 0;
-}
-
-static int
-SELinuxArraySet(SELinuxArrayRec *rec, unsigned key, void *val)
-{
- if (key >= rec->size) {
- /* Need to increase size of array */
- rec->array = realloc(rec->array, (key + 1) * sizeof(val));
- if (!rec->array)
- return FALSE;
- memset(rec->array + rec->size, 0, (key - rec->size + 1) * sizeof(val));
- rec->size = key + 1;
- }
-
- rec->array[key] = val;
- return TRUE;
-}
-
-static void
-SELinuxArrayFree(SELinuxArrayRec *rec, int free_elements)
-{
- if (free_elements) {
- unsigned i = rec->size;
- while (i)
- free(rec->array[--i]);
- }
-
- free(rec->array);
- rec->size = 0;
- rec->array = NULL;
-}
-
-/*
- * Looks up a name in the selection or property mappings
- */
-static int
-SELinuxAtomToSIDLookup(Atom atom, SELinuxObjectRec *obj, int map, int polymap)
-{
- const char *name = NameForAtom(atom);
- security_context_t ctx;
- int rc = Success;
-
- obj->poly = 1;
-
- /* Look in the mappings of names to contexts */
- if (selabel_lookup_raw(label_hnd, &ctx, name, map) == 0) {
- obj->poly = 0;
- } else if (errno != ENOENT) {
- ErrorF("SELinux: a property label lookup failed!\n");
- return BadValue;
- } else if (selabel_lookup_raw(label_hnd, &ctx, name, polymap) < 0) {
- ErrorF("SELinux: a property label lookup failed!\n");
- return BadValue;
- }
-
- /* Get a SID for context */
- if (avc_context_to_sid_raw(ctx, &obj->sid) < 0) {
- ErrorF("SELinux: a context_to_SID_raw call failed!\n");
- rc = BadAlloc;
- }
-
- freecon(ctx);
- return rc;
-}
-
-/*
- * Looks up the SID corresponding to the given property or selection atom
- */
-int
-SELinuxAtomToSID(Atom atom, int prop, SELinuxObjectRec **obj_rtn)
-{
- SELinuxAtomRec *rec;
- SELinuxObjectRec *obj;
- int rc, map, polymap;
-
- rec = SELinuxArrayGet(&arr_atoms, atom);
- if (!rec) {
- rec = calloc(1, sizeof(SELinuxAtomRec));
- if (!rec || !SELinuxArraySet(&arr_atoms, atom, rec))
- return BadAlloc;
- }
-
- if (prop) {
- obj = &rec->prp;
- map = SELABEL_X_PROP;
- polymap = SELABEL_X_POLYPROP;
- } else {
- obj = &rec->sel;
- map = SELABEL_X_SELN;
- polymap = SELABEL_X_POLYSELN;
- }
-
- if (!obj->sid) {
- rc = SELinuxAtomToSIDLookup(atom, obj, map, polymap);
- if (rc != Success)
- goto out;
- }
-
- *obj_rtn = obj;
- rc = Success;
-out:
- return rc;
-}
-
-/*
- * Looks up a SID for a selection/subject pair
- */
-int
-SELinuxSelectionToSID(Atom selection, SELinuxSubjectRec *subj,
- security_id_t *sid_rtn, int *poly_rtn)
-{
- int rc;
- SELinuxObjectRec *obj;
- security_id_t tsid;
-
- /* Get the default context and polyinstantiation bit */
- rc = SELinuxAtomToSID(selection, 0, &obj);
- if (rc != Success)
- return rc;
-
- /* Check for an override context next */
- if (subj->sel_use_sid) {
- tsid = subj->sel_use_sid;
- goto out;
- }
-
- tsid = obj->sid;
-
- /* Polyinstantiate if necessary to obtain the final SID */
- if (obj->poly && avc_compute_member(subj->sid, obj->sid,
- SECCLASS_X_SELECTION, &tsid) < 0) {
- ErrorF("SELinux: a compute_member call failed!\n");
- return BadValue;
- }
-out:
- *sid_rtn = tsid;
- if (poly_rtn)
- *poly_rtn = obj->poly;
- return Success;
-}
-
-/*
- * Looks up a SID for a property/subject pair
- */
-int
-SELinuxPropertyToSID(Atom property, SELinuxSubjectRec *subj,
- security_id_t *sid_rtn, int *poly_rtn)
-{
- int rc;
- SELinuxObjectRec *obj;
- security_id_t tsid, tsid2;
-
- /* Get the default context and polyinstantiation bit */
- rc = SELinuxAtomToSID(property, 1, &obj);
- if (rc != Success)
- return rc;
-
- /* Check for an override context next */
- if (subj->prp_use_sid) {
- tsid = subj->prp_use_sid;
- goto out;
- }
-
- /* Perform a transition */
- if (avc_compute_create(subj->sid, obj->sid,
- SECCLASS_X_PROPERTY, &tsid) < 0) {
- ErrorF("SELinux: a compute_create call failed!\n");
- return BadValue;
- }
-
- /* Polyinstantiate if necessary to obtain the final SID */
- if (obj->poly) {
- tsid2 = tsid;
- if (avc_compute_member(subj->sid, tsid2,
- SECCLASS_X_PROPERTY, &tsid) < 0) {
- ErrorF("SELinux: a compute_member call failed!\n");
- return BadValue;
- }
- }
-out:
- *sid_rtn = tsid;
- if (poly_rtn)
- *poly_rtn = obj->poly;
- return Success;
-}
-
-/*
- * Looks up the SID corresponding to the given event type
- */
-int
-SELinuxEventToSID(unsigned type, security_id_t sid_of_window,
- SELinuxObjectRec *sid_return)
-{
- const char *name = LookupEventName(type);
- security_id_t sid;
- security_context_t ctx;
- type &= 127;
-
- sid = SELinuxArrayGet(&arr_events, type);
- if (!sid) {
- /* Look in the mappings of event names to contexts */
- if (selabel_lookup_raw(label_hnd, &ctx, name, SELABEL_X_EVENT) < 0) {
- ErrorF("SELinux: an event label lookup failed!\n");
- return BadValue;
- }
- /* Get a SID for context */
- if (avc_context_to_sid_raw(ctx, &sid) < 0) {
- ErrorF("SELinux: a context_to_SID_raw call failed!\n");
- freecon(ctx);
- return BadAlloc;
- }
- freecon(ctx);
- /* Cache the SID value */
- if (!SELinuxArraySet(&arr_events, type, sid))
- return BadAlloc;
- }
-
- /* Perform a transition to obtain the final SID */
- if (avc_compute_create(sid_of_window, sid, SECCLASS_X_EVENT,
- &sid_return->sid) < 0) {
- ErrorF("SELinux: a compute_create call failed!\n");
- return BadValue;
- }
-
- return Success;
-}
-
-int
-SELinuxExtensionToSID(const char *name, security_id_t *sid_rtn)
-{
- security_context_t ctx;
-
- /* Look in the mappings of extension names to contexts */
- if (selabel_lookup_raw(label_hnd, &ctx, name, SELABEL_X_EXT) < 0) {
- ErrorF("SELinux: a property label lookup failed!\n");
- return BadValue;
- }
- /* Get a SID for context */
- if (avc_context_to_sid_raw(ctx, sid_rtn) < 0) {
- ErrorF("SELinux: a context_to_SID_raw call failed!\n");
- freecon(ctx);
- return BadAlloc;
- }
- freecon(ctx);
- return Success;
-}
-
-/*
- * Returns the object class corresponding to the given resource type.
- */
-security_class_t
-SELinuxTypeToClass(RESTYPE type)
-{
- void *tmp;
-
- tmp = SELinuxArrayGet(&arr_types, type & TypeMask);
- if (!tmp) {
- unsigned long class = SECCLASS_X_RESOURCE;
-
- if (type & RC_DRAWABLE)
- class = SECCLASS_X_DRAWABLE;
- else if (type == RT_GC)
- class = SECCLASS_X_GC;
- else if (type == RT_FONT)
- class = SECCLASS_X_FONT;
- else if (type == RT_CURSOR)
- class = SECCLASS_X_CURSOR;
- else if (type == RT_COLORMAP)
- class = SECCLASS_X_COLORMAP;
- else {
- /* Need to do a string lookup */
- const char *str = LookupResourceName(type);
- if (!strcmp(str, "PICTURE"))
- class = SECCLASS_X_DRAWABLE;
- else if (!strcmp(str, "GLYPHSET"))
- class = SECCLASS_X_FONT;
- }
-
- tmp = (void *)class;
- SELinuxArraySet(&arr_types, type & TypeMask, tmp);
- }
-
- return (security_class_t)(unsigned long)tmp;
-}
-
-security_context_t
-SELinuxDefaultClientLabel(void)
-{
- security_context_t ctx;
-
- if (selabel_lookup_raw(label_hnd, &ctx, "remote", SELABEL_X_CLIENT) < 0)
- FatalError("SELinux: failed to look up remote-client context\n");
-
- return ctx;
-}
-
-void
-SELinuxLabelInit(void)
-{
- struct selinux_opt selabel_option = { SELABEL_OPT_VALIDATE, (char *)1 };
-
- label_hnd = selabel_open(SELABEL_CTX_X, &selabel_option, 1);
- if (!label_hnd)
- FatalError("SELinux: Failed to open x_contexts mapping in policy\n");
-}
-
-void
-SELinuxLabelReset(void)
-{
- selabel_close(label_hnd);
- label_hnd = NULL;
-
- /* Free local state */
- SELinuxArrayFree(&arr_types, 0);
- SELinuxArrayFree(&arr_events, 0);
- SELinuxArrayFree(&arr_atoms, 1);
-}
+/************************************************************ + +Author: Eamon Walsh <ewalsh@tycho.nsa.gov> + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +this permission notice appear in supporting documentation. This permission +notice shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +********************************************************/ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <selinux/label.h> + +#include "registry.h" +#include "xselinuxint.h" + +/* selection and property atom cache */ +typedef struct { + SELinuxObjectRec prp; + SELinuxObjectRec sel; +} SELinuxAtomRec; + +/* dynamic array */ +typedef struct { + unsigned size; + void **array; +} SELinuxArrayRec; + +/* labeling handle */ +static struct selabel_handle *label_hnd; + +/* Array of object classes indexed by resource type */ +SELinuxArrayRec arr_types; + +/* Array of event SIDs indexed by event type */ +SELinuxArrayRec arr_events; + +/* Array of property and selection SID structures */ +SELinuxArrayRec arr_atoms; + +/* + * Dynamic array helpers + */ +static void * +SELinuxArrayGet(SELinuxArrayRec * rec, unsigned key) +{ + return (rec->size > key) ? rec->array[key] : 0; +} + +static int +SELinuxArraySet(SELinuxArrayRec * rec, unsigned key, void *val) +{ + if (key >= rec->size) { + /* Need to increase size of array */ + rec->array = realloc(rec->array, (key + 1) * sizeof(val)); + if (!rec->array) + return FALSE; + memset(rec->array + rec->size, 0, (key - rec->size + 1) * sizeof(val)); + rec->size = key + 1; + } + + rec->array[key] = val; + return TRUE; +} + +static void +SELinuxArrayFree(SELinuxArrayRec * rec, int free_elements) +{ + if (free_elements) { + unsigned i = rec->size; + + while (i) + free(rec->array[--i]); + } + + free(rec->array); + rec->size = 0; + rec->array = NULL; +} + +/* + * Looks up a name in the selection or property mappings + */ +static int +SELinuxAtomToSIDLookup(Atom atom, SELinuxObjectRec * obj, int map, int polymap) +{ + const char *name = NameForAtom(atom); + security_context_t ctx; + int rc = Success; + + obj->poly = 1; + + /* Look in the mappings of names to contexts */ + if (selabel_lookup_raw(label_hnd, &ctx, name, map) == 0) { + obj->poly = 0; + } + else if (errno != ENOENT) { + ErrorF("SELinux: a property label lookup failed!\n"); + return BadValue; + } + else if (selabel_lookup_raw(label_hnd, &ctx, name, polymap) < 0) { + ErrorF("SELinux: a property label lookup failed!\n"); + return BadValue; + } + + /* Get a SID for context */ + if (avc_context_to_sid_raw(ctx, &obj->sid) < 0) { + ErrorF("SELinux: a context_to_SID_raw call failed!\n"); + rc = BadAlloc; + } + + freecon(ctx); + return rc; +} + +/* + * Looks up the SID corresponding to the given property or selection atom + */ +int +SELinuxAtomToSID(Atom atom, int prop, SELinuxObjectRec ** obj_rtn) +{ + SELinuxAtomRec *rec; + SELinuxObjectRec *obj; + int rc, map, polymap; + + rec = SELinuxArrayGet(&arr_atoms, atom); + if (!rec) { + rec = calloc(1, sizeof(SELinuxAtomRec)); + if (!rec || !SELinuxArraySet(&arr_atoms, atom, rec)) + return BadAlloc; + } + + if (prop) { + obj = &rec->prp; + map = SELABEL_X_PROP; + polymap = SELABEL_X_POLYPROP; + } + else { + obj = &rec->sel; + map = SELABEL_X_SELN; + polymap = SELABEL_X_POLYSELN; + } + + if (!obj->sid) { + rc = SELinuxAtomToSIDLookup(atom, obj, map, polymap); + if (rc != Success) + goto out; + } + + *obj_rtn = obj; + rc = Success; + out: + return rc; +} + +/* + * Looks up a SID for a selection/subject pair + */ +int +SELinuxSelectionToSID(Atom selection, SELinuxSubjectRec * subj, + security_id_t * sid_rtn, int *poly_rtn) +{ + int rc; + SELinuxObjectRec *obj; + security_id_t tsid; + + /* Get the default context and polyinstantiation bit */ + rc = SELinuxAtomToSID(selection, 0, &obj); + if (rc != Success) + return rc; + + /* Check for an override context next */ + if (subj->sel_use_sid) { + tsid = subj->sel_use_sid; + goto out; + } + + tsid = obj->sid; + + /* Polyinstantiate if necessary to obtain the final SID */ + if (obj->poly && avc_compute_member(subj->sid, obj->sid, + SECCLASS_X_SELECTION, &tsid) < 0) { + ErrorF("SELinux: a compute_member call failed!\n"); + return BadValue; + } + out: + *sid_rtn = tsid; + if (poly_rtn) + *poly_rtn = obj->poly; + return Success; +} + +/* + * Looks up a SID for a property/subject pair + */ +int +SELinuxPropertyToSID(Atom property, SELinuxSubjectRec * subj, + security_id_t * sid_rtn, int *poly_rtn) +{ + int rc; + SELinuxObjectRec *obj; + security_id_t tsid, tsid2; + + /* Get the default context and polyinstantiation bit */ + rc = SELinuxAtomToSID(property, 1, &obj); + if (rc != Success) + return rc; + + /* Check for an override context next */ + if (subj->prp_use_sid) { + tsid = subj->prp_use_sid; + goto out; + } + + /* Perform a transition */ + if (avc_compute_create(subj->sid, obj->sid, SECCLASS_X_PROPERTY, &tsid) < 0) { + ErrorF("SELinux: a compute_create call failed!\n"); + return BadValue; + } + + /* Polyinstantiate if necessary to obtain the final SID */ + if (obj->poly) { + tsid2 = tsid; + if (avc_compute_member(subj->sid, tsid2, + SECCLASS_X_PROPERTY, &tsid) < 0) { + ErrorF("SELinux: a compute_member call failed!\n"); + return BadValue; + } + } + out: + *sid_rtn = tsid; + if (poly_rtn) + *poly_rtn = obj->poly; + return Success; +} + +/* + * Looks up the SID corresponding to the given event type + */ +int +SELinuxEventToSID(unsigned type, security_id_t sid_of_window, + SELinuxObjectRec * sid_return) +{ + const char *name = LookupEventName(type); + security_id_t sid; + security_context_t ctx; + + type &= 127; + + sid = SELinuxArrayGet(&arr_events, type); + if (!sid) { + /* Look in the mappings of event names to contexts */ + if (selabel_lookup_raw(label_hnd, &ctx, name, SELABEL_X_EVENT) < 0) { + ErrorF("SELinux: an event label lookup failed!\n"); + return BadValue; + } + /* Get a SID for context */ + if (avc_context_to_sid_raw(ctx, &sid) < 0) { + ErrorF("SELinux: a context_to_SID_raw call failed!\n"); + freecon(ctx); + return BadAlloc; + } + freecon(ctx); + /* Cache the SID value */ + if (!SELinuxArraySet(&arr_events, type, sid)) + return BadAlloc; + } + + /* Perform a transition to obtain the final SID */ + if (avc_compute_create(sid_of_window, sid, SECCLASS_X_EVENT, + &sid_return->sid) < 0) { + ErrorF("SELinux: a compute_create call failed!\n"); + return BadValue; + } + + return Success; +} + +int +SELinuxExtensionToSID(const char *name, security_id_t * sid_rtn) +{ + security_context_t ctx; + + /* Look in the mappings of extension names to contexts */ + if (selabel_lookup_raw(label_hnd, &ctx, name, SELABEL_X_EXT) < 0) { + ErrorF("SELinux: a property label lookup failed!\n"); + return BadValue; + } + /* Get a SID for context */ + if (avc_context_to_sid_raw(ctx, sid_rtn) < 0) { + ErrorF("SELinux: a context_to_SID_raw call failed!\n"); + freecon(ctx); + return BadAlloc; + } + freecon(ctx); + return Success; +} + +/* + * Returns the object class corresponding to the given resource type. + */ +security_class_t +SELinuxTypeToClass(RESTYPE type) +{ + void *tmp; + + tmp = SELinuxArrayGet(&arr_types, type & TypeMask); + if (!tmp) { + unsigned long class = SECCLASS_X_RESOURCE; + + if (type & RC_DRAWABLE) + class = SECCLASS_X_DRAWABLE; + else if (type == RT_GC) + class = SECCLASS_X_GC; + else if (type == RT_FONT) + class = SECCLASS_X_FONT; + else if (type == RT_CURSOR) + class = SECCLASS_X_CURSOR; + else if (type == RT_COLORMAP) + class = SECCLASS_X_COLORMAP; + else { + /* Need to do a string lookup */ + const char *str = LookupResourceName(type); + + if (!strcmp(str, "PICTURE")) + class = SECCLASS_X_DRAWABLE; + else if (!strcmp(str, "GLYPHSET")) + class = SECCLASS_X_FONT; + } + + tmp = (void *) class; + SELinuxArraySet(&arr_types, type & TypeMask, tmp); + } + + return (security_class_t) (unsigned long) tmp; +} + +security_context_t +SELinuxDefaultClientLabel(void) +{ + security_context_t ctx; + + if (selabel_lookup_raw(label_hnd, &ctx, "remote", SELABEL_X_CLIENT) < 0) + FatalError("SELinux: failed to look up remote-client context\n"); + + return ctx; +} + +void +SELinuxLabelInit(void) +{ + struct selinux_opt selabel_option = { SELABEL_OPT_VALIDATE, (char *) 1 }; + + label_hnd = selabel_open(SELABEL_CTX_X, &selabel_option, 1); + if (!label_hnd) + FatalError("SELinux: Failed to open x_contexts mapping in policy\n"); +} + +void +SELinuxLabelReset(void) +{ + selabel_close(label_hnd); + label_hnd = NULL; + + /* Free local state */ + SELinuxArrayFree(&arr_types, 0); + SELinuxArrayFree(&arr_events, 0); + SELinuxArrayFree(&arr_atoms, 1); +} diff --git a/xorg-server/Xext/xselinuxint.h b/xorg-server/Xext/xselinuxint.h index fb1d7f4c7..57f8b7305 100644 --- a/xorg-server/Xext/xselinuxint.h +++ b/xorg-server/Xext/xselinuxint.h @@ -1,561 +1,564 @@ -/************************************************************
-
-Author: Eamon Walsh <ewalsh@tycho.nsa.gov>
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-this permission notice appear in supporting documentation. This permission
-notice shall be included in all copies or substantial portions of the
-Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-********************************************************/
-
-#ifndef _XSELINUXINT_H
-#define _XSELINUXINT_H
-
-#include <selinux/selinux.h>
-#include <selinux/avc.h>
-
-#include "globals.h"
-#include "dixaccess.h"
-#include "dixstruct.h"
-#include "privates.h"
-#include "resource.h"
-#include "registry.h"
-#include "inputstr.h"
-#include "xselinux.h"
-
-/*
- * Types
- */
-
-#define COMMAND_LEN 64
-
-/* subject state (clients and devices only) */
-typedef struct {
- security_id_t sid;
- security_id_t dev_create_sid;
- security_id_t win_create_sid;
- security_id_t sel_create_sid;
- security_id_t prp_create_sid;
- security_id_t sel_use_sid;
- security_id_t prp_use_sid;
- struct avc_entry_ref aeref;
- char command[COMMAND_LEN];
- int privileged;
-} SELinuxSubjectRec;
-
-/* object state */
-typedef struct {
- security_id_t sid;
- int poly;
-} SELinuxObjectRec;
-
-/*
- * Globals
- */
-
-extern DevPrivateKeyRec subjectKeyRec;
-#define subjectKey (&subjectKeyRec)
-extern DevPrivateKeyRec objectKeyRec;
-#define objectKey (&objectKeyRec)
-extern DevPrivateKeyRec dataKeyRec;
-#define dataKey (&dataKeyRec)
-
-/*
- * Label functions
- */
-
-int
-SELinuxAtomToSID(Atom atom, int prop, SELinuxObjectRec **obj_rtn);
-
-int
-SELinuxSelectionToSID(Atom selection, SELinuxSubjectRec *subj,
- security_id_t *sid_rtn, int *poly_rtn);
-
-int
-SELinuxPropertyToSID(Atom property, SELinuxSubjectRec *subj,
- security_id_t *sid_rtn, int *poly_rtn);
-
-int
-SELinuxEventToSID(unsigned type, security_id_t sid_of_window,
- SELinuxObjectRec *sid_return);
-
-int
-SELinuxExtensionToSID(const char *name, security_id_t *sid_rtn);
-
-security_class_t
-SELinuxTypeToClass(RESTYPE type);
-
-security_context_t
-SELinuxDefaultClientLabel(void);
-
-void
-SELinuxLabelInit(void);
-
-void
-SELinuxLabelReset(void);
-
-/*
- * Security module functions
- */
-
-void
-SELinuxFlaskInit(void);
-
-void
-SELinuxFlaskReset(void);
-
-
-/*
- * Private Flask definitions
- */
-
-/* Security class constants */
-#define SECCLASS_X_DRAWABLE 1
-#define SECCLASS_X_SCREEN 2
-#define SECCLASS_X_GC 3
-#define SECCLASS_X_FONT 4
-#define SECCLASS_X_COLORMAP 5
-#define SECCLASS_X_PROPERTY 6
-#define SECCLASS_X_SELECTION 7
-#define SECCLASS_X_CURSOR 8
-#define SECCLASS_X_CLIENT 9
-#define SECCLASS_X_POINTER 10
-#define SECCLASS_X_KEYBOARD 11
-#define SECCLASS_X_SERVER 12
-#define SECCLASS_X_EXTENSION 13
-#define SECCLASS_X_EVENT 14
-#define SECCLASS_X_FAKEEVENT 15
-#define SECCLASS_X_RESOURCE 16
-
-#ifdef _XSELINUX_NEED_FLASK_MAP
-/* Mapping from DixAccess bits to Flask permissions */
-static struct security_class_mapping map[] = {
- { "x_drawable",
- { "read", /* DixReadAccess */
- "write", /* DixWriteAccess */
- "destroy", /* DixDestroyAccess */
- "create", /* DixCreateAccess */
- "getattr", /* DixGetAttrAccess */
- "setattr", /* DixSetAttrAccess */
- "list_property", /* DixListPropAccess */
- "get_property", /* DixGetPropAccess */
- "set_property", /* DixSetPropAccess */
- "", /* DixGetFocusAccess */
- "", /* DixSetFocusAccess */
- "list_child", /* DixListAccess */
- "add_child", /* DixAddAccess */
- "remove_child", /* DixRemoveAccess */
- "hide", /* DixHideAccess */
- "show", /* DixShowAccess */
- "blend", /* DixBlendAccess */
- "override", /* DixGrabAccess */
- "", /* DixFreezeAccess */
- "", /* DixForceAccess */
- "", /* DixInstallAccess */
- "", /* DixUninstallAccess */
- "send", /* DixSendAccess */
- "receive", /* DixReceiveAccess */
- "", /* DixUseAccess */
- "manage", /* DixManageAccess */
- NULL }},
- { "x_screen",
- { "", /* DixReadAccess */
- "", /* DixWriteAccess */
- "", /* DixDestroyAccess */
- "", /* DixCreateAccess */
- "getattr", /* DixGetAttrAccess */
- "setattr", /* DixSetAttrAccess */
- "saver_getattr", /* DixListPropAccess */
- "saver_setattr", /* DixGetPropAccess */
- "", /* DixSetPropAccess */
- "", /* DixGetFocusAccess */
- "", /* DixSetFocusAccess */
- "", /* DixListAccess */
- "", /* DixAddAccess */
- "", /* DixRemoveAccess */
- "hide_cursor", /* DixHideAccess */
- "show_cursor", /* DixShowAccess */
- "saver_hide", /* DixBlendAccess */
- "saver_show", /* DixGrabAccess */
- NULL }},
- { "x_gc",
- { "", /* DixReadAccess */
- "", /* DixWriteAccess */
- "destroy", /* DixDestroyAccess */
- "create", /* DixCreateAccess */
- "getattr", /* DixGetAttrAccess */
- "setattr", /* DixSetAttrAccess */
- "", /* DixListPropAccess */
- "", /* DixGetPropAccess */
- "", /* DixSetPropAccess */
- "", /* DixGetFocusAccess */
- "", /* DixSetFocusAccess */
- "", /* DixListAccess */
- "", /* DixAddAccess */
- "", /* DixRemoveAccess */
- "", /* DixHideAccess */
- "", /* DixShowAccess */
- "", /* DixBlendAccess */
- "", /* DixGrabAccess */
- "", /* DixFreezeAccess */
- "", /* DixForceAccess */
- "", /* DixInstallAccess */
- "", /* DixUninstallAccess */
- "", /* DixSendAccess */
- "", /* DixReceiveAccess */
- "use", /* DixUseAccess */
- NULL }},
- { "x_font",
- { "", /* DixReadAccess */
- "", /* DixWriteAccess */
- "destroy", /* DixDestroyAccess */
- "create", /* DixCreateAccess */
- "getattr", /* DixGetAttrAccess */
- "", /* DixSetAttrAccess */
- "", /* DixListPropAccess */
- "", /* DixGetPropAccess */
- "", /* DixSetPropAccess */
- "", /* DixGetFocusAccess */
- "", /* DixSetFocusAccess */
- "", /* DixListAccess */
- "add_glyph", /* DixAddAccess */
- "remove_glyph", /* DixRemoveAccess */
- "", /* DixHideAccess */
- "", /* DixShowAccess */
- "", /* DixBlendAccess */
- "", /* DixGrabAccess */
- "", /* DixFreezeAccess */
- "", /* DixForceAccess */
- "", /* DixInstallAccess */
- "", /* DixUninstallAccess */
- "", /* DixSendAccess */
- "", /* DixReceiveAccess */
- "use", /* DixUseAccess */
- NULL }},
- { "x_colormap",
- { "read", /* DixReadAccess */
- "write", /* DixWriteAccess */
- "destroy", /* DixDestroyAccess */
- "create", /* DixCreateAccess */
- "getattr", /* DixGetAttrAccess */
- "", /* DixSetAttrAccess */
- "", /* DixListPropAccess */
- "", /* DixGetPropAccess */
- "", /* DixSetPropAccess */
- "", /* DixGetFocusAccess */
- "", /* DixSetFocusAccess */
- "", /* DixListAccess */
- "add_color", /* DixAddAccess */
- "remove_color", /* DixRemoveAccess */
- "", /* DixHideAccess */
- "", /* DixShowAccess */
- "", /* DixBlendAccess */
- "", /* DixGrabAccess */
- "", /* DixFreezeAccess */
- "", /* DixForceAccess */
- "install", /* DixInstallAccess */
- "uninstall", /* DixUninstallAccess */
- "", /* DixSendAccess */
- "", /* DixReceiveAccess */
- "use", /* DixUseAccess */
- NULL }},
- { "x_property",
- { "read", /* DixReadAccess */
- "write", /* DixWriteAccess */
- "destroy", /* DixDestroyAccess */
- "create", /* DixCreateAccess */
- "getattr", /* DixGetAttrAccess */
- "setattr", /* DixSetAttrAccess */
- "", /* DixListPropAccess */
- "", /* DixGetPropAccess */
- "", /* DixSetPropAccess */
- "", /* DixGetFocusAccess */
- "", /* DixSetFocusAccess */
- "", /* DixListAccess */
- "", /* DixAddAccess */
- "", /* DixRemoveAccess */
- "", /* DixHideAccess */
- "", /* DixShowAccess */
- "write", /* DixBlendAccess */
- NULL }},
- { "x_selection",
- { "read", /* DixReadAccess */
- "", /* DixWriteAccess */
- "", /* DixDestroyAccess */
- "setattr", /* DixCreateAccess */
- "getattr", /* DixGetAttrAccess */
- "setattr", /* DixSetAttrAccess */
- NULL }},
- { "x_cursor",
- { "read", /* DixReadAccess */
- "write", /* DixWriteAccess */
- "destroy", /* DixDestroyAccess */
- "create", /* DixCreateAccess */
- "getattr", /* DixGetAttrAccess */
- "setattr", /* DixSetAttrAccess */
- "", /* DixListPropAccess */
- "", /* DixGetPropAccess */
- "", /* DixSetPropAccess */
- "", /* DixGetFocusAccess */
- "", /* DixSetFocusAccess */
- "", /* DixListAccess */
- "", /* DixAddAccess */
- "", /* DixRemoveAccess */
- "", /* DixHideAccess */
- "", /* DixShowAccess */
- "", /* DixBlendAccess */
- "", /* DixGrabAccess */
- "", /* DixFreezeAccess */
- "", /* DixForceAccess */
- "", /* DixInstallAccess */
- "", /* DixUninstallAccess */
- "", /* DixSendAccess */
- "", /* DixReceiveAccess */
- "use", /* DixUseAccess */
- NULL }},
- { "x_client",
- { "", /* DixReadAccess */
- "", /* DixWriteAccess */
- "destroy", /* DixDestroyAccess */
- "", /* DixCreateAccess */
- "getattr", /* DixGetAttrAccess */
- "setattr", /* DixSetAttrAccess */
- "", /* DixListPropAccess */
- "", /* DixGetPropAccess */
- "", /* DixSetPropAccess */
- "", /* DixGetFocusAccess */
- "", /* DixSetFocusAccess */
- "", /* DixListAccess */
- "", /* DixAddAccess */
- "", /* DixRemoveAccess */
- "", /* DixHideAccess */
- "", /* DixShowAccess */
- "", /* DixBlendAccess */
- "", /* DixGrabAccess */
- "", /* DixFreezeAccess */
- "", /* DixForceAccess */
- "", /* DixInstallAccess */
- "", /* DixUninstallAccess */
- "", /* DixSendAccess */
- "", /* DixReceiveAccess */
- "", /* DixUseAccess */
- "manage", /* DixManageAccess */
- NULL }},
- { "x_pointer",
- { "read", /* DixReadAccess */
- "write", /* DixWriteAccess */
- "destroy", /* DixDestroyAccess */
- "create", /* DixCreateAccess */
- "getattr", /* DixGetAttrAccess */
- "setattr", /* DixSetAttrAccess */
- "list_property", /* DixListPropAccess */
- "get_property", /* DixGetPropAccess */
- "set_property", /* DixSetPropAccess */
- "getfocus", /* DixGetFocusAccess */
- "setfocus", /* DixSetFocusAccess */
- "", /* DixListAccess */
- "add", /* DixAddAccess */
- "remove", /* DixRemoveAccess */
- "", /* DixHideAccess */
- "", /* DixShowAccess */
- "", /* DixBlendAccess */
- "grab", /* DixGrabAccess */
- "freeze", /* DixFreezeAccess */
- "force_cursor", /* DixForceAccess */
- "", /* DixInstallAccess */
- "", /* DixUninstallAccess */
- "", /* DixSendAccess */
- "", /* DixReceiveAccess */
- "use", /* DixUseAccess */
- "manage", /* DixManageAccess */
- "", /* DixDebugAccess */
- "bell", /* DixBellAccess */
- NULL }},
- { "x_keyboard",
- { "read", /* DixReadAccess */
- "write", /* DixWriteAccess */
- "destroy", /* DixDestroyAccess */
- "create", /* DixCreateAccess */
- "getattr", /* DixGetAttrAccess */
- "setattr", /* DixSetAttrAccess */
- "list_property", /* DixListPropAccess */
- "get_property", /* DixGetPropAccess */
- "set_property", /* DixSetPropAccess */
- "getfocus", /* DixGetFocusAccess */
- "setfocus", /* DixSetFocusAccess */
- "", /* DixListAccess */
- "add", /* DixAddAccess */
- "remove", /* DixRemoveAccess */
- "", /* DixHideAccess */
- "", /* DixShowAccess */
- "", /* DixBlendAccess */
- "grab", /* DixGrabAccess */
- "freeze", /* DixFreezeAccess */
- "force_cursor", /* DixForceAccess */
- "", /* DixInstallAccess */
- "", /* DixUninstallAccess */
- "", /* DixSendAccess */
- "", /* DixReceiveAccess */
- "use", /* DixUseAccess */
- "manage", /* DixManageAccess */
- "", /* DixDebugAccess */
- "bell", /* DixBellAccess */
- NULL }},
- { "x_server",
- { "record", /* DixReadAccess */
- "", /* DixWriteAccess */
- "", /* DixDestroyAccess */
- "", /* DixCreateAccess */
- "getattr", /* DixGetAttrAccess */
- "setattr", /* DixSetAttrAccess */
- "", /* DixListPropAccess */
- "", /* DixGetPropAccess */
- "", /* DixSetPropAccess */
- "", /* DixGetFocusAccess */
- "", /* DixSetFocusAccess */
- "", /* DixListAccess */
- "", /* DixAddAccess */
- "", /* DixRemoveAccess */
- "", /* DixHideAccess */
- "", /* DixShowAccess */
- "", /* DixBlendAccess */
- "grab", /* DixGrabAccess */
- "", /* DixFreezeAccess */
- "", /* DixForceAccess */
- "", /* DixInstallAccess */
- "", /* DixUninstallAccess */
- "", /* DixSendAccess */
- "", /* DixReceiveAccess */
- "", /* DixUseAccess */
- "manage", /* DixManageAccess */
- "debug", /* DixDebugAccess */
- NULL }},
- { "x_extension",
- { "", /* DixReadAccess */
- "", /* DixWriteAccess */
- "", /* DixDestroyAccess */
- "", /* DixCreateAccess */
- "query", /* DixGetAttrAccess */
- "", /* DixSetAttrAccess */
- "", /* DixListPropAccess */
- "", /* DixGetPropAccess */
- "", /* DixSetPropAccess */
- "", /* DixGetFocusAccess */
- "", /* DixSetFocusAccess */
- "", /* DixListAccess */
- "", /* DixAddAccess */
- "", /* DixRemoveAccess */
- "", /* DixHideAccess */
- "", /* DixShowAccess */
- "", /* DixBlendAccess */
- "", /* DixGrabAccess */
- "", /* DixFreezeAccess */
- "", /* DixForceAccess */
- "", /* DixInstallAccess */
- "", /* DixUninstallAccess */
- "", /* DixSendAccess */
- "", /* DixReceiveAccess */
- "use", /* DixUseAccess */
- NULL }},
- { "x_event",
- { "", /* DixReadAccess */
- "", /* DixWriteAccess */
- "", /* DixDestroyAccess */
- "", /* DixCreateAccess */
- "", /* DixGetAttrAccess */
- "", /* DixSetAttrAccess */
- "", /* DixListPropAccess */
- "", /* DixGetPropAccess */
- "", /* DixSetPropAccess */
- "", /* DixGetFocusAccess */
- "", /* DixSetFocusAccess */
- "", /* DixListAccess */
- "", /* DixAddAccess */
- "", /* DixRemoveAccess */
- "", /* DixHideAccess */
- "", /* DixShowAccess */
- "", /* DixBlendAccess */
- "", /* DixGrabAccess */
- "", /* DixFreezeAccess */
- "", /* DixForceAccess */
- "", /* DixInstallAccess */
- "", /* DixUninstallAccess */
- "send", /* DixSendAccess */
- "receive", /* DixReceiveAccess */
- NULL }},
- { "x_synthetic_event",
- { "", /* DixReadAccess */
- "", /* DixWriteAccess */
- "", /* DixDestroyAccess */
- "", /* DixCreateAccess */
- "", /* DixGetAttrAccess */
- "", /* DixSetAttrAccess */
- "", /* DixListPropAccess */
- "", /* DixGetPropAccess */
- "", /* DixSetPropAccess */
- "", /* DixGetFocusAccess */
- "", /* DixSetFocusAccess */
- "", /* DixListAccess */
- "", /* DixAddAccess */
- "", /* DixRemoveAccess */
- "", /* DixHideAccess */
- "", /* DixShowAccess */
- "", /* DixBlendAccess */
- "", /* DixGrabAccess */
- "", /* DixFreezeAccess */
- "", /* DixForceAccess */
- "", /* DixInstallAccess */
- "", /* DixUninstallAccess */
- "send", /* DixSendAccess */
- "receive", /* DixReceiveAccess */
- NULL }},
- { "x_resource",
- { "read", /* DixReadAccess */
- "write", /* DixWriteAccess */
- "write", /* DixDestroyAccess */
- "write", /* DixCreateAccess */
- "read", /* DixGetAttrAccess */
- "write", /* DixSetAttrAccess */
- "read", /* DixListPropAccess */
- "read", /* DixGetPropAccess */
- "write", /* DixSetPropAccess */
- "read", /* DixGetFocusAccess */
- "write", /* DixSetFocusAccess */
- "read", /* DixListAccess */
- "write", /* DixAddAccess */
- "write", /* DixRemoveAccess */
- "write", /* DixHideAccess */
- "read", /* DixShowAccess */
- "read", /* DixBlendAccess */
- "write", /* DixGrabAccess */
- "write", /* DixFreezeAccess */
- "write", /* DixForceAccess */
- "write", /* DixInstallAccess */
- "write", /* DixUninstallAccess */
- "write", /* DixSendAccess */
- "read", /* DixReceiveAccess */
- "read", /* DixUseAccess */
- "write", /* DixManageAccess */
- "read", /* DixDebugAccess */
- "write", /* DixBellAccess */
- NULL }},
- { NULL }
-};
-
-/* x_resource "read" bits from the list above */
-#define SELinuxReadMask (DixReadAccess|DixGetAttrAccess|DixListPropAccess| \
- DixGetPropAccess|DixGetFocusAccess|DixListAccess| \
- DixShowAccess|DixBlendAccess|DixReceiveAccess| \
- DixUseAccess|DixDebugAccess)
-
-#endif /* _XSELINUX_NEED_FLASK_MAP */
-#endif /* _XSELINUXINT_H */
+/************************************************************ + +Author: Eamon Walsh <ewalsh@tycho.nsa.gov> + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +this permission notice appear in supporting documentation. This permission +notice shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +********************************************************/ + +#ifndef _XSELINUXINT_H +#define _XSELINUXINT_H + +#include <selinux/selinux.h> +#include <selinux/avc.h> + +#include "globals.h" +#include "dixaccess.h" +#include "dixstruct.h" +#include "privates.h" +#include "resource.h" +#include "registry.h" +#include "inputstr.h" +#include "xselinux.h" + +/* + * Types + */ + +#define COMMAND_LEN 64 + +/* subject state (clients and devices only) */ +typedef struct { + security_id_t sid; + security_id_t dev_create_sid; + security_id_t win_create_sid; + security_id_t sel_create_sid; + security_id_t prp_create_sid; + security_id_t sel_use_sid; + security_id_t prp_use_sid; + struct avc_entry_ref aeref; + char command[COMMAND_LEN]; + int privileged; +} SELinuxSubjectRec; + +/* object state */ +typedef struct { + security_id_t sid; + int poly; +} SELinuxObjectRec; + +/* + * Globals + */ + +extern DevPrivateKeyRec subjectKeyRec; + +#define subjectKey (&subjectKeyRec) +extern DevPrivateKeyRec objectKeyRec; + +#define objectKey (&objectKeyRec) +extern DevPrivateKeyRec dataKeyRec; + +#define dataKey (&dataKeyRec) + +/* + * Label functions + */ + +int + SELinuxAtomToSID(Atom atom, int prop, SELinuxObjectRec ** obj_rtn); + +int + +SELinuxSelectionToSID(Atom selection, SELinuxSubjectRec * subj, + security_id_t * sid_rtn, int *poly_rtn); + +int + +SELinuxPropertyToSID(Atom property, SELinuxSubjectRec * subj, + security_id_t * sid_rtn, int *poly_rtn); + +int + +SELinuxEventToSID(unsigned type, security_id_t sid_of_window, + SELinuxObjectRec * sid_return); + +int + SELinuxExtensionToSID(const char *name, security_id_t * sid_rtn); + +security_class_t SELinuxTypeToClass(RESTYPE type); + +security_context_t SELinuxDefaultClientLabel(void); + +void + SELinuxLabelInit(void); + +void + SELinuxLabelReset(void); + +/* + * Security module functions + */ + +void + SELinuxFlaskInit(void); + +void + SELinuxFlaskReset(void); + +/* + * Private Flask definitions + */ + +/* Security class constants */ +#define SECCLASS_X_DRAWABLE 1 +#define SECCLASS_X_SCREEN 2 +#define SECCLASS_X_GC 3 +#define SECCLASS_X_FONT 4 +#define SECCLASS_X_COLORMAP 5 +#define SECCLASS_X_PROPERTY 6 +#define SECCLASS_X_SELECTION 7 +#define SECCLASS_X_CURSOR 8 +#define SECCLASS_X_CLIENT 9 +#define SECCLASS_X_POINTER 10 +#define SECCLASS_X_KEYBOARD 11 +#define SECCLASS_X_SERVER 12 +#define SECCLASS_X_EXTENSION 13 +#define SECCLASS_X_EVENT 14 +#define SECCLASS_X_FAKEEVENT 15 +#define SECCLASS_X_RESOURCE 16 + +#ifdef _XSELINUX_NEED_FLASK_MAP +/* Mapping from DixAccess bits to Flask permissions */ +static struct security_class_mapping map[] = { + {"x_drawable", + {"read", /* DixReadAccess */ + "write", /* DixWriteAccess */ + "destroy", /* DixDestroyAccess */ + "create", /* DixCreateAccess */ + "getattr", /* DixGetAttrAccess */ + "setattr", /* DixSetAttrAccess */ + "list_property", /* DixListPropAccess */ + "get_property", /* DixGetPropAccess */ + "set_property", /* DixSetPropAccess */ + "", /* DixGetFocusAccess */ + "", /* DixSetFocusAccess */ + "list_child", /* DixListAccess */ + "add_child", /* DixAddAccess */ + "remove_child", /* DixRemoveAccess */ + "hide", /* DixHideAccess */ + "show", /* DixShowAccess */ + "blend", /* DixBlendAccess */ + "override", /* DixGrabAccess */ + "", /* DixFreezeAccess */ + "", /* DixForceAccess */ + "", /* DixInstallAccess */ + "", /* DixUninstallAccess */ + "send", /* DixSendAccess */ + "receive", /* DixReceiveAccess */ + "", /* DixUseAccess */ + "manage", /* DixManageAccess */ + NULL}}, + {"x_screen", + {"", /* DixReadAccess */ + "", /* DixWriteAccess */ + "", /* DixDestroyAccess */ + "", /* DixCreateAccess */ + "getattr", /* DixGetAttrAccess */ + "setattr", /* DixSetAttrAccess */ + "saver_getattr", /* DixListPropAccess */ + "saver_setattr", /* DixGetPropAccess */ + "", /* DixSetPropAccess */ + "", /* DixGetFocusAccess */ + "", /* DixSetFocusAccess */ + "", /* DixListAccess */ + "", /* DixAddAccess */ + "", /* DixRemoveAccess */ + "hide_cursor", /* DixHideAccess */ + "show_cursor", /* DixShowAccess */ + "saver_hide", /* DixBlendAccess */ + "saver_show", /* DixGrabAccess */ + NULL}}, + {"x_gc", + {"", /* DixReadAccess */ + "", /* DixWriteAccess */ + "destroy", /* DixDestroyAccess */ + "create", /* DixCreateAccess */ + "getattr", /* DixGetAttrAccess */ + "setattr", /* DixSetAttrAccess */ + "", /* DixListPropAccess */ + "", /* DixGetPropAccess */ + "", /* DixSetPropAccess */ + "", /* DixGetFocusAccess */ + "", /* DixSetFocusAccess */ + "", /* DixListAccess */ + "", /* DixAddAccess */ + "", /* DixRemoveAccess */ + "", /* DixHideAccess */ + "", /* DixShowAccess */ + "", /* DixBlendAccess */ + "", /* DixGrabAccess */ + "", /* DixFreezeAccess */ + "", /* DixForceAccess */ + "", /* DixInstallAccess */ + "", /* DixUninstallAccess */ + "", /* DixSendAccess */ + "", /* DixReceiveAccess */ + "use", /* DixUseAccess */ + NULL}}, + {"x_font", + {"", /* DixReadAccess */ + "", /* DixWriteAccess */ + "destroy", /* DixDestroyAccess */ + "create", /* DixCreateAccess */ + "getattr", /* DixGetAttrAccess */ + "", /* DixSetAttrAccess */ + "", /* DixListPropAccess */ + "", /* DixGetPropAccess */ + "", /* DixSetPropAccess */ + "", /* DixGetFocusAccess */ + "", /* DixSetFocusAccess */ + "", /* DixListAccess */ + "add_glyph", /* DixAddAccess */ + "remove_glyph", /* DixRemoveAccess */ + "", /* DixHideAccess */ + "", /* DixShowAccess */ + "", /* DixBlendAccess */ + "", /* DixGrabAccess */ + "", /* DixFreezeAccess */ + "", /* DixForceAccess */ + "", /* DixInstallAccess */ + "", /* DixUninstallAccess */ + "", /* DixSendAccess */ + "", /* DixReceiveAccess */ + "use", /* DixUseAccess */ + NULL}}, + {"x_colormap", + {"read", /* DixReadAccess */ + "write", /* DixWriteAccess */ + "destroy", /* DixDestroyAccess */ + "create", /* DixCreateAccess */ + "getattr", /* DixGetAttrAccess */ + "", /* DixSetAttrAccess */ + "", /* DixListPropAccess */ + "", /* DixGetPropAccess */ + "", /* DixSetPropAccess */ + "", /* DixGetFocusAccess */ + "", /* DixSetFocusAccess */ + "", /* DixListAccess */ + "add_color", /* DixAddAccess */ + "remove_color", /* DixRemoveAccess */ + "", /* DixHideAccess */ + "", /* DixShowAccess */ + "", /* DixBlendAccess */ + "", /* DixGrabAccess */ + "", /* DixFreezeAccess */ + "", /* DixForceAccess */ + "install", /* DixInstallAccess */ + "uninstall", /* DixUninstallAccess */ + "", /* DixSendAccess */ + "", /* DixReceiveAccess */ + "use", /* DixUseAccess */ + NULL}}, + {"x_property", + {"read", /* DixReadAccess */ + "write", /* DixWriteAccess */ + "destroy", /* DixDestroyAccess */ + "create", /* DixCreateAccess */ + "getattr", /* DixGetAttrAccess */ + "setattr", /* DixSetAttrAccess */ + "", /* DixListPropAccess */ + "", /* DixGetPropAccess */ + "", /* DixSetPropAccess */ + "", /* DixGetFocusAccess */ + "", /* DixSetFocusAccess */ + "", /* DixListAccess */ + "", /* DixAddAccess */ + "", /* DixRemoveAccess */ + "", /* DixHideAccess */ + "", /* DixShowAccess */ + "write", /* DixBlendAccess */ + NULL}}, + {"x_selection", + {"read", /* DixReadAccess */ + "", /* DixWriteAccess */ + "", /* DixDestroyAccess */ + "setattr", /* DixCreateAccess */ + "getattr", /* DixGetAttrAccess */ + "setattr", /* DixSetAttrAccess */ + NULL}}, + {"x_cursor", + {"read", /* DixReadAccess */ + "write", /* DixWriteAccess */ + "destroy", /* DixDestroyAccess */ + "create", /* DixCreateAccess */ + "getattr", /* DixGetAttrAccess */ + "setattr", /* DixSetAttrAccess */ + "", /* DixListPropAccess */ + "", /* DixGetPropAccess */ + "", /* DixSetPropAccess */ + "", /* DixGetFocusAccess */ + "", /* DixSetFocusAccess */ + "", /* DixListAccess */ + "", /* DixAddAccess */ + "", /* DixRemoveAccess */ + "", /* DixHideAccess */ + "", /* DixShowAccess */ + "", /* DixBlendAccess */ + "", /* DixGrabAccess */ + "", /* DixFreezeAccess */ + "", /* DixForceAccess */ + "", /* DixInstallAccess */ + "", /* DixUninstallAccess */ + "", /* DixSendAccess */ + "", /* DixReceiveAccess */ + "use", /* DixUseAccess */ + NULL}}, + {"x_client", + {"", /* DixReadAccess */ + "", /* DixWriteAccess */ + "destroy", /* DixDestroyAccess */ + "", /* DixCreateAccess */ + "getattr", /* DixGetAttrAccess */ + "setattr", /* DixSetAttrAccess */ + "", /* DixListPropAccess */ + "", /* DixGetPropAccess */ + "", /* DixSetPropAccess */ + "", /* DixGetFocusAccess */ + "", /* DixSetFocusAccess */ + "", /* DixListAccess */ + "", /* DixAddAccess */ + "", /* DixRemoveAccess */ + "", /* DixHideAccess */ + "", /* DixShowAccess */ + "", /* DixBlendAccess */ + "", /* DixGrabAccess */ + "", /* DixFreezeAccess */ + "", /* DixForceAccess */ + "", /* DixInstallAccess */ + "", /* DixUninstallAccess */ + "", /* DixSendAccess */ + "", /* DixReceiveAccess */ + "", /* DixUseAccess */ + "manage", /* DixManageAccess */ + NULL}}, + {"x_pointer", + {"read", /* DixReadAccess */ + "write", /* DixWriteAccess */ + "destroy", /* DixDestroyAccess */ + "create", /* DixCreateAccess */ + "getattr", /* DixGetAttrAccess */ + "setattr", /* DixSetAttrAccess */ + "list_property", /* DixListPropAccess */ + "get_property", /* DixGetPropAccess */ + "set_property", /* DixSetPropAccess */ + "getfocus", /* DixGetFocusAccess */ + "setfocus", /* DixSetFocusAccess */ + "", /* DixListAccess */ + "add", /* DixAddAccess */ + "remove", /* DixRemoveAccess */ + "", /* DixHideAccess */ + "", /* DixShowAccess */ + "", /* DixBlendAccess */ + "grab", /* DixGrabAccess */ + "freeze", /* DixFreezeAccess */ + "force_cursor", /* DixForceAccess */ + "", /* DixInstallAccess */ + "", /* DixUninstallAccess */ + "", /* DixSendAccess */ + "", /* DixReceiveAccess */ + "use", /* DixUseAccess */ + "manage", /* DixManageAccess */ + "", /* DixDebugAccess */ + "bell", /* DixBellAccess */ + NULL}}, + {"x_keyboard", + {"read", /* DixReadAccess */ + "write", /* DixWriteAccess */ + "destroy", /* DixDestroyAccess */ + "create", /* DixCreateAccess */ + "getattr", /* DixGetAttrAccess */ + "setattr", /* DixSetAttrAccess */ + "list_property", /* DixListPropAccess */ + "get_property", /* DixGetPropAccess */ + "set_property", /* DixSetPropAccess */ + "getfocus", /* DixGetFocusAccess */ + "setfocus", /* DixSetFocusAccess */ + "", /* DixListAccess */ + "add", /* DixAddAccess */ + "remove", /* DixRemoveAccess */ + "", /* DixHideAccess */ + "", /* DixShowAccess */ + "", /* DixBlendAccess */ + "grab", /* DixGrabAccess */ + "freeze", /* DixFreezeAccess */ + "force_cursor", /* DixForceAccess */ + "", /* DixInstallAccess */ + "", /* DixUninstallAccess */ + "", /* DixSendAccess */ + "", /* DixReceiveAccess */ + "use", /* DixUseAccess */ + "manage", /* DixManageAccess */ + "", /* DixDebugAccess */ + "bell", /* DixBellAccess */ + NULL}}, + {"x_server", + {"record", /* DixReadAccess */ + "", /* DixWriteAccess */ + "", /* DixDestroyAccess */ + "", /* DixCreateAccess */ + "getattr", /* DixGetAttrAccess */ + "setattr", /* DixSetAttrAccess */ + "", /* DixListPropAccess */ + "", /* DixGetPropAccess */ + "", /* DixSetPropAccess */ + "", /* DixGetFocusAccess */ + "", /* DixSetFocusAccess */ + "", /* DixListAccess */ + "", /* DixAddAccess */ + "", /* DixRemoveAccess */ + "", /* DixHideAccess */ + "", /* DixShowAccess */ + "", /* DixBlendAccess */ + "grab", /* DixGrabAccess */ + "", /* DixFreezeAccess */ + "", /* DixForceAccess */ + "", /* DixInstallAccess */ + "", /* DixUninstallAccess */ + "", /* DixSendAccess */ + "", /* DixReceiveAccess */ + "", /* DixUseAccess */ + "manage", /* DixManageAccess */ + "debug", /* DixDebugAccess */ + NULL}}, + {"x_extension", + {"", /* DixReadAccess */ + "", /* DixWriteAccess */ + "", /* DixDestroyAccess */ + "", /* DixCreateAccess */ + "query", /* DixGetAttrAccess */ + "", /* DixSetAttrAccess */ + "", /* DixListPropAccess */ + "", /* DixGetPropAccess */ + "", /* DixSetPropAccess */ + "", /* DixGetFocusAccess */ + "", /* DixSetFocusAccess */ + "", /* DixListAccess */ + "", /* DixAddAccess */ + "", /* DixRemoveAccess */ + "", /* DixHideAccess */ + "", /* DixShowAccess */ + "", /* DixBlendAccess */ + "", /* DixGrabAccess */ + "", /* DixFreezeAccess */ + "", /* DixForceAccess */ + "", /* DixInstallAccess */ + "", /* DixUninstallAccess */ + "", /* DixSendAccess */ + "", /* DixReceiveAccess */ + "use", /* DixUseAccess */ + NULL}}, + {"x_event", + {"", /* DixReadAccess */ + "", /* DixWriteAccess */ + "", /* DixDestroyAccess */ + "", /* DixCreateAccess */ + "", /* DixGetAttrAccess */ + "", /* DixSetAttrAccess */ + "", /* DixListPropAccess */ + "", /* DixGetPropAccess */ + "", /* DixSetPropAccess */ + "", /* DixGetFocusAccess */ + "", /* DixSetFocusAccess */ + "", /* DixListAccess */ + "", /* DixAddAccess */ + "", /* DixRemoveAccess */ + "", /* DixHideAccess */ + "", /* DixShowAccess */ + "", /* DixBlendAccess */ + "", /* DixGrabAccess */ + "", /* DixFreezeAccess */ + "", /* DixForceAccess */ + "", /* DixInstallAccess */ + "", /* DixUninstallAccess */ + "send", /* DixSendAccess */ + "receive", /* DixReceiveAccess */ + NULL}}, + {"x_synthetic_event", + {"", /* DixReadAccess */ + "", /* DixWriteAccess */ + "", /* DixDestroyAccess */ + "", /* DixCreateAccess */ + "", /* DixGetAttrAccess */ + "", /* DixSetAttrAccess */ + "", /* DixListPropAccess */ + "", /* DixGetPropAccess */ + "", /* DixSetPropAccess */ + "", /* DixGetFocusAccess */ + "", /* DixSetFocusAccess */ + "", /* DixListAccess */ + "", /* DixAddAccess */ + "", /* DixRemoveAccess */ + "", /* DixHideAccess */ + "", /* DixShowAccess */ + "", /* DixBlendAccess */ + "", /* DixGrabAccess */ + "", /* DixFreezeAccess */ + "", /* DixForceAccess */ + "", /* DixInstallAccess */ + "", /* DixUninstallAccess */ + "send", /* DixSendAccess */ + "receive", /* DixReceiveAccess */ + NULL}}, + {"x_resource", + {"read", /* DixReadAccess */ + "write", /* DixWriteAccess */ + "write", /* DixDestroyAccess */ + "write", /* DixCreateAccess */ + "read", /* DixGetAttrAccess */ + "write", /* DixSetAttrAccess */ + "read", /* DixListPropAccess */ + "read", /* DixGetPropAccess */ + "write", /* DixSetPropAccess */ + "read", /* DixGetFocusAccess */ + "write", /* DixSetFocusAccess */ + "read", /* DixListAccess */ + "write", /* DixAddAccess */ + "write", /* DixRemoveAccess */ + "write", /* DixHideAccess */ + "read", /* DixShowAccess */ + "read", /* DixBlendAccess */ + "write", /* DixGrabAccess */ + "write", /* DixFreezeAccess */ + "write", /* DixForceAccess */ + "write", /* DixInstallAccess */ + "write", /* DixUninstallAccess */ + "write", /* DixSendAccess */ + "read", /* DixReceiveAccess */ + "read", /* DixUseAccess */ + "write", /* DixManageAccess */ + "read", /* DixDebugAccess */ + "write", /* DixBellAccess */ + NULL}}, + {NULL} +}; + +/* x_resource "read" bits from the list above */ +#define SELinuxReadMask (DixReadAccess|DixGetAttrAccess|DixListPropAccess| \ + DixGetPropAccess|DixGetFocusAccess|DixListAccess| \ + DixShowAccess|DixBlendAccess|DixReceiveAccess| \ + DixUseAccess|DixDebugAccess) + +#endif /* _XSELINUX_NEED_FLASK_MAP */ +#endif /* _XSELINUXINT_H */ diff --git a/xorg-server/Xext/xtest.c b/xorg-server/Xext/xtest.c index bd8e1d3a7..e659b4154 100644 --- a/xorg-server/Xext/xtest.c +++ b/xorg-server/Xext/xtest.c @@ -62,7 +62,7 @@ extern int DeviceValuator; /* XTest events are sent during request processing and may be interruped by * a SIGIO. We need a separate event list to avoid events overwriting each * other's memory */ -static InternalEvent* xtest_evlist; +static InternalEvent *xtest_evlist; /** * xtestpointer @@ -81,11 +81,9 @@ DeviceIntPtr xtestpointer, xtestkeyboard; #include "panoramiXsrv.h" #endif -static int XTestSwapFakeInput( - ClientPtr /* client */, - xReq * /* req */ - ); - +static int XTestSwapFakeInput(ClientPtr /* client */ , + xReq * /* req */ + ); static int ProcXTestGetVersion(ClientPtr client) @@ -102,7 +100,7 @@ ProcXTestGetVersion(ClientPtr client) swaps(&rep.sequenceNumber); swaps(&rep.minorVersion); } - WriteToClient(client, sizeof(xXTestGetVersionReply), (char *)&rep); + WriteToClient(client, sizeof(xXTestGetVersionReply), (char *) &rep); return Success; } @@ -120,15 +118,18 @@ ProcXTestCompareCursor(ClientPtr client) rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); if (rc != Success) return rc; + + if (!ptr) + return BadAccess; + if (stuff->cursor == None) pCursor = NullCursor; else if (stuff->cursor == XTestCurrentCursor) pCursor = GetSpriteCursor(ptr); else { - rc = dixLookupResourceByType((pointer *)&pCursor, stuff->cursor, RT_CURSOR, - client, DixReadAccess); - if (rc != Success) - { + rc = dixLookupResourceByType((pointer *) &pCursor, stuff->cursor, + RT_CURSOR, client, DixReadAccess); + if (rc != Success) { client->errorValue = stuff->cursor; return rc; } @@ -140,7 +141,7 @@ ProcXTestCompareCursor(ClientPtr client) if (client->swapped) { swaps(&rep.sequenceNumber); } - WriteToClient(client, sizeof(xXTestCompareCursorReply), (char *)&rep); + WriteToClient(client, sizeof(xXTestCompareCursorReply), (char *) &rep); return Success; } @@ -155,7 +156,7 @@ ProcXTestFakeInput(ClientPtr client) Bool extension = FALSE; deviceValuator *dv = NULL; ValuatorMask mask; - int valuators[MAX_VALUATORS] = {0}; + int valuators[MAX_VALUATORS] = { 0 }; int numValuators = 0; int firstValuator = 0; int nevents = 0; @@ -169,18 +170,16 @@ ProcXTestFakeInput(ClientPtr client) return BadLength; nev /= sizeof(xEvent); UpdateCurrentTime(); - ev = (xEvent *)&((xReq *)stuff)[1]; + ev = (xEvent *) &((xReq *) stuff)[1]; type = ev->u.u.type & 0177; - if (type >= EXTENSION_EVENT_BASE) - { + if (type >= EXTENSION_EVENT_BASE) { extension = TRUE; /* check device */ rc = dixLookupDevice(&dev, stuff->deviceid & 0177, client, - DixWriteAccess); - if (rc != Success) - { + DixWriteAccess); + if (rc != Success) { client->errorValue = stuff->deviceid & 0177; return rc; } @@ -188,144 +187,141 @@ ProcXTestFakeInput(ClientPtr client) /* check type */ type -= DeviceValuator; switch (type) { - case XI_DeviceKeyPress: - case XI_DeviceKeyRelease: - if (!dev->key) - { - client->errorValue = ev->u.u.type; - return BadValue; - } - break; - case XI_DeviceButtonPress: - case XI_DeviceButtonRelease: - if (!dev->button) - { - client->errorValue = ev->u.u.type; - return BadValue; - } - break; - case XI_DeviceMotionNotify: - if (!dev->valuator) - { - client->errorValue = ev->u.u.type; - return BadValue; - } - break; - case XI_ProximityIn: - case XI_ProximityOut: - if (!dev->proximity) - { - client->errorValue = ev->u.u.type; - return BadValue; - } - break; - default: + case XI_DeviceKeyPress: + case XI_DeviceKeyRelease: + if (!dev->key) { client->errorValue = ev->u.u.type; return BadValue; + } + break; + case XI_DeviceButtonPress: + case XI_DeviceButtonRelease: + if (!dev->button) { + client->errorValue = ev->u.u.type; + return BadValue; + } + break; + case XI_DeviceMotionNotify: + if (!dev->valuator) { + client->errorValue = ev->u.u.type; + return BadValue; + } + break; + case XI_ProximityIn: + case XI_ProximityOut: + if (!dev->proximity) { + client->errorValue = ev->u.u.type; + return BadValue; + } + break; + default: + client->errorValue = ev->u.u.type; + return BadValue; } /* check validity */ if (nev == 1 && type == XI_DeviceMotionNotify) - return BadLength; /* DevMotion must be followed by DevValuator */ + return BadLength; /* DevMotion must be followed by DevValuator */ - if (type == XI_DeviceMotionNotify) - { - firstValuator = ((deviceValuator *)(ev+1))->first_valuator; - if (firstValuator > dev->valuator->numAxes) - { + if (type == XI_DeviceMotionNotify) { + firstValuator = ((deviceValuator *) (ev + 1))->first_valuator; + if (firstValuator > dev->valuator->numAxes) { client->errorValue = ev->u.u.type; return BadValue; } if (ev->u.u.detail == xFalse) flags |= POINTER_ABSOLUTE; - } else - { + } + else { firstValuator = 0; flags |= POINTER_ABSOLUTE; } - if (nev > 1 && !dev->valuator) - { + if (nev > 1 && !dev->valuator) { client->errorValue = dv->first_valuator; return BadValue; } - /* check validity of valuator events */ base = firstValuator; - for (n = 1; n < nev; n++) - { - dv = (deviceValuator *)(ev + n); - if (dv->type != DeviceValuator) - { + for (n = 1; n < nev; n++) { + dv = (deviceValuator *) (ev + n); + if (dv->type != DeviceValuator) { client->errorValue = dv->type; return BadValue; } - if (dv->first_valuator != base) - { + if (dv->first_valuator != base) { client->errorValue = dv->first_valuator; return BadValue; } - switch(dv->num_valuators) - { - case 6: valuators[base + 5] = dv->valuator5; - case 5: valuators[base + 4] = dv->valuator4; - case 4: valuators[base + 3] = dv->valuator3; - case 3: valuators[base + 2] = dv->valuator2; - case 2: valuators[base + 1] = dv->valuator1; - case 1: valuators[base] = dv->valuator0; - break; - default: - client->errorValue = dv->num_valuators; - return BadValue; + switch (dv->num_valuators) { + case 6: + valuators[base + 5] = dv->valuator5; + case 5: + valuators[base + 4] = dv->valuator4; + case 4: + valuators[base + 3] = dv->valuator3; + case 3: + valuators[base + 2] = dv->valuator2; + case 2: + valuators[base + 1] = dv->valuator1; + case 1: + valuators[base] = dv->valuator0; + break; + default: + client->errorValue = dv->num_valuators; + return BadValue; } base += dv->num_valuators; numValuators += dv->num_valuators; - if (firstValuator + numValuators > dev->valuator->numAxes) - { + if (firstValuator + numValuators > dev->valuator->numAxes) { client->errorValue = dv->num_valuators; return BadValue; } } type = type - XI_DeviceKeyPress + KeyPress; - } else - { + } + else { if (nev != 1) return BadLength; - switch (type) - { - case KeyPress: - case KeyRelease: - dev = PickKeyboard(client); - break; - case ButtonPress: - case ButtonRelease: - dev = PickPointer(client); - break; - case MotionNotify: - dev = PickPointer(client); - valuators[0] = ev->u.keyButtonPointer.rootX; - valuators[1] = ev->u.keyButtonPointer.rootY; - numValuators = 2; - firstValuator = 0; - if (ev->u.u.detail == xFalse) - flags = POINTER_ABSOLUTE | POINTER_SCREEN; - break; - default: - client->errorValue = ev->u.u.type; - return BadValue; + switch (type) { + case KeyPress: + case KeyRelease: + dev = PickKeyboard(client); + break; + case ButtonPress: + case ButtonRelease: + dev = PickPointer(client); + break; + case MotionNotify: + dev = PickPointer(client); + valuators[0] = ev->u.keyButtonPointer.rootX; + valuators[1] = ev->u.keyButtonPointer.rootY; + numValuators = 2; + firstValuator = 0; + if (ev->u.u.detail == xFalse) + flags = POINTER_ABSOLUTE | POINTER_SCREEN; + break; + default: + client->errorValue = ev->u.u.type; + return BadValue; } + /* Technically the protocol doesn't allow for BadAccess here but + * this can only happen when all MDs are disabled. */ + if (!dev) + return BadAccess; + dev = GetXTestDevice(dev); } + /* If the event has a time set, wait for it to pass */ - if (ev->u.keyButtonPointer.time) - { + if (ev->u.keyButtonPointer.time) { TimeStamp activateTime; CARD32 ms; @@ -339,92 +335,85 @@ ProcXTestFakeInput(ClientPtr client) /* see mbuf.c:QueueDisplayRequest (from the deprecated Multibuffer * extension) for code similar to this */ - if (!ClientSleepUntil(client, &activateTime, NULL, NULL)) - { + if (!ClientSleepUntil(client, &activateTime, NULL, NULL)) { return BadAlloc; } /* swap the request back so we can simply re-execute it */ - if (client->swapped) - { - (void) XTestSwapFakeInput(client, (xReq *)stuff); + if (client->swapped) { + (void) XTestSwapFakeInput(client, (xReq *) stuff); swaps(&stuff->length); } - ResetCurrentRequest (client); + ResetCurrentRequest(client); client->sequence--; return Success; } - switch (type) - { - case KeyPress: - case KeyRelease: - if (!dev->key) - return BadDevice; + switch (type) { + case KeyPress: + case KeyRelease: + if (!dev->key) + return BadDevice; - if (ev->u.u.detail < dev->key->xkbInfo->desc->min_key_code || - ev->u.u.detail > dev->key->xkbInfo->desc->max_key_code) - { - client->errorValue = ev->u.u.detail; - return BadValue; - } + if (ev->u.u.detail < dev->key->xkbInfo->desc->min_key_code || + ev->u.u.detail > dev->key->xkbInfo->desc->max_key_code) { + client->errorValue = ev->u.u.detail; + return BadValue; + } - need_ptr_update = 0; - break; - case MotionNotify: - if (!dev->valuator) - return BadDevice; - - if (!(extension || ev->u.keyButtonPointer.root == None)) - { - rc = dixLookupWindow(&root, ev->u.keyButtonPointer.root, - client, DixGetAttrAccess); - if (rc != Success) - return rc; - if (root->parent) - { - client->errorValue = ev->u.keyButtonPointer.root; - return BadValue; - } - } - if (ev->u.u.detail != xTrue && ev->u.u.detail != xFalse) - { - client->errorValue = ev->u.u.detail; + need_ptr_update = 0; + break; + case MotionNotify: + if (!dev->valuator) + return BadDevice; + + if (!(extension || ev->u.keyButtonPointer.root == None)) { + rc = dixLookupWindow(&root, ev->u.keyButtonPointer.root, + client, DixGetAttrAccess); + if (rc != Success) + return rc; + if (root->parent) { + client->errorValue = ev->u.keyButtonPointer.root; return BadValue; } + } + if (ev->u.u.detail != xTrue && ev->u.u.detail != xFalse) { + client->errorValue = ev->u.u.detail; + return BadValue; + } - /* FIXME: Xinerama! */ + /* FIXME: Xinerama! */ - break; - case ButtonPress: - case ButtonRelease: - if (!dev->button) - return BadDevice; + break; + case ButtonPress: + case ButtonRelease: + if (!dev->button) + return BadDevice; - if (!ev->u.u.detail || ev->u.u.detail > dev->button->numButtons) - { - client->errorValue = ev->u.u.detail; - return BadValue; - } - break; + if (!ev->u.u.detail || ev->u.u.detail > dev->button->numButtons) { + client->errorValue = ev->u.u.detail; + return BadValue; + } + break; } if (screenIsSaved == SCREEN_SAVER_ON) dixSaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset); - switch(type) { - case MotionNotify: - valuator_mask_set_range(&mask, firstValuator, numValuators, valuators); - nevents = GetPointerEvents(xtest_evlist, dev, type, 0, flags, &mask); - break; - case ButtonPress: - case ButtonRelease: - valuator_mask_set_range(&mask, firstValuator, numValuators, valuators); - nevents = GetPointerEvents(xtest_evlist, dev, type, ev->u.u.detail, - flags, &mask); - break; - case KeyPress: - case KeyRelease: - nevents = GetKeyboardEvents(xtest_evlist, dev, type, ev->u.u.detail, NULL); - break; + switch (type) { + case MotionNotify: + valuator_mask_set_range(&mask, firstValuator, numValuators, valuators); + nevents = GetPointerEvents(xtest_evlist, dev, type, 0, flags, &mask); + break; + case ButtonPress: + case ButtonRelease: + valuator_mask_set_range(&mask, firstValuator, numValuators, valuators); + nevents = GetPointerEvents(xtest_evlist, dev, type, ev->u.u.detail, + flags, &mask); + break; + case KeyPress: + case KeyRelease: + nevents = + GetKeyboardEvents(xtest_evlist, dev, type, ev->u.u.detail, NULL); + break; } for (i = 0; i < nevents; i++) @@ -441,8 +430,7 @@ ProcXTestGrabControl(ClientPtr client) REQUEST(xXTestGrabControlReq); REQUEST_SIZE_MATCH(xXTestGrabControlReq); - if ((stuff->impervious != xTrue) && (stuff->impervious != xFalse)) - { + if ((stuff->impervious != xTrue) && (stuff->impervious != xFalse)) { client->errorValue = stuff->impervious; return BadValue; } @@ -454,21 +442,20 @@ ProcXTestGrabControl(ClientPtr client) } static int -ProcXTestDispatch (ClientPtr client) +ProcXTestDispatch(ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { - case X_XTestGetVersion: - return ProcXTestGetVersion(client); - case X_XTestCompareCursor: - return ProcXTestCompareCursor(client); - case X_XTestFakeInput: - return ProcXTestFakeInput(client); - case X_XTestGrabControl: - return ProcXTestGrabControl(client); - default: - return BadRequest; + switch (stuff->data) { + case X_XTestGetVersion: + return ProcXTestGetVersion(client); + case X_XTestCompareCursor: + return ProcXTestCompareCursor(client); + case X_XTestFakeInput: + return ProcXTestFakeInput(client); + case X_XTestGrabControl: + return ProcXTestGrabControl(client); + default: + return BadRequest; } } @@ -496,7 +483,7 @@ SProcXTestCompareCursor(ClientPtr client) } static int -XTestSwapFakeInput(ClientPtr client, xReq *req) +XTestSwapFakeInput(ClientPtr client, xReq * req) { int nev; xEvent *ev; @@ -504,16 +491,15 @@ XTestSwapFakeInput(ClientPtr client, xReq *req) EventSwapPtr proc; nev = ((req->length << 2) - sizeof(xReq)) / sizeof(xEvent); - for (ev = (xEvent *)&req[1]; --nev >= 0; ev++) - { + for (ev = (xEvent *) &req[1]; --nev >= 0; ev++) { /* Swap event */ proc = EventSwapVector[ev->u.u.type & 0177]; /* no swapping proc; invalid event type? */ - if (!proc || proc == NotImplemented) { + if (!proc || proc == NotImplemented) { client->errorValue = ev->u.u.type; return BadValue; } - (*proc)(ev, &sev); + (*proc) (ev, &sev); *ev = sev; } return Success; @@ -522,7 +508,8 @@ XTestSwapFakeInput(ClientPtr client, xReq *req) static int SProcXTestFakeInput(ClientPtr client) { - int n; + int n; + REQUEST(xReq); swaps(&stuff->length); @@ -543,21 +530,20 @@ SProcXTestGrabControl(ClientPtr client) } static int -SProcXTestDispatch (ClientPtr client) +SProcXTestDispatch(ClientPtr client) { REQUEST(xReq); - switch (stuff->data) - { - case X_XTestGetVersion: - return SProcXTestGetVersion(client); - case X_XTestCompareCursor: - return SProcXTestCompareCursor(client); - case X_XTestFakeInput: - return SProcXTestFakeInput(client); - case X_XTestGrabControl: - return SProcXTestGrabControl(client); - default: - return BadRequest; + switch (stuff->data) { + case X_XTestGetVersion: + return SProcXTestGetVersion(client); + case X_XTestCompareCursor: + return SProcXTestCompareCursor(client); + case X_XTestFakeInput: + return SProcXTestFakeInput(client); + case X_XTestGrabControl: + return SProcXTestGrabControl(client); + default: + return BadRequest; } } @@ -565,21 +551,22 @@ SProcXTestDispatch (ClientPtr client) * Allocate an virtual slave device for xtest events, this * is a slave device to inputInfo master devices */ -void InitXTestDevices(void) +void +InitXTestDevices(void) { - if(AllocXTestDevice(serverClient, "Virtual core", - &xtestpointer, &xtestkeyboard, - inputInfo.pointer, inputInfo.keyboard) != Success) - FatalError("Failed to allocate XTest devices"); + if (AllocXTestDevice(serverClient, "Virtual core", + &xtestpointer, &xtestkeyboard, + inputInfo.pointer, inputInfo.keyboard) != Success) + FatalError("Failed to allocate XTest devices"); if (ActivateDevice(xtestpointer, TRUE) != Success || ActivateDevice(xtestkeyboard, TRUE) != Success) FatalError("Failed to activate XTest core devices."); - if (!EnableDevice(xtestpointer, TRUE) || - !EnableDevice(xtestkeyboard, TRUE)) + if (!EnableDevice(xtestpointer, TRUE) || !EnableDevice(xtestkeyboard, TRUE)) FatalError("Failed to enable XTest core devices."); AttachDevice(NULL, xtestpointer, inputInfo.pointer); + AttachDevice(NULL, xtestkeyboard, inputInfo.keyboard); } @@ -588,7 +575,7 @@ void InitXTestDevices(void) */ static int DeviceSetXTestProperty(DeviceIntPtr dev, Atom property, - XIPropertyValuePtr prop, BOOL checkonly) + XIPropertyValuePtr prop, BOOL checkonly) { if (property == XIGetKnownProperty(XI_PROP_XTEST_DEVICE)) return BadAccess; @@ -603,35 +590,42 @@ DeviceSetXTestProperty(DeviceIntPtr dev, Atom property, * This only creates the pair, Activate/Enable Device * still need to be called. */ -int AllocXTestDevice (ClientPtr client, const char* name, - DeviceIntPtr* ptr, DeviceIntPtr* keybd, - DeviceIntPtr master_ptr, DeviceIntPtr master_keybd) +int +AllocXTestDevice(ClientPtr client, const char *name, + DeviceIntPtr *ptr, DeviceIntPtr *keybd, + DeviceIntPtr master_ptr, DeviceIntPtr master_keybd) { int retval; char *xtestname; char dummy = 1; if (asprintf(&xtestname, "%s XTEST", name) == -1) - return BadAlloc; + return BadAlloc; - retval = AllocDevicePair( client, xtestname, ptr, keybd, CorePointerProc, CoreKeyboardProc, FALSE); - if ( retval == Success ){ - (*ptr)->xtest_master_id = master_ptr->id; - (*keybd)->xtest_master_id = master_keybd->id; + retval = + AllocDevicePair(client, xtestname, ptr, keybd, CorePointerProc, + CoreKeyboardProc, FALSE); + if (retval == Success) { + (*ptr)->xtest_master_id = master_ptr->id; + (*keybd)->xtest_master_id = master_keybd->id; XIChangeDeviceProperty(*ptr, XIGetKnownProperty(XI_PROP_XTEST_DEVICE), - XA_INTEGER, 8, PropModeReplace, 1, &dummy, - FALSE); - XISetDevicePropertyDeletable(*ptr, XIGetKnownProperty(XI_PROP_XTEST_DEVICE), FALSE); + XA_INTEGER, 8, PropModeReplace, 1, &dummy, + FALSE); + XISetDevicePropertyDeletable(*ptr, + XIGetKnownProperty(XI_PROP_XTEST_DEVICE), + FALSE); XIRegisterPropertyHandler(*ptr, DeviceSetXTestProperty, NULL, NULL); XIChangeDeviceProperty(*keybd, XIGetKnownProperty(XI_PROP_XTEST_DEVICE), - XA_INTEGER, 8, PropModeReplace, 1, &dummy, - FALSE); - XISetDevicePropertyDeletable(*keybd, XIGetKnownProperty(XI_PROP_XTEST_DEVICE), FALSE); + XA_INTEGER, 8, PropModeReplace, 1, &dummy, + FALSE); + XISetDevicePropertyDeletable(*keybd, + XIGetKnownProperty(XI_PROP_XTEST_DEVICE), + FALSE); XIRegisterPropertyHandler(*keybd, DeviceSetXTestProperty, NULL, NULL); } - free( xtestname ); + free(xtestname); return retval; } @@ -651,7 +645,7 @@ IsXTestDevice(DeviceIntPtr dev, DeviceIntPtr master) /* deviceid 0 is reserved for XIAllDevices, non-zero mid means XTest * device */ if (master) - return dev->xtest_master_id == master->id; + return dev->xtest_master_id == master->id; return dev->xtest_master_id != 0; } @@ -664,8 +658,7 @@ GetXTestDevice(DeviceIntPtr master) { DeviceIntPtr it; - for (it = inputInfo.devices; it; it = it->next) - { + for (it = inputInfo.devices; it; it = it->next) { if (IsXTestDevice(it, master)) return it; } @@ -675,7 +668,7 @@ GetXTestDevice(DeviceIntPtr master) } static void -XTestExtensionTearDown(ExtensionEntry *e) +XTestExtensionTearDown(ExtensionEntry * e) { FreeEventList(xtest_evlist, GetMaximumEventsNum()); xtest_evlist = NULL; @@ -685,8 +678,8 @@ void XTestExtensionInit(INITARGS) { AddExtension(XTestExtensionName, 0, 0, - ProcXTestDispatch, SProcXTestDispatch, - XTestExtensionTearDown, StandardMinorOpcode); + ProcXTestDispatch, SProcXTestDispatch, + XTestExtensionTearDown, StandardMinorOpcode); xtest_evlist = InitEventList(GetMaximumEventsNum()); } diff --git a/xorg-server/Xext/xvdisp.c b/xorg-server/Xext/xvdisp.c index 0795a1475..8abd51c11 100644 --- a/xorg-server/Xext/xvdisp.c +++ b/xorg-server/Xext/xvdisp.c @@ -55,215 +55,189 @@ unsigned long XvXRTPort; #endif static int -SWriteQueryExtensionReply( - ClientPtr client, - xvQueryExtensionReply *rep -){ - swaps(&rep->sequenceNumber); - swapl(&rep->length); - swaps(&rep->version); - swaps(&rep->revision); - - (void)WriteToClient(client, sz_xvQueryExtensionReply, (char *)rep); +SWriteQueryExtensionReply(ClientPtr client, xvQueryExtensionReply * rep) +{ + swaps(&rep->sequenceNumber); + swapl(&rep->length); + swaps(&rep->version); + swaps(&rep->revision); + + (void) WriteToClient(client, sz_xvQueryExtensionReply, (char *) rep); - return Success; + return Success; } static int -SWriteQueryAdaptorsReply( - ClientPtr client, - xvQueryAdaptorsReply *rep -){ - swaps(&rep->sequenceNumber); - swapl(&rep->length); - swaps(&rep->num_adaptors); - - (void)WriteToClient(client, sz_xvQueryAdaptorsReply, (char *)rep); +SWriteQueryAdaptorsReply(ClientPtr client, xvQueryAdaptorsReply * rep) +{ + swaps(&rep->sequenceNumber); + swapl(&rep->length); + swaps(&rep->num_adaptors); + + (void) WriteToClient(client, sz_xvQueryAdaptorsReply, (char *) rep); - return Success; + return Success; } static int -SWriteQueryEncodingsReply( - ClientPtr client, - xvQueryEncodingsReply *rep -){ - swaps(&rep->sequenceNumber); - swapl(&rep->length); - swaps(&rep->num_encodings); - - (void)WriteToClient(client, sz_xvQueryEncodingsReply, (char *)rep); +SWriteQueryEncodingsReply(ClientPtr client, xvQueryEncodingsReply * rep) +{ + swaps(&rep->sequenceNumber); + swapl(&rep->length); + swaps(&rep->num_encodings); + + (void) WriteToClient(client, sz_xvQueryEncodingsReply, (char *) rep); - return Success; + return Success; } static int -SWriteAdaptorInfo( - ClientPtr client, - xvAdaptorInfo *pAdaptor -){ - swapl(&pAdaptor->base_id); - swaps(&pAdaptor->name_size); - swaps(&pAdaptor->num_ports); - swaps(&pAdaptor->num_formats); +SWriteAdaptorInfo(ClientPtr client, xvAdaptorInfo * pAdaptor) +{ + swapl(&pAdaptor->base_id); + swaps(&pAdaptor->name_size); + swaps(&pAdaptor->num_ports); + swaps(&pAdaptor->num_formats); - (void)WriteToClient(client, sz_xvAdaptorInfo, (char *)pAdaptor); + (void) WriteToClient(client, sz_xvAdaptorInfo, (char *) pAdaptor); - return Success; + return Success; } static int -SWriteEncodingInfo( - ClientPtr client, - xvEncodingInfo *pEncoding -){ - - swapl(&pEncoding->encoding); - swaps(&pEncoding->name_size); - swaps(&pEncoding->width); - swaps(&pEncoding->height); - swapl(&pEncoding->rate.numerator); - swapl(&pEncoding->rate.denominator); - (void)WriteToClient(client, sz_xvEncodingInfo, (char *)pEncoding); - - return Success; +SWriteEncodingInfo(ClientPtr client, xvEncodingInfo * pEncoding) +{ + + swapl(&pEncoding->encoding); + swaps(&pEncoding->name_size); + swaps(&pEncoding->width); + swaps(&pEncoding->height); + swapl(&pEncoding->rate.numerator); + swapl(&pEncoding->rate.denominator); + (void) WriteToClient(client, sz_xvEncodingInfo, (char *) pEncoding); + + return Success; } static int -SWriteFormat( - ClientPtr client, - xvFormat *pFormat -){ - swapl(&pFormat->visual); - (void)WriteToClient(client, sz_xvFormat, (char *)pFormat); +SWriteFormat(ClientPtr client, xvFormat * pFormat) +{ + swapl(&pFormat->visual); + (void) WriteToClient(client, sz_xvFormat, (char *) pFormat); - return Success; + return Success; } static int -SWriteAttributeInfo( - ClientPtr client, - xvAttributeInfo *pAtt -){ - swapl(&pAtt->flags); - swapl(&pAtt->size); - swapl(&pAtt->min); - swapl(&pAtt->max); - (void)WriteToClient(client, sz_xvAttributeInfo, (char *)pAtt); +SWriteAttributeInfo(ClientPtr client, xvAttributeInfo * pAtt) +{ + swapl(&pAtt->flags); + swapl(&pAtt->size); + swapl(&pAtt->min); + swapl(&pAtt->max); + (void) WriteToClient(client, sz_xvAttributeInfo, (char *) pAtt); - return Success; + return Success; } static int -SWriteImageFormatInfo( - ClientPtr client, - xvImageFormatInfo *pImage -){ - swapl(&pImage->id); - swapl(&pImage->red_mask); - swapl(&pImage->green_mask); - swapl(&pImage->blue_mask); - swapl(&pImage->y_sample_bits); - swapl(&pImage->u_sample_bits); - swapl(&pImage->v_sample_bits); - swapl(&pImage->horz_y_period); - swapl(&pImage->horz_u_period); - swapl(&pImage->horz_v_period); - swapl(&pImage->vert_y_period); - swapl(&pImage->vert_u_period); - swapl(&pImage->vert_v_period); - - (void)WriteToClient(client, sz_xvImageFormatInfo, (char *)pImage); - - return Success; +SWriteImageFormatInfo(ClientPtr client, xvImageFormatInfo * pImage) +{ + swapl(&pImage->id); + swapl(&pImage->red_mask); + swapl(&pImage->green_mask); + swapl(&pImage->blue_mask); + swapl(&pImage->y_sample_bits); + swapl(&pImage->u_sample_bits); + swapl(&pImage->v_sample_bits); + swapl(&pImage->horz_y_period); + swapl(&pImage->horz_u_period); + swapl(&pImage->horz_v_period); + swapl(&pImage->vert_y_period); + swapl(&pImage->vert_u_period); + swapl(&pImage->vert_v_period); + + (void) WriteToClient(client, sz_xvImageFormatInfo, (char *) pImage); + + return Success; } static int -SWriteGrabPortReply( - ClientPtr client, - xvGrabPortReply *rep -){ - swaps(&rep->sequenceNumber); - swapl(&rep->length); +SWriteGrabPortReply(ClientPtr client, xvGrabPortReply * rep) +{ + swaps(&rep->sequenceNumber); + swapl(&rep->length); - (void)WriteToClient(client, sz_xvGrabPortReply, (char *)rep); + (void) WriteToClient(client, sz_xvGrabPortReply, (char *) rep); - return Success; + return Success; } static int -SWriteGetPortAttributeReply( - ClientPtr client, - xvGetPortAttributeReply *rep -){ - swaps(&rep->sequenceNumber); - swapl(&rep->length); - swapl(&rep->value); +SWriteGetPortAttributeReply(ClientPtr client, xvGetPortAttributeReply * rep) +{ + swaps(&rep->sequenceNumber); + swapl(&rep->length); + swapl(&rep->value); - (void)WriteToClient(client, sz_xvGetPortAttributeReply, (char *)rep); + (void) WriteToClient(client, sz_xvGetPortAttributeReply, (char *) rep); - return Success; + return Success; } static int -SWriteQueryBestSizeReply( - ClientPtr client, - xvQueryBestSizeReply *rep -){ - swaps(&rep->sequenceNumber); - swapl(&rep->length); - swaps(&rep->actual_width); - swaps(&rep->actual_height); +SWriteQueryBestSizeReply(ClientPtr client, xvQueryBestSizeReply * rep) +{ + swaps(&rep->sequenceNumber); + swapl(&rep->length); + swaps(&rep->actual_width); + swaps(&rep->actual_height); - (void)WriteToClient(client, sz_xvQueryBestSizeReply, (char *)rep); + (void) WriteToClient(client, sz_xvQueryBestSizeReply, (char *) rep); - return Success; + return Success; } static int -SWriteQueryPortAttributesReply( - ClientPtr client, - xvQueryPortAttributesReply *rep -){ - swaps(&rep->sequenceNumber); - swapl(&rep->length); - swapl(&rep->num_attributes); - swapl(&rep->text_size); +SWriteQueryPortAttributesReply(ClientPtr client, + xvQueryPortAttributesReply * rep) +{ + swaps(&rep->sequenceNumber); + swapl(&rep->length); + swapl(&rep->num_attributes); + swapl(&rep->text_size); - (void)WriteToClient(client, sz_xvQueryPortAttributesReply, (char *)rep); + (void) WriteToClient(client, sz_xvQueryPortAttributesReply, (char *) rep); - return Success; + return Success; } static int -SWriteQueryImageAttributesReply( - ClientPtr client, - xvQueryImageAttributesReply *rep -){ - swaps(&rep->sequenceNumber); - swapl(&rep->length); - swapl(&rep->num_planes); - swapl(&rep->data_size); - swaps(&rep->width); - swaps(&rep->height); +SWriteQueryImageAttributesReply(ClientPtr client, + xvQueryImageAttributesReply * rep) +{ + swaps(&rep->sequenceNumber); + swapl(&rep->length); + swapl(&rep->num_planes); + swapl(&rep->data_size); + swaps(&rep->width); + swaps(&rep->height); - (void)WriteToClient(client, sz_xvQueryImageAttributesReply, (char *)rep); + (void) WriteToClient(client, sz_xvQueryImageAttributesReply, (char *) rep); - return Success; + return Success; } static int -SWriteListImageFormatsReply( - ClientPtr client, - xvListImageFormatsReply *rep -){ - swaps(&rep->sequenceNumber); - swapl(&rep->length); - swapl(&rep->num_formats); +SWriteListImageFormatsReply(ClientPtr client, xvListImageFormatsReply * rep) +{ + swaps(&rep->sequenceNumber); + swapl(&rep->length); + swapl(&rep->num_formats); - (void)WriteToClient(client, sz_xvListImageFormatsReply, (char *)rep); + (void) WriteToClient(client, sz_xvListImageFormatsReply, (char *) rep); - return Success; + return Success; } #define _WriteQueryAdaptorsReply(_c,_d) \ @@ -328,662 +302,638 @@ SWriteListImageFormatsReply( static int ProcXvQueryExtension(ClientPtr client) { - xvQueryExtensionReply rep; - /* REQUEST(xvQueryExtensionReq); */ - REQUEST_SIZE_MATCH(xvQueryExtensionReq); + xvQueryExtensionReply rep; - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.version = XvVersion; - rep.revision = XvRevision; + /* REQUEST(xvQueryExtensionReq); */ + REQUEST_SIZE_MATCH(xvQueryExtensionReq); - _WriteQueryExtensionReply(client, &rep); + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.length = 0; + rep.version = XvVersion; + rep.revision = XvRevision; - return Success; + _WriteQueryExtensionReply(client, &rep); + + return Success; } static int ProcXvQueryAdaptors(ClientPtr client) { - xvFormat format; - xvAdaptorInfo ainfo; - xvQueryAdaptorsReply rep; - int totalSize, na, nf, rc; - int nameSize; - XvAdaptorPtr pa; - XvFormatPtr pf; - WindowPtr pWin; - ScreenPtr pScreen; - XvScreenPtr pxvs; - - REQUEST(xvQueryAdaptorsReq); - REQUEST_SIZE_MATCH(xvQueryAdaptorsReq); - - rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); - if (rc != Success) - return rc; - - pScreen = pWin->drawable.pScreen; - pxvs = (XvScreenPtr)dixLookupPrivate(&pScreen->devPrivates, - XvGetScreenKey()); - if (!pxvs) - { - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_adaptors = 0; - rep.length = 0; - - _WriteQueryAdaptorsReply(client, &rep); - - return Success; + xvFormat format; + xvAdaptorInfo ainfo; + xvQueryAdaptorsReply rep; + int totalSize, na, nf, rc; + int nameSize; + XvAdaptorPtr pa; + XvFormatPtr pf; + WindowPtr pWin; + ScreenPtr pScreen; + XvScreenPtr pxvs; + + REQUEST(xvQueryAdaptorsReq); + REQUEST_SIZE_MATCH(xvQueryAdaptorsReq); + + rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); + if (rc != Success) + return rc; + + pScreen = pWin->drawable.pScreen; + pxvs = (XvScreenPtr) dixLookupPrivate(&pScreen->devPrivates, + XvGetScreenKey()); + if (!pxvs) { + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.num_adaptors = 0; + rep.length = 0; + + _WriteQueryAdaptorsReply(client, &rep); + + return Success; } - (* pxvs->ddQueryAdaptors)(pScreen, &pxvs->pAdaptors, &pxvs->nAdaptors); + (*pxvs->ddQueryAdaptors) (pScreen, &pxvs->pAdaptors, &pxvs->nAdaptors); - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_adaptors = pxvs->nAdaptors; + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.num_adaptors = pxvs->nAdaptors; - /* CALCULATE THE TOTAL SIZE OF THE REPLY IN BYTES */ + /* CALCULATE THE TOTAL SIZE OF THE REPLY IN BYTES */ - totalSize = pxvs->nAdaptors * sz_xvAdaptorInfo; + totalSize = pxvs->nAdaptors * sz_xvAdaptorInfo; - /* FOR EACH ADPATOR ADD UP THE BYTES FOR ENCODINGS AND FORMATS */ + /* FOR EACH ADPATOR ADD UP THE BYTES FOR ENCODINGS AND FORMATS */ - na = pxvs->nAdaptors; - pa = pxvs->pAdaptors; - while (na--) - { - totalSize += pad_to_int32(strlen(pa->name)); - totalSize += pa->nFormats * sz_xvFormat; - pa++; + na = pxvs->nAdaptors; + pa = pxvs->pAdaptors; + while (na--) { + totalSize += pad_to_int32(strlen(pa->name)); + totalSize += pa->nFormats * sz_xvFormat; + pa++; } - rep.length = bytes_to_int32(totalSize); + rep.length = bytes_to_int32(totalSize); - _WriteQueryAdaptorsReply(client, &rep); + _WriteQueryAdaptorsReply(client, &rep); - na = pxvs->nAdaptors; - pa = pxvs->pAdaptors; - while (na--) - { + na = pxvs->nAdaptors; + pa = pxvs->pAdaptors; + while (na--) { - ainfo.base_id = pa->base_id; - ainfo.num_ports = pa->nPorts; - ainfo.type = pa->type; - ainfo.name_size = nameSize = strlen(pa->name); - ainfo.num_formats = pa->nFormats; + ainfo.base_id = pa->base_id; + ainfo.num_ports = pa->nPorts; + ainfo.type = pa->type; + ainfo.name_size = nameSize = strlen(pa->name); + ainfo.num_formats = pa->nFormats; - _WriteAdaptorInfo(client, &ainfo); + _WriteAdaptorInfo(client, &ainfo); - WriteToClient(client, nameSize, pa->name); + WriteToClient(client, nameSize, pa->name); - nf = pa->nFormats; - pf = pa->pFormats; - while (nf--) - { - format.depth = pf->depth; - format.visual = pf->visual; - _WriteFormat(client, &format); - pf++; - } + nf = pa->nFormats; + pf = pa->pFormats; + while (nf--) { + format.depth = pf->depth; + format.visual = pf->visual; + _WriteFormat(client, &format); + pf++; + } - pa++; + pa++; } - return Success; + return Success; } static int ProcXvQueryEncodings(ClientPtr client) { - xvEncodingInfo einfo; - xvQueryEncodingsReply rep; - int totalSize; - int nameSize; - XvPortPtr pPort; - int ne; - XvEncodingPtr pe; - int status; - - REQUEST(xvQueryEncodingsReq); - REQUEST_SIZE_MATCH(xvQueryEncodingsReq); - - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); - - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + xvEncodingInfo einfo; + xvQueryEncodingsReply rep; + int totalSize; + int nameSize; + XvPortPtr pPort; + int ne; + XvEncodingPtr pe; + int status; + + REQUEST(xvQueryEncodingsReq); + REQUEST_SIZE_MATCH(xvQueryEncodingsReq); + + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_encodings = pPort->pAdaptor->nEncodings; + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.num_encodings = pPort->pAdaptor->nEncodings; - /* FOR EACH ENCODING ADD UP THE BYTES FOR ENCODING NAMES */ + /* FOR EACH ENCODING ADD UP THE BYTES FOR ENCODING NAMES */ - ne = pPort->pAdaptor->nEncodings; - pe = pPort->pAdaptor->pEncodings; - totalSize = ne * sz_xvEncodingInfo; - while (ne--) - { - totalSize += pad_to_int32(strlen(pe->name)); - pe++; + ne = pPort->pAdaptor->nEncodings; + pe = pPort->pAdaptor->pEncodings; + totalSize = ne * sz_xvEncodingInfo; + while (ne--) { + totalSize += pad_to_int32(strlen(pe->name)); + pe++; } - rep.length = bytes_to_int32(totalSize); - - _WriteQueryEncodingsReply(client, &rep); - - ne = pPort->pAdaptor->nEncodings; - pe = pPort->pAdaptor->pEncodings; - while (ne--) - { - einfo.encoding = pe->id; - einfo.name_size = nameSize = strlen(pe->name); - einfo.width = pe->width; - einfo.height = pe->height; - einfo.rate.numerator = pe->rate.numerator; - einfo.rate.denominator = pe->rate.denominator; - _WriteEncodingInfo(client, &einfo); - WriteToClient(client, nameSize, pe->name); - pe++; + rep.length = bytes_to_int32(totalSize); + + _WriteQueryEncodingsReply(client, &rep); + + ne = pPort->pAdaptor->nEncodings; + pe = pPort->pAdaptor->pEncodings; + while (ne--) { + einfo.encoding = pe->id; + einfo.name_size = nameSize = strlen(pe->name); + einfo.width = pe->width; + einfo.height = pe->height; + einfo.rate.numerator = pe->rate.numerator; + einfo.rate.denominator = pe->rate.denominator; + _WriteEncodingInfo(client, &einfo); + WriteToClient(client, nameSize, pe->name); + pe++; } - return Success; + return Success; } static int ProcXvPutVideo(ClientPtr client) { - DrawablePtr pDraw; - XvPortPtr pPort; - GCPtr pGC; - int status; + DrawablePtr pDraw; + XvPortPtr pPort; + GCPtr pGC; + int status; - REQUEST(xvPutVideoReq); - REQUEST_SIZE_MATCH(xvPutVideoReq); + REQUEST(xvPutVideoReq); + REQUEST_SIZE_MATCH(xvPutVideoReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - if (!(pPort->pAdaptor->type & XvInputMask) || - !(pPort->pAdaptor->type & XvVideoMask)) - { - client->errorValue = stuff->port; - return BadMatch; + if (!(pPort->pAdaptor->type & XvInputMask) || + !(pPort->pAdaptor->type & XvVideoMask)) { + client->errorValue = stuff->port; + return BadMatch; } - status = XvdiMatchPort(pPort, pDraw); - if (status != Success) - { - return status; + status = XvdiMatchPort(pPort, pDraw); + if (status != Success) { + return status; } - return XvdiPutVideo(client, pDraw, pPort, pGC, stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); + return XvdiPutVideo(client, pDraw, pPort, pGC, stuff->vid_x, stuff->vid_y, + stuff->vid_w, stuff->vid_h, stuff->drw_x, stuff->drw_y, + stuff->drw_w, stuff->drw_h); } static int ProcXvPutStill(ClientPtr client) { - DrawablePtr pDraw; - XvPortPtr pPort; - GCPtr pGC; - int status; + DrawablePtr pDraw; + XvPortPtr pPort; + GCPtr pGC; + int status; - REQUEST(xvPutStillReq); - REQUEST_SIZE_MATCH(xvPutStillReq); + REQUEST(xvPutStillReq); + REQUEST_SIZE_MATCH(xvPutStillReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - if (!(pPort->pAdaptor->type & XvInputMask) || - !(pPort->pAdaptor->type & XvStillMask)) - { - client->errorValue = stuff->port; - return BadMatch; + if (!(pPort->pAdaptor->type & XvInputMask) || + !(pPort->pAdaptor->type & XvStillMask)) { + client->errorValue = stuff->port; + return BadMatch; } - status = XvdiMatchPort(pPort, pDraw); - if (status != Success) - { - return status; + status = XvdiMatchPort(pPort, pDraw); + if (status != Success) { + return status; } - return XvdiPutStill(client, pDraw, pPort, pGC, stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); + return XvdiPutStill(client, pDraw, pPort, pGC, stuff->vid_x, stuff->vid_y, + stuff->vid_w, stuff->vid_h, stuff->drw_x, stuff->drw_y, + stuff->drw_w, stuff->drw_h); } static int ProcXvGetVideo(ClientPtr client) { - DrawablePtr pDraw; - XvPortPtr pPort; - GCPtr pGC; - int status; + DrawablePtr pDraw; + XvPortPtr pPort; + GCPtr pGC; + int status; - REQUEST(xvGetVideoReq); - REQUEST_SIZE_MATCH(xvGetVideoReq); + REQUEST(xvGetVideoReq); + REQUEST_SIZE_MATCH(xvGetVideoReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixReadAccess); - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixReadAccess); + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - if (!(pPort->pAdaptor->type & XvOutputMask) || - !(pPort->pAdaptor->type & XvVideoMask)) - { - client->errorValue = stuff->port; - return BadMatch; + if (!(pPort->pAdaptor->type & XvOutputMask) || + !(pPort->pAdaptor->type & XvVideoMask)) { + client->errorValue = stuff->port; + return BadMatch; } - status = XvdiMatchPort(pPort, pDraw); - if (status != Success) - { - return status; + status = XvdiMatchPort(pPort, pDraw); + if (status != Success) { + return status; } - return XvdiGetVideo(client, pDraw, pPort, pGC, stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); + return XvdiGetVideo(client, pDraw, pPort, pGC, stuff->vid_x, stuff->vid_y, + stuff->vid_w, stuff->vid_h, stuff->drw_x, stuff->drw_y, + stuff->drw_w, stuff->drw_h); } static int ProcXvGetStill(ClientPtr client) { - DrawablePtr pDraw; - XvPortPtr pPort; - GCPtr pGC; - int status; + DrawablePtr pDraw; + XvPortPtr pPort; + GCPtr pGC; + int status; - REQUEST(xvGetStillReq); - REQUEST_SIZE_MATCH(xvGetStillReq); + REQUEST(xvGetStillReq); + REQUEST_SIZE_MATCH(xvGetStillReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixReadAccess); - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixReadAccess); + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - if (!(pPort->pAdaptor->type & XvOutputMask) || - !(pPort->pAdaptor->type & XvStillMask)) - { - client->errorValue = stuff->port; - return BadMatch; + if (!(pPort->pAdaptor->type & XvOutputMask) || + !(pPort->pAdaptor->type & XvStillMask)) { + client->errorValue = stuff->port; + return BadMatch; } - status = XvdiMatchPort(pPort, pDraw); - if (status != Success) - { - return status; + status = XvdiMatchPort(pPort, pDraw); + if (status != Success) { + return status; } - return XvdiGetStill(client, pDraw, pPort, pGC, stuff->vid_x, stuff->vid_y, - stuff->vid_w, stuff->vid_h, stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h); + return XvdiGetStill(client, pDraw, pPort, pGC, stuff->vid_x, stuff->vid_y, + stuff->vid_w, stuff->vid_h, stuff->drw_x, stuff->drw_y, + stuff->drw_w, stuff->drw_h); } static int ProcXvSelectVideoNotify(ClientPtr client) { - DrawablePtr pDraw; - int rc; - REQUEST(xvSelectVideoNotifyReq); - REQUEST_SIZE_MATCH(xvSelectVideoNotifyReq); + DrawablePtr pDraw; + int rc; + + REQUEST(xvSelectVideoNotifyReq); + REQUEST_SIZE_MATCH(xvSelectVideoNotifyReq); - rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixReceiveAccess); - if (rc != Success) - return rc; + rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, + DixReceiveAccess); + if (rc != Success) + return rc; - return XvdiSelectVideoNotify(client, pDraw, stuff->onoff); + return XvdiSelectVideoNotify(client, pDraw, stuff->onoff); } static int ProcXvSelectPortNotify(ClientPtr client) { - int status; - XvPortPtr pPort; - REQUEST(xvSelectPortNotifyReq); - REQUEST_SIZE_MATCH(xvSelectPortNotifyReq); + int status; + XvPortPtr pPort; + + REQUEST(xvSelectPortNotifyReq); + REQUEST_SIZE_MATCH(xvSelectPortNotifyReq); - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - return XvdiSelectPortNotify(client, pPort, stuff->onoff); + return XvdiSelectPortNotify(client, pPort, stuff->onoff); } static int ProcXvGrabPort(ClientPtr client) { - int result, status; - XvPortPtr pPort; - xvGrabPortReply rep; - REQUEST(xvGrabPortReq); - REQUEST_SIZE_MATCH(xvGrabPortReq); + int result, status; + XvPortPtr pPort; + xvGrabPortReply rep; - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + REQUEST(xvGrabPortReq); + REQUEST_SIZE_MATCH(xvGrabPortReq); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - status = XvdiGrabPort(client, pPort, stuff->time, &result); + status = XvdiGrabPort(client, pPort, stuff->time, &result); - if (status != Success) - { - return status; + if (status != Success) { + return status; } - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.result = result; + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.length = 0; + rep.result = result; - _WriteGrabPortReply(client, &rep); + _WriteGrabPortReply(client, &rep); - return Success; + return Success; } static int ProcXvUngrabPort(ClientPtr client) { - int status; - XvPortPtr pPort; - REQUEST(xvGrabPortReq); - REQUEST_SIZE_MATCH(xvGrabPortReq); + int status; + XvPortPtr pPort; + + REQUEST(xvGrabPortReq); + REQUEST_SIZE_MATCH(xvGrabPortReq); - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - return XvdiUngrabPort(client, pPort, stuff->time); + return XvdiUngrabPort(client, pPort, stuff->time); } static int ProcXvStopVideo(ClientPtr client) { - int status, rc; - DrawablePtr pDraw; - XvPortPtr pPort; - REQUEST(xvStopVideoReq); - REQUEST_SIZE_MATCH(xvStopVideoReq); + int status, rc; + DrawablePtr pDraw; + XvPortPtr pPort; - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + REQUEST(xvStopVideoReq); + REQUEST_SIZE_MATCH(xvStopVideoReq); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixWriteAccess); - if (rc != Success) - return rc; + rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixWriteAccess); + if (rc != Success) + return rc; - return XvdiStopVideo(client, pPort, pDraw); + return XvdiStopVideo(client, pPort, pDraw); } static int ProcXvSetPortAttribute(ClientPtr client) { - int status; - XvPortPtr pPort; - REQUEST(xvSetPortAttributeReq); - REQUEST_SIZE_MATCH(xvSetPortAttributeReq); + int status; + XvPortPtr pPort; - VALIDATE_XV_PORT(stuff->port, pPort, DixSetAttrAccess); + REQUEST(xvSetPortAttributeReq); + REQUEST_SIZE_MATCH(xvSetPortAttributeReq); + + VALIDATE_XV_PORT(stuff->port, pPort, DixSetAttrAccess); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - if (!ValidAtom(stuff->attribute)) - { - client->errorValue = stuff->attribute; - return BadAtom; + if (!ValidAtom(stuff->attribute)) { + client->errorValue = stuff->attribute; + return BadAtom; } - status = XvdiSetPortAttribute(client, pPort, stuff->attribute, stuff->value); + status = + XvdiSetPortAttribute(client, pPort, stuff->attribute, stuff->value); - if (status == BadMatch) - client->errorValue = stuff->attribute; - else - client->errorValue = stuff->value; + if (status == BadMatch) + client->errorValue = stuff->attribute; + else + client->errorValue = stuff->value; - return status; + return status; } static int ProcXvGetPortAttribute(ClientPtr client) { - INT32 value; - int status; - XvPortPtr pPort; - xvGetPortAttributeReply rep; - REQUEST(xvGetPortAttributeReq); - REQUEST_SIZE_MATCH(xvGetPortAttributeReq); + INT32 value; + int status; + XvPortPtr pPort; + xvGetPortAttributeReply rep; + + REQUEST(xvGetPortAttributeReq); + REQUEST_SIZE_MATCH(xvGetPortAttributeReq); - VALIDATE_XV_PORT(stuff->port, pPort, DixGetAttrAccess); + VALIDATE_XV_PORT(stuff->port, pPort, DixGetAttrAccess); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - if (!ValidAtom(stuff->attribute)) - { - client->errorValue = stuff->attribute; - return BadAtom; + if (!ValidAtom(stuff->attribute)) { + client->errorValue = stuff->attribute; + return BadAtom; } - status = XvdiGetPortAttribute(client, pPort, stuff->attribute, &value); - if (status != Success) - { - client->errorValue = stuff->attribute; - return status; + status = XvdiGetPortAttribute(client, pPort, stuff->attribute, &value); + if (status != Success) { + client->errorValue = stuff->attribute; + return status; } - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.value = value; - - _WriteGetPortAttributeReply(client, &rep); + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.length = 0; + rep.value = value; - return Success; + _WriteGetPortAttributeReply(client, &rep); + + return Success; } static int ProcXvQueryBestSize(ClientPtr client) { - int status; - unsigned int actual_width, actual_height; - XvPortPtr pPort; - xvQueryBestSizeReply rep; - REQUEST(xvQueryBestSizeReq); - REQUEST_SIZE_MATCH(xvQueryBestSizeReq); + int status; + unsigned int actual_width, actual_height; + XvPortPtr pPort; + xvQueryBestSizeReply rep; + + REQUEST(xvQueryBestSizeReq); + REQUEST_SIZE_MATCH(xvQueryBestSizeReq); - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.length = 0; - (* pPort->pAdaptor->ddQueryBestSize)(client, pPort, stuff->motion, - stuff->vid_w, stuff->vid_h, - stuff->drw_w, stuff->drw_h, - &actual_width, &actual_height); + (*pPort->pAdaptor->ddQueryBestSize) (client, pPort, stuff->motion, + stuff->vid_w, stuff->vid_h, + stuff->drw_w, stuff->drw_h, + &actual_width, &actual_height); - rep.actual_width = actual_width; - rep.actual_height = actual_height; - - _WriteQueryBestSizeReply(client, &rep); + rep.actual_width = actual_width; + rep.actual_height = actual_height; - return Success; -} + _WriteQueryBestSizeReply(client, &rep); + return Success; +} static int ProcXvQueryPortAttributes(ClientPtr client) { - int status, size, i; - XvPortPtr pPort; - XvAttributePtr pAtt; - xvQueryPortAttributesReply rep; - xvAttributeInfo Info; - REQUEST(xvQueryPortAttributesReq); - REQUEST_SIZE_MATCH(xvQueryPortAttributesReq); + int status, size, i; + XvPortPtr pPort; + XvAttributePtr pAtt; + xvQueryPortAttributesReply rep; + xvAttributeInfo Info; - VALIDATE_XV_PORT(stuff->port, pPort, DixGetAttrAccess); + REQUEST(xvQueryPortAttributesReq); + REQUEST_SIZE_MATCH(xvQueryPortAttributesReq); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + VALIDATE_XV_PORT(stuff->port, pPort, DixGetAttrAccess); + + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_attributes = pPort->pAdaptor->nAttributes; - rep.text_size = 0; + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.num_attributes = pPort->pAdaptor->nAttributes; + rep.text_size = 0; - for(i = 0, pAtt = pPort->pAdaptor->pAttributes; - i < pPort->pAdaptor->nAttributes; i++, pAtt++) - { - rep.text_size += pad_to_int32(strlen(pAtt->name) + 1); - } + for (i = 0, pAtt = pPort->pAdaptor->pAttributes; + i < pPort->pAdaptor->nAttributes; i++, pAtt++) { + rep.text_size += pad_to_int32(strlen(pAtt->name) + 1); + } - rep.length = (pPort->pAdaptor->nAttributes * sz_xvAttributeInfo) - + rep.text_size; - rep.length >>= 2; + rep.length = (pPort->pAdaptor->nAttributes * sz_xvAttributeInfo) + + rep.text_size; + rep.length >>= 2; - _WriteQueryPortAttributesReply(client, &rep); + _WriteQueryPortAttributesReply(client, &rep); - for(i = 0, pAtt = pPort->pAdaptor->pAttributes; - i < pPort->pAdaptor->nAttributes; i++, pAtt++) - { - size = strlen(pAtt->name) + 1; /* pass the NULL */ - Info.flags = pAtt->flags; - Info.min = pAtt->min_value; - Info.max = pAtt->max_value; - Info.size = pad_to_int32(size); + for (i = 0, pAtt = pPort->pAdaptor->pAttributes; + i < pPort->pAdaptor->nAttributes; i++, pAtt++) { + size = strlen(pAtt->name) + 1; /* pass the NULL */ + Info.flags = pAtt->flags; + Info.min = pAtt->min_value; + Info.max = pAtt->max_value; + Info.size = pad_to_int32(size); - _WriteAttributeInfo(client, &Info); + _WriteAttributeInfo(client, &Info); - WriteToClient(client, size, pAtt->name); - } + WriteToClient(client, size, pAtt->name); + } - return Success; + return Success; } -static int +static int ProcXvPutImage(ClientPtr client) { - DrawablePtr pDraw; - XvPortPtr pPort; - XvImagePtr pImage = NULL; - GCPtr pGC; - int status, i, size; - CARD16 width, height; + DrawablePtr pDraw; + XvPortPtr pPort; + XvImagePtr pImage = NULL; + GCPtr pGC; + int status, i, size; + CARD16 width, height; - REQUEST(xvPutImageReq); - REQUEST_AT_LEAST_SIZE(xvPutImageReq); + REQUEST(xvPutImageReq); + REQUEST_AT_LEAST_SIZE(xvPutImageReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - if (!(pPort->pAdaptor->type & XvImageMask) || - !(pPort->pAdaptor->type & XvInputMask)) - { - client->errorValue = stuff->port; - return BadMatch; + if (!(pPort->pAdaptor->type & XvImageMask) || + !(pPort->pAdaptor->type & XvInputMask)) { + client->errorValue = stuff->port; + return BadMatch; } - status = XvdiMatchPort(pPort, pDraw); - if (status != Success) - { - return status; + status = XvdiMatchPort(pPort, pDraw); + if (status != Success) { + return status; } - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } + for (i = 0; i < pPort->pAdaptor->nImages; i++) { + if (pPort->pAdaptor->pImages[i].id == stuff->id) { + pImage = &(pPort->pAdaptor->pImages[i]); + break; + } + } + + if (!pImage) + return BadMatch; - if(!pImage) - return BadMatch; + width = stuff->width; + height = stuff->height; + size = (*pPort->pAdaptor->ddQueryImageAttributes) (client, + pPort, pImage, &width, + &height, NULL, NULL); + size += sizeof(xvPutImageReq); + size = bytes_to_int32(size); - width = stuff->width; - height = stuff->height; - size = (*pPort->pAdaptor->ddQueryImageAttributes)(client, - pPort, pImage, &width, &height, NULL, NULL); - size += sizeof(xvPutImageReq); - size = bytes_to_int32(size); - - if((width < stuff->width) || (height < stuff->height)) - return BadValue; + if ((width < stuff->width) || (height < stuff->height)) + return BadValue; - if(client->req_len < size) - return BadLength; + if (client->req_len < size) + return BadLength; - return XvdiPutImage(client, pDraw, pPort, pGC, stuff->src_x, stuff->src_y, - stuff->src_w, stuff->src_h, stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h, pImage, - (unsigned char*)(&stuff[1]), FALSE, - stuff->width, stuff->height); + return XvdiPutImage(client, pDraw, pPort, pGC, stuff->src_x, stuff->src_y, + stuff->src_w, stuff->src_h, stuff->drw_x, stuff->drw_y, + stuff->drw_w, stuff->drw_h, pImage, + (unsigned char *) (&stuff[1]), FALSE, + stuff->width, stuff->height); } #ifdef MITSHM @@ -1000,74 +950,73 @@ typedef struct _ShmDesc { extern RESTYPE ShmSegType; extern int ShmCompletionCode; -static int +static int ProcXvShmPutImage(ClientPtr client) { - ShmDescPtr shmdesc; - DrawablePtr pDraw; - XvPortPtr pPort; - XvImagePtr pImage = NULL; - GCPtr pGC; - int status, size_needed, i; - CARD16 width, height; + ShmDescPtr shmdesc; + DrawablePtr pDraw; + XvPortPtr pPort; + XvImagePtr pImage = NULL; + GCPtr pGC; + int status, size_needed, i; + CARD16 width, height; - REQUEST(xvShmPutImageReq); - REQUEST_SIZE_MATCH(xvShmPutImageReq); + REQUEST(xvShmPutImageReq); + REQUEST_SIZE_MATCH(xvShmPutImageReq); - VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); - if ((status = _AllocatePort(stuff->port, pPort)) != Success) - { - client->errorValue = stuff->port; - return status; + if ((status = _AllocatePort(stuff->port, pPort)) != Success) { + client->errorValue = stuff->port; + return status; } - if (!(pPort->pAdaptor->type & XvImageMask) || - !(pPort->pAdaptor->type & XvInputMask)) - { - client->errorValue = stuff->port; - return BadMatch; + if (!(pPort->pAdaptor->type & XvImageMask) || + !(pPort->pAdaptor->type & XvInputMask)) { + client->errorValue = stuff->port; + return BadMatch; } - status = XvdiMatchPort(pPort, pDraw); - if (status != Success) - { - return status; + status = XvdiMatchPort(pPort, pDraw); + if (status != Success) { + return status; } - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } - - if(!pImage) - return BadMatch; - - status = dixLookupResourceByType((pointer *)&shmdesc, stuff->shmseg, - ShmSegType, serverClient, DixReadAccess); - if (status != Success) - return status; - - width = stuff->width; - height = stuff->height; - size_needed = (*pPort->pAdaptor->ddQueryImageAttributes)(client, - pPort, pImage, &width, &height, NULL, NULL); - if((size_needed + stuff->offset) > shmdesc->size) - return BadAccess; - - if((width < stuff->width) || (height < stuff->height)) - return BadValue; - - status = XvdiPutImage(client, pDraw, pPort, pGC, stuff->src_x, stuff->src_y, - stuff->src_w, stuff->src_h, stuff->drw_x, stuff->drw_y, - stuff->drw_w, stuff->drw_h, pImage, - (unsigned char *)shmdesc->addr + stuff->offset, - stuff->send_event, stuff->width, stuff->height); - - if((status == Success) && stuff->send_event) { + for (i = 0; i < pPort->pAdaptor->nImages; i++) { + if (pPort->pAdaptor->pImages[i].id == stuff->id) { + pImage = &(pPort->pAdaptor->pImages[i]); + break; + } + } + + if (!pImage) + return BadMatch; + + status = dixLookupResourceByType((pointer *) &shmdesc, stuff->shmseg, + ShmSegType, serverClient, DixReadAccess); + if (status != Success) + return status; + + width = stuff->width; + height = stuff->height; + size_needed = (*pPort->pAdaptor->ddQueryImageAttributes) (client, + pPort, pImage, + &width, &height, + NULL, NULL); + if ((size_needed + stuff->offset) > shmdesc->size) + return BadAccess; + + if ((width < stuff->width) || (height < stuff->height)) + return BadValue; + + status = XvdiPutImage(client, pDraw, pPort, pGC, stuff->src_x, stuff->src_y, + stuff->src_w, stuff->src_h, stuff->drw_x, + stuff->drw_y, stuff->drw_w, stuff->drw_h, pImage, + (unsigned char *) shmdesc->addr + stuff->offset, + stuff->send_event, stuff->width, stuff->height); + + if ((status == Success) && stuff->send_event) { xShmCompletionEvent ev; ev.type = ShmCompletionCode; @@ -1077,11 +1026,11 @@ ProcXvShmPutImage(ClientPtr client) ev.shmseg = stuff->shmseg; ev.offset = stuff->offset; WriteEventsToClient(client, 1, (xEvent *) &ev); - } + } - return status; + return status; } -#else /* !MITSHM */ +#else /* !MITSHM */ static int ProcXvShmPutImage(ClientPtr client) { @@ -1094,156 +1043,157 @@ ProcXvShmPutImage(ClientPtr client) #include "xvmcext.h" #endif -static int +static int ProcXvQueryImageAttributes(ClientPtr client) { - xvQueryImageAttributesReply rep; - int size, num_planes, i; - CARD16 width, height; - XvImagePtr pImage = NULL; - XvPortPtr pPort; - int *offsets; - int *pitches; - int planeLength; - REQUEST(xvQueryImageAttributesReq); - - REQUEST_SIZE_MATCH(xvQueryImageAttributesReq); - - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); - - for(i = 0; i < pPort->pAdaptor->nImages; i++) { - if(pPort->pAdaptor->pImages[i].id == stuff->id) { - pImage = &(pPort->pAdaptor->pImages[i]); - break; - } - } + xvQueryImageAttributesReply rep; + int size, num_planes, i; + CARD16 width, height; + XvImagePtr pImage = NULL; + XvPortPtr pPort; + int *offsets; + int *pitches; + int planeLength; + + REQUEST(xvQueryImageAttributesReq); + + REQUEST_SIZE_MATCH(xvQueryImageAttributesReq); + + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + + for (i = 0; i < pPort->pAdaptor->nImages; i++) { + if (pPort->pAdaptor->pImages[i].id == stuff->id) { + pImage = &(pPort->pAdaptor->pImages[i]); + break; + } + } #ifdef XvMCExtension - if(!pImage) - pImage = XvMCFindXvImage(pPort, stuff->id); + if (!pImage) + pImage = XvMCFindXvImage(pPort, stuff->id); #endif - if(!pImage) - return BadMatch; + if (!pImage) + return BadMatch; + + num_planes = pImage->num_planes; - num_planes = pImage->num_planes; + if (!(offsets = malloc(num_planes << 3))) + return BadAlloc; + pitches = offsets + num_planes; - if(!(offsets = malloc(num_planes << 3))) - return BadAlloc; - pitches = offsets + num_planes; + width = stuff->width; + height = stuff->height; - width = stuff->width; - height = stuff->height; + size = (*pPort->pAdaptor->ddQueryImageAttributes) (client, pPort, pImage, + &width, &height, offsets, + pitches); - size = (*pPort->pAdaptor->ddQueryImageAttributes)(client, pPort, pImage, - &width, &height, offsets, pitches); + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.length = planeLength = num_planes << 1; + rep.num_planes = num_planes; + rep.width = width; + rep.height = height; + rep.data_size = size; - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = planeLength = num_planes << 1; - rep.num_planes = num_planes; - rep.width = width; - rep.height = height; - rep.data_size = size; - - _WriteQueryImageAttributesReply(client, &rep); - if(client->swapped) - SwapLongs((CARD32*)offsets, planeLength); - WriteToClient(client, planeLength << 2, (char*)offsets); + _WriteQueryImageAttributesReply(client, &rep); + if (client->swapped) + SwapLongs((CARD32 *) offsets, planeLength); + WriteToClient(client, planeLength << 2, (char *) offsets); - free(offsets); + free(offsets); - return Success; + return Success; } -static int +static int ProcXvListImageFormats(ClientPtr client) { - XvPortPtr pPort; - XvImagePtr pImage; - int i; - xvListImageFormatsReply rep; - xvImageFormatInfo info; - REQUEST(xvListImageFormatsReq); - - REQUEST_SIZE_MATCH(xvListImageFormatsReq); - - VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.num_formats = pPort->pAdaptor->nImages; - rep.length = bytes_to_int32(pPort->pAdaptor->nImages * sz_xvImageFormatInfo); - - _WriteListImageFormatsReply(client, &rep); - - pImage = pPort->pAdaptor->pImages; - - for(i = 0; i < pPort->pAdaptor->nImages; i++, pImage++) { - info.id = pImage->id; - info.type = pImage->type; - info.byte_order = pImage->byte_order; - memcpy(&info.guid, pImage->guid, 16); - info.bpp = pImage->bits_per_pixel; - info.num_planes = pImage->num_planes; - info.depth = pImage->depth; - info.red_mask = pImage->red_mask; - info.green_mask = pImage->green_mask; - info.blue_mask = pImage->blue_mask; - info.format = pImage->format; - info.y_sample_bits = pImage->y_sample_bits; - info.u_sample_bits = pImage->u_sample_bits; - info.v_sample_bits = pImage->v_sample_bits; - info.horz_y_period = pImage->horz_y_period; - info.horz_u_period = pImage->horz_u_period; - info.horz_v_period = pImage->horz_v_period; - info.vert_y_period = pImage->vert_y_period; - info.vert_u_period = pImage->vert_u_period; - info.vert_v_period = pImage->vert_v_period; - memcpy(&info.comp_order, pImage->component_order, 32); - info.scanline_order = pImage->scanline_order; - _WriteImageFormatInfo(client, &info); - } - - return Success; -} - -static int (*XvProcVector[xvNumRequests])(ClientPtr) = { - ProcXvQueryExtension, - ProcXvQueryAdaptors, - ProcXvQueryEncodings, - ProcXvGrabPort, - ProcXvUngrabPort, - ProcXvPutVideo, - ProcXvPutStill, - ProcXvGetVideo, - ProcXvGetStill, - ProcXvStopVideo, - ProcXvSelectVideoNotify, - ProcXvSelectPortNotify, - ProcXvQueryBestSize, - ProcXvSetPortAttribute, - ProcXvGetPortAttribute, - ProcXvQueryPortAttributes, - ProcXvListImageFormats, - ProcXvQueryImageAttributes, - ProcXvPutImage, - ProcXvShmPutImage, -}; + XvPortPtr pPort; + XvImagePtr pImage; + int i; + xvListImageFormatsReply rep; + xvImageFormatInfo info; + + REQUEST(xvListImageFormatsReq); + + REQUEST_SIZE_MATCH(xvListImageFormatsReq); + + VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); + + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.num_formats = pPort->pAdaptor->nImages; + rep.length = + bytes_to_int32(pPort->pAdaptor->nImages * sz_xvImageFormatInfo); + + _WriteListImageFormatsReply(client, &rep); + + pImage = pPort->pAdaptor->pImages; + + for (i = 0; i < pPort->pAdaptor->nImages; i++, pImage++) { + info.id = pImage->id; + info.type = pImage->type; + info.byte_order = pImage->byte_order; + memcpy(&info.guid, pImage->guid, 16); + info.bpp = pImage->bits_per_pixel; + info.num_planes = pImage->num_planes; + info.depth = pImage->depth; + info.red_mask = pImage->red_mask; + info.green_mask = pImage->green_mask; + info.blue_mask = pImage->blue_mask; + info.format = pImage->format; + info.y_sample_bits = pImage->y_sample_bits; + info.u_sample_bits = pImage->u_sample_bits; + info.v_sample_bits = pImage->v_sample_bits; + info.horz_y_period = pImage->horz_y_period; + info.horz_u_period = pImage->horz_u_period; + info.horz_v_period = pImage->horz_v_period; + info.vert_y_period = pImage->vert_y_period; + info.vert_u_period = pImage->vert_u_period; + info.vert_v_period = pImage->vert_v_period; + memcpy(&info.comp_order, pImage->component_order, 32); + info.scanline_order = pImage->scanline_order; + _WriteImageFormatInfo(client, &info); + } + + return Success; +} + +static int (*XvProcVector[xvNumRequests]) (ClientPtr) = { +ProcXvQueryExtension, + ProcXvQueryAdaptors, + ProcXvQueryEncodings, + ProcXvGrabPort, + ProcXvUngrabPort, + ProcXvPutVideo, + ProcXvPutStill, + ProcXvGetVideo, + ProcXvGetStill, + ProcXvStopVideo, + ProcXvSelectVideoNotify, + ProcXvSelectPortNotify, + ProcXvQueryBestSize, + ProcXvSetPortAttribute, + ProcXvGetPortAttribute, + ProcXvQueryPortAttributes, + ProcXvListImageFormats, + ProcXvQueryImageAttributes, ProcXvPutImage, ProcXvShmPutImage,}; int ProcXvDispatch(ClientPtr client) { - REQUEST(xReq); + REQUEST(xReq); - UpdateCurrentTime(); + UpdateCurrentTime(); - if (stuff->data >= xvNumRequests) { - SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest); - return BadRequest; - } + if (stuff->data >= xvNumRequests) { + SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest); + return BadRequest; + } - return XvProcVector[stuff->data](client); + return XvProcVector[stuff->data] (client); } /* Swapped Procs */ @@ -1251,333 +1201,331 @@ ProcXvDispatch(ClientPtr client) static int SProcXvQueryExtension(ClientPtr client) { - REQUEST(xvQueryExtensionReq); - swaps(&stuff->length); - return XvProcVector[xv_QueryExtension](client); + REQUEST(xvQueryExtensionReq); + swaps(&stuff->length); + return XvProcVector[xv_QueryExtension] (client); } static int SProcXvQueryAdaptors(ClientPtr client) { - REQUEST(xvQueryAdaptorsReq); - swaps(&stuff->length); - swapl(&stuff->window); - return XvProcVector[xv_QueryAdaptors](client); + REQUEST(xvQueryAdaptorsReq); + swaps(&stuff->length); + swapl(&stuff->window); + return XvProcVector[xv_QueryAdaptors] (client); } static int SProcXvQueryEncodings(ClientPtr client) { - REQUEST(xvQueryEncodingsReq); - swaps(&stuff->length); - swapl(&stuff->port); - return XvProcVector[xv_QueryEncodings](client); + REQUEST(xvQueryEncodingsReq); + swaps(&stuff->length); + swapl(&stuff->port); + return XvProcVector[xv_QueryEncodings] (client); } static int SProcXvGrabPort(ClientPtr client) { - REQUEST(xvGrabPortReq); - swaps(&stuff->length); - swapl(&stuff->port); - swapl(&stuff->time); - return XvProcVector[xv_GrabPort](client); + REQUEST(xvGrabPortReq); + swaps(&stuff->length); + swapl(&stuff->port); + swapl(&stuff->time); + return XvProcVector[xv_GrabPort] (client); } static int SProcXvUngrabPort(ClientPtr client) { - REQUEST(xvUngrabPortReq); - swaps(&stuff->length); - swapl(&stuff->port); - swapl(&stuff->time); - return XvProcVector[xv_UngrabPort](client); + REQUEST(xvUngrabPortReq); + swaps(&stuff->length); + swapl(&stuff->port); + swapl(&stuff->time); + return XvProcVector[xv_UngrabPort] (client); } static int SProcXvPutVideo(ClientPtr client) { - REQUEST(xvPutVideoReq); - swaps(&stuff->length); - swapl(&stuff->port); - swapl(&stuff->drawable); - swapl(&stuff->gc); - swaps(&stuff->vid_x); - swaps(&stuff->vid_y); - swaps(&stuff->vid_w); - swaps(&stuff->vid_h); - swaps(&stuff->drw_x); - swaps(&stuff->drw_y); - swaps(&stuff->drw_w); - swaps(&stuff->drw_h); - return XvProcVector[xv_PutVideo](client); + REQUEST(xvPutVideoReq); + swaps(&stuff->length); + swapl(&stuff->port); + swapl(&stuff->drawable); + swapl(&stuff->gc); + swaps(&stuff->vid_x); + swaps(&stuff->vid_y); + swaps(&stuff->vid_w); + swaps(&stuff->vid_h); + swaps(&stuff->drw_x); + swaps(&stuff->drw_y); + swaps(&stuff->drw_w); + swaps(&stuff->drw_h); + return XvProcVector[xv_PutVideo] (client); } static int SProcXvPutStill(ClientPtr client) { - REQUEST(xvPutStillReq); - swaps(&stuff->length); - swapl(&stuff->port); - swapl(&stuff->drawable); - swapl(&stuff->gc); - swaps(&stuff->vid_x); - swaps(&stuff->vid_y); - swaps(&stuff->vid_w); - swaps(&stuff->vid_h); - swaps(&stuff->drw_x); - swaps(&stuff->drw_y); - swaps(&stuff->drw_w); - swaps(&stuff->drw_h); - return XvProcVector[xv_PutStill](client); + REQUEST(xvPutStillReq); + swaps(&stuff->length); + swapl(&stuff->port); + swapl(&stuff->drawable); + swapl(&stuff->gc); + swaps(&stuff->vid_x); + swaps(&stuff->vid_y); + swaps(&stuff->vid_w); + swaps(&stuff->vid_h); + swaps(&stuff->drw_x); + swaps(&stuff->drw_y); + swaps(&stuff->drw_w); + swaps(&stuff->drw_h); + return XvProcVector[xv_PutStill] (client); } static int SProcXvGetVideo(ClientPtr client) { - REQUEST(xvGetVideoReq); - swaps(&stuff->length); - swapl(&stuff->port); - swapl(&stuff->drawable); - swapl(&stuff->gc); - swaps(&stuff->vid_x); - swaps(&stuff->vid_y); - swaps(&stuff->vid_w); - swaps(&stuff->vid_h); - swaps(&stuff->drw_x); - swaps(&stuff->drw_y); - swaps(&stuff->drw_w); - swaps(&stuff->drw_h); - return XvProcVector[xv_GetVideo](client); + REQUEST(xvGetVideoReq); + swaps(&stuff->length); + swapl(&stuff->port); + swapl(&stuff->drawable); + swapl(&stuff->gc); + swaps(&stuff->vid_x); + swaps(&stuff->vid_y); + swaps(&stuff->vid_w); + swaps(&stuff->vid_h); + swaps(&stuff->drw_x); + swaps(&stuff->drw_y); + swaps(&stuff->drw_w); + swaps(&stuff->drw_h); + return XvProcVector[xv_GetVideo] (client); } static int SProcXvGetStill(ClientPtr client) { - REQUEST(xvGetStillReq); - swaps(&stuff->length); - swapl(&stuff->port); - swapl(&stuff->drawable); - swapl(&stuff->gc); - swaps(&stuff->vid_x); - swaps(&stuff->vid_y); - swaps(&stuff->vid_w); - swaps(&stuff->vid_h); - swaps(&stuff->drw_x); - swaps(&stuff->drw_y); - swaps(&stuff->drw_w); - swaps(&stuff->drw_h); - return XvProcVector[xv_GetStill](client); + REQUEST(xvGetStillReq); + swaps(&stuff->length); + swapl(&stuff->port); + swapl(&stuff->drawable); + swapl(&stuff->gc); + swaps(&stuff->vid_x); + swaps(&stuff->vid_y); + swaps(&stuff->vid_w); + swaps(&stuff->vid_h); + swaps(&stuff->drw_x); + swaps(&stuff->drw_y); + swaps(&stuff->drw_w); + swaps(&stuff->drw_h); + return XvProcVector[xv_GetStill] (client); } static int SProcXvPutImage(ClientPtr client) { - REQUEST(xvPutImageReq); - swaps(&stuff->length); - swapl(&stuff->port); - swapl(&stuff->drawable); - swapl(&stuff->gc); - swapl(&stuff->id); - swaps(&stuff->src_x); - swaps(&stuff->src_y); - swaps(&stuff->src_w); - swaps(&stuff->src_h); - swaps(&stuff->drw_x); - swaps(&stuff->drw_y); - swaps(&stuff->drw_w); - swaps(&stuff->drw_h); - swaps(&stuff->width); - swaps(&stuff->height); - return XvProcVector[xv_PutImage](client); + REQUEST(xvPutImageReq); + swaps(&stuff->length); + swapl(&stuff->port); + swapl(&stuff->drawable); + swapl(&stuff->gc); + swapl(&stuff->id); + swaps(&stuff->src_x); + swaps(&stuff->src_y); + swaps(&stuff->src_w); + swaps(&stuff->src_h); + swaps(&stuff->drw_x); + swaps(&stuff->drw_y); + swaps(&stuff->drw_w); + swaps(&stuff->drw_h); + swaps(&stuff->width); + swaps(&stuff->height); + return XvProcVector[xv_PutImage] (client); } #ifdef MITSHM static int SProcXvShmPutImage(ClientPtr client) { - REQUEST(xvShmPutImageReq); - swaps(&stuff->length); - swapl(&stuff->port); - swapl(&stuff->drawable); - swapl(&stuff->gc); - swapl(&stuff->shmseg); - swapl(&stuff->id); - swapl(&stuff->offset); - swaps(&stuff->src_x); - swaps(&stuff->src_y); - swaps(&stuff->src_w); - swaps(&stuff->src_h); - swaps(&stuff->drw_x); - swaps(&stuff->drw_y); - swaps(&stuff->drw_w); - swaps(&stuff->drw_h); - swaps(&stuff->width); - swaps(&stuff->height); - return XvProcVector[xv_ShmPutImage](client); -} -#else /* MITSHM */ + REQUEST(xvShmPutImageReq); + swaps(&stuff->length); + swapl(&stuff->port); + swapl(&stuff->drawable); + swapl(&stuff->gc); + swapl(&stuff->shmseg); + swapl(&stuff->id); + swapl(&stuff->offset); + swaps(&stuff->src_x); + swaps(&stuff->src_y); + swaps(&stuff->src_w); + swaps(&stuff->src_h); + swaps(&stuff->drw_x); + swaps(&stuff->drw_y); + swaps(&stuff->drw_w); + swaps(&stuff->drw_h); + swaps(&stuff->width); + swaps(&stuff->height); + return XvProcVector[xv_ShmPutImage] (client); +} +#else /* MITSHM */ #define SProcXvShmPutImage ProcXvShmPutImage #endif static int SProcXvSelectVideoNotify(ClientPtr client) { - REQUEST(xvSelectVideoNotifyReq); - swaps(&stuff->length); - swapl(&stuff->drawable); - return XvProcVector[xv_SelectVideoNotify](client); + REQUEST(xvSelectVideoNotifyReq); + swaps(&stuff->length); + swapl(&stuff->drawable); + return XvProcVector[xv_SelectVideoNotify] (client); } static int SProcXvSelectPortNotify(ClientPtr client) { - REQUEST(xvSelectPortNotifyReq); - swaps(&stuff->length); - swapl(&stuff->port); - return XvProcVector[xv_SelectPortNotify](client); + REQUEST(xvSelectPortNotifyReq); + swaps(&stuff->length); + swapl(&stuff->port); + return XvProcVector[xv_SelectPortNotify] (client); } static int SProcXvStopVideo(ClientPtr client) { - REQUEST(xvStopVideoReq); - swaps(&stuff->length); - swapl(&stuff->port); - swapl(&stuff->drawable); - return XvProcVector[xv_StopVideo](client); + REQUEST(xvStopVideoReq); + swaps(&stuff->length); + swapl(&stuff->port); + swapl(&stuff->drawable); + return XvProcVector[xv_StopVideo] (client); } static int SProcXvSetPortAttribute(ClientPtr client) { - REQUEST(xvSetPortAttributeReq); - swaps(&stuff->length); - swapl(&stuff->port); - swapl(&stuff->attribute); - swapl(&stuff->value); - return XvProcVector[xv_SetPortAttribute](client); + REQUEST(xvSetPortAttributeReq); + swaps(&stuff->length); + swapl(&stuff->port); + swapl(&stuff->attribute); + swapl(&stuff->value); + return XvProcVector[xv_SetPortAttribute] (client); } static int SProcXvGetPortAttribute(ClientPtr client) { - REQUEST(xvGetPortAttributeReq); - swaps(&stuff->length); - swapl(&stuff->port); - swapl(&stuff->attribute); - return XvProcVector[xv_GetPortAttribute](client); + REQUEST(xvGetPortAttributeReq); + swaps(&stuff->length); + swapl(&stuff->port); + swapl(&stuff->attribute); + return XvProcVector[xv_GetPortAttribute] (client); } static int SProcXvQueryBestSize(ClientPtr client) { - REQUEST(xvQueryBestSizeReq); - swaps(&stuff->length); - swapl(&stuff->port); - swaps(&stuff->vid_w); - swaps(&stuff->vid_h); - swaps(&stuff->drw_w); - swaps(&stuff->drw_h); - return XvProcVector[xv_QueryBestSize](client); + REQUEST(xvQueryBestSizeReq); + swaps(&stuff->length); + swapl(&stuff->port); + swaps(&stuff->vid_w); + swaps(&stuff->vid_h); + swaps(&stuff->drw_w); + swaps(&stuff->drw_h); + return XvProcVector[xv_QueryBestSize] (client); } static int SProcXvQueryPortAttributes(ClientPtr client) { - REQUEST(xvQueryPortAttributesReq); - swaps(&stuff->length); - swapl(&stuff->port); - return XvProcVector[xv_QueryPortAttributes](client); + REQUEST(xvQueryPortAttributesReq); + swaps(&stuff->length); + swapl(&stuff->port); + return XvProcVector[xv_QueryPortAttributes] (client); } static int SProcXvQueryImageAttributes(ClientPtr client) { - REQUEST(xvQueryImageAttributesReq); - swaps(&stuff->length); - swapl(&stuff->port); - swapl(&stuff->id); - swaps(&stuff->width); - swaps(&stuff->height); - return XvProcVector[xv_QueryImageAttributes](client); + REQUEST(xvQueryImageAttributesReq); + swaps(&stuff->length); + swapl(&stuff->port); + swapl(&stuff->id); + swaps(&stuff->width); + swaps(&stuff->height); + return XvProcVector[xv_QueryImageAttributes] (client); } static int SProcXvListImageFormats(ClientPtr client) { - REQUEST(xvListImageFormatsReq); - swaps(&stuff->length); - swapl(&stuff->port); - return XvProcVector[xv_ListImageFormats](client); -} - -static int (*SXvProcVector[xvNumRequests])(ClientPtr) = { - SProcXvQueryExtension, - SProcXvQueryAdaptors, - SProcXvQueryEncodings, - SProcXvGrabPort, - SProcXvUngrabPort, - SProcXvPutVideo, - SProcXvPutStill, - SProcXvGetVideo, - SProcXvGetStill, - SProcXvStopVideo, - SProcXvSelectVideoNotify, - SProcXvSelectPortNotify, - SProcXvQueryBestSize, - SProcXvSetPortAttribute, - SProcXvGetPortAttribute, - SProcXvQueryPortAttributes, - SProcXvListImageFormats, - SProcXvQueryImageAttributes, - SProcXvPutImage, - SProcXvShmPutImage, -}; + REQUEST(xvListImageFormatsReq); + swaps(&stuff->length); + swapl(&stuff->port); + return XvProcVector[xv_ListImageFormats] (client); +} + +static int (*SXvProcVector[xvNumRequests]) (ClientPtr) = { +SProcXvQueryExtension, + SProcXvQueryAdaptors, + SProcXvQueryEncodings, + SProcXvGrabPort, + SProcXvUngrabPort, + SProcXvPutVideo, + SProcXvPutStill, + SProcXvGetVideo, + SProcXvGetStill, + SProcXvStopVideo, + SProcXvSelectVideoNotify, + SProcXvSelectPortNotify, + SProcXvQueryBestSize, + SProcXvSetPortAttribute, + SProcXvGetPortAttribute, + SProcXvQueryPortAttributes, + SProcXvListImageFormats, + SProcXvQueryImageAttributes, SProcXvPutImage, SProcXvShmPutImage,}; int SProcXvDispatch(ClientPtr client) { - REQUEST(xReq); + REQUEST(xReq); - UpdateCurrentTime(); + UpdateCurrentTime(); - if (stuff->data >= xvNumRequests) { - SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest); - return BadRequest; - } + if (stuff->data >= xvNumRequests) { + SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest); + return BadRequest; + } - return SXvProcVector[stuff->data](client); + return SXvProcVector[stuff->data] (client); } #ifdef PANORAMIX static int XineramaXvStopVideo(ClientPtr client) { - int result, i; - PanoramiXRes *draw, *port; - REQUEST(xvStopVideoReq); - REQUEST_SIZE_MATCH(xvStopVideoReq); + int result, i; + PanoramiXRes *draw, *port; - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); - if (result != Success) - return (result == BadValue) ? BadDrawable : result; + REQUEST(xvStopVideoReq); + REQUEST_SIZE_MATCH(xvStopVideoReq); - result = dixLookupResourceByType((pointer *)&port, stuff->port, - XvXRTPort, client, DixReadAccess); - if (result != Success) - return result; + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); + if (result != Success) + return (result == BadValue) ? BadDrawable : result; + + result = dixLookupResourceByType((pointer *) &port, stuff->port, + XvXRTPort, client, DixReadAccess); + if (result != Success) + return result; - FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - result = ProcXvStopVideo(client); - } - } + FOR_NSCREENS_BACKWARD(i) { + if (port->info[i].id) { + stuff->drawable = draw->info[i].id; + stuff->port = port->info[i].id; + result = ProcXvStopVideo(client); + } + } - return result; + return result; } static int @@ -1589,22 +1537,22 @@ XineramaXvSetPortAttribute(ClientPtr client) REQUEST_SIZE_MATCH(xvSetPortAttributeReq); - result = dixLookupResourceByType((pointer *)&port, stuff->port, - XvXRTPort, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &port, stuff->port, + XvXRTPort, client, DixReadAccess); if (result != Success) - return result; + return result; FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->port = port->info[i].id; - result = ProcXvSetPortAttribute(client); - } + if (port->info[i].id) { + stuff->port = port->info[i].id; + result = ProcXvSetPortAttribute(client); + } } return result; } #ifdef MITSHM -static int +static int XineramaXvShmPutImage(ClientPtr client) { REQUEST(xvShmPutImageReq); @@ -1615,41 +1563,41 @@ XineramaXvShmPutImage(ClientPtr client) REQUEST_SIZE_MATCH(xvShmPutImageReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, - XRT_GC, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, + XRT_GC, client, DixReadAccess); if (result != Success) return result; - result = dixLookupResourceByType((pointer *)&port, stuff->port, - XvXRTPort, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &port, stuff->port, + XvXRTPort, client, DixReadAccess); if (result != Success) - return result; - + return result; + isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; x = stuff->drw_x; y = stuff->drw_y; FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= screenInfo.screens[i]->x; - stuff->drw_y -= screenInfo.screens[i]->y; - } - stuff->send_event = (send_event && !i) ? 1 : 0; - - result = ProcXvShmPutImage(client); - } + if (port->info[i].id) { + stuff->drawable = draw->info[i].id; + stuff->port = port->info[i].id; + stuff->gc = gc->info[i].id; + stuff->drw_x = x; + stuff->drw_y = y; + if (isRoot) { + stuff->drw_x -= screenInfo.screens[i]->x; + stuff->drw_y -= screenInfo.screens[i]->y; + } + stuff->send_event = (send_event && !i) ? 1 : 0; + + result = ProcXvShmPutImage(client); + } } return result; } @@ -1657,7 +1605,7 @@ XineramaXvShmPutImage(ClientPtr client) #define XineramaXvShmPutImage ProcXvShmPutImage #endif -static int +static int XineramaXvPutImage(ClientPtr client) { REQUEST(xvPutImageReq); @@ -1667,40 +1615,40 @@ XineramaXvPutImage(ClientPtr client) REQUEST_AT_LEAST_SIZE(xvPutImageReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, - XRT_GC, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, + XRT_GC, client, DixReadAccess); if (result != Success) return result; - result = dixLookupResourceByType((pointer *)&port, stuff->port, - XvXRTPort, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &port, stuff->port, + XvXRTPort, client, DixReadAccess); if (result != Success) - return result; - + return result; + isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; x = stuff->drw_x; y = stuff->drw_y; FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { - stuff->drw_x -= screenInfo.screens[i]->x; - stuff->drw_y -= screenInfo.screens[i]->y; - } - - result = ProcXvPutImage(client); - } + if (port->info[i].id) { + stuff->drawable = draw->info[i].id; + stuff->port = port->info[i].id; + stuff->gc = gc->info[i].id; + stuff->drw_x = x; + stuff->drw_y = y; + if (isRoot) { + stuff->drw_x -= screenInfo.screens[i]->x; + stuff->drw_y -= screenInfo.screens[i]->y; + } + + result = ProcXvPutImage(client); + } } return result; } @@ -1715,20 +1663,20 @@ XineramaXvPutVideo(ClientPtr client) REQUEST_AT_LEAST_SIZE(xvPutVideoReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, - XRT_GC, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, + XRT_GC, client, DixReadAccess); if (result != Success) return result; - result = dixLookupResourceByType((pointer *)&port, stuff->port, - XvXRTPort, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &port, stuff->port, + XvXRTPort, client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; @@ -1736,18 +1684,18 @@ XineramaXvPutVideo(ClientPtr client) y = stuff->drw_y; FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { + if (port->info[i].id) { + stuff->drawable = draw->info[i].id; + stuff->port = port->info[i].id; + stuff->gc = gc->info[i].id; + stuff->drw_x = x; + stuff->drw_y = y; + if (isRoot) { stuff->drw_x -= screenInfo.screens[i]->x; stuff->drw_y -= screenInfo.screens[i]->y; - } + } - result = ProcXvPutVideo(client); + result = ProcXvPutVideo(client); } } return result; @@ -1763,20 +1711,20 @@ XineramaXvPutStill(ClientPtr client) REQUEST_AT_LEAST_SIZE(xvPutImageReq); - result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable, - XRC_DRAWABLE, client, DixWriteAccess); + result = dixLookupResourceByClass((pointer *) &draw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) - return (result == BadValue) ? BadDrawable : result; + return (result == BadValue) ? BadDrawable : result; - result = dixLookupResourceByType((pointer *)&gc, stuff->gc, - XRT_GC, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &gc, stuff->gc, + XRT_GC, client, DixReadAccess); if (result != Success) return result; - result = dixLookupResourceByType((pointer *)&port, stuff->port, - XvXRTPort, client, DixReadAccess); + result = dixLookupResourceByType((pointer *) &port, stuff->port, + XvXRTPort, client, DixReadAccess); if (result != Success) - return result; + return result; isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; @@ -1784,18 +1732,18 @@ XineramaXvPutStill(ClientPtr client) y = stuff->drw_y; FOR_NSCREENS_BACKWARD(i) { - if(port->info[i].id) { - stuff->drawable = draw->info[i].id; - stuff->port = port->info[i].id; - stuff->gc = gc->info[i].id; - stuff->drw_x = x; - stuff->drw_y = y; - if(isRoot) { + if (port->info[i].id) { + stuff->drawable = draw->info[i].id; + stuff->port = port->info[i].id; + stuff->gc = gc->info[i].id; + stuff->drw_x = x; + stuff->drw_y = y; + if (isRoot) { stuff->drw_x -= screenInfo.screens[i]->x; stuff->drw_y -= screenInfo.screens[i]->y; - } + } - result = ProcXvPutStill(client); + result = ProcXvPutStill(client); } } return result; @@ -1811,9 +1759,10 @@ static Bool hasOverlay(XvAdaptorPtr pAdapt) { int i; - for(i = 0; i < pAdapt->nAttributes; i++) - if(!strcmp(pAdapt->pAttributes[i].name, "XV_COLORKEY")) - return TRUE; + + for (i = 0; i < pAdapt->nAttributes; i++) + if (!strcmp(pAdapt->pAttributes[i].name, "XV_COLORKEY")) + return TRUE; return FALSE; } @@ -1821,94 +1770,105 @@ static XvAdaptorPtr matchAdaptor(ScreenPtr pScreen, XvAdaptorPtr refAdapt, Bool isOverlay) { int i; - XvScreenPtr xvsp = dixLookupPrivate(&pScreen->devPrivates, XvGetScreenKey()); + XvScreenPtr xvsp = + dixLookupPrivate(&pScreen->devPrivates, XvGetScreenKey()); /* Do not try to go on if xv is not supported on this screen */ - if(xvsp == NULL) - return NULL; + if (xvsp == NULL) + return NULL; /* if the adaptor has the same name it's a perfect match */ - for(i = 0; i < xvsp->nAdaptors; i++) { - XvAdaptorPtr pAdapt = xvsp->pAdaptors + i; - if(!strcmp(refAdapt->name, pAdapt->name)) - return pAdapt; + for (i = 0; i < xvsp->nAdaptors; i++) { + XvAdaptorPtr pAdapt = xvsp->pAdaptors + i; + + if (!strcmp(refAdapt->name, pAdapt->name)) + return pAdapt; } /* otherwise we only look for XvImage adaptors */ - if(!isImageAdaptor(refAdapt)) - return NULL; + if (!isImageAdaptor(refAdapt)) + return NULL; /* prefer overlay/overlay non-overlay/non-overlay pairing */ - for(i = 0; i < xvsp->nAdaptors; i++) { - XvAdaptorPtr pAdapt = xvsp->pAdaptors + i; - if(isImageAdaptor(pAdapt) && isOverlay == hasOverlay(pAdapt)) - return pAdapt; + for (i = 0; i < xvsp->nAdaptors; i++) { + XvAdaptorPtr pAdapt = xvsp->pAdaptors + i; + + if (isImageAdaptor(pAdapt) && isOverlay == hasOverlay(pAdapt)) + return pAdapt; } /* but we'll take any XvImage pairing if we can get it */ - for(i = 0; i < xvsp->nAdaptors; i++) { - XvAdaptorPtr pAdapt = xvsp->pAdaptors + i; - if(isImageAdaptor(pAdapt)) - return pAdapt; + for (i = 0; i < xvsp->nAdaptors; i++) { + XvAdaptorPtr pAdapt = xvsp->pAdaptors + i; + + if (isImageAdaptor(pAdapt)) + return pAdapt; } return NULL; } -void XineramifyXv(void) +void +XineramifyXv(void) { - XvScreenPtr xvsp0 = dixLookupPrivate(&screenInfo.screens[0]->devPrivates, XvGetScreenKey()); - XvAdaptorPtr MatchingAdaptors[MAXSCREENS]; - int i, j, k; - - XvXRTPort = CreateNewResourceType(XineramaDeleteResource, "XvXRTPort"); - - if (!xvsp0 || !XvXRTPort) return; - SetResourceTypeErrorValue(XvXRTPort, _XvBadPort); - - for(i = 0; i < xvsp0->nAdaptors; i++) { - Bool isOverlay; - XvAdaptorPtr refAdapt = xvsp0->pAdaptors + i; - if(!(refAdapt->type & XvInputMask)) continue; - - MatchingAdaptors[0] = refAdapt; - isOverlay = hasOverlay(refAdapt); - FOR_NSCREENS_FORWARD_SKIP(j) - MatchingAdaptors[j] = matchAdaptor(screenInfo.screens[j], refAdapt, isOverlay); - - /* now create a resource for each port */ - for(j = 0; j < refAdapt->nPorts; j++) { - PanoramiXRes *port = malloc(sizeof(PanoramiXRes)); - if(!port) - break; - - FOR_NSCREENS(k) { - if(MatchingAdaptors[k] && (MatchingAdaptors[k]->nPorts > j)) - port->info[k].id = MatchingAdaptors[k]->base_id + j; - else - port->info[k].id = 0; - } - AddResource(port->info[0].id, XvXRTPort, port); - } - } + XvScreenPtr xvsp0 = + dixLookupPrivate(&screenInfo.screens[0]->devPrivates, XvGetScreenKey()); + XvAdaptorPtr MatchingAdaptors[MAXSCREENS]; + int i, j, k; + + XvXRTPort = CreateNewResourceType(XineramaDeleteResource, "XvXRTPort"); + + if (!xvsp0 || !XvXRTPort) + return; + SetResourceTypeErrorValue(XvXRTPort, _XvBadPort); + + for (i = 0; i < xvsp0->nAdaptors; i++) { + Bool isOverlay; + XvAdaptorPtr refAdapt = xvsp0->pAdaptors + i; + + if (!(refAdapt->type & XvInputMask)) + continue; + + MatchingAdaptors[0] = refAdapt; + isOverlay = hasOverlay(refAdapt); + FOR_NSCREENS_FORWARD_SKIP(j) + MatchingAdaptors[j] = + matchAdaptor(screenInfo.screens[j], refAdapt, isOverlay); + + /* now create a resource for each port */ + for (j = 0; j < refAdapt->nPorts; j++) { + PanoramiXRes *port = malloc(sizeof(PanoramiXRes)); + + if (!port) + break; + + FOR_NSCREENS(k) { + if (MatchingAdaptors[k] && (MatchingAdaptors[k]->nPorts > j)) + port->info[k].id = MatchingAdaptors[k]->base_id + j; + else + port->info[k].id = 0; + } + AddResource(port->info[0].id, XvXRTPort, port); + } + } - /* munge the dispatch vector */ - XvProcVector[xv_PutVideo] = XineramaXvPutVideo; - XvProcVector[xv_PutStill] = XineramaXvPutStill; - XvProcVector[xv_StopVideo] = XineramaXvStopVideo; - XvProcVector[xv_SetPortAttribute] = XineramaXvSetPortAttribute; - XvProcVector[xv_PutImage] = XineramaXvPutImage; - XvProcVector[xv_ShmPutImage] = XineramaXvShmPutImage; + /* munge the dispatch vector */ + XvProcVector[xv_PutVideo] = XineramaXvPutVideo; + XvProcVector[xv_PutStill] = XineramaXvPutStill; + XvProcVector[xv_StopVideo] = XineramaXvStopVideo; + XvProcVector[xv_SetPortAttribute] = XineramaXvSetPortAttribute; + XvProcVector[xv_PutImage] = XineramaXvPutImage; + XvProcVector[xv_ShmPutImage] = XineramaXvShmPutImage; } -#endif /* PANORAMIX */ +#endif /* PANORAMIX */ void XvResetProcVector(void) { #ifdef PANORAMIX - XvProcVector[xv_PutVideo] = ProcXvPutVideo; - XvProcVector[xv_PutStill] = ProcXvPutStill; - XvProcVector[xv_StopVideo] = ProcXvStopVideo; - XvProcVector[xv_SetPortAttribute] = ProcXvSetPortAttribute; - XvProcVector[xv_PutImage] = ProcXvPutImage; - XvProcVector[xv_ShmPutImage] = ProcXvShmPutImage; + XvProcVector[xv_PutVideo] = ProcXvPutVideo; + XvProcVector[xv_PutStill] = ProcXvPutStill; + XvProcVector[xv_StopVideo] = ProcXvStopVideo; + XvProcVector[xv_SetPortAttribute] = ProcXvSetPortAttribute; + XvProcVector[xv_PutImage] = ProcXvPutImage; + XvProcVector[xv_ShmPutImage] = ProcXvShmPutImage; #endif } diff --git a/xorg-server/Xext/xvdix.h b/xorg-server/Xext/xvdix.h index e9c22bf65..d22672620 100644 --- a/xorg-server/Xext/xvdix.h +++ b/xorg-server/Xext/xvdix.h @@ -73,132 +73,131 @@ extern _X_EXPORT RESTYPE XvRTPortNotify; #endif typedef struct { - int numerator; - int denominator; + int numerator; + int denominator; } XvRationalRec, *XvRationalPtr; typedef struct { - char depth; - unsigned long visual; + char depth; + unsigned long visual; } XvFormatRec, *XvFormatPtr; typedef struct { - unsigned long id; - ClientPtr client; + unsigned long id; + ClientPtr client; } XvGrabRec, *XvGrabPtr; typedef struct _XvVideoNotifyRec { - struct _XvVideoNotifyRec *next; - ClientPtr client; - unsigned long id; - unsigned long mask; + struct _XvVideoNotifyRec *next; + ClientPtr client; + unsigned long id; + unsigned long mask; } XvVideoNotifyRec, *XvVideoNotifyPtr; typedef struct _XvPortNotifyRec { - struct _XvPortNotifyRec *next; - ClientPtr client; - unsigned long id; + struct _XvPortNotifyRec *next; + ClientPtr client; + unsigned long id; } XvPortNotifyRec, *XvPortNotifyPtr; typedef struct { - int id; - ScreenPtr pScreen; - char *name; - unsigned short width, height; - XvRationalRec rate; + int id; + ScreenPtr pScreen; + char *name; + unsigned short width, height; + XvRationalRec rate; } XvEncodingRec, *XvEncodingPtr; typedef struct _XvAttributeRec { - int flags; - int min_value; - int max_value; - char *name; + int flags; + int min_value; + int max_value; + char *name; } XvAttributeRec, *XvAttributePtr; typedef struct { - int id; - int type; - int byte_order; - char guid[16]; - int bits_per_pixel; - int format; - int num_planes; - - /* for RGB formats only */ - int depth; - unsigned int red_mask; - unsigned int green_mask; - unsigned int blue_mask; - - /* for YUV formats only */ - unsigned int y_sample_bits; - unsigned int u_sample_bits; - unsigned int v_sample_bits; - unsigned int horz_y_period; - unsigned int horz_u_period; - unsigned int horz_v_period; - unsigned int vert_y_period; - unsigned int vert_u_period; - unsigned int vert_v_period; - char component_order[32]; - int scanline_order; -} XvImageRec, *XvImagePtr; + int id; + int type; + int byte_order; + char guid[16]; + int bits_per_pixel; + int format; + int num_planes; + + /* for RGB formats only */ + int depth; + unsigned int red_mask; + unsigned int green_mask; + unsigned int blue_mask; + + /* for YUV formats only */ + unsigned int y_sample_bits; + unsigned int u_sample_bits; + unsigned int v_sample_bits; + unsigned int horz_y_period; + unsigned int horz_u_period; + unsigned int horz_v_period; + unsigned int vert_y_period; + unsigned int vert_u_period; + unsigned int vert_v_period; + char component_order[32]; + int scanline_order; +} XvImageRec, *XvImagePtr; typedef struct { - unsigned long base_id; - unsigned char type; - char *name; - int nEncodings; - XvEncodingPtr pEncodings; - int nFormats; - XvFormatPtr pFormats; - int nAttributes; - XvAttributePtr pAttributes; - int nImages; - XvImagePtr pImages; - int nPorts; - struct _XvPortRec *pPorts; - ScreenPtr pScreen; - int (* ddAllocatePort)(unsigned long, struct _XvPortRec*, - struct _XvPortRec**); - int (* ddFreePort)(struct _XvPortRec*); - int (* ddPutVideo)(ClientPtr, DrawablePtr,struct _XvPortRec*, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); - int (* ddPutStill)(ClientPtr, DrawablePtr,struct _XvPortRec*, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); - int (* ddGetVideo)(ClientPtr, DrawablePtr,struct _XvPortRec*, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); - int (* ddGetStill)(ClientPtr, DrawablePtr,struct _XvPortRec*, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); - int (* ddStopVideo)(ClientPtr, struct _XvPortRec*, DrawablePtr); - int (* ddSetPortAttribute)(ClientPtr, struct _XvPortRec*, Atom, INT32); - int (* ddGetPortAttribute)(ClientPtr, struct _XvPortRec*, Atom, INT32*); - int (* ddQueryBestSize)(ClientPtr, struct _XvPortRec*, CARD8, - CARD16, CARD16,CARD16, CARD16, - unsigned int*, unsigned int*); - int (* ddPutImage)(ClientPtr, DrawablePtr, struct _XvPortRec*, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16, - XvImagePtr, unsigned char*, Bool, - CARD16, CARD16); - int (* ddQueryImageAttributes)(ClientPtr, struct _XvPortRec*, XvImagePtr, - CARD16*, CARD16*, int*, int*); - DevUnion devPriv; + unsigned long base_id; + unsigned char type; + char *name; + int nEncodings; + XvEncodingPtr pEncodings; + int nFormats; + XvFormatPtr pFormats; + int nAttributes; + XvAttributePtr pAttributes; + int nImages; + XvImagePtr pImages; + int nPorts; + struct _XvPortRec *pPorts; + ScreenPtr pScreen; + int (*ddAllocatePort) (unsigned long, struct _XvPortRec *, + struct _XvPortRec **); + int (*ddFreePort) (struct _XvPortRec *); + int (*ddPutVideo) (ClientPtr, DrawablePtr, struct _XvPortRec *, GCPtr, + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16); + int (*ddPutStill) (ClientPtr, DrawablePtr, struct _XvPortRec *, GCPtr, + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16); + int (*ddGetVideo) (ClientPtr, DrawablePtr, struct _XvPortRec *, GCPtr, + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16); + int (*ddGetStill) (ClientPtr, DrawablePtr, struct _XvPortRec *, GCPtr, + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16); + int (*ddStopVideo) (ClientPtr, struct _XvPortRec *, DrawablePtr); + int (*ddSetPortAttribute) (ClientPtr, struct _XvPortRec *, Atom, INT32); + int (*ddGetPortAttribute) (ClientPtr, struct _XvPortRec *, Atom, INT32 *); + int (*ddQueryBestSize) (ClientPtr, struct _XvPortRec *, CARD8, + CARD16, CARD16, CARD16, CARD16, + unsigned int *, unsigned int *); + int (*ddPutImage) (ClientPtr, DrawablePtr, struct _XvPortRec *, GCPtr, + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16, + XvImagePtr, unsigned char *, Bool, CARD16, CARD16); + int (*ddQueryImageAttributes) (ClientPtr, struct _XvPortRec *, XvImagePtr, + CARD16 *, CARD16 *, int *, int *); + DevUnion devPriv; } XvAdaptorRec, *XvAdaptorPtr; typedef struct _XvPortRec { - unsigned long id; - XvAdaptorPtr pAdaptor; - XvPortNotifyPtr pNotify; - DrawablePtr pDraw; - ClientPtr client; - XvGrabRec grab; - TimeStamp time; - DevUnion devPriv; + unsigned long id; + XvAdaptorPtr pAdaptor; + XvPortNotifyPtr pNotify; + DrawablePtr pDraw; + ClientPtr client; + XvGrabRec grab; + TimeStamp time; + DevUnion devPriv; } XvPortRec, *XvPortPtr; #define VALIDATE_XV_PORT(portID, pPort, mode)\ @@ -210,15 +209,15 @@ typedef struct _XvPortRec { } typedef struct { - int version, revision; - int nAdaptors; - XvAdaptorPtr pAdaptors; - DestroyWindowProcPtr DestroyWindow; - DestroyPixmapProcPtr DestroyPixmap; - CloseScreenProcPtr CloseScreen; - Bool (* ddCloseScreen)(int, ScreenPtr); - int (* ddQueryAdaptors)(ScreenPtr, XvAdaptorPtr*, int*); - DevUnion devPriv; + int version, revision; + int nAdaptors; + XvAdaptorPtr pAdaptors; + DestroyWindowProcPtr DestroyWindow; + DestroyPixmapProcPtr DestroyPixmap; + CloseScreenProcPtr CloseScreen; + Bool (*ddCloseScreen) (int, ScreenPtr); + int (*ddQueryAdaptors) (ScreenPtr, XvAdaptorPtr *, int *); + DevUnion devPriv; } XvScreenRec, *XvScreenPtr; #define SCREEN_PROLOGUE(pScreen, field) ((pScreen)->field = ((XvScreenPtr) \ @@ -244,32 +243,31 @@ extern _X_EXPORT int XvdiSendPortNotify(XvPortPtr, Atom, INT32); extern _X_EXPORT int XvdiVideoStopped(XvPortPtr, int); extern _X_EXPORT int XvdiPutVideo(ClientPtr, DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16); extern _X_EXPORT int XvdiPutStill(ClientPtr, DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16); extern _X_EXPORT int XvdiGetVideo(ClientPtr, DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16); extern _X_EXPORT int XvdiGetStill(ClientPtr, DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16); extern _X_EXPORT int XvdiPutImage(ClientPtr, DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16, - XvImagePtr, unsigned char*, Bool, - CARD16, CARD16); + INT16, INT16, CARD16, CARD16, + INT16, INT16, CARD16, CARD16, + XvImagePtr, unsigned char *, Bool, + CARD16, CARD16); extern _X_EXPORT int XvdiSelectVideoNotify(ClientPtr, DrawablePtr, BOOL); extern _X_EXPORT int XvdiSelectPortNotify(ClientPtr, XvPortPtr, BOOL); extern _X_EXPORT int XvdiSetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32); -extern _X_EXPORT int XvdiGetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32*); +extern _X_EXPORT int XvdiGetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32 *); extern _X_EXPORT int XvdiStopVideo(ClientPtr, XvPortPtr, DrawablePtr); extern _X_EXPORT int XvdiPreemptVideo(ClientPtr, XvPortPtr, DrawablePtr); extern _X_EXPORT int XvdiMatchPort(XvPortPtr, DrawablePtr); extern _X_EXPORT int XvdiGrabPort(ClientPtr, XvPortPtr, Time, int *); -extern _X_EXPORT int XvdiUngrabPort( ClientPtr, XvPortPtr, Time); -#endif /* XorgLoader */ - -#endif /* XVDIX_H */ +extern _X_EXPORT int XvdiUngrabPort(ClientPtr, XvPortPtr, Time); +#endif /* XorgLoader */ +#endif /* XVDIX_H */ diff --git a/xorg-server/Xext/xvmain.c b/xorg-server/Xext/xvmain.c index a530a1b77..28f2a56df 100644 --- a/xorg-server/Xext/xvmain.c +++ b/xorg-server/Xext/xvmain.c @@ -106,6 +106,7 @@ SOFTWARE. #include "xvdisp.h" static DevPrivateKeyRec XvScreenKeyRec; + #define XvScreenKey (&XvScreenKeyRec) unsigned long XvExtensionGeneration = 0; unsigned long XvScreenGeneration = 0; @@ -131,7 +132,7 @@ static Bool CreateResourceTypes(void); static Bool XvCloseScreen(int, ScreenPtr); static Bool XvDestroyPixmap(PixmapPtr); static Bool XvDestroyWindow(WindowPtr); -static void XvResetProc(ExtensionEntry*); +static void XvResetProc(ExtensionEntry *); static int XvdiDestroyGrab(pointer, XID); static int XvdiDestroyEncoding(pointer, XID); static int XvdiDestroyVideoNotify(pointer, XID); @@ -140,9 +141,6 @@ static int XvdiDestroyVideoNotifyList(pointer, XID); static int XvdiDestroyPort(pointer, XID); static int XvdiSendVideoNotify(XvPortPtr, DrawablePtr, int); - - - /* ** XvExtensionInit ** @@ -152,179 +150,168 @@ static int XvdiSendVideoNotify(XvPortPtr, DrawablePtr, int); void XvExtensionInit(void) { - ExtensionEntry *extEntry; - - if (!dixRegisterPrivateKey(&XvScreenKeyRec, PRIVATE_SCREEN, 0)) - return; - - /* LOOK TO SEE IF ANY SCREENS WERE INITIALIZED; IF NOT THEN - INIT GLOBAL VARIABLES SO THE EXTENSION CAN FUNCTION */ - if (XvScreenGeneration != serverGeneration) - { - if (!CreateResourceTypes()) - { - ErrorF("XvExtensionInit: Unable to allocate resource types\n"); - return; - } + ExtensionEntry *extEntry; + + if (!dixRegisterPrivateKey(&XvScreenKeyRec, PRIVATE_SCREEN, 0)) + return; + + /* LOOK TO SEE IF ANY SCREENS WERE INITIALIZED; IF NOT THEN + INIT GLOBAL VARIABLES SO THE EXTENSION CAN FUNCTION */ + if (XvScreenGeneration != serverGeneration) { + if (!CreateResourceTypes()) { + ErrorF("XvExtensionInit: Unable to allocate resource types\n"); + return; + } #ifdef PANORAMIX XineramaRegisterConnectionBlockCallback(XineramifyXv); #endif - XvScreenGeneration = serverGeneration; + XvScreenGeneration = serverGeneration; } - if (XvExtensionGeneration != serverGeneration) - { - XvExtensionGeneration = serverGeneration; + if (XvExtensionGeneration != serverGeneration) { + XvExtensionGeneration = serverGeneration; - extEntry = AddExtension(XvName, XvNumEvents, XvNumErrors, - ProcXvDispatch, SProcXvDispatch, - XvResetProc, StandardMinorOpcode); - if (!extEntry) - { - FatalError("XvExtensionInit: AddExtensions failed\n"); - } + extEntry = AddExtension(XvName, XvNumEvents, XvNumErrors, + ProcXvDispatch, SProcXvDispatch, + XvResetProc, StandardMinorOpcode); + if (!extEntry) { + FatalError("XvExtensionInit: AddExtensions failed\n"); + } - XvReqCode = extEntry->base; - XvEventBase = extEntry->eventBase; - XvErrorBase = extEntry->errorBase; + XvReqCode = extEntry->base; + XvEventBase = extEntry->eventBase; + XvErrorBase = extEntry->errorBase; - EventSwapVector[XvEventBase+XvVideoNotify] = - (EventSwapPtr)WriteSwappedVideoNotifyEvent; - EventSwapVector[XvEventBase+XvPortNotify] = - (EventSwapPtr)WriteSwappedPortNotifyEvent; + EventSwapVector[XvEventBase + XvVideoNotify] = + (EventSwapPtr) WriteSwappedVideoNotifyEvent; + EventSwapVector[XvEventBase + XvPortNotify] = + (EventSwapPtr) WriteSwappedPortNotifyEvent; - SetResourceTypeErrorValue(XvRTPort, _XvBadPort); - (void)MakeAtom(XvName, strlen(XvName), xTrue); + SetResourceTypeErrorValue(XvRTPort, _XvBadPort); + (void) MakeAtom(XvName, strlen(XvName), xTrue); } } static Bool CreateResourceTypes(void) - { - - if (XvResourceGeneration == serverGeneration) return TRUE; - XvResourceGeneration = serverGeneration; + if (XvResourceGeneration == serverGeneration) + return TRUE; + + XvResourceGeneration = serverGeneration; - if (!(XvRTPort = CreateNewResourceType(XvdiDestroyPort, "XvRTPort"))) - { - ErrorF("CreateResourceTypes: failed to allocate port resource.\n"); - return FALSE; + if (!(XvRTPort = CreateNewResourceType(XvdiDestroyPort, "XvRTPort"))) { + ErrorF("CreateResourceTypes: failed to allocate port resource.\n"); + return FALSE; } - if (!(XvRTGrab = CreateNewResourceType(XvdiDestroyGrab, "XvRTGrab"))) - { - ErrorF("CreateResourceTypes: failed to allocate grab resource.\n"); - return FALSE; + if (!(XvRTGrab = CreateNewResourceType(XvdiDestroyGrab, "XvRTGrab"))) { + ErrorF("CreateResourceTypes: failed to allocate grab resource.\n"); + return FALSE; } - if (!(XvRTEncoding = CreateNewResourceType(XvdiDestroyEncoding, - "XvRTEncoding"))) - { - ErrorF("CreateResourceTypes: failed to allocate encoding resource.\n"); - return FALSE; + if (!(XvRTEncoding = CreateNewResourceType(XvdiDestroyEncoding, + "XvRTEncoding"))) { + ErrorF("CreateResourceTypes: failed to allocate encoding resource.\n"); + return FALSE; } - if (!(XvRTVideoNotify = CreateNewResourceType(XvdiDestroyVideoNotify, - "XvRTVideoNotify"))) - { - ErrorF("CreateResourceTypes: failed to allocate video notify resource.\n"); - return FALSE; + if (!(XvRTVideoNotify = CreateNewResourceType(XvdiDestroyVideoNotify, + "XvRTVideoNotify"))) { + ErrorF + ("CreateResourceTypes: failed to allocate video notify resource.\n"); + return FALSE; } - if (!(XvRTVideoNotifyList = CreateNewResourceType(XvdiDestroyVideoNotifyList, - "XvRTVideoNotifyList"))) - { - ErrorF("CreateResourceTypes: failed to allocate video notify list resource.\n"); - return FALSE; + if (! + (XvRTVideoNotifyList = + CreateNewResourceType(XvdiDestroyVideoNotifyList, + "XvRTVideoNotifyList"))) { + ErrorF + ("CreateResourceTypes: failed to allocate video notify list resource.\n"); + return FALSE; } - if (!(XvRTPortNotify = CreateNewResourceType(XvdiDestroyPortNotify, - "XvRTPortNotify"))) - { - ErrorF("CreateResourceTypes: failed to allocate port notify resource.\n"); - return FALSE; + if (!(XvRTPortNotify = CreateNewResourceType(XvdiDestroyPortNotify, + "XvRTPortNotify"))) { + ErrorF + ("CreateResourceTypes: failed to allocate port notify resource.\n"); + return FALSE; } - return TRUE; + return TRUE; } int XvScreenInit(ScreenPtr pScreen) { - XvScreenPtr pxvs; - - if (XvScreenGeneration != serverGeneration) - { - if (!CreateResourceTypes()) - { - ErrorF("XvScreenInit: Unable to allocate resource types\n"); - return BadAlloc; - } + XvScreenPtr pxvs; + + if (XvScreenGeneration != serverGeneration) { + if (!CreateResourceTypes()) { + ErrorF("XvScreenInit: Unable to allocate resource types\n"); + return BadAlloc; + } #ifdef PANORAMIX XineramaRegisterConnectionBlockCallback(XineramifyXv); #endif - XvScreenGeneration = serverGeneration; + XvScreenGeneration = serverGeneration; } - if (!dixRegisterPrivateKey(&XvScreenKeyRec, PRIVATE_SCREEN, 0)) - return BadAlloc; + if (!dixRegisterPrivateKey(&XvScreenKeyRec, PRIVATE_SCREEN, 0)) + return BadAlloc; - if (dixLookupPrivate(&pScreen->devPrivates, XvScreenKey)) - { - ErrorF("XvScreenInit: screen devPrivates ptr non-NULL before init\n"); + if (dixLookupPrivate(&pScreen->devPrivates, XvScreenKey)) { + ErrorF("XvScreenInit: screen devPrivates ptr non-NULL before init\n"); } - /* ALLOCATE SCREEN PRIVATE RECORD */ - - pxvs = calloc (1,sizeof (XvScreenRec)); - if (!pxvs) - { - ErrorF("XvScreenInit: Unable to allocate screen private structure\n"); - return BadAlloc; + /* ALLOCATE SCREEN PRIVATE RECORD */ + + pxvs = calloc(1,sizeof(XvScreenRec)); + if (!pxvs) { + ErrorF("XvScreenInit: Unable to allocate screen private structure\n"); + return BadAlloc; } - dixSetPrivate(&pScreen->devPrivates, XvScreenKey, pxvs); - - pxvs->DestroyPixmap = pScreen->DestroyPixmap; - pxvs->DestroyWindow = pScreen->DestroyWindow; - pxvs->CloseScreen = pScreen->CloseScreen; - - pScreen->DestroyPixmap = XvDestroyPixmap; - pScreen->DestroyWindow = XvDestroyWindow; - pScreen->CloseScreen = XvCloseScreen; - - return Success; + dixSetPrivate(&pScreen->devPrivates, XvScreenKey, pxvs); + + pxvs->DestroyPixmap = pScreen->DestroyPixmap; + pxvs->DestroyWindow = pScreen->DestroyWindow; + pxvs->CloseScreen = pScreen->CloseScreen; + + pScreen->DestroyPixmap = XvDestroyPixmap; + pScreen->DestroyWindow = XvDestroyWindow; + pScreen->CloseScreen = XvCloseScreen; + + return Success; } static Bool -XvCloseScreen( - int ii, - ScreenPtr pScreen -){ +XvCloseScreen(int ii, ScreenPtr pScreen) +{ - XvScreenPtr pxvs; + XvScreenPtr pxvs; - pxvs = (XvScreenPtr)dixLookupPrivate(&pScreen->devPrivates, XvScreenKey); + pxvs = (XvScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XvScreenKey); - pScreen->DestroyPixmap = pxvs->DestroyPixmap; - pScreen->DestroyWindow = pxvs->DestroyWindow; - pScreen->CloseScreen = pxvs->CloseScreen; + pScreen->DestroyPixmap = pxvs->DestroyPixmap; + pScreen->DestroyWindow = pxvs->DestroyWindow; + pScreen->CloseScreen = pxvs->CloseScreen; - if (pxvs->ddCloseScreen) (* pxvs->ddCloseScreen)(ii, pScreen); + if (pxvs->ddCloseScreen) (*pxvs->ddCloseScreen) (ii, pScreen); - free(pxvs); + free(pxvs); - dixSetPrivate(&pScreen->devPrivates, XvScreenKey, NULL); + dixSetPrivate(&pScreen->devPrivates, XvScreenKey, NULL); - return (*pScreen->CloseScreen)(ii, pScreen); + return (*pScreen->CloseScreen) (ii, pScreen); } static void -XvResetProc(ExtensionEntry* extEntry) +XvResetProc(ExtensionEntry * extEntry) { XvResetProcVector(); } @@ -338,109 +325,102 @@ XvGetScreenKey(void) unsigned long XvGetRTPort(void) { - return XvRTPort; + return XvRTPort; } static Bool XvDestroyPixmap(PixmapPtr pPix) { - Bool status; - ScreenPtr pScreen; - XvScreenPtr pxvs; - XvAdaptorPtr pa; - int na; - XvPortPtr pp; - int np; - - pScreen = pPix->drawable.pScreen; - - SCREEN_PROLOGUE(pScreen, DestroyPixmap); - - pxvs = (XvScreenPtr)dixLookupPrivate(&pScreen->devPrivates, XvScreenKey); - - /* CHECK TO SEE IF THIS PORT IS IN USE */ - - pa = pxvs->pAdaptors; - na = pxvs->nAdaptors; - while (na--) - { - np = pa->nPorts; - pp = pa->pPorts; - - while (np--) - { - if (pp->pDraw == (DrawablePtr)pPix) - { - XvdiSendVideoNotify(pp, pp->pDraw, XvPreempted); - - (void)(* pp->pAdaptor->ddStopVideo)(NULL, pp, pp->pDraw); - - pp->pDraw = NULL; - pp->client = NULL; - pp->time = currentTime; - } - pp++; - } - pa++; + Bool status; + ScreenPtr pScreen; + XvScreenPtr pxvs; + XvAdaptorPtr pa; + int na; + XvPortPtr pp; + int np; + + pScreen = pPix->drawable.pScreen; + + SCREEN_PROLOGUE(pScreen, DestroyPixmap); + + pxvs = (XvScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XvScreenKey); + + /* CHECK TO SEE IF THIS PORT IS IN USE */ + + pa = pxvs->pAdaptors; + na = pxvs->nAdaptors; + while (na--) { + np = pa->nPorts; + pp = pa->pPorts; + + while (np--) { + if (pp->pDraw == (DrawablePtr) pPix) { + XvdiSendVideoNotify(pp, pp->pDraw, XvPreempted); + + (void) (*pp->pAdaptor->ddStopVideo) (NULL, pp, pp->pDraw); + + pp->pDraw = NULL; + pp->client = NULL; + pp->time = currentTime; + } + pp++; + } + pa++; } - - status = (* pScreen->DestroyPixmap)(pPix); - SCREEN_EPILOGUE(pScreen, DestroyPixmap, XvDestroyPixmap); + status = (*pScreen->DestroyPixmap) (pPix); + + SCREEN_EPILOGUE(pScreen, DestroyPixmap, XvDestroyPixmap); - return status; + return status; } static Bool XvDestroyWindow(WindowPtr pWin) { - Bool status; - ScreenPtr pScreen; - XvScreenPtr pxvs; - XvAdaptorPtr pa; - int na; - XvPortPtr pp; - int np; - - pScreen = pWin->drawable.pScreen; - - SCREEN_PROLOGUE(pScreen, DestroyWindow); - - pxvs = (XvScreenPtr)dixLookupPrivate(&pScreen->devPrivates, XvScreenKey); - - /* CHECK TO SEE IF THIS PORT IS IN USE */ - - pa = pxvs->pAdaptors; - na = pxvs->nAdaptors; - while (na--) - { - np = pa->nPorts; - pp = pa->pPorts; - - while (np--) - { - if (pp->pDraw == (DrawablePtr)pWin) - { - XvdiSendVideoNotify(pp, pp->pDraw, XvPreempted); - - (void)(* pp->pAdaptor->ddStopVideo)(NULL, pp, pp->pDraw); - - pp->pDraw = NULL; - pp->client = NULL; - pp->time = currentTime; - } - pp++; - } - pa++; + Bool status; + ScreenPtr pScreen; + XvScreenPtr pxvs; + XvAdaptorPtr pa; + int na; + XvPortPtr pp; + int np; + + pScreen = pWin->drawable.pScreen; + + SCREEN_PROLOGUE(pScreen, DestroyWindow); + + pxvs = (XvScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XvScreenKey); + + /* CHECK TO SEE IF THIS PORT IS IN USE */ + + pa = pxvs->pAdaptors; + na = pxvs->nAdaptors; + while (na--) { + np = pa->nPorts; + pp = pa->pPorts; + + while (np--) { + if (pp->pDraw == (DrawablePtr) pWin) { + XvdiSendVideoNotify(pp, pp->pDraw, XvPreempted); + + (void) (*pp->pAdaptor->ddStopVideo) (NULL, pp, pp->pDraw); + + pp->pDraw = NULL; + pp->client = NULL; + pp->time = currentTime; + } + pp++; + } + pa++; } - - status = (* pScreen->DestroyWindow)(pWin); + status = (*pScreen->DestroyWindow) (pWin); - SCREEN_EPILOGUE(pScreen, DestroyWindow, XvDestroyWindow); + SCREEN_EPILOGUE(pScreen, DestroyWindow, XvDestroyWindow); - return status; + return status; } @@ -452,129 +432,123 @@ XvDestroyWindow(WindowPtr pWin) int XvdiVideoStopped(XvPortPtr pPort, int reason) { - - /* IF PORT ISN'T ACTIVE THEN WE'RE DONE */ - if (!pPort->pDraw) return Success; + /* IF PORT ISN'T ACTIVE THEN WE'RE DONE */ - XvdiSendVideoNotify(pPort, pPort->pDraw, reason); + if (!pPort->pDraw) + return Success; - pPort->pDraw = NULL; - pPort->client = NULL; - pPort->time = currentTime; + XvdiSendVideoNotify(pPort, pPort->pDraw, reason); - return Success; + pPort->pDraw = NULL; + pPort->client = NULL; + pPort->time = currentTime; + + return Success; } -static int +static int XvdiDestroyPort(pointer pPort, XID id) { - return (* ((XvPortPtr)pPort)->pAdaptor->ddFreePort)(pPort); + return (*((XvPortPtr) pPort)->pAdaptor->ddFreePort) (pPort); } static int XvdiDestroyGrab(pointer pGrab, XID id) { - ((XvGrabPtr)pGrab)->client = NULL; - return Success; + ((XvGrabPtr) pGrab)->client = NULL; + return Success; } static int XvdiDestroyVideoNotify(pointer pn, XID id) { - /* JUST CLEAR OUT THE client POINTER FIELD */ + /* JUST CLEAR OUT THE client POINTER FIELD */ - ((XvVideoNotifyPtr)pn)->client = NULL; - return Success; + ((XvVideoNotifyPtr) pn)->client = NULL; + return Success; } static int XvdiDestroyPortNotify(pointer pn, XID id) { - /* JUST CLEAR OUT THE client POINTER FIELD */ + /* JUST CLEAR OUT THE client POINTER FIELD */ - ((XvPortNotifyPtr)pn)->client = NULL; - return Success; + ((XvPortNotifyPtr) pn)->client = NULL; + return Success; } static int XvdiDestroyVideoNotifyList(pointer pn, XID id) { - XvVideoNotifyPtr npn,cpn; + XvVideoNotifyPtr npn, cpn; - /* ACTUALLY DESTROY THE NOTITY LIST */ + /* ACTUALLY DESTROY THE NOTITY LIST */ - cpn = (XvVideoNotifyPtr)pn; + cpn = (XvVideoNotifyPtr) pn; - while (cpn) - { - npn = cpn->next; - if (cpn->client) FreeResource(cpn->id, XvRTVideoNotify); - free(cpn); - cpn = npn; + while (cpn) { + npn = cpn->next; + if (cpn->client) + FreeResource(cpn->id, XvRTVideoNotify); + free(cpn); + cpn = npn; } - return Success; + return Success; } static int XvdiDestroyEncoding(pointer value, XID id) { - return Success; + return Success; } static int XvdiSendVideoNotify(XvPortPtr pPort, DrawablePtr pDraw, int reason) { - xvEvent event; - XvVideoNotifyPtr pn; - - dixLookupResourceByType((pointer *)&pn, pDraw->id, XvRTVideoNotifyList, - serverClient, DixReadAccess); - - while (pn) - { - event.u.u.type = XvEventBase + XvVideoNotify; - event.u.videoNotify.time = currentTime.milliseconds; - event.u.videoNotify.drawable = pDraw->id; - event.u.videoNotify.port = pPort->id; - event.u.videoNotify.reason = reason; - WriteEventsToClient(pn->client, 1, (xEventPtr)&event); - pn = pn->next; + xvEvent event; + XvVideoNotifyPtr pn; + + dixLookupResourceByType((pointer *) &pn, pDraw->id, XvRTVideoNotifyList, + serverClient, DixReadAccess); + + while (pn) { + event.u.u.type = XvEventBase + XvVideoNotify; + event.u.videoNotify.time = currentTime.milliseconds; + event.u.videoNotify.drawable = pDraw->id; + event.u.videoNotify.port = pPort->id; + event.u.videoNotify.reason = reason; + WriteEventsToClient(pn->client, 1, (xEventPtr) & event); + pn = pn->next; } - return Success; + return Success; } - int -XvdiSendPortNotify( - XvPortPtr pPort, - Atom attribute, - INT32 value -){ - xvEvent event; - XvPortNotifyPtr pn; - - pn = pPort->pNotify; - - while (pn) - { - event.u.u.type = XvEventBase + XvPortNotify; - event.u.portNotify.time = currentTime.milliseconds; - event.u.portNotify.port = pPort->id; - event.u.portNotify.attribute = attribute; - event.u.portNotify.value = value; - WriteEventsToClient(pn->client, 1, (xEventPtr)&event); - pn = pn->next; +XvdiSendPortNotify(XvPortPtr pPort, Atom attribute, INT32 value) +{ + xvEvent event; + XvPortNotifyPtr pn; + + pn = pPort->pNotify; + + while (pn) { + event.u.u.type = XvEventBase + XvPortNotify; + event.u.portNotify.time = currentTime.milliseconds; + event.u.portNotify.port = pPort->id; + event.u.portNotify.attribute = attribute; + event.u.portNotify.value = value; + WriteEventsToClient(pn->client, 1, (xEventPtr) & event); + pn = pn->next; } - return Success; + return Success; } - #define CHECK_SIZE(dw, dh, sw, sh) { \ if(!dw || !dh || !sw || !sh) return Success; \ /* The region code will break these if they are too large */ \ @@ -582,597 +556,535 @@ XvdiSendPortNotify( return BadValue; \ } - int -XvdiPutVideo( - ClientPtr client, - DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, - CARD16 drw_w, CARD16 drw_h -){ - DrawablePtr pOldDraw; - - CHECK_SIZE(drw_w, drw_h, vid_w, vid_h); - - /* UPDATE TIME VARIABLES FOR USE IN EVENTS */ - - UpdateCurrentTime(); - - /* CHECK FOR GRAB; IF THIS CLIENT DOESN'T HAVE THE PORT GRABBED THEN - INFORM CLIENT OF ITS FAILURE */ - - if (pPort->grab.client && (pPort->grab.client != client)) - { - XvdiSendVideoNotify(pPort, pDraw, XvBusy); - return Success; +XvdiPutVideo(ClientPtr client, + DrawablePtr pDraw, + XvPortPtr pPort, + GCPtr pGC, + INT16 vid_x, INT16 vid_y, + CARD16 vid_w, CARD16 vid_h, + INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) +{ + DrawablePtr pOldDraw; + + CHECK_SIZE(drw_w, drw_h, vid_w, vid_h); + + /* UPDATE TIME VARIABLES FOR USE IN EVENTS */ + + UpdateCurrentTime(); + + /* CHECK FOR GRAB; IF THIS CLIENT DOESN'T HAVE THE PORT GRABBED THEN + INFORM CLIENT OF ITS FAILURE */ + + if (pPort->grab.client && (pPort->grab.client != client)) { + XvdiSendVideoNotify(pPort, pDraw, XvBusy); + return Success; } - /* CHECK TO SEE IF PORT IS IN USE; IF SO THEN WE MUST DELIVER INTERRUPTED - EVENTS TO ANY CLIENTS WHO WANT THEM */ + /* CHECK TO SEE IF PORT IS IN USE; IF SO THEN WE MUST DELIVER INTERRUPTED + EVENTS TO ANY CLIENTS WHO WANT THEM */ - pOldDraw = pPort->pDraw; - if ((pOldDraw) && (pOldDraw != pDraw)) - { - XvdiSendVideoNotify(pPort, pPort->pDraw, XvPreempted); + pOldDraw = pPort->pDraw; + if ((pOldDraw) && (pOldDraw != pDraw)) { + XvdiSendVideoNotify(pPort, pPort->pDraw, XvPreempted); } - (void) (* pPort->pAdaptor->ddPutVideo)(client, pDraw, pPort, pGC, - vid_x, vid_y, vid_w, vid_h, - drw_x, drw_y, drw_w, drw_h); + (void) (*pPort->pAdaptor->ddPutVideo) (client, pDraw, pPort, pGC, + vid_x, vid_y, vid_w, vid_h, + drw_x, drw_y, drw_w, drw_h); - if ((pPort->pDraw) && (pOldDraw != pDraw)) - { - pPort->client = client; - XvdiSendVideoNotify(pPort, pPort->pDraw, XvStarted); + if ((pPort->pDraw) && (pOldDraw != pDraw)) { + pPort->client = client; + XvdiSendVideoNotify(pPort, pPort->pDraw, XvStarted); } - pPort->time = currentTime; + pPort->time = currentTime; - return Success; + return Success; } int -XvdiPutStill( - ClientPtr client, - DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, - CARD16 drw_w, CARD16 drw_h -){ - int status; - - CHECK_SIZE(drw_w, drw_h, vid_w, vid_h); - - /* UPDATE TIME VARIABLES FOR USE IN EVENTS */ - - UpdateCurrentTime(); - - /* CHECK FOR GRAB; IF THIS CLIENT DOESN'T HAVE THE PORT GRABBED THEN - INFORM CLIENT OF ITS FAILURE */ - - if (pPort->grab.client && (pPort->grab.client != client)) - { - XvdiSendVideoNotify(pPort, pDraw, XvBusy); - return Success; +XvdiPutStill(ClientPtr client, + DrawablePtr pDraw, + XvPortPtr pPort, + GCPtr pGC, + INT16 vid_x, INT16 vid_y, + CARD16 vid_w, CARD16 vid_h, + INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) +{ + int status; + + CHECK_SIZE(drw_w, drw_h, vid_w, vid_h); + + /* UPDATE TIME VARIABLES FOR USE IN EVENTS */ + + UpdateCurrentTime(); + + /* CHECK FOR GRAB; IF THIS CLIENT DOESN'T HAVE THE PORT GRABBED THEN + INFORM CLIENT OF ITS FAILURE */ + + if (pPort->grab.client && (pPort->grab.client != client)) { + XvdiSendVideoNotify(pPort, pDraw, XvBusy); + return Success; } - pPort->time = currentTime; + pPort->time = currentTime; - status = (* pPort->pAdaptor->ddPutStill)(client, pDraw, pPort, pGC, - vid_x, vid_y, vid_w, vid_h, - drw_x, drw_y, drw_w, drw_h); + status = (*pPort->pAdaptor->ddPutStill) (client, pDraw, pPort, pGC, + vid_x, vid_y, vid_w, vid_h, + drw_x, drw_y, drw_w, drw_h); - return status; + return status; } int -XvdiPutImage( - ClientPtr client, - DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 src_x, INT16 src_y, - CARD16 src_w, CARD16 src_h, - INT16 drw_x, INT16 drw_y, - CARD16 drw_w, CARD16 drw_h, - XvImagePtr image, - unsigned char* data, - Bool sync, - CARD16 width, CARD16 height -){ - CHECK_SIZE(drw_w, drw_h, src_w, src_h); - - /* UPDATE TIME VARIABLES FOR USE IN EVENTS */ - - UpdateCurrentTime(); - - /* CHECK FOR GRAB; IF THIS CLIENT DOESN'T HAVE THE PORT GRABBED THEN - INFORM CLIENT OF ITS FAILURE */ - - if (pPort->grab.client && (pPort->grab.client != client)) - { - XvdiSendVideoNotify(pPort, pDraw, XvBusy); - return Success; +XvdiPutImage(ClientPtr client, + DrawablePtr pDraw, + XvPortPtr pPort, + GCPtr pGC, + INT16 src_x, INT16 src_y, + CARD16 src_w, CARD16 src_h, + INT16 drw_x, INT16 drw_y, + CARD16 drw_w, CARD16 drw_h, + XvImagePtr image, + unsigned char *data, Bool sync, CARD16 width, CARD16 height) +{ + CHECK_SIZE(drw_w, drw_h, src_w, src_h); + + /* UPDATE TIME VARIABLES FOR USE IN EVENTS */ + + UpdateCurrentTime(); + + /* CHECK FOR GRAB; IF THIS CLIENT DOESN'T HAVE THE PORT GRABBED THEN + INFORM CLIENT OF ITS FAILURE */ + + if (pPort->grab.client && (pPort->grab.client != client)) { + XvdiSendVideoNotify(pPort, pDraw, XvBusy); + return Success; } - pPort->time = currentTime; + pPort->time = currentTime; - return (* pPort->pAdaptor->ddPutImage)(client, pDraw, pPort, pGC, - src_x, src_y, src_w, src_h, - drw_x, drw_y, drw_w, drw_h, - image, data, sync, width, height); + return (*pPort->pAdaptor->ddPutImage) (client, pDraw, pPort, pGC, + src_x, src_y, src_w, src_h, + drw_x, drw_y, drw_w, drw_h, + image, data, sync, width, height); } - int -XvdiGetVideo( - ClientPtr client, - DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, - CARD16 drw_w, CARD16 drw_h -){ - DrawablePtr pOldDraw; - - CHECK_SIZE(drw_w, drw_h, vid_w, vid_h); - - /* UPDATE TIME VARIABLES FOR USE IN EVENTS */ - - UpdateCurrentTime(); - - /* CHECK FOR GRAB; IF THIS CLIENT DOESN'T HAVE THE PORT GRABBED THEN - INFORM CLIENT OF ITS FAILURE */ - - if (pPort->grab.client && (pPort->grab.client != client)) - { - XvdiSendVideoNotify(pPort, pDraw, XvBusy); - return Success; +XvdiGetVideo(ClientPtr client, + DrawablePtr pDraw, + XvPortPtr pPort, + GCPtr pGC, + INT16 vid_x, INT16 vid_y, + CARD16 vid_w, CARD16 vid_h, + INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) +{ + DrawablePtr pOldDraw; + + CHECK_SIZE(drw_w, drw_h, vid_w, vid_h); + + /* UPDATE TIME VARIABLES FOR USE IN EVENTS */ + + UpdateCurrentTime(); + + /* CHECK FOR GRAB; IF THIS CLIENT DOESN'T HAVE THE PORT GRABBED THEN + INFORM CLIENT OF ITS FAILURE */ + + if (pPort->grab.client && (pPort->grab.client != client)) { + XvdiSendVideoNotify(pPort, pDraw, XvBusy); + return Success; } - /* CHECK TO SEE IF PORT IS IN USE; IF SO THEN WE MUST DELIVER INTERRUPTED - EVENTS TO ANY CLIENTS WHO WANT THEM */ + /* CHECK TO SEE IF PORT IS IN USE; IF SO THEN WE MUST DELIVER INTERRUPTED + EVENTS TO ANY CLIENTS WHO WANT THEM */ - pOldDraw = pPort->pDraw; - if ((pOldDraw) && (pOldDraw != pDraw)) - { - XvdiSendVideoNotify(pPort, pPort->pDraw, XvPreempted); + pOldDraw = pPort->pDraw; + if ((pOldDraw) && (pOldDraw != pDraw)) { + XvdiSendVideoNotify(pPort, pPort->pDraw, XvPreempted); } - (void) (* pPort->pAdaptor->ddGetVideo)(client, pDraw, pPort, pGC, - vid_x, vid_y, vid_w, vid_h, - drw_x, drw_y, drw_w, drw_h); + (void) (*pPort->pAdaptor->ddGetVideo) (client, pDraw, pPort, pGC, + vid_x, vid_y, vid_w, vid_h, + drw_x, drw_y, drw_w, drw_h); - if ((pPort->pDraw) && (pOldDraw != pDraw)) - { - pPort->client = client; - XvdiSendVideoNotify(pPort, pPort->pDraw, XvStarted); + if ((pPort->pDraw) && (pOldDraw != pDraw)) { + pPort->client = client; + XvdiSendVideoNotify(pPort, pPort->pDraw, XvStarted); } - pPort->time = currentTime; + pPort->time = currentTime; - return Success; + return Success; } int -XvdiGetStill( - ClientPtr client, - DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, - CARD16 drw_w, CARD16 drw_h -){ - int status; - - CHECK_SIZE(drw_w, drw_h, vid_w, vid_h); - - /* UPDATE TIME VARIABLES FOR USE IN EVENTS */ - - UpdateCurrentTime(); - - /* CHECK FOR GRAB; IF THIS CLIENT DOESN'T HAVE THE PORT GRABBED THEN - INFORM CLIENT OF ITS FAILURE */ - - if (pPort->grab.client && (pPort->grab.client != client)) - { - XvdiSendVideoNotify(pPort, pDraw, XvBusy); - return Success; +XvdiGetStill(ClientPtr client, + DrawablePtr pDraw, + XvPortPtr pPort, + GCPtr pGC, + INT16 vid_x, INT16 vid_y, + CARD16 vid_w, CARD16 vid_h, + INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) +{ + int status; + + CHECK_SIZE(drw_w, drw_h, vid_w, vid_h); + + /* UPDATE TIME VARIABLES FOR USE IN EVENTS */ + + UpdateCurrentTime(); + + /* CHECK FOR GRAB; IF THIS CLIENT DOESN'T HAVE THE PORT GRABBED THEN + INFORM CLIENT OF ITS FAILURE */ + + if (pPort->grab.client && (pPort->grab.client != client)) { + XvdiSendVideoNotify(pPort, pDraw, XvBusy); + return Success; } - status = (* pPort->pAdaptor->ddGetStill)(client, pDraw, pPort, pGC, - vid_x, vid_y, vid_w, vid_h, - drw_x, drw_y, drw_w, drw_h); + status = (*pPort->pAdaptor->ddGetStill) (client, pDraw, pPort, pGC, + vid_x, vid_y, vid_w, vid_h, + drw_x, drw_y, drw_w, drw_h); - pPort->time = currentTime; + pPort->time = currentTime; - return status; + return status; } int -XvdiGrabPort( - ClientPtr client, - XvPortPtr pPort, - Time ctime, - int *p_result -){ - unsigned long id; - TimeStamp time; - - UpdateCurrentTime(); - time = ClientTimeToServerTime(ctime); - - if (pPort->grab.client && (client != pPort->grab.client)) - { - *p_result = XvAlreadyGrabbed; - return Success; +XvdiGrabPort(ClientPtr client, XvPortPtr pPort, Time ctime, int *p_result) +{ + unsigned long id; + TimeStamp time; + + UpdateCurrentTime(); + time = ClientTimeToServerTime(ctime); + + if (pPort->grab.client && (client != pPort->grab.client)) { + *p_result = XvAlreadyGrabbed; + return Success; } - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, pPort->time) == EARLIER)) - { - *p_result = XvInvalidTime; - return Success; + if ((CompareTimeStamps(time, currentTime) == LATER) || + (CompareTimeStamps(time, pPort->time) == EARLIER)) { + *p_result = XvInvalidTime; + return Success; } - if (client == pPort->grab.client) - { - *p_result = Success; - return Success; + if (client == pPort->grab.client) { + *p_result = Success; + return Success; } - id = FakeClientID(client->index); + id = FakeClientID(client->index); - if (!AddResource(id, XvRTGrab, &pPort->grab)) - { - return BadAlloc; + if (!AddResource(id, XvRTGrab, &pPort->grab)) { + return BadAlloc; } - /* IF THERE IS ACTIVE VIDEO THEN STOP IT */ + /* IF THERE IS ACTIVE VIDEO THEN STOP IT */ - if ((pPort->pDraw) && (client != pPort->client)) - { - XvdiStopVideo(NULL, pPort, pPort->pDraw); + if ((pPort->pDraw) && (client != pPort->client)) { + XvdiStopVideo(NULL, pPort, pPort->pDraw); } - pPort->grab.client = client; - pPort->grab.id = id; + pPort->grab.client = client; + pPort->grab.id = id; - pPort->time = currentTime; + pPort->time = currentTime; - *p_result = Success; + *p_result = Success; - return Success; + return Success; } int -XvdiUngrabPort( - ClientPtr client, - XvPortPtr pPort, - Time ctime -){ - TimeStamp time; - - UpdateCurrentTime(); - time = ClientTimeToServerTime(ctime); - - if ((!pPort->grab.client) || (client != pPort->grab.client)) - { - return Success; +XvdiUngrabPort(ClientPtr client, XvPortPtr pPort, Time ctime) +{ + TimeStamp time; + + UpdateCurrentTime(); + time = ClientTimeToServerTime(ctime); + + if ((!pPort->grab.client) || (client != pPort->grab.client)) { + return Success; } - if ((CompareTimeStamps(time, currentTime) == LATER) || - (CompareTimeStamps(time, pPort->time) == EARLIER)) - { - return Success; + if ((CompareTimeStamps(time, currentTime) == LATER) || + (CompareTimeStamps(time, pPort->time) == EARLIER)) { + return Success; } - /* FREE THE GRAB RESOURCE; AND SET THE GRAB CLIENT TO NULL */ + /* FREE THE GRAB RESOURCE; AND SET THE GRAB CLIENT TO NULL */ - FreeResource(pPort->grab.id, XvRTGrab); - pPort->grab.client = NULL; + FreeResource(pPort->grab.id, XvRTGrab); + pPort->grab.client = NULL; - pPort->time = currentTime; + pPort->time = currentTime; - return Success; + return Success; } - int -XvdiSelectVideoNotify( - ClientPtr client, - DrawablePtr pDraw, - BOOL onoff -){ - XvVideoNotifyPtr pn,tpn,fpn; - int rc; - - /* FIND VideoNotify LIST */ - - rc = dixLookupResourceByType((pointer *)&pn, pDraw->id, XvRTVideoNotifyList, - client, DixWriteAccess); - if (rc != Success && rc != BadValue) - return rc; - - /* IF ONE DONES'T EXIST AND NO MASK, THEN JUST RETURN */ - - if (!onoff && !pn) return Success; - - /* IF ONE DOESN'T EXIST CREATE IT AND ADD A RESOURCE SO THAT THE LIST - WILL BE DELETED WHEN THE DRAWABLE IS DESTROYED */ - - if (!pn) - { - if (!(tpn = malloc(sizeof(XvVideoNotifyRec)))) - return BadAlloc; - tpn->next = NULL; - if (!AddResource(pDraw->id, XvRTVideoNotifyList, tpn)) - { - free(tpn); - return BadAlloc; - } +XvdiSelectVideoNotify(ClientPtr client, DrawablePtr pDraw, BOOL onoff) +{ + XvVideoNotifyPtr pn, tpn, fpn; + int rc; + + /* FIND VideoNotify LIST */ + + rc = dixLookupResourceByType((pointer *) &pn, pDraw->id, + XvRTVideoNotifyList, client, DixWriteAccess); + if (rc != Success && rc != BadValue) + return rc; + + /* IF ONE DONES'T EXIST AND NO MASK, THEN JUST RETURN */ + + if (!onoff && !pn) + return Success; + + /* IF ONE DOESN'T EXIST CREATE IT AND ADD A RESOURCE SO THAT THE LIST + WILL BE DELETED WHEN THE DRAWABLE IS DESTROYED */ + + if (!pn) { + if (!(tpn = malloc(sizeof(XvVideoNotifyRec)))) + return BadAlloc; + tpn->next = NULL; + if (!AddResource(pDraw->id, XvRTVideoNotifyList, tpn)) { + free(tpn); + return BadAlloc; + } } - else - { - /* LOOK TO SEE IF ENTRY ALREADY EXISTS */ - - fpn = NULL; - tpn = pn; - while (tpn) - { - if (tpn->client == client) - { - if (!onoff) tpn->client = NULL; - return Success; - } - if (!tpn->client) fpn = tpn; /* TAKE NOTE OF FREE ENTRY */ - tpn = tpn->next; - } - - /* IF TUNNING OFF, THEN JUST RETURN */ - - if (!onoff) return Success; - - /* IF ONE ISN'T FOUND THEN ALLOCATE ONE AND LINK IT INTO THE LIST */ - - if (fpn) - { - tpn = fpn; - } - else - { - if (!(tpn = malloc(sizeof(XvVideoNotifyRec)))) - return BadAlloc; - tpn->next = pn->next; - pn->next = tpn; - } + else { + /* LOOK TO SEE IF ENTRY ALREADY EXISTS */ + + fpn = NULL; + tpn = pn; + while (tpn) { + if (tpn->client == client) { + if (!onoff) + tpn->client = NULL; + return Success; + } + if (!tpn->client) + fpn = tpn; /* TAKE NOTE OF FREE ENTRY */ + tpn = tpn->next; + } + + /* IF TUNNING OFF, THEN JUST RETURN */ + + if (!onoff) + return Success; + + /* IF ONE ISN'T FOUND THEN ALLOCATE ONE AND LINK IT INTO THE LIST */ + + if (fpn) { + tpn = fpn; + } + else { + if (!(tpn = malloc(sizeof(XvVideoNotifyRec)))) + return BadAlloc; + tpn->next = pn->next; + pn->next = tpn; + } } - /* INIT CLIENT PTR IN CASE WE CAN'T ADD RESOURCE */ - /* ADD RESOURCE SO THAT IF CLIENT EXITS THE CLIENT PTR WILL BE CLEARED */ + /* INIT CLIENT PTR IN CASE WE CAN'T ADD RESOURCE */ + /* ADD RESOURCE SO THAT IF CLIENT EXITS THE CLIENT PTR WILL BE CLEARED */ - tpn->client = NULL; - tpn->id = FakeClientID(client->index); - AddResource(tpn->id, XvRTVideoNotify, tpn); + tpn->client = NULL; + tpn->id = FakeClientID(client->index); + AddResource(tpn->id, XvRTVideoNotify, tpn); - tpn->client = client; - return Success; + tpn->client = client; + return Success; } int -XvdiSelectPortNotify( - ClientPtr client, - XvPortPtr pPort, - BOOL onoff -){ - XvPortNotifyPtr pn,tpn; - - /* SEE IF CLIENT IS ALREADY IN LIST */ - - tpn = NULL; - pn = pPort->pNotify; - while (pn) - { - if (!pn->client) tpn = pn; /* TAKE NOTE OF FREE ENTRY */ - if (pn->client == client) break; - pn = pn->next; +XvdiSelectPortNotify(ClientPtr client, XvPortPtr pPort, BOOL onoff) +{ + XvPortNotifyPtr pn, tpn; + + /* SEE IF CLIENT IS ALREADY IN LIST */ + + tpn = NULL; + pn = pPort->pNotify; + while (pn) { + if (!pn->client) + tpn = pn; /* TAKE NOTE OF FREE ENTRY */ + if (pn->client == client) + break; + pn = pn->next; } - /* IS THE CLIENT ALREADY ON THE LIST? */ + /* IS THE CLIENT ALREADY ON THE LIST? */ - if (pn) - { - /* REMOVE IT? */ + if (pn) { + /* REMOVE IT? */ - if (!onoff) - { - pn->client = NULL; - FreeResource(pn->id, XvRTPortNotify); - } + if (!onoff) { + pn->client = NULL; + FreeResource(pn->id, XvRTPortNotify); + } - return Success; + return Success; } - /* DIDN'T FIND IT; SO REUSE LIST ELEMENT IF ONE IS FREE OTHERWISE - CREATE A NEW ONE AND ADD IT TO THE BEGINNING OF THE LIST */ + /* DIDN'T FIND IT; SO REUSE LIST ELEMENT IF ONE IS FREE OTHERWISE + CREATE A NEW ONE AND ADD IT TO THE BEGINNING OF THE LIST */ - if (!tpn) - { - if (!(tpn = malloc(sizeof(XvPortNotifyRec)))) - return BadAlloc; - tpn->next = pPort->pNotify; - pPort->pNotify = tpn; + if (!tpn) { + if (!(tpn = malloc(sizeof(XvPortNotifyRec)))) + return BadAlloc; + tpn->next = pPort->pNotify; + pPort->pNotify = tpn; } - tpn->client = client; - tpn->id = FakeClientID(client->index); - AddResource(tpn->id, XvRTPortNotify, tpn); + tpn->client = client; + tpn->id = FakeClientID(client->index); + AddResource(tpn->id, XvRTPortNotify, tpn); - return Success; + return Success; } int -XvdiStopVideo( - ClientPtr client, - XvPortPtr pPort, - DrawablePtr pDraw -){ - int status; - - /* IF PORT ISN'T ACTIVE THEN WE'RE DONE */ - - if (!pPort->pDraw || (pPort->pDraw != pDraw)) - { - XvdiSendVideoNotify(pPort, pDraw, XvStopped); - return Success; +XvdiStopVideo(ClientPtr client, XvPortPtr pPort, DrawablePtr pDraw) +{ + int status; + + /* IF PORT ISN'T ACTIVE THEN WE'RE DONE */ + + if (!pPort->pDraw || (pPort->pDraw != pDraw)) { + XvdiSendVideoNotify(pPort, pDraw, XvStopped); + return Success; } - /* CHECK FOR GRAB; IF THIS CLIENT DOESN'T HAVE THE PORT GRABBED THEN - INFORM CLIENT OF ITS FAILURE */ + /* CHECK FOR GRAB; IF THIS CLIENT DOESN'T HAVE THE PORT GRABBED THEN + INFORM CLIENT OF ITS FAILURE */ - if ((client) && (pPort->grab.client) && (pPort->grab.client != client)) - { - XvdiSendVideoNotify(pPort, pDraw, XvBusy); - return Success; + if ((client) && (pPort->grab.client) && (pPort->grab.client != client)) { + XvdiSendVideoNotify(pPort, pDraw, XvBusy); + return Success; } - XvdiSendVideoNotify(pPort, pDraw, XvStopped); + XvdiSendVideoNotify(pPort, pDraw, XvStopped); - status = (* pPort->pAdaptor->ddStopVideo)(client, pPort, pDraw); + status = (*pPort->pAdaptor->ddStopVideo) (client, pPort, pDraw); - pPort->pDraw = NULL; - pPort->client = (ClientPtr)client; - pPort->time = currentTime; + pPort->pDraw = NULL; + pPort->client = (ClientPtr) client; + pPort->time = currentTime; - return status; + return status; } int -XvdiPreemptVideo( - ClientPtr client, - XvPortPtr pPort, - DrawablePtr pDraw -){ - int status; +XvdiPreemptVideo(ClientPtr client, XvPortPtr pPort, DrawablePtr pDraw) +{ + int status; - /* IF PORT ISN'T ACTIVE THEN WE'RE DONE */ + /* IF PORT ISN'T ACTIVE THEN WE'RE DONE */ - if (!pPort->pDraw || (pPort->pDraw != pDraw)) return Success; + if (!pPort->pDraw || (pPort->pDraw != pDraw)) + return Success; - XvdiSendVideoNotify(pPort, pPort->pDraw, XvPreempted); + XvdiSendVideoNotify(pPort, pPort->pDraw, XvPreempted); - status = (* pPort->pAdaptor->ddStopVideo)(client, pPort, pPort->pDraw); + status = (*pPort->pAdaptor->ddStopVideo) (client, pPort, pPort->pDraw); - pPort->pDraw = NULL; - pPort->client = (ClientPtr)client; - pPort->time = currentTime; + pPort->pDraw = NULL; + pPort->client = (ClientPtr) client; + pPort->time = currentTime; - return status; + return status; } int -XvdiMatchPort( - XvPortPtr pPort, - DrawablePtr pDraw -){ +XvdiMatchPort(XvPortPtr pPort, DrawablePtr pDraw) +{ - XvAdaptorPtr pa; - XvFormatPtr pf; - int nf; + XvAdaptorPtr pa; + XvFormatPtr pf; + int nf; - pa = pPort->pAdaptor; + pa = pPort->pAdaptor; - if (pa->pScreen != pDraw->pScreen) return BadMatch; + if (pa->pScreen != pDraw->pScreen) + return BadMatch; - nf = pa->nFormats; - pf = pa->pFormats; + nf = pa->nFormats; + pf = pa->pFormats; - while (nf--) - { - if (pf->depth == pDraw->depth) - return Success; - pf++; + while (nf--) { + if (pf->depth == pDraw->depth) + return Success; + pf++; } - return BadMatch; + return BadMatch; } int -XvdiSetPortAttribute( - ClientPtr client, - XvPortPtr pPort, - Atom attribute, - INT32 value -){ - int status; - - status = (* pPort->pAdaptor->ddSetPortAttribute)(client, pPort, attribute, value); - if (status == Success) - XvdiSendPortNotify(pPort, attribute, value); - - return status; +XvdiSetPortAttribute(ClientPtr client, + XvPortPtr pPort, Atom attribute, INT32 value) +{ + int status; + + status = + (*pPort->pAdaptor->ddSetPortAttribute) (client, pPort, attribute, + value); + if (status == Success) + XvdiSendPortNotify(pPort, attribute, value); + + return status; } int -XvdiGetPortAttribute( - ClientPtr client, - XvPortPtr pPort, - Atom attribute, - INT32 *p_value -){ +XvdiGetPortAttribute(ClientPtr client, + XvPortPtr pPort, Atom attribute, INT32 *p_value) +{ - return - (* pPort->pAdaptor->ddGetPortAttribute)(client, pPort, attribute, p_value); + return + (*pPort->pAdaptor->ddGetPortAttribute) (client, pPort, attribute, + p_value); } static void -WriteSwappedVideoNotifyEvent(xvEvent *from, xvEvent *to) - +WriteSwappedVideoNotifyEvent(xvEvent * from, xvEvent * to) { - to->u.u.type = from->u.u.type; - to->u.u.detail = from->u.u.detail; - cpswaps(from->u.videoNotify.sequenceNumber, - to->u.videoNotify.sequenceNumber); - cpswapl(from->u.videoNotify.time, to->u.videoNotify.time); - cpswapl(from->u.videoNotify.drawable, to->u.videoNotify.drawable); - cpswapl(from->u.videoNotify.port, to->u.videoNotify.port); + to->u.u.type = from->u.u.type; + to->u.u.detail = from->u.u.detail; + cpswaps(from->u.videoNotify.sequenceNumber, + to->u.videoNotify.sequenceNumber); + cpswapl(from->u.videoNotify.time, to->u.videoNotify.time); + cpswapl(from->u.videoNotify.drawable, to->u.videoNotify.drawable); + cpswapl(from->u.videoNotify.port, to->u.videoNotify.port); } static void -WriteSwappedPortNotifyEvent(xvEvent *from, xvEvent *to) - +WriteSwappedPortNotifyEvent(xvEvent * from, xvEvent * to) { - to->u.u.type = from->u.u.type; - to->u.u.detail = from->u.u.detail; - cpswaps(from->u.portNotify.sequenceNumber, to->u.portNotify.sequenceNumber); - cpswapl(from->u.portNotify.time, to->u.portNotify.time); - cpswapl(from->u.portNotify.port, to->u.portNotify.port); - cpswapl(from->u.portNotify.value, to->u.portNotify.value); + to->u.u.type = from->u.u.type; + to->u.u.detail = from->u.u.detail; + cpswaps(from->u.portNotify.sequenceNumber, to->u.portNotify.sequenceNumber); + cpswapl(from->u.portNotify.time, to->u.portNotify.time); + cpswapl(from->u.portNotify.port, to->u.portNotify.port); + cpswapl(from->u.portNotify.value, to->u.portNotify.value); } diff --git a/xorg-server/Xext/xvmc.c b/xorg-server/Xext/xvmc.c index 47b9f476e..8a1d94085 100644 --- a/xorg-server/Xext/xvmc.c +++ b/xorg-server/Xext/xvmc.c @@ -26,14 +26,13 @@ #include <sys/ipc.h> #include <sys/types.h> #include <sys/shm.h> -#endif /* HAS_XVMCSHM */ - - +#endif /* HAS_XVMCSHM */ #define DR_CLIENT_DRIVER_NAME_SIZE 48 #define DR_BUSID_SIZE 48 static DevPrivateKeyRec XvMCScreenKeyRec; + #define XvMCScreenKey (&XvMCScreenKeyRec) static Bool XvMCInUse; @@ -47,71 +46,71 @@ static RESTYPE XvMCRTSurface; static RESTYPE XvMCRTSubpicture; typedef struct { - int num_adaptors; - XvMCAdaptorPtr adaptors; - CloseScreenProcPtr CloseScreen; - char clientDriverName[DR_CLIENT_DRIVER_NAME_SIZE]; - char busID[DR_BUSID_SIZE]; - int major; - int minor; - int patchLevel; -} XvMCScreenRec, *XvMCScreenPtr; + int num_adaptors; + XvMCAdaptorPtr adaptors; + CloseScreenProcPtr CloseScreen; + char clientDriverName[DR_CLIENT_DRIVER_NAME_SIZE]; + char busID[DR_BUSID_SIZE]; + int major; + int minor; + int patchLevel; +} XvMCScreenRec, *XvMCScreenPtr; #define XVMC_GET_PRIVATE(pScreen) \ (XvMCScreenPtr)(dixLookupPrivate(&(pScreen)->devPrivates, XvMCScreenKey)) - static int XvMCDestroyContextRes(pointer data, XID id) { - XvMCContextPtr pContext = (XvMCContextPtr)data; - - pContext->refcnt--; + XvMCContextPtr pContext = (XvMCContextPtr) data; - if(!pContext->refcnt) { - XvMCScreenPtr pScreenPriv = XVMC_GET_PRIVATE(pContext->pScreen); - (*pScreenPriv->adaptors[pContext->adapt_num].DestroyContext)(pContext); - free(pContext); - } + pContext->refcnt--; - return Success; + if (!pContext->refcnt) { + XvMCScreenPtr pScreenPriv = XVMC_GET_PRIVATE(pContext->pScreen); + + (*pScreenPriv->adaptors[pContext->adapt_num].DestroyContext) (pContext); + free(pContext); + } + + return Success; } static int XvMCDestroySurfaceRes(pointer data, XID id) { - XvMCSurfacePtr pSurface = (XvMCSurfacePtr)data; - XvMCContextPtr pContext = pSurface->context; - XvMCScreenPtr pScreenPriv = XVMC_GET_PRIVATE(pContext->pScreen); + XvMCSurfacePtr pSurface = (XvMCSurfacePtr) data; + XvMCContextPtr pContext = pSurface->context; + XvMCScreenPtr pScreenPriv = XVMC_GET_PRIVATE(pContext->pScreen); - (*pScreenPriv->adaptors[pContext->adapt_num].DestroySurface)(pSurface); - free(pSurface); + (*pScreenPriv->adaptors[pContext->adapt_num].DestroySurface) (pSurface); + free(pSurface); - XvMCDestroyContextRes((pointer)pContext, pContext->context_id); + XvMCDestroyContextRes((pointer) pContext, pContext->context_id); - return Success; + return Success; } - static int XvMCDestroySubpictureRes(pointer data, XID id) { - XvMCSubpicturePtr pSubpict = (XvMCSubpicturePtr)data; - XvMCContextPtr pContext = pSubpict->context; - XvMCScreenPtr pScreenPriv = XVMC_GET_PRIVATE(pContext->pScreen); + XvMCSubpicturePtr pSubpict = (XvMCSubpicturePtr) data; + XvMCContextPtr pContext = pSubpict->context; + XvMCScreenPtr pScreenPriv = XVMC_GET_PRIVATE(pContext->pScreen); - (*pScreenPriv->adaptors[pContext->adapt_num].DestroySubpicture)(pSubpict); - free(pSubpict); + (*pScreenPriv->adaptors[pContext->adapt_num].DestroySubpicture) (pSubpict); + free(pSubpict); - XvMCDestroyContextRes((pointer)pContext, pContext->context_id); + XvMCDestroyContextRes((pointer) pContext, pContext->context_id); - return Success; + return Success; } -static int +static int ProcXvMCQueryVersion(ClientPtr client) { xvmcQueryVersionReply rep; + /* REQUEST(xvmcQueryVersionReq); */ REQUEST_SIZE_MATCH(xvmcQueryVersionReq); rep.type = X_Reply; @@ -119,12 +118,11 @@ ProcXvMCQueryVersion(ClientPtr client) rep.length = 0; rep.major = SERVER_XVMC_MAJOR_VERSION; rep.minor = SERVER_XVMC_MINOR_VERSION; - WriteToClient(client, sizeof(xvmcQueryVersionReply), (char*)&rep); + WriteToClient(client, sizeof(xvmcQueryVersionReply), (char *) &rep); return Success; } - -static int +static int ProcXvMCListSurfaceTypes(ClientPtr client) { XvPortPtr pPort; @@ -134,52 +132,54 @@ ProcXvMCListSurfaceTypes(ClientPtr client) xvmcSurfaceInfo info; XvMCAdaptorPtr adaptor = NULL; XvMCSurfaceInfoPtr surface; + REQUEST(xvmcListSurfaceTypesReq); REQUEST_SIZE_MATCH(xvmcListSurfaceTypesReq); VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess); - if(XvMCInUse) { /* any adaptors at all */ - ScreenPtr pScreen = pPort->pAdaptor->pScreen; - if((pScreenPriv = XVMC_GET_PRIVATE(pScreen))) { /* any this screen */ - for(i = 0; i < pScreenPriv->num_adaptors; i++) { - if(pPort->pAdaptor == pScreenPriv->adaptors[i].xv_adaptor) { - adaptor = &(pScreenPriv->adaptors[i]); - break; - } - } - } + if (XvMCInUse) { /* any adaptors at all */ + ScreenPtr pScreen = pPort->pAdaptor->pScreen; + + if ((pScreenPriv = XVMC_GET_PRIVATE(pScreen))) { /* any this screen */ + for (i = 0; i < pScreenPriv->num_adaptors; i++) { + if (pPort->pAdaptor == pScreenPriv->adaptors[i].xv_adaptor) { + adaptor = &(pScreenPriv->adaptors[i]); + break; + } + } + } } rep.type = X_Reply; rep.sequenceNumber = client->sequence; rep.num = (adaptor) ? adaptor->num_surfaces : 0; rep.length = bytes_to_int32(rep.num * sizeof(xvmcSurfaceInfo)); - - WriteToClient(client, sizeof(xvmcListSurfaceTypesReply), (char*)&rep); - - for(i = 0; i < rep.num; i++) { - surface = adaptor->surfaces[i]; - info.surface_type_id = surface->surface_type_id; - info.chroma_format = surface->chroma_format; - info.max_width = surface->max_width; - info.max_height = surface->max_height; - info.subpicture_max_width = surface->subpicture_max_width; - info.subpicture_max_height = surface->subpicture_max_height; - info.mc_type = surface->mc_type; - info.flags = surface->flags; - WriteToClient(client, sizeof(xvmcSurfaceInfo), (char*)&info); + + WriteToClient(client, sizeof(xvmcListSurfaceTypesReply), (char *) &rep); + + for (i = 0; i < rep.num; i++) { + surface = adaptor->surfaces[i]; + info.surface_type_id = surface->surface_type_id; + info.chroma_format = surface->chroma_format; + info.max_width = surface->max_width; + info.max_height = surface->max_height; + info.subpicture_max_width = surface->subpicture_max_width; + info.subpicture_max_height = surface->subpicture_max_height; + info.mc_type = surface->mc_type; + info.flags = surface->flags; + WriteToClient(client, sizeof(xvmcSurfaceInfo), (char *) &info); } return Success; } -static int +static int ProcXvMCCreateContext(ClientPtr client) { XvPortPtr pPort; CARD32 *data = NULL; - int dwords = 0; + int dwords = 0; int i, result, adapt_num = -1; ScreenPtr pScreen; XvMCContextPtr pContext; @@ -187,6 +187,7 @@ ProcXvMCCreateContext(ClientPtr client) XvMCAdaptorPtr adaptor = NULL; XvMCSurfaceInfoPtr surface = NULL; xvmcCreateContextReply rep; + REQUEST(xvmcCreateContextReq); REQUEST_SIZE_MATCH(xvmcCreateContextReq); @@ -194,43 +195,42 @@ ProcXvMCCreateContext(ClientPtr client) pScreen = pPort->pAdaptor->pScreen; - if(!XvMCInUse) /* no XvMC adaptors */ - return BadMatch; - - if(!(pScreenPriv = XVMC_GET_PRIVATE(pScreen))) /* none this screen */ - return BadMatch; - - for(i = 0; i < pScreenPriv->num_adaptors; i++) { - if(pPort->pAdaptor == pScreenPriv->adaptors[i].xv_adaptor) { - adaptor = &(pScreenPriv->adaptors[i]); - adapt_num = i; - break; - } + if (!XvMCInUse) /* no XvMC adaptors */ + return BadMatch; + + if (!(pScreenPriv = XVMC_GET_PRIVATE(pScreen))) /* none this screen */ + return BadMatch; + + for (i = 0; i < pScreenPriv->num_adaptors; i++) { + if (pPort->pAdaptor == pScreenPriv->adaptors[i].xv_adaptor) { + adaptor = &(pScreenPriv->adaptors[i]); + adapt_num = i; + break; + } } - if(adapt_num < 0) /* none this port */ - return BadMatch; + if (adapt_num < 0) /* none this port */ + return BadMatch; - for(i = 0; i < adaptor->num_surfaces; i++) { - if(adaptor->surfaces[i]->surface_type_id == stuff->surface_type_id) { + for (i = 0; i < adaptor->num_surfaces; i++) { + if (adaptor->surfaces[i]->surface_type_id == stuff->surface_type_id) { surface = adaptor->surfaces[i]; break; } } /* adaptor doesn't support this suface_type_id */ - if(!surface) return BadMatch; - + if (!surface) + return BadMatch; - if((stuff->width > surface->max_width) || - (stuff->height > surface->max_height)) + if ((stuff->width > surface->max_width) || + (stuff->height > surface->max_height)) return BadValue; - if(!(pContext = malloc(sizeof(XvMCContextRec)))) { - return BadAlloc; + if (!(pContext = malloc(sizeof(XvMCContextRec)))) { + return BadAlloc; } - pContext->pScreen = pScreen; pContext->adapt_num = adapt_num; pContext->context_id = stuff->context_id; @@ -240,23 +240,23 @@ ProcXvMCCreateContext(ClientPtr client) pContext->flags = stuff->flags; pContext->refcnt = 1; - result = (*adaptor->CreateContext)(pPort, pContext, &dwords, &data); + result = (*adaptor->CreateContext) (pPort, pContext, &dwords, &data); - if(result != Success) { - free(pContext); - return result; + if (result != Success) { + free(pContext); + return result; } rep.type = X_Reply; rep.sequenceNumber = client->sequence; - rep.width_actual = pContext->width; - rep.height_actual = pContext->height; - rep.flags_return = pContext->flags; + rep.width_actual = pContext->width; + rep.height_actual = pContext->height; + rep.flags_return = pContext->flags; rep.length = dwords; - WriteToClient(client, sizeof(xvmcCreateContextReply), (char*)&rep); - if(dwords) - WriteToClient(client, dwords << 2, (char*)data); + WriteToClient(client, sizeof(xvmcCreateContextReply), (char *) &rep); + if (dwords) + WriteToClient(client, dwords << 2, (char *) data); AddResource(pContext->context_id, XvMCRTContext, pContext); free(data); @@ -264,25 +264,26 @@ ProcXvMCCreateContext(ClientPtr client) return Success; } -static int +static int ProcXvMCDestroyContext(ClientPtr client) { pointer val; int rc; + REQUEST(xvmcDestroyContextReq); REQUEST_SIZE_MATCH(xvmcDestroyContextReq); rc = dixLookupResourceByType(&val, stuff->context_id, XvMCRTContext, - client, DixDestroyAccess); + client, DixDestroyAccess); if (rc != Success) - return rc; + return rc; - FreeResource(stuff->context_id, RT_NONE); + FreeResource(stuff->context_id, RT_NONE); return Success; } -static int +static int ProcXvMCCreateSurface(ClientPtr client) { CARD32 *data = NULL; @@ -292,27 +293,30 @@ ProcXvMCCreateSurface(ClientPtr client) XvMCSurfacePtr pSurface; XvMCScreenPtr pScreenPriv; xvmcCreateSurfaceReply rep; + REQUEST(xvmcCreateSurfaceReq); REQUEST_SIZE_MATCH(xvmcCreateSurfaceReq); - result = dixLookupResourceByType((pointer *)&pContext, stuff->context_id, - XvMCRTContext, client, DixUseAccess); + result = dixLookupResourceByType((pointer *) &pContext, stuff->context_id, + XvMCRTContext, client, DixUseAccess); if (result != Success) return result; pScreenPriv = XVMC_GET_PRIVATE(pContext->pScreen); - if(!(pSurface = malloc(sizeof(XvMCSurfaceRec)))) + if (!(pSurface = malloc(sizeof(XvMCSurfaceRec)))) return BadAlloc; pSurface->surface_id = stuff->surface_id; pSurface->surface_type_id = pContext->surface_type_id; pSurface->context = pContext; - result = (*pScreenPriv->adaptors[pContext->adapt_num].CreateSurface)( - pSurface, &dwords, &data); + result = + (*pScreenPriv->adaptors[pContext->adapt_num].CreateSurface) (pSurface, + &dwords, + &data); - if(result != Success) { + if (result != Success) { free(pSurface); return result; } @@ -321,9 +325,9 @@ ProcXvMCCreateSurface(ClientPtr client) rep.sequenceNumber = client->sequence; rep.length = dwords; - WriteToClient(client, sizeof(xvmcCreateSurfaceReply), (char*)&rep); - if(dwords) - WriteToClient(client, dwords << 2, (char*)data); + WriteToClient(client, sizeof(xvmcCreateSurfaceReply), (char *) &rep); + if (dwords) + WriteToClient(client, dwords << 2, (char *) data); AddResource(pSurface->surface_id, XvMCRTSurface, pSurface); free(data); @@ -333,16 +337,17 @@ ProcXvMCCreateSurface(ClientPtr client) return Success; } -static int +static int ProcXvMCDestroySurface(ClientPtr client) { pointer val; int rc; + REQUEST(xvmcDestroySurfaceReq); REQUEST_SIZE_MATCH(xvmcDestroySurfaceReq); rc = dixLookupResourceByType(&val, stuff->surface_id, XvMCRTSurface, - client, DixDestroyAccess); + client, DixDestroyAccess); if (rc != Success) return rc; @@ -351,7 +356,7 @@ ProcXvMCDestroySurface(ClientPtr client) return Success; } -static int +static int ProcXvMCCreateSubpicture(ClientPtr client) { Bool image_supported = FALSE; @@ -363,64 +368,70 @@ ProcXvMCCreateSubpicture(ClientPtr client) xvmcCreateSubpictureReply rep; XvMCAdaptorPtr adaptor; XvMCSurfaceInfoPtr surface = NULL; + REQUEST(xvmcCreateSubpictureReq); REQUEST_SIZE_MATCH(xvmcCreateSubpictureReq); - result = dixLookupResourceByType((pointer *)&pContext, stuff->context_id, - XvMCRTContext, client, DixUseAccess); + result = dixLookupResourceByType((pointer *) &pContext, stuff->context_id, + XvMCRTContext, client, DixUseAccess); if (result != Success) return result; pScreenPriv = XVMC_GET_PRIVATE(pContext->pScreen); - adaptor = &(pScreenPriv->adaptors[pContext->adapt_num]); + adaptor = &(pScreenPriv->adaptors[pContext->adapt_num]); /* find which surface this context supports */ - for(i = 0; i < adaptor->num_surfaces; i++) { - if(adaptor->surfaces[i]->surface_type_id == pContext->surface_type_id){ - surface = adaptor->surfaces[i]; - break; - } - } + for (i = 0; i < adaptor->num_surfaces; i++) { + if (adaptor->surfaces[i]->surface_type_id == pContext->surface_type_id) { + surface = adaptor->surfaces[i]; + break; + } + } - if(!surface) return BadMatch; + if (!surface) + return BadMatch; /* make sure this surface supports that xvimage format */ - if(!surface->compatible_subpictures) return BadMatch; + if (!surface->compatible_subpictures) + return BadMatch; - for(i = 0; i < surface->compatible_subpictures->num_xvimages; i++) { - if(surface->compatible_subpictures->xvimage_ids[i] == stuff->xvimage_id) { - image_supported = TRUE; - break; - } + for (i = 0; i < surface->compatible_subpictures->num_xvimages; i++) { + if (surface->compatible_subpictures->xvimage_ids[i] == + stuff->xvimage_id) { + image_supported = TRUE; + break; + } } - if(!image_supported) return BadMatch; + if (!image_supported) + return BadMatch; /* make sure the size is OK */ - if((stuff->width > surface->subpicture_max_width) || - (stuff->height > surface->subpicture_max_height)) - return BadValue; + if ((stuff->width > surface->subpicture_max_width) || + (stuff->height > surface->subpicture_max_height)) + return BadValue; - if(!(pSubpicture = malloc(sizeof(XvMCSubpictureRec)))) + if (!(pSubpicture = malloc(sizeof(XvMCSubpictureRec)))) return BadAlloc; pSubpicture->subpicture_id = stuff->subpicture_id; pSubpicture->xvimage_id = stuff->xvimage_id; pSubpicture->width = stuff->width; pSubpicture->height = stuff->height; - pSubpicture->num_palette_entries = 0; /* overwritten by DDX */ - pSubpicture->entry_bytes = 0; /* overwritten by DDX */ - pSubpicture->component_order[0] = 0; /* overwritten by DDX */ + pSubpicture->num_palette_entries = 0; /* overwritten by DDX */ + pSubpicture->entry_bytes = 0; /* overwritten by DDX */ + pSubpicture->component_order[0] = 0; /* overwritten by DDX */ pSubpicture->component_order[1] = 0; pSubpicture->component_order[2] = 0; pSubpicture->component_order[3] = 0; pSubpicture->context = pContext; - - result = (*pScreenPriv->adaptors[pContext->adapt_num].CreateSubpicture)( - pSubpicture, &dwords, &data); - if(result != Success) { + result = + (*pScreenPriv->adaptors[pContext->adapt_num]. + CreateSubpicture) (pSubpicture, &dwords, &data); + + if (result != Success) { free(pSubpicture); return result; } @@ -437,9 +448,9 @@ ProcXvMCCreateSubpicture(ClientPtr client) rep.component_order[3] = pSubpicture->component_order[3]; rep.length = dwords; - WriteToClient(client, sizeof(xvmcCreateSubpictureReply), (char*)&rep); - if(dwords) - WriteToClient(client, dwords << 2, (char*)data); + WriteToClient(client, sizeof(xvmcCreateSubpictureReply), (char *) &rep); + if (dwords) + WriteToClient(client, dwords << 2, (char *) data); AddResource(pSubpicture->subpicture_id, XvMCRTSubpicture, pSubpicture); free(data); @@ -449,16 +460,17 @@ ProcXvMCCreateSubpicture(ClientPtr client) return Success; } -static int +static int ProcXvMCDestroySubpicture(ClientPtr client) { pointer val; int rc; + REQUEST(xvmcDestroySubpictureReq); REQUEST_SIZE_MATCH(xvmcDestroySubpictureReq); rc = dixLookupResourceByType(&val, stuff->subpicture_id, XvMCRTSubpicture, - client, DixDestroyAccess); + client, DixDestroyAccess); if (rc != Success) return rc; @@ -467,7 +479,6 @@ ProcXvMCDestroySubpicture(ClientPtr client) return Success; } - static int ProcXvMCListSubpictureTypes(ClientPtr client) { @@ -480,6 +491,7 @@ ProcXvMCListSubpictureTypes(ClientPtr client) xvImageFormatInfo info; XvImagePtr pImage; int i, j; + REQUEST(xvmcListSubpictureTypesReq); REQUEST_SIZE_MATCH(xvmcListSubpictureTypesReq); @@ -488,74 +500,76 @@ ProcXvMCListSubpictureTypes(ClientPtr client) pScreen = pPort->pAdaptor->pScreen; if (!dixPrivateKeyRegistered(XvMCScreenKey)) - return BadMatch; /* No XvMC adaptors */ + return BadMatch; /* No XvMC adaptors */ - if(!(pScreenPriv = XVMC_GET_PRIVATE(pScreen))) - return BadMatch; /* None this screen */ + if (!(pScreenPriv = XVMC_GET_PRIVATE(pScreen))) + return BadMatch; /* None this screen */ - for(i = 0; i < pScreenPriv->num_adaptors; i++) { - if(pPort->pAdaptor == pScreenPriv->adaptors[i].xv_adaptor) { + for (i = 0; i < pScreenPriv->num_adaptors; i++) { + if (pPort->pAdaptor == pScreenPriv->adaptors[i].xv_adaptor) { adaptor = &(pScreenPriv->adaptors[i]); break; } } - if(!adaptor) return BadMatch; + if (!adaptor) + return BadMatch; - for(i = 0; i < adaptor->num_surfaces; i++) { - if(adaptor->surfaces[i]->surface_type_id == stuff->surface_type_id) { + for (i = 0; i < adaptor->num_surfaces; i++) { + if (adaptor->surfaces[i]->surface_type_id == stuff->surface_type_id) { surface = adaptor->surfaces[i]; break; } } - if(!surface) return BadMatch; + if (!surface) + return BadMatch; rep.type = X_Reply; rep.sequenceNumber = client->sequence; rep.num = 0; - if(surface->compatible_subpictures) - rep.num = surface->compatible_subpictures->num_xvimages; + if (surface->compatible_subpictures) + rep.num = surface->compatible_subpictures->num_xvimages; rep.length = bytes_to_int32(rep.num * sizeof(xvImageFormatInfo)); - WriteToClient(client, sizeof(xvmcListSubpictureTypesReply), (char*)&rep); - - for(i = 0; i < rep.num; i++) { - pImage = NULL; - for(j = 0; j < adaptor->num_subpictures; j++) { - if(surface->compatible_subpictures->xvimage_ids[i] == - adaptor->subpictures[j]->id) - { - pImage = adaptor->subpictures[j]; - break; - } - } - if(!pImage) return BadImplementation; - - info.id = pImage->id; - info.type = pImage->type; - info.byte_order = pImage->byte_order; - memcpy(&info.guid, pImage->guid, 16); - info.bpp = pImage->bits_per_pixel; - info.num_planes = pImage->num_planes; - info.depth = pImage->depth; - info.red_mask = pImage->red_mask; - info.green_mask = pImage->green_mask; - info.blue_mask = pImage->blue_mask; - info.format = pImage->format; - info.y_sample_bits = pImage->y_sample_bits; - info.u_sample_bits = pImage->u_sample_bits; - info.v_sample_bits = pImage->v_sample_bits; - info.horz_y_period = pImage->horz_y_period; - info.horz_u_period = pImage->horz_u_period; - info.horz_v_period = pImage->horz_v_period; - info.vert_y_period = pImage->vert_y_period; - info.vert_u_period = pImage->vert_u_period; - info.vert_v_period = pImage->vert_v_period; - memcpy(&info.comp_order, pImage->component_order, 32); + WriteToClient(client, sizeof(xvmcListSubpictureTypesReply), (char *) &rep); + + for (i = 0; i < rep.num; i++) { + pImage = NULL; + for (j = 0; j < adaptor->num_subpictures; j++) { + if (surface->compatible_subpictures->xvimage_ids[i] == + adaptor->subpictures[j]->id) { + pImage = adaptor->subpictures[j]; + break; + } + } + if (!pImage) + return BadImplementation; + + info.id = pImage->id; + info.type = pImage->type; + info.byte_order = pImage->byte_order; + memcpy(&info.guid, pImage->guid, 16); + info.bpp = pImage->bits_per_pixel; + info.num_planes = pImage->num_planes; + info.depth = pImage->depth; + info.red_mask = pImage->red_mask; + info.green_mask = pImage->green_mask; + info.blue_mask = pImage->blue_mask; + info.format = pImage->format; + info.y_sample_bits = pImage->y_sample_bits; + info.u_sample_bits = pImage->u_sample_bits; + info.v_sample_bits = pImage->v_sample_bits; + info.horz_y_period = pImage->horz_y_period; + info.horz_u_period = pImage->horz_u_period; + info.horz_v_period = pImage->horz_v_period; + info.vert_y_period = pImage->vert_y_period; + info.vert_u_period = pImage->vert_u_period; + info.vert_v_period = pImage->vert_v_period; + memcpy(&info.comp_order, pImage->component_order, 32); info.scanline_order = pImage->scanline_order; - WriteToClient(client, sizeof(xvImageFormatInfo), (char*)&info); + WriteToClient(client, sizeof(xvImageFormatInfo), (char *) &info); } return Success; @@ -580,7 +594,7 @@ ProcXvMCGetDRInfo(ClientPtr client) pScreen = pPort->pAdaptor->pScreen; pScreenPriv = XVMC_GET_PRIVATE(pScreen); - + rep.type = X_Reply; rep.sequenceNumber = client->sequence; rep.major = pScreenPriv->major; @@ -590,8 +604,8 @@ ProcXvMCGetDRInfo(ClientPtr client) rep.busIDLen = bytes_to_int32(strlen(pScreenPriv->busID) + 1); rep.length = rep.nameLen + rep.busIDLen; - rep.nameLen <<=2; - rep.busIDLen <<=2; + rep.nameLen <<= 2; + rep.busIDLen <<= 2; /* * Read back to the client what she has put in the shared memory @@ -600,64 +614,58 @@ ProcXvMCGetDRInfo(ClientPtr client) rep.isLocal = 1; #ifdef HAS_XVMCSHM - patternP = (CARD32 *)shmat( stuff->shmKey, NULL, SHM_RDONLY ); - if ( -1 != (long) patternP) { + patternP = (CARD32 *) shmat(stuff->shmKey, NULL, SHM_RDONLY); + if (-1 != (long) patternP) { volatile CARD32 *patternC = patternP; - int i; - CARD32 magic = stuff->magic; - - rep.isLocal = 1; - i = 1024 / sizeof(CARD32); - - while ( i-- ) { - if (*patternC++ != magic) { - rep.isLocal = 0; - break; - } - magic = ~magic; - } - shmdt( (char *)patternP ); + int i; + CARD32 magic = stuff->magic; + + rep.isLocal = 1; + i = 1024 / sizeof(CARD32); + + while (i--) { + if (*patternC++ != magic) { + rep.isLocal = 0; + break; + } + magic = ~magic; + } + shmdt((char *) patternP); + } +#endif /* HAS_XVMCSHM */ + + WriteToClient(client, sizeof(xvmcGetDRInfoReply), (char *) &rep); + if (rep.length) { + WriteToClient(client, rep.nameLen, pScreenPriv->clientDriverName); + WriteToClient(client, rep.busIDLen, pScreenPriv->busID); } -#endif /* HAS_XVMCSHM */ - - WriteToClient(client, sizeof(xvmcGetDRInfoReply), - (char*)&rep); - if (rep.length) { - WriteToClient(client, rep.nameLen, - pScreenPriv->clientDriverName); - WriteToClient(client, rep.busIDLen, - pScreenPriv->busID); - } return Success; } - -int (*ProcXvMCVector[xvmcNumRequest])(ClientPtr) = { - ProcXvMCQueryVersion, - ProcXvMCListSurfaceTypes, - ProcXvMCCreateContext, - ProcXvMCDestroyContext, - ProcXvMCCreateSurface, - ProcXvMCDestroySurface, - ProcXvMCCreateSubpicture, - ProcXvMCDestroySubpicture, - ProcXvMCListSubpictureTypes, - ProcXvMCGetDRInfo -}; +int (*ProcXvMCVector[xvmcNumRequest]) (ClientPtr) = { +ProcXvMCQueryVersion, + ProcXvMCListSurfaceTypes, + ProcXvMCCreateContext, + ProcXvMCDestroyContext, + ProcXvMCCreateSurface, + ProcXvMCDestroySurface, + ProcXvMCCreateSubpicture, + ProcXvMCDestroySubpicture, + ProcXvMCListSubpictureTypes, ProcXvMCGetDRInfo}; static int -ProcXvMCDispatch (ClientPtr client) +ProcXvMCDispatch(ClientPtr client) { REQUEST(xReq); - - if(stuff->data < xvmcNumRequest) - return (*ProcXvMCVector[stuff->data])(client); + + if (stuff->data < xvmcNumRequest) + return (*ProcXvMCVector[stuff->data]) (client); else - return BadRequest; + return BadRequest; } static int -SProcXvMCDispatch (ClientPtr client) +SProcXvMCDispatch(ClientPtr client) { /* We only support local */ return BadImplementation; @@ -666,38 +674,42 @@ SProcXvMCDispatch (ClientPtr client) void XvMCExtensionInit(void) { - ExtensionEntry *extEntry; - - if (!dixPrivateKeyRegistered(XvMCScreenKey)) - return; - - if(!(XvMCRTContext = CreateNewResourceType(XvMCDestroyContextRes, - "XvMCRTContext"))) - return; - - if(!(XvMCRTSurface = CreateNewResourceType(XvMCDestroySurfaceRes, - "XvMCRTSurface"))) - return; - - if(!(XvMCRTSubpicture = CreateNewResourceType(XvMCDestroySubpictureRes, - "XvMCRTSubpicture"))) - return; - - extEntry = AddExtension(XvMCName, XvMCNumEvents, XvMCNumErrors, - ProcXvMCDispatch, SProcXvMCDispatch, - NULL, StandardMinorOpcode); - - if(!extEntry) return; - - XvMCReqCode = extEntry->base; - XvMCEventBase = extEntry->eventBase; - SetResourceTypeErrorValue(XvMCRTContext, extEntry->errorBase + XvMCBadContext); - SetResourceTypeErrorValue(XvMCRTSurface, extEntry->errorBase + XvMCBadSurface); - SetResourceTypeErrorValue(XvMCRTSubpicture, extEntry->errorBase + XvMCBadSubpicture); + ExtensionEntry *extEntry; + + if (!dixPrivateKeyRegistered(XvMCScreenKey)) + return; + + if (!(XvMCRTContext = CreateNewResourceType(XvMCDestroyContextRes, + "XvMCRTContext"))) + return; + + if (!(XvMCRTSurface = CreateNewResourceType(XvMCDestroySurfaceRes, + "XvMCRTSurface"))) + return; + + if (!(XvMCRTSubpicture = CreateNewResourceType(XvMCDestroySubpictureRes, + "XvMCRTSubpicture"))) + return; + + extEntry = AddExtension(XvMCName, XvMCNumEvents, XvMCNumErrors, + ProcXvMCDispatch, SProcXvMCDispatch, + NULL, StandardMinorOpcode); + + if (!extEntry) + return; + + XvMCReqCode = extEntry->base; + XvMCEventBase = extEntry->eventBase; + SetResourceTypeErrorValue(XvMCRTContext, + extEntry->errorBase + XvMCBadContext); + SetResourceTypeErrorValue(XvMCRTSurface, + extEntry->errorBase + XvMCBadSurface); + SetResourceTypeErrorValue(XvMCRTSubpicture, + extEntry->errorBase + XvMCBadSubpicture); } static Bool -XvMCCloseScreen (int i, ScreenPtr pScreen) +XvMCCloseScreen(int i, ScreenPtr pScreen) { XvMCScreenPtr pScreenPriv = XVMC_GET_PRIVATE(pScreen); @@ -705,40 +717,40 @@ XvMCCloseScreen (int i, ScreenPtr pScreen) free(pScreenPriv); - return (*pScreen->CloseScreen)(i, pScreen); + return (*pScreen->CloseScreen) (i, pScreen); } - int XvMCScreenInit(ScreenPtr pScreen, int num, XvMCAdaptorPtr pAdapt) { - XvMCScreenPtr pScreenPriv; + XvMCScreenPtr pScreenPriv; - if (!dixRegisterPrivateKey(&XvMCScreenKeyRec, PRIVATE_SCREEN, 0)) - return BadAlloc; + if (!dixRegisterPrivateKey(&XvMCScreenKeyRec, PRIVATE_SCREEN, 0)) + return BadAlloc; - if(!(pScreenPriv = malloc(sizeof(XvMCScreenRec)))) - return BadAlloc; + if (!(pScreenPriv = malloc(sizeof(XvMCScreenRec)))) + return BadAlloc; - dixSetPrivate(&pScreen->devPrivates, XvMCScreenKey, pScreenPriv); + dixSetPrivate(&pScreen->devPrivates, XvMCScreenKey, pScreenPriv); - pScreenPriv->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = XvMCCloseScreen; + pScreenPriv->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = XvMCCloseScreen; - pScreenPriv->num_adaptors = num; - pScreenPriv->adaptors = pAdapt; - pScreenPriv->clientDriverName[0] = 0; - pScreenPriv->busID[0] = 0; - pScreenPriv->major = 0; - pScreenPriv->minor = 0; - pScreenPriv->patchLevel = 0; + pScreenPriv->num_adaptors = num; + pScreenPriv->adaptors = pAdapt; + pScreenPriv->clientDriverName[0] = 0; + pScreenPriv->busID[0] = 0; + pScreenPriv->major = 0; + pScreenPriv->minor = 0; + pScreenPriv->patchLevel = 0; - XvMCInUse = TRUE; + XvMCInUse = TRUE; - return Success; + return Success; } -XvImagePtr XvMCFindXvImage(XvPortPtr pPort, CARD32 id) +XvImagePtr +XvMCFindXvImage(XvPortPtr pPort, CARD32 id) { XvImagePtr pImage = NULL; ScreenPtr pScreen = pPort->pAdaptor->pScreen; @@ -749,20 +761,21 @@ XvImagePtr XvMCFindXvImage(XvPortPtr pPort, CARD32 id) if (!dixPrivateKeyRegistered(XvMCScreenKey)) return NULL; - if(!(pScreenPriv = XVMC_GET_PRIVATE(pScreen))) + if (!(pScreenPriv = XVMC_GET_PRIVATE(pScreen))) return NULL; - for(i = 0; i < pScreenPriv->num_adaptors; i++) { - if(pPort->pAdaptor == pScreenPriv->adaptors[i].xv_adaptor) { - adaptor = &(pScreenPriv->adaptors[i]); - break; - } + for (i = 0; i < pScreenPriv->num_adaptors; i++) { + if (pPort->pAdaptor == pScreenPriv->adaptors[i].xv_adaptor) { + adaptor = &(pScreenPriv->adaptors[i]); + break; + } } - if(!adaptor) return NULL; + if (!adaptor) + return NULL; - for(i = 0; i < adaptor->num_subpictures; i++) { - if(adaptor->subpictures[i]->id == id) { + for (i = 0; i < adaptor->num_subpictures; i++) { + if (adaptor->subpictures[i]->id == id) { pImage = adaptor->subpictures[i]; break; } @@ -773,16 +786,14 @@ XvImagePtr XvMCFindXvImage(XvPortPtr pPort, CARD32 id) int xf86XvMCRegisterDRInfo(ScreenPtr pScreen, char *name, - char *busID, int major, int minor, - int patchLevel) + char *busID, int major, int minor, int patchLevel) { XvMCScreenPtr pScreenPriv = XVMC_GET_PRIVATE(pScreen); - strlcpy(pScreenPriv->clientDriverName, name, - DR_CLIENT_DRIVER_NAME_SIZE); + + strlcpy(pScreenPriv->clientDriverName, name, DR_CLIENT_DRIVER_NAME_SIZE); strlcpy(pScreenPriv->busID, busID, DR_BUSID_SIZE); pScreenPriv->major = major; pScreenPriv->minor = minor; pScreenPriv->patchLevel = patchLevel; return Success; } - diff --git a/xorg-server/Xext/xvmcext.h b/xorg-server/Xext/xvmcext.h index 5b431260f..5a4261bbd 100644 --- a/xorg-server/Xext/xvmcext.h +++ b/xorg-server/Xext/xvmcext.h @@ -5,114 +5,96 @@ #include "xvdix.h" typedef struct { - int num_xvimages; - int *xvimage_ids; + int num_xvimages; + int *xvimage_ids; } XvMCImageIDList; typedef struct { - int surface_type_id; - int chroma_format; - int color_description; - unsigned short max_width; - unsigned short max_height; - unsigned short subpicture_max_width; - unsigned short subpicture_max_height; - int mc_type; - int flags; - XvMCImageIDList *compatible_subpictures; + int surface_type_id; + int chroma_format; + int color_description; + unsigned short max_width; + unsigned short max_height; + unsigned short subpicture_max_width; + unsigned short subpicture_max_height; + int mc_type; + int flags; + XvMCImageIDList *compatible_subpictures; } XvMCSurfaceInfoRec, *XvMCSurfaceInfoPtr; typedef struct { - XID context_id; - ScreenPtr pScreen; - int adapt_num; - int surface_type_id; - unsigned short width; - unsigned short height; - CARD32 flags; - int refcnt; - pointer port_priv; - pointer driver_priv; + XID context_id; + ScreenPtr pScreen; + int adapt_num; + int surface_type_id; + unsigned short width; + unsigned short height; + CARD32 flags; + int refcnt; + pointer port_priv; + pointer driver_priv; } XvMCContextRec, *XvMCContextPtr; typedef struct { - XID surface_id; - int surface_type_id; - XvMCContextPtr context; - pointer driver_priv; + XID surface_id; + int surface_type_id; + XvMCContextPtr context; + pointer driver_priv; } XvMCSurfaceRec, *XvMCSurfacePtr; - typedef struct { - XID subpicture_id; - int xvimage_id; - unsigned short width; - unsigned short height; - int num_palette_entries; - int entry_bytes; - char component_order[4]; - XvMCContextPtr context; - pointer driver_priv; + XID subpicture_id; + int xvimage_id; + unsigned short width; + unsigned short height; + int num_palette_entries; + int entry_bytes; + char component_order[4]; + XvMCContextPtr context; + pointer driver_priv; } XvMCSubpictureRec, *XvMCSubpicturePtr; -typedef int (*XvMCCreateContextProcPtr) ( - XvPortPtr port, - XvMCContextPtr context, - int *num_priv, - CARD32 **priv -); - -typedef void (*XvMCDestroyContextProcPtr) ( - XvMCContextPtr context -); +typedef int (*XvMCCreateContextProcPtr) (XvPortPtr port, + XvMCContextPtr context, + int *num_priv, CARD32 **priv); -typedef int (*XvMCCreateSurfaceProcPtr) ( - XvMCSurfacePtr surface, - int *num_priv, - CARD32 **priv -); +typedef void (*XvMCDestroyContextProcPtr) (XvMCContextPtr context); -typedef void (*XvMCDestroySurfaceProcPtr) ( - XvMCSurfacePtr surface -); +typedef int (*XvMCCreateSurfaceProcPtr) (XvMCSurfacePtr surface, + int *num_priv, CARD32 **priv); -typedef int (*XvMCCreateSubpictureProcPtr) ( - XvMCSubpicturePtr subpicture, - int *num_priv, - CARD32 **priv -); +typedef void (*XvMCDestroySurfaceProcPtr) (XvMCSurfacePtr surface); -typedef void (*XvMCDestroySubpictureProcPtr) ( - XvMCSubpicturePtr subpicture -); +typedef int (*XvMCCreateSubpictureProcPtr) (XvMCSubpicturePtr subpicture, + int *num_priv, CARD32 **priv); +typedef void (*XvMCDestroySubpictureProcPtr) (XvMCSubpicturePtr subpicture); typedef struct { - XvAdaptorPtr xv_adaptor; - int num_surfaces; - XvMCSurfaceInfoPtr *surfaces; - int num_subpictures; - XvImagePtr *subpictures; - XvMCCreateContextProcPtr CreateContext; - XvMCDestroyContextProcPtr DestroyContext; - XvMCCreateSurfaceProcPtr CreateSurface; - XvMCDestroySurfaceProcPtr DestroySurface; - XvMCCreateSubpictureProcPtr CreateSubpicture; - XvMCDestroySubpictureProcPtr DestroySubpicture; + XvAdaptorPtr xv_adaptor; + int num_surfaces; + XvMCSurfaceInfoPtr *surfaces; + int num_subpictures; + XvImagePtr *subpictures; + XvMCCreateContextProcPtr CreateContext; + XvMCDestroyContextProcPtr DestroyContext; + XvMCCreateSurfaceProcPtr CreateSurface; + XvMCDestroySurfaceProcPtr DestroySurface; + XvMCCreateSubpictureProcPtr CreateSubpicture; + XvMCDestroySubpictureProcPtr DestroySubpicture; } XvMCAdaptorRec, *XvMCAdaptorPtr; #ifndef XorgLoader extern _X_EXPORT void XvMCExtensionInit(void); extern _X_EXPORT int XvMCScreenInit(ScreenPtr pScreen, - int num, - XvMCAdaptorPtr adapt); + int num, XvMCAdaptorPtr adapt); extern _X_EXPORT XvImagePtr XvMCFindXvImage(XvPortPtr pPort, CARD32 id); extern _X_EXPORT int xf86XvMCRegisterDRInfo(ScreenPtr pScreen, char *name, - char *busID, int major, int minor, - int patchLevel); + char *busID, int major, int minor, + int patchLevel); #endif -#endif /* _XVMC_H */ +#endif /* _XVMC_H */ |