refactor buffer detection

This commit is contained in:
Tony Crisci 2017-10-22 21:07:32 -04:00
parent 53174f3d61
commit d1dd0a6970
4 changed files with 19 additions and 8 deletions

View File

@ -109,6 +109,14 @@ void wlr_surface_get_matrix(struct wlr_surface *surface,
int wlr_surface_set_role(struct wlr_surface *surface, const char *role, int wlr_surface_set_role(struct wlr_surface *surface, const char *role,
struct wl_resource *error_resource, uint32_t error_code); struct wl_resource *error_resource, uint32_t error_code);
/**
* Whether or not this surface currently has an attached buffer. A surface has
* an attached buffer when it commits with a non-null buffer in its pending
* state. A surface will not have a buffer if it has never committed one, has
* committed a null buffer, or something went wrong with uploading the buffer.
*/
bool wlr_surface_has_buffer(struct wlr_surface *surface);
/** /**
* Create the subsurface implementation for this surface. * Create the subsurface implementation for this surface.
*/ */

View File

@ -655,6 +655,10 @@ void wlr_surface_get_matrix(struct wlr_surface *surface,
wlr_matrix_mul(projection, matrix, matrix); wlr_matrix_mul(projection, matrix, matrix);
} }
bool wlr_surface_has_buffer(struct wlr_surface *surface) {
return surface->texture && surface->texture->valid;
}
int wlr_surface_set_role(struct wlr_surface *surface, const char *role, int wlr_surface_set_role(struct wlr_surface *surface, const char *role,
struct wl_resource *error_resource, uint32_t error_code) { struct wl_resource *error_resource, uint32_t error_code) {
assert(role); assert(role);

View File

@ -8,7 +8,6 @@
#include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_wl_shell.h>
#include <stdlib.h> #include <stdlib.h>
#include <wayland-server-protocol.h> #include <wayland-server-protocol.h>
#include <wlr/render/interface.h>
static const char *wlr_wl_shell_surface_role = "wl-shell-surface"; static const char *wlr_wl_shell_surface_role = "wl-shell-surface";
@ -482,7 +481,7 @@ static void handle_wlr_surface_committed(struct wl_listener *listener,
struct wlr_wl_shell_surface *surface = struct wlr_wl_shell_surface *surface =
wl_container_of(listener, surface, surface_commit_listener); wl_container_of(listener, surface, surface_commit_listener);
if (!surface->configured && if (!surface->configured &&
surface->surface->texture->valid && wlr_surface_has_buffer(surface->surface) &&
surface->state != WLR_WL_SHELL_SURFACE_STATE_NONE) { surface->state != WLR_WL_SHELL_SURFACE_STATE_NONE) {
surface->configured = true; surface->configured = true;
wl_signal_emit(&surface->shell->events.new_surface, surface); wl_signal_emit(&surface->shell->events.new_surface, surface);
@ -490,7 +489,7 @@ static void handle_wlr_surface_committed(struct wl_listener *listener,
if (surface->popup_mapped && if (surface->popup_mapped &&
surface->state == WLR_WL_SHELL_SURFACE_STATE_POPUP && surface->state == WLR_WL_SHELL_SURFACE_STATE_POPUP &&
!surface->surface->texture->valid) { !wlr_surface_has_buffer(surface->surface)) {
surface->popup_mapped = false; surface->popup_mapped = false;
struct wlr_wl_shell_popup_grab *grab = struct wlr_wl_shell_popup_grab *grab =
shell_popup_grab_from_seat(surface->shell, shell_popup_grab_from_seat(surface->shell,

View File

@ -9,7 +9,6 @@
#include <wlr/types/wlr_surface.h> #include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_seat.h> #include <wlr/types/wlr_seat.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/render/interface.h>
#include "xdg-shell-unstable-v6-protocol.h" #include "xdg-shell-unstable-v6-protocol.h"
static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel"; static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel";
@ -1018,7 +1017,8 @@ static void wlr_xdg_surface_v6_toplevel_committed(
struct wlr_xdg_surface_v6 *surface) { struct wlr_xdg_surface_v6 *surface) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
if (!surface->surface->texture->valid && !surface->toplevel_state->added) { if (!wlr_surface_has_buffer(surface->surface)
&& !surface->toplevel_state->added) {
// on the first commit, send a configure request to tell the client it // on the first commit, send a configure request to tell the client it
// is added // is added
wlr_xdg_surface_v6_schedule_configure(surface); wlr_xdg_surface_v6_schedule_configure(surface);
@ -1026,7 +1026,7 @@ static void wlr_xdg_surface_v6_toplevel_committed(
return; return;
} }
if (!surface->surface->texture->valid) { if (!wlr_surface_has_buffer(surface->surface)) {
return; return;
} }
@ -1048,7 +1048,7 @@ static void handle_wlr_surface_committed(struct wl_listener *listener,
struct wlr_xdg_surface_v6 *surface = struct wlr_xdg_surface_v6 *surface =
wl_container_of(listener, surface, surface_commit_listener); wl_container_of(listener, surface, surface_commit_listener);
if (surface->surface->texture->valid && !surface->configured) { if (wlr_surface_has_buffer(surface->surface) && !surface->configured) {
wl_resource_post_error(surface->resource, wl_resource_post_error(surface->resource,
ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
"xdg_surface has never been configured"); "xdg_surface has never been configured");
@ -1117,7 +1117,7 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
&zxdg_surface_v6_interface, wl_resource_get_version(client_resource), &zxdg_surface_v6_interface, wl_resource_get_version(client_resource),
id); id);
if (surface->surface->texture->valid) { if (wlr_surface_has_buffer(surface->surface)) {
wl_resource_post_error(surface->resource, wl_resource_post_error(surface->resource,
ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
"xdg_surface must not have a buffer at creation"); "xdg_surface must not have a buffer at creation");