mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 21:05:58 +01:00
Merge pull request #850 from emersion/remove-backend-egl
backend: remove wlr_backend_get_egl
This commit is contained in:
commit
bef5c1fd56
16 changed files with 127 additions and 111 deletions
|
@ -47,13 +47,6 @@ void wlr_backend_destroy(struct wlr_backend *backend) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_egl *wlr_backend_get_egl(struct wlr_backend *backend) {
|
|
||||||
if (backend->impl->get_egl) {
|
|
||||||
return backend->impl->get_egl(backend);
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend) {
|
struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend) {
|
||||||
if (backend->impl->get_renderer) {
|
if (backend->impl->get_renderer) {
|
||||||
return backend->impl->get_renderer(backend);
|
return backend->impl->get_renderer(backend);
|
||||||
|
|
|
@ -48,11 +48,6 @@ static void wlr_drm_backend_destroy(struct wlr_backend *backend) {
|
||||||
free(drm);
|
free(drm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wlr_egl *wlr_drm_backend_get_egl(struct wlr_backend *backend) {
|
|
||||||
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)backend;
|
|
||||||
return &drm->renderer.egl;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct wlr_renderer *wlr_drm_backend_get_renderer(
|
static struct wlr_renderer *wlr_drm_backend_get_renderer(
|
||||||
struct wlr_backend *backend) {
|
struct wlr_backend *backend) {
|
||||||
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)backend;
|
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)backend;
|
||||||
|
@ -62,7 +57,6 @@ static struct wlr_renderer *wlr_drm_backend_get_renderer(
|
||||||
static struct wlr_backend_impl backend_impl = {
|
static struct wlr_backend_impl backend_impl = {
|
||||||
.start = wlr_drm_backend_start,
|
.start = wlr_drm_backend_start,
|
||||||
.destroy = wlr_drm_backend_destroy,
|
.destroy = wlr_drm_backend_destroy,
|
||||||
.get_egl = wlr_drm_backend_get_egl,
|
|
||||||
.get_renderer = wlr_drm_backend_get_renderer,
|
.get_renderer = wlr_drm_backend_get_renderer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -58,12 +58,6 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
|
||||||
free(backend);
|
free(backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wlr_egl *backend_get_egl(struct wlr_backend *wlr_backend) {
|
|
||||||
struct wlr_headless_backend *backend =
|
|
||||||
(struct wlr_headless_backend *)wlr_backend;
|
|
||||||
return &backend->egl;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct wlr_renderer *backend_get_renderer(
|
static struct wlr_renderer *backend_get_renderer(
|
||||||
struct wlr_backend *wlr_backend) {
|
struct wlr_backend *wlr_backend) {
|
||||||
struct wlr_headless_backend *backend =
|
struct wlr_headless_backend *backend =
|
||||||
|
@ -74,7 +68,6 @@ static struct wlr_renderer *backend_get_renderer(
|
||||||
static const struct wlr_backend_impl backend_impl = {
|
static const struct wlr_backend_impl backend_impl = {
|
||||||
.start = backend_start,
|
.start = backend_start,
|
||||||
.destroy = backend_destroy,
|
.destroy = backend_destroy,
|
||||||
.get_egl = backend_get_egl,
|
|
||||||
.get_renderer = backend_get_renderer,
|
.get_renderer = backend_get_renderer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -52,18 +52,6 @@ static void multi_backend_destroy(struct wlr_backend *wlr_backend) {
|
||||||
free(backend);
|
free(backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wlr_egl *multi_backend_get_egl(struct wlr_backend *wlr_backend) {
|
|
||||||
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)wlr_backend;
|
|
||||||
struct subbackend_state *sub;
|
|
||||||
wl_list_for_each(sub, &backend->backends, link) {
|
|
||||||
struct wlr_egl *egl = wlr_backend_get_egl(sub->backend);
|
|
||||||
if (egl) {
|
|
||||||
return egl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct wlr_renderer *multi_backend_get_renderer(
|
static struct wlr_renderer *multi_backend_get_renderer(
|
||||||
struct wlr_backend *backend) {
|
struct wlr_backend *backend) {
|
||||||
struct wlr_multi_backend *multi = (struct wlr_multi_backend *)backend;
|
struct wlr_multi_backend *multi = (struct wlr_multi_backend *)backend;
|
||||||
|
@ -80,7 +68,6 @@ static struct wlr_renderer *multi_backend_get_renderer(
|
||||||
struct wlr_backend_impl backend_impl = {
|
struct wlr_backend_impl backend_impl = {
|
||||||
.start = multi_backend_start,
|
.start = multi_backend_start,
|
||||||
.destroy = multi_backend_destroy,
|
.destroy = multi_backend_destroy,
|
||||||
.get_egl = multi_backend_get_egl,
|
|
||||||
.get_renderer = multi_backend_get_renderer,
|
.get_renderer = multi_backend_get_renderer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -110,11 +110,6 @@ static void wlr_wl_backend_destroy(struct wlr_backend *wlr_backend) {
|
||||||
free(backend);
|
free(backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wlr_egl *wlr_wl_backend_get_egl(struct wlr_backend *wlr_backend) {
|
|
||||||
struct wlr_wl_backend *backend = (struct wlr_wl_backend *)wlr_backend;
|
|
||||||
return &backend->egl;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct wlr_renderer *wlr_wl_backend_get_renderer(
|
static struct wlr_renderer *wlr_wl_backend_get_renderer(
|
||||||
struct wlr_backend *wlr_backend) {
|
struct wlr_backend *wlr_backend) {
|
||||||
struct wlr_wl_backend *backend = (struct wlr_wl_backend *)wlr_backend;
|
struct wlr_wl_backend *backend = (struct wlr_wl_backend *)wlr_backend;
|
||||||
|
@ -124,7 +119,6 @@ static struct wlr_renderer *wlr_wl_backend_get_renderer(
|
||||||
static struct wlr_backend_impl backend_impl = {
|
static struct wlr_backend_impl backend_impl = {
|
||||||
.start = wlr_wl_backend_start,
|
.start = wlr_wl_backend_start,
|
||||||
.destroy = wlr_wl_backend_destroy,
|
.destroy = wlr_wl_backend_destroy,
|
||||||
.get_egl = wlr_wl_backend_get_egl,
|
|
||||||
.get_renderer = wlr_wl_backend_get_renderer,
|
.get_renderer = wlr_wl_backend_get_renderer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -257,11 +257,6 @@ static void wlr_x11_backend_destroy(struct wlr_backend *backend) {
|
||||||
free(x11);
|
free(x11);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wlr_egl *wlr_x11_backend_get_egl(struct wlr_backend *backend) {
|
|
||||||
struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend;
|
|
||||||
return &x11->egl;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct wlr_renderer *wlr_x11_backend_get_renderer(
|
static struct wlr_renderer *wlr_x11_backend_get_renderer(
|
||||||
struct wlr_backend *backend) {
|
struct wlr_backend *backend) {
|
||||||
struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend;
|
struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend;
|
||||||
|
@ -271,7 +266,6 @@ static struct wlr_renderer *wlr_x11_backend_get_renderer(
|
||||||
static const struct wlr_backend_impl backend_impl = {
|
static const struct wlr_backend_impl backend_impl = {
|
||||||
.start = wlr_x11_backend_start,
|
.start = wlr_x11_backend_start,
|
||||||
.destroy = wlr_x11_backend_destroy,
|
.destroy = wlr_x11_backend_destroy,
|
||||||
.get_egl = wlr_x11_backend_get_egl,
|
|
||||||
.get_renderer = wlr_x11_backend_get_renderer,
|
.get_renderer = wlr_x11_backend_get_renderer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,6 @@ bool wlr_backend_start(struct wlr_backend *backend);
|
||||||
* automatically when the wl_display is destroyed.
|
* automatically when the wl_display is destroyed.
|
||||||
*/
|
*/
|
||||||
void wlr_backend_destroy(struct wlr_backend *backend);
|
void wlr_backend_destroy(struct wlr_backend *backend);
|
||||||
/**
|
|
||||||
* Obtains the wlr_egl reference this backend is using.
|
|
||||||
*/
|
|
||||||
struct wlr_egl *wlr_backend_get_egl(struct wlr_backend *backend);
|
|
||||||
/**
|
/**
|
||||||
* Obtains the wlr_renderer reference this backend is using.
|
* Obtains the wlr_renderer reference this backend is using.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
struct wlr_backend_impl {
|
struct wlr_backend_impl {
|
||||||
bool (*start)(struct wlr_backend *backend);
|
bool (*start)(struct wlr_backend *backend);
|
||||||
void (*destroy)(struct wlr_backend *backend);
|
void (*destroy)(struct wlr_backend *backend);
|
||||||
struct wlr_egl *(*get_egl)(struct wlr_backend *backend);
|
|
||||||
struct wlr_renderer *(*get_renderer)(struct wlr_backend *backend);
|
struct wlr_renderer *(*get_renderer)(struct wlr_backend *backend);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,11 @@ struct wlr_renderer_impl {
|
||||||
struct wl_resource *resource);
|
struct wl_resource *resource);
|
||||||
void (*wl_drm_buffer_get_size)(struct wlr_renderer *renderer,
|
void (*wl_drm_buffer_get_size)(struct wlr_renderer *renderer,
|
||||||
struct wl_resource *buffer, int *width, int *height);
|
struct wl_resource *buffer, int *width, int *height);
|
||||||
|
bool (*check_import_dmabuf)(struct wlr_renderer *renderer,
|
||||||
|
struct wlr_dmabuf_buffer *dmabuf);
|
||||||
|
int (*get_dmabuf_formats)(struct wlr_renderer *renderer, int **formats);
|
||||||
|
int (*get_dmabuf_modifiers)(struct wlr_renderer *renderer, int format,
|
||||||
|
uint64_t **modifiers);
|
||||||
bool (*read_pixels)(struct wlr_renderer *renderer, enum wl_shm_format fmt,
|
bool (*read_pixels)(struct wlr_renderer *renderer, enum wl_shm_format fmt,
|
||||||
uint32_t stride, uint32_t width, uint32_t height,
|
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,
|
uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y,
|
||||||
|
|
|
@ -64,6 +64,22 @@ bool wlr_renderer_resource_is_wl_drm_buffer(struct wlr_renderer *renderer,
|
||||||
*/
|
*/
|
||||||
void wlr_renderer_wl_drm_buffer_get_size(struct wlr_renderer *renderer,
|
void wlr_renderer_wl_drm_buffer_get_size(struct wlr_renderer *renderer,
|
||||||
struct wl_resource *buffer, int *width, int *height);
|
struct wl_resource *buffer, int *width, int *height);
|
||||||
|
/**
|
||||||
|
* Get the available dmabuf formats
|
||||||
|
*/
|
||||||
|
int wlr_renderer_get_dmabuf_formats(struct wlr_renderer *renderer,
|
||||||
|
int **formats);
|
||||||
|
/**
|
||||||
|
* Get the available dmabuf modifiers for a given format
|
||||||
|
*/
|
||||||
|
int wlr_renderer_get_dmabuf_modifiers(struct wlr_renderer *renderer, int format,
|
||||||
|
uint64_t **modifiers);
|
||||||
|
/**
|
||||||
|
* 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_renderer_check_import_dmabuf(struct wlr_renderer *renderer,
|
||||||
|
struct wlr_dmabuf_buffer *dmabuf);
|
||||||
/**
|
/**
|
||||||
* Reads out of pixels of the currently bound surface into data. `stride` is in
|
* Reads out of pixels of the currently bound surface into data. `stride` is in
|
||||||
* bytes.
|
* bytes.
|
||||||
|
|
|
@ -32,7 +32,7 @@ struct wlr_dmabuf_buffer_attribs {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_dmabuf_buffer {
|
struct wlr_dmabuf_buffer {
|
||||||
struct wlr_egl *egl;
|
struct wlr_renderer *renderer;
|
||||||
struct wl_resource *buffer_resource;
|
struct wl_resource *buffer_resource;
|
||||||
struct wl_resource *params_resource;
|
struct wl_resource *params_resource;
|
||||||
struct wlr_dmabuf_buffer_attribs attributes;
|
struct wlr_dmabuf_buffer_attribs attributes;
|
||||||
|
@ -62,14 +62,14 @@ struct wlr_dmabuf_buffer *wlr_dmabuf_buffer_from_params_resource(
|
||||||
struct wlr_linux_dmabuf {
|
struct wlr_linux_dmabuf {
|
||||||
struct wl_global *wl_global;
|
struct wl_global *wl_global;
|
||||||
struct wl_listener display_destroy;
|
struct wl_listener display_destroy;
|
||||||
struct wlr_egl *egl;
|
struct wlr_renderer *renderer;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create linux-dmabuf interface
|
* Create linux-dmabuf interface
|
||||||
*/
|
*/
|
||||||
struct wlr_linux_dmabuf *wlr_linux_dmabuf_create(struct wl_display *display,
|
struct wlr_linux_dmabuf *wlr_linux_dmabuf_create(struct wl_display *display,
|
||||||
struct wlr_egl *egl);
|
struct wlr_renderer *renderer);
|
||||||
/**
|
/**
|
||||||
* Destroy the linux-dmabuf interface
|
* Destroy the linux-dmabuf interface
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -222,6 +222,24 @@ static void gles2_wl_drm_buffer_get_size(struct wlr_renderer *wlr_renderer,
|
||||||
eglQueryWaylandBufferWL(renderer->egl->display, buffer, EGL_HEIGHT, height);
|
eglQueryWaylandBufferWL(renderer->egl->display, buffer, EGL_HEIGHT, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int gles2_get_dmabuf_formats(struct wlr_renderer *wlr_renderer,
|
||||||
|
int **formats) {
|
||||||
|
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||||
|
return wlr_egl_get_dmabuf_formats(renderer->egl, formats);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int gles2_get_dmabuf_modifiers(struct wlr_renderer *wlr_renderer,
|
||||||
|
int format, uint64_t **modifiers) {
|
||||||
|
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||||
|
return wlr_egl_get_dmabuf_modifiers(renderer->egl, format, modifiers);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool gles2_check_import_dmabuf(struct wlr_renderer *wlr_renderer,
|
||||||
|
struct wlr_dmabuf_buffer *dmabuf) {
|
||||||
|
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||||
|
return wlr_egl_check_import_dmabuf(renderer->egl, dmabuf);
|
||||||
|
}
|
||||||
|
|
||||||
static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
|
static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
|
||||||
enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width,
|
enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width,
|
||||||
uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x,
|
uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x,
|
||||||
|
@ -311,6 +329,9 @@ static const struct wlr_renderer_impl renderer_impl = {
|
||||||
.formats = gles2_renderer_formats,
|
.formats = gles2_renderer_formats,
|
||||||
.resource_is_wl_drm_buffer = gles2_resource_is_wl_drm_buffer,
|
.resource_is_wl_drm_buffer = gles2_resource_is_wl_drm_buffer,
|
||||||
.wl_drm_buffer_get_size = gles2_wl_drm_buffer_get_size,
|
.wl_drm_buffer_get_size = gles2_wl_drm_buffer_get_size,
|
||||||
|
.get_dmabuf_formats = gles2_get_dmabuf_formats,
|
||||||
|
.get_dmabuf_modifiers = gles2_get_dmabuf_modifiers,
|
||||||
|
.check_import_dmabuf = gles2_check_import_dmabuf,
|
||||||
.read_pixels = gles2_read_pixels,
|
.read_pixels = gles2_read_pixels,
|
||||||
.format_supported = gles2_format_supported,
|
.format_supported = gles2_format_supported,
|
||||||
.texture_from_pixels = gles2_texture_from_pixels,
|
.texture_from_pixels = gles2_texture_from_pixels,
|
||||||
|
|
|
@ -112,6 +112,30 @@ void wlr_renderer_wl_drm_buffer_get_size(struct wlr_renderer *r,
|
||||||
return r->impl->wl_drm_buffer_get_size(r, buffer, width, height);
|
return r->impl->wl_drm_buffer_get_size(r, buffer, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int wlr_renderer_get_dmabuf_formats(struct wlr_renderer *r,
|
||||||
|
int **formats) {
|
||||||
|
if (!r->impl->get_dmabuf_formats) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return r->impl->get_dmabuf_formats(r, formats);
|
||||||
|
}
|
||||||
|
|
||||||
|
int wlr_renderer_get_dmabuf_modifiers(struct wlr_renderer *r, int format,
|
||||||
|
uint64_t **modifiers) {
|
||||||
|
if (!r->impl->get_dmabuf_modifiers) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return r->impl->get_dmabuf_modifiers(r, format, modifiers);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wlr_renderer_check_import_dmabuf(struct wlr_renderer *r,
|
||||||
|
struct wlr_dmabuf_buffer *dmabuf) {
|
||||||
|
if (!r->impl->check_import_dmabuf) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return r->impl->check_import_dmabuf(r, dmabuf);
|
||||||
|
}
|
||||||
|
|
||||||
bool wlr_renderer_read_pixels(struct wlr_renderer *r, enum wl_shm_format fmt,
|
bool wlr_renderer_read_pixels(struct wlr_renderer *r, enum wl_shm_format fmt,
|
||||||
uint32_t stride, uint32_t width, uint32_t height,
|
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,
|
uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y,
|
||||||
|
|
|
@ -869,8 +869,8 @@ struct roots_desktop *desktop_create(struct roots_server *server,
|
||||||
wl_signal_add(&desktop->input_inhibit->events.deactivate,
|
wl_signal_add(&desktop->input_inhibit->events.deactivate,
|
||||||
&desktop->input_inhibit_deactivate);
|
&desktop->input_inhibit_deactivate);
|
||||||
|
|
||||||
struct wlr_egl *egl = wlr_backend_get_egl(server->backend);
|
desktop->linux_dmabuf = wlr_linux_dmabuf_create(server->wl_display,
|
||||||
desktop->linux_dmabuf = wlr_linux_dmabuf_create(server->wl_display, egl);
|
server->renderer);
|
||||||
return desktop;
|
return desktop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#ifndef _POSIX_C_SOURCE
|
|
||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#endif
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include <wlr/render/egl.h>
|
#include <wlr/render/wlr_renderer.h>
|
||||||
#include <wlr/types/wlr_linux_dmabuf.h>
|
#include <wlr/types/wlr_linux_dmabuf.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "linux-dmabuf-unstable-v1-protocol.h"
|
#include "linux-dmabuf-unstable-v1-protocol.h"
|
||||||
|
@ -25,7 +23,8 @@ bool wlr_dmabuf_resource_is_buffer(struct wl_resource *buffer_resource) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_dmabuf_buffer *buffer = wl_resource_get_user_data(buffer_resource);
|
struct wlr_dmabuf_buffer *buffer =
|
||||||
|
wl_resource_get_user_data(buffer_resource);
|
||||||
if (buffer && buffer->buffer_resource && !buffer->params_resource &&
|
if (buffer && buffer->buffer_resource && !buffer->params_resource &&
|
||||||
buffer->buffer_resource == buffer_resource) {
|
buffer->buffer_resource == buffer_resource) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -39,7 +38,8 @@ struct wlr_dmabuf_buffer *wlr_dmabuf_buffer_from_buffer_resource(
|
||||||
assert(wl_resource_instance_of(buffer_resource, &wl_buffer_interface,
|
assert(wl_resource_instance_of(buffer_resource, &wl_buffer_interface,
|
||||||
&wl_buffer_impl));
|
&wl_buffer_impl));
|
||||||
|
|
||||||
struct wlr_dmabuf_buffer *buffer = wl_resource_get_user_data(buffer_resource);
|
struct wlr_dmabuf_buffer *buffer =
|
||||||
|
wl_resource_get_user_data(buffer_resource);
|
||||||
assert(buffer);
|
assert(buffer);
|
||||||
assert(buffer->buffer_resource);
|
assert(buffer->buffer_resource);
|
||||||
assert(!buffer->params_resource);
|
assert(!buffer->params_resource);
|
||||||
|
@ -57,7 +57,8 @@ static void linux_dmabuf_buffer_destroy(struct wlr_dmabuf_buffer *buffer) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void params_destroy(struct wl_client *client, struct wl_resource *resource) {
|
static void params_destroy(struct wl_client *client,
|
||||||
|
struct wl_resource *resource) {
|
||||||
wl_resource_destroy(resource);
|
wl_resource_destroy(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,8 +66,8 @@ static void params_add(struct wl_client *client,
|
||||||
struct wl_resource *params_resource, int32_t name_fd,
|
struct wl_resource *params_resource, int32_t name_fd,
|
||||||
uint32_t plane_idx, uint32_t offset, uint32_t stride,
|
uint32_t plane_idx, uint32_t offset, uint32_t stride,
|
||||||
uint32_t modifier_hi, uint32_t modifier_lo) {
|
uint32_t modifier_hi, uint32_t modifier_lo) {
|
||||||
struct wlr_dmabuf_buffer *buffer = wlr_dmabuf_buffer_from_params_resource(
|
struct wlr_dmabuf_buffer *buffer =
|
||||||
params_resource);
|
wlr_dmabuf_buffer_from_params_resource(params_resource);
|
||||||
|
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
wl_resource_post_error(params_resource,
|
wl_resource_post_error(params_resource,
|
||||||
|
@ -97,15 +98,15 @@ static void params_add(struct wl_client *client,
|
||||||
buffer->attributes.fd[plane_idx] = name_fd;
|
buffer->attributes.fd[plane_idx] = name_fd;
|
||||||
buffer->attributes.offset[plane_idx] = offset;
|
buffer->attributes.offset[plane_idx] = offset;
|
||||||
buffer->attributes.stride[plane_idx] = stride;
|
buffer->attributes.stride[plane_idx] = stride;
|
||||||
buffer->attributes.modifier[plane_idx] = ((uint64_t)modifier_hi << 32) |
|
buffer->attributes.modifier[plane_idx] =
|
||||||
modifier_lo;
|
((uint64_t)modifier_hi << 32) | modifier_lo;
|
||||||
buffer->attributes.n_planes++;
|
buffer->attributes.n_planes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_buffer_destroy(struct wl_resource *buffer_resource)
|
static void handle_buffer_destroy(struct wl_resource *buffer_resource)
|
||||||
{
|
{
|
||||||
struct wlr_dmabuf_buffer *buffer = wlr_dmabuf_buffer_from_buffer_resource(
|
struct wlr_dmabuf_buffer *buffer =
|
||||||
buffer_resource);
|
wlr_dmabuf_buffer_from_buffer_resource(buffer_resource);
|
||||||
|
|
||||||
linux_dmabuf_buffer_destroy(buffer);
|
linux_dmabuf_buffer_destroy(buffer);
|
||||||
}
|
}
|
||||||
|
@ -119,8 +120,8 @@ static void params_create_common(struct wl_client *client,
|
||||||
"params was already used to create a wl_buffer");
|
"params was already used to create a wl_buffer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
struct wlr_dmabuf_buffer *buffer = wlr_dmabuf_buffer_from_params_resource(
|
struct wlr_dmabuf_buffer *buffer =
|
||||||
params_resource);
|
wlr_dmabuf_buffer_from_params_resource(params_resource);
|
||||||
|
|
||||||
/* Switch the linux_dmabuf_buffer object from params resource to
|
/* Switch the linux_dmabuf_buffer object from params resource to
|
||||||
* eventually wl_buffer resource. */
|
* eventually wl_buffer resource. */
|
||||||
|
@ -216,7 +217,7 @@ static void params_create_common(struct wl_client *client,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if dmabuf is usable */
|
/* Check if dmabuf is usable */
|
||||||
if (!wlr_egl_check_import_dmabuf(buffer->egl, buffer)) {
|
if (!wlr_renderer_check_import_dmabuf(buffer->renderer, buffer)) {
|
||||||
goto err_failed;
|
goto err_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,26 +255,28 @@ err_failed:
|
||||||
}
|
}
|
||||||
err_out:
|
err_out:
|
||||||
linux_dmabuf_buffer_destroy(buffer);
|
linux_dmabuf_buffer_destroy(buffer);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void params_create(struct wl_client *client,
|
static void params_create(struct wl_client *client,
|
||||||
struct wl_resource *params_resource,
|
struct wl_resource *params_resource,
|
||||||
int32_t width, int32_t height, uint32_t format, uint32_t flags) {
|
int32_t width, int32_t height, uint32_t format, uint32_t flags) {
|
||||||
params_create_common(client, params_resource, 0, width, height, format, flags);
|
params_create_common(client, params_resource, 0, width, height, format,
|
||||||
|
flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void params_create_immed(struct wl_client *client,
|
static void params_create_immed(struct wl_client *client,
|
||||||
struct wl_resource *params_resource, uint32_t buffer_id,
|
struct wl_resource *params_resource, uint32_t buffer_id,
|
||||||
int32_t width, int32_t height, uint32_t format, uint32_t flags) {
|
int32_t width, int32_t height, uint32_t format, uint32_t flags) {
|
||||||
params_create_common(client, params_resource, buffer_id, width, height, format, flags);
|
params_create_common(client, params_resource, buffer_id, width, height,
|
||||||
|
format, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct zwp_linux_buffer_params_v1_interface linux_buffer_params_impl = {
|
static const struct zwp_linux_buffer_params_v1_interface
|
||||||
params_destroy,
|
linux_buffer_params_impl = {
|
||||||
params_add,
|
.destroy = params_destroy,
|
||||||
params_create,
|
.add = params_add,
|
||||||
params_create_immed,
|
.create = params_create,
|
||||||
|
.create_immed = params_create_immed,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_dmabuf_buffer *wlr_dmabuf_buffer_from_params_resource(
|
struct wlr_dmabuf_buffer *wlr_dmabuf_buffer_from_params_resource(
|
||||||
|
@ -282,7 +285,8 @@ struct wlr_dmabuf_buffer *wlr_dmabuf_buffer_from_params_resource(
|
||||||
&zwp_linux_buffer_params_v1_interface,
|
&zwp_linux_buffer_params_v1_interface,
|
||||||
&linux_buffer_params_impl));
|
&linux_buffer_params_impl));
|
||||||
|
|
||||||
struct wlr_dmabuf_buffer *buffer = wl_resource_get_user_data(params_resource);
|
struct wlr_dmabuf_buffer *buffer =
|
||||||
|
wl_resource_get_user_data(params_resource);
|
||||||
assert(buffer);
|
assert(buffer);
|
||||||
assert(buffer->params_resource);
|
assert(buffer->params_resource);
|
||||||
assert(!buffer->buffer_resource);
|
assert(!buffer->buffer_resource);
|
||||||
|
@ -305,8 +309,8 @@ static void handle_params_destroy(struct wl_resource *params_resource) {
|
||||||
static void linux_dmabuf_create_params(struct wl_client *client,
|
static void linux_dmabuf_create_params(struct wl_client *client,
|
||||||
struct wl_resource *linux_dmabuf_resource,
|
struct wl_resource *linux_dmabuf_resource,
|
||||||
uint32_t params_id) {
|
uint32_t params_id) {
|
||||||
struct wlr_linux_dmabuf *linux_dmabuf = wlr_linux_dmabuf_from_resource(
|
struct wlr_linux_dmabuf *linux_dmabuf =
|
||||||
linux_dmabuf_resource);
|
wlr_linux_dmabuf_from_resource(linux_dmabuf_resource);
|
||||||
|
|
||||||
uint32_t version = wl_resource_get_version(linux_dmabuf_resource);
|
uint32_t version = wl_resource_get_version(linux_dmabuf_resource);
|
||||||
struct wlr_dmabuf_buffer *buffer = calloc(1, sizeof *buffer);
|
struct wlr_dmabuf_buffer *buffer = calloc(1, sizeof *buffer);
|
||||||
|
@ -318,7 +322,7 @@ static void linux_dmabuf_create_params(struct wl_client *client,
|
||||||
buffer->attributes.fd[i] = -1;
|
buffer->attributes.fd[i] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->egl = linux_dmabuf->egl;
|
buffer->renderer = linux_dmabuf->renderer;
|
||||||
buffer->params_resource = wl_resource_create(client,
|
buffer->params_resource = wl_resource_create(client,
|
||||||
&zwp_linux_buffer_params_v1_interface,
|
&zwp_linux_buffer_params_v1_interface,
|
||||||
version, params_id);
|
version, params_id);
|
||||||
|
@ -336,13 +340,14 @@ err:
|
||||||
wl_resource_post_no_memory(linux_dmabuf_resource);
|
wl_resource_post_no_memory(linux_dmabuf_resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void linux_dmabuf_destroy(struct wl_client *client, struct wl_resource *resource) {
|
static void linux_dmabuf_destroy(struct wl_client *client,
|
||||||
|
struct wl_resource *resource) {
|
||||||
wl_resource_destroy(resource);
|
wl_resource_destroy(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct zwp_linux_dmabuf_v1_interface linux_dmabuf_impl = {
|
static const struct zwp_linux_dmabuf_v1_interface linux_dmabuf_impl = {
|
||||||
linux_dmabuf_destroy,
|
.destroy = linux_dmabuf_destroy,
|
||||||
linux_dmabuf_create_params
|
.create_params = linux_dmabuf_create_params,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_linux_dmabuf *wlr_linux_dmabuf_from_resource(
|
struct wlr_linux_dmabuf *wlr_linux_dmabuf_from_resource(
|
||||||
|
@ -357,25 +362,22 @@ struct wlr_linux_dmabuf *wlr_linux_dmabuf_from_resource(
|
||||||
|
|
||||||
static void linux_dmabuf_send_modifiers(struct wlr_linux_dmabuf *linux_dmabuf,
|
static void linux_dmabuf_send_modifiers(struct wlr_linux_dmabuf *linux_dmabuf,
|
||||||
struct wl_resource *resource) {
|
struct wl_resource *resource) {
|
||||||
struct wlr_egl *egl = linux_dmabuf->egl;
|
struct wlr_renderer *renderer = linux_dmabuf->renderer;
|
||||||
/*
|
/*
|
||||||
* Use EGL_EXT_image_dma_buf_import_modifiers to query and advertise
|
* Use EGL_EXT_image_dma_buf_import_modifiers to query and advertise
|
||||||
* format/modifier codes.
|
* format/modifier codes.
|
||||||
*/
|
*/
|
||||||
uint64_t modifier_invalid = DRM_FORMAT_MOD_INVALID;
|
uint64_t modifier_invalid = DRM_FORMAT_MOD_INVALID;
|
||||||
int *formats = NULL;
|
int *formats = NULL;
|
||||||
int num_formats = wlr_egl_get_dmabuf_formats(egl, &formats);
|
int num_formats = wlr_renderer_get_dmabuf_formats(renderer, &formats);
|
||||||
|
|
||||||
if (num_formats < 0) {
|
if (num_formats < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < num_formats; i++) {
|
for (int i = 0; i < num_formats; i++) {
|
||||||
int num_modifiers;
|
|
||||||
uint64_t *modifiers = NULL;
|
uint64_t *modifiers = NULL;
|
||||||
|
int num_modifiers = wlr_renderer_get_dmabuf_modifiers(renderer,
|
||||||
num_modifiers = wlr_egl_get_dmabuf_modifiers(egl, formats[i],
|
formats[i], &modifiers);
|
||||||
&modifiers);
|
|
||||||
if (num_modifiers < 0) {
|
if (num_modifiers < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -389,8 +391,7 @@ static void linux_dmabuf_send_modifiers(struct wlr_linux_dmabuf *linux_dmabuf,
|
||||||
uint32_t modifier_lo = modifiers[j] & 0xFFFFFFFF;
|
uint32_t modifier_lo = modifiers[j] & 0xFFFFFFFF;
|
||||||
uint32_t modifier_hi = modifiers[j] >> 32;
|
uint32_t modifier_hi = modifiers[j] >> 32;
|
||||||
zwp_linux_dmabuf_v1_send_modifier(resource, formats[i],
|
zwp_linux_dmabuf_v1_send_modifier(resource, formats[i],
|
||||||
modifier_hi,
|
modifier_hi, modifier_lo);
|
||||||
modifier_lo);
|
|
||||||
}
|
}
|
||||||
if (modifiers != &modifier_invalid) {
|
if (modifiers != &modifier_invalid) {
|
||||||
free(modifiers);
|
free(modifiers);
|
||||||
|
@ -399,13 +400,12 @@ static void linux_dmabuf_send_modifiers(struct wlr_linux_dmabuf *linux_dmabuf,
|
||||||
free(formats);
|
free(formats);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void linux_dmabuf_bind(struct wl_client *client,
|
static void linux_dmabuf_bind(struct wl_client *client, void *data,
|
||||||
void *data, uint32_t version, uint32_t id) {
|
uint32_t version, uint32_t id) {
|
||||||
struct wlr_linux_dmabuf *linux_dmabuf = data;
|
struct wlr_linux_dmabuf *linux_dmabuf = data;
|
||||||
struct wl_resource *resource = wl_resource_create(client,
|
|
||||||
&zwp_linux_dmabuf_v1_interface,
|
|
||||||
version, id);
|
|
||||||
|
|
||||||
|
struct wl_resource *resource = wl_resource_create(client,
|
||||||
|
&zwp_linux_dmabuf_v1_interface, version, id);
|
||||||
if (resource == NULL) {
|
if (resource == NULL) {
|
||||||
wl_client_post_no_memory(client);
|
wl_client_post_no_memory(client);
|
||||||
return;
|
return;
|
||||||
|
@ -431,32 +431,32 @@ void wlr_linux_dmabuf_destroy(struct wlr_linux_dmabuf *linux_dmabuf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
||||||
struct wlr_linux_dmabuf *linux_dmabuf = wl_container_of(listener, linux_dmabuf, display_destroy);
|
struct wlr_linux_dmabuf *linux_dmabuf =
|
||||||
|
wl_container_of(listener, linux_dmabuf, display_destroy);
|
||||||
wlr_linux_dmabuf_destroy(linux_dmabuf);
|
wlr_linux_dmabuf_destroy(linux_dmabuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_linux_dmabuf *wlr_linux_dmabuf_create(struct wl_display *display,
|
struct wlr_linux_dmabuf *wlr_linux_dmabuf_create(struct wl_display *display,
|
||||||
struct wlr_egl *egl) {
|
struct wlr_renderer *renderer) {
|
||||||
struct wlr_linux_dmabuf *linux_dmabuf =
|
struct wlr_linux_dmabuf *linux_dmabuf =
|
||||||
calloc(1, sizeof(struct wlr_linux_dmabuf));
|
calloc(1, sizeof(struct wlr_linux_dmabuf));
|
||||||
if (linux_dmabuf == NULL) {
|
if (linux_dmabuf == NULL) {
|
||||||
wlr_log(L_ERROR, "could not create simple dmabuf manager");
|
wlr_log(L_ERROR, "could not create simple dmabuf manager");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
linux_dmabuf->renderer = renderer;
|
||||||
linux_dmabuf->display_destroy.notify = handle_display_destroy;
|
|
||||||
wl_display_add_destroy_listener(display, &linux_dmabuf->display_destroy);
|
|
||||||
|
|
||||||
linux_dmabuf->wl_global =
|
linux_dmabuf->wl_global =
|
||||||
wl_global_create(display, &zwp_linux_dmabuf_v1_interface,
|
wl_global_create(display, &zwp_linux_dmabuf_v1_interface,
|
||||||
3, linux_dmabuf, linux_dmabuf_bind);
|
3, linux_dmabuf, linux_dmabuf_bind);
|
||||||
|
|
||||||
linux_dmabuf->egl = egl;
|
|
||||||
if (!linux_dmabuf->wl_global) {
|
if (!linux_dmabuf->wl_global) {
|
||||||
wlr_log(L_ERROR, "could not create linux dmabuf v1 wl global");
|
wlr_log(L_ERROR, "could not create linux dmabuf v1 wl global");
|
||||||
free(linux_dmabuf);
|
free(linux_dmabuf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linux_dmabuf->display_destroy.notify = handle_display_destroy;
|
||||||
|
wl_display_add_destroy_listener(display, &linux_dmabuf->display_destroy);
|
||||||
|
|
||||||
return linux_dmabuf;
|
return linux_dmabuf;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue