2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1999-04-09 14:00:11 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2006-01-12 08:50:44 +08:00
|
|
|
* pixel_processor.c: Copyright (C) 1999 Jay Cox <jaycox@gimp.org>
|
1999-04-09 14:00:11 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1999-04-09 14:00:11 +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
|
1999-04-09 14:00:11 +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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1999-04-09 14:00:11 +08:00
|
|
|
*/
|
|
|
|
|
Win32 portability changes:
* config.h.win32, README.win32: Small changes.
* tools/pdbgen/pdb/*.pdb: Include <string.h>.
* app/*_cmds.c: Autogenerated files reflect above changes.
* libgimp/makefile.msc app/makefile.msc: Various updates,
including new object files. Gtk+ directory now should be called
gtk+ (not gtk-plus). Use win32-specific gdk subdir. Glib directory
now should be called just glib.
* libgimp/gimp.def: Updates.
* libgimp/gimpfeatures.h.win32: Made current with
gimpfeatures.h.in.
* libgimp/gimpfileselection.c: Define S_ISDIR and S_ISREG if
necessary.
* tools/pdbgen/pdb/fileops.pdb: Must have a
statement (even an empty one) after a label.
* app/fileops_cmds.c: Autogenerated file reflects above changes.
* app/crop.c: Include <string.h>.
* app/{app_procs,batch,fileops,datafiles,errorconsole,general,
plug_in,temp_buf,tile_swap}.c: Test NATIVE_WIN32, not
_MSC_VER. (NATIVE_WIN32 means we are using the Microsoft C
runtime, even if we might be compiling with gcc.)
* app/fileops.c: Don't include <process.h> here.
* app/fileops.h: Do include <process.h> here.
* app/gimpparasite.c: Include config.h, guard inclusion of
<unistd.h>. (Is the inclusion of unistd.h in source files all over
the place really necessary?)
* app/ink.c: MSC doesn't handle conversion from unsigned __int64
to double, so cast to signed.
* app/lut_funcs.c: Include config.h, and define rint() if necessary.
* app/pixel_processor.c: Include config.h without "..", like in
all the other places. Include <string.h>
* app/text_tool.c: Guard the "POINTS" identifier that clashes with
<windows.h>, sigh.
1999-05-05 05:32:17 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
#ifdef ENABLE_MP
|
2005-02-11 23:24:02 +08:00
|
|
|
#include <string.h>
|
2003-01-15 21:40:44 +08:00
|
|
|
#endif
|
1999-04-09 14:00:11 +08:00
|
|
|
|
2001-12-08 00:10:53 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base-types.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2002-11-19 04:50:31 +08:00
|
|
|
#include "config/gimpbaseconfig.h"
|
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "pixel-processor.h"
|
|
|
|
#include "pixel-region.h"
|
1999-04-09 14:00:11 +08:00
|
|
|
|
2001-01-12 07:36:59 +08:00
|
|
|
#include "tile.h"
|
2005-02-16 22:54:56 +08:00
|
|
|
|
2005-02-26 19:55:52 +08:00
|
|
|
|
2005-02-17 05:24:13 +08:00
|
|
|
#define TILES_PER_THREAD 8
|
2005-02-16 22:54:56 +08:00
|
|
|
#define PROGRESS_TIMEOUT 64
|
|
|
|
|
2005-02-26 19:55:52 +08:00
|
|
|
|
2005-02-17 05:24:13 +08:00
|
|
|
static GThreadPool *pool = NULL;
|
|
|
|
static GMutex *pool_mutex = NULL;
|
|
|
|
static GCond *pool_cond = NULL;
|
2003-01-15 21:40:44 +08:00
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
|
2005-02-26 19:55:52 +08:00
|
|
|
typedef void (* p1_func) (gpointer data,
|
|
|
|
PixelRegion *region1);
|
|
|
|
typedef void (* p2_func) (gpointer data,
|
|
|
|
PixelRegion *region1,
|
|
|
|
PixelRegion *region2);
|
|
|
|
typedef void (* p3_func) (gpointer data,
|
|
|
|
PixelRegion *region1,
|
|
|
|
PixelRegion *region2,
|
|
|
|
PixelRegion *region3);
|
|
|
|
typedef void (* p4_func) (gpointer data,
|
|
|
|
PixelRegion *region1,
|
|
|
|
PixelRegion *region2,
|
|
|
|
PixelRegion *region3,
|
|
|
|
PixelRegion *region4);
|
1999-04-09 14:00:11 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
|
2005-02-12 01:03:56 +08:00
|
|
|
typedef struct _PixelProcessor PixelProcessor;
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
struct _PixelProcessor
|
|
|
|
{
|
2005-02-13 00:07:00 +08:00
|
|
|
PixelProcessorFunc func;
|
2005-02-16 22:54:56 +08:00
|
|
|
gpointer data;
|
2003-01-15 21:40:44 +08:00
|
|
|
|
|
|
|
#ifdef ENABLE_MP
|
2005-02-26 19:55:52 +08:00
|
|
|
GMutex *mutex;
|
2005-02-14 04:58:30 +08:00
|
|
|
gint threads;
|
2005-02-25 06:58:02 +08:00
|
|
|
gboolean first;
|
2003-01-15 21:40:44 +08:00
|
|
|
#endif
|
|
|
|
|
2005-02-16 22:54:56 +08:00
|
|
|
PixelRegionIterator *PRI;
|
2005-02-13 00:07:00 +08:00
|
|
|
gint num_regions;
|
|
|
|
PixelRegion *regions[4];
|
2005-02-16 22:54:56 +08:00
|
|
|
|
|
|
|
gulong progress;
|
1999-04-09 14:00:11 +08:00
|
|
|
};
|
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
|
2003-01-15 21:40:44 +08:00
|
|
|
#ifdef ENABLE_MP
|
2005-02-13 23:08:08 +08:00
|
|
|
static void
|
2005-02-12 01:03:56 +08:00
|
|
|
do_parallel_regions (PixelProcessor *processor)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
PixelRegion tr[4];
|
2001-05-15 19:25:25 +08:00
|
|
|
gint i;
|
1999-04-09 14:00:11 +08:00
|
|
|
|
2005-02-25 06:58:02 +08:00
|
|
|
g_mutex_lock (processor->mutex);
|
2000-10-18 02:32:43 +08:00
|
|
|
|
2005-02-14 04:58:30 +08:00
|
|
|
/* the first thread getting here must not call pixel_regions_process() */
|
2005-02-25 06:58:02 +08:00
|
|
|
if (!processor->first && processor->PRI)
|
2005-02-12 01:03:56 +08:00
|
|
|
processor->PRI = pixel_regions_process (processor->PRI);
|
2005-02-25 06:58:02 +08:00
|
|
|
else
|
|
|
|
processor->first = FALSE;
|
2000-10-18 02:32:43 +08:00
|
|
|
|
2005-02-25 06:58:02 +08:00
|
|
|
while (processor->PRI)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
2005-02-16 22:54:56 +08:00
|
|
|
guint pixels = (processor->PRI->portion_width *
|
|
|
|
processor->PRI->portion_height);
|
|
|
|
|
2005-02-13 00:07:00 +08:00
|
|
|
for (i = 0; i < processor->num_regions; i++)
|
2006-04-12 20:49:29 +08:00
|
|
|
if (processor->regions[i])
|
|
|
|
{
|
|
|
|
memcpy (&tr[i], processor->regions[i], sizeof (PixelRegion));
|
|
|
|
if (tr[i].tiles)
|
|
|
|
tile_lock (tr[i].curtile);
|
|
|
|
}
|
2000-10-18 02:32:43 +08:00
|
|
|
|
2005-02-25 06:58:02 +08:00
|
|
|
g_mutex_unlock (processor->mutex);
|
2000-10-18 02:32:43 +08:00
|
|
|
|
2006-09-28 07:29:05 +08:00
|
|
|
switch (processor->num_regions)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
((p1_func) processor->func) (processor->data,
|
2005-02-13 00:07:00 +08:00
|
|
|
processor->regions[0] ? &tr[0] : NULL);
|
2006-04-12 20:49:29 +08:00
|
|
|
break;
|
2000-10-18 02:32:43 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
case 2:
|
|
|
|
((p2_func) processor->func) (processor->data,
|
2005-02-13 00:07:00 +08:00
|
|
|
processor->regions[0] ? &tr[0] : NULL,
|
|
|
|
processor->regions[1] ? &tr[1] : NULL);
|
2006-04-12 20:49:29 +08:00
|
|
|
break;
|
2000-10-18 02:32:43 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
case 3:
|
|
|
|
((p3_func) processor->func) (processor->data,
|
2005-02-13 00:07:00 +08:00
|
|
|
processor->regions[0] ? &tr[0] : NULL,
|
|
|
|
processor->regions[1] ? &tr[1] : NULL,
|
|
|
|
processor->regions[2] ? &tr[2] : NULL);
|
2006-04-12 20:49:29 +08:00
|
|
|
break;
|
2000-10-18 02:32:43 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
case 4:
|
|
|
|
((p4_func) processor->func) (processor->data,
|
2005-02-13 00:07:00 +08:00
|
|
|
processor->regions[0] ? &tr[0] : NULL,
|
|
|
|
processor->regions[1] ? &tr[1] : NULL,
|
|
|
|
processor->regions[2] ? &tr[2] : NULL,
|
|
|
|
processor->regions[3] ? &tr[3] : NULL);
|
2006-04-12 20:49:29 +08:00
|
|
|
break;
|
2000-10-18 02:32:43 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
default:
|
|
|
|
g_warning ("do_parallel_regions: Bad number of regions %d\n",
|
2005-02-13 00:07:00 +08:00
|
|
|
processor->num_regions);
|
2003-01-15 21:40:44 +08:00
|
|
|
break;
|
2005-02-16 22:54:56 +08:00
|
|
|
}
|
2000-10-18 02:32:43 +08:00
|
|
|
|
2005-02-25 06:58:02 +08:00
|
|
|
g_mutex_lock (processor->mutex);
|
2000-10-18 02:32:43 +08:00
|
|
|
|
2005-02-16 22:54:56 +08:00
|
|
|
for (i = 0; i < processor->num_regions; i++)
|
|
|
|
if (processor->regions[i])
|
|
|
|
{
|
|
|
|
if (tr[i].tiles)
|
|
|
|
tile_release (tr[i].curtile, tr[i].dirty);
|
|
|
|
}
|
2003-01-15 21:40:44 +08:00
|
|
|
|
2005-02-16 22:54:56 +08:00
|
|
|
processor->progress += pixels;
|
2005-02-26 19:55:52 +08:00
|
|
|
|
2005-02-25 06:58:02 +08:00
|
|
|
if (processor->PRI)
|
2006-04-12 20:49:29 +08:00
|
|
|
processor->PRI = pixel_regions_process (processor->PRI);
|
2005-02-16 22:54:56 +08:00
|
|
|
}
|
2000-10-18 02:32:43 +08:00
|
|
|
|
2005-02-17 05:24:13 +08:00
|
|
|
processor->threads--;
|
|
|
|
|
|
|
|
if (processor->threads == 0)
|
|
|
|
{
|
2005-02-25 06:58:02 +08:00
|
|
|
g_mutex_unlock (processor->mutex);
|
2005-02-26 19:55:52 +08:00
|
|
|
|
|
|
|
g_mutex_lock (pool_mutex);
|
2005-02-25 06:58:02 +08:00
|
|
|
g_cond_signal (pool_cond);
|
2005-02-26 19:55:52 +08:00
|
|
|
g_mutex_unlock (pool_mutex);
|
2005-02-17 05:24:13 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-25 06:58:02 +08:00
|
|
|
g_mutex_unlock (processor->mutex);
|
2005-02-17 05:24:13 +08:00
|
|
|
}
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|
2003-01-15 21:40:44 +08:00
|
|
|
#endif
|
2000-05-05 09:15:39 +08:00
|
|
|
|
2005-02-11 23:24:02 +08:00
|
|
|
/* do_parallel_regions_single is just like do_parallel_regions
|
2000-05-05 09:15:39 +08:00
|
|
|
* except that all the mutex and tile locks have been removed
|
|
|
|
*
|
2005-02-13 23:08:08 +08:00
|
|
|
* If we are processing with only a single thread we don't need to do
|
|
|
|
* the mutex locks etc. and aditional tile locks even if we were
|
2000-05-05 09:15:39 +08:00
|
|
|
* configured --with-mp
|
|
|
|
*/
|
|
|
|
|
2001-01-23 22:21:37 +08:00
|
|
|
static gpointer
|
2005-02-16 22:54:56 +08:00
|
|
|
do_parallel_regions_single (PixelProcessor *processor,
|
|
|
|
PixelProcessorProgressFunc progress_func,
|
|
|
|
gpointer progress_data,
|
|
|
|
gulong total)
|
2000-05-05 09:15:39 +08:00
|
|
|
{
|
2005-02-16 22:54:56 +08:00
|
|
|
GTimeVal last_time;
|
|
|
|
|
|
|
|
if (progress_func)
|
|
|
|
g_get_current_time (&last_time);
|
|
|
|
|
2000-05-05 09:15:39 +08:00
|
|
|
do
|
|
|
|
{
|
2005-02-13 00:07:00 +08:00
|
|
|
switch (processor->num_regions)
|
2003-01-15 21:40:44 +08:00
|
|
|
{
|
|
|
|
case 1:
|
2005-02-13 00:07:00 +08:00
|
|
|
((p1_func) processor->func) (processor->data,
|
|
|
|
processor->regions[0]);
|
2003-01-15 21:40:44 +08:00
|
|
|
break;
|
2005-02-11 23:24:02 +08:00
|
|
|
|
2003-01-15 21:40:44 +08:00
|
|
|
case 2:
|
2005-02-13 00:07:00 +08:00
|
|
|
((p2_func) processor->func) (processor->data,
|
|
|
|
processor->regions[0],
|
|
|
|
processor->regions[1]);
|
2003-01-15 21:40:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2005-02-13 00:07:00 +08:00
|
|
|
((p3_func) processor->func) (processor->data,
|
|
|
|
processor->regions[0],
|
|
|
|
processor->regions[1],
|
|
|
|
processor->regions[2]);
|
2003-01-15 21:40:44 +08:00
|
|
|
break;
|
2005-02-11 23:24:02 +08:00
|
|
|
|
2003-01-15 21:40:44 +08:00
|
|
|
case 4:
|
2005-02-13 00:07:00 +08:00
|
|
|
((p4_func) processor->func) (processor->data,
|
|
|
|
processor->regions[0],
|
|
|
|
processor->regions[1],
|
|
|
|
processor->regions[2],
|
|
|
|
processor->regions[3]);
|
2003-01-15 21:40:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_warning ("do_parallel_regions_single: Bad number of regions %d\n",
|
2005-02-13 00:07:00 +08:00
|
|
|
processor->num_regions);
|
2006-07-06 20:27:32 +08:00
|
|
|
break;
|
2003-01-15 21:40:44 +08:00
|
|
|
}
|
2001-01-23 22:21:37 +08:00
|
|
|
|
2005-02-16 22:54:56 +08:00
|
|
|
if (progress_func)
|
|
|
|
{
|
|
|
|
GTimeVal now;
|
|
|
|
|
|
|
|
processor->progress += (processor->PRI->portion_width *
|
|
|
|
processor->PRI->portion_height);
|
|
|
|
|
|
|
|
g_get_current_time (&now);
|
|
|
|
|
|
|
|
if (((now.tv_sec - last_time.tv_sec) * 1024 +
|
|
|
|
(now.tv_usec - last_time.tv_usec) / 1024) > PROGRESS_TIMEOUT)
|
|
|
|
{
|
|
|
|
progress_func (progress_data,
|
|
|
|
(gdouble) processor->progress / (gdouble) total);
|
|
|
|
|
|
|
|
last_time = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-02-12 01:03:56 +08:00
|
|
|
while (processor->PRI &&
|
2006-04-12 20:49:29 +08:00
|
|
|
(processor->PRI = pixel_regions_process (processor->PRI)));
|
2001-01-23 22:21:37 +08:00
|
|
|
|
2000-05-05 09:15:39 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
static void
|
2005-02-16 22:54:56 +08:00
|
|
|
pixel_regions_do_parallel (PixelProcessor *processor,
|
|
|
|
PixelProcessorProgressFunc progress_func,
|
|
|
|
gpointer progress_data)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
2005-02-16 22:54:56 +08:00
|
|
|
gulong pixels = (processor->PRI->region_width *
|
|
|
|
processor->PRI->region_height);
|
|
|
|
gulong tiles = pixels / (TILE_WIDTH * TILE_HEIGHT);
|
2000-05-05 09:15:39 +08:00
|
|
|
|
2005-02-17 05:24:13 +08:00
|
|
|
#ifdef ENABLE_MP
|
|
|
|
if (pool && tiles > TILES_PER_THREAD)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
2005-02-21 05:14:06 +08:00
|
|
|
GError *error = NULL;
|
|
|
|
gint tasks = MIN (tiles / TILES_PER_THREAD,
|
2005-02-25 19:54:18 +08:00
|
|
|
g_thread_pool_get_max_threads (pool));
|
2001-01-23 22:21:37 +08:00
|
|
|
|
2005-02-17 05:24:13 +08:00
|
|
|
/*
|
|
|
|
* g_printerr ("pushing %d tasks into the thread pool (for %lu tiles)\n",
|
|
|
|
* tasks, tiles);
|
2005-02-14 04:58:30 +08:00
|
|
|
*/
|
|
|
|
|
2006-09-28 07:29:05 +08:00
|
|
|
processor->first = TRUE;
|
2005-02-25 06:58:02 +08:00
|
|
|
processor->threads = tasks;
|
2006-09-28 07:29:05 +08:00
|
|
|
processor->mutex = g_mutex_new();
|
2005-02-25 06:58:02 +08:00
|
|
|
|
2005-02-26 19:55:52 +08:00
|
|
|
g_mutex_lock (pool_mutex);
|
|
|
|
|
2005-02-17 05:24:13 +08:00
|
|
|
while (tasks--)
|
2005-02-21 05:14:06 +08:00
|
|
|
{
|
|
|
|
g_thread_pool_push (pool, processor, &error);
|
|
|
|
|
2006-07-06 20:27:32 +08:00
|
|
|
if (G_UNLIKELY (error))
|
2005-02-21 05:14:06 +08:00
|
|
|
{
|
|
|
|
g_warning ("thread creation failed: %s", error->message);
|
|
|
|
g_clear_error (&error);
|
2006-04-12 20:49:29 +08:00
|
|
|
processor->threads--;
|
2005-02-21 05:14:06 +08:00
|
|
|
}
|
|
|
|
}
|
2005-02-17 05:24:13 +08:00
|
|
|
|
|
|
|
if (progress_func)
|
2001-01-23 22:21:37 +08:00
|
|
|
{
|
2005-02-25 06:58:02 +08:00
|
|
|
while (processor->threads != 0)
|
2005-02-13 23:08:08 +08:00
|
|
|
{
|
2006-04-12 20:49:29 +08:00
|
|
|
GTimeVal timeout;
|
2005-02-25 19:54:18 +08:00
|
|
|
gulong progress;
|
2005-02-17 05:24:13 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
g_get_current_time (&timeout);
|
|
|
|
g_time_val_add (&timeout, PROGRESS_TIMEOUT * 1024);
|
2005-02-25 06:58:02 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
g_cond_timed_wait (pool_cond, pool_mutex, &timeout);
|
2005-02-25 06:58:02 +08:00
|
|
|
|
|
|
|
g_mutex_lock (processor->mutex);
|
2005-02-17 05:24:13 +08:00
|
|
|
progress = processor->progress;
|
2005-02-25 06:58:02 +08:00
|
|
|
g_mutex_unlock (processor->mutex);
|
2005-02-17 05:24:13 +08:00
|
|
|
|
|
|
|
progress_func (progress_data,
|
|
|
|
(gdouble) progress / (gdouble) pixels);
|
2005-02-13 23:08:08 +08:00
|
|
|
}
|
2005-02-17 05:24:13 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-25 06:58:02 +08:00
|
|
|
while (processor->threads != 0)
|
2005-02-25 19:54:18 +08:00
|
|
|
g_cond_wait (pool_cond, pool_mutex);
|
2005-02-13 23:08:08 +08:00
|
|
|
}
|
2005-02-12 01:03:56 +08:00
|
|
|
|
2005-02-17 05:24:13 +08:00
|
|
|
g_mutex_unlock (pool_mutex);
|
2005-02-25 06:58:02 +08:00
|
|
|
|
|
|
|
g_mutex_free (processor->mutex);
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|
2001-01-23 22:21:37 +08:00
|
|
|
else
|
2003-01-15 21:40:44 +08:00
|
|
|
#endif
|
2005-02-11 23:24:02 +08:00
|
|
|
{
|
2005-02-16 22:54:56 +08:00
|
|
|
do_parallel_regions_single (processor,
|
|
|
|
progress_func, progress_data, pixels);
|
2005-02-11 23:24:02 +08:00
|
|
|
}
|
2005-02-17 05:24:13 +08:00
|
|
|
|
|
|
|
if (progress_func)
|
|
|
|
progress_func (progress_data, 1.0);
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|
|
|
|
|
2005-02-13 00:07:00 +08:00
|
|
|
static void
|
2005-02-16 22:54:56 +08:00
|
|
|
pixel_regions_process_parallel_valist (PixelProcessorFunc func,
|
|
|
|
gpointer data,
|
|
|
|
PixelProcessorProgressFunc progress_func,
|
|
|
|
gpointer progress_data,
|
|
|
|
gint num_regions,
|
|
|
|
va_list ap)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
2005-02-13 00:07:00 +08:00
|
|
|
PixelProcessor processor = { NULL, };
|
2001-01-23 22:21:37 +08:00
|
|
|
gint i;
|
1999-04-09 14:00:11 +08:00
|
|
|
|
|
|
|
for (i = 0; i < num_regions; i++)
|
2005-02-13 00:07:00 +08:00
|
|
|
processor.regions[i] = va_arg (ap, PixelRegion *);
|
1999-04-09 14:00:11 +08:00
|
|
|
|
2005-02-16 22:54:56 +08:00
|
|
|
switch (num_regions)
|
2001-01-23 22:21:37 +08:00
|
|
|
{
|
|
|
|
case 1:
|
2005-02-13 00:07:00 +08:00
|
|
|
processor.PRI = pixel_regions_register (num_regions,
|
|
|
|
processor.regions[0]);
|
2001-01-23 22:21:37 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2005-02-13 00:07:00 +08:00
|
|
|
processor.PRI = pixel_regions_register (num_regions,
|
|
|
|
processor.regions[0],
|
|
|
|
processor.regions[1]);
|
2002-08-22 17:48:56 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2005-02-13 00:07:00 +08:00
|
|
|
processor.PRI = pixel_regions_register (num_regions,
|
|
|
|
processor.regions[0],
|
|
|
|
processor.regions[1],
|
|
|
|
processor.regions[2]);
|
2002-08-22 17:48:56 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2005-02-13 00:07:00 +08:00
|
|
|
processor.PRI = pixel_regions_register (num_regions,
|
|
|
|
processor.regions[0],
|
|
|
|
processor.regions[1],
|
|
|
|
processor.regions[2],
|
|
|
|
processor.regions[3]);
|
2002-08-22 17:48:56 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-02-16 22:54:56 +08:00
|
|
|
g_warning ("pixel_regions_process_parallel: "
|
2005-02-21 05:14:06 +08:00
|
|
|
"bad number of regions (%d)", processor.num_regions);
|
2006-07-06 20:27:32 +08:00
|
|
|
break;
|
2001-01-23 22:21:37 +08:00
|
|
|
}
|
|
|
|
|
2005-02-13 00:07:00 +08:00
|
|
|
if (! processor.PRI)
|
2005-02-26 19:55:52 +08:00
|
|
|
return;
|
2005-02-13 00:07:00 +08:00
|
|
|
|
|
|
|
processor.func = func;
|
|
|
|
processor.data = data;
|
|
|
|
processor.num_regions = num_regions;
|
2003-01-15 21:40:44 +08:00
|
|
|
|
|
|
|
#ifdef ENABLE_MP
|
2005-02-14 04:58:30 +08:00
|
|
|
processor.threads = 0;
|
2003-01-15 21:40:44 +08:00
|
|
|
#endif
|
1999-04-09 14:00:11 +08:00
|
|
|
|
2005-02-16 22:54:56 +08:00
|
|
|
processor.progress = 0;
|
|
|
|
|
|
|
|
pixel_regions_do_parallel (&processor, progress_func, progress_data);
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|
|
|
|
|
2005-02-13 23:47:36 +08:00
|
|
|
void
|
|
|
|
pixel_processor_init (gint num_threads)
|
|
|
|
{
|
2005-02-14 04:58:30 +08:00
|
|
|
pixel_processor_set_num_threads (num_threads);
|
2005-02-13 23:47:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pixel_processor_set_num_threads (gint num_threads)
|
|
|
|
{
|
2005-02-17 05:24:13 +08:00
|
|
|
#ifdef ENABLE_MP
|
2005-02-14 04:58:30 +08:00
|
|
|
|
2005-02-17 05:24:13 +08:00
|
|
|
g_return_if_fail (num_threads > 0 && num_threads <= GIMP_MAX_NUM_THREADS);
|
2005-02-16 22:54:56 +08:00
|
|
|
|
2005-02-17 05:24:13 +08:00
|
|
|
if (num_threads < 2)
|
|
|
|
{
|
|
|
|
if (pool)
|
|
|
|
{
|
|
|
|
g_thread_pool_free (pool, TRUE, TRUE);
|
|
|
|
pool = NULL;
|
|
|
|
|
|
|
|
g_cond_free (pool_cond);
|
|
|
|
pool_cond = NULL;
|
|
|
|
|
|
|
|
g_mutex_free (pool_mutex);
|
|
|
|
pool_mutex = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (pool)
|
|
|
|
{
|
|
|
|
g_thread_pool_set_max_threads (pool, num_threads, &error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pool = g_thread_pool_new ((GFunc) do_parallel_regions, NULL,
|
|
|
|
num_threads, TRUE, &error);
|
|
|
|
|
|
|
|
pool_mutex = g_mutex_new ();
|
|
|
|
pool_cond = g_cond_new ();
|
|
|
|
}
|
|
|
|
|
2006-07-06 20:27:32 +08:00
|
|
|
if (G_UNLIKELY (error))
|
2005-02-17 05:24:13 +08:00
|
|
|
{
|
2005-02-21 05:14:06 +08:00
|
|
|
g_warning ("changing the number of threads to %d failed: %s",
|
2005-02-17 05:24:13 +08:00
|
|
|
num_threads, error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2005-02-13 23:47:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pixel_processor_exit (void)
|
|
|
|
{
|
2005-02-17 05:24:13 +08:00
|
|
|
pixel_processor_set_num_threads (1);
|
2005-02-13 23:47:36 +08:00
|
|
|
}
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
void
|
2005-02-13 00:07:00 +08:00
|
|
|
pixel_regions_process_parallel (PixelProcessorFunc func,
|
2006-04-12 20:49:29 +08:00
|
|
|
gpointer data,
|
|
|
|
gint num_regions,
|
|
|
|
...)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
va_list va;
|
2001-01-23 22:21:37 +08:00
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
va_start (va, num_regions);
|
|
|
|
|
2005-02-16 22:54:56 +08:00
|
|
|
pixel_regions_process_parallel_valist (func, data,
|
|
|
|
NULL, NULL,
|
|
|
|
num_regions, va);
|
|
|
|
|
|
|
|
va_end (va);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pixel_regions_process_parallel_progress (PixelProcessorFunc func,
|
|
|
|
gpointer data,
|
|
|
|
PixelProcessorProgressFunc progress_func,
|
|
|
|
gpointer progress_data,
|
|
|
|
gint num_regions,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start (va, num_regions);
|
|
|
|
|
|
|
|
pixel_regions_process_parallel_valist (func, data,
|
|
|
|
progress_func, progress_data,
|
|
|
|
num_regions, va);
|
1999-04-09 14:00:11 +08:00
|
|
|
|
|
|
|
va_end (va);
|
|
|
|
}
|