Skip to content

Commit

Permalink
Merge branch 'main' into wlr_scene_blur
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikReider committed May 7, 2024
2 parents 2f9505a + 0abffbe commit 3bccfb1
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 173 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
# scenefx

wlroots is the de-facto library for building wayland compositors, and its scene api is a great stride in simplifying wayland compositor development. The problem with the scene api (for compositors looking for eye candy), however, is that it forces you to use the wlr renderer, which is powerful yet simple. SceneFX is a project that takes the scene api and replaces the wlr renderer with our own fx renderer, capable of rendering surfaces with eye-candy effects including blur, shadows, and rounded corners, while maintaining the benefits of simplicity gained from using the scene api.

**Please note: while SceneFX is in use by SwayFX version 0.4, it is not yet ready for usage by other compositors. Please refer to the [1.0 milestone](https://github.com/wlrfx/scenefx/milestone/2) to track the remaining tasks for our stable 1.0 release**

## Installation
<a href="https://repology.org/project/scenefx/versions"><img src="https://repology.org/badge/vertical-allrepos/scenefx.svg"/></a>


## Compiling From Source
Install dependencies:
* meson \*
* wlroots
* wayland
* wayland-protocols \*
* EGL and GLESv2
* libdrm
* pixman

_\* Compile-time dep_

Run these commands:
```sh
meson setup build/
ninja -C build/
```

Install like so:
```sh
sudo ninja -C build/ install
```


---
[Join our Discord](https://discord.gg/qsSx397rkh)
23 changes: 3 additions & 20 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 72 additions & 37 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,49 +1,84 @@
{
description = "scenefx development environment";

inputs = {
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};

nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};

outputs = { self, nixpkgs, flake-compat, ... }:
description = "Scenefx development environment";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
outputs =
{ self, nixpkgs, ... }:
let
pkgsFor = system:
import nixpkgs {
inherit system;
overlays = [ ];
};

targetSystems = [ "aarch64-linux" "x86_64-linux" ];
in {
devShells = nixpkgs.lib.genAttrs targetSystems (system:
let pkgs = pkgsFor system;
in {
default = pkgs.mkShell {
name = "scenefx-shell";

inputsFrom = [ pkgs.wlroots_0_17 ];
mkPackages = pkgs: {
scenefx = pkgs.callPackage (
{ wlroots_0_17, ... }:
pkgs.stdenv.mkDerivation {
pname = "scenefx";
version = "0.1.0-git";
src = ./.;
outputs = [
"out"
"lib"
];

nativeBuildInputs = with pkgs; [
cmake
pkg-config
meson
cmake
ninja
scdoc
pkg-config
hwdata
];

shellHook = with pkgs; ''(
mkdir -p "$PWD/subprojects"
cd "$PWD/subprojects"
cp -R --no-preserve=mode,ownership ${wlroots_0_17.src} wlroots
buildInputs = with pkgs; [
libdrm
libxkbcommon
pixman
libGL # egl
mesa # gbm
wayland # wayland-server
wayland-protocols
wlroots_0_17
];

meta = with pkgs.lib; {
description = "A drop-in replacement for the wlroots scene API that allows wayland compositors to render surfaces with eye-candy effects";
homepage = "https://github.com/wlrfx/scenefx";
license = licenses.mit;
platforms = platforms.linux;
};
}
) { };
};

targetSystems = [
"aarch64-linux"
"x86_64-linux"
];
pkgsFor = system: import nixpkgs { inherit system; };
forEachSystem = f: nixpkgs.lib.genAttrs targetSystems (system: f (pkgsFor system));
in
{
overlays = rec {
default = insert;
override = _: prev: mkPackages prev;
insert = _: prev: mkPackages (pkgsFor prev.system);
};

packages = forEachSystem (
pkgs: (mkPackages pkgs) // { default = self.packages.${pkgs.system}.scenefx; }
);

devShells = forEachSystem (pkgs: {
default = pkgs.mkShell {
name = "scenefx-shell";
inputsFrom = [
self.packages.${pkgs.system}.scenefx
pkgs.wlroots_0_17
];
shellHook = ''
(
# Copy the nix version of wlroots into the project
mkdir -p "$PWD/subprojects" && cd "$PWD/subprojects"
cp -R --no-preserve=mode,ownership ${pkgs.wlroots_0_17.src} wlroots
)'';
};
});
};
});

formatter = forEachSystem (pkgs: pkgs.nixfmt-rfc-style);
};
}

70 changes: 70 additions & 0 deletions include/render/fx_renderer/fx_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <wlr/util/addon.h>
#include <wlr/util/box.h>

#include "render/fx_renderer/shaders.h"

struct fx_pixel_format {
uint32_t drm_format;
// optional field, if empty then internalformat = format
Expand Down Expand Up @@ -118,4 +120,72 @@ struct fx_render_timer {

bool wlr_render_timer_is_fx(struct wlr_render_timer *timer);

///
/// fx_renderer
///

struct fx_renderer {
struct wlr_renderer wlr_renderer;

float projection[9];
struct wlr_egl *egl;
int drm_fd;

const char *exts_str;
struct {
bool EXT_read_format_bgra;
bool KHR_debug;
bool OES_egl_image_external;
bool OES_egl_image;
bool EXT_texture_type_2_10_10_10_REV;
bool OES_texture_half_float_linear;
bool EXT_texture_norm16;
bool EXT_disjoint_timer_query;
} exts;

struct {
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
PFNGLDEBUGMESSAGECALLBACKKHRPROC glDebugMessageCallbackKHR;
PFNGLDEBUGMESSAGECONTROLKHRPROC glDebugMessageControlKHR;
PFNGLPOPDEBUGGROUPKHRPROC glPopDebugGroupKHR;
PFNGLPUSHDEBUGGROUPKHRPROC glPushDebugGroupKHR;
PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES;
PFNGLGETGRAPHICSRESETSTATUSKHRPROC glGetGraphicsResetStatusKHR;
PFNGLGENQUERIESEXTPROC glGenQueriesEXT;
PFNGLDELETEQUERIESEXTPROC glDeleteQueriesEXT;
PFNGLQUERYCOUNTEREXTPROC glQueryCounterEXT;
PFNGLGETQUERYOBJECTIVEXTPROC glGetQueryObjectivEXT;
PFNGLGETQUERYOBJECTUI64VEXTPROC glGetQueryObjectui64vEXT;
PFNGLGETINTEGER64VEXTPROC glGetInteger64vEXT;
} procs;

struct {
struct quad_shader quad;
struct quad_round_shader quad_round;
struct quad_round_shader quad_round_tl;
struct quad_round_shader quad_round_tr;
struct quad_round_shader quad_round_bl;
struct quad_round_shader quad_round_br;
struct tex_shader tex_rgba;
struct tex_shader tex_rgbx;
struct tex_shader tex_ext;
struct box_shadow_shader box_shadow;
struct rounded_border_corner_shader rounded_border_corner;
struct stencil_mask_shader stencil_mask;
struct blur_shader blur1;
struct blur_shader blur2;
struct blur_effects_shader blur_effects;
} shaders;

struct wl_list buffers; // fx_framebuffer.link
struct wl_list textures; // fx_texture.link

struct fx_framebuffer *current_buffer;
uint32_t viewport_width, viewport_height;

// Set to true when 'wlr_renderer_begin_buffer_pass' is called instead of
// our custom 'fx_renderer_begin_buffer_pass' function
bool basic_renderer;
};

#endif
3 changes: 3 additions & 0 deletions include/scenefx/render/fx_renderer/fx_effect_framebuffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ struct fx_effect_framebuffers {
struct fx_framebuffer *effects_buffer_swapped;

bool blur_buffer_dirty;

// The region where there's blur
pixman_region32_t blur_padding_region;
};

struct fx_effect_framebuffers *fx_effect_framebuffers_try_get(struct wlr_output *output);
Expand Down
75 changes: 1 addition & 74 deletions include/scenefx/render/fx_renderer/fx_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <wlr/render/interface.h>
#include <wlr/types/wlr_buffer.h>

#include "render/fx_renderer/shaders.h"
struct fx_renderer;

struct wlr_renderer *fx_renderer_create_with_drm_fd(int drm_fd);
struct wlr_renderer *fx_renderer_create(struct wlr_backend *backend);
Expand All @@ -26,79 +26,6 @@ struct fx_texture_attribs {
bool has_alpha;
};

///
/// fx_renderer
///

// TODO: make this private
struct fx_renderer {
struct wlr_renderer wlr_renderer;

float projection[9];
struct wlr_egl *egl;
int drm_fd;

const char *exts_str;
struct {
bool EXT_read_format_bgra;
bool KHR_debug;
bool OES_egl_image_external;
bool OES_egl_image;
bool EXT_texture_type_2_10_10_10_REV;
bool OES_texture_half_float_linear;
bool EXT_texture_norm16;
bool EXT_disjoint_timer_query;
} exts;

struct {
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
PFNGLDEBUGMESSAGECALLBACKKHRPROC glDebugMessageCallbackKHR;
PFNGLDEBUGMESSAGECONTROLKHRPROC glDebugMessageControlKHR;
PFNGLPOPDEBUGGROUPKHRPROC glPopDebugGroupKHR;
PFNGLPUSHDEBUGGROUPKHRPROC glPushDebugGroupKHR;
PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES;
PFNGLGETGRAPHICSRESETSTATUSKHRPROC glGetGraphicsResetStatusKHR;
PFNGLGENQUERIESEXTPROC glGenQueriesEXT;
PFNGLDELETEQUERIESEXTPROC glDeleteQueriesEXT;
PFNGLQUERYCOUNTEREXTPROC glQueryCounterEXT;
PFNGLGETQUERYOBJECTIVEXTPROC glGetQueryObjectivEXT;
PFNGLGETQUERYOBJECTUI64VEXTPROC glGetQueryObjectui64vEXT;
PFNGLGETINTEGER64VEXTPROC glGetInteger64vEXT;
} procs;

struct {
struct quad_shader quad;
struct quad_round_shader quad_round;
struct quad_round_shader quad_round_tl;
struct quad_round_shader quad_round_tr;
struct quad_round_shader quad_round_bl;
struct quad_round_shader quad_round_br;
struct tex_shader tex_rgba;
struct tex_shader tex_rgbx;
struct tex_shader tex_ext;
struct box_shadow_shader box_shadow;
struct rounded_border_corner_shader rounded_border_corner;
struct stencil_mask_shader stencil_mask;
struct blur_shader blur1;
struct blur_shader blur2;
struct blur_effects_shader blur_effects;
} shaders;

struct wl_list buffers; // fx_framebuffer.link
struct wl_list textures; // fx_texture.link

struct fx_framebuffer *current_buffer;
uint32_t viewport_width, viewport_height;

// Set to true when 'wlr_renderer_begin_buffer_pass' is called instead of
// our custom 'fx_renderer_begin_buffer_pass' function
bool basic_renderer;

// The region where there's blur
pixman_region32_t blur_padding_region;
};


struct wlr_texture *fx_texture_from_buffer(struct wlr_renderer *wlr_renderer,
struct wlr_buffer *buffer);

Expand Down
Loading

0 comments on commit 3bccfb1

Please sign in to comment.