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; }
static __inline int FbClipImageReg (pixman_region16_t *region, pixman_region16_t *clip, int dx, int dy) { if (pixman_region_num_rects (region) == 1 && pixman_region_num_rects (clip) == 1) { pixman_box16_t *pRbox = pixman_region_rects (region); pixman_box16_t *pCbox = pixman_region_rects (clip); int v; if (pRbox->x1 < (v = pCbox->x1 + dx)) pRbox->x1 = BOUND(v); if (pRbox->x2 > (v = pCbox->x2 + dx)) pRbox->x2 = BOUND(v); if (pRbox->y1 < (v = pCbox->y1 + dy)) pRbox->y1 = BOUND(v); if (pRbox->y2 > (v = pCbox->y2 + dy)) pRbox->y2 = BOUND(v); if (pRbox->x1 >= pRbox->x2 || pRbox->y1 >= pRbox->y2) { pixman_region_empty (region); } } else { pixman_region_translate (region, dx, dy); pixman_region_intersect (region, clip, region); pixman_region_translate (region, -dx, -dy); } return 1; }
static inline pixman_bool_t miClipPictureReg(pixman_region16_t * pRegion, pixman_region16_t * pClip, int dx, int dy) { if (pixman_region_n_rects(pRegion) == 1 && pixman_region_n_rects(pClip) == 1) { pixman_box16_t *pRbox = pixman_region_rectangles(pRegion, NULL); pixman_box16_t *pCbox = pixman_region_rectangles(pClip, NULL); int v; if (pRbox->x1 < (v = pCbox->x1 + dx)) pRbox->x1 = BOUND(v); if (pRbox->x2 > (v = pCbox->x2 + dx)) pRbox->x2 = BOUND(v); if (pRbox->y1 < (v = pCbox->y1 + dy)) pRbox->y1 = BOUND(v); if (pRbox->y2 > (v = pCbox->y2 + dy)) pRbox->y2 = BOUND(v); if (pRbox->x1 >= pRbox->x2 || pRbox->y1 >= pRbox->y2) { pixman_region_init(pRegion); } } else if (!pixman_region_not_empty(pClip)) return FALSE; else { if (dx || dy) pixman_region_translate(pRegion, -dx, -dy); if (!pixman_region_intersect(pRegion, pRegion, pClip)) return FALSE; if (dx || dy) pixman_region_translate(pRegion, dx, dy); } return pixman_region_not_empty(pRegion); }
static __inline Bool miClipPictureSrc (RegionPtr pRegion, PicturePtr pPicture, int dx, int dy) { if (pPicture->clientClipType != CT_NONE) { Bool result; pixman_region_translate ( pPicture->clientClip, pPicture->clipOrigin.x + dx, pPicture->clipOrigin.y + dy); result = RegionIntersect(pRegion, pRegion, pPicture->clientClip); pixman_region_translate ( pPicture->clientClip, - (pPicture->clipOrigin.x + dx), - (pPicture->clipOrigin.y + dy)); if (!result) return FALSE; } return TRUE; }
static pixman_image_t * create_bits_picture(PicturePtr pict, Bool has_clip, int *xoff, int *yoff) { PixmapPtr pixmap; FbBits *bits; FbStride stride; int bpp; pixman_image_t *image; fbGetDrawablePixmap(pict->pDrawable, pixmap, *xoff, *yoff); fbGetPixmapBitsData(pixmap, bits, stride, bpp); image = pixman_image_create_bits((pixman_format_code_t) pict->format, pixmap->drawable.width, pixmap->drawable.height, (uint32_t *) bits, stride * sizeof(FbStride)); if (!image) return NULL; #ifdef FB_ACCESS_WRAPPER #if FB_SHIFT==5 pixman_image_set_accessors(image, (pixman_read_memory_func_t) wfbReadMemory, (pixman_write_memory_func_t) wfbWriteMemory); #else #error The pixman library only works when FbBits is 32 bits wide #endif #endif /* pCompositeClip is undefined for source pictures, so * only set the clip region for pictures with drawables */ if (has_clip) { if (pict->clientClipType != CT_NONE) pixman_image_set_has_client_clip(image, TRUE); if (*xoff || *yoff) pixman_region_translate(pict->pCompositeClip, *xoff, *yoff); pixman_image_set_clip_region(image, pict->pCompositeClip); if (*xoff || *yoff) pixman_region_translate(pict->pCompositeClip, -*xoff, -*yoff); } /* Indexed table */ if (pict->pFormat->index.devPrivate) pixman_image_set_indexed(image, pict->pFormat->index.devPrivate); /* Add in drawable origin to position within the image */ *xoff += pict->pDrawable->x; *yoff += pict->pDrawable->y; return image; }
void _cairo_clip_translate (cairo_clip_t *clip, cairo_fixed_t tx, cairo_fixed_t ty) { if (clip->region) { pixman_region_translate (clip->region, _cairo_fixed_integer_part (tx), _cairo_fixed_integer_part (ty)); } if (clip->surface) { clip->surface_rect.x += _cairo_fixed_integer_part (tx); clip->surface_rect.y += _cairo_fixed_integer_part (ty); } if (clip->path) { cairo_clip_path_t *clip_path = clip->path; cairo_matrix_t matrix; cairo_matrix_init_translate (&matrix, _cairo_fixed_to_double (tx), _cairo_fixed_to_double (ty)); while (clip_path) { _cairo_path_fixed_device_transform (&clip_path->path, &matrix); clip_path = clip_path->prev; } } }
EAPI void ecore_x_xregion_translate(Ecore_X_XRegion *region, int x, int y) { if (!region) return; pixman_region_translate((pixman_region16_t *)region, x, y); }
static pixman_image_t * create_bits_picture(PicturePtr pict, Bool has_clip, int *xoff, int *yoff) { PixmapPtr pixmap; FbBits *bits; FbStride stride; int bpp; pixman_image_t *image; fbGetDrawablePixmap(pict->pDrawable, pixmap, *xoff, *yoff); fbGetPixmapBitsData(pixmap, bits, stride, bpp); image = pixman_image_create_bits((pixman_format_code_t) pict->format, pixmap->drawable.width, pixmap->drawable.height, (uint32_t *) bits, stride * sizeof(FbStride)); if (!image) return NULL; /* pCompositeClip is undefined for source pictures, so * only set the clip region for pictures with drawables */ if (has_clip) { if (picture_has_clip(pict)) pixman_image_set_has_client_clip(image, TRUE); if (*xoff || *yoff) pixman_region_translate(pict->pCompositeClip, *xoff, *yoff); pixman_image_set_clip_region(image, pict->pCompositeClip); if (*xoff || *yoff) pixman_region_translate(pict->pCompositeClip, -*xoff, -*yoff); } /* Indexed table */ if (pict->pFormat->index.devPrivate) pixman_image_set_indexed(image, pict->pFormat->index.devPrivate); /* Add in drawable origin to position within the image */ *xoff += pict->pDrawable->x; *yoff += pict->pDrawable->y; return image; }
static inline pixman_bool_t miClipPictureSrc (pixman_region16_t * pRegion, pixman_image_t * pPicture, int dx, int dy) { /* XXX what to do with clipping from transformed pictures? */ if (pPicture->common.transform || pPicture->type != BITS) return TRUE; if (pPicture->common.repeat) { /* If the clip region was set by a client, then it should be intersected * with the composite region since it's interpreted as happening * after the repeat algorithm. * * If the clip region was not set by a client, then it was imposed by * boundaries of the pixmap, or by sibling or child windows, which means * it should in theory be repeated along. FIXME: we ignore that case. * It is only relevant for windows that are (a) clipped by siblings/children * and (b) used as source. However this case is not useful anyway due * to lack of GraphicsExpose events. */ if (pPicture->common.has_client_clip) { pixman_region_translate ( pRegion, dx, dy); if (!pixman_region_intersect (pRegion, pRegion, (pixman_region16_t *) pPicture->common.src_clip)) return FALSE; pixman_region_translate ( pRegion, -dx, -dy); } return TRUE; } else { return miClipPictureReg (pRegion, pPicture->common.src_clip, dx, dy); } }
static __inline int FbClipImageSrc (pixman_region16_t *region, pixman_image_t *image, int dx, int dy) { /* XXX what to do with clipping from transformed pictures? */ if (image->transform) return 1; if (image->repeat) { /* XXX no source clipping */ if (image->compositeClipSource && image->clientClipType != CT_NONE) { pixman_region_translate (region, dx - image->clipOrigin.x, dy - image->clipOrigin.y); pixman_region_intersect (region, image->clientClip, region); pixman_region_translate (region, - (dx - image->clipOrigin.x), - (dy - image->clipOrigin.y)); } return 1; } else { pixman_region16_t *clip; if (image->compositeClipSource) clip = image->pCompositeClip; else clip = image->pSourceClip; return FbClipImageReg (region, clip, dx, dy); } return 1; }
void _cairo_clip_translate (cairo_clip_t *clip, cairo_fixed_t tx, cairo_fixed_t ty) { if (clip->region) { pixman_region_translate (clip->region, _cairo_fixed_integer_part (tx), _cairo_fixed_integer_part (ty)); } if (clip->surface) { clip->surface_rect.x += _cairo_fixed_integer_part (tx); clip->surface_rect.y += _cairo_fixed_integer_part (ty); } if (clip->path) { cairo_clip_path_t *clip_path = clip->path; while (clip_path) { _cairo_path_fixed_offset (&clip_path->path, tx, ty); clip_path = clip_path->prev; } } }
static Bool _glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y, int w, int h, int left_pad, int image_format, char *bits, Bool fallback) { PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable); glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap); RegionPtr clip; int x_off, y_off; Bool ret = FALSE; PixmapPtr temp_pixmap, sub_pixmap; glamor_pixmap_private *temp_pixmap_priv; BoxRec box; int stride; glamor_get_drawable_deltas(drawable, pixmap, &x_off, &y_off); clip = fbGetCompositeClip(gc); if (image_format == XYBitmap) { assert(depth == 1); goto fail; } if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)) { glamor_fallback("has no fbo.\n"); goto fail; } if (image_format != ZPixmap) { glamor_fallback("non-ZPixmap\n"); goto fail; } if (!glamor_set_planemask(pixmap, gc->planemask)) { goto fail; } /* create a temporary pixmap and upload the bits to that * pixmap, then apply clip copy it to the destination pixmap.*/ stride = PixmapBytePad(w, depth); box.x1 = x + drawable->x; box.y1 = y + drawable->y; box.x2 = x + w + drawable->x; box.y2 = y + h + drawable->y; if ((clip != NULL && RegionContainsRect(clip, &box) != rgnIN) || gc->alu != GXcopy) { temp_pixmap = glamor_create_pixmap(drawable->pScreen, w, h, depth, 0); if (temp_pixmap == NULL) goto fail; temp_pixmap_priv = glamor_get_pixmap_private(temp_pixmap); if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv)) { temp_pixmap_priv->base.picture = pixmap_priv->base.picture; temp_pixmap_priv->base.is_picture = pixmap_priv->base.is_picture; } glamor_upload_sub_pixmap_to_texture(temp_pixmap, 0, 0, w, h, stride, bits, 0); glamor_copy_area(&temp_pixmap->drawable, drawable, gc, 0, 0, w, h, x, y); glamor_destroy_pixmap(temp_pixmap); } else { glamor_upload_sub_pixmap_to_texture(pixmap, x + drawable->x + x_off, y + drawable->y + y_off, w, h, stride, bits, 0); } ret = TRUE; goto done; fail: glamor_set_planemask(pixmap, ~0); if (!fallback && glamor_ddx_fallback_check_pixmap(&pixmap->drawable)) goto done; glamor_fallback("to %p (%c)\n", drawable, glamor_get_drawable_location(drawable)); sub_pixmap = glamor_get_sub_pixmap(pixmap, x + x_off + drawable->x, y + y_off + drawable->y, w, h, GLAMOR_ACCESS_RW); if (sub_pixmap) { if (clip != NULL) pixman_region_translate (clip, -x - drawable->x, -y - drawable->y); fbPutImage(&sub_pixmap->drawable, gc, depth, 0, 0, w, h, left_pad, image_format, bits); glamor_put_sub_pixmap(sub_pixmap, pixmap, x + x_off + drawable->x, y + y_off + drawable->y, w, h, GLAMOR_ACCESS_RW); if (clip != NULL) pixman_region_translate (clip, x + drawable->x, y + drawable->y); } else fbPutImage(drawable, gc, depth, x, y, w, h, left_pad, image_format, bits); ret = TRUE; done: return ret; }
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; } } }