winsetsp.c revision 706f2543
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 38/* See Porting Layer Definition - p. 55 */ 39void 40winSetSpansNativeGDI (DrawablePtr pDrawable, 41 GCPtr pGC, 42 char *pSrcs, 43 DDXPointPtr pPoints, 44 int *piWidths, 45 int iSpans, 46 int fSorted) 47{ 48 winGCPriv(pGC); 49 PixmapPtr pPixmap = NULL; 50 winPrivPixmapPtr pPixmapPriv = NULL; 51 HBITMAP hbmpOrig = NULL; 52 BITMAPINFO bmi; 53 HRGN hrgn = NULL, combined = NULL; 54 int nbox; 55 BoxPtr pbox; 56 57 nbox = RegionNumRects (pGC->pCompositeClip); 58 pbox = RegionRects (pGC->pCompositeClip); 59 60 if (!nbox) return; 61 62 combined = CreateRectRgn (pbox->x1, pbox->y1, pbox->x2, pbox->y2); 63 nbox--; pbox++; 64 while (nbox--) 65 { 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 { 76 case DRAWABLE_PIXMAP: 77 78 SelectClipRgn (pGCPriv->hdcMem, combined); 79 DeleteObject (combined); 80 combined = NULL; 81 82 pPixmap = (PixmapPtr) pDrawable; 83 pPixmapPriv = winGetPixmapPriv (pPixmap); 84 85 /* Select the drawable pixmap into a DC */ 86 hbmpOrig = SelectObject (pGCPriv->hdcMem, pPixmapPriv->hBitmap); 87 if (hbmpOrig == NULL) 88 FatalError ("winSetSpans - DRAWABLE_PIXMAP - SelectObject () " 89 "failed on pPixmapPriv->hBitmap\n"); 90 91 while (iSpans--) 92 { 93 ZeroMemory (&bmi, sizeof (BITMAPINFO)); 94 bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); 95 bmi.bmiHeader.biWidth = *piWidths; 96 bmi.bmiHeader.biHeight = 1; 97 bmi.bmiHeader.biPlanes = 1; 98 bmi.bmiHeader.biBitCount = pDrawable->depth; 99 bmi.bmiHeader.biCompression = BI_RGB; 100 101 /* Setup color table for mono DIBs */ 102 if (pDrawable->depth == 1) 103 { 104 bmi.bmiColors[1].rgbBlue = 255; 105 bmi.bmiColors[1].rgbGreen = 255; 106 bmi.bmiColors[1].rgbRed = 255; 107 } 108 109 StretchDIBits (pGCPriv->hdcMem, 110 pPoints->x, pPoints->y, 111 *piWidths, 1, 112 0, 0, 113 *piWidths, 1, 114 pSrcs, 115 (BITMAPINFO *) &bmi, 116 DIB_RGB_COLORS, 117 g_copyROP[pGC->alu]); 118 119 pSrcs += PixmapBytePad (*piWidths, pDrawable->depth); 120 pPoints++; 121 piWidths++; 122 } 123 124 /* Reset the clip region */ 125 SelectClipRgn (pGCPriv->hdcMem, NULL); 126 127 /* Push the drawable pixmap out of the GC HDC */ 128 SelectObject (pGCPriv->hdcMem, hbmpOrig); 129 break; 130 131 case DRAWABLE_WINDOW: 132 133 SelectClipRgn (pGCPriv->hdc, combined); 134 DeleteObject (combined); 135 combined = NULL; 136 137 while (iSpans--) 138 { 139 ZeroMemory (&bmi, sizeof (BITMAPINFO)); 140 bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); 141 bmi.bmiHeader.biWidth = *piWidths; 142 bmi.bmiHeader.biHeight = 1; 143 bmi.bmiHeader.biPlanes = 1; 144 bmi.bmiHeader.biBitCount = pDrawable->depth; 145 bmi.bmiHeader.biCompression = BI_RGB; 146 147 /* Setup color table for mono DIBs */ 148 if (pDrawable->depth == 1) 149 { 150 bmi.bmiColors[1].rgbBlue = 255; 151 bmi.bmiColors[1].rgbGreen = 255; 152 bmi.bmiColors[1].rgbRed = 255; 153 } 154 155 StretchDIBits (pGCPriv->hdc, 156 pPoints->x, pPoints->y, 157 *piWidths, 1, 158 0, 0, 159 *piWidths, 1, 160 pSrcs, 161 (BITMAPINFO *) &bmi, 162 DIB_RGB_COLORS, 163 g_copyROP[pGC->alu]); 164 165 pSrcs += PixmapBytePad (*piWidths, pDrawable->depth); 166 pPoints++; 167 piWidths++; 168 } 169 170 /* Reset the clip region */ 171 SelectClipRgn (pGCPriv->hdc, NULL); 172 break; 173 174 default: 175 FatalError ("\nwinSetSpansNativeGDI - Unknown drawable type\n\n"); 176 break; 177 } 178} 179