[libgd] main-view: Don't let the Cairo surface get bigger while copying



commit 3ed74952612a5e6dbde3f5785b40141fae760c60
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Dec 15 13:46:59 2016 +0100

    main-view: Don't let the Cairo surface get bigger while copying
    
    The cairo_surface_create_similar API expects the width and height to be
    in device-space units, not pixels. So either we need to scale down the
    outputs of cairo_image_surface_get_{width, height}, or we need to use
    cairo_surface_create_similar_image. I prefer the latter because we are
    already using other image surface API and pixel values.
    
    Note that unlike cairo_surface_create_similar, we need to manually set
    the device scale because cairo_surface_create_similar_image doesn't
    inherit it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=776133

 libgd/gd-main-view.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/libgd/gd-main-view.c b/libgd/gd-main-view.c
index 7aca51a..0e3688f 100644
--- a/libgd/gd-main-view.c
+++ b/libgd/gd-main-view.c
@@ -860,10 +860,15 @@ copy_surface (cairo_surface_t *surface)
 {
   cairo_surface_t *copy;
   cairo_t *cr;
+  gdouble scale_x;
+  gdouble scale_y;
+
+  copy = cairo_surface_create_similar_image (surface, CAIRO_FORMAT_ARGB32,
+                                             cairo_image_surface_get_width (surface),
+                                             cairo_image_surface_get_height (surface));
+  cairo_surface_get_device_scale (surface, &scale_x, &scale_y);
+  cairo_surface_set_device_scale (copy, scale_x, scale_y);
 
-  copy = cairo_surface_create_similar (surface, CAIRO_CONTENT_COLOR_ALPHA,
-                                       cairo_image_surface_get_width (surface),
-                                       cairo_image_surface_get_height (surface));
   cr = cairo_create (copy);
   cairo_set_source_surface (cr, surface, 0, 0);
   cairo_paint (cr);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]