2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +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
|
1997-11-25 06:05:25 +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/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc
1999-09-01 Tor Lillqvist <tml@iki.fi>
* app/appenv.h
* libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI,
RINT(), ROUND() etc from app/appenv.h here, so plug-ins can
use them, too. Remove some commented-out old stuff in appenv.h.
* libgimp/gimp.h: Include gimpmath.h.
* libgimp/gimp.c (gimp_main): Win32: Don't install signal
handlers, we can't do anything useful in the handler ourselves
anyway (it would be nice to print out a backtrace, but that seems
pretty hard to do, even if not impossible). Let Windows inform the
user about the crash. If the plug-in was compiled with MSVC, and
the user also has it, she is offered a chance to start the
debugger automatically anyway.
* app/*several*.c: Include gimpmath.h for G_PI etc. Don't include
<math.h>, as gimpmath.h includes it.
* plug-ins/*/*many*.c: Include config.h. Don't include <math.h>.
Remove all the duplicated definitions of G_PI and rint(). Use
RINT() instead of rint().
* app/app_procs.[ch]: app_exit() takes a gboolean.
* app/batch.c
* app/commands.c
* app/interface.c: Call app_exit() with FALSE or TRUE.
* app/main.c (on_error): Call gimp_fatal_error. (main): Don't
install any signal handler on Win32 here, either.
* app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format
the message and call MessageBox with it. g_on_error_query doesn't
do anything useful on Win32, and printf'ing a message to stdout or
stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
|
|
|
#include "config.h"
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2014-06-04 07:23:41 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-07-06 03:42:26 +08:00
|
|
|
#include <cairo.h>
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
#include "core-types.h"
|
2002-05-03 20:45:22 +08:00
|
|
|
|
2012-08-25 04:16:02 +08:00
|
|
|
#include "gegl/gimp-babl.h"
|
2012-03-15 04:16:58 +08:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
2015-03-11 15:14:00 +08:00
|
|
|
#include "gegl/gimptilehandlervalidate.h"
|
2012-03-15 04:16:58 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
#include "gimp.h"
|
2014-08-12 19:57:57 +08:00
|
|
|
#include "gimp-memsize.h"
|
2004-07-14 00:36:29 +08:00
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimpmarshal.h"
|
2004-07-14 07:04:05 +08:00
|
|
|
#include "gimppickable.h"
|
2008-11-05 02:06:36 +08:00
|
|
|
#include "gimpprojectable.h"
|
2004-07-14 00:36:29 +08:00
|
|
|
#include "gimpprojection.h"
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2013-08-10 02:20:02 +08:00
|
|
|
#include "gimp-log.h"
|
2014-07-02 10:47:24 +08:00
|
|
|
#include "gimp-priorities.h"
|
2013-08-10 02:20:02 +08:00
|
|
|
|
2001-07-31 19:33:13 +08:00
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
/* chunk size for one iteration of the chunk renderer */
|
2014-06-04 07:23:41 +08:00
|
|
|
static gint GIMP_PROJECTION_CHUNK_WIDTH = 256;
|
|
|
|
static gint GIMP_PROJECTION_CHUNK_HEIGHT = 128;
|
2008-01-23 04:27:13 +08:00
|
|
|
|
2014-06-03 07:30:59 +08:00
|
|
|
/* how much time, in seconds, do we allow chunk rendering to take,
|
|
|
|
* aiming for 15fps
|
|
|
|
*/
|
2014-06-22 22:38:44 +08:00
|
|
|
static gdouble GIMP_PROJECTION_CHUNK_TIME = 0.0666;
|
2013-08-10 02:20:02 +08:00
|
|
|
|
2008-01-23 04:27:13 +08:00
|
|
|
|
2002-05-10 21:09:19 +08:00
|
|
|
enum
|
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
UPDATE,
|
|
|
|
LAST_SIGNAL
|
2002-05-10 21:09:19 +08:00
|
|
|
};
|
|
|
|
|
2013-09-05 16:37:09 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_BUFFER
|
|
|
|
};
|
|
|
|
|
2002-05-10 21:09:19 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
typedef struct _GimpProjectionChunkRender GimpProjectionChunkRender;
|
|
|
|
|
|
|
|
struct _GimpProjectionChunkRender
|
|
|
|
{
|
2014-05-31 07:42:28 +08:00
|
|
|
guint idle_id;
|
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
gint x;
|
|
|
|
gint y;
|
2014-05-31 07:42:28 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
|
|
|
gint work_x;
|
|
|
|
gint work_y;
|
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
cairo_region_t *update_region; /* flushed update region */
|
2014-05-31 06:08:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GimpProjectionPrivate
|
|
|
|
{
|
|
|
|
GimpProjectable *projectable;
|
|
|
|
|
|
|
|
GeglBuffer *buffer;
|
2015-03-11 15:14:00 +08:00
|
|
|
GimpTileHandlerValidate *validate_handler;
|
2014-05-31 06:08:43 +08:00
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
cairo_region_t *update_region;
|
2014-05-31 06:08:43 +08:00
|
|
|
GimpProjectionChunkRender chunk_render;
|
2014-05-31 08:34:56 +08:00
|
|
|
cairo_rectangle_int_t priority_rect;
|
2014-05-31 06:08:43 +08:00
|
|
|
|
|
|
|
gboolean invalidate_preview;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
/* local function prototypes */
|
2001-07-31 19:33:13 +08:00
|
|
|
|
2008-11-04 20:07:17 +08:00
|
|
|
static void gimp_projection_pickable_iface_init (GimpPickableInterface *iface);
|
|
|
|
|
|
|
|
static void gimp_projection_finalize (GObject *object);
|
2013-09-05 16:37:09 +08:00
|
|
|
static void gimp_projection_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_projection_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2008-11-04 20:07:17 +08:00
|
|
|
|
|
|
|
static gint64 gimp_projection_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size);
|
|
|
|
|
|
|
|
static void gimp_projection_pickable_flush (GimpPickable *pickable);
|
|
|
|
static GimpImage * gimp_projection_get_image (GimpPickable *pickable);
|
2012-03-18 23:20:01 +08:00
|
|
|
static const Babl * gimp_projection_get_format (GimpPickable *pickable);
|
2012-06-26 22:09:29 +08:00
|
|
|
static GeglBuffer * gimp_projection_get_buffer (GimpPickable *pickable);
|
2008-11-04 20:07:17 +08:00
|
|
|
static gboolean gimp_projection_get_pixel_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
2012-04-21 16:03:32 +08:00
|
|
|
const Babl *format,
|
|
|
|
gpointer pixel);
|
2012-04-21 22:05:49 +08:00
|
|
|
static gdouble gimp_projection_get_opacity_at (GimpPickable *pickable,
|
2008-11-04 20:07:17 +08:00
|
|
|
gint x,
|
|
|
|
gint y);
|
|
|
|
|
2012-07-06 03:42:26 +08:00
|
|
|
static void gimp_projection_free_buffer (GimpProjection *proj);
|
2008-11-04 20:07:17 +08:00
|
|
|
static void gimp_projection_add_update_area (GimpProjection *proj,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
|
|
|
static void gimp_projection_flush_whenever (GimpProjection *proj,
|
|
|
|
gboolean now);
|
2013-07-28 21:57:28 +08:00
|
|
|
static void gimp_projection_chunk_render_start (GimpProjection *proj);
|
|
|
|
static void gimp_projection_chunk_render_stop (GimpProjection *proj);
|
|
|
|
static gboolean gimp_projection_chunk_render_callback (gpointer data);
|
|
|
|
static void gimp_projection_chunk_render_init (GimpProjection *proj);
|
|
|
|
static gboolean gimp_projection_chunk_render_iteration(GimpProjection *proj);
|
|
|
|
static gboolean gimp_projection_chunk_render_next_area(GimpProjection *proj);
|
2008-11-04 20:07:17 +08:00
|
|
|
static void gimp_projection_paint_area (GimpProjection *proj,
|
|
|
|
gboolean now,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
2008-11-05 02:06:36 +08:00
|
|
|
|
2009-08-26 19:06:55 +08:00
|
|
|
static void gimp_projection_projectable_invalidate(GimpProjectable *projectable,
|
2008-11-04 20:07:17 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
GimpProjection *proj);
|
2008-11-05 02:06:36 +08:00
|
|
|
static void gimp_projection_projectable_flush (GimpProjectable *projectable,
|
2008-11-04 20:07:17 +08:00
|
|
|
gboolean invalidate_preview,
|
|
|
|
GimpProjection *proj);
|
2008-11-05 07:22:45 +08:00
|
|
|
static void gimp_projection_projectable_changed (GimpProjectable *projectable,
|
2008-11-05 02:06:36 +08:00
|
|
|
GimpProjection *proj);
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpProjection, gimp_projection, GIMP_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_PICKABLE,
|
2006-05-15 17:46:31 +08:00
|
|
|
gimp_projection_pickable_iface_init))
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
#define parent_class gimp_projection_parent_class
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static guint projection_signals[LAST_SIGNAL] = { 0 };
|
2001-02-02 02:44:22 +08:00
|
|
|
|
2001-09-26 01:44:03 +08:00
|
|
|
|
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_class_init (GimpProjectionClass *klass)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
2014-06-04 07:23:41 +08:00
|
|
|
const gchar *env;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
projection_signals[UPDATE] =
|
|
|
|
g_signal_new ("update",
|
2006-04-12 20:49:29 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpProjectionClass, update),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__BOOLEAN_INT_INT_INT_INT,
|
|
|
|
G_TYPE_NONE, 5,
|
2004-07-14 00:36:29 +08:00
|
|
|
G_TYPE_BOOLEAN,
|
2006-04-12 20:49:29 +08:00
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT);
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
object_class->finalize = gimp_projection_finalize;
|
2013-09-05 16:37:09 +08:00
|
|
|
object_class->set_property = gimp_projection_set_property;
|
|
|
|
object_class->get_property = gimp_projection_get_property;
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
gimp_object_class->get_memsize = gimp_projection_get_memsize;
|
2013-09-05 16:37:09 +08:00
|
|
|
|
|
|
|
g_object_class_override_property (object_class, PROP_BUFFER, "buffer");
|
2014-05-31 06:08:43 +08:00
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (GimpProjectionPrivate));
|
2014-06-04 07:23:41 +08:00
|
|
|
|
|
|
|
env = g_getenv ("GIMP_DISPLAY_RENDER_BUF_SIZE");
|
|
|
|
if (env)
|
|
|
|
{
|
|
|
|
gint width = atoi (env);
|
|
|
|
gint height = width;
|
|
|
|
|
|
|
|
env = strchr (env, 'x');
|
|
|
|
if (env)
|
2014-06-04 08:06:55 +08:00
|
|
|
height = atoi (env + 1);
|
2014-06-04 07:23:41 +08:00
|
|
|
|
|
|
|
if (width > 0 && width <= 8192 &&
|
|
|
|
height > 0 && height <= 8192)
|
|
|
|
{
|
|
|
|
GIMP_PROJECTION_CHUNK_WIDTH = width;
|
|
|
|
GIMP_PROJECTION_CHUNK_HEIGHT = height;
|
|
|
|
}
|
|
|
|
}
|
2001-09-26 01:44:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_init (GimpProjection *proj)
|
2001-09-26 01:44:03 +08:00
|
|
|
{
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv = G_TYPE_INSTANCE_GET_PRIVATE (proj,
|
|
|
|
GIMP_TYPE_PROJECTION,
|
|
|
|
GimpProjectionPrivate);
|
2001-09-26 01:44:03 +08:00
|
|
|
}
|
|
|
|
|
2004-07-14 07:04:05 +08:00
|
|
|
static void
|
2005-12-11 03:24:36 +08:00
|
|
|
gimp_projection_pickable_iface_init (GimpPickableInterface *iface)
|
2004-07-14 07:04:05 +08:00
|
|
|
{
|
2012-03-18 23:20:01 +08:00
|
|
|
iface->flush = gimp_projection_pickable_flush;
|
|
|
|
iface->get_image = gimp_projection_get_image;
|
|
|
|
iface->get_format = gimp_projection_get_format;
|
|
|
|
iface->get_format_with_alpha = gimp_projection_get_format; /* sic */
|
|
|
|
iface->get_buffer = gimp_projection_get_buffer;
|
|
|
|
iface->get_pixel_at = gimp_projection_get_pixel_at;
|
|
|
|
iface->get_opacity_at = gimp_projection_get_opacity_at;
|
2004-07-14 07:04:05 +08:00
|
|
|
}
|
|
|
|
|
2002-05-10 21:09:19 +08:00
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_finalize (GObject *object)
|
2002-05-10 21:09:19 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *proj = GIMP_PROJECTION (object);
|
2004-07-12 19:43:00 +08:00
|
|
|
|
2012-07-06 03:42:26 +08:00
|
|
|
gimp_projection_free_buffer (proj);
|
2008-11-11 06:15:40 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2002-05-10 21:09:19 +08:00
|
|
|
}
|
|
|
|
|
2013-09-05 16:37:09 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_BUFFER:
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_projection_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpProjection *projection = GIMP_PROJECTION (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_BUFFER:
|
2014-05-31 06:08:43 +08:00
|
|
|
g_value_set_object (value, projection->priv->buffer);
|
2013-09-05 16:37:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
static gint64
|
|
|
|
gimp_projection_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size)
|
2001-09-26 01:44:03 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *projection = GIMP_PROJECTION (object);
|
2007-06-21 00:15:16 +08:00
|
|
|
gint64 memsize = 0;
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2014-06-16 00:21:05 +08:00
|
|
|
memsize += gimp_gegl_pyramid_get_memsize (projection->priv->buffer);
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
gui_size);
|
|
|
|
}
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2007-06-06 18:03:17 +08:00
|
|
|
/**
|
|
|
|
* gimp_projection_estimate_memsize:
|
2014-06-15 05:20:52 +08:00
|
|
|
* @type: the projectable's base type
|
|
|
|
* @component_type: the projectable's component type
|
|
|
|
* @width: projection width
|
|
|
|
* @height: projection height
|
2007-06-06 18:03:17 +08:00
|
|
|
*
|
|
|
|
* Calculates a rough estimate of the memory that is required for the
|
|
|
|
* projection of an image with the given @width and @height.
|
|
|
|
*
|
|
|
|
* Return value: a rough estimate of the memory requirements.
|
|
|
|
**/
|
|
|
|
gint64
|
|
|
|
gimp_projection_estimate_memsize (GimpImageBaseType type,
|
2014-06-15 05:20:52 +08:00
|
|
|
GimpComponentType component_type,
|
2007-06-06 18:03:17 +08:00
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
2012-08-25 04:16:02 +08:00
|
|
|
const Babl *format;
|
|
|
|
gint64 bytes;
|
2007-06-06 18:48:00 +08:00
|
|
|
|
2012-08-25 04:16:02 +08:00
|
|
|
if (type == GIMP_INDEXED)
|
|
|
|
type = GIMP_RGB;
|
|
|
|
|
2014-06-15 05:20:52 +08:00
|
|
|
format = gimp_babl_format (type,
|
|
|
|
gimp_babl_precision (component_type, FALSE),
|
|
|
|
TRUE);
|
2012-08-25 04:16:02 +08:00
|
|
|
bytes = babl_format_get_bytes_per_pixel (format);
|
2007-06-06 18:48:00 +08:00
|
|
|
|
2007-06-21 00:15:16 +08:00
|
|
|
/* The pyramid levels constitute a geometric sum with a ratio of 1/4. */
|
2007-06-06 21:45:44 +08:00
|
|
|
return bytes * (gint64) width * (gint64) height * 1.33;
|
2007-06-06 18:03:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-03 03:30:59 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_pickable_flush (GimpPickable *pickable)
|
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
|
2012-12-19 02:30:33 +08:00
|
|
|
/* create the buffer if it doesn't exist */
|
|
|
|
gimp_projection_get_buffer (pickable);
|
|
|
|
|
2006-03-03 03:30:59 +08:00
|
|
|
gimp_projection_finish_draw (proj);
|
|
|
|
gimp_projection_flush_now (proj);
|
2007-08-02 22:54:29 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
if (proj->priv->invalidate_preview)
|
2007-08-02 22:54:29 +08:00
|
|
|
{
|
|
|
|
/* invalidate the preview here since it is constructed from
|
|
|
|
* the projection
|
|
|
|
*/
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv->invalidate_preview = FALSE;
|
2007-08-02 22:54:29 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
gimp_projectable_invalidate_preview (proj->priv->projectable);
|
2007-08-02 22:54:29 +08:00
|
|
|
}
|
2006-03-03 03:30:59 +08:00
|
|
|
}
|
|
|
|
|
2008-11-04 20:07:17 +08:00
|
|
|
static GimpImage *
|
|
|
|
gimp_projection_get_image (GimpPickable *pickable)
|
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
return gimp_projectable_get_image (proj->priv->projectable);
|
2008-11-04 20:07:17 +08:00
|
|
|
}
|
|
|
|
|
2012-03-17 22:21:11 +08:00
|
|
|
static const Babl *
|
2012-03-18 23:20:01 +08:00
|
|
|
gimp_projection_get_format (GimpPickable *pickable)
|
2012-03-17 22:21:11 +08:00
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
return gimp_projectable_get_format (proj->priv->projectable);
|
2012-03-17 22:21:11 +08:00
|
|
|
}
|
|
|
|
|
2012-03-15 21:38:54 +08:00
|
|
|
static GeglBuffer *
|
|
|
|
gimp_projection_get_buffer (GimpPickable *pickable)
|
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
if (! proj->priv->buffer)
|
2012-03-15 21:38:54 +08:00
|
|
|
{
|
2012-07-06 03:42:26 +08:00
|
|
|
GeglNode *graph;
|
2012-06-21 03:44:09 +08:00
|
|
|
const Babl *format;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
graph = gimp_projectable_get_graph (proj->priv->projectable);
|
2012-06-21 03:44:09 +08:00
|
|
|
format = gimp_projection_get_format (GIMP_PICKABLE (proj));
|
2014-05-31 06:08:43 +08:00
|
|
|
gimp_projectable_get_size (proj->priv->projectable, &width, &height);
|
2012-03-15 21:38:54 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv->buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height),
|
|
|
|
format);
|
2012-03-26 21:27:55 +08:00
|
|
|
|
2015-03-11 15:14:00 +08:00
|
|
|
proj->priv->validate_handler =
|
|
|
|
GIMP_TILE_HANDLER_VALIDATE (gimp_tile_handler_validate_new (graph));
|
2012-12-16 02:33:21 +08:00
|
|
|
|
2015-03-11 15:14:00 +08:00
|
|
|
gimp_tile_handler_validate_assign (proj->priv->validate_handler,
|
|
|
|
proj->priv->buffer);
|
|
|
|
|
|
|
|
/* This used to call gimp_tile_handler_validate_invalidate()
|
2012-12-16 02:33:21 +08:00
|
|
|
* which forced the entire projection to be constructed in one
|
|
|
|
* go for new images, causing a potentially huge delay. Now we
|
|
|
|
* initially validate stuff the normal way, which makes the
|
|
|
|
* image appear incrementally, but it keeps everything
|
|
|
|
* responsive.
|
|
|
|
*/
|
|
|
|
gimp_projection_add_update_area (proj, 0, 0, width, height);
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv->invalidate_preview = TRUE;
|
2012-12-16 02:33:21 +08:00
|
|
|
gimp_projection_flush (proj);
|
2013-09-05 16:37:09 +08:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (pickable), "buffer");
|
2012-03-15 21:38:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
return proj->priv->buffer;
|
2012-03-15 21:38:54 +08:00
|
|
|
}
|
|
|
|
|
2007-04-28 00:07:49 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_projection_get_pixel_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
2012-04-21 16:03:32 +08:00
|
|
|
const Babl *format,
|
|
|
|
gpointer pixel)
|
2007-04-28 00:07:49 +08:00
|
|
|
{
|
2012-03-19 17:46:47 +08:00
|
|
|
GeglBuffer *buffer = gimp_projection_get_buffer (pickable);
|
2007-04-28 00:07:49 +08:00
|
|
|
|
2012-03-19 17:46:47 +08:00
|
|
|
if (x < 0 ||
|
|
|
|
y < 0 ||
|
|
|
|
x >= gegl_buffer_get_width (buffer) ||
|
|
|
|
y >= gegl_buffer_get_height (buffer))
|
2007-04-28 00:07:49 +08:00
|
|
|
return FALSE;
|
|
|
|
|
2012-04-21 16:03:32 +08:00
|
|
|
gegl_buffer_sample (buffer, x, y, NULL, pixel, format,
|
2012-03-26 08:17:24 +08:00
|
|
|
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
|
2007-04-28 00:07:49 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-04-21 22:05:49 +08:00
|
|
|
static gdouble
|
2005-07-12 03:21:52 +08:00
|
|
|
gimp_projection_get_opacity_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
2012-04-21 22:05:49 +08:00
|
|
|
return GIMP_OPACITY_OPAQUE;
|
2005-07-12 03:21:52 +08:00
|
|
|
}
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *
|
2008-11-05 02:06:36 +08:00
|
|
|
gimp_projection_new (GimpProjectable *projectable)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
|
|
|
GimpProjection *proj;
|
|
|
|
|
2008-11-05 02:06:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTABLE (projectable), NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
proj = g_object_new (GIMP_TYPE_PROJECTION, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv->projectable = projectable;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2009-08-26 19:06:55 +08:00
|
|
|
g_signal_connect_object (projectable, "invalidate",
|
|
|
|
G_CALLBACK (gimp_projection_projectable_invalidate),
|
|
|
|
proj, 0);
|
2008-11-05 02:06:36 +08:00
|
|
|
g_signal_connect_object (projectable, "flush",
|
|
|
|
G_CALLBACK (gimp_projection_projectable_flush),
|
2004-07-14 00:36:29 +08:00
|
|
|
proj, 0);
|
2008-11-05 07:22:45 +08:00
|
|
|
g_signal_connect_object (projectable, "structure-changed",
|
|
|
|
G_CALLBACK (gimp_projection_projectable_changed),
|
2004-07-14 00:36:29 +08:00
|
|
|
proj, 0);
|
2001-11-10 00:54:56 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
return proj;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 08:34:56 +08:00
|
|
|
void
|
|
|
|
gimp_projection_set_priority_rect (GimpProjection *proj,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
2014-05-31 21:13:32 +08:00
|
|
|
gint w,
|
|
|
|
gint h)
|
2014-05-31 08:34:56 +08:00
|
|
|
{
|
2014-06-02 03:30:11 +08:00
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
gint off_x, off_y;
|
2014-06-30 05:57:22 +08:00
|
|
|
gint width, height;
|
2014-05-31 08:34:56 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
|
|
|
|
|
|
|
gimp_projectable_get_offset (proj->priv->projectable, &off_x, &off_y);
|
2014-05-31 21:13:32 +08:00
|
|
|
gimp_projectable_get_size (proj->priv->projectable, &width, &height);
|
2014-05-31 08:34:56 +08:00
|
|
|
|
|
|
|
/* subtract the projectable's offsets because the list of update
|
|
|
|
* areas is in tile-pyramid coordinates, but our external API is
|
|
|
|
* always in terms of image coordinates.
|
|
|
|
*/
|
|
|
|
x -= off_x;
|
|
|
|
y -= off_y;
|
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
if (gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
0, 0, width, height,
|
|
|
|
&rect.x, &rect.y, &rect.width, &rect.height))
|
|
|
|
{
|
|
|
|
proj->priv->priority_rect = rect;
|
2014-05-31 08:34:56 +08:00
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
if (proj->priv->chunk_render.idle_id)
|
|
|
|
gimp_projection_chunk_render_init (proj);
|
|
|
|
}
|
2014-05-31 08:34:56 +08:00
|
|
|
}
|
|
|
|
|
2014-06-30 05:57:22 +08:00
|
|
|
void
|
|
|
|
gimp_projection_stop_rendering (GimpProjection *proj)
|
|
|
|
{
|
|
|
|
GimpProjectionChunkRender *chunk_render;
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
|
|
|
|
|
|
|
chunk_render = &proj->priv->chunk_render;
|
|
|
|
|
|
|
|
if (! chunk_render->idle_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (chunk_render->update_region)
|
|
|
|
{
|
|
|
|
if (proj->priv->update_region)
|
|
|
|
{
|
|
|
|
cairo_region_union (proj->priv->update_region,
|
|
|
|
chunk_render->update_region);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
proj->priv->update_region =
|
|
|
|
cairo_region_copy (chunk_render->update_region);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_region_destroy (chunk_render->update_region);
|
|
|
|
chunk_render->update_region = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rect.x = chunk_render->x;
|
|
|
|
rect.y = chunk_render->work_y;
|
|
|
|
rect.width = chunk_render->width;
|
|
|
|
rect.height = chunk_render->height - (chunk_render->work_y - chunk_render->y);
|
|
|
|
|
|
|
|
/* FIXME this is too much, the entire current row */
|
|
|
|
if (proj->priv->update_region)
|
|
|
|
cairo_region_union_rectangle (proj->priv->update_region, &rect);
|
|
|
|
else
|
|
|
|
proj->priv->update_region = cairo_region_create_rectangle (&rect);
|
|
|
|
|
|
|
|
gimp_projection_chunk_render_stop (proj);
|
|
|
|
}
|
|
|
|
|
1998-10-02 00:22:28 +08:00
|
|
|
void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_flush (GimpProjection *proj)
|
1998-10-02 00:22:28 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
/* Construct in chunks */
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_flush_whenever (proj, FALSE);
|
1998-10-02 00:22:28 +08:00
|
|
|
}
|
|
|
|
|
2001-02-20 23:15:30 +08:00
|
|
|
void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_flush_now (GimpProjection *proj)
|
2001-02-20 23:15:30 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
2001-02-20 23:15:30 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* Construct NOW */
|
|
|
|
gimp_projection_flush_whenever (proj, TRUE);
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
2001-02-20 23:15:30 +08:00
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
void
|
|
|
|
gimp_projection_finish_draw (GimpProjection *proj)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
|
|
|
|
2014-05-31 07:42:28 +08:00
|
|
|
if (proj->priv->chunk_render.idle_id)
|
2004-07-14 18:31:59 +08:00
|
|
|
{
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_stop (proj);
|
2004-07-14 18:31:59 +08:00
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
while (gimp_projection_chunk_render_iteration (proj));
|
2004-07-14 18:31:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* private functions */
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2012-07-06 03:42:26 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_free_buffer (GimpProjection *proj)
|
|
|
|
{
|
2014-05-31 21:13:32 +08:00
|
|
|
if (proj->priv->chunk_render.idle_id)
|
|
|
|
gimp_projection_chunk_render_stop (proj);
|
|
|
|
|
|
|
|
if (proj->priv->update_region)
|
|
|
|
{
|
|
|
|
cairo_region_destroy (proj->priv->update_region);
|
|
|
|
proj->priv->update_region = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proj->priv->chunk_render.update_region)
|
|
|
|
{
|
|
|
|
cairo_region_destroy (proj->priv->chunk_render.update_region);
|
|
|
|
proj->priv->chunk_render.update_region = NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
if (proj->priv->buffer)
|
2012-07-06 03:42:26 +08:00
|
|
|
{
|
2014-05-31 06:08:43 +08:00
|
|
|
if (proj->priv->validate_handler)
|
|
|
|
gegl_buffer_remove_handler (proj->priv->buffer,
|
|
|
|
proj->priv->validate_handler);
|
2012-07-06 03:42:26 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
g_object_unref (proj->priv->buffer);
|
|
|
|
proj->priv->buffer = NULL;
|
2012-07-06 03:42:26 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
if (proj->priv->validate_handler)
|
2012-07-06 03:42:26 +08:00
|
|
|
{
|
2014-05-31 06:08:43 +08:00
|
|
|
g_object_unref (proj->priv->validate_handler);
|
|
|
|
proj->priv->validate_handler = NULL;
|
2012-07-06 03:42:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_add_update_area (GimpProjection *proj,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
|
|
|
{
|
2014-05-31 07:22:54 +08:00
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
gint off_x, off_y;
|
|
|
|
gint width, height;
|
2004-07-14 18:31:59 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
gimp_projectable_get_offset (proj->priv->projectable, &off_x, &off_y);
|
|
|
|
gimp_projectable_get_size (proj->priv->projectable, &width, &height);
|
2009-08-24 21:59:14 +08:00
|
|
|
|
|
|
|
/* subtract the projectable's offsets because the list of update
|
|
|
|
* areas is in tile-pyramid coordinates, but our external API is
|
|
|
|
* always in terms of image coordinates.
|
|
|
|
*/
|
|
|
|
x -= off_x;
|
|
|
|
y -= off_y;
|
2004-07-14 18:31:59 +08:00
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
if (gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
0, 0, width, height,
|
|
|
|
&rect.x, &rect.y, &rect.width, &rect.height))
|
|
|
|
{
|
|
|
|
if (proj->priv->update_region)
|
|
|
|
cairo_region_union_rectangle (proj->priv->update_region, &rect);
|
|
|
|
else
|
|
|
|
proj->priv->update_region = cairo_region_create_rectangle (&rect);
|
|
|
|
}
|
2004-07-14 18:31:59 +08:00
|
|
|
}
|
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_flush_whenever (GimpProjection *proj,
|
|
|
|
gboolean now)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2014-05-31 07:22:54 +08:00
|
|
|
if (proj->priv->update_region)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2004-07-12 19:43:00 +08:00
|
|
|
if (now) /* Synchronous */
|
2003-07-30 00:36:56 +08:00
|
|
|
{
|
2014-05-31 07:22:54 +08:00
|
|
|
gint n_rects = cairo_region_num_rectangles (proj->priv->update_region);
|
|
|
|
gint i;
|
2003-07-30 00:36:56 +08:00
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
for (i = 0; i < n_rects; i++)
|
2003-07-30 00:36:56 +08:00
|
|
|
{
|
2014-05-31 07:22:54 +08:00
|
|
|
cairo_rectangle_int_t rect;
|
2003-07-30 00:36:56 +08:00
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
cairo_region_get_rectangle (proj->priv->update_region,
|
|
|
|
i, &rect);
|
|
|
|
|
|
|
|
gimp_projection_paint_area (proj,
|
|
|
|
FALSE, /* sic! */
|
|
|
|
rect.x,
|
|
|
|
rect.y,
|
|
|
|
rect.width,
|
|
|
|
rect.height);
|
2003-07-30 00:36:56 +08:00
|
|
|
}
|
|
|
|
}
|
2004-07-12 19:43:00 +08:00
|
|
|
else /* Asynchronous */
|
2003-07-30 00:36:56 +08:00
|
|
|
{
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_init (proj);
|
2003-07-30 00:36:56 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
/* Free the update region */
|
|
|
|
cairo_region_destroy (proj->priv->update_region);
|
|
|
|
proj->priv->update_region = NULL;
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
2014-05-31 06:08:43 +08:00
|
|
|
else if (! now && proj->priv->invalidate_preview)
|
2007-06-27 05:39:51 +08:00
|
|
|
{
|
|
|
|
/* invalidate the preview here since it is constructed from
|
|
|
|
* the projection
|
|
|
|
*/
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv->invalidate_preview = FALSE;
|
2007-06-27 05:39:51 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
gimp_projectable_invalidate_preview (proj->priv->projectable);
|
2007-06-27 05:39:51 +08:00
|
|
|
}
|
2004-07-14 00:36:29 +08:00
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
static void
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_start (GimpProjection *proj)
|
|
|
|
{
|
2014-05-31 07:42:28 +08:00
|
|
|
g_return_if_fail (proj->priv->chunk_render.idle_id == 0);
|
2013-07-28 21:57:28 +08:00
|
|
|
|
2014-05-31 07:42:28 +08:00
|
|
|
proj->priv->chunk_render.idle_id =
|
2014-07-02 10:47:24 +08:00
|
|
|
g_idle_add_full (GIMP_PRIORITY_PROJECTION_IDLE,
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_callback, proj,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_projection_chunk_render_stop (GimpProjection *proj)
|
|
|
|
{
|
2014-05-31 07:42:28 +08:00
|
|
|
g_return_if_fail (proj->priv->chunk_render.idle_id != 0);
|
2013-07-28 21:57:28 +08:00
|
|
|
|
2014-05-31 07:42:28 +08:00
|
|
|
g_source_remove (proj->priv->chunk_render.idle_id);
|
|
|
|
proj->priv->chunk_render.idle_id = 0;
|
2013-07-28 21:57:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_projection_chunk_render_callback (gpointer data)
|
|
|
|
{
|
2013-08-10 02:20:02 +08:00
|
|
|
GimpProjection *proj = data;
|
|
|
|
GTimer *timer = g_timer_new ();
|
|
|
|
gint chunks = 0;
|
|
|
|
gboolean retval = TRUE;
|
2013-07-28 21:57:28 +08:00
|
|
|
|
2013-08-10 02:20:02 +08:00
|
|
|
do
|
2013-07-28 21:57:28 +08:00
|
|
|
{
|
2013-08-10 02:20:02 +08:00
|
|
|
if (! gimp_projection_chunk_render_iteration (proj))
|
|
|
|
{
|
|
|
|
gimp_projection_chunk_render_stop (proj);
|
|
|
|
|
|
|
|
retval = FALSE;
|
2013-07-28 21:57:28 +08:00
|
|
|
|
2013-08-10 02:20:02 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
chunks++;
|
2013-07-28 21:57:28 +08:00
|
|
|
}
|
2013-08-10 02:20:02 +08:00
|
|
|
while (g_timer_elapsed (timer, NULL) < GIMP_PROJECTION_CHUNK_TIME);
|
2013-07-28 21:57:28 +08:00
|
|
|
|
2013-08-10 02:20:02 +08:00
|
|
|
GIMP_LOG (PROJECTION, "%d chunks in %f seconds\n",
|
|
|
|
chunks, g_timer_elapsed (timer, NULL));
|
|
|
|
g_timer_destroy (timer);
|
|
|
|
|
|
|
|
return retval;
|
2013-07-28 21:57:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_projection_chunk_render_init (GimpProjection *proj)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
GimpProjectionChunkRender *chunk_render = &proj->priv->chunk_render;
|
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
/* We need to merge the ChunkRender's and the GimpProjection's
|
2014-05-31 07:22:54 +08:00
|
|
|
* update_regions list to keep track of which of the updates have
|
|
|
|
* been flushed and hence need to be drawn.
|
2001-11-11 07:03:22 +08:00
|
|
|
*/
|
2014-05-31 07:22:54 +08:00
|
|
|
if (proj->priv->update_region)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
if (chunk_render->update_region)
|
2014-05-31 07:22:54 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
cairo_region_union (chunk_render->update_region,
|
2014-05-31 07:22:54 +08:00
|
|
|
proj->priv->update_region);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
chunk_render->update_region =
|
2014-05-31 07:22:54 +08:00
|
|
|
cairo_region_copy (proj->priv->update_region);
|
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
/* If a chunk renderer was already running, merge the remainder of
|
|
|
|
* its unrendered area with the update_areas list, and make it start
|
|
|
|
* work on the next unrendered area in the list.
|
2001-11-11 07:03:22 +08:00
|
|
|
*/
|
2014-05-31 08:58:21 +08:00
|
|
|
if (chunk_render->idle_id)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2014-05-31 07:22:54 +08:00
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
rect.x = chunk_render->x;
|
|
|
|
rect.y = chunk_render->work_y;
|
|
|
|
rect.width = chunk_render->width;
|
|
|
|
rect.height = (chunk_render->height -
|
|
|
|
(chunk_render->work_y - chunk_render->y));
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
if (chunk_render->update_region)
|
|
|
|
cairo_region_union_rectangle (chunk_render->update_region, &rect);
|
2014-05-31 08:34:56 +08:00
|
|
|
else
|
2014-05-31 08:58:21 +08:00
|
|
|
chunk_render->update_region = cairo_region_create_rectangle (&rect);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_next_area (proj);
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
if (chunk_render->update_region == NULL)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
2014-05-31 07:22:54 +08:00
|
|
|
g_warning ("%s: wanted to start chunk render with no update_region",
|
2004-07-14 18:31:59 +08:00
|
|
|
G_STRFUNC);
|
2004-07-14 00:36:29 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_next_area (proj);
|
2004-07-14 00:36:29 +08:00
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_start (proj);
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* Unless specified otherwise, projection re-rendering is organised by
|
2013-07-28 21:57:28 +08:00
|
|
|
* ChunkRender, which amalgamates areas to be re-rendered and breaks
|
|
|
|
* them into bite-sized chunks which are chewed on in an idle
|
|
|
|
* function. This greatly improves responsiveness for many GIMP
|
2001-11-11 07:03:22 +08:00
|
|
|
* operations. -- Adam
|
|
|
|
*/
|
|
|
|
static gboolean
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_iteration (GimpProjection *proj)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
GimpProjectionChunkRender *chunk_render = &proj->priv->chunk_render;
|
|
|
|
gint work_x = chunk_render->work_x;
|
|
|
|
gint work_y = chunk_render->work_y;
|
|
|
|
gint work_w;
|
|
|
|
gint work_h;
|
2004-07-14 18:31:59 +08:00
|
|
|
|
2014-05-31 07:42:28 +08:00
|
|
|
work_w = MIN (GIMP_PROJECTION_CHUNK_WIDTH,
|
2014-05-31 08:58:21 +08:00
|
|
|
chunk_render->x + chunk_render->width - work_x);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 07:42:28 +08:00
|
|
|
work_h = MIN (GIMP_PROJECTION_CHUNK_HEIGHT,
|
2014-05-31 08:58:21 +08:00
|
|
|
chunk_render->y + chunk_render->height - work_y);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
gimp_projection_paint_area (proj, TRUE /* sic! */,
|
2014-05-31 07:42:28 +08:00
|
|
|
work_x, work_y, work_w, work_h);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-07-01 05:12:53 +08:00
|
|
|
chunk_render->work_x += work_w;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
if (chunk_render->work_x >= chunk_render->x + chunk_render->width)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
chunk_render->work_x = chunk_render->x;
|
2014-05-31 07:42:28 +08:00
|
|
|
|
2014-07-01 05:12:53 +08:00
|
|
|
chunk_render->work_y += work_h;
|
2004-07-14 00:36:29 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
if (chunk_render->work_y >= chunk_render->y + chunk_render->height)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
2013-07-28 21:57:28 +08:00
|
|
|
if (! gimp_projection_chunk_render_next_area (proj))
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
2014-05-31 06:08:43 +08:00
|
|
|
if (proj->priv->invalidate_preview)
|
2007-06-27 05:39:51 +08:00
|
|
|
{
|
|
|
|
/* invalidate the preview here since it is constructed from
|
|
|
|
* the projection
|
|
|
|
*/
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv->invalidate_preview = FALSE;
|
2007-06-27 05:39:51 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
gimp_projectable_invalidate_preview (proj->priv->projectable);
|
2007-06-27 05:39:51 +08:00
|
|
|
}
|
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
/* FINISHED */
|
2004-07-14 00:36:29 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Still work to do. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_next_area (GimpProjection *proj)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
GimpProjectionChunkRender *chunk_render = &proj->priv->chunk_render;
|
|
|
|
cairo_region_t *next_region;
|
|
|
|
cairo_rectangle_int_t rect;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
if (! chunk_render->update_region)
|
2001-11-16 23:08:59 +08:00
|
|
|
return FALSE;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
if (cairo_region_is_empty (chunk_render->update_region))
|
2014-05-31 07:22:54 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
cairo_region_destroy (chunk_render->update_region);
|
|
|
|
chunk_render->update_region = NULL;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
next_region = cairo_region_copy (chunk_render->update_region);
|
2014-05-31 08:34:56 +08:00
|
|
|
cairo_region_intersect_rectangle (next_region, &proj->priv->priority_rect);
|
|
|
|
|
|
|
|
if (cairo_region_is_empty (next_region))
|
2014-05-31 08:58:21 +08:00
|
|
|
cairo_region_get_rectangle (chunk_render->update_region, 0, &rect);
|
2014-05-31 08:34:56 +08:00
|
|
|
else
|
2014-05-31 08:58:21 +08:00
|
|
|
cairo_region_get_rectangle (next_region, 0, &rect);
|
2014-05-31 08:34:56 +08:00
|
|
|
|
|
|
|
cairo_region_destroy (next_region);
|
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
cairo_region_subtract_rectangle (chunk_render->update_region, &rect);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
if (cairo_region_is_empty (chunk_render->update_region))
|
2014-05-31 07:22:54 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
cairo_region_destroy (chunk_render->update_region);
|
|
|
|
chunk_render->update_region = NULL;
|
2014-05-31 07:22:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
chunk_render->x = rect.x;
|
|
|
|
chunk_render->y = rect.y;
|
|
|
|
chunk_render->width = rect.width;
|
|
|
|
chunk_render->height = rect.height;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
chunk_render->work_x = chunk_render->x;
|
|
|
|
chunk_render->work_y = chunk_render->y;
|
2014-05-31 07:42:28 +08:00
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_paint_area (GimpProjection *proj,
|
|
|
|
gboolean now,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2009-08-24 21:59:14 +08:00
|
|
|
gint off_x, off_y;
|
2008-11-05 02:06:36 +08:00
|
|
|
gint width, height;
|
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
gimp_projectable_get_offset (proj->priv->projectable, &off_x, &off_y);
|
|
|
|
gimp_projectable_get_size (proj->priv->projectable, &width, &height);
|
2008-08-13 00:30:44 +08:00
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
if (gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
0, 0, width, height,
|
|
|
|
&x, &y, &w, &h))
|
2013-08-03 02:43:44 +08:00
|
|
|
{
|
2014-05-31 06:08:43 +08:00
|
|
|
if (proj->priv->validate_handler)
|
2015-03-11 15:14:00 +08:00
|
|
|
gimp_tile_handler_validate_invalidate (proj->priv->validate_handler,
|
|
|
|
x, y, w, h);
|
2014-06-02 03:30:11 +08:00
|
|
|
if (now)
|
|
|
|
{
|
|
|
|
GeglNode *graph = gimp_projectable_get_graph (proj->priv->projectable);
|
2013-08-11 14:49:38 +08:00
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
if (proj->priv->validate_handler)
|
2015-03-11 15:14:00 +08:00
|
|
|
gimp_tile_handler_validate_undo_invalidate (proj->priv->validate_handler,
|
|
|
|
x, y, w, h);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
gegl_node_blit_buffer (graph, proj->priv->buffer,
|
|
|
|
GEGL_RECTANGLE (x, y, w, h));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add the projectable's offsets because the list of update areas
|
|
|
|
* is in tile-pyramid coordinates, but our external API is always
|
|
|
|
* in terms of image coordinates.
|
|
|
|
*/
|
|
|
|
g_signal_emit (proj, projection_signals[UPDATE], 0,
|
|
|
|
now,
|
|
|
|
x + off_x,
|
|
|
|
y + off_y,
|
|
|
|
w,
|
|
|
|
h);
|
|
|
|
}
|
2004-07-14 00:36:29 +08:00
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2012-06-21 03:44:09 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* image callbacks */
|
|
|
|
|
|
|
|
static void
|
2009-08-26 19:06:55 +08:00
|
|
|
gimp_projection_projectable_invalidate (GimpProjectable *projectable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
GimpProjection *proj)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
|
|
|
gimp_projection_add_update_area (proj, x, y, w, h);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
static void
|
2008-11-05 02:06:36 +08:00
|
|
|
gimp_projection_projectable_flush (GimpProjectable *projectable,
|
|
|
|
gboolean invalidate_preview,
|
|
|
|
GimpProjection *proj)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
2008-11-05 02:06:36 +08:00
|
|
|
if (invalidate_preview)
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv->invalidate_preview = TRUE;
|
2007-06-21 00:15:16 +08:00
|
|
|
|
2008-11-05 02:06:36 +08:00
|
|
|
gimp_projection_flush (proj);
|
2004-07-14 00:36:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-11-05 07:22:45 +08:00
|
|
|
gimp_projection_projectable_changed (GimpProjectable *projectable,
|
|
|
|
GimpProjection *proj)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
2009-09-03 03:55:14 +08:00
|
|
|
gint off_x, off_y;
|
2008-11-05 02:06:36 +08:00
|
|
|
gint width, height;
|
|
|
|
|
2012-07-06 03:42:26 +08:00
|
|
|
gimp_projection_free_buffer (proj);
|
2012-03-15 21:38:54 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
gimp_projectable_get_offset (proj->priv->projectable, &off_x, &off_y);
|
2014-05-31 21:13:32 +08:00
|
|
|
gimp_projectable_get_size (projectable, &width, &height);
|
2007-06-27 05:39:51 +08:00
|
|
|
|
2009-09-03 03:55:14 +08:00
|
|
|
gimp_projection_add_update_area (proj, off_x, off_y, width, height);
|
2014-05-31 08:34:56 +08:00
|
|
|
|
|
|
|
proj->priv->priority_rect.x = 0;
|
|
|
|
proj->priv->priority_rect.y = 0;
|
|
|
|
proj->priv->priority_rect.width = width;
|
|
|
|
proj->priv->priority_rect.height = height;
|
2004-07-14 00:36:29 +08:00
|
|
|
}
|