ReactOS 0.4.16-dev-117-g38f21f9
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 271 of file brush.cpp.

275{
276 return pbr->cjGetObject(cjBuffer, plbBuffer);
277}
_In_ ULONG cjBuffer
Definition: ntgdi.h:2860

Referenced by GreGetObject().

◆ BRUSH_vDeleteObject()

VOID NTAPI BRUSH_vDeleteObject ( PVOID  pvObject)

Definition at line 263 of file brush.cpp.

265{
266 BRUSH::vDeleteObject(pvObject);
267}
static VOID vDeleteObject(_In_ PVOID pvObject)
Definition: brush.cpp:91

◆ 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 202 of file brush.cpp.

208{
209 BASEOBJECT::OWNER owner;
210 PBRUSH pbr;
211 HBRUSH hbr;
212
213 NT_ASSERT(((flAttrs & BR_IS_BITMAP) == 0) || (hbmPattern != NULL));
214
215 /* Create the brush (brush takes ownership of the bitmap) */
216 pbr = new BRUSH(flAttrs, crColor, iHatch, hbmPattern, pvClient);
217 if (pbr == NULL)
218 {
219 ERR("Failed to allocate a brush\n");
220 GreSetBitmapOwner(hbmPattern, BASEOBJECT::OWNER::POWNED);
221 GreDeleteObject(hbmPattern);
222 return NULL;
223 }
224
225 /* Check if this is a global brush */
226 if (!(flAttrs & BR_IS_GLOBAL))
227 {
228 /* Not a global brush, so allocate a user mode brush attribute */
229 if (!pbr->bAllocateBrushAttr())
230 {
231 ERR("Failed to allocate brush attribute\n");
232 delete pbr;
233 return NULL;
234 }
235 }
236
237 /* Set the owner, either public or process owned */
238 owner = (flAttrs & BR_IS_GLOBAL) ? BASEOBJECT::OWNER::PUBLIC :
239 BASEOBJECT::OWNER::POWNED;
240
241 /* Insert the object into the GDI handle table */
242 hbr = static_cast<HBRUSH>(pbr->hInsertObject(owner));
243 if (hbr == NULL)
244 {
245 ERR("Failed to insert brush\n");
246 delete pbr;
247 return NULL;
248 }
249
250 /* Unlock the brush */
251 pbr->vUnlock();
252
253 return hbr;
254}
#define ERR(fmt,...)
Definition: precomp.h:57
BOOL NTAPI GreSetBitmapOwner(_In_ HBITMAP hbmp, _In_ ULONG ulOwner)
Definition: bitmaps.c:17
Definition: brush.hpp:16
#define NULL
Definition: types.h:112
#define BR_IS_GLOBAL
Definition: brush.h:106
#define BR_IS_BITMAP
Definition: brush.h:103
Definition: types.h:101
BOOL NTAPI GreDeleteObject(HGDIOBJ hobj)
Definition: gdiobj.c:1158
_Inout_ SURFOBJ _In_opt_ SURFOBJ _In_opt_ SURFOBJ _In_opt_ XLATEOBJ _In_ ULONG iHatch
Definition: winddi.h:3963
#define NT_ASSERT
Definition: rtlfuncs.h:3324

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 281 of file brush.cpp.

283{
284 /* Call the internal function */
286}
static HBRUSH CreateBrushInternal(_In_ ULONG flAttrs, _In_ COLORREF crColor, _In_ ULONG iHatch, _In_opt_ HBITMAP hbmPattern, _In_opt_ PVOID pvClient)
Definition: brush.cpp:202
#define BR_IS_NULL
Definition: brush.h:105

Referenced by CreateStockObjects().

◆ IntGdiCreatePatternBrush()

HBRUSH NTAPI IntGdiCreatePatternBrush ( HBITMAP  hbmPattern)

Definition at line 303 of file brush.cpp.

305{
306 NT_ASSERT(hbmPattern != NULL);
307 GreSetBitmapOwner(hbmPattern, BASEOBJECT::OWNER::PUBLIC);
309 0,
310 0,
311 hbmPattern,
312 NULL);
313}

Referenced by UserInitialize().

◆ IntGdiCreateSolidBrush()

HBRUSH APIENTRY IntGdiCreateSolidBrush ( COLORREF  crColor)

Definition at line 290 of file brush.cpp.

292{
293 /* Call the internal function */
295 crColor,
296 0,
297 NULL,
298 NULL);
299}
#define BR_IS_SOLID
Definition: brush.h:101

Referenced by CreateStockObjects(), and CreateSysColorObjects().

◆ IntGdiSetSolidBrushColor()

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

