一段时间以来,我一直在使用Linux的Direct Rendering Manager,它允许人们执行一些非常底层的图形管理。通常这是在C中借助libdrm或直接使用DRM标头完成的。
我正在尝试在Rust中创建一个与libdrm等效的文件,这不仅是对C库的绑定,而是直接使用syscalls。鉴于几乎没有关于DRM的文档,这并不是一件容易的事,但是我正在C中跟踪此示例以获取有关从何处开始的提示。
现在,我应该创建一个哑缓冲并将其映射到内存中,以便可以修改屏幕上出现的每个像素的像素。为此,我必须使用mmap,但是会收到一个非常奇怪的错误。
这是C语言中最少的工作代码:
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <drm/drm.h>
#include <drm/drm_mode.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
int main() {
// STEP 1: GET ACCESS TO DRM
int fd = open("/dev/dri/card0", O_RDWR | O_CLOEXEC);
if (fd < 0) {
printf("Error in function open(): %s\n", strerror(errno));
return 1;
}
// STEP 2: CREATE DUMBBUFFER
struct drm_mode_create_dumb dreq;
dreq.height = 1080,
dreq.width = …Run Code Online (Sandbox Code Playgroud)