~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_xmesa.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
/* $XFree86: xc/lib/GL/mesa/src/drv/gamma/gamma_xmesa.c,v 1.14 2002/10/30 12:51:30 alanh Exp $ */
 
2
/*
 
3
 * Copyright 2001 by Alan Hourihane.
 
4
 *
 
5
 * Permission to use, copy, modify, distribute, and sell this software and its
 
6
 * documentation for any purpose is hereby granted without fee, provided that
 
7
 * the above copyright notice appear in all copies and that both that
 
8
 * copyright notice and this permission notice appear in supporting
 
9
 * documentation, and that the name of Alan Hourihane not be used in
 
10
 * advertising or publicity pertaining to distribution of the software without
 
11
 * specific, written prior permission.  Alan Hourihane makes no representations
 
12
 * about the suitability of this software for any purpose.  It is provided
 
13
 * "as is" without express or implied warranty.
 
14
 *
 
15
 * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
16
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
17
 * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
18
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
19
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
20
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
21
 * PERFORMANCE OF THIS SOFTWARE.
 
22
 *
 
23
 * Authors:  Alan Hourihane, <alanh@tungstengraphics.com>
 
24
 *
 
25
 * 3DLabs Gamma driver
 
26
 */
 
27
 
 
28
#include "gamma_context.h"
 
29
#include "gamma_vb.h"
 
30
#include "context.h"
 
31
#include "mmath.h"
 
32
#include "matrix.h"
 
33
#include "glint_dri.h"
 
34
 
 
35
#include "swrast/swrast.h"
 
36
#include "swrast_setup/swrast_setup.h"
 
37
#include "tnl/tnl.h"
 
38
#include "array_cache/acache.h"
 
39
 
 
40
static GLboolean 
 
41
gammaInitDriver(__DRIscreenPrivate *sPriv)
 
42
{
 
43
    sPriv->private = (void *) gammaCreateScreen( sPriv );
 
44
 
 
45
    if (!sPriv->private) {
 
46
        gammaDestroyScreen( sPriv );
 
47
        return GL_FALSE;
 
48
    }
 
49
 
 
50
    return GL_TRUE;
 
51
}
 
52
 
 
53
static void 
 
54
gammaDestroyContext(__DRIcontextPrivate *driContextPriv)
 
55
{
 
56
    gammaContextPtr gmesa = (gammaContextPtr)driContextPriv->driverPrivate;
 
57
 
 
58
    if (gmesa) {
 
59
      _swsetup_DestroyContext( gmesa->glCtx );
 
60
      _tnl_DestroyContext( gmesa->glCtx );
 
61
      _ac_DestroyContext( gmesa->glCtx );
 
62
      _swrast_DestroyContext( gmesa->glCtx );
 
63
 
 
64
      gammaFreeVB( gmesa->glCtx );
 
65
 
 
66
      /* free the Mesa context */
 
67
      gmesa->glCtx->DriverCtx = NULL;
 
68
      _mesa_destroy_context(gmesa->glCtx);
 
69
 
 
70
      Xfree(gmesa);
 
71
      driContextPriv->driverPrivate = NULL;
 
72
    }
 
73
}
 
74
 
 
75
 
 
76
static GLboolean
 
77
gammaCreateBuffer( Display *dpy,
 
78
                   __DRIscreenPrivate *driScrnPriv,
 
79
                   __DRIdrawablePrivate *driDrawPriv,
 
80
                   const __GLcontextModes *mesaVis,
 
81
                   GLboolean isPixmap )
 
82
{
 
83
   if (isPixmap) {
 
84
      return GL_FALSE; /* not implemented */
 
85
   }
 
86
   else {
 
87
      driDrawPriv->driverPrivate = (void *) 
 
88
         _mesa_create_framebuffer(mesaVis,
 
89
                                  GL_FALSE,  /* software depth buffer? */
 
90
                                  mesaVis->stencilBits > 0,
 
91
                                  mesaVis->accumRedBits > 0,
 
92
                                  mesaVis->alphaBits > 0
 
93
                                  );
 
94
      return (driDrawPriv->driverPrivate != NULL);
 
95
   }
 
96
}
 
97
 
 
98
 
 
99
static void
 
100
gammaDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 
101
{
 
102
   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
 
103
}
 
104
 
 
105
static void
 
106
gammaSwapBuffers(Display *dpy, void *drawablePrivate)
 
