mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-11-03 09:01:40 -05:00 
			
		
		
		
	render/egl: replace wlr_egl_create with wlr_egl_create_with_drm_fd
We never create an EGL context with the platform set to something other than EGL_PLATFORM_GBM_KHR. Let's simplify wlr_egl_create by taking a DRM FD instead of a (platform, remote_display) tuple. This hides the internal details of creating an EGL context for a specific device. This will allow us to transparently use the device platform [1] when the time comes. [1]: https://github.com/swaywm/wlroots/pull/2671
This commit is contained in:
		
							parent
							
								
									1c4b5bcab3
								
							
						
					
					
						commit
						1db976cecb
					
				
					 3 changed files with 17 additions and 21 deletions
				
			
		| 
						 | 
				
			
			@ -11,10 +11,11 @@ struct wlr_egl_context {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Initializes an EGL context for the given platform and remote display.
 | 
			
		||||
 * Will attempt to load all possibly required api functions.
 | 
			
		||||
 * Initializes an EGL context for the given DRM FD.
 | 
			
		||||
 *
 | 
			
		||||
 * Will attempt to load all possibly required API functions.
 | 
			
		||||
 */
 | 
			
		||||
struct wlr_egl *wlr_egl_create(EGLenum platform, void *remote_display);
 | 
			
		||||
struct wlr_egl *wlr_egl_create_with_drm_fd(int drm_fd);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Frees all related EGL resources, makes the context not-current and
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										14
									
								
								render/egl.c
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								render/egl.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -156,7 +156,7 @@ out:
 | 
			
		|||
	free(formats);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct wlr_egl *wlr_egl_create(EGLenum platform, void *remote_display) {
 | 
			
		||||
struct wlr_egl *wlr_egl_create_with_drm_fd(int drm_fd) {
 | 
			
		||||
	struct wlr_egl *egl = calloc(1, sizeof(struct wlr_egl));
 | 
			
		||||
	if (egl == NULL) {
 | 
			
		||||
		wlr_log_errno(WLR_ERROR, "Allocation failed");
 | 
			
		||||
| 
						 | 
				
			
			@ -173,12 +173,10 @@ struct wlr_egl *wlr_egl_create(EGLenum platform, void *remote_display) {
 | 
			
		|||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (platform == EGL_PLATFORM_GBM_KHR) {
 | 
			
		||||
	if (!check_egl_ext(client_exts_str, "EGL_KHR_platform_gbm")) {
 | 
			
		||||
		wlr_log(WLR_ERROR, "EGL_KHR_platform_gbm not supported");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!check_egl_ext(client_exts_str, "EGL_EXT_platform_base")) {
 | 
			
		||||
		wlr_log(WLR_ERROR, "EGL_EXT_platform_base not supported");
 | 
			
		||||
| 
						 | 
				
			
			@ -206,8 +204,14 @@ struct wlr_egl *wlr_egl_create(EGLenum platform, void *remote_display) {
 | 
			
		|||
		goto error;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	egl->display = egl->procs.eglGetPlatformDisplayEXT(platform,
 | 
			
		||||
		remote_display, NULL);
 | 
			
		||||
	egl->gbm_device = gbm_create_device(drm_fd);
 | 
			
		||||
	if (!egl->gbm_device) {
 | 
			
		||||
		wlr_log(WLR_ERROR, "Failed to create GBM device");
 | 
			
		||||
		goto error;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	egl->display = egl->procs.eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR,
 | 
			
		||||
		egl->gbm_device, NULL);
 | 
			
		||||
	if (egl->display == EGL_NO_DISPLAY) {
 | 
			
		||||
		wlr_log(WLR_ERROR, "Failed to create EGL display");
 | 
			
		||||
		goto error;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -733,21 +733,12 @@ extern const GLchar tex_fragment_src_rgbx[];
 | 
			
		|||
extern const GLchar tex_fragment_src_external[];
 | 
			
		||||
 | 
			
		||||
struct wlr_renderer *wlr_gles2_renderer_create_with_drm_fd(int drm_fd) {
 | 
			
		||||
	struct gbm_device *gbm_device = gbm_create_device(drm_fd);
 | 
			
		||||
	if (!gbm_device) {
 | 
			
		||||
		wlr_log(WLR_ERROR, "Failed to create GBM device");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	struct wlr_egl *egl = wlr_egl_create(EGL_PLATFORM_GBM_KHR, gbm_device);
 | 
			
		||||
	struct wlr_egl *egl = wlr_egl_create_with_drm_fd(drm_fd);
 | 
			
		||||
	if (egl == NULL) {
 | 
			
		||||
		wlr_log(WLR_ERROR, "Could not initialize EGL");
 | 
			
		||||
		gbm_device_destroy(gbm_device);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	egl->gbm_device = gbm_device;
 | 
			
		||||
 | 
			
		||||
	struct wlr_renderer *renderer = wlr_gles2_renderer_create(egl);
 | 
			
		||||
	if (!renderer) {
 | 
			
		||||
		wlr_log(WLR_ERROR, "Failed to create GLES2 renderer");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue