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

« back to all changes in this revision

Viewing changes to render/miglyph.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/miglyph.c,v 1.4 2000/11/20 07:13:13 keithp Exp $
 
3
 *
 
4
 * Copyright Ā© 2000 SuSE, 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 SuSE not be used in advertising or
 
11
 * publicity pertaining to distribution of the software without specific,
 
12
 * written prior permission.  SuSE makes no representations about the
 
13
 * suitability of this software for any purpose.  It is provided "as is"
 
14
 * without express or implied warranty.
 
15
 *
 
16
 * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
 
17
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
 
18
 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
19
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 
20
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
 
21
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
22
 *
 
23
 * Author:  Keith Packard, SuSE, Inc.
 
24
 */
 
25
 
 
26
#ifdef HAVE_DIX_CONFIG_H
 
27
#include <dix-config.h>
 
28
#endif
 
29
 
 
30
#include "scrnintstr.h"
 
31
#include "gcstruct.h"
 
32
#include "pixmapstr.h"
 
33
#include "windowstr.h"
 
34
#include "mi.h"
 
35
#include "picturestr.h"
 
36
#include "mipict.h"
 
37
 
 
38
Bool
 
39
miRealizeGlyph (ScreenPtr pScreen,
 
40
                GlyphPtr  glyph)
 
41
{
 
42
    return TRUE;
 
43
}
 
44
 
 
45
void
 
46
miUnrealizeGlyph (ScreenPtr pScreen,
 
47
                  GlyphPtr  glyph)
 
48
{
 
49
}
 
50
 
 
51
void
 
52
miGlyphExtents (int             nlist,
 
53
                GlyphListPtr    list,
 
54
                GlyphPtr        *glyphs,
 
55
                BoxPtr          extents)
 
56
{
 
57
    int         x1, x2, y1, y2;
 
58
    int         n;
 
59
    GlyphPtr    glyph;
 
60
    int         x, y;
 
61
    
 
62
    x = 0;
 
63
    y = 0;
 
64
    extents->x1 = MAXSHORT;
 
65
    extents->x2 = MINSHORT;
 
66
    extents->y1 = MAXSHORT;
 
67
    extents->y2 = MINSHORT;
 
68
    while (nlist--)
 
69
    {
 
70
        x += list->xOff;
 
71
        y += list->yOff;
 
72
        n = list->len;
 
73
        list++;
 
74
        while (n--)
 
75
        {
 
76
            glyph = *glyphs++;
 
77
            x1 = x - glyph->info.x;
 
78
            if (x1 < MINSHORT)
 
79
                x1 = MINSHORT;
 
80
            y1 = y - glyph->info.y;
 
81
            if (y1 < MINSHORT)
 
82
                y1 = MINSHORT;
 
83
            x2 = x1 + glyph->info.width;
 
84
            if (x2 > MAXSHORT)
 
85
                x2 = MAXSHORT;
 
86
            y2 = y1 + glyph->info.height;
 
87
            if (y2 > MAXSHORT)
 
88
                y2 = MAXSHORT;
 
89
            if (x1 < extents->x1)
 
90
                extents->x1 = x1;
 
91
            if (x2 > extents->x2)
 
92
                extents->x2 = x2;
 
93
            if (y1 < extents->y1)
 
94
                extents->y1 = y1;
 
95
            if (y2 > extents->y2)
 
96
                extents->y2 = y2;
 
97
            x += glyph->info.xOff;
 
98
            y += glyph->info.yOff;
 
99
        }
 
100
    }
 
101
}
 
102
 
 
103
#define NeedsComponent(f) (PICT_FORMAT_A(f) != 0 && PICT_FORMAT_RGB(f) != 0)
 
104
 
 
105
void
 
106
miGlyphs (CARD8         op,
 
107
          PicturePtr    pSrc,
 
108
          PicturePtr    pDst,
 
109
          PictFormatPtr maskFormat,
 
110
          INT16         xSrc,
 
111
          INT16         ySrc,
 
112
          int           nlist,
 
113
          GlyphListPtr  list,
 
114
          GlyphPtr      *glyphs)
 
