2 * DIB driver initialization and DC functions.
4 * Copyright 2011 Huw Davies
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
23 #include "gdi_private.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(dib);
30 /***********************************************************************
33 static BOOL CDECL dibdrv_DeleteDC( PHYSDEV dev )
35 dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
37 DeleteObject(pdev->clip);
41 static void calc_shift_and_len(DWORD mask, int *shift, int *len)
52 while ((mask & 1) == 0)
58 while ((mask & 1) == 1)
67 static void init_bit_fields(dib_info *dib, const DWORD *bit_fields)
69 dib->red_mask = bit_fields[0];
70 dib->green_mask = bit_fields[1];
71 dib->blue_mask = bit_fields[2];
72 calc_shift_and_len(dib->red_mask, &dib->red_shift, &dib->red_len);
73 calc_shift_and_len(dib->green_mask, &dib->green_shift, &dib->green_len);
74 calc_shift_and_len(dib->blue_mask, &dib->blue_shift, &dib->blue_len);
77 static BOOL init_dib(dib_info *dib, const BITMAPINFOHEADER *bi, const DWORD *bit_fields, void *bits)
79 dib->bit_count = bi->biBitCount;
80 dib->width = bi->biWidth;
81 dib->height = bi->biHeight;
82 dib->stride = ((dib->width * dib->bit_count + 31) >> 3) & ~3;
85 if(dib->height < 0) /* top-down */
87 dib->height = -dib->height;
91 /* bits always points to the top-left corner and the stride is -ve */
92 dib->bits = (BYTE*)dib->bits + (dib->height - 1) * dib->stride;
93 dib->stride = -dib->stride;
96 dib->funcs = &funcs_null;
98 switch(dib->bit_count)
101 if(bi->biCompression == BI_RGB)
102 dib->funcs = &funcs_8888;
105 init_bit_fields(dib, bit_fields);
106 if(dib->red_mask == 0xff0000 && dib->green_mask == 0x00ff00 && dib->blue_mask == 0x0000ff)
107 dib->funcs = &funcs_8888;
109 dib->funcs = &funcs_32;
114 TRACE("bpp %d not supported, will forward to graphics driver.\n", dib->bit_count);
121 /***********************************************************************
122 * dibdrv_SelectBitmap
124 static HBITMAP CDECL dibdrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
126 PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSelectBitmap );
127 dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
128 BITMAPOBJ *bmp = GDI_GetObjPtr( bitmap, OBJ_BITMAP );
129 TRACE("(%p, %p)\n", dev, bitmap);
134 pdev->clip = CreateRectRgn(0, 0, 0, 0);
137 if(!init_dib(&pdev->dib, &bmp->dib->dsBmih, bmp->dib->dsBitfields, bmp->dib->dsBm.bmBits))
138 pdev->defer |= DEFER_FORMAT;
140 GDI_ReleaseObj( bitmap );
142 return next->funcs->pSelectBitmap( next, bitmap );
145 /***********************************************************************
148 static COLORREF CDECL dibdrv_SetBkColor( PHYSDEV dev, COLORREF color )
150 PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSetBkColor );
151 dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
153 pdev->bkgnd_color = pdev->dib.funcs->colorref_to_pixel( &pdev->dib, color );
155 if( GetBkMode(dev->hdc) == OPAQUE )
156 calc_and_xor_masks( GetROP2(dev->hdc), pdev->bkgnd_color, &pdev->bkgnd_and, &pdev->bkgnd_xor );
159 pdev->bkgnd_and = ~0u;
163 return next->funcs->pSetBkColor( next, color );
166 /***********************************************************************
169 static INT CDECL dibdrv_SetBkMode( PHYSDEV dev, INT mode )
171 PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSetBkMode );
172 dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
175 calc_and_xor_masks( GetROP2(dev->hdc), pdev->bkgnd_color, &pdev->bkgnd_and, &pdev->bkgnd_xor );
178 pdev->bkgnd_and = ~0u;
182 return next->funcs->pSetBkMode( next, mode );
185 /***********************************************************************
186 * dibdrv_SetDeviceClipping
188 static void CDECL dibdrv_SetDeviceClipping( PHYSDEV dev, HRGN vis_rgn, HRGN clip_rgn )
190 PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSetDeviceClipping );
191 dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
192 TRACE("(%p, %p, %p)\n", dev, vis_rgn, clip_rgn);
194 CombineRgn( pdev->clip, vis_rgn, clip_rgn, clip_rgn ? RGN_AND : RGN_COPY );
195 return next->funcs->pSetDeviceClipping( next, vis_rgn, clip_rgn);
198 /***********************************************************************
201 static INT CDECL dibdrv_SetROP2( PHYSDEV dev, INT rop )
203 PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSetROP2 );
204 dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
206 calc_and_xor_masks(rop, pdev->pen_color, &pdev->pen_and, &pdev->pen_xor);
207 update_brush_rop(pdev, rop);
208 if( GetBkMode(dev->hdc) == OPAQUE )
209 calc_and_xor_masks(rop, pdev->bkgnd_color, &pdev->bkgnd_and, &pdev->bkgnd_xor);
211 return next->funcs->pSetROP2( next, rop );
214 const DC_FUNCTIONS dib_driver =
216 NULL, /* pAbortDoc */
217 NULL, /* pAbortPath */
218 NULL, /* pAlphaBlend */
219 NULL, /* pAngleArc */
222 NULL, /* pBeginPath */
223 NULL, /* pChoosePixelFormat */
225 NULL, /* pCloseFigure */
226 NULL, /* pCreateBitmap */
227 NULL, /* pCreateDC */
228 NULL, /* pCreateDIBSection */
229 NULL, /* pDeleteBitmap */
230 dibdrv_DeleteDC, /* pDeleteDC */
231 NULL, /* pDeleteObject */
232 NULL, /* pDescribePixelFormat */
233 NULL, /* pDeviceCapabilities */
238 NULL, /* pEnumDeviceFonts */
239 NULL, /* pEnumICMProfiles */
240 NULL, /* pExcludeClipRect */
241 NULL, /* pExtDeviceMode */
242 NULL, /* pExtEscape */
243 NULL, /* pExtFloodFill */
244 NULL, /* pExtSelectClipRgn */
245 NULL, /* pExtTextOut */
246 NULL, /* pFillPath */
248 NULL, /* pFlattenPath */
249 NULL, /* pFrameRgn */
250 NULL, /* pGdiComment */
251 NULL, /* pGetBitmapBits */
252 NULL, /* pGetCharWidth */
253 NULL, /* pGetDIBits */
254 NULL, /* pGetDeviceCaps */
255 NULL, /* pGetDeviceGammaRamp */
256 NULL, /* pGetICMProfile */
257 NULL, /* pGetNearestColor */
258 NULL, /* pGetPixel */
259 NULL, /* pGetPixelFormat */
260 NULL, /* pGetSystemPaletteEntries */
261 NULL, /* pGetTextExtentExPoint */
262 NULL, /* pGetTextMetrics */
263 NULL, /* pIntersectClipRect */
264 NULL, /* pInvertRgn */
265 dibdrv_LineTo, /* pLineTo */
266 NULL, /* pModifyWorldTransform */
268 NULL, /* pOffsetClipRgn */
269 NULL, /* pOffsetViewportOrg */
270 NULL, /* pOffsetWindowOrg */
271 NULL, /* pPaintRgn */
272 dibdrv_PatBlt, /* pPatBlt */
274 NULL, /* pPolyBezier */
275 NULL, /* pPolyBezierTo */
276 NULL, /* pPolyDraw */
277 NULL, /* pPolyPolygon */
278 NULL, /* pPolyPolyline */
280 NULL, /* pPolyline */
281 NULL, /* pPolylineTo */
282 NULL, /* pRealizeDefaultPalette */
283 NULL, /* pRealizePalette */
284 NULL, /* pRectangle */
286 NULL, /* pRestoreDC */
287 NULL, /* pRoundRect */
289 NULL, /* pScaleViewportExt */
290 NULL, /* pScaleWindowExt */
291 dibdrv_SelectBitmap, /* pSelectBitmap */
292 dibdrv_SelectBrush, /* pSelectBrush */
293 NULL, /* pSelectClipPath */
294 NULL, /* pSelectFont */
295 NULL, /* pSelectPalette */
296 dibdrv_SelectPen, /* pSelectPen */
297 NULL, /* pSetArcDirection */
298 NULL, /* pSetBitmapBits */
299 dibdrv_SetBkColor, /* pSetBkColor */
300 dibdrv_SetBkMode, /* pSetBkMode */
301 dibdrv_SetDCBrushColor, /* pSetDCBrushColor */
302 dibdrv_SetDCPenColor, /* pSetDCPenColor */
303 NULL, /* pSetDIBColorTable */
304 NULL, /* pSetDIBits */
305 NULL, /* pSetDIBitsToDevice */
306 dibdrv_SetDeviceClipping, /* pSetDeviceClipping */
307 NULL, /* pSetDeviceGammaRamp */
308 NULL, /* pSetLayout */
309 NULL, /* pSetMapMode */
310 NULL, /* pSetMapperFlags */
311 NULL, /* pSetPixel */
312 NULL, /* pSetPixelFormat */
313 NULL, /* pSetPolyFillMode */
314 dibdrv_SetROP2, /* pSetROP2 */
315 NULL, /* pSetRelAbs */
316 NULL, /* pSetStretchBltMode */
317 NULL, /* pSetTextAlign */
318 NULL, /* pSetTextCharacterExtra */
319 NULL, /* pSetTextColor */
320 NULL, /* pSetTextJustification */
321 NULL, /* pSetViewportExt */
322 NULL, /* pSetViewportOrg */
323 NULL, /* pSetWindowExt */
324 NULL, /* pSetWindowOrg */
325 NULL, /* pSetWorldTransform */
326 NULL, /* pStartDoc */
327 NULL, /* pStartPage */
328 NULL, /* pStretchBlt */
329 NULL, /* pStretchDIBits */
330 NULL, /* pStrokeAndFillPath */
331 NULL, /* pStrokePath */
332 NULL, /* pSwapBuffers */
333 NULL, /* pUnrealizePalette */
334 NULL, /* pWidenPath */
335 NULL, /* pwglCopyContext */
336 NULL, /* pwglCreateContext */
337 NULL, /* pwglCreateContextAttribsARB */
338 NULL, /* pwglDeleteContext */
339 NULL, /* pwglGetProcAddress */
340 NULL, /* pwglGetPbufferDCARB */
341 NULL, /* pwglMakeCurrent */
342 NULL, /* pwglMakeContextCurrentARB */
343 NULL, /* pwglSetPixelFormatWINE */
344 NULL, /* pwglShareLists */
345 NULL, /* pwglUseFontBitmapsA */
346 NULL /* pwglUseFontBitmapsW */