Merge pull request #1071 from emersion/remove-wlr-frame-callback

surface: remove wlr_frame_callback
This commit is contained in:
Drew DeVault 2018-06-20 13:04:26 -07:00 committed by GitHub
commit 637479ce05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 35 deletions

View File

@ -8,11 +8,6 @@
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
struct wlr_frame_callback {
struct wl_resource *resource;
struct wl_list link;
};
#define WLR_SURFACE_INVALID_BUFFER 1 #define WLR_SURFACE_INVALID_BUFFER 1
#define WLR_SURFACE_INVALID_SURFACE_DAMAGE 2 #define WLR_SURFACE_INVALID_SURFACE_DAMAGE 2
#define WLR_SURFACE_INVALID_BUFFER_DAMAGE 4 #define WLR_SURFACE_INVALID_BUFFER_DAMAGE 4

View File

@ -86,40 +86,25 @@ static void surface_damage(struct wl_client *client,
x, y, width, height); x, y, width, height);
} }
static struct wlr_frame_callback *frame_callback_from_resource(
struct wl_resource *resource) {
assert(wl_resource_instance_of(resource, &wl_callback_interface, NULL));
return wl_resource_get_user_data(resource);
}
static void callback_handle_resource_destroy(struct wl_resource *resource) { static void callback_handle_resource_destroy(struct wl_resource *resource) {
struct wlr_frame_callback *cb = frame_callback_from_resource(resource); wl_list_remove(wl_resource_get_link(resource));
wl_list_remove(&cb->link);
free(cb);
} }
static void surface_frame(struct wl_client *client, static void surface_frame(struct wl_client *client,
struct wl_resource *resource, uint32_t callback) { struct wl_resource *resource, uint32_t callback) {
struct wlr_surface *surface = wlr_surface_from_resource(resource); struct wlr_surface *surface = wlr_surface_from_resource(resource);
struct wlr_frame_callback *cb = struct wl_resource *callback_resource = wl_resource_create(client,
calloc(1, sizeof(struct wlr_frame_callback)); &wl_callback_interface, CALLBACK_VERSION, callback);
if (cb == NULL) { if (callback_resource == NULL) {
wl_resource_post_no_memory(resource); wl_resource_post_no_memory(resource);
return; return;
} }
wl_resource_set_implementation(callback_resource, NULL, NULL,
cb->resource = wl_resource_create(client, &wl_callback_interface,
CALLBACK_VERSION, callback);
if (cb->resource == NULL) {
free(cb);
wl_resource_post_no_memory(resource);
return;
}
wl_resource_set_implementation(cb->resource, NULL, cb,
callback_handle_resource_destroy); callback_handle_resource_destroy);
wl_list_insert(surface->pending->frame_callback_list.prev, &cb->link); wl_list_insert(surface->pending->frame_callback_list.prev,
wl_resource_get_link(callback_resource));
surface->pending->invalid |= WLR_SURFACE_INVALID_FRAME_CALLBACK_LIST; surface->pending->invalid |= WLR_SURFACE_INVALID_FRAME_CALLBACK_LIST;
} }
@ -549,9 +534,9 @@ static struct wlr_surface_state *surface_state_create(void) {
static void surface_state_destroy(struct wlr_surface_state *state) { static void surface_state_destroy(struct wlr_surface_state *state) {
surface_state_reset_buffer(state); surface_state_reset_buffer(state);
struct wlr_frame_callback *cb, *tmp; struct wl_resource *resource, *tmp;
wl_list_for_each_safe(cb, tmp, &state->frame_callback_list, link) { wl_resource_for_each_safe(resource, tmp, &state->frame_callback_list) {
wl_resource_destroy(cb->resource); wl_resource_destroy(resource);
} }
pixman_region32_fini(&state->surface_damage); pixman_region32_fini(&state->surface_damage);
@ -965,11 +950,11 @@ static inline int64_t timespec_to_msec(const struct timespec *a) {
void wlr_surface_send_frame_done(struct wlr_surface *surface, void wlr_surface_send_frame_done(struct wlr_surface *surface,
const struct timespec *when) { const struct timespec *when) {
struct wlr_frame_callback *cb, *cnext; struct wl_resource *resource, *tmp;
wl_list_for_each_safe(cb, cnext, &surface->current->frame_callback_list, wl_resource_for_each_safe(resource, tmp,
link) { &surface->current->frame_callback_list) {
wl_callback_send_done(cb->resource, timespec_to_msec(when)); wl_callback_send_done(resource, timespec_to_msec(when));
wl_resource_destroy(cb->resource); wl_resource_destroy(resource);
} }
} }