Definition at line 317 of file brush.cpp.

320{
321 PBRUSH pbr;
322
323 /* Lock the brush */
324 pbr = BRUSH::LockAny(hbr);
325 if (pbr == NULL)
326 {
327 ERR("Failed to lock brush %p\n", hbr);
328 return;
329 }
330
331 /* Call the member function */
332 pbr->vSetSolidColor(crColor);
333
334 /* Unlock the brush */
335 pbr->vUnlock();
336}

Referenced by IntSetSysColors().

◆ NtGdiClearBrushAttributes()

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

Definition at line 579 of file brush.cpp.

582{
583 PBRUSH pbr;
584 if ( dwFlags & SC_BB_STOCKOBJ )
585 {
587 {
588 pbr = BRUSH::LockAny(hbr);
589 if (pbr == NULL)
590 {
591 ERR("Failed to lock brush %p\n", hbr);
592 return NULL;
593 }
594 if (!pbr->bAllocateBrushAttr())
595 {
596 ERR("Failed to allocate brush attribute\n");
597 }
598 pbr->vUnlock();
599 return hbr;
600 }
601 }
602 return NULL;
603}
#define SC_BB_STOCKOBJ
Definition: ntgdihdl.h:199
BOOL NTAPI GDIOBJ_ConvertFromStockObj(HGDIOBJ *phObj)
Definition: gdiobj.c:1489
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

Referenced by ClearBrushAttributes().

◆ 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 423 of file brush.cpp.

430{
431 PVOID pvPackedDIB;
432 FLONG flAttrs;
433 HBITMAP hbm;
434 HBRUSH hbr = NULL;
435
436 if (b8X8)
437 {
438 WARN("b8X8 is not supported, ignoring\n");
439 }
440
441 if (bPen)
442 {
443 WARN("bPen is not supported, ignoring\n");
444 }
445
446 if (uUsage > DIB_PAL_INDICES)
447 {
448 ERR("Invalid uUsage value: %lu\n", uUsage);
450 return NULL;
451 }
452
453 /* Allocate a buffer for the packed DIB */
455 if (pvPackedDIB == NULL)
456 {
457 ERR("Failed to allocate temp buffer of %u bytes\n", cj);
458 return NULL;
459 }
460
461 /* Probe and copy the packed DIB */
463 {
464 ProbeForRead(pv, cj, 1);
465 RtlCopyMemory(pvPackedDIB, pv, cj);
466 }
468 {
469 ERR("Got exception, pv = %p, cj = %lu\n", pv, cj);
470 goto cleanup;
471 }
472 _SEH2_END;
473
474 flAttrs = BR_IS_BITMAP | BR_IS_DIB;
475
476 /* Check what kind of color table we have */
477 if (uUsage == DIB_PAL_COLORS)
478 {
479 /* Remember it and use DIB_PAL_BRUSHHACK to create a "special" palette */
480 flAttrs |= BR_IS_DIBPALCOLORS;
481 uUsage = DIB_PAL_BRUSHHACK;
482 }
483 else if (uUsage == DIB_PAL_INDICES)
484 {
485 /* No color table, bitmap contains device palette indices */
486 flAttrs |= BR_IS_DIBPALINDICES;
487
488 /* FIXME: This makes tests pass, but needs investigation. */
489 flAttrs |= BR_IS_NULL;
490 }
491
492 /* Create a bitmap from the DIB */
493 hbm = GreCreateDIBitmapFromPackedDIB(pvPackedDIB, cj, uUsage);
494 if (hbm == NULL)
495 {
496 ERR("Failed to create bitmap from DIB\n");
497 goto cleanup;
498 }
499
500 /* Call the internal function (will delete hbm on failure) */
501 hbr = CreateBrushInternal(flAttrs, 0, 0, hbm, pvClient);
502
503cleanup:
504
505 ExFreePoolWithTag(pvPackedDIB, GDITAG_TEMP);
506
507 return hbr;
508}
#define DIB_PAL_INDICES
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static void cleanup(void)
Definition: main.c:1335
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define BR_IS_DIB
Definition: brush.h:104
#define BR_IS_DIBPALINDICES
Definition: brush.h:110
#define BR_IS_DIBPALCOLORS
Definition: brush.h:109
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
static HBITMAP
Definition: button.c:44
unsigned long FLONG
Definition: ntbasedef.h:366
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
HBITMAP NTAPI GreCreateDIBitmapFromPackedDIB(_In_reads_(cjPackedDIB) PVOID pvPackedDIB, _In_ UINT cjPackedDIB, _In_ ULONG uUsage)
Definition: dibobj.c:1794
#define DIB_PAL_BRUSHHACK
Definition: dib.h:36
#define GDITAG_TEMP
Definition: tags.h:167
_In_ ULONG cj
Definition: winddi.h:3540
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:22
#define DIB_PAL_COLORS
Definition: wingdi.h:366

