output, backend/drm: add wlr_output_export_dmabuf

This commit is contained in:
emersion 2018-05-21 18:50:51 +01:00
parent e1f56538a8
commit 9e26808c28
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
6 changed files with 51 additions and 10 deletions

View File

@ -254,6 +254,26 @@ static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) {
return 0; return 0;
} }
static bool drm_connector_export_dmabuf(struct wlr_output *output,
struct wlr_dmabuf_buffer_attribs *attribs) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
if (!drm->session->active) {
return false;
}
struct wlr_drm_crtc *crtc = conn->crtc;
if (!crtc) {
return false;
}
struct wlr_drm_plane *plane = crtc->primary;
struct wlr_drm_surface *surf = &plane->surf;
export_drm_bo(surf->back, attribs);
return true;
}
static void drm_connector_start_renderer(struct wlr_drm_connector *conn) { static void drm_connector_start_renderer(struct wlr_drm_connector *conn) {
if (conn->state != WLR_DRM_CONN_CONNECTED) { if (conn->state != WLR_DRM_CONN_CONNECTED) {
return; return;
@ -742,6 +762,7 @@ static const struct wlr_output_impl output_impl = {
.swap_buffers = drm_connector_swap_buffers, .swap_buffers = drm_connector_swap_buffers,
.set_gamma = drm_connector_set_gamma, .set_gamma = drm_connector_set_gamma,
.get_gamma_size = drm_connector_get_gamma_size, .get_gamma_size = drm_connector_get_gamma_size,
.export_dmabuf = drm_connector_export_dmabuf,
}; };
bool wlr_output_is_drm(struct wlr_output *output) { bool wlr_output_is_drm(struct wlr_output *output) {

View File

@ -160,6 +160,19 @@ void post_drm_surface(struct wlr_drm_surface *surf) {
} }
} }
void export_drm_bo(struct gbm_bo *bo,
struct wlr_dmabuf_buffer_attribs *attribs) {
memset(attribs, 0, sizeof(struct wlr_dmabuf_buffer_attribs));
attribs->n_planes = 1;
attribs->width = gbm_bo_get_width(bo);
attribs->height = gbm_bo_get_height(bo);
attribs->format = gbm_bo_get_format(bo);
attribs->offset[0] = 0;
attribs->stride[0] = gbm_bo_get_stride_for_plane(bo, 0);
attribs->modifier[0] = DRM_FORMAT_MOD_LINEAR;
attribs->fd[0] = gbm_bo_get_fd(bo);
}
struct tex { struct tex {
struct wlr_egl *egl; struct wlr_egl *egl;
EGLImageKHR img; EGLImageKHR img;
@ -186,16 +199,8 @@ static struct wlr_texture *get_tex_for_bo(struct wlr_drm_renderer *renderer,
return NULL; return NULL;
} }
struct wlr_dmabuf_buffer_attribs attribs = { struct wlr_dmabuf_buffer_attribs attribs;
.n_planes = 1, export_drm_bo(bo, &attribs);
.width = gbm_bo_get_width(bo),
.height = gbm_bo_get_height(bo),
.format = gbm_bo_get_format(bo),
};
attribs.offset[0] = 0;
attribs.stride[0] = gbm_bo_get_stride_for_plane(bo, 0);
attribs.modifier[0] = DRM_FORMAT_MOD_LINEAR;
attribs.fd[0] = gbm_bo_get_fd(bo);
tex->tex = wlr_texture_from_dmabuf(renderer->wlr_rend, &attribs); tex->tex = wlr_texture_from_dmabuf(renderer->wlr_rend, &attribs);
if (tex->tex == NULL) { if (tex->tex == NULL) {

View File

@ -52,5 +52,7 @@ struct gbm_bo *get_drm_surface_front(struct wlr_drm_surface *surf);
void post_drm_surface(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 *copy_drm_surface_mgpu(struct wlr_drm_surface *dest,
struct gbm_bo *src); struct gbm_bo *src);
void export_drm_bo(struct gbm_bo *bo,
struct wlr_dmabuf_buffer_attribs *attribs);
#endif #endif

View File

@ -23,6 +23,8 @@ struct wlr_output_impl {
void (*set_gamma)(struct wlr_output *output, void (*set_gamma)(struct wlr_output *output,
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b);
uint32_t (*get_gamma_size)(struct wlr_output *output); uint32_t (*get_gamma_size)(struct wlr_output *output);
bool (*export_dmabuf)(struct wlr_output *output,
struct wlr_dmabuf_buffer_attribs *attribs);
}; };
void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,

View File

@ -6,6 +6,7 @@
#include <time.h> #include <time.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wayland-util.h> #include <wayland-util.h>
#include <wlr/types/wlr_linux_dmabuf.h>
struct wlr_output_mode { struct wlr_output_mode {
uint32_t flags; // enum wl_output_mode uint32_t flags; // enum wl_output_mode
@ -162,6 +163,8 @@ void wlr_output_schedule_frame(struct wlr_output *output);
void wlr_output_set_gamma(struct wlr_output *output, void wlr_output_set_gamma(struct wlr_output *output,
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b);
uint32_t wlr_output_get_gamma_size(struct wlr_output *output); 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);
void wlr_output_set_fullscreen_surface(struct wlr_output *output, void wlr_output_set_fullscreen_surface(struct wlr_output *output,
struct wlr_surface *surface); struct wlr_surface *surface);
struct wlr_output *wlr_output_from_resource(struct wl_resource *resource); struct wlr_output *wlr_output_from_resource(struct wl_resource *resource);

View File

@ -560,6 +560,14 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) {
return output->impl->get_gamma_size(output); return output->impl->get_gamma_size(output);
} }
bool wlr_output_export_dmabuf(struct wlr_output *output,
struct wlr_dmabuf_buffer_attribs *attribs) {
if (!output->impl->export_dmabuf) {
return false;
}
return output->impl->export_dmabuf(output, attribs);
}
void wlr_output_update_needs_swap(struct wlr_output *output) { void wlr_output_update_needs_swap(struct wlr_output *output) {
output->needs_swap = true; output->needs_swap = true;
wlr_signal_emit_safe(&output->events.needs_swap, output); wlr_signal_emit_safe(&output->events.needs_swap, output);