Use the content scaling filters

Both ClutterCanvas and ClutterImage should use the minification and
magnification filters set on the actor, just like the use the content
box and the paint opacity.
This commit is contained in:
Emmanuele Bassi 2012-03-08 17:19:12 +00:00
parent 77729c7362
commit fb106ece05
4 changed files with 49 additions and 21 deletions

View File

@ -293,6 +293,7 @@ clutter_canvas_paint_content (ClutterContent *content,
ClutterActorBox box; ClutterActorBox box;
ClutterColor color; ClutterColor color;
guint8 paint_opacity; guint8 paint_opacity;
ClutterScalingFilter min_f, mag_f;
if (self->priv->buffer == NULL) if (self->priv->buffer == NULL)
return; return;
@ -305,13 +306,14 @@ clutter_canvas_paint_content (ClutterContent *content,
clutter_actor_get_content_box (actor, &box); clutter_actor_get_content_box (actor, &box);
paint_opacity = clutter_actor_get_paint_opacity (actor); paint_opacity = clutter_actor_get_paint_opacity (actor);
clutter_actor_get_content_scaling_filters (actor, &min_f, &mag_f);
color.red = paint_opacity; color.red = paint_opacity;
color.green = paint_opacity; color.green = paint_opacity;
color.blue = paint_opacity; color.blue = paint_opacity;
color.alpha = paint_opacity; color.alpha = paint_opacity;
node = clutter_texture_node_new (texture, &color); node = clutter_texture_node_new (texture, &color, min_f, mag_f);
cogl_object_unref (texture); cogl_object_unref (texture);
clutter_paint_node_set_name (node, "Canvas"); clutter_paint_node_set_name (node, "Canvas");

View File

@ -87,6 +87,7 @@ clutter_image_paint_content (ClutterContent *content,
ClutterPaintNode *root) ClutterPaintNode *root)
{ {
ClutterImagePrivate *priv = CLUTTER_IMAGE (content)->priv; ClutterImagePrivate *priv = CLUTTER_IMAGE (content)->priv;
ClutterScalingFilter min_f, mag_f;
ClutterPaintNode *node; ClutterPaintNode *node;
ClutterActorBox box; ClutterActorBox box;
ClutterColor color; ClutterColor color;
@ -97,13 +98,14 @@ clutter_image_paint_content (ClutterContent *content,
clutter_actor_get_content_box (actor, &box); clutter_actor_get_content_box (actor, &box);
paint_opacity = clutter_actor_get_paint_opacity (actor); paint_opacity = clutter_actor_get_paint_opacity (actor);
clutter_actor_get_content_scaling_filters (actor, &min_f, &mag_f);
color.red = paint_opacity; color.red = paint_opacity;
color.green = paint_opacity; color.green = paint_opacity;
color.blue = paint_opacity; color.blue = paint_opacity;
color.alpha = paint_opacity; color.alpha = paint_opacity;
node = clutter_texture_node_new (priv->texture, &color); node = clutter_texture_node_new (priv->texture, &color, min_f, mag_f);
clutter_paint_node_set_name (node, "Image"); clutter_paint_node_set_name (node, "Image");
clutter_paint_node_add_rectangle (node, &box); clutter_paint_node_add_rectangle (node, &box);
clutter_paint_node_add_child (root, node); clutter_paint_node_add_child (root, node);

View File

@ -609,10 +609,30 @@ clutter_texture_node_init (ClutterTextureNode *self)
pnode->pipeline = cogl_pipeline_copy (default_texture_pipeline); pnode->pipeline = cogl_pipeline_copy (default_texture_pipeline);
} }
static CoglPipelineFilter
clutter_scaling_filter_to_cogl_pipeline_filter (ClutterScalingFilter filter)
{
switch (filter)
{
case CLUTTER_SCALING_FILTER_NEAREST:
return COGL_PIPELINE_FILTER_NEAREST;
case CLUTTER_SCALING_FILTER_LINEAR:
return COGL_PIPELINE_FILTER_LINEAR;
case CLUTTER_SCALING_FILTER_BILINEAR:
return COGL_PIPELINE_FILTER_LINEAR_MIPMAP_LINEAR;
}
return COGL_PIPELINE_FILTER_LINEAR;
}
/** /**
* clutter_texture_node_new: * clutter_texture_node_new:
* @texture: (allow-none): a #CoglTexture * @texture: a #CoglTexture
* @color: (allow-none): a #ClutterColor * @color: a #ClutterColor
* @min_filter: the minification filter for the texture
* @mag_filter: the magnification filter for the texture
* *
* Creates a new #ClutterPaintNode that will paint the passed @texture. * Creates a new #ClutterPaintNode that will paint the passed @texture.
* *
@ -626,20 +646,23 @@ clutter_texture_node_init (ClutterTextureNode *self)
*/ */
ClutterPaintNode * ClutterPaintNode *
clutter_texture_node_new (CoglTexture *texture, clutter_texture_node_new (CoglTexture *texture,
const ClutterColor *color) const ClutterColor *color,
ClutterScalingFilter min_filter,
ClutterScalingFilter mag_filter)
{ {
ClutterPipelineNode *tnode; ClutterPipelineNode *tnode;
CoglColor cogl_color;
CoglPipelineFilter min_f, mag_f;
g_return_val_if_fail (texture == NULL || cogl_is_texture (texture), NULL); g_return_val_if_fail (cogl_is_texture (texture), NULL);
tnode = _clutter_paint_node_internal (CLUTTER_TYPE_TEXTURE_NODE); tnode = _clutter_paint_node_internal (CLUTTER_TYPE_TEXTURE_NODE);
if (texture != NULL)
cogl_pipeline_set_layer_texture (tnode->pipeline, 0, texture); cogl_pipeline_set_layer_texture (tnode->pipeline, 0, texture);
if (color != NULL) min_f = clutter_scaling_filter_to_cogl_pipeline_filter (min_filter);
{ mag_f = clutter_scaling_filter_to_cogl_pipeline_filter (mag_filter);
CoglColor cogl_color; cogl_pipeline_set_layer_filters (tnode->pipeline, 0, min_f, mag_f);
cogl_color_init_from_4ub (&cogl_color, cogl_color_init_from_4ub (&cogl_color,
color->red, color->red,
@ -648,7 +671,6 @@ clutter_texture_node_new (CoglTexture *texture,
color->alpha); color->alpha);
cogl_color_premultiply (&cogl_color); cogl_color_premultiply (&cogl_color);
cogl_pipeline_set_color (tnode->pipeline, &cogl_color); cogl_pipeline_set_color (tnode->pipeline, &cogl_color);
}
return (ClutterPaintNode *) tnode; return (ClutterPaintNode *) tnode;
} }

View File

@ -71,7 +71,9 @@ typedef struct _ClutterTextureNodeClass ClutterTextureNodeClass;
GType clutter_texture_node_get_type (void) G_GNUC_CONST; GType clutter_texture_node_get_type (void) G_GNUC_CONST;
ClutterPaintNode * clutter_texture_node_new (CoglTexture *texture, ClutterPaintNode * clutter_texture_node_new (CoglTexture *texture,
const ClutterColor *color); const ClutterColor *color,
ClutterScalingFilter min_filter,
ClutterScalingFilter mag_filter);
#define CLUTTER_TYPE_CLIP_NODE (clutter_clip_node_get_type ()) #define CLUTTER_TYPE_CLIP_NODE (clutter_clip_node_get_type ())
#define CLUTTER_CLIP_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_CLIP_NODE, ClutterClipNode)) #define CLUTTER_CLIP_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_CLIP_NODE, ClutterClipNode))