diff options
author | Lionel Landwerlin <llandwerlin@gmail.com> | 2013-07-01 16:10:55 +0100 |
---|---|---|
committer | Lionel Landwerlin <llandwerlin@gmail.com> | 2013-07-08 12:11:09 +0100 |
commit | 2b077e89c620c630e4fdaf2d9cb73ab141127ea9 (patch) | |
tree | f7b9fadc1448321003926a5a295b39dd64b0af18 /clutter-gst/clutter-gst-aspectratio.c | |
parent | a661cbdca1c5a807ab48017cd4c93c149f878b0b (diff) | |
download | clutter-gst-2b077e89c620c630e4fdaf2d9cb73ab141127ea9.tar.gz |
switch ClutterGst to use ClutterContent
Diffstat (limited to 'clutter-gst/clutter-gst-aspectratio.c')
-rw-r--r-- | clutter-gst/clutter-gst-aspectratio.c | 413 |
1 files changed, 261 insertions, 152 deletions
diff --git a/clutter-gst/clutter-gst-aspectratio.c b/clutter-gst/clutter-gst-aspectratio.c index 7baa127..c875a58 100644 --- a/clutter-gst/clutter-gst-aspectratio.c +++ b/clutter-gst/clutter-gst-aspectratio.c @@ -3,8 +3,9 @@ * * GStreamer integration library for Clutter. * - * clutter-gst-aspectratio.c - An actor rendering a video with respect - * to its aspect ratio. + * clutter-gst-aspectratio.c - An object implementing the + * ClutterContent interface to render a video with respect to its + * aspect ratio. * * Authored by Lionel Landwerlin <lionel.g.landwerlin@linux.intel.com> * @@ -29,19 +30,21 @@ #include "clutter-gst-aspectratio.h" #include "clutter-gst-private.h" -G_DEFINE_TYPE (ClutterGstAspectratio, clutter_gst_aspectratio, CLUTTER_GST_TYPE_ACTOR) +static void content_iface_init (ClutterContentIface *iface); -#define ASPECTRATIO_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), CLUTTER_GST_TYPE_ASPECTRATIO, ClutterGstAspectratioPrivate)) +G_DEFINE_TYPE_WITH_CODE (ClutterGstAspectratio, + clutter_gst_aspectratio, + CLUTTER_GST_TYPE_CONTENT, + G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTENT, + content_iface_init)) + +#define ASPECTRATIO_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ + CLUTTER_GST_TYPE_ASPECTRATIO, \ + ClutterGstAspectratioPrivate)) struct _ClutterGstAspectratioPrivate { - ClutterGstPlayer *player; - - gint frame_width; - gint frame_height; - ClutterActorBox paint_box; - gboolean paint_borders; }; @@ -55,114 +58,22 @@ enum /**/ static void -clutter_gst_aspectratio_get_preferred_width (ClutterActor *actor, - gfloat for_height, - gfloat *min_width, - gfloat *nat_width) -{ - ClutterGstAspectratioPrivate *priv = CLUTTER_GST_ASPECTRATIO (actor)->priv; - - if (min_width) - *min_width = 0; - if (nat_width) - { - gdouble aspect = (gdouble) priv->frame_width / (gdouble) priv->frame_height; - - if (for_height > 0) - *nat_width = for_height * aspect; - else - *nat_width = priv->frame_width; - } -} - -static void -clutter_gst_aspectratio_get_preferred_height (ClutterActor *actor, - gfloat for_width, - gfloat *min_height, - gfloat *nat_height) -{ - ClutterGstAspectratioPrivate *priv = CLUTTER_GST_ASPECTRATIO (actor)->priv; - - if (min_height) - *min_height = 0; - if (nat_height) - { - gdouble aspect = (gdouble) priv->frame_width / (gdouble) priv->frame_height; - - if (for_width > 0) - *nat_height = for_width / aspect; - else - *nat_height = priv->frame_height; - } -} - - -static void -clutter_gst_aspectratio_paint_frame (ClutterGstActor *self, - ClutterGstFrame *frame) -{ - ClutterGstAspectratioPrivate *priv = CLUTTER_GST_ASPECTRATIO (self)->priv; - guint8 paint_opacity; - - paint_opacity = clutter_actor_get_paint_opacity (CLUTTER_ACTOR (self)); - cogl_pipeline_set_color4ub (frame->pipeline, - paint_opacity, - paint_opacity, - paint_opacity, - paint_opacity); - cogl_set_source (frame->pipeline); - - cogl_rectangle (priv->paint_box.x1, priv->paint_box.y1, - priv->paint_box.x2, priv->paint_box.y2); - - if (priv->paint_borders) - { - ClutterColor bg_color; - ClutterActorBox box; - gfloat box_width, box_height; - - clutter_actor_get_background_color (CLUTTER_ACTOR (self), &bg_color); - clutter_actor_get_allocation_box (CLUTTER_ACTOR (self), &box); - - box_width = clutter_actor_box_get_width (&box); - box_height = clutter_actor_box_get_height (&box); - - cogl_set_source_color4ub (bg_color.red, - bg_color.green, - bg_color.blue, - paint_opacity); - - if (box_width != clutter_actor_box_get_width (&priv->paint_box)) - { - cogl_rectangle (0, 0, priv->paint_box.x1, box_height); - cogl_rectangle (priv->paint_box.x2, 0, box_width, box_height); - } - if (box_height != clutter_actor_box_get_height (&priv->paint_box)) - { - cogl_rectangle (0, 0, box_width, priv->paint_box.y1); - cogl_rectangle (0, priv->paint_box.y2, box_width, box_height); - } - } -} - -static void -_recompute_paint_box (ClutterGstAspectratio *self) +clutter_gst_aspectratio_get_frame_box (ClutterGstAspectratio *self, + ClutterGstBox *paint_box, + ClutterActorBox *content_box, + ClutterGstFrame *frame) { - ClutterGstAspectratioPrivate *priv = self->priv; - ClutterActorBox box; gfloat actor_width, actor_height; gdouble new_width, new_height; gdouble frame_aspect, actor_aspect; - clutter_actor_get_allocation_box (CLUTTER_ACTOR (self), &box); - - actor_width = box.x2 - box.x1; - actor_height = box.y2 - box.y1; + actor_width = clutter_actor_box_get_width (content_box); + actor_height = clutter_actor_box_get_height (content_box); if (actor_width <= 0 || actor_height <= 0) return; - frame_aspect = (gdouble) priv->frame_width / (gdouble) priv->frame_height; + frame_aspect = (gdouble) frame->resolution.width / (gdouble) frame->resolution.height; actor_aspect = actor_width / actor_height; if (actor_aspect < frame_aspect) @@ -176,54 +87,255 @@ _recompute_paint_box (ClutterGstAspectratio *self) new_width = actor_height * frame_aspect; } - priv->paint_box.x1 = (actor_width - new_width) / 2; - priv->paint_box.y1 = (actor_height - new_height) / 2; - priv->paint_box.x2 = priv->paint_box.x1 + new_width; - priv->paint_box.y2 = priv->paint_box.y1 + new_height; + paint_box->x1 = (actor_width - new_width) / 2; + paint_box->y1 = (actor_height - new_height) / 2; + paint_box->x2 = paint_box->x1 + new_width; + paint_box->y2 = paint_box->y1 + new_height; } -static void -_player_size_changed (ClutterGstPlayer *player, - gint width, - gint height, - ClutterGstAspectratio *self) +/**/ + +static gboolean +clutter_gst_aspectratio_get_preferred_size (ClutterContent *content, + gfloat *width, + gfloat *height) { - ClutterGstAspectratioPrivate *priv = self->priv; + ClutterGstFrame *frame = + clutter_gst_content_get_frame (CLUTTER_GST_CONTENT (content)); + + if (!frame) + return FALSE; - priv->frame_width = width; - priv->frame_height = height; + if (width) + *width = frame->resolution.width; + if (height) + *height = frame->resolution.height; - _recompute_paint_box (self); - clutter_actor_queue_relayout (CLUTTER_ACTOR (self)); + return TRUE; } static void -_player_changed (ClutterGstAspectratio *self, - GParamSpec *spec, - gpointer user_data) +clutter_gst_aspectratio_paint_content (ClutterContent *content, + ClutterActor *actor, + ClutterPaintNode *root) { + ClutterGstAspectratio *self = CLUTTER_GST_ASPECTRATIO (content); ClutterGstAspectratioPrivate *priv = self->priv; - ClutterGstPlayer *player = clutter_gst_actor_get_player (CLUTTER_GST_ACTOR (self)); + ClutterGstFrame *frame = + clutter_gst_content_get_frame (CLUTTER_GST_CONTENT (content)); + ClutterGstBox paint_box; + ClutterActorBox content_box; + ClutterPaintNode *node; + guint8 paint_opacity = clutter_actor_get_paint_opacity (actor); + ClutterColor color; + + clutter_actor_get_content_box (actor, &content_box); + + if (!frame) + { + /* No frame to paint, just paint the background color of the + actor. */ + if (priv->paint_borders) + { + clutter_actor_get_background_color (actor, &color); + color.alpha = paint_opacity; + + clutter_paint_node_add_rectangle_custom (node, + content_box.x1, content_box.y1, + content_box.x2, content_box.y2); + clutter_paint_node_add_child (root, node); + clutter_paint_node_unref (node); + } + + return; + } + + clutter_gst_aspectratio_get_frame_box (self, &paint_box, &content_box, frame); - if (priv->player) - g_signal_handlers_disconnect_by_func (priv->player, _player_size_changed, self); - priv->player = player; - if (priv->player) + if (priv->paint_borders) { - ClutterGstFrame *frame = clutter_gst_player_get_frame (player); + clutter_actor_get_background_color (actor, &color); + color.alpha = paint_opacity; - priv->frame_width = frame->resolution.width; - priv->frame_height = frame->resolution.height; + node = clutter_color_node_new (&color); + clutter_paint_node_set_name (node, "AspectRatioVideoBorders"); - g_signal_connect (priv->player, "size-change", - G_CALLBACK (_player_size_changed), self); + if (clutter_actor_box_get_width (&content_box) != + clutter_gst_box_get_width (&paint_box)) + { + clutter_paint_node_add_rectangle_custom (node, + content_box.x1, content_box.y1, + paint_box.x1, content_box.y2); + clutter_paint_node_add_rectangle_custom (node, + paint_box.x2, content_box.y1, + content_box.x2, content_box.y2); + } + if (clutter_actor_box_get_height (&content_box) != + clutter_gst_box_get_height (&paint_box)) + { + clutter_paint_node_add_rectangle_custom (node, + content_box.x1, content_box.y1, + content_box.x2, paint_box.y1); + clutter_paint_node_add_rectangle_custom (node, + content_box.x1, paint_box.y2, + content_box.x2, content_box.y2); + } + + clutter_paint_node_add_child (root, node); + clutter_paint_node_unref (node); } - _recompute_paint_box (self); + cogl_pipeline_set_color4ub (frame->pipeline, + paint_opacity, paint_opacity, + paint_opacity, paint_opacity); + + node = clutter_pipeline_node_new (frame->pipeline); + clutter_paint_node_set_name (node, "AspectRatioVideoFrame"); + + clutter_paint_node_add_rectangle_custom (node, + paint_box.x1, paint_box.y1, + paint_box.x2, paint_box.y2); + + clutter_paint_node_add_child (root, node); + clutter_paint_node_unref (node); +} + +static void +content_iface_init (ClutterContentIface *iface) +{ + iface->get_preferred_size = clutter_gst_aspectratio_get_preferred_size; + iface->paint_content = clutter_gst_aspectratio_paint_content; } /**/ +/* static void */ +/* clutter_gst_aspectratio_paint_frame (ClutterGstActor *self, */ +/* ClutterGstFrame *frame) */ +/* { */ +/* ClutterGstAspectratioPrivate *priv = CLUTTER_GST_ASPECTRATIO (self)->priv; */ +/* guint8 paint_opacity; */ + +/* paint_opacity = clutter_actor_get_paint_opacity (CLUTTER_ACTOR (self)); */ +/* cogl_pipeline_set_color4ub (frame->pipeline, */ +/* paint_opacity, */ +/* paint_opacity, */ +/* paint_opacity, */ +/* paint_opacity); */ +/* cogl_set_source (frame->pipeline); */ + +/* cogl_rectangle (priv->paint_box.x1, priv->paint_box.y1, */ +/* priv->paint_box.x2, priv->paint_box.y2); */ + +/* if (priv->paint_borders) */ +/* { */ +/* ClutterColor bg_color; */ +/* ClutterActorBox box; */ +/* gfloat box_width, box_height; */ + +/* clutter_actor_get_background_color (CLUTTER_ACTOR (self), &bg_color); */ +/* clutter_actor_get_allocation_box (CLUTTER_ACTOR (self), &box); */ + +/* box_width = clutter_actor_box_get_width (&box); */ +/* box_height = clutter_actor_box_get_height (&box); */ + +/* cogl_set_source_color4ub (bg_color.red, */ +/* bg_color.green, */ +/* bg_color.blue, */ +/* paint_opacity); */ + +/* if (box_width != clutter_actor_box_get_width (&priv->paint_box)) */ +/* { */ +/* cogl_rectangle (0, 0, priv->paint_box.x1, box_height); */ +/* cogl_rectangle (priv->paint_box.x2, 0, box_width, box_height); */ +/* } */ +/* if (box_height != clutter_actor_box_get_height (&priv->paint_box)) */ +/* { */ +/* cogl_rectangle (0, 0, box_width, priv->paint_box.y1); */ +/* cogl_rectangle (0, priv->paint_box.y2, box_width, box_height); */ +/* } */ +/* } */ +/* } */ + +/* static void */ +/* _recompute_paint_box (ClutterGstAspectratio *self) */ +/* { */ +/* ClutterGstAspectratioPrivate *priv = self->priv; */ +/* ClutterActorBox box; */ +/* gfloat actor_width, actor_height; */ +/* gdouble new_width, new_height; */ +/* gdouble frame_aspect, actor_aspect; */ + +/* clutter_actor_get_allocation_box (CLUTTER_ACTOR (self), &box); */ + +/* actor_width = box.x2 - box.x1; */ +/* actor_height = box.y2 - box.y1; */ + +/* if (actor_width <= 0 || actor_height <= 0) */ +/* return; */ + +/* frame_aspect = (gdouble) priv->frame_width / (gdouble) priv->frame_height; */ +/* actor_aspect = actor_width / actor_height; */ + +/* if (actor_aspect < frame_aspect) */ +/* { */ +/* new_width = actor_width; */ +/* new_height = actor_width / frame_aspect; */ +/* } */ +/* else */ +/* { */ +/* new_height = actor_height; */ +/* new_width = actor_height * frame_aspect; */ +/* } */ + +/* priv->paint_box.x1 = (actor_width - new_width) / 2; */ +/* priv->paint_box.y1 = (actor_height - new_height) / 2; */ +/* priv->paint_box.x2 = priv->paint_box.x1 + new_width; */ +/* priv->paint_box.y2 = priv->paint_box.y1 + new_height; */ +/* } */ + +/* static void */ +/* _player_size_changed (ClutterGstPlayer *player, */ +/* gint width, */ +/* gint height, */ +/* ClutterGstAspectratio *self) */ +/* { */ +/* ClutterGstAspectratioPrivate *priv = self->priv; */ + +/* priv->frame_width = width; */ +/* priv->frame_height = height; */ + +/* _recompute_paint_box (self); */ +/* clutter_actor_queue_relayout (CLUTTER_ACTOR (self)); */ +/* } */ + +/* static void */ +/* _player_changed (ClutterGstAspectratio *self, */ +/* GParamSpec *spec, */ +/* gpointer user_data) */ +/* { */ +/* ClutterGstAspectratioPrivate *priv = self->priv; */ +/* ClutterGstPlayer *player = clutter_gst_actor_get_player (CLUTTER_GST_ACTOR (self)); */ + +/* if (priv->player) */ +/* g_signal_handlers_disconnect_by_func (priv->player, _player_size_changed, self); */ +/* priv->player = player; */ +/* if (priv->player) */ +/* { */ +/* ClutterGstFrame *frame = clutter_gst_player_get_frame (player); */ + +/* priv->frame_width = frame->resolution.width; */ +/* priv->frame_height = frame->resolution.height; */ + +/* g_signal_connect (priv->player, "size-change", */ +/* G_CALLBACK (_player_size_changed), self); */ +/* } */ + +/* _recompute_paint_box (self); */ +/* } */ + +/**/ + static void clutter_gst_aspectratio_get_property (GObject *object, guint property_id, @@ -253,7 +365,11 @@ clutter_gst_aspectratio_set_property (GObject *object, switch (property_id) { case PROP_PAINT_BORDERS: - priv->paint_borders = g_value_get_boolean (value); + if (priv->paint_borders != g_value_get_boolean (value)) + { + priv->paint_borders = g_value_get_boolean (value); + clutter_content_invalidate (CLUTTER_CONTENT (object)); + } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -276,8 +392,6 @@ static void clutter_gst_aspectratio_class_init (ClutterGstAspectratioClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - ClutterGstActorClass *gst_actor_class = CLUTTER_GST_ACTOR_CLASS (klass); GParamSpec *pspec; g_type_class_add_private (klass, sizeof (ClutterGstAspectratioPrivate)); @@ -287,11 +401,6 @@ clutter_gst_aspectratio_class_init (ClutterGstAspectratioClass *klass) object_class->dispose = clutter_gst_aspectratio_dispose; object_class->finalize = clutter_gst_aspectratio_finalize; - actor_class->get_preferred_width = clutter_gst_aspectratio_get_preferred_width; - actor_class->get_preferred_height = clutter_gst_aspectratio_get_preferred_height; - - gst_actor_class->paint_frame = clutter_gst_aspectratio_paint_frame; - /** * ClutterGstAspectratio:paint-borders: * @@ -311,14 +420,14 @@ static void clutter_gst_aspectratio_init (ClutterGstAspectratio *self) { self->priv = ASPECTRATIO_PRIVATE (self); - - g_signal_connect (self, "notify::player", - G_CALLBACK (_player_changed), NULL); - g_signal_connect_swapped (self, "allocation-changed", - G_CALLBACK (_recompute_paint_box), self); } -ClutterActor * +/** + * clutter_gst_aspectratio_new: + * + * Returns: (transfer full): a new #ClutterGstAspectratio instance + */ +ClutterContent * clutter_gst_aspectratio_new (void) { return g_object_new (CLUTTER_GST_TYPE_ASPECTRATIO, NULL); |