~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/kdrive/trio/s3curs.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Id: s3curs.c,v 1.1 1999/11/02 08:17:24 keithp Exp $
 
3
 *
 
4
 * Copyright ļæ½ 1999 Keith Packard
 
5
 *
 
6
 * Permission to use, copy, modify, distribute, and sell this software and its
 
7
 * documentation for any purpose is hereby granted without fee, provided that
 
8
 * the above copyright notice appear in all copies and that both that
 
9
 * copyright notice and this permission notice appear in supporting
 
10
 * documentation, and that the name of Keith Packard not be used in
 
11
 * advertising or publicity pertaining to distribution of the software without
 
12
 * specific, written prior permission.  Keith Packard makes no
 
13
 * representations about the suitability of this software for any purpose.  It
 
14
 * is provided "as is" without express or implied warranty.
 
15
 *
 
16
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
18
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
19
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
20
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
21
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
22
 * PERFORMANCE OF THIS SOFTWARE.
 
23
 */
 
24
/* $RCSId: xc/programs/Xserver/hw/kdrive/trio/s3curs.c,v 1.2 1999/12/30 03:03:19 robin Exp $ */
 
25
 
 
26
#ifdef HAVE_CONFIG_H
 
27
#include <kdrive-config.h>
 
28
#endif
 
29
#include "s3.h"
 
30
#include "s3draw.h"
 
31
#include "cursorstr.h"
 
32
 
 
33
#define SetupCursor(s)      KdScreenPriv(s); \
 
34
                            s3CardInfo(pScreenPriv); \
 
35
                            s3ScreenInfo(pScreenPriv); \
 
36
                            S3Ptr s3 = s3c->s3; \
 
37
                            S3Cursor *pCurPriv = &s3s->cursor
 
38
 
 
39
static void
 
40
_s3MoveCursor (ScreenPtr pScreen, int x, int y)
 
41
{
 
42
    SetupCursor(pScreen);
 
43
    CARD8   xlow, xhigh, ylow, yhigh;
 
44
    CARD8   xoff, yoff;
 
45
 
 
46
    x -= pCurPriv->xhot;
 
47
    xoff = 0;
 
48
    if (x < 0)
 
49
    {
 
50
        xoff = -x;
 
51
        x = 0;
 
52
    }
 
53
    y -= pCurPriv->yhot;
 
54
    yoff = 0;
 
55
    if (y < 0)
 
56
    {
 
57
        yoff = -y;
 
58
        y = 0;
 
59
    }
 
60
    xlow = (CARD8) x;
 
61
    xhigh = (CARD8) (x >> 8);
 
62
    ylow = (CARD8) y;
 
63
    yhigh = (CARD8) (y >> 8);
 
64
    
 
65
    
 
66
    /* This is the recommended order to move the cursor */
 
67
    
 
68
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x46, xhigh);
 
69
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x47, xlow);
 
70
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x49, ylow);
 
71
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4e, xoff);
 
72
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4f, yoff);
 
73
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x48, yhigh);
 
74
}    
 
75
 
 
76
static void
 
77
s3MoveCursor (ScreenPtr pScreen, int x, int y)
 
78
{
 
79
    SetupCursor (pScreen);
 
80
    
 
81
    if (!pCurPriv->has_cursor)
 
82
        return;
 
83
    
 
84
    if (!pScreenPriv->enabled)
 
85
        return;
 
86
    
 
87
    LockS3(s3c);
 
88
    _s3UnlockExt(s3);
 
89
    _s3MoveCursor (pScreen, x, y);
 
90
    _s3LockExt(s3);
 
91
    UnlockS3(s3c);
 
92
}
 
93
 
 
94
static void
 
95
s3AllocCursorColors (ScreenPtr pScreen)
 
