Re: GIcon thoughts



On Wed, 2008-01-09 at 13:53 -0500, Matthias Clasen wrote:
> This leaves GIcon support, pixel sizes and caching. Concrete API
> additions could look as follows:

That sounds like a good plan to me.

> /* Creates a new GtkIconInfo for a fixed pixbuf - this is not
> * really necessary as API, but it is used internally 
> * for GFileIcons, and making it public doesn't cost us much
> */
> GtkIconInfo *
> gtk_icon_info_new_for_pixbuf (GtkIconTheme *theme,
>                               GdkPixbuf    *pixbuf);
> 
> /* Looks up a GtkIconInfo for a GIcon and a given pixel size.
> * Note that looking up by pixel size still doesn't guarantee
> * that you actually get a pixbuf of that size; for that, see
> * load_at_size().
> *
> * To look up by GtkIconSize, use gtk_icon_size_lookup_for_settings. 
> */
> GtkIconInfo *
> gtk_icon_theme_lookup_by_gicon (GtkIconTheme *theme,
>                                 GIcon        *icon,
>                                 gint          pixel_size);
>
> /* Loads the icon, and scales it to the given size -
> * some care should be taken to make load_at_size(); load() work
> * correctly wrt. to sizes, while still getting some caching 
> * benefits for repeated load_at_size() with the same size 
> */
> GdkPixbuf *
> gtk_icon_info_load_at_size (GtkIconInfo *info,
>                             gint         pixel_size);
> 

Since this does I/O it would be nice if it took a GCancellable argument.
However, that might be slightly weird, given that
gtk_icon_info_load_icon() doesn't. It should have a GError arg too.

> We can't implement the cache using toggle references for 2 reasons:
> a) GtkIconSize is a boxed, not an object 
> b) toggle references only work for a single user, thus they have
>    to be reserved for bindings, at least bindable objects.
> I propose to instead turn GtkIconInfo into a refcounted boxed object,
> and then implement the caching logic for the case that the refcount
> drops to one.

I'm not sure this is enought, cache-wise. In many cases you'd get a
GtkIconInfo, then get the pixbuf for that, save the pixbuf (e.g. in a
widget) and unref the info. In fact, it seems unlikely that apps would
keep the GtkIconInfo alive for long periods of time. It would be nice if
we could get the GtkIconInfo cached until the last ref is dropped to the
pixbuf. 

Of course, this is slightly harder, as GdkPixbuf is a public GObject
where we can't use toggle references. We could however implement this
with some help from the GdkPixbuf implementation. For instance, if we
add a resurrect signal to GdkPixbuf and have the dispose()
implementation emit this then the cache could connect to this and grab a
ref (for some time) before finalization. (The dispose call must also
detect that the object is ressurected and avoid chaining to dispose.)

That might be useful for other pixbuf caches too.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]