115
{
 
116
    PixmapPtr   pPixmap = 0;
 
117
    PicturePtr  pPicture;
 
118
    PixmapPtr   pMaskPixmap = 0;
 
119
    PicturePtr  pMask;
 
120
    ScreenPtr   pScreen = pDst->pDrawable->pScreen;
 
121
    int         width = 0, height = 0;
 
122
    int         x, y;
 
123
    int         xDst = list->xOff, yDst = list->yOff;
 
124
    int         n;
 
125
    GlyphPtr    glyph;
 
126
    int         error;
 
127
    BoxRec      extents;
 
128
    CARD32      component_alpha;
 
129
    
 
130
    if (maskFormat)
 
131
    {
 
132
        GCPtr       pGC;
 
133
        xRectangle  rect;
 
134
        
 
135
        miGlyphExtents (nlist, list, glyphs, &extents);
 
136
        
 
137
        if (extents.x2 <= extents.x1 || extents.y2 <= extents.y1)
 
138
            return;
 
139
        width = extents.x2 - extents.x1;
 
140
        height = extents.y2 - extents.y1;
 
141
        pMaskPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, maskFormat->depth);
 
142
        if (!pMaskPixmap)
 
143
            return;
 
144
        component_alpha = NeedsComponent(maskFormat->format);
 
145
        pMask = CreatePicture (0, &pMaskPixmap->drawable,
 
146
                               maskFormat, CPComponentAlpha, &component_alpha,
 
147
                               serverClient, &error);
 
148
        if (!pMask)
 
149
        {
 
150
            (*pScreen->DestroyPixmap) (pMaskPixmap);
 
151
            return;
 
152
        }
 
153
        pGC = GetScratchGC (pMaskPixmap->drawable.depth, pScreen);
 
154
        ValidateGC (&pMaskPixmap->drawable, pGC);
 
155
        rect.x = 0;
 
156
        rect.y = 0;
 
157
        rect.width = width;
 
158
        rect.height = height;
 
159
        (*pGC->ops->PolyFillRect) (&pMaskPixmap->drawable, pGC, 1, &rect);
 
160
        FreeScratchGC (pGC);
 
161
        x = -extents.x1;
 
162
        y = -extents.y1;
 
163
    }
 
164
    else
 
165
    {
 
166
        pMask = pDst;
 
167
        x = 0;
 
168
        y = 0;
 
169
    }
 
170
    pPicture = 0;
 
171
    while (nlist--)
 
172
    {
 
173
        x += list->xOff;
 
174
        y += list->yOff;
 
175
        n = list->len;
 
176
        while (n--)
 
177
        {
 
178
            glyph = *glyphs++;
 
179
            if (!pPicture)
 
180
            {
 
181
                pPixmap = GetScratchPixmapHeader (pScreen, glyph->info.width, glyph->info.height, 
 
182
                                                  list->format->depth,
 
183
                                                  list->format->depth, 
 
184
                                                  0, (pointer) (glyph + 1));
 
185
                if (!pPixmap)
 
186
                    return;
 
187
                component_alpha = NeedsComponent(list->format->format);
 
188
                pPicture = CreatePicture (0, &pPixmap->drawable, list->format,
 
189
                                          CPComponentAlpha, &component_alpha, 
 
190
                                          serverClient, &error);
 
191
                if (!pPicture)
 
192
                {
 
193
                    FreeScratchPixmapHeader (pPixmap);
 
194
                    return;
 
195
                }
 
196
            }
 
197
            (*pScreen->ModifyPixmapHeader) (pPixmap, 
 
198
                                            glyph->info.width, glyph->info.height,
 
199
                                            0, 0, -1, (pointer) (glyph + 1));
 
200
            pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 
201
            if (maskFormat)
 
202
            {
 
203
                CompositePicture (PictOpAdd,
 
204
                                  pPicture,
 
205
                                  None,
 
206
                                  pMask,
 
207
                                  0, 0,
 
208
                                  0, 0,
 
209
                                  x - glyph->info.x,
 
210
                                  y - glyph->info.y,
 
211
                                  glyph->info.width,
 
212
                                  glyph->info.height);
 
213
            }
 
214
            else
 
215
            {
 
216
                CompositePicture (op,
 
217
                                  pSrc,
 
218
                                  pPicture,
 
219
                                  pDst,
 
220
                                  xSrc + (x - glyph->info.x) - xDst,
 
221
                                  ySrc + (y - glyph->info.y) - yDst,
 
222
                                  0, 0,
 
223
                                  x - glyph->info.x,
 
224
                                  y - glyph->info.y,
 
225
                                  glyph->info.width,
 
226
                                  glyph->info.height);
 
227
            }
 
228
            x += glyph->info.xOff;
 
229
            y += glyph->info.yOff;
 
230
        }
 
231
        list++;
 
232
        if (pPicture)
 
233
        {
 
234
            FreeScratchPixmapHeader (pPixmap);
 
235
            FreePicture ((pointer) pPicture, 0);
 
236
            pPicture = 0;
 
237
            pPixmap = 0;
 
238
        }
 
239
    }
 
240
    if (maskFormat)
 
241
    {
 
242
        x = extents.x1;
 
243
        y = extents.y1;
 
244
        CompositePicture (op,
 
245
                          pSrc,
 
246
                          pMask,
 
247
                          pDst,
 
248
                          xSrc + x - xDst,
 
249
                          ySrc + y - yDst,
 
250
                          0, 0,
 
251
                          x, y,
 
252
                          width, height);
 
253
        FreePicture ((pointer) pMask, (XID) 0);
 
254
        (*pScreen->DestroyPixmap) (pMaskPixmap);
 
255
    }
 
256
}