ffb_cursor.c revision e96acad6
1dbbd9e4bSmacallan/*
2dbbd9e4bSmacallan * Hardware cursor support for Creator, Creator 3D and Elite 3D
3dbbd9e4bSmacallan *
4dbbd9e4bSmacallan * Copyright 2000 by Jakub Jelinek <jakub@redhat.com>.
5dbbd9e4bSmacallan *
6dbbd9e4bSmacallan * Permission to use, copy, modify, distribute, and sell this software
7dbbd9e4bSmacallan * and its documentation for any purpose is hereby granted without
8dbbd9e4bSmacallan * fee, provided that the above copyright notice appear in all copies
9dbbd9e4bSmacallan * and that both that copyright notice and this permission notice
10dbbd9e4bSmacallan * appear in supporting documentation, and that the name of Jakub
11dbbd9e4bSmacallan * Jelinek not be used in advertising or publicity pertaining to
12dbbd9e4bSmacallan * distribution of the software without specific, written prior
13dbbd9e4bSmacallan * permission.  Jakub Jelinek makes no representations about the
14dbbd9e4bSmacallan * suitability of this software for any purpose.  It is provided "as
15dbbd9e4bSmacallan * is" without express or implied warranty.
16dbbd9e4bSmacallan *
17dbbd9e4bSmacallan * JAKUB JELINEK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
18dbbd9e4bSmacallan * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19dbbd9e4bSmacallan * FITNESS, IN NO EVENT SHALL JAKUB JELINEK BE LIABLE FOR ANY
20dbbd9e4bSmacallan * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21dbbd9e4bSmacallan * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
22dbbd9e4bSmacallan * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
23dbbd9e4bSmacallan * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24dbbd9e4bSmacallan * SOFTWARE.
25dbbd9e4bSmacallan */
26dbbd9e4bSmacallan
27dbbd9e4bSmacallan#ifdef HAVE_CONFIG_H
28dbbd9e4bSmacallan#include "config.h"
29dbbd9e4bSmacallan#endif
30dbbd9e4bSmacallan
31dbbd9e4bSmacallan#include "ffb.h"
32dbbd9e4bSmacallan
33dbbd9e4bSmacallan/* This file just performs cursor software state management.  The
34dbbd9e4bSmacallan * actual programming is done by calls into the DAC layer.
35dbbd9e4bSmacallan */
36dbbd9e4bSmacallan
37dbbd9e4bSmacallanstatic void FFBLoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src);
38dbbd9e4bSmacallanstatic void FFBShowCursor(ScrnInfoPtr pScrn);
39dbbd9e4bSmacallanstatic void FFBHideCursor(ScrnInfoPtr pScrn);
40dbbd9e4bSmacallanstatic void FFBSetCursorPosition(ScrnInfoPtr pScrn, int x, int y);
41dbbd9e4bSmacallanstatic void FFBSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg);
42dbbd9e4bSmacallan
43dbbd9e4bSmacallanstatic void
44dbbd9e4bSmacallanFFBLoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src)
45dbbd9e4bSmacallan{
46dbbd9e4bSmacallan    FFBPtr pFfb = GET_FFB_FROM_SCRN(pScrn);
47dbbd9e4bSmacallan    unsigned int *data = (unsigned int *)src;
48dbbd9e4bSmacallan    int x, y;
49dbbd9e4bSmacallan
50dbbd9e4bSmacallan    pFfb->CursorData = src;
51dbbd9e4bSmacallan    x = pFfb->CursorShiftX;
52dbbd9e4bSmacallan    y = pFfb->CursorShiftY;
53dbbd9e4bSmacallan    if (x >= 64 || y >= 64)
54dbbd9e4bSmacallan	y = 64;
55dbbd9e4bSmacallan    FFBDacCursorLoadBitmap(pFfb, x, y, data);
56dbbd9e4bSmacallan}
57dbbd9e4bSmacallan
58dbbd9e4bSmacallanstatic void
59dbbd9e4bSmacallanFFBShowCursor(ScrnInfoPtr pScrn)
60dbbd9e4bSmacallan{
61dbbd9e4bSmacallan    FFBPtr pFfb = GET_FFB_FROM_SCRN(pScrn);
62dbbd9e4bSmacallan
63dbbd9e4bSmacallan    FFBDacCursorEnableDisable(pFfb, 1);
64dbbd9e4bSmacallan}
65dbbd9e4bSmacallan
66dbbd9e4bSmacallanstatic void
67dbbd9e4bSmacallanFFBHideCursor(ScrnInfoPtr pScrn)
68dbbd9e4bSmacallan{
69dbbd9e4bSmacallan    FFBPtr pFfb = GET_FFB_FROM_SCRN(pScrn);
70dbbd9e4bSmacallan
71dbbd9e4bSmacallan    FFBDacCursorEnableDisable(pFfb, 0);
72dbbd9e4bSmacallan    pFfb->CursorData = NULL;
73dbbd9e4bSmacallan}
74dbbd9e4bSmacallan
75dbbd9e4bSmacallanstatic void
76dbbd9e4bSmacallanFFBSetCursorPosition(ScrnInfoPtr pScrn, int x, int y)
77dbbd9e4bSmacallan{
78dbbd9e4bSmacallan    FFBPtr pFfb = GET_FFB_FROM_SCRN(pScrn);
79dbbd9e4bSmacallan    int CursorShiftX = 0, CursorShiftY = 0;
80dbbd9e4bSmacallan
81dbbd9e4bSmacallan    if (x < 0) {
82dbbd9e4bSmacallan	CursorShiftX = -x;
83dbbd9e4bSmacallan	x = 0;
84dbbd9e4bSmacallan	if (CursorShiftX > 64)
85dbbd9e4bSmacallan	    CursorShiftX = 64;
86dbbd9e4bSmacallan    }
87dbbd9e4bSmacallan    if (y < 0) {
88dbbd9e4bSmacallan	CursorShiftY = -y;
89dbbd9e4bSmacallan	y = 0;
90dbbd9e4bSmacallan	if (CursorShiftY > 64)
91dbbd9e4bSmacallan	    CursorShiftY = 64;
92dbbd9e4bSmacallan    }
93dbbd9e4bSmacallan    if ((CursorShiftX != pFfb->CursorShiftX ||
94dbbd9e4bSmacallan	 CursorShiftY != pFfb->CursorShiftY) &&
95dbbd9e4bSmacallan	pFfb->CursorData != NULL) {
96dbbd9e4bSmacallan	pFfb->CursorShiftX = CursorShiftX;
97dbbd9e4bSmacallan	pFfb->CursorShiftY = CursorShiftY;
98dbbd9e4bSmacallan	FFBLoadCursorImage(pScrn, pFfb->CursorData);
99dbbd9e4bSmacallan    }
100dbbd9e4bSmacallan
101dbbd9e4bSmacallan    FFBDacLoadCursorPos(pFfb, x, y);
102dbbd9e4bSmacallan}
103dbbd9e4bSmacallan
104dbbd9e4bSmacallanstatic void
105dbbd9e4bSmacallanFFBSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg)
106dbbd9e4bSmacallan{
107dbbd9e4bSmacallan    FFBPtr pFfb = GET_FFB_FROM_SCRN(pScrn);
108dbbd9e4bSmacallan
109dbbd9e4bSmacallan    FFBDacLoadCursorColor(pFfb, fg, bg);
110dbbd9e4bSmacallan}
111dbbd9e4bSmacallan
112dbbd9e4bSmacallanBool
113dbbd9e4bSmacallanFFBHWCursorInit(ScreenPtr pScreen)
114dbbd9e4bSmacallan{
115e96acad6Smrg    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
116dbbd9e4bSmacallan    FFBPtr pFfb;
117dbbd9e4bSmacallan    xf86CursorInfoPtr infoPtr;
118dbbd9e4bSmacallan
119dbbd9e4bSmacallan    pFfb = GET_FFB_FROM_SCRN(pScrn);
120dbbd9e4bSmacallan    pFfb->CursorShiftX = 0;
121dbbd9e4bSmacallan    pFfb->CursorShiftY = 0;
122dbbd9e4bSmacallan    pFfb->CursorData = NULL;
123dbbd9e4bSmacallan
124dbbd9e4bSmacallan    infoPtr = xf86CreateCursorInfoRec();
125dbbd9e4bSmacallan    if(!infoPtr) return FALSE;
126dbbd9e4bSmacallan
127dbbd9e4bSmacallan    pFfb->CursorInfoRec = infoPtr;
128dbbd9e4bSmacallan
129dbbd9e4bSmacallan    infoPtr->MaxWidth = 64;
130dbbd9e4bSmacallan    infoPtr->MaxHeight = 64;
131dbbd9e4bSmacallan    infoPtr->Flags =  HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
132dbbd9e4bSmacallan	HARDWARE_CURSOR_SOURCE_MASK_NOT_INTERLEAVED;
133dbbd9e4bSmacallan
134dbbd9e4bSmacallan    infoPtr->SetCursorColors = FFBSetCursorColors;
135dbbd9e4bSmacallan    infoPtr->SetCursorPosition = FFBSetCursorPosition;
136dbbd9e4bSmacallan    infoPtr->LoadCursorImage = FFBLoadCursorImage;
137dbbd9e4bSmacallan    infoPtr->HideCursor = FFBHideCursor;
138dbbd9e4bSmacallan    infoPtr->ShowCursor = FFBShowCursor;
139dbbd9e4bSmacallan    infoPtr->UseHWCursor = NULL;
140dbbd9e4bSmacallan
141dbbd9e4bSmacallan    return xf86InitCursor(pScreen, infoPtr);
142dbbd9e4bSmacallan}
143