mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-21 22:52:20 +00:00
Merge branch 'master' into screencontent
This commit is contained in:
commit
21928cbe61
@ -96,7 +96,7 @@ not use GNU extensions.
|
||||
Brackets always go on the same line, including in functions.
|
||||
Always include brackets for if/while/for, even if it's a single statement.
|
||||
```c
|
||||
void function() {
|
||||
void function(void) {
|
||||
if (condition1) {
|
||||
do_thing1();
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) {
|
||||
}
|
||||
|
||||
static bool drm_connector_export_dmabuf(struct wlr_output *output,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs) {
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
|
||||
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
|
||||
|
||||
|
@ -160,23 +160,22 @@ void post_drm_surface(struct wlr_drm_surface *surf) {
|
||||
}
|
||||
}
|
||||
|
||||
bool export_drm_bo(struct gbm_bo *bo,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs) {
|
||||
memset(attribs, 0, sizeof(struct wlr_dmabuf_buffer_attribs));
|
||||
bool export_drm_bo(struct gbm_bo *bo, struct wlr_dmabuf_attributes *attribs) {
|
||||
memset(attribs, 0, sizeof(struct wlr_dmabuf_attributes));
|
||||
|
||||
attribs->n_planes = gbm_bo_get_plane_count(bo);
|
||||
if (attribs->n_planes > WLR_LINUX_DMABUF_MAX_PLANES) {
|
||||
if (attribs->n_planes > WLR_DMABUF_MAX_PLANES) {
|
||||
return false;
|
||||
}
|
||||
|
||||
attribs->width = gbm_bo_get_width(bo);
|
||||
attribs->height = gbm_bo_get_height(bo);
|
||||
attribs->format = gbm_bo_get_format(bo);
|
||||
attribs->modifier = gbm_bo_get_modifier(bo);
|
||||
|
||||
for (int i = 0; i < attribs->n_planes; ++i) {
|
||||
attribs->offset[i] = gbm_bo_get_offset(bo, i);
|
||||
attribs->stride[i] = gbm_bo_get_stride_for_plane(bo, i);
|
||||
attribs->modifier[i] = gbm_bo_get_modifier(bo);
|
||||
attribs->fd[i] = gbm_bo_get_fd(bo);
|
||||
if (attribs->fd[i] < 0) {
|
||||
for (int j = 0; j < i; ++j) {
|
||||
@ -215,7 +214,7 @@ static struct wlr_texture *get_tex_for_bo(struct wlr_drm_renderer *renderer,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_dmabuf_buffer_attribs attribs;
|
||||
struct wlr_dmabuf_attributes attribs;
|
||||
if (!export_drm_bo(bo, &attribs)) {
|
||||
free(tex);
|
||||
return NULL;
|
||||
|
@ -149,7 +149,7 @@ static void draw(void) {
|
||||
demo.last_frame = ts;
|
||||
}
|
||||
|
||||
static void draw_popup() {
|
||||
static void draw_popup(void) {
|
||||
static float alpha_mod = -0.01;
|
||||
|
||||
eglMakeCurrent(egl.display, popup_egl_surface, popup_egl_surface, egl.context);
|
||||
@ -188,7 +188,7 @@ static void xdg_popup_configure(void *data, struct xdg_popup *xdg_popup,
|
||||
}
|
||||
}
|
||||
|
||||
static void popup_destroy() {
|
||||
static void popup_destroy(void) {
|
||||
wlr_egl_destroy_surface(&egl, popup_egl_surface);
|
||||
wl_egl_window_destroy(popup_egl_window);
|
||||
xdg_popup_destroy(popup);
|
||||
|
@ -284,7 +284,7 @@ int main(int argc, char *argv[]) {
|
||||
wl_display_run(display);
|
||||
|
||||
wlr_texture_destroy(state.cat_texture);
|
||||
wlr_renderer_destroy(state.renderer);
|
||||
|
||||
wlr_output_layout_destroy(state.layout);
|
||||
wl_display_destroy(state.display);
|
||||
}
|
||||
|
@ -268,6 +268,5 @@ int main(int argc, char *argv[]) {
|
||||
wl_display_run(display);
|
||||
|
||||
wlr_texture_destroy(state.cat_texture);
|
||||
wlr_renderer_destroy(state.renderer);
|
||||
wl_display_destroy(display);
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ void new_input_notify(struct wl_listener *listener, void *data) {
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
wlr_log_init(L_DEBUG, NULL);
|
||||
struct wl_display *display = wl_display_create();
|
||||
struct sample_state state = {
|
||||
|
@ -372,6 +372,5 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
wl_display_run(display);
|
||||
|
||||
wlr_renderer_destroy(state.renderer);
|
||||
wl_display_destroy(display);
|
||||
}
|
||||
|
@ -277,6 +277,5 @@ int main(int argc, char *argv[]) {
|
||||
wl_display_run(display);
|
||||
|
||||
wlr_texture_destroy(state.cat_texture);
|
||||
wlr_renderer_destroy(state.renderer);
|
||||
wl_display_destroy(display);
|
||||
}
|
||||
|
@ -52,7 +52,6 @@ struct gbm_bo *get_drm_surface_front(struct wlr_drm_surface *surf);
|
||||
void post_drm_surface(struct wlr_drm_surface *surf);
|
||||
struct gbm_bo *copy_drm_surface_mgpu(struct wlr_drm_surface *dest,
|
||||
struct gbm_bo *src);
|
||||
bool export_drm_bo(struct gbm_bo *bo,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs);
|
||||
bool export_drm_bo(struct gbm_bo *bo, struct wlr_dmabuf_attributes *attribs);
|
||||
|
||||
#endif
|
||||
|
@ -24,7 +24,7 @@ struct wlr_output_impl {
|
||||
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b);
|
||||
uint32_t (*get_gamma_size)(struct wlr_output *output);
|
||||
bool (*export_dmabuf)(struct wlr_output *output,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs);
|
||||
struct wlr_dmabuf_attributes *attribs);
|
||||
};
|
||||
|
||||
void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
|
||||
|
36
include/wlr/render/dmabuf.h
Normal file
36
include/wlr/render/dmabuf.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef WLR_RENDER_DMABUF_H
|
||||
#define WLR_RENDER_DMABUF_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// So we don't have to pull in linux specific drm headers
|
||||
#ifndef DRM_FORMAT_MOD_INVALID
|
||||
#define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
|
||||
#endif
|
||||
|
||||
#define WLR_DMABUF_MAX_PLANES 4
|
||||
|
||||
enum wlr_dmabuf_attributes_flags {
|
||||
WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT = 1,
|
||||
WLR_DMABUF_ATTRIBUTES_FLAGS_INTERLACED = 2,
|
||||
WLR_DMABUF_ATTRIBUTES_FLAGS_BOTTOM_FIRST = 4,
|
||||
};
|
||||
|
||||
struct wlr_dmabuf_attributes {
|
||||
int32_t width, height;
|
||||
uint32_t format;
|
||||
uint32_t flags; // enum wlr_dmabuf_attributes_flags
|
||||
uint64_t modifier;
|
||||
|
||||
int n_planes;
|
||||
uint32_t offset[WLR_DMABUF_MAX_PLANES];
|
||||
uint32_t stride[WLR_DMABUF_MAX_PLANES];
|
||||
int fd[WLR_DMABUF_MAX_PLANES];
|
||||
};
|
||||
|
||||
/**
|
||||
* Closes all file descriptors in the DMA-BUF attributes.
|
||||
*/
|
||||
void wlr_dmabuf_attributes_finish(struct wlr_dmabuf_attributes *attribs);
|
||||
|
||||
#endif
|
@ -6,7 +6,7 @@
|
||||
#include <pixman.h>
|
||||
#include <stdbool.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_linux_dmabuf.h>
|
||||
#include <wlr/render/dmabuf.h>
|
||||
|
||||
struct wlr_egl {
|
||||
EGLDisplay display;
|
||||
@ -66,14 +66,14 @@ EGLImageKHR wlr_egl_create_image_from_wl_drm(struct wlr_egl *egl,
|
||||
* of the dmabuf with wlr_egl_check_import_dmabuf once first.
|
||||
*/
|
||||
EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
|
||||
struct wlr_dmabuf_buffer_attribs *attributes);
|
||||
struct wlr_dmabuf_attributes *attributes);
|
||||
|
||||
/**
|
||||
* Try to import the given dmabuf. On success return true false otherwise.
|
||||
* If this succeeds the dmabuf can be used for rendering on a texture
|
||||
*/
|
||||
bool wlr_egl_check_import_dmabuf(struct wlr_egl *egl,
|
||||
struct wlr_dmabuf_buffer *dmabuf);
|
||||
struct wlr_dmabuf_attributes *attributes);
|
||||
|
||||
/**
|
||||
* Get the available dmabuf formats
|
||||
@ -88,7 +88,7 @@ int wlr_egl_get_dmabuf_modifiers(struct wlr_egl *egl, int format,
|
||||
|
||||
bool wlr_egl_export_image_to_dmabuf(struct wlr_egl *egl, EGLImageKHR image,
|
||||
int32_t width, int32_t height, uint32_t flags,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs);
|
||||
struct wlr_dmabuf_attributes *attribs);
|
||||
|
||||
/**
|
||||
* Destroys an EGL image created with the given wlr_egl.
|
||||
|
@ -14,6 +14,6 @@ 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 wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs);
|
||||
struct wlr_dmabuf_attributes *attribs);
|
||||
|
||||
#endif
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include <wlr/render/wlr_renderer.h>
|
||||
#include <wlr/render/wlr_texture.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_linux_dmabuf.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/render/dmabuf.h>
|
||||
|
||||
struct wlr_renderer_impl {
|
||||
void (*begin)(struct wlr_renderer *renderer, uint32_t width,
|
||||
@ -31,7 +31,7 @@ struct wlr_renderer_impl {
|
||||
void (*wl_drm_buffer_get_size)(struct wlr_renderer *renderer,
|
||||
struct wl_resource *buffer, int *width, int *height);
|
||||
bool (*check_import_dmabuf)(struct wlr_renderer *renderer,
|
||||
struct wlr_dmabuf_buffer *dmabuf);
|
||||
struct wlr_dmabuf_attributes *attribs);
|
||||
int (*get_dmabuf_formats)(struct wlr_renderer *renderer, int **formats);
|
||||
int (*get_dmabuf_modifiers)(struct wlr_renderer *renderer, int format,
|
||||
uint64_t **modifiers);
|
||||
@ -47,7 +47,7 @@ struct wlr_renderer_impl {
|
||||
struct wlr_texture *(*texture_from_wl_drm)(struct wlr_renderer *renderer,
|
||||
struct wl_resource *data);
|
||||
struct wlr_texture *(*texture_from_dmabuf)(struct wlr_renderer *renderer,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs);
|
||||
struct wlr_dmabuf_attributes *attribs);
|
||||
void (*destroy)(struct wlr_renderer *renderer);
|
||||
void (*init_wl_display)(struct wlr_renderer *renderer,
|
||||
struct wl_display *wl_display);
|
||||
@ -63,7 +63,7 @@ struct wlr_texture_impl {
|
||||
uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x,
|
||||
uint32_t dst_y, const void *data);
|
||||
bool (*to_dmabuf)(struct wlr_texture *texture,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs);
|
||||
struct wlr_dmabuf_attributes *attribs);
|
||||
void (*destroy)(struct wlr_texture *texture);
|
||||
};
|
||||
|
||||
|
@ -89,7 +89,7 @@ int wlr_renderer_get_dmabuf_modifiers(struct wlr_renderer *renderer, int format,
|
||||
* If this succeeds the dmabuf can be used for rendering on a texture
|
||||
*/
|
||||
bool wlr_renderer_check_import_dmabuf(struct wlr_renderer *renderer,
|
||||
struct wlr_dmabuf_buffer *dmabuf);
|
||||
struct wlr_dmabuf_attributes *attributes);
|
||||
/**
|
||||
* Reads out of pixels of the currently bound surface into data. `stride` is in
|
||||
* bytes.
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <EGL/eglext.h>
|
||||
#include <stdint.h>
|
||||
#include <wayland-server-protocol.h>
|
||||
#include <wlr/types/wlr_linux_dmabuf.h>
|
||||
#include <wlr/render/dmabuf.h>
|
||||
|
||||
struct wlr_renderer;
|
||||
struct wlr_texture_impl;
|
||||
@ -33,7 +33,7 @@ struct wlr_texture *wlr_texture_from_wl_drm(struct wlr_renderer *renderer,
|
||||
* Create a new texture from a DMA-BUF. The returned texture is immutable.
|
||||
*/
|
||||
struct wlr_texture *wlr_texture_from_dmabuf(struct wlr_renderer *renderer,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs);
|
||||
struct wlr_dmabuf_attributes *attribs);
|
||||
|
||||
/**
|
||||
* Get the texture width and height.
|
||||
@ -49,7 +49,7 @@ bool wlr_texture_write_pixels(struct wlr_texture *texture,
|
||||
const void *data);
|
||||
|
||||
bool wlr_texture_to_dmabuf(struct wlr_texture *texture,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs);
|
||||
struct wlr_dmabuf_attributes *attribs);
|
||||
|
||||
/**
|
||||
* Destroys this wlr_texture.
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define WLR_TYPES_WLR_EXPORT_DMABUF_V1_H
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_linux_dmabuf.h>
|
||||
#include <wlr/render/dmabuf.h>
|
||||
|
||||
struct wlr_export_dmabuf_manager_v1;
|
||||
|
||||
@ -11,7 +11,7 @@ struct wlr_export_dmabuf_frame_v1 {
|
||||
struct wlr_export_dmabuf_manager_v1 *manager;
|
||||
struct wl_list link;
|
||||
|
||||
struct wlr_dmabuf_buffer_attribs attribs;
|
||||
struct wlr_dmabuf_attributes attribs;
|
||||
struct wlr_output *output;
|
||||
|
||||
struct wl_listener output_swap_buffers;
|
||||
|
@ -1,48 +1,18 @@
|
||||
#ifndef WLR_TYPES_WLR_LINUX_DMABUF_H
|
||||
#define WLR_TYPES_WLR_LINUX_DMABUF_H
|
||||
|
||||
#define WLR_LINUX_DMABUF_MAX_PLANES 4
|
||||
|
||||
#include <stdint.h>
|
||||
#include <wayland-server-protocol.h>
|
||||
|
||||
/* So we don't have to pull in linux specific drm headers */
|
||||
#ifndef DRM_FORMAT_MOD_INVALID
|
||||
#define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
|
||||
#endif
|
||||
|
||||
enum {
|
||||
WLR_DMABUF_BUFFER_ATTRIBS_FLAGS_Y_INVERT = 1,
|
||||
WLR_DMABUF_BUFFER_ATTRIBS_FLAGS_INTERLACED = 2,
|
||||
WLR_DMABUF_BUFFER_ATTRIBS_FLAGS_BOTTOM_FIRST = 4,
|
||||
};
|
||||
|
||||
struct wlr_dmabuf_buffer_attribs {
|
||||
/* set via params_add */
|
||||
int n_planes;
|
||||
uint32_t offset[WLR_LINUX_DMABUF_MAX_PLANES];
|
||||
uint32_t stride[WLR_LINUX_DMABUF_MAX_PLANES];
|
||||
uint64_t modifier[WLR_LINUX_DMABUF_MAX_PLANES];
|
||||
int fd[WLR_LINUX_DMABUF_MAX_PLANES];
|
||||
/* set via params_create */
|
||||
int32_t width, height;
|
||||
uint32_t format;
|
||||
uint32_t flags;
|
||||
};
|
||||
#include <wlr/render/dmabuf.h>
|
||||
|
||||
struct wlr_dmabuf_buffer {
|
||||
struct wlr_renderer *renderer;
|
||||
struct wl_resource *buffer_resource;
|
||||
struct wl_resource *params_resource;
|
||||
struct wlr_dmabuf_buffer_attribs attributes;
|
||||
struct wlr_dmabuf_attributes attributes;
|
||||
bool has_modifier;
|
||||
};
|
||||
|
||||
/**
|
||||
* Closes all file descriptors in the DMA-BUF attributes.
|
||||
*/
|
||||
void wlr_dmabuf_buffer_attribs_finish(
|
||||
struct wlr_dmabuf_buffer_attribs *attribs);
|
||||
|
||||
/**
|
||||
* Returns true if the given resource was created via the linux-dmabuf
|
||||
* buffer protocol, false otherwise
|
||||
|
@ -170,7 +170,7 @@ void wlr_output_set_gamma(struct wlr_output *output,
|
||||
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b);
|
||||
uint32_t wlr_output_get_gamma_size(struct wlr_output *output);
|
||||
bool wlr_output_export_dmabuf(struct wlr_output *output,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs);
|
||||
struct wlr_dmabuf_attributes *attribs);
|
||||
void wlr_output_set_fullscreen_surface(struct wlr_output *output,
|
||||
struct wlr_surface *surface);
|
||||
struct wlr_output *wlr_output_from_resource(struct wl_resource *resource);
|
||||
|
@ -46,7 +46,7 @@ endif
|
||||
# Avoid wl_buffer deprecation warnings
|
||||
add_project_arguments('-DWL_HIDE_DEPRECATED', language: 'c')
|
||||
|
||||
wayland_server = dependency('wayland-server')
|
||||
wayland_server = dependency('wayland-server', version: '>=1.15')
|
||||
wayland_client = dependency('wayland-client')
|
||||
wayland_egl = dependency('wayland-egl')
|
||||
wayland_protos = dependency('wayland-protocols', version: '>=1.14')
|
||||
|
10
render/dmabuf.c
Normal file
10
render/dmabuf.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <unistd.h>
|
||||
#include <wlr/render/dmabuf.h>
|
||||
|
||||
void wlr_dmabuf_attributes_finish( struct wlr_dmabuf_attributes *attribs) {
|
||||
for (int i = 0; i < attribs->n_planes; ++i) {
|
||||
close(attribs->fd[i]);
|
||||
attribs->fd[i] = -1;
|
||||
}
|
||||
attribs->n_planes = 0;
|
||||
}
|
31
render/egl.c
31
render/egl.c
@ -344,9 +344,9 @@ EGLImageKHR wlr_egl_create_image_from_wl_drm(struct wlr_egl *egl,
|
||||
}
|
||||
|
||||
EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
|
||||
struct wlr_dmabuf_buffer_attribs *attributes) {
|
||||
struct wlr_dmabuf_attributes *attributes) {
|
||||
bool has_modifier = false;
|
||||
if (attributes->modifier[0] != DRM_FORMAT_MOD_INVALID) {
|
||||
if (attributes->modifier != DRM_FORMAT_MOD_INVALID) {
|
||||
if (!egl->egl_exts.dmabuf_import_modifiers) {
|
||||
return NULL;
|
||||
}
|
||||
@ -368,7 +368,7 @@ EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
|
||||
EGLint pitch;
|
||||
EGLint mod_lo;
|
||||
EGLint mod_hi;
|
||||
} attr_names[WLR_LINUX_DMABUF_MAX_PLANES] = {
|
||||
} attr_names[WLR_DMABUF_MAX_PLANES] = {
|
||||
{
|
||||
EGL_DMA_BUF_PLANE0_FD_EXT,
|
||||
EGL_DMA_BUF_PLANE0_OFFSET_EXT,
|
||||
@ -405,9 +405,9 @@ EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
|
||||
attribs[atti++] = attributes->stride[i];
|
||||
if (has_modifier) {
|
||||
attribs[atti++] = attr_names[i].mod_lo;
|
||||
attribs[atti++] = attributes->modifier[i] & 0xFFFFFFFF;
|
||||
attribs[atti++] = attributes->modifier & 0xFFFFFFFF;
|
||||
attribs[atti++] = attr_names[i].mod_hi;
|
||||
attribs[atti++] = attributes->modifier[i] >> 32;
|
||||
attribs[atti++] = attributes->modifier >> 32;
|
||||
}
|
||||
}
|
||||
attribs[atti++] = EGL_NONE;
|
||||
@ -421,8 +421,8 @@ EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
|
||||
#define DRM_FORMAT_BIG_ENDIAN 0x80000000
|
||||
#endif
|
||||
bool wlr_egl_check_import_dmabuf(struct wlr_egl *egl,
|
||||
struct wlr_dmabuf_buffer *dmabuf) {
|
||||
switch (dmabuf->attributes.format & ~DRM_FORMAT_BIG_ENDIAN) {
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
switch (attribs->format & ~DRM_FORMAT_BIG_ENDIAN) {
|
||||
/* TODO: YUV based formats not yet supported, require multiple
|
||||
* wlr_create_image_from_dmabuf */
|
||||
case WL_SHM_FORMAT_YUYV:
|
||||
@ -435,8 +435,7 @@ bool wlr_egl_check_import_dmabuf(struct wlr_egl *egl,
|
||||
break;
|
||||
}
|
||||
|
||||
EGLImage egl_image = wlr_egl_create_image_from_dmabuf(egl,
|
||||
&dmabuf->attributes);
|
||||
EGLImage egl_image = wlr_egl_create_image_from_dmabuf(egl, attribs);
|
||||
if (egl_image) {
|
||||
/* We can import the image, good. No need to keep it
|
||||
since wlr_texture_upload_dmabuf will import it again */
|
||||
@ -507,8 +506,8 @@ int wlr_egl_get_dmabuf_modifiers(struct wlr_egl *egl,
|
||||
|
||||
bool wlr_egl_export_image_to_dmabuf(struct wlr_egl *egl, EGLImageKHR image,
|
||||
int32_t width, int32_t height, uint32_t flags,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs) {
|
||||
memset(attribs, 0, sizeof(struct wlr_dmabuf_buffer_attribs));
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
memset(attribs, 0, sizeof(struct wlr_dmabuf_attributes));
|
||||
|
||||
if (!egl->egl_exts.dmabuf_export || !eglExportDMABUFImageQueryMESA ||
|
||||
!eglExportDMABUFImageMESA) {
|
||||
@ -516,19 +515,15 @@ bool wlr_egl_export_image_to_dmabuf(struct wlr_egl *egl, EGLImageKHR image,
|
||||
}
|
||||
|
||||
// Only one set of modifiers is returned for all planes
|
||||
EGLuint64KHR modifiers;
|
||||
if (!eglExportDMABUFImageQueryMESA(egl->display, image,
|
||||
(int *)&attribs->format, &attribs->n_planes, &modifiers)) {
|
||||
(int *)&attribs->format, &attribs->n_planes, &attribs->modifier)) {
|
||||
return false;
|
||||
}
|
||||
if (attribs->n_planes > WLR_LINUX_DMABUF_MAX_PLANES) {
|
||||
if (attribs->n_planes > WLR_DMABUF_MAX_PLANES) {
|
||||
wlr_log(L_ERROR, "EGL returned %d planes, but only %d are supported",
|
||||
attribs->n_planes, WLR_LINUX_DMABUF_MAX_PLANES);
|
||||
attribs->n_planes, WLR_DMABUF_MAX_PLANES);
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < attribs->n_planes; ++i) {
|
||||
attribs->modifier[i] = modifiers;
|
||||
}
|
||||
|
||||
if (!eglExportDMABUFImageMESA(egl->display, image, attribs->fd,
|
||||
(EGLint *)attribs->stride, (EGLint *)attribs->offset)) {
|
||||
|
@ -84,7 +84,7 @@ static void gles2_scissor(struct wlr_renderer *wlr_renderer,
|
||||
POP_GLES2_DEBUG;
|
||||
}
|
||||
|
||||
static void draw_quad() {
|
||||
static void draw_quad(void) {
|
||||
GLfloat verts[] = {
|
||||
1, 0, // top right
|
||||
0, 0, // top left
|
||||
@ -243,9 +243,9 @@ static int gles2_get_dmabuf_modifiers(struct wlr_renderer *wlr_renderer,
|
||||
}
|
||||
|
||||
static bool gles2_check_import_dmabuf(struct wlr_renderer *wlr_renderer,
|
||||
struct wlr_dmabuf_buffer *dmabuf) {
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
return wlr_egl_check_import_dmabuf(renderer->egl, dmabuf);
|
||||
return wlr_egl_check_import_dmabuf(renderer->egl, attribs);
|
||||
}
|
||||
|
||||
static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
|
||||
@ -299,7 +299,7 @@ static struct wlr_texture *gles2_texture_from_wl_drm(
|
||||
|
||||
static struct wlr_texture *gles2_texture_from_dmabuf(
|
||||
struct wlr_renderer *wlr_renderer,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs) {
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
return wlr_gles2_texture_from_dmabuf(renderer->egl, attribs);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
|
||||
}
|
||||
|
||||
static bool gles2_texture_to_dmabuf(struct wlr_texture *wlr_texture,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs) {
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
|
||||
|
||||
if (!texture->image) {
|
||||
@ -95,7 +95,7 @@ static bool gles2_texture_to_dmabuf(struct wlr_texture *wlr_texture,
|
||||
|
||||
uint32_t flags = 0;
|
||||
if (texture->inverted_y) {
|
||||
flags |= WLR_DMABUF_BUFFER_ATTRIBS_FLAGS_Y_INVERT;
|
||||
flags |= WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT;
|
||||
}
|
||||
|
||||
return wlr_egl_export_image_to_dmabuf(texture->egl, texture->image,
|
||||
@ -228,7 +228,7 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
|
||||
}
|
||||
|
||||
struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs) {
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
assert(wlr_egl_is_current(egl));
|
||||
|
||||
if (!glEGLImageTargetTexture2DOES) {
|
||||
@ -254,7 +254,7 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
|
||||
texture->type = WLR_GLES2_TEXTURE_DMABUF;
|
||||
texture->has_alpha = true;
|
||||
texture->inverted_y =
|
||||
(attribs->flags & WLR_DMABUF_BUFFER_ATTRIBS_FLAGS_Y_INVERT) != 0;
|
||||
(attribs->flags & WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT) != 0;
|
||||
|
||||
texture->image = wlr_egl_create_image_from_dmabuf(egl, attribs);
|
||||
if (texture->image == NULL) {
|
||||
|
@ -9,6 +9,7 @@ glapi = custom_target('glapi',
|
||||
lib_wlr_render = static_library(
|
||||
'wlr_render',
|
||||
files(
|
||||
'dmabuf.c',
|
||||
'egl.c',
|
||||
'gles2/pixel_format.c',
|
||||
'gles2/renderer.c',
|
||||
|
@ -136,11 +136,11 @@ int wlr_renderer_get_dmabuf_modifiers(struct wlr_renderer *r, int format,
|
||||
}
|
||||
|
||||
bool wlr_renderer_check_import_dmabuf(struct wlr_renderer *r,
|
||||
struct wlr_dmabuf_buffer *dmabuf) {
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
if (!r->impl->check_import_dmabuf) {
|
||||
return false;
|
||||
}
|
||||
return r->impl->check_import_dmabuf(r, dmabuf);
|
||||
return r->impl->check_import_dmabuf(r, attribs);
|
||||
}
|
||||
|
||||
bool wlr_renderer_read_pixels(struct wlr_renderer *r, enum wl_shm_format fmt,
|
||||
|
@ -35,7 +35,7 @@ struct wlr_texture *wlr_texture_from_wl_drm(struct wlr_renderer *renderer,
|
||||
}
|
||||
|
||||
struct wlr_texture *wlr_texture_from_dmabuf(struct wlr_renderer *renderer,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs) {
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
if (!renderer->impl->texture_from_dmabuf) {
|
||||
return NULL;
|
||||
}
|
||||
@ -56,7 +56,7 @@ bool wlr_texture_write_pixels(struct wlr_texture *texture,
|
||||
}
|
||||
|
||||
bool wlr_texture_to_dmabuf(struct wlr_texture *texture,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs) {
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
if (!texture->impl->to_dmabuf) {
|
||||
return false;
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
wl_display_run(server.wl_display);
|
||||
wl_display_destroy_clients(server.wl_display);
|
||||
wl_display_destroy(server.wl_display);
|
||||
return 0;
|
||||
}
|
||||
|
@ -135,11 +135,10 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) {
|
||||
if (surface->geometry.width > 0 && surface->geometry.height > 0) {
|
||||
box->width = surface->geometry.width;
|
||||
box->height = surface->geometry.height;
|
||||
} else if (view->wlr_surface != NULL) {
|
||||
box->width = view->wlr_surface->current->width;
|
||||
box->height = view->wlr_surface->current->height;
|
||||
} else {
|
||||
box->width = box->height = 0;
|
||||
assert(surface->surface);
|
||||
box->width = surface->surface->current->width;
|
||||
box->height = surface->surface->current->height;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,11 +136,10 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) {
|
||||
if (surface->geometry.width > 0 && surface->geometry.height > 0) {
|
||||
box->width = surface->geometry.width;
|
||||
box->height = surface->geometry.height;
|
||||
} else if (view->wlr_surface != NULL) {
|
||||
box->width = view->wlr_surface->current->width;
|
||||
box->height = view->wlr_surface->current->height;
|
||||
} else {
|
||||
box->width = box->height = 0;
|
||||
assert(surface->surface);
|
||||
box->width = surface->surface->current->width;
|
||||
box->height = surface->surface->current->height;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,8 +61,8 @@ bool wlr_box_contains_point(const struct wlr_box *box, double x, double y) {
|
||||
if (wlr_box_empty(box)) {
|
||||
return false;
|
||||
} else {
|
||||
return x >= box->x && x <= box->x + box->width &&
|
||||
y >= box->y && y <= box->y + box->height;
|
||||
return x >= box->x && x < box->x + box->width &&
|
||||
y >= box->y && y < box->y + box->height;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ struct wlr_cursor_state {
|
||||
struct wl_listener layout_destroy;
|
||||
};
|
||||
|
||||
struct wlr_cursor *wlr_cursor_create() {
|
||||
struct wlr_cursor *wlr_cursor_create(void) {
|
||||
struct wlr_cursor *cur = calloc(1, sizeof(struct wlr_cursor));
|
||||
if (!cur) {
|
||||
wlr_log(L_ERROR, "Failed to allocate wlr_cursor");
|
||||
|
@ -33,7 +33,7 @@ static void frame_handle_resource_destroy(struct wl_resource *resource) {
|
||||
struct wlr_export_dmabuf_frame_v1 *frame = frame_from_resource(resource);
|
||||
wl_list_remove(&frame->link);
|
||||
wl_list_remove(&frame->output_swap_buffers.link);
|
||||
wlr_dmabuf_buffer_attribs_finish(&frame->attribs);
|
||||
wlr_dmabuf_attributes_finish(&frame->attribs);
|
||||
free(frame);
|
||||
}
|
||||
|
||||
@ -97,17 +97,16 @@ static void manager_handle_capture_output(struct wl_client *client,
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_dmabuf_buffer_attribs *attribs = &frame->attribs;
|
||||
struct wlr_dmabuf_attributes *attribs = &frame->attribs;
|
||||
if (!wlr_output_export_dmabuf(output, attribs)) {
|
||||
zwlr_export_dmabuf_frame_v1_send_cancel(frame->resource,
|
||||
ZWLR_EXPORT_DMABUF_FRAME_V1_CANCEL_REASON_TEMPORARY);
|
||||
return;
|
||||
}
|
||||
assert(attribs->n_planes > 0);
|
||||
|
||||
uint32_t frame_flags = ZWLR_EXPORT_DMABUF_FRAME_V1_FLAGS_TRANSIENT;
|
||||
uint32_t mod_high = attribs->modifier[0] >> 32;
|
||||
uint32_t mod_low = attribs->modifier[0] & 0xFFFFFFFF;
|
||||
uint32_t mod_high = attribs->modifier >> 32;
|
||||
uint32_t mod_low = attribs->modifier & 0xFFFFFFFF;
|
||||
|
||||
zwlr_export_dmabuf_frame_v1_send_frame(frame->resource,
|
||||
output->width, output->height, 0, 0, attribs->flags, frame_flags,
|
||||
|
@ -51,17 +51,8 @@ struct wlr_dmabuf_buffer *wlr_dmabuf_buffer_from_buffer_resource(
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void wlr_dmabuf_buffer_attribs_finish(
|
||||
struct wlr_dmabuf_buffer_attribs *attribs) {
|
||||
for (int i = 0; i < attribs->n_planes; ++i) {
|
||||
close(attribs->fd[i]);
|
||||
attribs->fd[i] = -1;
|
||||
}
|
||||
attribs->n_planes = 0;
|
||||
}
|
||||
|
||||
static void linux_dmabuf_buffer_destroy(struct wlr_dmabuf_buffer *buffer) {
|
||||
wlr_dmabuf_buffer_attribs_finish(&buffer->attributes);
|
||||
wlr_dmabuf_attributes_finish(&buffer->attributes);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
@ -71,7 +62,7 @@ static void params_destroy(struct wl_client *client,
|
||||
}
|
||||
|
||||
static void params_add(struct wl_client *client,
|
||||
struct wl_resource *params_resource, int32_t name_fd,
|
||||
struct wl_resource *params_resource, int32_t fd,
|
||||
uint32_t plane_idx, uint32_t offset, uint32_t stride,
|
||||
uint32_t modifier_hi, uint32_t modifier_lo) {
|
||||
struct wlr_dmabuf_buffer *buffer =
|
||||
@ -81,33 +72,42 @@ static void params_add(struct wl_client *client,
|
||||
wl_resource_post_error(params_resource,
|
||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED,
|
||||
"params was already used to create a wl_buffer");
|
||||
close(name_fd);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (plane_idx >= WLR_LINUX_DMABUF_MAX_PLANES) {
|
||||
if (plane_idx >= WLR_DMABUF_MAX_PLANES) {
|
||||
wl_resource_post_error(params_resource,
|
||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX,
|
||||
"plane index %u > %u", plane_idx, WLR_LINUX_DMABUF_MAX_PLANES);
|
||||
close(name_fd);
|
||||
"plane index %u > %u", plane_idx, WLR_DMABUF_MAX_PLANES);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (buffer->attributes.fd[plane_idx] != -1) {
|
||||
wl_resource_post_error(params_resource,
|
||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET,
|
||||
"a dmabuf with id %d has already been added for plane %u",
|
||||
buffer->attributes.fd[plane_idx],
|
||||
plane_idx);
|
||||
close(name_fd);
|
||||
"a dmabuf with FD %d has already been added for plane %u",
|
||||
buffer->attributes.fd[plane_idx], plane_idx);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
buffer->attributes.fd[plane_idx] = name_fd;
|
||||
uint64_t modifier = ((uint64_t)modifier_hi << 32) | modifier_lo;
|
||||
if (buffer->has_modifier && modifier != buffer->attributes.modifier) {
|
||||
wl_resource_post_error(params_resource,
|
||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT,
|
||||
"sent modifier %lu for plane %u, expected modifier %lu like other planes",
|
||||
modifier, plane_idx, buffer->attributes.modifier);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
buffer->attributes.modifier = modifier;
|
||||
buffer->has_modifier = true;
|
||||
|
||||
buffer->attributes.fd[plane_idx] = fd;
|
||||
buffer->attributes.offset[plane_idx] = offset;
|
||||
buffer->attributes.stride[plane_idx] = stride;
|
||||
buffer->attributes.modifier[plane_idx] =
|
||||
((uint64_t)modifier_hi << 32) | modifier_lo;
|
||||
buffer->attributes.n_planes++;
|
||||
}
|
||||
|
||||
@ -186,7 +186,8 @@ static void params_create_common(struct wl_client *client,
|
||||
}
|
||||
|
||||
off_t size = lseek(buffer->attributes.fd[i], 0, SEEK_END);
|
||||
if (size == -1) { /* Skip checks if kernel does no support seek on buffer */
|
||||
if (size == -1) {
|
||||
// Skip checks if kernel does no support seek on buffer
|
||||
continue;
|
||||
}
|
||||
if (buffer->attributes.offset[i] >= size) {
|
||||
@ -205,8 +206,9 @@ static void params_create_common(struct wl_client *client,
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
if (i == 0 && /* planes > 0 might be subsampled according to fourcc format */
|
||||
buffer->attributes.offset[i] + buffer->attributes.stride[i] * height > size) {
|
||||
// planes > 0 might be subsampled according to fourcc format
|
||||
if (i == 0 && buffer->attributes.offset[i] +
|
||||
buffer->attributes.stride[i] * height >= size) {
|
||||
wl_resource_post_error(params_resource,
|
||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
|
||||
"invalid buffer stride or height for plane %d", i);
|
||||
@ -223,7 +225,8 @@ static void params_create_common(struct wl_client *client,
|
||||
}
|
||||
|
||||
/* Check if dmabuf is usable */
|
||||
if (!wlr_renderer_check_import_dmabuf(buffer->renderer, buffer)) {
|
||||
if (!wlr_renderer_check_import_dmabuf(buffer->renderer,
|
||||
&buffer->attributes)) {
|
||||
goto err_failed;
|
||||
}
|
||||
|
||||
@ -324,7 +327,7 @@ static void linux_dmabuf_create_params(struct wl_client *client,
|
||||
goto err;
|
||||
}
|
||||
|
||||
for (int i = 0; i < WLR_LINUX_DMABUF_MAX_PLANES; i++) {
|
||||
for (int i = 0; i < WLR_DMABUF_MAX_PLANES; i++) {
|
||||
buffer->attributes.fd[i] = -1;
|
||||
}
|
||||
|
||||
|
@ -566,7 +566,7 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) {
|
||||
}
|
||||
|
||||
bool wlr_output_export_dmabuf(struct wlr_output *output,
|
||||
struct wlr_dmabuf_buffer_attribs *attribs) {
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
if (!output->impl->export_dmabuf) {
|
||||
return false;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ struct wlr_output_layout_output_state {
|
||||
struct wl_listener output_destroy;
|
||||
};
|
||||
|
||||
struct wlr_output_layout *wlr_output_layout_create() {
|
||||
struct wlr_output_layout *wlr_output_layout_create(void) {
|
||||
struct wlr_output_layout *layout =
|
||||
calloc(1, sizeof(struct wlr_output_layout));
|
||||
if (layout == NULL) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <wlr/render/egl.h>
|
||||
#include <wlr/render/interface.h>
|
||||
#include <wlr/types/wlr_compositor.h>
|
||||
#include <wlr/types/wlr_linux_dmabuf.h>
|
||||
#include <wlr/types/wlr_matrix.h>
|
||||
#include <wlr/types/wlr_region.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
@ -569,7 +570,7 @@ struct wlr_surface *wlr_surface_from_resource(struct wl_resource *resource) {
|
||||
return wl_resource_get_user_data(resource);
|
||||
}
|
||||
|
||||
static struct wlr_surface_state *surface_state_create() {
|
||||
static struct wlr_surface_state *surface_state_create(void) {
|
||||
struct wlr_surface_state *state =
|
||||
calloc(1, sizeof(struct wlr_surface_state));
|
||||
if (state == NULL) {
|
||||
|
@ -231,6 +231,16 @@ struct wlr_virtual_keyboard_manager_v1*
|
||||
|
||||
void wlr_virtual_keyboard_manager_v1_destroy(
|
||||
struct wlr_virtual_keyboard_manager_v1 *manager) {
|
||||
wl_list_remove(&manager->display_destroy.link);
|
||||
wl_global_destroy(manager->global);
|
||||
struct wl_resource *resource, *resource_tmp;
|
||||
wl_resource_for_each_safe(resource, resource_tmp, &manager->resources) {
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
struct wlr_virtual_keyboard_v1 *keyboard, *keyboard_tmp;
|
||||
wl_list_for_each_safe(keyboard, keyboard_tmp, &manager->virtual_keyboards,
|
||||
link) {
|
||||
wl_resource_destroy(keyboard->resource);
|
||||
}
|
||||
free(manager);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user