ReactOS  0.4.14-dev-376-gaedba84
brush.cpp File Reference
#include "brush.hpp"
Include dependency graph for brush.cpp:

Go to the source code of this file.

Functions

 DBG_DEFAULT_CHANNEL (GdiBrush)
 
static HBRUSH CreateBrushInternal (_In_ ULONG flAttrs, _In_ COLORREF crColor, _In_ ULONG iHatch, _In_opt_ HBITMAP hbmPattern, _In_opt_ PVOID pvClient)
 
VOID NTAPI BRUSH_vDeleteObject (PVOID pvObject)
 
INT FASTCALL BRUSH_GetObject (PBRUSH pbr, INT cjBuffer, LPLOGBRUSH plbBuffer)
 
HBRUSH NTAPI IntGdiCreateNullBrush (VOID)
 
HBRUSH APIENTRY IntGdiCreateSolidBrush (COLORREF crColor)
 
HBRUSH NTAPI IntGdiCreatePatternBrush (HBITMAP hbmPattern)
 
VOID NTAPI IntGdiSetSolidBrushColor (_In_ HBRUSH hbr, _In_ COLORREF crColor)
 
__kernel_entry HBRUSH APIENTRY NtGdiCreateSolidBrush (_In_ COLORREF crColor, _In_opt_ HBRUSH hbr)
 
__kernel_entry HBRUSH APIENTRY NtGdiCreateHatchBrushInternal (_In_ ULONG iHatch, _In_ COLORREF crColor, _In_ BOOL bPen)
 
__kernel_entry HBRUSH APIENTRY NtGdiCreatePatternBrushInternal (_In_ HBITMAP hbmClient, _In_ BOOL bPen, _In_ BOOL b8X8)
 
__kernel_entry HBRUSH APIENTRY NtGdiCreateDIBBrush (_In_reads_bytes_(cj) PVOID pv, _In_ FLONG uUsage, _In_ UINT cj, _In_ BOOL b8X8, _In_ BOOL bPen, _In_ PVOID pvClient)
 
__kernel_entry HBITMAP APIENTRY NtGdiGetObjectBitmapHandle (_In_ HBRUSH hbr, _Out_ UINT *piUsage)
 
__kernel_entry HBRUSH APIENTRY NtGdiSetBrushAttributes (_In_ HBRUSH hbr, _In_ DWORD dwFlags)
 
__kernel_entry HBRUSH APIENTRY NtGdiClearBrushAttributes (_In_ HBRUSH hbr, _In_ DWORD dwFlags)
 

Function Documentation

◆ BRUSH_GetObject()

INT FASTCALL BRUSH_GetObject ( PBRUSH  pbr,
INT  cjBuffer,
LPLOGBRUSH  plbBuffer 
)

Definition at line 260 of file brush.cpp.

264 {
265  return pbr->cjGetObject(cjBuffer, plbBuffer);
266 }
_In_ ULONG cjBuffer
Definition: ntgdi.h:2860

Referenced by GreGetObject().

◆ BRUSH_vDeleteObject()

VOID NTAPI BRUSH_vDeleteObject ( PVOID  pvObject)

Definition at line 252 of file brush.cpp.

254 {
255  BRUSH::vDeleteObject(pvObject);
256 }
static VOID vDeleteObject(_In_ PVOID pvObject)
Definition: brush.cpp:80

◆ CreateBrushInternal()

static HBRUSH CreateBrushInternal ( _In_ ULONG  flAttrs,
_In_ COLORREF  crColor,
_In_ ULONG  iHatch,
_In_opt_ HBITMAP  hbmPattern,
_In_opt_ PVOID  pvClient 
)
static

Definition at line 191 of file brush.cpp.

