Color handling changes




I have a fairly large set of color-handling changes that I've been
working on recently.

These changes can be though of as:

 a) A set of changes to the way color handling works internally
    that improve the performance of GTK+ significantly, and
    are the basis for an accompanying important set of changes to the
    Text widget. (They remove the need to pre-realize the Text
    widget, and allow it to change styles properly).

 b) A new set of interfaces to color allocation and freeing that
    are (IMO) considerably better than the old ones, but that
    I'm not sure are completely right yet. The old interfaces
    still work as before.

I'd really like to get the Text widget improvements into the main tree
soon (the bugs they fix are causing problems for the themes branch),
and since all of the above changes really need to be committed at
once, I'm planning on committing the above, then fine-tuning the new
interfaces, instead of doing it the other way around. 

I don't think this will adversly affect anyone, since I've been using
this code for a while and it seems to work pretty well, and
all old code should work as before.


To elaborate on the above, the improvements in a) are:

 - For true-color visuals, compose pixel values ourself instead
   of calling XAllocColor(). (Big speedup)

 - For pseudo-color and grayscale visuals, we do several things:
  
   * We keep a hash table so that we can quickly find if we've 
     previously allocated a given color.

   * When allocating a given color repeatedly, we only call
     XAllocColor once and reference count our allocations.

   * When best-matching to existing colors, don't just 
     read the system colormap once, but also synchronize
     to it periodically.


And now on to b)... the reason for redesigning the color
allocation interface was because the current interface sticks
very close to X and has some unneeded features (planar allocation)
and weird quirks (gdk_color_alloc() allocates a read-only
color cell, gdk_colors_alloc() allocates read-write color
cells) as a consequence.

Currently, the new interfaces are:

gboolean gdk_colormap_alloc_color  (GdkColormap *colormap,
				    GdkColor    *color,
				    gboolean     writeable,
				    gboolean     best_match);

gint     gdk_colormap_alloc_colors (GdkColormap *colormap,
				    GdkColor    *colors,
				    gint         ncolors,
				    gboolean     writeable,
				    gboolean     best_match,
				    gboolean    *success);

void     gdk_colormap_free_colors  (GdkColormap *colormap,
				    GdkColor    *colors,
				    gint         ncolors);
     
I haven't yet decided whether the gdk_colormap_alloc_colors()
form necessary at all. (It is now more efficient to allocate
a bunch of colors at once, but I think that advantage could
be eliminated.) So, feel free to use the new interfaces,
but be aware that the details may change.

(If any body is interest in more design thoughts I had when
 I was beginning to work on this, see:

 http://www.gtk.org/~otaylor/whitepapers/color-handling.html

 There is still quite a bit of that which isn't implemented 
 yet)

Anyways, this is sort of a heads-up about these changes.
If anything breaks, let me know - I'll fix it as quickly
as possible. See the ChangeLog for more complete information
about these changes.

Regards,
                                        Owen



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