source: trunk/third/bonobo/bonobo/bonobo-ui-pixmap-cache.c @ 17169

Revision 17169, 2.5 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17168, which included commits to RCS files with non-trunk default branches.
Line 
1/* bonobo-ui-pixmap-cache.h: Pixmap cache for the Bonobo UI engine
2 *
3 * Copyright (C) 2001 Ximian, Inc.
4 *
5 * Author: Federico Mena-Quintero <federico@ximian.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
27#include "bonobo-ui-pixmap-cache.h"
28
29
30
31/* Pair of pixmap/mask from a rendered pixbuf */
32typedef struct {
33        GdkPixmap *pixmap;
34        GdkBitmap *mask;
35} PixmapMask;
36
37/* Mapping of pixbuf pointers to PixmapMask pairs */
38static GHashTable *pixbuf_pixmap_hash = NULL;
39
40
41
42/* Ensures that the pixbuf->pixmap hash table has been created */
43static void
44ensure_hash_table (void)
45{
46        if (pixbuf_pixmap_hash)
47                return;
48
49        pixbuf_pixmap_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
50}
51
52/**
53 * bonobo_ui_pixmap_cache_get:
54 * @source: Source pixbuf.
55 * @pixmap_ret: Return value for the rendered pixmap.
56 * @mask_ret: Return value for the opacity mask.
57 *
58 * Gets a rendered pixmap/mask pair from a pixbuf.  The pixmap and mask are
59 * cached based on the @source pixbuf pointer so that no duplicated rendering is
60 * performed.  You should unref the returned pixmap and mask with
61 * gdk_pixmap_unref() and gdk_bitmap_unref(), respectively, when you are done
62 * with them.
63 **/
64void
65bonobo_ui_pixmap_cache_get (GdkPixbuf *source, GdkPixmap **pixmap_ret, GdkBitmap **mask_ret)
66{
67        PixmapMask *pm;
68
69        g_return_if_fail (source != NULL);
70        g_return_if_fail (pixmap_ret != NULL);
71        g_return_if_fail (mask_ret != NULL);
72
73        ensure_hash_table ();
74
75        pm = g_hash_table_lookup (pixbuf_pixmap_hash, source);
76
77        if (!pm) {
78                pm = g_new (PixmapMask, 1);
79                gdk_pixbuf_render_pixmap_and_mask (source, &pm->pixmap, &pm->mask, 128);
80                g_hash_table_insert (pixbuf_pixmap_hash, source, pm);
81        }
82
83        if (pm->pixmap)
84                gdk_pixmap_ref (pm->pixmap);
85
86        if (pm->mask)
87                gdk_bitmap_ref (pm->mask);
88
89        *pixmap_ret = pm->pixmap;
90        *mask_ret = pm->mask;
91}
Note: See TracBrowser for help on using the repository browser.