1 /***********************************************************
3 Copyright 1987, 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.
25 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Digital not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
37 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 ******************************************************************/
47 #ifdef HAVE_DIX_CONFIG_H
48 #include <dix-config.h>
54 #include "scrnintstr.h"
55 #include "dixstruct.h"
56 #include "cursorstr.h"
57 #include "dixfontstr.h"
62 typedef struct _GlyphShare
{
64 unsigned short sourceChar
;
65 unsigned short maskChar
;
67 struct _GlyphShare
*next
;
68 } GlyphShare
, *GlyphSharePtr
;
70 static GlyphSharePtr sharedGlyphs
= (GlyphSharePtr
) NULL
;
72 DevScreenPrivateKeyRec cursorScreenDevPriv
;
74 static CARD32 cursorSerial
;
77 FreeCursorBits(CursorBitsPtr bits
)
79 if (--bits
->refcnt
> 0)
86 dixFiniPrivates(bits
, PRIVATE_CURSOR_BITS
);
87 if (bits
->refcnt
== 0) {
88 GlyphSharePtr
*prev
, this;
90 for (prev
= &sharedGlyphs
;
91 (this = *prev
) && (this->bits
!= bits
); prev
= &this->next
);
94 CloseFont(this->font
, (Font
) 0);
102 * To be called indirectly by DeleteResource; must use exactly two args.
104 * \param value must conform to DeleteType
107 FreeCursor(pointer value
, XID cid
)
110 CursorPtr pCurs
= (CursorPtr
) value
;
113 DeviceIntPtr pDev
= NULL
; /* unused anyway */
117 if (CursorRefCount(pCurs
) != 0)
120 BUG_WARN(CursorRefCount(pCurs
) < 0);
122 for (nscr
= 0; nscr
< screenInfo
.numScreens
; nscr
++) {
123 pscr
= screenInfo
.screens
[nscr
];
124 (void) (*pscr
->UnrealizeCursor
) (pDev
, pscr
, pCurs
);
126 FreeCursorBits(pCurs
->bits
);
127 dixFiniPrivates(pCurs
, PRIVATE_CURSOR
);
133 RefCursor(CursorPtr cursor
)
141 UnrefCursor(CursorPtr cursor
)
149 CursorRefCount(const CursorPtr cursor
)
151 return cursor
? cursor
->refcnt
: 0;
156 * We check for empty cursors so that we won't have to display them
159 CheckForEmptyMask(CursorBitsPtr bits
)
161 unsigned char *msk
= bits
->mask
;
162 int n
= BitmapBytePad(bits
->width
) * bits
->height
;
164 bits
->emptyMask
= FALSE
;
170 CARD32
*argb
= bits
->argb
;
172 n
= bits
->width
* bits
->height
;
174 if (*argb
++ & 0xff000000)
178 bits
->emptyMask
= TRUE
;
182 * realize the cursor for every screen. Do not change the refcnt, this will be
183 * changed when ChangeToCursor actually changes the sprite.
185 * @return Success if all cursors realize on all screens, BadAlloc if realize
186 * failed for a device on a given screen.
189 RealizeCursorAllScreens(CursorPtr pCurs
)
195 for (nscr
= 0; nscr
< screenInfo
.numScreens
; nscr
++) {
196 pscr
= screenInfo
.screens
[nscr
];
197 for (pDev
= inputInfo
.devices
; pDev
; pDev
= pDev
->next
) {
198 if (DevHasCursor(pDev
)) {
199 if (!(*pscr
->RealizeCursor
) (pDev
, pscr
, pCurs
)) {
200 /* Realize failed for device pDev on screen pscr.
201 * We have to assume that for all devices before, realize
202 * worked. We need to rollback all devices so far on the
203 * current screen and then all devices on previous
206 DeviceIntPtr pDevIt
= inputInfo
.devices
; /*dev iterator */
208 while (pDevIt
&& pDevIt
!= pDev
) {
209 if (DevHasCursor(pDevIt
))
210 (*pscr
->UnrealizeCursor
) (pDevIt
, pscr
, pCurs
);
211 pDevIt
= pDevIt
->next
;
213 while (--nscr
>= 0) {
214 pscr
= screenInfo
.screens
[nscr
];
215 /* now unrealize all devices on previous screens */
216 pDevIt
= inputInfo
.devices
;
218 if (DevHasCursor(pDevIt
))
219 (*pscr
->UnrealizeCursor
) (pDevIt
, pscr
, pCurs
);
220 pDevIt
= pDevIt
->next
;
222 (*pscr
->UnrealizeCursor
) (pDev
, pscr
, pCurs
);
234 * does nothing about the resource table, just creates the data structure.
235 * does not copy the src and mask bits
237 * \param psrcbits server-defined padding
238 * \param pmaskbits server-defined padding
239 * \param argb no padding
242 AllocARGBCursor(unsigned char *psrcbits
, unsigned char *pmaskbits
,
243 CARD32
*argb
, CursorMetricPtr cm
,
244 unsigned foreRed
, unsigned foreGreen
, unsigned foreBlue
,
245 unsigned backRed
, unsigned backGreen
, unsigned backBlue
,
246 CursorPtr
*ppCurs
, ClientPtr client
, XID cid
)
253 pCurs
= (CursorPtr
) calloc(CURSOR_REC_SIZE
+ CURSOR_BITS_SIZE
, 1);
257 bits
= (CursorBitsPtr
) ((char *) pCurs
+ CURSOR_REC_SIZE
);
258 dixInitPrivates(pCurs
, pCurs
+ 1, PRIVATE_CURSOR
);
259 dixInitPrivates(bits
, bits
+ 1, PRIVATE_CURSOR_BITS
)
260 bits
->source
= psrcbits
;
261 bits
->mask
= pmaskbits
;
265 bits
->width
= cm
->width
;
266 bits
->height
= cm
->height
;
267 bits
->xhot
= cm
->xhot
;
268 bits
->yhot
= cm
->yhot
;
271 CheckForEmptyMask(bits
);
273 pCurs
->serialNumber
= ++cursorSerial
;
276 pCurs
->foreRed
= foreRed
;
277 pCurs
->foreGreen
= foreGreen
;
278 pCurs
->foreBlue
= foreBlue
;
280 pCurs
->backRed
= backRed
;
281 pCurs
->backGreen
= backGreen
;
282 pCurs
->backBlue
= backBlue
;
286 /* security creation/labeling check */
287 rc
= XaceHook(XACE_RESOURCE_ACCESS
, client
, cid
, RT_CURSOR
,
288 pCurs
, RT_NONE
, NULL
, DixCreateAccess
);
292 rc
= RealizeCursorAllScreens(pCurs
);
300 FreeCursorBits(bits
);
301 dixFiniPrivates(pCurs
, PRIVATE_CURSOR
);
308 AllocGlyphCursor(Font source
, unsigned sourceChar
, Font mask
, unsigned maskChar
,
309 unsigned foreRed
, unsigned foreGreen
, unsigned foreBlue
,
310 unsigned backRed
, unsigned backGreen
, unsigned backBlue
,
311 CursorPtr
*ppCurs
, ClientPtr client
, XID cid
)
313 FontPtr sourcefont
, maskfont
;
314 unsigned char *srcbits
;
315 unsigned char *mskbits
;
320 GlyphSharePtr pShare
;
322 rc
= dixLookupResourceByType((pointer
*) &sourcefont
, source
, RT_FONT
,
323 client
, DixUseAccess
);
325 client
->errorValue
= source
;
328 rc
= dixLookupResourceByType((pointer
*) &maskfont
, mask
, RT_FONT
, client
,
330 if (rc
!= Success
&& mask
!= None
) {
331 client
->errorValue
= mask
;
334 if (sourcefont
!= maskfont
)
335 pShare
= (GlyphSharePtr
) NULL
;
337 for (pShare
= sharedGlyphs
;
339 ((pShare
->font
!= sourcefont
) ||
340 (pShare
->sourceChar
!= sourceChar
) ||
341 (pShare
->maskChar
!= maskChar
)); pShare
= pShare
->next
);
344 pCurs
= (CursorPtr
) calloc(CURSOR_REC_SIZE
, 1);
347 dixInitPrivates(pCurs
, pCurs
+ 1, PRIVATE_CURSOR
);
352 if (!CursorMetricsFromGlyph(sourcefont
, sourceChar
, &cm
)) {
353 client
->errorValue
= sourceChar
;
358 unsigned char *mskptr
;
360 n
= BitmapBytePad(cm
.width
) * (long) cm
.height
;
361 mskptr
= mskbits
= malloc(n
);
368 if (!CursorMetricsFromGlyph(maskfont
, maskChar
, &cm
)) {
369 client
->errorValue
= maskChar
;
372 if ((rc
= ServerBitsFromGlyph(maskfont
, maskChar
, &cm
, &mskbits
)))
375 if ((rc
= ServerBitsFromGlyph(sourcefont
, sourceChar
, &cm
, &srcbits
))) {
379 if (sourcefont
!= maskfont
) {
380 pCurs
= (CursorPtr
) calloc(CURSOR_REC_SIZE
+ CURSOR_BITS_SIZE
, 1);
382 bits
= (CursorBitsPtr
) ((char *) pCurs
+ CURSOR_REC_SIZE
);
384 bits
= (CursorBitsPtr
) NULL
;
387 pCurs
= (CursorPtr
) calloc(CURSOR_REC_SIZE
, 1);
389 bits
= (CursorBitsPtr
) calloc(CURSOR_BITS_SIZE
, 1);
391 bits
= (CursorBitsPtr
) NULL
;
399 dixInitPrivates(pCurs
, pCurs
+ 1, PRIVATE_CURSOR
);
400 dixInitPrivates(bits
, bits
+ 1, PRIVATE_CURSOR_BITS
);
401 bits
->source
= srcbits
;
402 bits
->mask
= mskbits
;
406 bits
->width
= cm
.width
;
407 bits
->height
= cm
.height
;
408 bits
->xhot
= cm
.xhot
;
409 bits
->yhot
= cm
.yhot
;
410 if (sourcefont
!= maskfont
)
414 pShare
= malloc(sizeof(GlyphShare
));
416 FreeCursorBits(bits
);
419 pShare
->font
= sourcefont
;
420 sourcefont
->refcnt
++;
421 pShare
->sourceChar
= sourceChar
;
422 pShare
->maskChar
= maskChar
;
424 pShare
->next
= sharedGlyphs
;
425 sharedGlyphs
= pShare
;
429 CheckForEmptyMask(bits
);
432 pCurs
->serialNumber
= ++cursorSerial
;
435 pCurs
->foreRed
= foreRed
;
436 pCurs
->foreGreen
= foreGreen
;
437 pCurs
->foreBlue
= foreBlue
;
439 pCurs
->backRed
= backRed
;
440 pCurs
->backGreen
= backGreen
;
441 pCurs
->backBlue
= backBlue
;
445 /* security creation/labeling check */
446 rc
= XaceHook(XACE_RESOURCE_ACCESS
, client
, cid
, RT_CURSOR
,
447 pCurs
, RT_NONE
, NULL
, DixCreateAccess
);
451 rc
= RealizeCursorAllScreens(pCurs
);
459 FreeCursorBits(bits
);
460 dixFiniPrivates(pCurs
, PRIVATE_CURSOR
);
468 * look up the name of a font
470 * add the font to the resource table
471 * make a cursor from the glyphs
472 * add the cursor to the resource table
473 *************************************************************/
476 CreateRootCursor(char *unused1
, unsigned int unused2
)
483 fontID
= FakeClientID(0);
484 err
= OpenFont(serverClient
, fontID
, FontLoadAll
| FontOpenSync
,
485 (unsigned) strlen(defaultCursorFont
), defaultCursorFont
);
489 err
= dixLookupResourceByType((pointer
*) &cursorfont
, fontID
, RT_FONT
,
490 serverClient
, DixReadAccess
);
493 if (AllocGlyphCursor(fontID
, 0, fontID
, 1, 0, 0, 0, ~0, ~0, ~0,
494 &curs
, serverClient
, (XID
) 0) != Success
)
497 if (!AddResource(FakeClientID(0), RT_CURSOR
, (pointer
) curs
))