#include #include #include #include #include #include #include #include "drm.h" #include "egl.h" /** * When Linux detects a GPU it loads modprobes the device driver * to provide two character-devices to control it. Udev (or whatever * hotplugging framework) will create them as: * /dev/dri/card0 * /dev/dri/controlID64 * We only need the first one. We simply hardcode its path though * libudev would be the way to do real hotplugging. * * This helper opens the DRM device which is given as 'node'. The * new fd is stored in 'out' on success. On failure a negative err * code is returned. * * After openning the file, we check for the DRM_CAP_DUMB_BUFFER * capability. If the driver supports this capability, we can * create simple memory-mapped buffers without any driver-dependent * code, as want to avoid any vendor specifics. */ struct egl egl; static const struct gbm *gbm; static const struct drm *drm; extern void run_gl_example();// XX move to header. int main() { const char * card = "/dev/dri/card0"; drm = init_drm_runner(card); if (!drm) { fprintf(stderr, "failed to initialize DRM\n"); exit(1); } gbm = init_gbm(drm->fd, drm->mode->hdisplay, drm->mode->vdisplay); if (!gbm) { printf("failed to initialize GBM\n"); exit(1); } init_egl(&egl, gbm); /* ...... */ /* draw here?? */ setup_egl_draw_loop(&egl, run_gl_example); drm->run(gbm, &egl); // main render loop /* ...... */ /* cleanups */ deinit_egl(&egl); deinit_gbm(gbm); deinit_drm(drm); return 0; }