render/texture: add width and height fields

Instead of requiring compositors to call wlr_texture_get_size each time
they want to access the texture's size, expose this information as
wlr_texture fields.
This commit is contained in:
Simon Ser 2020-04-27 12:45:21 +02:00 committed by Drew DeVault
parent 21397e2b4a
commit 06f4c3945d
5 changed files with 32 additions and 31 deletions

View File

@ -82,7 +82,6 @@ struct wlr_gles2_texture {
EGLImageKHR image;
int width, height;
bool inverted_y;
bool has_alpha;

View File

@ -70,7 +70,6 @@ void wlr_renderer_init(struct wlr_renderer *renderer,
const struct wlr_renderer_impl *impl);
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,
uint32_t stride, uint32_t width, uint32_t height,
@ -82,6 +81,6 @@ struct wlr_texture_impl {
};
void wlr_texture_init(struct wlr_texture *texture,
const struct wlr_texture_impl *impl);
const struct wlr_texture_impl *impl, uint32_t width, uint32_t height);
#endif

View File

@ -18,6 +18,7 @@ struct wlr_texture_impl;
struct wlr_texture {
const struct wlr_texture_impl *impl;
uint32_t width, height;
};
/**
@ -43,6 +44,9 @@ struct wlr_texture *wlr_texture_from_dmabuf(struct wlr_renderer *renderer,
/**
* Get the texture width and height.
*
* This function is deprecated. Access wlr_texture's width and height fields
* directly instead.
*/
void wlr_texture_get_size(struct wlr_texture *texture, int *width, int *height);

View File

@ -35,13 +35,6 @@ static struct wlr_gles2_texture *get_gles2_texture_in_context(
return texture;
}
static void gles2_texture_get_size(struct wlr_texture *wlr_texture, int *width,
int *height) {
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
*width = texture->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;
@ -110,7 +103,7 @@ static bool gles2_texture_to_dmabuf(struct wlr_texture *wlr_texture,
}
return wlr_egl_export_image_to_dmabuf(texture->egl, texture->image,
texture->width, texture->height, flags, attribs);
wlr_texture->width, wlr_texture->height, flags, attribs);
}
static void gles2_texture_destroy(struct wlr_texture *wlr_texture) {
@ -135,7 +128,6 @@ 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,
@ -161,10 +153,8 @@ struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl,
wlr_log(WLR_ERROR, "Allocation failed");
return NULL;
}
wlr_texture_init(&texture->wlr_texture, &texture_impl);
wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height);
texture->egl = egl;
texture->width = width;
texture->height = height;
texture->target = GL_TEXTURE_2D;
texture->has_alpha = fmt->has_alpha;
texture->wl_format = fmt->wl_format;
@ -186,7 +176,7 @@ struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl,
}
struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
struct wl_resource *data) {
struct wl_resource *resource) {
if (!wlr_egl_is_current(egl)) {
wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
}
@ -195,23 +185,29 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
return NULL;
}
EGLint fmt;
int width, height;
bool inverted_y;
EGLImageKHR image = wlr_egl_create_image_from_wl_drm(egl, resource,
&fmt, &width, &height, &inverted_y);
if (image == EGL_NO_IMAGE_KHR) {
wlr_log(WLR_ERROR, "Failed to create EGL image from wl_drm resource");
return NULL;
}
struct wlr_gles2_texture *texture =
calloc(1, sizeof(struct wlr_gles2_texture));
if (texture == NULL) {
wlr_log(WLR_ERROR, "Allocation failed");
wlr_egl_destroy_image(egl, image);
return NULL;
}
wlr_texture_init(&texture->wlr_texture, &texture_impl);
wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height);
texture->egl = egl;
EGLint fmt;
texture->wl_format = 0xFFFFFFFF; // texture can't be written anyways
texture->image = wlr_egl_create_image_from_wl_drm(egl, data, &fmt,
&texture->width, &texture->height, &texture->inverted_y);
if (texture->image == NULL) {
free(texture);
return NULL;
}
texture->image = image;
texture->inverted_y = inverted_y;
switch (fmt) {
case EGL_TEXTURE_RGB:
@ -223,6 +219,7 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
break;
default:
wlr_log(WLR_ERROR, "Invalid or unsupported EGL buffer format");
wlr_egl_destroy_image(egl, image);
free(texture);
return NULL;
}
@ -275,10 +272,9 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
wlr_log(WLR_ERROR, "Allocation failed");
return NULL;
}
wlr_texture_init(&texture->wlr_texture, &texture_impl);
wlr_texture_init(&texture->wlr_texture, &texture_impl,
attribs->width, attribs->height);
texture->egl = egl;
texture->width = attribs->width;
texture->height = attribs->height;
texture->target = GL_TEXTURE_EXTERNAL_OES;
texture->has_alpha = true;
texture->wl_format = 0xFFFFFFFF; // texture can't be written anyways
@ -286,7 +282,8 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
(attribs->flags & WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT) != 0;
texture->image = wlr_egl_create_image_from_dmabuf(egl, attribs);
if (texture->image == NULL) {
if (texture->image == EGL_NO_IMAGE_KHR) {
wlr_log(WLR_ERROR, "Failed to create EGL image from DMA-BUF");
free(texture);
return NULL;
}

View File

@ -5,10 +5,11 @@
#include <wlr/render/wlr_texture.h>
void wlr_texture_init(struct wlr_texture *texture,
const struct wlr_texture_impl *impl) {
assert(impl->get_size);
const struct wlr_texture_impl *impl, uint32_t width, uint32_t height) {
assert(impl->write_pixels);
texture->impl = impl;
texture->width = width;
texture->height = height;
}
void wlr_texture_destroy(struct wlr_texture *texture) {
@ -44,7 +45,8 @@ struct wlr_texture *wlr_texture_from_dmabuf(struct wlr_renderer *renderer,
void wlr_texture_get_size(struct wlr_texture *texture, int *width,
int *height) {
texture->impl->get_size(texture, width, height);
*width = texture->width;
*height = texture->height;
}
bool wlr_texture_is_opaque(struct wlr_texture *texture) {