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

« back to all changes in this revision

Viewing changes to unix/xc/lib/GL/mesa/src/drv/mga/mgaspan.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
 * Copyright 2000-2001 VA Linux Systems, Inc.
 
3
 * All Rights Reserved.
 
4
 *
 
5
 * Permission is hereby granted, free of charge, to any person obtaining a
 
6
 * copy of this software and associated documentation files (the "Software"),
 
7
 * to deal in the Software without restriction, including without limitation
 
8
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 
9
 * license, and/or sell copies of the Software, and to permit persons to whom
 
10
 * the Software is furnished to do so, subject to the following conditions:
 
11
 *
 
12
 * The above copyright notice and this permission notice (including the next
 
13
 * paragraph) shall be included in all copies or substantial portions of the
 
14
 * Software.
 
15
 *
 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
 
19
 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
20
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
21
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
22
 * OTHER DEALINGS IN THE SOFTWARE.
 
23
 *
 
24
 * Authors:
 
25
 *    Keith Whitwell <keith@tungstengraphics.com>
 
26
 */
 
27
/* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgaspan.c,v 1.11 2002/10/30 12:51:36 alanh Exp $ */
 
28
 
 
29
#include "mtypes.h"
 
30
#include "mgadd.h"
 
31
#include "mgacontext.h"
 
32
#include "mgaspan.h"
 
33
#include "mgaioctl.h"
 
34
#include "swrast/swrast.h"
 
35
 
 
36
#define DBG 0
 
37
 
 
38
 
 
39
#define LOCAL_VARS                                      \
 
40
   __DRIdrawablePrivate *dPriv = mmesa->driDrawable;    \
 
41
   mgaScreenPrivate *mgaScreen = mmesa->mgaScreen;      \
 
42
   __DRIscreenPrivate *sPriv = mmesa->driScreen;        \
 
43
   GLuint pitch = mgaScreen->frontPitch;                \
 
44
   GLuint height = dPriv->h;                            \
 
45
   char *read_buf = (char *)(sPriv->pFB +               \
 
46
                        mmesa->readOffset +             \
 
47
                        dPriv->x * mgaScreen->cpp +     \
 
48
                        dPriv->y * pitch);              \
 
49
   char *buf = (char *)(sPriv->pFB +                    \
 
50
                        mmesa->drawOffset +             \
 
51
                        dPriv->x * mgaScreen->cpp +     \
 
52
                        dPriv->y * pitch);              \
 
53
   GLuint p;                                            \
 
54
   (void) read_buf; (void) buf; (void) p
 
55
   
 
56
 
 
57
 
 
58
#define LOCAL_DEPTH_VARS                                                \
 
59
   __DRIdrawablePrivate *dPriv = mmesa->driDrawable;                    \
 
60
   mgaScreenPrivate *mgaScreen = mmesa->mgaScreen;                      \
 
61
   __DRIscreenPrivate *sPriv = mmesa->driScreen;                        \
 
62
   GLuint pitch = mgaScreen->frontPitch;                                \
 
63
   GLuint height = dPriv->h;                                            \
 
64
   char *buf = (char *)(sPriv->pFB +                                    \
 
65
                        mgaScreen->depthOffset +                        \
 
66
                        dPriv->x * mgaScreen->cpp +                     \
 
67
                        dPriv->y * pitch)
 
68
 
 
69
#define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS 
 
70
 
 
71
#define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
 
72
                          _y >= miny && _y < maxy)
 
73
 
 
74
#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                            \
 
75
   if ( _y < miny || _y >= maxy ) {                                     \
 
76
      _n1 = 0, _x1 = x;                                                 \
 
77
   } else {                                                             \
 
78
      _n1 = _n;                                                         \
 
79
      _x1 = _x;                                                         \
 
80
      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
 
81
      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);                 \
 
82
   }
 
83
 
 
84
 
 
85
#define HW_LOCK()                               \
 
86
   mgaContextPtr mmesa = MGA_CONTEXT(ctx);      \
 
87
   FLUSH_BATCH(mmesa);                          \
 
88
   LOCK_HARDWARE_QUIESCENT(mmesa);
 
89
 
 
90
 
 
91
#define HW_CLIPLOOP()                                           \
 
92
  do {                                                          \
 
93
    int _nc = mmesa->numClipRects;                              \
 
94
    while (_nc--) {                                             \
 
95
       int minx = mmesa->pClipRects[_nc].x1 - mmesa->drawX;     \
 
96
       int miny = mmesa->pClipRects[_nc].y1 - mmesa->drawY;     \
 
97
       int maxx = mmesa->pClipRects[_nc].x2 - mmesa->drawX;     \
 
98
       int maxy = mmesa->pClipRects[_nc].y2 - mmesa->drawY;
 
99
 
 
100
#define HW_ENDCLIPLOOP()                        \
 
101
    }                                           \
 
102
  } while (0)
 
103
 
 
104
#define HW_UNLOCK()                             \
 
105
    UNLOCK_HARDWARE(mmesa);
 