107
{
 
108
   __DRIdrawablePrivate *dPriv = (__DRIdrawablePrivate *) drawablePrivate;
 
109
   (void) dpy;
 
110
 
 
111
   if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
 
112
    gammaContextPtr gmesa;
 
113
    __DRIscreenPrivate *driScrnPriv;
 
114
    GLcontext *ctx;
 
115
 
 
116
    gmesa = (gammaContextPtr) dPriv->driContextPriv->driverPrivate;
 
117
    ctx = gmesa->glCtx;
 
118
    driScrnPriv = gmesa->driScreen;
 
119
 
 
120
    VALIDATE_DRAWABLE_INFO(gmesa);
 
121
 
 
122
    /* Flush any partially filled buffers */
 
123
    FLUSH_DMA_BUFFER(gmesa);
 
124
 
 
125
    DRM_SPINLOCK(&driScrnPriv->pSAREA->drawable_lock,
 
126
                     driScrnPriv->drawLockID);
 
127
    VALIDATE_DRAWABLE_INFO_NO_LOCK(gmesa);
 
128
 
 
129
    if (gmesa->EnabledFlags & GAMMA_BACK_BUFFER) {
 
130
        int src, dst, x0, y0, x1, h;
 
131
        int i;
 
132
        int nRect = dPriv->numClipRects;
 
133
        XF86DRIClipRectPtr pRect = dPriv->pClipRects;
 
134
        __DRIscreenPrivate *driScrnPriv = gmesa->driScreen;
 
135
        GLINTDRIPtr gDRIPriv = (GLINTDRIPtr)driScrnPriv->pDevPriv;
 
136
 
 
137
        CHECK_DMA_BUFFER(gmesa, 2);
 
138
        WRITE(gmesa->buf, FBReadMode, (gmesa->FBReadMode |
 
139
                                         FBReadSrcEnable));
 
140
        WRITE(gmesa->buf, LBWriteMode, LBWriteModeDisable);
 
141
 
 
142
        for (i = 0; i < nRect; i++, pRect++) {
 
143
            x0 = pRect->x1;
 
144
            x1 = pRect->x2;
 
145
            h  = pRect->y2 - pRect->y1;
 
146
 
 
147
            y0 = driScrnPriv->fbHeight - (pRect->y1+h);
 
148
            if (gDRIPriv->numMultiDevices == 2) 
 
149
                src = (y0/2)*driScrnPriv->fbWidth+x0;
 
150
            else
 
151
                src = y0*driScrnPriv->fbWidth+x0;
 
152
 
 
153
            y0 += driScrnPriv->fbHeight;
 
154
            if (gDRIPriv->numMultiDevices == 2) 
 
155
                dst = (y0/2)*driScrnPriv->fbWidth+x0;
 
156
            else
 
157
                dst = y0*driScrnPriv->fbWidth+x0;
 
158
 
 
159
            CHECK_DMA_BUFFER(gmesa, 9);
 
160
            WRITE(gmesa->buf, StartXDom,       x0<<16);   /* X0dest */
 
161
            WRITE(gmesa->buf, StartY,          y0<<16);   /* Y0dest */
 
162
            WRITE(gmesa->buf, StartXSub,       x1<<16);   /* X1dest */
 
163
            WRITE(gmesa->buf, GLINTCount,      h);        /* H */
 
164
            WRITE(gmesa->buf, dY,              1<<16);    /* ydir */
 
165
            WRITE(gmesa->buf, dXDom,           0<<16);
 
166
            WRITE(gmesa->buf, dXSub,           0<<16);
 
167
            WRITE(gmesa->buf, FBSourceOffset, (dst-src));
 
168
            WRITE(gmesa->buf, Render,          0x00040048); /* NOT_DONE */
 
169
        }
 
170
 
 
171
        /*
 
172
        ** NOTE: FBSourceOffset (above) is backwards from what is
 
173
        ** described in the manual (i.e., dst-src instead of src-dst)
 
174
        ** due to our using the bottom-left window origin instead of the
 
175
        ** top-left window origin.
 
176
        */
 
177
 
 
178
        /* Restore FBReadMode */
 
179
        CHECK_DMA_BUFFER(gmesa, 2);
 
180
        WRITE(gmesa->buf, FBReadMode, (gmesa->FBReadMode |
 
181
                                       gmesa->AB_FBReadMode));
 
182
        WRITE(gmesa->buf, LBWriteMode, LBWriteModeEnable);
 
183
    }
 
184
 
 
185
    if (gmesa->EnabledFlags & GAMMA_BACK_BUFFER)
 
186
        PROCESS_DMA_BUFFER_TOP_HALF(gmesa);
 
187
 
 
188
    DRM_SPINUNLOCK(&driScrnPriv->pSAREA->drawable_lock,
 
189
                       driScrnPriv->drawLockID);
 
190
    VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gmesa);
 
