~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to render/mirect.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
Import upstream version 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $XFree86: xc/programs/Xserver/render/mirect.c,v 1.3 2000/12/08 07:52:05 keithp Exp $
 
3
 *
 
4
 * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
 
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
#ifdef HAVE_DIX_CONFIG_H
 
26
#include <dix-config.h>
 
27
#endif
 
28
 
 
29
#include "scrnintstr.h"
 
30
#include "gcstruct.h"
 
31
#include "pixmapstr.h"
 
32
#include "windowstr.h"
 
33
#include "mi.h"
 
34
#include "picturestr.h"
 
35
#include "mipict.h"
 
36
 
 
37
static void
 
38
miColorRects (PicturePtr    pDst,
 
39
              PicturePtr    pClipPict,
 
40
              xRenderColor  *color,
 
41
              int           nRect,
 
42
              xRectangle    *rects,
 
43
              int           xoff,
 
44
              int           yoff)
 
45
{
 
46
    ScreenPtr           pScreen = pDst->pDrawable->pScreen;
 
47
    CARD32              pixel;
 
48
    GCPtr               pGC;
 
49
    CARD32              tmpval[5];
 
50
    RegionPtr           pClip;
 
51
    unsigned long       mask;
 
52
 
 
53
    miRenderColorToPixel (pDst->pFormat, color, &pixel);
 
54
 
 
55
    pGC = GetScratchGC (pDst->pDrawable->depth, pScreen);
 
56
    if (!pGC)
 
57
        return;
 
58
    tmpval[0] = GXcopy;
 
59
    tmpval[1] = pixel;
 
60
    tmpval[2] = pDst->subWindowMode;
 
61
    mask = GCFunction | GCForeground | GCSubwindowMode;
 
62
    if (pClipPict->clientClipType == CT_REGION)
 
63
    {
 
64
        tmpval[3] = pDst->clipOrigin.x - xoff;
 
65
        tmpval[4] = pDst->clipOrigin.y - yoff;
 
66
        mask |= GCClipXOrigin|GCClipYOrigin;
 
67
        
 
68
        pClip = REGION_CREATE (pScreen, NULL, 1);
 
69
        REGION_COPY (pScreen, pClip,
 
70
                     (RegionPtr) pClipPict->clientClip);
 
71
        (*pGC->funcs->ChangeClip) (pGC, CT_REGION, pClip, 0);
 
72
    }
 
73
 
 
74
    ChangeGC (pGC, mask, tmpval);
 
75
    ValidateGC (pDst->pDrawable, pGC);
 
76
    if (xoff || yoff)
 
77
    {
 
78
        int     i;
 
79
        for (i = 0; i < nRect; i++)
 
80
        {
 
81
            rects[i].x -= xoff;
 
82
            rects[i].y -= yoff;
 
83
        }
 
84
    }
 
85
    (*pGC->ops->PolyFillRect) (pDst->pDrawable, pGC, nRect, rects);
 
86
    if (xoff || yoff)
 
87
    {
 
88
        int     i;
 
89
        for (i = 0; i < nRect; i++)
 
90
        {
 
91
            rects[i].x += xoff;
 
92
            rects[i].y += yoff;
 
93
        }
 
94
    }
 
95
    FreeScratchGC (pGC);
 
96
}
 
97
 
 
98
void
 
99
miCompositeRects (CARD8         op,
 
100
                  PicturePtr    pDst,
 
101
                  xRenderColor  *color,
 
102
                  int           nRect,
 
103
                  xRectangle    *rects)
 
104
{
 
105
    ScreenPtr           pScreen = pDst->pDrawable->pScreen;
 
106
    
 
107
    if (color->alpha == 0xffff)
 
108
    {
 
109
        if (op == PictOpOver)
 
110
            op = PictOpSrc;
 
111
    }
 
112
    if (op == PictOpClear)
 
113
        color->red = color->green = color->blue = color->alpha = 0;
 
114
    
 
115
    if (op == PictOpSrc || op == PictOpClear)
 
116
    {
 
117
        miColorRects (pDst, pDst, color, nRect, rects, 0, 0);
 
118
        if (pDst->alphaMap)
 
119
            miColorRects (pDst->alphaMap, pDst,
 
120
                          color, nRect, rects,
 
121
                          pDst->alphaOrigin.x,
 
122
                          pDst->alphaOrigin.y);
 
123
    }
 
124
    else
 
125
    {
 
126
        PictFormatPtr   rgbaFormat;
 
127
        PixmapPtr       pPixmap;
 
128
        PicturePtr      pSrc;
 
129
        xRectangle      one;
 
130
        int             error;
 
131
        Pixel           pixel;
 
132
        GCPtr           pGC;
 
133
        CARD32          tmpval[2];
 
134
 
 
135
        rgbaFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8);
 
136
        if (!rgbaFormat)
 
137
            goto bail1;
 
138
        
 
139
        pPixmap = (*pScreen->CreatePixmap) (pScreen, 1, 1,
 
140
                                            rgbaFormat->depth);
 
141
        if (!pPixmap)
 
142
            goto bail2;
 
143
        
 
144
        miRenderColorToPixel (rgbaFormat, color, &pixel);
 
145
 
 
146
        pGC = GetScratchGC (rgbaFormat->depth, pScreen);
 
147
        if (!pGC)
 
148
            goto bail3;
 
149
        tmpval[0] = GXcopy;
 
150
        tmpval[1] = pixel;
 
151
 
 
152
        ChangeGC (pGC, GCFunction | GCForeground, tmpval);
 
153
        ValidateGC (&pPixmap->drawable, pGC);
 
154
        one.x = 0;
 
155
        one.y = 0;
 
156
        one.width = 1;
 
157
        one.height = 1;
 
158
        (*pGC->ops->PolyFillRect) (&pPixmap->drawable, pGC, 1, &one);
 
159
        
 
160
        tmpval[0] = xTrue;
 
161
        pSrc = CreatePicture (0, &pPixmap->drawable, rgbaFormat,
 
162
                              CPRepeat, tmpval, 0, &error);
 
163
                              
 
164
        if (!pSrc)
 
165
            goto bail4;
 
166
 
 
167
        while (nRect--)
 
168
        {
 
169
            CompositePicture (op, pSrc, 0, pDst, 0, 0, 0, 0, 
 
170
                              rects->x,
 
171
                              rects->y,
 
172
                              rects->width,
 
173
                              rects->height);
 
174
            rects++;
 
175
        }
 
176
 
 
177
        FreePicture ((pointer) pSrc, 0);
 
178
bail4:
 
179
        FreeScratchGC (pGC);
 
180
bail3:
 
181
        (*pScreen->DestroyPixmap) (pPixmap);
 
182
bail2:
 
183
bail1:
 
184
        ;
 
185
    }
 
186
}