106
 
 
107
 
 
108
 
 
109
 
 
110
 
 
111
 
 
112
 
 
113
/* 16 bit, 565 rgb color spanline and pixel functions
 
114
 */
 
115
#define Y_FLIP(_y) (height - _y - 1)
 
116
 
 
117
#undef INIT_MONO_PIXEL
 
118
#define INIT_MONO_PIXEL(p, color) \
 
119
  p = MGAPACKCOLOR565( color[0], color[1], color[2] )
 
120
 
 
121
 
 
122
#define WRITE_RGBA( _x, _y, r, g, b, a )                                \
 
123
   *(GLushort *)(buf + _x*2 + _y*pitch)  = ( (((int)r & 0xf8) << 8) |   \
 
124
                                             (((int)g & 0xfc) << 3) |   \
 
125
                                             (((int)b & 0xf8) >> 3))
 
126
 
 
127
#define WRITE_PIXEL( _x, _y, p )  \
 
128
   *(GLushort *)(buf + _x*2 + _y*pitch) = p
 
129
 
 
130
#define READ_RGBA( rgba, _x, _y )                               \
 
131
do {                                                            \
 
132
   GLushort p = *(GLushort *)(read_buf + _x*2 + _y*pitch);      \
 
133
   rgba[0] = (((p >> 11) & 0x1f) * 255) / 31;                   \
 
134
   rgba[1] = (((p >>  5) & 0x3f) * 255) / 63;                   \
 
135
   rgba[2] = (((p >>  0) & 0x1f) * 255) / 31;                   \
 
136
   rgba[3] = 255;                                               \
 
137
} while(0)
 
138
 
 
139
#define TAG(x) mga##x##_565
 
140
#include "spantmp.h"
 
141
 
 
142
 
 
143
 
 
144
 
 
145
 
 
146
/* 32 bit, 8888 argb color spanline and pixel functions
 
147
 */
 
148
 
 
149
#undef INIT_MONO_PIXEL
 
150
#define INIT_MONO_PIXEL(p, color) \
 
151
  p = MGAPACKCOLOR8888( color[0], color[1], color[2], color[3] )
 
152
 
 
153
 
 
154
#define WRITE_RGBA(_x, _y, r, g, b, a)                  \
 
155
    *(GLuint *)(buf + _x*4 + _y*pitch) = ((r << 16) |   \
 
156
                                          (g << 8)  |   \
 
157
                                          (b << 0)  |   \
 
158
                                          (a << 24) )
 
159
 
 
160
#define WRITE_PIXEL(_x, _y, p)                  \
 
161
    *(GLuint *)(buf + _x*4 + _y*pitch) = p
 
162
 
 
163
#define READ_RGBA(rgba, _x, _y)                                 \
 
164
    do {                                                        \
 
165
        GLuint p = *(GLuint *)(read_buf + _x*4 + _y*pitch);     \
 
166
        rgba[0] = (p >> 16) & 0xff;                             \
 
167
        rgba[1] = (p >> 8)  & 0xff;                             \
 
168
        rgba[2] = (p >> 0)  & 0xff;                             \
 
169
        rgba[3] = 0xff;                                         \
 
170
    } while (0)
 
171
 
 
172
#define TAG(x) mga##x##_8888
 
173
#include "spantmp.h"
 
174
 
 
175
 
 
176
 
 
177
 
 
178
/* 16 bit depthbuffer functions.
 
179
 */
 
180
#define WRITE_DEPTH( _x, _y, d )        \
 
181
   *(GLushort *)(buf + _x*2 + _y*pitch) = d;
 
182
 
 
183
#define READ_DEPTH( d, _x, _y )         \
 
184
   d = *(GLushort *)(buf + _x*2 + _y*pitch);
 
185
 
 
186
#define TAG(x) mga##x##_16
 
187
#include "depthtmp.h"
 
188
 
 
189
 
 
190
 
 
191
 
 
192
/* 32 bit depthbuffer functions.
 
193
 */
 
194
#define WRITE_DEPTH( _x, _y, d )        \
 
195
   *(GLuint *)(buf + _x*4 + _y*pitch) = d;
 
196
 
 
197
#define READ_DEPTH( d, _x, _y )         \
 
198
   d = *(GLuint *)(buf + _x*4 + _y*pitch);
 
199
 
 
200
#define TAG(x) mga##x##_32
 
201
#include "depthtmp.h"
 
202
 
 
203
 
 
204
 
 
205
/* 24/8 bit interleaved depth/stencil functions
 
206
 */
 
207
#define WRITE_DEPTH( _x, _y, d ) {                      \
 
208
   GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch);     \
 
209
   tmp &= 0xff;                                         \
 
210
   tmp |= (d) << 8;                                     \
 
211
   *(GLuint *)(buf + _x*4 + _y*pitch) = tmp;            \
 
212
}
 
213
 
 
214
#define READ_DEPTH( d, _x, _y ) {                               \
 
