static void fill_rect(struct test_display *dpy,
		      Drawable d, XRenderPictFormat *format,
		      int use_shm,
		      uint8_t alu, int x, int y, int w, int h, uint32_t fg)
{
	XImage image;
	XGCValues val;
	GC gc;

	test_init_image(&image, &dpy->shm, format, w, h);

	pixman_fill((uint32_t*)image.data,
		    image.bytes_per_line/sizeof(uint32_t),
		    image.bits_per_pixel,
		    0, 0, w, h, fg);

	val.function = alu;
	gc = XCreateGC(dpy->dpy, d, GCFunction, &val);
	if (use_shm) {
		XShmPutImage(dpy->dpy, d, gc, &image, 0, 0, x, y, w, h, 0);
		XSync(dpy->dpy, 1);
	} else {
		XPutImage(dpy->dpy, d, gc, &image, 0, 0, x, y, w, h);
	}
	XFreeGC(dpy->dpy, gc);
}
Exemple #2
0
void
fbSolidBoxClipped(DrawablePtr pDrawable,
                  RegionPtr pClip,
                  int x1, int y1, int x2, int y2, FbBits and, FbBits xor)
{
    FbBits *dst;
    FbStride dstStride;
    int dstBpp;
    int dstXoff, dstYoff;
    BoxPtr pbox;
    int nbox;
    int partX1, partX2, partY1, partY2;

    fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);

    for (nbox = RegionNumRects(pClip), pbox = RegionRects(pClip);
         nbox--; pbox++) {
        partX1 = pbox->x1;
        if (partX1 < x1)
            partX1 = x1;

        partX2 = pbox->x2;
        if (partX2 > x2)
            partX2 = x2;

        if (partX2 <= partX1)
            continue;

        partY1 = pbox->y1;
        if (partY1 < y1)
            partY1 = y1;

        partY2 = pbox->y2;
        if (partY2 > y2)
            partY2 = y2;

        if (partY2 <= partY1)
            continue;

#ifndef FB_ACCESS_WRAPPER
        if (and || !pixman_fill((uint32_t *) dst, dstStride, dstBpp,
                                partX1 + dstXoff, partY1 + dstYoff,
                                (partX2 - partX1), (partY2 - partY1), xor))
#endif
            fbSolid(dst + (partY1 + dstYoff) * dstStride,
                    dstStride,
                    (partX1 + dstXoff) * dstBpp,
                    dstBpp,
                    (partX2 - partX1) * dstBpp, (partY2 - partY1), and, xor);
    }
    fbFinishAccess(pDrawable);
}
Exemple #3
0
void
fbFillRegionSolid (DrawablePtr	pDrawable,
		   RegionPtr	pRegion,
		   FbBits	and,
		   FbBits	xor)
{
    FbBits	*dst;
    FbStride	dstStride;
    int		dstBpp;
    int		dstXoff, dstYoff;
    int		n = REGION_NUM_RECTS(pRegion);
    BoxPtr	pbox = REGION_RECTS(pRegion);

#ifndef FB_ACCESS_WRAPPER
    int try_mmx = 0;
    if (!and)
        try_mmx = 1;
#endif

    fbGetDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
    
    while (n--)
    {
#ifndef FB_ACCESS_WRAPPER
	if (!try_mmx || !pixman_fill ((uint32_t *)dst, dstStride, dstBpp,
				      pbox->x1 + dstXoff, pbox->y1 + dstYoff,
				      (pbox->x2 - pbox->x1),
				      (pbox->y2 - pbox->y1),
				      xor))
	{
#endif
	    fbSolid (dst + (pbox->y1 + dstYoff) * dstStride,
		     dstStride,
		     (pbox->x1 + dstXoff) * dstBpp,
		     dstBpp,
		     (pbox->x2 - pbox->x1) * dstBpp,
		     pbox->y2 - pbox->y1,
		     and, xor);
#ifndef FB_ACCESS_WRAPPER
	}
#endif
	fbValidateDrawable (pDrawable);
	pbox++;
    }
    
    fbFinishAccess (pDrawable);
}
static void _put(struct test_target *tt,
		 int x, int y, int w,int h, int color, int alu)
{
	XImage image;
	XGCValues val;

	val.function = alu;

	test_init_image(&image, &tt->dpy->shm, tt->format, w, h);
	pixman_fill((uint32_t*)image.data,
		    image.bytes_per_line/sizeof(uint32_t),
		    image.bits_per_pixel,
		    0, 0, w, h, color);

	XChangeGC(tt->dpy->dpy, tt->gc, GCFunction, &val);
	if (rand() & 1) {
		XShmPutImage(tt->dpy->dpy, tt->draw, tt->gc, &image,
			     0, 0, x, y, w, h, 0);
		XSync(tt->dpy->dpy, 1);
	} else {
		XPutImage(tt->dpy->dpy, tt->draw, tt->gc, &image,
			  0, 0, x, y, w, h);
	}
}
Exemple #5
0
static void area_tests(struct test *t, int reps, int sets, enum target target)
{
	struct test_target tt;
	XImage image;
	uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
	int r, s, x, y;

	printf("Testing area sets (%s): ", test_target_name(target));
	fflush(stdout);

	test_target_create_render(&t->real, target, &tt);
	clear(&t->real, &tt);

	test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);

	for (s = 0; s < sets; s++) {
		for (r = 0; r < reps; r++) {
			int w = rand() % tt.width;
			int h = rand() % tt.height;
			int red = rand() % 0xff;
			int green = rand() % 0xff;
			int blue = rand() % 0xff;
			int alpha = rand() % 0xff;

			x = rand() % (2*tt.width) - tt.width;
			y = rand() % (2*tt.height) - tt.height;

			fill_rect(&t->real, tt.picture, PictOpSrc,
				  x, y, w, h, red, green, blue, alpha);

			if (x < 0)
				w += x, x = 0;
			if (y < 0)
				h += y, y = 0;
			if (x >= tt.width || y >= tt.height)
				continue;

			if (x + w > tt.width)
				w = tt.width - x;
			if (y + h > tt.height)
				h = tt.height - y;
			if (w <= 0 || h <= 0)
				continue;

			pixman_fill(cells, tt.width, 32, x, y, w, h,
				    color(red, green, blue, alpha));
		}

		XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);

		for (y = 0; y < tt.height; y++) {
			for (x = 0; x < tt.width; x++) {
				uint32_t result =
					*(uint32_t *)(image.data +
						      y*image.bytes_per_line +
						      image.bits_per_pixel*x/8);
				if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
					uint32_t mask;
					if (image.depth == 32)
						mask = 0xffffffff;
					else
						mask = (1 << image.depth) - 1;
					die("failed to set pixel (%d,%d) to %08x[%08x], found %08x instead\n",
					    x, y,
					    cells[y*tt.width+x] & mask,
					    cells[y*tt.width+x],
					    result & mask);
				}
			}
		}
	}

	printf("passed [%d iterations x %d]\n", reps, sets);

	test_target_destroy_render(&t->real, &tt);
	free(cells);
}
static void area_tests(struct test *t, int reps, int sets, enum target target)
{
	struct test_target tt;
	XImage image;
	uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
	int r, s, x, y;

	printf("Testing area sets (%s): ", test_target_name(target));
	fflush(stdout);

	test_target_create_render(&t->real, target, &tt);
	clear(&t->real, &tt);

	test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);

	for (s = 0; s < sets; s++) {
		for (r = 0; r < reps; r++) {
			int w = rand() % tt.width;
			int h = rand() % tt.height;
			uint32_t fg = rand();

			x = rand() % (2*tt.width) - tt.width;
			y = rand() % (2*tt.height) - tt.height;

			fill_rect(&t->real, tt.draw, GXcopy,
				  x, y, w, h, fg);

			if (x < 0)
				w += x, x = 0;
			if (y < 0)
				h += y, y = 0;
			if (x >= tt.width || y >= tt.height)
				continue;

			if (x + w > tt.width)
				w = tt.width - x;
			if (y + h > tt.height)
				h = tt.height - y;
			if (w <= 0 || h <= 0)
				continue;

			pixman_fill(cells, tt.width, 32, x, y, w, h, fg);
		}

		XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);

		for (y = 0; y < tt.height; y++) {
			for (x = 0; x < tt.width; x++) {
				uint32_t result = *(uint32_t *)
					(image.data +
					 y*image.bytes_per_line +
					 x*image.bits_per_pixel/8);
				if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
					char buf[600];
					uint32_t mask = depth_mask(image.depth);
					show_cells(buf,
						   (uint32_t*)image.data, cells,
						   x, y, tt.width, tt.height);

					die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n%s",
					    x, y,
					    cells[y*tt.width+x] & mask,
					    cells[y*tt.width+x],
					    result & mask,
					    result, buf);
				}
			}
		}
	}

	printf("passed [%d iterations x %d]\n", reps, sets);

	test_target_destroy_render(&t->real, &tt);
	free(cells);
}
Exemple #7
0
void
fbFill(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int width, int height)
{
    FbBits *dst;
    FbStride dstStride;
    int dstBpp;
    int dstXoff, dstYoff;
    FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);

    fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);

    switch (pGC->fillStyle) {
    case FillSolid:
#ifndef FB_ACCESS_WRAPPER
        if (pPriv->and || !pixman_fill((uint32_t *) dst, dstStride, dstBpp,
                                       x + dstXoff, y + dstYoff,
                                       width, height, pPriv->xor))
#endif
            fbSolid(dst + (y + dstYoff) * dstStride,
                    dstStride,
                    (x + dstXoff) * dstBpp,
                    dstBpp, width * dstBpp, height, pPriv->and, pPriv->xor);
        break;
    case FillStippled:
    case FillOpaqueStippled:{
        PixmapPtr pStip = pGC->stipple;
        int stipWidth = pStip->drawable.width;
        int stipHeight = pStip->drawable.height;

        if (dstBpp == 1) {
            int alu;
            FbBits *stip;
            FbStride stipStride;
            int stipBpp;
            _X_UNUSED int stipXoff, stipYoff;

            if (pGC->fillStyle == FillStippled)
                alu = FbStipple1Rop(pGC->alu, pGC->fgPixel);
            else
                alu = FbOpaqueStipple1Rop(pGC->alu, pGC->fgPixel, pGC->bgPixel);
            fbGetDrawable(&pStip->drawable, stip, stipStride, stipBpp, stipXoff,
                          stipYoff);
            fbTile(dst + (y + dstYoff) * dstStride, dstStride, x + dstXoff,
                   width, height, stip, stipStride, stipWidth, stipHeight, alu,
                   pPriv->pm, dstBpp, (pGC->patOrg.x + pDrawable->x + dstXoff),
                   pGC->patOrg.y + pDrawable->y - y);
            fbFinishAccess(&pStip->drawable);
        }
        else {
            FbStip *stip;
            FbStride stipStride;
            int stipBpp;
            _X_UNUSED int stipXoff, stipYoff;
            FbBits fgand, fgxor, bgand, bgxor;

            fgand = pPriv->and;
            fgxor = pPriv->xor;
            if (pGC->fillStyle == FillStippled) {
                bgand = fbAnd(GXnoop, (FbBits) 0, FB_ALLONES);
                bgxor = fbXor(GXnoop, (FbBits) 0, FB_ALLONES);
            }
            else {
                bgand = pPriv->bgand;
                bgxor = pPriv->bgxor;
            }

            fbGetStipDrawable(&pStip->drawable, stip, stipStride, stipBpp,
                              stipXoff, stipYoff);
            fbStipple(dst + (y + dstYoff) * dstStride, dstStride,
                      (x + dstXoff) * dstBpp, dstBpp, width * dstBpp, height,
                      stip, stipStride, stipWidth, stipHeight,
                      pPriv->evenStipple, fgand, fgxor, bgand, bgxor,
                      pGC->patOrg.x + pDrawable->x + dstXoff,
                      pGC->patOrg.y + pDrawable->y - y);
            fbFinishAccess(&pStip->drawable);
        }
        break;
    }
    case FillTiled:{
        PixmapPtr pTile = pGC->tile.pixmap;
        FbBits *tile;
        FbStride tileStride;
        int tileBpp;
        int tileWidth;
        int tileHeight;
        _X_UNUSED int tileXoff, tileYoff;

        fbGetDrawable(&pTile->drawable, tile, tileStride, tileBpp, tileXoff,
                      tileYoff);
        tileWidth = pTile->drawable.width;
        tileHeight = pTile->drawable.height;
        fbTile(dst + (y + dstYoff) * dstStride,
               dstStride,
               (x + dstXoff) * dstBpp,
               width * dstBpp, height,
               tile,
               tileStride,
               tileWidth * tileBpp,
               tileHeight,
               pGC->alu,
               pPriv->pm,
               dstBpp,
               (pGC->patOrg.x + pDrawable->x + dstXoff) * dstBpp,
               pGC->patOrg.y + pDrawable->y - y);
        fbFinishAccess(&pTile->drawable);
        break;
    }
    }
    fbValidateDrawable(pDrawable);
    fbFinishAccess(pDrawable);
}
static void area_tests(struct test *t, int reps, int sets, enum target target, int use_shm)
{
	struct test_target tt;
	XImage image;
	uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
	int r, s, x, y;

	printf("Testing area sets (%s %s shm): ",
	       test_target_name(target), use_shm ? "with" : "without" );
	fflush(stdout);

	test_target_create_render(&t->real, target, &tt);
	clear(&t->real, &tt);

	test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);

	for (s = 0; s < sets; s++) {
		for (r = 0; r < reps; r++) {
			int red = rand() % 0xff;
			int green = rand() % 0xff;
			int blue = rand() % 0xff;
			int alpha = rand() % 0xff;
			uint32_t fg = color(red, green, blue, alpha);
			int w, h;

			x = rand() % tt.width;
			y = rand() % tt.height;
			w = rand() % (tt.width - x);
			h = rand() % (tt.height - y);

			fill_rect(&t->real, tt.draw, tt.format, use_shm,
				  GXcopy, x, y, w, h, fg);

			pixman_fill(cells, tt.width, 32, x, y, w, h, fg);
		}

		XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);

		for (y = 0; y < tt.height; y++) {
			for (x = 0; x < tt.width; x++) {
				uint32_t result =
					*(uint32_t *)(image.data +
						      y*image.bytes_per_line +
						      image.bits_per_pixel*x/8);
				if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
					uint32_t mask = depth_mask(image.depth);
					char buf[600];

					show_cells(buf,
						   (uint32_t*)image.data, cells,
						   x, y, tt.width, tt.height);

					die("failed to set pixel (%d,%d) to %08x[%08x], found %08x [%08x] instead\n%s",
					    x, y,
					    cells[y*tt.width+x] & mask,
					    cells[y*tt.width+x],
					    result & mask, result,
					    buf);
				}
			}
		}
	}

	printf("passed [%d iterations x %d]\n", reps, sets);

	test_target_destroy_render(&t->real, &tt);
	free(cells);
}