3 Copyright 1996, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
27 * (c) Copyright 1996 Hewlett-Packard Company
28 * (c) Copyright 1996 International Business Machines Corp.
29 * (c) Copyright 1996, 2000 Sun Microsystems, Inc. All Rights Reserved.
30 * (c) Copyright 1996 Novell, Inc.
31 * (c) Copyright 1996 Digital Equipment Corp.
32 * (c) Copyright 1996 Fujitsu Limited
33 * (c) Copyright 1996 Hitachi, Ltd.
35 * Permission is hereby granted, free of charge, to any person obtaining
36 * a copy of this software and associated documentation files (the
37 * "Software"), to deal in the Software without restriction, including
38 * without limitation the rights to use, copy, modify, merge, publish,
39 * distribute, sublicense, and/or sell copies of the Software, and to
40 * permit persons to whom the Software is furnished to do so, subject
41 * to the following conditions:
43 * The above copyright notice and this permission notice shall be included
44 * in all copies or substantial portions of the Software.
46 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
49 * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
50 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
51 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
54 * Except as contained in this notice, the names of the copyright holders
55 * shall not be used in advertising or otherwise to promote the sale, use
56 * or other dealings in this Software without prior written authorization
57 * from said copyright holders.
60 /*******************************************************************
62 ** *********************************************************
66 ** * Contents: Character-caching routines
68 ** * Created By: Jay Hobson (Sun MicroSystems)
70 ** * Copyright: Copyright 1996 The Open Group, Inc.
72 ** *********************************************************
74 ********************************************************************/
76 #ifdef HAVE_DIX_CONFIG_H
77 #include <dix-config.h>
82 #include "windowstr.h"
83 #include <X11/fonts/fntfil.h>
84 #include <X11/fonts/fntfilst.h>
89 struct bm_cache_list
{
90 struct bm_cache_list
*next
;
91 struct bm_cache_list
*prev
;
97 struct bm_cache_head
{
98 struct bm_cache_list
*head
;
100 struct bm_cache_head
*next
;
101 struct bm_cache_head
*prev
;
104 static struct bm_cache_head
*bm_cache
= NULL
;
107 PsBmUniqueId(int func
)
109 static long unique_id
= 0;
127 struct bm_cache_head
*pList
= bm_cache
;
129 while(pList
!= NULL
&& !return_val
)
131 if(pList
->width
== gWidth
)
133 struct bm_cache_list
*pItem
= pList
->head
;
137 if(pItem
->height
== gHeight
)
139 int length
= 4*(gWidth
/32+(gWidth
%32!=0))*gHeight
;
141 if(!memcmp(pItem
->pBuffer
, pBuffer
, sizeof(char)*length
))
143 return_val
= pItem
->id
;
147 else if(pItem
->height
> gHeight
)
153 else if(pList
->width
> gWidth
)
168 struct bm_cache_head
*pList
= bm_cache
;
169 struct bm_cache_list
*pNew
;
170 int length
= 4*(gWidth
/32+(gWidth
%32!=0))*gHeight
;
172 if(gWidth
== 1 && gHeight
== 1 && pBuffer
[0] == 0)
175 pNew
= (struct bm_cache_list
*)malloc(sizeof(struct bm_cache_list
));
178 pNew
->height
= gHeight
;
179 pNew
->id
= PsBmUniqueId(GET
);
180 pNew
->pBuffer
= (char *)malloc(sizeof(char)*length
);
182 memcpy(pNew
->pBuffer
, pBuffer
, length
);
186 if(pList
->width
== gWidth
)
188 struct bm_cache_list
*pItem
= pList
->head
;
192 if(pItem
->height
>= gHeight
)
195 pNew
->prev
= pItem
->prev
;
196 if(pItem
->prev
!= NULL
)
197 pItem
->prev
->next
= pNew
;
202 return_val
= pNew
->id
;
206 else if(pItem
->next
== NULL
)
211 return_val
= pNew
->id
;
227 struct bm_cache_head
*pNewList
;
229 pNewList
= (struct bm_cache_head
*)malloc(sizeof(struct bm_cache_head
));
231 pNewList
->next
= NULL
;
232 pNewList
->prev
= NULL
;
233 pNewList
->width
= gWidth
;
234 pNewList
->head
= pNew
;
239 return_val
= pNew
->id
;
247 if(pList
->width
> gWidth
)
249 pNewList
->next
= pList
;
250 pNewList
->prev
= pList
->prev
;
252 if(pList
->prev
!= NULL
)
253 pList
->prev
->next
= pNewList
;
256 pList
->prev
= pNewList
;
258 return_val
= pNew
->id
;
262 else if(pList
->next
== NULL
)
264 pNewList
->prev
= pList
;
265 pList
->next
= pNewList
;
267 return_val
= pNew
->id
;
282 PsBmClearImageCacheItem(
283 struct bm_cache_list
*pItem
)
287 if(pItem
->pBuffer
!= NULL
)
288 free(pItem
->pBuffer
);
289 pItem
->pBuffer
= NULL
;
292 PsBmClearImageCacheItem(pItem
->next
);
301 PsBmClearImageCacheList(
302 struct bm_cache_head
*pList
)
307 PsBmClearImageCacheItem(pList
->head
);
311 PsBmClearImageCacheList(pList
->next
);
320 PsBmClearImageCache(void)
322 PsBmClearImageCacheList(bm_cache
);