mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-04 20: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',
|
||||
version: '>=2.4.113',
|
||||
version: '>=2.4.114',
|
||||
fallback: 'libdrm',
|
||||
default_options: [
|
||||
'intel=disabled',
|
||||
|
|
|
@ -55,41 +55,30 @@ static struct wlr_drm_dumb_buffer *create_buffer(
|
|||
|
||||
buffer->drm_fd = alloc->drm_fd;
|
||||
|
||||
struct drm_mode_create_dumb create = {0};
|
||||
create.width = (uint32_t)width;
|
||||
create.height = (uint32_t)height;
|
||||
create.bpp = info->bpp;
|
||||
|
||||
if (drmIoctl(alloc->drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create) != 0) {
|
||||
if (drmModeCreateDumbBuffer(alloc->drm_fd, width, height, info->bpp, 0,
|
||||
&buffer->handle, &buffer->stride, &buffer->size) != 0) {
|
||||
wlr_log_errno(WLR_ERROR, "Failed to create DRM dumb buffer");
|
||||
goto create_destroy;
|
||||
}
|
||||
|
||||
buffer->width = create.width;
|
||||
buffer->height = create.height;
|
||||
|
||||
buffer->stride = create.pitch;
|
||||
buffer->handle = create.handle;
|
||||
buffer->width = width;
|
||||
buffer->height = height;
|
||||
buffer->format = format->format;
|
||||
|
||||
struct drm_mode_map_dumb map = {0};
|
||||
map.handle = buffer->handle;
|
||||
|
||||
if (drmIoctl(alloc->drm_fd, DRM_IOCTL_MODE_MAP_DUMB, &map) != 0) {
|
||||
uint64_t offset;
|
||||
if (drmModeMapDumbBuffer(alloc->drm_fd, buffer->handle, &offset) != 0) {
|
||||
wlr_log_errno(WLR_ERROR, "Failed to map DRM dumb buffer");
|
||||
goto create_destroy;
|
||||
}
|
||||
|
||||
buffer->data = mmap(NULL, create.size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||
alloc->drm_fd, map.offset);
|
||||
buffer->data = mmap(NULL, buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||
alloc->drm_fd, offset);
|
||||
if (buffer->data == MAP_FAILED) {
|
||||
wlr_log_errno(WLR_ERROR, "Failed to mmap DRM dumb buffer");
|
||||
goto create_destroy;
|
||||
}
|
||||
|
||||
buffer->size = create.size;
|
||||
|
||||
memset(buffer->data, 0, create.size);
|
||||
memset(buffer->data, 0, buffer->size);
|
||||
|
||||
int prime_fd;
|
||||
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);
|
||||
|
||||
if (buf->drm_fd >= 0) {
|
||||
struct drm_mode_destroy_dumb destroy = { .handle = buf->handle };
|
||||
if (drmIoctl(buf->drm_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy)) {
|
||||
if (drmModeDestroyDumbBuffer(buf->drm_fd, buf->handle) != 0) {
|
||||
wlr_log_errno(WLR_ERROR, "Failed to destroy DRM dumb buffer");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue