[gtk+/wip/window-scales: 9/16] gdkwindow: Respect cairo surfaces with device scale



commit c2de32d315b53775e5d7ce9a405d4cd27be10847
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Jun 4 10:41:44 2013 +0200

    gdkwindow: Respect cairo surfaces with device scale
    
    If a cairo_surface for a window has a device scale set we need
    to respect this when creating a similar window. I.e. we want
    to then automatically create a larger window which inherits
    the scale from the original.
    
    We also need to calculate a different device_offset if there
    is a device_scale set.

 gdk/gdkwindow.c |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 6e4f4bc..426b9f4 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -2756,6 +2756,7 @@ gdk_window_begin_paint_region (GdkWindow       *window,
   GdkWindowImplClass *impl_class;
   GdkWindowPaint *paint;
   GSList *list;
+  double sx, sy;
   gboolean needs_surface;
 
   g_return_if_fail (GDK_IS_WINDOW (window));
@@ -2782,7 +2783,11 @@ gdk_window_begin_paint_region (GdkWindow       *window,
                                                          gdk_window_get_content (window),
                                                          MAX (clip_box.width, 1),
                                                          MAX (clip_box.height, 1));
-      cairo_surface_set_device_offset (paint->surface, -clip_box.x, -clip_box.y);
+      sx = sy = 1;
+#ifdef HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE
+      cairo_surface_get_device_scale (paint->surface, &sx, &sy);
+#endif
+      cairo_surface_set_device_offset (paint->surface, -clip_box.x*sx, -clip_box.y*sy);
     }
 
   for (list = window->paint_stack; list != NULL; list = list->next)
@@ -9177,10 +9182,18 @@ gdk_window_create_similar_surface (GdkWindow *     window,
                                    int             height)
 {
   cairo_surface_t *window_surface, *surface;
+  double sx, sy;
 
   g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
-  
+
   window_surface = gdk_window_ref_impl_surface (window);
+  sx = sy = 1;
+#ifdef HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE
+  cairo_surface_get_device_scale (window_surface, &sx, &sy);
+#endif
+
+  width = width * sx;
+  height = height * sy;
 
   switch (_gdk_rendering_mode)
   {
@@ -9203,6 +9216,10 @@ gdk_window_create_similar_surface (GdkWindow *     window,
       break;
   }
 
+#ifdef HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE
+  cairo_surface_set_device_scale (surface, sx, sy);
+#endif
+
   cairo_surface_destroy (window_surface);
 
   _gdk_cairo_surface_set_window (surface, window);


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