1
/* $XFree86: xc/programs/Xserver/dix/cursor.c,v 3.8 2003/01/12 02:44:26 dawes Exp $ */
2
/***********************************************************
4
Copyright 1987, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
Except as contained in this notice, the name of The Open Group shall not be
23
used in advertising or otherwise to promote the sale, use or other dealings
24
in this Software without prior written authorization from The Open Group.
27
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31
Permission to use, copy, modify, and distribute this software and its
32
documentation for any purpose and without fee is hereby granted,
33
provided that the above copyright notice appear in all copies and that
34
both that copyright notice and this permission notice appear in
35
supporting documentation, and that the name of Digital not be
36
used in advertising or publicity pertaining to distribution of the
37
software without specific, written prior permission.
39
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47
******************************************************************/
50
/* $Xorg: cursor.c,v 1.4 2001/02/09 02:04:39 xorgcvs Exp $ */
52
#ifdef HAVE_DIX_CONFIG_H
53
#include <dix-config.h>
59
#include "scrnintstr.h"
60
#include "dixstruct.h"
61
#include "cursorstr.h"
62
#include "dixfontstr.h"
65
typedef struct _GlyphShare {
67
unsigned short sourceChar;
68
unsigned short maskChar;
70
struct _GlyphShare *next;
71
} GlyphShare, *GlyphSharePtr;
73
static GlyphSharePtr sharedGlyphs = (GlyphSharePtr)NULL;
76
static CARD32 cursorSerial;
80
FreeCursorBits(CursorBitsPtr bits)
82
if (--bits->refcnt > 0)
89
if (bits->refcnt == 0)
91
register GlyphSharePtr *prev, this;
93
for (prev = &sharedGlyphs;
94
(this = *prev) && (this->bits != bits);
100
CloseFont(this->font, (Font)0);
108
* To be called indirectly by DeleteResource; must use exactly two args.
110
* \param value must conform to DeleteType
113
FreeCursor(pointer value, XID cid)
116
CursorPtr pCurs = (CursorPtr)value;
120
if ( --pCurs->refcnt > 0)
123
for (nscr = 0; nscr < screenInfo.numScreens; nscr++)
125
pscr = screenInfo.screens[nscr];
126
(void)( *pscr->UnrealizeCursor)( pscr, pCurs);
128
FreeCursorBits(pCurs->bits);
135
* We check for empty cursors so that we won't have to display them
138
CheckForEmptyMask(CursorBitsPtr bits)
140
register unsigned char *msk = bits->mask;
141
int n = BitmapBytePad(bits->width) * bits->height;
143
bits->emptyMask = FALSE;
145
if(*(msk++) != 0) return;
149
CARD32 *argb = bits->argb;
150
int n = bits->width * bits->height;
152
if (*argb++ & 0xff000000) return;
155
bits->emptyMask = TRUE;
159
* does nothing about the resource table, just creates the data structure.
160
* does not copy the src and mask bits
162
* \param psrcbits server-defined padding
163
* \param pmaskbits server-defined padding
164
* \param argb no padding
167
AllocCursorARGB(unsigned char *psrcbits, unsigned char *pmaskbits, CARD32 *argb,
169
unsigned foreRed, unsigned foreGreen, unsigned foreBlue,
170
unsigned backRed, unsigned backGreen, unsigned backBlue)
177
pCurs = (CursorPtr)xalloc(sizeof(CursorRec) + sizeof(CursorBits));
182
return (CursorPtr)NULL;
184
bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec));
185
bits->source = psrcbits;
186
bits->mask = pmaskbits;
190
bits->width = cm->width;
191
bits->height = cm->height;
192
bits->xhot = cm->xhot;
193
bits->yhot = cm->yhot;
195
CheckForEmptyMask(bits);
200
pCurs->serialNumber = ++cursorSerial;
204
pCurs->foreRed = foreRed;
205
pCurs->foreGreen = foreGreen;
206
pCurs->foreBlue = foreBlue;
208
pCurs->backRed = backRed;
209
pCurs->backGreen = backGreen;
210
pCurs->backBlue = backBlue;
213
* realize the cursor for every screen
215
for (nscr = 0; nscr < screenInfo.numScreens; nscr++)
217
pscr = screenInfo.screens[nscr];
218
if (!( *pscr->RealizeCursor)( pscr, pCurs))
222
pscr = screenInfo.screens[nscr];
223
( *pscr->UnrealizeCursor)( pscr, pCurs);
225
FreeCursorBits(bits);
227
return (CursorPtr)NULL;
235
* \param psrcbits server-defined padding
236
* \param pmaskbits server-defined padding
239
AllocCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
241
unsigned foreRed, unsigned foreGreen, unsigned foreBlue,
242
unsigned backRed, unsigned backGreen, unsigned backBlue)
244
return AllocCursorARGB (psrcbits, pmaskbits, (CARD32 *) 0, cm,
245
foreRed, foreGreen, foreBlue,
246
backRed, backGreen, backBlue);
250
AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
251
unsigned foreRed, unsigned foreGreen, unsigned foreBlue,
252
unsigned backRed, unsigned backGreen, unsigned backBlue,
253
CursorPtr *ppCurs, ClientPtr client)
255
FontPtr sourcefont, maskfont;
256
unsigned char *srcbits;
257
unsigned char *mskbits;
264
GlyphSharePtr pShare;
266
sourcefont = (FontPtr) SecurityLookupIDByType(client, source, RT_FONT,
268
maskfont = (FontPtr) SecurityLookupIDByType(client, mask, RT_FONT,
273
client->errorValue = source;
276
if (!maskfont && (mask != None))
278
client->errorValue = mask;
281
if (sourcefont != maskfont)
282
pShare = (GlyphSharePtr)NULL;
285
for (pShare = sharedGlyphs;
287
((pShare->font != sourcefont) ||
288
(pShare->sourceChar != sourceChar) ||
289
(pShare->maskChar != maskChar));
290
pShare = pShare->next)
295
pCurs = (CursorPtr)xalloc(sizeof(CursorRec));
303
if (!CursorMetricsFromGlyph(sourcefont, sourceChar, &cm))
305
client->errorValue = sourceChar;
311
register unsigned char *mskptr;
313
n = BitmapBytePad(cm.width)*(long)cm.height;
314
mskptr = mskbits = (unsigned char *)xalloc(n);
322
if (!CursorMetricsFromGlyph(maskfont, maskChar, &cm))
324
client->errorValue = maskChar;
327
if ((res = ServerBitsFromGlyph(maskfont, maskChar, &cm, &mskbits)) != 0)
330
if ((res = ServerBitsFromGlyph(sourcefont, sourceChar, &cm, &srcbits)) != 0)
335
if (sourcefont != maskfont)
337
pCurs = (CursorPtr)xalloc(sizeof(CursorRec) + sizeof(CursorBits));
339
bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec));
341
bits = (CursorBitsPtr)NULL;
345
pCurs = (CursorPtr)xalloc(sizeof(CursorRec));
347
bits = (CursorBitsPtr)xalloc(sizeof(CursorBits));
349
bits = (CursorBitsPtr)NULL;
358
bits->source = srcbits;
359
bits->mask = mskbits;
363
bits->width = cm.width;
364
bits->height = cm.height;
365
bits->xhot = cm.xhot;
366
bits->yhot = cm.yhot;
367
if (sourcefont != maskfont)
372
pShare = (GlyphSharePtr)xalloc(sizeof(GlyphShare));
375
FreeCursorBits(bits);
378
pShare->font = sourcefont;
379
sourcefont->refcnt++;
380
pShare->sourceChar = sourceChar;
381
pShare->maskChar = maskChar;
383
pShare->next = sharedGlyphs;
384
sharedGlyphs = pShare;
387
CheckForEmptyMask(bits);
391
pCurs->serialNumber = ++cursorSerial;
395
pCurs->foreRed = foreRed;
396
pCurs->foreGreen = foreGreen;
397
pCurs->foreBlue = foreBlue;
399
pCurs->backRed = backRed;
400
pCurs->backGreen = backGreen;
401
pCurs->backBlue = backBlue;
404
* realize the cursor for every screen
406
for (nscr = 0; nscr < screenInfo.numScreens; nscr++)
408
pscr = screenInfo.screens[nscr];
409
if (!( *pscr->RealizeCursor)( pscr, pCurs))
413
pscr = screenInfo.screens[nscr];
414
( *pscr->UnrealizeCursor)( pscr, pCurs);
416
FreeCursorBits(pCurs->bits);
427
* look up the name of a font
429
* add the font to the resource table
430
* make a cursor from the glyphs
431
* add the cursor to the resource table
432
*************************************************************/
435
CreateRootCursor(char *pfilename, unsigned glyph)
442
fontID = FakeClientID(0);
443
err = OpenFont(serverClient, fontID, FontLoadAll | FontOpenSync,
444
(unsigned)strlen( pfilename), pfilename);
448
cursorfont = (FontPtr)LookupIDByType(fontID, RT_FONT);
451
if (AllocGlyphCursor(fontID, glyph, fontID, glyph + 1,
452
0, 0, 0, ~0, ~0, ~0, &curs, serverClient) != Success)
455
if (!AddResource(FakeClientID(0), RT_CURSOR, (pointer)curs))