mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-11-03 09:01:40 -05:00 
			
		
		
		
	render/gles2: make wlr_gles2_texture a wlr_buffer addon
This commit is contained in:
		
							parent
							
								
									ee1156b62b
								
							
						
					
					
						commit
						ad7651a370
					
				
					 2 changed files with 24 additions and 20 deletions
				
			
		| 
						 | 
					@ -108,8 +108,7 @@ struct wlr_gles2_texture {
 | 
				
			||||||
	uint32_t drm_format; // used to interpret upload data
 | 
						uint32_t drm_format; // used to interpret upload data
 | 
				
			||||||
	// If imported from a wlr_buffer
 | 
						// If imported from a wlr_buffer
 | 
				
			||||||
	struct wlr_buffer *buffer;
 | 
						struct wlr_buffer *buffer;
 | 
				
			||||||
 | 
						struct wlr_addon buffer_addon;
 | 
				
			||||||
	struct wl_listener buffer_destroy;
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -129,7 +129,9 @@ static bool gles2_texture_invalidate(struct wlr_gles2_texture *texture) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void gles2_texture_destroy(struct wlr_gles2_texture *texture) {
 | 
					void gles2_texture_destroy(struct wlr_gles2_texture *texture) {
 | 
				
			||||||
	wl_list_remove(&texture->link);
 | 
						wl_list_remove(&texture->link);
 | 
				
			||||||
	wl_list_remove(&texture->buffer_destroy.link);
 | 
						if (texture->buffer != NULL) {
 | 
				
			||||||
 | 
							wlr_addon_finish(&texture->buffer_addon);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct wlr_egl_context prev_ctx;
 | 
						struct wlr_egl_context prev_ctx;
 | 
				
			||||||
	wlr_egl_save_context(&prev_ctx);
 | 
						wlr_egl_save_context(&prev_ctx);
 | 
				
			||||||
| 
						 | 
					@ -175,7 +177,6 @@ static struct wlr_gles2_texture *gles2_texture_create(
 | 
				
			||||||
	wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height);
 | 
						wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height);
 | 
				
			||||||
	texture->renderer = renderer;
 | 
						texture->renderer = renderer;
 | 
				
			||||||
	wl_list_insert(&renderer->textures, &texture->link);
 | 
						wl_list_insert(&renderer->textures, &texture->link);
 | 
				
			||||||
	wl_list_init(&texture->buffer_destroy.link);
 | 
					 | 
				
			||||||
	return texture;
 | 
						return texture;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -294,26 +295,31 @@ static struct wlr_texture *gles2_texture_from_dmabuf(
 | 
				
			||||||
	return &texture->wlr_texture;
 | 
						return &texture->wlr_texture;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void texture_handle_buffer_destroy(struct wl_listener *listener,
 | 
					static void texture_handle_buffer_destroy(struct wlr_addon *addon) {
 | 
				
			||||||
		void *data) {
 | 
					 | 
				
			||||||
	struct wlr_gles2_texture *texture =
 | 
						struct wlr_gles2_texture *texture =
 | 
				
			||||||
		wl_container_of(listener, texture, buffer_destroy);
 | 
							wl_container_of(addon, texture, buffer_addon);
 | 
				
			||||||
	gles2_texture_destroy(texture);
 | 
						gles2_texture_destroy(texture);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const struct wlr_addon_interface texture_addon_impl = {
 | 
				
			||||||
 | 
						.name = "wlr_gles2_texture",
 | 
				
			||||||
 | 
						.destroy = texture_handle_buffer_destroy,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct wlr_texture *gles2_texture_from_dmabuf_buffer(
 | 
					static struct wlr_texture *gles2_texture_from_dmabuf_buffer(
 | 
				
			||||||
		struct wlr_gles2_renderer *renderer, struct wlr_buffer *buffer,
 | 
							struct wlr_gles2_renderer *renderer, struct wlr_buffer *buffer,
 | 
				
			||||||
		struct wlr_dmabuf_attributes *dmabuf) {
 | 
							struct wlr_dmabuf_attributes *dmabuf) {
 | 
				
			||||||
	struct wlr_gles2_texture *texture;
 | 
						struct wlr_addon *addon =
 | 
				
			||||||
	wl_list_for_each(texture, &renderer->textures, link) {
 | 
							wlr_addon_find(&buffer->addons, renderer, &texture_addon_impl);
 | 
				
			||||||
		if (texture->buffer == buffer) {
 | 
						if (addon != NULL) {
 | 
				
			||||||
			if (!gles2_texture_invalidate(texture)) {
 | 
							struct wlr_gles2_texture *texture =
 | 
				
			||||||
				wlr_log(WLR_ERROR, "Failed to invalidate texture");
 | 
								wl_container_of(addon, texture, buffer_addon);
 | 
				
			||||||
				return false;
 | 
							if (!gles2_texture_invalidate(texture)) {
 | 
				
			||||||
			}
 | 
								wlr_log(WLR_ERROR, "Failed to invalidate texture");
 | 
				
			||||||
			wlr_buffer_lock(texture->buffer);
 | 
								return false;
 | 
				
			||||||
			return &texture->wlr_texture;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							wlr_buffer_lock(texture->buffer);
 | 
				
			||||||
 | 
							return &texture->wlr_texture;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct wlr_texture *wlr_texture =
 | 
						struct wlr_texture *wlr_texture =
 | 
				
			||||||
| 
						 | 
					@ -322,11 +328,10 @@ static struct wlr_texture *gles2_texture_from_dmabuf_buffer(
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	texture = gles2_get_texture(wlr_texture);
 | 
						struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
 | 
				
			||||||
	texture->buffer = wlr_buffer_lock(buffer);
 | 
						texture->buffer = wlr_buffer_lock(buffer);
 | 
				
			||||||
 | 
						wlr_addon_init(&texture->buffer_addon, &buffer->addons,
 | 
				
			||||||
	texture->buffer_destroy.notify = texture_handle_buffer_destroy;
 | 
							renderer, &texture_addon_impl);
 | 
				
			||||||
	wl_signal_add(&buffer->events.destroy, &texture->buffer_destroy);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &texture->wlr_texture;
 | 
						return &texture->wlr_texture;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue