📄 shm.c
字号:
stuffptr = shmdesc->addr + stuff->offset ; tmpptr = tmpImage; for (i = 0; i < stuff->totalHeight*stuff->depth; stuffptr += lineBytesProto,tmpptr += lineBytes, i++) bcopy(stuffptr,tmpptr,lineBytesProto); } else { for (i = 0, stuffptr = shmdesc->addr + stuff->offset, tmpptr=tmpImage; i < stuff->totalHeight; stuffptr += lengthProto,tmpptr += length, i++) bcopy(stuffptr,tmpptr,lengthProto); } } /* handle 64-bit case where stuff is not 64-bit aligned */ else if ((unsigned long)(shmdesc->addr+stuff->offset) & (sizeof(long)-1)) { if(!(tmpImage = (char *) ALLOCATE_LOCAL(length*stuff->totalHeight))) return (BadAlloc); tmpAlloced = 1; bcopy((char *)(shmdesc->addr+stuff->offset), tmpImage, length*stuff->totalHeight); } else tmpImage = (char *)(shmdesc->addr+stuff->offset);#endif 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, #ifdef INTERNAL_VS_EXTERNAL_PADDING tmpImage +#else shmdesc->addr + stuff->offset +#endif (stuff->srcY * length)); else (*shmFuncs[pDraw->pScreen->myNum]->PutImage)( pDraw, pGC, stuff->depth, stuff->format, stuff->totalWidth, stuff->totalHeight, stuff->srcX, stuff->srcY, stuff->srcWidth, stuff->srcHeight, stuff->dstX, stuff->dstY,#ifdef INTERNAL_VS_EXTERNAL_PADDING tmpImage); #else shmdesc->addr + stuff->offset);#endif if (stuff->sendEvent) { xShmCompletionEvent ev; ev.type = ShmCompletionCode; ev.drawable = stuff->drawable; ev.sequenceNumber = client->sequence; ev.minorEvent = X_ShmPutImage; ev.majorEvent = ShmReqCode; ev.shmseg = stuff->shmseg; ev.offset = stuff->offset; WriteEventsToClient(client, 1, (xEvent *) &ev); }#ifdef INTERNAL_VS_EXTERNAL_PADDING if (tmpAlloced) DEALLOCATE_LOCAL(tmpImage);#endif return (client->noClientException);}static intProcShmGetImage(client) register ClientPtr client;{ register DrawablePtr pDraw; long lenPer, length; Mask plane; xShmGetImageReply xgi; ShmDescPtr shmdesc; int n;#ifdef INTERNAL_VS_EXTERNAL_PADDING long widthBytesLine,widthBytesLineProto; long lenPerProto,lengthProto; char *tmpImage; int tmpAlloced = 0;#endif REQUEST(xShmGetImageReq); REQUEST_SIZE_MATCH(xShmGetImageReq); if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) { client->errorValue = stuff->format; return(BadValue); } VERIFY_DRAWABLE(pDraw, stuff->drawable, client); 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)); } 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) {#ifdef INTERNAL_VS_EXTERNAL_PADDING widthBytesLine = PixmapBytePad(stuff->width, pDraw->depth); length = widthBytesLine * stuff->height; widthBytesLineProto = PixmapBytePadProto(stuff->width, pDraw->depth); lengthProto = widthBytesLineProto * stuff->height;#else length = PixmapBytePad(stuff->width, pDraw->depth) * stuff->height;#endif } else {#ifdef INTERNAL_VS_EXTERNAL_PADDING widthBytesLine = PixmapBytePad(stuff->width, 1); lenPer = widthBytesLine * stuff->height; plane = ((Mask)1) << (pDraw->depth - 1); /* only planes asked for */ length = lenPer * Ones(stuff->planeMask & (plane | (plane - 1))); widthBytesLineProto = PixmapBytePadProto(stuff->width, 1); lenPerProto = widthBytesLineProto * stuff->height; lengthProto = lenPerProto * 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)));#endif }#ifdef INTERNAL_VS_EXTERNAL_PADDING VERIFY_SHMSIZE(shmdesc, stuff->offset, lengthProto, client); xgi.size = lengthProto;#else VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); xgi.size = length;#endif if (length == 0) { /* nothing to do */ } else if (stuff->format == ZPixmap) {#ifdef INTERNAL_VS_EXTERNAL_PADDING /* check for protocol/server padding differences. */ if ((widthBytesLine != widthBytesLineProto) || ((unsigned long)shmdesc->addr + stuff->offset & (sizeof(long)-1))) { /* temp stuff for 64 bit alignment stuff */ register char * bufPtr, * protoPtr; register int i; if(!(tmpImage = (char *) ALLOCATE_LOCAL(length))) return (BadAlloc); tmpAlloced = 1; (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y, stuff->width, stuff->height, stuff->format, stuff->planeMask, tmpImage); /* for 64-bit server, convert image to pad to 32 bits */ bzero(shmdesc->addr + stuff->offset,lengthProto); for (i=0,bufPtr=tmpImage,protoPtr=shmdesc->addr + stuff->offset; i < stuff->height; bufPtr += widthBytesLine,protoPtr += widthBytesLineProto, i++) bcopy(bufPtr,protoPtr,widthBytesLineProto); } else { (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y, stuff->width, stuff->height, stuff->format, stuff->planeMask, shmdesc->addr + stuff->offset); }#else (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y, stuff->width, stuff->height, stuff->format, stuff->planeMask, shmdesc->addr + stuff->offset);#endif } else {#ifdef INTERNAL_VS_EXTERNAL_PADDING /* check for protocol/server padding differences. */ if ((widthBytesLine != widthBytesLineProto) || ((unsigned long)shmdesc->addr + stuff->offset & (sizeof(long)-1))) { if(!(tmpImage = (char *) ALLOCATE_LOCAL(length))) return (BadAlloc); tmpAlloced = 1; }#endif length = stuff->offset; for (; plane; plane >>= 1) { if (stuff->planeMask & plane) {#ifdef INTERNAL_VS_EXTERNAL_PADDING if ((widthBytesLine != widthBytesLineProto) || ((unsigned long)shmdesc->addr + stuff->offset & (sizeof(long)-1))) { /* get image for each plane. */ (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y, stuff->width, stuff->height, stuff->format, plane, tmpImage); /* for 64-bit server, convert image to pad to 32 bits */ bzero(shmdesc->addr+length, widthBytesLine); bcopy(tmpImage, shmdesc->addr+length, widthBytesLineProto); /* increment length */ length += lenPerProto; } else /* no diff between protocol and server */ { (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y, stuff->width, stuff->height, stuff->format, plane, shmdesc->addr + length); length += lenPer; }#else (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y, stuff->width, stuff->height, stuff->format, plane, shmdesc->addr + length); length += lenPer;#endif } } } if (client->swapped) { swaps(&xgi.sequenceNumber, n); swapl(&xgi.length, n); swapl(&xgi.visual, n); swapl(&xgi.size, n); } WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi);#ifdef INTERNAL_VS_EXTERNAL_PADDING if (tmpAlloced) DEALLOCATE_LOCAL(tmpImage);#endif return(client->noClientException);}static PixmapPtrfbShmCreatePixmap (pScreen, width, height, depth, addr) ScreenPtr pScreen; int width; int height; int depth; char *addr;{ register PixmapPtr pPixmap; pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScreen->rootDepth); if (!pPixmap) return NullPixmap; if (!(*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth, /*XXX*/depth, PixmapBytePad(width, depth), (pointer)addr)) return NullPixmap; return pPixmap;}static intProcShmCreatePixmap(client) register ClientPtr client;{ PixmapPtr pMap; register DrawablePtr pDraw; DepthPtr pDepth; register int i; ShmDescPtr shmdesc; REQUEST(xShmCreatePixmapReq); REQUEST_SIZE_MATCH(xShmCreatePixmapReq); client->errorValue = stuff->pid; if (!sharedPixmaps) return BadImplementation; LEGAL_NEW_RESOURCE(stuff->pid, client); VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client); VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); if (!stuff->width || !stuff->height) { client->errorValue = 0; return BadValue; } 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; return BadValue; }CreatePmap: VERIFY_SHMSIZE(shmdesc, stuff->offset, PixmapBytePad(stuff->width, stuff->depth) * stuff->height, client); pMap = (*shmFuncs[pDraw->pScreen->myNum]->CreatePixmap)( pDraw->pScreen, stuff->width, stuff->height, stuff->depth, shmdesc->addr + stuff->offset); if (pMap) { pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; pMap->drawable.id = stuff->pid; if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap)) { shmdesc->refcnt++; if (AddResource(stuff->pid, ShmPixType, (pointer)shmdesc)) return(client->noClientException); FreeResource(stuff->pid, RT_NONE); } } return (BadAlloc);}static intProcShmDispatch (client) register ClientPtr client;{ REQUEST(xReq); switch (stuff->data) { case X_ShmQueryVersion: return ProcShmQueryVersion(client); case X_ShmAttach: return ProcShmAttach(client); case X_ShmDetach: return ProcShmDetach(client); case X_ShmPutImage: return ProcShmPutImage(client); case X_ShmGetImage: return ProcShmGetImage(client); case X_ShmCreatePixmap: return ProcShmCreatePixmap(client); default: return BadRequest; }}static voidSShmCompletionEvent(from, to) xShmCompletionEvent *from, *to;{ to->type = from->type; cpswaps(from->sequenceNumber, to->sequenceNumber); cpswapl(from->drawable, to->drawable); cpswaps(from->minorEvent, to->minorEvent); to->majorEvent = from->majorEvent; cpswapl(from->shmseg, to->shmseg); cpswapl(from->offset, to->offset);}static intSProcShmQueryVersion(client) register ClientPtr client;{ register int n; REQUEST(xShmQueryVersionReq); swaps(&stuff->length, n); return ProcShmQueryVersion(client);}static intSProcShmAttach(client) ClientPtr client;{ register int n; REQUEST(xShmAttachReq); swaps(&stuff->length, n); REQUEST_SIZE_MATCH(xShmAttachReq); swapl(&stuff->shmseg, n); swapl(&stuff->shmid, n); return ProcShmAttach(client);}static intSProcShmDetach(client) ClientPtr client;{ register int n; REQUEST(xShmDetachReq); swaps(&stuff->length, n); REQUEST_SIZE_MATCH(xShmDetachReq); swapl(&stuff->shmseg, n); return ProcShmDetach(client);}static intSProcShmPutImage(client) ClientPtr client;{ register int n; REQUEST(xShmPutImageReq); swaps(&stuff->length, n); REQUEST_SIZE_MATCH(xShmPutImageReq); swapl(&stuff->drawable, n); swapl(&stuff->gc, n); swaps(&stuff->totalWidth, n); swaps(&stuff->totalHeight, n); swaps(&stuff->srcX, n); swaps(&stuff->srcY, n); swaps(&stuff->srcWidth, n); swaps(&stuff->srcHeight, n); swaps(&stuff->dstX, n); swaps(&stuff->dstY, n); swapl(&stuff->shmseg, n); swapl(&stuff->offset, n); return ProcShmPutImage(client);}static intSProcShmGetImage(client) ClientPtr client;{ register int n; REQUEST(xShmGetImageReq); swaps(&stuff->length, n); REQUEST_SIZE_MATCH(xShmGetImageReq); swapl(&stuff->drawable, n); swaps(&stuff->x, n); swaps(&stuff->y, n); swaps(&stuff->width, n); swaps(&stuff->height, n); swapl(&stuff->planeMask, n); swapl(&stuff->shmseg, n); swapl(&stuff->offset, n); return ProcShmGetImage(client);}static intSProcShmCreatePixmap(client) ClientPtr client;{ register int n; REQUEST(xShmCreatePixmapReq); swaps(&stuff->length, n); REQUEST_SIZE_MATCH(xShmCreatePixmapReq); swapl(&stuff->pid, n); swapl(&stuff->drawable, n); swaps(&stuff->width, n); swaps(&stuff->height, n); swapl(&stuff->shmseg, n); swapl(&stuff->offset, n); return ProcShmCreatePixmap(client);}static intSProcShmDispatch (client) register ClientPtr client;{ REQUEST(xReq); switch (stuff->data) { case X_ShmQueryVersion: return SProcShmQueryVersion(client); case X_ShmAttach: return SProcShmAttach(client); case X_ShmDetach: return SProcShmDetach(client); case X_ShmPutImage: return SProcShmPutImage(client); case X_ShmGetImage: return SProcShmGetImage(client); case X_ShmCreatePixmap: return SProcShmCreatePixmap(client); default: return BadRequest; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -