Module: wine Branch: master Commit: 574a07e4c96da2541b44f2f2b0a29d0ab5262b25 URL: http://source.winehq.org/git/wine.git/?a=commit;h=574a07e4c96da2541b44f2f2b0...
Author: Alexandre Julliard julliard@winehq.org Date: Tue May 22 22:03:18 2012 +0200
gdi32: Add a helper function to allocate the brush bits.
---
dlls/gdi32/dibdrv/objects.c | 57 ++++++++++++++++-------------------------- 1 files changed, 22 insertions(+), 35 deletions(-)
diff --git a/dlls/gdi32/dibdrv/objects.c b/dlls/gdi32/dibdrv/objects.c index ce0b4a2..f5b4c05 100644 --- a/dlls/gdi32/dibdrv/objects.c +++ b/dlls/gdi32/dibdrv/objects.c @@ -1732,17 +1732,28 @@ static BOOL solid_brush(dibdrv_physdev *pdev, dib_brush *brush, dib_info *dib, return TRUE; }
-static void free_pattern_brush_bits( dib_brush *brush ) +static BOOL alloc_brush_mask_bits( dib_brush *brush ) +{ + DWORD size = brush->dib.height * abs(brush->dib.stride); + + assert(brush->masks.and == NULL); + assert(brush->masks.xor == NULL); + assert(brush->dib.stride > 0); + + if (!(brush->masks.and = HeapAlloc(GetProcessHeap(), 0, 2 * size))) return FALSE; + brush->masks.xor = (char *)brush->masks.and + size; + return TRUE; +} + +static void free_brush_mask_bits( dib_brush *brush ) { HeapFree(GetProcessHeap(), 0, brush->masks.and); - HeapFree(GetProcessHeap(), 0, brush->masks.xor); - brush->masks.and = NULL; - brush->masks.xor = NULL; + brush->masks.and = brush->masks.xor = NULL; }
void free_pattern_brush( dib_brush *brush ) { - free_pattern_brush_bits( brush ); + free_brush_mask_bits( brush ); free_dib_info( &brush->dib ); }
@@ -1752,20 +1763,10 @@ static BOOL create_pattern_brush_bits( dib_brush *brush ) DWORD *brush_bits = brush->dib.bits.ptr; DWORD *and_bits, *xor_bits;
- assert(brush->masks.and == NULL); - assert(brush->masks.xor == NULL); - - assert(brush->dib.stride > 0); - - and_bits = brush->masks.and = HeapAlloc(GetProcessHeap(), 0, size); - xor_bits = brush->masks.xor = HeapAlloc(GetProcessHeap(), 0, size); + if (!alloc_brush_mask_bits( brush )) return FALSE;
- if(!and_bits || !xor_bits) - { - ERR("Failed to create pattern brush bits\n"); - free_pattern_brush_bits( brush ); - return FALSE; - } + and_bits = brush->masks.and; + xor_bits = brush->masks.xor;
while(size) { @@ -1790,12 +1791,8 @@ static BOOL create_hatch_brush_bits(dibdrv_physdev *pdev, dib_brush *brush, BOOL { dib_info hatch; rop_mask fg_mask, bg_mask; - DWORD size; BOOL ret;
- assert(brush->masks.and == NULL); - assert(brush->masks.xor == NULL); - /* Just initialise brush dib with the color / sizing info. We don't need the bits as we'll calculate the rop masks straight from the hatch patterns. */ @@ -1809,17 +1806,7 @@ static BOOL create_hatch_brush_bits(dibdrv_physdev *pdev, dib_brush *brush, BOOL brush->dib.rect.right = 8; brush->dib.rect.bottom = 8;
- size = brush->dib.height * brush->dib.stride; - - brush->masks.and = HeapAlloc(GetProcessHeap(), 0, size); - brush->masks.xor = HeapAlloc(GetProcessHeap(), 0, size); - - if (!brush->masks.and || !brush->masks.xor) - { - ERR("Failed to create pattern brush bits\n"); - free_pattern_brush_bits( brush ); - return FALSE; - } + if (!alloc_brush_mask_bits( brush )) return FALSE;
hatch.bit_count = 1; hatch.height = hatch.width = 8; @@ -1841,7 +1828,7 @@ static BOOL create_hatch_brush_bits(dibdrv_physdev *pdev, dib_brush *brush, BOOL *needs_reselect = TRUE;
ret = brush->dib.funcs->create_rop_masks( &brush->dib, &hatch, &fg_mask, &bg_mask, &brush->masks ); - if(!ret) free_pattern_brush_bits( brush ); + if(!ret) free_brush_mask_bits( brush );
return ret; } @@ -1961,7 +1948,7 @@ static BOOL pattern_brush(dibdrv_physdev *pdev, dib_brush *brush, dib_info *dib,
if (rop != brush->rop) { - free_pattern_brush_bits( brush ); + free_brush_mask_bits( brush ); brush->rop = rop; }