diff options
author | William McKinnon <[email protected]> | 2024-04-15 01:32:22 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2024-04-15 01:32:22 -0400 |
commit | e1f4bc5996b1c77c7fa8536b7c03d9eb4140227d (patch) | |
tree | 3fa8045ca37131acc96c88cec4a2f920de6113fb /render/fx_renderer/fx_effect_framebuffers.c | |
parent | 7e723f983b074e62e676caffe21cd5527b524587 (diff) |
feat: add functions required by SwayFX (#35)
Diffstat (limited to 'render/fx_renderer/fx_effect_framebuffers.c')
-rw-r--r-- | render/fx_renderer/fx_effect_framebuffers.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/render/fx_renderer/fx_effect_framebuffers.c b/render/fx_renderer/fx_effect_framebuffers.c new file mode 100644 index 0000000..4589b21 --- /dev/null +++ b/render/fx_renderer/fx_effect_framebuffers.c @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <stdlib.h> +#include <wlr/types/wlr_output.h> +#include <wlr/util/addon.h> +#include <wlr/util/log.h> + +#include "scenefx/render/fx_renderer/fx_effect_framebuffers.h" + +static void addon_handle_destroy(struct wlr_addon *addon) { + struct fx_effect_framebuffers *fbos = wl_container_of(addon, fbos, addon); + wlr_addon_finish(&fbos->addon); + free(fbos); +} + +static const struct wlr_addon_interface fbos_addon_impl = { + .name = "fx_effect_framebuffers", + .destroy = addon_handle_destroy, +}; + +static bool fx_effect_framebuffers_assign(struct wlr_output *output, + struct fx_effect_framebuffers *fbos) { + wlr_addon_init(&fbos->addon, &output->addons, output, &fbos_addon_impl); + return true; +} + +struct fx_effect_framebuffers *fx_effect_framebuffers_try_get(struct wlr_output *output) { + struct fx_effect_framebuffers *fbos = NULL; + + struct wlr_addon *addon = wlr_addon_find(&output->addons, output, + &fbos_addon_impl); + if (!addon) { + goto create_new; + return NULL; + } + + if (!(fbos = wl_container_of(addon, fbos, addon))) { + goto create_new; + } + return fbos; + +create_new:; + fbos = calloc(1, sizeof(*fbos)); + if (!fbos) { + wlr_log(WLR_ERROR, "Could not allocate a fx_effect_framebuffers"); + abort(); + } + fbos->blur_buffer_dirty = false; + + if (!fx_effect_framebuffers_assign(output, fbos)) { + wlr_log(WLR_ERROR, "Could not assign fx_effect_framebuffers to output: '%s'", + output->name); + abort(); + } + return fbos; +} |