Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

External renderer #3195

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions backend/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ void wlr_backend_init(struct wlr_backend *backend,
void wlr_backend_finish(struct wlr_backend *backend) {
wlr_signal_emit_safe(&backend->events.destroy, backend);
wlr_allocator_destroy(backend->allocator);
if (backend->has_own_renderer) {
wlr_renderer_destroy(backend->renderer);
}
}

bool wlr_backend_start(struct wlr_backend *backend) {
Expand All @@ -71,33 +68,10 @@ void wlr_backend_destroy(struct wlr_backend *backend) {
}
}

static bool backend_create_renderer(struct wlr_backend *backend) {
if (backend->renderer != NULL) {
return true;
}

backend->renderer = wlr_renderer_autocreate(backend);
if (backend->renderer == NULL) {
return false;
}

backend->has_own_renderer = true;
return true;
}

struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend) {
if (backend->impl->get_renderer) {
return backend->impl->get_renderer(backend);
}
if (backend_get_buffer_caps(backend) != 0) {
// If the backend is capable of presenting buffers, automatically create
// the renderer if necessary.
if (!backend_create_renderer(backend)) {
wlr_log(WLR_ERROR, "Failed to create backend renderer");
return NULL;
}
return backend->renderer;
}
return NULL;
}

Expand Down
11 changes: 3 additions & 8 deletions backend/drm/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,

if (drm->parent) {
// Ensure we use the same renderer as the parent backend
drm->backend.renderer = wlr_backend_get_renderer(&drm->parent->backend);
assert(drm->backend.renderer != NULL);
struct wlr_renderer *parent_renderer =
wlr_backend_get_renderer(&drm->parent->backend);
assert(parent_renderer != NULL);

if (!init_drm_renderer(drm, &drm->mgpu_renderer)) {
wlr_log(WLR_ERROR, "Failed to initialize renderer");
Expand Down Expand Up @@ -258,12 +259,6 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
}
}

struct wlr_renderer *renderer = wlr_backend_get_renderer(&drm->backend);
struct wlr_allocator *allocator = backend_get_allocator(&drm->backend);
if (renderer == NULL || allocator == NULL) {
goto error_mgpu_renderer;
}

drm->session_destroy.notify = handle_session_destroy;
wl_signal_add(&session->events.destroy, &drm->session_destroy);

Expand Down
2 changes: 1 addition & 1 deletion backend/drm/drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <wayland-util.h>
#include <wlr/backend/interface.h>
#include <wlr/interfaces/wlr_output.h>
#include <wlr/render/pixel_format.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/util/box.h>
Expand All @@ -25,7 +26,6 @@
#include "backend/drm/drm.h"
#include "backend/drm/iface.h"
#include "backend/drm/util.h"
#include "render/pixel_format.h"
#include "render/drm_format_set.h"
#include "render/swapchain.h"
#include "render/wlr_renderer.h"
Expand Down
6 changes: 3 additions & 3 deletions backend/drm/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#include <string.h>
#include <unistd.h>
#include <wayland-util.h>
#include <wlr/render/pixel_format.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/util/log.h>
#include "backend/drm/drm.h"
#include "backend/drm/util.h"
#include "render/drm_format_set.h"
#include "render/allocator/allocator.h"
#include "render/pixel_format.h"
#include "render/swapchain.h"
#include "render/wlr_renderer.h"

