Blame tests/examples/gl/clutter/clutteractor.c

Packit 971217
/* 
Packit 971217
 * GStreamer
Packit 971217
 * Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
#ifdef HAVE_CONFIG_H
Packit 971217
#include "config.h"
Packit 971217
#endif
Packit 971217
Packit 971217
#define CLUTTER_VERSION_MIN_REQUIRED CLUTTER_VERSION_1_8
Packit 971217
Packit 971217
#include <X11/Xlib.h>
Packit 971217
#include <X11/extensions/Xcomposite.h>
Packit 971217
#include <clutter/clutter.h>
Packit 971217
#include <clutter/x11/clutter-x11.h>
Packit 971217
#include <clutter/glx/clutter-glx.h>
Packit 971217
#include <gst/gst.h>
Packit 971217
#include <gst/video/videooverlay.h>
Packit 971217
Packit 971217
#define W 320
Packit 971217
#define H 240
Packit 971217
Packit 971217
struct GstGLClutterActor_
Packit 971217
{
Packit 971217
  Window win;
Packit 971217
  Window root;
Packit 971217
  ClutterActor *texture;
Packit 971217
  ClutterActor *stage;
Packit 971217
};
Packit 971217
Packit 971217
typedef struct GstGLClutterActor_ GstGLClutterActor;
Packit 971217
Packit 971217
static gboolean
Packit 971217
create_actor (GstGLClutterActor * actor)
Packit 971217
{
Packit 971217
  //ClutterKnot knot[2];
Packit 971217
  //ClutterTimeline *timeline;
Packit 971217
  ClutterAnimation *animation = NULL;
Packit 971217
Packit 971217
  actor->texture = g_object_new (CLUTTER_X11_TYPE_TEXTURE_PIXMAP,
Packit 971217
      "window", actor->win, "automatic-updates", TRUE, NULL);
Packit 971217
  clutter_container_add_actor (CLUTTER_CONTAINER (actor->stage),
Packit 971217
      actor->texture);
Packit 971217
  clutter_actor_set_scale (actor->texture, 0.2, 0.2);
Packit 971217
  clutter_actor_set_opacity (actor->texture, 0);
Packit 971217
  clutter_actor_show (actor->texture);
Packit 971217
Packit 971217
  //timeline =
Packit 971217
  //    clutter_timeline_new (120 /* frames */ , 50 /* frames per second. */ );
Packit 971217
  //clutter_timeline_set_loop (timeline, TRUE);
Packit 971217
  //clutter_timeline_start (timeline);
Packit 971217
Packit 971217
  /* Instead of our custom callback, 
Packit 971217
   * we could use a standard callback. For instance, CLUTTER_ALPHA_SINE_INC. 
Packit 971217
   */
Packit 971217
  /*effect_template =
Packit 971217
     clutter_effect_template_new (timeline, CLUTTER_ALPHA_SINE_INC); */
Packit 971217
  animation =
Packit 971217
      clutter_actor_animate (actor->texture, CLUTTER_LINEAR, 2400,
Packit 971217
      "x", 100.0, "y", 100.0, "opacity", 0, NULL);
Packit 971217
Packit 971217
  /* knot[0].x = -10;
Packit 971217
     knot[0].y = -10;
Packit 971217
     knot[1].x = 160;
Packit 971217
     knot[1].y = 120; */
Packit 971217
Packit 971217
  // Move the actor along the path:
Packit 971217
  /* clutter_effect_path (effect_template, actor->texture, knot,
Packit 971217
     sizeof (knot) / sizeof (ClutterKnot), NULL, NULL);
Packit 971217
     clutter_effect_scale (effect_template, actor->texture, 1.0, 1.0, NULL, NULL);
Packit 971217
     clutter_effect_rotate (effect_template, actor->texture,
Packit 971217
     CLUTTER_Z_AXIS, 360.0, W / 2.0, H / 2.0, 0.0,
Packit 971217
     CLUTTER_ROTATE_CW, NULL, NULL);
Packit 971217
     clutter_effect_rotate (effect_template, actor->texture,
Packit 971217
     CLUTTER_X_AXIS, 360.0, 0.0, W / 4.0, 0.0, CLUTTER_ROTATE_CW, NULL, NULL); */
