render/gbm_allocator: make wlr_gbm_allocator_create return a wlr_allocator

This commit is contained in:
Simon Zeni 2021-04-15 14:32:13 -04:00 committed by Simon Ser
parent 3a04fb4560
commit c75aa71816
7 changed files with 24 additions and 21 deletions

View file

@ -62,7 +62,7 @@ void finish_drm_renderer(struct wlr_drm_renderer *renderer) {
return;
}
wlr_allocator_destroy(&renderer->allocator->base);
wlr_allocator_destroy(renderer->allocator);
wlr_renderer_destroy(renderer->wlr_rend);
gbm_device_destroy(renderer->gbm);
}
@ -83,8 +83,8 @@ static bool init_drm_surface(struct wlr_drm_surface *surf,
wlr_swapchain_destroy(surf->swapchain);
surf->swapchain = NULL;
surf->swapchain = wlr_swapchain_create(&renderer->allocator->base,
width, height, drm_format);
surf->swapchain = wlr_swapchain_create(renderer->allocator, width, height,
drm_format);
if (surf->swapchain == NULL) {
wlr_log(WLR_ERROR, "Failed to create swapchain");
memset(surf, 0, sizeof(*surf));

View file

@ -220,21 +220,21 @@ struct wlr_backend *wlr_headless_backend_create(struct wl_display *display) {
goto error_dup;
}
struct wlr_gbm_allocator *gbm_alloc = wlr_gbm_allocator_create(drm_fd);
if (gbm_alloc == NULL) {
struct wlr_allocator *alloc = wlr_gbm_allocator_create(drm_fd);
if (alloc == NULL) {
wlr_log(WLR_ERROR, "Failed to create GBM allocator");
close(drm_fd);
goto error_dup;
}
if (!backend_init(backend, display, &gbm_alloc->base, NULL)) {
if (!backend_init(backend, display, alloc, NULL)) {
goto error_init;
}
return &backend->backend;
error_init:
wlr_allocator_destroy(&gbm_alloc->base);
wlr_allocator_destroy(alloc);
error_dup:
close(backend->drm_fd);
error_drm_fd:
@ -266,14 +266,14 @@ struct wlr_backend *wlr_headless_backend_create_with_renderer(
goto error_dup;
}
struct wlr_gbm_allocator *gbm_alloc = wlr_gbm_allocator_create(drm_fd);
if (gbm_alloc == NULL) {
struct wlr_allocator *alloc = wlr_gbm_allocator_create(drm_fd);
if (alloc == NULL) {
wlr_log(WLR_ERROR, "Failed to create GBM allocator");
close(drm_fd);
goto error_dup;
}
if (!backend_init(backend, display, &gbm_alloc->base, renderer)) {
if (!backend_init(backend, display, alloc, renderer)) {
goto error_init;
}
@ -283,7 +283,7 @@ struct wlr_backend *wlr_headless_backend_create_with_renderer(
return &backend->backend;
error_init:
wlr_allocator_destroy(&gbm_alloc->base);
wlr_allocator_destroy(alloc);
error_dup:
close(backend->drm_fd);
error_drm_fd:

View file

@ -452,13 +452,13 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
goto error_drm_fd;
}
struct wlr_gbm_allocator *gbm_alloc = wlr_gbm_allocator_create(drm_fd);
if (gbm_alloc == NULL) {
struct wlr_allocator *alloc = wlr_gbm_allocator_create(drm_fd);
if (alloc == NULL) {
wlr_log(WLR_ERROR, "Failed to create GBM allocator");
close(drm_fd);
goto error_drm_fd;
}
wl->allocator = &gbm_alloc->base;
wl->allocator = alloc;
} else {
wlr_log(WLR_DEBUG, "No render node found, falling back to shared memory");
struct wlr_shm_allocator *shm_alloc = wlr_shm_allocator_create();

View file

@ -622,13 +622,13 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
goto error_event;
}
struct wlr_gbm_allocator *gbm_alloc = wlr_gbm_allocator_create(drm_fd);
if (gbm_alloc == NULL) {
struct wlr_allocator *alloc = wlr_gbm_allocator_create(drm_fd);
if (alloc == NULL) {
wlr_log(WLR_ERROR, "Failed to create GBM allocator");
close(drm_fd);
goto error_event;
}
x11->allocator = &gbm_alloc->base;
x11->allocator = alloc;
pixmap_formats = &x11->dri3_formats;
} else if (x11->have_shm) {
x11->drm_fd = -1;

View file

@ -16,7 +16,7 @@ struct wlr_drm_renderer {
struct gbm_device *gbm;
struct wlr_renderer *wlr_rend;
struct wlr_gbm_allocator *allocator;
struct wlr_allocator *allocator;
};
struct wlr_drm_surface {

View file

@ -28,6 +28,6 @@ struct wlr_gbm_allocator {
*
* Takes ownership over the FD.
*/
struct wlr_gbm_allocator *wlr_gbm_allocator_create(int drm_fd);
struct wlr_allocator *wlr_gbm_allocator_create(int drm_fd);
#endif

View file

@ -159,7 +159,7 @@ static struct wlr_gbm_allocator *get_gbm_alloc_from_alloc(
return (struct wlr_gbm_allocator *)alloc;
}
struct wlr_gbm_allocator *wlr_gbm_allocator_create(int fd) {
struct wlr_allocator *wlr_gbm_allocator_create(int fd) {
uint64_t cap;
if (drmGetCap(fd, DRM_CAP_PRIME, &cap) ||
!(cap & DRM_PRIME_CAP_EXPORT)) {
@ -185,8 +185,11 @@ struct wlr_gbm_allocator *wlr_gbm_allocator_create(int fd) {
wlr_log(WLR_DEBUG, "Created GBM allocator with backend %s",
gbm_device_get_backend_name(alloc->gbm_device));
char *drm_name = drmGetDeviceNameFromFd2(fd);
wlr_log(WLR_DEBUG, "Using DRM node %s", drm_name);
free(drm_name);
return alloc;
return &alloc->base;
}
static void allocator_destroy(struct wlr_allocator *wlr_alloc) {