static boolean wayland_drm_display_init_screen(struct native_display *ndpy) { struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy); uint32_t id; id = wl_display_get_global(drmdpy->base.dpy, "wl_drm", 1); if (id == 0) wl_display_roundtrip(drmdpy->base.dpy); id = wl_display_get_global(drmdpy->base.dpy, "wl_drm", 1); if (id == 0) return FALSE; drmdpy->wl_drm = wl_display_bind(drmdpy->base.dpy, id, &wl_drm_interface); if (!drmdpy->wl_drm) return FALSE; wl_drm_add_listener(drmdpy->wl_drm, &drm_listener, drmdpy); wl_display_roundtrip(drmdpy->base.dpy); if (drmdpy->fd == -1) return FALSE; wl_display_roundtrip(drmdpy->base.dpy); if (!drmdpy->authenticated) return FALSE; if (drmdpy->base.formats == 0) wl_display_roundtrip(drmdpy->base.dpy); if (drmdpy->base.formats == 0) return FALSE; drmdpy->base.base.screen = drmdpy->event_handler->new_drm_screen(&drmdpy->base.base, NULL, drmdpy->fd); if (!drmdpy->base.base.screen) { _eglLog(_EGL_WARNING, "failed to create DRM screen"); return FALSE; } return TRUE; }
/* Initialize a native display for use with WSEGL */ static WSEGLError wseglInitializeDisplay (NativeDisplayType nativeDisplay, WSEGLDisplayHandle *display, const WSEGLCaps **caps, WSEGLConfig **configs) { struct wl_egl_display *egldisplay = wl_egl_display_create((struct wl_display *) nativeDisplay); if (wseglFetchContext(egldisplay) != 1) { wl_egl_display_destroy(egldisplay); return WSEGL_OUT_OF_MEMORY; } /* If it is a framebuffer */ if (egldisplay->display == NULL) { int fd; WSEGLPixelFormat format; /* Open the framebuffer and fetch its properties */ fd = open("/dev/fb0", O_RDWR, 0); if (fd < 0) { perror("/dev/fb0"); wseglReleaseContext(egldisplay); wl_egl_display_destroy(egldisplay); return WSEGL_CANNOT_INITIALISE; } if (ioctl(fd, FBIOGET_VSCREENINFO, &egldisplay->var) < 0) { perror("FBIOGET_VSCREENINFO"); wseglReleaseContext(egldisplay); wl_egl_display_destroy(egldisplay); close(fd); return WSEGL_CANNOT_INITIALISE; } if (ioctl(fd, FBIOGET_FSCREENINFO, &egldisplay->fix) < 0) { perror("FBIOGET_FSCREENINFO"); wseglReleaseContext(egldisplay); wl_egl_display_destroy(egldisplay); close(fd); return WSEGL_CANNOT_INITIALISE; } format = getwseglPixelFormat(egldisplay); egldisplay->wseglDisplayConfigs[0].ePixelFormat = format; egldisplay->wseglDisplayConfigs[1].ePixelFormat = format; } else { uint32_t id; id = wl_display_get_global(egldisplay->display, "wl_drm", 1); if (id == 0) wl_display_roundtrip(egldisplay->display); id = wl_display_get_global(egldisplay->display, "wl_drm", 1); if (id == 0) return WSEGL_CANNOT_INITIALISE; egldisplay->drm = wl_display_bind(egldisplay->display, id, &wl_drm_interface); if (!egldisplay->drm) return WSEGL_CANNOT_INITIALISE; wl_drm_add_listener(egldisplay->drm, &drm_listener, egldisplay); wl_display_roundtrip(egldisplay->display); } *display = (WSEGLDisplayHandle)egldisplay; *caps = wseglDisplayCaps; *configs = egldisplay->wseglDisplayConfigs; return WSEGL_SUCCESS; }
EGLBoolean dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp) { struct dri2_egl_display *dri2_dpy; const __DRIconfig *config; uint32_t id, types; int i; static const unsigned int argb_masks[4] = { 0xff0000, 0xff00, 0xff, 0xff000000 }; static const unsigned int rgb_masks[4] = { 0xff0000, 0xff00, 0xff, 0 }; drv->API.CreateWindowSurface = dri2_create_window_surface; drv->API.CreatePixmapSurface = dri2_create_pixmap_surface; drv->API.DestroySurface = dri2_destroy_surface; drv->API.SwapBuffers = dri2_swap_buffers; drv->API.CreateImageKHR = dri2_wayland_create_image_khr; drv->API.Terminate = dri2_terminate; dri2_dpy = malloc(sizeof *dri2_dpy); if (!dri2_dpy) return _eglError(EGL_BAD_ALLOC, "eglInitialize"); memset(dri2_dpy, 0, sizeof *dri2_dpy); disp->DriverData = (void *) dri2_dpy; if (disp->PlatformDisplay == NULL) { dri2_dpy->wl_dpy = wl_display_connect(NULL); if (dri2_dpy->wl_dpy == NULL) goto cleanup_dpy; dri2_dpy->own_device = 1; } else { dri2_dpy->wl_dpy = disp->PlatformDisplay; } id = wl_display_get_global(dri2_dpy->wl_dpy, "wl_drm", 1); if (id == 0) wl_display_roundtrip(dri2_dpy->wl_dpy); id = wl_display_get_global(dri2_dpy->wl_dpy, "wl_drm", 1); if (id == 0) goto cleanup_dpy; dri2_dpy->wl_drm = wl_display_bind(dri2_dpy->wl_dpy, id, &wl_drm_interface); if (!dri2_dpy->wl_drm) goto cleanup_dpy; wl_drm_add_listener(dri2_dpy->wl_drm, &drm_listener, dri2_dpy); wl_display_roundtrip(dri2_dpy->wl_dpy); if (dri2_dpy->fd == -1) goto cleanup_drm; wl_display_roundtrip(dri2_dpy->wl_dpy); if (!dri2_dpy->authenticated) goto cleanup_fd; dri2_dpy->driver_name = dri2_get_driver_for_fd(dri2_dpy->fd); if (dri2_dpy->driver_name == NULL) { _eglError(EGL_BAD_ALLOC, "DRI2: failed to get driver name"); goto cleanup_fd; } if (!dri2_load_driver(disp)) goto cleanup_driver_name; dri2_dpy->dri2_loader_extension.base.name = __DRI_DRI2_LOADER; dri2_dpy->dri2_loader_extension.base.version = 3; dri2_dpy->dri2_loader_extension.getBuffers = dri2_get_buffers; dri2_dpy->dri2_loader_extension.flushFrontBuffer = dri2_flush_front_buffer; dri2_dpy->dri2_loader_extension.getBuffersWithFormat = dri2_get_buffers_with_format; dri2_dpy->extensions[0] = &dri2_dpy->dri2_loader_extension.base; dri2_dpy->extensions[1] = &image_lookup_extension.base; dri2_dpy->extensions[2] = &use_invalidate.base; dri2_dpy->extensions[3] = NULL; if (!dri2_create_screen(disp)) goto cleanup_driver; types = EGL_WINDOW_BIT | EGL_PIXMAP_BIT; if (dri2_dpy->formats & HAS_PREMUL_ARGB32) types |= EGL_VG_ALPHA_FORMAT_PRE_BIT; for (i = 0; dri2_dpy->driver_configs[i]; i++) { config = dri2_dpy->driver_configs[i]; if (dri2_dpy->formats & HAS_XRGB32) dri2_add_config(disp, config, i + 1, 0, types, NULL, rgb_masks); if (dri2_dpy->formats & (HAS_ARGB32 | HAS_PREMUL_ARGB32)) dri2_add_config(disp, config, i + 1, 0, types, NULL, argb_masks); } disp->Extensions.KHR_image_pixmap = EGL_TRUE; disp->Extensions.WL_bind_wayland_display = EGL_TRUE; dri2_dpy->authenticate = dri2_wayland_authenticate; /* we're supporting EGL 1.4 */ disp->VersionMajor = 1; disp->VersionMinor = 4; return EGL_TRUE; cleanup_driver: dlclose(dri2_dpy->driver); cleanup_driver_name: free(dri2_dpy->driver_name); cleanup_fd: close(dri2_dpy->fd); cleanup_drm: free(dri2_dpy->device_name); wl_drm_destroy(dri2_dpy->wl_drm); cleanup_dpy: free(dri2_dpy); return EGL_FALSE; }