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