diff --git a/backend/drm/drm.c b/backend/drm/drm.c index abfd1c2f4..14682dfe3 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,6 @@ #include "backend/drm/drm.h" #include "backend/drm/iface.h" #include "backend/drm/util.h" -#include "render/pixel_format.h" #include "render/drm_format_set.h" #include "render/swapchain.h" #include "render/wlr_renderer.h" diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 2d81ccd5e..bb5b5f943 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -14,7 +15,6 @@ #include "backend/drm/util.h" #include "render/drm_format_set.h" #include "render/allocator/allocator.h" -#include "render/pixel_format.h" #include "render/swapchain.h" #include "render/wlr_renderer.h" @@ -151,7 +151,7 @@ struct wlr_drm_format *drm_plane_pick_render_format( uint32_t fmt = DRM_FORMAT_ARGB8888; if (!wlr_drm_format_set_has(&plane->formats, fmt, DRM_FORMAT_MOD_INVALID)) { const struct wlr_pixel_format_info *format_info = - drm_get_pixel_format_info(fmt); + wlr_pixel_format_info_from_drm(fmt); assert(format_info != NULL && format_info->opaque_substitute != DRM_FORMAT_INVALID); fmt = format_info->opaque_substitute; @@ -306,7 +306,7 @@ static struct wlr_drm_fb *drm_fb_create(struct wlr_drm_backend *drm, // The format isn't supported by the plane. Try stripping the alpha // channel, if any. const struct wlr_pixel_format_info *info = - drm_get_pixel_format_info(attribs.format); + wlr_pixel_format_info_from_drm(attribs.format); if (info != NULL && info->opaque_substitute != DRM_FORMAT_INVALID && wlr_drm_format_set_has(formats, info->opaque_substitute, attribs.modifier)) { attribs.format = info->opaque_substitute; diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index c11d25ca9..3dcb5ea7f 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -13,12 +13,12 @@ #include #include #include +#include #include #include "backend/backend.h" #include "backend/wayland.h" #include "render/drm_format_set.h" -#include "render/pixel_format.h" #include "render/wlr_renderer.h" #include "util/signal.h" @@ -192,7 +192,7 @@ static const struct wl_drm_listener legacy_drm_listener = { static void shm_handle_format(void *data, struct wl_shm *shm, uint32_t shm_format) { struct wlr_wl_backend *wl = data; - uint32_t drm_format = convert_wl_shm_format_to_drm(shm_format); + uint32_t drm_format = wlr_convert_wl_shm_format_to_drm(shm_format); wlr_drm_format_set_add(&wl->shm_formats, drm_format, DRM_FORMAT_MOD_INVALID); } diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 16eb17f59..b4efb3564 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -11,12 +11,12 @@ #include #include +#include #include #include #include #include "backend/wayland.h" -#include "render/pixel_format.h" #include "render/swapchain.h" #include "render/wlr_renderer.h" #include "util/signal.h" @@ -178,7 +178,8 @@ static struct wl_buffer *import_dmabuf(struct wlr_wl_backend *wl, static struct wl_buffer *import_shm(struct wlr_wl_backend *wl, struct wlr_shm_attributes *shm) { - enum wl_shm_format wl_shm_format = convert_drm_format_to_wl_shm(shm->format); + enum wl_shm_format wl_shm_format = + wlr_convert_drm_format_to_wl_shm(shm->format); uint32_t size = shm->stride * shm->height; struct wl_shm_pool *pool = wl_shm_create_pool(wl->shm, shm->fd, size); if (pool == NULL) { diff --git a/include/render/pixel_format.h b/include/render/pixel_format.h deleted file mode 100644 index 471fa1067..000000000 --- a/include/render/pixel_format.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef RENDER_PIXEL_FORMAT_H -#define RENDER_PIXEL_FORMAT_H - -#include - -struct wlr_pixel_format_info { - uint32_t drm_format; - - /* Equivalent of the format if it has an alpha channel, - * DRM_FORMAT_INVALID (0) if NA - */ - uint32_t opaque_substitute; - - /* Bits per pixels */ - uint32_t bpp; - - /* True if the format has an alpha channel */ - bool has_alpha; -}; - -const struct wlr_pixel_format_info *drm_get_pixel_format_info(uint32_t fmt); - -uint32_t convert_wl_shm_format_to_drm(enum wl_shm_format fmt); -enum wl_shm_format convert_drm_format_to_wl_shm(uint32_t fmt); - -#endif diff --git a/include/render/pixman.h b/include/render/pixman.h index 24847d1a7..54a5e5e61 100644 --- a/include/render/pixman.h +++ b/include/render/pixman.h @@ -1,10 +1,10 @@ #ifndef RENDER_PIXMAN_H #define RENDER_PIXMAN_H +#include +#include #include #include -#include -#include "render/pixel_format.h" struct wlr_pixman_pixel_format { uint32_t drm_format; diff --git a/include/wlr/render/pixel_format.h b/include/wlr/render/pixel_format.h new file mode 100644 index 000000000..7a7fba298 --- /dev/null +++ b/include/wlr/render/pixel_format.h @@ -0,0 +1,31 @@ +#ifndef WLR_RENDER_PIXEL_FORMAT_H +#define WLR_RENDER_PIXEL_FORMAT_H + +#include + +struct wlr_pixel_format_info { + uint32_t drm_format; + + /* Equivalent of the format if it has an alpha channel, + * DRM_FORMAT_INVALID (0) if NA + */ + uint32_t opaque_substitute; + + /* Bits per pixels */ + uint32_t bpp; + + /* True if the format has an alpha channel */ + bool has_alpha; +}; + +/** + * Gets the pixel format info from a provided fourcc format. + * Returns NULL if not found + */ +const struct wlr_pixel_format_info *wlr_pixel_format_info_from_drm( + uint32_t fmt); + +uint32_t wlr_convert_wl_shm_format_to_drm(enum wl_shm_format fmt); +enum wl_shm_format wlr_convert_drm_format_to_wl_shm(uint32_t fmt); + +#endif diff --git a/render/allocator/drm_dumb.c b/render/allocator/drm_dumb.c index 170d9c331..4ca35a8dc 100644 --- a/render/allocator/drm_dumb.c +++ b/render/allocator/drm_dumb.c @@ -12,9 +12,9 @@ #include #include #include +#include #include "render/allocator/drm_dumb.h" -#include "render/pixel_format.h" static const struct wlr_buffer_impl buffer_impl; @@ -52,7 +52,7 @@ static struct wlr_drm_dumb_buffer *create_buffer( wl_list_insert(&alloc->buffers, &buffer->link); const struct wlr_pixel_format_info *info = - drm_get_pixel_format_info(format->format); + wlr_pixel_format_info_from_drm(format->format); if (info == NULL) { wlr_log(WLR_ERROR, "DRM format 0x%"PRIX32" not supported", format->format); diff --git a/render/allocator/shm.c b/render/allocator/shm.c index 77054dbe9..b899cfd5b 100644 --- a/render/allocator/shm.c +++ b/render/allocator/shm.c @@ -3,8 +3,9 @@ #include #include #include +#include +#include #include -#include "render/pixel_format.h" #include "render/allocator/shm.h" #include "util/shm.h" @@ -54,7 +55,7 @@ static struct wlr_buffer *allocator_create_buffer( struct wlr_allocator *wlr_allocator, int width, int height, const struct wlr_drm_format *format) { const struct wlr_pixel_format_info *info = - drm_get_pixel_format_info(format->format); + wlr_pixel_format_info_from_drm(format->format); if (info == NULL) { wlr_log(WLR_ERROR, "Unsupported pixel format 0x%"PRIX32, format->format); return NULL; diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 62aab8620..45116bda5 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -11,13 +11,13 @@ #include #include #include +#include #include #include #include #include #include "render/egl.h" #include "render/gles2.h" -#include "render/pixel_format.h" static const GLfloat verts[] = { 1, 0, // top right @@ -443,7 +443,7 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer, } const struct wlr_pixel_format_info *drm_fmt = - drm_get_pixel_format_info(fmt->drm_format); + wlr_pixel_format_info_from_drm(fmt->drm_format); assert(drm_fmt); push_gles2_debug(renderer); diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 43833cc7c..926b00aaf 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -8,12 +8,12 @@ #include #include #include +#include #include #include #include #include "render/egl.h" #include "render/gles2.h" -#include "render/pixel_format.h" #include "types/wlr_buffer.h" #include "util/signal.h" @@ -65,7 +65,7 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture, assert(fmt); const struct wlr_pixel_format_info *drm_fmt = - drm_get_pixel_format_info(texture->drm_format); + wlr_pixel_format_info_from_drm(texture->drm_format); assert(drm_fmt); if (!check_stride(drm_fmt, stride, width)) { @@ -194,7 +194,7 @@ static struct wlr_texture *gles2_texture_from_pixels( } const struct wlr_pixel_format_info *drm_fmt = - drm_get_pixel_format_info(drm_format); + wlr_pixel_format_info_from_drm(drm_format); assert(drm_fmt); if (!check_stride(drm_fmt, stride, width)) { @@ -254,7 +254,7 @@ static struct wlr_texture *gles2_texture_from_dmabuf( (attribs->flags & WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT) != 0; const struct wlr_pixel_format_info *drm_fmt = - drm_get_pixel_format_info(attribs->format); + wlr_pixel_format_info_from_drm(attribs->format); if (drm_fmt != NULL) { texture->has_alpha = drm_fmt->has_alpha; } else { diff --git a/render/pixel_format.c b/render/pixel_format.c index bd59af8b1..29e31c60c 100644 --- a/render/pixel_format.c +++ b/render/pixel_format.c @@ -1,5 +1,5 @@ #include -#include "render/pixel_format.h" +#include static const struct wlr_pixel_format_info pixel_format_info[] = { { @@ -133,7 +133,8 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { static const size_t pixel_format_info_size = sizeof(pixel_format_info) / sizeof(pixel_format_info[0]); -const struct wlr_pixel_format_info *drm_get_pixel_format_info(uint32_t fmt) { +const struct wlr_pixel_format_info *wlr_pixel_format_info_from_drm( + uint32_t fmt) { for (size_t i = 0; i < pixel_format_info_size; ++i) { if (pixel_format_info[i].drm_format == fmt) { return &pixel_format_info[i]; @@ -143,7 +144,7 @@ const struct wlr_pixel_format_info *drm_get_pixel_format_info(uint32_t fmt) { return NULL; } -uint32_t convert_wl_shm_format_to_drm(enum wl_shm_format fmt) { +uint32_t wlr_convert_wl_shm_format_to_drm(enum wl_shm_format fmt) { switch (fmt) { case WL_SHM_FORMAT_XRGB8888: return DRM_FORMAT_XRGB8888; @@ -154,7 +155,7 @@ uint32_t convert_wl_shm_format_to_drm(enum wl_shm_format fmt) { } } -enum wl_shm_format convert_drm_format_to_wl_shm(uint32_t fmt) { +enum wl_shm_format wlr_convert_drm_format_to_wl_shm(uint32_t fmt) { switch (fmt) { case DRM_FORMAT_XRGB8888: return WL_SHM_FORMAT_XRGB8888; diff --git a/render/pixman/renderer.c b/render/pixman/renderer.c index 2ae05d002..3f31c8e30 100644 --- a/render/pixman/renderer.c +++ b/render/pixman/renderer.c @@ -353,7 +353,7 @@ static struct wlr_pixman_texture *pixman_texture_create( wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height); texture->renderer = renderer; - texture->format_info = drm_get_pixel_format_info(drm_format); + texture->format_info = wlr_pixel_format_info_from_drm(drm_format); if (!texture->format_info) { wlr_log(WLR_ERROR, "Unsupported drm format 0x%"PRIX32, drm_format); free(texture); @@ -476,7 +476,7 @@ static bool pixman_read_pixels(struct wlr_renderer *wlr_renderer, } const struct wlr_pixel_format_info *drm_fmt = - drm_get_pixel_format_info(drm_format); + wlr_pixel_format_info_from_drm(drm_format); assert(drm_fmt); pixman_image_t *dst = pixman_image_create_bits_no_clear(fmt, width, height, diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index 5818cd4a2..75fa177de 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -18,7 +19,6 @@ #endif #include "util/signal.h" -#include "render/pixel_format.h" #include "render/wlr_renderer.h" void wlr_renderer_init(struct wlr_renderer *renderer, @@ -211,7 +211,7 @@ bool wlr_renderer_init_wl_display(struct wlr_renderer *r, for (size_t i = 0; i < len; ++i) { // ARGB8888 and XRGB8888 must be supported and are implicitly // advertised by wl_display_init_shm - enum wl_shm_format fmt = convert_drm_format_to_wl_shm(formats[i]); + enum wl_shm_format fmt = wlr_convert_drm_format_to_wl_shm(formats[i]); switch (fmt) { case WL_SHM_FORMAT_ARGB8888: argb8888 = true; diff --git a/types/wlr_buffer.c b/types/wlr_buffer.c index fa281c682..c50e6c6fe 100644 --- a/types/wlr_buffer.c +++ b/types/wlr_buffer.c @@ -1,12 +1,12 @@ #include #include #include +#include #include #include #include #include #include -#include "render/pixel_format.h" #include "types/wlr_buffer.h" #include "util/signal.h" @@ -427,7 +427,7 @@ static struct wlr_shm_client_buffer *shm_client_buffer_get_or_create( buffer->shm_buffer = shm_buffer; enum wl_shm_format wl_shm_format = wl_shm_buffer_get_format(shm_buffer); - buffer->format = convert_wl_shm_format_to_drm(wl_shm_format); + buffer->format = wlr_convert_wl_shm_format_to_drm(wl_shm_format); buffer->stride = wl_shm_buffer_get_stride(shm_buffer); buffer->resource_destroy.notify = shm_client_buffer_resource_handle_destroy; diff --git a/types/wlr_screencopy_v1.c b/types/wlr_screencopy_v1.c index 5ef9d2694..68980f075 100644 --- a/types/wlr_screencopy_v1.c +++ b/types/wlr_screencopy_v1.c @@ -6,11 +6,11 @@ #include #include #include +#include #include #include #include #include "wlr-screencopy-unstable-v1-protocol.h" -#include "render/pixel_format.h" #include "util/signal.h" #define SCREENCOPY_MANAGER_VERSION 3 @@ -199,7 +199,7 @@ static bool frame_shm_copy(struct wlr_screencopy_frame_v1 *frame, int y = frame->box.y; enum wl_shm_format wl_shm_format = wl_shm_buffer_get_format(shm_buffer); - uint32_t drm_format = convert_wl_shm_format_to_drm(wl_shm_format); + uint32_t drm_format = wlr_convert_wl_shm_format_to_drm(wl_shm_format); int32_t width = wl_shm_buffer_get_width(shm_buffer); int32_t height = wl_shm_buffer_get_height(shm_buffer); int32_t stride = wl_shm_buffer_get_stride(shm_buffer); @@ -555,7 +555,7 @@ static void capture_output(struct wl_client *wl_client, goto error; } - frame->format = convert_drm_format_to_wl_shm(drm_format); + frame->format = wlr_convert_drm_format_to_wl_shm(drm_format); frame->fourcc = get_output_fourcc(output); struct wlr_box buffer_box = {0};