TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / gdi32 / dibdrv / dc.c
blobb80e52216301d7f9592a8746a4d8d44d44e8bb4e
1 /*
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
21 #include <assert.h>
23 #include "gdi_private.h"
24 #include "dibdrv.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)
36 int s, l;
38 if(!mask)
40 *shift = *len = 0;
41 return;
44 s = 0;
45 while ((mask & 1) == 0)
47 mask >>= 1;
48 s++;
50 l = 0;
51 while ((mask & 1) == 1)
53 mask >>= 1;
54 l++;
56 *shift = s;
57 *len = l;
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;
76 dib->rect.left = 0;
77 dib->rect.top = 0;
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 );
82 dib->bits.ptr = bits;
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;
91 else /* bottom-up */
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)
102 case 32:
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;
110 else
111 dib->funcs = &funcs_32;
112 break;
114 case 24:
115 dib->funcs = &funcs_24;
116 break;
118 case 16:
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;
126 else
127 dib->funcs = &funcs_16;
128 break;
130 case 8:
131 dib->funcs = &funcs_8;
132 break;
134 case 4:
135 dib->funcs = &funcs_4;
136 break;
138 case 1:
139 dib->funcs = &funcs_1;
140 break;
143 if (color_table && bi->biClrUsed)
145 dib->color_table = color_table;
146 dib->color_table_size = bi->biClrUsed;
148 else
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 ))
164 BITMAPINFO info;
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 );
178 return TRUE;
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 /**********************************************************************
189 * free_dib_info
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;
220 DWORD ret;
222 init_dib_info_from_bitmapinfo( &src_dib, src_info, src_bits );
223 init_dib_info_from_bitmapinfo( &dst_dib, dst_info, dst_bits );
225 __TRY
227 dst_dib.funcs->convert_to( &dst_dib, &src_dib, &src->visrect, FALSE );
228 ret = TRUE;
230 __EXCEPT_PAGE_FAULT
232 WARN( "invalid bits pointer %p\n", src_bits );
233 ret = FALSE;
235 __ENDTRY
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 )
248 RECT rect;
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;
262 int i;
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;
273 if (!clip)
275 *out = rect;
276 clip_rects->count = 1;
277 return 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, &region->rects[i] )) continue;
286 out++;
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;
303 RECT rc;
305 if (!dev->bounds) return;
306 if (clip)
308 if (!(region = get_wine_region( clip ))) return;
309 if (!rect) rc = region->extents;
310 else intersect_rect( &rc, rect, &region->extents );
311 release_wine_region( clip );
313 else rc = *rect;
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 /**********************************************************************
321 * dibdrv_CreateDC
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 );
333 return TRUE;
336 /***********************************************************************
337 * dibdrv_DeleteDC
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 release_cached_font( pdev->font );
346 HeapFree( GetProcessHeap(), 0, pdev );
347 return TRUE;
350 /***********************************************************************
351 * dibdrv_SelectBitmap
353 static HBITMAP dibdrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
355 dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
356 BITMAPOBJ *bmp = GDI_GetObjPtr( bitmap, OBJ_BITMAP );
357 dib_info dib;
359 TRACE("(%p, %p)\n", dev, bitmap);
361 if (!bmp) return 0;
363 if (!init_dib_info_from_bitmapobj(&dib, bmp))
365 GDI_ReleaseObj( bitmap );
366 return 0;
368 pdev->dib = dib;
369 GDI_ReleaseObj( bitmap );
371 return bitmap;
374 /***********************************************************************
375 * dibdrv_SetDeviceClipping
377 static void dibdrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
379 dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
380 TRACE("(%p, %p)\n", dev, rgn);
382 pdev->clip = rgn;
385 /***********************************************************************
386 * dibdrv_SetBoundsRect
388 static UINT dibdrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
390 dibdrv_physdev *pdev = get_dibdrv_pdev( dev );
392 if (flags & DCB_DISABLE) pdev->bounds = NULL;
393 else if (flags & DCB_ENABLE) pdev->bounds = rect;
394 return DCB_RESET; /* we don't have device-specific bounds */
397 const struct gdi_dc_funcs dib_driver =
399 NULL, /* pAbortDoc */
400 NULL, /* pAbortPath */
401 dibdrv_AlphaBlend, /* pAlphaBlend */
402 NULL, /* pAngleArc */
403 dibdrv_Arc, /* pArc */
404 dibdrv_ArcTo, /* pArcTo */
405 NULL, /* pBeginPath */
406 dibdrv_BlendImage, /* pBlendImage */
407 dibdrv_Chord, /* pChord */
408 NULL, /* pCloseFigure */
409 NULL, /* pCreateCompatibleDC */
410 dibdrv_CreateDC, /* pCreateDC */
411 dibdrv_DeleteDC, /* pDeleteDC */
412 NULL, /* pDeleteObject */
413 NULL, /* pDeviceCapabilities */
414 dibdrv_Ellipse, /* pEllipse */
415 NULL, /* pEndDoc */
416 NULL, /* pEndPage */
417 NULL, /* pEndPath */
418 NULL, /* pEnumFonts */
419 NULL, /* pEnumICMProfiles */
420 NULL, /* pExcludeClipRect */
421 NULL, /* pExtDeviceMode */
422 NULL, /* pExtEscape */
423 dibdrv_ExtFloodFill, /* pExtFloodFill */
424 NULL, /* pExtSelectClipRgn */
425 dibdrv_ExtTextOut, /* pExtTextOut */
426 NULL, /* pFillPath */
427 NULL, /* pFillRgn */
428 NULL, /* pFlattenPath */
429 NULL, /* pFontIsLinked */
430 NULL, /* pFrameRgn */
431 NULL, /* pGdiComment */
432 NULL, /* pGetBoundsRect */
433 NULL, /* pGetCharABCWidths */
434 NULL, /* pGetCharABCWidthsI */
435 NULL, /* pGetCharWidth */
436 NULL, /* pGetDeviceCaps */
437 NULL, /* pGetDeviceGammaRamp */
438 NULL, /* pGetFontData */
439 NULL, /* pGetFontRealizationInfo */
440 NULL, /* pGetFontUnicodeRanges */
441 NULL, /* pGetGlyphIndices */
442 NULL, /* pGetGlyphOutline */
443 NULL, /* pGetICMProfile */
444 dibdrv_GetImage, /* pGetImage */
445 NULL, /* pGetKerningPairs */
446 dibdrv_GetNearestColor, /* pGetNearestColor */
447 NULL, /* pGetOutlineTextMetrics */
448 dibdrv_GetPixel, /* pGetPixel */
449 NULL, /* pGetSystemPaletteEntries */
450 NULL, /* pGetTextCharsetInfo */
451 NULL, /* pGetTextExtentExPoint */
452 NULL, /* pGetTextExtentExPointI */
453 NULL, /* pGetTextFace */
454 NULL, /* pGetTextMetrics */
455 dibdrv_GradientFill, /* pGradientFill */
456 NULL, /* pIntersectClipRect */
457 NULL, /* pInvertRgn */
458 dibdrv_LineTo, /* pLineTo */
459 NULL, /* pModifyWorldTransform */
460 NULL, /* pMoveTo */
461 NULL, /* pOffsetClipRgn */
462 NULL, /* pOffsetViewportOrg */
463 NULL, /* pOffsetWindowOrg */
464 dibdrv_PaintRgn, /* pPaintRgn */
465 dibdrv_PatBlt, /* pPatBlt */
466 dibdrv_Pie, /* pPie */
467 NULL, /* pPolyBezier */
468 NULL, /* pPolyBezierTo */
469 NULL, /* pPolyDraw */
470 dibdrv_PolyPolygon, /* pPolyPolygon */
471 dibdrv_PolyPolyline, /* pPolyPolyline */
472 dibdrv_Polygon, /* pPolygon */
473 dibdrv_Polyline, /* pPolyline */
474 NULL, /* pPolylineTo */
475 dibdrv_PutImage, /* pPutImage */
476 NULL, /* pRealizeDefaultPalette */
477 NULL, /* pRealizePalette */
478 dibdrv_Rectangle, /* pRectangle */
479 NULL, /* pResetDC */
480 NULL, /* pRestoreDC */
481 dibdrv_RoundRect, /* pRoundRect */
482 NULL, /* pSaveDC */
483 NULL, /* pScaleViewportExt */
484 NULL, /* pScaleWindowExt */
485 dibdrv_SelectBitmap, /* pSelectBitmap */
486 dibdrv_SelectBrush, /* pSelectBrush */
487 NULL, /* pSelectClipPath */
488 dibdrv_SelectFont, /* pSelectFont */
489 NULL, /* pSelectPalette */
490 dibdrv_SelectPen, /* pSelectPen */
491 NULL, /* pSetArcDirection */
492 NULL, /* pSetBkColor */
493 NULL, /* pSetBkMode */
494 dibdrv_SetBoundsRect, /* pSetBoundsRect */
495 dibdrv_SetDCBrushColor, /* pSetDCBrushColor */
496 dibdrv_SetDCPenColor, /* pSetDCPenColor */
497 NULL, /* pSetDIBitsToDevice */
498 dibdrv_SetDeviceClipping, /* pSetDeviceClipping */
499 NULL, /* pSetDeviceGammaRamp */
500 NULL, /* pSetLayout */
501 NULL, /* pSetMapMode */
502 NULL, /* pSetMapperFlags */
503 dibdrv_SetPixel, /* pSetPixel */
504 NULL, /* pSetPolyFillMode */
505 NULL, /* pSetROP2 */
506 NULL, /* pSetRelAbs */
507 NULL, /* pSetStretchBltMode */
508 NULL, /* pSetTextAlign */
509 NULL, /* pSetTextCharacterExtra */
510 NULL, /* pSetTextColor */
511 NULL, /* pSetTextJustification */
512 NULL, /* pSetViewportExt */
513 NULL, /* pSetViewportOrg */
514 NULL, /* pSetWindowExt */
515 NULL, /* pSetWindowOrg */
516 NULL, /* pSetWorldTransform */
517 NULL, /* pStartDoc */
518 NULL, /* pStartPage */
519 dibdrv_StretchBlt, /* pStretchBlt */
520 NULL, /* pStretchDIBits */
521 NULL, /* pStrokeAndFillPath */
522 NULL, /* pStrokePath */
523 NULL, /* pUnrealizePalette */
524 NULL, /* pWidenPath */
525 dibdrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
526 GDI_PRIORITY_DIB_DRV /* priority */
530 /***********************************************************************
531 * Driver for window surfaces.
533 * It uses the DIB engine but needs extra locking since multiple DCs
534 * can paint to the same window.
537 #define FLUSH_PERIOD 50 /* time in ms since drawing started for forcing a surface flush */
539 struct windrv_physdev
541 struct gdi_physdev dev;
542 struct dibdrv_physdev *dibdrv;
543 struct window_surface *surface;
544 DWORD start_ticks;
547 static const struct gdi_dc_funcs window_driver;
549 static inline struct windrv_physdev *get_windrv_physdev( PHYSDEV dev )
551 return (struct windrv_physdev *)dev;
554 static inline void lock_surface( struct windrv_physdev *dev )
556 GDI_CheckNotLock();
557 dev->surface->funcs->lock( dev->surface );
558 if (is_rect_empty( dev->dibdrv->bounds )) dev->start_ticks = GetTickCount();
561 static inline void unlock_surface( struct windrv_physdev *dev )
563 dev->surface->funcs->unlock( dev->surface );
564 if (GetTickCount() - dev->start_ticks > FLUSH_PERIOD) dev->surface->funcs->flush( dev->surface );
567 static void unlock_bits_surface( struct gdi_image_bits *bits )
569 struct window_surface *surface = bits->param;
570 surface->funcs->unlock( surface );
573 void dibdrv_set_window_surface( DC *dc, struct window_surface *surface )
575 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
576 BITMAPINFO *info = (BITMAPINFO *)buffer;
577 RECT rect;
578 void *bits;
579 PHYSDEV windev;
580 struct windrv_physdev *physdev;
581 struct dibdrv_physdev *dibdrv;
583 TRACE( "%p %p\n", dc->hSelf, surface );
585 windev = pop_dc_driver( dc, &window_driver );
587 if (surface)
589 if (windev) push_dc_driver( &dc->physDev, windev, windev->funcs );
590 else
592 if (!window_driver.pCreateDC( &dc->physDev, NULL, NULL, NULL, NULL )) return;
593 windev = find_dc_driver( dc, &window_driver );
596 physdev = get_windrv_physdev( windev );
597 window_surface_add_ref( surface );
598 if (physdev->surface) window_surface_release( physdev->surface );
599 physdev->surface = surface;
601 dibdrv = physdev->dibdrv;
602 bits = surface->funcs->get_info( surface, info );
603 init_dib_info_from_bitmapinfo( &dibdrv->dib, info, bits );
604 /* clip the device rect to the surface */
605 rect = surface->rect;
606 offset_rect( &rect, dc->device_rect.left, dc->device_rect.top );
607 intersect_rect( &dc->device_rect, &dc->device_rect, &rect );
608 dibdrv->dib.rect = dc->vis_rect;
609 offset_rect( &dibdrv->dib.rect, -rect.left, -rect.top );
610 dibdrv->bounds = surface->funcs->get_bounds( surface );
611 DC_InitDC( dc );
613 else if (windev)
615 dib_driver.pDeleteDC( pop_dc_driver( dc, &dib_driver ));
616 windev->funcs->pDeleteDC( windev );
617 DC_InitDC( dc );
621 static BOOL windrv_AlphaBlend( PHYSDEV dst_dev, struct bitblt_coords *dst,
622 PHYSDEV src_dev, struct bitblt_coords *src, BLENDFUNCTION func )
624 struct windrv_physdev *physdev = get_windrv_physdev( dst_dev );
625 BOOL ret;
627 lock_surface( physdev );
628 dst_dev = GET_NEXT_PHYSDEV( dst_dev, pAlphaBlend );
629 ret = dst_dev->funcs->pAlphaBlend( dst_dev, dst, src_dev, src, func );
630 unlock_surface( physdev );
631 return ret;
634 static BOOL windrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
635 INT xstart, INT ystart, INT xend, INT yend )
637 struct windrv_physdev *physdev = get_windrv_physdev( dev );
638 BOOL ret;
640 lock_surface( physdev );
641 dev = GET_NEXT_PHYSDEV( dev, pArc );
642 ret = dev->funcs->pArc( dev, left, top, right, bottom, xstart, ystart, xend, yend );
643 unlock_surface( physdev );
644 return ret;
647 static BOOL windrv_ArcTo( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
648 INT xstart, INT ystart, INT xend, INT yend )
650 struct windrv_physdev *physdev = get_windrv_physdev( dev );
651 BOOL ret;
653 lock_surface( physdev );
654 dev = GET_NEXT_PHYSDEV( dev, pArc );
655 ret = dev->funcs->pArcTo( dev, left, top, right, bottom, xstart, ystart, xend, yend );
656 unlock_surface( physdev );
657 return ret;
660 static DWORD windrv_BlendImage( PHYSDEV dev, BITMAPINFO *info, const struct gdi_image_bits *bits,
661 struct bitblt_coords *src, struct bitblt_coords *dst, BLENDFUNCTION blend )
663 struct windrv_physdev *physdev = get_windrv_physdev( dev );
664 DWORD ret;
666 lock_surface( physdev );
667 dev = GET_NEXT_PHYSDEV( dev, pBlendImage );
668 ret = dev->funcs->pBlendImage( dev, info, bits, src, dst, blend );
669 unlock_surface( physdev );
670 return ret;
673 static BOOL windrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
674 INT xstart, INT ystart, INT xend, INT yend )
676 struct windrv_physdev *physdev = get_windrv_physdev( dev );
677 BOOL ret;
679 lock_surface( physdev );
680 dev = GET_NEXT_PHYSDEV( dev, pChord );
681 ret = dev->funcs->pChord( dev, left, top, right, bottom, xstart, ystart, xend, yend );
682 unlock_surface( physdev );
683 return ret;
686 static BOOL windrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
687 LPCWSTR output, const DEVMODEW *devmode )
689 struct windrv_physdev *physdev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physdev) );
691 if (!physdev) return FALSE;
693 if (!dib_driver.pCreateDC( dev, NULL, NULL, NULL, NULL ))
695 HeapFree( GetProcessHeap(), 0, physdev );
696 return FALSE;
698 physdev->dibdrv = get_dibdrv_pdev( *dev );
699 push_dc_driver( dev, &physdev->dev, &window_driver );
700 return TRUE;
703 static BOOL windrv_DeleteDC( PHYSDEV dev )
705 struct windrv_physdev *physdev = get_windrv_physdev( dev );
707 window_surface_release( physdev->surface );
708 HeapFree( GetProcessHeap(), 0, physdev );
709 return TRUE;
712 static BOOL windrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
714 struct windrv_physdev *physdev = get_windrv_physdev( dev );
715 BOOL ret;
717 lock_surface( physdev );
718 dev = GET_NEXT_PHYSDEV( dev, pEllipse );
719 ret = dev->funcs->pEllipse( dev, left, top, right, bottom );
720 unlock_surface( physdev );
721 return ret;
724 static BOOL windrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
726 struct windrv_physdev *physdev = get_windrv_physdev( dev );
727 BOOL ret;
729 lock_surface( physdev );
730 dev = GET_NEXT_PHYSDEV( dev, pExtFloodFill );
731 ret = dev->funcs->pExtFloodFill( dev, x, y, color, type );
732 unlock_surface( physdev );
733 return ret;
736 static BOOL windrv_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags, const RECT *rect,
737 LPCWSTR str, UINT count, const INT *dx )
739 struct windrv_physdev *physdev = get_windrv_physdev( dev );
740 BOOL ret;
742 lock_surface( physdev );
743 dev = GET_NEXT_PHYSDEV( dev, pExtTextOut );
744 ret = dev->funcs->pExtTextOut( dev, x, y, flags, rect, str, count, dx );
745 unlock_surface( physdev );
746 return ret;
749 static DWORD windrv_GetImage( PHYSDEV dev, BITMAPINFO *info,
750 struct gdi_image_bits *bits, struct bitblt_coords *src )
752 struct windrv_physdev *physdev = get_windrv_physdev( dev );
753 DWORD ret;
755 lock_surface( physdev );
756 dev = GET_NEXT_PHYSDEV( dev, pGetImage );
757 ret = dev->funcs->pGetImage( dev, info, bits, src );
759 /* don't return alpha if original surface doesn't support it */
760 if (info->bmiHeader.biBitCount == 32 &&
761 info->bmiHeader.biCompression == BI_RGB &&
762 physdev->dibdrv->dib.compression == BI_BITFIELDS)
764 DWORD *colors = (DWORD *)info->bmiColors;
765 colors[0] = 0xff0000;
766 colors[1] = 0x00ff00;
767 colors[2] = 0x0000ff;
768 info->bmiHeader.biCompression = BI_BITFIELDS;
771 if (!bits->is_copy)
773 /* use the freeing callback to unlock the surface */
774 assert( !bits->free );
775 bits->free = unlock_bits_surface;
776 bits->param = physdev->surface;
778 else unlock_surface( physdev );
779 return ret;
782 static COLORREF windrv_GetPixel( PHYSDEV dev, INT x, INT y )
784 struct windrv_physdev *physdev = get_windrv_physdev( dev );
785 COLORREF ret;
787 lock_surface( physdev );
788 dev = GET_NEXT_PHYSDEV( dev, pGetPixel );
789 ret = dev->funcs->pGetPixel( dev, x, y );
790 unlock_surface( physdev );
791 return ret;
794 static BOOL windrv_GradientFill( PHYSDEV dev, TRIVERTEX *vert_array, ULONG nvert,
795 void * grad_array, ULONG ngrad, ULONG mode )
797 struct windrv_physdev *physdev = get_windrv_physdev( dev );
798 BOOL ret;
800 lock_surface( physdev );
801 dev = GET_NEXT_PHYSDEV( dev, pGradientFill );
802 ret = dev->funcs->pGradientFill( dev, vert_array, nvert, grad_array, ngrad, mode );
803 unlock_surface( physdev );
804 return ret;
807 static BOOL windrv_LineTo( PHYSDEV dev, INT x, INT y )
809 struct windrv_physdev *physdev = get_windrv_physdev( dev );
810 BOOL ret;
812 lock_surface( physdev );
813 dev = GET_NEXT_PHYSDEV( dev, pLineTo );
814 ret = dev->funcs->pLineTo( dev, x, y );
815 unlock_surface( physdev );
816 return ret;
819 static BOOL windrv_PaintRgn( PHYSDEV dev, HRGN rgn )
821 struct windrv_physdev *physdev = get_windrv_physdev( dev );
822 BOOL ret;
824 lock_surface( physdev );
825 dev = GET_NEXT_PHYSDEV( dev, pPaintRgn );
826 ret = dev->funcs->pPaintRgn( dev, rgn );
827 unlock_surface( physdev );
828 return ret;
831 static BOOL windrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
833 struct windrv_physdev *physdev = get_windrv_physdev( dev );
834 BOOL ret;
836 lock_surface( physdev );
837 dev = GET_NEXT_PHYSDEV( dev, pPatBlt );
838 ret = dev->funcs->pPatBlt( dev, dst, rop );
839 unlock_surface( physdev );
840 return ret;
843 static BOOL windrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
844 INT xstart, INT ystart, INT xend, INT yend )
846 struct windrv_physdev *physdev = get_windrv_physdev( dev );
847 BOOL ret;
849 lock_surface( physdev );
850 dev = GET_NEXT_PHYSDEV( dev, pPie );
851 ret = dev->funcs->pPie( dev, left, top, right, bottom, xstart, ystart, xend, yend );
852 unlock_surface( physdev );
853 return ret;
856 static BOOL windrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
858 struct windrv_physdev *physdev = get_windrv_physdev( dev );
859 BOOL ret;
861 lock_surface( physdev );
862 dev = GET_NEXT_PHYSDEV( dev, pPolyPolygon );
863 ret = dev->funcs->pPolyPolygon( dev, points, counts, polygons );
864 unlock_surface( physdev );
865 return ret;
868 static BOOL windrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
870 struct windrv_physdev *physdev = get_windrv_physdev( dev );
871 BOOL ret;
873 lock_surface( physdev );
874 dev = GET_NEXT_PHYSDEV( dev, pPolyPolyline );
875 ret = dev->funcs->pPolyPolyline( dev, points, counts, lines );
876 unlock_surface( physdev );
877 return ret;
880 static BOOL windrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
882 struct windrv_physdev *physdev = get_windrv_physdev( dev );
883 BOOL ret;
885 lock_surface( physdev );
886 dev = GET_NEXT_PHYSDEV( dev, pPolygon );
887 ret = dev->funcs->pPolygon( dev, points, count );
888 unlock_surface( physdev );
889 return ret;
892 static BOOL windrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
894 struct windrv_physdev *physdev = get_windrv_physdev( dev );
895 BOOL ret;
897 lock_surface( physdev );
898 dev = GET_NEXT_PHYSDEV( dev, pPolyline );
899 ret = dev->funcs->pPolyline( dev, points, count );
900 unlock_surface( physdev );
901 return ret;
904 static DWORD windrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
905 const struct gdi_image_bits *bits, struct bitblt_coords *src,
906 struct bitblt_coords *dst, DWORD rop )
908 struct windrv_physdev *physdev = get_windrv_physdev( dev );
909 DWORD ret;
911 lock_surface( physdev );
912 dev = GET_NEXT_PHYSDEV( dev, pPutImage );
913 ret = dev->funcs->pPutImage( dev, clip, info, bits, src, dst, rop );
914 unlock_surface( physdev );
915 return ret;
918 static BOOL windrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
920 struct windrv_physdev *physdev = get_windrv_physdev( dev );
921 BOOL ret;
923 lock_surface( physdev );
924 dev = GET_NEXT_PHYSDEV( dev, pRectangle );
925 ret = dev->funcs->pRectangle( dev, left, top, right, bottom );
926 unlock_surface( physdev );
927 return ret;
930 static BOOL windrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
931 INT ell_width, INT ell_height )
933 struct windrv_physdev *physdev = get_windrv_physdev( dev );
934 BOOL ret;
936 lock_surface( physdev );
937 dev = GET_NEXT_PHYSDEV( dev, pRoundRect );
938 ret = dev->funcs->pRoundRect( dev, left, top, right, bottom, ell_width, ell_height );
939 unlock_surface( physdev );
940 return ret;
943 static UINT windrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
945 /* do nothing, we use the dibdrv bounds tracking for our own purpose */
946 return DCB_RESET;
949 static INT windrv_SetDIBitsToDevice( PHYSDEV dev, INT x_dst, INT y_dst, DWORD cx, DWORD cy,
950 INT x_src, INT y_src, UINT startscan, UINT lines,
951 const void *bits, BITMAPINFO *src_info, UINT coloruse )
953 struct windrv_physdev *physdev = get_windrv_physdev( dev );
954 INT ret;
956 lock_surface( physdev );
957 dev = GET_NEXT_PHYSDEV( dev, pSetDIBitsToDevice );
958 ret = dev->funcs->pSetDIBitsToDevice( dev, x_dst, y_dst, cx, cy,
959 x_src, y_src, startscan, lines, bits, src_info, coloruse );
960 unlock_surface( physdev );
961 return ret;
964 static void windrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
966 dev = GET_NEXT_PHYSDEV( dev, pSetDeviceClipping );
967 dev->funcs->pSetDeviceClipping( dev, rgn );
968 /* also forward to the graphics driver for the OpenGL case */
969 if (dev->funcs == &dib_driver)
971 dev = GET_NEXT_PHYSDEV( dev, pSetDeviceClipping );
972 dev->funcs->pSetDeviceClipping( dev, rgn );
976 static COLORREF windrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
978 struct windrv_physdev *physdev = get_windrv_physdev( dev );
979 COLORREF ret;
981 lock_surface( physdev );
982 dev = GET_NEXT_PHYSDEV( dev, pSetPixel );
983 ret = dev->funcs->pSetPixel( dev, x, y, color );
984 unlock_surface( physdev );
985 return ret;
988 static BOOL windrv_StretchBlt( PHYSDEV dst_dev, struct bitblt_coords *dst,
989 PHYSDEV src_dev, struct bitblt_coords *src, DWORD rop )
991 struct windrv_physdev *physdev = get_windrv_physdev( dst_dev );
992 BOOL ret;
994 lock_surface( physdev );
995 dst_dev = GET_NEXT_PHYSDEV( dst_dev, pStretchBlt );
996 ret = dst_dev->funcs->pStretchBlt( dst_dev, dst, src_dev, src, rop );
997 unlock_surface( physdev );
998 return ret;
1001 static INT windrv_StretchDIBits( PHYSDEV dev, INT x_dst, INT y_dst, INT width_dst, INT height_dst,
1002 INT x_src, INT y_src, INT width_src, INT height_src, const void *bits,
1003 BITMAPINFO *src_info, UINT coloruse, DWORD rop )
1005 struct windrv_physdev *physdev = get_windrv_physdev( dev );
1006 INT ret;
1008 lock_surface( physdev );
1009 dev = GET_NEXT_PHYSDEV( dev, pStretchDIBits );
1010 ret = dev->funcs->pStretchDIBits( dev, x_dst, y_dst, width_dst, height_dst,
1011 x_src, y_src, width_src, height_src, bits, src_info, coloruse, rop );
1012 unlock_surface( physdev );
1013 return ret;
1016 static struct opengl_funcs *windrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
1018 dev = GET_NEXT_PHYSDEV( dev, wine_get_wgl_driver );
1019 if (dev->funcs == &dib_driver) dev = GET_NEXT_PHYSDEV( dev, wine_get_wgl_driver );
1020 return dev->funcs->wine_get_wgl_driver( dev, version );
1023 static const struct gdi_dc_funcs window_driver =
1025 NULL, /* pAbortDoc */
1026 NULL, /* pAbortPath */
1027 windrv_AlphaBlend, /* pAlphaBlend */
1028 NULL, /* pAngleArc */
1029 windrv_Arc, /* pArc */
1030 windrv_ArcTo, /* pArcTo */
1031 NULL, /* pBeginPath */
1032 windrv_BlendImage, /* pBlendImage */
1033 windrv_Chord, /* pChord */
1034 NULL, /* pCloseFigure */
1035 NULL, /* pCreateCompatibleDC */
1036 windrv_CreateDC, /* pCreateDC */
1037 windrv_DeleteDC, /* pDeleteDC */
1038 NULL, /* pDeleteObject */
1039 NULL, /* pDeviceCapabilities */
1040 windrv_Ellipse, /* pEllipse */
1041 NULL, /* pEndDoc */
1042 NULL, /* pEndPage */
1043 NULL, /* pEndPath */
1044 NULL, /* pEnumFonts */
1045 NULL, /* pEnumICMProfiles */
1046 NULL, /* pExcludeClipRect */
1047 NULL, /* pExtDeviceMode */
1048 NULL, /* pExtEscape */
1049 windrv_ExtFloodFill, /* pExtFloodFill */
1050 NULL, /* pExtSelectClipRgn */
1051 windrv_ExtTextOut, /* pExtTextOut */
1052 NULL, /* pFillPath */
1053 NULL, /* pFillRgn */
1054 NULL, /* pFlattenPath */
1055 NULL, /* pFontIsLinked */
1056 NULL, /* pFrameRgn */
1057 NULL, /* pGdiComment */
1058 NULL, /* pGetBoundsRect */
1059 NULL, /* pGetCharABCWidths */
1060 NULL, /* pGetCharABCWidthsI */
1061 NULL, /* pGetCharWidth */
1062 NULL, /* pGetDeviceCaps */
1063 NULL, /* pGetDeviceGammaRamp */
1064 NULL, /* pGetFontData */
1065 NULL, /* pGetFontRealizationInfo */
1066 NULL, /* pGetFontUnicodeRanges */
1067 NULL, /* pGetGlyphIndices */
1068 NULL, /* pGetGlyphOutline */
1069 NULL, /* pGetICMProfile */
1070 windrv_GetImage, /* pGetImage */
1071 NULL, /* pGetKerningPairs */
1072 NULL, /* pGetNearestColor */
1073 NULL, /* pGetOutlineTextMetrics */
1074 windrv_GetPixel, /* pGetPixel */
1075 NULL, /* pGetSystemPaletteEntries */
1076 NULL, /* pGetTextCharsetInfo */
1077 NULL, /* pGetTextExtentExPoint */
1078 NULL, /* pGetTextExtentExPointI */
1079 NULL, /* pGetTextFace */
1080 NULL, /* pGetTextMetrics */
1081 windrv_GradientFill, /* pGradientFill */
1082 NULL, /* pIntersectClipRect */
1083 NULL, /* pInvertRgn */
1084 windrv_LineTo, /* pLineTo */
1085 NULL, /* pModifyWorldTransform */
1086 NULL, /* pMoveTo */
1087 NULL, /* pOffsetClipRgn */
1088 NULL, /* pOffsetViewportOrg */
1089 NULL, /* pOffsetWindowOrg */
1090 windrv_PaintRgn, /* pPaintRgn */
1091 windrv_PatBlt, /* pPatBlt */
1092 windrv_Pie, /* pPie */
1093 NULL, /* pPolyBezier */
1094 NULL, /* pPolyBezierTo */
1095 NULL, /* pPolyDraw */
1096 windrv_PolyPolygon, /* pPolyPolygon */
1097 windrv_PolyPolyline, /* pPolyPolyline */
1098 windrv_Polygon, /* pPolygon */
1099 windrv_Polyline, /* pPolyline */
1100 NULL, /* pPolylineTo */
1101 windrv_PutImage, /* pPutImage */
1102 NULL, /* pRealizeDefaultPalette */
1103 NULL, /* pRealizePalette */
1104 windrv_Rectangle, /* pRectangle */
1105 NULL, /* pResetDC */
1106 NULL, /* pRestoreDC */
1107 windrv_RoundRect, /* pRoundRect */
1108 NULL, /* pSaveDC */
1109 NULL, /* pScaleViewportExt */
1110 NULL, /* pScaleWindowExt */
1111 NULL, /* pSelectBitmap */
1112 NULL, /* pSelectBrush */
1113 NULL, /* pSelectClipPath */
1114 NULL, /* pSelectFont */
1115 NULL, /* pSelectPalette */
1116 NULL, /* pSelectPen */
1117 NULL, /* pSetArcDirection */
1118 NULL, /* pSetBkColor */
1119 NULL, /* pSetBkMode */
1120 windrv_SetBoundsRect, /* pSetBoundsRect */
1121 NULL, /* pSetDCBrushColor */
1122 NULL, /* pSetDCPenColor */
1123 windrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
1124 windrv_SetDeviceClipping, /* pSetDeviceClipping */
1125 NULL, /* pSetDeviceGammaRamp */
1126 NULL, /* pSetLayout */
1127 NULL, /* pSetMapMode */
1128 NULL, /* pSetMapperFlags */
1129 windrv_SetPixel, /* pSetPixel */
1130 NULL, /* pSetPolyFillMode */
1131 NULL, /* pSetROP2 */
1132 NULL, /* pSetRelAbs */
1133 NULL, /* pSetStretchBltMode */
1134 NULL, /* pSetTextAlign */
1135 NULL, /* pSetTextCharacterExtra */
1136 NULL, /* pSetTextColor */
1137 NULL, /* pSetTextJustification */
1138 NULL, /* pSetViewportExt */
1139 NULL, /* pSetViewportOrg */
1140 NULL, /* pSetWindowExt */
1141 NULL, /* pSetWindowOrg */
1142 NULL, /* pSetWorldTransform */
1143 NULL, /* pStartDoc */
1144 NULL, /* pStartPage */
1145 windrv_StretchBlt, /* pStretchBlt */
1146 windrv_StretchDIBits, /* pStretchDIBits */
1147 NULL, /* pStrokeAndFillPath */
1148 NULL, /* pStrokePath */
1149 NULL, /* pUnrealizePalette */
1150 NULL, /* pWidenPath */
1151 windrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
1152 GDI_PRIORITY_DIB_DRV + 10 /* priority */