[gegl] gegl: Add gegl_tile_set_unlock_notify()
- From: Martin Nordholts <martinn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] gegl: Add gegl_tile_set_unlock_notify()
- Date: Wed, 12 Oct 2011 18:36:20 +0000 (UTC)
commit dd956488e51387d459754faa35bd198fc3b97a0f
Author: Martin Nordholts <martinn src gnome org>
Date: Tue Oct 11 08:06:44 2011 +0200
gegl: Add gegl_tile_set_unlock_notify()
So that custom tile backends can run code when GeglTile data has
changed. Also add an API test case.
gegl/buffer/gegl-buffer-backend.h | 5 +++
gegl/buffer/gegl-buffer-private.h | 6 +++
gegl/buffer/gegl-tile.c | 14 +++++++
gegl/buffer/gegl-tile.h | 5 +++
tests/simple/.gitignore | 1 +
tests/simple/Makefile.am | 1 +
tests/simple/test-gegl-tile.c | 69 +++++++++++++++++++++++++++++++++++++
7 files changed, 101 insertions(+), 0 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-backend.h b/gegl/buffer/gegl-buffer-backend.h
index 40342ac..4d8320e 100644
--- a/gegl/buffer/gegl-buffer-backend.h
+++ b/gegl/buffer/gegl-buffer-backend.h
@@ -29,6 +29,11 @@ typedef struct _GeglTileBackendPrivate GeglTileBackendPrivate;
typedef struct _GeglTile GeglTile;
+
+typedef void (*GeglTileCallback) (GeglTile *tile,
+ gpointer user_data);
+
+
#include "gegl-types.h"
#include "gegl-tile-backend.h"
#include "gegl-tile-source.h"
diff --git a/gegl/buffer/gegl-buffer-private.h b/gegl/buffer/gegl-buffer-private.h
index f3c55fa..4acd333 100644
--- a/gegl/buffer/gegl-buffer-private.h
+++ b/gegl/buffer/gegl-buffer-private.h
@@ -166,6 +166,12 @@ struct _GeglTile
/* called when the tile is about to be destroyed */
GeglDestroyNotify destroy_notify;
gpointer destroy_notify_data;
+
+ /* called when the tile has been unlocked which typically means tile
+ * data has changed
+ */
+ GeglTileCallback unlock_notify;
+ gpointer unlock_notify_data;
};
#ifndef __GEGL_TILE_C
diff --git a/gegl/buffer/gegl-tile.c b/gegl/buffer/gegl-tile.c
index b85e8cf..308dbe9 100644
--- a/gegl/buffer/gegl-tile.c
+++ b/gegl/buffer/gegl-tile.c
@@ -231,6 +231,12 @@ gegl_tile_unlock (GeglTile *tile)
#if 0
total_unlocks++;
#endif
+
+ if (tile->unlock_notify != NULL)
+ {
+ tile->unlock_notify (tile, tile->unlock_notify_data);
+ }
+
if (tile->lock == 0)
{
g_warning ("unlocked a tile with lock count == 0");
@@ -319,3 +325,11 @@ guint gegl_tile_get_rev (GeglTile *tile)
{
return tile->rev;
}
+
+void gegl_tile_set_unlock_notify (GeglTile *tile,
+ GeglTileCallback unlock_notify,
+ gpointer unlock_notify_data)
+{
+ tile->unlock_notify = unlock_notify;
+ tile->unlock_notify_data = unlock_notify_data;
+}
diff --git a/gegl/buffer/gegl-tile.h b/gegl/buffer/gegl-tile.h
index 5af5e33..8732c63 100644
--- a/gegl/buffer/gegl-tile.h
+++ b/gegl/buffer/gegl-tile.h
@@ -58,5 +58,10 @@ void gegl_tile_set_data_full (GeglTile *tile,
GeglDestroyNotify destroy_notify,
gpointer destroy_notify_data);
+void gegl_tile_set_unlock_notify
+ (GeglTile *tile,
+ GeglTileCallback unlock_notify,
+ gpointer unlock_notify_data);
+
#endif
diff --git a/tests/simple/.gitignore b/tests/simple/.gitignore
index 724711a..3bca66b 100644
--- a/tests/simple/.gitignore
+++ b/tests/simple/.gitignore
@@ -8,6 +8,7 @@
/test-color-op*
/test-exp-combine.sh
/test-gegl-rectangle*
+/test-gegl-tile*
/test-misc*
/test-path*
/test-proxynop-processing*
diff --git a/tests/simple/Makefile.am b/tests/simple/Makefile.am
index eee5747..ecc5edb 100644
--- a/tests/simple/Makefile.am
+++ b/tests/simple/Makefile.am
@@ -7,6 +7,7 @@ TESTS_ENVIRONMENT = \
# The tests
noinst_PROGRAMS = \
test-change-processor-rect \
+ test-gegl-tile \
test-color-op \
test-gegl-rectangle \
test-misc \
diff --git a/tests/simple/test-gegl-tile.c b/tests/simple/test-gegl-tile.c
new file mode 100644
index 0000000..4c02aa8
--- /dev/null
+++ b/tests/simple/test-gegl-tile.c
@@ -0,0 +1,69 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (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
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2011 Martin Nordholts <martinn src gnome org>
+ */
+
+
+#include <gegl.h>
+#include <gegl-buffer-backend.h>
+
+
+#define ADD_TEST(function) g_test_add_func ("/gegl-tile/" #function, function);
+
+
+static void
+unlock_callback (GeglTile *tile,
+ gpointer user_data)
+{
+ gboolean *callback_called = user_data;
+ *callback_called = TRUE;
+}
+
+/**
+ * gegl_tile_set_unlock_notify_works:
+ * @fixture:
+ * @data:
+ *
+ * Tests that gegl_tile_set_unlock_notify_works() can be used to set a
+ * callback that is called in gegl_tile_unlock().
+ **/
+static void
+gegl_tile_set_unlock_notify_works (void)
+{
+ GeglTile *tile = gegl_tile_new (1);
+ gboolean callback_called = FALSE;
+
+ gegl_tile_set_unlock_notify (tile, unlock_callback, &callback_called);
+ g_assert (! callback_called);
+
+ gegl_tile_lock (tile);
+ g_assert (! callback_called);
+
+ gegl_tile_unlock(tile);
+ g_assert (callback_called);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ g_type_init ();
+ gegl_init (&argc, &argv);
+ g_test_init (&argc, &argv, NULL);
+
+ ADD_TEST (gegl_tile_set_unlock_notify_works);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]