void LeoFillSpansStippled (DrawablePtr pDrawable, GCPtr pGC, int n, DDXPointPtr ppt, int *pwidth, int fSorted) { LeoPrivGCPtr gcPriv = LeoGetGCPrivate (pGC); LeoPtr pLeo = LeoGetScreenPrivate (pGC->pScreen); LeoCommand0 *lc0 = pLeo->lc0; LeoDraw *ld0 = pLeo->ld0; int numRects, *pwidthFree; DDXPointPtr pptFree; RegionPtr clip; unsigned char *fb; unsigned int *bits, msk; int cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0; clip = cfbGetCompositeClip(pGC); numRects = REGION_NUM_RECTS(clip); if (!numRects) return; if (numRects == 1) { cx1 = clip->extents.x1; cx2 = clip->extents.x2; cy1 = clip->extents.y1; cy2 = clip->extents.y2; } else { int nTmp = n * miFindMaxBand(clip); pwidthFree = (int *)ALLOCATE_LOCAL(nTmp * sizeof(int)); pptFree = (DDXPointRec *)ALLOCATE_LOCAL(nTmp * sizeof(DDXPointRec)); if (!pptFree || !pwidthFree) { if (pptFree) DEALLOCATE_LOCAL(pptFree); if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree); return; } n = miClipSpans(clip, ppt, pwidth, n, pptFree, pwidthFree, fSorted); pwidth = pwidthFree; ppt = pptFree; } if (pGC->alu != GXcopy) ld0->rop = leoRopTable[pGC->alu]; if (pGC->planemask != 0xffffff) ld0->planemask = pGC->planemask; ld0->fg = gcPriv->stipple->fg; fb = (unsigned char *)pLeo->fb; lc0->addrspace = LEO_ADDRSPC_FONT_OBGR; if (gcPriv->stipple->alu & 0x80) { lc0->fontt = 1; } else { lc0->fontt = 0; ld0->bg = gcPriv->stipple->bg; } lc0->fontmsk = 0xffffffff; msk = 0xffffffff; bits = &gcPriv->stipple->bits[0]; while (n--) { int x, y, w; unsigned int *dst, s, i, sw, sm; w = *pwidth++; x = ppt->x; y = ppt->y; ppt++; if (numRects == 1) { if (y < cy1 || y >= cy2) continue; if (x < cx1) { w -= (cx1 - x); if (w <= 0) continue; x = cx1; } if (x + w > cx2) { if (x >= cx2) continue; w = cx2 - x; } } s = bits[y & 31]; dst = (unsigned int *)(fb + (y << 13) + ((x & ~31) << 2)); if (x & 31) { sw = 32 - (x & 31); sm = 0xffffffff >> (x & 31); w -= sw; if (w <= 0) { if (w) sm &= 0xffffffff << (32 - (w & 31)); if (msk != sm) { msk = sm; lc0->fontmsk = sm; } *dst = s; continue; } if (msk != sm) { msk = sm; lc0->fontmsk = sm; } *dst = s; dst += 32; } else {
void winCopyWindowNativeGDI (WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc) { DDXPointPtr pptSrc; DDXPointPtr ppt; RegionPtr prgnDst; BoxPtr pBox; int dx, dy; int i, nbox; WindowPtr pwinRoot; BoxPtr pBoxDst; ScreenPtr pScreen = pWin->drawable.pScreen; winScreenPriv(pScreen); #if 0 ErrorF ("winCopyWindow\n"); #endif /* Get a pointer to the root window */ pwinRoot = WindowTable[pWin->drawable.pScreen->myNum]; /* Create a region for the destination */ prgnDst = REGION_CREATE(pWin->drawable.pScreen, NULL, 1); /* Calculate the shift from the source to the destination */ dx = ptOldOrg.x - pWin->drawable.x; dy = ptOldOrg.y - pWin->drawable.y; /* Translate the region from the destination to the source? */ REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy); REGION_INTERSECT(pWin->drawable.pScreen, prgnDst, &pWin->borderClip, prgnSrc); /* Get a pointer to the first box in the region to be copied */ pBox = REGION_RECTS(prgnDst); /* Get the number of boxes in the region */ nbox = REGION_NUM_RECTS(prgnDst); /* Allocate source points for each box */ if(!(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec)))) return; /* Set an iterator pointer */ ppt = pptSrc; /* Calculate the source point of each box? */ for (i = nbox; --i >= 0; ppt++, pBox++) { ppt->x = pBox->x1 + dx; ppt->y = pBox->y1 + dy; } /* Setup loop pointers again */ pBoxDst = REGION_RECTS(prgnDst); ppt = pptSrc; #if 0 ErrorF ("winCopyWindow - x1\tx2\ty1\ty2\tx\ty\n"); #endif /* BitBlt each source to the destination point */ for (i = nbox; --i >= 0; pBoxDst++, ppt++) { #if 0 ErrorF ("winCopyWindow - %d\t%d\t%d\t%d\t%d\t%d\n", pBoxDst->x1, pBoxDst->x2, pBoxDst->y1, pBoxDst->y2, ppt->x, ppt->y); #endif BitBlt (pScreenPriv->hdcScreen, pBoxDst->x1, pBoxDst->y1, pBoxDst->x2 - pBoxDst->x1, pBoxDst->y2 - pBoxDst->y1, pScreenPriv->hdcScreen, ppt->x, ppt->y, SRCCOPY); } /* Cleanup the regions, etc. */ DEALLOCATE_LOCAL(pptSrc); REGION_DESTROY(pWin->drawable.pScreen, prgnDst); }
/* * Graft in the DoBitblt from cfb. It does everything correctly. */ static void vga16DoBitblt ( DrawablePtr pSrc, DrawablePtr pDst, int alu, RegionPtr prgnDst, DDXPointPtr pptSrc, unsigned long planemask ) { int widthSrc, widthDst; /* add to get to same position in next line */ BoxPtr pbox; int nbox; BoxPtr pboxTmp, pboxNext, pboxBase, pboxNew1, pboxNew2; /* temporaries for shuffling rectangles */ DDXPointPtr pptTmp, pptNew1, pptNew2; /* shuffling boxes entails shuffling the source points too */ int w, h; int careful; widthSrc = cfbGetLongWidth(pSrc); widthDst = cfbGetLongWidth(pDst); /* XXX we have to err on the side of safety when both are windows, * because we don't know if IncludeInferiors is being used. */ careful = ((pSrc == pDst) || ((pSrc->type == DRAWABLE_WINDOW) && (pDst->type == DRAWABLE_WINDOW))); pbox = REGION_RECTS(prgnDst); nbox = REGION_NUM_RECTS(prgnDst); pboxNew1 = NULL; pptNew1 = NULL; pboxNew2 = NULL; pptNew2 = NULL; if (careful && (pptSrc->y < pbox->y1)) { /* walk source botttom to top */ widthSrc = -widthSrc; widthDst = -widthDst; if (nbox > 1) { /* keep ordering in each band, reverse order of bands */ pboxNew1 = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox); if(!pboxNew1) return; pptNew1 = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * nbox); if(!pptNew1) { DEALLOCATE_LOCAL(pboxNew1); return; } pboxBase = pboxNext = pbox+nbox-1; while (pboxBase >= pbox) { while ((pboxNext >= pbox) && (pboxBase->y1 == pboxNext->y1)) pboxNext--; pboxTmp = pboxNext+1; pptTmp = pptSrc + (pboxTmp - pbox); while (pboxTmp <= pboxBase) { *pboxNew1++ = *pboxTmp++; *pptNew1++ = *pptTmp++; } pboxBase = pboxNext; } pboxNew1 -= nbox; pbox = pboxNew1; pptNew1 -= nbox; pptSrc = pptNew1; } } if (careful && (pptSrc->x < pbox->x1)) { if (nbox > 1) { /* reverse order of rects in each band */ pboxNew2 = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox); pptNew2 = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * nbox); if(!pboxNew2 || !pptNew2) { if (pptNew2) DEALLOCATE_LOCAL(pptNew2); if (pboxNew2) DEALLOCATE_LOCAL(pboxNew2); if (pboxNew1) { DEALLOCATE_LOCAL(pptNew1); DEALLOCATE_LOCAL(pboxNew1); } return; } pboxBase = pboxNext = pbox; while (pboxBase < pbox+nbox) { while ((pboxNext < pbox+nbox) && (pboxNext->y1 == pboxBase->y1)) pboxNext++; pboxTmp = pboxNext; pptTmp = pptSrc + (pboxTmp - pbox); while (pboxTmp != pboxBase) { *pboxNew2++ = *--pboxTmp; *pptNew2++ = *--pptTmp; } pboxBase = pboxNext; } pboxNew2 -= nbox; pbox = pboxNew2; pptNew2 -= nbox; pptSrc = pptNew2; } } while(nbox--) { w = pbox->x2 - pbox->x1; h = pbox->y2 - pbox->y1; if( pSrc->type == DRAWABLE_WINDOW ) xf4bppBitBlt( (WindowPtr)pDst, alu, planemask, pptSrc->x, /* x0 */ pptSrc->y, /* y0 */ pbox->x1, /* x1 */ pbox->y1, /* y1 */ w, h ); /* w, h */ else /* DRAWABLE_PIXMAP */ xf4bppDrawColorImage( (WindowPtr)pDst, pbox->x1, pbox->y1, w, h, ((unsigned char *)((PixmapPtr)pSrc)->devPrivate.ptr + pptSrc->x + (pptSrc->y*((PixmapPtr)pSrc)->devKind)), ((PixmapPtr)pSrc)->devKind, alu, planemask ) ; pbox++; pptSrc++; } if (pboxNew2) { DEALLOCATE_LOCAL(pptNew2); DEALLOCATE_LOCAL(pboxNew2); } if (pboxNew1) { DEALLOCATE_LOCAL(pptNew1); DEALLOCATE_LOCAL(pboxNew1); } }
RegionPtr XAABitBlt( DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GC *pGC, int srcx, int srcy, int width, int height, int dstx, int dsty, void (*doBitBlt)(DrawablePtr, DrawablePtr, GCPtr, RegionPtr, DDXPointPtr), unsigned long bitPlane ) { RegionPtr prgnSrcClip = NULL; /* may be a new region, or just a copy */ RegionPtr prgnExposed; Bool freeSrcClip = FALSE; RegionRec rgnDst; DDXPointPtr pptSrc, ppt; DDXPointRec origDest; BoxPtr pbox; BoxRec fastBox; int i, dx, dy, numRects; xRectangle origSource; int fastClip = 0; /* for fast clipping with pixmap source */ int fastExpose = 0; /* for fast exposures with pixmap source */ origSource.x = srcx; origSource.y = srcy; origSource.width = width; origSource.height = height; origDest.x = dstx; origDest.y = dsty; if((pSrcDrawable != pDstDrawable) && pSrcDrawable->pScreen->SourceValidate) { (*pSrcDrawable->pScreen->SourceValidate) ( pSrcDrawable, srcx, srcy, width, height); } srcx += pSrcDrawable->x; srcy += pSrcDrawable->y; /* clip the source */ if (pSrcDrawable->type == DRAWABLE_PIXMAP) { if ((pSrcDrawable == pDstDrawable) && (pGC->clientClipType == CT_NONE)) prgnSrcClip = pGC->pCompositeClip; else fastClip = 1; } else { /* Window */ if (pGC->subWindowMode == IncludeInferiors) { if (!((WindowPtr) pSrcDrawable)->parent) { /* * special case bitblt from root window in * IncludeInferiors mode; just like from a pixmap */ fastClip = 1; } else if ((pSrcDrawable == pDstDrawable) && (pGC->clientClipType == CT_NONE)) { prgnSrcClip = pGC->pCompositeClip; } else { prgnSrcClip = NotClippedByChildren((WindowPtr)pSrcDrawable); freeSrcClip = TRUE; } } else { prgnSrcClip = &((WindowPtr)pSrcDrawable)->clipList; } } fastBox.x1 = srcx; fastBox.y1 = srcy; fastBox.x2 = srcx + width; fastBox.y2 = srcy + height; /* Don't create a source region if we are doing a fast clip */ if (fastClip) { fastExpose = 1; /* * clip the source; if regions extend beyond the source size, * make sure exposure events get sent */ if (fastBox.x1 < pSrcDrawable->x) { fastBox.x1 = pSrcDrawable->x; fastExpose = 0; } if (fastBox.y1 < pSrcDrawable->y) { fastBox.y1 = pSrcDrawable->y; fastExpose = 0; } if (fastBox.x2 > pSrcDrawable->x + (int) pSrcDrawable->width) { fastBox.x2 = pSrcDrawable->x + (int) pSrcDrawable->width; fastExpose = 0; } if (fastBox.y2 > pSrcDrawable->y + (int) pSrcDrawable->height) { fastBox.y2 = pSrcDrawable->y + (int) pSrcDrawable->height; fastExpose = 0; } } else { REGION_INIT(pGC->pScreen, &rgnDst, &fastBox, 1); REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst, prgnSrcClip); } dstx += pDstDrawable->x; dsty += pDstDrawable->y; if (pDstDrawable->type == DRAWABLE_WINDOW) { if (!((WindowPtr)pDstDrawable)->realized) { if (!fastClip) REGION_UNINIT(pGC->pScreen, &rgnDst); if (freeSrcClip) REGION_DESTROY(pGC->pScreen, prgnSrcClip); return NULL; } } dx = srcx - dstx; dy = srcy - dsty; /* Translate and clip the dst to the destination composite clip */ if (fastClip) { RegionPtr cclip; /* Translate the region directly */ fastBox.x1 -= dx; fastBox.x2 -= dx; fastBox.y1 -= dy; fastBox.y2 -= dy; /* If the destination composite clip is one rectangle we can do the clip directly. Otherwise we have to create a full blown region and call intersect */ cclip = pGC->pCompositeClip; if (REGION_NUM_RECTS(cclip) == 1) { BoxPtr pBox = REGION_RECTS(cclip); if (fastBox.x1 < pBox->x1) fastBox.x1 = pBox->x1; if (fastBox.x2 > pBox->x2) fastBox.x2 = pBox->x2; if (fastBox.y1 < pBox->y1) fastBox.y1 = pBox->y1; if (fastBox.y2 > pBox->y2) fastBox.y2 = pBox->y2; /* Check to see if the region is empty */ if (fastBox.x1 >= fastBox.x2 || fastBox.y1 >= fastBox.y2) { REGION_NULL(pGC->pScreen, &rgnDst); } else { REGION_INIT(pGC->pScreen, &rgnDst, &fastBox, 1); } } else { /* We must turn off fastClip now, since we must create a full blown region. It is intersected with the composite clip below. */ fastClip = 0; REGION_INIT(pGC->pScreen, &rgnDst, &fastBox,1); } } else { REGION_TRANSLATE(pGC->pScreen, &rgnDst, -dx, -dy); } if (!fastClip) { REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst, pGC->pCompositeClip); } /* Do bit blitting */ numRects = REGION_NUM_RECTS(&rgnDst); if (numRects && width && height) { if(!(pptSrc = (DDXPointPtr)ALLOCATE_LOCAL(numRects * sizeof(DDXPointRec)))) { REGION_UNINIT(pGC->pScreen, &rgnDst); if (freeSrcClip) REGION_DESTROY(pGC->pScreen, prgnSrcClip); return NULL; } pbox = REGION_RECTS(&rgnDst); ppt = pptSrc; for (i = numRects; --i >= 0; pbox++, ppt++) { ppt->x = pbox->x1 + dx; ppt->y = pbox->y1 + dy; } (*doBitBlt) (pSrcDrawable, pDstDrawable, pGC, &rgnDst, pptSrc); DEALLOCATE_LOCAL(pptSrc); } prgnExposed = NULL; if (pGC->fExpose) { /* Pixmap sources generate a NoExposed (we return NULL to do this) */ if (!fastExpose) prgnExposed = miHandleExposures(pSrcDrawable, pDstDrawable, pGC, origSource.x, origSource.y, (int)origSource.width, (int)origSource.height, origDest.x, origDest.y, bitPlane); } REGION_UNINIT(pGC->pScreen, &rgnDst); if (freeSrcClip) REGION_DESTROY(pGC->pScreen, prgnSrcClip); return prgnExposed; }
/* * convexpoly.c * * Written by Brian Kelleher; Dec. 1985. * * Fill a convex polygon. If the given polygon * is not convex, then the result is undefined. * The algorithm is to order the edges from smallest * y to largest by partitioning the array into a left * edge list and a right edge list. The algorithm used * to traverse each edge is an extension of Bresenham's * line algorithm with y as the major axis. * For a derivation of the algorithm, see the author of * this code. */ Bool miFillConvexPoly(DrawablePtr dst, GCPtr pgc, int count, DDXPointPtr ptsIn) { int xl = 0, xr = 0; /* x vals of left and right edges */ int dl = 0, dr = 0; /* decision variables */ int ml = 0, m1l = 0;/* left edge slope and slope+1 */ int mr = 0, m1r = 0; /* right edge slope and slope+1 */ int incr1l = 0, incr2l = 0; /* left edge error increments */ int incr1r = 0, incr2r = 0; /* right edge error increments */ int dy; /* delta y */ int y; /* current scanline */ int left, right; /* indices to first endpoints */ int i; /* loop counter */ int nextleft, nextright; /* indices to second endpoints */ DDXPointPtr ptsOut, FirstPoint; /* output buffer */ int *width, *FirstWidth; /* output buffer */ int imin; /* index of smallest vertex (in y) */ int ymin; /* y-extents of polygon */ int ymax; /* * find leftx, bottomy, rightx, topy, and the index * of bottomy. Also translate the points. */ imin = getPolyYBounds(ptsIn, count, &ymin, &ymax); dy = ymax - ymin + 1; if ((count < 3) || (dy < 0)) return(TRUE); ptsOut = FirstPoint = (DDXPointPtr )ALLOCATE_LOCAL(sizeof(DDXPointRec)*dy); width = FirstWidth = (int *)ALLOCATE_LOCAL(sizeof(int) * dy); if(!FirstPoint || !FirstWidth) { if (FirstWidth) DEALLOCATE_LOCAL(FirstWidth); if (FirstPoint) DEALLOCATE_LOCAL(FirstPoint); return(FALSE); } nextleft = nextright = imin; y = ptsIn[nextleft].y; /* * loop through all edges of the polygon */ do { /* * add a left edge if we need to */ if (ptsIn[nextleft].y == y) { left = nextleft; /* * find the next edge, considering the end * conditions of the array. */ nextleft++; if (nextleft >= count) nextleft = 0; /* * now compute all of the random information * needed to run the iterative algorithm. */ BRESINITPGON(ptsIn[nextleft].y-ptsIn[left].y, ptsIn[left].x,ptsIn[nextleft].x, xl, dl, ml, m1l, incr1l, incr2l); } /* * add a right edge if we need to */ if (ptsIn[nextright].y == y) { right = nextright; /* * find the next edge, considering the end * conditions of the array. */ nextright--; if (nextright < 0) nextright = count-1; /* * now compute all of the random information * needed to run the iterative algorithm. */ BRESINITPGON(ptsIn[nextright].y-ptsIn[right].y, ptsIn[right].x,ptsIn[nextright].x, xr, dr, mr, m1r, incr1r, incr2r); } /* * generate scans to fill while we still have * a right edge as well as a left edge. */ i = min(ptsIn[nextleft].y, ptsIn[nextright].y) - y; /* in case we're called with non-convex polygon */ if(i < 0) { DEALLOCATE_LOCAL(FirstWidth); DEALLOCATE_LOCAL(FirstPoint); return(TRUE); } while (i-- > 0) { ptsOut->y = y; /* * reverse the edges if necessary */ if (xl < xr) { *(width++) = xr - xl; (ptsOut++)->x = xl; } else { *(width++) = xl - xr; (ptsOut++)->x = xr; } y++; /* increment down the edges */ BRESINCRPGON(dl, xl, ml, m1l, incr1l, incr2l); BRESINCRPGON(dr, xr, mr, m1r, incr1r, incr2r); } } while (y != ymax); /* * Finally, fill the <remaining> spans */ (*pgc->ops->FillSpans)(dst, pgc, ptsOut-FirstPoint,FirstPoint,FirstWidth, 1); DEALLOCATE_LOCAL(FirstWidth); DEALLOCATE_LOCAL(FirstPoint); return(TRUE); }
int ProcListExtensions(ClientPtr client) { xListExtensionsReply reply; char *bufptr, *buffer; int total_length = 0; REQUEST_SIZE_MATCH(xReq); reply.type = X_Reply; reply.nExtensions = 0; reply.length = 0; reply.sequenceNumber = client->sequence; buffer = NULL; if ( NumExtensions ) { register int i, j; for (i=0; i<NumExtensions; i++) { #ifdef XCSECURITY /* don't show insecure extensions to untrusted clients */ if (client->trustLevel == XSecurityClientUntrusted && !extensions[i]->secure) continue; #endif total_length += strlen(extensions[i]->name) + 1; reply.nExtensions += 1 + extensions[i]->num_aliases; for (j = extensions[i]->num_aliases; --j >= 0;) total_length += strlen(extensions[i]->aliases[j]) + 1; } reply.length = (total_length + 3) >> 2; buffer = bufptr = (char *)ALLOCATE_LOCAL(total_length); if (!buffer) return(BadAlloc); for (i=0; i<NumExtensions; i++) { int len; #ifdef XCSECURITY if (client->trustLevel == XSecurityClientUntrusted && !extensions[i]->secure) continue; #endif *bufptr++ = len = strlen(extensions[i]->name); memmove(bufptr, extensions[i]->name, len); bufptr += len; for (j = extensions[i]->num_aliases; --j >= 0;) { *bufptr++ = len = strlen(extensions[i]->aliases[j]); memmove(bufptr, extensions[i]->aliases[j], len); bufptr += len; } } } WriteReplyToClient(client, sizeof(xListExtensionsReply), &reply); if (reply.length) { WriteToClient(client, total_length, buffer); DEALLOCATE_LOCAL(buffer); } return(client->noClientException); }
static void XAACopyWindow8_32( WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc ){ DDXPointPtr pptSrc, ppt; RegionRec rgnDst; BoxPtr pbox; int dx, dy, nbox; WindowPtr pwinRoot; ScreenPtr pScreen = pWin->drawable.pScreen; XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_DRAWABLE((&pWin->drawable)); Bool doUnderlay = miOverlayCopyUnderlay(pScreen); RegionPtr borderClip = &pWin->borderClip; Bool freeReg = FALSE; if (!infoRec->pScrn->vtSema || !infoRec->ScreenToScreenBitBlt || (infoRec->ScreenToScreenBitBltFlags & NO_PLANEMASK)) { XAA_SCREEN_PROLOGUE (pScreen, CopyWindow); if(infoRec->pScrn->vtSema && infoRec->NeedToSync) { (*infoRec->Sync)(infoRec->pScrn); infoRec->NeedToSync = FALSE; } (*pScreen->CopyWindow) (pWin, ptOldOrg, prgnSrc); XAA_SCREEN_EPILOGUE (pScreen, CopyWindow, XAACopyWindow8_32); return; } pwinRoot = WindowTable[pScreen->myNum]; if(doUnderlay) freeReg = miOverlayCollectUnderlayRegions(pWin, &borderClip); REGION_NULL(pScreen, &rgnDst); dx = ptOldOrg.x - pWin->drawable.x; dy = ptOldOrg.y - pWin->drawable.y; REGION_TRANSLATE(pScreen, prgnSrc, -dx, -dy); REGION_INTERSECT(pScreen, &rgnDst, borderClip, prgnSrc); pbox = REGION_RECTS(&rgnDst); nbox = REGION_NUM_RECTS(&rgnDst); if(!nbox || !(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec)))) { REGION_UNINIT(pScreen, &rgnDst); return; } ppt = pptSrc; while(nbox--) { ppt->x = pbox->x1 + dx; ppt->y = pbox->y1 + dy; ppt++; pbox++; } infoRec->ScratchGC.planemask = doUnderlay ? 0x00ffffff : 0xff000000; infoRec->ScratchGC.alu = GXcopy; XAADoBitBlt((DrawablePtr)pwinRoot, (DrawablePtr)pwinRoot, &(infoRec->ScratchGC), &rgnDst, pptSrc); DEALLOCATE_LOCAL(pptSrc); REGION_UNINIT(pScreen, &rgnDst); if(freeReg) REGION_DESTROY(pScreen, borderClip); }
/* * This function is largely ripped from miPaintWindow, but modified so * that the background is not painted to the root window, and so that * the backing store is not referenced. */ void PclPaintWindow( WindowPtr pWin, RegionPtr pRegion, int what) { #define FUNCTION 0 #define FOREGROUND 1 #define TILE 2 #define FILLSTYLE 3 #define ABSX 4 #define ABSY 5 #define CLIPMASK 6 #define SUBWINDOW 7 #define COUNT_BITS 8 pointer gcval[7]; pointer newValues [COUNT_BITS]; BITS32 gcmask, index, mask; RegionRec prgnWin; DDXPointRec oldCorner; BoxRec box; WindowPtr pBgWin; GCPtr pGC; register int i; register BoxPtr pbox; register ScreenPtr pScreen = pWin->drawable.pScreen; register xRectangle *prect; int numRects; gcmask = 0; /* * We don't want to paint a window that has no place to put the * PCL output. */ if( PclGetContextFromWindow( pWin ) == (XpContextPtr)NULL ) return; if (what == PW_BACKGROUND) { switch (pWin->backgroundState) { case None: return; case ParentRelative: (*pWin->parent->drawable.pScreen->PaintWindowBackground) (pWin->parent, pRegion, what); return; case BackgroundPixel: newValues[FOREGROUND] = (pointer)pWin->background.pixel; newValues[FILLSTYLE] = (pointer)FillSolid; gcmask |= GCForeground | GCFillStyle; break; case BackgroundPixmap: newValues[TILE] = (pointer)pWin->background.pixmap; newValues[FILLSTYLE] = (pointer)FillTiled; gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin; break; } } else { if (pWin->borderIsPixel) { newValues[FOREGROUND] = (pointer)pWin->border.pixel; newValues[FILLSTYLE] = (pointer)FillSolid; gcmask |= GCForeground | GCFillStyle; } else { newValues[TILE] = (pointer)pWin->border.pixmap; newValues[FILLSTYLE] = (pointer)FillTiled; gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin; } } prect = (xRectangle *)ALLOCATE_LOCAL(REGION_NUM_RECTS(pRegion) * sizeof(xRectangle)); if (!prect) return; newValues[FUNCTION] = (pointer)GXcopy; gcmask |= GCFunction | GCClipMask; i = pScreen->myNum; pBgWin = pWin; if (what == PW_BORDER) { while (pBgWin->backgroundState == ParentRelative) pBgWin = pBgWin->parent; } pGC = GetScratchGC(pWin->drawable.depth, pWin->drawable.pScreen); if (!pGC) { DEALLOCATE_LOCAL(prect); return; } /* * mash the clip list so we can paint the border by * mangling the window in place, pretending it * spans the entire screen */ if (what == PW_BORDER) { prgnWin = pWin->clipList; oldCorner.x = pWin->drawable.x; oldCorner.y = pWin->drawable.y; pWin->drawable.x = pWin->drawable.y = 0; box.x1 = 0; box.y1 = 0; box.x2 = pScreen->width; box.y2 = pScreen->height; REGION_INIT(pScreen, &pWin->clipList, &box, 1); pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; newValues[ABSX] = (pointer)(long)pBgWin->drawable.x; newValues[ABSY] = (pointer)(long)pBgWin->drawable.y; } else { newValues[ABSX] = (pointer)0; newValues[ABSY] = (pointer)0; } /* * XXX Backing store is turned off for the PCL driver if (pWin->backStorage) (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack); */ mask = gcmask; gcmask = 0; i = 0; while (mask) { index = lowbit (mask); mask &= ~index; switch (index) { case GCFunction: if ((pointer)(long) pGC->alu != newValues[FUNCTION]) { gcmask |= index; gcval[i++] = newValues[FUNCTION]; } break; case GCTileStipXOrigin: if ((pointer)(long) pGC->patOrg.x != newValues[ABSX]) { gcmask |= index; gcval[i++] = newValues[ABSX]; } break; case GCTileStipYOrigin: if ((pointer)(long) pGC->patOrg.y != newValues[ABSY]) { gcmask |= index; gcval[i++] = newValues[ABSY]; } break; case GCClipMask: if ((pointer)(long) pGC->clientClipType != (pointer)CT_NONE) { gcmask |= index; gcval[i++] = (pointer)CT_NONE; } break; case GCSubwindowMode: if ((pointer)(long) pGC->subWindowMode != newValues[SUBWINDOW]) { gcmask |= index; gcval[i++] = newValues[SUBWINDOW]; } break; case GCTile: if (pGC->tileIsPixel || (pointer) pGC->tile.pixmap != newValues[TILE]) { gcmask |= index; gcval[i++] = newValues[TILE]; } break; case GCFillStyle: if ((pointer)(long) pGC->fillStyle != newValues[FILLSTYLE]) { gcmask |= index; gcval[i++] = newValues[FILLSTYLE]; } break; case GCForeground: if ((pointer) pGC->fgPixel != newValues[FOREGROUND]) { gcmask |= index; gcval[i++] = newValues[FOREGROUND]; } break; } } if (gcmask) DoChangeGC(pGC, gcmask, (XID *)gcval, 1); if (pWin->drawable.serialNumber != pGC->serialNumber) ValidateGC((DrawablePtr)pWin, pGC); numRects = REGION_NUM_RECTS(pRegion); pbox = REGION_RECTS(pRegion); for (i= numRects; --i >= 0; pbox++, prect++) { prect->x = pbox->x1 - pWin->drawable.x; prect->y = pbox->y1 - pWin->drawable.y; prect->width = pbox->x2 - pbox->x1; prect->height = pbox->y2 - pbox->y1; } prect -= numRects; (*pGC->ops->PolyFillRect)((DrawablePtr)pWin, pGC, numRects, prect); DEALLOCATE_LOCAL(prect); /* * XXX Backing store is turned off for the PCL driver if (pWin->backStorage) (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeNothing); */ if (what == PW_BORDER) { REGION_UNINIT(pScreen, &pWin->clipList); pWin->clipList = prgnWin; pWin->drawable.x = oldCorner.x; pWin->drawable.y = oldCorner.y; pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER; } FreeScratchGC(pGC); }
Bool OsInitColors(void) { FILE *rgb; char *path; char line[BUFSIZ]; char name[BUFSIZ]; int red, green, blue, lineno = 0; dbEntryPtr entry; static Bool was_here = FALSE; if (!was_here) { #ifndef __UNIXOS2__ path = (char*)ALLOCATE_LOCAL(strlen(rgbPath) +5); strcpy(path, rgbPath); strcat(path, ".txt"); #else char *tmp = (char*)__XOS2RedirRoot(rgbPath); path = (char*)ALLOCATE_LOCAL(strlen(tmp) +5); strcpy(path, tmp); strcat(path, ".txt"); #endif if (!(rgb = fopen(path, "r"))) { ErrorF( "Couldn't open RGB_DB '%s'\n", rgbPath ); DEALLOCATE_LOCAL(path); return FALSE; } while(fgets(line, sizeof(line), rgb)) { lineno++; #ifndef __UNIXOS2__ if (sscanf(line,"%d %d %d %[^\n]\n", &red, &green, &blue, name) == 4) #else if (sscanf(line,"%d %d %d %[^\n\r]\n", &red, &green, &blue, name) == 4) #endif { if (red >= 0 && red <= 0xff && green >= 0 && green <= 0xff && blue >= 0 && blue <= 0xff) { if ((entry = lookup(name, strlen(name), TRUE))) { entry->red = (red * 65535) / 255; entry->green = (green * 65535) / 255; entry->blue = (blue * 65535) / 255; } } else ErrorF("Value out of range: %s:%d\n", path, lineno); } else if (*line && *line != '#' && *line != '!') ErrorF("Syntax Error: %s:%d\n", path, lineno); } fclose(rgb); DEALLOCATE_LOCAL(path); was_here = TRUE; } return TRUE; }
void XAAOverCopyWindow( WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc ){ ScreenPtr pScreen = pWin->drawable.pScreen; XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen); XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pScreen); ScrnInfoPtr pScrn = infoRec->pScrn; DDXPointPtr ppt, pptSrc; RegionRec rgnDst; BoxPtr pbox; int i, nbox, dx, dy; WindowPtr pRoot = WindowTable[pScreen->myNum]; if (!pScrn->vtSema || !infoRec->ScreenToScreenBitBlt) { XAA_SCREEN_PROLOGUE (pScreen, CopyWindow); if(pScrn->vtSema && infoRec->NeedToSync) { (*infoRec->Sync)(pScrn); infoRec->NeedToSync = FALSE; } (*pScreen->CopyWindow) (pWin, ptOldOrg, prgnSrc); XAA_SCREEN_EPILOGUE (pScreen, CopyWindow, XAAOverCopyWindow); return; } infoRec->ScratchGC.alu = GXcopy; infoRec->ScratchGC.planemask = ~0; REGION_NULL(pScreen, &rgnDst); dx = ptOldOrg.x - pWin->drawable.x; dy = ptOldOrg.y - pWin->drawable.y; REGION_TRANSLATE(pScreen, prgnSrc, -dx, -dy); REGION_INTERSECT(pScreen, &rgnDst, &pWin->borderClip, prgnSrc); nbox = REGION_NUM_RECTS(&rgnDst); if(nbox && (pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec)))) { pbox = REGION_RECTS(&rgnDst); for (i = nbox, ppt = pptSrc; i--; ppt++, pbox++) { ppt->x = pbox->x1 + dx; ppt->y = pbox->y1 + dy; } SWITCH_DEPTH(8); XAADoBitBlt((DrawablePtr)pRoot, (DrawablePtr)pRoot, &(infoRec->ScratchGC), &rgnDst, pptSrc); if(pWin->drawable.bitsPerPixel != 8) { SWITCH_DEPTH(pScrn->depth); XAADoBitBlt((DrawablePtr)pRoot, (DrawablePtr)pRoot, &(infoRec->ScratchGC), &rgnDst, pptSrc); } DEALLOCATE_LOCAL(pptSrc); } REGION_UNINIT(pScreen, &rgnDst); if(pWin->drawable.depth == 8) { REGION_NULL(pScreen, &rgnDst); miSegregateChildren(pWin, &rgnDst, pScrn->depth); if(REGION_NOTEMPTY(pScreen, &rgnDst)) { REGION_INTERSECT(pScreen, &rgnDst, &rgnDst, prgnSrc); nbox = REGION_NUM_RECTS(&rgnDst); if(nbox && (pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec)))){ pbox = REGION_RECTS(&rgnDst); for (i = nbox, ppt = pptSrc; i--; ppt++, pbox++) { ppt->x = pbox->x1 + dx; ppt->y = pbox->y1 + dy; } SWITCH_DEPTH(pScrn->depth); XAADoBitBlt((DrawablePtr)pRoot, (DrawablePtr)pRoot, &(infoRec->ScratchGC), &rgnDst, pptSrc); DEALLOCATE_LOCAL(pptSrc); } } REGION_UNINIT(pScreen, &rgnDst); } }
void xf86CheckBeta(int extraDays, char *key) { FILE *m = NULL; Bool showmessage = FALSE; Bool expired = FALSE; Bool expiresoon = FALSE; Bool requireconfirm = FALSE; int expiryextended = 0; #ifdef SHOW_BETA_MESSAGE FILE *f = NULL; char *home = NULL; char *filename = NULL; Bool writefile = FALSE; char oldvers[16] = {0, }; #endif #ifndef X_NOT_STDC_ENV time_t expirytime = EXPIRY_TIME; #else long expirytime = EXPIRY_TIME; #endif /* * Check if the beta message should be displayed. It is displayed when * the version doesn't match that in $HOME/.XFree86, and when within * one week of the expiry date. */ #ifdef SHOW_BETA_MESSAGE if (!(home = getenv("HOME"))) home = "/"; { char homebuf[PATH_MAX]; strcpy(homebuf,home); /* getenv might return R/O memory, as with OS/2 */ home = homebuf; if (!(filename = (char *)ALLOCATE_LOCAL(strlen(home) + strlen(xf86ServerName) + 3))) showmessage = TRUE; else { if (home[0] == '/' && home[1] == '\0') home[0] = '\0'; sprintf(filename, "%s/.%s", home, xf86ServerName); writefile = TRUE; if (!(f = fopen(filename, "r+"))) showmessage = TRUE; else { fgets(oldvers, 16, f); if (strncmp(oldvers, XF86_VERSION, 15)) { showmessage = TRUE; } fclose(f); } } } #endif #ifdef EXPIRE_SERVER if (expirytime != 0) { if (extraDays > 0 && key != NULL && strlen(key) == KEY_LENGTH) { #ifndef X_NOT_STDC_ENV time_t newExpiry; #else long newExpiry; #endif unsigned long key1, key2; char tmp[9]; strncpy(tmp, key, 8); tmp[8] = '\0'; key1 = strtoul(tmp, NULL, 16); key2 = strtoul(key + 8, NULL, 16); newExpiry = expirytime + extraDays * DAY_IN_SECONDS; if ((newExpiry ^ key1) == XOR_VALUE_1 && (newExpiry ^ key2) == XOR_VALUE_2) { expirytime = newExpiry; expiryextended = extraDays; } } if (time(NULL) > expirytime) { showmessage = TRUE; expired = TRUE; } else if (expirytime - time(NULL) < WARNING_DAYS * (DAY_IN_SECONDS)) { showmessage = TRUE; expiresoon = TRUE; } } #endif if (showmessage) { #if 0 /* * This doesn't work very well. stdin is usually closed, and even if * the server doesn't close it, xinit prevents this from being useful. */ /* Check if stderr is a tty */ if (isatty(fileno(stderr))) { requireconfirm = TRUE; } #endif #if 0 /* This doesn't work when the server is started by xinit */ #ifndef __EMX__ /* See if /dev/tty can be opened */ m = fopen("/dev/tty", "r+"); #endif #endif if (m) requireconfirm = TRUE; else m = stderr; if (m) { putc('\007', m); fprintf(m, "\n"); fprintf(m, " This is a beta version of XFree86.\n\n"); fprintf(m, " This binary may be redistributed providing it is not" " modified in any way.\n\n"); fprintf(m, " Please send success and problem reports to" " <*****@*****.**>.\n\n"); if (expired) { fprintf(m, " This version (%s) has expired.\n", XF86_VERSION); fprintf(m, " Please get the release version or a newer beta" " version.\n"); } else if (expiresoon) { fprintf(m, " WARNING! This version (%s) will expire in less than" " %ld day(s)\n at %s\n", XF86_VERSION, (long)(expirytime - time(NULL)) / DAY_IN_SECONDS + 1, ctime(&expirytime)); fprintf(m, " Please get the release version or a newer beta" " version.\n"); } else if (expirytime != 0) { fprintf(m, " This version (%s) will expire at %s\n", XF86_VERSION, ctime(&expirytime)); } if (!expired && expiryextended) { fprintf(m, " Note: the expiry date has been extended by %d days\n", expiryextended); } if (!expired) { if (requireconfirm) { char c[2]; fflush(m); fprintf(m, "\nHit <Enter> to continue: "); fflush(m); fgets(c, 2, m); } else { fflush(m); fprintf(m, "\nWaiting for %d seconds...", MESSAGE_SLEEP); fflush(m); sleep(MESSAGE_SLEEP); fprintf(m, "\n"); } } fprintf(m, "\n"); if (m != stderr) fclose(m); } } #ifdef SHOW_BETA_MESSAGE #define WRITE_BETA_FILE { \ unlink(filename); \ if (f = fopen(filename, "w")) { \ fprintf(f, XF86_VERSION); \ fclose(f); \ } \ } if (writefile) { #if !defined(__EMX__) #if defined(SYSV) || defined(linux) /* Need to fork to change to ruid without loosing euid */ if (getuid() != 0) { switch (fork()) { case -1: FatalError("xf86CheckBeta(): fork failed (%s)\n", strerror(errno)); break; case 0: /* child */ setuid(getuid()); WRITE_BETA_FILE exit(0); break; default: /* parent */ wait(NULL); } } else { WRITE_BETA_FILE } #else /* ! (SYSV || linux) */ { int realuid = getuid(); #if !defined(SVR4) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) setruid(0); #endif seteuid(realuid); WRITE_BETA_FILE seteuid(0); #if !defined(SVR4) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) setruid(realuid); #endif } #endif /* SYSV || linux */ #else /* __EMX__ */ WRITE_BETA_FILE #endif /* __EMX__ */ } if (filename) { DEALLOCATE_LOCAL(filename); filename = NULL; } #endif if (expired) exit(1); }
static void miFillPolyHelper (DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel, SpanDataPtr spanData, int y, int overall_height, PolyEdgePtr left, PolyEdgePtr right, int left_count, int right_count) { int left_x = 0, left_e = 0; int left_stepx = 0; int left_signdx = 0; int left_dy = 0, left_dx = 0; int right_x = 0, right_e = 0; int right_stepx = 0; int right_signdx = 0; int right_dy = 0, right_dx = 0; int height = 0; int left_height = 0, right_height = 0; DDXPointPtr ppt; DDXPointPtr pptInit = NULL; int *pwidth; int *pwidthInit = NULL; XID oldPixel; int xorg; Spans spanRec; left_height = 0; right_height = 0; if (!spanData) { pptInit = (DDXPointPtr) ALLOCATE_LOCAL (overall_height * sizeof(*ppt)); if (!pptInit) return; pwidthInit = (int *) ALLOCATE_LOCAL (overall_height * sizeof(*pwidth)); if (!pwidthInit) { DEALLOCATE_LOCAL (pptInit); return; } ppt = pptInit; pwidth = pwidthInit; oldPixel = pGC->fgPixel; if (pixel != oldPixel) { XID tmpPixel = (XID)pixel; DoChangeGC (pGC, GCForeground, &tmpPixel, FALSE); ValidateGC (pDrawable, pGC); } } else { spanRec.points = (DDXPointPtr) xalloc (overall_height * sizeof (*ppt)); if (!spanRec.points) return; spanRec.widths = (int *) xalloc (overall_height * sizeof (int)); if (!spanRec.widths) { xfree (spanRec.points); return; } ppt = spanRec.points; pwidth = spanRec.widths; } xorg = 0; if (pGC->miTranslate) { y += pDrawable->y; xorg = pDrawable->x; } while ((left_count || left_height) && (right_count || right_height)) { MIPOLYRELOADLEFT MIPOLYRELOADRIGHT height = left_height; if (height > right_height) height = right_height; left_height -= height; right_height -= height; while (--height >= 0) { if (right_x >= left_x) { ppt->y = y; ppt->x = left_x + xorg; ppt++; *pwidth++ = right_x - left_x + 1; } y++; MIPOLYSTEPLEFT MIPOLYSTEPRIGHT } } if (!spanData) { (*pGC->ops->FillSpans) (pDrawable, pGC, ppt - pptInit, pptInit, pwidthInit, TRUE); DEALLOCATE_LOCAL (pwidthInit); DEALLOCATE_LOCAL (pptInit); if (pixel != oldPixel) { DoChangeGC (pGC, GCForeground, &oldPixel, FALSE); ValidateGC (pDrawable, pGC); } } else { spanRec.count = ppt - spanRec.points; AppendSpanGroup (pGC, pixel, &spanRec, spanData) } }
Bool XkbWriteRulesProp(ClientPtr client, pointer closure) { int len,out; Atom name; char * pval; if (rulesDefined && (!XkbRulesFile)) return False; len= (XkbRulesFile?strlen(XkbRulesFile):strlen(XKB_DFLT_RULES_FILE)); len+= (XkbModelUsed?strlen(XkbModelUsed):0); len+= (XkbLayoutUsed?strlen(XkbLayoutUsed):0); len+= (XkbVariantUsed?strlen(XkbVariantUsed):0); len+= (XkbOptionsUsed?strlen(XkbOptionsUsed):0); if (len<1) return True; len+= 5; /* trailing NULs */ name= MakeAtom(_XKB_RF_NAMES_PROP_ATOM,strlen(_XKB_RF_NAMES_PROP_ATOM),1); if (name==None) { ErrorF("Atom error: %s not created\n",_XKB_RF_NAMES_PROP_ATOM); return True; } pval= (char*) ALLOCATE_LOCAL(len); if (!pval) { ErrorF("Allocation error: %s proprerty not created\n", _XKB_RF_NAMES_PROP_ATOM); return True; } out= 0; if (XkbRulesFile) { strcpy(&pval[out],XkbRulesFile); out+= strlen(XkbRulesFile); } else { strcpy(&pval[out],XKB_DFLT_RULES_FILE); out+= strlen(XKB_DFLT_RULES_FILE); } pval[out++]= '\0'; if (XkbModelUsed) { strcpy(&pval[out],XkbModelUsed); out+= strlen(XkbModelUsed); } pval[out++]= '\0'; if (XkbLayoutUsed) { strcpy(&pval[out],XkbLayoutUsed); out+= strlen(XkbLayoutUsed); } pval[out++]= '\0'; if (XkbVariantUsed) { strcpy(&pval[out],XkbVariantUsed); out+= strlen(XkbVariantUsed); } pval[out++]= '\0'; if (XkbOptionsUsed) { strcpy(&pval[out],XkbOptionsUsed); out+= strlen(XkbOptionsUsed); } pval[out++]= '\0'; if (out!=len) { ErrorF("Internal Error! bad size (%d!=%d) for _XKB_RULES_NAMES\n", out,len); } ChangeWindowProperty(WindowTable[0],name,XA_STRING,8,PropModeReplace, len,pval,True); DEALLOCATE_LOCAL(pval); return True; }
static int ProcXF86BigfontQueryFont( ClientPtr client) { FontPtr pFont; REQUEST(xXF86BigfontQueryFontReq); CARD32 stuff_flags; xCharInfo* pmax; xCharInfo* pmin; int nCharInfos; int shmid; #ifdef HAS_SHM ShmDescPtr pDesc; #else #define pDesc 0 #endif 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; } #endif client->errorValue = stuff->id; /* EITHER font or gc */ pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT, SecurityReadAccess); if (!pFont) { /* can't use VERIFY_GC because it might return BadGC */ GC *pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC, SecurityReadAccess); if (!pGC) { client->errorValue = stuff->id; return BadFont; /* procotol spec says only error is BadFont */ } pFont = pGC->font; } 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); shmid = -1; pCI = NULL; pIndex2UniqIndex = NULL; pUniqIndex2Index = NULL; nUniqCharInfos = 0; if (nCharInfos > 0) { #ifdef HAS_SHM if (!badSysCall) pDesc = (ShmDescPtr) FontGetPrivate(pFont, FontShmdescIndex); else pDesc = NULL; 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 = (xCharInfo *) ALLOCATE_LOCAL(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++; } } } #ifdef HAS_SHM 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 = (CARD16*) ALLOCATE_LOCAL((4*nCharInfos+1) * sizeof(CARD16)); if (!tmp) { if (!pDesc) DEALLOCATE_LOCAL(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 = (xXF86BigfontQueryFontReply *) ALLOCATE_LOCAL(rlength); char* p; if (!reply) { if (nCharInfos > 0) { if (shmid == -1) DEALLOCATE_LOCAL(pIndex2UniqIndex); if (!pDesc) DEALLOCATE_LOCAL(pCI); } return BadAlloc; } reply->type = X_Reply; reply->length = (rlength - sizeof(xGenericReply)) >> 2; 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, tmp); swapl(&reply->length, tmp); swapCharInfo(&reply->minBounds); swapCharInfo(&reply->maxBounds); swaps(&reply->minCharOrByte2, tmp); swaps(&reply->maxCharOrByte2, tmp); swaps(&reply->defaultChar, tmp); swaps(&reply->nFontProps, tmp); swaps(&reply->fontAscent, tmp); swaps(&reply->fontDescent, tmp); swapl(&reply->nCharInfos, tmp); swapl(&reply->nUniqCharInfos, tmp); swapl(&reply->shmid, tmp); swapl(&reply->shmsegoffset, tmp); } 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, tmp); swapl(&prFP->value, tmp); } } 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, tmp); } } } WriteToClient(client, rlength, (char *)reply); DEALLOCATE_LOCAL(reply); if (nCharInfos > 0) { if (shmid == -1) DEALLOCATE_LOCAL(pIndex2UniqIndex); if (!pDesc) DEALLOCATE_LOCAL(pCI); } return (client->noClientException); } }
void cfb8_32WidCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc) { ScreenPtr pScreen = pWin->drawable.pScreen; cfb8_32WidScreenPtr pScreenPriv = CFB8_32WID_GET_SCREEN_PRIVATE(pScreen); ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; PixmapPtr pPixChildren; DDXPointPtr ppt, pptSrc; RegionRec rgnDst, rgnOther, rgnPixmap; BoxPtr pbox; int i, nbox, dx, dy, other_bpp; REGION_INIT(pScreen, &rgnDst, NullBox, 0); dx = ptOldOrg.x - pWin->drawable.x; dy = ptOldOrg.y - pWin->drawable.y; REGION_TRANSLATE(pScreen, prgnSrc, -dx, -dy); REGION_INTERSECT(pScreen, &rgnDst, &pWin->borderClip, prgnSrc); if ((nbox = REGION_NUM_RECTS(&rgnDst)) == 0) { /* Nothing to render. */ REGION_UNINIT(pScreen, &rgnDst); return; } /* First, copy the WID plane for the whole area. */ pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec)); if(pptSrc) { pbox = REGION_RECTS(&rgnDst); for (i = nbox, ppt = pptSrc; i--; ppt++, pbox++) { ppt->x = pbox->x1 + dx; ppt->y = pbox->y1 + dy; } pScreenPriv->WIDOps->WidCopyArea((DrawablePtr)pScreenPriv->pixWid, &rgnDst, pptSrc); DEALLOCATE_LOCAL(pptSrc); } /* Next, we copy children which have a different * bpp than pWin into a temporary pixmap. We will * toss this pixmap back onto the framebuffer before * we return. */ if (pWin->drawable.bitsPerPixel == 8) other_bpp = pScrn->bitsPerPixel; else other_bpp = 8; REGION_INIT(pScreen, &rgnOther, NullBox, 0); SegregateChildrenBpp(pWin, &rgnOther, 0, other_bpp, pWin->drawable.bitsPerPixel); pPixChildren = NULL; if (REGION_NOTEMPTY(pScreen, &rgnOther)) { REGION_INTERSECT(pScreen, &rgnOther, &rgnOther, prgnSrc); nbox = REGION_NUM_RECTS(&rgnOther); if (nbox) { int width = rgnOther.extents.x2 - rgnOther.extents.x1; int height = rgnOther.extents.y2 - rgnOther.extents.y1; int depth = (other_bpp == 8) ? 8 : pScrn->depth; if (other_bpp == 8) pPixChildren = cfbCreatePixmap(pScreen, width, height, depth); else pPixChildren = cfb32CreatePixmap(pScreen, width, height, depth); } if (nbox && pPixChildren && (pptSrc = (DDXPointPtr) ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec)))) { pbox = REGION_RECTS(&rgnOther); for (i = nbox, ppt = pptSrc; i--; ppt++, pbox++) { ppt->x = pbox->x1 + dx; ppt->y = pbox->y1 + dy; } REGION_INIT(pScreen, &rgnPixmap, NullBox, 0); REGION_COPY(pScreen, &rgnPixmap, &rgnOther); REGION_TRANSLATE(pScreen, &rgnPixmap, -(rgnOther.extents.x1), -(rgnOther.extents.y1)); if (other_bpp == 8) cfbDoBitbltCopy((DrawablePtr)pScreenPriv->pix8, (DrawablePtr)pPixChildren, GXcopy, &rgnPixmap, pptSrc, ~0L); else cfb32DoBitbltCopy((DrawablePtr)pScreenPriv->pix32, (DrawablePtr)pPixChildren, GXcopy, &rgnPixmap, pptSrc, ~0L); REGION_UNINIT(pScreen, &rgnPixmap); DEALLOCATE_LOCAL(pptSrc); } REGION_SUBTRACT(pScreen, &rgnDst, &rgnDst, &rgnOther); } /* Now copy the parent along with all child windows using the same depth. */ nbox = REGION_NUM_RECTS(&rgnDst); if(nbox && (pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec)))) { pbox = REGION_RECTS(&rgnDst); for (i = nbox, ppt = pptSrc; i--; ppt++, pbox++) { ppt->x = pbox->x1 + dx; ppt->y = pbox->y1 + dy; } if (pWin->drawable.bitsPerPixel == 8) cfbDoBitbltCopy((DrawablePtr)pScreenPriv->pix8, (DrawablePtr)pScreenPriv->pix8, GXcopy, &rgnDst, pptSrc, ~0L); else cfb32DoBitbltCopy((DrawablePtr)pScreenPriv->pix32, (DrawablePtr)pScreenPriv->pix32, GXcopy, &rgnDst, pptSrc, ~0L); DEALLOCATE_LOCAL(pptSrc); } REGION_UNINIT(pScreen, &rgnDst); if (pPixChildren) { nbox = REGION_NUM_RECTS(&rgnOther); pptSrc = (DDXPointPtr) ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec)); if (pptSrc) { pbox = REGION_RECTS(&rgnOther); for (i = nbox, ppt = pptSrc; i--; ppt++, pbox++) { ppt->x = pbox->x1 - rgnOther.extents.x1; ppt->y = pbox->y1 - rgnOther.extents.y1; } if (other_bpp == 8) cfbDoBitbltCopy((DrawablePtr)pPixChildren, (DrawablePtr)pScreenPriv->pix8, GXcopy, &rgnOther, pptSrc, ~0L); else cfb32DoBitbltCopy((DrawablePtr)pPixChildren, (DrawablePtr)pScreenPriv->pix32, GXcopy, &rgnOther, pptSrc, ~0L); DEALLOCATE_LOCAL(pptSrc); } if (other_bpp == 8) cfbDestroyPixmap(pPixChildren); else cfb32DestroyPixmap(pPixChildren); } REGION_UNINIT(pScreen, &rgnOther); }