<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 23, 2018 at 2:15 PM, Derek Foreman <span dir="ltr"><<a href="mailto:derekf@osg.samsung.com" target="_blank">derekf@osg.samsung.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="m_-8348019795479344516gmail-HOEnZb"><div class="m_-8348019795479344516gmail-h5">On 2018-03-23 02:47 PM, Scott Moreau wrote:<br>
> This scales the icon cairo surface for the titlebar if it isn't the<br>
> target size.<br>
><br>
> shared/cairo-util: Add surface resizing function to be used for this<br>
> case and other potential cases.<br>
> ---<br>
><br>
> Changed in v2:<br>
><br>
> - Rebase to [PATCH 1/1 v3] xwm: Choose icon closest to target size<br>
><br>
> Changed in v3:<br>
><br>
> - No changes<br>
><br>
> Changed in v4:<br>
><br>
> - Fixed whitespace problems<br>
> - Renamed cairo_resize_surface() to resize_cairo_surface()<br>
><br>
>  shared/cairo-util.c       | 63 ++++++++++++++++++++++++++++++<wbr>+++++++++++++++++<br>
>  shared/cairo-util.h       |  4 +++<br>
>  xwayland/window-manager.c |  4 +++<br>
>  3 files changed, 71 insertions(+)<br>
><br>
> diff --git a/shared/cairo-util.c b/shared/cairo-util.c<br>
> index d71e0ed..442182b 100644<br>
> --- a/shared/cairo-util.c<br>
> +++ b/shared/cairo-util.c<br>
> @@ -365,6 +365,69 @@ load_cairo_surface(const char *filename)<br>
>                                                  width, height, stride);<br>
>  }<br>
><br>
> +static cairo_surface_t *<br>
> +scale_surface(cairo_surface_t *source, cairo_filter_t filter,<br>
> +                                     double width, double height)<br>
<br>
</div></div>Still have some whitespace issues here.<br></blockquote><div><br></div><div>Hm, I have 5 * 8 wide tabs here and it seems to appear correct in my editor.<br></div><div>I'll wait for other potential comments/reviews before submitting another patch.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Otherwise, this is<br>
Reviewed-by: Derek Foreman <<a href="mailto:derekf@osg.samsung.com" target="_blank">derekf@osg.samsung.com</a>><br>
<br>
Does this + your leak fix close all known bugs in the icon code?<br></blockquote><div><br></div><div>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.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Thanks,<br>
Derek<br></blockquote><div><br></div><div>Thanks,<br></div><div>Scott<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="m_-8348019795479344516gmail-HOEnZb"><div class="m_-8348019795479344516gmail-h5"><br>
> +{<br>
> +     cairo_surface_t *dest;<br>
> +     cairo_t *cr;<br>
> +     int old_width, old_height;<br>
> +<br>
> +     old_width = cairo_image_surface_get_width(<wbr>source);<br>
> +     old_height = cairo_image_surface_get_height<wbr>(source);<br>
> +<br>
> +     dest = cairo_surface_create_similar(s<wbr>ource,<br>
> +                                     CAIRO_CONTENT_COLOR_ALPHA,<br>
> +                                     width, height);<br>
> +     cr = cairo_create (dest);<br>
> +<br>
> +     cairo_scale (cr, width / old_width, height / old_height);<br>
> +     cairo_set_source_surface (cr, source, 0, 0);<br>
> +<br>
> +     cairo_pattern_set_extend (cairo_get_source(cr),<br>
> +                                     CAIRO_EXTEND_REFLECT);<br>
> +<br>
> +     cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);<br>
> +<br>
> +     cairo_paint (cr);<br>
> +<br>
> +     cairo_destroy (cr);<br>
> +<br>
> +     cairo_surface_destroy(source)<wbr>;<br>
> +<br>
> +     return dest;<br>
> +}<br>
> +<br>
> +cairo_surface_t *<br>
> +resize_cairo_surface(cairo_su<wbr>rface_t *source, cairo_filter_t filter,<br>
> +                                             int width, int height)<br>
> +{<br>
> +     if (!filter)<br>
> +             filter = CAIRO_FILTER_BEST;<br>
> +<br>
> +     while((cairo_image_surface_ge<wbr>t_width(source) / 2.0f) > width)<br>
> +             source = scale_surface(source, filter,<br>
> +                     cairo_image_surface_get_<wbr>width(source) / 2.0f,<br>
> +                     cairo_image_surface_get_heigh<wbr>t(source));<br>
> +<br>
> +     while((cairo_image_surface_ge<wbr>t_height(source) / 2.0f) > height)<br>
> +             source = scale_surface(source, filter,<br>
> +                     cairo_image_surface_get_<wbr>width(source),<br>
> +                     cairo_image_surface_get_heigh<wbr>t(source) / 2.0f);<br>
> +<br>
> +     while((cairo_image_surface_ge<wbr>t_width(source) * 2.0f) < width)<br>
> +             source = scale_surface(source, filter,<br>
> +                     cairo_image_surface_get_<wbr>width(source) * 2.0f,<br>
> +                     cairo_image_surface_get_heigh<wbr>t(source));<br>
> +<br>
> +     while((cairo_image_surface_ge<wbr>t_height(source) * 2.0f) < height)<br>
> +             source = scale_surface(source, filter,<br>
> +                     cairo_image_surface_get_<wbr>width(source),<br>
> +                     cairo_image_surface_get_heigh<wbr>t(source) * 2.0f);<br>
> +<br>
> +     return scale_surface(source, filter, width, height);<br>
> +}<br>
> +<br>
>  void<br>
>  theme_set_background_source(st<wbr>ruct theme *t, cairo_t *cr, uint32_t flags)<br>
>  {<br>
> diff --git a/shared/cairo-util.h b/shared/cairo-util.h<br>
> index 6fd11f6..1c58f3b 100644<br>
> --- a/shared/cairo-util.h<br>
> +++ b/shared/cairo-util.h<br>
> @@ -49,6 +49,10 @@ rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius);<br>
>  cairo_surface_t *<br>
>  load_cairo_surface(const char *filename);<br>
><br>
> +cairo_surface_t *<br>
> +resize_cairo_surface(cairo_su<wbr>rface_t *source, cairo_filter_t filter,<br>
> +                                             int width, int height);<br>
> +<br>
>  struct theme {<br>
>       cairo_surface_t *active_frame;<br>
>       cairo_surface_t *inactive_frame;<br>
> diff --git a/xwayland/window-manager.c b/xwayland/window-manager.c<br>
> index 5fb41bf..50c5855 100644<br>
> --- a/xwayland/window-manager.c<br>
> +++ b/xwayland/window-manager.c<br>
> @@ -1463,6 +1463,10 @@ weston_wm_handle_icon(struct weston_wm *wm, struct weston_wm_window *window)<br>
>               return;<br>
>       }<br>
><br>
> +     if (width != XWM_ICON_SIZE || height != XWM_ICON_SIZE)<br>
> +             new_surface = resize_cairo_surface(new_surfa<wbr>ce, 0,<br>
> +                                     XWM_ICON_SIZE, XWM_ICON_SIZE);<br>
> +<br>
>       if (window->frame)<br>
>               frame_set_icon(window->frame, new_surface);<br>
>       else /* We don’t have a frame yet */<br>
><br>
<br>
</div></div></blockquote></div><br></div></div>