diff options
author | Filippo Argiolas <filippo.argiolas@gmail.com> | 2009-04-04 18:01:06 +0200 |
---|---|---|
committer | Filippo Argiolas <filippo.argiolas@gmail.com> | 2009-04-04 18:01:06 +0200 |
commit | 779e11f6d89efced9c8a81ae2a7d089f3b5722b5 (patch) | |
tree | 18e9899d136d9203795a107245de0b607ef185b6 | |
parent | 106b6400907a6f48bfae35030e888eabff22e399 (diff) |
Create xwindows directly from cheese_texture_new
Rearrange everything a bit to abstract the window creation process
-rw-r--r-- | src/cheese-stage.c | 115 | ||||
-rw-r--r-- | src/cheese-texture.c | 35 | ||||
-rw-r--r-- | src/cheese-texture.h | 3 |
3 files changed, 68 insertions, 85 deletions
diff --git a/src/cheese-stage.c b/src/cheese-stage.c index cf2a5d2..59c93c8 100644 --- a/src/cheese-stage.c +++ b/src/cheese-stage.c @@ -35,17 +35,8 @@ #define W 160 #define H 120 -struct GstGLClutterActor_ -{ - Window win; - Window root; - ClutterActor *texture; - ClutterActor *stage; -}; - -typedef struct GstGLClutterActor_ GstGLClutterActor; -static ClutterX11FilterReturn event_filter (XEvent * ev, ClutterEvent * cev, +/*static ClutterX11FilterReturn event_filter (XEvent * ev, ClutterEvent * cev, gpointer unused); static ClutterX11FilterReturn @@ -84,37 +75,15 @@ event_filter (XEvent * ev, ClutterEvent * cev, gpointer data) return CLUTTER_X11_FILTER_CONTINUE; } } - -static gboolean -create_actor (GstGLClutterActor * actor) -{ - static gint xpos = 0; - static gint ypos = 0; - Display *disp; - actor->texture = g_object_new (CHEESE_TYPE_TEXTURE, - "window", actor->win, "automatic-updates", TRUE, NULL); - clutter_container_add_actor (CLUTTER_CONTAINER (actor->stage), - actor->texture); - clutter_actor_set_position (actor->texture, xpos, ypos); - - disp = clutter_x11_get_default_display (); - - if (xpos > (COLS - 1) * W) { - xpos = 0; - ypos += H + 1; - } else - xpos += W + 1; - clutter_actor_show (actor->texture); - - return FALSE; -} +*/ static GstBusSyncReply create_window (GstBus * bus, GstMessage * message, gpointer data) { - GstGLClutterActor **actor = (GstGLClutterActor **) data; + CheeseTexture **actor = (CheeseTexture **) data; static gint count = 0; static GMutex *mutex = NULL; + Window win; // ignore anything but 'prepare-xwindow-id' element messages if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT) return GST_BUS_PASS; @@ -128,10 +97,10 @@ create_window (GstBus * bus, GstMessage * message, gpointer data) g_mutex_lock (mutex); if (count < N_ACTORS) { - g_message ("adding actor %d", count); + g_object_get (G_OBJECT (actor[count]), "window", &win, NULL); + g_message ("adding actor: %d win: %d", count, win); gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)), - actor[count]->win); - clutter_threads_add_idle ((GSourceFunc) create_actor, actor[count]); + win); count++; } @@ -174,17 +143,18 @@ main (int argc, char *argv[]) GstElement *upload[N_ACTORS]; GstElement *effect[N_ACTORS]; */ - ClutterActor *stage; - GstGLClutterActor *actor[N_ACTORS]; - Window windows[N_ACTORS + 1]; - Display *disp; - Window stage_win; const gchar *desc; gint i; gint ok = FALSE; - XSetWindowAttributes attributes; - unsigned long mask; + gint xpos = 0; + gint ypos = 0; + + Display *disp; + + ClutterActor *stage; + ClutterColor color; + ClutterActor *actor[N_ACTORS]; clutter_init (&argc, &argv); gst_init (&argc, &argv); @@ -197,34 +167,25 @@ main (int argc, char *argv[]) stage = clutter_stage_get_default (); clutter_actor_set_size (CLUTTER_ACTOR (stage), W * COLS + (COLS - 1), H * ROWS + (ROWS - 1)); - - stage_win = clutter_x11_get_stage_window (CLUTTER_STAGE (stage)); - - attributes.background_pixel = BlackPixel (disp, DefaultScreen (disp)); - attributes.event_mask = StructureNotifyMask | VisibilityChangeMask; - mask = CWBackPixel | CWEventMask; + + clutter_color_from_string (&color, "DarkSlateGrey"); + clutter_stage_set_color (CLUTTER_STAGE (stage), &color); +// clutter_stage_set_user_resizable (stage, TRUE); for (i = 0; i < N_ACTORS; i++) { - actor[i] = g_new0 (GstGLClutterActor, 1); - actor[i]->stage = stage; - actor[i]->win = XCreateWindow (disp, stage_win, - 0, 0, W, H, 0, CopyFromParent, InputOutput, CopyFromParent, - mask, &attributes); - windows[i] = actor[i]->win; - XCompositeRedirectWindow (disp, actor[i]->win, CompositeRedirectManual); - XMapRaised (disp, actor[i]->win); - XSync (disp, FALSE); + actor[i] = cheese_texture_new (); + clutter_container_add_actor (CLUTTER_CONTAINER (stage), + actor[i]); + clutter_actor_set_position (actor[i], xpos, ypos); + if (xpos > (COLS - 1) * W) { + xpos = 0; + ypos += H + 1; + } else + xpos += W + 1; + clutter_actor_show (actor[i]); } - windows[N_ACTORS] = stage_win; - clutter_x11_add_filter (event_filter, windows); +// clutter_x11_add_filter (event_filter, actor); -/* - desc = g_strdup_printf ("v4l2src ! " - "video/x-raw-yuv, width=640, height=480, framerate=30/1 ! " - "videoscale !" - "video/x-raw-yuv, width=%d, height=%d ! " - "identity", W, H); -*/ desc = g_strdup_printf ("videotestsrc ! " "video/x-raw-rgb, width=%d, height=%d !" "identity", W, H); pipeline = GST_PIPELINE (gst_pipeline_new (NULL)); @@ -239,33 +200,19 @@ main (int argc, char *argv[]) for (i = 0; i < N_ACTORS; i++) { queue[i] = gst_element_factory_make ("queue", NULL); -/* upload[i] = gst_element_factory_make ("glupload", NULL); - effect[i] = gst_element_factory_make ("gleffects", NULL); */ sink[i] = gst_element_factory_make ("glimagesink", NULL); -/* gst_bin_add_many (GST_BIN (pipeline), - queue[i], upload[i], effect[i], sink[i], NULL); */ gst_bin_add_many (GST_BIN (pipeline), queue[i], sink[i], NULL); } gst_element_link_many (srcbin, tee, NULL); for (i = 0; i < N_ACTORS; i++) { - ok |= -// gst_element_link_many (tee, queue[i], upload[i], effect[i], sink[i], - gst_element_link_many (tee, queue[i], sink[i], NULL); + ok |= gst_element_link_many (tee, queue[i], sink[i], NULL); } if (!ok) g_error ("Failed to link one or more elements"); -/* - for (i = 0; i < N_ACTORS; i++) { - g_message ("setting effect %d on %s", i + 1, - gst_element_get_name (effect[i])); - g_object_set (G_OBJECT (effect[i]), "effect", i + 1, NULL); - } -*/ - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, actor); diff --git a/src/cheese-texture.c b/src/cheese-texture.c index 9b1dc31..65a967c 100644 --- a/src/cheese-texture.c +++ b/src/cheese-texture.c @@ -60,7 +60,40 @@ cheese_texture_init (CheeseTexture *self) ClutterActor * cheese_texture_new (void) { - ClutterActor *self = g_object_new (CHEESE_TYPE_TEXTURE, NULL); + Display *disp; + Window win; + Window stage_win; + XSetWindowAttributes attr; + unsigned long mask; + ClutterActor *stage; + ClutterActor *self; + + /* require xcomposite */ + g_assert (clutter_x11_has_composite_extension ()); + + disp = clutter_x11_get_default_display (); + + stage = clutter_stage_get_default (); + stage_win = clutter_x11_get_stage_window (CLUTTER_STAGE (stage)); + + attr.background_pixel = BlackPixel (disp, DefaultScreen (disp)); + attr.event_mask = SubstructureNotifyMask; + mask = CWBackPixel | CWEventMask; + + win = XCreateWindow (disp, stage_win, + 0, 0, DEFAULT_W, DEFAULT_H, 0, + CopyFromParent, InputOutput, CopyFromParent, + mask, &attr); + + XCompositeRedirectWindow (disp, win, CompositeRedirectManual); + XMapRaised (disp, win); + XSync (disp, FALSE); + + g_message ("created win: %d", win); + + self = g_object_new (CHEESE_TYPE_TEXTURE, + "window", win, "automatic-updates", TRUE, NULL); + return self; } diff --git a/src/cheese-texture.h b/src/cheese-texture.h index 44f1db9..eedf6e5 100644 --- a/src/cheese-texture.h +++ b/src/cheese-texture.h @@ -28,6 +28,9 @@ /* TODO: fallback to X11 TFP if GLX is not supported */ #include <clutter/glx/clutter-glx.h> +#define DEFAULT_W 160 +#define DEFAULT_H 120 + G_BEGIN_DECLS #define CHEESE_TYPE_TEXTURE (cheese_texture_get_type()) |