diff --git a/gdk/gdkdmabuf.c b/gdk/gdkdmabuf.c index 0c5af05db7..46b5006ae6 100644 --- a/gdk/gdkdmabuf.c +++ b/gdk/gdkdmabuf.c @@ -2372,3 +2372,20 @@ gdk_dmabuf_is_disjoint (const GdkDmabuf *dmabuf) } #endif /* HAVE_DMABUF */ + +void +gdk_dmabuf_close_fds (GdkDmabuf *dmabuf) +{ + guint i, j; + + for (i = 0; i < dmabuf->n_planes; i++) + { + for (j = 0; j < i; j++) + { + if (dmabuf->planes[i].fd == dmabuf->planes[j].fd) + break; + } + if (i == j) + g_close (dmabuf->planes[i].fd, NULL); + } +} diff --git a/gdk/gdkdmabufprivate.h b/gdk/gdkdmabufprivate.h index 914ee1f408..e3b2f01308 100644 --- a/gdk/gdkdmabufprivate.h +++ b/gdk/gdkdmabufprivate.h @@ -22,6 +22,8 @@ struct _GdkDmabuf } planes[GDK_DMABUF_MAX_PLANES]; }; +void gdk_dmabuf_close_fds (GdkDmabuf *dmabuf); + #ifdef HAVE_DMABUF GdkDmabufFormats * gdk_dmabuf_get_mmap_formats (void) G_GNUC_CONST; @@ -30,7 +32,6 @@ void gdk_dmabuf_download_mmap (GdkTexture guchar *data, gsize stride); - int gdk_dmabuf_ioctl (int fd, unsigned long request, void *arg); diff --git a/gtk/gtkglarea.c b/gtk/gtkglarea.c index 871e086ef0..95e3752436 100644 --- a/gtk/gtkglarea.c +++ b/gtk/gtkglarea.c @@ -727,15 +727,6 @@ release_gl_texture (gpointer data) texture->gl_texture = NULL; } -static void -release_dmabuf (const GdkDmabuf *dmabuf) -{ -#ifndef G_OS_WIN32 - for (unsigned int i = 0; i < dmabuf->n_planes; i++) - close (dmabuf->planes[i].fd); -#endif -} - static void release_dmabuf_texture (gpointer data) { @@ -746,7 +737,7 @@ release_dmabuf_texture (gpointer data) if (texture->dmabuf_texture == NULL) return; - release_dmabuf (gdk_dmabuf_texture_get_dmabuf (GDK_DMABUF_TEXTURE (texture->dmabuf_texture ))); + gdk_dmabuf_close_fds ((GdkDmabuf *) gdk_dmabuf_texture_get_dmabuf (GDK_DMABUF_TEXTURE (texture->dmabuf_texture))); texture->dmabuf_texture = NULL; } @@ -843,7 +834,7 @@ gtk_gl_area_snapshot (GtkWidget *widget, if (texture->dmabuf_texture != NULL) holder = texture->dmabuf_texture; else - release_dmabuf (&dmabuf); + gdk_dmabuf_close_fds (&dmabuf); } /* Our texture is rendered by OpenGL, so it is upside down,