Exemplo n.º 1
0
int
pixman_image_set_clip_region (pixman_image_t	*image,
                              pixman_region16_t	*region)
{
    pixman_image_destroyClip (image);
    if (region) {
        image->clientClip = pixman_region_create ();
        pixman_region_copy (image->clientClip, region);
        image->clientClipType = CT_REGION;
    }

    if (image->freeCompClip)
        pixman_region_destroy (image->pCompositeClip);
    image->pCompositeClip = pixman_region_create();
    pixman_region_union_rect (image->pCompositeClip, image->pCompositeClip,
                              0, 0, image->pixels->width, image->pixels->height);
    image->freeCompClip = 1;
    if (region) {
        pixman_region_translate (image->pCompositeClip,
                                 - image->clipOrigin.x,
                                 - image->clipOrigin.y);
        pixman_region_intersect (image->pCompositeClip,
                                 image->pCompositeClip,
                                 region);
        pixman_region_translate (image->pCompositeClip,
                                 image->clipOrigin.x,
                                 image->clipOrigin.y);
    }

    image->stateChanges |= CPClipMask;
    return 0;
}
Exemplo n.º 2
0
void
pixman_image_init (pixman_image_t *image)
{
    image->refcnt = 1;
    image->repeat = 0;
    image->graphicsExposures = 0;
    image->subWindowMode = ClipByChildren;
    image->polyEdge = PolyEdgeSharp;
    image->polyMode = PolyModePrecise;
    /*
     * In the server this was 0 because the composite clip list
     * can be referenced from a window (and often is)
     */
    image->freeCompClip = 0;
    image->freeSourceClip = 0;
    image->clientClipType = CT_NONE;
    image->componentAlpha = 0;
    image->compositeClipSource = 0;

    image->alphaMap = NULL;
    image->alphaOrigin.x = 0;
    image->alphaOrigin.y = 0;

    image->clipOrigin.x = 0;
    image->clipOrigin.y = 0;
    image->clientClip = NULL;

    image->dither = 0L;

    image->stateChanges = (1 << (CPLastBit+1)) - 1;
    /* XXX: What to lodge here?
        image->serialNumber = GC_CHANGE_SERIAL_BIT;
    */

    image->pCompositeClip = pixman_region_create();
    pixman_region_union_rect (image->pCompositeClip, image->pCompositeClip,
                              0, 0, image->pixels->width, image->pixels->height);
    image->freeCompClip = 1;

    image->pSourceClip = pixman_region_create ();
    pixman_region_union_rect (image->pSourceClip, image->pSourceClip,
                              0, 0, image->pixels->width, image->pixels->height);
    image->freeSourceClip = 1;

    image->transform = NULL;

    image->filter = PIXMAN_FILTER_NEAREST;
    image->filter_params = NULL;
    image->filter_nparams = 0;


    image->owns_pixels = 0;
}
Exemplo n.º 3
0
void
_cairo_clip_init_deep_copy (cairo_clip_t    *clip,
                            cairo_clip_t    *other,
                            cairo_surface_t *target)
{
    _cairo_clip_init (clip, target);

    if (other->mode != clip->mode) {
        /* We should reapply the original clip path in this case, and let
         * whatever the right handling is happen */
    } else {
        if (other->region) {
            clip->region = pixman_region_create ();
            pixman_region_copy (clip->region, other->region);
        }

        if (other->surface) {
            _cairo_surface_clone_similar (target, other->surface, &clip->surface);
            clip->surface_rect = other->surface_rect;
        }

        if (other->path) {
            _cairo_clip_path_reapply_clip_path (clip, other->path);
        }
    }
}
/**
 * _cairo_region_create_from_rectangle:
 * @rect: a #cairo_rectangle_t
 * 
 * Creates a region with extents initialized from the given
 * rectangle.
 * 
 * Return value: a newly created #pixman_region16_t or %NULL if
 *    memory couldn't a allocated.
 **/