Referenced by CreateDIBPatternBrush(), and CreateDIBPatternBrushPt().

◆ NtGdiCreateHatchBrushInternal()

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

Definition at line 357 of file brush.cpp.

361{
362 FLONG flAttr;
363
364 if (bPen)
365 {
366 WARN("bPen is not supported, ignoring\n");
367 }
368
369 /* Check what kind if hatch style this is */
370 if (iHatch < HS_DDI_MAX)
371 {
372 flAttr = BR_IS_HATCH;
373 }
374 else if (iHatch < HS_API_MAX)
375 {
376 flAttr = BR_IS_SOLID;
377 }
378 else
379 {
380 ERR("Invalid iHatch: %lu\n", iHatch);
381 return NULL;
382 }
383
384 /* Call the internal function */
385 return CreateBrushInternal(flAttr, crColor, iHatch, NULL, NULL);
386}
#define BR_IS_HATCH
Definition: brush.h:102
#define HS_DDI_MAX
Definition: winddi.h:3954
#define HS_API_MAX
Definition: wingdi.h:582

Referenced by CreateBrushIndirect(), and CreateHatchBrush().

◆ NtGdiCreatePatternBrushInternal()

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

Definition at line 391 of file brush.cpp.

395{
396 HBITMAP hbmPattern;
397
398 if (b8X8)
399 {
400 WARN("b8X8 is not supported, ignoring\n");
401 }
402
403 if (bPen)
404 {
405 WARN("bPen is not supported, ignoring\n");
406 }
407
408 /* Copy the bitmap */
409 hbmPattern = BITMAP_CopyBitmap(hbmClient);
410 if (hbmPattern == NULL)
411 {
412 ERR("Failed to copy the bitmap %p\n", hbmPattern);
413 return NULL;
414 }
415
416 /* Call the internal function (will delete hbmPattern on failure) */
417 return CreateBrushInternal(BR_IS_BITMAP, 0, 0, hbmPattern, hbmClient);
418}
HBITMAP FASTCALL BITMAP_CopyBitmap(HBITMAP hBitmap)
Definition: bitmaps.c:714

Referenced by CreateBrushIndirect(), and CreatePatternBrush().

◆ NtGdiCreateSolidBrush()

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

Definition at line 341 of file brush.cpp.

344{
345 if (hbr != NULL)
346 {
347 WARN("hbr is not supported, ignoring\n");
348 }
349
350 /* Call the internal function */
351 return CreateBrushInternal(BR_IS_SOLID, crColor, 0, NULL, NULL);
352}

Referenced by CreateBrushIndirect(), and CreateSolidBrush().

◆ NtGdiGetObjectBitmapHandle()

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

Definition at line 513 of file brush.cpp.

516{
517 PBRUSH pbr;
518 HBITMAP hbm;
519 UINT uUsage;
520
521 /* Lock the brush */
522 pbr = BRUSH::LockForRead(hbr);
523 if (pbr == NULL)
524 {
525 ERR("Failed to lock brush %p\n", hbr);
526 return NULL;
527 }
528
529 /* Call the member function */
530 hbm = pbr->hbmGetBitmapHandle(&uUsage);
531
532 /* Unlock the brush */
533 pbr->vUnlock();
534
536 {
537 ProbeForWrite(piUsage, sizeof(*piUsage), 1);
538 *piUsage = uUsage;
539 }
541 {
542 ERR("Got exception! piUsage = %p\n", piUsage);
543 hbm = NULL;
544 }
545 _SEH2_END;
546
547 return hbm;
548}
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
unsigned int UINT
Definition: ndis.h:50

Referenced by get_brush_bitmap_info().

◆ NtGdiSetBrushAttributes()

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

Definition at line 553 of file brush.cpp.

556{
557 PBRUSH pbr;
558 if ( dwFlags & SC_BB_STOCKOBJ )
559 {
561 {
562 pbr = BRUSH::LockAny(hbr);
563 if (pbr == NULL)
564 {
565 ERR("Failed to lock brush %p\n", hbr);
566 return NULL;
567 }
568 pbr->vReleaseAttribute();
569 pbr->vUnlock();
570 return hbr;
571 }
572 }
573 return NULL;
574}
BOOL NTAPI GDIOBJ_ConvertToStockObj(HGDIOBJ *phObj)
Definition: gdiobj.c:1455

Referenced by SetBrushAttributes().