1706f2543Smrg/* 2706f2543Smrg *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. 3706f2543Smrg * 4706f2543Smrg *Permission is hereby granted, free of charge, to any person obtaining 5706f2543Smrg * a copy of this software and associated documentation files (the 6706f2543Smrg *"Software"), to deal in the Software without restriction, including 7706f2543Smrg *without limitation the rights to use, copy, modify, merge, publish, 8706f2543Smrg *distribute, sublicense, and/or sell copies of the Software, and to 9706f2543Smrg *permit persons to whom the Software is furnished to do so, subject to 10706f2543Smrg *the following conditions: 11706f2543Smrg * 12706f2543Smrg *The above copyright notice and this permission notice shall be 13706f2543Smrg *included in all copies or substantial portions of the Software. 14706f2543Smrg * 15706f2543Smrg *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16706f2543Smrg *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17706f2543Smrg *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18706f2543Smrg *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR 19706f2543Smrg *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 20706f2543Smrg *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21706f2543Smrg *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22706f2543Smrg * 23706f2543Smrg *Except as contained in this notice, the name of the XFree86 Project 24706f2543Smrg *shall not be used in advertising or otherwise to promote the sale, use 25706f2543Smrg *or other dealings in this Software without prior written authorization 26706f2543Smrg *from the XFree86 Project. 27706f2543Smrg * 28706f2543Smrg * Authors: Harold L Hunt II 29706f2543Smrg * Alan Hourihane <alanh@fairlite.demon.co.uk> 30706f2543Smrg */ 31706f2543Smrg 32706f2543Smrg#ifdef HAVE_XWIN_CONFIG_H 33706f2543Smrg#include <xwin-config.h> 34706f2543Smrg#endif 35706f2543Smrg#include "win.h" 36706f2543Smrg 37706f2543Smrg/* See Porting Layer Definition - p. 55 */ 38706f2543Smrgvoid 39706f2543SmrgwinGetSpansNativeGDI (DrawablePtr pDrawable, 40706f2543Smrg int nMax, 41706f2543Smrg DDXPointPtr pPoints, 42706f2543Smrg int *piWidths, 43706f2543Smrg int iSpans, 44706f2543Smrg char *pDsts) 45706f2543Smrg{ 46706f2543Smrg PixmapPtr pPixmap = NULL; 47706f2543Smrg winPrivPixmapPtr pPixmapPriv = NULL; 48706f2543Smrg int iSpan; 49706f2543Smrg DDXPointPtr pPoint = NULL; 50706f2543Smrg int *piWidth = NULL; 51706f2543Smrg char *pDst = pDsts; 52706f2543Smrg HBITMAP hbmpWindow, hbmpOrig, hbmpOrig1; 53706f2543Smrg BYTE *pbWindow = NULL; 54706f2543Smrg HDC hdcMem, hdcMem1; 55706f2543Smrg ScreenPtr pScreen = pDrawable->pScreen; 56706f2543Smrg winScreenPriv(pScreen); 57706f2543Smrg 58706f2543Smrg /* Branch on the drawable type */ 59706f2543Smrg switch (pDrawable->type) 60706f2543Smrg { 61706f2543Smrg case DRAWABLE_PIXMAP: 62706f2543Smrg#if 0 63706f2543Smrg ErrorF ("winGetSpans - DRAWABLE_PIXMAP %08x\n", 64706f2543Smrg pDrawable); 65706f2543Smrg#endif 66706f2543Smrg 67706f2543Smrg pPixmap = (PixmapPtr) pDrawable; 68706f2543Smrg pPixmapPriv = winGetPixmapPriv (pPixmap); 69706f2543Smrg 70706f2543Smrg /* Open a memory HDC */ 71706f2543Smrg hdcMem1 = CreateCompatibleDC (NULL); 72706f2543Smrg hdcMem = CreateCompatibleDC (NULL); 73706f2543Smrg 74706f2543Smrg /* Select the drawable pixmap into a DC */ 75706f2543Smrg hbmpOrig1 = SelectObject (hdcMem1, pPixmapPriv->hBitmap); 76706f2543Smrg 77706f2543Smrg if (hbmpOrig1 == NULL) 78706f2543Smrg FatalError ("winGetSpans - DRAWABLE_PIXMAP - SelectObject () " 79706f2543Smrg "failed on pPixmapPriv->hBitmap\n"); 80706f2543Smrg 81706f2543Smrg /* Loop through spans */ 82706f2543Smrg for (iSpan = 0; iSpan < iSpans; ++iSpan) 83706f2543Smrg { 84706f2543Smrg pPoint = pPoints + iSpan; 85706f2543Smrg piWidth = piWidths + iSpan; 86706f2543Smrg 87706f2543Smrg hbmpWindow = winCreateDIBNativeGDI (*piWidth, 1, 88706f2543Smrg pDrawable->depth, 89706f2543Smrg &pbWindow, 90706f2543Smrg NULL); 91706f2543Smrg 92706f2543Smrg hbmpOrig = SelectObject (hdcMem, hbmpWindow); 93706f2543Smrg 94706f2543Smrg /* Transfer the window bits to the window bitmap */ 95706f2543Smrg BitBlt (hdcMem, 96706f2543Smrg 0, 0, 97706f2543Smrg *piWidth, 1, 98706f2543Smrg hdcMem1, 99706f2543Smrg pPoint->x, pPoint->y, 100706f2543Smrg SRCCOPY); 101706f2543Smrg 102706f2543Smrg memcpy (pDst, 103706f2543Smrg (char*) pbWindow, 104706f2543Smrg PixmapBytePad (*piWidth, pDrawable->depth)); 105706f2543Smrg 106706f2543Smrg /* Pop the window bitmap out of the HDC and delete the bitmap */ 107706f2543Smrg SelectObject (hdcMem, hbmpOrig); 108706f2543Smrg DeleteObject (hbmpWindow); 109706f2543Smrg 110706f2543Smrg#if 0 111706f2543Smrg ErrorF ("(%dx%dx%d) (%d,%d) w: %d\n", 112706f2543Smrg pDrawable->width, pDrawable->height, pDrawable->depth, 113706f2543Smrg pPoint->x, pPoint->y, *piWidth); 114706f2543Smrg#endif 115706f2543Smrg 116706f2543Smrg /* Calculate offset of next bit destination */ 117706f2543Smrg pDst += PixmapBytePad (*piWidth, pDrawable->depth); 118706f2543Smrg } 119706f2543Smrg 120706f2543Smrg /* Pop the pixmap's bitmap out of the HDC */ 121706f2543Smrg SelectObject (hdcMem1, hbmpOrig1); 122706f2543Smrg 123706f2543Smrg /* Delete the HDCs */ 124706f2543Smrg DeleteDC (hdcMem1); 125706f2543Smrg DeleteDC (hdcMem); 126706f2543Smrg break; 127706f2543Smrg 128706f2543Smrg case DRAWABLE_WINDOW: 129706f2543Smrg#if 0 130706f2543Smrg ErrorF ("winGetSpans - DRAWABLE_WINDOW\n"); 131706f2543Smrg#endif 132706f2543Smrg 133706f2543Smrg /* Open a memory HDC */ 134706f2543Smrg hdcMem = CreateCompatibleDC (NULL); 135706f2543Smrg 136706f2543Smrg /* Loop through spans */ 137706f2543Smrg for (iSpan = 0; iSpan < iSpans; ++iSpan) 138706f2543Smrg { 139706f2543Smrg pPoint = pPoints + iSpan; 140706f2543Smrg piWidth = piWidths + iSpan; 141706f2543Smrg 142706f2543Smrg hbmpWindow = winCreateDIBNativeGDI (*piWidth, 1, 143706f2543Smrg pDrawable->depth, 144706f2543Smrg &pbWindow, 145706f2543Smrg NULL); 146706f2543Smrg 147706f2543Smrg hbmpOrig = SelectObject (hdcMem, hbmpWindow); 148706f2543Smrg 149706f2543Smrg /* Transfer the window bits to the window bitmap */ 150706f2543Smrg BitBlt (hdcMem, 151706f2543Smrg 0, 0, 152706f2543Smrg *piWidth, 1, 153706f2543Smrg pScreenPriv->hdcScreen, 154706f2543Smrg pPoint->x, pPoint->y, 155706f2543Smrg SRCCOPY); 156706f2543Smrg 157706f2543Smrg memcpy (pDst, 158706f2543Smrg (char*) pbWindow, 159706f2543Smrg PixmapBytePad (*piWidth, pDrawable->depth)); 160706f2543Smrg 161706f2543Smrg /* Pop the window bitmap out of the HDC */ 162706f2543Smrg SelectObject (hdcMem, hbmpOrig); 163706f2543Smrg 164706f2543Smrg DeleteObject (hbmpWindow); 165706f2543Smrg 166706f2543Smrg#if 0 167706f2543Smrg ErrorF ("(%dx%dx%d) (%d,%d) w: %d\n", 168706f2543Smrg pDrawable->width, pDrawable->height, pDrawable->depth, 169706f2543Smrg pPoint->x, pPoint->y, *piWidth); 170706f2543Smrg#endif 171706f2543Smrg 172706f2543Smrg /* Calculate offset of next bit destination */ 173706f2543Smrg pDst += PixmapBytePad (*piWidth, pDrawable->depth); 174706f2543Smrg } 175706f2543Smrg 176706f2543Smrg /* Delete the window bitmap */ 177706f2543Smrg DeleteDC (hdcMem); 178706f2543Smrg break; 179706f2543Smrg 180706f2543Smrg default: 181706f2543Smrg FatalError ("winGetSpans - Unknown drawable type\n"); 182706f2543Smrg break; 183706f2543Smrg } 184706f2543Smrg} 185