Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /* |
2 | *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. | |
3 | * | |
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: | |
11 | * | |
12 | *The above copyright notice and this permission notice shall be | |
13 | *included in all copies or substantial portions of the Software. | |
14 | * | |
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. | |
22 | * | |
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. | |
27 | * | |
28 | * Authors: Harold L Hunt II | |
29 | * Alan Hourihane <alanh@fairlite.demon.co.uk> | |
30 | */ | |
31 | ||
32 | #ifdef HAVE_XWIN_CONFIG_H | |
33 | #include <xwin-config.h> | |
34 | #endif | |
35 | #include "win.h" | |
36 | ||
37 | /* See Porting Layer Definition - p. 55 */ | |
38 | void | |
39 | winSetSpansNativeGDI(DrawablePtr pDrawable, | |
40 | GCPtr pGC, | |
41 | char *pSrcs, | |
42 | DDXPointPtr pPoints, | |
43 | int *piWidths, int iSpans, int fSorted) | |
44 | { | |
45 | winGCPriv(pGC); | |
46 | PixmapPtr pPixmap = NULL; | |
47 | winPrivPixmapPtr pPixmapPriv = NULL; | |
48 | HBITMAP hbmpOrig = NULL; | |
49 | BITMAPINFO *pbmi; | |
50 | HRGN hrgn = NULL, combined = NULL; | |
51 | int nbox; | |
52 | BoxPtr pbox; | |
53 | ||
54 | nbox = RegionNumRects(pGC->pCompositeClip); | |
55 | pbox = RegionRects(pGC->pCompositeClip); | |
56 | ||
57 | if (!nbox) | |
58 | return; | |
59 | ||
60 | pbmi = malloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD)); | |
61 | ||
62 | combined = CreateRectRgn(pbox->x1, pbox->y1, pbox->x2, pbox->y2); | |
63 | nbox--; | |
64 | pbox++; | |
65 | while (nbox--) { | |
66 | hrgn = CreateRectRgn(pbox->x1, pbox->y1, pbox->x2, pbox->y2); | |
67 | CombineRgn(combined, combined, hrgn, RGN_OR); | |
68 | DeleteObject(hrgn); | |
69 | hrgn = NULL; | |
70 | pbox++; | |
71 | } | |
72 | ||
73 | /* Branch on the drawable type */ | |
74 | switch (pDrawable->type) { | |
75 | case DRAWABLE_PIXMAP: | |
76 | ||
77 | SelectClipRgn(pGCPriv->hdcMem, combined); | |
78 | DeleteObject(combined); | |
79 | combined = NULL; | |
80 | ||
81 | pPixmap = (PixmapPtr) pDrawable; | |
82 | pPixmapPriv = winGetPixmapPriv(pPixmap); | |
83 | ||
84 | /* Select the drawable pixmap into a DC */ | |
85 | hbmpOrig = SelectObject(pGCPriv->hdcMem, pPixmapPriv->hBitmap); | |
86 | if (hbmpOrig == NULL) | |
87 | FatalError("winSetSpans - DRAWABLE_PIXMAP - SelectObject () " | |
88 | "failed on pPixmapPriv->hBitmap\n"); | |
89 | ||
90 | while (iSpans--) { | |
91 | ZeroMemory(pbmi, sizeof(BITMAPINFO)); | |
92 | pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
93 | pbmi->bmiHeader.biWidth = *piWidths; | |
94 | pbmi->bmiHeader.biHeight = 1; | |
95 | pbmi->bmiHeader.biPlanes = 1; | |
96 | pbmi->bmiHeader.biBitCount = pDrawable->depth; | |
97 | pbmi->bmiHeader.biCompression = BI_RGB; | |
98 | ||
99 | /* Setup color table for mono DIBs */ | |
100 | if (pDrawable->depth == 1) { | |
101 | RGBQUAD *bmiColors = &(pbmi->bmiColors[0]); | |
102 | bmiColors[1].rgbBlue = 255; | |
103 | bmiColors[1].rgbGreen = 255; | |
104 | bmiColors[1].rgbRed = 255; | |
105 | } | |
106 | ||
107 | StretchDIBits(pGCPriv->hdcMem, | |
108 | pPoints->x, pPoints->y, | |
109 | *piWidths, 1, | |
110 | 0, 0, | |
111 | *piWidths, 1, | |
112 | pSrcs, | |
113 | (BITMAPINFO *) pbmi, | |
114 | DIB_RGB_COLORS, g_copyROP[pGC->alu]); | |
115 | ||
116 | pSrcs += PixmapBytePad(*piWidths, pDrawable->depth); | |
117 | pPoints++; | |
118 | piWidths++; | |
119 | } | |
120 | ||
121 | /* Reset the clip region */ | |
122 | SelectClipRgn(pGCPriv->hdcMem, NULL); | |
123 | ||
124 | /* Push the drawable pixmap out of the GC HDC */ | |
125 | SelectObject(pGCPriv->hdcMem, hbmpOrig); | |
126 | break; | |
127 | ||
128 | case DRAWABLE_WINDOW: | |
129 | ||
130 | SelectClipRgn(pGCPriv->hdc, combined); | |
131 | DeleteObject(combined); | |
132 | combined = NULL; | |
133 | ||
134 | while (iSpans--) { | |
135 | ZeroMemory(pbmi, sizeof(BITMAPINFO)); | |
136 | pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
137 | pbmi->bmiHeader.biWidth = *piWidths; | |
138 | pbmi->bmiHeader.biHeight = 1; | |
139 | pbmi->bmiHeader.biPlanes = 1; | |
140 | pbmi->bmiHeader.biBitCount = pDrawable->depth; | |
141 | pbmi->bmiHeader.biCompression = BI_RGB; | |
142 | ||
143 | /* Setup color table for mono DIBs */ | |
144 | if (pDrawable->depth == 1) { | |
145 | RGBQUAD *bmiColors = &(pbmi->bmiColors[0]); | |
146 | bmiColors[1].rgbBlue = 255; | |
147 | bmiColors[1].rgbGreen = 255; | |
148 | bmiColors[1].rgbRed = 255; | |
149 | } | |
150 | ||
151 | StretchDIBits(pGCPriv->hdc, | |
152 | pPoints->x, pPoints->y, | |
153 | *piWidths, 1, | |
154 | 0, 0, | |
155 | *piWidths, 1, | |
156 | pSrcs, | |
157 | (BITMAPINFO *) pbmi, | |
158 | DIB_RGB_COLORS, g_copyROP[pGC->alu]); | |
159 | ||
160 | pSrcs += PixmapBytePad(*piWidths, pDrawable->depth); | |
161 | pPoints++; | |
162 | piWidths++; | |
163 | } | |
164 | ||
165 | /* Reset the clip region */ | |
166 | SelectClipRgn(pGCPriv->hdc, NULL); | |
167 | break; | |
168 | ||
169 | default: | |
170 | FatalError("\nwinSetSpansNativeGDI - Unknown drawable type\n\n"); | |
171 | break; | |
172 | } | |
173 | ||
174 | free(pbmi); | |
175 | } |