mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-24 21:55:58 +01:00
allocator/drm_dumb: use libdrm dumb buffer helpers
References: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/272
This commit is contained in:
parent
8b12037cad
commit
fdb24d19ca
2 changed files with 11 additions and 23 deletions
|
@ -107,7 +107,7 @@ wayland_server = dependency('wayland-server',
|
||||||
)
|
)
|
||||||
|
|
||||||
drm = dependency('libdrm',
|
drm = dependency('libdrm',
|
||||||
version: '>=2.4.113',
|
version: '>=2.4.114',
|
||||||
fallback: 'libdrm',
|
fallback: 'libdrm',
|
||||||
default_options: [
|
default_options: [
|
||||||
'intel=disabled',
|
'intel=disabled',
|
||||||
|
|
|
@ -55,41 +55,30 @@ static struct wlr_drm_dumb_buffer *create_buffer(
|
||||||
|
|
||||||
buffer->drm_fd = alloc->drm_fd;
|
buffer->drm_fd = alloc->drm_fd;
|
||||||
|
|
||||||
struct drm_mode_create_dumb create = {0};
|
if (drmModeCreateDumbBuffer(alloc->drm_fd, width, height, info->bpp, 0,
|
||||||
create.width = (uint32_t)width;
|
&buffer->handle, &buffer->stride, &buffer->size) != 0) {
|
||||||
create.height = (uint32_t)height;
|
|
||||||
create.bpp = info->bpp;
|
|
||||||
|
|
||||||
if (drmIoctl(alloc->drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create) != 0) {
|
|
||||||
wlr_log_errno(WLR_ERROR, "Failed to create DRM dumb buffer");
|
wlr_log_errno(WLR_ERROR, "Failed to create DRM dumb buffer");
|
||||||
goto create_destroy;
|
goto create_destroy;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->width = create.width;
|
buffer->width = width;
|
||||||
buffer->height = create.height;
|
buffer->height = height;
|
||||||
|
|
||||||
buffer->stride = create.pitch;
|
|
||||||
buffer->handle = create.handle;
|
|
||||||
buffer->format = format->format;
|
buffer->format = format->format;
|
||||||
|
|
||||||
struct drm_mode_map_dumb map = {0};
|
uint64_t offset;
|
||||||
map.handle = buffer->handle;
|
if (drmModeMapDumbBuffer(alloc->drm_fd, buffer->handle, &offset) != 0) {
|
||||||
|
|
||||||
if (drmIoctl(alloc->drm_fd, DRM_IOCTL_MODE_MAP_DUMB, &map) != 0) {
|
|
||||||
wlr_log_errno(WLR_ERROR, "Failed to map DRM dumb buffer");
|
wlr_log_errno(WLR_ERROR, "Failed to map DRM dumb buffer");
|
||||||
goto create_destroy;
|
goto create_destroy;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->data = mmap(NULL, create.size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
buffer->data = mmap(NULL, buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||||
alloc->drm_fd, map.offset);
|
alloc->drm_fd, offset);
|
||||||
if (buffer->data == MAP_FAILED) {
|
if (buffer->data == MAP_FAILED) {
|
||||||
wlr_log_errno(WLR_ERROR, "Failed to mmap DRM dumb buffer");
|
wlr_log_errno(WLR_ERROR, "Failed to mmap DRM dumb buffer");
|
||||||
goto create_destroy;
|
goto create_destroy;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->size = create.size;
|
memset(buffer->data, 0, buffer->size);
|
||||||
|
|
||||||
memset(buffer->data, 0, create.size);
|
|
||||||
|
|
||||||
int prime_fd;
|
int prime_fd;
|
||||||
if (drmPrimeHandleToFD(alloc->drm_fd, buffer->handle, DRM_CLOEXEC,
|
if (drmPrimeHandleToFD(alloc->drm_fd, buffer->handle, DRM_CLOEXEC,
|
||||||
|
@ -149,8 +138,7 @@ static void buffer_destroy(struct wlr_buffer *wlr_buffer) {
|
||||||
wlr_dmabuf_attributes_finish(&buf->dmabuf);
|
wlr_dmabuf_attributes_finish(&buf->dmabuf);
|
||||||
|
|
||||||
if (buf->drm_fd >= 0) {
|
if (buf->drm_fd >= 0) {
|
||||||
struct drm_mode_destroy_dumb destroy = { .handle = buf->handle };
|
if (drmModeDestroyDumbBuffer(buf->drm_fd, buf->handle) != 0) {
|
||||||
if (drmIoctl(buf->drm_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy)) {
|
|
||||||
wlr_log_errno(WLR_ERROR, "Failed to destroy DRM dumb buffer");
|
wlr_log_errno(WLR_ERROR, "Failed to destroy DRM dumb buffer");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue