Beispiel #1
0
void
_g_debug_init (void) 
{
  const gchar *val;
  
  _g_debug_initialized = TRUE;
  
  val = g_getenv ("G_DEBUG");
  if (val != NULL)
    {
      const GDebugKey keys[] = {
	{"fatal_warnings", G_DEBUG_FATAL_WARNINGS},
	{"fatal_criticals", G_DEBUG_FATAL_CRITICALS}
      };
      
      _g_debug_flags = g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
    }
  
  if (_g_debug_flags & G_DEBUG_FATAL_WARNINGS) 
    {
      GLogLevelFlags fatal_mask;
      
      fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
      fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
      g_log_set_always_fatal (fatal_mask);
    }
  
  if (_g_debug_flags & G_DEBUG_FATAL_CRITICALS) 
    {
      GLogLevelFlags fatal_mask;
      
      fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
      fatal_mask |= G_LOG_LEVEL_CRITICAL;
      g_log_set_always_fatal (fatal_mask);
    }
}
Beispiel #2
0
/**
 * gtk_gl_parse_args:
 * @argc: (inout): the number of command line arguments.
 * @argv: (array length=argc) (inout) (allow-none): the array of command line arguments.
 *
 * Parses command line arguments, and initializes global
 * attributes of GtkGLExt.
 *
 * Any arguments used by GtkGLExt are removed from the array and
 * @argc and @argv are updated accordingly.
 *
 * You shouldn't call this function explicitely if you are using
 * gtk_gl_init(), or gtk_gl_init_check().
 **/
