[libgd/wip/rishi/main-box: 1/11] icon-utils, main-view: Export the image surface copying code



commit bd9bfa58142b7ed7b7b46702f98d28f3d3376e0c
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Dec 21 07:54:17 2016 +0100

    icon-utils, main-view: Export the image surface copying code
    
    We will also need it for GdMainIconBox, so it is better to share the
    same code.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774914

 libgd.m4              |    1 +
 libgd/gd-icon-utils.c |   30 +++++++++++++++++++++++++++++-
 libgd/gd-icon-utils.h |    5 ++++-
 libgd/gd-main-view.c  |   25 ++-----------------------
 4 files changed, 36 insertions(+), 25 deletions(-)
---
diff --git a/libgd.m4 b/libgd.m4
index 2ce3571..90b2080 100644
--- a/libgd.m4
+++ b/libgd.m4
@@ -55,6 +55,7 @@ AC_DEFUN([LIBGD_INIT], [
     _LIBGD_IF_OPTION_SET([main-view],[
         _LIBGD_SET_OPTION([main-icon-view])
         _LIBGD_SET_OPTION([main-list-view])
+        _LIBGD_SET_OPTION([gtk-hacks])
         AC_DEFINE([LIBGD_MAIN_VIEW], [1], [Description])
     ])
 
diff --git a/libgd/gd-icon-utils.c b/libgd/gd-icon-utils.c
index d68f89d..3d83ba4 100644
--- a/libgd/gd-icon-utils.c
+++ b/libgd/gd-icon-utils.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, 2015 Red Hat, Inc.
+ * Copyright (c) 2011, 2012, 2015, 2016 Red Hat, Inc.
  *
  * Gnome Documents is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by the
@@ -29,6 +29,34 @@
 #define _EMBLEM_MIN_SIZE 8
 
 /**
+ * gd_copy_image_surface:
+ * @surface:
+ *
+ * Returns: (transfer full):
+ */
+cairo_surface_t *
+gd_copy_image_surface (cairo_surface_t *surface)
+{
+  cairo_surface_t *copy = NULL;
+  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);
+
+  cr = cairo_create (copy);
+  cairo_set_source_surface (cr, surface, 0, 0);
+  cairo_paint (cr);
+  cairo_destroy (cr);
+
+  return copy;
+}
+
+/**
  * gd_create_symbolic_icon_for_scale:
  * @name:
  * @base_size:
diff --git a/libgd/gd-icon-utils.h b/libgd/gd-icon-utils.h
index 63f96da..46cea28 100644
--- a/libgd/gd-icon-utils.h
+++ b/libgd/gd-icon-utils.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, 2015 Red Hat, Inc.
+ * Copyright (c) 2011, 2012, 2015, 2016 Red Hat, Inc.
  *
  * Gnome Documents is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by the
@@ -22,8 +22,11 @@
 #ifndef __GD_CREATE_SYMBOLIC_ICON_H__
 #define __GD_CREATE_SYMBOLIC_ICON_H__
 
+#include <cairo.h>
 #include <gtk/gtk.h>
 
+cairo_surface_t *gd_copy_image_surface (cairo_surface_t *surface);
+
 GIcon *gd_create_symbolic_icon (const gchar *name,
                                 gint base_size);
 GIcon *gd_create_symbolic_icon_for_scale (const gchar *name,
diff --git a/libgd/gd-main-view.c b/libgd/gd-main-view.c
index c4fa561..897c7fc 100644
--- a/libgd/gd-main-view.c
+++ b/libgd/gd-main-view.c
@@ -21,6 +21,7 @@
 
 #include "gd-main-view.h"
 
+#include "gd-icon-utils.h"
 #include "gd-main-view-generic.h"
 #include "gd-main-icon-view.h"
 #include "gd-main-list-view.h"
@@ -872,28 +873,6 @@ on_motion_event (GtkWidget      *widget,
   return FALSE;
 }
 
-static cairo_surface_t *
-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);
-
-  cr = cairo_create (copy);
-  cairo_set_source_surface (cr, surface, 0, 0);
-  cairo_paint (cr);
-  cairo_destroy (cr);
-
-  return copy;
-}
-
 static void
 on_drag_begin (GdMainViewGeneric *generic,
                GdkDragContext *drag_context,
@@ -926,7 +905,7 @@ on_drag_begin (GdMainViewGeneric *generic,
 
       if (column_gtype == CAIRO_GOBJECT_TYPE_SURFACE)
         {
-          surface = copy_surface (data);
+          surface = gd_copy_image_surface (data);
           cairo_surface_destroy (data);
         }
       else if (column_gtype == GDK_TYPE_PIXBUF)


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