From 2388e30bd5ef01ab67d6be769743da3e830f59c4 Mon Sep 17 00:00:00 2001 From: Shinyzenith Date: Tue, 11 Jul 2023 18:07:26 +0530 Subject: libscenefx and tinywl compilation success Signed-off-by: Shinyzenith --- flake.nix | 28 +++---- include/render/pixel_format.h | 26 ++++++ meson.build | 40 +++++++++- render/meson.build | 3 + render/pixel_format.c | 178 ++++++++++++++++++++++++++++++++++++++++++ tinywl/meson.build | 2 +- types/buffer/buffer.c | 29 +++++++ types/meson.build | 1 + 8 files changed, 288 insertions(+), 19 deletions(-) create mode 100644 include/render/pixel_format.h create mode 100644 render/meson.build create mode 100644 render/pixel_format.c create mode 100644 types/buffer/buffer.c diff --git a/flake.nix b/flake.nix index a6b50a6..4df374b 100644 --- a/flake.nix +++ b/flake.nix @@ -19,33 +19,29 @@ }; targetSystems = [ "aarch64-linux" "x86_64-linux" ]; - in - { + in { devShells = nixpkgs.lib.genAttrs targetSystems (system: - let - pkgs = pkgsFor system; - in - { + let pkgs = pkgsFor system; + in { default = pkgs.mkShell { name = "scenefx-shell"; - depsBuildBuild = with pkgs; [ pkg-config ]; - inputsFrom = [ pkgs.wlroots_0_16 ]; - nativeBuildInputs = with pkgs; [ cmake meson ninja + scdoc pkg-config + + wayland wayland-scanner - scdoc + wayland-protocols + wlroots_0_16 hwdata + udev + pixman + libxkbcommon + libdrm ]; - -# shellHook = with pkgs; ''( -# mkdir -p "$PWD/subprojects" -# cd "$PWD/subprojects" -# cp -R --no-preserve=mode,ownership ${wlroots_0_16.src} wlroots -# )''; }; }); }; diff --git a/include/render/pixel_format.h b/include/render/pixel_format.h new file mode 100644 index 0000000..d045b6a --- /dev/null +++ b/include/render/pixel_format.h @@ -0,0 +1,26 @@ +#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/meson.build b/meson.build index d94b871..75c7a7b 100644 --- a/meson.build +++ b/meson.build @@ -106,6 +106,13 @@ wayland_server = dependency('wayland-server', default_options: wayland_project_options, ) +wlroots_options = [ 'examples=false' ] +wlroots = dependency('wlroots', + version: '0.16.2', + fallback: 'wayland', + default_options: wlroots_options, +) + drm = dependency('libdrm', version: '>=2.4.113', fallback: 'libdrm', @@ -135,6 +142,7 @@ rt = cc.find_library('rt') wlr_files = [] wlr_deps = [ + wlroots, wayland_server, drm, xkbcommon, @@ -145,6 +153,7 @@ wlr_deps = [ ] subdir('protocol') +subdir('render') subdir('types') subdir('util') @@ -158,17 +167,44 @@ foreach name, have : internal_features ) endforeach -symbols_file = 'wlroots.syms' -symbols_flag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), symbols_file) +scenefx_inc = include_directories('include') +proto_inc = include_directories('protocol') + +lib_scenefx = library( + meson.project_name(), wlr_files, + soversion: soversion.to_string(), + dependencies: wlr_deps, + include_directories: [ scenefx_inc, proto_inc ], + install: true, +) + wlr_vars = {} foreach name, have : features wlr_vars += { 'have_' + name.underscorify(): have.to_string() } endforeach +scenefx = declare_dependency( + link_with: lib_scenefx, + dependencies: wlr_deps, + include_directories: scenefx_inc, + variables: wlr_vars, +) + +meson.override_dependency('scenefx', scenefx) + summary(features + internal_features, bool_yn: true) if get_option('examples') # TODO: subdir('examples') subdir('tinywl') endif + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_scenefx, + version: meson.project_version(), + filebase: meson.project_name(), + name: meson.project_name(), + description: 'Wlroots effects library', + variables: wlr_vars, +) diff --git a/render/meson.build b/render/meson.build new file mode 100644 index 0000000..7916da6 --- /dev/null +++ b/render/meson.build @@ -0,0 +1,3 @@ +wlr_files += files( + 'pixel_format.c', +) diff --git a/render/pixel_format.c b/render/pixel_format.c new file mode 100644 index 0000000..46bcecf --- /dev/null +++ b/render/pixel_format.c @@ -0,0 +1,178 @@ +#include "render/pixel_format.h" +#include + +static const struct wlr_pixel_format_info pixel_format_info[] = { + { + .drm_format = DRM_FORMAT_XRGB8888, + .opaque_substitute = DRM_FORMAT_INVALID, + .bpp = 32, + .has_alpha = false, + }, + { + .drm_format = DRM_FORMAT_ARGB8888, + .opaque_substitute = DRM_FORMAT_XRGB8888, + .bpp = 32, + .has_alpha = true, + }, + { + .drm_format = DRM_FORMAT_XBGR8888, + .opaque_substitute = DRM_FORMAT_INVALID, + .bpp = 32, + .has_alpha = false, + }, + { + .drm_format = DRM_FORMAT_ABGR8888, + .opaque_substitute = DRM_FORMAT_XBGR8888, + .bpp = 32, + .has_alpha = true, + }, + { + .drm_format = DRM_FORMAT_RGBX8888, + .opaque_substitute = DRM_FORMAT_INVALID, + .bpp = 32, + .has_alpha = false, + }, + { + .drm_format = DRM_FORMAT_RGBA8888, + .opaque_substitute = DRM_FORMAT_RGBX8888, + .bpp = 32, + .has_alpha = true, + }, + { + .drm_format = DRM_FORMAT_BGRX8888, + .opaque_substitute = DRM_FORMAT_INVALID, + .bpp = 32, + .has_alpha = false, + }, + { + .drm_format = DRM_FORMAT_BGRA8888, + .opaque_substitute = DRM_FORMAT_BGRX8888, + .bpp = 32, + .has_alpha = true, + }, + { + .drm_format = DRM_FORMAT_BGR888, + .opaque_substitute = DRM_FORMAT_INVALID, + .bpp = 24, + .has_alpha = false, + }, + { + .drm_format = DRM_FORMAT_RGBX4444, + .opaque_substitute = DRM_FORMAT_INVALID, + .bpp = 16, + .has_alpha = false, + }, + { + .drm_format = DRM_FORMAT_RGBA4444, + .opaque_substitute = DRM_FORMAT_RGBX4444, + .bpp = 16, + .has_alpha = true, + }, + { + .drm_format = DRM_FORMAT_RGBX5551, + .opaque_substitute = DRM_FORMAT_INVALID, + .bpp = 16, + .has_alpha = false, + }, + { + .drm_format = DRM_FORMAT_RGBA5551, + .opaque_substitute = DRM_FORMAT_RGBX5551, + .bpp = 16, + .has_alpha = true, + }, + { + .drm_format = DRM_FORMAT_RGB565, + .opaque_substitute = DRM_FORMAT_INVALID, + .bpp = 16, + .has_alpha = false, + }, + { + .drm_format = DRM_FORMAT_BGR565, + .opaque_substitute = DRM_FORMAT_INVALID, + .bpp = 16, + .has_alpha = false, + }, + { + .drm_format = DRM_FORMAT_XRGB2101010, + .opaque_substitute = DRM_FORMAT_INVALID, + .bpp = 32, + .has_alpha = false, + }, + { + .drm_format = DRM_FORMAT_ARGB2101010, + .opaque_substitute = DRM_FORMAT_XRGB2101010, + .bpp = 32, + .has_alpha = true, + }, + { + .drm_format = DRM_FORMAT_XBGR2101010, + .opaque_substitute = DRM_FORMAT_INVALID, + .bpp = 32, + .has_alpha = false, + }, + { + .drm_format = DRM_FORMAT_ABGR2101010, + .opaque_substitute = DRM_FORMAT_XBGR2101010, + .bpp = 32, + .has_alpha = true, + }, + { + .drm_format = DRM_FORMAT_XBGR16161616F, + .opaque_substitute = DRM_FORMAT_INVALID, + .bpp = 64, + .has_alpha = false, + }, + { + .drm_format = DRM_FORMAT_ABGR16161616F, + .opaque_substitute = DRM_FORMAT_XBGR16161616F, + .bpp = 64, + .has_alpha = true, + }, + { + .drm_format = DRM_FORMAT_XBGR16161616, + .opaque_substitute = DRM_FORMAT_INVALID, + .bpp = 64, + .has_alpha = false, + }, + { + .drm_format = DRM_FORMAT_ABGR16161616, + .opaque_substitute = DRM_FORMAT_XBGR16161616, + .bpp = 64, + .has_alpha = true, + }, +}; + +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) { + for (size_t i = 0; i < pixel_format_info_size; ++i) { + if (pixel_format_info[i].drm_format == fmt) { + return &pixel_format_info[i]; + } + } + + return NULL; +} + +uint32_t convert_wl_shm_format_to_drm(enum wl_shm_format fmt) { + switch (fmt) { + case WL_SHM_FORMAT_XRGB8888: + return DRM_FORMAT_XRGB8888; + case WL_SHM_FORMAT_ARGB8888: + return DRM_FORMAT_ARGB8888; + default: + return (uint32_t)fmt; + } +} + +enum wl_shm_format convert_drm_format_to_wl_shm(uint32_t fmt) { + switch (fmt) { + case DRM_FORMAT_XRGB8888: + return WL_SHM_FORMAT_XRGB8888; + case DRM_FORMAT_ARGB8888: + return WL_SHM_FORMAT_ARGB8888; + default: + return (enum wl_shm_format)fmt; + } +} diff --git a/tinywl/meson.build b/tinywl/meson.build index 74fe731..4c3a1d0 100644 --- a/tinywl/meson.build +++ b/tinywl/meson.build @@ -1,5 +1,5 @@ executable( 'tinywl', ['tinywl.c', protocols_client_header['xdg-shell']], -# dependencies: wlroots, + dependencies: scenefx, ) diff --git a/types/buffer/buffer.c b/types/buffer/buffer.c new file mode 100644 index 0000000..d4c47bc --- /dev/null +++ b/types/buffer/buffer.c @@ -0,0 +1,29 @@ +#include "render/pixel_format.h" +#include "types/wlr_buffer.h" + +bool buffer_is_opaque(struct wlr_buffer *buffer) { + void *data; + uint32_t format; + size_t stride; + struct wlr_dmabuf_attributes dmabuf; + struct wlr_shm_attributes shm; + if (wlr_buffer_get_dmabuf(buffer, &dmabuf)) { + format = dmabuf.format; + } else if (wlr_buffer_get_shm(buffer, &shm)) { + format = shm.format; + } else if (wlr_buffer_begin_data_ptr_access(buffer, + WLR_BUFFER_DATA_PTR_ACCESS_READ, + &data, &format, &stride)) { + wlr_buffer_end_data_ptr_access(buffer); + } else { + return false; + } + + const struct wlr_pixel_format_info *format_info = + drm_get_pixel_format_info(format); + if (format_info == NULL) { + return false; + } + + return !format_info->has_alpha; +} diff --git a/types/meson.build b/types/meson.build index 0654669..fa37bda 100644 --- a/types/meson.build +++ b/types/meson.build @@ -5,4 +5,5 @@ wlr_files += files( 'scene/output_layout.c', 'scene/xdg_shell.c', 'scene/layer_shell_v1.c', + 'buffer/buffer.c', ) -- cgit v1.2.3