96
{
 
97
    SetupCursor (pScreen);
 
98
    CursorPtr       pCursor = pCurPriv->pCursor;
 
99
    xColorItem      sourceColor, maskColor;
 
100
    
 
101
    KdAllocateCursorPixels (pScreen, 0, pCursor,
 
102
                            &pCurPriv->source, &pCurPriv->mask);
 
103
    switch (pScreenPriv->screen->fb[0].bitsPerPixel) {
 
104
    case 4:
 
105
        pCurPriv->source |= pCurPriv->source << 4;
 
106
        pCurPriv->mask |= pCurPriv->mask << 4;
 
107
    case 8:
 
108
        pCurPriv->source |= pCurPriv->source << 8;
 
109
        pCurPriv->mask |= pCurPriv->mask << 8;
 
110
    case 16:
 
111
        pCurPriv->source |= pCurPriv->source << 16;
 
112
        pCurPriv->mask |= pCurPriv->mask << 16;
 
113
    }
 
114
}
 
115
 
 
116
static void
 
117
_s3SetCursorColors (ScreenPtr pScreen)
 
118
{
 
119
    SetupCursor (pScreen);
 
120
    /* set foreground */
 
121
    /* Reset cursor color stack pointers */
 
122
    (void) _s3ReadIndexRegister(&s3->crt_vga_3d4, 0x45);
 
123
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4a, pCurPriv->source);
 
124
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4a, pCurPriv->source >> 8);
 
125
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4a, pCurPriv->source >> 16);
 
126
        
 
127
    /* set background */
 
128
    /* Reset cursor color stack pointers */
 
129
    (void) _s3ReadIndexRegister(&s3->crt_vga_3d4, 0x45);
 
130
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4b, pCurPriv->mask);
 
131
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4b, pCurPriv->mask >> 8);
 
132
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x4b, pCurPriv->mask >> 16);
 
133
}
 
134
    
 
135
void
 
136
s3RecolorCursor (ScreenPtr pScreen, int ndef, xColorItem *pdef)
 
137
{
 
138
    SetupCursor (pScreen);
 
139
    CursorPtr       pCursor = pCurPriv->pCursor;
 
140
    xColorItem      sourceColor, maskColor;
 
141
 
 
142
    if (!pCurPriv->has_cursor || !pCursor)
 
143
        return;
 
144
    
 
145
    if (!pScreenPriv->enabled)
 
146
        return;
 
147
    
 
148
    if (pdef)
 
149
    {
 
150
        while (ndef)
 
151
        {
 
152
            if (pdef->pixel == pCurPriv->source || 
 
153
                pdef->pixel == pCurPriv->mask)
 
154
                break;
 
155
            ndef--;
 
156
        }
 
157
        if (!ndef)
 
158
            return;
 
159
    }
 
160
    s3AllocCursorColors (pScreen);
 
161
    LockS3 (s3c);
 
162
    _s3UnlockExt(s3);
 
163
    _s3SetCursorColors (pScreen);
 
164
    _s3LockExt (s3);
 
165
    UnlockS3 (s3c);
 
166
}
 
167
    
 
168
static void
 
169
s3LoadCursor (ScreenPtr pScreen, int x, int y)
 
