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?
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:
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
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.
@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.