Need a simpler method to get a GdkTexture from a cairo_surface_t

Hi,

I’m trying to port Evince to gtk4 and I encountered an issue. The recent view widget of Evince is just a GtkIconView drawing previews (cairo_surface_t) of PDF thumnails. Since the old surface property is dropped for GtkCellRendererPixbuf in Gtk4, the only viable way to draw cairo_surface_t is the texture property which requires a GtkTexture. I know there is a gdk_memory_texture_new function to construct such GdkTexture. But there is also a private function named gdk_texture_new_for_surface. So what is the reason to keep this function private to gtk? Is there any simpler way to turn a cairo_surface_t into a GtkTexture?

Thanks

Ideally, the GTK4 port should drop the IconView and instead use a GridView with cells containing a preview widget that would draw the contents of the surface; so having that API as a public function would not really save you much, except as a stepping stone.

The reason we don’t expose that function is twofold:

  1. It requires a lot of invariants on the cairo surface - image surface, no device scale, no device offset - and those are complex to document and even more complex to reliably check

  2. It’s small, so you can just copy/paste it. And then you can adapt it to the invariants your code satisfies.

So the recommended solution is indeed for everybody to copy gdk_texture_new_for_surface() into their code - it’s why GDK_MEMORY_DEFAULT exists after all.

2 Likes

As @ebassi said, it is better to adjust the Recent View. Still there are plenty of other places where cairo is used.

Out of curiosity, where is the branch you are working on?

@otte Actually that is my current workaround. And it works as my expect.
@gpoo That is totally a mess. I’m not ready to push it to a public branch. But I have ported almost every widget except EvView. There is still a lot of work to do such as event controller and widget style.

This is the working branch of my GTK4 port of Evince.

https://gitlab.gnome.org/crab2313/evince/-/commits/gtk4-port-target/

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.