gdi32: Store internal brush data in separate fields in the brush object.

This commit is contained in:
Alexandre Julliard 2011-11-02 20:58:36 +01:00
parent b4987d095f
commit 20ecd97bee
1 changed files with 29 additions and 42 deletions

View File

@ -36,6 +36,10 @@ typedef struct
{ {
GDIOBJHDR header; GDIOBJHDR header;
LOGBRUSH logbrush; LOGBRUSH logbrush;
HBITMAP bitmap; /* bitmap handle for DDB pattern brushes */
BITMAPINFO *info; /* DIB info for pattern brushes */
struct gdi_image_bits bits; /* DIB bits for pattern brushes */
UINT usage; /* color usage for DIB info */
} BRUSHOBJ; } BRUSHOBJ;
#define NB_HATCH_STYLES 6 #define NB_HATCH_STYLES 6
@ -77,12 +81,11 @@ HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush )
{ {
BRUSHOBJ * ptr; BRUSHOBJ * ptr;
HBRUSH hbrush; HBRUSH hbrush;
HGLOBAL hmem = 0;
if (!(ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(*ptr) ))) return 0; if (!(ptr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ptr) ))) return 0;
ptr->logbrush.lbStyle = brush->lbStyle; ptr->logbrush = *brush;
ptr->logbrush.lbColor = brush->lbColor;
ptr->logbrush.lbHatch = brush->lbHatch;
switch (ptr->logbrush.lbStyle) switch (ptr->logbrush.lbStyle)
{ {
@ -95,30 +98,25 @@ HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush )
ptr->logbrush.lbStyle = BS_PATTERN; ptr->logbrush.lbStyle = BS_PATTERN;
/* fall through */ /* fall through */
case BS_PATTERN: case BS_PATTERN:
ptr->logbrush.lbHatch = (ULONG_PTR)BITMAP_CopyBitmap( (HBITMAP) ptr->logbrush.lbHatch ); ptr->bitmap = BITMAP_CopyBitmap( (HBITMAP)ptr->logbrush.lbHatch );
if (!ptr->bitmap) goto error;
ptr->logbrush.lbHatch = (ULONG_PTR)ptr->bitmap;
ptr->logbrush.lbColor = 0; ptr->logbrush.lbColor = 0;
if (!ptr->logbrush.lbHatch) goto error;
break;
case BS_DIBPATTERNPT:
ptr->logbrush.lbStyle = BS_DIBPATTERN;
ptr->logbrush.lbHatch = (ULONG_PTR)copy_packed_dib( (BITMAPINFO *) ptr->logbrush.lbHatch,
ptr->logbrush.lbColor );
if (!ptr->logbrush.lbHatch) goto error;
break; break;
case BS_DIBPATTERN: case BS_DIBPATTERN:
{ hmem = (HGLOBAL)ptr->logbrush.lbHatch;
BITMAPINFO* bmi; if (!(ptr->logbrush.lbHatch = (ULONG_PTR)GlobalLock( hmem ))) goto error;
HGLOBAL h = (HGLOBAL)ptr->logbrush.lbHatch; /* fall through */
case BS_DIBPATTERNPT:
ptr->usage = ptr->logbrush.lbColor;
ptr->info = copy_packed_dib( (BITMAPINFO *)ptr->logbrush.lbHatch, ptr->usage );
if (hmem) GlobalUnlock( hmem );
if (!ptr->info) goto error;
ptr->bits.ptr = (char *)ptr->info + bitmap_info_size( ptr->info, ptr->usage );
ptr->logbrush.lbStyle = BS_DIBPATTERN; ptr->logbrush.lbStyle = BS_DIBPATTERN;
if (!(bmi = GlobalLock( h ))) goto error; ptr->logbrush.lbHatch = (ULONG_PTR)ptr->info;
ptr->logbrush.lbHatch = (ULONG_PTR)copy_packed_dib( bmi, ptr->logbrush.lbColor );
GlobalUnlock( h );
if (!ptr->logbrush.lbHatch) goto error;
break; break;
}
case BS_DIBPATTERN8X8: case BS_DIBPATTERN8X8:
case BS_MONOPATTERN: case BS_MONOPATTERN:
@ -135,13 +133,8 @@ HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush )
} }
error: error:
if (ptr->logbrush.lbHatch) if (ptr->bitmap) DeleteObject( ptr->bitmap );
{ HeapFree( GetProcessHeap(), 0, ptr->info );
if (ptr->logbrush.lbStyle == BS_PATTERN)
DeleteObject( (HGDIOBJ)ptr->logbrush.lbHatch );
else if (ptr->logbrush.lbStyle == BS_DIBPATTERN)
HeapFree( GetProcessHeap(), 0, (void *)ptr->logbrush.lbHatch );
}
HeapFree( GetProcessHeap(), 0, ptr ); HeapFree( GetProcessHeap(), 0, ptr );
return 0; return 0;
} }
@ -411,15 +404,9 @@ static BOOL BRUSH_DeleteObject( HGDIOBJ handle )
BRUSHOBJ *brush = free_gdi_handle( handle ); BRUSHOBJ *brush = free_gdi_handle( handle );
if (!brush) return FALSE; if (!brush) return FALSE;
switch(brush->logbrush.lbStyle) if (brush->bits.free) brush->bits.free( &brush->bits );
{ if (brush->bitmap) DeleteObject( brush->bitmap );
case BS_PATTERN: HeapFree( GetProcessHeap(), 0, brush->info );
DeleteObject( (HGDIOBJ)brush->logbrush.lbHatch );
break;
case BS_DIBPATTERN:
HeapFree( GetProcessHeap(), 0, (void *)brush->logbrush.lbHatch );
break;
}
return HeapFree( GetProcessHeap(), 0, brush ); return HeapFree( GetProcessHeap(), 0, brush );
} }