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/shm.c | |
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/shm.c')
-rw-r--r-- | xorg-server/Xext/shm.c | 1075 |
1 files changed, 526 insertions, 549 deletions
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; } } |