197 {
198  BASEOBJECT::OWNER owner;
199  PBRUSH pbr;
200  HBRUSH hbr;
201 
202  NT_ASSERT(((flAttrs & BR_IS_BITMAP) == 0) || (hbmPattern != NULL));
203 
204  /* Create the brush (brush takes ownership of the bitmap) */
205  pbr = new BRUSH(flAttrs, crColor, iHatch, hbmPattern, pvClient);
206  if (pbr == NULL)
207  {
208  ERR("Failed to allocate a brush\n");
209  GreSetBitmapOwner(hbmPattern, BASEOBJECT::OWNER::POWNED);
210  GreDeleteObject(hbmPattern);
211  return NULL;
212  }
213 
214  /* Check if this is a global brush */
215  if (!(flAttrs & BR_IS_GLOBAL))
216  {
217  /* Not a global brush, so allocate a user mode brush attribute */
218  if (!pbr->bAllocateBrushAttr())
219  {
220  ERR("Failed to allocate brush attribute\n");
221  delete pbr;
222  return NULL;
223  }
224  }
225 
226  /* Set the owner, either public or process owned */
227  owner = (flAttrs & BR_IS_GLOBAL) ? BASEOBJECT::OWNER::PUBLIC :
228  BASEOBJECT::OWNER::POWNED;
229 
230  /* Insert the object into the GDI handle table */
231  hbr = static_cast<HBRUSH>(pbr->hInsertObject(owner));
232  if (hbr == NULL)
233  {
234  ERR("Failed to insert brush\n");
235  delete pbr;
236  return NULL;
237  }
238 
239  /* Unlock the brush */
240  pbr->vUnlock();
241 
242  return hbr;
243 }
BOOL NTAPI GreDeleteObject(HGDIOBJ hobj)
Definition: gdiobj.c:1155
struct _BRUSH BRUSH
#define BR_IS_BITMAP
Definition: brush.h:99
smooth NULL
Definition: ftsmooth.c:416
Definition: types.h:100
_Inout_ SURFOBJ _In_opt_ SURFOBJ _In_opt_ SURFOBJ _In_opt_ XLATEOBJ _In_ ULONG iHatch
Definition: winddi.h:3959
#define ERR(fmt,...)
Definition: debug.h:109
BOOL NTAPI GreSetBitmapOwner(_In_ HBITMAP hbmp, _In_ ULONG ulOwner)
Definition: bitmaps.c:17
#define BR_IS_GLOBAL
Definition: brush.h:102
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by IntGdiCreateNullBrush(), IntGdiCreatePatternBrush(), IntGdiCreateSolidBrush(), NtGdiCreateDIBBrush(), NtGdiCreateHatchBrushInternal(), NtGdiCreatePatternBrushInternal(), and NtGdiCreateSolidBrush().

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( GdiBrush  )

◆ IntGdiCreateNullBrush()

HBRUSH NTAPI IntGdiCreateNullBrush ( VOID  )

Definition at line 270 of file brush.cpp.

272 {
273  /* Call the internal function */
275 }
smooth NULL
Definition: ftsmooth.c:416
#define BR_IS_NULL
Definition: brush.h:101
#define BR_IS_GLOBAL
Definition: brush.h:102
static HBRUSH CreateBrushInternal(_In_ ULONG flAttrs, _In_ COLORREF crColor, _In_ ULONG iHatch, _In_opt_ HBITMAP hbmPattern, _In_opt_ PVOID pvClient)
Definition: brush.cpp:191

Referenced by CreateStockObjects().

◆ IntGdiCreatePatternBrush()

HBRUSH NTAPI IntGdiCreatePatternBrush ( HBITMAP  hbmPattern)

Definition at line 292 of file brush.cpp.

294 {
295  NT_ASSERT(hbmPattern != NULL);
296  GreSetBitmapOwner(hbmPattern, BASEOBJECT::OWNER::PUBLIC);
298  0,
299  0,
300  hbmPattern,
301  NULL);
302 }
#define BR_IS_BITMAP
Definition: brush.h:99
smooth NULL
Definition: ftsmooth.c:416
BOOL NTAPI GreSetBitmapOwner(_In_ HBITMAP hbmp, _In_ ULONG ulOwner)
Definition: bitmaps.c:17
#define BR_IS_GLOBAL
Definition: brush.h:102
static HBRUSH CreateBrushInternal(_In_ ULONG flAttrs, _In_ COLORREF crColor, _In_ ULONG iHatch, _In_opt_ HBITMAP hbmPattern, _In_opt_ PVOID pvClient)
Definition: brush.cpp:191
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by UserInitialize().

◆ IntGdiCreateSolidBrush()

HBRUSH APIENTRY IntGdiCreateSolidBrush ( COLORREF  crColor)

Definition at line 279 of file brush.cpp.

