From dc3a08d840186c7692cc3cae45bdd517ab099e07 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Tue, 14 Feb 2012 13:50:59 -0600 Subject: [PATCH] gdiplus: Rewrite SOFTWARE_GdipFillRegion to call brush_fill_pixels less. --- dlls/gdiplus/graphics.c | 186 ++++++++++++++++++++---------------------------- 1 file changed, 79 insertions(+), 107 deletions(-) diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c index 6cf0a68abed..ddae06ee3b5 100644 --- a/dlls/gdiplus/graphics.c +++ b/dlls/gdiplus/graphics.c @@ -413,6 +413,61 @@ static GpStatus alpha_blend_pixels(GpGraphics *graphics, INT dst_x, INT dst_y, } } +static GpStatus alpha_blend_pixels_hrgn(GpGraphics *graphics, INT dst_x, INT dst_y, + const BYTE *src, INT src_width, INT src_height, INT src_stride, HRGN hregion) +{ + GpStatus stat=Ok; + + if (graphics->image && graphics->image->type == ImageTypeBitmap) + { + int i, size; + RGNDATA *rgndata; + RECT *rects; + + size = GetRegionData(hregion, 0, NULL); + + rgndata = GdipAlloc(size); + if (!rgndata) + return OutOfMemory; + + GetRegionData(hregion, size, rgndata); + + rects = (RECT*)&rgndata->Buffer; + + for (i=0; stat == Ok && irdh.nCount; i++) + { + stat = alpha_blend_pixels(graphics, rects[i].left, rects[i].top, + &src[(rects[i].left - dst_x) * 4 + (rects[i].top - dst_y) * src_stride], + rects[i].right - rects[i].left, rects[i].bottom - rects[i].top, + src_stride); + } + + GdipFree(rgndata); + + return stat; + } + else if (graphics->image && graphics->image->type == ImageTypeMetafile) + { + ERR("This should not be used for metafiles; fix caller\n"); + return NotImplemented; + } + else + { + int save; + + save = SaveDC(graphics->hdc); + + ExtSelectClipRgn(graphics->hdc, hregion, RGN_AND); + + stat = alpha_blend_pixels(graphics, dst_x, dst_y, src, src_width, + src_height, src_stride); + + RestoreDC(graphics->hdc, save); + + return stat; + } +} + static ARGB blend_colors(ARGB start, ARGB end, REAL position) { ARGB result=0; @@ -3928,12 +3983,12 @@ static GpStatus SOFTWARE_GdipFillRegion(GpGraphics *graphics, GpBrush *brush, { GpStatus stat; GpRegion *temp_region; - GpMatrix *world_to_device, *identity; + GpMatrix *world_to_device; GpRectF graphics_bounds; - UINT scans_count, i; - INT dummy; - GpRect *scans = NULL; DWORD *pixel_data; + HRGN hregion; + RECT bound_rect; + GpRect gp_bound_rect; if (!brush_can_fill_pixels(brush)) return NotImplemented; @@ -3959,125 +4014,42 @@ static GpStatus SOFTWARE_GdipFillRegion(GpGraphics *graphics, GpBrush *brush, stat = GdipCombineRegionRect(temp_region, &graphics_bounds, CombineModeIntersect); if (stat == Ok) - stat = GdipCreateMatrix(&identity); - - if (stat == Ok) - { - stat = GdipGetRegionScansCount(temp_region, &scans_count, identity); - - if (stat == Ok && scans_count != 0) - { - scans = GdipAlloc(sizeof(*scans) * scans_count); - if (!scans) - stat = OutOfMemory; - - if (stat == Ok) - { - stat = GdipGetRegionScansI(temp_region, scans, &dummy, identity); - - if (stat != Ok) - GdipFree(scans); - } - } - - GdipDeleteMatrix(identity); - } + stat = GdipGetRegionHRgn(temp_region, NULL, &hregion); GdipDeleteRegion(temp_region); } - if (stat == Ok && scans_count == 0) + if (stat == Ok && GetRgnBox(hregion, &bound_rect) == NULLREGION) + { + DeleteObject(hregion); return Ok; + } if (stat == Ok) { - if (!graphics->image) - { - /* If we have to go through gdi32, use as few alpha blends as possible. */ - INT min_x, min_y, max_x, max_y; - UINT data_width, data_height; - - min_x = scans[0].X; - min_y = scans[0].Y; - max_x = scans[0].X+scans[0].Width; - max_y = scans[0].Y+scans[0].Height; - - for (i=1; i max_size) - max_size = size; - } - - pixel_data = GdipAlloc(sizeof(*pixel_data) * max_size); - if (!pixel_data) - stat = OutOfMemory; + stat = brush_fill_pixels(graphics, brush, pixel_data, + &gp_bound_rect, gp_bound_rect.Width); if (stat == Ok) - { - for (i=0; i