From 6c04eba8c6d00db17866d929c462b496cd6904e7 Mon Sep 17 00:00:00 2001 From: "Pierre-Loup A. Griffais" Date: Sun, 3 Nov 2019 15:27:38 -0800 Subject: [PATCH] Allow re-import, still consume FDs that fall through the crack. Lets glxgears animate at 60fps and doesn't leak FDs anymore. steamcompmgr still goes down when glxgears exits. --- src/steamcompmgr.c | 14 ++++++++++++-- src/xwayland.c | 10 +++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/steamcompmgr.c b/src/steamcompmgr.c index e9a2ef6..ea830c9 100644 --- a/src/steamcompmgr.c +++ b/src/steamcompmgr.c @@ -333,7 +333,7 @@ teardown_win_resources (Display *dpy, win *w) if (!w) return; - if (w->eglImage) + if (w->eglImage != EGL_NO_IMAGE_KHR) { glBindTexture( GL_TEXTURE_2D, 0 ); glDeleteTextures( 1, &w->texName ); @@ -353,7 +353,7 @@ ensure_win_resources (Display *dpy, win *w) if (!w) return; - if (!w->eglImage && w->dmabuf_attribs_valid == True) + if (w->dmabuf_attribs_valid == True) { teardown_win_resources( dpy, w ); @@ -370,10 +370,15 @@ ensure_win_resources (Display *dpy, win *w) w->eglImage = __pointer_to_eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr); + close(w->dmabuf_attribs.fd[0]); + glGenTextures( 1, &w->texName ); glBindTexture (GL_TEXTURE_2D, w->texName); glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, w->eglImage); + // Only consume once + w->dmabuf_attribs_valid = False; + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -1677,6 +1682,11 @@ void check_new_wayland_res(void) { if (w->xwl_surface == newEntry.surf) { + if ( w->dmabuf_attribs_valid == True ) + { + // Existing data here hasn't been consumed - need to consume the dma-buf fd + close(w->dmabuf_attribs.fd[0]); + } w->dmabuf_attribs = newEntry.attribs; w->dmabuf_attribs_valid = True; bFound = True; diff --git a/src/xwayland.c b/src/xwayland.c index 4e8957d..b1ec7c8 100644 --- a/src/xwayland.c +++ b/src/xwayland.c @@ -370,10 +370,18 @@ static void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) { surface->mapped = true; } +// wlr_buffer_ref( surface->surface->buffer ); + struct wlr_texture *tex = wlr_surface_get_texture( wlr_surface ); struct wlr_dmabuf_attributes dmabuf_attribs = {}; - wlr_texture_to_dmabuf( tex, &dmabuf_attribs ); + bool result = False; + result = wlr_texture_to_dmabuf( tex, &dmabuf_attribs ); + + if (result == False) + { + // + } wayland_PushSurface( surface, &dmabuf_attribs ); }