diff --git a/ges/ges-clip.c b/ges/ges-clip.c index 9e2156ddc6..fab363bf8e 100644 --- a/ges/ges-clip.c +++ b/ges/ges-clip.c @@ -257,6 +257,17 @@ _set_priority (GESTimelineElement * element, guint32 priority) return TRUE; } +static guint32 +_get_layer_priority (GESTimelineElement * element) +{ + GESClip *clip = GES_CLIP (element); + + if (clip->priv->layer == NULL) + return GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY; + + return ges_layer_get_priority (clip->priv->layer); +} + /**************************************************** * * * GESContainer virtual methods implementation * @@ -833,6 +844,7 @@ ges_clip_class_init (GESClipClass * klass) element_class->paste = _paste; element_class->deep_copy = _deep_copy; element_class->lookup_child = _lookup_child; + element_class->get_layer_priority = _get_layer_priority; container_class->add_child = _add_child; container_class->remove_child = _remove_child; diff --git a/ges/ges-group.c b/ges/ges-group.c index 19fc30410d..c50a8a47d7 100644 --- a/ges/ges-group.c +++ b/ges/ges-group.c @@ -118,7 +118,7 @@ _update_our_values (GESGroup * group) for (tmp = GES_CONTAINER_CHILDREN (group); tmp; tmp = tmp->next) { GESTimelineElement *child = tmp->data; guint32 child_prio = GES_IS_CLIP (child) ? - ges_clip_get_layer_priority (GES_CLIP (child)) : _PRIORITY (child); + GES_TIMELINE_ELEMENT_LAYER_PRIORITY (child) : _PRIORITY (child); _ges_container_set_priority_offset (container, child, min_layer_prio - child_prio); @@ -159,7 +159,7 @@ _child_clip_changed_layer_cb (GESTimelineElement * clip, ChildSignalIds *sigids; gchar *signals_ids_key; GESLayer *old_layer, *new_layer; - gint offset, layer_prio = ges_clip_get_layer_priority (GES_CLIP (clip)); + gint offset, layer_prio = GES_TIMELINE_ELEMENT_LAYER_PRIORITY (clip); GESContainer *container = GES_CONTAINER (group); offset = _ges_container_get_priority_offset (container, clip); @@ -335,11 +335,10 @@ _set_priority (GESTimelineElement * element, guint32 priority) if (child != container->initiated_move) { if (GES_IS_CLIP (child)) { - guint32 layer_prio = - ges_clip_get_layer_priority (GES_CLIP (child)) + diff; + guint32 layer_prio = GES_TIMELINE_ELEMENT_LAYER_PRIORITY (child) + diff; GST_DEBUG_OBJECT (child, "moving from layer: %i to %i", - ges_clip_get_layer_priority (GES_CLIP (child)), layer_prio); + GES_TIMELINE_ELEMENT_LAYER_PRIORITY (child), layer_prio); ges_clip_move_to_layer (GES_CLIP (child), g_list_nth_data (layers, layer_prio)); } else if (GES_IS_GROUP (child)) { diff --git a/ges/ges-timeline-element.c b/ges/ges-timeline-element.c index 1e1e83d783..040a7f90b6 100644 --- a/ges/ges-timeline-element.c +++ b/ges/ges-timeline-element.c @@ -1853,6 +1853,26 @@ ges_timeline_element_paste (GESTimelineElement * self, return g_object_ref (res); } +/** + * ges_timeline_element_get_layer_priority: + * @self: A #GESTimelineElement + * + * Returns: The priority of the first layer the element is in (note that only + * groups can span over several layers). %GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY + * means that the element is not in a layer. + */ +guint32 +ges_timeline_element_get_layer_priority (GESTimelineElement * self) +{ + g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), + GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY); + + if (!GES_TIMELINE_ELEMENT_GET_CLASS (self)->get_layer_priority) + return self->priority; + + return GES_TIMELINE_ELEMENT_GET_CLASS (self)->get_layer_priority (self); +} + /* Internal */ gdouble ges_timeline_element_get_media_duration_factor (GESTimelineElement * self) @@ -1912,18 +1932,6 @@ ges_timeline_element_flags (GESTimelineElement * self) return self->priv->flags; } -gint32 -_layer_priority (GESTimelineElement * element) -{ - if (GES_IS_CLIP (element)) - return ges_clip_get_layer_priority (GES_CLIP (element)); - - if (GES_IS_TRACK_ELEMENT (element)) - return element->priority / LAYER_HEIGHT; - - return element->priority; -} - void ges_timeline_element_set_flags (GESTimelineElement * self, GESTimelineElementFlags flags) diff --git a/ges/ges-timeline-element.h b/ges/ges-timeline-element.h index 04354ad210..860b72b765 100644 --- a/ges/ges-timeline-element.h +++ b/ges/ges-timeline-element.h @@ -84,6 +84,21 @@ typedef struct _GESTimelineElementPrivate GESTimelineElementPrivate; */ #define GES_TIMELINE_ELEMENT_PRIORITY(obj) (((GESTimelineElement*)obj)->priority) +/** + * GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY: + * + * Layer priority when the element is not in a layer + */ +#define GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY ((guint32) -1) + +/** + * GES_TIMELINE_ELEMENT_LAYER_PRIORITY: + * @obj: The object to retrieve the layer priority from + * + * See #ges_timeline_element_get_layer_priority + */ +#define GES_TIMELINE_ELEMENT_LAYER_PRIORITY(obj) (ges_timeline_element_get_layer_priority(((GESTimelineElement*)obj))) + /** * GES_TIMELINE_ELEMENT_PARENT: * @obj: a #GESTimelineElement @@ -198,9 +213,11 @@ struct _GESTimelineElementClass void (*set_child_property) (GESTimelineElement * self, GObject *child, GParamSpec *pspec, GValue *value); + guint32 (*get_layer_priority) (GESTimelineElement *self); + /*< private > */ /* Padding for API extension */ - gpointer _ges_reserved[GES_PADDING_LARGE - 3]; + gpointer _ges_reserved[GES_PADDING_LARGE - 4]; }; GES_API @@ -319,6 +336,9 @@ GESTimelineElement * ges_timeline_element_paste (GESTimelineElement * self, GES_API GESTrackType ges_timeline_element_get_track_types (GESTimelineElement * self); +GES_API +guint32 ges_timeline_element_get_layer_priority (GESTimelineElement * self); + G_END_DECLS #endif /* _GES_TIMELINE_ELEMENT_H_ */ diff --git a/ges/ges-track-element.c b/ges/ges-track-element.c index f45023cce3..f744649ec2 100644 --- a/ges/ges-track-element.c +++ b/ges/ges-track-element.c @@ -122,6 +122,15 @@ strv_find_str (const gchar ** strv, const char *str) return FALSE; } +static guint32 +_get_layer_priority (GESTimelineElement * element) +{ + if (!element->parent) + return GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY; + + return ges_timeline_element_get_layer_priority (element->parent); +} + static void ges_track_element_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) @@ -310,6 +319,7 @@ ges_track_element_class_init (GESTrackElementClass * klass) element_class->set_priority = _set_priority; element_class->get_track_types = _get_track_types; element_class->deep_copy = ges_track_element_copy_properties; + element_class->get_layer_priority = _get_layer_priority; klass->create_gnl_object = ges_track_element_create_gnl_object_func; klass->list_children_properties = default_list_children_properties; diff --git a/tests/check/ges/group.c b/tests/check/ges/group.c index 0184357f0d..84944b0226 100644 --- a/tests/check/ges/group.c +++ b/tests/check/ges/group.c @@ -565,15 +565,15 @@ GST_START_TEST (test_group_in_group_layer_moving) CHECK_OBJECT_PROPS (c, 10, 0, 10); CHECK_OBJECT_PROPS (c1, 20, 0, 10); CHECK_OBJECT_PROPS (group, 10, 0, 20); - assert_equals_int (ges_clip_get_layer_priority (c), 0); - assert_equals_int (ges_clip_get_layer_priority (c1), 1); + assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 0); + assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 1); ges_layer_set_priority (layer2, 0); ges_layer_set_priority (layer, 1); ges_layer_set_priority (layer1, 2); - assert_equals_int (ges_clip_get_layer_priority (c), 1); - assert_equals_int (ges_clip_get_layer_priority (c1), 2); + assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 1); + assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 2); /* Our timeline * @@ -595,8 +595,8 @@ GST_START_TEST (test_group_in_group_layer_moving) CHECK_OBJECT_PROPS (c, 10, 0, 10); CHECK_OBJECT_PROPS (c1, 20, 0, 10); CHECK_OBJECT_PROPS (group, 10, 0, 20); - assert_equals_int (ges_clip_get_layer_priority (c), 0); - assert_equals_int (ges_clip_get_layer_priority (c1), 1); + assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 0); + assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 1); /* Our timeline * @@ -617,8 +617,8 @@ GST_START_TEST (test_group_in_group_layer_moving) CHECK_OBJECT_PROPS (c, 10, 0, 10); CHECK_OBJECT_PROPS (c1, 20, 0, 10); CHECK_OBJECT_PROPS (group, 10, 0, 20); - assert_equals_int (ges_clip_get_layer_priority (c), 1); - assert_equals_int (ges_clip_get_layer_priority (c1), 2); + assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 1); + assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 2); gst_object_unref (timeline); gst_object_unref (asset); diff --git a/tests/check/ges/timelineedition.c b/tests/check/ges/timelineedition.c index e61e191101..144db177eb 100644 --- a/tests/check/ges/timelineedition.c +++ b/tests/check/ges/timelineedition.c @@ -738,9 +738,7 @@ GST_START_TEST (test_timeline_edition_mode) CHECK_OBJECT_PROPS (trackelement, 32, 5, 3); CHECK_OBJECT_PROPS (trackelement1, 20, 0, 10); CHECK_OBJECT_PROPS (trackelement2, 35, 0, 60); - layer = ges_clip_get_layer (GES_CLIP (clip)); - assert_equals_int (ges_layer_get_priority (layer), 2); - gst_object_unref (layer); + assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (clip), 2); /* Roll end clip to 50 * New timeline: @@ -802,10 +800,8 @@ GST_START_TEST (test_timeline_edition_mode) GES_EDGE_END, 52) == TRUE); CHECK_OBJECT_PROPS (trackelement, 32, 5, 20); CHECK_OBJECT_PROPS (trackelement1, 20, 0, 10); - CHECK_OBJECT_PROPS (trackelement2, 52, 0, 60) - layer = ges_clip_get_layer (GES_CLIP (clip)); - assert_equals_int (ges_layer_get_priority (layer), 2); - gst_object_unref (layer); + CHECK_OBJECT_PROPS (trackelement2, 52, 0, 60); + assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (clip), 2); /* Little check that we have 4 layers in the timeline */