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/exception.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(dib);
31 static const DWORD bit_fields_888[3] = {0xff0000, 0x00ff00, 0x0000ff};
32 static const DWORD bit_fields_555[3] = {0x7c00, 0x03e0, 0x001f};
34 static void calc_shift_and_len(DWORD mask, int *shift, int *len)
45 while ((mask & 1) == 0)
51 while ((mask & 1) == 1)
60 static void init_bit_fields(dib_info *dib, const DWORD *bit_fields)
62 dib->red_mask = bit_fields[0];
63 dib->green_mask = bit_fields[1];
64 dib->blue_mask = bit_fields[2];
65 calc_shift_and_len(dib->red_mask, &dib->red_shift, &dib->red_len);
66 calc_shift_and_len(dib->green_mask, &dib->green_shift, &dib->green_len);
67 calc_shift_and_len(dib->blue_mask, &dib->blue_shift, &dib->blue_len);
70 static void init_dib_info(dib_info *dib, const BITMAPINFOHEADER *bi, const DWORD *bit_fields,
71 const RGBQUAD *color_table, void *bits)
73 dib->bit_count = bi->biBitCount;
74 dib->width = bi->biWidth;
75 dib->height = bi->biHeight;
78 dib->rect.right = bi->biWidth;
79 dib->rect.bottom = abs( bi->biHeight );
80 dib->compression = bi->biCompression;
81 dib->stride = get_dib_stride( dib->width, dib->bit_count );
83 dib->bits.is_copy = FALSE;
84 dib->bits.free = NULL;
85 dib->bits.param = NULL;
87 if(dib->height < 0) /* top-down */
89 dib->height = -dib->height;
93 /* bits always points to the top-left corner and the stride is -ve */
94 dib->bits.ptr = (BYTE*)dib->bits.ptr + (dib->height - 1) * dib->stride;
95 dib->stride = -dib->stride;
98 dib->funcs = &funcs_null;
100 switch(dib->bit_count)
103 if(bi->biCompression == BI_RGB)
104 bit_fields = bit_fields_888;
106 init_bit_fields(dib, bit_fields);
108 if(dib->red_mask == 0xff0000 && dib->green_mask == 0x00ff00 && dib->blue_mask == 0x0000ff)
109 dib->funcs = &funcs_8888;
111 dib->funcs = &funcs_32;
115 dib->funcs = &funcs_24;
119 if(bi->biCompression == BI_RGB)
120 bit_fields = bit_fields_555;
122 init_bit_fields(dib, bit_fields);
124 if(dib->red_mask == 0x7c00 && dib->green_mask == 0x03e0 && dib->blue_mask == 0x001f)
125 dib->funcs = &funcs_555;
127 dib->funcs = &funcs_16;
131 dib->funcs = &funcs_8;
135 dib->funcs = &funcs_4;
139 dib->funcs = &funcs_1;
143 if (color_table && bi->biClrUsed)
145 dib->color_table = color_table;
146 dib->color_table_size = bi->biClrUsed;
150 dib->color_table = NULL;
151 dib->color_table_size = 0;
155 void init_dib_info_from_bitmapinfo(dib_info *dib, const BITMAPINFO *info, void *bits)
157 init_dib_info( dib, &info->bmiHeader, (const DWORD *)info->bmiColors, info->bmiColors, bits );
160 BOOL init_dib_info_from_bitmapobj(dib_info *dib, BITMAPOBJ *bmp)
162 if (!is_bitmapobj_dib( bmp ))
166 get_ddb_bitmapinfo( bmp, &info );
167 if (!bmp->dib.dsBm.bmBits)
169 int width_bytes = get_dib_stride( bmp->dib.dsBm.bmWidth, bmp->dib.dsBm.bmBitsPixel );
170 bmp->dib.dsBm.bmBits = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
171 bmp->dib.dsBm.bmHeight * width_bytes );
172 if (!bmp->dib.dsBm.bmBits) return FALSE;
174 init_dib_info_from_bitmapinfo( dib, &info, bmp->dib.dsBm.bmBits );
176 else init_dib_info( dib, &bmp->dib.dsBmih, bmp->dib.dsBitfields,
177 bmp->color_table, bmp->dib.dsBm.bmBits );
181 static void clear_dib_info(dib_info *dib)
183 dib->bits.ptr = NULL;
184 dib->bits.free = NULL;
185 dib->bits.param = NULL;
188 /**********************************************************************
191 * Free the resources associated with a dib and optionally the bits
193 void free_dib_info(dib_info *dib)
195 if (dib->bits.free) dib->bits.free( &dib->bits );
196 clear_dib_info( dib );
199 void copy_dib_color_info(dib_info *dst, const dib_info *src)
201 dst->bit_count = src->bit_count;
202 dst->red_mask = src->red_mask;
203 dst->green_mask = src->green_mask;
204 dst->blue_mask = src->blue_mask;
205 dst->red_len = src->red_len;
206 dst->green_len = src->green_len;
207 dst->blue_len = src->blue_len;
208 dst->red_shift = src->red_shift;
209 dst->green_shift = src->green_shift;
210 dst->blue_shift = src->blue_shift;
211 dst->funcs = src->funcs;
212 dst->color_table_size = src->color_table_size;
213 dst->color_table = src->color_table;
216 DWORD convert_bitmapinfo( const BITMAPINFO *src_info, void *src_bits, struct bitblt_coords *src,
217 const BITMAPINFO *dst_info, void *dst_bits )
219 dib_info src_dib, dst_dib;
222 init_dib_info_from_bitmapinfo( &src_dib, src_info, src_bits );
223 init_dib_info_from_bitmapinfo( &dst_dib, dst_info, dst_bits );
227 dst_dib.funcs->convert_to( &dst_dib, &src_dib, &src->visrect, FALSE );
232 WARN( "invalid bits pointer %p\n", src_bits );
237 if(!ret) return ERROR_BAD_FORMAT;
239 /* update coordinates, the destination rectangle is always stored at 0,0 */
240 src->x -= src->visrect.left;
241 src->y -= src->visrect.top;
242 offset_rect( &src->visrect, -src->visrect.left, -src->visrect.top );
243 return ERROR_SUCCESS;
246 int clip_rect_to_dib( const dib_info *dib, RECT *rc )
250 rect.left = max( 0, -dib->rect.left );
251 rect.top = max( 0, -dib->rect.top );
252 rect.right = min( dib->rect.right, dib->width ) - dib->rect.left;
253 rect.bottom = min( dib->rect.bottom, dib->height ) - dib->rect.top;
254 if (is_rect_empty( &rect )) return 0;
255 return intersect_rect( rc, &rect, rc );
258 int get_clipped_rects( const dib_info *dib, const RECT *rc, HRGN clip, struct clipped_rects *clip_rects )
260 const WINEREGION *region;
261 RECT rect, *out = clip_rects->buffer;
264 init_clipped_rects( clip_rects );
266 rect.left = max( 0, -dib->rect.left );
267 rect.top = max( 0, -dib->rect.top );
268 rect.right = min( dib->rect.right, dib->width ) - dib->rect.left;
269 rect.bottom = min( dib->rect.bottom, dib->height ) - dib->rect.top;
270 if (is_rect_empty( &rect )) return 0;
271 if (rc && !intersect_rect( &rect, &rect, rc )) return 0;
276 clip_rects->count = 1;
280 if (!(region = get_wine_region( clip ))) return 0;
282 for (i = 0; i < region->numRects; i++)
284 if (region->rects[i].top >= rect.bottom) break;
285 if (!intersect_rect( out, &rect, ®ion->rects[i] )) continue;
287 if (out == &clip_rects->buffer[sizeof(clip_rects->buffer) / sizeof(RECT)])
289 clip_rects->rects = HeapAlloc( GetProcessHeap(), 0, region->numRects * sizeof(RECT) );
290 if (!clip_rects->rects) return 0;
291 memcpy( clip_rects->rects, clip_rects->buffer, (out - clip_rects->buffer) * sizeof(RECT) );
292 out = clip_rects->rects + (out - clip_rects->buffer);
295 release_wine_region( clip );
296 clip_rects->count = out - clip_rects->rects;
297 return clip_rects->count;
300 void add_clipped_bounds( dibdrv_physdev *dev, const RECT *rect, HRGN clip )
302 const WINEREGION *region;
305 if (!dev->bounds) return;
308 if (!(region = get_wine_region( clip ))) return;
309 if (!rect) rc = region->extents;
310 else intersect_rect( &rc, rect, ®ion->extents );
311 release_wine_region( clip );
315 if (is_rect_empty( &rc )) return;
316 offset_rect( &rc, dev->dib.rect.left, dev->dib.rect.top );
317 add_bounds_rect( dev->bounds, &rc );
320 /**********************************************************************
323 static BOOL dibdrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
324 LPCWSTR output, const DEVMODEW *data )
326 dibdrv_physdev *pdev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pdev) );
328 if (!pdev) return FALSE;
329 clear_dib_info(&pdev->dib);
330 clear_dib_info(&pdev->brush.dib);
331 clear_dib_info(&pdev->pen_brush.dib);
332 push_dc_driver( dev, &pdev->dev, &dib_driver );
336 /***********************************************************************
339 static BOOL dibdrv_DeleteDC( PHYSDEV dev )
341 dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
342 TRACE("(%p)\n", dev);
343 free_pattern_brush( &pdev->brush );
344 free_pattern_brush( &pdev->pen_brush );
345 HeapFree( GetProcessHeap(), 0, pdev );
349 /***********************************************************************
350 * dibdrv_SelectBitmap
352 static HBITMAP dibdrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
354 dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
355 BITMAPOBJ *bmp = GDI_GetObjPtr( bitmap, OBJ_BITMAP );
358 TRACE("(%p, %p)\n", dev, bitmap);
362 if (!init_dib_info_from_bitmapobj(&dib, bmp))
364 GDI_ReleaseObj( bitmap );
368 GDI_ReleaseObj( bitmap );
373 /***********************************************************************
374 * dibdrv_SetDeviceClipping
376 static void dibdrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
378 dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
379 TRACE("(%p, %p)\n", dev, rgn);
384 /***********************************************************************
385 * dibdrv_SetBoundsRect
387 static UINT dibdrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
389 dibdrv_physdev *pdev = get_dibdrv_pdev( dev );
391 if (flags & DCB_DISABLE) pdev->bounds = NULL;
392 else if (flags & DCB_ENABLE) pdev->bounds = rect;
393 return DCB_RESET; /* we don't have device-specific bounds */
396 const struct gdi_dc_funcs dib_driver =
398 NULL, /* pAbortDoc */
399 NULL, /* pAbortPath */
400 dibdrv_AlphaBlend, /* pAlphaBlend */
401 NULL, /* pAngleArc */
402 dibdrv_Arc, /* pArc */
403 dibdrv_ArcTo, /* pArcTo */
404 NULL, /* pBeginPath */
405 dibdrv_BlendImage, /* pBlendImage */
406 dibdrv_Chord, /* pChord */
407 NULL, /* pCloseFigure */
408 NULL, /* pCreateCompatibleDC */
409 dibdrv_CreateDC, /* pCreateDC */
410 dibdrv_DeleteDC, /* pDeleteDC */
411 NULL, /* pDeleteObject */
412 NULL, /* pDeviceCapabilities */
413 dibdrv_Ellipse, /* pEllipse */
417 NULL, /* pEnumFonts */
418 NULL, /* pEnumICMProfiles */
419 NULL, /* pExcludeClipRect */
420 NULL, /* pExtDeviceMode */
421 NULL, /* pExtEscape */
422 dibdrv_ExtFloodFill, /* pExtFloodFill */
423 NULL, /* pExtSelectClipRgn */
424 dibdrv_ExtTextOut, /* pExtTextOut */
425 NULL, /* pFillPath */
427 NULL, /* pFlattenPath */
428 NULL, /* pFontIsLinked */
429 NULL, /* pFrameRgn */
430 NULL, /* pGdiComment */
431 NULL, /* pGdiRealizationInfo */
432 NULL, /* pGetBoundsRect */
433 NULL, /* pGetCharABCWidths */
434 NULL, /* pGetCharABCWidthsI */
435 NULL, /* pGetCharWidth */
436 NULL, /* pGetDeviceCaps */
437 NULL, /* pGetDeviceGammaRamp */
438 NULL, /* pGetFontData */
439 NULL, /* pGetFontUnicodeRanges */
440 NULL, /* pGetGlyphIndices */
441 NULL, /* pGetGlyphOutline */
442 NULL, /* pGetICMProfile */
443 dibdrv_GetImage, /* pGetImage */
444 NULL, /* pGetKerningPairs */
445 dibdrv_GetNearestColor, /* pGetNearestColor */
446 NULL, /* pGetOutlineTextMetrics */
447 dibdrv_GetPixel, /* pGetPixel */
448 NULL, /* pGetSystemPaletteEntries */
449 NULL, /* pGetTextCharsetInfo */
450 NULL, /* pGetTextExtentExPoint */
451 NULL, /* pGetTextExtentExPointI */
452 NULL, /* pGetTextFace */
453 NULL, /* pGetTextMetrics */
454 dibdrv_GradientFill, /* pGradientFill */
455 NULL, /* pIntersectClipRect */
456 NULL, /* pInvertRgn */
457 dibdrv_LineTo, /* pLineTo */
458 NULL, /* pModifyWorldTransform */
460 NULL, /* pOffsetClipRgn */
461 NULL, /* pOffsetViewportOrg */
462 NULL, /* pOffsetWindowOrg */
463 dibdrv_PaintRgn, /* pPaintRgn */
464 dibdrv_PatBlt, /* pPatBlt */
465 dibdrv_Pie, /* pPie */
466 NULL, /* pPolyBezier */
467 NULL, /* pPolyBezierTo */
468 NULL, /* pPolyDraw */
469 dibdrv_PolyPolygon, /* pPolyPolygon */
470 dibdrv_PolyPolyline, /* pPolyPolyline */
471 dibdrv_Polygon, /* pPolygon */
472 dibdrv_Polyline, /* pPolyline */
473 NULL, /* pPolylineTo */
474 dibdrv_PutImage, /* pPutImage */
475 NULL, /* pRealizeDefaultPalette */
476 NULL, /* pRealizePalette */
477 dibdrv_Rectangle, /* pRectangle */
479 NULL, /* pRestoreDC */
480 dibdrv_RoundRect, /* pRoundRect */
482 NULL, /* pScaleViewportExt */
483 NULL, /* pScaleWindowExt */
484 dibdrv_SelectBitmap, /* pSelectBitmap */
485 dibdrv_SelectBrush, /* pSelectBrush */
486 NULL, /* pSelectClipPath */
487 dibdrv_SelectFont, /* pSelectFont */
488 NULL, /* pSelectPalette */
489 dibdrv_SelectPen, /* pSelectPen */
490 NULL, /* pSetArcDirection */
491 NULL, /* pSetBkColor */
492 NULL, /* pSetBkMode */
493 dibdrv_SetBoundsRect, /* pSetBoundsRect */
494 dibdrv_SetDCBrushColor, /* pSetDCBrushColor */
495 dibdrv_SetDCPenColor, /* pSetDCPenColor */
496 NULL, /* pSetDIBitsToDevice */
497 dibdrv_SetDeviceClipping, /* pSetDeviceClipping */
498 NULL, /* pSetDeviceGammaRamp */
499 NULL, /* pSetLayout */
500 NULL, /* pSetMapMode */
501 NULL, /* pSetMapperFlags */
502 dibdrv_SetPixel, /* pSetPixel */
503 NULL, /* pSetPolyFillMode */
505 NULL, /* pSetRelAbs */
506 NULL, /* pSetStretchBltMode */
507 NULL, /* pSetTextAlign */
508 NULL, /* pSetTextCharacterExtra */
509 NULL, /* pSetTextColor */
510 NULL, /* pSetTextJustification */
511 NULL, /* pSetViewportExt */
512 NULL, /* pSetViewportOrg */
513 NULL, /* pSetWindowExt */
514 NULL, /* pSetWindowOrg */
515 NULL, /* pSetWorldTransform */
516 NULL, /* pStartDoc */
517 NULL, /* pStartPage */
518 dibdrv_StretchBlt, /* pStretchBlt */
519 NULL, /* pStretchDIBits */
520 NULL, /* pStrokeAndFillPath */
521 NULL, /* pStrokePath */
522 NULL, /* pUnrealizePalette */
523 NULL, /* pWidenPath */
524 dibdrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
525 GDI_PRIORITY_DIB_DRV /* priority */
529 /***********************************************************************
530 * Driver for window surfaces.
532 * It uses the DIB engine but needs extra locking since multiple DCs
533 * can paint to the same window.
536 struct windrv_physdev
538 struct gdi_physdev dev;
539 struct dibdrv_physdev *dibdrv;
540 struct window_surface *surface;
543 static const struct gdi_dc_funcs window_driver;
545 static inline struct windrv_physdev *get_windrv_physdev( PHYSDEV dev )
547 return (struct windrv_physdev *)dev;
550 static inline void lock_surface( struct window_surface *surface )
553 surface->funcs->lock( surface );
556 static inline void unlock_surface( struct window_surface *surface )
558 surface->funcs->unlock( surface );
561 static void unlock_bits_surface( struct gdi_image_bits *bits )
563 unlock_surface( bits->param );
566 void dibdrv_set_window_surface( DC *dc, struct window_surface *surface )
568 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
569 BITMAPINFO *info = (BITMAPINFO *)buffer;
573 struct windrv_physdev *physdev;
574 struct dibdrv_physdev *dibdrv;
576 TRACE( "%p %p\n", dc->hSelf, surface );
578 windev = pop_dc_driver( dc, &window_driver );
582 if (windev) push_dc_driver( &dc->physDev, windev, windev->funcs );
585 if (!window_driver.pCreateDC( &dc->physDev, NULL, NULL, NULL, NULL )) return;
586 windev = find_dc_driver( dc, &window_driver );
589 physdev = get_windrv_physdev( windev );
590 window_surface_add_ref( surface );
591 if (physdev->surface) window_surface_release( physdev->surface );
592 physdev->surface = surface;
594 dibdrv = physdev->dibdrv;
595 bits = surface->funcs->get_info( surface, info );
596 init_dib_info_from_bitmapinfo( &dibdrv->dib, info, bits );
597 /* clip the device rect to the surface */
598 rect = surface->rect;
599 offset_rect( &rect, dc->device_rect.left, dc->device_rect.top );
600 intersect_rect( &dc->device_rect, &dc->device_rect, &rect );
601 dibdrv->dib.rect = dc->vis_rect;
602 offset_rect( &dibdrv->dib.rect, -rect.left, -rect.top );
603 dibdrv->bounds = surface->funcs->get_bounds( surface );
608 dib_driver.pDeleteDC( pop_dc_driver( dc, &dib_driver ));
609 windev->funcs->pDeleteDC( windev );
614 static BOOL windrv_AlphaBlend( PHYSDEV dst_dev, struct bitblt_coords *dst,
615 PHYSDEV src_dev, struct bitblt_coords *src, BLENDFUNCTION func )
617 struct windrv_physdev *physdev = get_windrv_physdev( dst_dev );
620 lock_surface( physdev->surface );
621 dst_dev = GET_NEXT_PHYSDEV( dst_dev, pAlphaBlend );
622 ret = dst_dev->funcs->pAlphaBlend( dst_dev, dst, src_dev, src, func );
623 unlock_surface( physdev->surface );
627 static BOOL windrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
628 INT xstart, INT ystart, INT xend, INT yend )
630 struct windrv_physdev *physdev = get_windrv_physdev( dev );
633 lock_surface( physdev->surface );
634 dev = GET_NEXT_PHYSDEV( dev, pArc );
635 ret = dev->funcs->pArc( dev, left, top, right, bottom, xstart, ystart, xend, yend );
636 unlock_surface( physdev->surface );
640 static BOOL windrv_ArcTo( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
641 INT xstart, INT ystart, INT xend, INT yend )
643 struct windrv_physdev *physdev = get_windrv_physdev( dev );
646 lock_surface( physdev->surface );
647 dev = GET_NEXT_PHYSDEV( dev, pArc );
648 ret = dev->funcs->pArcTo( dev, left, top, right, bottom, xstart, ystart, xend, yend );
649 unlock_surface( physdev->surface );
653 static DWORD windrv_BlendImage( PHYSDEV dev, BITMAPINFO *info, const struct gdi_image_bits *bits,
654 struct bitblt_coords *src, struct bitblt_coords *dst, BLENDFUNCTION blend )
656 struct windrv_physdev *physdev = get_windrv_physdev( dev );
659 lock_surface( physdev->surface );
660 dev = GET_NEXT_PHYSDEV( dev, pBlendImage );
661 ret = dev->funcs->pBlendImage( dev, info, bits, src, dst, blend );
662 unlock_surface( physdev->surface );
666 static BOOL windrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
667 INT xstart, INT ystart, INT xend, INT yend )
669 struct windrv_physdev *physdev = get_windrv_physdev( dev );
672 lock_surface( physdev->surface );
673 dev = GET_NEXT_PHYSDEV( dev, pChord );
674 ret = dev->funcs->pChord( dev, left, top, right, bottom, xstart, ystart, xend, yend );
675 unlock_surface( physdev->surface );
679 static BOOL windrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
680 LPCWSTR output, const DEVMODEW *devmode )
682 struct windrv_physdev *physdev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physdev) );
684 if (!physdev) return FALSE;
686 if (!dib_driver.pCreateDC( dev, NULL, NULL, NULL, NULL ))
688 HeapFree( GetProcessHeap(), 0, physdev );
691 physdev->dibdrv = get_dibdrv_pdev( *dev );
692 push_dc_driver( dev, &physdev->dev, &window_driver );
696 static BOOL windrv_DeleteDC( PHYSDEV dev )
698 struct windrv_physdev *physdev = get_windrv_physdev( dev );
700 window_surface_release( physdev->surface );
701 HeapFree( GetProcessHeap(), 0, physdev );
705 static BOOL windrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
707 struct windrv_physdev *physdev = get_windrv_physdev( dev );
710 lock_surface( physdev->surface );
711 dev = GET_NEXT_PHYSDEV( dev, pEllipse );
712 ret = dev->funcs->pEllipse( dev, left, top, right, bottom );
713 unlock_surface( physdev->surface );
717 static BOOL windrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
719 struct windrv_physdev *physdev = get_windrv_physdev( dev );
722 lock_surface( physdev->surface );
723 dev = GET_NEXT_PHYSDEV( dev, pExtFloodFill );
724 ret = dev->funcs->pExtFloodFill( dev, x, y, color, type );
725 unlock_surface( physdev->surface );
729 static BOOL windrv_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags, const RECT *rect,
730 LPCWSTR str, UINT count, const INT *dx )
732 struct windrv_physdev *physdev = get_windrv_physdev( dev );
735 lock_surface( physdev->surface );
736 dev = GET_NEXT_PHYSDEV( dev, pExtTextOut );
737 ret = dev->funcs->pExtTextOut( dev, x, y, flags, rect, str, count, dx );
738 unlock_surface( physdev->surface );
742 static DWORD windrv_GetImage( PHYSDEV dev, BITMAPINFO *info,
743 struct gdi_image_bits *bits, struct bitblt_coords *src )
745 struct windrv_physdev *physdev = get_windrv_physdev( dev );
748 lock_surface( physdev->surface );
749 dev = GET_NEXT_PHYSDEV( dev, pGetImage );
750 ret = dev->funcs->pGetImage( dev, info, bits, src );
752 /* don't return alpha if original surface doesn't support it */
753 if (info->bmiHeader.biBitCount == 32 &&
754 info->bmiHeader.biCompression == BI_RGB &&
755 physdev->dibdrv->dib.compression == BI_BITFIELDS)
757 DWORD *colors = (DWORD *)info->bmiColors;
758 colors[0] = 0xff0000;
759 colors[1] = 0x00ff00;
760 colors[2] = 0x0000ff;
761 info->bmiHeader.biCompression = BI_BITFIELDS;
766 /* use the freeing callback to unlock the surface */
767 assert( !bits->free );
768 bits->free = unlock_bits_surface;
769 bits->param = physdev->surface;
771 else unlock_surface( physdev->surface );
775 static COLORREF windrv_GetPixel( PHYSDEV dev, INT x, INT y )
777 struct windrv_physdev *physdev = get_windrv_physdev( dev );
780 lock_surface( physdev->surface );
781 dev = GET_NEXT_PHYSDEV( dev, pGetPixel );
782 ret = dev->funcs->pGetPixel( dev, x, y );
783 unlock_surface( physdev->surface );
787 static BOOL windrv_GradientFill( PHYSDEV dev, TRIVERTEX *vert_array, ULONG nvert,
788 void * grad_array, ULONG ngrad, ULONG mode )
790 struct windrv_physdev *physdev = get_windrv_physdev( dev );
793 lock_surface( physdev->surface );
794 dev = GET_NEXT_PHYSDEV( dev, pGradientFill );
795 ret = dev->funcs->pGradientFill( dev, vert_array, nvert, grad_array, ngrad, mode );
796 unlock_surface( physdev->surface );
800 static BOOL windrv_LineTo( PHYSDEV dev, INT x, INT y )
802 struct windrv_physdev *physdev = get_windrv_physdev( dev );
805 lock_surface( physdev->surface );
806 dev = GET_NEXT_PHYSDEV( dev, pLineTo );
807 ret = dev->funcs->pLineTo( dev, x, y );
808 unlock_surface( physdev->surface );
812 static BOOL windrv_PaintRgn( PHYSDEV dev, HRGN rgn )
814 struct windrv_physdev *physdev = get_windrv_physdev( dev );
817 lock_surface( physdev->surface );
818 dev = GET_NEXT_PHYSDEV( dev, pPaintRgn );
819 ret = dev->funcs->pPaintRgn( dev, rgn );
820 unlock_surface( physdev->surface );
824 static BOOL windrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
826 struct windrv_physdev *physdev = get_windrv_physdev( dev );
829 lock_surface( physdev->surface );
830 dev = GET_NEXT_PHYSDEV( dev, pPatBlt );
831 ret = dev->funcs->pPatBlt( dev, dst, rop );
832 unlock_surface( physdev->surface );
836 static BOOL windrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
837 INT xstart, INT ystart, INT xend, INT yend )
839 struct windrv_physdev *physdev = get_windrv_physdev( dev );
842 lock_surface( physdev->surface );
843 dev = GET_NEXT_PHYSDEV( dev, pPie );
844 ret = dev->funcs->pPie( dev, left, top, right, bottom, xstart, ystart, xend, yend );
845 unlock_surface( physdev->surface );
849 static BOOL windrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
851 struct windrv_physdev *physdev = get_windrv_physdev( dev );
854 lock_surface( physdev->surface );
855 dev = GET_NEXT_PHYSDEV( dev, pPolyPolygon );
856 ret = dev->funcs->pPolyPolygon( dev, points, counts, polygons );
857 unlock_surface( physdev->surface );
861 static BOOL windrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
863 struct windrv_physdev *physdev = get_windrv_physdev( dev );
866 lock_surface( physdev->surface );
867 dev = GET_NEXT_PHYSDEV( dev, pPolyPolyline );
868 ret = dev->funcs->pPolyPolyline( dev, points, counts, lines );
869 unlock_surface( physdev->surface );
873 static BOOL windrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
875 struct windrv_physdev *physdev = get_windrv_physdev( dev );
878 lock_surface( physdev->surface );
879 dev = GET_NEXT_PHYSDEV( dev, pPolygon );
880 ret = dev->funcs->pPolygon( dev, points, count );
881 unlock_surface( physdev->surface );
885 static BOOL windrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
887 struct windrv_physdev *physdev = get_windrv_physdev( dev );
890 lock_surface( physdev->surface );
891 dev = GET_NEXT_PHYSDEV( dev, pPolyline );
892 ret = dev->funcs->pPolyline( dev, points, count );
893 unlock_surface( physdev->surface );
897 static DWORD windrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
898 const struct gdi_image_bits *bits, struct bitblt_coords *src,
899 struct bitblt_coords *dst, DWORD rop )
901 struct windrv_physdev *physdev = get_windrv_physdev( dev );
904 lock_surface( physdev->surface );
905 dev = GET_NEXT_PHYSDEV( dev, pPutImage );
906 ret = dev->funcs->pPutImage( dev, clip, info, bits, src, dst, rop );
907 unlock_surface( physdev->surface );
911 static BOOL windrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
913 struct windrv_physdev *physdev = get_windrv_physdev( dev );
916 lock_surface( physdev->surface );
917 dev = GET_NEXT_PHYSDEV( dev, pRectangle );
918 ret = dev->funcs->pRectangle( dev, left, top, right, bottom );
919 unlock_surface( physdev->surface );
923 static BOOL windrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
924 INT ell_width, INT ell_height )
926 struct windrv_physdev *physdev = get_windrv_physdev( dev );
929 lock_surface( physdev->surface );
930 dev = GET_NEXT_PHYSDEV( dev, pRoundRect );
931 ret = dev->funcs->pRoundRect( dev, left, top, right, bottom, ell_width, ell_height );
932 unlock_surface( physdev->surface );
936 static UINT windrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
938 /* do nothing, we use the dibdrv bounds tracking for our own purpose */
942 static INT windrv_SetDIBitsToDevice( PHYSDEV dev, INT x_dst, INT y_dst, DWORD cx, DWORD cy,
943 INT x_src, INT y_src, UINT startscan, UINT lines,
944 const void *bits, BITMAPINFO *src_info, UINT coloruse )
946 struct windrv_physdev *physdev = get_windrv_physdev( dev );
949 lock_surface( physdev->surface );
950 dev = GET_NEXT_PHYSDEV( dev, pSetDIBitsToDevice );
951 ret = dev->funcs->pSetDIBitsToDevice( dev, x_dst, y_dst, cx, cy,
952 x_src, y_src, startscan, lines, bits, src_info, coloruse );
953 unlock_surface( physdev->surface );
957 static void windrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
959 dev = GET_NEXT_PHYSDEV( dev, pSetDeviceClipping );
960 dev->funcs->pSetDeviceClipping( dev, rgn );
961 /* also forward to the graphics driver for the OpenGL case */
962 if (dev->funcs == &dib_driver)
964 dev = GET_NEXT_PHYSDEV( dev, pSetDeviceClipping );
965 dev->funcs->pSetDeviceClipping( dev, rgn );
969 static COLORREF windrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
971 struct windrv_physdev *physdev = get_windrv_physdev( dev );
974 lock_surface( physdev->surface );
975 dev = GET_NEXT_PHYSDEV( dev, pSetPixel );
976 ret = dev->funcs->pSetPixel( dev, x, y, color );
977 unlock_surface( physdev->surface );
981 static BOOL windrv_StretchBlt( PHYSDEV dst_dev, struct bitblt_coords *dst,
982 PHYSDEV src_dev, struct bitblt_coords *src, DWORD rop )
984 struct windrv_physdev *physdev = get_windrv_physdev( dst_dev );
987 lock_surface( physdev->surface );
988 dst_dev = GET_NEXT_PHYSDEV( dst_dev, pStretchBlt );
989 ret = dst_dev->funcs->pStretchBlt( dst_dev, dst, src_dev, src, rop );
990 unlock_surface( physdev->surface );
994 static INT windrv_StretchDIBits( PHYSDEV dev, INT x_dst, INT y_dst, INT width_dst, INT height_dst,
995 INT x_src, INT y_src, INT width_src, INT height_src, const void *bits,
996 BITMAPINFO *src_info, UINT coloruse, DWORD rop )
998 struct windrv_physdev *physdev = get_windrv_physdev( dev );
1001 lock_surface( physdev->surface );
1002 dev = GET_NEXT_PHYSDEV( dev, pStretchDIBits );
1003 ret = dev->funcs->pStretchDIBits( dev, x_dst, y_dst, width_dst, height_dst,
1004 x_src, y_src, width_src, height_src, bits, src_info, coloruse, rop );
1005 unlock_surface( physdev->surface );
1009 static struct opengl_funcs *windrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
1011 dev = GET_NEXT_PHYSDEV( dev, wine_get_wgl_driver );
1012 if (dev->funcs == &dib_driver) dev = GET_NEXT_PHYSDEV( dev, wine_get_wgl_driver );
1013 return dev->funcs->wine_get_wgl_driver( dev, version );
1016 static const struct gdi_dc_funcs window_driver =
1018 NULL, /* pAbortDoc */
1019 NULL, /* pAbortPath */
1020 windrv_AlphaBlend, /* pAlphaBlend */
1021 NULL, /* pAngleArc */
1022 windrv_Arc, /* pArc */
1023 windrv_ArcTo, /* pArcTo */
1024 NULL, /* pBeginPath */
1025 windrv_BlendImage, /* pBlendImage */
1026 windrv_Chord, /* pChord */
1027 NULL, /* pCloseFigure */
1028 NULL, /* pCreateCompatibleDC */
1029 windrv_CreateDC, /* pCreateDC */
1030 windrv_DeleteDC, /* pDeleteDC */
1031 NULL, /* pDeleteObject */
1032 NULL, /* pDeviceCapabilities */
1033 windrv_Ellipse, /* pEllipse */
1035 NULL, /* pEndPage */
1036 NULL, /* pEndPath */
1037 NULL, /* pEnumFonts */
1038 NULL, /* pEnumICMProfiles */
1039 NULL, /* pExcludeClipRect */
1040 NULL, /* pExtDeviceMode */
1041 NULL, /* pExtEscape */
1042 windrv_ExtFloodFill, /* pExtFloodFill */
1043 NULL, /* pExtSelectClipRgn */
1044 windrv_ExtTextOut, /* pExtTextOut */
1045 NULL, /* pFillPath */
1046 NULL, /* pFillRgn */
1047 NULL, /* pFlattenPath */
1048 NULL, /* pFontIsLinked */
1049 NULL, /* pFrameRgn */
1050 NULL, /* pGdiComment */
1051 NULL, /* pGdiRealizationInfo */
1052 NULL, /* pGetBoundsRect */
1053 NULL, /* pGetCharABCWidths */
1054 NULL, /* pGetCharABCWidthsI */
1055 NULL, /* pGetCharWidth */
1056 NULL, /* pGetDeviceCaps */
1057 NULL, /* pGetDeviceGammaRamp */
1058 NULL, /* pGetFontData */
1059 NULL, /* pGetFontUnicodeRanges */
1060 NULL, /* pGetGlyphIndices */
1061 NULL, /* pGetGlyphOutline */
1062 NULL, /* pGetICMProfile */
1063 windrv_GetImage, /* pGetImage */
1064 NULL, /* pGetKerningPairs */
1065 NULL, /* pGetNearestColor */
1066 NULL, /* pGetOutlineTextMetrics */
1067 windrv_GetPixel, /* pGetPixel */
1068 NULL, /* pGetSystemPaletteEntries */
1069 NULL, /* pGetTextCharsetInfo */
1070 NULL, /* pGetTextExtentExPoint */
1071 NULL, /* pGetTextExtentExPointI */
1072 NULL, /* pGetTextFace */
1073 NULL, /* pGetTextMetrics */
1074 windrv_GradientFill, /* pGradientFill */
1075 NULL, /* pIntersectClipRect */
1076 NULL, /* pInvertRgn */
1077 windrv_LineTo, /* pLineTo */
1078 NULL, /* pModifyWorldTransform */
1080 NULL, /* pOffsetClipRgn */
1081 NULL, /* pOffsetViewportOrg */
1082 NULL, /* pOffsetWindowOrg */
1083 windrv_PaintRgn, /* pPaintRgn */
1084 windrv_PatBlt, /* pPatBlt */
1085 windrv_Pie, /* pPie */
1086 NULL, /* pPolyBezier */
1087 NULL, /* pPolyBezierTo */
1088 NULL, /* pPolyDraw */
1089 windrv_PolyPolygon, /* pPolyPolygon */
1090 windrv_PolyPolyline, /* pPolyPolyline */
1091 windrv_Polygon, /* pPolygon */
1092 windrv_Polyline, /* pPolyline */
1093 NULL, /* pPolylineTo */
1094 windrv_PutImage, /* pPutImage */
1095 NULL, /* pRealizeDefaultPalette */
1096 NULL, /* pRealizePalette */
1097 windrv_Rectangle, /* pRectangle */
1098 NULL, /* pResetDC */
1099 NULL, /* pRestoreDC */
1100 windrv_RoundRect, /* pRoundRect */
1102 NULL, /* pScaleViewportExt */
1103 NULL, /* pScaleWindowExt */
1104 NULL, /* pSelectBitmap */
1105 NULL, /* pSelectBrush */
1106 NULL, /* pSelectClipPath */
1107 NULL, /* pSelectFont */
1108 NULL, /* pSelectPalette */
1109 NULL, /* pSelectPen */
1110 NULL, /* pSetArcDirection */
1111 NULL, /* pSetBkColor */
1112 NULL, /* pSetBkMode */
1113 windrv_SetBoundsRect, /* pSetBoundsRect */
1114 NULL, /* pSetDCBrushColor */
1115 NULL, /* pSetDCPenColor */
1116 windrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
1117 windrv_SetDeviceClipping, /* pSetDeviceClipping */
1118 NULL, /* pSetDeviceGammaRamp */
1119 NULL, /* pSetLayout */
1120 NULL, /* pSetMapMode */
1121 NULL, /* pSetMapperFlags */
1122 windrv_SetPixel, /* pSetPixel */
1123 NULL, /* pSetPolyFillMode */
1124 NULL, /* pSetROP2 */
1125 NULL, /* pSetRelAbs */
1126 NULL, /* pSetStretchBltMode */
1127 NULL, /* pSetTextAlign */
1128 NULL, /* pSetTextCharacterExtra */
1129 NULL, /* pSetTextColor */
1130 NULL, /* pSetTextJustification */
1131 NULL, /* pSetViewportExt */
1132 NULL, /* pSetViewportOrg */
1133 NULL, /* pSetWindowExt */
1134 NULL, /* pSetWindowOrg */
1135 NULL, /* pSetWorldTransform */
1136 NULL, /* pStartDoc */
1137 NULL, /* pStartPage */
1138 windrv_StretchBlt, /* pStretchBlt */
1139 windrv_StretchDIBits, /* pStretchDIBits */
1140 NULL, /* pStrokeAndFillPath */
1141 NULL, /* pStrokePath */
1142 NULL, /* pUnrealizePalette */
1143 NULL, /* pWidenPath */
1144 windrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
1145 GDI_PRIORITY_DIB_DRV + 10 /* priority */