started the switch to a fb approach

This commit is contained in:
William McKinnon 2023-12-22 01:00:10 -05:00
parent e20b8860da
commit 71fa52f695
8 changed files with 60 additions and 9 deletions

View file

@ -8,6 +8,7 @@
#include "sway/desktop/fx_renderer/fx_framebuffer.h" #include "sway/desktop/fx_renderer/fx_framebuffer.h"
#include "sway/desktop/fx_renderer/fx_texture.h" #include "sway/desktop/fx_renderer/fx_texture.h"
#include "sway/tree/view.h"
enum corner_location { TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT, ALL, NONE }; enum corner_location { TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT, ALL, NONE };
@ -124,6 +125,8 @@ struct fx_renderer {
struct wlr_output *wlr_output; struct wlr_output *wlr_output;
struct wlr_egl *wlr_egl;
// The framebuffer used by wlroots // The framebuffer used by wlroots
struct fx_framebuffer wlr_buffer; struct fx_framebuffer wlr_buffer;
// Contains the blurred background for tiled windows // Contains the blurred background for tiled windows
@ -214,4 +217,6 @@ void fx_render_blur(struct fx_renderer *renderer, const float matrix[static 9],
struct fx_framebuffer **buffer, struct blur_shader *shader, const struct wlr_box *box, struct fx_framebuffer **buffer, struct blur_shader *shader, const struct wlr_box *box,
int blur_radius); int blur_radius);
void fx_create_view_snapshot(struct fx_renderer *renderer, struct sway_view *view);
#endif #endif

View file

@ -185,6 +185,8 @@ void render_rounded_rect(struct sway_output *output,
float color[static 4], int corner_radius, float color[static 4], int corner_radius,
enum corner_location corner_location); enum corner_location corner_location);
void render_container(struct sway_output *output,
pixman_region32_t *damage, struct sway_container *con, bool parent_focused);
void premultiply_alpha(float color[4], float opacity); void premultiply_alpha(float color[4], float opacity);

View file

@ -4,6 +4,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include "list.h" #include "list.h"
#include "sway/desktop/fx_renderer/fx_framebuffer.h"
#include "sway/tree/node.h" #include "sway/tree/node.h"
struct sway_view; struct sway_view;
@ -124,6 +125,7 @@ struct sway_container {
float target_alpha; float target_alpha;
float max_alpha; float max_alpha;
struct fx_framebuffer close_animation_fb;
struct wl_event_source *animation_present_timer; struct wl_event_source *animation_present_timer;
int corner_radius; int corner_radius;

View file

@ -328,6 +328,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
bool fullscreen, struct wlr_output *fullscreen_output, bool decoration); bool fullscreen, struct wlr_output *fullscreen_output, bool decoration);
void view_unmap(struct sway_view *view); void view_unmap(struct sway_view *view);
void view_unmap_finish(struct sway_view *view);
void view_update_size(struct sway_view *view); void view_update_size(struct sway_view *view);
void view_center_surface(struct sway_view *view); void view_center_surface(struct sway_view *view);

View file

@ -19,6 +19,7 @@
#include "sway/desktop/fx_renderer/fx_texture.h" #include "sway/desktop/fx_renderer/fx_texture.h"
#include "sway/desktop/fx_renderer/matrix.h" #include "sway/desktop/fx_renderer/matrix.h"
#include "sway/server.h" #include "sway/server.h"
#include "sway/output.h"
// shaders // shaders
#include "blur1_frag_src.h" #include "blur1_frag_src.h"
@ -29,6 +30,8 @@
#include "quad_frag_src.h" #include "quad_frag_src.h"
#include "quad_round_frag_src.h" #include "quad_round_frag_src.h"
#include "stencil_mask_frag_src.h" #include "stencil_mask_frag_src.h"
#include "sway/tree/node.h"
#include "sway/tree/workspace.h"
#include "tex_frag_src.h" #include "tex_frag_src.h"
static const GLfloat verts[] = { static const GLfloat verts[] = {
@ -269,6 +272,7 @@ struct fx_renderer *fx_renderer_create(struct wlr_egl *egl, struct wlr_output *w
sway_log(SWAY_ERROR, "GLES2 RENDERER: Could not make EGL current"); sway_log(SWAY_ERROR, "GLES2 RENDERER: Could not make EGL current");
return NULL; return NULL;
} }
renderer->wlr_egl = egl;
renderer->wlr_buffer = fx_framebuffer_create(); renderer->wlr_buffer = fx_framebuffer_create();
renderer->blur_buffer = fx_framebuffer_create(); renderer->blur_buffer = fx_framebuffer_create();
@ -871,5 +875,36 @@ void fx_render_blur(struct fx_renderer *renderer, const float matrix[static 9],
glDisableVertexAttribArray(shader->pos_attrib); glDisableVertexAttribArray(shader->pos_attrib);
glDisableVertexAttribArray(shader->tex_attrib); glDisableVertexAttribArray(shader->tex_attrib);
}
void fx_create_view_snapshot(struct fx_renderer *renderer, struct sway_view *view) {
assert(view);
// TODO: move to function? used in creation too
if (!eglMakeCurrent(wlr_egl_get_display(renderer->wlr_egl), EGL_NO_SURFACE, EGL_NO_SURFACE,
wlr_egl_get_context(renderer->wlr_egl))) {
sway_log(SWAY_ERROR, "GLES2 RENDERER: Could not make EGL current");
return;
}
struct sway_container *con = view->container;
struct sway_output *output = con->pending.workspace->output;
//fx_framebuffer_update(&con->close_animation_fb, output->width, output->height);
//fx_framebuffer_bind(&con->close_animation_fb);
// damage whole output to ensure full container is rendered
// (temporary, render_container will only render container area)
struct wlr_box box = { 0, 0, output->width, output->height };
scale_box(&box, output->wlr_output->scale);
pixman_region32_t damage;
pixman_region32_init(&damage);
pixman_region32_union_rect(&damage, &damage, box.x, box.y, box.width, box.height);
// TODO: add check to see if container is fading out in render_container
// TODO: render without blur?
render_container(output, &damage, con, con->current.focused);
// rebind the main fb
//fx_framebuffer_bind(&renderer->wlr_buffer);
} }

