After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 736046 - GdMainView DnD code doesn't handle cairo_surface_t objects from the model
GdMainView DnD code doesn't handle cairo_surface_t objects from the model
Status: RESOLVED FIXED
Product: libgd
Classification: Platform
Component: general
unspecified
Other Mac OS
: Normal normal
: ---
Assigned To: libgd maintainer(s)
libgd maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2014-09-04 12:13 UTC by Carlos Garnacho
Modified: 2014-09-04 21:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
main-view: Handle cairo_surface_t icons during DnD (2.14 KB, patch)
2014-09-04 12:14 UTC, Carlos Garnacho
needs-work Details | Review
main-view: Use cairo surfaces as DnD icon (7.03 KB, patch)
2014-09-04 19:46 UTC, Carlos Garnacho
none Details | Review
main-view: Use cairo surfaces as DnD icon (6.92 KB, patch)
2014-09-04 19:49 UTC, Carlos Garnacho
needs-work Details | Review
main-view: Use cairo surfaces as DnD icon (6.42 KB, patch)
2014-09-04 20:45 UTC, Carlos Garnacho
committed Details | Review

Description Carlos Garnacho 2014-09-04 12:13:25 UTC
When trying to drag something in gnome-documents, I see GDK_IS_PIXBUF warnings and a crash. From what I've seen the model can now hold either GdkPixbufs or cairo_surface_t objects, but the DnD didn't seem to be updated to handle that.

I'm attaching a patch to make cairo_surface_t objects fine to create a DnD icon.
Comment 1 Carlos Garnacho 2014-09-04 12:14:03 UTC
Created attachment 285358 [details] [review]
main-view: Handle cairo_surface_t icons during DnD

A GdkPixbuf was being assumed, but the model can now hold cairo_surface_t
objects too, so check for the model GType before creating the DnD icon.
Comment 2 Cosimo Cecchi 2014-09-04 17:26:26 UTC
Review of attachment 285358 [details] [review]:

::: libgd/gd-main-view.c
@@ +857,3 @@
+        icon = GDK_PIXBUF (data);
+      else if (column_gtype == CAIRO_GOBJECT_TYPE_SURFACE)
+        icon = gdk_pixbuf_get_from_surface (data, 0, 0,

A nice cleanup would be to always use gtk_drag_set_icon_surface(), but for that you would need to change also gd_main_view_get_counter_icon() which is probably a little bit of work - so it's fine if you want to leave it this way.

You should call cairo_surface_destroy() on the surface in this case though, or we'll leak a surface reference.
Comment 3 Carlos Garnacho 2014-09-04 19:46:08 UTC
(In reply to comment #2)
> Review of attachment 285358 [details] [review]:
> 
> ::: libgd/gd-main-view.c
> @@ +857,3 @@
> +        icon = GDK_PIXBUF (data);
> +      else if (column_gtype == CAIRO_GOBJECT_TYPE_SURFACE)
> +        icon = gdk_pixbuf_get_from_surface (data, 0, 0,
> 
> A nice cleanup would be to always use gtk_drag_set_icon_surface(), but for that
> you would need to change also gd_main_view_get_counter_icon() which is probably
> a little bit of work - so it's fine if you want to leave it this way.

I did that patch, one thing I don't like much of it is that in multiple selection, you end up creating a cairo surface twice, one as a copy of the treemodel data, and another with the emblem composed. Using a copy is a must if you want to do cairo_surface_set_device_offset() so the drag icon appears displaced and you don't modify the treemodel/cellrenderer surface too.

Optimizing that to just create a single copy in the process with GdkPixbuf in between was making it growingly unreadable, and copying a few tenths of pixels across image once during DnD isn't much of a performance concern, so I kept it as it is.

> 
> You should call cairo_surface_destroy() on the surface in this case though, or
> we'll leak a surface reference.

Oops, I indeed was, the new patch shouldn't leak.
Comment 4 Carlos Garnacho 2014-09-04 19:46:39 UTC
Created attachment 285407 [details] [review]
main-view: Use cairo surfaces as DnD icon

Now all DnD icons are dealt with as cairo_surface_t, if pixbufs are used
in the data model, a cairo surface is created out of it first.
Comment 5 Carlos Garnacho 2014-09-04 19:49:40 UTC
Created attachment 285408 [details] [review]
main-view: Use cairo surfaces as DnD icon

Now all DnD icons are dealt with as cairo_surface_t, if pixbufs are used
in the data model, a cairo surface is created out of it first.
Comment 6 Cosimo Cecchi 2014-09-04 20:24:13 UTC
Review of attachment 285408 [details] [review]:

::: libgd/gd-main-view.c
@@ +838,3 @@
+
+static cairo_surface_t *
+                                       cairo_image_surface_get_height (surface));

You should use gdk_cairo_surface_create_from_pixbuf() here instead of a custom function

@@ +916,2 @@
         {
+          cairo_surface_write_to_png (surface, "/home/carlos/foo.png");

Whoops :-)
Comment 7 Carlos Garnacho 2014-09-04 20:44:41 UTC
(In reply to comment #6)
> Review of attachment 285408 [details] [review]:
> 
> ::: libgd/gd-main-view.c
> @@ +838,3 @@
> +
> +static cairo_surface_t *
> +                                       cairo_image_surface_get_height
> (surface));
> 
> You should use gdk_cairo_surface_create_from_pixbuf() here instead of a custom
> function

I somehow missed that one, useful indeed.

> 
> @@ +916,2 @@
>          {
> +          cairo_surface_write_to_png (surface, "/home/carlos/foo.png");
> 
> Whoops :-)

Doh! Never mistake cairo_format_t with cairo_content_t, and never leave the traces :)
Comment 8 Carlos Garnacho 2014-09-04 20:45:41 UTC
Created attachment 285413 [details] [review]
main-view: Use cairo surfaces as DnD icon

Now all DnD icons are dealt with as cairo_surface_t, if pixbufs are used
in the data model, a cairo surface is created out of it first.
Comment 9 Cosimo Cecchi 2014-09-04 20:56:37 UTC
Review of attachment 285413 [details] [review]:

Thanks, Carlos!
Comment 10 Carlos Garnacho 2014-09-04 21:18:39 UTC
Attachment 285413 [details] pushed as 04b2480 - main-view: Use cairo surfaces as DnD icon