render/texture: drop wlr_texture_is_opaque

Whether a texture is opaque or not doesn't depend on the renderer
at all, it just depends on the source buffer. Instead of forcing
all renderers to implement wlr_texture_impl.is_opaque, let's move
this in common code and use the wlr_buffer format to know whether
a texture will be opaque.
This commit is contained in:
Simon Ser 2022-06-16 14:43:24 +02:00
parent f28c0e2046
commit 29291cb47c
10 changed files with 42 additions and 35 deletions

View file

@ -237,6 +237,32 @@ struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource) {
return buffer;
}
bool buffer_is_opaque(struct wlr_buffer *buffer) {
void *data;
uint32_t format;
size_t stride;
struct wlr_dmabuf_attributes dmabuf;
struct wlr_shm_attributes shm;
if (wlr_buffer_get_dmabuf(buffer, &dmabuf)) {
format = dmabuf.format;
} else if (wlr_buffer_get_shm(buffer, &shm)) {
format = shm.format;
} else if (wlr_buffer_begin_data_ptr_access(buffer,
WLR_BUFFER_DATA_PTR_ACCESS_READ, &data, &format, &stride)) {
wlr_buffer_end_data_ptr_access(buffer);
} else {
return false;
}
const struct wlr_pixel_format_info *format_info =
drm_get_pixel_format_info(format);
if (format_info == NULL) {
return false;
}
return !format_info->has_alpha;
}
struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer,
struct wlr_renderer *renderer) {
struct wlr_texture *texture = wlr_texture_from_buffer(renderer, buffer);

View file

@ -10,6 +10,7 @@
#include <wlr/types/wlr_output.h>
#include <wlr/util/log.h>
#include <wlr/util/region.h>
#include "types/wlr_buffer.h"
#include "types/wlr_region.h"
#include "util/signal.h"
#include "util/time.h"
@ -336,9 +337,12 @@ static void surface_apply_damage(struct wlr_surface *surface) {
wlr_buffer_unlock(&surface->buffer->base);
}
surface->buffer = NULL;
surface->opaque = false;
return;
}
surface->opaque = buffer_is_opaque(surface->current.buffer);
if (surface->buffer != NULL) {
if (wlr_client_buffer_apply_damage(surface->buffer,
surface->current.buffer, &surface->buffer_damage)) {
@ -372,7 +376,7 @@ static void surface_update_opaque_region(struct wlr_surface *surface) {
return;
}
if (wlr_texture_is_opaque(texture)) {
if (surface->opaque) {
pixman_region32_init_rect(&surface->opaque_region,
0, 0, surface->current.width, surface->current.height);
return;