Skip to content

Commit

Permalink
Remove the use of ClutterTexture
Browse files Browse the repository at this point in the history
ClutterTexture has been deprecated, so this patch removes API that exposes
ClutterTexture and replaces the use of ClutterTexture internally. In most
cases, ClutterTexture can be replaced by CoglTexture, which should also
improve performance.

This patch also removes the MxTextureFrame actor (which depended on
ClutterTexture) since it was not useful on its own and can be
implemented in other actors by using the mx_texture_frame_paint_texture
utility function.
  • Loading branch information
thos committed Mar 12, 2013
1 parent 6c989d7 commit e5f2db8
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 930 deletions.
55 changes: 19 additions & 36 deletions mx/mx-button.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct _MxButtonPrivate

ClutterAnimation *animation;

ClutterActor *content_image;
CoglTexture *content_image;
ClutterActor *child;

MxAction *action;
Expand Down Expand Up @@ -226,18 +226,12 @@ mx_button_style_changed (MxWidget *widget)
if (content_image && content_image->uri)
{
if (priv->content_image)
{
clutter_actor_remove_child (CLUTTER_ACTOR (widget),
priv->content_image);
}
cogl_object_unref (priv->content_image);

priv->content_image =
(ClutterActor*) mx_texture_cache_get_texture (mx_texture_cache_get_default (),
content_image->uri);
priv->content_image = mx_texture_cache_get_cogl_texture (mx_texture_cache_get_default (),
content_image->uri);

if (priv->content_image)
clutter_actor_add_child (CLUTTER_ACTOR (widget), priv->content_image);
else
if (!priv->content_image)
g_warning ("Could not load content image \"%s\"", content_image->uri);

g_boxed_free (MX_TYPE_BORDER_IMAGE, content_image);
Expand All @@ -248,11 +242,7 @@ mx_button_style_changed (MxWidget *widget)
{
/* remove any previous content image */
if (priv->content_image)
{
clutter_actor_remove_child (CLUTTER_ACTOR (widget),
priv->content_image);
priv->content_image = NULL;
}
cogl_object_unref (priv->content_image);

if (content_image)
g_boxed_free (MX_TYPE_BORDER_IMAGE, content_image);
Expand Down Expand Up @@ -645,7 +635,7 @@ mx_button_dispose (GObject *gobject)

if (priv->content_image)
{
clutter_actor_remove_child (CLUTTER_ACTOR (gobject), priv->content_image);
cogl_object_unref (priv->content_image);
priv->content_image = NULL;
}

Expand All @@ -662,20 +652,6 @@ mx_button_allocate (ClutterActor *actor,

CLUTTER_ACTOR_CLASS (mx_button_parent_class)->allocate (actor, box, flags);

if (priv->content_image)
{
ClutterActorBox childbox;

childbox.x1 = 0;
childbox.y1 = 0;
childbox.x2 = (box->x2 - box->x1);
childbox.y2 = (box->y2 - box->y1);

clutter_actor_allocate (priv->content_image, &childbox, flags);

return;
}

mx_widget_get_available_area (MX_WIDGET (actor), box, &child_box);
clutter_actor_allocate (priv->child, &child_box, flags);
}
Expand All @@ -693,8 +669,8 @@ mx_button_get_preferred_width (ClutterActor *actor,
{
gfloat width;

clutter_actor_get_preferred_width (priv->content_image, for_height,
NULL, &width);
width = cogl_texture_get_width (priv->content_image);

if (min_width)
*min_width = width;
if (pref_width)
Expand Down Expand Up @@ -733,8 +709,8 @@ mx_button_get_preferred_height (ClutterActor *actor,
{
gfloat height;

clutter_actor_get_preferred_height (priv->content_image, for_width,
NULL, &height);
height = cogl_texture_get_height (priv->content_image);

if (min_height)
*min_height = height;
if (pref_height)
Expand Down Expand Up @@ -765,7 +741,14 @@ mx_button_paint (ClutterActor *actor)
MxButtonPrivate *priv = MX_BUTTON (actor)->priv;

if (priv->content_image)
clutter_actor_paint (priv->content_image);
{
ClutterActorBox box;
clutter_actor_get_allocation_box (actor, &box);

cogl_set_source_texture (priv->content_image);
cogl_rectangle (0, 0, clutter_actor_box_get_width (&box),
clutter_actor_box_get_height (&box));
}
else
{
CLUTTER_ACTOR_CLASS (mx_button_parent_class)->paint (actor);
Expand Down
79 changes: 32 additions & 47 deletions mx/mx-combo-box.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct _MxComboBoxPrivate
{
ClutterActor *label;
ClutterActor *icon;
ClutterActor *marker;
CoglTexture *marker;
GSList *actions;
gfloat clip_x;
gfloat clip_y;
Expand Down Expand Up @@ -181,7 +181,24 @@ mx_combo_box_paint (ClutterActor *actor)
clutter_actor_paint (priv->icon);

if (priv->marker)
clutter_actor_paint (priv->marker);
{
ClutterActorBox allocation, box;
gfloat x, y, width, height;

clutter_actor_get_allocation_box (actor, &allocation);
mx_widget_get_available_area (MX_WIDGET (actor), &allocation, &box);

width = cogl_texture_get_width (priv->marker);
height = cogl_texture_get_height (priv->marker);

height = width = MAX (width, height);

x = box.x1 + clutter_actor_box_get_width (&box) - width;
y = box.y1 + (clutter_actor_box_get_height (&box) / 2) - (height / 2);

cogl_set_source_texture (priv->marker);
cogl_rectangle (x, y, x + width, y + height);
}
}

static void
Expand All @@ -196,7 +213,7 @@ mx_combo_box_get_preferred_width (ClutterActor *actor,

gfloat min_icon_w = 0, nat_icon_w = 0;
gfloat min_menu_w = 0, nat_menu_w = 0;
gfloat min_marker_w = 0, nat_marker_w = 0;
gfloat marker_w = 0;
MxComboBoxPrivate *priv = MX_COMBO_BOX (actor)->priv;

MxPadding padding;
Expand Down Expand Up @@ -238,13 +255,10 @@ mx_combo_box_get_preferred_width (ClutterActor *actor,

if (priv->marker)
{
clutter_actor_get_preferred_width (priv->marker,
height,
&min_marker_w,
&nat_marker_w);
marker_w = cogl_texture_get_width (priv->marker);

min_w += min_marker_w + priv->spacing;
nat_w += nat_marker_w + priv->spacing;
min_w += marker_w + priv->spacing;
nat_w += marker_w + priv->spacing;
}

if (min_width_p)
Expand All @@ -263,7 +277,7 @@ mx_combo_box_get_preferred_height (ClutterActor *actor,
MxComboBoxPrivate *priv = MX_COMBO_BOX (actor)->priv;
gfloat min_label_h, nat_label_h;
gfloat min_icon_h = 0, nat_icon_h = 0;
gfloat min_marker_h = 0, nat_marker_h = 0;
gfloat marker_h = 0;
gfloat min_h, nat_h;
MxPadding padding;

Expand All @@ -283,15 +297,10 @@ mx_combo_box_get_preferred_height (ClutterActor *actor,
}

if (priv->marker)
{
clutter_actor_get_preferred_height (priv->marker,
-1,
&min_marker_h,
&nat_marker_h);
}
marker_h = cogl_texture_get_height (priv->marker);

min_h = MAX (MAX (min_icon_h, min_label_h), min_marker_h);
nat_h = MAX (MAX (nat_icon_h, nat_label_h), nat_marker_h);
min_h = MAX (MAX (min_icon_h, min_label_h), marker_h);
nat_h = MAX (MAX (nat_icon_h, nat_label_h), marker_h);

if (min_height_p)
*min_height_p = padding.top + padding.bottom + min_h;
Expand All @@ -311,7 +320,7 @@ mx_combo_box_allocate (ClutterActor *actor,
gfloat min_menu_h, nat_menu_h;
gfloat label_h;
gfloat nat_icon_h, icon_h, icon_w;
gfloat nat_marker_h, marker_h, marker_w;
gfloat marker_w;
ClutterActorBox childbox;
ClutterActor *menu, *stage;

Expand Down Expand Up @@ -355,29 +364,7 @@ mx_combo_box_allocate (ClutterActor *actor,

if (priv->marker)
{
clutter_actor_get_preferred_height (priv->marker, -1,
NULL, &nat_marker_h);

if (height >= nat_marker_h)
{
marker_h = nat_marker_h;
clutter_actor_get_preferred_width (priv->marker, -1, NULL,
&marker_w);
}
else
{
marker_h = height;
clutter_actor_get_preferred_width (priv->marker, marker_h,
NULL, &marker_w);
}

childbox.x2 = (int)(x + width);
childbox.x1 = (int)(childbox.x2 - marker_w);
childbox.y1 = (int)(y + (height - marker_h) / 2);
childbox.y2 = (int)(childbox.y1 + marker_h);

clutter_actor_allocate (priv->marker, &childbox, flags);

marker_w = cogl_texture_get_width (priv->marker);
marker_w += priv->spacing;
}

Expand Down Expand Up @@ -566,17 +553,15 @@ mx_combo_box_style_changed (MxComboBox *combo, MxStyleChangedFlags flags)

if (priv->marker)
{
clutter_actor_destroy (priv->marker);
cogl_object_unref (priv->marker);
priv->marker = NULL;
}

if (marker_filename)
{
MxTextureCache *cache = mx_texture_cache_get_default ();
priv->marker = (ClutterActor *)
mx_texture_cache_get_texture (cache, marker_filename->uri);
if (priv->marker)
clutter_actor_add_child (CLUTTER_ACTOR (combo), priv->marker);
priv->marker = mx_texture_cache_get_cogl_texture (cache,
marker_filename->uri);

g_boxed_free (MX_TYPE_BORDER_IMAGE, marker_filename);
}
Expand Down
27 changes: 21 additions & 6 deletions mx/mx-entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <glib.h>

#include <clutter/clutter.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#ifdef HAVE_CLUTTER_IMCONTEXT
#include <clutter-imcontext/clutter-imtext.h>
#endif
Expand Down Expand Up @@ -1719,13 +1720,27 @@ _mx_entry_set_icon_from_file (MxEntry *entry,

if (filename)
{
MxTextureCache *cache;

cache = mx_texture_cache_get_default ();


ClutterContent *content;
GdkPixbuf *pixbuf;

*icon = clutter_actor_new ();

content = clutter_image_new ();

pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
content = clutter_image_new ();
clutter_image_set_data (CLUTTER_IMAGE (content),
gdk_pixbuf_get_pixels (pixbuf),
gdk_pixbuf_get_has_alpha (pixbuf)
? COGL_PIXEL_FORMAT_RGBA_8888
: COGL_PIXEL_FORMAT_RGB_888,
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf),
gdk_pixbuf_get_rowstride (pixbuf),
NULL);
g_object_unref (pixbuf);

*icon = (ClutterActor*) mx_texture_cache_get_texture (cache, filename);
clutter_actor_set_content (*icon, content);

if (!*icon)
return;
Expand Down
29 changes: 0 additions & 29 deletions mx/mx-icon-theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,35 +946,6 @@ mx_icon_theme_lookup (MxIconTheme *theme,
return mx_texture_cache_get_cogl_texture (texture_cache, icon_data->path);
}

/**
* mx_icon_theme_lookup_texture:
* @theme: an #MxIconTheme
* @icon_name: The name of the icon
* @size: The desired size of the icon
*
* If the icon is available, returns a #ClutterTexture of the icon.
*
* Return value: (transfer none): a #ClutterTexture of the icon, or %NULL.
*/
ClutterTexture *
mx_icon_theme_lookup_texture (MxIconTheme *theme,
const gchar *icon_name,
gint size)
{
MxTextureCache *texture_cache;
MxIconData *icon_data;

g_return_val_if_fail (MX_IS_ICON_THEME (theme), NULL);
g_return_val_if_fail (icon_name, NULL);
g_return_val_if_fail (size > 0, NULL);

if (!(icon_data = mx_icon_theme_lookup_internal (theme, icon_name, size)))
return NULL;

texture_cache = mx_texture_cache_get_default ();
return mx_texture_cache_get_texture (texture_cache, icon_data->path);
}

gboolean
mx_icon_theme_has_icon (MxIconTheme *theme,
const gchar *icon_name)
Expand Down
4 changes: 0 additions & 4 deletions mx/mx-icon-theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ CoglHandle mx_icon_theme_lookup (MxIconTheme *theme,
const gchar *icon_name,
gint size);

ClutterTexture *mx_icon_theme_lookup_texture (MxIconTheme *theme,
const gchar *icon_name,
gint size);

gboolean mx_icon_theme_has_icon (MxIconTheme *theme,
const gchar *icon_name);

Expand Down
Loading

0 comments on commit e5f2db8

Please sign in to comment.