Beispiel #1
0
flux_t flux_open (const char *uri, int flags)
{
    char *path = NULL;
    char *scheme = NULL;
    void *dso = NULL;
    connector_init_f *connector_init = NULL;
    flux_t h = NULL;

    if (!uri)
        uri = getenv ("FLUX_URI");
    if (!uri) {
        errno = EINVAL;
        goto done;
    }
    if (uri) {
        if (!(scheme = strdup (uri))) {
            errno = ENOMEM;
            goto done;
        }
        path = strstr (scheme, "://");
        if (path) {
            *path = '\0';
            path = strtrim (path + 3, " \t");
        }
    }
    if (!(connector_init = find_connector (scheme, &dso)))
        goto done;
    if (getenv ("FLUX_HANDLE_TRACE"))
        flags |= FLUX_O_TRACE;
    if (!(h = connector_init (path, flags))) {
        dlclose (dso);
        goto done;
    }
    h->dso = dso;
#if HAVE_CALIPER
    profiling_context_init(&h->prof);
#endif
done:
    if (scheme)
        free (scheme);
    return h;
}
static CoglOutputKMS *
find_output (int _index,
             int fd,
             drmModeRes *resources,
             int *excluded_connectors,
             int n_excluded_connectors,
             CoglError **error)
{
  char *connector_env_name = g_strdup_printf ("COGL_KMS_CONNECTOR%d", _index);
  char *mode_env_name;
  drmModeConnector *connector;
  drmModeEncoder *encoder;
  CoglOutputKMS *output;
  drmModeModeInfo *modes;
  int n_modes;

  if (getenv (connector_env_name))
    {
      unsigned long id = strtoul (getenv (connector_env_name), NULL, 10);
      connector = drmModeGetConnector (fd, id);
    }
  else
    connector = NULL;
  g_free (connector_env_name);

  if (connector == NULL)
    connector = find_connector (fd, resources,
                                excluded_connectors, n_excluded_connectors);
  if (connector == NULL)
    {
      _cogl_set_error (error, COGL_WINSYS_ERROR,
                   COGL_WINSYS_ERROR_INIT,
                   "No currently active connector found");
      return NULL;
    }

  /* XXX: At this point it seems connector->encoder_id may be an invalid id of 0
   * even though the connector is marked as connected. Referencing ->encoders[0]
   * seems more reliable. */
  encoder = drmModeGetEncoder (fd, connector->encoders[0]);

  output = g_slice_new0 (CoglOutputKMS);
  output->connector = connector;
  output->encoder = encoder;
  output->saved_crtc = drmModeGetCrtc (fd, encoder->crtc_id);

  if (is_panel (connector->connector_type))
    {
      n_modes = connector->count_modes + 1;
      modes = g_new (drmModeModeInfo, n_modes);
      memcpy (modes, connector->modes,
              sizeof (drmModeModeInfo) * connector->count_modes);
      /* TODO: parse EDID */
      modes[n_modes - 1] = builtin_1024x768;
    }
  else
    {
      n_modes = connector->count_modes;
      modes = g_new (drmModeModeInfo, n_modes);
      memcpy (modes, connector->modes,
              sizeof (drmModeModeInfo) * n_modes);
    }

  mode_env_name = g_strdup_printf ("COGL_KMS_CONNECTOR%d_MODE", _index);
  if (getenv (mode_env_name))
    {
      const char *name = getenv (mode_env_name);
      int i;
      CoglBool found = FALSE;
      drmModeModeInfo mode;

      for (i = 0; i < n_modes; i++)
        {
          if (strcmp (modes[i].name, name) == 0)
            {
              found = TRUE;
              break;
            }
        }
      if (!found)
        {
          g_free (mode_env_name);
          _cogl_set_error (error, COGL_WINSYS_ERROR,
                       COGL_WINSYS_ERROR_INIT,
                       "COGL_KMS_CONNECTOR%d_MODE of %s could not be found",
                       _index, name);
          return NULL;
        }
      n_modes = 1;
      mode = modes[i];
      g_free (modes);
      modes = g_new (drmModeModeInfo, 1);
      modes[0] = mode;
    }
  g_free (mode_env_name);

  output->modes = modes;
  output->n_modes = n_modes;

  return output;
}
Beispiel #3
0
flux_t *flux_open (const char *uri, int flags)
{
    char *default_uri = NULL;
    char *path = NULL;
    char *scheme = NULL;
    void *dso = NULL;
    connector_init_f *connector_init = NULL;
    const char *s;
    flux_t *h = NULL;

    if (!uri)
        uri = getenv ("FLUX_URI");
    if (!uri) {
        if (asprintf (&default_uri, "local://%s",
                      flux_conf_get ("rundir", 0)) < 0)
            goto done;
        uri = default_uri;
    }
    if (!(scheme = strdup (uri))) {
        errno = ENOMEM;
        goto done;
    }
    path = strstr (scheme, "://");
    if (path) {
        *path = '\0';
        path = strtrim (path + 3, " \t");
    }
    if (!(connector_init = find_connector (scheme, &dso)))
        goto done;
    if (getenv ("FLUX_HANDLE_TRACE"))
        flags |= FLUX_O_TRACE;
    if (getenv ("FLUX_HANDLE_MATCHDEBUG"))
        flags |= FLUX_O_MATCHDEBUG;
    if (!(h = connector_init (path, flags))) {
        dlclose (dso);
        goto done;
    }
    h->dso = dso;
#if HAVE_CALIPER
    profiling_context_init(&h->prof);
#endif
    if ((s = getenv ("FLUX_HANDLE_USERID"))) {
        uint32_t userid = strtoul (s, NULL, 10);
        if (flux_opt_set (h, FLUX_OPT_TESTING_USERID, &userid,
                                                      sizeof (userid)) < 0) {
            flux_handle_destroy (h);
            h = NULL;
            goto done;
        }
    }
    if ((s = getenv ("FLUX_HANDLE_ROLEMASK"))) {
        uint32_t rolemask = strtoul (s, NULL, 0);
        if (flux_opt_set (h, FLUX_OPT_TESTING_ROLEMASK, &rolemask,
                                                    sizeof (rolemask)) < 0) {
            flux_handle_destroy (h);
            h = NULL;
            goto done;
        }
    }
done:
    free (scheme);
    free (default_uri);
    return h;
}