static void xwl_drm_handle_device(void *data, struct wl_drm *drm, const char *device) { struct xwl_screen *xwl_screen = data; drm_magic_t magic; xwl_screen->device_name = strdup(device); if (!xwl_screen->device_name) return; xwl_screen->drm_fd = open(xwl_screen->device_name, O_RDWR | O_CLOEXEC); if (xwl_screen->drm_fd == -1) { ErrorF("wayland-egl: could not open %s (%s)\n", xwl_screen->device_name, strerror(errno)); return; } if (is_fd_render_node(xwl_screen->drm_fd)) { xwl_screen->fd_render_node = 1; xwl_drm_init_egl(xwl_screen); } else { drmGetMagic(xwl_screen->drm_fd, &magic); wl_drm_authenticate(xwl_screen->drm, magic); } }
static void drm_handle_device(void *data, struct wl_drm *drm, const char *device) { VADisplayContextP const pDisplayContext = data; VADriverContextP const ctx = pDisplayContext->pDriverContext; VADisplayContextWaylandDRM * const wl_drm_ctx = pDisplayContext->opaque; struct drm_state * const drm_state = ctx->drm_state; drm_magic_t magic; struct stat st; if (stat(device, &st) < 0) { va_wayland_error("failed to identify %s: %s (errno %d)", device, strerror(errno), errno); return; } if (!S_ISCHR(st.st_mode)) { va_wayland_error("%s is not a device", device); return; } drm_state->fd = open(device, O_RDWR); if (drm_state->fd < 0) { va_wayland_error("failed to open %s: %s (errno %d)", device, strerror(errno), errno); return; } drmGetMagic(drm_state->fd, &magic); wl_drm_authenticate(wl_drm_ctx->drm, magic); }
static int init_drm(struct display *d) { EGLint major, minor; int fd; drm_magic_t magic; fd = open(d->device_name, O_RDWR); if (fd < 0) { fprintf(stderr, "drm open failed: %m\n"); return -1; } if (drmGetMagic(fd, &magic)) { fprintf(stderr, "DRI2: failed to get drm magic"); return -1; } /* Wait for authenticated event */ wl_drm_authenticate(d->drm, magic); wl_display_iterate(d->display, WL_DISPLAY_WRITABLE); while (!d->authenticated) wl_display_iterate(d->display, WL_DISPLAY_READABLE); d->dpy = eglGetDRMDisplayMESA(fd); if (!eglInitialize(d->dpy, &major, &minor)) { fprintf(stderr, "failed to initialize display\n"); return -1; } if (!eglBindAPI(EGL_OPENGL_API)) { fprintf(stderr, "failed to bind api EGL_OPENGL_API\n"); return -1; } d->ctx = eglCreateContext(d->dpy, NULL, EGL_NO_CONTEXT, NULL); if (d->ctx == NULL) { fprintf(stderr, "failed to create context\n"); return -1; } if (!eglMakeCurrent(d->dpy, NULL, NULL, d->ctx)) { fprintf(stderr, "faile to make context current\n"); return -1; } #ifdef HAVE_CAIRO_EGL d->device = cairo_egl_device_create(d->dpy, d->ctx); if (d->device == NULL) { fprintf(stderr, "failed to get cairo drm device\n"); return -1; } #endif return 0; }
static int wayland_drm_display_authenticate(void *user_data, uint32_t magic) { struct native_display *ndpy = user_data; struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy); boolean current_authenticate, authenticated; current_authenticate = drmdpy->authenticated; wl_drm_authenticate(drmdpy->wl_drm, magic); wl_display_roundtrip(drmdpy->base.dpy); authenticated = drmdpy->authenticated; drmdpy->authenticated = current_authenticate; return authenticated ? 0 : -1; }
static int xwl_dri3_open_client(ClientPtr client, ScreenPtr screen, RRProviderPtr provider, int *pfd) { struct xwl_screen *xwl_screen = xwl_screen_get(screen); struct xwl_auth_state *state; struct wl_callback *callback; drm_magic_t magic; int fd; fd = open(xwl_screen->device_name, O_RDWR | O_CLOEXEC); if (fd < 0) return BadAlloc; if (xwl_screen->fd_render_node) { *pfd = fd; return Success; } state = malloc(sizeof *state); if (state == NULL) { close(fd); return BadAlloc; } state->client = client; state->fd = fd; if (drmGetMagic(state->fd, &magic) < 0) { close(state->fd); free(state); return BadMatch; } wl_drm_authenticate(xwl_screen->drm, magic); callback = wl_display_sync(xwl_screen->display); wl_callback_add_listener(callback, &sync_listener, state); IgnoreClient(client); return Success; }
static int dri2_wayland_authenticate(_EGLDisplay *disp, uint32_t id) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); int ret = 0; dri2_dpy->authenticated = 0; wl_drm_authenticate(dri2_dpy->wl_drm, id); wl_display_roundtrip(dri2_dpy->wl_dpy); if (!dri2_dpy->authenticated) ret = -1; /* reset authenticated */ dri2_dpy->authenticated = 1; return ret; }
static void drm_handle_device(void *data, struct wl_drm *drm, const char *device) { struct wayland_drm_display *drmdpy = data; drm_magic_t magic; drmdpy->device_name = strdup(device); if (!drmdpy->device_name) return; drmdpy->fd = open(drmdpy->device_name, O_RDWR); if (drmdpy->fd == -1) { _eglLog(_EGL_WARNING, "wayland-egl: could not open %s (%s)", drmdpy->device_name, strerror(errno)); return; } drmGetMagic(drmdpy->fd, &magic); wl_drm_authenticate(drmdpy->wl_drm, magic); }
static void drm_handle_device(void *data, struct wl_drm *drm, const char *device) { wl_drm_authenticate(drm, 0); }
static gboolean try_enable_drm (ClutterBackendWayland *backend_wayland, GError **error) { drm_magic_t magic; const gchar *exts, *glexts; if (backend_wayland->drm_fd < 0) { g_set_error (error, CLUTTER_INIT_ERROR, CLUTTER_INIT_ERROR_BACKEND, "Failed to open drm device"); return FALSE; } glexts = glGetString(GL_EXTENSIONS); exts = eglQueryString (backend_wayland->edpy, EGL_EXTENSIONS); if (!_cogl_check_extension ("EGL_KHR_image_base", exts) || !_cogl_check_extension ("EGL_MESA_drm_image", exts) || !_cogl_check_extension ("GL_OES_EGL_image", glexts)) { g_set_error (error, CLUTTER_INIT_ERROR, CLUTTER_INIT_ERROR_BACKEND, "Missing EGL extensions"); return FALSE; } backend_wayland->create_drm_image = (PFNEGLCREATEDRMIMAGEMESA) eglGetProcAddress ("eglCreateDRMImageMESA"); backend_wayland->destroy_image = (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress ("eglDestroyImageKHR"); backend_wayland->export_drm_image = (PFNEGLEXPORTDRMIMAGEMESA) eglGetProcAddress ("eglExportDRMImageMESA"); backend_wayland->image_target_texture_2d = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) eglGetProcAddress ("glEGLImageTargetTexture2DOES"); if (backend_wayland->create_drm_image == NULL || backend_wayland->destroy_image == NULL || backend_wayland->export_drm_image == NULL || backend_wayland->image_target_texture_2d == NULL) { g_set_error (error, CLUTTER_INIT_ERROR, CLUTTER_INIT_ERROR_BACKEND, "Missing EGL extensions"); return FALSE; } if (drmGetMagic (backend_wayland->drm_fd, &magic)) { g_set_error (error, CLUTTER_INIT_ERROR, CLUTTER_INIT_ERROR_BACKEND, "Failed to get drm magic"); return FALSE; } wl_drm_authenticate (backend_wayland->wayland_drm, magic); wl_display_iterate (backend_wayland->wayland_display, WL_DISPLAY_WRITABLE); while (!backend_wayland->authenticated) wl_display_iterate (backend_wayland->wayland_display, WL_DISPLAY_READABLE); return TRUE; };