215
   d = (*(GLuint *)(buf + _x*4 + _y*pitch) & ~0xff) >> 8;       \
 
216
}
 
217
 
 
218
#define TAG(x) mga##x##_24_8
 
219
#include "depthtmp.h"
 
220
 
 
221
#define WRITE_STENCIL( _x, _y, d ) {                    \
 
222
   GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch);     \
 
223
   tmp &= 0xffffff00;                                   \
 
224
   tmp |= d & 0xff;                                     \
 
225
   *(GLuint *)(buf + _x*4 + _y*pitch) = tmp;            \
 
226
}
 
227
 
 
228
#define READ_STENCIL( d, _x, _y )               \
 
229
   d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
 
230
 
 
231
#define TAG(x) mga##x##_24_8
 
232
#include "stenciltmp.h"
 
233
 
 
234
 
 
235
 
 
236
static void mgaDDSetReadBuffer(GLcontext *ctx, GLframebuffer *buffer,
 
237
                        GLenum mode )
 
238
{
 
239
   mgaContextPtr mmesa = MGA_CONTEXT(ctx);
 
240
 
 
241
   if (mode == GL_FRONT_LEFT) 
 
242
   {
 
243
      mmesa->readOffset = mmesa->mgaScreen->frontOffset;
 
244
      mmesa->read_buffer = MGA_FRONT;
 
245
   } 
 
246
   else 
 
247
   {
 
248
      mmesa->readOffset = mmesa->mgaScreen->backOffset;
 
249
      mmesa->read_buffer = MGA_BACK;
 
250
   }
 
251
}
 
252
 
 
253
void mgaDDInitSpanFuncs( GLcontext *ctx )
 
254
{
 
255
   mgaContextPtr mmesa = MGA_CONTEXT(ctx);
 
256
   struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
 
257
 
 
258
   swdd->SetReadBuffer = mgaDDSetReadBuffer;
 
259
 
 
260
   switch (mmesa->mgaScreen->cpp) {
 
261
   case 2:
 
262
      swdd->WriteRGBASpan = mgaWriteRGBASpan_565;
 
263
      swdd->WriteRGBSpan = mgaWriteRGBSpan_565;
 
264
      swdd->WriteMonoRGBASpan = mgaWriteMonoRGBASpan_565;
 
265
      swdd->WriteRGBAPixels = mgaWriteRGBAPixels_565;
 
266
      swdd->WriteMonoRGBAPixels = mgaWriteMonoRGBAPixels_565;
 
267
      swdd->ReadRGBASpan = mgaReadRGBASpan_565;
 
268
      swdd->ReadRGBAPixels = mgaReadRGBAPixels_565;
 
269
 
 
270
      swdd->ReadDepthSpan = mgaReadDepthSpan_16;
 
271
      swdd->WriteDepthSpan = mgaWriteDepthSpan_16;
 
272
      swdd->ReadDepthPixels = mgaReadDepthPixels_16;
 
273
      swdd->WriteDepthPixels = mgaWriteDepthPixels_16;
 
274
      break;
 
275
 
 
276
   case 4:
 
277
      swdd->WriteRGBASpan = mgaWriteRGBASpan_8888;
 
278
      swdd->WriteRGBSpan = mgaWriteRGBSpan_8888;
 
279
      swdd->WriteMonoRGBASpan = mgaWriteMonoRGBASpan_8888;
 
280
      swdd->WriteRGBAPixels = mgaWriteRGBAPixels_8888;
 
281
      swdd->WriteMonoRGBAPixels = mgaWriteMonoRGBAPixels_8888;
 
282
      swdd->ReadRGBASpan = mgaReadRGBASpan_8888;
 
283
      swdd->ReadRGBAPixels = mgaReadRGBAPixels_8888;
 
284
      
 
285
      if (!mmesa->hw_stencil) {
 
286
         swdd->ReadDepthSpan = mgaReadDepthSpan_32;
 
287
         swdd->WriteDepthSpan = mgaWriteDepthSpan_32;
 
288
         swdd->ReadDepthPixels = mgaReadDepthPixels_32;
 
289
         swdd->WriteDepthPixels = mgaWriteDepthPixels_32;
 
290
      } else {
 
291
         swdd->ReadDepthSpan = mgaReadDepthSpan_24_8;
 
292
         swdd->WriteDepthSpan = mgaWriteDepthSpan_24_8;
 
293
         swdd->ReadDepthPixels = mgaReadDepthPixels_24_8;
 
294
         swdd->WriteDepthPixels = mgaWriteDepthPixels_24_8;
 
295
 
 
296
         swdd->ReadStencilSpan = mgaReadStencilSpan_24_8;
 
297
         swdd->WriteStencilSpan = mgaWriteStencilSpan_24_8;
 
298
         swdd->ReadStencilPixels = mgaReadStencilPixels_24_8;
 
299
         swdd->WriteStencilPixels = mgaWriteStencilPixels_24_8;
 
300
      }
 
301
      break;
 
302
   }
 
303
}