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