From b6a990da71b5b0947650a50dcf1a083acfce868c Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Sat, 30 Dec 2023 12:45:04 +0100 Subject: Added fx_texture and fx_framebuffer --- include/render/egl.h | 117 +++++++++++++++++++++++++++++++ include/render/fx_renderer/fx_renderer.h | 99 ++++++++++++++++++++++++-- 2 files changed, 211 insertions(+), 5 deletions(-) create mode 100644 include/render/egl.h (limited to 'include/render') diff --git a/include/render/egl.h b/include/render/egl.h new file mode 100644 index 0000000..e8b8596 --- /dev/null +++ b/include/render/egl.h @@ -0,0 +1,117 @@ +#ifndef RENDER_EGL_H +#define RENDER_EGL_H + +#include + +struct wlr_egl { + EGLDisplay display; + EGLContext context; + EGLDeviceEXT device; // may be EGL_NO_DEVICE_EXT + struct gbm_device *gbm_device; + + struct { + // Display extensions + bool KHR_image_base; + bool EXT_image_dma_buf_import; + bool EXT_image_dma_buf_import_modifiers; + bool IMG_context_priority; + bool EXT_create_context_robustness; + + // Device extensions + bool EXT_device_drm; + bool EXT_device_drm_render_node; + + // Client extensions + bool EXT_device_query; + bool KHR_platform_gbm; + bool EXT_platform_device; + bool KHR_display_reference; + } exts; + + struct { + PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT; + PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; + PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; + PFNEGLQUERYDMABUFFORMATSEXTPROC eglQueryDmaBufFormatsEXT; + PFNEGLQUERYDMABUFMODIFIERSEXTPROC eglQueryDmaBufModifiersEXT; + PFNEGLDEBUGMESSAGECONTROLKHRPROC eglDebugMessageControlKHR; + PFNEGLQUERYDISPLAYATTRIBEXTPROC eglQueryDisplayAttribEXT; + PFNEGLQUERYDEVICESTRINGEXTPROC eglQueryDeviceStringEXT; + PFNEGLQUERYDEVICESEXTPROC eglQueryDevicesEXT; + } procs; + + bool has_modifiers; + struct wlr_drm_format_set dmabuf_texture_formats; + struct wlr_drm_format_set dmabuf_render_formats; +}; + +struct wlr_egl_context { + EGLDisplay display; + EGLContext context; + EGLSurface draw_surface; + EGLSurface read_surface; +}; + +/** + * Initializes an EGL context for the given DRM FD. + * + * Will attempt to load all possibly required API functions. + */ +struct wlr_egl *wlr_egl_create_with_drm_fd(int drm_fd); + +/** + * Frees all related EGL resources, makes the context not-current and + * unbinds a bound wayland display. + */ +void wlr_egl_destroy(struct wlr_egl *egl); + +/** + * Creates an EGL image from the given dmabuf attributes. Check usability + * of the dmabuf with wlr_egl_check_import_dmabuf once first. + */ +EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl, + struct wlr_dmabuf_attributes *attributes, bool *external_only); + +/** + * Get DMA-BUF formats suitable for sampling usage. + */ +const struct wlr_drm_format_set *wlr_egl_get_dmabuf_texture_formats( + struct wlr_egl *egl); +/** + * Get DMA-BUF formats suitable for rendering usage. + */ +const struct wlr_drm_format_set *wlr_egl_get_dmabuf_render_formats( + struct wlr_egl *egl); + +/** + * Destroys an EGL image created with the given wlr_egl. + */ +bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImageKHR image); + +int wlr_egl_dup_drm_fd(struct wlr_egl *egl); + +/** + * Save the current EGL context to the structure provided in the argument. + * + * This includes display, context, draw surface and read surface. + */ +void wlr_egl_save_context(struct wlr_egl_context *context); + +/** + * Restore EGL context that was previously saved using wlr_egl_save_current(). + */ +bool wlr_egl_restore_context(struct wlr_egl_context *context); + +/** + * Make the EGL context current. + * + * Callers are expected to clear the current context when they are done by + * calling wlr_egl_unset_current(). + */ +bool wlr_egl_make_current(struct wlr_egl *egl); + +bool wlr_egl_unset_current(struct wlr_egl *egl); + +bool wlr_egl_is_current(struct wlr_egl *egl); + +#endif diff --git a/include/render/fx_renderer/fx_renderer.h b/include/render/fx_renderer/fx_renderer.h index f569aa9..ffd31da 100644 --- a/include/render/fx_renderer/fx_renderer.h +++ b/include/render/fx_renderer/fx_renderer.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -57,19 +58,70 @@ struct box_shadow_shader { GLint corner_radius; }; +struct fx_framebuffer { + bool initialized; + + GLuint fbo; + GLuint rbo; + + struct wlr_buffer *wlr_buffer; + struct fx_renderer *renderer; + struct wl_list link; // fx_renderer.buffers + struct wlr_addon addon; + + EGLImageKHR image; +}; + +struct fx_texture { + struct wlr_texture wlr_texture; + struct fx_renderer *fx_renderer; + struct wl_list link; // fx_renderer.textures + + // Basically: + // GL_TEXTURE_2D == mutable + // GL_TEXTURE_EXTERNAL_OES == immutable + GLuint target; + GLuint tex; + + EGLImageKHR image; + + bool has_alpha; + + // Only affects target == GL_TEXTURE_2D + uint32_t drm_format; // used to interpret upload data + // If imported from a wlr_buffer + struct wlr_buffer *buffer; + struct wlr_addon buffer_addon; +}; + struct fx_renderer { float projection[9]; + int viewport_width, viewport_height; + + struct wlr_output *wlr_output; + + struct wlr_egl *egl; + struct fx_stencilbuffer stencil_buffer; + struct wl_list textures; // fx_texture.link + struct wl_list buffers; // fx_framebuffer.link + + // The FBO and texture used by wlroots + GLuint wlr_main_buffer_fbo; + struct wlr_gles2_texture_attribs wlr_main_texture_attribs; + struct wlr_addon addon; struct { bool OES_egl_image_external; + bool OES_egl_image; } exts; struct { PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; + PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES; } procs; struct { @@ -82,18 +134,55 @@ struct fx_renderer { } shaders; }; -void fx_renderer_init_addon(struct wlr_egl *egl, struct wlr_addon_set *addons, - const void * owner); +/// +/// fx_framebuffer +/// + +struct fx_framebuffer fx_framebuffer_create(void); + +void fx_framebuffer_bind(struct fx_framebuffer *buffer); + +void fx_framebuffer_bind_wlr_fbo(struct fx_renderer *renderer); + +void fx_framebuffer_update(struct fx_renderer *fx_renderer, struct fx_framebuffer *fx_buffer, + int width, int height); + +void fx_framebuffer_add_stencil_buffer(struct fx_framebuffer *buffer, int width, int height); + +void fx_framebuffer_release(struct fx_framebuffer *buffer); + +/// +/// fx_texture +/// + +struct fx_texture *fx_get_texture(struct wlr_texture *wlr_texture); + +struct fx_texture *fx_texture_from_buffer(struct fx_renderer *fx_renderer, + struct wlr_buffer *buffer); + +void fx_texture_destroy(struct fx_texture *texture); + +bool wlr_texture_is_fx(struct wlr_texture *wlr_texture); + +void wlr_gles2_texture_get_fx_attribs(struct fx_texture *texture, + struct wlr_gles2_texture_attribs *attribs); + +/// +/// fx_renderer +/// + +void fx_renderer_init_addon(struct wlr_egl *egl, struct wlr_output *output, + struct wlr_addon_set *addons, const void * owner); struct fx_renderer *fx_renderer_addon_find(struct wlr_addon_set *addons, const void * owner); -struct fx_renderer *fx_renderer_create(struct wlr_egl *egl); - -void fx_renderer_fini(struct fx_renderer *renderer); +struct fx_renderer *fx_renderer_create(struct wlr_egl *egl, struct wlr_output *output); void fx_renderer_begin(struct fx_renderer *renderer, int width, int height); +void fx_renderer_end(struct fx_renderer *renderer); + void fx_renderer_clear(const float color[static 4]); void fx_renderer_scissor(struct wlr_box *box); -- cgit v1.2.3