mirror of
https://gitlab.freedesktop.org/wayland/weston.git
synced 2026-06-10 03:18:29 +02:00
libweston: Use a string for storing surface label
This is an alternative to using set_label_func to avoid using get_label() callback. get_label() is inconvenient to set up and to call. It incurs the cost of creating the string every time it is needed. During debug logging, the string is needed much more often than it changes. The new label field simply stores the string, making it easy and cheap to use. As the trade-off, components that set the label string must re-create the string when it changes, whether it is needed or not. For the migration to the new label field, get_label_member callback is used. It will be deleted once the migration is done. Signed-off-by: Marius Vlad <marius.vlad@collabora.com> Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
parent
03a081f2c8
commit
2e61633b32
2 changed files with 56 additions and 1 deletions
|
|
@ -1976,6 +1976,11 @@ struct weston_surface {
|
|||
void *committed_private;
|
||||
int (*get_label)(struct weston_surface *surface, char *buf, size_t len);
|
||||
|
||||
/** human-readable, non-unique label */
|
||||
const char *label;
|
||||
/** freed when changing the label */
|
||||
char *label_dyn;
|
||||
|
||||
/*
|
||||
* Sent when the surface has been mapped and unmapped, respectively.
|
||||
* The data argument is the weston_surface.
|
||||
|
|
@ -2402,6 +2407,11 @@ void
|
|||
weston_surface_set_label_func(struct weston_surface *surface,
|
||||
int (*desc)(struct weston_surface *,
|
||||
char *, size_t));
|
||||
void
|
||||
weston_surface_set_label(struct weston_surface *surface, char *label);
|
||||
|
||||
void
|
||||
weston_surface_set_label_static(struct weston_surface *surface, const char *label);
|
||||
|
||||
void
|
||||
weston_surface_get_content_size(struct weston_surface *surface,
|
||||
|
|
|
|||
|
|
@ -976,7 +976,7 @@ weston_surface_update_preferred_color_profile(struct weston_surface *surface)
|
|||
static int
|
||||
get_label_member(struct weston_surface *surface, char *buf, size_t len)
|
||||
{
|
||||
return snprintf(buf, len, "(no label)");
|
||||
return snprintf(buf, len, "%s", surface->label);
|
||||
}
|
||||
|
||||
WL_EXPORT struct weston_surface *
|
||||
|
|
@ -1053,6 +1053,9 @@ weston_surface_create(struct weston_compositor *compositor,
|
|||
|
||||
wl_list_init(&surface->fifo_barrier_link);
|
||||
|
||||
/* Set default label */
|
||||
weston_surface_set_label(surface, NULL);
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
|
|
@ -2787,6 +2790,8 @@ weston_surface_unref(struct weston_surface *surface)
|
|||
wl_list_remove(&surface->fifo_barrier_link);
|
||||
|
||||
free(surface->internal_name);
|
||||
|
||||
free(surface->label_dyn);
|
||||
free(surface);
|
||||
}
|
||||
|
||||
|
|
@ -5452,6 +5457,46 @@ weston_surface_set_label_func(struct weston_surface *surface,
|
|||
surface);
|
||||
}
|
||||
|
||||
static void
|
||||
weston_surface_do_set_label(struct weston_surface *surface,
|
||||
char *label_dyn,
|
||||
const char *label_static)
|
||||
{
|
||||
free(surface->label_dyn);
|
||||
surface->label_dyn = label_dyn;
|
||||
|
||||
if (label_static)
|
||||
surface->label = label_static;
|
||||
else
|
||||
surface->label = "(no label)";
|
||||
|
||||
weston_timeline_refresh_subscription_objects(surface->compositor, surface);
|
||||
}
|
||||
/**
|
||||
* Set a human-readable label on a surface, malloc'd
|
||||
*
|
||||
* \param surface The surface to label.
|
||||
* \param label A malloc'd string. This function takes the ownership of the
|
||||
* string and will free() it as necessary. Can be NULL to remove the label.
|
||||
*/
|
||||
WL_EXPORT void
|
||||
weston_surface_set_label(struct weston_surface *surface, char *label)
|
||||
{
|
||||
weston_surface_do_set_label(surface, label, label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a human-readable label on a surface, static
|
||||
*
|
||||
* \param surface The surface to label.
|
||||
* \param label A static string, never free()'d. Can be NULL to remove the label.
|
||||
*/
|
||||
WL_EXPORT void
|
||||
weston_surface_set_label_static(struct weston_surface *surface, const char *label)
|
||||
{
|
||||
weston_surface_do_set_label(surface, NULL, label);
|
||||
}
|
||||
|
||||
/** Get the size of surface contents
|
||||
*
|
||||
* \param surface The surface to query.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue