1 #include <fcntl.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <xf86drm.h>
5 #include <sys/mman.h>
6
7 #include <xf86drm.h>
8 #include <xf86drmMode.h>
9
10 #define CURSOR_WIDTH 64
11 #define CURSOR_HEIGHT 64
12
main(int argc,const char ** argv)13 int main(int argc, const char **argv)
14 {
15 int fd = open("/dev/dri/card0", O_RDWR | O_CLOEXEC);
16 int width = CURSOR_WIDTH;
17 int height = CURSOR_HEIGHT;
18 int crtc_id = 0;
19
20 struct drm_mode_create_dumb create_arg = {
21 .width = width,
22 .height = height,
23 .bpp = 32,
24 };
25
26 drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_arg);
27 int handle = create_arg.handle;
28 int size = create_arg.size;
29
30 struct drm_mode_map_dumb map_arg = {
31 .handle = handle,
32 };
33
34 drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);
35
36 int *ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED,
37 fd, map_arg.offset);
38 for (int i = 0; i < width * height; i++)
39 ptr[i] = 0x4F000000 | (i % width) * 2 << 16 | (i / height) << 8;
40
41 if (argc > 1)
42 crtc_id = atoi(argv[1]);
43
44 if (argc > 2)
45 setenv("DRM_CURSOR_PREFER_PLANE", argv[2], 1);
46
47 drmModeSetCursor(fd, crtc_id, handle, width, height);
48
49 for (int i = 0; i < 100000; i++) {
50 drmModeMoveCursor(fd, crtc_id, i % 1024, i % 1024);
51 usleep(100000);
52 }
53
54 return 0;
55 }
56