281 {
282  /* Call the internal function */
284  crColor,
285  0,
286  NULL,
287  NULL);
288 }
#define BR_IS_SOLID
Definition: brush.h:97
smooth NULL
Definition: ftsmooth.c:416
#define BR_IS_GLOBAL
Definition: brush.h:102
static HBRUSH CreateBrushInternal(_In_ ULONG flAttrs, _In_ COLORREF crColor, _In_ ULONG iHatch, _In_opt_ HBITMAP hbmPattern, _In_opt_ PVOID pvClient)
Definition: brush.cpp:191

Referenced by CreateStockObjects(), and CreateSysColorObjects().

◆ IntGdiSetSolidBrushColor()

VOID NTAPI IntGdiSetSolidBrushColor ( _In_ HBRUSH  hbr,
_In_ COLORREF  crColor 
)

Definition at line 306 of file brush.cpp.

309 {
310  PBRUSH pbr;
311 
312  /* Lock the brush */
313  pbr = BRUSH::LockAny(hbr);
314  if (pbr == NULL)
315  {
316  ERR("Failed to lock brush %p\n", hbr);
317  return;
318  }
319 
320  /* Call the member function */
321  pbr->vSetSolidColor(crColor);
322 
323  /* Unlock the brush */
324  pbr->vUnlock();
325 }
smooth NULL
Definition: ftsmooth.c:416
Definition: types.h:100
#define ERR(fmt,...)
Definition: debug.h:109

Referenced by IntSetSysColors().

◆ NtGdiClearBrushAttributes()

__kernel_entry HBRUSH APIENTRY NtGdiClearBrushAttributes ( _In_ HBRUSH  hbr,
_In_ DWORD  dwFlags 
)

Definition at line 553 of file brush.cpp.

556 {
557  __debugbreak();
558  return NULL;
559 }
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
smooth NULL
Definition: ftsmooth.c:416

◆ NtGdiCreateDIBBrush()

__kernel_entry HBRUSH APIENTRY NtGdiCreateDIBBrush ( _In_reads_bytes_(cj) PVOID  pv,
_In_ FLONG  uUsage,
_In_ UINT  cj,
_In_ BOOL  b8X8,
_In_ BOOL  bPen,
_In_ PVOID  pvClient 
)

Definition at line 412 of file brush.cpp.