191
 
 
192
    if (gmesa->EnabledFlags & GAMMA_BACK_BUFFER)
 
193
        PROCESS_DMA_BUFFER_BOTTOM_HALF(gmesa);
 
194
  } else {
 
195
    _mesa_problem(NULL, "gammaSwapBuffers: drawable has no context!\n");
 
196
  }
 
197
}
 
198
 
 
199
static GLboolean 
 
200
gammaMakeCurrent(__DRIcontextPrivate *driContextPriv,
 
201
                 __DRIdrawablePrivate *driDrawPriv,
 
202
                 __DRIdrawablePrivate *driReadPriv)
 
203
{
 
204
    if (driContextPriv) {
 
205
        GET_CURRENT_CONTEXT(ctx);
 
206
        gammaContextPtr oldGammaCtx = ctx ? GAMMA_CONTEXT(ctx) : NULL;
 
207
        gammaContextPtr newGammaCtx = (gammaContextPtr) driContextPriv->driverPrivate;
 
208
 
 
209
        if ( newGammaCtx != oldGammaCtx ) {
 
210
            newGammaCtx->dirty = ~0;
 
211
        }
 
212
 
 
213
        if (newGammaCtx->driDrawable != driDrawPriv) {
 
214
            newGammaCtx->driDrawable = driDrawPriv;
 
215
            gammaUpdateWindow ( newGammaCtx->glCtx );
 
216
            gammaUpdateViewportOffset( newGammaCtx->glCtx );
 
217
        }
 
218
 
 
219
#if 0
 
220
        newGammaCtx->Window &= ~W_GIDMask;
 
221
        newGammaCtx->Window |= (driDrawPriv->index << 5);
 
222
        CHECK_DMA_BUFFER(newGammaCtx,1);
 
223
        WRITE(newGammaCtx->buf, GLINTWindow, newGammaCtx->Window);
 
224
#endif
 
225
 
 
226
newGammaCtx->new_state |= GAMMA_NEW_WINDOW; /* FIXME */
 
227
 
 
228
        _mesa_make_current2( newGammaCtx->glCtx, 
 
229
                          (GLframebuffer *) driDrawPriv->driverPrivate,
 
230
                          (GLframebuffer *) driReadPriv->driverPrivate );
 
231
 
 
232
        if (!newGammaCtx->glCtx->Viewport.Width) {
 
233
            _mesa_set_viewport(newGammaCtx->glCtx, 0, 0, 
 
234
                                        driDrawPriv->w, driDrawPriv->h);
 
235
        }
 
236
    } else {
 
237
        _mesa_make_current( 0, 0 );
 
238
    }
 
239
    return GL_TRUE;
 
240
}
 
241
 
 
242
 
 
243
static GLboolean 
 
244
gammaUnbindContext( __DRIcontextPrivate *driContextPriv )
 
245
{
 
246
   return GL_TRUE;
 
247
}
 
248
 
 
249
static GLboolean
 
250
gammaOpenFullScreen(__DRIcontextPrivate *driContextPriv)
 
251
{
 
252
    return GL_TRUE;
 
253
}
 
254
 
 
255
static GLboolean
 
256
gammaCloseFullScreen(__DRIcontextPrivate *driContextPriv)
 
257
{
 
258
    return GL_TRUE;
 
259
}
 
260
 
 
261
 
 
262
static struct __DriverAPIRec gammaAPI = {
 
263
   gammaInitDriver,
 
264
   gammaDestroyScreen,
 
265
   gammaCreateContext,
 
266
   gammaDestroyContext,
 
267
   gammaCreateBuffer,
 
268
   gammaDestroyBuffer,
 
269
   gammaSwapBuffers,
 
270
   gammaMakeCurrent,
 
271
   gammaUnbindContext,
 
272
   gammaOpenFullScreen,
 
273
   gammaCloseFullScreen
 
274
};
 
275
 
 
276
 
 
277
 
 
278
/*
 
279
 * This is the bootstrap function for the driver.
 
280
 * The __driCreateScreen name is the symbol that libGL.so fetches.
 
281
 * Return:  pointer to a __DRIscreenPrivate.
 
282
 */
 
283
void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
 
284
                        int numConfigs, __GLXvisualConfig *config)
 
285
{
 
286
   __DRIscreenPrivate *psp;
 
287
   psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &gammaAPI);
 
288
   return (void *) psp;
 
289
}
 
290
 
 
291
void __driRegisterExtensions(void)
 
292
{
 
293
   /* No extensions */
 
294
}
 
295
 
 
296