1
/* cairo - a vector graphics library with display and print output
3
* Copyright © 2004 Red Hat, Inc.
4
* Copyright © 2005 Red Hat, Inc.
6
* This library is free software; you can redistribute it and/or
7
* modify it either under the terms of the GNU Lesser General Public
8
* License version 2.1 as published by the Free Software Foundation
9
* (the "LGPL") or, at your option, under the terms of the Mozilla
10
* Public License Version 1.1 (the "MPL"). If you do not alter this
11
* notice, a recipient may use your version of this file under either
12
* the MPL or the LGPL.
14
* You should have received a copy of the LGPL along with this library
15
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
* You should have received a copy of the MPL along with this library
18
* in the file COPYING-MPL-1.1
20
* The contents of this file are subject to the Mozilla Public License
21
* Version 1.1 (the "License"); you may not use this file except in
22
* compliance with the License. You may obtain a copy of the License at
23
* http://www.mozilla.org/MPL/
25
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
26
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
27
* the specific language governing rights and limitations.
29
* The Original Code is the cairo graphics library.
31
* The Initial Developer of the Original Code is Red Hat, Inc.
34
* Keith Packard <keithp@keithp.com>
35
* Graydon Hoare <graydon@redhat.com>
36
* Carl Worth <cworth@cworth.org>
39
#ifndef CAIRO_CACHE_PRIVATE_H
40
#define CAIRO_CACHE_PRIVATE_H
42
#include "cairo-compiler-private.h"
43
#include "cairo-types-private.h"
46
* cairo_cache_entry_t:
48
* A #cairo_cache_entry_t contains both a key and a value for
49
* #cairo_cache_t. User-derived types for #cairo_cache_entry_t must
50
* have a #cairo_cache_entry_t as their first field. For example:
53
* cairo_cache_entry_t base;
54
* ... Remainder of key and value fields here ..
57
* which then allows a pointer to my_entry_t to be passed to any of
58
* the #cairo_cache_t functions as follows without requiring a cast:
60
* _cairo_cache_insert (cache, &my_entry->base, size);
62
* IMPORTANT: The caller is responsible for initializing
63
* my_entry->base.hash with a hash code derived from the key. The
64
* essential property of the hash code is that keys_equal must never
65
* return %TRUE for two keys that have different hashes. The best hash
66
* code will reduce the frequency of two keys with the same code for
67
* which keys_equal returns %FALSE.
69
* The user must also initialize my_entry->base.size to indicate
70
* the size of the current entry. What units to use for size is
71
* entirely up to the caller, (though the same units must be used for
72
* the max_size parameter passed to _cairo_cache_create()). If all
73
* entries are close to the same size, the simplest thing to do is to
74
* just use units of "entries", (eg. set size==1 in all entries and
75
* set max_size to the number of entries which you want to be saved
78
* Which parts of the entry make up the "key" and which part make up
79
* the value are entirely up to the caller, (as determined by the
80
* computation going into base.hash as well as the keys_equal
81
* function). A few of the #cairo_cache_t functions accept an entry which
82
* will be used exclusively as a "key", (indicated by a parameter name
83
* of key). In these cases, the value-related fields of the entry need
84
* not be initialized if so desired.
86
typedef struct _cairo_cache_entry {
89
} cairo_cache_entry_t;
92
(*cairo_cache_keys_equal_func_t) (const void *key_a, const void *key_b);
95
(*cairo_cache_callback_func_t) (void *entry,
98
cairo_private cairo_cache_t *
99
_cairo_cache_create (cairo_cache_keys_equal_func_t keys_equal,
100
cairo_destroy_func_t entry_destroy,
101
unsigned long max_size);
104
_cairo_cache_destroy (cairo_cache_t *cache);
107
_cairo_cache_freeze (cairo_cache_t *cache);
110
_cairo_cache_thaw (cairo_cache_t *cache);
112
cairo_private cairo_bool_t
113
_cairo_cache_lookup (cairo_cache_t *cache,
114
cairo_cache_entry_t *key,
115
cairo_cache_entry_t **entry_return);
117
cairo_private cairo_status_t
118
_cairo_cache_insert (cairo_cache_t *cache,
119
cairo_cache_entry_t *entry);
122
_cairo_cache_foreach (cairo_cache_t *cache,
123
cairo_cache_callback_func_t cache_callback,