419 {
420  PVOID pvPackedDIB;
421  FLONG flAttrs;
422  HBITMAP hbm;
423  HBRUSH hbr = NULL;
424 
425  if (b8X8)
426  {
427  WARN("b8X8 is not supported, ignoring\n");
428  }
429 
430  if (bPen)
431  {
432  WARN("bPen is not supported, ignoring\n");
433  }
434 
435  if (uUsage > DIB_PAL_INDICES)
436  {
437  ERR("Invalid uUsage value: %lu\n", uUsage);
439  return NULL;
440  }
441 
442  /* Allocate a buffer for the packed DIB */
444  if (pvPackedDIB == NULL)
445  {
446  ERR("Failed to allocate temp buffer of %u bytes\n", cj);
447  return NULL;
448  }
449 
450  /* Probe and copy the packed DIB */
451  _SEH2_TRY
452  {
453  ProbeForRead(pv, cj, 1);
454  RtlCopyMemory(pvPackedDIB, pv, cj);
455  }
457  {
458  ERR("Got exception, pv = %p, cj = %lu\n", pv, cj);
459  goto cleanup;
460  }
461  _SEH2_END;
462 
463  flAttrs = BR_IS_BITMAP | BR_IS_DIB;
464 
465  /* Check what kind of color table we have */
466  if (uUsage == DIB_PAL_COLORS)
467  {
468  /* Remember it and use DIB_PAL_BRUSHHACK to create a "special" palette */
469  flAttrs |= BR_IS_DIBPALCOLORS;
470  uUsage = DIB_PAL_BRUSHHACK;
471  }
472  else if (uUsage == DIB_PAL_INDICES)
473  {
474  /* No color table, bitmap contains device palette indices */
475  flAttrs |= BR_IS_DIBPALINDICES;
476 
477  /* FIXME: This makes tests pass, but needs investigation. */
478  flAttrs |= BR_IS_NULL;
479  }
480 
481  /* Create a bitmap from the DIB */
482  hbm = GreCreateDIBitmapFromPackedDIB(pvPackedDIB, cj, uUsage);
483  if (hbm == NULL)
484  {
485  ERR("Failed to create bitmap from DIB\n");
486  goto cleanup;
487  }
488 
489  /* Call the internal function (will delete hbm on failure) */
490  hbr = CreateBrushInternal(flAttrs, 0, 0, hbm, pvClient);
491 
492 cleanup:
493 
494  ExFreePoolWithTag(pvPackedDIB, GDITAG_TEMP);
495 
496  return hbr;
497 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ ULONG cj
Definition: winddi.h:3540
#define GDITAG_TEMP
Definition: tags.h:166
#define DIB_PAL_COLORS
Definition: wingdi.h:365
#define DIB_PAL_BRUSHHACK
Definition: dib.h:36
#define WARN(fmt,...)
Definition: debug.h:111
#define BR_IS_BITMAP
Definition: brush.h:99
_SEH2_TRY
Definition: create.c:4250
#define BR_IS_DIB
Definition: brush.h:100
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
unsigned long FLONG
Definition: ntbasedef.h:373
HBITMAP NTAPI GreCreateDIBitmapFromPackedDIB(_In_reads_(cjPackedDIB) PVOID pvPackedDIB, _In_ UINT cjPackedDIB, _In_ ULONG uUsage)
Definition: dibobj.c:1607
#define BR_IS_NULL
Definition: brush.h:101
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define ERR(fmt,...)
Definition: debug.h:109
#define BR_IS_DIBPALINDICES
Definition: brush.h:106
_SEH2_END
Definition: create.c:4424
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
#define BR_IS_DIBPALCOLORS
Definition: brush.h:105
#define DIB_PAL_INDICES
char * cleanup(char *str)
Definition: wpickclick.c:99
static HBITMAP
Definition: button.c:44
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
static HBRUSH CreateBrushInternal(_In_ ULONG flAttrs, _In_ COLORREF crColor, _In_ ULONG iHatch, _In_opt_ HBITMAP hbmPattern, _In_opt_ PVOID pvClient)
Definition: brush.cpp:191
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27

Referenced by CreateDIBPatternBrush(), and CreateDIBPatternBrushPt().

◆ NtGdiCreateHatchBrushInternal()

__kernel_entry HBRUSH APIENTRY NtGdiCreateHatchBrushInternal ( _In_ ULONG  iHatch,
_In_ COLORREF  crColor,
_In_ BOOL  bPen 
)

Definition at line 346 of file brush.cpp.

350 {
351  FLONG flAttr;
352 
353  if (bPen)
354  {
355  WARN("bPen is not supported, ignoring\n");
356  }
357 
358  /* Check what kind if hatch style this is */
359  if (iHatch < HS_DDI_MAX)
360  {
361  flAttr = BR_IS_HATCH;
362  }
363  else if (iHatch < HS_API_MAX)
364  {
365  flAttr = BR_IS_SOLID;
366  }
367  else
368  {
369  ERR("Invalid iHatch: %lu\n", iHatch);
370  return NULL;
371  }
372 
373  /* Call the internal function */
374  return CreateBrushInternal(flAttr, crColor, iHatch, NULL, NULL);
375 }
#define HS_DDI_MAX
Definition: winddi.h:3954
#define WARN(fmt,...)
Definition: debug.h:111
#define BR_IS_SOLID
Definition: brush.h:97
smooth NULL
Definition: ftsmooth.c:416
#define HS_API_MAX
Definition: wingdi.h:581
unsigned long FLONG
Definition: ntbasedef.h:373
#define BR_IS_HATCH
Definition: brush.h:98
_Inout_ SURFOBJ _In_opt_ SURFOBJ _In_opt_ SURFOBJ _In_opt_ XLATEOBJ _In_ ULONG iHatch
Definition: winddi.h:3959
#define ERR(fmt,...)
Definition: debug.h:109
static HBRUSH CreateBrushInternal(_In_ ULONG flAttrs, _In_ COLORREF crColor, _In_ ULONG iHatch, _In_opt_ HBITMAP hbmPattern, _In_opt_ PVOID pvClient)
Definition: brush.cpp:191

Referenced by CreateBrushIndirect(), and CreateHatchBrush().

◆ NtGdiCreatePatternBrushInternal()

__kernel_entry HBRUSH APIENTRY NtGdiCreatePatternBrushInternal ( _In_ HBITMAP  hbmClient,
_In_ BOOL  bPen,
_In_ BOOL  b8X8 
)

Definition at line 380 of file brush.cpp.

384 {
385  HBITMAP hbmPattern;
386 
387  if (b8X8)
388  {
389  WARN("b8X8 is not supported, ignoring\n");
390  }
391 
392  if (bPen)
393  {
394  WARN("bPen is not supported, ignoring\n");
395  }
396 
397  /* Copy the bitmap */
398  hbmPattern = BITMAP_CopyBitmap(hbmClient);
399  if (hbmPattern == NULL)
400  {
401  ERR("Failed to copy the bitmap %p\n", hbmPattern);
402  return NULL;
403  }
404 
405  /* Call the internal function (will delete hbmPattern on failure) */
406  return CreateBrushInternal(BR_IS_BITMAP, 0, 0, hbmPattern, hbmClient);
407 }
#define WARN(fmt,...)
Definition: debug.h:111
#define BR_IS_BITMAP
Definition: brush.h:99
smooth NULL
Definition: ftsmooth.c:416
#define ERR(fmt,...)
Definition: debug.h:109
HBITMAP FASTCALL BITMAP_CopyBitmap(HBITMAP hBitmap)
Definition: bitmaps.c:709
static HBITMAP
Definition: button.c:44
static HBRUSH CreateBrushInternal(_In_ ULONG flAttrs, _In_ COLORREF crColor, _In_ ULONG iHatch, _In_opt_ HBITMAP hbmPattern, _In_opt_ PVOID pvClient)
Definition: brush.cpp:191

Referenced by CreateBrushIndirect(), and CreatePatternBrush().

◆ NtGdiCreateSolidBrush()

__kernel_entry HBRUSH APIENTRY NtGdiCreateSolidBrush ( _In_ COLORREF  crColor,
_In_opt_ HBRUSH  hbr 
)

Definition at line 330 of file brush.cpp.

333 {
334  if (hbr != NULL)
335  {
336  WARN("hbr is not supported, ignoring\n");
337  }
338 
339  /* Call the internal function */
340  return CreateBrushInternal(BR_IS_SOLID, crColor, 0, NULL, NULL);
341 }
#define WARN(fmt,...)
Definition: debug.h:111
#define BR_IS_SOLID
Definition: brush.h:97
smooth NULL
Definition: ftsmooth.c:416
static HBRUSH CreateBrushInternal(_In_ ULONG flAttrs, _In_ COLORREF crColor, _In_ ULONG iHatch, _In_opt_ HBITMAP hbmPattern, _In_opt_ PVOID pvClient)
Definition: brush.cpp:191

Referenced by CreateBrushIndirect(), and CreateSolidBrush().

◆ NtGdiGetObjectBitmapHandle()

__kernel_entry HBITMAP APIENTRY NtGdiGetObjectBitmapHandle ( _In_ HBRUSH  hbr,
_Out_ UINT piUsage 
)

Definition at line 502 of file brush.cpp.

505 {
506  PBRUSH pbr;
507  HBITMAP hbm;
508  UINT uUsage;
509 
510  /* Lock the brush */
511  pbr = BRUSH::LockForRead(hbr);
512  if (pbr == NULL)
513  {
514  ERR("Failed to lock brush %p\n", hbr);
515  return NULL;
516  }
517 
518  /* Call the member function */
519  hbm = pbr->hbmGetBitmapHandle(&uUsage);
520 
521  /* Unlock the brush */
522  pbr->vUnlock();
523 
524  _SEH2_TRY
525  {
526  ProbeForWrite(piUsage, sizeof(*piUsage), 1);
527  *piUsage = uUsage;
528  }
530  {
531  ERR("Got exception! piUsage = %p\n", piUsage);
532  hbm = NULL;
533  }
534  _SEH2_END;
535 
536  return hbm;
537 }
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
Definition: types.h:100
#define ERR(fmt,...)
Definition: debug.h:109
_SEH2_END
Definition: create.c:4424
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
unsigned int UINT
Definition: ndis.h:50
static HBITMAP
Definition: button.c:44
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6

Referenced by get_brush_bitmap_info().

◆ NtGdiSetBrushAttributes()

__kernel_entry HBRUSH APIENTRY NtGdiSetBrushAttributes ( _In_ HBRUSH  hbr,
_In_ DWORD  dwFlags 
)

Definition at line 542 of file brush.cpp.

545 {
546  __debugbreak();
547  return NULL;
548 }
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
smooth NULL
Definition: ftsmooth.c:416