--- rxvt-unicode/src/rxvtimg.C 2012/06/14 18:19:11 1.84 +++ rxvt-unicode/src/rxvtimg.C 2012/06/14 19:42:01 1.88 @@ -4,6 +4,38 @@ #if HAVE_IMG +#if 0 +struct pict +{ + Display *dpy; + Picture pic; + + operator Picture () const + { + return pic; + } + + pict () + : pic (0) + { + } + + pict (rxvt_img *img, XRenderPictFormat *format = 0) + : dpy (img->s->display->dpy) + { + XRenderPictureAttributes pa; + pa.repeat = img->repeat; + pic = XRenderCreatePicture (dpy, img->pm, format ? format : img->format, CPRepeat, &pa); + } + + ~pict () + { + if (pic) + XRenderFreePicture (dpy, pic); + } +}; +#endif + static XRenderPictFormat * find_alpha_format_for (Display *dpy, XRenderPictFormat *format) { @@ -217,7 +249,7 @@ } Picture -rxvt_img::src_picture () +rxvt_img::picture () { Display *dpy = s->display->dpy; @@ -251,7 +283,7 @@ XRenderColor rc = { c.r, c.g, c.b, c.a }; Display *dpy = s->display->dpy; - Picture src = src_picture (); + Picture src = picture (); XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); XRenderFreePicture (dpy, src); } @@ -267,7 +299,7 @@ rxvt_img *img = new rxvt_img (s, find_alpha_format_for (dpy, format), x, y, w, h, repeat); img->alloc (); - Picture src = src_picture (); + Picture src = picture (); Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); @@ -451,7 +483,7 @@ Display *dpy = s->display->dpy; - Picture src = src_picture (); + Picture src = picture (); Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); Picture mul = create_xrender_mask (dpy, pm, True, True); @@ -478,6 +510,32 @@ delete img; } +void +rxvt_img::draw (rxvt_img *img, int op, nv mask) +{ + unshare (); + + Display *dpy = s->display->dpy; + Picture src = img->picture (); + Picture dst = picture (); + Picture mask_p = 0; + + if (mask != 1.) + { + mask_p = create_xrender_mask (dpy, img->pm, False, False); + XRenderColor mask_c = { 0, 0, 0, float_to_component (mask) }; + XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); + } + + XRenderComposite (dpy, op, src, mask_p, dst, x - img->x, y - img->y, 0, 0, 0, 0, w, h); + + XRenderFreePicture (dpy, src); + XRenderFreePicture (dpy, dst); + + if (mask_p) + XRenderFreePicture (dpy, mask_p); +} + rxvt_img * rxvt_img::clone () { @@ -500,17 +558,17 @@ rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); img->alloc (); - Picture src = src_picture (); + Picture src = picture (); Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); if (alpha) { XRenderColor rc = { 0, 0, 0, 0 }; XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles - XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h); + XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, x, y, ref->w, ref->h); } else - XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); + XRenderComposite (dpy, PictOpSrc, src, None, dst, -x, -y, 0, 0, 0, 0, w, h); XRenderFreePicture (dpy, src); XRenderFreePicture (dpy, dst); @@ -523,8 +581,8 @@ { rxvt_img *img = clone (); - img->x += x; - img->y += y; + img->x -= x; + img->y -= y; if (w != width || h != height) { @@ -573,20 +631,16 @@ rxvt_img * rxvt_img::transform (nv matrix[3][3]) { - // find new offset - int ox = mat_apply (matrix, 0, x, y); - int oy = mat_apply (matrix, 1, x, y); - // calculate new pixel bounding box coordinates - nv d [2], rmin[2], rmax[2]; + nv rmin[2], rmax[2]; for (int i = 0; i < 2; ++i) { nv v; - v = mat_apply (matrix, i, 0, 0); rmin [i] = rmax [i] = v; d [i] = v; - v = mat_apply (matrix, i, w, 0); min_it (rmin [i], v); max_it (rmax [i], v); - v = mat_apply (matrix, i, 0, h); min_it (rmin [i], v); max_it (rmax [i], v); - v = mat_apply (matrix, i, w, h); min_it (rmin [i], v); max_it (rmax [i], v); + v = mat_apply (matrix, i, 0+x, 0+y); rmin [i] = rmax [i] = v; + v = mat_apply (matrix, i, w+x, 0+y); min_it (rmin [i], v); max_it (rmax [i], v); + v = mat_apply (matrix, i, 0+x, h+y); min_it (rmin [i], v); max_it (rmax [i], v); + v = mat_apply (matrix, i, w+x, h+y); min_it (rmin [i], v); max_it (rmax [i], v); } int dx = floor (rmin [0]); @@ -598,11 +652,11 @@ nv inv[3][3]; mat_invert (matrix, inv); - rxvt_img *img = new rxvt_img (s, format, ox - dx - d [0], oy - dy - d [1], new_width, new_height, repeat); + rxvt_img *img = new rxvt_img (s, format, dx, dy, new_width, new_height, repeat); img->alloc (); Display *dpy = s->display->dpy; - Picture src = src_picture (); + Picture src = picture (); Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); XTransform xfrm; @@ -651,7 +705,7 @@ nv c = cos (phi); nv matrix[3][3] = { - { c, -s, cx - c * cx + s * cy }, + { c, -s, cx - c * cx + s * cy + 200 }, { s, c, cy - s * cx - c * cy }, { 0, 0, 1 } //{ c, -s, 0 }, @@ -677,7 +731,7 @@ img->alloc (); Display *dpy = s->display->dpy; - Picture src = src_picture (); + Picture src = picture (); Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); int op = PictOpSrc; @@ -703,7 +757,7 @@ { rxvt_img *img2 = clone (); Display *dpy = s->display->dpy; - Picture src = img->src_picture (); + Picture src = img->picture (); Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); Picture mask = create_xrender_mask (dpy, img->pm, False, False);