2 * Copyright 1996-1997 David J. McKay
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
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
17 * DAVID J. MCKAY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 /* Rewritten with reference from mga driver and 3.3.4 NVIDIA driver by
24 Jarno Paananen <jpaana@s2.org> */
26 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/riva_cursor.c $ */
28 #include "riva_include.h"
30 #include "cursorstr.h"
32 /****************************************************************************\
34 * HW Cursor Entrypoints *
36 \****************************************************************************/
38 #define TRANSPARENT_PIXEL 0
40 #define ConvertToRGB555(c) \
41 (((c & 0xf80000) >> 9 ) | ((c & 0xf800) >> 6 ) | ((c & 0xf8) >> 3 ) | 0x8000)
45 RivaConvertCursor1555(RivaPtr pRiva, CARD32 *src, CARD16 *dst)
50 for ( i = 0; i < 32; i++ ) {
53 for ( j = 0; j < 32; j++ ) {
55 *dst = ( b & 1) ? pRiva->curFg : pRiva->curBg;
57 *dst = TRANSPARENT_PIXEL;
67 RivaTransformCursor (RivaPtr pRiva)
72 dwords = (32 * 32) >> 1;
73 if(!(tmp = ALLOCATE_LOCAL(dwords * 4))) return;
74 RivaConvertCursor1555(pRiva, pRiva->curImage, (CARD16*)tmp);
76 for(i = 0; i < dwords; i++)
77 pRiva->riva.CURSOR[i] = tmp[i];
79 DEALLOCATE_LOCAL(tmp);
83 RivaLoadCursorImage( ScrnInfoPtr pScrn, unsigned char *src )
85 RivaPtr pRiva = RivaPTR(pScrn);
87 /* save copy of image for color changes */
88 memcpy(pRiva->curImage, src, 256);
90 RivaTransformCursor(pRiva);
94 RivaSetCursorPosition(ScrnInfoPtr pScrn, int x, int y)
96 RivaPtr pRiva = RivaPTR(pScrn);
98 pRiva->riva.PRAMDAC[0x0000300/4] = (x & 0xFFFF) | (y << 16);
102 RivaSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg)
104 RivaPtr pRiva = RivaPTR(pScrn);
107 fore = ConvertToRGB555(fg);
108 back = ConvertToRGB555(bg);
110 if ((pRiva->curFg != fore) || (pRiva->curBg != back)) {
114 RivaTransformCursor(pRiva);
120 RivaShowCursor(ScrnInfoPtr pScrn)
122 RivaPtr pRiva = RivaPTR(pScrn);
123 /* Enable cursor - X-Windows mode */
124 pRiva->riva.ShowHideCursor(&pRiva->riva, 1);
128 RivaHideCursor(ScrnInfoPtr pScrn)
130 RivaPtr pRiva = RivaPTR(pScrn);
132 pRiva->riva.ShowHideCursor(&pRiva->riva, 0);
136 RivaUseHWCursor(ScreenPtr pScreen, CursorPtr pCurs)
143 RivaCursorInit(ScreenPtr pScreen)
145 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
146 RivaPtr pRiva = RivaPTR(pScrn);
147 xf86CursorInfoPtr infoPtr;
149 infoPtr = xf86CreateCursorInfoRec();
150 if(!infoPtr) return FALSE;
152 pRiva->CursorInfoRec = infoPtr;
154 infoPtr->MaxWidth = infoPtr->MaxHeight = 32;
155 infoPtr->Flags = HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
156 HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32;
157 infoPtr->SetCursorColors = RivaSetCursorColors;
158 infoPtr->SetCursorPosition = RivaSetCursorPosition;
159 infoPtr->LoadCursorImage = RivaLoadCursorImage;
160 infoPtr->HideCursor = RivaHideCursor;
161 infoPtr->ShowCursor = RivaShowCursor;
162 infoPtr->UseHWCursor = RivaUseHWCursor;
164 return(xf86InitCursor(pScreen, infoPtr));