[PATCH v4 2/2] xwm: Scale icon if size is not the target size
Scott Moreau
oreaus at gmail.com
Fri Mar 23 20:30:47 UTC 2018
On Fri, Mar 23, 2018 at 2:15 PM, Derek Foreman <derekf at osg.samsung.com>
wrote:
> On 2018-03-23 02:47 PM, Scott Moreau wrote:
> > This scales the icon cairo surface for the titlebar if it isn't the
> > target size.
> >
> > shared/cairo-util: Add surface resizing function to be used for this
> > case and other potential cases.
> > ---
> >
> > Changed in v2:
> >
> > - Rebase to [PATCH 1/1 v3] xwm: Choose icon closest to target size
> >
> > Changed in v3:
> >
> > - No changes
> >
> > Changed in v4:
> >
> > - Fixed whitespace problems
> > - Renamed cairo_resize_surface() to resize_cairo_surface()
> >
> > shared/cairo-util.c | 63 ++++++++++++++++++++++++++++++
> +++++++++++++++++
> > shared/cairo-util.h | 4 +++
> > xwayland/window-manager.c | 4 +++
> > 3 files changed, 71 insertions(+)
> >
> > diff --git a/shared/cairo-util.c b/shared/cairo-util.c
> > index d71e0ed..442182b 100644
> > --- a/shared/cairo-util.c
> > +++ b/shared/cairo-util.c
> > @@ -365,6 +365,69 @@ load_cairo_surface(const char *filename)
> > width, height, stride);
> > }
> >
> > +static cairo_surface_t *
> > +scale_surface(cairo_surface_t *source, cairo_filter_t filter,
> > + double width, double height)
>
> Still have some whitespace issues here.
>
Hm, I have 5 * 8 wide tabs here and it seems to appear correct in my editor.
I'll wait for other potential comments/reviews before submitting another
patch.
>
> Otherwise, this is
> Reviewed-by: Derek Foreman <derekf at osg.samsung.com>
>
> Does this + your leak fix close all known bugs in the icon code?
>
Well now that you mention it, I did notice one other thing.
weston_wm_handle_icon() can be called multiple times and sets
window->icon_surface from a newly created surface without destroying the
old one first, in the case where there isn't a frame yet. I haven't
submitted a patch for this at all.
>
> Thanks,
> Derek
>
Thanks,
Scott
>
> > +{
> > + cairo_surface_t *dest;
> > + cairo_t *cr;
> > + int old_width, old_height;
> > +
> > + old_width = cairo_image_surface_get_width(source);
> > + old_height = cairo_image_surface_get_height(source);
> > +
> > + dest = cairo_surface_create_similar(source,
> > + CAIRO_CONTENT_COLOR_ALPHA,
> > + width, height);
> > + cr = cairo_create (dest);
> > +
> > + cairo_scale (cr, width / old_width, height / old_height);
> > + cairo_set_source_surface (cr, source, 0, 0);
> > +
> > + cairo_pattern_set_extend (cairo_get_source(cr),
> > + CAIRO_EXTEND_REFLECT);
> > +
> > + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
> > +
> > + cairo_paint (cr);
> > +
> > + cairo_destroy (cr);
> > +
> > + cairo_surface_destroy(source);
> > +
> > + return dest;
> > +}
> > +
> > +cairo_surface_t *
> > +resize_cairo_surface(cairo_surface_t *source, cairo_filter_t filter,
> > + int width, int height)
> > +{
> > + if (!filter)
> > + filter = CAIRO_FILTER_BEST;
> > +
> > + while((cairo_image_surface_get_width(source) / 2.0f) > width)
> > + source = scale_surface(source, filter,
> > + cairo_image_surface_get_width(source) / 2.0f,
> > + cairo_image_surface_get_height(source));
> > +
> > + while((cairo_image_surface_get_height(source) / 2.0f) > height)
> > + source = scale_surface(source, filter,
> > + cairo_image_surface_get_width(source),
> > + cairo_image_surface_get_height(source) / 2.0f);
> > +
> > + while((cairo_image_surface_get_width(source) * 2.0f) < width)
> > + source = scale_surface(source, filter,
> > + cairo_image_surface_get_width(source) * 2.0f,
> > + cairo_image_surface_get_height(source));
> > +
> > + while((cairo_image_surface_get_height(source) * 2.0f) < height)
> > + source = scale_surface(source, filter,
> > + cairo_image_surface_get_width(source),
> > + cairo_image_surface_get_height(source) * 2.0f);
> > +
> > + return scale_surface(source, filter, width, height);
> > +}
> > +
> > void
> > theme_set_background_source(struct theme *t, cairo_t *cr, uint32_t
> flags)
> > {
> > diff --git a/shared/cairo-util.h b/shared/cairo-util.h
> > index 6fd11f6..1c58f3b 100644
> > --- a/shared/cairo-util.h
> > +++ b/shared/cairo-util.h
> > @@ -49,6 +49,10 @@ rounded_rect(cairo_t *cr, int x0, int y0, int x1, int
> y1, int radius);
> > cairo_surface_t *
> > load_cairo_surface(const char *filename);
> >
> > +cairo_surface_t *
> > +resize_cairo_surface(cairo_surface_t *source, cairo_filter_t filter,
> > + int width, int height);
> > +
> > struct theme {
> > cairo_surface_t *active_frame;
> > cairo_surface_t *inactive_frame;
> > diff --git a/xwayland/window-manager.c b/xwayland/window-manager.c
> > index 5fb41bf..50c5855 100644
> > --- a/xwayland/window-manager.c
> > +++ b/xwayland/window-manager.c
> > @@ -1463,6 +1463,10 @@ weston_wm_handle_icon(struct weston_wm *wm,
> struct weston_wm_window *window)
> > return;
> > }
> >
> > + if (width != XWM_ICON_SIZE || height != XWM_ICON_SIZE)
> > + new_surface = resize_cairo_surface(new_surface, 0,
> > + XWM_ICON_SIZE, XWM_ICON_SIZE);
> > +
> > if (window->frame)
> > frame_set_icon(window->frame, new_surface);
> > else /* We don’t have a frame yet */
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20180323/c1492c21/attachment.html>
More information about the wayland-devel
mailing list