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); }
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; }
static gboolean rc_area_changed_cb(gpointer data) { RendererClutter *rc = (RendererClutter *)data; PixbufRenderer *pr = rc->pr; RendererClutterAreaParam *par = rc->pending_updates->data; gint h = MAX_REGION_AREA / par->w; if (h == 0) h = 1; if (h > par->h) h = par->h; DEBUG_3("%s upload start", get_exec_time()); if (pr->pixbuf) { CoglHandle texture = clutter_texture_get_cogl_texture(CLUTTER_TEXTURE(rc->texture)); cogl_texture_set_region(texture, par->x + GET_RIGHT_PIXBUF_OFFSET(rc), par->y, par->x, par->y, par->w, h, par->w, h, gdk_pixbuf_get_has_alpha(pr->pixbuf) ? COGL_PIXEL_FORMAT_BGRA_8888 : COGL_PIXEL_FORMAT_BGR_888, gdk_pixbuf_get_rowstride(pr->pixbuf), gdk_pixbuf_get_pixels(pr->pixbuf)); } DEBUG_3("%s upload end", get_exec_time()); rc_area_clip_add(rc, par->x, par->y, par->w, h); par->y += h; par->h -= h; if (par->h == 0) { rc->pending_updates = g_list_remove(rc->pending_updates, par); g_free(par); } if (!rc->pending_updates) { clutter_actor_queue_redraw(CLUTTER_ACTOR(rc->texture)); rc->idle_update = 0; /* FIXME: find a better place for this */ if (!rc->clut_updated) rc_prepare_post_process_lut(rc); return FALSE; } rc_schedule_texture_upload(rc); return FALSE; /* it was rescheduled, possibly with different prio */ }
CoglHandle _st_create_shadow_material_from_actor (StShadow *shadow_spec, ClutterActor *actor) { CoglHandle shadow_material = COGL_INVALID_HANDLE; if (CLUTTER_IS_TEXTURE (actor)) { CoglHandle texture; texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (actor)); shadow_material = _st_create_shadow_material (shadow_spec, texture); } else { CoglHandle buffer, offscreen; ClutterActorBox box; CoglColor clear_color; float width, height; clutter_actor_get_allocation_box (actor, &box); clutter_actor_box_get_size (&box, &width, &height); if (width == 0 || height == 0) return COGL_INVALID_HANDLE; buffer = st_cogl_texture_new_with_size_wrapper (width, height, COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_ANY); if (buffer == COGL_INVALID_HANDLE) return COGL_INVALID_HANDLE; offscreen = cogl_offscreen_new_to_texture (buffer); if (offscreen == COGL_INVALID_HANDLE) { cogl_handle_unref (buffer); return COGL_INVALID_HANDLE; } cogl_color_set_from_4ub (&clear_color, 0, 0, 0, 0); cogl_push_framebuffer (offscreen); cogl_clear (&clear_color, COGL_BUFFER_BIT_COLOR); cogl_translate (-box.x1, -box.y1, 0); cogl_ortho (0, width, height, 0, 0, 1.0); clutter_actor_paint (actor); cogl_pop_framebuffer (); cogl_handle_unref (offscreen); shadow_material = _st_create_shadow_material (shadow_spec, buffer); cogl_handle_unref (buffer); } return shadow_material; }
static void clutter_cairo_texture_context_destroy (void *data) { ClutterCairoTextureContext *ctxt = data; ClutterCairoTexture *cairo = ctxt->cairo; ClutterCairoTexturePrivate *priv = cairo->priv; guint8 *cairo_data; gint cairo_width, cairo_height, cairo_stride; gint surface_width, surface_height; CoglHandle cogl_texture; if (priv->cr_surface == NULL) return; /* for any other surface type, we presume that there exists a native * communication between Cairo and GL that is triggered by cairo_destroy(). * * for instance, cairo-drm will flush the outstanding modifications to the * surface upon context destruction and so the texture is automatically * updated. */ if (cairo_surface_get_type (priv->cr_surface) != CAIRO_SURFACE_TYPE_IMAGE) goto out; surface_width = cairo_image_surface_get_width (priv->cr_surface); surface_height = cairo_image_surface_get_height (priv->cr_surface); cairo_width = MIN (ctxt->rect.width, surface_width); cairo_height = MIN (ctxt->rect.height, surface_height); cogl_texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (cairo)); if (!cairo_width || !cairo_height || cogl_texture == COGL_INVALID_HANDLE) { g_slice_free (ClutterCairoTextureContext, ctxt); return; } cairo_stride = cairo_image_surface_get_stride (priv->cr_surface); cairo_data = cairo_image_surface_get_data (priv->cr_surface); cairo_data += cairo_stride * ctxt->rect.y; cairo_data += 4 * ctxt->rect.x; cogl_texture_set_region (cogl_texture, 0, 0, ctxt->rect.x, ctxt->rect.y, cairo_width, cairo_height, cairo_width, cairo_height, CLUTTER_CAIRO_FORMAT_ARGB32, cairo_stride, cairo_data); out: g_slice_free (ClutterCairoTextureContext, ctxt); clutter_actor_queue_redraw (CLUTTER_ACTOR (cairo)); }
/** * clutter_glx_texture_pixmap_using_extension: * @texture: A #ClutterGLXTexturePixmap * * Checks whether @texture is using the GLX_EXT_texture_from_pixmap * extension; this extension can be optionally (though it is strongly * encouraged) implemented as a zero-copy between a GLX pixmap and * a GL texture. * * Return value: %TRUE if the texture is using the * GLX_EXT_texture_from_pixmap OpenGL extension or falling back to the * slower software mechanism. * * Deprecated: 1.6: Use cogl_texture_pixmap_x11_is_using_tfp_extension() * on the texture handle instead. * * Since: 0.8 */ gboolean clutter_glx_texture_pixmap_using_extension (ClutterGLXTexturePixmap *texture) { CoglHandle cogl_texture; g_return_val_if_fail (CLUTTER_GLX_IS_TEXTURE_PIXMAP (texture), FALSE); cogl_texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (texture)); return (cogl_is_texture_pixmap_x11 (cogl_texture) && cogl_texture_pixmap_x11_is_using_tfp_extension (cogl_texture)); }
static void penge_magic_texture_paint (ClutterActor *actor) { ClutterActorBox box; CoglHandle *material, *tex; float bw, bh; float aw, ah; float v; float tx1, tx2, ty1, ty2; guint8 alpha; clutter_actor_get_allocation_box (actor, &box); material = clutter_texture_get_cogl_material (CLUTTER_TEXTURE (actor)); tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (actor)); bw = (float) cogl_texture_get_width (tex); /* base texture width */ bh = (float) cogl_texture_get_height (tex); /* base texture height */ aw = (float) (box.x2 - box.x1); /* allocation width */ ah = (float) (box.y2 - box.y1); /* allocation height */ /* no comment */ if ((float)bw/bh < (float)aw/ah) { /* fit width */ v = (((float)ah * bw) / ((float)aw * bh)) / 2; tx1 = 0; tx2 = 1; ty1 = (0.5 - v); ty2 = (0.5 + v); } else { /* fit height */ v = (((float)aw * bh) / ((float)ah * bw)) / 2; tx1 = (0.5 - v); tx2 = (0.5 + v); ty1 = 0; ty2 = 1; } alpha = clutter_actor_get_paint_opacity (actor); cogl_material_set_color4ub (material, alpha, alpha, alpha, alpha); cogl_set_source (material); cogl_rectangle_with_texture_coords (0, 0, aw, ah, tx1, ty1, tx2, ty2); }
/** * 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); }
/** * 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); }
static gboolean texture_bind (ClutterGLXTexturePixmap *tex) { GLuint handle = 0; GLenum target = 0; CoglHandle cogl_tex; cogl_tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE(tex)); if (!cogl_texture_get_gl_texture (cogl_tex, &handle, &target)) return FALSE; glEnable(target); /* FIXME: fire off an error here? */ glBindTexture (target, handle); return TRUE; }
CoglPipeline * _st_create_shadow_pipeline_from_actor (StShadow *shadow_spec, ClutterActor *actor) { CoglPipeline *shadow_pipeline = NULL; if (CLUTTER_IS_TEXTURE (actor)) { CoglTexture *texture; texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (actor)); shadow_pipeline = _st_create_shadow_pipeline (shadow_spec, texture); } else { CoglTexture *buffer; CoglOffscreen *offscreen; CoglFramebuffer *fb; ClutterActorBox box; CoglColor clear_color; float width, height; CoglError *catch_error = NULL; clutter_actor_get_allocation_box (actor, &box); clutter_actor_box_get_size (&box, &width, &height); if (width == 0 || height == 0) return NULL; buffer = cogl_texture_new_with_size (width, height, COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_ANY); if (buffer == NULL) return NULL; offscreen = cogl_offscreen_new_with_texture (buffer); fb = COGL_FRAMEBUFFER (offscreen); if (!cogl_framebuffer_allocate (fb, &catch_error)) { cogl_error_free (catch_error); cogl_object_unref (buffer); return NULL; } cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 0); /* XXX: There's no way to render a ClutterActor to an offscreen * as it uses the implicit API. */ G_GNUC_BEGIN_IGNORE_DEPRECATIONS; cogl_push_framebuffer (fb); G_GNUC_END_IGNORE_DEPRECATIONS; cogl_framebuffer_clear (fb, COGL_BUFFER_BIT_COLOR, &clear_color); cogl_framebuffer_translate (fb, -box.x1, -box.y1, 0); cogl_framebuffer_orthographic (fb, 0, 0, width, height, 0, 1.0); clutter_actor_set_opacity_override (actor, 255); clutter_actor_paint (actor); clutter_actor_set_opacity_override (actor, -1); G_GNUC_BEGIN_IGNORE_DEPRECATIONS; cogl_pop_framebuffer (); G_GNUC_END_IGNORE_DEPRECATIONS; cogl_object_unref (fb); shadow_pipeline = _st_create_shadow_pipeline (shadow_spec, buffer); cogl_object_unref (buffer); } return shadow_pipeline; }
static void clutter_reflect_texture_paint (ClutterActor *actor) { ClutterReflectTexturePrivate *priv; ClutterReflectTexture *texture; ClutterClone *clone; ClutterTexture *parent; guint width, height; gfloat fwidth, fheight; gint r_height; gint opacity; gint bottom; CoglHandle cogl_texture; CoglTextureVertex tvert[4]; CoglFixed rty; texture = CLUTTER_REFLECT_TEXTURE (actor); clone = CLUTTER_CLONE (actor); parent = (ClutterTexture*) clutter_clone_get_source (clone); if (!parent) return; if (!CLUTTER_ACTOR_IS_REALIZED (parent)) clutter_actor_realize (CLUTTER_ACTOR (parent)); cogl_texture = clutter_texture_get_cogl_texture (parent); if (cogl_texture == COGL_INVALID_HANDLE) return; priv = texture->priv; clutter_actor_get_size (CLUTTER_ACTOR(parent), &fwidth, &fheight); width = fwidth; height = fheight; if (!height) // probably won't happen, but just in case, to avoid divide by zero. return; r_height = priv->reflection_height; bottom = priv->reflect_bottom; opacity = clutter_actor_get_opacity(actor); if (r_height < 0 || r_height > height) r_height = height; #define FX(x) COGL_FIXED_FROM_INT(x) rty = COGL_FIXED_FAST_DIV(FX(bottom ? height-r_height : r_height),FX(height)); /* clockise vertices and tex coords and colors! */ tvert[0].x = tvert[0].y = tvert[0].z = 0; tvert[0].tx = 0; tvert[0].ty = bottom ? COGL_FIXED_1 : rty; tvert[0].color.red = tvert[0].color.green = tvert[0].color.blue = 0xff; tvert[0].color.alpha = bottom ? opacity : 0; tvert[1].x = FX(width); tvert[1].y = tvert[1].z = 0; tvert[1].tx = COGL_FIXED_1; tvert[1].ty = bottom ? COGL_FIXED_1 : rty; tvert[1].color.red = tvert[1].color.green = tvert[1].color.blue = 0xff; tvert[1].color.alpha = bottom ? opacity : 0; tvert[2].x = FX(width); tvert[2].y = FX(r_height); tvert[2].z = 0; tvert[2].tx = COGL_FIXED_1; tvert[2].ty = bottom ? rty : 0; tvert[2].color.red = tvert[2].color.green = tvert[2].color.blue = 0xff; tvert[2].color.alpha = bottom ? 0 : opacity; tvert[3].x = 0; tvert[3].y = FX(r_height); tvert[3].z = 0; tvert[3].tx = 0; tvert[3].ty = bottom ? rty : 0; tvert[3].color.red = tvert[3].color.green = tvert[3].color.blue = 0xff; tvert[3].color.alpha = bottom ? 0 : opacity; cogl_push_matrix (); cogl_set_source_texture(cogl_texture); /* FIXME: this does not work as expected */ /* cogl_polygon(tvert, 4, TRUE); */ cogl_pop_matrix (); }
static void mnb_toolbar_background_paint_background (MxWidget *self, ClutterActor *background, const ClutterColor *color) { MnbToolbarBackgroundPrivate *priv = TOOLBAR_BACKGROUND_PRIVATE (self); ClutterActor *actor = (ClutterActor *) self; CoglHandle cogl_texture, cogl_material; ClutterActorBox box = { 0, }; gfloat width, height; gfloat tex_width, tex_height; gfloat ex, ey; gfloat tx1, ty1, tx2, ty2; guint8 opacity; /* Copied from MxWidget: * * Default implementation just draws the background * colour and the image on top */ if (color && color->alpha != 0) { ClutterColor bg_color = *color; bg_color.alpha = clutter_actor_get_paint_opacity (actor) * bg_color.alpha / 255; clutter_actor_get_allocation_box (actor, &box); width = box.x2 - box.x1; height = box.y2 - box.y1; cogl_set_source_color4ub (bg_color.red, bg_color.green, bg_color.blue, bg_color.alpha); cogl_rectangle (0, 0, width, height); } /* * Copied from MxTextureFrame */ /* no need to paint stuff if we don't have a texture */ if (G_UNLIKELY (priv->parent_texture == NULL)) return; cogl_texture = clutter_texture_get_cogl_texture (priv->parent_texture); if (cogl_texture == COGL_INVALID_HANDLE) return; cogl_material = clutter_texture_get_cogl_material (priv->parent_texture); if (cogl_material == COGL_INVALID_HANDLE) return; tex_width = cogl_texture_get_width (cogl_texture); tex_height = cogl_texture_get_height (cogl_texture); clutter_actor_get_allocation_box (actor, &box); width = box.x2 - box.x1; height = box.y2 - box.y1; opacity = clutter_actor_get_paint_opacity (actor); /* Paint using the parent texture's material. It should already have the cogl texture set as the first layer */ /* NB: for correct blending we need set a preumultiplied color here: */ cogl_material_set_color4ub (cogl_material, opacity, opacity, opacity, opacity); selector_texture = mnb_toolbar_get_selector_texture (priv->toolbar); cogl_material_set_layer (cogl_material, 1, selector_texture); cogl_material_set_layer_wrap_mode (cogl_material, 1, COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE); if (!cogl_material_set_layer_combine (cogl_material, 1, "RGBA = MODULATE(PREVIOUS,TEXTURE)", &error)) { g_warning (G_STRLOC ": Error setting layer combine blend string: %s", error->message); g_error_free (error); } cogl_set_source (cogl_material); /* simple stretch */ if (priv->left == 0 && priv->right == 0 && priv->top == 0 && priv->bottom == 0) { float spot_width, spot_height; float coords[8] = { 0, 0, 1, 1, 0, 0, 0, 0 }; mnb_toolbar_get_selector_allocation_box (priv->toolbar, &box); spot_width = box.x2 - box.x1; spot_height = box.y2 - box.y1; coords[4] = -(box.x1 / width) * (width / spot_width); coords[5] = -(box.y1 / height) * (height / spot_height); coords[6] = width / spot_width - (box.x1 / width) * (width / spot_width); coords[7] = height / spot_height - (box.y1 / height) * (height / spot_height); cogl_rectangle_with_multitexture_coords (0, 0, width, height, coords, 8); return; } tx1 = priv->left / tex_width; tx2 = (tex_width - priv->right) / tex_width; ty1 = priv->top / tex_height; ty2 = (tex_height - priv->bottom) / tex_height; ex = width - priv->right; if (ex < priv->left) ex = priv->left; ey = height - priv->bottom; if (ey < priv->top) ey = priv->top; { GLfloat rectangles[] = { /* top left corner */ 0, 0, priv->left, priv->top, 0.0, 0.0, tx1, ty1, /* top middle */ priv->left, 0, MAX (priv->left, ex), priv->top, tx1, 0.0, tx2, ty1, /* top right */ ex, 0, MAX (ex + priv->right, width), priv->top, tx2, 0.0, 1.0, ty1, /* mid left */ 0, priv->top, priv->left, ey, 0.0, ty1, tx1, ty2, /* center */ priv->left, priv->top, ex, ey, tx1, ty1, tx2, ty2, /* mid right */ ex, priv->top, MAX (ex + priv->right, width), ey, tx2, ty1, 1.0, ty2, /* bottom left */ 0, ey, priv->left, MAX (ey + priv->bottom, height), 0.0, ty2, tx1, 1.0, /* bottom center */ priv->left, ey, ex, MAX (ey + priv->bottom, height), tx1, ty2, tx2, 1.0, /* bottom right */ ex, ey, MAX (ex + priv->right, width), MAX (ey + priv->bottom, height), tx2, ty2, 1.0, 1.0 }; cogl_rectangles_with_texture_coords (rectangles, 9); } }
Context::Context( ClutterActor * actor ) : unpack_flip_y( false ), unpack_premultiply_alpha( false ), unpack_colorspace_conversion( GL_BROWSER_DEFAULT_WEBGL ), have_depth( false ), have_stencil( false ), acquisitions( 0 ), texture( 0 ), texture_target( 0 ), framebuffer( 0 ) { g_assert( CLUTTER_IS_TEXTURE( actor ) ); // Make sure we are in the clutter context context_op( SWITCH_TO_CLUTTER_CONTEXT ); // Get the Clutter GL texture id and target #ifdef CLUTTER_VERSION_1_10 CoglTexture * th = COGL_TEXTURE( clutter_texture_get_cogl_texture( CLUTTER_TEXTURE( actor ) ) ); #else CoglHandle th = clutter_texture_get_cogl_texture( CLUTTER_TEXTURE( actor ) ); #endif if ( ! cogl_texture_get_gl_texture( th , & texture , & texture_target ) ) { tpwarn( "FAILED TO GET GL TEXTURE HANDLE" ); } // Now, create our context and switch to it context_op( CREATE_CONTEXT ); context_op( SWITCH_TO_MY_CONTEXT ); // Get the width and height of the actor gfloat width; gfloat height; clutter_actor_get_size( actor , & width , & height ); // Try to create the frame buffer in different ways until one // succeeds (or all fail). const int try_flags[] = { #if defined(CLUTTER_WINDOWING_GLX) || defined(CLUTTER_WINDOWING_OSX) FBO_TRY_DEPTH_STENCIL , #endif FBO_TRY_DEPTH | FBO_TRY_STENCIL , FBO_TRY_DEPTH , FBO_TRY_STENCIL , 0 }; for ( size_t i = 0; i < sizeof( try_flags ) / sizeof( int ); ++i ) { if ( try_create_fbo( width , height , try_flags[ i ] ) ) { break; } } if ( ! framebuffer ) { tpwarn( "UNABLE TO CREATE FRAMEBUFFER" ); } else { tplog2( "FRAMEBUFFER READY : DEPTH = %s : STENCIL = %s" , have_depth ? "YES" : "NO" , have_stencil ? "YES" : "NO" ); } context_op( SWITCH_TO_CLUTTER_CONTEXT ); }
/* * Paints the provided texture frame trimming to the area indicated by padding. * * (Basically, we have one asset that gets split into two parts: an border area * that matches the padding, and the inside; MplPanelBackground paints the * latter, while the border is painted by the compositor as the window shadow.) */ static void mpl_panel_background_paint_border_image (CoglHandle *frame, MxPadding *padding) { CoglHandle cogl_texture = COGL_INVALID_HANDLE; CoglHandle cogl_material = COGL_INVALID_HANDLE; ClutterActorBox box = { 0, }; gfloat width, height; gfloat tex_width, tex_height; gfloat ex, ey; gfloat tx1, ty1, tx2, ty2; gfloat left = 4, right = 4 , top = 4, bottom =4; guint8 opacity; ClutterTexture *parent_texture; gfloat margin_l, margin_r, margin_t, margin_b; parent_texture = mx_texture_frame_get_parent_texture (frame); mx_texture_frame_get_border_values (frame, &top, &right, &bottom, &left); /* no need to paint stuff if we don't have a texture */ if (G_UNLIKELY (parent_texture == NULL)) return; /* parent texture may have been hidden, so need to make sure it gets * realized */ if (!CLUTTER_ACTOR_IS_REALIZED (parent_texture)) clutter_actor_realize (CLUTTER_ACTOR (parent_texture)); cogl_texture = clutter_texture_get_cogl_texture (parent_texture); if (cogl_texture == COGL_INVALID_HANDLE) return; cogl_material = clutter_texture_get_cogl_material (parent_texture); if (cogl_material == COGL_INVALID_HANDLE) return; tex_width = cogl_texture_get_width (cogl_texture); tex_height = cogl_texture_get_height (cogl_texture); clutter_actor_get_allocation_box ((ClutterActor*) frame, &box); width = box.x2 - box.x1; height = box.y2 - box.y1; /* * These are the margins we are to trim expressed in texture coordinates. */ margin_l = padding->left / tex_width; margin_r = padding->right / tex_width; margin_t = padding->top / tex_height; margin_b = padding->bottom / tex_height; tx1 = left / tex_width; tx2 = (tex_width - right) / tex_width; ty1 = top / tex_height; ty2 = (tex_height - bottom) / tex_height; ex = width - right; if (ex < 0) ex = right; ey = height - bottom; if (ey < 0) ey = bottom; opacity = clutter_actor_get_paint_opacity ((ClutterActor*)frame); cogl_material_set_color4ub (cogl_material, opacity, opacity, opacity, opacity); cogl_set_source (cogl_material); cogl_material_set_layer_filters (cogl_material, 0, COGL_MATERIAL_FILTER_NEAREST, COGL_MATERIAL_FILTER_NEAREST); { GLfloat rectangles[] = { /* top left corner */ 0.0, 0.0, left, top, margin_l, margin_t, tx1, ty1, /* top middle */ left, 0.0, ex, top, tx1, margin_t, tx2, ty1, /* top right */ ex, 0.0, width, top, tx2, margin_t, 1.0 - margin_r, ty1, /* mid left */ 0.0, top, left, ey, margin_l, ty1, tx1, ty2, /* center */ left, top, ex, ey, tx1, ty1, tx2, ty2, /* mid right */ ex, top, width, ey, tx2, ty1, 1.0 - margin_r, ty2, /* bottom left */ 0.0, ey, left, height, margin_l, ty2, tx1, 1.0 - margin_b, /* bottom center */ left, ey, ex, height, tx1, ty2, tx2, 1.0 - margin_b, /* bottom right */ ex, ey, width, height, tx2, ty2, 1.0 - margin_r, 1.0 - margin_b }; cogl_rectangles_with_texture_coords (rectangles, 9); } }
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; }
static void clutter_x11_texture_pixmap_paint (ClutterActor *self) { ClutterX11TexturePixmap *texture = CLUTTER_X11_TEXTURE_PIXMAP (self); ClutterX11TexturePixmapPrivate *priv = texture->priv; gint x_1, y_1, x_2, y_2; ClutterColor col = { 0xff, 0xff, 0xff, 0xff }; ClutterFixed t_w, t_h; GList *shape; CoglHandle cogl_texture; g_return_if_fail (CLUTTER_X11_IS_TEXTURE_PIXMAP (texture)); /* If we have no shapes, just call what we had before */ if (priv->shapes==0) { CLUTTER_ACTOR_CLASS(clutter_x11_texture_pixmap_parent_class)->paint(self); return; } if (!CLUTTER_ACTOR_IS_REALIZED (CLUTTER_ACTOR(texture))) clutter_actor_realize (CLUTTER_ACTOR(texture)); CLUTTER_NOTE (PAINT, "painting X11 texture '%s'", clutter_actor_get_name (self) ? clutter_actor_get_name (self) : "unknown"); col.alpha = clutter_actor_get_paint_opacity (self); cogl_color (&col); clutter_actor_get_allocation_coords (self, &x_1, &y_1, &x_2, &y_2); CLUTTER_NOTE (PAINT, "paint to x1: %i, y1: %i x2: %i, y2: %i " "opacity: %i", x_1, y_1, x_2, y_2, clutter_actor_get_opacity (self)); t_w = CFX_ONE; t_h = CFX_ONE; cogl_texture = clutter_texture_get_cogl_texture(CLUTTER_TEXTURE(self)); if (cogl_texture == COGL_INVALID_HANDLE) return; /* so now we go through our shapes and render */ for (shape = priv->shapes; shape; shape = shape->next) { gint w = x_2 - x_1; gint h = y_2 - y_1; ClutterGeometry *geo = (ClutterGeometry*)shape->data; cogl_texture_rectangle ( cogl_texture, CLUTTER_INT_TO_FIXED(w * geo->x / priv->pixmap_width), CLUTTER_INT_TO_FIXED(h * geo->y / priv->pixmap_height), CLUTTER_INT_TO_FIXED(w * (geo->x+geo->width) / priv->pixmap_width), CLUTTER_INT_TO_FIXED(h * (geo->y+geo->height) / priv->pixmap_height), t_w * geo->x / priv->pixmap_width, t_h * geo->y / priv->pixmap_height, t_w * (geo->x+geo->width) / priv->pixmap_width, t_h * (geo->y+geo->height) / priv->pixmap_height); } }
static void mnb_toolbar_shadow_paint (ClutterActor *self) { MnbToolbarShadowPrivate *priv = MNB_TOOLBAR_SHADOW (self)->priv; CoglHandle cogl_texture = COGL_INVALID_HANDLE; CoglHandle cogl_material = COGL_INVALID_HANDLE; ClutterActorBox box = { 0, }; gfloat width, height; gfloat tex_width, tex_height; gfloat ex, ey; gfloat tx1, ty1, tx2, ty2; guint8 opacity; /* no need to paint stuff if we don't have a texture */ if (G_UNLIKELY (priv->parent_texture == NULL)) return; /* parent texture may have been hidden, so need to make sure it gets * realized */ if (!CLUTTER_ACTOR_IS_REALIZED (priv->parent_texture)) clutter_actor_realize (CLUTTER_ACTOR (priv->parent_texture)); cogl_texture = clutter_texture_get_cogl_texture (priv->parent_texture); if (cogl_texture == COGL_INVALID_HANDLE) return; cogl_material = clutter_texture_get_cogl_material (priv->parent_texture); if (cogl_material == COGL_INVALID_HANDLE) return; tex_width = cogl_texture_get_width (cogl_texture); tex_height = cogl_texture_get_height (cogl_texture); clutter_actor_get_allocation_box (self, &box); width = box.x2 - box.x1; height = box.y2 - box.y1; opacity = clutter_actor_get_paint_opacity (self); /* Paint using the parent texture's material. It should already have the cogl texture set as the first layer */ /* NB: for correct blending we need set a preumultiplied color here: */ cogl_material_set_color4ub (cogl_material, opacity, opacity, opacity, opacity); #if TOOLBAR_CUT_OUT selector_texture = mnb_toolbar_get_selector_texture (priv->toolbar); cogl_material_set_layer (cogl_material, 1, selector_texture); cogl_material_set_layer_wrap_mode (cogl_material, 1, COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE); if (!cogl_material_set_layer_combine (cogl_material, 1, "RGBA = MODULATE(PREVIOUS,TEXTURE)", &error)) { g_warning (G_STRLOC ": Error setting layer combine blend string: %s", error->message); g_error_free (error); } #endif cogl_set_source (cogl_material); /* simple stretch */ if (priv->left == 0 && priv->right == 0 && priv->top == 0 && priv->bottom == 0) { #if TOOLBAR_CUT_OUT float spot_width, spot_height; float coords[8] = { 0, 0, 1, 1, 0, 0, 0, 0 }; mnb_toolbar_get_selector_allocation_box (priv->toolbar, &box); spot_width = box.x2 - box.x1; spot_height = box.y2 - box.y1; coords[4] = -(box.x1 / width) * (width / spot_width); coords[5] = -(box.y1 + SHADOW_CUT_OUT_OFFSET / height) * (height / spot_height); coords[6] = width / spot_width - (box.x1 / width) * (width / spot_width); coords[7] = height / spot_height - (box.y1 + SHADOW_CUT_OUT_OFFSET / height) * (height / spot_height); cogl_rectangle_with_multitexture_coords (0, 0, width, height, coords, 8); #else cogl_rectangle (0, 0, width, height); #endif /* TOOLBAR_CUT_OUT */ return; } tx1 = priv->left / tex_width; tx2 = (tex_width - priv->right) / tex_width; ty1 = priv->top / tex_height; ty2 = (tex_height - priv->bottom) / tex_height; ex = width - priv->right; if (ex < priv->left) ex = priv->left; ey = height - priv->bottom; if (ey < priv->top) ey = priv->top; { GLfloat rectangles[] = { /* top left corner */ 0, 0, priv->left, priv->top, 0.0, 0.0, tx1, ty1, /* top middle */ priv->left, 0, MAX (priv->left, ex), priv->top, tx1, 0.0, tx2, ty1, /* top right */ ex, 0, MAX (ex + priv->right, width), priv->top, tx2, 0.0, 1.0, ty1, /* mid left */ 0, priv->top, priv->left, ey, 0.0, ty1, tx1, ty2, /* center */ priv->left, priv->top, ex, ey, tx1, ty1, tx2, ty2, /* mid right */ ex, priv->top, MAX (ex + priv->right, width), ey, tx2, ty1, 1.0, ty2, /* bottom left */ 0, ey, priv->left, MAX (ey + priv->bottom, height), 0.0, ty2, tx1, 1.0, /* bottom center */ priv->left, ey, ex, MAX (ey + priv->bottom, height), tx1, ty2, tx2, 1.0, /* bottom right */ ex, ey, MAX (ex + priv->right, width), MAX (ey + priv->bottom, height), tx2, ty2, 1.0, 1.0 }; cogl_rectangles_with_texture_coords (rectangles, 9); } }
int main (int argc, char *argv[]) { ClutterActor *video; GdkPixbuf *shot = NULL; gint duration; CoglHandle tex_id; CoglPixelFormat format; gint size; gint width; gint height; gint rowstride; guchar *data = NULL; #ifdef USE_HELIX clutter_helix_init (&argc, &argv); #else gst_init (&argc, &argv); #endif clutter_init (&argc, &argv); if (argc < 3) { g_print ("Usage: %s <path to movie file> <output png>\n", argv[0]); exit(-1); } totem_resources_monitor_start (argv[1], 60 * G_USEC_PER_SEC); #ifdef USE_HELIX video = clutter_helix_video_texture_new (); #else video = clutter_gst_video_texture_new (); #endif if (argv[1][0] == '/') clutter_media_set_filename(CLUTTER_MEDIA(video), argv[1]); else clutter_media_set_uri(CLUTTER_MEDIA(video), argv[1]); clutter_media_set_volume (CLUTTER_MEDIA(video), 0); clutter_media_set_playing (CLUTTER_MEDIA(video), TRUE); do { while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, FALSE); duration = clutter_media_get_duration (CLUTTER_MEDIA(video)); } while (duration == 0); clutter_actor_realize (video); clutter_media_set_position (CLUTTER_MEDIA(video), duration/3); do { while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, FALSE); } while (clutter_media_get_position (CLUTTER_MEDIA(video)) <= duration/3); tex_id = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (video)); if (tex_id) { format = cogl_texture_get_format (tex_id); size = cogl_texture_get_data (tex_id, format, 0, NULL); width = cogl_texture_get_width (tex_id); height = cogl_texture_get_height (tex_id); rowstride = cogl_texture_get_rowstride (tex_id); data = (guchar*) g_malloc (sizeof(guchar) * size); if (!data) g_error ("malloc");; cogl_texture_get_data (tex_id, format, rowstride, data); shot = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, FALSE, 8, width, height, rowstride, NULL, NULL); } totem_resources_monitor_stop (); if (shot) { GdkPixbuf *thumb, *pic; gint x, y, nw, nh, w, h, size; size = 128; /* FIXME swap RGB pixels */ w = clutter_actor_get_width (video); h = clutter_actor_get_height (video); nh = ( h * size) / w; if (nh <= size) { nw = size; x = 0; y = (size - nh) / 2; } else { nw = ( w * size ) / h; nh = size; x = (size - nw) / 2; y = 0; } thumb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, size, size); gdk_pixbuf_fill (thumb, 0x000000FF); pic = gdk_pixbuf_scale_simple (shot, nw, nh, GDK_INTERP_BILINEAR); gdk_pixbuf_copy_area (pic, 0, 0, nw, nh, thumb, x, y); if (!gdk_pixbuf_save (thumb, argv[2], "png", NULL, NULL)) { g_error ("%s: Pixbuf save failed\n", argv[0]); exit(-1); } g_object_unref (shot); g_object_unref (thumb); g_object_unref (pic); exit(0); } exit (-1); }
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; }