mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-11-03 09:01:40 -05:00 
			
		
		
		
	buffer: don't destroy DMA-BUF textures with wl_buffer
After some discussions on #wayland, it seems that as soon as you hold a reference to a DMA-BUF (via EGLImage for instance), the underlying memory won't get free'd. The client is allowed to re-use the DMA-BUF and upload something else to it though.
This commit is contained in:
		
							parent
							
								
									73f924b5ec
								
							
						
					
					
						commit
						da114d5013
					
				
					 1 changed files with 10 additions and 5 deletions
				
			
		| 
						 | 
					@ -43,11 +43,12 @@ static void buffer_resource_handle_destroy(struct wl_listener *listener,
 | 
				
			||||||
	wl_list_init(&buffer->resource_destroy.link);
 | 
						wl_list_init(&buffer->resource_destroy.link);
 | 
				
			||||||
	buffer->resource = NULL;
 | 
						buffer->resource = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!buffer->released) {
 | 
						// At this point, if the wl_buffer comes from linux-dmabuf or wl_drm, we
 | 
				
			||||||
		// The texture becomes invalid
 | 
						// still haven't released it (ie. we'll read it in the future) but the
 | 
				
			||||||
		wlr_texture_destroy(buffer->texture);
 | 
						// client destroyed it. Reading the texture itself should be fine because
 | 
				
			||||||
		buffer->texture = NULL;
 | 
						// we still hold a reference to the DMA-BUF via the texture. However the
 | 
				
			||||||
	}
 | 
						// client could decide to re-use the same DMA-BUF for something else, in
 | 
				
			||||||
 | 
						// which case we'll read garbage. We decide to accept this risk.
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct wlr_buffer *wlr_buffer_create(struct wlr_renderer *renderer,
 | 
					struct wlr_buffer *wlr_buffer_create(struct wlr_renderer *renderer,
 | 
				
			||||||
| 
						 | 
					@ -80,6 +81,10 @@ struct wlr_buffer *wlr_buffer_create(struct wlr_renderer *renderer,
 | 
				
			||||||
		struct wlr_dmabuf_buffer *dmabuf =
 | 
							struct wlr_dmabuf_buffer *dmabuf =
 | 
				
			||||||
			wlr_dmabuf_buffer_from_buffer_resource(resource);
 | 
								wlr_dmabuf_buffer_from_buffer_resource(resource);
 | 
				
			||||||
		texture = wlr_texture_from_dmabuf(renderer, &dmabuf->attributes);
 | 
							texture = wlr_texture_from_dmabuf(renderer, &dmabuf->attributes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// We have imported the DMA-BUF, but we need to prevent the client from
 | 
				
			||||||
 | 
							// re-using the same DMA-BUF for the next frames, so we don't release
 | 
				
			||||||
 | 
							// the buffer yet.
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		wlr_log(L_ERROR, "Cannot upload texture: unknown buffer type");
 | 
							wlr_log(L_ERROR, "Cannot upload texture: unknown buffer type");
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue