[pitivi] effects: Fix OpenGL effects



commit cd4533c6faae769f4e9dd1cfa3e33e25c8819862
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Sun Nov 6 03:36:30 2016 +0100

    effects: Fix OpenGL effects
    
    Fixes https://phabricator.freedesktop.org/T7579
    
    Differential Revision: https://phabricator.freedesktop.org/D1447

 pitivi/clipproperties.py |    5 +++--
 pitivi/effects.py        |   22 +++++++++++++++++++---
 tests/meson.build        |    1 +
 tests/test_effects.py    |   39 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 62 insertions(+), 5 deletions(-)
---
diff --git a/pitivi/clipproperties.py b/pitivi/clipproperties.py
index cb8e66c..ebd394c 100644
--- a/pitivi/clipproperties.py
+++ b/pitivi/clipproperties.py
@@ -320,7 +320,8 @@ class EffectProperties(Gtk.Expander, Loggable):
                         return effect
 
         model = self.treeview.get_model()
-        media_type = self.app.effects.getInfo(factory_name).media_type
+        effect_info = self.app.effects.getInfo(factory_name)
+        media_type = effect_info.media_type
 
         for track_element in clip.get_children(False):
             track_type = track_element.get_track_type()
@@ -330,7 +331,7 @@ class EffectProperties(Gtk.Expander, Loggable):
                 pipeline = self._project.pipeline
                 with self.app.action_log.started("add effect",
                                                  CommitTimelineFinalizingAction(pipeline)):
-                    effect = GES.Effect.new(bin_description=factory_name)
+                    effect = GES.Effect.new(effect_info.bin_description)
                     clip.add(effect)
                     if priority is not None and priority < len(model):
                         clip.set_top_effect_priority(effect, priority)
diff --git a/pitivi/effects.py b/pitivi/effects.py
index 6681227..88dc2fb 100644
--- a/pitivi/effects.py
+++ b/pitivi/effects.py
@@ -164,7 +164,6 @@ class EffectInfo(object):
     @property
     def icon(self):
         pixdir = os.path.join(get_pixmap_dir(), "effects")
-        icon = None
         try:
             # We can afford to scale the images here, the impact is negligible
             icon = GdkPixbuf.Pixbuf.new_from_file_at_size(
@@ -176,6 +175,22 @@ class EffectInfo(object):
                 os.path.join(pixdir, "defaultthumbnail.svg"))
         return icon
 
+    @property
+    def bin_description(self):
+        """Gets the bin description which defines this effect."""
+        if self.effect_name.startswith("gl"):
+            return "glupload ! %s ! gldownload" % self.effect_name
+        else:
+            return self.effect_name
+
+    @staticmethod
+    def name_from_bin_description(bin_description):
+        """Gets the name of the effect defined by the `bin_description`."""
+        if bin_description.startswith("glupload"):
+            return bin_description.split("!")[1].strip()
+        else:
+            return bin_description
+
 
 class EffectsManager(object):
     """Keeps info about effects and their categories.
@@ -235,15 +250,16 @@ class EffectsManager(object):
                                 description=factory.get_description())
             self._effects[name] = effect
 
-    def getInfo(self, name):
+    def getInfo(self, bin_description):
         """Gets the info for an effect which can be applied.
 
         Args:
-            name (str): The bin_description identifying the effect.
+            bin_description (str): The bin_description defining the effect.
 
         Returns:
             EffectInfo: The info corresponding to the name, or None.
         """
+        name = EffectInfo.name_from_bin_description(bin_description)
         return self._effects.get(name)
 
     def _getEffectCategories(self, effect_name):
diff --git a/tests/meson.build b/tests/meson.build
index 3ab506e..7e172a1 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -7,6 +7,7 @@ if runtests.found()
         ['Test clipproperties', 'test_clipproperties'],
         ['Test common utilities', 'test_common'],
         ['Test logging subsystem', 'test_log'],
+        ['Test effects', 'test_effects'],
         ['Test the main window', 'test_mainwindow'],
         ['Test the media library', 'test_media_library'],
         ['Test the misc utilities', 'test_misc'],
diff --git a/tests/test_effects.py b/tests/test_effects.py
new file mode 100644
index 0000000..e368e4f
--- /dev/null
+++ b/tests/test_effects.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+# Pitivi video editor
+# Copyright (c) 2016, Alex Băluț <alexandru balut gmail com>
+#
+# This program 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.1 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+"""Tests for the effects module."""
+import unittest
+
+from pitivi.effects import EffectInfo
+
+
+class EffectInfoTest(unittest.TestCase):
+    """Tests for the EffectInfo class."""
+
+    def test_bin_description(self):
+        """Tests the bin_description property."""
+        effect_info = EffectInfo("name", None, None, None, None)
+        self.assertEqual(effect_info.bin_description, "name")
+
+        effect_info = EffectInfo("glname", None, None, None, None)
+        self.assertEqual(effect_info.bin_description, "glupload ! glname ! gldownload")
+
+    def test_name_from_bin_description(self):
+        """Tests the name_from_bin_description method."""
+        self.assertEqual(EffectInfo.name_from_bin_description("name"), "name")
+        self.assertEqual(EffectInfo.name_from_bin_description("glupload ! glname ! gldownload"), "glname")


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