View file

@ -1398,9 +1398,6 @@ struct parent_data {
struct sway_container *active_child; struct sway_container *active_child;
}; };
static void render_container(struct sway_output *output,
pixman_region32_t *damage, struct sway_container *con, bool parent_focused);
/** /**
* Render a container's children using a L_HORIZ or L_VERT layout. * Render a container's children using a L_HORIZ or L_VERT layout.
* *
@ -1685,7 +1682,7 @@ static void render_containers(struct sway_output *output,
} }
} }
static void render_container(struct sway_output *output, void render_container(struct sway_output *output,
pixman_region32_t *damage, struct sway_container *con, bool focused) { pixman_region32_t *damage, struct sway_container *con, bool focused) {
struct parent_data data = { struct parent_data data = {
.layout = con->current.layout, .layout = con->current.layout,

View file

@ -51,7 +51,6 @@ static int animation_timer(void *data) {
if (con->alpha != con->target_alpha) { if (con->alpha != con->target_alpha) {
wl_event_source_timer_update(con->animation_present_timer, fastest_output_refresh_s * 1000); wl_event_source_timer_update(con->animation_present_timer, fastest_output_refresh_s * 1000);
} else if (is_closing && con->view->impl->close) { } else if (is_closing && con->view->impl->close) {
con->view->impl->close(con->view);
} }
container_damage_whole(con); container_damage_whole(con);
@ -75,6 +74,7 @@ struct sway_container *container_create(struct sway_view *view) {
c->shadow_enabled = config->shadow_enabled; c->shadow_enabled = config->shadow_enabled;
c->blur_enabled = config->blur_enabled; c->blur_enabled = config->blur_enabled;
c->corner_radius = config->corner_radius; c->corner_radius = config->corner_radius;
c->close_animation_fb = fx_framebuffer_create();
if (!view) { if (!view) {
c->pending.children = create_list(); c->pending.children = create_list();
@ -96,6 +96,7 @@ struct sway_container *container_create(struct sway_view *view) {
} }
void container_destroy(struct sway_container *con) { void container_destroy(struct sway_container *con) {
printf("destroying container\n");
if (!sway_assert(con->node.destroying, if (!sway_assert(con->node.destroying,
"Tried to free container which wasn't marked as destroying")) { "Tried to free container which wasn't marked as destroying")) {
return; return;
@ -135,6 +136,7 @@ void container_destroy(struct sway_container *con) {
} }
void container_begin_destroy(struct sway_container *con) { void container_begin_destroy(struct sway_container *con) {
printf("beginning container destroy\n");
if (con->view) { if (con->view) {
ipc_event_window(con, "close"); ipc_event_window(con, "close");
} }

View file

@ -428,8 +428,9 @@ void view_set_tiled(struct sway_view *view, bool tiled) {
} }
void view_close(struct sway_view *view) { void view_close(struct sway_view *view) {
view->container->target_alpha = 0; if (view->impl->close) {
wl_event_source_timer_update(view->container->animation_present_timer, 1); view->impl->close(view);
}
} }
void view_close_popups(struct sway_view *view) { void view_close_popups(struct sway_view *view) {
@ -906,6 +907,13 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
} }
void view_unmap(struct sway_view *view) { void view_unmap(struct sway_view *view) {
printf("unmap view\n");
// take a snapshot for fade-out animation
struct sway_workspace *ws = view->container->pending.workspace;
if (ws) {
fx_create_view_snapshot(ws->output->renderer, view);
}
wl_signal_emit_mutable(&view->events.unmap, view); wl_signal_emit_mutable(&view->events.unmap, view);
wl_list_remove(&view->surface_new_subsurface.link); wl_list_remove(&view->surface_new_subsurface.link);
@ -921,7 +929,6 @@ void view_unmap(struct sway_view *view) {
} }
struct sway_container *parent = view->container->pending.parent; struct sway_container *parent = view->container->pending.parent;
struct sway_workspace *ws = view->container->pending.workspace;
container_begin_destroy(view->container); container_begin_destroy(view->container);
if (parent) { if (parent) {
container_reap_empty(parent); container_reap_empty(parent);