static void
gtk_gl_parse_args (int    *argc,
                   char ***argv)
{
  const gchar *env_string;

  if (gtk_gl_initialized)
    return;

  /*
   * If window manager doesn't watch the WM_COLORMAP_WINDOWS property on
   * the top-level window, we have to set OpenGL window's colormap to the
   * top-level window, especially in color index mode (color index mode
   * uses own private colormap).
   */
  env_string = g_getenv ("GTK_GL_INSTALL_COLORMAP");
  if (env_string != NULL)
    {
      _gtk_gl_widget_install_toplevel_cmap = (atoi (env_string) != 0);
      env_string = NULL;
    }

#ifdef G_ENABLE_DEBUG
  env_string = g_getenv ("GTK_GL_DEBUG");
  if (env_string != NULL)
    {
      gtk_gl_debug_flags = g_parse_debug_string (env_string,
                                                 gtk_gl_debug_keys,
                                                 gtk_gl_ndebug_keys);
      env_string = NULL;
    }
#endif	/* G_ENABLE_DEBUG */

  if (argc && argv)
    {
      gint i, j, k;

      for (i = 1; i < *argc;)
	{
          if (strcmp ("--gtk-gl-install-colormap", (*argv)[i]) == 0)
            {
              _gtk_gl_widget_install_toplevel_cmap = TRUE;
              (*argv)[i] = NULL;
            }
#ifdef G_ENABLE_DEBUG
          else if ((strcmp ("--gtk-gl-debug", (*argv)[i]) == 0) ||
                   (strncmp ("--gtk-gl-debug=", (*argv)[i], 15) == 0))
	    {
	      gchar *equal_pos = strchr ((*argv)[i], '=');

	      if (equal_pos != NULL)
		{
		  gtk_gl_debug_flags |= g_parse_debug_string (equal_pos+1,
                                                              gtk_gl_debug_keys,
                                                              gtk_gl_ndebug_keys);
		}
	      else if ((i + 1) < *argc && (*argv)[i + 1])
		{
		  gtk_gl_debug_flags |= g_parse_debug_string ((*argv)[i+1],
                                                              gtk_gl_debug_keys,
                                                              gtk_gl_ndebug_keys);
		  (*argv)[i] = NULL;
		  i += 1;
		}
	      (*argv)[i] = NULL;
	    }
	  else if ((strcmp ("--gtk-gl-no-debug", (*argv)[i]) == 0) ||
		   (strncmp ("--gtk-gl-no-debug=", (*argv)[i], 18) == 0))
	    {
	      gchar *equal_pos = strchr ((*argv)[i], '=');

	      if (equal_pos != NULL)
		{
		  gtk_gl_debug_flags &= ~g_parse_debug_string (equal_pos+1,
                                                               gtk_gl_debug_keys,
                                                               gtk_gl_ndebug_keys);
		}
	      else if ((i + 1) < *argc && (*argv)[i + 1])
		{
		  gtk_gl_debug_flags &= ~g_parse_debug_string ((*argv)[i+1],
                                                               gtk_gl_debug_keys,
                                                               gtk_gl_ndebug_keys);
		  (*argv)[i] = NULL;
		  i += 1;
		}
	      (*argv)[i] = NULL;
	    }
#endif /* G_ENABLE_DEBUG */
	  i += 1;
	}

      for (i = 1; i < *argc; i++)
	{
	  for (k = i; k < *argc; k++)
	    if ((*argv)[k] != NULL)
	      break;

	  if (k > i)
	    {
	      k -= i;
	      for (j = i + k; j < *argc; j++)
		(*argv)[j-k] = (*argv)[j];
	      *argc -= k;
	    }
	}

    }

  /* Set the 'initialized' flag. */
  gtk_gl_initialized = TRUE;
}
Beispiel #3
0
static gboolean
gegl_post_parse_hook (GOptionContext *context,
                      GOptionGroup   *group,
                      gpointer        data,
                      GError        **error)
{
  glong time;

  if (config)
    return TRUE;


  g_assert (global_time == 0);
  global_time = gegl_ticks ();
  g_type_init ();
  gegl_instrument ("gegl", "gegl_init", 0);

  config = (void*)gegl_config ();

  if (cmd_gegl_swap)
    g_object_set (config, "swap", cmd_gegl_swap, NULL);
  if (cmd_gegl_quality)
    config->quality = atof (cmd_gegl_quality);
  if (cmd_gegl_cache_size)
    config->cache_size = atoi (cmd_gegl_cache_size)*1024*1024;
  if (cmd_gegl_chunk_size)
    config->chunk_size = atoi (cmd_gegl_chunk_size);
  if (cmd_gegl_tile_size)
    {
      const gchar *str = cmd_gegl_tile_size;
      config->tile_width = atoi(str);
      str = strchr (str, 'x');
      if (str)
        config->tile_height = atoi(str+1);
    }
  if (cmd_gegl_threads)
    config->threads = atoi (cmd_gegl_threads);
  if (cmd_babl_tolerance)
    g_object_set (config, "babl-tolerance", atof(cmd_babl_tolerance), NULL);

#ifdef GEGL_ENABLE_DEBUG
  {
    const char *env_string;
    env_string = g_getenv ("GEGL_DEBUG");
    if (env_string != NULL)
      {
        gegl_debug_flags =
          g_parse_debug_string (env_string,
                                gegl_debug_keys,
                                G_N_ELEMENTS (gegl_debug_keys));
        env_string = NULL;
      }
  }
#endif /* GEGL_ENABLE_DEBUG */

  time = gegl_ticks ();

  babl_init ();
  gegl_instrument ("gegl_init", "babl_init", gegl_ticks () - time);

  gegl_init_i18n ();

  time = gegl_ticks ();
  if (!module_db)
    {
      const gchar *gegl_path = g_getenv ("GEGL_PATH");

      module_db = gegl_module_db_new (FALSE);

      if (gegl_path)
        {
          gegl_module_db_load (module_db, gegl_path);
        }
      else
        {
          gchar *module_path;

#ifdef G_OS_WIN32
          {
            gchar *prefix;
            prefix = g_win32_get_package_installation_directory_of_module ( hLibGeglModule );
            module_path = g_build_filename (prefix, "lib", GEGL_LIBRARY, NULL);
            g_free(prefix);
          }
#else
          module_path = g_build_filename (LIBDIR, GEGL_LIBRARY, NULL);
#endif

          gegl_module_db_load (module_db, module_path);
          g_free (module_path);

          /* also load plug-ins from ~/.local/share/gegl-0.0/plugins */
          module_path = g_build_filename (g_get_user_data_dir (),
                                          GEGL_LIBRARY,
                                          "plug-ins",
                                          NULL);

          if (g_mkdir_with_parents (module_path,
                                    S_IRUSR | S_IWUSR | S_IXUSR) == 0)
            {
              gchar *makefile_path = g_build_filename (module_path,
                                                       "Makefile",
                                                       NULL);

              if (! g_file_test (makefile_path, G_FILE_TEST_EXISTS))
                g_file_set_contents (makefile_path, makefile (), -1, NULL);

              g_free (makefile_path);
            }

          gegl_module_db_load (module_db, module_path);
          g_free (module_path);
        }

      gegl_instrument ("gegl_init", "load modules", gegl_ticks () - time);
    }

  gegl_instrument ("gegl", "gegl_init", gegl_ticks () - global_time);

  if (g_getenv ("GEGL_SWAP"))
    g_object_set (config, "swap", g_getenv ("GEGL_SWAP"), NULL);
  if (g_getenv ("GEGL_QUALITY"))
    {
      const gchar *quality = g_getenv ("GEGL_QUALITY");
      if (g_str_equal (quality, "fast"))
        g_object_set (config, "quality", 0.0, NULL);
      if (g_str_equal (quality, "good"))
        g_object_set (config, "quality", 0.5, NULL);
      if (g_str_equal (quality, "best"))
        g_object_set (config, "quality", 1.0, NULL);
    }

  swap_clean ();
  return TRUE;
}
Beispiel #4
0
/**
 * gdk_gl_parse_args:
 * @argc: the number of command line arguments.
 * @argv: the array of command line arguments.
 *
 * Parses command line arguments, and initializes global
 * attributes of GdkGLExt.
 *
 * Any arguments used by GdkGLExt are removed from the array and
 * @argc and @argv are updated accordingly.
 *
 * You shouldn't call this function explicitely if you are using
 * gdk_gl_init(), or gdk_gl_init_check().
 **/
