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

« back to all changes in this revision

Viewing changes to unix/xc/lib/GL/mesa/src/drv/gamma/gamma_macros.h

  • 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
/* $XFree86: xc/lib/GL/mesa/src/drv/gamma/gamma_macros.h,v 1.5 2002/02/22 21:33:02 dawes Exp $ */
 
2
/**************************************************************************
 
3
 
 
4
Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
 
5
All Rights Reserved.
 
6
 
 
7
Permission is hereby granted, free of charge, to any person obtaining a
 
8
copy of this software and associated documentation files (the
 
9
"Software"), to deal in the Software without restriction, including
 
10
without limitation the rights to use, copy, modify, merge, publish,
 
11
distribute, sub license, and/or sell copies of the Software, and to
 
12
permit persons to whom the Software is furnished to do so, subject to
 
13
the following conditions:
 
14
 
 
15
The above copyright notice and this permission notice (including the
 
16
next paragraph) shall be included in all copies or substantial portions
 
17
of the Software.
 
18
 
 
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
20
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
21
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 
22
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
 
23
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 
24
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 
25
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
26
 
 
27
**************************************************************************/
 
28
 
 
29
/*
 
30
 * Authors:
 
31
 *   Kevin E. Martin <kevin@precisioninsight.com>
 
32
 *
 
33
 */
 
34
 
 
35
#ifndef _GAMMA_MACROS_H_
 
36
#define _GAMMA_MACROS_H_
 
37
 
 
38
#ifdef GLX_DIRECT_RENDERING
 
39
 
 
40
#define DEBUG_DRMDMA
 
41
#define DEBUG_ERRORS
 
42
#define DEBUG_COMMANDS_NOT
 
43
#define DEBUG_VERBOSE_NOT
 
44
#define DEBUG_VERBOSE_EXTRA_NOT
 
45
 
 
46
#define RANDOMIZE_COLORS_NOT
 
47
#define TURN_OFF_CLEARS_NOT
 
48
#define CULL_ALL_PRIMS_NOT
 
49
#define TURN_OFF_DEPTH_NOT
 
50
#define TURN_OFF_BLEND_NOT
 
51
#define FAST_CLEAR_4_NOT
 
52
#define FORCE_DEPTH32_NOT
 
53
#define DONT_SEND_DMA_NOT
 
54
#define TURN_OFF_FCP_NOT
 
55
#define TURN_OFF_TEXTURES_NOT
 
56
#define DO_VALIDATE
 
57
 
 
58
#define GAMMA_DMA_BUFFER_SIZE 4096
 
59
 
 
60
#if 0
 
61
#define GAMMA_DMA_SEND_FLAGS    DRM_DMA_PRIORITY
 
62
#define GAMMA_DMA_SEND_FLAGS    DRM_DMA_BLOCK
 
63
#else
 
64
/* MUST use non-blocking dma flags for drawable lock routines */
 
65
#define GAMMA_DMA_SEND_FLAGS    0
 
66
#endif
 
67
 
 
68
#if 0
 
69
#define GAMMA_DMA_GET_FLAGS     \
 
70
    (DRM_DMA_SMALLER_OK | DRM_DMA_LARGER_OK | DRM_DMA_WAIT)
 
71
#else
 
72
#define GAMMA_DMA_GET_FLAGS     DRM_DMA_WAIT
 
73
#endif
 
74
 
 
75
#if defined(DEBUG_DRMDMA) || defined(DEBUG_COMMANDS) || defined(DEBUG_VERBOSE)
 
76
#include <stdio.h>
 
77
#endif
 
78
 
 
79
/* Note: The argument to DEBUG_GLCMDS() _must_ be enclosed in parenthesis */
 
80
#ifdef DEBUG_VERBOSE
 
81
#define DEBUG_GLCMDS(s) printf s
 
82
#else
 
83
#define DEBUG_GLCMDS(s)
 
84
#endif
 
85
 
 
86
/* Note: The argument to DEBUG_DMACMDS() _must_ be enclosed in parenthesis */
 
87
#ifdef DEBUG_DRMDMA
 
88
#define DEBUG_DMACMDS(s) printf s
 
89
#else
 
90
#define DEBUG_DMACMDS(s)
 
91
#endif
 
