~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/kdrive/igs/igscurs.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $XFree86: xc/programs/Xserver/hw/kdrive/igs/igscurs.c,v 1.1 2000/05/24 23:52:48 keithp Exp $
 
3
 *
 
4
 * Copyright � 2000 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
 
 
25
#include "igs.h"
 
26
#include "cursorstr.h"
 
27
 
 
28
#define SetupCursor(s)      KdScreenPriv(s); \
 
29
                            igsCardInfo(pScreenPriv); \
 
30
                            igsScreenInfo(pScreenPriv); \
 
31
                            IgsCursor *pCurPriv = &igss->cursor; \
 
32
                            IgsVga    *igsvga = &igsc->igsvga
 
33
 
 
34
static void
 
35
_igsMoveCursor (ScreenPtr pScreen, int x, int y)
 
36
{
 
37
    SetupCursor(pScreen);
 
38
    CARD8   xoff, yoff;
 
39
 
 
40
    x -= pCurPriv->xhot;
 
41
    xoff = 0;
 
42
    if (x < 0)
 
43
    {
 
44
        xoff = -x;
 
45
        x = 0;
 
46
    }
 
47
    y -= pCurPriv->yhot;
 
48
    yoff = 0;
 
49
    if (y < 0)
 
50
    {
 
51
        yoff = -y;
 
52
        y = 0;
 
53
    }
 
54
 
 
55
    igsSet (igsvga, igs_sprite_x, x);
 
56
    igsSet (igsvga, igs_sprite_preset_x, xoff);
 
57
    igsSet (igsvga, igs_sprite_y, y);
 
58
    igsSet (igsvga, igs_sprite_preset_y, yoff);
 
59
}
 
60
 
 
61
static void
 
62
igsMoveCursor (ScreenPtr pScreen, int x, int y)
 
63
{
 
64
    SetupCursor (pScreen);
 
65
    
 
66
    if (!pCurPriv->has_cursor)
 
67
        return;
 
68
    
 
69
    if (!pScreenPriv->enabled)
 
70
        return;
 
71
    
 
72
    _igsMoveCursor (pScreen, x, y);
 
73
    VgaFlush (&igsvga->card);
 
74
}
 
75
 
 
76
 
 
77
static void
 
78
igsSetCursorColors (ScreenPtr pScreen)
 
79
{
 
80
    SetupCursor (pScreen);
 
81
    CursorPtr   pCursor = pCurPriv->pCursor;
 
82
    
 
83
    igsSetImm (igsvga, igs_cursor_write_index, 0);
 
84
    igsSetImm (igsvga, igs_cursor_data, pCursor->backRed >> 8);
 
85
    igsSetImm (igsvga, igs_cursor_data, pCursor->backGreen >> 8);
 
86
    igsSetImm (igsvga, igs_cursor_data, pCursor->backBlue >> 8);
 
87
    igsSetImm (igsvga, igs_cursor_write_index, 1);
 
88
    igsSetImm (igsvga, igs_cursor_data, pCursor->foreRed >> 8);
 
89
    igsSetImm (igsvga, igs_cursor_data, pCursor->foreGreen >> 8);
 
90
    igsSetImm (igsvga, igs_cursor_data, pCursor->foreBlue >> 8);
 
91
}
 
92
    
 
93
#if BITMAP_BIT_ORDER == MSBFirst
 
94
#define IgsAdjustCursor(v) { \
 
95
    v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555); \
 
96
    v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333); \
 
97
    v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f); \
 
98
    v = ((v & 0x00ff00ff) << 8) | ((v >> 8) & 0x00ff00ff); \
 
99
    v = ((v & 0x0000ffff) <<16) | ((v >>16) & 0x0000ffff); \
 
100
}
 
101
#else
 
102
#define IgsAdjustCursor(v)
 
103
#endif
 
104
 
 
105
#define ExplodeBits2(v)     (((v) & 1) | (((v) & 2) << 1))
 
106
#define ExplodeBits4(v)     ((ExplodeBits2((v) >> 2) << 4) | \
 
107
                             (ExplodeBits2((v) & 0x3)))
 
108
#define ExplodeBits8(v)     ((ExplodeBits4((v) >> 4) << 8) | \
 
109
                             (ExplodeBits4((v) & 0xf)))
 
110
#define ExplodeBits16(v)    ((ExplodeBits8((v) >> 8) << 16) | \
 
