-
Notifications
You must be signed in to change notification settings - Fork 32
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] == '#') { | ||
|
@@ -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 | ||
|
@@ -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; | ||
}; | ||
|
||
|
@@ -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); | ||
|
@@ -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); | ||
} | ||
} | ||
|
||
|
@@ -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); | ||
output->committed_width = 0; | ||
output->committed_height = 0; | ||
output->committed_scale = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, why do we need to reset these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, to trigger the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can add There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = | ||
|
There was a problem hiding this comment.
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
.