summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2010-04-21 09:10:49 +0200
committerBenjamin Otte <otte@redhat.com>2010-04-21 09:10:49 +0200
commit7d78a90258ec20a7804bb13a9745fb4146dc558b (patch)
tree3f37edcb9037ccedca3b44ca2c67e6a220e76893
parent6d5cbb6526ed1faf7ff382adb3f41839ef8971ed (diff)
Make the supported_types functions more readable
-rw-r--r--gst-libs/gst/cairo/gstcairocaps.c65
1 files changed, 35 insertions, 30 deletions
diff --git a/gst-libs/gst/cairo/gstcairocaps.c b/gst-libs/gst/cairo/gstcairocaps.c
index 7cfe50d..1e34808 100644
--- a/gst-libs/gst/cairo/gstcairocaps.c
+++ b/gst-libs/gst/cairo/gstcairocaps.c
@@ -135,18 +135,31 @@ gst_cairo_caps_set_surface_types_by_value (GstCaps * caps,
}
static GstCaps *
-gst_cairo_caps_expand_surface_types (GstCaps * caps,
- const cairo_surface_type_t * types)
+gst_cairo_caps_get_default (void)
{
- GValue value = { 0, };
+ static gsize default_ = 0;
- g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
+ if (g_once_init_enter (&default_)) {
+ GstCaps *caps = gst_caps_make_writable (gst_cairo_caps_any ());
+ GValue value = { 0, };
- caps = gst_caps_make_writable (caps);
- gst_cairo_value_init_from_surface_types (&value, types);
- gst_cairo_caps_set_surface_types_by_value (caps, &value, TRUE);
- g_value_unset (&value);
+ g_value_init (&value, G_TYPE_INT);
+ caps = gst_cairo_caps_set_surface_types_by_value (caps, &value, FALSE);
+ g_value_unset (&value);
+
+ g_once_init_leave (&default_, GPOINTER_TO_SIZE (caps));
+ }
+
+ return gst_caps_ref (GSIZE_TO_POINTER (default_));
+}
+
+static GstCaps *
+gst_cairo_caps_default_for_value (const GValue * supported_types)
+{
+ GstCaps *caps = gst_cairo_caps_get_default ();
+ caps = gst_caps_make_writable (caps);
+ gst_cairo_caps_set_surface_types_by_value (caps, supported_types, FALSE);
return caps;
}
@@ -171,25 +184,17 @@ gst_cairo_caps_expand_surface_types (GstCaps * caps,
GstCaps *
gst_cairo_caps_default (const cairo_surface_type_t * types)
{
- static gsize default_ = 0;
-
- if (g_once_init_enter (&default_)) {
- GstCaps *caps = gst_caps_make_writable (gst_cairo_caps_any ());
- GValue value = { 0, };
+ GValue value = { 0, };
+ GstCaps *caps;
- g_value_init (&value, G_TYPE_INT);
- caps = gst_cairo_caps_set_surface_types_by_value (caps, &value, FALSE);
- g_value_unset (&value);
+ if (types == NULL)
+ return gst_cairo_caps_get_default ();
- g_once_init_leave (&default_, GPOINTER_TO_SIZE (caps));
- }
+ gst_cairo_value_init_from_surface_types (&value, types);
+ caps = gst_cairo_caps_default_for_value (&value);
+ g_value_unset (&value);
- if (types == NULL)
- return gst_caps_ref (GSIZE_TO_POINTER (default_));
- else
- return
- gst_cairo_caps_expand_surface_types (gst_caps_copy (GSIZE_TO_POINTER
- (default_)), types);
+ return caps;
}
/**
@@ -230,12 +235,12 @@ gst_cairo_caps_expand_for_surface_types (const GstCaps * caps,
GstCairoFormatOption expand, const cairo_surface_type_t * types)
{
GstCaps *expanded;
- GValue surfaces_value = { 0, };
+ GValue types_value = { 0, };
guint i;
g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
- gst_cairo_value_init_from_surface_types (&surfaces_value, types);
+ gst_cairo_value_init_from_surface_types (&types_value, types);
/* start with a copy of the current caps - we prefer unchanged caps */
expanded = gst_caps_copy (caps);
@@ -250,8 +255,8 @@ gst_cairo_caps_expand_for_surface_types (const GstCaps * caps,
const GValue *structure_types;
structure_types = gst_structure_get_value (expand_me, "surface-type");
- if (gst_value_intersect (&intersect, structure_types, &surfaces_value)) {
- copy = gst_caps_make_writable (gst_cairo_caps_default (types));
+ if (gst_value_intersect (&intersect, structure_types, &types_value)) {
+ copy = gst_cairo_caps_default_for_value (&types_value);
copy = gst_cairo_caps_set_surface_types_by_value (copy,
structure_types, TRUE);
g_value_unset (&intersect);
@@ -259,7 +264,7 @@ gst_cairo_caps_expand_for_surface_types (const GstCaps * caps,
copy = gst_caps_copy_nth (caps, i);
}
} else {
- copy = gst_caps_make_writable (gst_cairo_caps_default (types));
+ copy = gst_cairo_caps_default_for_value (&types_value);
}
} else {
copy = gst_caps_copy_nth (caps, i);
@@ -305,7 +310,7 @@ gst_cairo_caps_expand_for_surface_types (const GstCaps * caps,
gst_caps_append (expanded, copy);
}
- g_value_unset (&surfaces_value);
+ g_value_unset (&types_value);
return expanded;
}