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

« back to all changes in this revision

Viewing changes to unix/xc/extras/Mesa/src/swrast/s_alphabuf.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
/*
 
3
 * Mesa 3-D graphics library
 
4
 * Version:  4.0.2
 
5
 *
 
6
 * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person obtaining a
 
9
 * copy of this software and associated documentation files (the "Software"),
 
10
 * to deal in the Software without restriction, including without limitation
 
11
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
12
 * and/or sell copies of the Software, and to permit persons to whom the
 
13
 * Software is furnished to do so, subject to the following conditions:
 
14
 *
 
15
 * The above copyright notice and this permission notice shall be included
 
16
 * in all copies or substantial portions of the Software.
 
17
 *
 
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
19
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
21
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
22
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
23
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
24
 */
 
25
 
 
26
 
 
27
/*
 
28
 * Software alpha planes.  Many frame buffers don't have alpha bits so
 
29
 * we simulate them in software.
 
30
 */
 
31
 
 
32
 
 
33
#include "glheader.h"
 
34
#include "context.h"
 
35
#include "mem.h"
 
36
 
 
37
#include "s_alphabuf.h"
 
38
 
 
39
 
 
40
#define ALPHA_DRAW_ADDR(X,Y) \
 
41
   (ctx->DrawBuffer->Alpha + (Y) * ctx->DrawBuffer->Width + (X))
 
42
 
 
43
#define ALPHA_READ_ADDR(X,Y) \
 
44
   (ctx->ReadBuffer->Alpha + (Y) * ctx->ReadBuffer->Width + (X))
 
45
 
 
46
 
 
47
/*
 
48
 * Allocate a new front and back alpha buffer.
 
49
 */
 
50
void
 
51
_mesa_alloc_alpha_buffers( GLframebuffer *buffer )
 
52
{
 
53
   GET_CURRENT_CONTEXT(ctx);
 
54
   const GLint bytes = buffer->Width * buffer->Height * sizeof(GLchan);
 
55
 
 
56
   ASSERT(buffer->UseSoftwareAlphaBuffers);
 
57
 
 
58
   if (buffer->FrontLeftAlpha) {
 
59
      MESA_PBUFFER_FREE( buffer->FrontLeftAlpha );
 
60
   }
 
61
   buffer->FrontLeftAlpha = (GLchan *) MESA_PBUFFER_ALLOC( bytes );
 
62
   if (!buffer->FrontLeftAlpha) {
 
63
      /* out of memory */
 
64
      _mesa_error( NULL, GL_OUT_OF_MEMORY,
 
65
                   "Couldn't allocate front-left alpha buffer" );
 
66
   }
 
67
 
 
68
   if (buffer->Visual.doubleBufferMode) {
 
69
      if (buffer->BackLeftAlpha) {
 
70
         MESA_PBUFFER_FREE( buffer->BackLeftAlpha );
 
71
      }
 
72
      buffer->BackLeftAlpha = (GLchan *) MESA_PBUFFER_ALLOC( bytes );
 
73
      if (!buffer->BackLeftAlpha) {
 
74
         /* out of memory */
 
75
         _mesa_error( NULL, GL_OUT_OF_MEMORY,
 
76
                      "Couldn't allocate back-left alpha buffer" );
 
77
      }
 
78
   }
 
79
 
 
80
   if (buffer->Visual.stereoMode) {
 
81
      if (buffer->FrontRightAlpha) {
 
82
         MESA_PBUFFER_FREE( buffer->FrontRightAlpha );
 
83
      }
 
84
      buffer->FrontRightAlpha = (GLchan *) MESA_PBUFFER_ALLOC( bytes );
 
85
      if (!buffer->FrontRightAlpha) {
 
86
         /* out of memory */
 
87
         _mesa_error( NULL, GL_OUT_OF_MEMORY,
 
88
                      "Couldn't allocate front-right alpha buffer" );
 
89
      }
 
90
 
 
91
      if (buffer->Visual.doubleBufferMode) {
 
92
         if (buffer->BackRightAlpha) {
 
93
            MESA_PBUFFER_FREE( buffer->BackRightAlpha );
 
94
         }
 
95
         buffer->BackRightAlpha = (GLchan *) MESA_PBUFFER_ALLOC( bytes );
 
96
         if (!buffer->BackRightAlpha) {
 
97
            /* out of memory */
 
98
            _mesa_error( NULL, GL_OUT_OF_MEMORY,
 
99
                         "Couldn't allocate back-right alpha buffer" );
 
100
         }
 
101
      }
 
102
   }
 
103
 
 
104
   if (ctx) {
 
105
      if (ctx->Color.DriverDrawBuffer == GL_FRONT_LEFT)
 
106
         buffer->Alpha = buffer->FrontLeftAlpha;
 
107
      else if (ctx->Color.DriverDrawBuffer == GL_BACK_LEFT)
 
108
         buffer->Alpha = buffer->BackLeftAlpha;
 
109
      else if (ctx->Color.DriverDrawBuffer == GL_FRONT_RIGHT)
 
110
         buffer->Alpha = buffer->FrontRightAlpha;
 
111
      else if (ctx->Color.DriverDrawBuffer == GL_BACK_RIGHT)
 
112
         buffer->Alpha = buffer->BackRightAlpha;
 
113
   }
 
114
}
 
