static void pp_super_aa_paint (ClutterActor *actor) { CoglHandle texture; gfloat width, height; PPSuperAAPrivate *priv = PP_SUPER_AA (actor)->priv; clutter_actor_get_size (actor, &width, &height); texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (actor)); if (!texture || (cogl_texture_get_width (texture) != (guint)(width * priv->x_res)) || (cogl_texture_get_height (texture) != (guint)(height * priv->y_res))) { texture = cogl_texture_new_with_size ((guint)(width * priv->x_res), (guint)(height * priv->y_res), COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_RGBA_8888_PRE); clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (actor), texture); cogl_handle_unref (texture); } CLUTTER_ACTOR_CLASS (pp_super_aa_parent_class)->paint (actor); }
static cairo_surface_t * clutter_cairo_texture_create_surface (ClutterCairoTexture *self, guint width, guint height) { cairo_surface_t *surface; guint cairo_stride; guint8 *cairo_data; CoglHandle cogl_texture; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); cairo_stride = cairo_image_surface_get_stride (surface); cairo_data = cairo_image_surface_get_data (surface); self->priv->surface_width = width; self->priv->surface_height = height; /* create a backing Cogl texture */ cogl_texture = cogl_texture_new_from_data (width, height, COGL_TEXTURE_NONE, CLUTTER_CAIRO_FORMAT_ARGB32, COGL_PIXEL_FORMAT_ANY, cairo_stride, cairo_data); clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (self), cogl_texture); cogl_handle_unref (cogl_texture); return surface; }
static gboolean create_cogl_texture (ClutterTexture *texture, guint width, guint height) { CoglHandle handle; handle = cogl_texture_new_with_size (width, height, -1, FALSE, COGL_PIXEL_FORMAT_RGBA_8888|COGL_BGR_BIT); if (handle) { clutter_texture_set_cogl_texture (texture, handle); CLUTTER_ACTOR_SET_FLAGS (texture, CLUTTER_ACTOR_REALIZED); clutter_glx_texture_pixmap_update_area (CLUTTER_X11_TEXTURE_PIXMAP (texture), 0, 0, width, height); return TRUE; } return FALSE; }
int main (int argc, char **argv) { ClutterActor *stage, *image, *sub_image; CoglHandle texture, sub_texture; gfloat image_width, image_height; /* Initialize Clutter */ if (clutter_init (NULL, NULL) != CLUTTER_INIT_SUCCESS) return 1; /* Get the default stage */ stage = clutter_stage_get_default (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Sub-texture"); /* Create a new ClutterTexture that shows smiley.png */ image = clutter_texture_new_from_file ("smiley.png", NULL); clutter_actor_get_size (image, &image_width, &image_height); clutter_actor_set_size (stage, image_width * 3 / 2 + 30, image_height + 20); /* Grab the CoglHandle of the underlying Cogl texture */ texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (image)); /* Create a new Cogl texture from the handle above. That new texture is a * rectangular region from image, more precisely the north ouest corner * of the image */ sub_texture = cogl_texture_new_from_sub_texture (texture, 0, 0, image_width / 2, image_height / 2); /* Finally, use the newly created Cogl texture to feed a new ClutterTexture * and thus create a new actor that displays sub_texture */ sub_image = clutter_texture_new (); clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (sub_image), sub_texture); /* * You could have used the more straightforward g_object_new() function that * can create an object and set some properties on it at the same time: * sub_image = g_object_new (CLUTTER_TYPE_TEXTURE, * "cogl-texture", sub_texture, * NULL); */ /* Put the original image at (10,10) and the new sub image next to it */ clutter_actor_set_position (image, 10, 10); clutter_actor_set_position (sub_image, 20 + image_width, 10); /* Add both ClutterTexture to the stage */ clutter_container_add (CLUTTER_CONTAINER (stage), image, sub_image, NULL); clutter_actor_show_all (stage); clutter_main (); return 0; }
void shell_util_cursor_tracker_to_clutter (MetaCursorTracker *tracker, ClutterTexture *texture) { CoglTexture *sprite; sprite = meta_cursor_tracker_get_sprite (tracker); clutter_texture_set_cogl_texture (texture, sprite); }
static void rc_update_pixbuf(void *renderer, gboolean lazy) { RendererClutter *rc = (RendererClutter *)renderer; PixbufRenderer *pr = rc->pr; DEBUG_3("rc_update_pixbuf"); rc_remove_pending_updates(rc); rc->last_pixbuf_change = g_get_monotonic_time(); DEBUG_3("%s change time reset", get_exec_time()); if (pr->pixbuf) { gint width = gdk_pixbuf_get_width(pr->pixbuf); gint height = gdk_pixbuf_get_height(pr->pixbuf); DEBUG_3("pixbuf size %d x %d (%d)", width, height, gdk_pixbuf_get_has_alpha(pr->pixbuf) ? 32 : 24); gint prev_width, prev_height; if (pr->stereo_data == STEREO_PIXBUF_SBS || pr->stereo_data == STEREO_PIXBUF_CROSS) { width /= 2; } clutter_texture_get_base_size(CLUTTER_TEXTURE(rc->texture), &prev_width, &prev_height); if (width != prev_width || height != prev_height) { /* FIXME use CoglMaterial with multiple textures for background, color management, anaglyph, ... */ CoglHandle texture = cogl_texture_new_with_size(width, height, COGL_TEXTURE_NO_AUTO_MIPMAP | COGL_TEXTURE_NO_SLICING, gdk_pixbuf_get_has_alpha(pr->pixbuf) ? COGL_PIXEL_FORMAT_BGRA_8888 : COGL_PIXEL_FORMAT_BGR_888); if (texture != COGL_INVALID_HANDLE) { clutter_texture_set_cogl_texture(CLUTTER_TEXTURE(rc->texture), texture); cogl_handle_unref(texture); } } clutter_actor_set_clip(rc->texture, 0, 0, 0, 0); /* visible area is extended as area_changed events arrive */ if (!lazy) { rc_area_changed(renderer, GET_RIGHT_PIXBUF_OFFSET(rc), 0, width, height); } } rc->clut_updated = FALSE; }
/** * shell_xfixes_cursor_update_texture_image: * @xfixes_cursor: the #ShellXFixesCursor * @texture: ClutterTexture to update with the current sprite image. */ void shell_xfixes_cursor_update_texture_image (ShellXFixesCursor *xfixes_cursor, ClutterTexture *texture) { CoglHandle *old_sprite; g_return_if_fail (SHELL_IS_XFIXES_CURSOR (xfixes_cursor)); if (texture == NULL) return; old_sprite = clutter_texture_get_cogl_texture (texture); if (xfixes_cursor->cursor_sprite == old_sprite) return; clutter_texture_set_cogl_texture (texture, xfixes_cursor->cursor_sprite); }
/** * cinnamon_xfixes_cursor_update_texture_image: * @xfixes_cursor: the #CinnamonXFixesCursor * @texture: ClutterTexture to update with the current sprite image. */ void cinnamon_xfixes_cursor_update_texture_image (CinnamonXFixesCursor *xfixes_cursor, ClutterTexture *texture) { CoglHandle *old_sprite; g_return_if_fail (CINNAMON_IS_XFIXES_CURSOR (xfixes_cursor)); if (texture == NULL) return; old_sprite = clutter_texture_get_cogl_texture (texture); if (xfixes_cursor->cursor_sprite == old_sprite) return; clutter_texture_set_cogl_texture (texture, xfixes_cursor->cursor_sprite); }
/** * cinnamon_app_get_faded_icon: * @app: A #CinnamonApp * @size: Size in pixels * * Return an actor with a horizontally faded look. * * Return value: (transfer none): A floating #ClutterActor, or %NULL if no icon */ ClutterActor * cinnamon_app_get_faded_icon (CinnamonApp *app, int size) { CoglHandle texture; ClutterActor *result; char *cache_key; CreateFadedIconData data; gint scale; CinnamonGlobal *global; StThemeContext *context; /* Don't fade for window backed apps for now...easier to reuse the * property tracking bits, and this helps us visually distinguish * app-tracked from not. */ if (!app->entry) return window_backed_app_get_icon (app, size); global = cinnamon_global_get (); context = st_theme_context_get_for_stage (cinnamon_global_get_stage (global)); g_object_get (context, "scale-factor", &scale, NULL); cache_key = g_strdup_printf ("faded-icon:%s,size=%d,scale=%d", cinnamon_app_get_id (app), size, scale); data.app = app; data.size = size; data.scale = scale; texture = st_texture_cache_load (st_texture_cache_get_default (), cache_key, ST_TEXTURE_CACHE_POLICY_FOREVER, cinnamon_app_create_faded_icon_cpu, &data, NULL); g_free (cache_key); if (texture != COGL_INVALID_HANDLE) { result = clutter_texture_new (); clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (result), texture); } else { result = clutter_texture_new (); g_object_set (result, "opacity", 0, "width", (float) size * scale, "height", (float) size * scale, NULL); } return result; }
static void st_texture_cache_reset_texture (StTextureCachePropertyBind *bind, const char *propname) { cairo_surface_t *surface; CoglTexture *texdata; ClutterBackend *backend = clutter_get_default_backend (); CoglContext *ctx = clutter_backend_get_cogl_context (backend); g_object_get (bind->source, propname, &surface, NULL); if (surface != NULL && cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE && (cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32 || cairo_image_surface_get_format (surface) == CAIRO_FORMAT_RGB24)) { CoglError *error = NULL; texdata = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, cairo_image_surface_get_width (surface), cairo_image_surface_get_height (surface), cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32 ? COGL_PIXEL_FORMAT_BGRA_8888 : COGL_PIXEL_FORMAT_BGR_888, cairo_image_surface_get_stride (surface), cairo_image_surface_get_data (surface), &error)); if (texdata) { clutter_texture_set_cogl_texture (bind->texture, texdata); cogl_object_unref (texdata); } else if (error) { g_warning ("Failed to allocate texture: %s", error->message); cogl_error_free (error); } clutter_actor_set_opacity (CLUTTER_ACTOR (bind->texture), 255); } else clutter_actor_set_opacity (CLUTTER_ACTOR (bind->texture), 0); }
static void clutter_gst_yv12_upload (ClutterGstVideoSink *sink, GstBuffer *buffer) { ClutterGstVideoSinkPrivate *priv = sink->priv; CoglHandle y_tex = cogl_texture_new_from_data (priv->width, priv->height, COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_G_8, COGL_PIXEL_FORMAT_G_8, priv->width, GST_BUFFER_DATA (buffer)); clutter_texture_set_cogl_texture (priv->texture, y_tex); cogl_texture_unref (y_tex); if (priv->u_tex) cogl_texture_unref (priv->u_tex); if (priv->v_tex) cogl_texture_unref (priv->v_tex); priv->v_tex = cogl_texture_new_from_data (priv->width / 2, priv->height / 2, COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_G_8, COGL_PIXEL_FORMAT_G_8, priv->width / 2, GST_BUFFER_DATA (buffer) + (priv->width * priv->height)); priv->u_tex = cogl_texture_new_from_data (priv->width / 2, priv->height / 2, COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_G_8, COGL_PIXEL_FORMAT_G_8, priv->width / 2, GST_BUFFER_DATA (buffer) + (priv->width * priv->height) + (priv->width / 2 * priv->height / 2)); }
/* put a gst gl buffer in the texture actor */ gboolean update_texture_actor (gpointer data) { ClutterTexture *texture_actor = (ClutterTexture *) data; GAsyncQueue *queue_input_buf = g_object_get_data (G_OBJECT (texture_actor), "queue_input_buf"); GAsyncQueue *queue_output_buf = g_object_get_data (G_OBJECT (texture_actor), "queue_output_buf"); GstGLBuffer *gst_gl_buf = g_async_queue_pop (queue_input_buf); ClutterActor *stage = g_object_get_data (G_OBJECT (texture_actor), "stage"); CoglHandle cogl_texture = 0; /* Create a cogl texture from the gst gl texture */ glEnable (GL_TEXTURE_RECTANGLE_ARB); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, gst_gl_buf->texture); if (glGetError () != GL_NO_ERROR) g_debug ("failed to bind texture that comes from gst-gl\n"); cogl_texture = cogl_texture_new_from_foreign (gst_gl_buf->texture, CGL_TEXTURE_RECTANGLE_ARB, gst_gl_buf->width, gst_gl_buf->height, 0, 0, COGL_PIXEL_FORMAT_RGBA_8888); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0); /* Previous cogl texture is replaced and so its ref counter discreases to 0. * According to the source code, glDeleteTexture is not called when the previous * ref counter of the previous cogl texture is reaching 0 because is_foreign is TRUE */ clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (texture_actor), cogl_texture); cogl_texture_unref (cogl_texture); /* we can now show the clutter scene if not yet visible */ if (!CLUTTER_ACTOR_IS_VISIBLE (stage)) clutter_actor_show_all (stage); /* push buffer so it can be unref later */ g_async_queue_push (queue_output_buf, gst_gl_buf); return FALSE; }
static void st_texture_cache_reset_texture (StTextureCachePropertyBind *bind, const char *propname) { GdkPixbuf *pixbuf; CoglTexture *texdata; g_object_get (bind->source, propname, &pixbuf, NULL); g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf)); if (pixbuf != NULL) { texdata = pixbuf_to_cogl_texture (pixbuf); g_object_unref (pixbuf); clutter_texture_set_cogl_texture (bind->texture, texdata); cogl_object_unref (texdata); clutter_actor_set_opacity (CLUTTER_ACTOR (bind->texture), 255); } else clutter_actor_set_opacity (CLUTTER_ACTOR (bind->texture), 0); }
/* Reverse the opacity we added while loading */ static void set_texture_cogl_texture (ClutterTexture *clutter_texture, CoglTexture *cogl_texture) { clutter_texture_set_cogl_texture (clutter_texture, cogl_texture); g_object_set (clutter_texture, "opacity", 255, NULL); }
int main (int argc, char *argv[]) { ClutterLayoutManager *layout; ClutterActor *box; ClutterActor *stage; ClutterActor *texture; CoglHandle *cogl_texture; GError *error = NULL; gfloat width; const gchar *filename = "redhand.png"; if (argc > 1) filename = argv[1]; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_actor_set_size (stage, STAGE_SIDE, STAGE_SIDE); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); box = clutter_actor_new (); clutter_actor_set_layout_manager (box, layout); clutter_actor_set_background_color (box, &box_color); texture = clutter_texture_new_from_file (filename, &error); if (error != NULL) g_error ("Error loading file %s; message was:\n%s", filename, error->message); /* * get a reference to the underlying Cogl texture * for copying onto each Clutter texture placed into the layout */ cogl_texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (texture)); /* * add gradually turning and shrinking textures, * smallest one last; each actor ends up on top * of the one added just before it */ for (width = STAGE_SIDE * 0.75; width >= STAGE_SIDE * 0.0625; width -= STAGE_SIDE * 0.0625) { ClutterActor *texture_copy = clutter_texture_new (); clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (texture_copy), cogl_texture); clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (texture_copy), TRUE); clutter_actor_set_z_rotation_from_gravity (texture_copy, (gfloat)(width * 0.5) - (STAGE_SIDE * 0.03125), CLUTTER_GRAVITY_CENTER); clutter_actor_set_width (texture_copy, width); clutter_actor_add_child (box, texture_copy); } clutter_actor_add_constraint (box, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5)); clutter_actor_add_child (stage, box); clutter_actor_show (stage); clutter_main (); return 0; }
int main (int argc, char *argv[]) { ClutterLayoutManager *layout; ClutterActor *box; ClutterActor *stage; ClutterActor *texture; CoglHandle *cogl_texture; GError *error = NULL; gfloat width; gchar *filename = TESTS_DATA_DIR "/redhand.png"; if (argc > 1) filename = argv[1]; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); clutter_actor_set_size (stage, STAGE_SIDE, STAGE_SIDE); layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); box = clutter_box_new (layout); clutter_box_set_color (CLUTTER_BOX (box), &box_color); texture = clutter_texture_new_from_file (filename, &error); if (error != NULL) g_error ("Error loading file %s; message was:\n%s", filename, error->message); /* * get a reference to the underlying Cogl texture * for copying onto each Clutter texture placed into the layout */ cogl_texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (texture)); /* * add gradually turning and shrinking textures, * smallest one last; each actor ends up on top * of the one added just before it */ for (width = STAGE_SIDE * 0.75; width >= STAGE_SIDE * 0.0625; width -= STAGE_SIDE * 0.0625) { ClutterActor *texture_copy = clutter_texture_new (); clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (texture_copy), cogl_texture); clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (texture_copy), TRUE); clutter_actor_set_z_rotation_from_gravity (texture_copy, (gfloat)(width * 0.5) - (STAGE_SIDE * 0.03125), CLUTTER_GRAVITY_CENTER); clutter_actor_set_width (texture_copy, width); clutter_container_add_actor (CLUTTER_CONTAINER (box), texture_copy); } clutter_actor_add_constraint (box, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5)); clutter_actor_add_constraint (box, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5)); clutter_container_add_actor (CLUTTER_CONTAINER (stage), box); clutter_actor_show (stage); clutter_main (); return 0; }