app: Make drawable updates happen at fixed framerate

This commit is contained in:
Alexia Death 2010-04-18 15:52:17 +03:00
parent 547c92d0f6
commit 32aca3c8b6
2 changed files with 62 additions and 2 deletions

View File

@ -18,6 +18,7 @@
#include "config.h" #include "config.h"
#include <gegl.h> #include <gegl.h>
#include <gegl-plugin.h> #include <gegl-plugin.h>
#include "libgimpbase/gimpbase.h" #include "libgimpbase/gimpbase.h"
@ -125,6 +126,8 @@ static void gimp_drawable_real_update (GimpDrawable *drawable,
gint width, gint width,
gint height); gint height);
static gboolean gimp_drawable_update_timeout (GimpDrawable *drawable);
static gint64 gimp_drawable_real_estimate_memsize (const GimpDrawable *drawable, static gint64 gimp_drawable_real_estimate_memsize (const GimpDrawable *drawable,
gint width, gint width,
gint height); gint height);
@ -256,6 +259,14 @@ gimp_drawable_init (GimpDrawable *drawable)
drawable->bytes = 0; drawable->bytes = 0;
drawable->type = -1; drawable->type = -1;
drawable->has_alpha = FALSE; drawable->has_alpha = FALSE;
drawable->dirty_x1 = 0;
drawable->dirty_y1 = 0;
drawable->dirty_x2 = 0;
drawable->dirty_y2 = 0;
drawable->update_count = 0;
drawable->update_timeout = 0;
} }
/* sorry for the evil casts */ /* sorry for the evil casts */
@ -1197,8 +1208,36 @@ gimp_drawable_update (GimpDrawable *drawable,
{ {
g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_signal_emit (drawable, gimp_drawable_signals[UPDATE], 0, if (drawable->update_timeout > 0)
x, y, width, height); {
drawable->dirty_x1 = MIN (x, drawable->dirty_x1);
drawable->dirty_y1 = MIN (y, drawable->dirty_y1);
drawable->dirty_x2 = MAX (x + width, drawable->dirty_x2);
drawable->dirty_y2 = MAX (y + height, drawable->dirty_y2);
drawable->update_count = drawable->update_count + 1;
}
else
{
g_signal_emit (drawable, gimp_drawable_signals[UPDATE], 0,
x, y, width, height);
drawable->dirty_x1 = drawable->dirty_x2;
drawable->dirty_y1 = drawable->dirty_y2;
drawable->dirty_x2 = 0;
drawable->dirty_y2 = 0;
drawable->update_count = 0;
drawable->update_timeout =
g_timeout_add_full (G_PRIORITY_HIGH,
40,
(GSourceFunc) gimp_drawable_update_timeout,
drawable, NULL);
}
} }
void void
@ -1996,3 +2035,15 @@ gimp_drawable_detach_floating_sel (GimpDrawable *drawable,
gimp_image_set_floating_selection (image, NULL); gimp_image_set_floating_selection (image, NULL);
} }
static gboolean
gimp_drawable_update_timeout (GimpDrawable *drawable)
{
drawable->update_timeout = 0;
if (drawable->update_count > 0)
gimp_drawable_update(drawable,
drawable->dirty_x1, drawable->dirty_y1,
drawable->dirty_x2 - drawable->dirty_x1, drawable->dirty_y2 - drawable->dirty_y1);
return FALSE;
}

View File

@ -41,6 +41,15 @@ struct _GimpDrawable
GimpImageType type; /* type of drawable */ GimpImageType type; /* type of drawable */
gboolean has_alpha; /* drawable has alpha */ gboolean has_alpha; /* drawable has alpha */
gint dirty_x1;
gint dirty_y1;
gint dirty_x2;
gint dirty_y2;
guint update_timeout; /* update delay timeout ID */
guint update_count;
GimpDrawablePrivate *private; GimpDrawablePrivate *private;
}; };