Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement surface-invalidation-v1 #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "viewporter-client-protocol.h"
#include "single-pixel-buffer-v1-client-protocol.h"
#include "surface-invalidation-v1-client-protocol.h"

static uint32_t parse_color(const char *color) {
if (color[0] == '#') {
Expand All @@ -41,6 +42,7 @@ struct swaybg_state {
struct zwlr_layer_shell_v1 *layer_shell;
struct wp_viewporter *viewporter;
struct wp_single_pixel_buffer_manager_v1 *single_pixel_buffer_manager;
struct wp_surface_invalidation_manager_v1 *surface_invalidation_manager;
struct wl_list configs; // struct swaybg_output_config::link
struct wl_list outputs; // struct swaybg_output::link
struct wl_list images; // struct swaybg_image::link
Expand Down Expand Up @@ -81,6 +83,12 @@ struct swaybg_output {
bool dirty, needs_ack;
int32_t committed_width, committed_height, committed_scale;

struct {
struct wp_surface_invalidation_v1 *object;
bool needs_ack;
uint32_t serial;
} surface_invalidation;

struct wl_list link;
};

Expand Down Expand Up @@ -255,10 +263,32 @@ static void output_mode(void *data, struct wl_output *output, uint32_t flags,
// Who cares
}

static void surface_invalidation_handle_invalidated(void *data,
struct wp_surface_invalidation_v1 *wp_surface_invalidation_v1, uint32_t serial) {
struct swaybg_output *output = data;
assert(output->surface_invalidation.object == wp_surface_invalidation_v1);

output->dirty = true;
output->surface_invalidation.needs_ack = true;
output->surface_invalidation.serial = serial;
}

static struct wp_surface_invalidation_v1_listener surface_invalidation_listener = {
.invalidated = surface_invalidation_handle_invalidated,
};

static void create_layer_surface(struct swaybg_output *output) {
output->surface = wl_compositor_create_surface(output->state->compositor);
assert(output->surface);

if (output->state->surface_invalidation_manager) {
output->surface_invalidation.object =
wp_surface_invalidation_manager_v1_get_surface_invalidation(
output->state->surface_invalidation_manager, output->surface);
wp_surface_invalidation_v1_add_listener(output->surface_invalidation.object,
&surface_invalidation_listener, output);
}

// Empty input region
struct wl_region *input_region =
wl_compositor_create_region(output->state->compositor);
Expand Down Expand Up @@ -385,6 +415,10 @@ static void handle_global(void *data, struct wl_registry *registry,
wp_single_pixel_buffer_manager_v1_interface.name) == 0) {
state->single_pixel_buffer_manager = wl_registry_bind(registry, name,
&wp_single_pixel_buffer_manager_v1_interface, 1);
} else if (strcmp(interface,
wp_surface_invalidation_manager_v1_interface.name) == 0) {
state->surface_invalidation_manager = wl_registry_bind(registry, name,
&wp_surface_invalidation_manager_v1_interface, 1);
}
}

Expand Down Expand Up @@ -600,6 +634,15 @@ int main(int argc, char **argv) {
output->configure_serial);
}

if (output->surface_invalidation.needs_ack) {
output->surface_invalidation.needs_ack = false;
wp_surface_invalidation_v1_ack(output->surface_invalidation.object,
output->surface_invalidation.serial);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be a bit nicer to move this to render_frame.

output->committed_width = 0;
output->committed_height = 0;
output->committed_scale = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why do we need to reset these?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, to trigger the buffer_change bool below?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add || output->surface_invalidation.needs_ack to the buffer_change condition?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the render loop, it will compare the old committed_state with whatever it wants to render now, If the results are the same it will simply commit and return early. This is not good enough: we need to make sure that the render_frame function goes all the way through to create a buffer and commit. Just flipping the buffer_change isn't good enough, took me a while to debug that.

}

int buffer_width = output->width * output->scale,
buffer_height = output->height * output->scale;
bool buffer_change =
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ client_protocols = [
wl_protocol_dir / 'stable/xdg-shell/xdg-shell.xml',
wl_protocol_dir / 'stable/viewporter/viewporter.xml',
wl_protocol_dir / 'staging/single-pixel-buffer/single-pixel-buffer-v1.xml',
wl_protocol_dir / 'staging/surface-invalidation/surface-invalidation-v1.xml',
'wlr-layer-shell-unstable-v1.xml',
]

Expand Down