Expand Down Expand Up @@ -151,7 +151,7 @@ struct wlr_drm_format *drm_plane_pick_render_format(
uint32_t fmt = DRM_FORMAT_ARGB8888;
if (!wlr_drm_format_set_has(&plane->formats, fmt, DRM_FORMAT_MOD_INVALID)) {
const struct wlr_pixel_format_info *format_info =
drm_get_pixel_format_info(fmt);
wlr_pixel_format_info_from_drm(fmt);
assert(format_info != NULL &&
format_info->opaque_substitute != DRM_FORMAT_INVALID);
fmt = format_info->opaque_substitute;
Expand Down Expand Up @@ -306,7 +306,7 @@ static struct wlr_drm_fb *drm_fb_create(struct wlr_drm_backend *drm,
// The format isn't supported by the plane. Try stripping the alpha
// channel, if any.
const struct wlr_pixel_format_info *info =
drm_get_pixel_format_info(attribs.format);
wlr_pixel_format_info_from_drm(attribs.format);
if (info != NULL && info->opaque_substitute != DRM_FORMAT_INVALID &&
wlr_drm_format_set_has(formats, info->opaque_substitute, attribs.modifier)) {
attribs.format = info->opaque_substitute;
Expand Down
4 changes: 2 additions & 2 deletions backend/headless/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static struct wlr_renderer *backend_get_renderer(
if (backend->parent_renderer != NULL) {
return backend->parent_renderer;
} else {
return wlr_backend->renderer;
return backend->renderer;
}
}

Expand Down Expand Up @@ -130,7 +130,7 @@ static bool backend_init(struct wlr_headless_backend *backend,
wlr_log(WLR_ERROR, "Failed to create renderer");
return false;
}
backend->backend.renderer = renderer;
backend->renderer = renderer;
} else {
backend->parent_renderer = renderer;
backend->parent_renderer_destroy.notify = handle_renderer_destroy;
Expand Down
12 changes: 2 additions & 10 deletions backend/wayland/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
#include <wlr/backend/interface.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_output.h>
#include <wlr/render/pixel_format.h>
#include <wlr/util/log.h>

#include "backend/backend.h"
#include "backend/wayland.h"
#include "render/drm_format_set.h"
#include "render/pixel_format.h"
#include "render/wlr_renderer.h"
#include "util/signal.h"

Expand Down Expand Up @@ -192,7 +192,7 @@ static const struct wl_drm_listener legacy_drm_listener = {
static void shm_handle_format(void *data, struct wl_shm *shm,
uint32_t shm_format) {
struct wlr_wl_backend *wl = data;
uint32_t drm_format = convert_wl_shm_format_to_drm(shm_format);
uint32_t drm_format = wlr_convert_wl_shm_format_to_drm(shm_format);
wlr_drm_format_set_add(&wl->shm_formats, drm_format, DRM_FORMAT_MOD_INVALID);
}

Expand Down Expand Up @@ -444,19 +444,11 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
wl->drm_fd = -1;
}

struct wlr_renderer *renderer = wlr_backend_get_renderer(&wl->backend);
struct wlr_allocator *allocator = backend_get_allocator(&wl->backend);
if (renderer == NULL || allocator == NULL) {
goto error_drm_fd;
}

wl->local_display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &wl->local_display_destroy);

return &wl->backend;

error_drm_fd:
close(wl->drm_fd);
error_remote_display_src:
wl_event_source_remove(wl->remote_display_src);
error_registry:
Expand Down
5 changes: 3 additions & 2 deletions backend/wayland/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
#include <wayland-client.h>

#include <wlr/interfaces/wlr_output.h>
#include <wlr/render/pixel_format.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/util/log.h>

#include "backend/wayland.h"
#include "render/pixel_format.h"
#include "render/swapchain.h"
#include "render/wlr_renderer.h"
#include "util/signal.h"
Expand Down Expand Up @@ -178,7 +178,8 @@ static struct wl_buffer *import_dmabuf(struct wlr_wl_backend *wl,

static struct wl_buffer *import_shm(struct wlr_wl_backend *wl,
struct wlr_shm_attributes *shm) {
enum wl_shm_format wl_shm_format = convert_drm_format_to_wl_shm(shm->format);
enum wl_shm_format wl_shm_format =
wlr_convert_drm_format_to_wl_shm(shm->format);
uint32_t size = shm->stride * shm->height;
struct wl_shm_pool *pool = wl_shm_create_pool(wl->shm, shm->fd, size);
if (pool == NULL) {
Expand Down
6 changes: 0 additions & 6 deletions backend/x11/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,6 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
}
}

struct wlr_renderer *renderer = wlr_backend_get_renderer(&x11->backend);
struct wlr_allocator *allocator = backend_get_allocator(&x11->backend);
if (renderer == NULL || allocator == NULL) {
goto error_event;
}

// Windows can only display buffers with the depth they were created with
// TODO: look into changing the window's depth at runtime
const struct wlr_drm_format *dri3_format =
Expand Down
1 change: 1 addition & 0 deletions include/backend/headless.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct wlr_headless_backend {
struct wl_list input_devices;
struct wl_listener display_destroy;
struct wlr_renderer *parent_renderer;
struct wlr_renderer *renderer;
struct wl_listener parent_renderer_destroy;
bool started;
};
Expand Down
54 changes: 37 additions & 17 deletions include/render/egl.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
#ifndef RENDER_EGL_H
#define RENDER_EGL_H

#include <wlr/render/dmabuf.h>
#include <wlr/render/egl.h>

struct wlr_egl_context {
EGLDisplay display;
EGLContext context;
EGLSurface draw_surface;
EGLSurface read_surface;
struct wlr_egl {
struct wlr_egl_context ctx;
EGLDeviceEXT device; // may be EGL_NO_DEVICE_EXT
struct gbm_device *gbm_device;

struct {
// Display extensions
bool KHR_image_base;
bool EXT_image_dma_buf_import;
bool EXT_image_dma_buf_import_modifiers;

// Device extensions
bool EXT_device_drm;
bool EXT_device_drm_render_node;

// Client extensions
bool EXT_device_query;
bool KHR_platform_gbm;
bool EXT_platform_device;
} exts;

struct {
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT;
PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
PFNEGLQUERYWAYLANDBUFFERWL eglQueryWaylandBufferWL;
PFNEGLQUERYDMABUFFORMATSEXTPROC eglQueryDmaBufFormatsEXT;
PFNEGLQUERYDMABUFMODIFIERSEXTPROC eglQueryDmaBufModifiersEXT;
PFNEGLDEBUGMESSAGECONTROLKHRPROC eglDebugMessageControlKHR;
PFNEGLQUERYDISPLAYATTRIBEXTPROC eglQueryDisplayAttribEXT;
PFNEGLQUERYDEVICESTRINGEXTPROC eglQueryDeviceStringEXT;
PFNEGLQUERYDEVICESEXTPROC eglQueryDevicesEXT;
} procs;

struct wlr_drm_format_set dmabuf_texture_formats;
struct wlr_drm_format_set dmabuf_render_formats;
};

/**
Expand Down Expand Up @@ -48,16 +80,4 @@ bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImageKHR image);

int wlr_egl_dup_drm_fd(struct wlr_egl *egl);

/**
* Save the current EGL context to the structure provided in the argument.
*
* This includes display, context, draw surface and read surface.
*/
void wlr_egl_save_context(struct wlr_egl_context *context);

/**
* Restore EGL context that was previously saved using wlr_egl_save_current().
*/
bool wlr_egl_restore_context(struct wlr_egl_context *context);

#endif
1 change: 1 addition & 0 deletions include/render/gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct wlr_gles2_texture {
struct wlr_addon buffer_addon;
};

struct wlr_renderer *gles2_renderer_create(struct wlr_egl *egl);

bool is_gles2_pixel_format_supported(const struct wlr_gles2_renderer *renderer,
const struct wlr_gles2_pixel_format *format);
Expand Down
26 changes: 0 additions & 26 deletions include/render/pixel_format.h

This file was deleted.

4 changes: 2 additions & 2 deletions include/render/pixman.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef RENDER_PIXMAN_H
#define RENDER_PIXMAN_H

#include <wlr/render/drm_format_set.h>
#include <wlr/render/pixel_format.h>
#include <wlr/render/pixman.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/render/drm_format_set.h>
#include "render/pixel_format.h"

struct wlr_pixman_pixel_format {
uint32_t drm_format;
Expand Down
2 changes: 0 additions & 2 deletions include/wlr/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ struct wlr_backend {

// Private state

bool has_own_renderer;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
};

Expand Down
Loading