git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

scenefx/include/render/egl.h (3.4K)

  1 #ifndef RENDER_EGL_H
  2 #define RENDER_EGL_H
  3 
  4 #include <wlr/render/egl.h>
  5 
  6 struct wlr_egl {
  7 	EGLDisplay display;
  8 	EGLContext context;
  9 	EGLDeviceEXT device; // may be EGL_NO_DEVICE_EXT
 10 	struct gbm_device *gbm_device;
 11 
 12 	struct {
 13 		// Display extensions
 14 		bool KHR_image_base;
 15 		bool EXT_image_dma_buf_import;
 16 		bool EXT_image_dma_buf_import_modifiers;
 17 		bool IMG_context_priority;
 18 		bool EXT_create_context_robustness;
 19 
 20 		// Device extensions
 21 		bool EXT_device_drm;
 22 		bool EXT_device_drm_render_node;
 23 
 24 		// Client extensions
 25 		bool EXT_device_query;
 26 		bool KHR_platform_gbm;
 27 		bool EXT_platform_device;
 28 		bool KHR_display_reference;
 29 	} exts;
 30 
 31 	struct {
 32 		PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT;
 33 		PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
 34 		PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
 35 		PFNEGLQUERYDMABUFFORMATSEXTPROC eglQueryDmaBufFormatsEXT;
 36 		PFNEGLQUERYDMABUFMODIFIERSEXTPROC eglQueryDmaBufModifiersEXT;
 37 		PFNEGLDEBUGMESSAGECONTROLKHRPROC eglDebugMessageControlKHR;
 38 		PFNEGLQUERYDISPLAYATTRIBEXTPROC eglQueryDisplayAttribEXT;
 39 		PFNEGLQUERYDEVICESTRINGEXTPROC eglQueryDeviceStringEXT;
 40 		PFNEGLQUERYDEVICESEXTPROC eglQueryDevicesEXT;
 41 		PFNEGLCREATESYNCKHRPROC eglCreateSyncKHR;
 42 		PFNEGLDESTROYSYNCKHRPROC eglDestroySyncKHR;
 43 		PFNEGLDUPNATIVEFENCEFDANDROIDPROC eglDupNativeFenceFDANDROID;
 44 		PFNEGLWAITSYNCKHRPROC eglWaitSyncKHR;
 45 	} procs;
 46 
 47 	bool has_modifiers;
 48 	struct wlr_drm_format_set dmabuf_texture_formats;
 49 	struct wlr_drm_format_set dmabuf_render_formats;
 50 };
 51 
 52 struct wlr_egl_context {
 53 	EGLDisplay display;
 54 	EGLContext context;
 55 	EGLSurface draw_surface;
 56 	EGLSurface read_surface;
 57 };
 58 
 59 /**
 60  * Initializes an EGL context for the given DRM FD.
 61  *
 62  * Will attempt to load all possibly required API functions.
 63  */
 64 struct wlr_egl *wlr_egl_create_with_drm_fd(int drm_fd);
 65 
 66 /**
 67  * Frees all related EGL resources, makes the context not-current and
 68  * unbinds a bound wayland display.
 69  */
 70 void wlr_egl_destroy(struct wlr_egl *egl);
 71 
 72 /**
 73  * Creates an EGL image from the given dmabuf attributes. Check usability
 74  * of the dmabuf with wlr_egl_check_import_dmabuf once first.
 75  */
 76 EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
 77 	struct wlr_dmabuf_attributes *attributes, bool *external_only);
 78 
 79 /**
 80  * Get DMA-BUF formats suitable for sampling usage.
 81  */
 82 const struct wlr_drm_format_set *wlr_egl_get_dmabuf_texture_formats(
 83 	struct wlr_egl *egl);
 84 /**
 85  * Get DMA-BUF formats suitable for rendering usage.
 86  */
 87 const struct wlr_drm_format_set *wlr_egl_get_dmabuf_render_formats(
 88 	struct wlr_egl *egl);
 89 
 90 /**
 91  * Destroys an EGL image created with the given wlr_egl.
 92  */
 93 bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImageKHR image);
 94 
 95 int wlr_egl_dup_drm_fd(struct wlr_egl *egl);
 96 
 97 /**
 98  * Restore EGL context that was previously saved using wlr_egl_save_current().
 99  */
100 bool wlr_egl_restore_context(struct wlr_egl_context *context);
101 
102 /**
103  * Make the EGL context current.
104  *
105  * The old EGL context is saved. Callers are expected to clear the current
106  * context when they are done by calling wlr_egl_restore_context().
107  */
108 bool wlr_egl_make_current(struct wlr_egl *egl, struct wlr_egl_context *save_context);
109 
110 bool wlr_egl_unset_current(struct wlr_egl *egl);
111 
112 EGLSyncKHR wlr_egl_create_sync(struct wlr_egl *egl, int fence_fd);
113 
114 void wlr_egl_destroy_sync(struct wlr_egl *egl, EGLSyncKHR sync);
115 
116 int wlr_egl_dup_fence_fd(struct wlr_egl *egl, EGLSyncKHR sync);
117 
118 bool wlr_egl_wait_sync(struct wlr_egl *egl, EGLSyncKHR sync);
119 
120 #endif