First import
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / i810 / i810_cursor.c
blob434fc40870e3e9a91eb73c90ffd9a2814ec106ff
1 /* COPYRIGHT AND PERMISSION NOTICE
3 Copyright (c) 2000, 2001 Nokia Home Communications
5 All rights reserved.
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, and/or sell copies of the Software, and to permit persons
12 to whom the Software is furnished to do so, provided that the above
13 copyright notice(s) and this permission notice appear in all copies of
14 the Software and that both the above copyright notice(s) and this
15 permission notice appear in supporting documentation.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
20 OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21 HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
22 SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
23 RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
24 CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
25 CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27 Except as contained in this notice, the name of a copyright holder
28 shall not be used in advertising or otherwise to promote the sale, use
29 or other dealings in this Software without prior written authorization
30 of the copyright holder.
32 X Window System is a trademark of The Open Group */
34 /**************************************************************************
36 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
37 All Rights Reserved.
39 Permission is hereby granted, free of charge, to any person obtaining a
40 copy of this software and associated documentation files (the
41 "Software"), to deal in the Software without restriction, including
42 without limitation the rights to use, copy, modify, merge, publish,
43 distribute, sub license, and/or sell copies of the Software, and to
44 permit persons to whom the Software is furnished to do so, subject to
45 the following conditions:
47 The above copyright notice and this permission notice (including the
48 next paragraph) shall be included in all copies or substantial portions
49 of the Software.
51 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
52 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
53 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
54 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
55 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
56 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
57 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
59 **************************************************************************/
61 /* i810_cursor.c: KDrive hardware cursor routines for the i810 chipset */
64 * Authors:
65 * Keith Whitwell <keith@tungstengraphics.com>
66 * Pontus Lidman <pontus.lidman@nokia.com>
70 #ifdef HAVE_CONFIG_H
71 #include <kdrive-config.h>
72 #endif
73 #include "kdrive.h"
74 #include "kxv.h"
75 #include "i810.h"
76 #include "cursorstr.h"
78 #define SetupCursor(s) KdScreenPriv(pScreen); \
79 i810CardInfo(pScreenPriv); \
80 i810ScreenInfo(pScreenPriv); \
81 i810Cursor *pCurPriv = &i810s->cursor
84 static void
85 writeStandardMMIO(I810CardInfo *i810c, int addr, CARD8 val)
87 moutb(addr, val);
90 static void
91 _i810MoveCursor(ScreenPtr pScreen, int x, int y)
93 KdScreenPriv(pScreen);
94 i810CardInfo(pScreenPriv);
95 int flag;
97 if (I810_DEBUG & DEBUG_VERBOSE_CURSOR)
98 ErrorF( "I810SetCursorPosition %d %d\n", x, y);
100 x += i810c->CursorOffset;
102 if (x >= 0) flag = CURSOR_X_POS;
103 else {
104 flag = CURSOR_X_NEG;
105 x=-x;
108 OUTREG8( CURSOR_X_LO, x&0xFF);
109 OUTREG8( CURSOR_X_HI, (((x >> 8) & 0x07) | flag));
111 if (y >= 0) flag = CURSOR_Y_POS;
112 else {
113 flag = CURSOR_Y_NEG;
114 y=-y;
116 OUTREG8( CURSOR_Y_LO, y&0xFF);
117 OUTREG8( CURSOR_Y_HI, (((y >> 8) & 0x07) | flag));
119 /* Enable cursor */
120 OUTREG( CURSOR_BASEADDR, i810c->CursorPhysical);
121 OUTREG8( CURSOR_CONTROL, CURSOR_ORIGIN_DISPLAY | CURSOR_MODE_64_3C);
125 static void i810LoadCursor(ScreenPtr pScreen, int x, int y);
127 static void
128 i810MoveCursor (ScreenPtr pScreen, int x, int y)
130 KdScreenPriv(pScreen);
131 i810ScreenInfo(pScreenPriv);
132 i810Cursor *pCurPriv = &i810s->cursor;
134 if (!pCurPriv->has_cursor)
135 return;
137 if (!pScreenPriv->enabled)
138 return;
140 _i810MoveCursor (pScreen, x, y);
142 i810LoadCursor(pScreen, x, y);
145 static void
146 _i810SetCursorColors(ScreenPtr pScreen)
149 KdScreenPriv(pScreen);
150 i810CardInfo(pScreenPriv);
151 int tmp;
153 int bg = 0xffffff;
154 int fg = 0x000000;
156 tmp=INREG8(PIXPIPE_CONFIG_0);
157 tmp |= EXTENDED_PALETTE;
158 OUTREG8( PIXPIPE_CONFIG_0, tmp);
160 writeStandardMMIO(i810c, DACMASK, 0xFF);
161 writeStandardMMIO(i810c, DACWX, 0x04);
163 writeStandardMMIO(i810c, DACDATA, (bg & 0x00FF0000) >> 16);
164 writeStandardMMIO(i810c, DACDATA, (bg & 0x0000FF00) >> 8);
165 writeStandardMMIO(i810c, DACDATA, (bg & 0x000000FF));
167 writeStandardMMIO(i810c, DACDATA, (fg & 0x00FF0000) >> 16);
168 writeStandardMMIO(i810c, DACDATA, (fg & 0x0000FF00) >> 8);
169 writeStandardMMIO(i810c, DACDATA, (fg & 0x000000FF));
171 tmp=INREG8( PIXPIPE_CONFIG_0 );
172 tmp &= ~EXTENDED_PALETTE;
173 OUTREG8( PIXPIPE_CONFIG_0, tmp );
176 #define InvertBits32(v) { \
177 v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555); \
178 v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333); \
179 v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f); \
182 static void i810LoadCursor(ScreenPtr pScreen, int x, int y)
184 SetupCursor(pScreen);
186 int h;
187 unsigned int *msk, *mskLine, *src, *srcLine;
189 int i, j;
190 int src_stride, src_width;
192 CursorPtr pCursor = pCurPriv->pCursor;
193 CursorBitsPtr bits = pCursor->bits;
194 CARD8 tmp;
195 unsigned int *ram, *ramLine;
197 pCurPriv->pCursor = pCursor;
198 pCurPriv->xhot = pCursor->bits->xhot;
199 pCurPriv->yhot = pCursor->bits->yhot;
201 ramLine = (unsigned int *) (i810c->FbBase + i810c->CursorStart);
202 mskLine = (unsigned int *) (bits->mask);
203 srcLine = (unsigned int *) (bits->source);
205 h = bits->height;
206 if (h > I810_CURSOR_HEIGHT)
207 h = I810_CURSOR_HEIGHT;
209 src_stride = BitmapBytePad(bits->width); /* bytes per line */
210 src_stride = (src_stride +3) >> 2;
211 src_width = (bits->width + 31) >> 5;
213 for (i = 0; i < I810_CURSOR_HEIGHT; i++) {
215 msk = mskLine;
216 src = srcLine;
217 ram = ramLine;
218 mskLine += src_stride;
219 srcLine += src_stride;
220 ramLine += I810_CURSOR_WIDTH / 16;
222 for (j = 0; j < I810_CURSOR_WIDTH / 32; j++) {
224 unsigned long m, s;
226 if (i < h && j < src_width)
228 m = *msk++;
229 s = *src++ & m;
230 m = ~m;
231 /* mask off right side */
232 if (j == src_width - 1 && (bits->width & 31))
234 m |= 0xffffffff << (bits->width & 31);
237 else
239 m = 0xffffffff;
240 s = 0x00000000;
243 InvertBits32(s);
244 InvertBits32(m);
246 ram[2+j]=s;
247 ram[0+j]=m;
250 /* Set new color */
251 _i810SetCursorColors (pScreen);
253 /* Move to new position */
254 _i810MoveCursor (pScreen, x, y);
256 /* Enable cursor */
257 OUTREG( CURSOR_BASEADDR, i810c->CursorPhysical);
258 OUTREG8( CURSOR_CONTROL, CURSOR_ORIGIN_DISPLAY | CURSOR_MODE_64_3C);
260 tmp = INREG8( PIXPIPE_CONFIG_0 );
261 tmp |= HW_CURSOR_ENABLE;
262 OUTREG8( PIXPIPE_CONFIG_0, tmp);
265 static void
266 i810UnloadCursor(ScreenPtr pScreen)
268 KdScreenPriv(pScreen);
269 i810CardInfo(pScreenPriv);
271 unsigned char tmp;
273 tmp=INREG8( PIXPIPE_CONFIG_0 );
274 tmp &= ~HW_CURSOR_ENABLE;
275 OUTREG8( PIXPIPE_CONFIG_0, tmp);
279 static Bool
280 i810RealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
282 KdScreenPriv(pScreen);
283 i810ScreenInfo(pScreenPriv);
284 i810Cursor *pCurPriv = &i810s->cursor;
286 if (!pScreenPriv->enabled)
287 return TRUE;
289 /* miRecolorCursor does this */
290 if (pCurPriv->pCursor == pCursor)
292 if (pCursor)
294 int x, y;
296 miPointerPosition (&x, &y);
297 i810LoadCursor (pScreen, x, y);
300 return TRUE;
303 static Bool
304 i810UnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
306 return TRUE;
309 static void
310 i810SetCursor (ScreenPtr pScreen, CursorPtr pCursor, int x, int y)
312 KdScreenPriv(pScreen);
313 i810ScreenInfo(pScreenPriv);
314 i810Cursor *pCurPriv = &i810s->cursor;
316 pCurPriv->pCursor = pCursor;
318 if (!pScreenPriv->enabled)
319 return;
321 if (pCursor)
322 i810LoadCursor (pScreen, x, y);
323 else
324 i810UnloadCursor (pScreen);
327 miPointerSpriteFuncRec i810PointerSpriteFuncs = {
328 i810RealizeCursor,
329 i810UnrealizeCursor,
330 i810SetCursor,
331 i810MoveCursor,
334 static void
335 i810QueryBestSize (int class,
336 unsigned short *pwidth, unsigned short *pheight,
337 ScreenPtr pScreen)
339 KdScreenPriv(pScreen);
340 i810ScreenInfo(pScreenPriv);
341 i810Cursor *pCurPriv = &i810s->cursor;
343 switch (class)
345 case CursorShape:
346 if (*pwidth > pCurPriv->width)
347 *pwidth = pCurPriv->width;
348 if (*pheight > pCurPriv->height)
349 *pheight = pCurPriv->height;
350 if (*pwidth > pScreen->width)
351 *pwidth = pScreen->width;
352 if (*pheight > pScreen->height)
353 *pheight = pScreen->height;
354 break;
355 default:
356 fbQueryBestSize (class, pwidth, pheight, pScreen);
357 break;
361 Bool
362 i810CursorInit(ScreenPtr pScreen)
364 KdScreenPriv(pScreen);
365 i810ScreenInfo(pScreenPriv);
366 i810CardInfo(pScreenPriv);
367 i810Cursor *pCurPriv = &i810s->cursor;
369 if (!i810c->CursorStart) {
370 pCurPriv->has_cursor = FALSE;
371 return FALSE;
374 pCurPriv->width = I810_CURSOR_WIDTH;
375 pCurPriv->height= I810_CURSOR_HEIGHT;
376 pScreen->QueryBestSize = i810QueryBestSize;
377 miPointerInitialize (pScreen,
378 &i810PointerSpriteFuncs,
379 &kdPointerScreenFuncs,
380 FALSE);
381 pCurPriv->has_cursor = TRUE;
382 pCurPriv->pCursor = NULL;
383 return TRUE;
386 void
387 i810CursorEnable (ScreenPtr pScreen)
389 KdScreenPriv(pScreen);
390 i810ScreenInfo(pScreenPriv);
391 i810Cursor *pCurPriv = &i810s->cursor;
393 if (pCurPriv->has_cursor)
395 if (pCurPriv->pCursor)
397 int x, y;
399 miPointerPosition (&x, &y);
400 i810LoadCursor (pScreen, x, y);
402 else
403 i810UnloadCursor (pScreen);
407 void
408 i810CursorDisable (ScreenPtr pScreen)
410 KdScreenPriv(pScreen);
411 i810ScreenInfo(pScreenPriv);
412 i810Cursor *pCurPriv = &i810s->cursor;
414 if (!pScreenPriv->enabled)
415 return;
417 if (pCurPriv->has_cursor)
419 if (pCurPriv->pCursor)
421 i810UnloadCursor (pScreen);
426 void
427 i810CursorFini (ScreenPtr pScreen)
429 KdScreenPriv(pScreen);
430 i810ScreenInfo(pScreenPriv);
431 i810Cursor *pCurPriv = &i810s->cursor;
433 pCurPriv->pCursor = NULL;