#include #include #include #include #include #include #include #define RENDERNODE "/dev/dri/renderD128" int main(int argc, char **argv) { int drm_fd = open(RENDERNODE, O_RDWR | O_CLOEXEC); if (drm_fd == -1) { fprintf(stderr, "Failed to open render node %s\n", RENDERNODE); return EXIT_FAILURE; } struct gbm_device *dev = gbm_create_device(drm_fd); if (!dev) { fprintf(stderr, "Failed to create gbm device\n"); return EXIT_FAILURE; } uint32_t width = 256; uint32_t height = 512; uint32_t cpp = 4; uint32_t format = GBM_FORMAT_XRGB8888; struct gbm_bo *bo = gbm_bo_create(dev, width, height, format, 0); if (!bo) { fprintf(stderr, "Failed to create buffer object: %s\n", strerror(errno)); return EXIT_FAILURE; } for (int i = 0; i < 8; i++) { uint32_t stride; void *handle = i != 4 ? NULL : 0x44; void *dst = gbm_bo_map(bo, 0, 0, width, height, GBM_BO_TRANSFER_WRITE, &stride, &handle); if (!dst) { fprintf(stderr, "Failed to map gbm buffer the %dth time, error=%d: %s\n", i, errno, strerror(errno)); return EXIT_FAILURE; } memset(dst, i, width * height * cpp); gbm_bo_unmap(bo, handle); } gbm_device_destroy(dev); close(drm_fd); fprintf(stderr, "Successful\n"); return EXIT_SUCCESS; }