Esempio n. 1
0
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;
}
Esempio n. 2
0
static cairo_surface_t *
_cairo_boilerplate_egl_create_surface (const char		 *name,
				       cairo_content_t		  content,
				       double			  width,
				       double			  height,
				       double			  max_width,
				       double			  max_height,
				       cairo_boilerplate_mode_t   mode,
				       int			  id,
				       void			**closure)
{
    egl_target_closure_t *gltc;
    cairo_surface_t *surface;
    int major, minor;
    EGLConfig *configs;
    EGLint numConfigs;

    gltc = xcalloc (1, sizeof (egl_target_closure_t));
    *closure = gltc;

    gltc->dpy = eglGetDisplay (EGL_DEFAULT_DISPLAY);

    if (! eglInitialize (gltc->dpy, &major, &minor)) {
	free (gltc);
	return NULL;
    }

    eglGetConfigs (gltc->dpy, NULL, 0, &numConfigs);
    if (numConfigs == 0) {
	free (gltc);
	return NULL;
    }
    configs = xmalloc(sizeof(*configs) *numConfigs);
    eglGetConfigs (gltc->dpy, configs, numConfigs, &numConfigs);

    eglBindAPI (EGL_OPENGL_API);

    gltc->ctx = eglCreateContext (gltc->dpy, configs[0], EGL_NO_CONTEXT, NULL);
    if (gltc->ctx == EGL_NO_CONTEXT) {
	eglTerminate (gltc->dpy);
	free (gltc);
	return NULL;
    }

    gltc->device = cairo_egl_device_create (gltc->dpy, gltc->ctx);

    gltc->surface = surface = cairo_gl_surface_create (gltc->device,
						       content,
						       ceil (width),
						       ceil (height));
    if (cairo_surface_status (surface))
	_cairo_boilerplate_egl_cleanup (gltc);

    return surface;
}
Esempio n. 3
0
static gboolean
gdk_display_init_egl(GdkDisplay *display)
{
  GdkDisplayWayland *display_wayland = GDK_DISPLAY_WAYLAND (display);
  EGLint major, minor, i;
  void *p;

  static const struct { const char *f; unsigned int offset; }
  extension_functions[] = {
    { "glEGLImageTargetTexture2DOES", offsetof(GdkDisplayWayland, image_target_texture_2d) },
    { "eglCreateImageKHR", offsetof(GdkDisplayWayland, create_image) },
    { "eglDestroyImageKHR", offsetof(GdkDisplayWayland, destroy_image) }
  };

  display_wayland->egl_display =
    eglGetDisplay(display_wayland->wl_display);
  if (!eglInitialize(display_wayland->egl_display, &major, &minor)) {
    fprintf(stderr, "failed to initialize display\n");
    return FALSE;
  }

  eglBindAPI(EGL_OPENGL_API);

  display_wayland->egl_context =
    eglCreateContext(display_wayland->egl_display, NULL, EGL_NO_CONTEXT, NULL);
  if (display_wayland->egl_context == NULL) {
    fprintf(stderr, "failed to create context\n");
    return FALSE;
  }

  if (!eglMakeCurrent(display_wayland->egl_display,
		      NULL, NULL, display_wayland->egl_context)) {
    fprintf(stderr, "faile to make context current\n");
    return FALSE;
  }

  display_wayland->cairo_device =
    cairo_egl_device_create(display_wayland->egl_display,
			    display_wayland->egl_context);
  if (cairo_device_status (display_wayland->cairo_device) != CAIRO_STATUS_SUCCESS) {
    fprintf(stderr, "failed to get cairo drm device\n");
    return FALSE;
  }

  for (i = 0; i < G_N_ELEMENTS(extension_functions); i++) {
    p = eglGetProcAddress(extension_functions[i].f);
    *(void **) ((char *) display_wayland + extension_functions[i].offset) = p;
    if (p == NULL) {
      fprintf(stderr, "failed to look up %s\n", extension_functions[i].f);
      return FALSE;
    }
  }

  return TRUE;
}
Esempio n. 4
0
cairo_device_t* GLContextEGL::cairoDevice()
{
    if (m_cairoDevice)
        return m_cairoDevice;

#if ENABLE(ACCELERATED_2D_CANVAS)
    m_cairoDevice = cairo_egl_device_create(m_display.eglDisplay(), m_context);
#endif

    return m_cairoDevice;
}
Esempio n. 5
0
cairo_device_t* GLContextEGL::cairoDevice()
	{
#if PLATFORM(JS)
		webkitTrace();
#endif
    if (m_cairoDevice)
        return m_cairoDevice;

#if ENABLE(ACCELERATED_2D_CANVAS)
    m_cairoDevice = cairo_egl_device_create(sharedEGLDisplay(), m_context);
#endif

    return m_cairoDevice;
}
Esempio n. 6
0
static MechEGLConfigPrivate *
_create_egl_config (gint renderable_type)
{
  EGLint major, minor, n_configs;
  MechBackendWayland *backend;
  MechEGLConfigPrivate *priv;
  const gchar *extensions;
  MechEGLConfig *config;
  GError *error;
  EGLenum api;
  const EGLint argb_config_attributes[] = {
    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
    EGL_RED_SIZE, 8,
    EGL_GREEN_SIZE, 8,
    EGL_BLUE_SIZE, 8,
    EGL_ALPHA_SIZE, 8,
    EGL_DEPTH_SIZE, 24,
    EGL_RENDERABLE_TYPE, renderable_type,
    EGL_NONE
  };

  priv = g_new0 (MechEGLConfigPrivate, 1);
  config = (MechEGLConfig *) priv;

  if (renderable_type != EGL_OPENGL_BIT &&
      renderable_type != EGL_OPENGL_ES_BIT &&
      renderable_type != EGL_OPENGL_ES2_BIT)
    {
      error = g_error_new (mech_surface_egl_error_quark (), 0,
                           "Not a valid renderable type");
      goto init_failed;
    }

  backend = _mech_backend_wayland_get ();
  config->egl_display = eglGetDisplay (backend->wl_display);

  if (eglInitialize (config->egl_display, &major, &minor) == EGL_FALSE)
    {
      error = g_error_new (mech_surface_egl_error_quark (), 0,
                           "Could not initialize EGL");
      goto init_failed;
    }

  api = (renderable_type == EGL_OPENGL_BIT) ?
    EGL_OPENGL_API : EGL_OPENGL_ES_API;

  if (eglBindAPI (api) == EGL_FALSE)
    {
      error = g_error_new (mech_surface_egl_error_quark (), 0,
                           "Could not bind a rendering API");
      goto init_failed;
    }

  if (eglChooseConfig (config->egl_display, argb_config_attributes,
                       &config->egl_argb_config, 1, &n_configs) == EGL_FALSE)
    {
      error = g_error_new (mech_surface_egl_error_quark (), 0,
                           "Could not find a matching configuration");
      goto init_failed;
    }

  config->egl_argb_context = eglCreateContext (config->egl_display,
                                               config->egl_argb_config,
                                               EGL_NO_CONTEXT, NULL);

  if (config->egl_argb_context == EGL_NO_CONTEXT)
    {
      error = g_error_new (mech_surface_egl_error_quark (), 0,
                           "Could not create an EGL context");
      goto init_failed;
    }

  if (eglMakeCurrent (config->egl_display, EGL_NO_SURFACE,
                      EGL_NO_SURFACE, config->egl_argb_context) == EGL_FALSE)
    {
      error = g_error_new (mech_surface_egl_error_quark (), 0,
                           "Could not make EGL context current");
      goto init_failed;
    }

  config->argb_device = cairo_egl_device_create (config->egl_display,
                                                 config->egl_argb_context);

  if (cairo_device_status (config->argb_device) != CAIRO_STATUS_SUCCESS)
    {
      error = g_error_new (mech_surface_egl_error_quark (), 0,
                           "Could not create a cairo EGL device");
      goto init_failed;
    }

  extensions = eglQueryString (config->egl_display, EGL_EXTENSIONS);

  if (strstr (extensions, "EGL_EXT_buffer_age"))
    config->has_buffer_age_ext = TRUE;

  if (strstr (extensions, "EGL_EXT_swap_buffers_with_damage"))
    config->has_swap_buffers_with_damage_ext = TRUE;

  return priv;

 init_failed:
  if (config->egl_argb_context != EGL_NO_CONTEXT)
    {
      eglDestroyContext (config->egl_display, config->egl_argb_context);
      config->egl_argb_context = EGL_NO_CONTEXT;
    }

  if (config->argb_device)
    {
      cairo_device_destroy (config->argb_device);
      config->argb_device = NULL;
    }

  priv->error = error;

  return priv;
}