/** * shell_global_create_root_pixmap_actor: * @global: a #ShellGlobal * * Creates an actor showing the root window pixmap. * * Return value: (transfer none): a #ClutterActor with the root window pixmap. * The actor is floating, hence (transfer none). */ ClutterActor * shell_global_create_root_pixmap_actor (ShellGlobal *global) { GdkWindow *window; ClutterActor *stage; ClutterColor stage_color; /* The actor created is actually a ClutterClone of global->root_pixmap. */ if (global->root_pixmap == NULL) { global->root_pixmap = clutter_glx_texture_pixmap_new (); clutter_texture_set_repeat (CLUTTER_TEXTURE (global->root_pixmap), TRUE, TRUE); /* The low and medium quality filters give nearest-neighbor resizing. */ clutter_texture_set_filter_quality (CLUTTER_TEXTURE (global->root_pixmap), CLUTTER_TEXTURE_QUALITY_HIGH); /* Initialize to the stage color, since that's what will be seen * in the main view if there's no actual background window. */ stage = mutter_plugin_get_stage (global->plugin); clutter_stage_get_color (CLUTTER_STAGE (stage), &stage_color); clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (global->root_pixmap), /* ClutterColor has the same layout * as one pixel of RGB(A) data. */ (const guchar *)&stage_color, FALSE, /* w, h, rowstride, bpp, flags */ 1, 1, 3, 3, 0, NULL); /* We can only clone an actor within a stage, so we hide the source * texture then add it to the stage */ clutter_actor_hide (global->root_pixmap); clutter_container_add_actor (CLUTTER_CONTAINER (stage), global->root_pixmap); /* This really should never happen; but just in case... */ g_signal_connect (global->root_pixmap, "destroy", G_CALLBACK (root_pixmap_destroy), global); /* Metacity handles changes to some root window properties in its global * event filter, though not _XROOTPMAP_ID. For all root window property * changes, the global filter returns GDK_FILTER_CONTINUE, so our * window specific filter will be called after the global one. * * Because Metacity is already handling root window property updates, * we don't have to worry about adding the PropertyChange mask to the * root window to get PropertyNotify events. */ window = gdk_get_default_root_window (); gdk_window_add_filter (window, root_window_filter, global); update_root_window_pixmap (global); } return clutter_clone_new (global->root_pixmap); }
static void on_depth_frame (GFreenectDevice *kinect, gpointer user_data) { gint width, height; gint dimension_factor; guchar *grayscale_buffer; guint16 *depth; BufferInfo *buffer_info; gsize len; GError *error = NULL; GFreenectFrameMode frame_mode; depth = (guint16 *) gfreenect_device_get_depth_frame_raw (kinect, &len, &frame_mode); width = frame_mode.width; height = frame_mode.height; g_object_get (skeleton, "dimension-reduction", &dimension_factor, NULL); buffer_info = process_buffer (depth, width, height, dimension_factor, THRESHOLD_BEGIN, THRESHOLD_END); skeltrack_skeleton_track_joints (skeleton, buffer_info->reduced_buffer, buffer_info->reduced_width, buffer_info->reduced_height, NULL, on_track_joints, buffer_info); if (!SHOW_SKELETON) { grayscale_buffer = create_grayscale_buffer (buffer_info, dimension_factor); if (! clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (depth_tex), grayscale_buffer, FALSE, width, height, 0, 3, CLUTTER_TEXTURE_NONE, &error)) { g_debug ("Error setting texture area: %s", error->message); g_error_free (error); } g_slice_free1 (width * height * sizeof (guchar) * 3, grayscale_buffer); } }
void Images::load_texture( ClutterTexture * texture, TPImage * image , guint x , guint y , guint w , guint h ) { PROFILER( "Images::load_texture/clutter" , PROFILER_INTERNAL_CALLS ); g_assert( texture ); g_assert( image ); const guchar * pixels = ( const guchar * ) image->pixels; guint width = image->width; guint height = image->height; if ( w != 0 && h != 0 ) { pixels += x * image->depth + y * image->pitch; width = w; height = h; } ClutterTextureFlags flags = image->bgr ? CLUTTER_TEXTURE_RGB_FLAG_BGR : CLUTTER_TEXTURE_NONE; if ( image->depth == 4 && image->pm_alpha ) { flags = ( ClutterTextureFlags ) ( flags | CLUTTER_TEXTURE_RGB_FLAG_PREMULT ); } clutter_texture_set_from_rgb_data( texture, pixels, image->depth == 4, width, height, image->pitch, image->depth, flags, NULL ); #ifndef TP_PRODUCTION ImageInfo info( image ); if ( w !=0 && h != 0 ) { info.width = w; info.height = h; info.bytes = w * h * image->depth; } add_to_image_list( texture , info ); #endif }
static void opt_show_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { OptShow *show = OPT_SHOW(object); OptShowPrivate *priv; priv = show->priv; switch (prop_id) { case PROP_TITLE_BORDER_SIZE: priv->title_border_size = g_value_get_int (value); break; case PROP_TITLE_BULLET_PAD: priv->title_bullet_pad = g_value_get_int (value); break; case PROP_BULLET_BORDER_SIZE: priv->bullet_border_size = g_value_get_int (value); break; case PROP_BULLET_PAD: priv->bullet_pad = g_value_get_int (value); break; case PROP_TITLE_FONT: if (priv->title_font) g_free (priv->title_font); priv->title_font = g_value_dup_string (value); break; case PROP_BULLET_FONT: if (priv->bullet_font) g_free (priv->bullet_font); priv->bullet_font = g_value_dup_string (value); break; case PROP_BACKGROUND: priv->background = g_value_get_object (value); clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (priv->bg), gdk_pixbuf_get_pixels (priv->background), gdk_pixbuf_get_has_alpha (priv->background), gdk_pixbuf_get_width (priv->background), gdk_pixbuf_get_height (priv->background), gdk_pixbuf_get_rowstride (priv->background), gdk_pixbuf_get_n_channels (priv->background), 0, NULL); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
/** * shell_clutter_texture_set_from_pixbuf: * texture: #ClutterTexture to be modified * pixbuf: #GdkPixbuf to set as an image for #ClutterTexture * * Convenience function for setting an image for #ClutterTexture based on #GdkPixbuf. * Copied from an example posted by hp in this thread http://mail.gnome.org/archives/gtk-devel-list/2008-September/msg00218.html * * Return value: %TRUE on success, %FALSE on failure */ gboolean shell_clutter_texture_set_from_pixbuf (ClutterTexture *texture, GdkPixbuf *pixbuf) { return clutter_texture_set_from_rgb_data (texture, gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf), gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), gdk_pixbuf_get_rowstride (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3, 0, NULL); }
static void clutter_gst_ayuv_upload (ClutterGstVideoSink *sink, GstBuffer *buffer) { ClutterGstVideoSinkPrivate *priv= sink->priv; clutter_texture_set_from_rgb_data (priv->texture, GST_BUFFER_DATA (buffer), TRUE, priv->width, priv->height, GST_ROUND_UP_4 (4 * priv->width), 4, 0, NULL); }
static void clutter_gst_rgb32_upload (ClutterGstVideoSink *sink, GstBuffer *buffer) { ClutterGstVideoSinkPrivate *priv= sink->priv; clutter_texture_set_from_rgb_data (priv->texture, GST_BUFFER_DATA (buffer), TRUE, priv->width, priv->height, GST_ROUND_UP_4 (4 * priv->width), 4, priv->bgr ? CLUTTER_TEXTURE_RGB_FLAG_BGR : 0, NULL); }
/** * gtk_clutter_texture_set_from_pixbuf: * @texture: a #GtkClutterTexture * @pixbuf: a #GdkPixbuf * @error: a return location for errors * * Sets the contents of @texture with a copy of @pixbuf. * * Return value: %TRUE on success, %FALSE on failure. */ gboolean gtk_clutter_texture_set_from_pixbuf (GtkClutterTexture *texture, GdkPixbuf *pixbuf, GError **error) { g_return_val_if_fail (GTK_CLUTTER_IS_TEXTURE (texture), FALSE); g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE); return clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (texture), gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf), gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), gdk_pixbuf_get_rowstride (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3, 0, error); }
void show_image(XImage *img) { ClutterActor *stage, *actor; // init stage clutter_init(0, NULL); stage = clutter_stage_get_default(); // XX TODO: use root window? // init actor actor = clutter_texture_new(); clutter_texture_set_from_rgb_data(CLUTTER_TEXTURE(actor), img->data, False, img->width, img->height, img->bytes_per_line, 4, (ClutterTextureFlags)0, NULL); clutter_container_add(CLUTTER_CONTAINER(stage), actor, NULL); clutter_actor_set_position(actor, 10, 10); g_signal_connect(stage, "button-press-event", clutter_main_quit, NULL); // show and wait for exit clutter_actor_show(stage); clutter_main(); }
static gboolean paint_texture (guchar *buffer, guint width, guint height) { GError *error = NULL; if (! clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (depth_tex), buffer, FALSE, width, height, 0, 3, CLUTTER_TEXTURE_NONE, &error)) { g_debug ("Error setting texture area: %s", error->message); g_error_free (error); return FALSE; } g_slice_free1 (width * height * sizeof (guchar) * 3, buffer); return TRUE; }
static void on_video_frame (GFreenectDevice *kinect, gpointer user_data) { guchar *buffer; GError *error = NULL; GFreenectFrameMode frame_mode; buffer = gfreenect_device_get_video_frame_rgb (kinect, NULL, &frame_mode); if (! clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (video_tex), buffer, FALSE, frame_mode.width, frame_mode.height, 0, frame_mode.bits_per_pixel / 8, CLUTTER_TEXTURE_NONE, &error)) { g_debug ("Error setting texture area: %s", error->message); g_error_free (error); } }
static void ntf_libnotify_update (NtfNotification *ntf, Notification *details) { ClutterActor *icon = NULL; g_return_if_fail (store && ntf && details); if (details->summary) ntf_notification_set_summary (ntf, details->summary); if (details->body) ntf_notification_set_body (ntf, details->body); if (details->icon_pixbuf) { GdkPixbuf *pixbuf = details->icon_pixbuf; icon = clutter_texture_new (); clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (icon), gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf), gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), gdk_pixbuf_get_rowstride (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3, 0, NULL); } else if (details->icon_name) { GtkIconTheme *theme; GtkIconInfo *info; theme = gtk_icon_theme_get_default (); info = gtk_icon_theme_lookup_icon (theme, details->icon_name, 24, 0); if (info) { icon = clutter_texture_new (); clutter_texture_set_from_file (CLUTTER_TEXTURE(icon), gtk_icon_info_get_filename (info), NULL); gtk_icon_info_free (info); } } if (icon) clutter_actor_set_size (icon, 24.0, 24.0); ntf_notification_set_icon (ntf, icon); if (details->actions) { GList *action; gchar *key, *value; ntf_notification_remove_all_buttons (ntf); for (action = details->actions; action;) { /* * The action list length is * guaranteed to be % 2 and > 0 */ key = action->data; action = g_list_next (action); value = action->data; action = g_list_next (action); if (strcasecmp(key, "default") != 0) { ActionData *data; ClutterActor *button; KeySym keysym = 0; data = g_slice_new0 (ActionData); data->notification = ntf; data->action = g_strdup (key); data->id = details->id; data->store = store; button = mx_button_new (); mx_button_set_label (MX_BUTTON (button), value); g_signal_connect_data (button, "clicked", G_CALLBACK (ntf_libnotify_action_cb), data, (GClosureNotify) free_action_data, 0); /* * Handle the dawati key shortcut protocol */ if (!strncmp (key, DAWATI_KEY_PREFIX, strlen (DAWATI_KEY_PREFIX))) { const char *k = key + strlen (DAWATI_KEY_PREFIX); const char *pfx = strstr (k, "XK_"); char *name; if (pfx) { if (k == pfx) { name = g_strdup (k + 3); } else { name = g_strdup (k); name [pfx - k] = 0; strcat (name, pfx + 3); } keysym = XStringToKeysym (name); if (!keysym) g_warning (G_STRLOC ": no keysym found for %s (%s)", key, name); g_free (name); } else { g_warning (G_STRLOC ": invalid key %s", key); } } ntf_notification_add_button (ntf, button, key, keysym); mx_stylable_set_style_class (MX_STYLABLE (button), "Primary"); } } } ntf_notification_set_urgent (ntf, details->is_urgent); ntf_notification_set_timeout (ntf, details->timeout_ms); }
static void render (ChamplainRenderer *renderer, ChamplainTile *tile) { ChamplainImageRendererPrivate *priv = GET_PRIVATE (renderer); gboolean error = TRUE; GdkPixbufLoader *loader = NULL; GError *gerror = NULL; ClutterActor *actor = NULL; GdkPixbuf *pixbuf; if (!priv->data || priv->size == 0) goto finish; loader = gdk_pixbuf_loader_new (); if (!gdk_pixbuf_loader_write (loader, (const guchar *) priv->data, priv->size, &gerror)) { if (gerror) { g_warning ("Unable to load the pixbuf: %s", gerror->message); g_error_free (gerror); } goto finish; } gdk_pixbuf_loader_close (loader, &gerror); if (gerror) { g_warning ("Unable to close the pixbuf loader: %s", gerror->message); g_error_free (gerror); goto finish; } /* Load the image into clutter */ pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); actor = clutter_texture_new (); if (!clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (actor), gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf), gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), gdk_pixbuf_get_rowstride (pixbuf), gdk_pixbuf_get_bits_per_sample (pixbuf) * gdk_pixbuf_get_n_channels (pixbuf) / 8, 0, &gerror)) { if (gerror) { g_warning ("Unable to transfer to clutter: %s", gerror->message); g_error_free (gerror); } g_object_unref (actor); actor = NULL; goto finish; } error = FALSE; finish: if (actor) champlain_tile_set_content (tile, actor); g_signal_emit_by_name (tile, "render-complete", priv->data, priv->size, error); if (loader) g_object_unref (loader); }
static void on_depth_frame (GFreenectDevice *kinect, gpointer user_data) { gint width, height; guchar *grayscale_buffer; guint16 *depth; gchar *contents; BufferInfo *buffer_info; gsize len; GError *error = NULL; GFreenectFrameMode frame_mode; depth = (guint16 *) gfreenect_device_get_depth_frame_raw (kinect, &len, &frame_mode); if (error != NULL) { g_debug ("ERROR Opening: %s", error->message); } width = frame_mode.width; height = frame_mode.height; buffer_info = process_buffer (depth, width, height, 1, THRESHOLD_BEGIN, THRESHOLD_END); grayscale_buffer = create_grayscale_buffer (buffer_info, 1); if (record_shot) { g_debug ("Taking shot..."); GError *error = NULL; gchar *name = g_strdup_printf ("./depth-data-%d", g_get_real_time ()); g_file_set_contents (name, (gchar *) buffer_info->reduced_buffer, width * height * sizeof (guint16), &error); if (error != NULL) { g_debug ("ERROR: %s", error->message); } else { g_print ("Created file: %s\n", name); } record_shot = FALSE; } if (! clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (depth_tex), grayscale_buffer, FALSE, width, height, 0, 3, CLUTTER_TEXTURE_NONE, &error)) { g_debug ("Error setting texture area: %s", error->message); g_error_free (error); } g_slice_free1 (width * height * sizeof (guchar) * 3, grayscale_buffer); }
static void clutter_x11_texture_pixmap_update_area_real (ClutterX11TexturePixmap *texture, gint x, gint y, gint width, gint height) { ClutterX11TexturePixmapPrivate *priv; Display *dpy; XImage *image; char *first_pixel; GError *error = NULL; guint bytes_per_line; char *data; int err_code; char pixel_bpp; gboolean pixel_has_alpha; #if 0 clock_t start_t = clock(); #endif if (!CLUTTER_ACTOR_IS_REALIZED (texture)) return; priv = texture->priv; dpy = clutter_x11_get_default_display(); if (!priv->pixmap) return; if (priv->shminfo.shmid == -1) try_alloc_shm (texture); clutter_x11_trap_x_errors (); if (priv->have_shm) { image = XShmCreateImage(dpy, DefaultVisual(dpy, clutter_x11_get_default_screen()), priv->depth, ZPixmap, NULL, &priv->shminfo, width, height); image->data = priv->shminfo.shmaddr; XShmGetImage (dpy, priv->pixmap, image, x, y, AllPlanes); first_pixel = image->data; } else { if (!priv->image) { priv->image = XGetImage (dpy, priv->pixmap, 0, 0, priv->pixmap_width, priv->pixmap_height, AllPlanes, ZPixmap); if (priv->image) first_pixel = priv->image->data + priv->image->bytes_per_line * y + x * priv->image->bits_per_pixel/8; else { g_warning ("%s: XGetImage() failed", __FUNCTION__); return; } } else { XGetSubImage (dpy, priv->pixmap, x, y, width, height, AllPlanes, ZPixmap, priv->image, x, y); first_pixel = priv->image->data + priv->image->bytes_per_line * y + x * priv->image->bits_per_pixel/8; } image = priv->image; } XSync (dpy, FALSE); if ((err_code = clutter_x11_untrap_x_errors ())) { g_warning ("Failed to get XImage of pixmap: %lx, removing", priv->pixmap); /* safe to assume pixmap has gone away? - therefor reset */ clutter_x11_texture_pixmap_set_pixmap (texture, None); goto free_image_and_return; } if (priv->depth == 24) { bytes_per_line = image->bytes_per_line; data = first_pixel; pixel_bpp = 3; pixel_has_alpha = FALSE; } else if (priv->depth == 16) { bytes_per_line = image->bytes_per_line; data = first_pixel; pixel_bpp = 2; pixel_has_alpha = FALSE; } else if (priv->depth == 32) { bytes_per_line = image->bytes_per_line; data = first_pixel; pixel_bpp = 4; pixel_has_alpha = TRUE; } else goto free_image_and_return; if (!priv->allow_alpha) pixel_has_alpha = FALSE; /* For debugging purposes, un comment to simply generate dummy * pixmap data. (A Green background and Blue cross) */ #if 0 { guint xpos, ypos; if (data_allocated) g_free (data); data_allocated = TRUE; data = g_malloc (width*height*4); bytes_per_line = width *4; for (ypos=0; ypos<height; ypos++) for (xpos=0; xpos<width; xpos++) { char *p = data + width*4*ypos + xpos * 4; guint32 *pixel = (guint32 *)p; if ((xpos > width/2 && xpos <= (width/2) + width/4) || (ypos > height/2 && ypos <= (height/2) + height/4)) *pixel=0xff0000ff; else *pixel=0xff00ff00; } } #endif if (x != 0 || y != 0 || width != priv->pixmap_width || height != priv->pixmap_height) clutter_texture_set_area_from_rgb_data (CLUTTER_TEXTURE (texture), (guint8 *)data, pixel_has_alpha, x, y, width, height, bytes_per_line, pixel_bpp, CLUTTER_TEXTURE_RGB_FLAG_BGR, &error); else clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (texture), (guint8 *)data, pixel_has_alpha, width, height, bytes_per_line, pixel_bpp, CLUTTER_TEXTURE_RGB_FLAG_BGR, &error); if (error) { g_warning ("Error when uploading from pixbuf: %s", error->message); g_error_free (error); } free_image_and_return: if (priv->have_shm) XFree (image); #if 0 clock_t end_t = clock(); int time = (int)((double)(end_t - start_t) * (1000.0 / CLOCKS_PER_SEC)); g_print("clutter-x11-update-area-real(%d,%d,%d,%d) %d bits - %d ms\n",x,y,width,height,priv->depth,time); #endif }
G_MODULE_EXPORT int test_textures_main (int argc, char *argv[]) { ClutterActor *texture; ClutterActor *stage; gint i, j; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_actor_show_all (CLUTTER_ACTOR (stage)); g_signal_connect (stage, "destroy", G_CALLBACK (exit_on_destroy), NULL); SPIN(); for (i=100; i<=5000; i += 100) for (j=0; j<4; j++) { const int width = i+j; const int height = i+j; const gboolean has_alpha = TRUE; const int bpp = has_alpha ? 4 : 3; int rowstride; guchar *pixels; pixels = make_rgba_data (width, height, bpp, has_alpha, &rowstride); if (!pixels) g_error("No memory for %ix%i RGBA data failed", width, height); printf("o %ix%i texture... ", width, height); texture = clutter_texture_new (); if (!clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (texture), pixels, has_alpha, width, height, rowstride, bpp, 0, NULL)) g_error("texture creation failed"); g_free(pixels); printf("uploaded to texture...\n"); clutter_container_add (CLUTTER_CONTAINER (stage), texture, NULL); clutter_actor_set_size (texture, 400, 400); clutter_actor_show (texture); /* Hide & show to unreaise then realise the texture */ clutter_actor_hide (texture); clutter_actor_show (texture); SPIN(); clutter_container_remove (CLUTTER_CONTAINER (stage), texture, NULL); } return EXIT_SUCCESS; }