static void
gdk_gl_parse_args (int    *argc,
                   char ***argv)
{
  const gchar *env_string;

  if (gdk_gl_initialized)
    return;

  env_string = g_getenv ("GDK_GL_FORCE_INDIRECT");
  if (env_string != NULL)
    {
      _gdk_gl_context_force_indirect = !!g_ascii_strtoll (env_string, NULL, 0);
      env_string = NULL;
    }

#ifdef G_ENABLE_DEBUG
  env_string = g_getenv ("GDK_GL_DEBUG");
  if (env_string != NULL)
    {
      gdk_gl_debug_flags = g_parse_debug_string (env_string,
                                                 gdk_gl_debug_keys,
                                                 gdk_gl_ndebug_keys);
      env_string = NULL;
    }
#endif	/* G_ENABLE_DEBUG */

  if (argc && argv)
    {
      gint i, j, k;

      for (i = 1; i < *argc;)
	{
          if (strcmp ("--gdk-gl-force-indirect", (*argv)[i]) == 0)
            {
              _gdk_gl_context_force_indirect = TRUE;
              (*argv)[i] = NULL;
            }
#ifdef G_ENABLE_DEBUG
          else if ((strcmp ("--gdk-gl-debug", (*argv)[i]) == 0) ||
                   (strncmp ("--gdk-gl-debug=", (*argv)[i], 15) == 0))
	    {
	      gchar *equal_pos = strchr ((*argv)[i], '=');

	      if (equal_pos != NULL)
		{
		  gdk_gl_debug_flags |= g_parse_debug_string (equal_pos+1,
                                                              gdk_gl_debug_keys,
                                                              gdk_gl_ndebug_keys);
		}
	      else if ((i + 1) < *argc && (*argv)[i + 1])
		{
		  gdk_gl_debug_flags |= g_parse_debug_string ((*argv)[i+1],
                                                              gdk_gl_debug_keys,
                                                              gdk_gl_ndebug_keys);
		  (*argv)[i] = NULL;
		  i += 1;
		}
	      (*argv)[i] = NULL;
	    }
	  else if ((strcmp ("--gdk-gl-no-debug", (*argv)[i]) == 0) ||
		   (strncmp ("--gdk-gl-no-debug=", (*argv)[i], 18) == 0))
	    {
	      gchar *equal_pos = strchr ((*argv)[i], '=');

	      if (equal_pos != NULL)
		{
		  gdk_gl_debug_flags &= ~g_parse_debug_string (equal_pos+1,
                                                               gdk_gl_debug_keys,
                                                               gdk_gl_ndebug_keys);
		}
	      else if ((i + 1) < *argc && (*argv)[i + 1])
		{
		  gdk_gl_debug_flags &= ~g_parse_debug_string ((*argv)[i+1],
                                                               gdk_gl_debug_keys,
                                                               gdk_gl_ndebug_keys);
		  (*argv)[i] = NULL;
		  i += 1;
		}
	      (*argv)[i] = NULL;
	    }
#endif /* G_ENABLE_DEBUG */
	  i += 1;
	}

      for (i = 1; i < *argc; i++)
	{
	  for (k = i; k < *argc; k++)
	    if ((*argv)[k] != NULL)
	      break;

	  if (k > i)
	    {
	      k -= i;
	      for (j = i + k; j < *argc; j++)
		(*argv)[j-k] = (*argv)[j];
	      *argc -= k;
	    }
	}

    }

  /* Set the 'initialized' flag. */
  gdk_gl_initialized = TRUE;
}
Beispiel #5
0
GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type,
					gssize io_rx_mtu, gssize io_tx_mtu)
{
	GObex *obex;
	GIOCondition cond;

	if (gobex_debug == 0) {
		const char *env = g_getenv("GOBEX_DEBUG");

		if (env) {
			gobex_debug = g_parse_debug_string(env, keys, 7);
			g_setenv("G_MESSAGES_DEBUG", "gobex", FALSE);
		} else
			gobex_debug = G_OBEX_DEBUG_NONE;
	}

	g_obex_debug(G_OBEX_DEBUG_COMMAND, "");

	if (io == NULL)
		return NULL;

	if (io_rx_mtu >= 0 && io_rx_mtu < G_OBEX_MINIMUM_MTU)
		return NULL;

	if (io_tx_mtu >= 0 && io_tx_mtu < G_OBEX_MINIMUM_MTU)
		return NULL;

	obex = g_new0(GObex, 1);

	obex->io = g_io_channel_ref(io);
	obex->ref_count = 1;
	obex->conn_id = CONNID_INVALID;
	obex->rx_last_op = G_OBEX_OP_NONE;

	obex->io_rx_mtu = io_rx_mtu;
	obex->io_tx_mtu = io_tx_mtu;

	if (io_rx_mtu > G_OBEX_MAXIMUM_MTU)
		obex->rx_mtu = G_OBEX_MAXIMUM_MTU;
	else if (io_rx_mtu < G_OBEX_MINIMUM_MTU)
		obex->rx_mtu = G_OBEX_DEFAULT_MTU;
	else
		obex->rx_mtu = io_rx_mtu;

	obex->tx_mtu = G_OBEX_MINIMUM_MTU;

	obex->tx_queue = g_queue_new();
	obex->rx_buf = g_malloc(obex->rx_mtu);
	obex->tx_buf = g_malloc(obex->tx_mtu);

	switch (transport_type) {
	case G_OBEX_TRANSPORT_STREAM:
		obex->read = read_stream;
		obex->write = write_stream;
		break;
	case G_OBEX_TRANSPORT_PACKET:
		obex->use_srm = TRUE;
		obex->read = read_packet;
		obex->write = write_packet;
		break;
	default:
		g_obex_unref(obex);
		return NULL;
	}

	g_io_channel_set_encoding(io, NULL, NULL);
	g_io_channel_set_buffered(io, FALSE);
	cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
	obex->io_source = g_io_add_watch(io, cond, incoming_data, obex);

	return obex;
}
Beispiel #6
0
static gboolean
gegl_post_parse_hook (GOptionContext *context,
                      GOptionGroup   *group,
                      gpointer        data,
                      GError        **error)
{
  GeglConfig *config;

  g_assert (global_time == 0);
  global_time = gegl_ticks ();

  if (g_getenv ("GEGL_DEBUG_TIME") != NULL)
    gegl_instrument_enable ();

  gegl_instrument ("gegl", "gegl_init", 0);

  config = gegl_config ();

  gegl_config_parse_env (config);

  babl_init ();

#ifdef GEGL_ENABLE_DEBUG
  {
    const char *env_string;
    env_string = g_getenv ("GEGL_DEBUG");
    if (env_string != NULL)
      {
        gegl_debug_flags =
          g_parse_debug_string (env_string,
                                gegl_debug_keys,
                                G_N_ELEMENTS (gegl_debug_keys));
        env_string = NULL;
      }
  }
#endif /* GEGL_ENABLE_DEBUG */

  if (cmd_gegl_swap)
    g_object_set (config, "swap", cmd_gegl_swap, NULL);
  if (cmd_gegl_quality)
    config->quality = atof (cmd_gegl_quality);
  if (cmd_gegl_cache_size)
    config->tile_cache_size = atoll (cmd_gegl_cache_size)*1024*1024;
  if (cmd_gegl_chunk_size)
    config->chunk_size = atoi (cmd_gegl_chunk_size);
  if (cmd_gegl_tile_size)
    {
      const gchar *str = cmd_gegl_tile_size;
      config->tile_width = atoi(str);
      str = strchr (str, 'x');
      if (str)
        config->tile_height = atoi(str+1);
    }
  if (cmd_gegl_threads)
    {
      _gegl_threads = atoi (cmd_gegl_threads);
      if (_gegl_threads > GEGL_MAX_THREADS)
        {
          g_warning ("Tried to use %i threads, max is %i",
                     _gegl_threads, GEGL_MAX_THREADS);
          _gegl_threads = GEGL_MAX_THREADS;
        }
    }
  if (cmd_gegl_disable_opencl)
    gegl_cl_hard_disable ();

  gegl_init_swap_dir ();

  GEGL_INSTRUMENT_START();

  gegl_operation_gtype_init ();

  if (!module_db)
    {
      GSList *paths = gegl_get_default_module_paths ();
      module_db = gegl_module_db_new (FALSE);
      g_slist_foreach(paths, (GFunc)load_module_path, module_db);
      g_slist_free_full (paths, g_free);
    }

  GEGL_INSTRUMENT_END ("gegl_init", "load modules");

  gegl_instrument ("gegl", "gegl_init", gegl_ticks () - global_time);

  swap_clean ();

  g_signal_connect (G_OBJECT (config),
                   "notify::use-opencl",
                   G_CALLBACK (gegl_config_use_opencl_notify),
                   NULL);
  g_object_set (config, "use-opencl", config->use_opencl, NULL);

  g_signal_connect (G_OBJECT (config),
                   "notify::application-license",
                   G_CALLBACK (gegl_config_application_license_notify),
                   NULL);
  gegl_operations_set_licenses_from_string (config->application_license);

  return TRUE;
}