170
{
 
171
    SetupCursor(pScreen);
 
172
    CursorPtr       pCursor = pCurPriv->pCursor;
 
173
    CursorBitsPtr   bits = pCursor->bits;
 
174
    int w, h;
 
175
    unsigned char   r[2], g[2], b[2];
 
176
    unsigned long   *ram;
 
177
    unsigned long   *msk, *mskLine, *src, *srcLine;
 
178
    unsigned long   and, xor;
 
179
    int             i, j;
 
180
    int             cursor_address;
 
181
    int             wsrc;
 
182
    unsigned char   ramdac_control_;
 
183
 
 
184
    /*
 
185
     * Allocate new colors
 
186
     */
 
187
    s3AllocCursorColors (pScreen);
 
188
    
 
189
    pCurPriv->pCursor = pCursor;
 
190
    pCurPriv->xhot = pCursor->bits->xhot;
 
191
    pCurPriv->yhot = pCursor->bits->yhot;
 
192
    
 
193
    /*
 
194
     * Stick new image into cursor memory
 
195
     */
 
196
    ram = (unsigned long *) s3s->cursor_base;
 
197
    mskLine = (unsigned long *) bits->mask;
 
198
    srcLine = (unsigned long *) bits->source;
 
199
 
 
200
    h = bits->height;
 
201
    if (h > S3_CURSOR_HEIGHT)
 
202
        h = S3_CURSOR_HEIGHT;
 
203
 
 
204
    wsrc = BitmapBytePad(bits->width) / 4;        /* ulongs per line */
 
205
 
 
206
    for (i = 0; i < S3_CURSOR_HEIGHT; i++) 
 
207
    {
 
208
        msk = mskLine;
 
209
        src = srcLine;
 
210
        mskLine += wsrc;
 
211
        srcLine += wsrc;
 
212
        for (j = 0; j < S3_CURSOR_WIDTH / 32; j++) {
 
213
 
 
214
            unsigned long  m, s;
 
215
 
 
216
            if (i < h && j < wsrc) 
 
217
            {
 
218
                m = *msk++;
 
219
                s = *src++;
 
220
                xor = m & s;
 
221
                and = ~m;
 
222
            }
 
223
            else
 
224
            {
 
225
                and = 0xffffffff;
 
226
                xor = 0x00000000;
 
227
            }
 
228
                
 
229
            S3AdjustBits32(and);
 
230
            S3AdjustBits32(xor);
 
231
            *ram++ = (and & 0xffff) | (xor << 16);
 
232
            *ram++ = (and >> 16) | (xor & 0xffff0000);
 
233
        }
 
234
    }
 
235
    
 
236
    _s3WaitIdle (s3);
 
237
    _s3UnlockExt (s3);
 
238
    
 
239
    /* Set new color */
 
240
    _s3SetCursorColors (pScreen);
 
241
     
 
242
    /* Enable the cursor */
 
243
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x45, 0x01);
 
244
    
 
245
    /* Wait for VRetrace to make sure the position is read */
 
246
    _s3WaitVRetrace (s3);
 
247
    
 
248
    /* Move to new position */
 
249
    _s3MoveCursor (pScreen, x, y);
 
250
    
 
251
    _s3LockExt (s3);
 
252
    UnlockS3(s3c);
 
253
}
 
254
 
 
255
static void
 
256
s3UnloadCursor (ScreenPtr pScreen)
 
257
{
 
258
    SetupCursor (pScreen);
 
259
 
 
260
    LockS3 (s3c);
 
261
    _s3UnlockExt(s3);
 
262
 
 
263
    /* Disable cursor */
 
264
    _s3WriteIndexRegister (&s3->crt_vga_3d4, 0x45, 0);
 
265
    
 
266
    _s3LockExt(s3);
 
267
    UnlockS3 (s3c);
 
268
}
 
269
 
 
270
static Bool
 
271
s3RealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
 
272
{
 
273
    SetupCursor(pScreen);
 
274
 
 
275
    if (!pScreenPriv->enabled)
 
276
        return TRUE;
 
277
    
 
278
    /* miRecolorCursor does this */
 
279
    if (pCurPriv->pCursor == pCursor)
 
280
    {
 
281
        if (pCursor)
 
282
        {
 
283
#ifdef FB_OLD_SCREEN
 
284
            short       x, y;
 
285
#else
 
286
            int         x, y;
 
287
#endif
 
288
            
 
289
            miPointerPosition (&x, &y);
 
290
            s3LoadCursor (pScreen, x, y);
 
291
        }
 
292
    }
 
293
    return TRUE;
 
294
}
 
295
 
 
296
static Bool
 
297
s3UnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
 
298
{
 
299
    return TRUE;
 
300
}
 
301
 
 
302
static void
 
303
s3SetCursor (ScreenPtr pScreen, CursorPtr pCursor, int x, int y)
 
