summaryrefslogtreecommitdiff
path: root/src/ffb_cursor.c
blob: 3fc22926bdb087f1ce1975fb527d076816aab1e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * Hardware cursor support for Creator, Creator 3D and Elite 3D
 *
 * Copyright 2000 by Jakub Jelinek <jakub@redhat.com>.
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without
 * fee, provided that the above copyright notice appear in all copies
 * and that both that copyright notice and this permission notice
 * appear in supporting documentation, and that the name of Jakub
 * Jelinek not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior
 * permission.  Jakub Jelinek makes no representations about the
 * suitability of this software for any purpose.  It is provided "as
 * is" without express or implied warranty.
 *
 * JAKUB JELINEK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS, IN NO EVENT SHALL JAKUB JELINEK BE LIABLE FOR ANY
 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/sunffb/ffb_cursor.c,v 1.2 2000/05/23 04:47:44 dawes Exp $ */

#include "ffb.h"

/* This file just performs cursor software state management.  The
 * actual programming is done by calls into the DAC layer.
 */

static void FFBLoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src);
static void FFBShowCursor(ScrnInfoPtr pScrn);
static void FFBHideCursor(ScrnInfoPtr pScrn);
static void FFBSetCursorPosition(ScrnInfoPtr pScrn, int x, int y);
static void FFBSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg);

static void
FFBLoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src)
{
    FFBPtr pFfb = GET_FFB_FROM_SCRN(pScrn);
    unsigned int *data = (unsigned int *)src;
    int x, y;

    pFfb->CursorData = src;
    x = pFfb->CursorShiftX;
    y = pFfb->CursorShiftY;
    if (x >= 64 || y >= 64)
	y = 64;
    FFBDacCursorLoadBitmap(pFfb, x, y, data);
}

static void 
FFBShowCursor(ScrnInfoPtr pScrn)
{
    FFBPtr pFfb = GET_FFB_FROM_SCRN(pScrn);

    FFBDacCursorEnableDisable(pFfb, 1);
}

static void
FFBHideCursor(ScrnInfoPtr pScrn)
{
    FFBPtr pFfb = GET_FFB_FROM_SCRN(pScrn);

    FFBDacCursorEnableDisable(pFfb, 0);
    pFfb->CursorData = NULL;
}

static void
FFBSetCursorPosition(ScrnInfoPtr pScrn, int x, int y)
{
    FFBPtr pFfb = GET_FFB_FROM_SCRN(pScrn);
    int CursorShiftX = 0, CursorShiftY = 0;

    if (x < 0) {
	CursorShiftX = -x;
	x = 0;
	if (CursorShiftX > 64)
	    CursorShiftX = 64;
    }
    if (y < 0) {
	CursorShiftY = -y;
	y = 0;
	if (CursorShiftY > 64)
	    CursorShiftY = 64;
    }
    if ((CursorShiftX != pFfb->CursorShiftX ||
	 CursorShiftY != pFfb->CursorShiftY) &&
	pFfb->CursorData != NULL) {
	pFfb->CursorShiftX = CursorShiftX;
	pFfb->CursorShiftY = CursorShiftY;
	FFBLoadCursorImage(pScrn, pFfb->CursorData);
    }
	
    FFBDacLoadCursorPos(pFfb, x, y);
}

static void
FFBSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg)
{
    FFBPtr pFfb = GET_FFB_FROM_SCRN(pScrn);

    FFBDacLoadCursorColor(pFfb, fg, bg);
}

Bool 
FFBHWCursorInit(ScreenPtr pScreen)
{
    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
    FFBPtr pFfb;
    xf86CursorInfoPtr infoPtr;

    pFfb = GET_FFB_FROM_SCRN(pScrn);
    pFfb->CursorShiftX = 0;
    pFfb->CursorShiftY = 0;
    pFfb->CursorData = NULL;

    infoPtr = xf86CreateCursorInfoRec();
    if(!infoPtr) return FALSE;
    
    pFfb->CursorInfoRec = infoPtr;

    infoPtr->MaxWidth = 64;
    infoPtr->MaxHeight = 64;
    infoPtr->Flags =  HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
	HARDWARE_CURSOR_SOURCE_MASK_NOT_INTERLEAVED;

    infoPtr->SetCursorColors = FFBSetCursorColors;
    infoPtr->SetCursorPosition = FFBSetCursorPosition;
    infoPtr->LoadCursorImage = FFBLoadCursorImage;
    infoPtr->HideCursor = FFBHideCursor;
    infoPtr->ShowCursor = FFBShowCursor;
    infoPtr->UseHWCursor = NULL;

    return xf86InitCursor(pScreen, infoPtr);
}