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:
parent
21397e2b4a
commit
06f4c3945d
|
@ -82,7 +82,6 @@ struct wlr_gles2_texture {
|
||||||
|
|
||||||
EGLImageKHR image;
|
EGLImageKHR image;
|
||||||
|
|
||||||
int width, height;
|
|
||||||
bool inverted_y;
|
bool inverted_y;
|
||||||
bool has_alpha;
|
bool has_alpha;
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,6 @@ void wlr_renderer_init(struct wlr_renderer *renderer,
|
||||||
const struct wlr_renderer_impl *impl);
|
const struct wlr_renderer_impl *impl);
|
||||||
|
|
||||||
struct wlr_texture_impl {
|
struct wlr_texture_impl {
|
||||||
void (*get_size)(struct wlr_texture *texture, int *width, int *height);
|
|
||||||
bool (*is_opaque)(struct wlr_texture *texture);
|
bool (*is_opaque)(struct wlr_texture *texture);
|
||||||
bool (*write_pixels)(struct wlr_texture *texture,
|
bool (*write_pixels)(struct wlr_texture *texture,
|
||||||
uint32_t stride, uint32_t width, uint32_t height,
|
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,
|
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
|
#endif
|
||||||
|
|
|
@ -18,6 +18,7 @@ struct wlr_texture_impl;
|
||||||
|
|
||||||
struct wlr_texture {
|
struct wlr_texture {
|
||||||
const struct wlr_texture_impl *impl;
|
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.
|
* 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);
|
void wlr_texture_get_size(struct wlr_texture *texture, int *width, int *height);
|
||||||
|
|
||||||
|
|
|
@ -35,13 +35,6 @@ static struct wlr_gles2_texture *get_gles2_texture_in_context(
|
||||||
return texture;
|
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) {
|
static bool gles2_texture_is_opaque(struct wlr_texture *wlr_texture) {
|
||||||
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
|
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
|
||||||
return !texture->has_alpha;
|
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,
|
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) {
|
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 = {
|
static const struct wlr_texture_impl texture_impl = {
|
||||||
.get_size = gles2_texture_get_size,
|
|
||||||
.is_opaque = gles2_texture_is_opaque,
|
.is_opaque = gles2_texture_is_opaque,
|
||||||
.write_pixels = gles2_texture_write_pixels,
|
.write_pixels = gles2_texture_write_pixels,
|
||||||
.to_dmabuf = gles2_texture_to_dmabuf,
|
.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");
|
wlr_log(WLR_ERROR, "Allocation failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
wlr_texture_init(&texture->wlr_texture, &texture_impl);
|
wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height);
|
||||||
texture->egl = egl;
|
texture->egl = egl;
|
||||||
texture->width = width;
|
|
||||||
texture->height = height;
|
|
||||||
texture->target = GL_TEXTURE_2D;
|
texture->target = GL_TEXTURE_2D;
|
||||||
texture->has_alpha = fmt->has_alpha;
|
texture->has_alpha = fmt->has_alpha;
|
||||||
texture->wl_format = fmt->wl_format;
|
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 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)) {
|
if (!wlr_egl_is_current(egl)) {
|
||||||
wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
|
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;
|
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 =
|
struct wlr_gles2_texture *texture =
|
||||||
calloc(1, sizeof(struct wlr_gles2_texture));
|
calloc(1, sizeof(struct wlr_gles2_texture));
|
||||||
if (texture == NULL) {
|
if (texture == NULL) {
|
||||||
wlr_log(WLR_ERROR, "Allocation failed");
|
wlr_log(WLR_ERROR, "Allocation failed");
|
||||||
|
wlr_egl_destroy_image(egl, image);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
wlr_texture_init(&texture->wlr_texture, &texture_impl);
|
wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height);
|
||||||
texture->egl = egl;
|
texture->egl = egl;
|
||||||
|
|
||||||
EGLint fmt;
|
|
||||||
texture->wl_format = 0xFFFFFFFF; // texture can't be written anyways
|
texture->wl_format = 0xFFFFFFFF; // texture can't be written anyways
|
||||||
texture->image = wlr_egl_create_image_from_wl_drm(egl, data, &fmt,
|
texture->image = image;
|
||||||
&texture->width, &texture->height, &texture->inverted_y);
|
texture->inverted_y = inverted_y;
|
||||||
if (texture->image == NULL) {
|
|
||||||
free(texture);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case EGL_TEXTURE_RGB:
|
case EGL_TEXTURE_RGB:
|
||||||
|
@ -223,6 +219,7 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
wlr_log(WLR_ERROR, "Invalid or unsupported EGL buffer format");
|
wlr_log(WLR_ERROR, "Invalid or unsupported EGL buffer format");
|
||||||
|
wlr_egl_destroy_image(egl, image);
|
||||||
free(texture);
|
free(texture);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -275,10 +272,9 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
|
||||||
wlr_log(WLR_ERROR, "Allocation failed");
|
wlr_log(WLR_ERROR, "Allocation failed");
|
||||||
return NULL;
|
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->egl = egl;
|
||||||
texture->width = attribs->width;
|
|
||||||
texture->height = attribs->height;
|
|
||||||
texture->target = GL_TEXTURE_EXTERNAL_OES;
|
texture->target = GL_TEXTURE_EXTERNAL_OES;
|
||||||
texture->has_alpha = true;
|
texture->has_alpha = true;
|
||||||
texture->wl_format = 0xFFFFFFFF; // texture can't be written anyways
|
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;
|
(attribs->flags & WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT) != 0;
|
||||||
|
|
||||||
texture->image = wlr_egl_create_image_from_dmabuf(egl, attribs);
|
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);
|
free(texture);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,11 @@
|
||||||
#include <wlr/render/wlr_texture.h>
|
#include <wlr/render/wlr_texture.h>
|
||||||
|
|
||||||
void wlr_texture_init(struct wlr_texture *texture,
|
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) {
|
||||||
assert(impl->get_size);
|
|
||||||
assert(impl->write_pixels);
|
assert(impl->write_pixels);
|
||||||
texture->impl = impl;
|
texture->impl = impl;
|
||||||
|
texture->width = width;
|
||||||
|
texture->height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_texture_destroy(struct wlr_texture *texture) {
|
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,
|
void wlr_texture_get_size(struct wlr_texture *texture, int *width,
|
||||||
int *height) {
|
int *height) {
|
||||||
texture->impl->get_size(texture, width, height);
|
*width = texture->width;
|
||||||
|
*height = texture->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wlr_texture_is_opaque(struct wlr_texture *texture) {
|
bool wlr_texture_is_opaque(struct wlr_texture *texture) {
|
||||||
|
|
Loading…
Reference in New Issue