/* 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)
    {
        wsegl_info("wayland-wsegl: Initializing framebuffer");
       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; 
       }
       egldisplay->fd = fd;
       format = getwseglPixelFormat(egldisplay);

       egldisplay->wseglDisplayConfigs[0].ePixelFormat = format;
       egldisplay->wseglDisplayConfigs[1].ePixelFormat = format;
    }
    else
    {
        egldisplay->queue = wl_display_create_queue(nativeDisplay);
        egldisplay->frame_callback = NULL;
        egldisplay->registry = wl_display_get_registry(nativeDisplay);
        wl_proxy_set_queue(egldisplay->registry, egldisplay->queue);
        wl_registry_add_listener(egldisplay->registry, &registry_listener, egldisplay);

        assert(wayland_roundtrip(egldisplay) >= 0);
        assert(egldisplay->sgx_wlegl);
    }

    *display = (WSEGLDisplayHandle)egldisplay;
    *caps = wseglDisplayCaps;
    *configs = egldisplay->wseglDisplayConfigs;
    return WSEGL_SUCCESS;
}
Esempio n. 2
0
/* 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;
}