mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-04-27 22:39:34 +00:00
Merge branch 'surface-invalidation' into 'master'
surface_invalidation_v1: New protocol implementation See merge request wlroots/wlroots!3921
This commit is contained in:
commit
e1028c66cc
35
include/wlr/types/wlr_surface_invalidation_v1.h
Normal file
35
include/wlr/types/wlr_surface_invalidation_v1.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This an unstable interface of wlroots. No guarantees are made regarding the
|
||||
* future consistency of this API.
|
||||
*/
|
||||
#ifndef WLR_USE_UNSTABLE
|
||||
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
|
||||
#endif
|
||||
|
||||
#ifndef WLR_TYPES_WLR_SURFACE_INVALIDATION_V1_H
|
||||
#define WLR_TYPES_WLR_SURFACE_INVALIDATION_V1_H
|
||||
|
||||
#include <wayland-server-core.h>
|
||||
|
||||
struct wlr_surface;
|
||||
|
||||
struct wlr_surface_invalidation_manager_v1 {
|
||||
struct wl_global *global;
|
||||
|
||||
struct {
|
||||
struct wl_signal destroy;
|
||||
} events;
|
||||
|
||||
// private state
|
||||
|
||||
struct wl_listener display_destroy;
|
||||
};
|
||||
|
||||
struct wlr_surface_invalidation_manager_v1 *wlr_surface_invalidation_manager_v1_create(
|
||||
struct wl_display *display, uint32_t version);
|
||||
|
||||
bool wlr_surface_invalidation_manager_v1_invalidate(
|
||||
const struct wlr_surface_invalidation_manager_v1 *manager,
|
||||
struct wlr_surface *surface);
|
||||
|
||||
#endif
|
@ -38,6 +38,7 @@ protocols = {
|
||||
'linux-drm-syncobj-v1': wl_protocol_dir / 'staging/linux-drm-syncobj/linux-drm-syncobj-v1.xml',
|
||||
'security-context-v1': wl_protocol_dir / 'staging/security-context/security-context-v1.xml',
|
||||
'single-pixel-buffer-v1': wl_protocol_dir / 'staging/single-pixel-buffer/single-pixel-buffer-v1.xml',
|
||||
'surface-invalidation-v1': wl_protocol_dir / 'staging/surface-invalidation/surface-invalidation-v1.xml',
|
||||
'xdg-activation-v1': wl_protocol_dir / 'staging/xdg-activation/xdg-activation-v1.xml',
|
||||
'xdg-dialog-v1': wl_protocol_dir / 'staging/xdg-dialog/xdg-dialog-v1.xml',
|
||||
'xdg-system-bell-v1': wl_protocol_dir / 'staging/xdg-system-bell/xdg-system-bell-v1.xml',
|
||||
|
@ -81,6 +81,7 @@ wlr_files += files(
|
||||
'wlr_shm.c',
|
||||
'wlr_single_pixel_buffer_v1.c',
|
||||
'wlr_subcompositor.c',
|
||||
'wlr_surface_invalidation_v1.c',
|
||||
'wlr_switch.c',
|
||||
'wlr_tablet_pad.c',
|
||||
'wlr_tablet_tool.c',
|
||||
|
218
types/wlr_surface_invalidation_v1.c
Normal file
218
types/wlr_surface_invalidation_v1.c
Normal file
@ -0,0 +1,218 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <wlr/types/wlr_surface_invalidation_v1.h>
|
||||
#include <wlr/types/wlr_compositor.h>
|
||||
#include <wlr/util/addon.h>
|
||||
#include "surface-invalidation-v1-protocol.h"
|
||||
|
||||
#define SURFACE_INVALIDATION_MANAGER_VERSION 1
|
||||
|
||||
struct wlr_surface_invalidation_v1_configure {
|
||||
struct wl_list link; // struct wlr_surface_invalidation_v1.configures
|
||||
uint32_t serial;
|
||||
bool configured;
|
||||
};
|
||||
|
||||
struct wlr_surface_invalidation_v1 {
|
||||
struct wl_resource *resource;
|
||||
struct wl_list configures; // struct wlr_surface_invalidation_v1_configure.link
|
||||
bool inert;
|
||||
struct wlr_addon addon;
|
||||
};
|
||||
|
||||
static void surface_invalidation_v1_configure_destroy(
|
||||
struct wlr_surface_invalidation_v1_configure *configure) {
|
||||
wl_list_remove(&configure->link);
|
||||
free(configure);
|
||||
}
|
||||
|
||||
static const struct wp_surface_invalidation_v1_interface surface_inval_impl;
|
||||
|
||||
static struct wlr_surface_invalidation_v1 *surface_invalidation_v1_from_resource(
|
||||
struct wl_resource *resource) {
|
||||
assert(wl_resource_instance_of(resource, &wp_surface_invalidation_v1_interface,
|
||||
&surface_inval_impl));
|
||||
return wl_resource_get_user_data(resource);
|
||||
}
|
||||
|
||||
static void surface_handle_resource_destroy(struct wl_resource *resource) {
|
||||
struct wlr_surface_invalidation_v1 *surface =
|
||||
surface_invalidation_v1_from_resource(resource);
|
||||
if (!surface->inert) {
|
||||
wlr_addon_finish(&surface->addon);
|
||||
}
|
||||
|
||||
struct wlr_surface_invalidation_v1_configure *configure, *tmp_configure;
|
||||
wl_list_for_each_safe(configure, tmp_configure, &surface->configures, link) {
|
||||
surface_invalidation_v1_configure_destroy(configure);
|
||||
}
|
||||
|
||||
free(surface);
|
||||
}
|
||||
|
||||
static void surface_invalidation_handle_ack(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t serial) {
|
||||
struct wlr_surface_invalidation_v1 *surface =
|
||||
surface_invalidation_v1_from_resource(resource);
|
||||
|
||||
// First find the ack'ed configure
|
||||
bool found = false;
|
||||
struct wlr_surface_invalidation_v1_configure *configure, *tmp_configure;
|
||||
wl_list_for_each(configure, &surface->configures, link) {
|
||||
if (configure->serial == serial) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
/*
|
||||
TODO: What do we do here?
|
||||
wl_resource_post_error(resource,
|
||||
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SURFACE_STATE,
|
||||
"wrong configure serial: %" PRIu32, serial);
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
configure->configured = true;
|
||||
|
||||
// Then remove old configures from the list
|
||||
wl_list_for_each_safe(configure, tmp_configure, &surface->configures, link) {
|
||||
if (configure->serial == serial) {
|
||||
break;
|
||||
}
|
||||
surface_invalidation_v1_configure_destroy(configure);
|
||||
}
|
||||
}
|
||||
|
||||
static void destroy_resource(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static const struct wp_surface_invalidation_v1_interface surface_inval_impl = {
|
||||
.destroy = destroy_resource,
|
||||
.ack = surface_invalidation_handle_ack,
|
||||
};
|
||||
|
||||
static void surface_addon_handle_destroy(struct wlr_addon *addon) {
|
||||
struct wlr_surface_invalidation_v1 *surface = wl_container_of(addon, surface, addon);
|
||||
wlr_addon_finish(&surface->addon);
|
||||
surface->inert = true;
|
||||
}
|
||||
|
||||
static const struct wlr_addon_interface surface_addon_impl = {
|
||||
.name = "surface_invalidation_v1",
|
||||
.destroy = surface_addon_handle_destroy,
|
||||
};
|
||||
|
||||
static const struct wp_surface_invalidation_manager_v1_interface manager_impl;
|
||||
|
||||
static struct wlr_surface_invalidation_manager_v1 *manager_from_resource(
|
||||
struct wl_resource *resource) {
|
||||
assert(wl_resource_instance_of(resource, &wp_surface_invalidation_manager_v1_interface,
|
||||
&manager_impl));
|
||||
return wl_resource_get_user_data(resource);
|
||||
}
|
||||
|
||||
static void manager_handle_get_surface_invalidation(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource) {
|
||||
struct wlr_surface *wlr_surface = wlr_surface_from_resource(surface_resource);
|
||||
struct wlr_surface_invalidation_manager_v1 *manager = manager_from_resource(resource);
|
||||
|
||||
struct wlr_surface_invalidation_v1 *surface = calloc(1, sizeof(*surface));
|
||||
if (!surface) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
|
||||
surface->resource = wl_resource_create(client, &wp_surface_invalidation_v1_interface,
|
||||
wl_global_get_version(manager->global), id);
|
||||
if (!surface->resource) {
|
||||
wl_client_post_no_memory(client);
|
||||
free(surface);
|
||||
return;
|
||||
}
|
||||
|
||||
wl_list_init(&surface->configures);
|
||||
wlr_addon_init(&surface->addon, &wlr_surface->addons, manager, &surface_addon_impl);
|
||||
|
||||
wl_resource_set_implementation(surface->resource,
|
||||
&surface_inval_impl, surface, surface_handle_resource_destroy);
|
||||
}
|
||||
|
||||
static const struct wp_surface_invalidation_manager_v1_interface manager_impl = {
|
||||
.destroy = destroy_resource,
|
||||
.get_surface_invalidation = manager_handle_get_surface_invalidation,
|
||||
};
|
||||
|
||||
static void manager_bind(struct wl_client *client, void *data,
|
||||
uint32_t version, uint32_t id) {
|
||||
struct wlr_surface_invalidation_manager_v1 *manager = data;
|
||||
struct wl_resource *resource = wl_resource_create(client,
|
||||
&wp_surface_invalidation_manager_v1_interface, version, id);
|
||||
if (!resource) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(resource, &manager_impl, manager, NULL);
|
||||
}
|
||||
|
||||
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
||||
struct wlr_surface_invalidation_manager_v1 *manager =
|
||||
wl_container_of(listener, manager, display_destroy);
|
||||
wl_signal_emit_mutable(&manager->events.destroy, NULL);
|
||||
wl_global_destroy(manager->global);
|
||||
wl_list_remove(&manager->display_destroy.link);
|
||||
free(manager);
|
||||
}
|
||||
|
||||
struct wlr_surface_invalidation_manager_v1 *wlr_surface_invalidation_manager_v1_create(
|
||||
struct wl_display *display, uint32_t version) {
|
||||
assert(version <= SURFACE_INVALIDATION_MANAGER_VERSION);
|
||||
|
||||
struct wlr_surface_invalidation_manager_v1 *manager = calloc(1, sizeof(*manager));
|
||||
if (!manager) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
manager->global = wl_global_create(display, &wp_surface_invalidation_manager_v1_interface,
|
||||
version, manager, manager_bind);
|
||||
if (!manager->global) {
|
||||
free(manager);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
manager->display_destroy.notify = handle_display_destroy;
|
||||
wl_display_add_destroy_listener(display, &manager->display_destroy);
|
||||
|
||||
wl_signal_init(&manager->events.destroy);
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
bool wlr_surface_invalidation_manager_v1_invalidate(
|
||||
const struct wlr_surface_invalidation_manager_v1 *manager,
|
||||
struct wlr_surface *wlr_surface) {
|
||||
struct wlr_addon *addon = wlr_addon_find(
|
||||
&wlr_surface->addons, manager, &surface_addon_impl);
|
||||
if (!addon) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct wlr_surface_invalidation_v1 *surface =
|
||||
wl_container_of(addon, surface, addon);
|
||||
struct wl_display *display =
|
||||
wl_client_get_display(wl_resource_get_client(surface->resource));
|
||||
|
||||
struct wlr_surface_invalidation_v1_configure *configure = calloc(1, sizeof(*configure));
|
||||
if (!configure) {
|
||||
wl_client_post_no_memory(wl_resource_get_client(surface->resource));
|
||||
return false;
|
||||
}
|
||||
|
||||
configure->serial = wl_display_next_serial(display);
|
||||
wl_list_insert(surface->configures.prev, &configure->link);
|
||||
wp_surface_invalidation_v1_send_invalidated(surface->resource, configure->serial);
|
||||
return true;
|
||||
}
|
Loading…
Reference in New Issue
Block a user