1 #include <assert.h>
2 #include <stdbool.h>
3 #include <stdlib.h>
4 #include <wlr/render/interface.h>
5 #include <wlr/render/wlr_texture.h>
6
wlr_texture_init(struct wlr_texture * texture,const struct wlr_texture_impl * impl,uint32_t width,uint32_t height)7 void wlr_texture_init(struct wlr_texture *texture,
8 const struct wlr_texture_impl *impl, uint32_t width, uint32_t height) {
9 texture->impl = impl;
10 texture->width = width;
11 texture->height = height;
12 }
13
wlr_texture_destroy(struct wlr_texture * texture)14 void wlr_texture_destroy(struct wlr_texture *texture) {
15 if (texture && texture->impl && texture->impl->destroy) {
16 texture->impl->destroy(texture);
17 } else {
18 free(texture);
19 }
20 }
21
wlr_texture_from_pixels(struct wlr_renderer * renderer,enum wl_shm_format wl_fmt,uint32_t stride,uint32_t width,uint32_t height,const void * data)22 struct wlr_texture *wlr_texture_from_pixels(struct wlr_renderer *renderer,
23 enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width,
24 uint32_t height, const void *data) {
25 return renderer->impl->texture_from_pixels(renderer, wl_fmt, stride, width,
26 height, data);
27 }
28
wlr_texture_from_wl_drm(struct wlr_renderer * renderer,struct wl_resource * data)29 struct wlr_texture *wlr_texture_from_wl_drm(struct wlr_renderer *renderer,
30 struct wl_resource *data) {
31 if (!renderer->impl->texture_from_wl_drm) {
32 return NULL;
33 }
34 return renderer->impl->texture_from_wl_drm(renderer, data);
35 }
36
wlr_texture_from_dmabuf(struct wlr_renderer * renderer,struct wlr_dmabuf_attributes * attribs)37 struct wlr_texture *wlr_texture_from_dmabuf(struct wlr_renderer *renderer,
38 struct wlr_dmabuf_attributes *attribs) {
39 if (!renderer->impl->texture_from_dmabuf) {
40 return NULL;
41 }
42 return renderer->impl->texture_from_dmabuf(renderer, attribs);
43 }
44
wlr_texture_get_size(struct wlr_texture * texture,int * width,int * height)45 void wlr_texture_get_size(struct wlr_texture *texture, int *width,
46 int *height) {
47 *width = texture->width;
48 *height = texture->height;
49 }
50
wlr_texture_is_opaque(struct wlr_texture * texture)51 bool wlr_texture_is_opaque(struct wlr_texture *texture) {
52 if (!texture->impl->is_opaque) {
53 return false;
54 }
55 return texture->impl->is_opaque(texture);
56 }
57
wlr_texture_write_pixels(struct wlr_texture * texture,uint32_t stride,uint32_t width,uint32_t height,uint32_t src_x,uint32_t src_y,uint32_t dst_x,uint32_t dst_y,const void * data)58 bool wlr_texture_write_pixels(struct wlr_texture *texture,
59 uint32_t stride, uint32_t width, uint32_t height,
60 uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y,
61 const void *data) {
62 if (!texture->impl->write_pixels) {
63 return false;
64 }
65 return texture->impl->write_pixels(texture, stride, width, height,
66 src_x, src_y, dst_x, dst_y, data);
67 }
68
wlr_texture_to_dmabuf(struct wlr_texture * texture,struct wlr_dmabuf_attributes * attribs)69 bool wlr_texture_to_dmabuf(struct wlr_texture *texture,
70 struct wlr_dmabuf_attributes *attribs) {
71 if (!texture->impl->to_dmabuf) {
72 return false;
73 }
74 return texture->impl->to_dmabuf(texture, attribs);
75 }
76