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
********************************************************************/
78
#include "windowstr.h"
85
struct bm_cache_list {
86
struct bm_cache_list *next;
87
struct bm_cache_list *prev;
93
struct bm_cache_head {
94
struct bm_cache_list *head;
96
struct bm_cache_head *next;
97
struct bm_cache_head *prev;
100
static struct bm_cache_head *bm_cache = NULL;
103
PsBmUniqueId(int func)
105
static long unique_id = 0;
123
struct bm_cache_head *pList = bm_cache;
125
while(pList != NULL && !return_val)
127
if(pList->width == gWidth)
129
struct bm_cache_list *pItem = pList->head;
133
if(pItem->height == gHeight)
135
int length = 4*(gWidth/32+(gWidth%32!=0))*gHeight;
137
if(!memcmp(pItem->pBuffer, pBuffer, sizeof(char)*length))
139
return_val = pItem->id;
143
else if(pItem->height > gHeight)
149
else if(pList->width > gWidth)
164
struct bm_cache_head *pList = bm_cache;
165
struct bm_cache_list *pNew;
166
int length = 4*(gWidth/32+(gWidth%32!=0))*gHeight;
168
if(gWidth == 1 && gHeight == 1 && pBuffer[0] == 0)
171
pNew = (struct bm_cache_list *)malloc(sizeof(struct bm_cache_list));
174
pNew->height = gHeight;
175
pNew->id = PsBmUniqueId(GET);
176
pNew->pBuffer = (char *)malloc(sizeof(char)*length);
178
memcpy(pNew->pBuffer, pBuffer, length);
182
if(pList->width == gWidth)
184
struct bm_cache_list *pItem = pList->head;
188
if(pItem->height >= gHeight)
191
pNew->prev = pItem->prev;
192
if(pItem->prev != NULL)
193
pItem->prev->next = pNew;
198
return_val = pNew->id;
202
else if(pItem->next == NULL)
207
return_val = pNew->id;
223
struct bm_cache_head *pNewList;
225
pNewList = (struct bm_cache_head *)malloc(sizeof(struct bm_cache_head));
227
pNewList->next = NULL;
228
pNewList->prev = NULL;
229
pNewList->width = gWidth;
230
pNewList->head = pNew;
235
return_val = pNew->id;
243
if(pList->width > gWidth)
245
pNewList->next = pList;
246
pNewList->prev = pList->prev;
248
if(pList->prev != NULL)
249
pList->prev->next = pNewList;
252
pList->prev = pNewList;
254
return_val = pNew->id;
258
else if(pList->next == NULL)
260
pNewList->prev = pList;
261
pList->next = pNewList;
263
return_val = pNew->id;
278
PsBmClearImageCacheItem(
279
struct bm_cache_list *pItem)
283
if(pItem->pBuffer != NULL)
284
free(pItem->pBuffer);
285
pItem->pBuffer = NULL;
288
PsBmClearImageCacheItem(pItem->next);
297
PsBmClearImageCacheList(
298
struct bm_cache_head *pList)
303
PsBmClearImageCacheItem(pList->head);
307
PsBmClearImageCacheList(pList->next);
316
PsBmClearImageCache()
318
PsBmClearImageCacheList(bm_cache);