From 39db46123ed6bbbc3e6ad359a64d4d344ca9e11b Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Wed, 28 Sep 2011 14:24:57 +0200 Subject: [PATCH 01/11] Add paint-deform-tiles option to CLUTTER_DEBUG To make easier to visualize the triangles in a ClutterDeformEffect https://bugzilla.gnome.org/show_bug.cgi?id=660354 --- clutter/clutter-debug.h | 3 ++- clutter/clutter-deform-effect.c | 20 ++++++++++++++++++++ clutter/clutter-main.c | 3 ++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/clutter/clutter-debug.h b/clutter/clutter-debug.h index f4a9bf872..be551e155 100644 --- a/clutter/clutter-debug.h +++ b/clutter/clutter-debug.h @@ -27,7 +27,8 @@ typedef enum { CLUTTER_DEBUG_PICK = 1 << 16, CLUTTER_DEBUG_EVENTLOOP = 1 << 17, CLUTTER_DEBUG_CLIPPING = 1 << 18, - CLUTTER_DEBUG_OOB_TRANSFORMS = 1 << 19 + CLUTTER_DEBUG_OOB_TRANSFORMS = 1 << 19, + CLUTTER_DEBUG_PAINT_DEFORM_TILES = 1 << 20, } ClutterDebugFlag; typedef enum { diff --git a/clutter/clutter-deform-effect.c b/clutter/clutter-deform-effect.c index 2454f233e..8037a1d99 100644 --- a/clutter/clutter-deform-effect.c +++ b/clutter/clutter-deform-effect.c @@ -290,6 +290,26 @@ clutter_deform_effect_paint_target (ClutterOffscreenEffect *effect) cogl_set_backface_culling_enabled (FALSE); else if (priv->back_material == COGL_INVALID_HANDLE && is_cull_enabled) cogl_set_backface_culling_enabled (TRUE); + + if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_PAINT_DEFORM_TILES)) + { + cogl_set_source_color4f (1.0, 0, 0, 1.0); + cogl_vertex_buffer_draw_elements (priv->vbo, + COGL_VERTICES_MODE_LINE_STRIP, + priv->indices, + 0, + n_tiles, + 0, + priv->n_indices); + + cogl_vertex_buffer_draw_elements (priv->vbo, + COGL_VERTICES_MODE_LINE_STRIP, + priv->back_indices, + 0, + n_tiles, + 0, + priv->n_indices); + } } static inline void diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c index 70fd22ab9..a589b12e0 100644 --- a/clutter/clutter-main.c +++ b/clutter/clutter-main.c @@ -168,7 +168,8 @@ static const GDebugKey clutter_debug_keys[] = { { "animation", CLUTTER_DEBUG_ANIMATION }, { "layout", CLUTTER_DEBUG_LAYOUT }, { "clipping", CLUTTER_DEBUG_CLIPPING }, - { "oob-transforms", CLUTTER_DEBUG_OOB_TRANSFORMS } + { "oob-transforms", CLUTTER_DEBUG_OOB_TRANSFORMS }, + { "paint-deform-tiles", CLUTTER_DEBUG_PAINT_DEFORM_TILES }, }; #endif /* CLUTTER_ENABLE_DEBUG */ From 1465aa04aa4a8da7ced0eeadb183083a8972a6bf Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 27 Sep 2011 14:21:41 +0100 Subject: [PATCH 02/11] Depend on GLib 2.31 We need to switch away from GStaticMutex and use GMutex instead, as the former has been deprecated. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index a7a21bd7f..279b621a8 100644 --- a/configure.ac +++ b/configure.ac @@ -113,7 +113,7 @@ LT_INIT([disable-static]) AC_HEADER_STDC # required versions for dependencies -m4_define([glib_req_version], [2.28.0]) +m4_define([glib_req_version], [2.31.0]) m4_define([cogl_req_version], [1.8.0]) m4_define([json_glib_req_version], [0.12.0]) m4_define([atk_req_version], [2.1.5]) From 11c585c420da633964beb93e80c0dc12d2901a61 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 27 Sep 2011 14:22:22 +0100 Subject: [PATCH 03/11] texture: Remove GStaticMutex It's now possible to statically initialize a GMutex. --- clutter/clutter-texture.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clutter/clutter-texture.c b/clutter/clutter-texture.c index ff602f711..d5c9654a7 100644 --- a/clutter/clutter-texture.c +++ b/clutter/clutter-texture.c @@ -166,7 +166,7 @@ static int texture_signals[LAST_SIGNAL] = { 0 }; static GThreadPool *async_thread_pool = NULL; static guint repaint_upload_func = 0; static GList *upload_list = NULL; -static GStaticMutex upload_list_mutex = G_STATIC_MUTEX_INIT; +static GMutex upload_list_mutex = G_MUTEX_INIT; static CoglMaterial *texture_template_material = NULL; @@ -1795,7 +1795,7 @@ texture_repaint_upload_func (gpointer user_data) { gulong start_time; - g_static_mutex_lock (&upload_list_mutex); + g_mutex_lock (&upload_list_mutex); if (upload_list) { @@ -1823,7 +1823,7 @@ texture_repaint_upload_func (gpointer user_data) _clutter_master_clock_ensure_next_iteration (master_clock); } - g_static_mutex_unlock (&upload_list_mutex); + g_mutex_unlock (&upload_list_mutex); return TRUE; } @@ -1870,7 +1870,7 @@ clutter_texture_thread_func (gpointer user_data, gpointer pool_data) * set it while we're holding the mutex so we can safely start the * idle handler now without the possibility of calling the * callback after it is aborted */ - g_static_mutex_lock (&upload_list_mutex); + g_mutex_lock (&upload_list_mutex); if (repaint_upload_func == 0) { @@ -1882,7 +1882,7 @@ clutter_texture_thread_func (gpointer user_data, gpointer pool_data) upload_list = g_list_append (upload_list, data); data->upload_queued = TRUE; - g_static_mutex_unlock (&upload_list_mutex); + g_mutex_unlock (&upload_list_mutex); g_mutex_unlock (data->mutex); From 56c7d9b0b3211af53952e97b059f8cc0f87d1de8 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 27 Sep 2011 16:06:43 +0100 Subject: [PATCH 04/11] texture: Simplify asynchronous loading code The asynchronous loading code could do with some modernization. First of all, we should drop the internal GMutex held when manipulating the boolean flags: it's far too expensive for its role, and modern GLib provides us with bitlocks that are quite a lot faster. Then we should consolidate most of the implementation into something smaller and more manageable. --- clutter/clutter-texture.c | 268 ++++++++++++++++---------------------- 1 file changed, 114 insertions(+), 154 deletions(-) diff --git a/clutter/clutter-texture.c b/clutter/clutter-texture.c index d5c9654a7..2c3c4e769 100644 --- a/clutter/clutter-texture.c +++ b/clutter/clutter-texture.c @@ -99,36 +99,37 @@ struct _ClutterTexturePrivate guint seen_create_pick_material_warning : 1; }; +#define ASYNC_STATE_LOCKED 1 +#define ASYNC_STATE_CANCELLED 2 +#define ASYNC_STATE_QUEUED 3 + struct _ClutterTextureAsyncData { - /* Mutex used to synchronize setting the abort flag */ - GMutex *mutex; - - /* If set to true, the loaded data will be discarded */ - gboolean abort; - /* The texture for which the data is being loaded */ ClutterTexture *texture; - /* Source ID of the idle handler for loading. If this is zero then - the data is being loaded in a thread from the thread pool. Once - the thread is finished it will be converted to idle load handler - and load_idle will be nonzero. If load_idle is nonzero, and - upload_queued is FALSE then the rest of the load can safely be - aborted by just removing the source, otherwise the abort flag - needs to be set and the data should be disowned */ - guint load_idle; + gchar *load_filename; + CoglHandle load_bitmap; - /* Set when the texture is queued for GPU upload, used to determine - * what to do with the texture data when load_idle is zero. - */ - gboolean upload_queued; + guint load_idle; - gchar *load_filename; - CoglHandle load_bitmap; - GError *load_error; + GError *load_error; + + gint state; }; +static inline void +clutter_texture_async_data_lock (ClutterTextureAsyncData *data) +{ + g_bit_lock (&data->state, 0); +} + +static inline void +clutter_texture_async_data_unlock (ClutterTextureAsyncData *data) +{ + g_bit_unlock (&data->state, 0); +} + enum { PROP_0, @@ -711,19 +712,14 @@ clutter_texture_async_data_free (ClutterTextureAsyncData *data) once it is known that the load thread has completed or from the load thread/upload function itself if the abort flag is true (in which case the main thread has disowned the data) */ + g_free (data->load_filename); - if (data->load_filename) - g_free (data->load_filename); - - if (data->load_bitmap) + if (data->load_bitmap != NULL) cogl_handle_unref (data->load_bitmap); - if (data->load_error) + if (data->load_error != NULL) g_error_free (data->load_error); - if (data->mutex) - g_mutex_free (data->mutex); - g_slice_free (ClutterTextureAsyncData, data); } @@ -739,40 +735,30 @@ clutter_texture_async_load_cancel (ClutterTexture *texture) { ClutterTexturePrivate *priv = texture->priv; - if (priv->async_data) + if (priv->async_data != NULL) { - GMutex *mutex = priv->async_data->mutex; + ClutterTextureAsyncData *async_data = priv->async_data; - /* The mutex will only be NULL if the no thread was used for - this load, in which case there's no need for any - synchronization */ - if (mutex) - g_mutex_lock (mutex); + priv->async_data = NULL; - /* If there is no thread behind this load then we can just abort - the idle handler and destroy the load data immediately */ - if (priv->async_data->load_idle) + if (async_data->load_idle != 0) { - g_source_remove (priv->async_data->load_idle); - priv->async_data->load_idle = 0; + g_source_remove (async_data->load_idle); + async_data->load_idle = 0; - if (mutex) - g_mutex_unlock (mutex); - - clutter_texture_async_data_free (priv->async_data); + clutter_texture_async_data_free (async_data); } else { - /* Otherwise we need to tell the thread to abort and disown - the data, if the data has been loaded and decoded the data - is now waiting for a master clock iteration to be repainted */ - priv->async_data->abort = TRUE; + clutter_texture_async_data_lock (async_data); - if (mutex) - g_mutex_unlock (mutex); + CLUTTER_NOTE (TEXTURE, "[async] cancelling operation for '%s'", + async_data->load_filename); + + async_data->state |= ASYNC_STATE_CANCELLED; + + clutter_texture_async_data_unlock (async_data); } - - priv->async_data = NULL; } } @@ -1736,8 +1722,8 @@ clutter_texture_async_load_complete (ClutterTexture *self, const GError *error) { ClutterTexturePrivate *priv = self->priv; - CoglHandle handle; CoglTextureFlags flags = COGL_TEXTURE_NONE; + CoglHandle handle; priv->async_data = NULL; @@ -1766,30 +1752,6 @@ clutter_texture_async_load_complete (ClutterTexture *self, clutter_actor_queue_relayout (CLUTTER_ACTOR (self)); } -static gboolean -clutter_texture_thread_idle_func (gpointer user_data) -{ - ClutterTextureAsyncData *data = user_data; - - /* Grab the mutex so we can be sure the thread has unlocked it - before we destroy it */ - g_mutex_lock (data->mutex); - if (data->abort) - { - g_mutex_unlock (data->mutex); - clutter_texture_async_data_free (data); - return FALSE; - } - g_mutex_unlock (data->mutex); - - clutter_texture_async_load_complete (data->texture, data->load_bitmap, - data->load_error); - - clutter_texture_async_data_free (data); - - return FALSE; -} - static gboolean texture_repaint_upload_func (gpointer user_data) { @@ -1797,7 +1759,7 @@ texture_repaint_upload_func (gpointer user_data) g_mutex_lock (&upload_list_mutex); - if (upload_list) + if (upload_list != NULL) { start_time = clutter_get_timestamp (); @@ -1806,16 +1768,32 @@ texture_repaint_upload_func (gpointer user_data) */ do { - ClutterTextureAsyncData *data = upload_list->data; + ClutterTextureAsyncData *async_data = upload_list->data; - clutter_texture_thread_idle_func (data); + clutter_texture_async_data_lock (async_data); - upload_list = g_list_remove (upload_list, data); + if (async_data->state & ASYNC_STATE_QUEUED) + { + CLUTTER_NOTE (TEXTURE, "[async] operation complete for '%s'", + async_data->load_filename); + + clutter_texture_async_load_complete (async_data->texture, + async_data->load_bitmap, + async_data->load_error); + } + else + CLUTTER_NOTE (TEXTURE, "[async] operation cancelled for '%s'", + async_data->load_filename); + + clutter_texture_async_data_unlock (async_data); + + upload_list = g_list_remove (upload_list, async_data); + clutter_texture_async_data_free (async_data); } while (upload_list && clutter_get_timestamp () < start_time + 5 * 1000); } - if (upload_list) + if (upload_list != NULL) { ClutterMasterClock *master_clock; @@ -1829,47 +1807,23 @@ texture_repaint_upload_func (gpointer user_data) } static void -clutter_texture_thread_func (gpointer user_data, gpointer pool_data) +clutter_texture_thread_load (gpointer user_data, + gpointer pool_data) { - ClutterTextureAsyncData *data = user_data; - gboolean should_abort; + ClutterTextureAsyncData *async_data = user_data; + ClutterMasterClock *master_clock = _clutter_master_clock_get_default (); - /* Make sure we haven't been told to abort before the thread had a - chance to run */ - g_mutex_lock (data->mutex); - should_abort = data->abort; - g_mutex_unlock (data->mutex); + clutter_texture_async_data_lock (async_data); - if (should_abort) + if (~async_data->state & ASYNC_STATE_CANCELLED) { - /* If we've been told to abort then main thread has disowned the - async data and we need to free it */ - clutter_texture_async_data_free (data); - return; - } + CLUTTER_NOTE (TEXTURE, "[async] loading bitmap from file '%s'", + async_data->load_filename); - data->load_bitmap = cogl_bitmap_new_from_file (data->load_filename, - &data->load_error); + async_data->load_bitmap = + cogl_bitmap_new_from_file (async_data->load_filename, + &async_data->load_error); - /* Check again if we've been told to abort */ - g_mutex_lock (data->mutex); - - if (data->abort) - { - g_mutex_unlock (data->mutex); - - clutter_texture_async_data_free (data); - } - else - { - ClutterMasterClock *master_clock = _clutter_master_clock_get_default (); - - /* Make sure we give the image to GL in the main thread, where we - * hold the main Clutter lock. Once load_idle is non-NULL then the - * main thread is guaranteed not to set the abort flag. It can't - * set it while we're holding the mutex so we can safely start the - * idle handler now without the possibility of calling the - * callback after it is aborted */ g_mutex_lock (&upload_list_mutex); if (repaint_upload_func == 0) @@ -1879,33 +1833,40 @@ clutter_texture_thread_func (gpointer user_data, gpointer pool_data) NULL, NULL); } - upload_list = g_list_append (upload_list, data); - data->upload_queued = TRUE; + upload_list = g_list_append (upload_list, async_data); + async_data->state |= ASYNC_STATE_QUEUED; + + CLUTTER_NOTE (TEXTURE, "[async] operation queued"); g_mutex_unlock (&upload_list_mutex); - - g_mutex_unlock (data->mutex); - - _clutter_master_clock_ensure_next_iteration (master_clock); } + else + { + clutter_texture_async_data_unlock (async_data); + clutter_texture_async_data_free (async_data); + + return; + } + + clutter_texture_async_data_unlock (async_data); + + _clutter_master_clock_ensure_next_iteration (master_clock); } static gboolean -clutter_texture_idle_func (gpointer user_data) +clutter_texture_idle_load (gpointer data) { - ClutterTextureAsyncData *data = user_data; - GError *internal_error = NULL; + ClutterTextureAsyncData *async_data = data; - data->load_bitmap = cogl_bitmap_new_from_file (data->load_filename, - &internal_error); + async_data->load_bitmap = + cogl_bitmap_new_from_file (async_data->load_filename, + &async_data->load_error); - clutter_texture_async_load_complete (data->texture, data->load_bitmap, - internal_error); + clutter_texture_async_load_complete (async_data->texture, + async_data->load_bitmap, + async_data->load_error); - if (internal_error) - g_error_free (internal_error); - - clutter_texture_async_data_free (data); + clutter_texture_async_data_free (async_data); return FALSE; } @@ -1956,9 +1917,7 @@ clutter_texture_async_load (ClutterTexture *self, height = 0; } else - { - res = cogl_bitmap_get_size_from_file (filename, &width, &height); - } + res = cogl_bitmap_get_size_from_file (filename, &width, &height); if (!res) { @@ -1975,35 +1934,34 @@ clutter_texture_async_load (ClutterTexture *self, clutter_texture_async_load_cancel (self); - data = g_slice_new (ClutterTextureAsyncData); + data = g_slice_new0 (ClutterTextureAsyncData); - data->abort = FALSE; data->texture = self; - data->load_idle = 0; data->load_filename = g_strdup (filename); - data->load_bitmap = NULL; - data->load_error = NULL; priv->async_data = data; if (g_thread_supported ()) { - data->mutex = g_mutex_new (); - - if (async_thread_pool == NULL) - /* This apparently can't fail if exclusive == FALSE */ - async_thread_pool - = g_thread_pool_new (clutter_texture_thread_func, - NULL, 1, FALSE, NULL); + if (G_UNLIKELY (async_thread_pool == NULL)) + { + /* This apparently can't fail if exclusive == FALSE */ + async_thread_pool = + g_thread_pool_new (clutter_texture_thread_load, NULL, + 1, + FALSE, + NULL); + } g_thread_pool_push (async_thread_pool, data, NULL); } else { - data->mutex = NULL; - - data->load_idle - = clutter_threads_add_idle (clutter_texture_idle_func, data); + data->load_idle = + clutter_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE, + clutter_texture_idle_load, + data, + NULL); } return TRUE; @@ -2921,6 +2879,8 @@ clutter_texture_set_load_async (ClutterTexture *texture, priv = texture->priv; + load_async = !!load_async; + if (priv->load_async_set != load_async) { priv->load_data_async = load_async; From 4ebdeede9feed7995335616ae5e9c2cf3af0ec6b Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 27 Sep 2011 16:40:34 +0100 Subject: [PATCH 05/11] test-texture-async: Clean up the test code Force threading on, and stop using the default stage and behaviours: let's try to use modern API. --- tests/interactive/test-texture-async.c | 63 ++++++++++++-------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/tests/interactive/test-texture-async.c b/tests/interactive/test-texture-async.c index f88f382a5..634796240 100644 --- a/tests/interactive/test-texture-async.c +++ b/tests/interactive/test-texture-async.c @@ -1,7 +1,5 @@ #include #include - -#undef CLUTTER_DISABLE_DEPRECATED #include enum @@ -11,6 +9,8 @@ enum LOAD_ASYNC }; +static ClutterActor *stage = NULL; + static void on_load_finished (ClutterTexture *texture, const GError *error, @@ -52,17 +52,11 @@ size_change_cb (ClutterTexture *texture, static gboolean task (gpointer user_data) { - ClutterTimeline *timeline; - ClutterAlpha *alpha; - ClutterBehaviour *depth_behavior; - ClutterActor *image[4]; - ClutterActor *clone[4]; - ClutterActor *stage; - gchar *path = user_data; + const gchar *path = user_data; + ClutterActor *image[3]; + ClutterActor *clone[3]; gint i; - stage = clutter_stage_get_default (); - image[0] = g_object_new (CLUTTER_TYPE_TEXTURE, NULL); g_signal_connect (image[0], "load-finished", G_CALLBACK (on_load_finished), @@ -93,62 +87,63 @@ gboolean task (gpointer user_data) } for (i = 0; i < 3; i++) - clutter_container_add (CLUTTER_CONTAINER (stage), image[i], NULL); + clutter_container_add_actor (CLUTTER_CONTAINER (stage), image[i]); for (i = 0; i < 3; i++) { - clutter_actor_set_position (image[i], 50+i*100, 0+i*50); - clone[i]=clutter_clone_new (image[i]); + clutter_actor_set_position (image[i], 50 + i * 100, 0 + i * 50); + clone[i] = clutter_clone_new (image[i]); g_signal_connect (image[i], "size-change", G_CALLBACK (size_change_cb), clone[i]); - clutter_container_add (CLUTTER_CONTAINER (stage), clone[i], NULL); - clutter_actor_set_position (clone[i], 50+i*100, 150+i*50+100); + clutter_container_add_actor (CLUTTER_CONTAINER (stage), clone[i]); + clutter_actor_set_position (clone[i], 50 + i * 100, 150 + i * 50 + 100); } for (i = 0; i < 3; i++) { - timeline = clutter_timeline_new (5000); - alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR); - depth_behavior = clutter_behaviour_depth_new (alpha, -2500, 0); - clutter_behaviour_apply (depth_behavior, image[i]); - clutter_timeline_start (timeline); + clutter_actor_set_depth (image[i], -2500); + clutter_actor_animate (image[i], CLUTTER_LINEAR, 5000, + "depth", 0.0, + NULL); } return FALSE; } +static void +cleanup_task (gpointer data) +{ +} G_MODULE_EXPORT gint test_texture_async_main (int argc, char *argv[]) { - ClutterActor *stage; - ClutterColor stage_color = { 0x12, 0x34, 0x56, 0xff }; - gchar *path; + gchar *path; + + g_thread_init (NULL); + clutter_threads_init (); if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; - g_thread_init (NULL); - stage = clutter_stage_get_default (); - clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); + stage = clutter_stage_new (); + clutter_stage_set_title (CLUTTER_STAGE (stage), "Asynchronous Texture Loading"); + clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_LightSkyBlue); + g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); clutter_actor_show (stage); - g_signal_connect (stage, - "button-press-event", G_CALLBACK (clutter_main_quit), - NULL); path = (argc > 1) ? g_strdup (argv[1]) : g_build_filename (TESTS_DATADIR, "redhand.png", NULL); - clutter_threads_add_timeout (500, task, path); + clutter_threads_add_timeout_full (G_PRIORITY_DEFAULT, 500, + task, path, + cleanup_task); clutter_main (); g_free (path); - /*g_object_unref (depth_behavior); - g_object_unref (timeline);*/ - return EXIT_SUCCESS; } From d640c56cef4738b2c9b75b034b81438390538561 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 27 Sep 2011 17:40:51 +0100 Subject: [PATCH 06/11] test-interactive: Allow querying the interactive test for a description It would be nice if the interactive tests had a way to be queried for a description, instead of "Just Knowing" what they are meant to be doing. --- tests/interactive/Makefile.am | 25 +++- tests/interactive/test-main.c | 210 ++++++++++++++++++++++++++++++---- 2 files changed, 211 insertions(+), 24 deletions(-) diff --git a/tests/interactive/Makefile.am b/tests/interactive/Makefile.am index 75da2add9..73d24eb3d 100644 --- a/tests/interactive/Makefile.am +++ b/tests/interactive/Makefile.am @@ -74,11 +74,13 @@ endif # For convenience, this provides a way to easily run individual unit tests: wrappers: stamp-test-interactive @true -stamp-test-interactive: Makefile test-interactive$(EXEEXT) +stamp-test-interactive: Makefile @wrapper=$(abs_builddir)/wrapper.sh ; \ chmod +x $$wrapper && \ ( echo "/stamp-test-interactive" ; \ + echo "/stamp-test-unit-names" ; \ echo "/test-interactive" ; \ + echo "/test-unit-names.h" ; \ echo "*.o" ; \ echo ".gitignore" ) > .gitignore ; \ for i in $(UNIT_TESTS); \ @@ -93,6 +95,21 @@ stamp-test-interactive: Makefile test-interactive$(EXEEXT) done \ && echo timestamp > $(@F) +test-unit-names.h: stamp-test-unit-names + @true + +stamp-test-unit-names: Makefile + @( echo "/* ** This file is autogenerated. Do not edit. ** */" ; \ + echo "" ; \ + echo "const char *test_unit_names[] = {" ) > test-unit-names.h ; \ + for i in $(UNIT_TESTS); \ + do \ + test_bin=$${i%*.c} ; \ + echo " \"$$test_bin\"," >> test-unit-names.h ; \ + done \ + && echo "};" >> test-unit-names.h \ + && echo timestamp > $(@F) + clean-wrappers: @for i in $(UNIT_TESTS); \ do \ @@ -115,7 +132,7 @@ common_ldadd = $(top_builddir)/clutter/libclutter-@CLUTTER_SONAME_INFIX@-@CLUTTE noinst_PROGRAMS = test-interactive -test_interactive_SOURCES = test-main.c $(UNIT_TESTS) +test_interactive_SOURCES = test-main.c test-unit-names.h $(UNIT_TESTS) test_interactive_CFLAGS = $(CLUTTER_CFLAGS) $(MAINTAINER_CFLAGS) test_interactive_CPPFLAGS = \ -DTESTS_DATADIR=\""$(abs_top_srcdir)/tests/data"\" \ @@ -126,8 +143,8 @@ test_interactive_LDFLAGS = -export-dynamic test_interactive_LDADD = $(CLUTTER_LIBS) $(common_ldadd) -lm EXTRA_DIST = wrapper.sh.in -DISTCLEANFILES = wrapper.sh .gitignore +DISTCLEANFILES = wrapper.sh .gitignore test-unit-names.h -BUILT_SOURCES = wrappers +BUILT_SOURCES = wrappers test-unit-names.h clean-local: clean-wrappers diff --git a/tests/interactive/test-main.c b/tests/interactive/test-main.c index 2a0cd74a5..10d032233 100644 --- a/tests/interactive/test-main.c +++ b/tests/interactive/test-main.c @@ -1,37 +1,207 @@ +#include +#include #include #include +#include "test-unit-names.h" + +#define MAX_DESC_SIZE 72 + +static GModule *module = NULL; + +static gpointer +get_symbol_with_suffix (const char *unit_name, + const char *suffix) +{ + char *main_symbol_name; + gpointer func; + + main_symbol_name = g_strconcat (unit_name, "_", suffix, NULL); + main_symbol_name = g_strdelimit (main_symbol_name, "-", '_'); + + g_module_symbol (module, main_symbol_name, &func); + + g_free (main_symbol_name); + + return func; +} + +static gpointer +get_unit_name_main (const char *unit_name) +{ + return get_symbol_with_suffix (unit_name, "main"); +} +static char * +get_unit_name_description (const char *unit_name, + gssize max_len) +{ + const char *description; + gpointer func; + char *retval; + + func = get_symbol_with_suffix (unit_name, "describe"); + if (func == NULL) + description = "No description found"; + else + { + const char *(* unit_test_describe) (void); + + unit_test_describe = func; + + description = unit_test_describe (); + } + + if (max_len > 0 && strlen (description) >= max_len) + { + GString *buf = g_string_sized_new (max_len); + char *newline; + + newline = strchr (description, '\n'); + if (newline != NULL) + { + g_string_append_len (buf, description, + MIN (newline - description - 1, max_len - 3)); + } + else + g_string_append_len (buf, description, max_len - 3); + + g_string_append (buf, "..."); + + retval = g_string_free (buf, FALSE); + } + else + retval = g_strdup (description); + + return retval; +} + +static gboolean list_all = FALSE; +static gboolean describe = FALSE; +static char **unit_names = NULL; + +static GOptionEntry entries[] = { + { + "describe", 'd', + 0, + G_OPTION_ARG_NONE, &describe, + "Describe the interactive unit test", NULL, + }, + { + "list-all", 'l', + 0, + G_OPTION_ARG_NONE, &list_all, + "List all available units", NULL, + }, + { + G_OPTION_REMAINING, 0, + 0, + G_OPTION_ARG_STRING_ARRAY, &unit_names, + "The interactive unit test", "UNIT_NAME" + }, + { NULL } +}; int main (int argc, char **argv) { - GModule *module; - char *unit_test; - char *main_symbol_name; - gpointer func; - int (*unit_test_main) (int argc, char **argv); - int ret; + int ret, i, n_unit_names; + GOptionContext *context; + + context = g_option_context_new (" - Interactive test suite"); + g_option_context_add_main_entries (context, entries, NULL); + g_option_context_set_help_enabled (context, TRUE); + g_option_context_set_ignore_unknown_options (context, TRUE); + if (!g_option_context_parse (context, &argc, &argv, NULL)) + { + g_print ("Usage: test-interactive \n"); + return EXIT_FAILURE; + } + + g_option_context_free (context); - if (argc < 2) - g_error ("Usage: %s unit_test", argv[0]); - module = g_module_open (NULL, 0); if (!module) - g_error ("Failed to open self for symbol lookup"); + g_error ("*** Failed to open self for symbol lookup"); - unit_test = g_path_get_basename (argv[1]); + ret = EXIT_SUCCESS; - main_symbol_name = g_strdup_printf ("%s_main", unit_test); - main_symbol_name = g_strdelimit (main_symbol_name, "-", '_'); + if (list_all) + { + g_print ("* Available unit tests:\n"); - if (!g_module_symbol (module, main_symbol_name, &func)) - g_error ("Failed to look up main symbol for the test: %s", unit_test); + for (i = 0; i < G_N_ELEMENTS (test_unit_names); i++) + { + char *str; + gsize len; - unit_test_main = func; - ret = unit_test_main (argc - 1, argv + 1); - - g_free (unit_test); - g_free (main_symbol_name); + len = MAX_DESC_SIZE - strlen (test_unit_names[i]); + str = get_unit_name_description (test_unit_names[i], len - 2); + + g_print (" - %s:%*s%s\n", + test_unit_names[i], + (int) len - strlen (str), " ", + str); + + g_free (str); + } + + ret = EXIT_SUCCESS; + goto out; + } + + n_unit_names = g_strv_length (unit_names); + for (i = 0; i < n_unit_names; i++) + { + const char *unit_name = unit_names[i]; + char *unit_test = NULL; + gboolean found; + int j; + + unit_test = g_path_get_basename (unit_name); + + found = FALSE; + for (j = 0; j < G_N_ELEMENTS (test_unit_names); j++) + { + if (strcmp (test_unit_names[j], unit_test) == 0) + { + found = TRUE; + break; + } + } + + if (!found) + g_error ("*** Unit '%s' does not exist", unit_test); + + if (describe) + { + char *str; + + str = get_unit_name_description (unit_test, -1); + + g_print ("* %s:\n%s\n\n", unit_test, str); + + g_free (str); + + ret = EXIT_SUCCESS; + } + else + { + int (* unit_test_main) (int argc, char **argv); + gpointer func; + + func = get_unit_name_main (unit_test); + if (func == NULL) + g_error ("*** Unable to find the main entry point for '%s'", unit_test); + + unit_test_main = func; + + ret = unit_test_main (argc, argv); + } + + g_free (unit_test); + } + +out: g_module_close (module); return ret; From 5fc953cb5eec7960138037f248440778239aef11 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 27 Sep 2011 17:50:51 +0100 Subject: [PATCH 07/11] test-textures -> test-texture-slicing The unit is supposed to be testing the slicing support in CoglTexture. --- tests/interactive/Makefile.am | 2 +- tests/interactive/{test-textures.c => test-texture-slicing.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/interactive/{test-textures.c => test-texture-slicing.c} (100%) diff --git a/tests/interactive/Makefile.am b/tests/interactive/Makefile.am index 73d24eb3d..eb4bde652 100644 --- a/tests/interactive/Makefile.am +++ b/tests/interactive/Makefile.am @@ -1,7 +1,7 @@ include $(top_srcdir)/build/autotools/Makefile.am.silent UNIT_TESTS = \ - test-textures.c \ + test-texture-slicing.c \ test-texture-async.c \ test-texture-material.c \ test-events.c \ diff --git a/tests/interactive/test-textures.c b/tests/interactive/test-texture-slicing.c similarity index 100% rename from tests/interactive/test-textures.c rename to tests/interactive/test-texture-slicing.c From ac8e174eca31a28dae4a7aa5b3336b8cf27d6767 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 28 Sep 2011 13:32:57 +0100 Subject: [PATCH 08/11] tests/interactive: Add some descriptions --- tests/interactive/test-animation.c | 6 ++++++ tests/interactive/test-cairo-clock.c | 6 ++++++ tests/interactive/test-constraints.c | 6 ++++++ tests/interactive/test-drop.c | 6 ++++++ tests/interactive/test-easing.c | 6 ++++++ tests/interactive/test-table-layout.c | 6 ++++++ tests/interactive/test-text-field.c | 11 +++++++++++ tests/interactive/test-texture-async.c | 6 ++++++ tests/interactive/test-texture-slicing.c | 6 ++++++ 9 files changed, 59 insertions(+) diff --git a/tests/interactive/test-animation.c b/tests/interactive/test-animation.c index 85b7213bc..aba1a9d50 100644 --- a/tests/interactive/test-animation.c +++ b/tests/interactive/test-animation.c @@ -114,3 +114,9 @@ test_animation_main (int argc, char *argv[]) return EXIT_SUCCESS; } + +G_MODULE_EXPORT const char * +test_animation_describe (void) +{ + return "Simple clutter_actor_animate() demo"; +} diff --git a/tests/interactive/test-cairo-clock.c b/tests/interactive/test-cairo-clock.c index 6c292d0df..6edd83ba2 100644 --- a/tests/interactive/test-cairo-clock.c +++ b/tests/interactive/test-cairo-clock.c @@ -111,3 +111,9 @@ test_cairo_clock_main (int argc, char *argv[]) return EXIT_SUCCESS; } + +G_MODULE_EXPORT const char * +test_cairo_clock_describe (void) +{ + return "Simple 2D canvas using a Cairo texture actor"; +} diff --git a/tests/interactive/test-constraints.c b/tests/interactive/test-constraints.c index 9f9a5f2c2..3e45ce990 100644 --- a/tests/interactive/test-constraints.c +++ b/tests/interactive/test-constraints.c @@ -247,3 +247,9 @@ test_constraints_main (int argc, char *argv[]) return EXIT_SUCCESS; } + +G_MODULE_EXPORT const char * +test_constraints_describe (void) +{ + return "Visualize usage of Bind and Align constraints"; +} diff --git a/tests/interactive/test-drop.c b/tests/interactive/test-drop.c index 2b511d4e8..0427b02e0 100644 --- a/tests/interactive/test-drop.c +++ b/tests/interactive/test-drop.c @@ -243,3 +243,9 @@ test_drop_main (int argc, char *argv[]) return EXIT_SUCCESS; } + +G_MODULE_EXPORT const char * +test_drop_describe (void) +{ + return "Drop action support"; +} diff --git a/tests/interactive/test-easing.c b/tests/interactive/test-easing.c index 2bd8a9c18..876ad957f 100644 --- a/tests/interactive/test-easing.c +++ b/tests/interactive/test-easing.c @@ -262,3 +262,9 @@ test_easing_main (int argc, char *argv[]) return EXIT_SUCCESS; } + +G_MODULE_EXPORT const char * +test_easing_describe (void) +{ + return "Visualize all easing modes provided by Clutter"; +} diff --git a/tests/interactive/test-table-layout.c b/tests/interactive/test-table-layout.c index 209659b48..62f3b17a1 100644 --- a/tests/interactive/test-table-layout.c +++ b/tests/interactive/test-table-layout.c @@ -274,3 +274,9 @@ test_table_layout_main (int argc, char *argv[]) return EXIT_SUCCESS; } + +G_MODULE_EXPORT const char * +test_table_layout_describe (void) +{ + return "Table layout manager"; +} diff --git a/tests/interactive/test-text-field.c b/tests/interactive/test-text-field.c index e837a021a..2897befa8 100644 --- a/tests/interactive/test-text-field.c +++ b/tests/interactive/test-text-field.c @@ -334,3 +334,14 @@ test_text_field_main (gint argc, return EXIT_SUCCESS; } + +G_MODULE_EXPORT const char * +test_text_field_describe (void) +{ + return +"Text actor single-line and password mode support\n" +"\n" +"This test checks the :single-line-mode and :password-char properties of\n" +"the ClutterText actor, plus the password hint feature and the :max-length\n" +"property."; +} diff --git a/tests/interactive/test-texture-async.c b/tests/interactive/test-texture-async.c index 634796240..a69690b27 100644 --- a/tests/interactive/test-texture-async.c +++ b/tests/interactive/test-texture-async.c @@ -147,3 +147,9 @@ test_texture_async_main (int argc, char *argv[]) return EXIT_SUCCESS; } + +G_MODULE_EXPORT const char * +test_texture_async_describe (void) +{ + return "Texture asynchronous loading using threads"; +} diff --git a/tests/interactive/test-texture-slicing.c b/tests/interactive/test-texture-slicing.c index d8094e947..f86a76e0c 100644 --- a/tests/interactive/test-texture-slicing.c +++ b/tests/interactive/test-texture-slicing.c @@ -110,3 +110,9 @@ test_textures_main (int argc, char *argv[]) return EXIT_SUCCESS; } + +G_MODULE_EXPORT const char * +test_texture_slicing_describe (void) +{ + return "Check texture slicing support in CoglTexture"; +} From 4829ae1c79f1ae60d562621b81a7be800e0697bb Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 27 Sep 2011 13:01:36 -0400 Subject: [PATCH 09/11] Add lightness, brightness, and contrast effects Added three classes for new clutter effects: inverse lightness, modify brightness, and modify contrast. https://bugzilla.gnome.org/show_bug.cgi?id=656156 --- clutter/Makefile.am | 6 + clutter/clutter-brightness-effect.c | 380 ++++++++++++++++++++ clutter/clutter-brightness-effect.h | 63 ++++ clutter/clutter-contrast-effect.c | 395 +++++++++++++++++++++ clutter/clutter-contrast-effect.h | 63 ++++ clutter/clutter-invert-lightness-effect.c | 243 +++++++++++++ clutter/clutter-invert-lightness-effect.h | 57 +++ doc/reference/clutter/clutter-docs.xml.in | 3 + doc/reference/clutter/clutter-sections.txt | 47 +++ doc/reference/clutter/clutter.types | 3 + 10 files changed, 1260 insertions(+) create mode 100644 clutter/clutter-brightness-effect.c create mode 100644 clutter/clutter-brightness-effect.h create mode 100644 clutter/clutter-contrast-effect.c create mode 100644 clutter/clutter-contrast-effect.h create mode 100644 clutter/clutter-invert-lightness-effect.c create mode 100644 clutter/clutter-invert-lightness-effect.h diff --git a/clutter/Makefile.am b/clutter/Makefile.am index d9b81a8c5..cf37c4d83 100644 --- a/clutter/Makefile.am +++ b/clutter/Makefile.am @@ -71,6 +71,7 @@ source_h = \ $(srcdir)/clutter-blur-effect.h \ $(srcdir)/clutter-box.h \ $(srcdir)/clutter-box-layout.h \ + $(srcdir)/clutter-brightness-effect.h \ $(srcdir)/clutter-cairo-texture.h \ $(srcdir)/clutter-child-meta.h \ $(srcdir)/clutter-click-action.h \ @@ -80,6 +81,7 @@ source_h = \ $(srcdir)/clutter-colorize-effect.h \ $(srcdir)/clutter-constraint.h \ $(srcdir)/clutter-container.h \ + $(srcdir)/clutter-contrast-effect.h \ $(srcdir)/clutter-deform-effect.h \ $(srcdir)/clutter-deprecated.h \ $(srcdir)/clutter-desaturate-effect.h \ @@ -96,6 +98,7 @@ source_h = \ $(srcdir)/clutter-gesture-action.h \ $(srcdir)/clutter-group.h \ $(srcdir)/clutter-input-device.h \ + $(srcdir)/clutter-invert-lightness-effect.h \ $(srcdir)/clutter-interval.h \ $(srcdir)/clutter-keysyms.h \ $(srcdir)/clutter-keysyms-compat.h \ @@ -158,6 +161,7 @@ source_c = \ $(srcdir)/clutter-blur-effect.c \ $(srcdir)/clutter-box.c \ $(srcdir)/clutter-box-layout.c \ + $(srcdir)/clutter-brightness-effect.c \ $(srcdir)/clutter-cairo-texture.c \ $(srcdir)/clutter-child-meta.c \ $(srcdir)/clutter-click-action.c \ @@ -166,6 +170,7 @@ source_c = \ $(srcdir)/clutter-colorize-effect.c \ $(srcdir)/clutter-constraint.c \ $(srcdir)/clutter-container.c \ + $(srcdir)/clutter-contrast-effect.c \ $(srcdir)/clutter-deform-effect.c \ $(srcdir)/clutter-desaturate-effect.c \ $(srcdir)/clutter-device-manager.c \ @@ -182,6 +187,7 @@ source_c = \ $(srcdir)/clutter-gesture-action.c \ $(srcdir)/clutter-group.c \ $(srcdir)/clutter-input-device.c \ + $(srcdir)/clutter-invert-lightness-effect.c \ $(srcdir)/clutter-interval.c \ $(srcdir)/clutter-keysyms-table.c \ $(srcdir)/clutter-layout-manager.c \ diff --git a/clutter/clutter-brightness-effect.c b/clutter/clutter-brightness-effect.c new file mode 100644 index 000000000..989115635 --- /dev/null +++ b/clutter/clutter-brightness-effect.c @@ -0,0 +1,380 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright (C) 2010, 2011 Inclusive Design Research Centre, OCAD University. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Author: + * Joseph Scheuhammer + */ + +/** + * SECTION:clutter-brightness-effect + * @short_description: Increase/decrease brightness of actor. + * @see_also: #ClutterEffect, #ClutterOffscreenEffect + * + * #ClutterBrightnessEffect is a sub-class of #ClutterEffect that changes the + * overall brightness of a #ClutterActor. + * + * #ClutterBrightnessEffect is available since Clutter 1.10 + */ + +#define CLUTTER_BRIGHTNESS_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_BRIGHTNESS_EFFECT, ClutterBrightnessEffectClass)) +#define CLUTTER_IS_BRIGHTNESS_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_BRIGHTNESS_EFFECT)) +#define CLUTTER_BRIGHTNESS_EFFECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_BRIGHTNESS_EFFECT, ClutterBrightnessEffectClass)) + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "clutter-brightness-effect.h" + +#include "clutter-actor.h" +#include "clutter-feature.h" +#include "clutter-offscreen-effect.h" +#include "clutter-private.h" + +struct _ClutterBrightnessEffect +{ + ClutterOffscreenEffect parent_instance; + + /* a back pointer to our actor, so that we can query it */ + ClutterActor *actor; + + CoglHandle shader; + CoglHandle program; + + /* Brightness changes. */ + ClutterColor brightness; + + gint tex_uniform; + gint brightness_uniform; + + guint is_compiled : 1; +}; + +struct _ClutterBrightnessEffectClass +{ + ClutterOffscreenEffectClass parent_class; +}; + +/* Brightness effects in GLSL. + */ +static const gchar *brightness_glsl_shader = +"uniform sampler2D tex;\n" +"uniform vec3 brightness;\n" +"\n" +"void main ()\n" +"{\n" +" vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy));\n" +" vec3 effect = vec3 (color);\n" +"\n" +" effect = clamp (effect + brightness, 0.0, 1.0);\n" +"\n" +"\n" +" cogl_color_out = vec4 (effect, color.a);\n" +"}\n"; + +/* No brightness change. */ +static const ClutterColor same_brightness = { 0x7f, 0x7f, 0x7f, 0xff }; + +enum +{ + PROP_0, + + PROP_BRIGHTNESS, + + PROP_LAST +}; + +static GParamSpec *obj_props[PROP_LAST]; + +G_DEFINE_TYPE (ClutterBrightnessEffect, + clutter_brightness_effect, + CLUTTER_TYPE_OFFSCREEN_EFFECT); + +static gboolean +clutter_brightness_effect_pre_paint (ClutterEffect *effect) +{ + ClutterBrightnessEffect *self = CLUTTER_BRIGHTNESS_EFFECT (effect); + ClutterEffectClass *parent_class; + + if (!clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (effect))) + return FALSE; + + self->actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (effect)); + if (self->actor == NULL) + return FALSE; + + if (!clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL)) + { + /* if we don't have support for GLSL shaders then we + * forcibly disable the ActorMeta + */ + g_warning ("Unable to use the ShaderEffect: the graphics hardware " + "or the current GL driver does not implement support " + "for the GLSL shading language."); + clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (effect), FALSE); + return FALSE; + } + + if (self->shader == COGL_INVALID_HANDLE) + { + self->shader = cogl_create_shader (COGL_SHADER_TYPE_FRAGMENT); + cogl_shader_source (self->shader, brightness_glsl_shader); + + self->is_compiled = FALSE; + self->tex_uniform = -1; + self->brightness_uniform = -1; + } + + if (self->program == COGL_INVALID_HANDLE) + self->program = cogl_create_program (); + + if (!self->is_compiled) + { + g_assert (self->shader != COGL_INVALID_HANDLE); + g_assert (self->program != COGL_INVALID_HANDLE); + + cogl_shader_compile (self->shader); + if (!cogl_shader_is_compiled (self->shader)) + { + gchar *log_buf = cogl_shader_get_info_log (self->shader); + + g_warning (G_STRLOC ": Unable to compile the brightness effects shader: %s", + log_buf); + g_free (log_buf); + + cogl_handle_unref (self->shader); + cogl_handle_unref (self->program); + + self->shader = COGL_INVALID_HANDLE; + self->program = COGL_INVALID_HANDLE; + } + else + { + cogl_program_attach_shader (self->program, self->shader); + cogl_program_link (self->program); + + cogl_handle_unref (self->shader); + + self->is_compiled = TRUE; + + self->tex_uniform = + cogl_program_get_uniform_location (self->program, "tex"); + self->brightness_uniform = + cogl_program_get_uniform_location (self->program, "brightness"); + } + } + + parent_class = CLUTTER_EFFECT_CLASS (clutter_brightness_effect_parent_class); + return parent_class->pre_paint (effect); +} + +static void +clutter_brightness_effect_paint_target (ClutterOffscreenEffect *effect) +{ + ClutterBrightnessEffect *self = CLUTTER_BRIGHTNESS_EFFECT (effect); + ClutterOffscreenEffectClass *parent; + CoglHandle material; + + if (self->program == COGL_INVALID_HANDLE) + goto out; + + if (self->tex_uniform > -1) + cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0); + + if (self->brightness_uniform > -1) + { + float brightness[3] = { + (self->brightness.red / 127.0) - 1.0, + (self->brightness.green / 127.0) - 1.0, + (self->brightness.blue / 127.0) - 1.0 + }; + cogl_program_set_uniform_float (self->program, self->brightness_uniform, + 3, 1, + brightness); + } + + material = clutter_offscreen_effect_get_target (effect); + cogl_material_set_user_program (material, self->program); + +out: + parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (clutter_brightness_effect_parent_class); + parent->paint_target (effect); +} + +static void +clutter_brightness_effect_dispose (GObject *gobject) +{ + ClutterBrightnessEffect *self = CLUTTER_BRIGHTNESS_EFFECT (gobject); + + if (self->program != COGL_INVALID_HANDLE) + { + cogl_handle_unref (self->program); + + self->program = COGL_INVALID_HANDLE; + self->shader = COGL_INVALID_HANDLE; + } + + self->actor = NULL; + + G_OBJECT_CLASS (clutter_brightness_effect_parent_class)->dispose (gobject); +} + +static void +clutter_brightness_effect_set_property (GObject *gobject, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + ClutterBrightnessEffect *effect = CLUTTER_BRIGHTNESS_EFFECT (gobject); + + switch (prop_id) + { + case PROP_BRIGHTNESS: + clutter_brightness_effect_set_brightness (effect, + clutter_value_get_color (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); + break; + } +} + +static void +clutter_brightness_effect_get_property (GObject *gobject, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + ClutterBrightnessEffect *effect = CLUTTER_BRIGHTNESS_EFFECT (gobject); + ClutterColor brightness; + + switch (prop_id) + { + case PROP_BRIGHTNESS: + clutter_brightness_effect_get_brightness (effect, &brightness); + clutter_value_set_color (value, &brightness); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); + break; + } +} + +static void +clutter_brightness_effect_class_init (ClutterBrightnessEffectClass *klass) +{ + ClutterEffectClass *effect_class = CLUTTER_EFFECT_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + ClutterOffscreenEffectClass *offscreen_class; + + offscreen_class = CLUTTER_OFFSCREEN_EFFECT_CLASS (klass); + offscreen_class->paint_target = clutter_brightness_effect_paint_target; + + effect_class->pre_paint = clutter_brightness_effect_pre_paint; + + gobject_class->set_property = clutter_brightness_effect_set_property; + gobject_class->get_property = clutter_brightness_effect_get_property; + gobject_class->dispose = clutter_brightness_effect_dispose; + + /** + * ClutterBrightnessEffect:brightness: + * + * The brightness change to apply to the actor + * + * Since: 1.10 + */ + obj_props[PROP_BRIGHTNESS] = + clutter_param_spec_color ("brightness", + P_("Brightness"), + P_("The brightness change to apply"), + &same_brightness, + G_PARAM_READWRITE); + + g_object_class_install_properties (gobject_class, PROP_LAST, obj_props); +} + +static void +clutter_brightness_effect_init (ClutterBrightnessEffect *self) +{ + self->brightness = same_brightness; +} + +/** + * clutter_brightness_effect_new: + * + * Creates a new #ClutterBrightnessEffect to be used with + * clutter_actor_add_effect() + * + * Return value: (transfer full): the newly created #ClutterBrightnessEffect or + * or %NULL. Use g_object_unref() when done. + * + * Since: 1.10 + */ +ClutterEffect * +clutter_brightness_effect_new (void) +{ + return g_object_new (CLUTTER_TYPE_BRIGHTNESS_EFFECT, + NULL); +} + +/** + * clutter_brightness_effect_set_brightness: + * @effect: a #ClutterBrightnessEffect + * @brightness: ClutterColor governing the brightness change. + * + * Add each of the red, green, blue components of the @brightness to + * the red, greeen, or blue components of the actor's colors. + * + * Since: 1.10 + */ +void +clutter_brightness_effect_set_brightness (ClutterBrightnessEffect *effect, + const ClutterColor *brightness) +{ + g_return_if_fail (CLUTTER_IS_BRIGHTNESS_EFFECT (effect)); + if (clutter_color_equal (&effect->brightness, brightness)) + return; + + effect->brightness = *brightness; + + if (effect->actor != NULL) + clutter_actor_queue_redraw (effect->actor); +} + +/** + * clutter_brightness_effect_get_brightness: + * @effect: a #ClutterBrightnessEffect + * @brightness: (out caller-allocates): return location for the brightness. + * + * Retrieves the brightness value used by @effect + * + * Since: 1.10 + */ +void +clutter_brightness_effect_get_brightness (ClutterBrightnessEffect *effect, + ClutterColor *brightness) +{ + g_return_if_fail (CLUTTER_IS_BRIGHTNESS_EFFECT (effect)); + g_return_if_fail (brightness != NULL); + + *brightness = effect->brightness; +} diff --git a/clutter/clutter-brightness-effect.h b/clutter/clutter-brightness-effect.h new file mode 100644 index 000000000..6b6fe3b61 --- /dev/null +++ b/clutter/clutter-brightness-effect.h @@ -0,0 +1,63 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright (C) 2010, 2011 Inclusive Design Research Centre, OCAD University. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Author: + * Joseph Scheuhammer + */ + +#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef __CLUTTER_BRIGHTNESS_EFFECT_H__ +#define __CLUTTER_BRIGHTNESS_EFFECT_H__ + +#include +#include + +G_BEGIN_DECLS + +#define CLUTTER_TYPE_BRIGHTNESS_EFFECT (clutter_brightness_effect_get_type ()) +#define CLUTTER_BRIGHTNESS_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_BRIGHTNESS_EFFECT, ClutterBrightnessEffect)) +#define CLUTTER_IS_BRIGHTNESS_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_BRIGHTNESS_EFFECT)) + +/** + * ClutterBrightnessEffect: + * + * ClutterBrightnessEffect is an opaque structure + * whose members cannot be directly accessed + * + * Since: 1.10 + */ +typedef struct _ClutterBrightnessEffect ClutterBrightnessEffect; +typedef struct _ClutterBrightnessEffectClass ClutterBrightnessEffectClass; + +GType clutter_brightness_effect_get_type (void) G_GNUC_CONST; + +ClutterEffect *clutter_brightness_effect_new (void); + +void clutter_brightness_effect_set_brightness (ClutterBrightnessEffect *effect, + const ClutterColor *brightness); +void clutter_brightness_effect_get_brightness (ClutterBrightnessEffect *effect, + ClutterColor *brightness); + +G_END_DECLS + +#endif /* __CLUTTER_BRIGHTNESS_EFFECT_H__ */ diff --git a/clutter/clutter-contrast-effect.c b/clutter/clutter-contrast-effect.c new file mode 100644 index 000000000..98a2d9079 --- /dev/null +++ b/clutter/clutter-contrast-effect.c @@ -0,0 +1,395 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright (C) 2010, 2011 Inclusive Design Research Centre, OCAD University. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Author: + * Joseph Scheuhammer + */ + +/** + * SECTION:clutter-contrast-effect + * @short_description: Increase/decrease contrast of actor. + * @see_also: #ClutterEffect, #ClutterOffscreenEffect + * + * #ClutterContrastEffect is a sub-class of #ClutterEffect that changes the + * overall contrast of a #ClutterActor. + * + * #ClutterContrastEffect is available since Clutter 1.10 + */ + +#define CLUTTER_CONTRAST_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_CONTRAST_EFFECT, ClutterContrastEffectClass)) +#define CLUTTER_IS_CONTRAST_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_CONTRAST_EFFECT)) +#define CLUTTER_CONTRAST_EFFECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_CONTRAST_EFFECT, ClutterContrastEffectClass)) + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "clutter-contrast-effect.h" + +#include "clutter-actor.h" +#include "clutter-feature.h" +#include "clutter-offscreen-effect.h" +#include "clutter-private.h" + +struct _ClutterContrastEffect +{ + ClutterOffscreenEffect parent_instance; + + /* a back pointer to our actor, so that we can query it */ + ClutterActor *actor; + + CoglHandle shader; + CoglHandle program; + + /* Contrast changes. */ + ClutterColor contrast; + + gint tex_uniform; + gint contrast_uniform; + + guint is_compiled : 1; +}; + +struct _ClutterContrastEffectClass +{ + ClutterOffscreenEffectClass parent_class; +}; + +/* Contrast effects in GLSL. + */ +static const gchar *contrast_glsl_shader = +"uniform sampler2D tex;\n" +"uniform vec3 contrast;\n" +"\n" +"void main ()\n" +"{\n" +" vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy));\n" +" vec3 effect = vec3 (color);\n" +"\n" +" if (effect.r < 0.5)\n" +" effect.r = clamp (effect.r - contrast.r, 0.0, 0.5);\n" +" else\n" +" effect.r = clamp (effect.r + contrast.r, 0.5, 1.0);\n" +"\n" +" if (effect.g < 0.5)\n" +" effect.g = clamp (effect.g - contrast.g, 0.0, 0.5);\n" +" else\n" +" effect.g = clamp (effect.g + contrast.g, 0.5, 1.0);\n" +"\n" +" if (effect.b < 0.5)\n" +" effect.b = clamp (effect.b - contrast.b, 0.0, 0.5);\n" +" else\n" +" effect.b = clamp (effect.b + contrast.b, 0.5, 1.0);\n" +"\n" +" cogl_color_out = vec4 (effect, color.a);\n" +"}\n"; + +/* No contrast change. */ +static const ClutterColor same_contrast = { 0x7f, 0x7f, 0x7f, 0xff }; + +enum +{ + PROP_0, + + PROP_CONTRAST, + + PROP_LAST +}; + +static GParamSpec *obj_props[PROP_LAST]; + +G_DEFINE_TYPE (ClutterContrastEffect, + clutter_contrast_effect, + CLUTTER_TYPE_OFFSCREEN_EFFECT); + +static gboolean +clutter_contrast_effect_pre_paint (ClutterEffect *effect) +{ + ClutterContrastEffect *self = CLUTTER_CONTRAST_EFFECT (effect); + ClutterEffectClass *parent_class; + + if (!clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (effect))) + return FALSE; + + self->actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (effect)); + if (self->actor == NULL) + return FALSE; + + if (!clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL)) + { + /* if we don't have support for GLSL shaders then we + * forcibly disable the ActorMeta + */ + g_warning ("Unable to use the ShaderEffect: the graphics hardware " + "or the current GL driver does not implement support " + "for the GLSL shading language."); + clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (effect), FALSE); + return FALSE; + } + + if (self->shader == COGL_INVALID_HANDLE) + { + self->shader = cogl_create_shader (COGL_SHADER_TYPE_FRAGMENT); + cogl_shader_source (self->shader, contrast_glsl_shader); + + self->is_compiled = FALSE; + self->tex_uniform = -1; + self->contrast_uniform = -1; + } + + if (self->program == COGL_INVALID_HANDLE) + self->program = cogl_create_program (); + + if (!self->is_compiled) + { + g_assert (self->shader != COGL_INVALID_HANDLE); + g_assert (self->program != COGL_INVALID_HANDLE); + + cogl_shader_compile (self->shader); + if (!cogl_shader_is_compiled (self->shader)) + { + gchar *log_buf = cogl_shader_get_info_log (self->shader); + + g_warning (G_STRLOC ": Unable to compile the contrast effects shader: %s", + log_buf); + g_free (log_buf); + + cogl_handle_unref (self->shader); + cogl_handle_unref (self->program); + + self->shader = COGL_INVALID_HANDLE; + self->program = COGL_INVALID_HANDLE; + } + else + { + cogl_program_attach_shader (self->program, self->shader); + cogl_program_link (self->program); + + cogl_handle_unref (self->shader); + + self->is_compiled = TRUE; + + self->tex_uniform = + cogl_program_get_uniform_location (self->program, "tex"); + self->contrast_uniform = + cogl_program_get_uniform_location (self->program, "contrast"); + } + } + + parent_class = CLUTTER_EFFECT_CLASS (clutter_contrast_effect_parent_class); + return parent_class->pre_paint (effect); +} + +static void +clutter_contrast_effect_paint_target (ClutterOffscreenEffect *effect) +{ + ClutterContrastEffect *self = CLUTTER_CONTRAST_EFFECT (effect); + ClutterOffscreenEffectClass *parent; + CoglHandle material; + + if (self->program == COGL_INVALID_HANDLE) + goto out; + + if (self->tex_uniform > -1) + cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0); + + if (self->contrast_uniform > -1) + { + float contrast[3] = { + (self->contrast.red / 255.0) - 0.5, + (self->contrast.green / 255.0) - 0.5, + (self->contrast.blue / 255.0) - 0.5 + }; + cogl_program_set_uniform_float (self->program, self->contrast_uniform, + 3, 1, + contrast); + } + + material = clutter_offscreen_effect_get_target (effect); + cogl_material_set_user_program (material, self->program); + +out: + parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (clutter_contrast_effect_parent_class); + parent->paint_target (effect); +} + +static void +clutter_contrast_effect_dispose (GObject *gobject) +{ + ClutterContrastEffect *self = CLUTTER_CONTRAST_EFFECT (gobject); + + if (self->program != COGL_INVALID_HANDLE) + { + cogl_handle_unref (self->program); + + self->program = COGL_INVALID_HANDLE; + self->shader = COGL_INVALID_HANDLE; + } + + self->actor = NULL; + + G_OBJECT_CLASS (clutter_contrast_effect_parent_class)->dispose (gobject); +} + +static void +clutter_contrast_effect_set_property (GObject *gobject, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + ClutterContrastEffect *effect = CLUTTER_CONTRAST_EFFECT (gobject); + + switch (prop_id) + { + case PROP_CONTRAST: + clutter_contrast_effect_set_contrast (effect, + clutter_value_get_color (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); + break; + } +} + +static void +clutter_contrast_effect_get_property (GObject *gobject, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + ClutterContrastEffect *effect = CLUTTER_CONTRAST_EFFECT (gobject); + ClutterColor contrast; + + switch (prop_id) + { + case PROP_CONTRAST: + clutter_contrast_effect_get_contrast (effect, &contrast); + clutter_value_set_color (value, &contrast); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); + break; + } +} + +static void +clutter_contrast_effect_class_init (ClutterContrastEffectClass *klass) +{ + ClutterEffectClass *effect_class = CLUTTER_EFFECT_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + ClutterOffscreenEffectClass *offscreen_class; + + offscreen_class = CLUTTER_OFFSCREEN_EFFECT_CLASS (klass); + offscreen_class->paint_target = clutter_contrast_effect_paint_target; + + effect_class->pre_paint = clutter_contrast_effect_pre_paint; + + gobject_class->set_property = clutter_contrast_effect_set_property; + gobject_class->get_property = clutter_contrast_effect_get_property; + gobject_class->dispose = clutter_contrast_effect_dispose; + + /** + * ClutterContrastEffect:contrast: + * + * The contrast change to apply to the actor + * + * Since: 1.10 + */ + obj_props[PROP_CONTRAST] = + clutter_param_spec_color ("contrast", + P_("Contrast"), + P_("The contrast change to apply"), + &same_contrast, + G_PARAM_READWRITE); + + g_object_class_install_properties (gobject_class, PROP_LAST, obj_props); +} + +static void +clutter_contrast_effect_init (ClutterContrastEffect *self) +{ + self->contrast = same_contrast; +} + +/** + * clutter_contrast_effect_new: + * + * Creates a new #ClutterContrastEffect to be used with + * clutter_actor_add_effect() + * + * Return value: (transfer full): the newly created #ClutterContrastEffect or + * %NULL. User g_object_unref() when done. + * + * Since: 1.10 + */ +ClutterEffect * +clutter_contrast_effect_new (void) +{ + return g_object_new (CLUTTER_TYPE_CONTRAST_EFFECT, + NULL); +} + +/** + * clutter_contrast_effect_set_contrast: + * @effect: a #ClutterContrastEffect + * @contrast: A ClutterColor governing the change in contrast. + * + * Add or subtract each of the red, green, blue components of the @contrast to + * the red, greeen, or blue component of the actor's colors. If the actor's + * color is less than the midpoint, subtract the contrast; otherwise, add the + * contrast. + * + * Since: 1.10 + */ +void +clutter_contrast_effect_set_contrast (ClutterContrastEffect *effect, + const ClutterColor *contrast) +{ + g_return_if_fail (CLUTTER_IS_CONTRAST_EFFECT (effect)); + + if (clutter_color_equal (&effect->contrast, contrast)) + return; + + effect->contrast = *contrast; + + if (effect->actor != NULL) + clutter_actor_queue_redraw (effect->actor); +} + +/** + * clutter_contrast_effect_get_contrast: + * @effect: a #ClutterContrastEffect + * @contrast: (out caller-allocates): return location for the contrast change. + * + * Retrieves the contrast value used by @effect + * + * Since 1.10 + */ +void +clutter_contrast_effect_get_contrast (ClutterContrastEffect *effect, + ClutterColor *contrast) +{ + g_return_if_fail (CLUTTER_IS_CONTRAST_EFFECT (effect)); + g_return_if_fail (contrast != NULL); + + *contrast = effect->contrast; +} diff --git a/clutter/clutter-contrast-effect.h b/clutter/clutter-contrast-effect.h new file mode 100644 index 000000000..d99f22f78 --- /dev/null +++ b/clutter/clutter-contrast-effect.h @@ -0,0 +1,63 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright (C) 2010, 2011 Inclusive Design Research Centre, OCAD University. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Author: + * Joseph Scheuhammer + */ + +#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef __CLUTTER_CONTRAST_EFFECT_H__ +#define __CLUTTER_CONTRAST_EFFECT_H__ + +#include +#include + +G_BEGIN_DECLS + +#define CLUTTER_TYPE_CONTRAST_EFFECT (clutter_contrast_effect_get_type ()) +#define CLUTTER_CONTRAST_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_CONTRAST_EFFECT, ClutterContrastEffect)) +#define CLUTTER_IS_CONTRAST_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_CONTRAST_EFFECT)) + +/** + * ClutterContrastEffect: + * + * ClutterContrastEffect is an opaque structure + * whose members cannot be directly accessed + * + * Since: 1.10 + */ +typedef struct _ClutterContrastEffect ClutterContrastEffect; +typedef struct _ClutterContrastEffectClass ClutterContrastEffectClass; + +GType clutter_contrast_effect_get_type (void) G_GNUC_CONST; + +ClutterEffect *clutter_contrast_effect_new (void); + +void clutter_contrast_effect_set_contrast (ClutterContrastEffect *effect, + const ClutterColor *contrast); +void clutter_contrast_effect_get_contrast (ClutterContrastEffect *effect, + ClutterColor *contrast); + +G_END_DECLS + +#endif /* __CLUTTER_CONTRAST_EFFECT_H__ */ diff --git a/clutter/clutter-invert-lightness-effect.c b/clutter/clutter-invert-lightness-effect.c new file mode 100644 index 000000000..3bdeb2c64 --- /dev/null +++ b/clutter/clutter-invert-lightness-effect.c @@ -0,0 +1,243 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright (C) 2010, 2011 Inclusive Design Research Centre, OCAD University. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Author: + * Joseph Scheuhammer + */ + +/** + * SECTION:clutter-invert-lightness-effect + * @short_description: A colorization effect where lightness is inverted but + * color is not. + * @see_also: #ClutterEffect, #ClutterOffscreenEffect + * + * #ClutterInvertLightnessEffect is a sub-class of #ClutterEffect that enhances + * the appearance of a clutter actor. Specifically it inverts the lightness + * of a #ClutterActor (e.g., darker colors become lighter, white becomes black, + * and white, black). + * + * #ClutterInvertLightnessEffect is available since Clutter 1.10 + */ + +#define CLUTTER_INVERT_LIGHTNESS_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT, ClutterInvertLightnessEffectClass)) +#define CLUTTER_IS_INVERT_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT)) +#define CLUTTER_INVERT_LIGHTNESS_EFFECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_INVERT_LIGHTNESS_EFFEC, ClutterInvertLightnessEffectClass)) + +#include "clutter-invert-lightness-effect.h" + +#include "clutter-actor.h" +#include "clutter-feature.h" +#include "clutter-offscreen-effect.h" + +struct _ClutterInvertLightnessEffect +{ + ClutterOffscreenEffect parent_instance; + + /* a back pointer to our actor, so that we can query it */ + ClutterActor *actor; + + CoglHandle shader; + CoglHandle program; + + gint tex_uniform; + + guint is_compiled : 1; +}; + +struct _ClutterInvertLightnessEffectClass +{ + ClutterOffscreenEffectClass parent_class; +}; + +/* Lightness inversion in GLSL. + */ +static const gchar *invert_lightness_glsl_shader = +"uniform sampler2D tex;\n" +"\n" +"void main ()\n" +"{\n" +" vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy));\n" +" vec3 effect = vec3 (color);\n" +"\n" +" float maxColor = max (color.r, max (color.g, color.b));\n" +" float minColor = min (color.r, min (color.g, color.b));\n" +" float lightness = (maxColor + minColor) / 2.0;\n" +"\n" +" float delta = (1.0 - lightness) - lightness;\n" +" effect.rgb = (effect.rgb + delta);\n" +"\n" +" cogl_color_out = vec4 (effect, color.a);\n" +"}\n"; + +G_DEFINE_TYPE (ClutterInvertLightnessEffect, + clutter_invert_lightness_effect, + CLUTTER_TYPE_OFFSCREEN_EFFECT); + +static gboolean +clutter_invert_lightness_effect_pre_paint (ClutterEffect *effect) +{ + ClutterInvertLightnessEffect *self = CLUTTER_INVERT_LIGHTNESS_EFFECT (effect); + ClutterEffectClass *parent_class; + + if (!clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (effect))) + return FALSE; + + self->actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (effect)); + if (self->actor == NULL) + return FALSE; + + if (!clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL)) + { + /* if we don't have support for GLSL shaders then we + * forcibly disable the ActorMeta + */ + g_warning ("Unable to use the ShaderEffect: the graphics hardware " + "or the current GL driver does not implement support " + "for the GLSL shading language."); + clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (effect), FALSE); + return FALSE; + } + + if (self->shader == COGL_INVALID_HANDLE) + { + self->shader = cogl_create_shader (COGL_SHADER_TYPE_FRAGMENT); + cogl_shader_source (self->shader, invert_lightness_glsl_shader); + + self->is_compiled = FALSE; + self->tex_uniform = -1; + } + + if (self->program == COGL_INVALID_HANDLE) + self->program = cogl_create_program (); + + if (!self->is_compiled) + { + g_assert (self->shader != COGL_INVALID_HANDLE); + g_assert (self->program != COGL_INVALID_HANDLE); + + cogl_shader_compile (self->shader); + if (!cogl_shader_is_compiled (self->shader)) + { + gchar *log_buf = cogl_shader_get_info_log (self->shader); + + g_warning (G_STRLOC ": Unable to compile the invert-lightness effects shader: %s", + log_buf); + g_free (log_buf); + + cogl_handle_unref (self->shader); + cogl_handle_unref (self->program); + + self->shader = COGL_INVALID_HANDLE; + self->program = COGL_INVALID_HANDLE; + } + else + { + cogl_program_attach_shader (self->program, self->shader); + cogl_program_link (self->program); + + cogl_handle_unref (self->shader); + + self->is_compiled = TRUE; + + self->tex_uniform = + cogl_program_get_uniform_location (self->program, "tex"); + } + } + + parent_class = CLUTTER_EFFECT_CLASS (clutter_invert_lightness_effect_parent_class); + return parent_class->pre_paint (effect); +} + +static void +clutter_invert_lightness_effect_paint_target (ClutterOffscreenEffect *effect) +{ + ClutterInvertLightnessEffect *self = CLUTTER_INVERT_LIGHTNESS_EFFECT (effect); + ClutterOffscreenEffectClass *parent; + CoglHandle material; + + if (self->program == COGL_INVALID_HANDLE) + goto out; + + if (self->tex_uniform > -1) + cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0); + + material = clutter_offscreen_effect_get_target (effect); + cogl_material_set_user_program (material, self->program); + +out: + parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (clutter_invert_lightness_effect_parent_class); + parent->paint_target (effect); +} + +static void +clutter_invert_lightness_effect_dispose (GObject *gobject) +{ + ClutterInvertLightnessEffect *self = CLUTTER_INVERT_LIGHTNESS_EFFECT (gobject); + + if (self->program != COGL_INVALID_HANDLE) + { + cogl_handle_unref (self->program); + + self->program = COGL_INVALID_HANDLE; + self->shader = COGL_INVALID_HANDLE; + } + + self->actor = NULL; + + G_OBJECT_CLASS (clutter_invert_lightness_effect_parent_class)->dispose (gobject); +} + +static void +clutter_invert_lightness_effect_class_init (ClutterInvertLightnessEffectClass *klass) +{ + ClutterEffectClass *effect_class = CLUTTER_EFFECT_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + ClutterOffscreenEffectClass *offscreen_class; + + offscreen_class = CLUTTER_OFFSCREEN_EFFECT_CLASS (klass); + offscreen_class->paint_target = clutter_invert_lightness_effect_paint_target; + + effect_class->pre_paint = clutter_invert_lightness_effect_pre_paint; + + gobject_class->dispose = clutter_invert_lightness_effect_dispose; +} + +static void +clutter_invert_lightness_effect_init (ClutterInvertLightnessEffect *self) +{ +} + +/** + * clutter_invert_lightness_effect_new: + * + * Creates a new #ClutterInvertLightnessEffect to be used with + * clutter_actor_add_effect() + * + * Return value: (transfer full): the newly created + * #ClutterInvertLightnessEffect or %NULL. Use g_object_unref() when done. + * + * Since: 1.10 + */ +ClutterEffect * +clutter_invert_lightness_effect_new (void) +{ + return g_object_new (CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT, + NULL); +} diff --git a/clutter/clutter-invert-lightness-effect.h b/clutter/clutter-invert-lightness-effect.h new file mode 100644 index 000000000..cc54415ff --- /dev/null +++ b/clutter/clutter-invert-lightness-effect.h @@ -0,0 +1,57 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright (C) 2010, 2011 Inclusive Design Research Centre, OCAD University. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Author: + * Joseph Scheuhammer + */ + +#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef __CLUTTER_INVERT_LIGHTNESS_EFFECT_H__ +#define __CLUTTER_INVERT_LIGHTNESS_EFFECT_H__ + +#include + +G_BEGIN_DECLS + +#define CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT (clutter_invert_lightness_effect_get_type ()) +#define CLUTTER_INVERT_LIGHTNESS_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT, ClutterInvertLightnessEffect)) +#define CLUTTER_IS_INVERT_LIGHTNESS_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT)) + +/** + * ClutterInvertLightnessEffect: + * + * ClutterInvertLightnessEffect is an opaque structure + * whose members cannot be directly accessed + * + * Since: 1.10 + */ +typedef struct _ClutterInvertLightnessEffect ClutterInvertLightnessEffect; +typedef struct _ClutterInvertLightnessEffectClass ClutterInvertLightnessEffectClass; + +GType clutter_invert_lightness_effect_get_type (void) G_GNUC_CONST; + +ClutterEffect *clutter_invert_lightness_effect_new (void); + +G_END_DECLS + +#endif /* __CLUTTER_INVERT_LIGHTNESS_EFFECT_H__ */ diff --git a/doc/reference/clutter/clutter-docs.xml.in b/doc/reference/clutter/clutter-docs.xml.in index 7a2c7b5cc..16f865651 100644 --- a/doc/reference/clutter/clutter-docs.xml.in +++ b/doc/reference/clutter/clutter-docs.xml.in @@ -120,8 +120,11 @@ + + + diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt index 2354712c2..5765c3b95 100644 --- a/doc/reference/clutter/clutter-sections.txt +++ b/doc/reference/clutter/clutter-sections.txt @@ -2640,6 +2640,53 @@ ClutterPageTurnEffectClass clutter_page_turn_effect_get_type +
+ClutterBrightnessEffect +clutter-brightness-effect +ClutterBrightnessEffect +clutter_brightness_effect_new +clutter_brightness_effect_set_brightness +clutter_brightness_effect_get_brightness + +CLUTTER_TYPE_BRIGHTNESS_EFFECT +CLUTTER_BRIGHTNESS_EFFECT +CLUTTER_IS_BRIGHTNESS_EFFECT + +ClutterBrightnessEffectClass +clutter_brightness_effect_get_type +
+ +
+ClutterContrastEffect +clutter-contrast-effect +ClutterContrastEffect +clutter_contrast_effect_new +clutter_contrast_effect_set_contrast +clutter_contrast_effect_get_contrast + +CLUTTER_TYPE_CONTRAST_EFFECT +CLUTTER_CONTRAST_EFFECT +CLUTTER_IS_CONTRAST_EFFECT + +ClutterContrastEffectClass +clutter_contrast_effect_get_type +
+ +
+ClutterInvertLightnessEffect +clutter-invert-lightness-effect +ClutterInvertLightnessEffect +clutter_contrast_effect_new + +CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT +CLUTTER_INVERT_LIGHTNESS_EFFECT +CLUTTER_IS_INVERT_LIGHTNESS_EFFECT + +ClutterInvertLightnessEffectClass +clutter_invert_lightness_effect_get_type +
+ +
clutter-settings ClutterSettings diff --git a/doc/reference/clutter/clutter.types b/doc/reference/clutter/clutter.types index 8fc224c75..a8ae0a5f4 100644 --- a/doc/reference/clutter/clutter.types +++ b/doc/reference/clutter/clutter.types @@ -21,12 +21,14 @@ clutter_bin_layout_get_type clutter_blur_effect_get_type clutter_box_get_type clutter_box_layout_get_type +clutter_brightness_effect_get_type clutter_cairo_texture_get_type clutter_child_meta_get_type clutter_click_action_get_type clutter_clone_get_type clutter_colorize_effect_get_type clutter_constraint_get_type +clutter_contrast_effect_get_type clutter_deform_effect_get_type clutter_desaturate_effect_get_type clutter_device_manager_get_type @@ -39,6 +41,7 @@ clutter_gesture_action_get_type clutter_group_get_type clutter_input_device_get_type clutter_interval_get_type +clutter_invert_lightness_effect_get_type clutter_layout_manager_get_type clutter_layout_meta_get_type clutter_list_model_get_type From b1fbbe23b43f56da9cbd515e92ef44a8f7b31aa2 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 28 Sep 2011 15:54:32 +0100 Subject: [PATCH 10/11] Revert "Add lightness, brightness, and contrast effects" Discussed a bit with Neil, and I might have jumped the gun a little. We might want a different API for 1.10. See comment 12 on: https://bugzilla.gnome.org/show_bug.cgi?id=656156 This reverts commit 4829ae1c79f1ae60d562621b81a7be800e0697bb. --- clutter/Makefile.am | 6 - clutter/clutter-brightness-effect.c | 380 -------------------- clutter/clutter-brightness-effect.h | 63 ---- clutter/clutter-contrast-effect.c | 395 --------------------- clutter/clutter-contrast-effect.h | 63 ---- clutter/clutter-invert-lightness-effect.c | 243 ------------- clutter/clutter-invert-lightness-effect.h | 57 --- doc/reference/clutter/clutter-docs.xml.in | 3 - doc/reference/clutter/clutter-sections.txt | 47 --- doc/reference/clutter/clutter.types | 3 - 10 files changed, 1260 deletions(-) delete mode 100644 clutter/clutter-brightness-effect.c delete mode 100644 clutter/clutter-brightness-effect.h delete mode 100644 clutter/clutter-contrast-effect.c delete mode 100644 clutter/clutter-contrast-effect.h delete mode 100644 clutter/clutter-invert-lightness-effect.c delete mode 100644 clutter/clutter-invert-lightness-effect.h diff --git a/clutter/Makefile.am b/clutter/Makefile.am index cf37c4d83..d9b81a8c5 100644 --- a/clutter/Makefile.am +++ b/clutter/Makefile.am @@ -71,7 +71,6 @@ source_h = \ $(srcdir)/clutter-blur-effect.h \ $(srcdir)/clutter-box.h \ $(srcdir)/clutter-box-layout.h \ - $(srcdir)/clutter-brightness-effect.h \ $(srcdir)/clutter-cairo-texture.h \ $(srcdir)/clutter-child-meta.h \ $(srcdir)/clutter-click-action.h \ @@ -81,7 +80,6 @@ source_h = \ $(srcdir)/clutter-colorize-effect.h \ $(srcdir)/clutter-constraint.h \ $(srcdir)/clutter-container.h \ - $(srcdir)/clutter-contrast-effect.h \ $(srcdir)/clutter-deform-effect.h \ $(srcdir)/clutter-deprecated.h \ $(srcdir)/clutter-desaturate-effect.h \ @@ -98,7 +96,6 @@ source_h = \ $(srcdir)/clutter-gesture-action.h \ $(srcdir)/clutter-group.h \ $(srcdir)/clutter-input-device.h \ - $(srcdir)/clutter-invert-lightness-effect.h \ $(srcdir)/clutter-interval.h \ $(srcdir)/clutter-keysyms.h \ $(srcdir)/clutter-keysyms-compat.h \ @@ -161,7 +158,6 @@ source_c = \ $(srcdir)/clutter-blur-effect.c \ $(srcdir)/clutter-box.c \ $(srcdir)/clutter-box-layout.c \ - $(srcdir)/clutter-brightness-effect.c \ $(srcdir)/clutter-cairo-texture.c \ $(srcdir)/clutter-child-meta.c \ $(srcdir)/clutter-click-action.c \ @@ -170,7 +166,6 @@ source_c = \ $(srcdir)/clutter-colorize-effect.c \ $(srcdir)/clutter-constraint.c \ $(srcdir)/clutter-container.c \ - $(srcdir)/clutter-contrast-effect.c \ $(srcdir)/clutter-deform-effect.c \ $(srcdir)/clutter-desaturate-effect.c \ $(srcdir)/clutter-device-manager.c \ @@ -187,7 +182,6 @@ source_c = \ $(srcdir)/clutter-gesture-action.c \ $(srcdir)/clutter-group.c \ $(srcdir)/clutter-input-device.c \ - $(srcdir)/clutter-invert-lightness-effect.c \ $(srcdir)/clutter-interval.c \ $(srcdir)/clutter-keysyms-table.c \ $(srcdir)/clutter-layout-manager.c \ diff --git a/clutter/clutter-brightness-effect.c b/clutter/clutter-brightness-effect.c deleted file mode 100644 index 989115635..000000000 --- a/clutter/clutter-brightness-effect.c +++ /dev/null @@ -1,380 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Copyright (C) 2010, 2011 Inclusive Design Research Centre, OCAD University. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * Author: - * Joseph Scheuhammer - */ - -/** - * SECTION:clutter-brightness-effect - * @short_description: Increase/decrease brightness of actor. - * @see_also: #ClutterEffect, #ClutterOffscreenEffect - * - * #ClutterBrightnessEffect is a sub-class of #ClutterEffect that changes the - * overall brightness of a #ClutterActor. - * - * #ClutterBrightnessEffect is available since Clutter 1.10 - */ - -#define CLUTTER_BRIGHTNESS_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_BRIGHTNESS_EFFECT, ClutterBrightnessEffectClass)) -#define CLUTTER_IS_BRIGHTNESS_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_BRIGHTNESS_EFFECT)) -#define CLUTTER_BRIGHTNESS_EFFECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_BRIGHTNESS_EFFECT, ClutterBrightnessEffectClass)) - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "clutter-brightness-effect.h" - -#include "clutter-actor.h" -#include "clutter-feature.h" -#include "clutter-offscreen-effect.h" -#include "clutter-private.h" - -struct _ClutterBrightnessEffect -{ - ClutterOffscreenEffect parent_instance; - - /* a back pointer to our actor, so that we can query it */ - ClutterActor *actor; - - CoglHandle shader; - CoglHandle program; - - /* Brightness changes. */ - ClutterColor brightness; - - gint tex_uniform; - gint brightness_uniform; - - guint is_compiled : 1; -}; - -struct _ClutterBrightnessEffectClass -{ - ClutterOffscreenEffectClass parent_class; -}; - -/* Brightness effects in GLSL. - */ -static const gchar *brightness_glsl_shader = -"uniform sampler2D tex;\n" -"uniform vec3 brightness;\n" -"\n" -"void main ()\n" -"{\n" -" vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy));\n" -" vec3 effect = vec3 (color);\n" -"\n" -" effect = clamp (effect + brightness, 0.0, 1.0);\n" -"\n" -"\n" -" cogl_color_out = vec4 (effect, color.a);\n" -"}\n"; - -/* No brightness change. */ -static const ClutterColor same_brightness = { 0x7f, 0x7f, 0x7f, 0xff }; - -enum -{ - PROP_0, - - PROP_BRIGHTNESS, - - PROP_LAST -}; - -static GParamSpec *obj_props[PROP_LAST]; - -G_DEFINE_TYPE (ClutterBrightnessEffect, - clutter_brightness_effect, - CLUTTER_TYPE_OFFSCREEN_EFFECT); - -static gboolean -clutter_brightness_effect_pre_paint (ClutterEffect *effect) -{ - ClutterBrightnessEffect *self = CLUTTER_BRIGHTNESS_EFFECT (effect); - ClutterEffectClass *parent_class; - - if (!clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (effect))) - return FALSE; - - self->actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (effect)); - if (self->actor == NULL) - return FALSE; - - if (!clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL)) - { - /* if we don't have support for GLSL shaders then we - * forcibly disable the ActorMeta - */ - g_warning ("Unable to use the ShaderEffect: the graphics hardware " - "or the current GL driver does not implement support " - "for the GLSL shading language."); - clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (effect), FALSE); - return FALSE; - } - - if (self->shader == COGL_INVALID_HANDLE) - { - self->shader = cogl_create_shader (COGL_SHADER_TYPE_FRAGMENT); - cogl_shader_source (self->shader, brightness_glsl_shader); - - self->is_compiled = FALSE; - self->tex_uniform = -1; - self->brightness_uniform = -1; - } - - if (self->program == COGL_INVALID_HANDLE) - self->program = cogl_create_program (); - - if (!self->is_compiled) - { - g_assert (self->shader != COGL_INVALID_HANDLE); - g_assert (self->program != COGL_INVALID_HANDLE); - - cogl_shader_compile (self->shader); - if (!cogl_shader_is_compiled (self->shader)) - { - gchar *log_buf = cogl_shader_get_info_log (self->shader); - - g_warning (G_STRLOC ": Unable to compile the brightness effects shader: %s", - log_buf); - g_free (log_buf); - - cogl_handle_unref (self->shader); - cogl_handle_unref (self->program); - - self->shader = COGL_INVALID_HANDLE; - self->program = COGL_INVALID_HANDLE; - } - else - { - cogl_program_attach_shader (self->program, self->shader); - cogl_program_link (self->program); - - cogl_handle_unref (self->shader); - - self->is_compiled = TRUE; - - self->tex_uniform = - cogl_program_get_uniform_location (self->program, "tex"); - self->brightness_uniform = - cogl_program_get_uniform_location (self->program, "brightness"); - } - } - - parent_class = CLUTTER_EFFECT_CLASS (clutter_brightness_effect_parent_class); - return parent_class->pre_paint (effect); -} - -static void -clutter_brightness_effect_paint_target (ClutterOffscreenEffect *effect) -{ - ClutterBrightnessEffect *self = CLUTTER_BRIGHTNESS_EFFECT (effect); - ClutterOffscreenEffectClass *parent; - CoglHandle material; - - if (self->program == COGL_INVALID_HANDLE) - goto out; - - if (self->tex_uniform > -1) - cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0); - - if (self->brightness_uniform > -1) - { - float brightness[3] = { - (self->brightness.red / 127.0) - 1.0, - (self->brightness.green / 127.0) - 1.0, - (self->brightness.blue / 127.0) - 1.0 - }; - cogl_program_set_uniform_float (self->program, self->brightness_uniform, - 3, 1, - brightness); - } - - material = clutter_offscreen_effect_get_target (effect); - cogl_material_set_user_program (material, self->program); - -out: - parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (clutter_brightness_effect_parent_class); - parent->paint_target (effect); -} - -static void -clutter_brightness_effect_dispose (GObject *gobject) -{ - ClutterBrightnessEffect *self = CLUTTER_BRIGHTNESS_EFFECT (gobject); - - if (self->program != COGL_INVALID_HANDLE) - { - cogl_handle_unref (self->program); - - self->program = COGL_INVALID_HANDLE; - self->shader = COGL_INVALID_HANDLE; - } - - self->actor = NULL; - - G_OBJECT_CLASS (clutter_brightness_effect_parent_class)->dispose (gobject); -} - -static void -clutter_brightness_effect_set_property (GObject *gobject, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - ClutterBrightnessEffect *effect = CLUTTER_BRIGHTNESS_EFFECT (gobject); - - switch (prop_id) - { - case PROP_BRIGHTNESS: - clutter_brightness_effect_set_brightness (effect, - clutter_value_get_color (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); - break; - } -} - -static void -clutter_brightness_effect_get_property (GObject *gobject, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - ClutterBrightnessEffect *effect = CLUTTER_BRIGHTNESS_EFFECT (gobject); - ClutterColor brightness; - - switch (prop_id) - { - case PROP_BRIGHTNESS: - clutter_brightness_effect_get_brightness (effect, &brightness); - clutter_value_set_color (value, &brightness); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); - break; - } -} - -static void -clutter_brightness_effect_class_init (ClutterBrightnessEffectClass *klass) -{ - ClutterEffectClass *effect_class = CLUTTER_EFFECT_CLASS (klass); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - ClutterOffscreenEffectClass *offscreen_class; - - offscreen_class = CLUTTER_OFFSCREEN_EFFECT_CLASS (klass); - offscreen_class->paint_target = clutter_brightness_effect_paint_target; - - effect_class->pre_paint = clutter_brightness_effect_pre_paint; - - gobject_class->set_property = clutter_brightness_effect_set_property; - gobject_class->get_property = clutter_brightness_effect_get_property; - gobject_class->dispose = clutter_brightness_effect_dispose; - - /** - * ClutterBrightnessEffect:brightness: - * - * The brightness change to apply to the actor - * - * Since: 1.10 - */ - obj_props[PROP_BRIGHTNESS] = - clutter_param_spec_color ("brightness", - P_("Brightness"), - P_("The brightness change to apply"), - &same_brightness, - G_PARAM_READWRITE); - - g_object_class_install_properties (gobject_class, PROP_LAST, obj_props); -} - -static void -clutter_brightness_effect_init (ClutterBrightnessEffect *self) -{ - self->brightness = same_brightness; -} - -/** - * clutter_brightness_effect_new: - * - * Creates a new #ClutterBrightnessEffect to be used with - * clutter_actor_add_effect() - * - * Return value: (transfer full): the newly created #ClutterBrightnessEffect or - * or %NULL. Use g_object_unref() when done. - * - * Since: 1.10 - */ -ClutterEffect * -clutter_brightness_effect_new (void) -{ - return g_object_new (CLUTTER_TYPE_BRIGHTNESS_EFFECT, - NULL); -} - -/** - * clutter_brightness_effect_set_brightness: - * @effect: a #ClutterBrightnessEffect - * @brightness: ClutterColor governing the brightness change. - * - * Add each of the red, green, blue components of the @brightness to - * the red, greeen, or blue components of the actor's colors. - * - * Since: 1.10 - */ -void -clutter_brightness_effect_set_brightness (ClutterBrightnessEffect *effect, - const ClutterColor *brightness) -{ - g_return_if_fail (CLUTTER_IS_BRIGHTNESS_EFFECT (effect)); - if (clutter_color_equal (&effect->brightness, brightness)) - return; - - effect->brightness = *brightness; - - if (effect->actor != NULL) - clutter_actor_queue_redraw (effect->actor); -} - -/** - * clutter_brightness_effect_get_brightness: - * @effect: a #ClutterBrightnessEffect - * @brightness: (out caller-allocates): return location for the brightness. - * - * Retrieves the brightness value used by @effect - * - * Since: 1.10 - */ -void -clutter_brightness_effect_get_brightness (ClutterBrightnessEffect *effect, - ClutterColor *brightness) -{ - g_return_if_fail (CLUTTER_IS_BRIGHTNESS_EFFECT (effect)); - g_return_if_fail (brightness != NULL); - - *brightness = effect->brightness; -} diff --git a/clutter/clutter-brightness-effect.h b/clutter/clutter-brightness-effect.h deleted file mode 100644 index 6b6fe3b61..000000000 --- a/clutter/clutter-brightness-effect.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Copyright (C) 2010, 2011 Inclusive Design Research Centre, OCAD University. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * Author: - * Joseph Scheuhammer - */ - -#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) -#error "Only can be included directly." -#endif - -#ifndef __CLUTTER_BRIGHTNESS_EFFECT_H__ -#define __CLUTTER_BRIGHTNESS_EFFECT_H__ - -#include -#include - -G_BEGIN_DECLS - -#define CLUTTER_TYPE_BRIGHTNESS_EFFECT (clutter_brightness_effect_get_type ()) -#define CLUTTER_BRIGHTNESS_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_BRIGHTNESS_EFFECT, ClutterBrightnessEffect)) -#define CLUTTER_IS_BRIGHTNESS_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_BRIGHTNESS_EFFECT)) - -/** - * ClutterBrightnessEffect: - * - * ClutterBrightnessEffect is an opaque structure - * whose members cannot be directly accessed - * - * Since: 1.10 - */ -typedef struct _ClutterBrightnessEffect ClutterBrightnessEffect; -typedef struct _ClutterBrightnessEffectClass ClutterBrightnessEffectClass; - -GType clutter_brightness_effect_get_type (void) G_GNUC_CONST; - -ClutterEffect *clutter_brightness_effect_new (void); - -void clutter_brightness_effect_set_brightness (ClutterBrightnessEffect *effect, - const ClutterColor *brightness); -void clutter_brightness_effect_get_brightness (ClutterBrightnessEffect *effect, - ClutterColor *brightness); - -G_END_DECLS - -#endif /* __CLUTTER_BRIGHTNESS_EFFECT_H__ */ diff --git a/clutter/clutter-contrast-effect.c b/clutter/clutter-contrast-effect.c deleted file mode 100644 index 98a2d9079..000000000 --- a/clutter/clutter-contrast-effect.c +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Copyright (C) 2010, 2011 Inclusive Design Research Centre, OCAD University. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * Author: - * Joseph Scheuhammer - */ - -/** - * SECTION:clutter-contrast-effect - * @short_description: Increase/decrease contrast of actor. - * @see_also: #ClutterEffect, #ClutterOffscreenEffect - * - * #ClutterContrastEffect is a sub-class of #ClutterEffect that changes the - * overall contrast of a #ClutterActor. - * - * #ClutterContrastEffect is available since Clutter 1.10 - */ - -#define CLUTTER_CONTRAST_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_CONTRAST_EFFECT, ClutterContrastEffectClass)) -#define CLUTTER_IS_CONTRAST_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_CONTRAST_EFFECT)) -#define CLUTTER_CONTRAST_EFFECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_CONTRAST_EFFECT, ClutterContrastEffectClass)) - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "clutter-contrast-effect.h" - -#include "clutter-actor.h" -#include "clutter-feature.h" -#include "clutter-offscreen-effect.h" -#include "clutter-private.h" - -struct _ClutterContrastEffect -{ - ClutterOffscreenEffect parent_instance; - - /* a back pointer to our actor, so that we can query it */ - ClutterActor *actor; - - CoglHandle shader; - CoglHandle program; - - /* Contrast changes. */ - ClutterColor contrast; - - gint tex_uniform; - gint contrast_uniform; - - guint is_compiled : 1; -}; - -struct _ClutterContrastEffectClass -{ - ClutterOffscreenEffectClass parent_class; -}; - -/* Contrast effects in GLSL. - */ -static const gchar *contrast_glsl_shader = -"uniform sampler2D tex;\n" -"uniform vec3 contrast;\n" -"\n" -"void main ()\n" -"{\n" -" vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy));\n" -" vec3 effect = vec3 (color);\n" -"\n" -" if (effect.r < 0.5)\n" -" effect.r = clamp (effect.r - contrast.r, 0.0, 0.5);\n" -" else\n" -" effect.r = clamp (effect.r + contrast.r, 0.5, 1.0);\n" -"\n" -" if (effect.g < 0.5)\n" -" effect.g = clamp (effect.g - contrast.g, 0.0, 0.5);\n" -" else\n" -" effect.g = clamp (effect.g + contrast.g, 0.5, 1.0);\n" -"\n" -" if (effect.b < 0.5)\n" -" effect.b = clamp (effect.b - contrast.b, 0.0, 0.5);\n" -" else\n" -" effect.b = clamp (effect.b + contrast.b, 0.5, 1.0);\n" -"\n" -" cogl_color_out = vec4 (effect, color.a);\n" -"}\n"; - -/* No contrast change. */ -static const ClutterColor same_contrast = { 0x7f, 0x7f, 0x7f, 0xff }; - -enum -{ - PROP_0, - - PROP_CONTRAST, - - PROP_LAST -}; - -static GParamSpec *obj_props[PROP_LAST]; - -G_DEFINE_TYPE (ClutterContrastEffect, - clutter_contrast_effect, - CLUTTER_TYPE_OFFSCREEN_EFFECT); - -static gboolean -clutter_contrast_effect_pre_paint (ClutterEffect *effect) -{ - ClutterContrastEffect *self = CLUTTER_CONTRAST_EFFECT (effect); - ClutterEffectClass *parent_class; - - if (!clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (effect))) - return FALSE; - - self->actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (effect)); - if (self->actor == NULL) - return FALSE; - - if (!clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL)) - { - /* if we don't have support for GLSL shaders then we - * forcibly disable the ActorMeta - */ - g_warning ("Unable to use the ShaderEffect: the graphics hardware " - "or the current GL driver does not implement support " - "for the GLSL shading language."); - clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (effect), FALSE); - return FALSE; - } - - if (self->shader == COGL_INVALID_HANDLE) - { - self->shader = cogl_create_shader (COGL_SHADER_TYPE_FRAGMENT); - cogl_shader_source (self->shader, contrast_glsl_shader); - - self->is_compiled = FALSE; - self->tex_uniform = -1; - self->contrast_uniform = -1; - } - - if (self->program == COGL_INVALID_HANDLE) - self->program = cogl_create_program (); - - if (!self->is_compiled) - { - g_assert (self->shader != COGL_INVALID_HANDLE); - g_assert (self->program != COGL_INVALID_HANDLE); - - cogl_shader_compile (self->shader); - if (!cogl_shader_is_compiled (self->shader)) - { - gchar *log_buf = cogl_shader_get_info_log (self->shader); - - g_warning (G_STRLOC ": Unable to compile the contrast effects shader: %s", - log_buf); - g_free (log_buf); - - cogl_handle_unref (self->shader); - cogl_handle_unref (self->program); - - self->shader = COGL_INVALID_HANDLE; - self->program = COGL_INVALID_HANDLE; - } - else - { - cogl_program_attach_shader (self->program, self->shader); - cogl_program_link (self->program); - - cogl_handle_unref (self->shader); - - self->is_compiled = TRUE; - - self->tex_uniform = - cogl_program_get_uniform_location (self->program, "tex"); - self->contrast_uniform = - cogl_program_get_uniform_location (self->program, "contrast"); - } - } - - parent_class = CLUTTER_EFFECT_CLASS (clutter_contrast_effect_parent_class); - return parent_class->pre_paint (effect); -} - -static void -clutter_contrast_effect_paint_target (ClutterOffscreenEffect *effect) -{ - ClutterContrastEffect *self = CLUTTER_CONTRAST_EFFECT (effect); - ClutterOffscreenEffectClass *parent; - CoglHandle material; - - if (self->program == COGL_INVALID_HANDLE) - goto out; - - if (self->tex_uniform > -1) - cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0); - - if (self->contrast_uniform > -1) - { - float contrast[3] = { - (self->contrast.red / 255.0) - 0.5, - (self->contrast.green / 255.0) - 0.5, - (self->contrast.blue / 255.0) - 0.5 - }; - cogl_program_set_uniform_float (self->program, self->contrast_uniform, - 3, 1, - contrast); - } - - material = clutter_offscreen_effect_get_target (effect); - cogl_material_set_user_program (material, self->program); - -out: - parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (clutter_contrast_effect_parent_class); - parent->paint_target (effect); -} - -static void -clutter_contrast_effect_dispose (GObject *gobject) -{ - ClutterContrastEffect *self = CLUTTER_CONTRAST_EFFECT (gobject); - - if (self->program != COGL_INVALID_HANDLE) - { - cogl_handle_unref (self->program); - - self->program = COGL_INVALID_HANDLE; - self->shader = COGL_INVALID_HANDLE; - } - - self->actor = NULL; - - G_OBJECT_CLASS (clutter_contrast_effect_parent_class)->dispose (gobject); -} - -static void -clutter_contrast_effect_set_property (GObject *gobject, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - ClutterContrastEffect *effect = CLUTTER_CONTRAST_EFFECT (gobject); - - switch (prop_id) - { - case PROP_CONTRAST: - clutter_contrast_effect_set_contrast (effect, - clutter_value_get_color (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); - break; - } -} - -static void -clutter_contrast_effect_get_property (GObject *gobject, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - ClutterContrastEffect *effect = CLUTTER_CONTRAST_EFFECT (gobject); - ClutterColor contrast; - - switch (prop_id) - { - case PROP_CONTRAST: - clutter_contrast_effect_get_contrast (effect, &contrast); - clutter_value_set_color (value, &contrast); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); - break; - } -} - -static void -clutter_contrast_effect_class_init (ClutterContrastEffectClass *klass) -{ - ClutterEffectClass *effect_class = CLUTTER_EFFECT_CLASS (klass); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - ClutterOffscreenEffectClass *offscreen_class; - - offscreen_class = CLUTTER_OFFSCREEN_EFFECT_CLASS (klass); - offscreen_class->paint_target = clutter_contrast_effect_paint_target; - - effect_class->pre_paint = clutter_contrast_effect_pre_paint; - - gobject_class->set_property = clutter_contrast_effect_set_property; - gobject_class->get_property = clutter_contrast_effect_get_property; - gobject_class->dispose = clutter_contrast_effect_dispose; - - /** - * ClutterContrastEffect:contrast: - * - * The contrast change to apply to the actor - * - * Since: 1.10 - */ - obj_props[PROP_CONTRAST] = - clutter_param_spec_color ("contrast", - P_("Contrast"), - P_("The contrast change to apply"), - &same_contrast, - G_PARAM_READWRITE); - - g_object_class_install_properties (gobject_class, PROP_LAST, obj_props); -} - -static void -clutter_contrast_effect_init (ClutterContrastEffect *self) -{ - self->contrast = same_contrast; -} - -/** - * clutter_contrast_effect_new: - * - * Creates a new #ClutterContrastEffect to be used with - * clutter_actor_add_effect() - * - * Return value: (transfer full): the newly created #ClutterContrastEffect or - * %NULL. User g_object_unref() when done. - * - * Since: 1.10 - */ -ClutterEffect * -clutter_contrast_effect_new (void) -{ - return g_object_new (CLUTTER_TYPE_CONTRAST_EFFECT, - NULL); -} - -/** - * clutter_contrast_effect_set_contrast: - * @effect: a #ClutterContrastEffect - * @contrast: A ClutterColor governing the change in contrast. - * - * Add or subtract each of the red, green, blue components of the @contrast to - * the red, greeen, or blue component of the actor's colors. If the actor's - * color is less than the midpoint, subtract the contrast; otherwise, add the - * contrast. - * - * Since: 1.10 - */ -void -clutter_contrast_effect_set_contrast (ClutterContrastEffect *effect, - const ClutterColor *contrast) -{ - g_return_if_fail (CLUTTER_IS_CONTRAST_EFFECT (effect)); - - if (clutter_color_equal (&effect->contrast, contrast)) - return; - - effect->contrast = *contrast; - - if (effect->actor != NULL) - clutter_actor_queue_redraw (effect->actor); -} - -/** - * clutter_contrast_effect_get_contrast: - * @effect: a #ClutterContrastEffect - * @contrast: (out caller-allocates): return location for the contrast change. - * - * Retrieves the contrast value used by @effect - * - * Since 1.10 - */ -void -clutter_contrast_effect_get_contrast (ClutterContrastEffect *effect, - ClutterColor *contrast) -{ - g_return_if_fail (CLUTTER_IS_CONTRAST_EFFECT (effect)); - g_return_if_fail (contrast != NULL); - - *contrast = effect->contrast; -} diff --git a/clutter/clutter-contrast-effect.h b/clutter/clutter-contrast-effect.h deleted file mode 100644 index d99f22f78..000000000 --- a/clutter/clutter-contrast-effect.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Copyright (C) 2010, 2011 Inclusive Design Research Centre, OCAD University. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * Author: - * Joseph Scheuhammer - */ - -#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) -#error "Only can be included directly." -#endif - -#ifndef __CLUTTER_CONTRAST_EFFECT_H__ -#define __CLUTTER_CONTRAST_EFFECT_H__ - -#include -#include - -G_BEGIN_DECLS - -#define CLUTTER_TYPE_CONTRAST_EFFECT (clutter_contrast_effect_get_type ()) -#define CLUTTER_CONTRAST_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_CONTRAST_EFFECT, ClutterContrastEffect)) -#define CLUTTER_IS_CONTRAST_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_CONTRAST_EFFECT)) - -/** - * ClutterContrastEffect: - * - * ClutterContrastEffect is an opaque structure - * whose members cannot be directly accessed - * - * Since: 1.10 - */ -typedef struct _ClutterContrastEffect ClutterContrastEffect; -typedef struct _ClutterContrastEffectClass ClutterContrastEffectClass; - -GType clutter_contrast_effect_get_type (void) G_GNUC_CONST; - -ClutterEffect *clutter_contrast_effect_new (void); - -void clutter_contrast_effect_set_contrast (ClutterContrastEffect *effect, - const ClutterColor *contrast); -void clutter_contrast_effect_get_contrast (ClutterContrastEffect *effect, - ClutterColor *contrast); - -G_END_DECLS - -#endif /* __CLUTTER_CONTRAST_EFFECT_H__ */ diff --git a/clutter/clutter-invert-lightness-effect.c b/clutter/clutter-invert-lightness-effect.c deleted file mode 100644 index 3bdeb2c64..000000000 --- a/clutter/clutter-invert-lightness-effect.c +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Copyright (C) 2010, 2011 Inclusive Design Research Centre, OCAD University. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * Author: - * Joseph Scheuhammer - */ - -/** - * SECTION:clutter-invert-lightness-effect - * @short_description: A colorization effect where lightness is inverted but - * color is not. - * @see_also: #ClutterEffect, #ClutterOffscreenEffect - * - * #ClutterInvertLightnessEffect is a sub-class of #ClutterEffect that enhances - * the appearance of a clutter actor. Specifically it inverts the lightness - * of a #ClutterActor (e.g., darker colors become lighter, white becomes black, - * and white, black). - * - * #ClutterInvertLightnessEffect is available since Clutter 1.10 - */ - -#define CLUTTER_INVERT_LIGHTNESS_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT, ClutterInvertLightnessEffectClass)) -#define CLUTTER_IS_INVERT_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT)) -#define CLUTTER_INVERT_LIGHTNESS_EFFECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_INVERT_LIGHTNESS_EFFEC, ClutterInvertLightnessEffectClass)) - -#include "clutter-invert-lightness-effect.h" - -#include "clutter-actor.h" -#include "clutter-feature.h" -#include "clutter-offscreen-effect.h" - -struct _ClutterInvertLightnessEffect -{ - ClutterOffscreenEffect parent_instance; - - /* a back pointer to our actor, so that we can query it */ - ClutterActor *actor; - - CoglHandle shader; - CoglHandle program; - - gint tex_uniform; - - guint is_compiled : 1; -}; - -struct _ClutterInvertLightnessEffectClass -{ - ClutterOffscreenEffectClass parent_class; -}; - -/* Lightness inversion in GLSL. - */ -static const gchar *invert_lightness_glsl_shader = -"uniform sampler2D tex;\n" -"\n" -"void main ()\n" -"{\n" -" vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy));\n" -" vec3 effect = vec3 (color);\n" -"\n" -" float maxColor = max (color.r, max (color.g, color.b));\n" -" float minColor = min (color.r, min (color.g, color.b));\n" -" float lightness = (maxColor + minColor) / 2.0;\n" -"\n" -" float delta = (1.0 - lightness) - lightness;\n" -" effect.rgb = (effect.rgb + delta);\n" -"\n" -" cogl_color_out = vec4 (effect, color.a);\n" -"}\n"; - -G_DEFINE_TYPE (ClutterInvertLightnessEffect, - clutter_invert_lightness_effect, - CLUTTER_TYPE_OFFSCREEN_EFFECT); - -static gboolean -clutter_invert_lightness_effect_pre_paint (ClutterEffect *effect) -{ - ClutterInvertLightnessEffect *self = CLUTTER_INVERT_LIGHTNESS_EFFECT (effect); - ClutterEffectClass *parent_class; - - if (!clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (effect))) - return FALSE; - - self->actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (effect)); - if (self->actor == NULL) - return FALSE; - - if (!clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL)) - { - /* if we don't have support for GLSL shaders then we - * forcibly disable the ActorMeta - */ - g_warning ("Unable to use the ShaderEffect: the graphics hardware " - "or the current GL driver does not implement support " - "for the GLSL shading language."); - clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (effect), FALSE); - return FALSE; - } - - if (self->shader == COGL_INVALID_HANDLE) - { - self->shader = cogl_create_shader (COGL_SHADER_TYPE_FRAGMENT); - cogl_shader_source (self->shader, invert_lightness_glsl_shader); - - self->is_compiled = FALSE; - self->tex_uniform = -1; - } - - if (self->program == COGL_INVALID_HANDLE) - self->program = cogl_create_program (); - - if (!self->is_compiled) - { - g_assert (self->shader != COGL_INVALID_HANDLE); - g_assert (self->program != COGL_INVALID_HANDLE); - - cogl_shader_compile (self->shader); - if (!cogl_shader_is_compiled (self->shader)) - { - gchar *log_buf = cogl_shader_get_info_log (self->shader); - - g_warning (G_STRLOC ": Unable to compile the invert-lightness effects shader: %s", - log_buf); - g_free (log_buf); - - cogl_handle_unref (self->shader); - cogl_handle_unref (self->program); - - self->shader = COGL_INVALID_HANDLE; - self->program = COGL_INVALID_HANDLE; - } - else - { - cogl_program_attach_shader (self->program, self->shader); - cogl_program_link (self->program); - - cogl_handle_unref (self->shader); - - self->is_compiled = TRUE; - - self->tex_uniform = - cogl_program_get_uniform_location (self->program, "tex"); - } - } - - parent_class = CLUTTER_EFFECT_CLASS (clutter_invert_lightness_effect_parent_class); - return parent_class->pre_paint (effect); -} - -static void -clutter_invert_lightness_effect_paint_target (ClutterOffscreenEffect *effect) -{ - ClutterInvertLightnessEffect *self = CLUTTER_INVERT_LIGHTNESS_EFFECT (effect); - ClutterOffscreenEffectClass *parent; - CoglHandle material; - - if (self->program == COGL_INVALID_HANDLE) - goto out; - - if (self->tex_uniform > -1) - cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0); - - material = clutter_offscreen_effect_get_target (effect); - cogl_material_set_user_program (material, self->program); - -out: - parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (clutter_invert_lightness_effect_parent_class); - parent->paint_target (effect); -} - -static void -clutter_invert_lightness_effect_dispose (GObject *gobject) -{ - ClutterInvertLightnessEffect *self = CLUTTER_INVERT_LIGHTNESS_EFFECT (gobject); - - if (self->program != COGL_INVALID_HANDLE) - { - cogl_handle_unref (self->program); - - self->program = COGL_INVALID_HANDLE; - self->shader = COGL_INVALID_HANDLE; - } - - self->actor = NULL; - - G_OBJECT_CLASS (clutter_invert_lightness_effect_parent_class)->dispose (gobject); -} - -static void -clutter_invert_lightness_effect_class_init (ClutterInvertLightnessEffectClass *klass) -{ - ClutterEffectClass *effect_class = CLUTTER_EFFECT_CLASS (klass); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - ClutterOffscreenEffectClass *offscreen_class; - - offscreen_class = CLUTTER_OFFSCREEN_EFFECT_CLASS (klass); - offscreen_class->paint_target = clutter_invert_lightness_effect_paint_target; - - effect_class->pre_paint = clutter_invert_lightness_effect_pre_paint; - - gobject_class->dispose = clutter_invert_lightness_effect_dispose; -} - -static void -clutter_invert_lightness_effect_init (ClutterInvertLightnessEffect *self) -{ -} - -/** - * clutter_invert_lightness_effect_new: - * - * Creates a new #ClutterInvertLightnessEffect to be used with - * clutter_actor_add_effect() - * - * Return value: (transfer full): the newly created - * #ClutterInvertLightnessEffect or %NULL. Use g_object_unref() when done. - * - * Since: 1.10 - */ -ClutterEffect * -clutter_invert_lightness_effect_new (void) -{ - return g_object_new (CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT, - NULL); -} diff --git a/clutter/clutter-invert-lightness-effect.h b/clutter/clutter-invert-lightness-effect.h deleted file mode 100644 index cc54415ff..000000000 --- a/clutter/clutter-invert-lightness-effect.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Copyright (C) 2010, 2011 Inclusive Design Research Centre, OCAD University. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * Author: - * Joseph Scheuhammer - */ - -#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) -#error "Only can be included directly." -#endif - -#ifndef __CLUTTER_INVERT_LIGHTNESS_EFFECT_H__ -#define __CLUTTER_INVERT_LIGHTNESS_EFFECT_H__ - -#include - -G_BEGIN_DECLS - -#define CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT (clutter_invert_lightness_effect_get_type ()) -#define CLUTTER_INVERT_LIGHTNESS_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT, ClutterInvertLightnessEffect)) -#define CLUTTER_IS_INVERT_LIGHTNESS_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT)) - -/** - * ClutterInvertLightnessEffect: - * - * ClutterInvertLightnessEffect is an opaque structure - * whose members cannot be directly accessed - * - * Since: 1.10 - */ -typedef struct _ClutterInvertLightnessEffect ClutterInvertLightnessEffect; -typedef struct _ClutterInvertLightnessEffectClass ClutterInvertLightnessEffectClass; - -GType clutter_invert_lightness_effect_get_type (void) G_GNUC_CONST; - -ClutterEffect *clutter_invert_lightness_effect_new (void); - -G_END_DECLS - -#endif /* __CLUTTER_INVERT_LIGHTNESS_EFFECT_H__ */ diff --git a/doc/reference/clutter/clutter-docs.xml.in b/doc/reference/clutter/clutter-docs.xml.in index 16f865651..7a2c7b5cc 100644 --- a/doc/reference/clutter/clutter-docs.xml.in +++ b/doc/reference/clutter/clutter-docs.xml.in @@ -120,11 +120,8 @@ - - - diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt index 5765c3b95..2354712c2 100644 --- a/doc/reference/clutter/clutter-sections.txt +++ b/doc/reference/clutter/clutter-sections.txt @@ -2640,53 +2640,6 @@ ClutterPageTurnEffectClass clutter_page_turn_effect_get_type
-
-ClutterBrightnessEffect -clutter-brightness-effect -ClutterBrightnessEffect -clutter_brightness_effect_new -clutter_brightness_effect_set_brightness -clutter_brightness_effect_get_brightness - -CLUTTER_TYPE_BRIGHTNESS_EFFECT -CLUTTER_BRIGHTNESS_EFFECT -CLUTTER_IS_BRIGHTNESS_EFFECT - -ClutterBrightnessEffectClass -clutter_brightness_effect_get_type -
- -
-ClutterContrastEffect -clutter-contrast-effect -ClutterContrastEffect -clutter_contrast_effect_new -clutter_contrast_effect_set_contrast -clutter_contrast_effect_get_contrast - -CLUTTER_TYPE_CONTRAST_EFFECT -CLUTTER_CONTRAST_EFFECT -CLUTTER_IS_CONTRAST_EFFECT - -ClutterContrastEffectClass -clutter_contrast_effect_get_type -
- -
-ClutterInvertLightnessEffect -clutter-invert-lightness-effect -ClutterInvertLightnessEffect -clutter_contrast_effect_new - -CLUTTER_TYPE_INVERT_LIGHTNESS_EFFECT -CLUTTER_INVERT_LIGHTNESS_EFFECT -CLUTTER_IS_INVERT_LIGHTNESS_EFFECT - -ClutterInvertLightnessEffectClass -clutter_invert_lightness_effect_get_type -
- -
clutter-settings ClutterSettings diff --git a/doc/reference/clutter/clutter.types b/doc/reference/clutter/clutter.types index a8ae0a5f4..8fc224c75 100644 --- a/doc/reference/clutter/clutter.types +++ b/doc/reference/clutter/clutter.types @@ -21,14 +21,12 @@ clutter_bin_layout_get_type clutter_blur_effect_get_type clutter_box_get_type clutter_box_layout_get_type -clutter_brightness_effect_get_type clutter_cairo_texture_get_type clutter_child_meta_get_type clutter_click_action_get_type clutter_clone_get_type clutter_colorize_effect_get_type clutter_constraint_get_type -clutter_contrast_effect_get_type clutter_deform_effect_get_type clutter_desaturate_effect_get_type clutter_device_manager_get_type @@ -41,7 +39,6 @@ clutter_gesture_action_get_type clutter_group_get_type clutter_input_device_get_type clutter_interval_get_type -clutter_invert_lightness_effect_get_type clutter_layout_manager_get_type clutter_layout_meta_get_type clutter_list_model_get_type From 7d515553e662210e8a17c3f6067f681bdbed1bbe Mon Sep 17 00:00:00 2001 From: krishnababu k Date: Thu, 29 Sep 2011 12:09:11 +0530 Subject: [PATCH 11/11] Updated Telugu Translations --- po/te.po | 83 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/po/te.po b/po/te.po index 15353c3e8..460360987 100644 --- a/po/te.po +++ b/po/te.po @@ -8,7 +8,7 @@ msgstr "" "Report-Msgid-Bugs-To: http://bugzilla.gnome.org/enter_bug." "cgi?product=clutter&keywords=I18N+L10N&component=general\n" "POT-Creation-Date: 2011-09-23 07:16+0000\n" -"PO-Revision-Date: 2011-09-23 14:38+0530\n" +"PO-Revision-Date: 2011-09-26 21:28+0530\n" "Last-Translator: Krishnababu Krothapalli \n" "Language-Team: Telugu \n" "MIME-Version: 1.0\n" @@ -24,15 +24,15 @@ msgstr "X అక్షము" #: ../clutter/clutter-actor.c:3876 msgid "X coordinate of the actor" -msgstr "" +msgstr "ఏక్టర్ యొక్క X అక్షము" #: ../clutter/clutter-actor.c:3891 msgid "Y coordinate" -msgstr "" +msgstr "Y అక్షము" #: ../clutter/clutter-actor.c:3892 msgid "Y coordinate of the actor" -msgstr "" +msgstr "ఏక్టర్ యొక్క Y అక్షము" #: ../clutter/clutter-actor.c:3907 ../clutter/clutter-behaviour-ellipse.c:477 msgid "Width" @@ -40,7 +40,7 @@ msgstr "వెడల్పు" #: ../clutter/clutter-actor.c:3908 msgid "Width of the actor" -msgstr "" +msgstr "ఏక్టర్ యొక్క వెడల్పు" #: ../clutter/clutter-actor.c:3922 ../clutter/clutter-behaviour-ellipse.c:493 msgid "Height" @@ -48,31 +48,31 @@ msgstr "ఎత్తు" #: ../clutter/clutter-actor.c:3923 msgid "Height of the actor" -msgstr "" +msgstr "ఏక్టర్ యొక్క యెత్తు" #: ../clutter/clutter-actor.c:3941 msgid "Fixed X" -msgstr "" +msgstr "నిర్దిష్ట X" #: ../clutter/clutter-actor.c:3942 msgid "Forced X position of the actor" -msgstr "" +msgstr "ఏక్టర్ యొక్క నిర్దిష్ట X స్థానం" #: ../clutter/clutter-actor.c:3960 msgid "Fixed Y" -msgstr "" +msgstr "నిర్దిష్ట Y" #: ../clutter/clutter-actor.c:3961 msgid "Forced Y position of the actor" -msgstr "" +msgstr "ఏక్టర్ యొక్క బలవంతపు Y స్థానం" #: ../clutter/clutter-actor.c:3977 msgid "Fixed position set" -msgstr "" +msgstr "నిర్దిష్ట స్థాన అమర్పు" #: ../clutter/clutter-actor.c:3978 msgid "Whether to use fixed positioning for the actor" -msgstr "" +msgstr "ఏక్టర్ కొరకు నిర్దిష్టంగా స్థానపరచుటను వుపయోగించాలా" #: ../clutter/clutter-actor.c:4000 msgid "Min Width" @@ -80,7 +80,7 @@ msgstr "కనిష్ఠ వెడల్పు" #: ../clutter/clutter-actor.c:4001 msgid "Forced minimum width request for the actor" -msgstr "" +msgstr "ఏక్టర్ కొరకు అభ్యర్దించిన బలవంతపు కనిష్ట వెడల్పు" #: ../clutter/clutter-actor.c:4020 msgid "Min Height" @@ -88,119 +88,120 @@ msgstr "కనిష్ఠ ఎత్తు" #: ../clutter/clutter-actor.c:4021 msgid "Forced minimum height request for the actor" -msgstr "" +msgstr "ఏక్టర్ కొరకు అభ్యర్దించిన బలవంతపు కనిష్ట యెత్తు" #: ../clutter/clutter-actor.c:4040 msgid "Natural Width" -msgstr "" +msgstr "సహజ వెడల్పు" #: ../clutter/clutter-actor.c:4041 msgid "Forced natural width request for the actor" -msgstr "" +msgstr "ఏక్టర్ కొరకు అభ్యర్దించిన బలవంతపు సహజ వెడల్పు" #: ../clutter/clutter-actor.c:4060 msgid "Natural Height" -msgstr "" +msgstr "సహజ యెత్తు" #: ../clutter/clutter-actor.c:4061 msgid "Forced natural height request for the actor" -msgstr "" +msgstr "ఏక్టర్ కొరకు అభ్యర్దించిన బలవంతపు సహజ యెత్తు" #: ../clutter/clutter-actor.c:4077 msgid "Minimum width set" -msgstr "" +msgstr "కనిష్ట వెడల్పు అమర్పు" #: ../clutter/clutter-actor.c:4078 msgid "Whether to use the min-width property" -msgstr "" +msgstr "కనిష్ట-వెడల్పు లక్షణం వుపయోగించాలా" #: ../clutter/clutter-actor.c:4093 msgid "Minimum height set" -msgstr "" +msgstr "కనిష్ట యెత్తు అమర్పు" #: ../clutter/clutter-actor.c:4094 msgid "Whether to use the min-height property" -msgstr "" +msgstr "కనిష్ట-యెత్తు లక్షణం వుపయోగించాలా" #: ../clutter/clutter-actor.c:4109 msgid "Natural width set" -msgstr "" +msgstr "సహజ వెడల్పు అమర్పు" #: ../clutter/clutter-actor.c:4110 msgid "Whether to use the natural-width property" -msgstr "" +msgstr "సహజ-వెడల్పు లక్షణం వుపయోగించాలా" #: ../clutter/clutter-actor.c:4127 msgid "Natural height set" -msgstr "" +msgstr "సహజ యెత్తు అమర్పు" #: ../clutter/clutter-actor.c:4128 msgid "Whether to use the natural-height property" -msgstr "" +msgstr "సహజ-యెత్తు లక్షణం వుపయోగించాలా" #: ../clutter/clutter-actor.c:4147 msgid "Allocation" -msgstr "" +msgstr "కేటాయింపు" #: ../clutter/clutter-actor.c:4148 msgid "The actor's allocation" -msgstr "" +msgstr "ఏక్టర్ యొక్క కేటాయింపు" #: ../clutter/clutter-actor.c:4204 msgid "Request Mode" -msgstr "" +msgstr "అభ్యర్దన రీతి" #: ../clutter/clutter-actor.c:4205 msgid "The actor's request mode" -msgstr "" +msgstr "ఏక్టర్ యొక్క అభ్యర్దన రీతి" #: ../clutter/clutter-actor.c:4220 msgid "Depth" -msgstr "" +msgstr "లోతు" #: ../clutter/clutter-actor.c:4221 msgid "Position on the Z axis" -msgstr "" +msgstr "Z అక్షంపై స్థానం" #: ../clutter/clutter-actor.c:4235 msgid "Opacity" -msgstr "" +msgstr "మసక" #: ../clutter/clutter-actor.c:4236 msgid "Opacity of an actor" -msgstr "" +msgstr "ఏక్టర్ యొక్క మసక" #: ../clutter/clutter-actor.c:4255 msgid "Offscreen redirect" -msgstr "" +msgstr "ఆఫ్‌స్క్రీన్ రీడైరెక్ట్" #: ../clutter/clutter-actor.c:4256 msgid "Flags controlling when to flatten the actor into a single image" msgstr "" +"ఏక్టర్‌ను వొంటరి ప్రతిరూపమునకు యెప్పుడు ఫ్లాటెన్ చేయాలో నియంత్రించే ఫ్లాగులు" #: ../clutter/clutter-actor.c:4274 msgid "Visible" -msgstr "" +msgstr "దృశ్యనీయం" #: ../clutter/clutter-actor.c:4275 msgid "Whether the actor is visible or not" -msgstr "" +msgstr "ఏక్టర్ దృశ్యనీయం కావలెనా లేదా" #: ../clutter/clutter-actor.c:4290 msgid "Mapped" -msgstr "" +msgstr "మాప్‌డ్" #: ../clutter/clutter-actor.c:4291 msgid "Whether the actor will be painted" -msgstr "" +msgstr "ఏక్టర్ రంగు వేయబడుదురా" #: ../clutter/clutter-actor.c:4305 msgid "Realized" -msgstr "" +msgstr "తెలుసుకొనెను" #: ../clutter/clutter-actor.c:4306 msgid "Whether the actor has been realized" -msgstr "" +msgstr "ఏక్టర్‌కు తెలియవలెనా" #: ../clutter/clutter-actor.c:4322 msgid "Reactive"