[cheese] Effect preview elements are now constructed on-demand, rather than at startup.



commit e89772cb20178da827fa3a85d39081e027703255
Author: Yuvaraj Pandian T <yuvipanda gmail com>
Date:   Fri Jul 30 19:53:14 2010 +0530

    Effect preview elements are now constructed on-demand, rather than at startup.
    
    Hacky. Needs to be cleaned up.

 libcheese/cheese-camera.c   |   13 +++++++++++--
 libcheese/cheese-effect.c   |    7 +++++++
 libcheese/cheese-effect.h   |    2 ++
 src/cheese-window.vala      |   20 +++++++++++++-------
 src/vapi/cheese-common.vapi |    1 +
 5 files changed, 34 insertions(+), 9 deletions(-)
---
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index e291ea5..1a9826a 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -818,11 +818,20 @@ cheese_camera_connect_effect_texture (CheeseCamera *camera, CheeseEffect *effect
 
   display_element = clutter_gst_video_sink_new (texture);
   g_object_set (G_OBJECT (display_element), "async", FALSE, NULL);
-    
+ 
   gst_bin_add_many (GST_BIN (priv->pipeline), control_valve, effect_filter, display_queue, display_element, NULL);
+
+
+
   ok = gst_element_link_many (priv->effects_tee, control_valve, effect_filter, display_queue, display_element, NULL);
 
-  g_object_set (G_OBJECT (priv->effects_valve), "drop", FALSE, NULL);
+  // HACK: I don't understand GStreamer enough to know why this works.
+  gst_element_set_state (control_valve, GST_STATE_PLAYING);
+  gst_element_set_state (effect_filter, GST_STATE_PLAYING);
+  gst_element_set_state (display_queue, GST_STATE_PLAYING);
+  gst_element_set_state (display_element, GST_STATE_PLAYING); 
+
+  g_object_set (G_OBJECT (priv->effects_valve), "drop", FALSE, NULL);  
 }
 
 
diff --git a/libcheese/cheese-effect.c b/libcheese/cheese-effect.c
index da9461b..a1e4905 100644
--- a/libcheese/cheese-effect.c
+++ b/libcheese/cheese-effect.c
@@ -120,6 +120,13 @@ cheese_effect_class_init (CheeseEffectClass *klass)
 
 }
 
+gboolean
+cheese_effect_is_preview_connected (CheeseEffect *self)
+{
+  CheeseEffectPrivate *priv = CHEESE_EFFECT_GET_PRIVATE (self);
+  return priv->control_valve != NULL;
+}
+
 void
 cheese_effect_enable_preview (CheeseEffect *self)
 {
diff --git a/libcheese/cheese-effect.h b/libcheese/cheese-effect.h
index 080e642..4157d25 100644
--- a/libcheese/cheese-effect.h
+++ b/libcheese/cheese-effect.h
@@ -52,8 +52,10 @@ typedef struct {
 GType cheese_effect_get_type (void);
 
 CheeseEffect* cheese_effect_new (void);
+gboolean cheese_effect_is_preview_connected (CheeseEffect* self);
 void cheese_effect_enable_preview (CheeseEffect* self);
 void cheese_effect_disable_preview (CheeseEffect* self);
+
 G_END_DECLS
 
 #endif /* _CHEESE_EFFECT_H_ */
diff --git a/src/cheese-window.vala b/src/cheese-window.vala
index 1c175a0..7d7f495 100644
--- a/src/cheese-window.vala
+++ b/src/cheese-window.vala
@@ -682,14 +682,20 @@ public class Cheese.MainWindow : Gtk.Window
 
     for (int i = 0; i < effects_manager.effects.size - 1; i++)
     {
-      int page_of_effect = i / EFFECTS_PER_PAGE;
-      if (page_of_effect == page_of_effect)
+      int           page_of_effect = i / EFFECTS_PER_PAGE;
+      Cheese.Effect effect         = effects_manager.effects[i];
+      if (page_of_effect == number)
       {
-        effects_manager.effects[i].enable_preview ();
+        if (!effect.is_preview_connected ())
+        {
+          Clutter.Texture texture = effect.get_data<Clutter.Texture> ("texture");
+          camera.connect_effect_texture (effect, texture);
+        }
+        effect.enable_preview ();
       }
       else
       {
-        effects_manager.effects[i].disable_preview ();
+        effect.disable_preview ();
       }
     }
     setup_effects_page_switch_sensitivity ();
@@ -744,7 +750,6 @@ public class Cheese.MainWindow : Gtk.Window
         grid.row_spacing    = 20;
       }
 
-
       for (int i = 0; i < effects_manager.effects.size - 1; i++)
       {
         Effect            effect  = effects_manager.effects[i];
@@ -767,6 +772,8 @@ public class Cheese.MainWindow : Gtk.Window
                   );
         box.reactive = true;
         box.set_data ("effect", effect);
+        effect.set_data ("texture", texture);
+
         box.button_release_event.connect (on_selected_effect_change);
 
         text.text  = effect.name;
@@ -784,7 +791,6 @@ public class Cheese.MainWindow : Gtk.Window
                   );
 
         effects_grids[i / EFFECTS_PER_PAGE].add ((Clutter.Actor)box);
-        camera.connect_effect_texture (effect, texture);
       }
 
       setup_effects_page_switch_sensitivity ();
@@ -939,7 +945,7 @@ public class Cheese.MainWindow : Gtk.Window
       }
       return;
     }
-   
+
 
     set_mode (MediaMode.PHOTO);
     setup_effects_selector ();
diff --git a/src/vapi/cheese-common.vapi b/src/vapi/cheese-common.vapi
index 21c58a6..c02621c 100644
--- a/src/vapi/cheese-common.vapi
+++ b/src/vapi/cheese-common.vapi
@@ -17,6 +17,7 @@ namespace Cheese
 
 		public void enable_preview();
 		public void disable_preview();
+		public bool is_preview_connected();
 	}
 
   [CCode (cheader_filename = "cheese-camera.h")]



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]