| 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: drewry, september 1986 |
| 29 | * Harold L Hunt II |
| 30 | */ |
| 31 | |
| 32 | #ifdef HAVE_XWIN_CONFIG_H |
| 33 | #include <xwin-config.h> |
| 34 | #endif |
| 35 | #include "win.h" |
| 36 | |
| 37 | /* |
| 38 | * Local prototypes |
| 39 | */ |
| 40 | |
| 41 | #if 0 |
| 42 | static void |
| 43 | winXRotatePixmapNativeGDI(PixmapPtr pPix, int rw); |
| 44 | |
| 45 | static void |
| 46 | winYRotatePixmapNativeGDI(PixmapPtr pPix, int rh); |
| 47 | |
| 48 | static void |
| 49 | |
| 50 | winCopyRotatePixmapNativeGDI(PixmapPtr psrcPix, PixmapPtr *ppdstPix, |
| 51 | int xrot, int yrot); |
| 52 | #endif |
| 53 | |
| 54 | /* See Porting Layer Definition - p. 34 */ |
| 55 | /* See mfb/mfbpixmap.c - mfbCreatePixmap() */ |
| 56 | PixmapPtr |
| 57 | winCreatePixmapNativeGDI(ScreenPtr pScreen, |
| 58 | int iWidth, int iHeight, |
| 59 | int iDepth, unsigned usage_hint) |
| 60 | { |
| 61 | winPrivPixmapPtr pPixmapPriv = NULL; |
| 62 | PixmapPtr pPixmap = NULL; |
| 63 | |
| 64 | /* Allocate pixmap memory */ |
| 65 | pPixmap = AllocatePixmap(pScreen, 0); |
| 66 | if (!pPixmap) { |
| 67 | ErrorF("winCreatePixmapNativeGDI () - Couldn't allocate a pixmap\n"); |
| 68 | return NullPixmap; |
| 69 | } |
| 70 | |
| 71 | #if CYGDEBUG |
| 72 | winDebug("winCreatePixmap () - w %d h %d d %d uh %d bw %d\n", |
| 73 | iWidth, iHeight, iDepth, usage_hint, |
| 74 | PixmapBytePad(iWidth, iDepth)); |
| 75 | #endif |
| 76 | |
| 77 | /* Setup pixmap values */ |
| 78 | pPixmap->drawable.type = DRAWABLE_PIXMAP; |
| 79 | pPixmap->drawable.class = 0; |
| 80 | pPixmap->drawable.pScreen = pScreen; |
| 81 | pPixmap->drawable.depth = iDepth; |
| 82 | pPixmap->drawable.bitsPerPixel = BitsPerPixel(iDepth); |
| 83 | pPixmap->drawable.id = 0; |
| 84 | pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER; |
| 85 | pPixmap->drawable.x = 0; |
| 86 | pPixmap->drawable.y = 0; |
| 87 | pPixmap->drawable.width = iWidth; |
| 88 | pPixmap->drawable.height = iHeight; |
| 89 | pPixmap->devKind = 0; |
| 90 | pPixmap->refcnt = 1; |
| 91 | pPixmap->devPrivate.ptr = NULL; |
| 92 | pPixmap->usage_hint = usage_hint; |
| 93 | |
| 94 | /* Pixmap privates are allocated by AllocatePixmap */ |
| 95 | pPixmapPriv = winGetPixmapPriv(pPixmap); |
| 96 | |
| 97 | /* Initialize pixmap privates */ |
| 98 | pPixmapPriv->hBitmap = NULL; |
| 99 | pPixmapPriv->hdcSelected = NULL; |
| 100 | pPixmapPriv->pbBits = NULL; |
| 101 | pPixmapPriv->dwScanlineBytes = PixmapBytePad(iWidth, iDepth); |
| 102 | |
| 103 | /* Check for zero width or height pixmaps */ |
| 104 | if (iWidth == 0 || iHeight == 0) { |
| 105 | /* Don't allocate a real pixmap, just set fields and return */ |
| 106 | return pPixmap; |
| 107 | } |
| 108 | |
| 109 | /* Create a DIB for the pixmap */ |
| 110 | pPixmapPriv->hBitmap = winCreateDIBNativeGDI(iWidth, iHeight, iDepth, |
| 111 | &pPixmapPriv->pbBits, |
| 112 | (BITMAPINFO **) &pPixmapPriv-> |
| 113 | pbmih); |
| 114 | |
| 115 | #if CYGDEBUG |
| 116 | winDebug("winCreatePixmap () - Created a pixmap %08x, %dx%dx%d, for " |
| 117 | "screen: %08x\n", |
| 118 | pPixmapPriv->hBitmap, iWidth, iHeight, iDepth, pScreen); |
| 119 | #endif |
| 120 | |
| 121 | return pPixmap; |
| 122 | } |
| 123 | |
| 124 | /* |
| 125 | * See Porting Layer Definition - p. 35 |
| 126 | * |
| 127 | * See mfb/mfbpixmap.c - mfbDestroyPixmap() |
| 128 | */ |
| 129 | |
| 130 | Bool |
| 131 | winDestroyPixmapNativeGDI(PixmapPtr pPixmap) |
| 132 | { |
| 133 | winPrivPixmapPtr pPixmapPriv = NULL; |
| 134 | |
| 135 | #if CYGDEBUG |
| 136 | winDebug("winDestroyPixmapNativeGDI ()\n"); |
| 137 | #endif |
| 138 | |
| 139 | /* Bail early if there is not a pixmap to destroy */ |
| 140 | if (pPixmap == NULL) { |
| 141 | ErrorF("winDestroyPixmapNativeGDI () - No pixmap to destroy\n"); |
| 142 | return TRUE; |
| 143 | } |
| 144 | |
| 145 | /* Get a handle to the pixmap privates */ |
| 146 | pPixmapPriv = winGetPixmapPriv(pPixmap); |
| 147 | |
| 148 | #if CYGDEBUG |
| 149 | winDebug("winDestroyPixmapNativeGDI - pPixmapPriv->hBitmap: %08x\n", |
| 150 | pPixmapPriv->hBitmap); |
| 151 | #endif |
| 152 | |
| 153 | /* Decrement reference count, return if nonzero */ |
| 154 | --pPixmap->refcnt; |
| 155 | if (pPixmap->refcnt != 0) |
| 156 | return TRUE; |
| 157 | |
| 158 | /* Free GDI bitmap */ |
| 159 | if (pPixmapPriv->hBitmap) |
| 160 | DeleteObject(pPixmapPriv->hBitmap); |
| 161 | |
| 162 | /* Free the bitmap info header memory */ |
| 163 | free(pPixmapPriv->pbmih); |
| 164 | pPixmapPriv->pbmih = NULL; |
| 165 | |
| 166 | /* Free the pixmap memory */ |
| 167 | free(pPixmap); |
| 168 | pPixmap = NULL; |
| 169 | |
| 170 | return TRUE; |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Not used yet |
| 175 | */ |
| 176 | |
| 177 | Bool |
| 178 | winModifyPixmapHeaderNativeGDI(PixmapPtr pPixmap, |
| 179 | int iWidth, int iHeight, |
| 180 | int iDepth, |
| 181 | int iBitsPerPixel, int devKind, pointer pPixData) |
| 182 | { |
| 183 | FatalError("winModifyPixmapHeaderNativeGDI ()\n"); |
| 184 | return TRUE; |
| 185 | } |
| 186 | |
| 187 | #if 0 |
| 188 | /* |
| 189 | * Not used yet. |
| 190 | * See cfb/cfbpixmap.c |
| 191 | */ |
| 192 | |
| 193 | static void |
| 194 | winXRotatePixmapNativeGDI(PixmapPtr pPix, int rw) |
| 195 | { |
| 196 | ErrorF("winXRotatePixmap()\n"); |
| 197 | /* fill in this function, look at CFB */ |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * Not used yet. |
| 202 | * See cfb/cfbpixmap.c |
| 203 | */ |
| 204 | static void |
| 205 | winYRotatePixmapNativeGDI(PixmapPtr pPix, int rh) |
| 206 | { |
| 207 | ErrorF("winYRotatePixmap()\n"); |
| 208 | /* fill in this function, look at CFB */ |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | * Not used yet. |
| 213 | * See cfb/cfbpixmap.c |
| 214 | */ |
| 215 | |
| 216 | static void |
| 217 | winCopyRotatePixmapNativeGDI(PixmapPtr psrcPix, PixmapPtr *ppdstPix, |
| 218 | int xrot, int yrot) |
| 219 | { |
| 220 | ErrorF("winCopyRotatePixmap()\n"); |
| 221 | /* fill in this function, look at CFB */ |
| 222 | } |
| 223 | #endif |