Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xwin / wingetsp.c
CommitLineData
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 */
38void
39winGetSpansNativeGDI(DrawablePtr pDrawable,
40 int nMax,
41 DDXPointPtr pPoints,
42 int *piWidths, int iSpans, char *pDsts)
43{
44 PixmapPtr pPixmap = NULL;
45 winPrivPixmapPtr pPixmapPriv = NULL;
46 int iSpan;
47 DDXPointPtr pPoint = NULL;
48 int *piWidth = NULL;
49 char *pDst = pDsts;
50 HBITMAP hbmpWindow, hbmpOrig, hbmpOrig1;
51 BYTE *pbWindow = NULL;
52 HDC hdcMem, hdcMem1;
53 ScreenPtr pScreen = pDrawable->pScreen;
54
55 winScreenPriv(pScreen);
56
57 /* Branch on the drawable type */
58 switch (pDrawable->type) {
59 case DRAWABLE_PIXMAP:
60#if 0
61 ErrorF("winGetSpans - DRAWABLE_PIXMAP %08x\n", pDrawable);
62#endif
63
64 pPixmap = (PixmapPtr) pDrawable;
65 pPixmapPriv = winGetPixmapPriv(pPixmap);
66
67 /* Open a memory HDC */
68 hdcMem1 = CreateCompatibleDC(NULL);
69 hdcMem = CreateCompatibleDC(NULL);
70
71 /* Select the drawable pixmap into a DC */
72 hbmpOrig1 = SelectObject(hdcMem1, pPixmapPriv->hBitmap);
73
74 if (hbmpOrig1 == NULL)
75 FatalError("winGetSpans - DRAWABLE_PIXMAP - SelectObject () "
76 "failed on pPixmapPriv->hBitmap\n");
77
78 /* Loop through spans */
79 for (iSpan = 0; iSpan < iSpans; ++iSpan) {
80 pPoint = pPoints + iSpan;
81 piWidth = piWidths + iSpan;
82
83 hbmpWindow = winCreateDIBNativeGDI(*piWidth, 1,
84 pDrawable->depth,
85 &pbWindow, NULL);
86
87 hbmpOrig = SelectObject(hdcMem, hbmpWindow);
88
89 /* Transfer the window bits to the window bitmap */
90 BitBlt(hdcMem,
91 0, 0, *piWidth, 1, hdcMem1, pPoint->x, pPoint->y, SRCCOPY);
92
93 memcpy(pDst,
94 (char *) pbWindow,
95 PixmapBytePad(*piWidth, pDrawable->depth));
96
97 /* Pop the window bitmap out of the HDC and delete the bitmap */
98 SelectObject(hdcMem, hbmpOrig);
99 DeleteObject(hbmpWindow);
100
101#if 0
102 ErrorF("(%dx%dx%d) (%d,%d) w: %d\n",
103 pDrawable->width, pDrawable->height, pDrawable->depth,
104 pPoint->x, pPoint->y, *piWidth);
105#endif
106
107 /* Calculate offset of next bit destination */
108 pDst += PixmapBytePad(*piWidth, pDrawable->depth);
109 }
110
111 /* Pop the pixmap's bitmap out of the HDC */
112 SelectObject(hdcMem1, hbmpOrig1);
113
114 /* Delete the HDCs */
115 DeleteDC(hdcMem1);
116 DeleteDC(hdcMem);
117 break;
118
119 case DRAWABLE_WINDOW:
120#if 0
121 ErrorF("winGetSpans - DRAWABLE_WINDOW\n");
122#endif
123
124 /* Open a memory HDC */
125 hdcMem = CreateCompatibleDC(NULL);
126
127 /* Loop through spans */
128 for (iSpan = 0; iSpan < iSpans; ++iSpan) {
129 pPoint = pPoints + iSpan;
130 piWidth = piWidths + iSpan;
131
132 hbmpWindow = winCreateDIBNativeGDI(*piWidth, 1,
133 pDrawable->depth,
134 &pbWindow, NULL);
135
136 hbmpOrig = SelectObject(hdcMem, hbmpWindow);
137
138 /* Transfer the window bits to the window bitmap */
139 BitBlt(hdcMem,
140 0, 0,
141 *piWidth, 1,
142 pScreenPriv->hdcScreen, pPoint->x, pPoint->y, SRCCOPY);
143
144 memcpy(pDst,
145 (char *) pbWindow,
146 PixmapBytePad(*piWidth, pDrawable->depth));
147
148 /* Pop the window bitmap out of the HDC */
149 SelectObject(hdcMem, hbmpOrig);
150
151 DeleteObject(hbmpWindow);
152
153#if 0
154 ErrorF("(%dx%dx%d) (%d,%d) w: %d\n",
155 pDrawable->width, pDrawable->height, pDrawable->depth,
156 pPoint->x, pPoint->y, *piWidth);
157#endif
158
159 /* Calculate offset of next bit destination */
160 pDst += PixmapBytePad(*piWidth, pDrawable->depth);
161 }
162
163 /* Delete the window bitmap */
164 DeleteDC(hdcMem);
165 break;
166
167 default:
168 FatalError("winGetSpans - Unknown drawable type\n");
169 break;
170 }
171}