92
 
 
93
/* Note: The argument to DEBUG_WRITE() _must_ be enclosed in parenthesis */
 
94
#ifdef DEBUG_COMMANDS
 
95
#define DEBUG_WRITE(s) printf s
 
96
#else
 
97
#define DEBUG_WRITE(s)
 
98
#endif
 
99
 
 
100
/* Note: The argument to DEBUG_ERROR() _must_ be enclosed in parenthesis */
 
101
#ifdef DEBUG_ERRORS
 
102
#define DEBUG_ERROR(s) printf s
 
103
#else
 
104
#define DEBUG_ERROR(s)
 
105
#endif
 
106
 
 
107
#define WRITEV(buf,val1,val2,val3,val4)                               \
 
108
do {                                                                  \
 
109
    buf++->i = 0x9C008300;                        \
 
110
    buf++->f = val1;                                                   \
 
111
    buf++->f = val2;                                                   \
 
112
    buf++->f = val3;                                                   \
 
113
    buf++->f = val4;                                                   \
 
114
} while (0)
 
115
 
 
116
#define WRITE(buf,reg,val)                                            \
 
117
do {                                                                  \
 
118
    buf++->i = Glint##reg##Tag;                                       \
 
119
    buf++->i = val;                                                   \
 
120
    DEBUG_WRITE(("WRITE(buf, %s, 0x%08x);\n", #reg, (int)val));       \
 
121
} while (0)
 
122
 
 
123
#define WRITEF(buf,reg,val)                                           \
 
124
do {                                                                  \
 
125
    buf++->i = Glint##reg##Tag;                                       \
 
126
    buf++->f = val;                                                   \
 
127
    DEBUG_WRITE(("WRITEF(buf, %s, %f);\n", #reg, (float)val));        \
 
128
} while (0)
 
129
 
 
130
#define CHECK_WC_DMA_BUFFER(gcp,n)                                    \
 
131
do {                                                                  \
 
132
    (gcp)->WCbufCount += (n<<1);                                      \
 
133
} while (0)
 
134
 
 
135
#define CHECK_DMA_BUFFER(gcp,n)                                   \
 
136
do {                                                                  \
 
137
    if ((gcp)->bufCount+(n<<1) >= (gcp)->bufSize)                     \
 
138
        PROCESS_DMA_BUFFER(gcp);                                  \
 
139
    (gcp)->bufCount += (n<<1);                                        \
 
140
} while (0)
 
141
 
 
142
#define CHECK_DMA_BUFFER2(gcp,n)                                   \
 
143
do {                                                                  \
 
144
    if ((gcp)->bufCount+n >= (gcp)->bufSize)                     \
 
145
        PROCESS_DMA_BUFFER(gcp);                                  \
 
146
    (gcp)->bufCount += n;                                        \
 
147
} while (0)
 
148
 
 
149
#define FLUSH_DMA_BUFFER(gcp)                                     \
 
150
do {                                                                  \
 
151
   if (gcp->bufCount)                                                \
 
152
        PROCESS_DMA_BUFFER(gcp);                                  \
 
153
} while (0)
 
154
 
 
155
#ifdef DONT_SEND_DMA
 
156
#define GET_DMA(fd, hHWCtx, n, idx, size)
 
157
#define SEND_DMA(fd, hHWCtx,n, idx, cnt)
 
158
#else
 
159
#define GET_DMA(fd, hHWCtx, n, idx, size)                                  \
 
160
do {                                                                       \
 
161
    drmDMAReq dma;                                                         \
 
162
    int retcode, i;                                                        \
 
163
                                                                           \
 
164
    dma.context       = (hHWCtx);                                          \
 
165
    dma.send_count    = 0;                                                 \
 
166
    dma.send_list     = NULL;                                              \
 
167
    dma.send_sizes    = NULL;                                              \
 
168
    dma.flags         = GAMMA_DMA_GET_FLAGS;                               \
 
169
    dma.request_count = (n);                                               \
 
170
    dma.request_size  = GAMMA_DMA_BUFFER_SIZE;                             \
 
171
    dma.request_list  = (idx);                                             \
 
172
    dma.request_sizes = (size);                                            \
 
173
                                                                           \
 
174
    do {                                                                   \
 
175
        if ((retcode = drmDMA((fd), &dma))) {                              \
 
176
            DEBUG_DMACMDS(("drmDMA returned %d\n", retcode));              \
 
177
        }                                                                  \
 
178
    } while (!(dma).granted_count);                                        \
 
179
                                                                           \
 
180
    for (i = 0; i < (n); i++) {                                            \
 
181
        (size)[i] >>= 2; /* Convert from bytes to words */                 \
 
182
    }                                                                      \
 
183
} while (0)
 
184
 
 
185
#define SEND_DMA(fd, hHWCtx, n, idx, cnt)                                  \
 
186
do {                                                                       \
 
187
    drmDMAReq dma;                                                         \
 
188
    int retcode, i;                                                        \
 
189
                                                                           \
 
190
    for (i = 0; i < (n); i++) {                                            \
 
191
        (cnt)[i] <<= 2; /* Convert from words to bytes */                  \
 
192
    }                                                                      \
 
193
                                                                           \
 
194
    dma.context       = (hHWCtx);                                          \
 
195
    dma.send_count    = 1;                                                 \
 
196
    dma.send_list     = (idx);                                             \
 
197
    dma.send_sizes    = (cnt);                                             \
 
198
    dma.flags         = GAMMA_DMA_SEND_FLAGS;                              \
 
199
    dma.request_count = 0;                                                 \
 
200
    dma.request_size  = 0;                                                 \
 
201
    dma.request_list  = NULL;                                              \
 
202
    dma.request_sizes = NULL;                                              \
 
203
                                                                           \
 
204
    if ((retcode = drmDMA((fd), &dma))) {                                  \
 
205
        DEBUG_DMACMDS(("drmDMA returned %d\n", retcode));                  \
 
206
    }                                                                      \
 
207
                                                                           \
 
208
    for (i = 0; i < (n); i++) {                                            \
 
209
        (cnt)[i] = 0;                                                      \
 
210
    }                                                                      \
 
211
} while (0)
 
212
#endif
 
213
 
 
214
#define GET_FIRST_DMA(fd, hHWCtx, n, idx, size, buf, cnt, gPriv)           \
 
215
do {                                                                       \
 
216
    int i;                                                                 \
 
217
                                                                           \
 
218
    GET_DMA(fd, hHWCtx, n, idx, size);                                     \
 
219
                                                                           \
 
220
    for (i = 0; i < (n); i++) {                                            \
 
221
        (buf)[i] = (dmaBuf)(gPriv)->bufs->list[(idx)[i]].address;          \
 
222
        (cnt)[i] = 0;                                                      \
 
223
    }                                                                      \
 
224
} while (0)
 
225
 
 
226
#define PROCESS_DMA_BUFFER_TOP_HALF(gcp)                                   \
 
227
do {                                                                       \
 
228
    SEND_DMA((gcp)->driFd,                        \
 
229
             (gcp)->hHWContext, 1, &(gcp)->bufIndex, &(gcp)->bufCount);    \
 
230
} while (0)
 
231
 
 
232
#define PROCESS_DMA_BUFFER_BOTTOM_HALF(gcp)                                \
 
233
do {                                                                       \
 
234
    GET_DMA((gcp)->driFd,                         \
 
235
            (gcp)->hHWContext, 1, &(gcp)->bufIndex, &(gcp)->bufSize);      \
 
236
                                                                           \
 
237
    (gcp)->buf =                                                           \
 
238
        (dmaBuf)(gcp)->gammaScreen->bufs->list[(gcp)->bufIndex].address; \
 
239
} while (0)
 
240
 
 
241
#define PROCESS_DMA_BUFFER(gcp)                                        \
 
242
do {                                                                       \
 
243
    VALIDATE_DRAWABLE_INFO(gcp);                             \
 
244
    PROCESS_DMA_BUFFER_TOP_HALF(gcp);                                      \
 
245
    PROCESS_DMA_BUFFER_BOTTOM_HALF(gcp);                                   \
 
246
} while (0)
 
247
 
 
248
#ifdef DO_VALIDATE
 
249
#define VALIDATE_DRAWABLE_INFO_NO_LOCK(gcp)                            \
 
250
do {                                                                       \
 
251
    __DRIscreenPrivate *psp = gcp->driScreen;                          \
 
252
    __DRIdrawablePrivate *pdp = gcp->driDrawable;                      \
 
253
                                                                           \
 
254
    if (*(pdp->pStamp) != pdp->lastStamp) {                                \
 
255
        int old_index = pdp->index;                                        \
 
256
        while (*(pdp->pStamp) != pdp->lastStamp) {                         \
 
257
            DRI_VALIDATE_DRAWABLE_INFO_ONCE(gcp->display, psp->myNum, pdp);\
 
258
        }                                                                  \
 
259
        if (pdp->index != old_index) {                                     \
 
260
            gcp->Window &= ~W_GIDMask;                                     \
 
261
            gcp->Window |= (pdp->index << 5);                              \
 
262
            CHECK_WC_DMA_BUFFER(gcp, 1);                                   \
 
263
            WRITE(gcp->WCbuf, GLINTWindow, gcp->Window|(gcp->FrameCount<<9));\
 
264
        }                                                                  \
 
265
                                                                        \
 
266
        gammaUpdateViewportOffset( gcp->glCtx);                         \
 
267
                                                                           \
 
268
        if (pdp->numClipRects == 1 &&                                      \
 
269
            pdp->pClipRects->x1 ==  pdp->x &&                              \
 
270
            pdp->pClipRects->x2 == (pdp->x+pdp->w) &&                      \
 
271
            pdp->pClipRects->y1 ==  pdp->y &&                              \
 
272
            pdp->pClipRects->y2 == (pdp->y+pdp->h)) {                      \
 
273
            CHECK_WC_DMA_BUFFER(gcp, 1);                                   \
 
274
            WRITE(gcp->WCbuf, Rectangle2DControl, 0);                     \
 
275
            gcp->NotClipped = GL_TRUE;                                     \
 
276
        } else {                                                           \
 
277
            CHECK_WC_DMA_BUFFER(gcp, 1);                                   \
 
278
            WRITE(gcp->WCbuf, Rectangle2DControl, 1);                     \
 
279
            gcp->NotClipped = GL_FALSE;                                    \
 
280
        }                                                                  \
 
281
        gcp->WindowChanged = GL_TRUE;                                      \
 
282
                                                                           \
 
283
        if (gcp->WCbufCount) {                                             \
 
284
            SEND_DMA((gcp)->gammaScreen->driScreen->fd,                \
 
285
                     (gcp)->hHWContext, 1, &(gcp)->WCbufIndex,             \
 
286
                     &(gcp)->WCbufCount);                                  \
 
287
            (gcp)->WCbufIndex = -1;                                        \
 
288
        }                                                                  \
 
289
    }                                                                      \
 
290
} while (0)
 
291
 
 
292
#define VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gcp)                       \
 
293
do {                                                                       \
 
294
    if ((gcp)->WCbufIndex < 0) {                                           \
 
295
        GET_DMA((gcp)->gammaScreen->driScreen->fd,                     \
 
296
                (gcp)->hHWContext, 1, &(gcp)->WCbufIndex,                  \
 
297
                &(gcp)->WCbufSize);                                        \
 
298
                                                                           \
 
299
        (gcp)->WCbuf =                                                     \
 
300
            (dmaBuf)(gcp)->gammaScreen->bufs->                           \
 
301
                list[(gcp)->WCbufIndex].address;                           \
 
302
    }                                                                      \
 
303
} while (0)
 
304
 
 
305
#define VALIDATE_DRAWABLE_INFO(gcp)                                    \
 
306
do {                                                                       \
 
307
    __DRIscreenPrivate *psp = gcp->driScreen;                          \
 
308
if (gcp->driDrawable) { \
 
309
    DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);            \
 
310
    VALIDATE_DRAWABLE_INFO_NO_LOCK(gcp);                               \
 
311
    DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);          \
 
312
    VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gcp);                          \
 
313
} \
 
314
} while (0)
 
315
#else
 
316
#define VALIDATE_DRAWABLE_INFO(gcp)
 
317
#endif
 
318
 
 
319
#define CALC_LOG2(l2,s)                       \
 
320
do {                                          \
 
321
    int __s = s;                              \
 
322
    l2 = 0;                                   \
 
323
    while (__s > 1) { ++l2; __s >>= 1; }      \
 
324
} while (0)
 
325
 
 
326
#endif
 
327
 
 
328
#endif /* _GAMMA_MACROS_H_ */