Packit 971217
Packit 971217
  // Also change the actor's opacity while moving it along the path:
Packit 971217
  // (You would probably want to use a different ClutterEffectTemplate, 
Packit 971217
  // so you could use a different alpha callback for this.)
Packit 971217
  //clutter_effect_fade (effect_template, actor->texture, 255, NULL, NULL);
Packit 971217
Packit 971217
  g_object_unref (animation);
Packit 971217
  //g_object_unref (timeline);
Packit 971217
Packit 971217
  return FALSE;
Packit 971217
}
Packit 971217
Packit 971217
static GstBusSyncReply
Packit 971217
create_window (GstBus * bus, GstMessage * message, gpointer data)
Packit 971217
{
Packit 971217
  GstGLClutterActor *actor = (GstGLClutterActor *) data;
Packit 971217
  // ignore anything but 'prepare-window-handle' element messages
Packit 971217
  if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
Packit 971217
    return GST_BUS_PASS;
Packit 971217
Packit 971217
  if (!gst_is_video_overlay_prepare_window_handle_message (message))
Packit 971217
    return GST_BUS_PASS;
Packit 971217
Packit 971217
  g_debug ("CREATING WINDOW");
Packit 971217
Packit 971217
  gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (GST_MESSAGE_SRC
Packit 971217
          (message)), actor->win);
Packit 971217
  clutter_threads_add_idle ((GSourceFunc) create_actor, actor);
Packit 971217
Packit 971217
  gst_message_unref (message);
Packit 971217
  return GST_BUS_DROP;
Packit 971217
}
Packit 971217
Packit 971217
int
Packit 971217
main (int argc, char *argv[])
Packit 971217
{
Packit 971217
  GstPipeline *pipeline;
Packit 971217
  GstBus *bus;
Packit 971217
  ClutterActor *stage;
Packit 971217
  GstGLClutterActor *actor;
Packit 971217
  Display *disp;
Packit 971217
  Window stage_win;
Packit 971217
  ClutterInitError clutter_err = CLUTTER_INIT_ERROR_UNKNOWN;
Packit 971217
Packit 971217
  clutter_err = clutter_init (&argc, &argv);
Packit 971217
  if (clutter_err != CLUTTER_INIT_SUCCESS)
Packit 971217
    g_warning ("Failed to initalize clutter: %d\n", clutter_err);
Packit 971217
Packit 971217
  gst_init (&argc, &argv);
Packit 971217
Packit 971217
  disp = clutter_x11_get_default_display ();
Packit 971217
  if (!clutter_x11_has_composite_extension ()) {
Packit 971217
    g_error ("XComposite extension missing");
Packit 971217
  }
Packit 971217
Packit 971217
Packit 971217
  stage = clutter_stage_get_default ();
Packit 971217
//  clutter_actor_set_size (CLUTTER_ACTOR (stage), W*3+2, H);
Packit 971217
Packit 971217
  stage_win = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
Packit 971217
Packit 971217
  actor = g_new0 (GstGLClutterActor, 1);
Packit 971217
  actor->stage = stage;
Packit 971217
  actor->win = XCreateSimpleWindow (disp, stage_win, 0, 0, W, H, 0, 0, 0);
Packit 971217
  XCompositeRedirectWindow (disp, actor->win, CompositeRedirectManual);
Packit 971217
  XMapRaised (disp, actor->win);
Packit 971217
  XSync (disp, FALSE);
Packit 971217
Packit 971217
  pipeline =
Packit 971217
      GST_PIPELINE (gst_parse_launch
Packit 971217
      ("videotestsrc ! video/x-raw, width=320, height=240, framerate=(fraction)30/1 ! "
Packit 971217
          "gleffects effect=twirl ! glimagesink", NULL));
Packit 971217
Packit 971217
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
Packit 971217
Packit 971217
  gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, actor,
Packit 971217
      NULL);
Packit 971217
  gst_object_unref (bus);
Packit 971217
Packit 971217
  gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
Packit 971217
Packit 971217
  clutter_actor_show_all (stage);
Packit 971217
Packit 971217
  clutter_main ();
Packit 971217
Packit 971217
  gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
Packit 971217
  gst_object_unref (pipeline);
Packit 971217
Packit 971217
  return 0;
Packit 971217
}