pixman_region16_t *
_cairo_region_create_from_rectangle (cairo_rectangle_t *rect)
{
    /* We can't use pixman_region_create_simple(), because it doesn't
     * have an error return
     */
    pixman_region16_t *region = pixman_region_create ();
    if (pixman_region_union_rect (region, region,
				  rect->x, rect->y,
				  rect->width, rect->height) != PIXMAN_REGION_STATUS_SUCCESS) {
	pixman_region_destroy (region);
	return NULL;
    }
    
    return region;
}
Exemplo n.º 5
0
static cairo_int_status_t
_cairo_quartz_surface_set_clip_region(void *abstract_surface,
                                      pixman_region16_t * region)
{
    cairo_quartz_surface_t *surface = abstract_surface;

    if (surface->clip_region)
        pixman_region_destroy (surface->clip_region);

    if (region) {
        surface->clip_region = pixman_region_create ();
        pixman_region_copy (surface->clip_region, region);
    } else
        surface->clip_region = NULL;

    return CAIRO_STATUS_SUCCESS;
}
Exemplo n.º 6
0
void
_cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other)
{
    clip->mode = other->mode;

    clip->surface = cairo_surface_reference (other->surface);
    clip->surface_rect = other->surface_rect;

    clip->serial = other->serial;

    if (other->region == NULL) {
	clip->region = other->region;
    } else {
	clip->region = pixman_region_create ();
	pixman_region_copy (clip->region, other->region);
    }

    clip->path = _cairo_clip_path_reference (other->path);
}
Exemplo n.º 7
0
/**
 * _cairo_traps_extract_region:
 * @traps: a #cairo_traps_t
 * @region: on return, %NULL is stored here if the trapezoids aren't
 *          exactly representable as a pixman region, otherwise a
 *          a pointer to such a region, newly allocated.
 *          (free with pixman region destroy)
 * 
 * Determines if a set of trapezoids are exactly representable as a
 * pixman region, and if so creates such a region.
 * 
 * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY
 **/
