2007-12-29 08:57:51 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2007-12-29 09:35:04 +08:00
|
|
|
* gimp-gegl.c
|
2007-12-29 08:57:51 +08:00
|
|
|
* Copyright (C) 2007 Øyvind Kolås <pippin@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2007-12-29 08:57:51 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2007-12-29 08:57:51 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2007-12-29 08:57:51 +08:00
|
|
|
*/
|
|
|
|
|
2007-12-29 09:35:04 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2014-07-05 18:51:54 +08:00
|
|
|
#include <gio/gio.h>
|
2008-01-16 23:52:02 +08:00
|
|
|
#include <gegl.h>
|
2007-12-29 09:35:04 +08:00
|
|
|
|
2018-11-19 01:10:34 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
|
|
|
|
2009-02-21 23:06:49 +08:00
|
|
|
#include "gimp-gegl-types.h"
|
2007-12-29 23:25:40 +08:00
|
|
|
|
2012-05-15 04:57:58 +08:00
|
|
|
#include "config/gimpgeglconfig.h"
|
2008-11-16 18:30:49 +08:00
|
|
|
|
2012-05-11 03:22:44 +08:00
|
|
|
#include "operations/gimp-operations.h"
|
|
|
|
|
2008-11-16 18:30:49 +08:00
|
|
|
#include "core/gimp.h"
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-05 03:16:42 +08:00
|
|
|
#include "core/gimp-parallel.h"
|
2008-11-16 18:30:49 +08:00
|
|
|
|
2012-04-22 05:46:41 +08:00
|
|
|
#include "gimp-babl.h"
|
2007-12-29 09:35:04 +08:00
|
|
|
#include "gimp-gegl.h"
|
2012-03-17 23:22:59 +08:00
|
|
|
|
2018-11-19 01:10:34 +08:00
|
|
|
#include <operation/gegl-operation.h>
|
|
|
|
|
2007-12-29 08:57:51 +08:00
|
|
|
|
2019-09-22 21:44:23 +08:00
|
|
|
static void gimp_gegl_notify_temp_path (GimpGeglConfig *config);
|
|
|
|
static void gimp_gegl_notify_swap_path (GimpGeglConfig *config);
|
|
|
|
static void gimp_gegl_notify_swap_compression (GimpGeglConfig *config);
|
|
|
|
static void gimp_gegl_notify_tile_cache_size (GimpGeglConfig *config);
|
|
|
|
static void gimp_gegl_notify_num_processors (GimpGeglConfig *config);
|
|
|
|
static void gimp_gegl_notify_use_opencl (GimpGeglConfig *config);
|
2008-11-16 18:30:49 +08:00
|
|
|
|
2018-11-19 01:10:34 +08:00
|
|
|
|
|
|
|
/* public functions */
|
2008-11-16 18:30:49 +08:00
|
|
|
|
2007-12-29 09:35:04 +08:00
|
|
|
void
|
2008-11-16 18:30:49 +08:00
|
|
|
gimp_gegl_init (Gimp *gimp)
|
2007-12-29 08:57:51 +08:00
|
|
|
{
|
2012-05-15 04:57:58 +08:00
|
|
|
GimpGeglConfig *config;
|
2008-11-16 18:30:49 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
|
2012-05-15 04:57:58 +08:00
|
|
|
config = GIMP_GEGL_CONFIG (gimp->config);
|
2008-11-16 18:30:49 +08:00
|
|
|
|
2019-09-22 21:44:23 +08:00
|
|
|
/* make sure temp and swap directories exist */
|
2018-11-19 01:10:34 +08:00
|
|
|
gimp_gegl_notify_temp_path (config);
|
2019-09-22 21:44:23 +08:00
|
|
|
gimp_gegl_notify_swap_path (config);
|
2018-11-19 01:10:34 +08:00
|
|
|
|
2013-06-06 06:03:26 +08:00
|
|
|
g_object_set (gegl_config (),
|
2019-09-22 21:44:23 +08:00
|
|
|
"swap-compression", config->swap_compression,
|
|
|
|
"tile-cache-size", (guint64) config->tile_cache_size,
|
|
|
|
"threads", config->num_processors,
|
|
|
|
"use-opencl", config->use_opencl,
|
2013-06-06 06:03:26 +08:00
|
|
|
NULL);
|
2008-06-04 20:49:18 +08:00
|
|
|
|
app: flush async-operations queue when setting async thread count to 0
In gimp-parallel, always flush the async-operations queue (by
executing all remaining operations on the caller thread) when
setting the async-pool thread count to 0 (as happens when setting
GEGL_THREADS=1, per the previous commit,) and not only when
shutting GIMP down. Otherwise, pending asynchronous operations
can "get lost" when setting GEGL_THREADS to 1.
Additionally, in gimp_gegl_init(), initialize gimp-parallel before
before connecting to GimpGeglConfig's "notify::num-processors"
signal, so that the number of async threads is set *before*
GEGL_THREADS, in order to avoid setting GEGL_THREADS to 1 while
async operations are still executing.
Also, allow setting the number of gimp-parallel-distribute threads
while a gimp-parallel-distribute function is running (which can
happen if gimp-parallel-distribute is used in an async operation,
as is the case for histogram calculation), by waiting for the
parallel-distribute function to finish before setting the number of
threads.
2018-07-15 16:58:29 +08:00
|
|
|
gimp_parallel_init (gimp);
|
|
|
|
|
2019-09-22 21:44:23 +08:00
|
|
|
g_signal_connect (config, "notify::temp-path",
|
|
|
|
G_CALLBACK (gimp_gegl_notify_temp_path),
|
|
|
|
NULL);
|
2018-11-19 01:10:34 +08:00
|
|
|
g_signal_connect (config, "notify::swap-path",
|
|
|
|
G_CALLBACK (gimp_gegl_notify_swap_path),
|
|
|
|
NULL);
|
2019-09-22 21:44:23 +08:00
|
|
|
g_signal_connect (config, "notify::swap-compression",
|
|
|
|
G_CALLBACK (gimp_gegl_notify_swap_compression),
|
2018-11-19 01:10:34 +08:00
|
|
|
NULL);
|
|
|
|
g_signal_connect (config, "notify::num-processors",
|
|
|
|
G_CALLBACK (gimp_gegl_notify_num_processors),
|
|
|
|
NULL);
|
2008-11-16 18:30:49 +08:00
|
|
|
g_signal_connect (config, "notify::tile-cache-size",
|
|
|
|
G_CALLBACK (gimp_gegl_notify_tile_cache_size),
|
|
|
|
NULL);
|
2012-05-19 14:50:05 +08:00
|
|
|
g_signal_connect (config, "notify::num-processors",
|
|
|
|
G_CALLBACK (gimp_gegl_notify_num_processors),
|
|
|
|
NULL);
|
2013-06-02 05:02:42 +08:00
|
|
|
g_signal_connect (config, "notify::use-opencl",
|
|
|
|
G_CALLBACK (gimp_gegl_notify_use_opencl),
|
|
|
|
NULL);
|
2008-11-16 18:30:49 +08:00
|
|
|
|
2012-04-22 05:46:41 +08:00
|
|
|
gimp_babl_init ();
|
2012-04-21 22:05:49 +08:00
|
|
|
|
2017-03-24 08:29:50 +08:00
|
|
|
gimp_operations_init (gimp);
|
2007-12-29 08:57:51 +08:00
|
|
|
}
|
2008-11-16 18:30:49 +08:00
|
|
|
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-05 03:16:42 +08:00
|
|
|
void
|
|
|
|
gimp_gegl_exit (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
|
2020-11-10 19:36:36 +08:00
|
|
|
gimp_operations_exit (gimp);
|
app: add gimp-parallel
Add gimp-parallel.[cc,h], which provides a set of parallel
algorithms.
These currently include:
- gimp_parallel_distribute(): Calls a callback function in
parallel on multiple threads, passing it the current thread
index, and the total number of threads. Allows specifying the
maximal number of threads used.
- gimp_parallel_distribute_range(): Splits a range of integers
between multiple threads, passing the sub-range to a callback
function. Allows specifying the minimal sub-range size.
- gimp_parallel_distribute_area(): Splits a rectangular area
between multiple threads, passing the sub-area to a callback
function. Allows specifying the minimal sub-area.
The callback function is passed using an appropriately-typed
function pointer, and a user-data pointer. Additionally, when used
in a C++ file, each of the above functions has an overloaded
template version, taking the callback through a generic parameter,
without a user-data pointer, which allows using function objects.
2018-04-05 03:16:42 +08:00
|
|
|
gimp_parallel_exit (gimp);
|
|
|
|
}
|
|
|
|
|
2018-11-19 01:10:34 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2019-09-22 21:44:23 +08:00
|
|
|
static void
|
|
|
|
gimp_gegl_notify_temp_path (GimpGeglConfig *config)
|
|
|
|
{
|
|
|
|
GFile *file = gimp_file_new_for_config_path (config->temp_path, NULL);
|
|
|
|
|
|
|
|
if (! g_file_query_exists (file, NULL))
|
|
|
|
g_file_make_directory_with_parents (file, NULL, NULL);
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
}
|
|
|
|
|
2018-11-19 01:10:34 +08:00
|
|
|
static void
|
|
|
|
gimp_gegl_notify_swap_path (GimpGeglConfig *config)
|
|
|
|
{
|
|
|
|
GFile *file = gimp_file_new_for_config_path (config->swap_path, NULL);
|
|
|
|
gchar *path = g_file_get_path (file);
|
|
|
|
|
|
|
|
if (! g_file_query_exists (file, NULL))
|
|
|
|
g_file_make_directory_with_parents (file, NULL, NULL);
|
|
|
|
|
|
|
|
g_object_set (gegl_config (),
|
|
|
|
"swap", path,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_free (path);
|
|
|
|
g_object_unref (file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-09-22 21:44:23 +08:00
|
|
|
gimp_gegl_notify_swap_compression (GimpGeglConfig *config)
|
2018-11-19 01:10:34 +08:00
|
|
|
{
|
2019-09-22 21:44:23 +08:00
|
|
|
g_object_set (gegl_config (),
|
|
|
|
"swap-compression", config->swap_compression,
|
|
|
|
NULL);
|
2018-11-19 01:10:34 +08:00
|
|
|
}
|
|
|
|
|
2008-11-16 18:30:49 +08:00
|
|
|
static void
|
2012-05-15 04:57:58 +08:00
|
|
|
gimp_gegl_notify_tile_cache_size (GimpGeglConfig *config)
|
2008-11-16 18:30:49 +08:00
|
|
|
{
|
2013-06-06 06:03:26 +08:00
|
|
|
g_object_set (gegl_config (),
|
|
|
|
"tile-cache-size", (guint64) config->tile_cache_size,
|
|
|
|
NULL);
|
2008-11-16 18:30:49 +08:00
|
|
|
}
|
2012-05-19 14:50:05 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_gegl_notify_num_processors (GimpGeglConfig *config)
|
|
|
|
{
|
|
|
|
g_object_set (gegl_config (),
|
|
|
|
"threads", config->num_processors,
|
|
|
|
NULL);
|
|
|
|
}
|
2013-06-02 05:02:42 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_gegl_notify_use_opencl (GimpGeglConfig *config)
|
|
|
|
{
|
|
|
|
g_object_set (gegl_config (),
|
|
|
|
"use-opencl", config->use_opencl,
|
|
|
|
NULL);
|
|
|
|
}
|