Remove some unused cruft
[nouveau] / src / riva_cursor.c
1 /*
2  * Copyright 1996-1997  David J. McKay
3  *
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:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
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
20  * SOFTWARE.
21  */
22
23 /* Rewritten with reference from mga driver and 3.3.4 NVIDIA driver by
24    Jarno Paananen <jpaana@s2.org> */
25
26 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/riva_cursor.c $ */
27
28 #include "riva_include.h"
29
30 #include "cursorstr.h"
31
32 /****************************************************************************\
33 *                                                                            *
34 *                          HW Cursor Entrypoints                             *
35 *                                                                            *
36 \****************************************************************************/
37
38 #define TRANSPARENT_PIXEL   0
39
40 #define ConvertToRGB555(c) \
41 (((c & 0xf80000) >> 9 ) | ((c & 0xf800) >> 6 ) | ((c & 0xf8) >> 3 ) | 0x8000)
42
43
44 static void 
45 RivaConvertCursor1555(RivaPtr pRiva, CARD32 *src, CARD16 *dst)
46 {
47     CARD32 b, m;
48     int i, j;
49     
50     for ( i = 0; i < 32; i++ ) {
51         b = *src++;
52         m = *src++;
53         for ( j = 0; j < 32; j++ ) {
54             if ( m & 1 )
55                 *dst = ( b & 1) ? pRiva->curFg : pRiva->curBg;
56             else
57                 *dst = TRANSPARENT_PIXEL;
58             b >>= 1;
59             m >>= 1;
60             dst++;
61         }
62     }
63 }
64
65
66 static void
67 RivaTransformCursor (RivaPtr pRiva)
68 {
69     CARD32 *tmp;
70     int i, dwords;
71
72     dwords = (32 * 32) >> 1;
73     if(!(tmp = ALLOCATE_LOCAL(dwords * 4))) return;
74     RivaConvertCursor1555(pRiva, pRiva->curImage, (CARD16*)tmp);
75
76     for(i = 0; i < dwords; i++)
77         pRiva->riva.CURSOR[i] = tmp[i];
78
79     DEALLOCATE_LOCAL(tmp);
80 }
81
82 static void
83 RivaLoadCursorImage( ScrnInfoPtr pScrn, unsigned char *src )
84 {
85     RivaPtr pRiva = RivaPTR(pScrn);
86
87     /* save copy of image for color changes */
88     memcpy(pRiva->curImage, src, 256);
89
90     RivaTransformCursor(pRiva);
91 }
92
93 static void
94 RivaSetCursorPosition(ScrnInfoPtr pScrn, int x, int y)
95 {
96     RivaPtr pRiva = RivaPTR(pScrn);
97
98     pRiva->riva.PRAMDAC[0x0000300/4] = (x & 0xFFFF) | (y << 16);
99 }
100
101 static void
102 RivaSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg)
103 {
104     RivaPtr pRiva = RivaPTR(pScrn);
105     CARD32 fore, back;
106
107     fore = ConvertToRGB555(fg);
108     back = ConvertToRGB555(bg);
109
110     if ((pRiva->curFg != fore) || (pRiva->curBg != back)) {
111         pRiva->curFg = fore;
112         pRiva->curBg = back;
113             
114         RivaTransformCursor(pRiva);
115     }
116 }
117
118
119 static void 
120 RivaShowCursor(ScrnInfoPtr pScrn)
121 {
122     RivaPtr pRiva = RivaPTR(pScrn);
123     /* Enable cursor - X-Windows mode */
124     pRiva->riva.ShowHideCursor(&pRiva->riva, 1);
125 }
126
127 static void
128 RivaHideCursor(ScrnInfoPtr pScrn)
129 {
130     RivaPtr pRiva = RivaPTR(pScrn);
131     /* Disable cursor */
132     pRiva->riva.ShowHideCursor(&pRiva->riva, 0);
133 }
134
135 static Bool 
136 RivaUseHWCursor(ScreenPtr pScreen, CursorPtr pCurs)
137 {
138     return TRUE;
139 }
140
141
142 Bool 
143 RivaCursorInit(ScreenPtr pScreen)
144 {
145     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
146     RivaPtr pRiva = RivaPTR(pScrn);
147     xf86CursorInfoPtr infoPtr;
148
149     infoPtr = xf86CreateCursorInfoRec();
150     if(!infoPtr) return FALSE;
151     
152     pRiva->CursorInfoRec = infoPtr;
153
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;
163
164     return(xf86InitCursor(pScreen, infoPtr));
165 }