304
{
 
305
    SetupCursor(pScreen);
 
306
 
 
307
    pCurPriv->pCursor = pCursor;
 
308
    
 
309
    if (!pScreenPriv->enabled)
 
310
        return;
 
311
    
 
312
    if (pCursor)
 
313
        s3LoadCursor (pScreen, x, y);
 
314
    else
 
315
        s3UnloadCursor (pScreen);
 
316
}
 
317
 
 
318
miPointerSpriteFuncRec s3PointerSpriteFuncs = {
 
319
    s3RealizeCursor,
 
320
    s3UnrealizeCursor,
 
321
    s3SetCursor,
 
322
    s3MoveCursor,
 
323
};
 
324
 
 
325
static void
 
326
s3QueryBestSize (int class, 
 
327
                 unsigned short *pwidth, unsigned short *pheight, 
 
328
                 ScreenPtr pScreen)
 
329
{
 
330
    SetupCursor (pScreen);
 
331
 
 
332
    switch (class)
 
333
    {
 
334
    case CursorShape:
 
335
        if (*pwidth > pCurPriv->width)
 
336
            *pwidth = pCurPriv->width;
 
337
        if (*pheight > pCurPriv->height)
 
338
            *pheight = pCurPriv->height;
 
339
        if (*pwidth > pScreen->width)
 
340
            *pwidth = pScreen->width;
 
341
        if (*pheight > pScreen->height)
 
342
            *pheight = pScreen->height;
 
343
        break;
 
344
    default:
 
345
        fbQueryBestSize (class, pwidth, pheight, pScreen);
 
346
        break;
 
347
    }
 
348
}
 
349
 
 
350
Bool
 
351
s3CursorInit (ScreenPtr pScreen)
 
352
{
 
353
    SetupCursor (pScreen);
 
354
 
 
355
    if (!s3s->cursor_base)
 
356
    {
 
357
        pCurPriv->has_cursor = FALSE;
 
358
        return FALSE;
 
359
    }
 
360
    
 
361
    pCurPriv->width = S3_CURSOR_WIDTH;
 
362
    pCurPriv->height= S3_CURSOR_HEIGHT;
 
363
    pScreen->QueryBestSize = s3QueryBestSize;
 
364
    miPointerInitialize (pScreen,
 
365
                         &s3PointerSpriteFuncs,
 
366
                         &kdPointerScreenFuncs,
 
367
                         FALSE);
 
368
    pCurPriv->has_cursor = TRUE;
 
369
    pCurPriv->pCursor = NULL;
 
370
    return TRUE;
 
371
}
 
372
 
 
373
void
 
374
s3CursorEnable (ScreenPtr pScreen)
 
375
{
 
376
    SetupCursor (pScreen);
 
377
 
 
378
    if (pCurPriv->has_cursor)
 
379
    {
 
380
        if (pCurPriv->pCursor)
 
381
        {
 
382
#ifdef FB_OLD_SCREEN
 
383
            short       x, y;
 
384
#else
 
385
            int         x, y;
 
386
#endif
 
387
            
 
388
            miPointerPosition (&x, &y);
 
389
            s3LoadCursor (pScreen, x, y);
 
390
        }
 
391
        else
 
392
            s3UnloadCursor (pScreen);
 
393
    }
 
394
}
 
395
 
 
396
void
 
397
s3CursorDisable (ScreenPtr pScreen)
 
398
{
 
399
    SetupCursor (pScreen);
 
400
 
 
401
    if (!pScreenPriv->enabled)
 
402
        return;
 
403
    
 
404
    if (pCurPriv->has_cursor)
 
405
    {
 
406
        if (pCurPriv->pCursor)
 
407
        {
 
408
            s3UnloadCursor (pScreen);
 
409
        }
 
410
    }
 
411
}
 
412
 
 
413
void
 
414
s3CursorFini (ScreenPtr pScreen)
 
415
{
 
416
    SetupCursor (pScreen);
 
417
 
 
418
    pCurPriv->pCursor = NULL;
 
419
}