115
 
 
116
 
 
117
/*
 
118
 * Clear all the alpha buffers
 
119
 */
 
120
void
 
121
_mesa_clear_alpha_buffers( GLcontext *ctx )
 
122
{
 
123
   const GLchan aclear = ctx->Color.ClearColor[3];
 
124
   GLuint bufferBit;
 
125
 
 
126
   ASSERT(ctx->DrawBuffer->UseSoftwareAlphaBuffers);
 
127
   ASSERT(ctx->Color.ColorMask[ACOMP]);
 
128
 
 
129
   /* loop over four possible alpha buffers */
 
130
   for (bufferBit = 1; bufferBit <= 8; bufferBit = bufferBit << 1) {
 
131
      if (bufferBit & ctx->Color.DrawDestMask) {
 
132
         GLchan *buffer;
 
133
         if (bufferBit == FRONT_LEFT_BIT) {
 
134
            buffer = ctx->DrawBuffer->FrontLeftAlpha;
 
135
         }
 
136
         else if (bufferBit == FRONT_RIGHT_BIT) {
 
137
            buffer = ctx->DrawBuffer->FrontRightAlpha;
 
138
         }
 
139
         else if (bufferBit == BACK_LEFT_BIT) {
 
140
            buffer = ctx->DrawBuffer->BackLeftAlpha;
 
141
         }
 
142
         else {
 
143
            buffer = ctx->DrawBuffer->BackRightAlpha;
 
144
         }
 
145
 
 
146
         if (ctx->Scissor.Enabled) {
 
147
            /* clear scissor region */
 
148
            GLint j;
 
149
            GLint rowLen = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
 
150
            GLint rows = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
 
151
            GLint width = ctx->DrawBuffer->Width;
 
152
            GLchan *aptr = buffer
 
153
                          + ctx->DrawBuffer->_Ymin * ctx->DrawBuffer->Width
 
154
                          + ctx->DrawBuffer->_Xmin;
 
155
            for (j = 0; j < rows; j++) {
 
156
#if CHAN_BITS == 8
 
157
               MEMSET( aptr, aclear, rowLen );
 
158
#elif CHAN_BITS == 16
 
159
               MEMSET16( aptr, aclear, rowLen );
 
160
#else
 
161
               GLint i;
 
162
               for (i = 0; i < rowLen; i++) {
 
163
                  aptr[i] = aclear;
 
164
               }
 
165
#endif
 
166
               aptr += width;
 
167
            }
 
168
         }
 
169
         else {
 
170
            /* clear whole buffer */
 
171
            GLuint pixels = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height;
 
172
#if CHAN_BITS == 8
 
173
            MEMSET(buffer, aclear, pixels);
 
174
#elif CHAN_BITS == 16
 
175
            MEMSET16(buffer, aclear, pixels);
 
176
#else
 
177
            GLuint i;
 
178
            for (i = 0; i < pixels; i++) {
 
179
               buffer[i] = aclear;
 
180
            }
 
181
#endif
 
182
         }
 
183
      }
 
184
   }
 
185
}
 
186
 
 
187
 
 
188
 
 
189
void
 
190
_mesa_write_alpha_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
 
191
                        CONST GLchan rgba[][4], const GLubyte mask[] )
 
