Merge pull request #1130 from emersion/surface-opaque

Add wlr_surface.opaque_region
master
Drew DeVault 6 years ago committed by GitHub
commit 3ae423b0e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -56,6 +56,7 @@ void wlr_renderer_init(struct wlr_renderer *renderer,
struct wlr_texture_impl {
void (*get_size)(struct wlr_texture *texture, int *width, int *height);
bool (*is_opaque)(struct wlr_texture *texture);
bool (*write_pixels)(struct wlr_texture *texture,
enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width,
uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x,

@ -40,6 +40,11 @@ struct wlr_texture *wlr_texture_from_dmabuf(struct wlr_renderer *renderer,
*/
void wlr_texture_get_size(struct wlr_texture *texture, int *width, int *height);
/**
* Returns true if this texture is using a fully opaque format.
*/
bool wlr_texture_is_opaque(struct wlr_texture *texture);
/**
* Update a texture with raw pixels. The texture must be mutable.
*/

@ -66,6 +66,12 @@ struct wlr_surface {
* just like the buffer's texture.
*/
pixman_region32_t buffer_damage;
/**
* The current opaque region, in surface-local coordinates. It is clipped to
* the surface bounds. If the surface's buffer is using a fully opaque
* format, this is set to the whole surface.
*/
pixman_region32_t opaque_region;
/**
* `current` contains the current, committed surface state. `pending`
* accumulates state changes from the client between commits and shouldn't

@ -36,6 +36,11 @@ static void gles2_texture_get_size(struct wlr_texture *wlr_texture, int *width,
*height = texture->height;
}
static bool gles2_texture_is_opaque(struct wlr_texture *wlr_texture) {
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
return !texture->has_alpha;
}
static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width,
uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x,
@ -129,6 +134,7 @@ static void gles2_texture_destroy(struct wlr_texture *wlr_texture) {
static const struct wlr_texture_impl texture_impl = {
.get_size = gles2_texture_get_size,
.is_opaque = gles2_texture_is_opaque,
.write_pixels = gles2_texture_write_pixels,
.to_dmabuf = gles2_texture_to_dmabuf,
.destroy = gles2_texture_destroy,

@ -47,6 +47,13 @@ void wlr_texture_get_size(struct wlr_texture *texture, int *width,
return texture->impl->get_size(texture, width, height);
}
bool wlr_texture_is_opaque(struct wlr_texture *texture) {
if (!texture->impl->is_opaque) {
return false;
}
return texture->impl->is_opaque(texture);
}
bool wlr_texture_write_pixels(struct wlr_texture *texture,
enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width,
uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x,

@ -340,6 +340,25 @@ static void surface_apply_damage(struct wlr_surface *surface) {
surface->buffer = buffer;
}
static void surface_update_opaque_region(struct wlr_surface *surface) {
struct wlr_texture *texture = wlr_surface_get_texture(surface);
if (texture == NULL) {
pixman_region32_clear(&surface->opaque_region);
return;
}
if (wlr_texture_is_opaque(texture)) {
pixman_region32_init_rect(&surface->opaque_region,
0, 0, surface->current.width, surface->current.height);
return;
}
pixman_region32_copy(&surface->opaque_region, &surface->current.opaque);
pixman_region32_intersect_rect(&surface->opaque_region,
&surface->opaque_region,
0, 0, surface->current.width, surface->current.height);
}
static void surface_commit_pending(struct wlr_surface *surface) {
bool invalid_buffer = surface->pending.committed & WLR_SURFACE_STATE_BUFFER;
@ -356,6 +375,7 @@ static void surface_commit_pending(struct wlr_surface *surface) {
if (invalid_buffer) {
surface_apply_damage(surface);
}
surface_update_opaque_region(surface);
// commit subsurface order
struct wlr_subsurface *subsurface;
@ -562,6 +582,7 @@ static void surface_handle_resource_destroy(struct wl_resource *resource) {
surface_state_finish(&surface->current);
surface_state_finish(&surface->previous);
pixman_region32_fini(&surface->buffer_damage);
pixman_region32_fini(&surface->opaque_region);
wlr_buffer_unref(surface->buffer);
free(surface);
}
@ -607,6 +628,7 @@ struct wlr_surface *wlr_surface_create(struct wl_client *client,
wl_list_init(&surface->subsurfaces);
wl_list_init(&surface->subsurface_pending_list);
pixman_region32_init(&surface->buffer_damage);
pixman_region32_init(&surface->opaque_region);
wl_signal_add(&renderer->events.destroy, &surface->renderer_destroy);
surface->renderer_destroy.notify = surface_handle_renderer_destroy;

Loading…
Cancel
Save