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