111
                             (ExplodeBits8((v) & 0xff)))
 
112
static void
 
113
igsLoadCursor (ScreenPtr pScreen, int x, int y)
 
114
{
 
115
    SetupCursor(pScreen);
 
116
    CursorPtr       pCursor = pCurPriv->pCursor;
 
117
    CursorBitsPtr   bits = pCursor->bits;
 
118
    int w, h;
 
119
    CARD32          *ram, *msk, *mskLine, *src, *srcLine;
 
120
    int             i, j;
 
121
    int             cursor_address;
 
122
    int             lwsrc;
 
123
    unsigned char   ramdac_control_;
 
124
    CARD32          offset;
 
125
    CARD32          b0, b1;
 
126
 
 
127
    pCurPriv->pCursor = pCursor;
 
128
    pCurPriv->xhot = pCursor->bits->xhot;
 
129
    pCurPriv->yhot = pCursor->bits->yhot;
 
130
    
 
131
    /*
 
132
     * Stick new image into cursor memory
 
133
     */
 
134
    ram = (CARD32 *) igss->cursor_base;
 
135
    mskLine = (CARD32 *) bits->mask;
 
136
    srcLine = (CARD32 *) bits->source;
 
137
 
 
138
    h = bits->height;
 
139
    if (h > IGS_CURSOR_HEIGHT)
 
140
        h = IGS_CURSOR_HEIGHT;
 
141
 
 
142
    lwsrc = BitmapBytePad(bits->width) / 4;        /* words per line */
 
143
 
 
144
    for (i = 0; i < IGS_CURSOR_HEIGHT; i++) {
 
145
        msk = mskLine;
 
146
        src = srcLine;
 
147
        mskLine += lwsrc;
 
148
        srcLine += lwsrc;
 
149
        for (j = 0; j < IGS_CURSOR_WIDTH / 32; j++) {
 
150
 
 
151
            CARD32  m, s;
 
152
 
 
153
            if (i < h && j < lwsrc) 
 
154
            {
 
155
                m = *msk++;
 
156
                s = *src++;
 
157
                IgsAdjustCursor(m);
 
158
                IgsAdjustCursor(s);
 
159
            }
 
160
            else
 
161
            {
 
162
                m = 0;
 
163
                s = 0;
 
164
            }
 
165
            s &= m;
 
166
            m = ~m;
 
167
            b0 = ExplodeBits16(s&0xffff) | (ExplodeBits16(m&0xffff)<<1);
 
168
            b1 = ExplodeBits16(s>>16) | (ExplodeBits16(m>>16)<<1);
 
169
            *ram++ = b0;
 
170
            *ram++ = b1;
 
171
        }
 
172
    }
 
173
    
 
174
    /* Set new color */
 
175
    igsSetCursorColors (pScreen);
 
176
     
 
177
    /* Set address for cursor bits */
 
178
    offset = igss->cursor_offset;
 
179
    offset >>= 10;
 
180
    igsSet (igsvga, igs_sprite_addr, offset);
 
181
    
 
182
    /* Assume TV interpolation off */
 
183
    igsSet (igsvga, igs_hcshf, 3);
 
184
    /* Enable the cursor */
 
185
    igsSet (igsvga, igs_sprite_visible, 1);
 
186
    igsSet (igsvga, igs_sprite_64x64, 1);
 
187
    /* Move to new position */
 
188
    _igsMoveCursor (pScreen, x, y);
 
189
 
 
190
    VgaFlush (&igsvga->card);
 
191
}
 
192
 
 
193
static void
 
194
igsUnloadCursor (ScreenPtr pScreen)
 
195
{
 
196
    SetupCursor (pScreen);
 
197
    
 
198
    /* Disable cursor */
 
199
    igsSet (igsvga, igs_sprite_visible, 0);
 
200
    VgaFlush (&igsvga->card);
 
201
}
 
202
 
 
203
static Bool
 
204
igsRealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
 
205
{
 
206
    SetupCursor(pScreen);
 
207
 
 
208
    if (!pScreenPriv->enabled)
 
209
        return TRUE;
 
210
    
 
211
    /* miRecolorCursor does this */
 
212
    if (pCurPriv->pCursor == pCursor)
 
213
    {
 
214
        if (pCursor)
 
215
        {
 
216
            int     x, y;
 
217
            
 
218
            miPointerPosition (&x, &y);
 
219
            igsLoadCursor (pScreen, x, y);
 
220
        }
 
221
    }
 
222
    return TRUE;
 
223
}
 
