Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / xwin / winsetsp.c
blob8a3faee93b6f66336559dd028dc1cd56ad808082
1 /*
2 *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
4 *Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 *"Software"), to deal in the Software without restriction, including
7 *without limitation the rights to use, copy, modify, merge, publish,
8 *distribute, sublicense, and/or sell copies of the Software, and to
9 *permit persons to whom the Software is furnished to do so, subject to
10 *the following conditions:
12 *The above copyright notice and this permission notice shall be
13 *included in all copies or substantial portions of the Software.
15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *Except as contained in this notice, the name of the XFree86 Project
24 *shall not be used in advertising or otherwise to promote the sale, use
25 *or other dealings in this Software without prior written authorization
26 *from the XFree86 Project.
28 * Authors: Harold L Hunt II
29 * Alan Hourihane <alanh@fairlite.demon.co.uk>
32 #ifdef HAVE_XWIN_CONFIG_H
33 #include <xwin-config.h>
34 #endif
35 #include "win.h"
39 * References to external symbols
42 extern int g_iPixmapPrivateIndex;
43 extern int g_iGCPrivateIndex;
44 extern int g_copyROP[];
47 /* See Porting Layer Definition - p. 55 */
48 void
49 winSetSpansNativeGDI (DrawablePtr pDrawable,
50 GCPtr pGC,
51 char *pSrcs,
52 DDXPointPtr pPoints,
53 int *piWidths,
54 int iSpans,
55 int fSorted)
57 winGCPriv(pGC);
58 PixmapPtr pPixmap = NULL;
59 winPrivPixmapPtr pPixmapPriv = NULL;
60 HBITMAP hbmpOrig = NULL;
61 BITMAPINFO bmi;
62 HRGN hrgn = NULL, combined = NULL;
63 int nbox;
64 BoxPtr pbox;
66 nbox = REGION_NUM_RECTS (pGC->pCompositeClip);
67 pbox = REGION_RECTS (pGC->pCompositeClip);
69 if (!nbox) return;
71 combined = CreateRectRgn (pbox->x1, pbox->y1, pbox->x2, pbox->y2);
72 nbox--; pbox++;
73 while (nbox--)
75 hrgn = CreateRectRgn (pbox->x1, pbox->y1, pbox->x2, pbox->y2);
76 CombineRgn (combined, combined, hrgn, RGN_OR);
77 DeleteObject (hrgn);
78 hrgn = NULL;
79 pbox++;
82 /* Branch on the drawable type */
83 switch (pDrawable->type)
85 case DRAWABLE_PIXMAP:
87 SelectClipRgn (pGCPriv->hdcMem, combined);
88 DeleteObject (combined);
89 combined = NULL;
91 pPixmap = (PixmapPtr) pDrawable;
92 pPixmapPriv = winGetPixmapPriv (pPixmap);
94 /* Select the drawable pixmap into a DC */
95 hbmpOrig = SelectObject (pGCPriv->hdcMem, pPixmapPriv->hBitmap);
96 if (hbmpOrig == NULL)
97 FatalError ("winSetSpans - DRAWABLE_PIXMAP - SelectObject () "
98 "failed on pPixmapPriv->hBitmap\n");
100 while (iSpans--)
102 ZeroMemory (&bmi, sizeof (BITMAPINFO));
103 bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
104 bmi.bmiHeader.biWidth = *piWidths;
105 bmi.bmiHeader.biHeight = 1;
106 bmi.bmiHeader.biPlanes = 1;
107 bmi.bmiHeader.biBitCount = pDrawable->depth;
108 bmi.bmiHeader.biCompression = BI_RGB;
110 /* Setup color table for mono DIBs */
111 if (pDrawable->depth == 1)
113 bmi.bmiColors[1].rgbBlue = 255;
114 bmi.bmiColors[1].rgbGreen = 255;
115 bmi.bmiColors[1].rgbRed = 255;
118 StretchDIBits (pGCPriv->hdcMem,
119 pPoints->x, pPoints->y,
120 *piWidths, 1,
121 0, 0,
122 *piWidths, 1,
123 pSrcs,
124 (BITMAPINFO *) &bmi,
125 DIB_RGB_COLORS,
126 g_copyROP[pGC->alu]);
128 pSrcs += PixmapBytePad (*piWidths, pDrawable->depth);
129 pPoints++;
130 piWidths++;
133 /* Reset the clip region */
134 SelectClipRgn (pGCPriv->hdcMem, NULL);
136 /* Push the drawable pixmap out of the GC HDC */
137 SelectObject (pGCPriv->hdcMem, hbmpOrig);
138 break;
140 case DRAWABLE_WINDOW:
142 SelectClipRgn (pGCPriv->hdc, combined);
143 DeleteObject (combined);
144 combined = NULL;
146 while (iSpans--)
148 ZeroMemory (&bmi, sizeof (BITMAPINFO));
149 bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
150 bmi.bmiHeader.biWidth = *piWidths;
151 bmi.bmiHeader.biHeight = 1;
152 bmi.bmiHeader.biPlanes = 1;
153 bmi.bmiHeader.biBitCount = pDrawable->depth;
154 bmi.bmiHeader.biCompression = BI_RGB;
156 /* Setup color table for mono DIBs */
157 if (pDrawable->depth == 1)
159 bmi.bmiColors[1].rgbBlue = 255;
160 bmi.bmiColors[1].rgbGreen = 255;
161 bmi.bmiColors[1].rgbRed = 255;
164 StretchDIBits (pGCPriv->hdc,
165 pPoints->x, pPoints->y,
166 *piWidths, 1,
167 0, 0,
168 *piWidths, 1,
169 pSrcs,
170 (BITMAPINFO *) &bmi,
171 DIB_RGB_COLORS,
172 g_copyROP[pGC->alu]);
174 pSrcs += PixmapBytePad (*piWidths, pDrawable->depth);
175 pPoints++;
176 piWidths++;
179 /* Reset the clip region */
180 SelectClipRgn (pGCPriv->hdc, NULL);
181 break;
183 case UNDRAWABLE_WINDOW:
184 FatalError ("\nwinSetSpansNativeGDI - UNDRAWABLE_WINDOW\n\n");
185 break;
187 case DRAWABLE_BUFFER:
188 FatalError ("\nwinSetSpansNativeGDI - DRAWABLE_BUFFER\n\n");
189 break;
191 default:
192 FatalError ("\nwinSetSpansNativeGDI - Unknown drawable type\n\n");
193 break;