192
{
 
193
   GLchan *aptr = ALPHA_DRAW_ADDR( x, y );
 
194
   GLuint i;
 
195
 
 
196
   if (mask) {
 
197
      for (i=0;i<n;i++) {
 
198
         if (mask[i]) {
 
199
            *aptr = rgba[i][ACOMP];
 
200
         }
 
201
         aptr++;
 
202
      }
 
203
   }
 
204
   else {
 
205
      for (i=0;i<n;i++) {
 
206
         *aptr++ = rgba[i][ACOMP];
 
207
      }
 
208
   }
 
209
}
 
210
 
 
211
 
 
212
void
 
213
_mesa_write_mono_alpha_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
 
214
                             GLchan alpha, const GLubyte mask[] )
 
215
{
 
216
   GLchan *aptr = ALPHA_DRAW_ADDR( x, y );
 
217
   GLuint i;
 
218
 
 
219
   if (mask) {
 
220
      for (i=0;i<n;i++) {
 
221
         if (mask[i]) {
 
222
            *aptr = alpha;
 
223
         }
 
224
         aptr++;
 
225
      }
 
226
   }
 
227
   else {
 
228
      for (i=0;i<n;i++) {
 
229
         *aptr++ = alpha;
 
230
      }
 
231
   }
 
232
}
 
233
 
 
234
 
 
235
void
 
236
_mesa_write_alpha_pixels( GLcontext *ctx,
 
237
                          GLuint n, const GLint x[], const GLint y[],
 
238
                          CONST GLchan rgba[][4], const GLubyte mask[] )
 
239
{
 
240
   GLuint i;
 
241
 
 
242
   if (mask) {
 
243
      for (i=0;i<n;i++) {
 
244
         if (mask[i]) {
 
245
            GLchan *aptr = ALPHA_DRAW_ADDR( x[i], y[i] );
 
246
            *aptr = rgba[i][ACOMP];
 
247
         }
 
248
      }
 
249
   }
 
250
   else {
 
251
      for (i=0;i<n;i++) {
 
252
         GLchan *aptr = ALPHA_DRAW_ADDR( x[i], y[i] );
 
253
         *aptr = rgba[i][ACOMP];
 
254
      }
 
255
   }
 
256
}
 
257
 
 
258
 
 
259
void
 
260
_mesa_write_mono_alpha_pixels( GLcontext *ctx,
 
261
                               GLuint n, const GLint x[], const GLint y[],
 
262
                               GLchan alpha, const GLubyte mask[] )
 
263
{
 
264
   GLuint i;
 
265
 
 
266
   if (mask) {
 
267
      for (i=0;i<n;i++) {
 
268
         if (mask[i]) {
 
269
            GLchan *aptr = ALPHA_DRAW_ADDR( x[i], y[i] );
 
270
            *aptr = alpha;
 
271
         }
 
272
      }
 
273
   }
 
274
   else {
 
275
      for (i=0;i<n;i++) {
 
276
         GLchan *aptr = ALPHA_DRAW_ADDR( x[i], y[i] );
 
277
         *aptr = alpha;
 
278
      }
 
279
   }
 
280
}
 
281
 
 
282
 
 
283
 
 
284
void
 
285
_mesa_read_alpha_span( GLcontext *ctx,
 
286
                       GLuint n, GLint x, GLint y, GLchan rgba[][4] )
 
287
{
 
288
   GLchan *aptr = ALPHA_READ_ADDR( x, y );
 
289
   GLuint i;
 
290
   for (i=0;i<n;i++) {
 
291
      rgba[i][ACOMP] = *aptr++;
 
292
   }
 
293
}
 
294
 
 
295
 
 
296
void
 
297
_mesa_read_alpha_pixels( GLcontext *ctx,
 
298
                         GLuint n, const GLint x[], const GLint y[],
 
299
                         GLchan rgba[][4], const GLubyte mask[] )
 
300
{
 
301
   GLuint i;
 
302
   for (i=0;i<n;i++) {
 
303
      if (mask[i]) {
 
304
         GLchan *aptr = ALPHA_READ_ADDR( x[i], y[i] );
 
305
         rgba[i][ACOMP] = *aptr;
 
306
      }
 
307
   }
 
308
}