224
 
 
225
static Bool
 
226
igsUnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
 
227
{
 
228
    return TRUE;
 
229
}
 
230
 
 
231
static void
 
232
igsSetCursor (ScreenPtr pScreen, CursorPtr pCursor, int x, int y)
 
233
{
 
234
    SetupCursor(pScreen);
 
235
 
 
236
    pCurPriv->pCursor = pCursor;
 
237
    
 
238
    if (!pScreenPriv->enabled)
 
239
        return;
 
240
    
 
241
    if (pCursor)
 
242
        igsLoadCursor (pScreen, x, y);
 
243
    else
 
244
        igsUnloadCursor (pScreen);
 
245
}
 
246
 
 
247
miPointerSpriteFuncRec igsPointerSpriteFuncs = {
 
248
    igsRealizeCursor,
 
249
    igsUnrealizeCursor,
 
250
    igsSetCursor,
 
251
    igsMoveCursor,
 
252
};
 
253
 
 
254
static void
 
255
igsQueryBestSize (int class, 
 
256
                 unsigned short *pwidth, unsigned short *pheight, 
 
257
                 ScreenPtr pScreen)
 
258
{
 
259
    SetupCursor (pScreen);
 
260
 
 
261
    switch (class)
 
262
    {
 
263
    case CursorShape:
 
264
        if (*pwidth > pCurPriv->width)
 
265
            *pwidth = pCurPriv->width;
 
266
        if (*pheight > pCurPriv->height)
 
267
            *pheight = pCurPriv->height;
 
268
        if (*pwidth > pScreen->width)
 
269
            *pwidth = pScreen->width;
 
270
        if (*pheight > pScreen->height)
 
271
            *pheight = pScreen->height;
 
272
        break;
 
273
    default:
 
274
        fbQueryBestSize (class, pwidth, pheight, pScreen);
 
275
        break;
 
276
    }
 
277
}
 
278
 
 
279
Bool
 
280
igsCursorInit (ScreenPtr pScreen)
 
281
{
 
282
    SetupCursor (pScreen);
 
283
 
 
284
    if (!igss->cursor_base)
 
285
    {
 
286
        pCurPriv->has_cursor = FALSE;
 
287
        return FALSE;
 
288
    }
 
289
    
 
290
    pCurPriv->width = IGS_CURSOR_WIDTH;
 
291
    pCurPriv->height= IGS_CURSOR_HEIGHT;
 
292
    pScreen->QueryBestSize = igsQueryBestSize;
 
293
    miPointerInitialize (pScreen,
 
294
                         &igsPointerSpriteFuncs,
 
295
                         &kdPointerScreenFuncs,
 
296
                         FALSE);
 
297
    pCurPriv->has_cursor = TRUE;
 
298
    pCurPriv->pCursor = NULL;
 
299
    return TRUE;
 
300
}
 
301
 
 
302
void
 
303
igsCursorEnable (ScreenPtr pScreen)
 
304
{
 
305
    SetupCursor (pScreen);
 
306
 
 
307
    if (pCurPriv->has_cursor)
 
308
    {
 
309
        if (pCurPriv->pCursor)
 
310
        {
 
311
            int     x, y;
 
312
            
 
313
            miPointerPosition (&x, &y);
 
314
            igsLoadCursor (pScreen, x, y);
 
315
        }
 
316
        else
 
317
            igsUnloadCursor (pScreen);
 
318
    }
 
319
}
 
320
 
 
321
void
 
322
igsCursorDisable (ScreenPtr pScreen)
 
323
{
 
324
    SetupCursor (pScreen);
 
325
 
 
326
    if (!pScreenPriv->enabled)
 
327
        return;
 
328
    
 
329
    if (pCurPriv->has_cursor)
 
330
    {
 
331
        if (pCurPriv->pCursor)
 
332
        {
 
333
            igsUnloadCursor (pScreen);
 
334
        }
 
335
    }
 
336
}
 
337
 
 
338
void
 
339
igsCursorFini (ScreenPtr pScreen)
 
340
{
 
341
    SetupCursor (pScreen);
 
342
 
 
343
    pCurPriv->pCursor = NULL;
 
344
}