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 38706f2543Smrg/* See Porting Layer Definition - p. 55 */ 39706f2543Smrgvoid 40706f2543SmrgwinSetSpansNativeGDI (DrawablePtr pDrawable, 41706f2543Smrg GCPtr pGC, 42706f2543Smrg char *pSrcs, 43706f2543Smrg DDXPointPtr pPoints, 44706f2543Smrg int *piWidths, 45706f2543Smrg int iSpans, 46706f2543Smrg int fSorted) 47706f2543Smrg{ 48706f2543Smrg winGCPriv(pGC); 49706f2543Smrg PixmapPtr pPixmap = NULL; 50706f2543Smrg winPrivPixmapPtr pPixmapPriv = NULL; 51706f2543Smrg HBITMAP hbmpOrig = NULL; 52706f2543Smrg BITMAPINFO bmi; 53706f2543Smrg HRGN hrgn = NULL, combined = NULL; 54706f2543Smrg int nbox; 55706f2543Smrg BoxPtr pbox; 56706f2543Smrg 57706f2543Smrg nbox = RegionNumRects (pGC->pCompositeClip); 58706f2543Smrg pbox = RegionRects (pGC->pCompositeClip); 59706f2543Smrg 60706f2543Smrg if (!nbox) return; 61706f2543Smrg 62706f2543Smrg combined = CreateRectRgn (pbox->x1, pbox->y1, pbox->x2, pbox->y2); 63706f2543Smrg nbox--; pbox++; 64706f2543Smrg while (nbox--) 65706f2543Smrg { 66706f2543Smrg hrgn = CreateRectRgn (pbox->x1, pbox->y1, pbox->x2, pbox->y2); 67706f2543Smrg CombineRgn (combined, combined, hrgn, RGN_OR); 68706f2543Smrg DeleteObject (hrgn); 69706f2543Smrg hrgn = NULL; 70706f2543Smrg pbox++; 71706f2543Smrg } 72706f2543Smrg 73706f2543Smrg /* Branch on the drawable type */ 74706f2543Smrg switch (pDrawable->type) 75706f2543Smrg { 76706f2543Smrg case DRAWABLE_PIXMAP: 77706f2543Smrg 78706f2543Smrg SelectClipRgn (pGCPriv->hdcMem, combined); 79706f2543Smrg DeleteObject (combined); 80706f2543Smrg combined = NULL; 81706f2543Smrg 82706f2543Smrg pPixmap = (PixmapPtr) pDrawable; 83706f2543Smrg pPixmapPriv = winGetPixmapPriv (pPixmap); 84706f2543Smrg 85706f2543Smrg /* Select the drawable pixmap into a DC */ 86706f2543Smrg hbmpOrig = SelectObject (pGCPriv->hdcMem, pPixmapPriv->hBitmap); 87706f2543Smrg if (hbmpOrig == NULL) 88706f2543Smrg FatalError ("winSetSpans - DRAWABLE_PIXMAP - SelectObject () " 89706f2543Smrg "failed on pPixmapPriv->hBitmap\n"); 90706f2543Smrg 91706f2543Smrg while (iSpans--) 92706f2543Smrg { 93706f2543Smrg ZeroMemory (&bmi, sizeof (BITMAPINFO)); 94706f2543Smrg bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); 95706f2543Smrg bmi.bmiHeader.biWidth = *piWidths; 96706f2543Smrg bmi.bmiHeader.biHeight = 1; 97706f2543Smrg bmi.bmiHeader.biPlanes = 1; 98706f2543Smrg bmi.bmiHeader.biBitCount = pDrawable->depth; 99706f2543Smrg bmi.bmiHeader.biCompression = BI_RGB; 100706f2543Smrg 101706f2543Smrg /* Setup color table for mono DIBs */ 102706f2543Smrg if (pDrawable->depth == 1) 103706f2543Smrg { 104706f2543Smrg bmi.bmiColors[1].rgbBlue = 255; 105706f2543Smrg bmi.bmiColors[1].rgbGreen = 255; 106706f2543Smrg bmi.bmiColors[1].rgbRed = 255; 107706f2543Smrg } 108706f2543Smrg 109706f2543Smrg StretchDIBits (pGCPriv->hdcMem, 110706f2543Smrg pPoints->x, pPoints->y, 111706f2543Smrg *piWidths, 1, 112706f2543Smrg 0, 0, 113706f2543Smrg *piWidths, 1, 114706f2543Smrg pSrcs, 115706f2543Smrg (BITMAPINFO *) &bmi, 116706f2543Smrg DIB_RGB_COLORS, 117706f2543Smrg g_copyROP[pGC->alu]); 118706f2543Smrg 119706f2543Smrg pSrcs += PixmapBytePad (*piWidths, pDrawable->depth); 120706f2543Smrg pPoints++; 121706f2543Smrg piWidths++; 122706f2543Smrg } 123706f2543Smrg 124706f2543Smrg /* Reset the clip region */ 125706f2543Smrg SelectClipRgn (pGCPriv->hdcMem, NULL); 126706f2543Smrg 127706f2543Smrg /* Push the drawable pixmap out of the GC HDC */ 128706f2543Smrg SelectObject (pGCPriv->hdcMem, hbmpOrig); 129706f2543Smrg break; 130706f2543Smrg 131706f2543Smrg case DRAWABLE_WINDOW: 132706f2543Smrg 133706f2543Smrg SelectClipRgn (pGCPriv->hdc, combined); 134706f2543Smrg DeleteObject (combined); 135706f2543Smrg combined = NULL; 136706f2543Smrg 137706f2543Smrg while (iSpans--) 138706f2543Smrg { 139706f2543Smrg ZeroMemory (&bmi, sizeof (BITMAPINFO)); 140706f2543Smrg bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); 141706f2543Smrg bmi.bmiHeader.biWidth = *piWidths; 142706f2543Smrg bmi.bmiHeader.biHeight = 1; 143706f2543Smrg bmi.bmiHeader.biPlanes = 1; 144706f2543Smrg bmi.bmiHeader.biBitCount = pDrawable->depth; 145706f2543Smrg bmi.bmiHeader.biCompression = BI_RGB; 146706f2543Smrg 147706f2543Smrg /* Setup color table for mono DIBs */ 148706f2543Smrg if (pDrawable->depth == 1) 149706f2543Smrg { 150706f2543Smrg bmi.bmiColors[1].rgbBlue = 255; 151706f2543Smrg bmi.bmiColors[1].rgbGreen = 255; 152706f2543Smrg bmi.bmiColors[1].rgbRed = 255; 153706f2543Smrg } 154706f2543Smrg 155706f2543Smrg StretchDIBits (pGCPriv->hdc, 156706f2543Smrg pPoints->x, pPoints->y, 157706f2543Smrg *piWidths, 1, 158706f2543Smrg 0, 0, 159706f2543Smrg *piWidths, 1, 160706f2543Smrg pSrcs, 161706f2543Smrg (BITMAPINFO *) &bmi, 162706f2543Smrg DIB_RGB_COLORS, 163706f2543Smrg g_copyROP[pGC->alu]); 164706f2543Smrg 165706f2543Smrg pSrcs += PixmapBytePad (*piWidths, pDrawable->depth); 166706f2543Smrg pPoints++; 167706f2543Smrg piWidths++; 168706f2543Smrg } 169706f2543Smrg 170706f2543Smrg /* Reset the clip region */ 171706f2543Smrg SelectClipRgn (pGCPriv->hdc, NULL); 172706f2543Smrg break; 173706f2543Smrg 174706f2543Smrg default: 175706f2543Smrg FatalError ("\nwinSetSpansNativeGDI - Unknown drawable type\n\n"); 176706f2543Smrg break; 177706f2543Smrg } 178706f2543Smrg} 179