cairo_status_t
_cairo_traps_extract_region (cairo_traps_t      *traps,
			     pixman_region16_t **region)
{
    int i;

    for (i = 0; i < traps->num_traps; i++)
	if (!(traps->traps[i].left.p1.x == traps->traps[i].left.p2.x
	      && traps->traps[i].right.p1.x == traps->traps[i].right.p2.x
	      && _cairo_fixed_is_integer(traps->traps[i].top)
	      && _cairo_fixed_is_integer(traps->traps[i].bottom)
	      && _cairo_fixed_is_integer(traps->traps[i].left.p1.x)
	      && _cairo_fixed_is_integer(traps->traps[i].right.p1.x))) {
	    *region = NULL;
	    return CAIRO_STATUS_SUCCESS;
	}
    
    *region = pixman_region_create ();

    for (i = 0; i < traps->num_traps; i++) {
	int x = _cairo_fixed_integer_part(traps->traps[i].left.p1.x);
	int y = _cairo_fixed_integer_part(traps->traps[i].top);
	int width = _cairo_fixed_integer_part(traps->traps[i].right.p1.x) - x;
	int height = _cairo_fixed_integer_part(traps->traps[i].bottom) - y;

	/* XXX: Sometimes we get degenerate trapezoids from the tesellator,
	 * if we call pixman_region_union_rect(), it bizarrly fails on such
	 * an empty rectangle, so skip them.
	 */
	if (width == 0 || height == 0)
	  continue;
	
	if (pixman_region_union_rect (*region, *region,
				      x, y, width, height) != PIXMAN_REGION_STATUS_SUCCESS) {
	    pixman_region_destroy (*region);
	    return CAIRO_STATUS_NO_MEMORY;
	}
    }

    return CAIRO_STATUS_SUCCESS;
}
Exemplo n.º 8
0
static cairo_status_t
_cairo_clip_intersect_region (cairo_clip_t    *clip,
			      cairo_traps_t   *traps,
			      cairo_surface_t *target)
{
    pixman_region16_t *region;
    cairo_status_t status;

    if (clip->mode != CAIRO_CLIP_MODE_REGION)
	return CAIRO_INT_STATUS_UNSUPPORTED;

    status = _cairo_traps_extract_region (traps, &region);
    if (status)
	return status;

    if (region == NULL)
	return CAIRO_INT_STATUS_UNSUPPORTED;

    status = CAIRO_STATUS_SUCCESS;
    if (clip->region == NULL) {
	clip->region = region;
    } else {
	pixman_region16_t *intersection = pixman_region_create();

	if (pixman_region_intersect (intersection,
				     clip->region, region)
	    == PIXMAN_REGION_STATUS_SUCCESS) {
	    pixman_region_destroy (clip->region);
	    clip->region = intersection;
	} else {
	    status = CAIRO_STATUS_NO_MEMORY;
	}
	pixman_region_destroy (region);
    }

    clip->serial = _cairo_surface_allocate_clip_serial (target);

    return status;
}
Exemplo n.º 9
0
static void
pixman_color_rects (pixman_image_t	 *dst,
                    pixman_image_t	 *clipPict,
                    pixman_color_t	 *color,
                    int	 nRect,
                    pixman_rectangle_t *rects,
                    int	 xoff,
                    int	 yoff)
{
    pixman_bits_t	pixel;
    pixman_region16_t  *clip;
    pixman_region16_t  *rects_as_region;
    pixman_box16_t     *clipped_rects;
    int	                i, n_clipped_rects;
    FillFunc            func;

    pixman_color_to_pixel (&dst->image_format,
                           color,
                           &pixel);

    /* offset to the right place on the destination image */
    xoff -= dst->pixels->x;
    yoff -= dst->pixels->y;

    clip = pixman_region_create();
    pixman_region_union_rect (clip, clip,
                              dst->pixels->x, dst->pixels->y,
                              dst->pixels->width, dst->pixels->height);

    pixman_region_intersect (clip, clip, clipPict->pCompositeClip);
    if (clipPict->alphaMap)
    {
        pixman_region_translate (clip,
                                 -clipPict->alphaOrigin.x,
                                 -clipPict->alphaOrigin.y);
        pixman_region_intersect (clip, clip, clipPict->alphaMap->pCompositeClip);
        pixman_region_translate (clip,
                                 clipPict->alphaOrigin.x,
                                 clipPict->alphaOrigin.y);
    }

    if (xoff || yoff)
    {
        for (i = 0; i < nRect; i++)
        {
            rects[i].x -= xoff;
            rects[i].y -= yoff;
        }
    }

    rects_as_region = pixman_region_create ();
    for (i = 0; i < nRect; i++)
    {
        pixman_region_union_rect (rects_as_region, rects_as_region,
                                  rects[i].x, rects[i].y,
                                  rects[i].width, rects[i].height);
    }

    pixman_region_intersect (rects_as_region, rects_as_region, clip);
    pixman_region_destroy (clip);

    n_clipped_rects = pixman_region_num_rects (rects_as_region);
    clipped_rects = pixman_region_rects (rects_as_region);

    if (dst->pixels->bpp == 8)
        func = pixman_fill_rect_8bpp;
    else if (dst->pixels->bpp == 32)
        func = pixman_fill_rect_32bpp;
    else if (dst->pixels->bpp == 1)
        func = pixman_fill_rect_1bpp;
    else
        func = pixman_fill_rect_general;

    for (i = 0; i < n_clipped_rects; i++) {
        (*func) (dst,
                 clipped_rects[i].x1,
                 clipped_rects[i].y1,
                 clipped_rects[i].x2 - clipped_rects[i].x1,
                 clipped_rects[i].y2 - clipped_rects[i].y1,
                 &pixel);
    }

    pixman_region_destroy (rects_as_region);

    if (xoff || yoff)
    {
        for (i = 0; i < nRect; i++)
        {
            rects[i].x += xoff;
            rects[i].y += yoff;
        }
    }
}