1 /* COPYRIGHT AND PERMISSION NOTICE
3 Copyright (c) 2000, 2001 Nokia Home Communications
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.
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
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 */
65 * Keith Whitwell <keith@tungstengraphics.com>
66 * Pontus Lidman <pontus.lidman@nokia.com>
71 #include <kdrive-config.h>
76 #include "cursorstr.h"
78 #define SetupCursor(s) KdScreenPriv(pScreen); \
79 i810CardInfo(pScreenPriv); \
80 i810ScreenInfo(pScreenPriv); \
81 i810Cursor *pCurPriv = &i810s->cursor
85 writeStandardMMIO(I810CardInfo
*i810c
, int addr
, CARD8 val
)
91 _i810MoveCursor(ScreenPtr pScreen
, int x
, int y
)
93 KdScreenPriv(pScreen
);
94 i810CardInfo(pScreenPriv
);
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
;
108 OUTREG8( CURSOR_X_LO
, x
&0xFF);
109 OUTREG8( CURSOR_X_HI
, (((x
>> 8) & 0x07) | flag
));
111 if (y
>= 0) flag
= CURSOR_Y_POS
;
116 OUTREG8( CURSOR_Y_LO
, y
&0xFF);
117 OUTREG8( CURSOR_Y_HI
, (((y
>> 8) & 0x07) | flag
));
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
);
128 i810MoveCursor (ScreenPtr pScreen
, int x
, int y
)
130 KdScreenPriv(pScreen
);
131 i810ScreenInfo(pScreenPriv
);
132 i810Cursor
*pCurPriv
= &i810s
->cursor
;
134 if (!pCurPriv
->has_cursor
)
137 if (!pScreenPriv
->enabled
)
140 _i810MoveCursor (pScreen
, x
, y
);
142 i810LoadCursor(pScreen
, x
, y
);
146 _i810SetCursorColors(ScreenPtr pScreen
)
149 KdScreenPriv(pScreen
);
150 i810CardInfo(pScreenPriv
);
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
);
187 unsigned int *msk
, *mskLine
, *src
, *srcLine
;
190 int src_stride
, src_width
;
192 CursorPtr pCursor
= pCurPriv
->pCursor
;
193 CursorBitsPtr bits
= pCursor
->bits
;
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
);
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
++) {
218 mskLine
+= src_stride
;
219 srcLine
+= src_stride
;
220 ramLine
+= I810_CURSOR_WIDTH
/ 16;
222 for (j
= 0; j
< I810_CURSOR_WIDTH
/ 32; j
++) {
226 if (i
< h
&& j
< src_width
)
231 /* mask off right side */
232 if (j
== src_width
- 1 && (bits
->width
& 31))
234 m
|= 0xffffffff << (bits
->width
& 31);
251 _i810SetCursorColors (pScreen
);
253 /* Move to new position */
254 _i810MoveCursor (pScreen
, x
, y
);
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
);
266 i810UnloadCursor(ScreenPtr pScreen
)
268 KdScreenPriv(pScreen
);
269 i810CardInfo(pScreenPriv
);
273 tmp
=INREG8( PIXPIPE_CONFIG_0
);
274 tmp
&= ~HW_CURSOR_ENABLE
;
275 OUTREG8( PIXPIPE_CONFIG_0
, tmp
);
280 i810RealizeCursor (ScreenPtr pScreen
, CursorPtr pCursor
)
282 KdScreenPriv(pScreen
);
283 i810ScreenInfo(pScreenPriv
);
284 i810Cursor
*pCurPriv
= &i810s
->cursor
;
286 if (!pScreenPriv
->enabled
)
289 /* miRecolorCursor does this */
290 if (pCurPriv
->pCursor
== pCursor
)
296 miPointerPosition (&x
, &y
);
297 i810LoadCursor (pScreen
, x
, y
);
304 i810UnrealizeCursor (ScreenPtr pScreen
, CursorPtr pCursor
)
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
)
322 i810LoadCursor (pScreen
, x
, y
);
324 i810UnloadCursor (pScreen
);
327 miPointerSpriteFuncRec i810PointerSpriteFuncs
= {
335 i810QueryBestSize (int class,
336 unsigned short *pwidth
, unsigned short *pheight
,
339 KdScreenPriv(pScreen
);
340 i810ScreenInfo(pScreenPriv
);
341 i810Cursor
*pCurPriv
= &i810s
->cursor
;
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
;
356 fbQueryBestSize (class, pwidth
, pheight
, pScreen
);
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
;
374 pCurPriv
->width
= I810_CURSOR_WIDTH
;
375 pCurPriv
->height
= I810_CURSOR_HEIGHT
;
376 pScreen
->QueryBestSize
= i810QueryBestSize
;
377 miPointerInitialize (pScreen
,
378 &i810PointerSpriteFuncs
,
379 &kdPointerScreenFuncs
,
381 pCurPriv
->has_cursor
= TRUE
;
382 pCurPriv
->pCursor
= NULL
;
387 i810CursorEnable (ScreenPtr pScreen
)
389 KdScreenPriv(pScreen
);
390 i810ScreenInfo(pScreenPriv
);
391 i810Cursor
*pCurPriv
= &i810s
->cursor
;
393 if (pCurPriv
->has_cursor
)
395 if (pCurPriv
->pCursor
)
399 miPointerPosition (&x
, &y
);
400 i810LoadCursor (pScreen
, x
, y
);
403 i810UnloadCursor (pScreen
);
408 i810CursorDisable (ScreenPtr pScreen
)
410 KdScreenPriv(pScreen
);
411 i810ScreenInfo(pScreenPriv
);
412 i810Cursor
*pCurPriv
= &i810s
->cursor
;
414 if (!pScreenPriv
->enabled
)
417 if (pCurPriv
->has_cursor
)
419 if (pCurPriv
->pCursor
)
421 i810UnloadCursor (pScreen
);
427 i810CursorFini (ScreenPtr pScreen
)
429 KdScreenPriv(pScreen
);
430 i810ScreenInfo(pScreenPriv
);
431 i810Cursor
*pCurPriv
= &i810s
->cursor
;
433 pCurPriv
->pCursor
= NULL
;