[PATCH v2 4/9] gdi32: Reimplement CreateBrushIndirect on top of other brush constructors.
Huw Davies
huw at codeweavers.com
Wed Aug 25 07:39:48 CDT 2021
From: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
---
dlls/gdi32/brush.c | 96 +++-----------------------------------
dlls/gdi32/gdiobj.c | 14 +++---
dlls/gdi32/ntgdi_private.h | 1 +
dlls/gdi32/objects.c | 26 +++++++++++
dlls/gdi32/tests/brush.c | 11 +++++
5 files changed, 51 insertions(+), 97 deletions(-)
diff --git a/dlls/gdi32/brush.c b/dlls/gdi32/brush.c
index 5febac710dc..75737d1083b 100644
--- a/dlls/gdi32/brush.c
+++ b/dlls/gdi32/brush.c
@@ -167,26 +167,7 @@ BOOL get_brush_bitmap_info( HBRUSH handle, BITMAPINFO *info, void **bits, UINT *
}
-/***********************************************************************
- * CreateBrushIndirect (GDI32.@)
- *
- * Create a logical brush with a given style, color or pattern.
- *
- * PARAMS
- * brush [I] Pointer to a LOGBRUSH structure describing the desired brush.
- *
- * RETURNS
- * A handle to the created brush, or a NULL handle if the brush cannot be
- * created.
- *
- * NOTES
- * - The brush returned should be freed by the caller using DeleteObject()
- * when it is no longer required.
- * - Windows 95 and earlier cannot create brushes from bitmaps or DIBs larger
- * than 8x8 pixels. If a larger bitmap is given, only a portion of the bitmap
- * is used.
- */
-HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush )
+HBRUSH create_brush( const LOGBRUSH *brush )
{
BRUSHOBJ * ptr;
HBRUSH hbrush;
@@ -212,19 +193,6 @@ HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush )
* CreateHatchBrush (GDI32.@)
*
* Create a logical brush with a hatched pattern.
- *
- * PARAMS
- * style [I] Direction of lines for the hatch pattern (HS_* values from "wingdi.h")
- * color [I] Colour of the hatched pattern
- *
- * RETURNS
- * A handle to the created brush, or a NULL handle if the brush cannot
- * be created.
- *
- * NOTES
- * - This function uses CreateBrushIndirect() to create the brush.
- * - The brush returned should be freed by the caller using DeleteObject()
- * when it is no longer required.
*/
HBRUSH WINAPI CreateHatchBrush( INT style, COLORREF color )
{
@@ -236,7 +204,7 @@ HBRUSH WINAPI CreateHatchBrush( INT style, COLORREF color )
logbrush.lbColor = color;
logbrush.lbHatch = style;
- return CreateBrushIndirect( &logbrush );
+ return create_brush( &logbrush );
}
@@ -244,18 +212,6 @@ HBRUSH WINAPI CreateHatchBrush( INT style, COLORREF color )
* CreatePatternBrush (GDI32.@)
*
* Create a logical brush with a pattern from a bitmap.
- *
- * PARAMS
- * hbitmap [I] Bitmap containing pattern for the brush
- *
- * RETURNS
- * A handle to the created brush, or a NULL handle if the brush cannot
- * be created.
- *
- * NOTES
- * - This function uses CreateBrushIndirect() to create the brush.
- * - The brush returned should be freed by the caller using DeleteObject()
- * when it is no longer required.
*/
HBRUSH WINAPI CreatePatternBrush( HBITMAP hbitmap )
{
@@ -263,7 +219,7 @@ HBRUSH WINAPI CreatePatternBrush( HBITMAP hbitmap )
TRACE("%p\n", hbitmap );
logbrush.lbHatch = (ULONG_PTR)hbitmap;
- return CreateBrushIndirect( &logbrush );
+ return create_brush( &logbrush );
}
@@ -271,21 +227,6 @@ HBRUSH WINAPI CreatePatternBrush( HBITMAP hbitmap )
* CreateDIBPatternBrush (GDI32.@)
*
* Create a logical brush with a pattern from a DIB.
- *
- * PARAMS
- * hbitmap [I] Global object containing BITMAPINFO structure for the pattern
- * coloruse [I] Specifies color format, if provided
- *
- * RETURNS
- * A handle to the created brush, or a NULL handle if the brush cannot
- * be created.
- *
- * NOTES
- * - This function uses CreateBrushIndirect() to create the brush.
- * - The brush returned should be freed by the caller using DeleteObject()
- * when it is no longer required.
- * - This function is for compatibility only. CreateDIBPatternBrushPt() should
- * be used instead.
*/
HBRUSH WINAPI CreateDIBPatternBrush( HGLOBAL hbitmap, UINT coloruse )
{
@@ -298,7 +239,7 @@ HBRUSH WINAPI CreateDIBPatternBrush( HGLOBAL hbitmap, UINT coloruse )
logbrush.lbHatch = (ULONG_PTR)hbitmap;
- return CreateBrushIndirect( &logbrush );
+ return create_brush( &logbrush );
}
@@ -306,19 +247,6 @@ HBRUSH WINAPI CreateDIBPatternBrush( HGLOBAL hbitmap, UINT coloruse )
* CreateDIBPatternBrushPt (GDI32.@)
*
* Create a logical brush with a pattern from a DIB.
- *
- * PARAMS
- * data [I] Pointer to a BITMAPINFO structure and image data for the pattern
- * coloruse [I] Specifies color format, if provided
- *
- * RETURNS
- * A handle to the created brush, or a NULL handle if the brush cannot
- * be created.
- *
- * NOTES
- * - This function uses CreateBrushIndirect() to create the brush.
- * - The brush returned should be freed by the caller using DeleteObject()
- * when it is no longer required.
*/
HBRUSH WINAPI CreateDIBPatternBrushPt( const void* data, UINT coloruse )
{
@@ -335,7 +263,7 @@ HBRUSH WINAPI CreateDIBPatternBrushPt( const void* data, UINT coloruse )
logbrush.lbColor = coloruse;
logbrush.lbHatch = (ULONG_PTR)data;
- return CreateBrushIndirect( &logbrush );
+ return create_brush( &logbrush );
}
@@ -343,18 +271,6 @@ HBRUSH WINAPI CreateDIBPatternBrushPt( const void* data, UINT coloruse )
* CreateSolidBrush (GDI32.@)
*
* Create a logical brush consisting of a single colour.
- *
- * PARAMS
- * color [I] Colour to make the solid brush
- *
- * RETURNS
- * A handle to the newly created brush, or a NULL handle if the brush cannot
- * be created.
- *
- * NOTES
- * - This function uses CreateBrushIndirect() to create the brush.
- * - The brush returned should be freed by the caller using DeleteObject()
- * when it is no longer required.
*/
HBRUSH WINAPI CreateSolidBrush( COLORREF color )
{
@@ -366,7 +282,7 @@ HBRUSH WINAPI CreateSolidBrush( COLORREF color )
logbrush.lbColor = color;
logbrush.lbHatch = 0;
- return CreateBrushIndirect( &logbrush );
+ return create_brush( &logbrush );
}
diff --git a/dlls/gdi32/gdiobj.c b/dlls/gdi32/gdiobj.c
index da428d149ce..07277a12e8c 100644
--- a/dlls/gdi32/gdiobj.c
+++ b/dlls/gdi32/gdiobj.c
@@ -641,12 +641,12 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
font_init();
/* create stock objects */
- stock_objects[WHITE_BRUSH] = CreateBrushIndirect( &WhiteBrush );
- stock_objects[LTGRAY_BRUSH] = CreateBrushIndirect( &LtGrayBrush );
- stock_objects[GRAY_BRUSH] = CreateBrushIndirect( &GrayBrush );
- stock_objects[DKGRAY_BRUSH] = CreateBrushIndirect( &DkGrayBrush );
- stock_objects[BLACK_BRUSH] = CreateBrushIndirect( &BlackBrush );
- stock_objects[NULL_BRUSH] = CreateBrushIndirect( &NullBrush );
+ stock_objects[WHITE_BRUSH] = create_brush( &WhiteBrush );
+ stock_objects[LTGRAY_BRUSH] = create_brush( &LtGrayBrush );
+ stock_objects[GRAY_BRUSH] = create_brush( &GrayBrush );
+ stock_objects[DKGRAY_BRUSH] = create_brush( &DkGrayBrush );
+ stock_objects[BLACK_BRUSH] = create_brush( &BlackBrush );
+ stock_objects[NULL_BRUSH] = create_brush( &NullBrush );
stock_objects[WHITE_PEN] = CreatePenIndirect( &WhitePen );
stock_objects[BLACK_PEN] = CreatePenIndirect( &BlackPen );
@@ -672,7 +672,7 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
scaled_stock_objects[SYSTEM_FIXED_FONT] = create_scaled_font( &deffonts->SystemFixedFont );
scaled_stock_objects[DEFAULT_GUI_FONT] = create_scaled_font( &deffonts->DefaultGuiFont );
- stock_objects[DC_BRUSH] = CreateBrushIndirect( &DCBrush );
+ stock_objects[DC_BRUSH] = create_brush( &DCBrush );
stock_objects[DC_PEN] = CreatePenIndirect( &DCPen );
/* clear the NOSYSTEM bit on all stock objects*/
diff --git a/dlls/gdi32/ntgdi_private.h b/dlls/gdi32/ntgdi_private.h
index 91230666fad..ffa28f39c73 100644
--- a/dlls/gdi32/ntgdi_private.h
+++ b/dlls/gdi32/ntgdi_private.h
@@ -168,6 +168,7 @@ extern DWORD stretch_bits( const BITMAPINFO *src_info, struct bitblt_coords *src
extern void get_mono_dc_colors( DC *dc, int color_table_size, BITMAPINFO *info, int count ) DECLSPEC_HIDDEN;
/* brush.c */
+extern HBRUSH create_brush( const LOGBRUSH *brush );
extern BOOL store_brush_pattern( LOGBRUSH *brush, struct brush_pattern *pattern ) DECLSPEC_HIDDEN;
extern void free_brush_pattern( struct brush_pattern *pattern ) DECLSPEC_HIDDEN;
extern BOOL get_brush_bitmap_info( HBRUSH handle, BITMAPINFO *info, void **bits, UINT *usage ) DECLSPEC_HIDDEN;
diff --git a/dlls/gdi32/objects.c b/dlls/gdi32/objects.c
index 4225437aa4a..48474515151 100644
--- a/dlls/gdi32/objects.c
+++ b/dlls/gdi32/objects.c
@@ -398,6 +398,32 @@ HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
return NtGdiCreatePen( style, width, color, NULL );
}
+/***********************************************************************
+ * CreateBrushIndirect (GDI32.@)
+ */
+HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH *brush )
+{
+ switch (brush->lbStyle)
+ {
+ case BS_NULL:
+ return GetStockObject( NULL_BRUSH );
+ case BS_SOLID:
+ return CreateSolidBrush( brush->lbColor );
+ case BS_HATCHED:
+ return CreateHatchBrush( brush->lbHatch, brush->lbColor );
+ case BS_PATTERN:
+ case BS_PATTERN8X8:
+ return CreatePatternBrush( (HBITMAP)brush->lbHatch );
+ case BS_DIBPATTERN:
+ return CreateDIBPatternBrush( (HGLOBAL)brush->lbHatch, brush->lbColor );
+ case BS_DIBPATTERNPT:
+ return CreateDIBPatternBrushPt( (void *)brush->lbHatch, brush->lbColor );
+ default:
+ WARN( "invalid brush style %u\n", brush->lbStyle );
+ return 0;
+ }
+}
+
/***********************************************************************
* CreateBitmapIndirect (GDI32.@)
*/
diff --git a/dlls/gdi32/tests/brush.c b/dlls/gdi32/tests/brush.c
index 1a2201bd511..f04ee22ab6d 100644
--- a/dlls/gdi32/tests/brush.c
+++ b/dlls/gdi32/tests/brush.c
@@ -361,6 +361,16 @@ static void test_brush_org( void )
ReleaseDC( 0, hdc );
}
+static void test_null_brush(void)
+{
+ LOGBRUSH lb;
+ HBRUSH brush;
+
+ lb.lbStyle = BS_NULL;
+ brush = CreateBrushIndirect(&lb);
+ ok(brush == GetStockObject(NULL_BRUSH), "brush is not NULL_BRUSH\n");
+}
+
START_TEST(brush)
{
test_solidbrush();
@@ -368,4 +378,5 @@ START_TEST(brush)
test_pattern_brush();
test_palette_brush();
test_brush_org();
+ test_null_brush();
}
--
2.23.0
More information about the wine-devel
mailing list