DIB Engine: implement most engine functions
[wine/hacks.git] / dlls / winedib.drv / bitmap.c
blobf3d3b9c24328d9bfcb187fcd702769db4694a1af
1 /*
2 * DIB driver bitmap objects
4 * Copyright 2009 Massimo Del Fedele
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include "dibdrv.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
29 /****************************************************************************
30 * SelectBitmap (WINEDIB.DRV.@)
32 HBITMAP DIBDRV_SelectBitmap( DIBDRVPHYSDEV *physDev, HBITMAP hbitmap )
34 DIBSECTION dibSection;
35 HBITMAP res;
37 /* try to get the DIBSECTION data from the bitmap */
38 if(GetObjectW(hbitmap, sizeof(DIBSECTION), &dibSection) == sizeof(BITMAP))
40 /* not a DIB section, sets it on physDev and use X11 behaviour */
42 MAYBE(TRACE("physDev:%p, hbitmap:%p\n", physDev, hbitmap));
43 physDev->hasDIB = FALSE;
44 res = _DIBDRV_GetDisplayDriver()->pSelectBitmap(physDev->X11PhysDev, hbitmap);
45 if(res)
46 physDev->hbitmap = hbitmap;
48 else
50 /* it's a DIB section, sets it on physDev and use DIB Engine behaviour */
52 MAYBE(TRACE("physDev:%p, hbitmap:%p, physBitmap=%p\n", physDev, hbitmap, &physDev->physBitmap));
54 /* frees any previously physical bitmap */
55 _DIBDRVBITMAP_Free(&physDev->physBitmap);
57 /* WARNING : the color table can't be grabbed here, since it's still
58 not initialized. It'll be grabbed on RealizeDefaultPalette(),
59 which is presumably the first call made after palette initialization.
60 So, by now we just set up palette size and leave NULL the palette pointer */
61 if(_DIBDRVBITMAP_InitFromBMIH(&physDev->physBitmap, &dibSection.dsBmih, dibSection.dsBitfields, NULL, dibSection.dsBm.bmBits))
63 /* stores the active bitmap */
64 res = physDev->hbitmap;
65 physDev->hbitmap = hbitmap;
67 /* remember there's a DIB selected in */
68 physDev->hasDIB = TRUE;
70 else
72 ERR("Failed to initialize physical bitmap\n");
73 res = 0;
76 return res;
80 /****************************************************************************
81 * DIBDRV_CreateBitmap
83 BOOL DIBDRV_CreateBitmap( DIBDRVPHYSDEV *physDev, HBITMAP hbitmap, LPVOID bmBits )
85 DIBSECTION dibSection;
86 BOOL res;
88 MAYBE(TRACE("physDev:%p, hbitmap:%p, bmBits:%p\n", physDev, hbitmap, bmBits));
90 /* try to get the DIBSECTION data from the bitmap */
91 if(GetObjectW(hbitmap, sizeof(DIBSECTION), &dibSection) == sizeof(BITMAP))
93 /* not a DIB section, use X11 behaviour */
94 res = _DIBDRV_GetDisplayDriver()->pCreateBitmap(physDev->X11PhysDev, hbitmap, bmBits);
96 else
98 /* it's a DIB section, use DIB Engine behaviour - should not happen, but.... */
99 ONCE(FIXME("CreateBitmap() called for a DIB section - shouldn't happen\n"));
100 res = TRUE;
102 return res;
105 /***********************************************************************
106 * DIBDRV_DeleteBitmap
108 BOOL DIBDRV_DeleteBitmap( HBITMAP hbitmap )
110 DIBSECTION dibSection;
111 BOOL res;
113 MAYBE(TRACE("hbitmap:%p\n", hbitmap));
115 /* try to get the DIBSECTION data from the bitmap */
116 if(GetObjectW(hbitmap, sizeof(DIBSECTION), &dibSection) == sizeof(BITMAP))
118 /* not a DIB section, use X11 behaviour */
119 res = _DIBDRV_GetDisplayDriver()->pDeleteBitmap(hbitmap);
121 else
123 /* it's a DIB section, use DIB Engine behaviour */
124 ONCE(FIXME("STUB\n"));
125 res = TRUE;
127 return res;
130 /***********************************************************************
131 * DIBDRV_GetBitmapBits
133 LONG DIBDRV_GetBitmapBits( HBITMAP hbitmap, void *buffer, LONG count )
135 LONG res;
137 MAYBE(TRACE("hbitmap:%p, buffer:%p, count:%d\n", hbitmap, buffer, count));
139 /* GetBitmapBits is only valid for DDBs, so use X11 driver */
140 res = _DIBDRV_GetDisplayDriver()->pGetBitmapBits(hbitmap, buffer, count);
142 return res;
145 /******************************************************************************
146 * DIBDRV_SetBitmapBits
148 LONG DIBDRV_SetBitmapBits( HBITMAP hbitmap, const void *bits, LONG count )
150 LONG res;
152 MAYBE(TRACE("hbitmap:%p, bits:%p, count:%d\n", hbitmap, bits, count));
154 /* SetBitmapBits is only valid for DDBs, so use X11 driver */
155 res = _DIBDRV_GetDisplayDriver()->pSetBitmapBits(hbitmap, bits, count);
157 return res;