2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: brush.c,v 1.32 2004/02/19 21:12:10 weiden Exp $
23 #undef WIN32_LEAN_AND_MEAN
25 #include <ddk/ntddk.h>
26 #include <win32k/bitmaps.h>
27 #include <win32k/brush.h>
28 #include <internal/safe.h>
29 //#include <win32k/debug.h>
30 #include <include/object.h>
31 #include <include/inteng.h>
32 #include <include/error.h>
33 #include <include/tags.h>
36 #include <win32k/debug1.h>
39 IntGdiCreateBrushIndirect(PLOGBRUSH lb
)
44 hBrush
= BRUSHOBJ_AllocBrush();
50 brushPtr
= BRUSHOBJ_LockBrush (hBrush
);
51 /* FIXME: Occurs! FiN */
52 /* ASSERT( brushPtr ); *///I want to know
if this ever occurs
55 brushPtr
->iSolidColor
= lb
->lbColor
;
56 brushPtr
->logbrush
.lbStyle
= lb
->lbStyle
;
57 brushPtr
->logbrush
.lbColor
= lb
->lbColor
;
58 brushPtr
->logbrush
.lbHatch
= lb
->lbHatch
;
60 BRUSHOBJ_UnlockBrush( hBrush
);
67 IntGdiCreateDIBPatternBrush(HGLOBAL hDIBPacked
,
73 PBITMAPINFO info
, newInfo
;
76 DPRINT("%04x\n", hbitmap
);
78 logbrush
.lbStyle
= BS_DIBPATTERN
;
79 logbrush
.lbColor
= coloruse
;
82 /* Make a copy of the bitmap */
83 if (!(info
= (BITMAPINFO
*)GlobalLock( hbitmap
)))
89 if (info
->bmiHeader
.biCompression
) size
= info
->bmiHeader
.biSizeImage
;
91 size
= DIB_GetDIBImageBytes(info
->bmiHeader
.biWidth
, info
->bmiHeader
.biHeight
, info
->bmiHeader
.biBitCount
);
92 size
+= DIB_BitmapInfoSize(info
, coloruse
);
94 if (!(logbrush
.lbHatch
= (INT
)GlobalAlloc16( GMEM_MOVEABLE
, size
)))
96 GlobalUnlock16( hbitmap
);
99 newInfo
= (BITMAPINFO
*) GlobalLock16((HGLOBAL16
)logbrush
.lbHatch
);
100 memcpy(newInfo
, info
, size
);
101 GlobalUnlock16((HGLOBAL16
)logbrush
.lbHatch
);
102 GlobalUnlock(hbitmap
);
103 return IntGdiCreateBrushIndirect(&logbrush
);
108 IntGdiCreateDIBPatternBrushPt(CONST VOID
*PackedDIB
,
116 info
= (BITMAPINFO
*) PackedDIB
;
121 DPRINT ("%p %ldx%ld %dbpp\n",
123 info
->bmiHeader
.biWidth
,
124 info
->bmiHeader
.biHeight
,
125 info
->bmiHeader
.biBitCount
);
127 logbrush
.lbStyle
= BS_DIBPATTERN
;
128 logbrush
.lbColor
= Usage
;
129 logbrush
.lbHatch
= 0;
131 /* Make a copy of the bitmap */
133 if (info
->bmiHeader
.biCompression
)
135 size
= info
->bmiHeader
.biSizeImage
;
139 size
= DIB_GetDIBImageBytes (info
->bmiHeader
.biWidth
, info
->bmiHeader
.biHeight
, info
->bmiHeader
.biBitCount
);
141 size
+= DIB_BitmapInfoSize (info
, Usage
);
143 logbrush
.lbHatch
= (LONG
) GDIOBJ_AllocObj(size
, GDI_OBJECT_TYPE_DONTCARE
, NULL
);
144 if (logbrush
.lbHatch
== 0)
148 newInfo
= (PBITMAPINFO
) GDIOBJ_LockObj ((HGDIOBJ
) logbrush
.lbHatch
, GDI_OBJECT_TYPE_DONTCARE
);
150 memcpy(newInfo
, info
, size
);
151 GDIOBJ_UnlockObj((HGDIOBJ
) logbrush
.lbHatch
, GDI_OBJECT_TYPE_DONTCARE
);
153 return IntGdiCreateBrushIndirect (&logbrush
);
169 SurfObj
= (SURFOBJ
*)AccessUserObject((ULONG
)dc
->Surface
);
172 SetLastWin32Error(ERROR_INVALID_HANDLE
);
177 if (BrushObj
->logbrush
.lbStyle
!= BS_NULL
)
181 DestRect
.left
= XLeft
+ dc
->w
.DCOrgX
;
182 DestRect
.right
= XLeft
+ Width
+ dc
->w
.DCOrgX
;
186 DestRect
.left
= XLeft
+ Width
+ 1 + dc
->w
.DCOrgX
;
187 DestRect
.right
= XLeft
+ dc
->w
.DCOrgX
+ 1;
191 DestRect
.top
= YLeft
+ dc
->w
.DCOrgY
;
192 DestRect
.bottom
= YLeft
+ Height
+ dc
->w
.DCOrgY
;
196 DestRect
.top
= YLeft
+ Height
+ dc
->w
.DCOrgY
+ 1;
197 DestRect
.bottom
= YLeft
+ dc
->w
.DCOrgY
+ 1;
199 ret
= IntEngBitBlt(SurfObj
,
216 IntGdiPolyPatBlt(HDC hDC
,
230 SetLastWin32Error(ERROR_INVALID_HANDLE
);
234 for (r
= pRects
, i
= 0; i
< cRects
; i
++)
236 BrushObj
= BRUSHOBJ_LockBrush(r
->hBrush
);
237 IntPatBlt(dc
,r
->r
.left
,r
->r
.top
,r
->r
.right
,r
->r
.bottom
,dwRop
,BrushObj
);
238 BRUSHOBJ_UnlockBrush(r
->hBrush
);
246 /******************************************************************************/
248 HBRUSH STDCALL
NtGdiCreateBrushIndirect(CONST LOGBRUSH
*lb
)
253 Status
= MmCopyFromCaller(&Safelb
, lb
, sizeof(LOGBRUSH
));
254 if(!NT_SUCCESS(Status
))
256 SetLastNtError(Status
);
260 return IntGdiCreateBrushIndirect(&Safelb
);
263 HBRUSH STDCALL
NtGdiCreateDIBPatternBrush(HGLOBAL hDIBPacked
,
266 /* IntGdiCreateDIBPatternBrush() */
270 HBRUSH STDCALL
NtGdiCreateDIBPatternBrushPt(CONST VOID
*PackedDIB
,
273 /* FIXME - copy PackedDIB memory first! */
274 return IntGdiCreateDIBPatternBrushPt(PackedDIB
, Usage
);
277 HBRUSH STDCALL
NtGdiCreateHatchBrush(INT Style
,
282 DPRINT("%d %06lx\n", Style
, Color
);
284 if (Style
< 0 || Style
>= NB_HATCH_STYLES
)
288 logbrush
.lbStyle
= BS_HATCHED
;
289 logbrush
.lbColor
= Color
;
290 logbrush
.lbHatch
= Style
;
292 return IntGdiCreateBrushIndirect (&logbrush
);
295 HBRUSH STDCALL
NtGdiCreatePatternBrush(HBITMAP hBitmap
)
297 LOGBRUSH logbrush
= { BS_PATTERN
, 0, 0 };
299 DPRINT ("%04x\n", hBitmap
);
300 logbrush
.lbHatch
= (INT
) BITMAPOBJ_CopyBitmap (hBitmap
);
301 if(!logbrush
.lbHatch
)
307 return IntGdiCreateBrushIndirect( &logbrush
);
311 HBRUSH STDCALL
NtGdiCreateSolidBrush(COLORREF Color
)
315 logbrush
.lbStyle
= BS_SOLID
;
316 logbrush
.lbColor
= Color
;
317 logbrush
.lbHatch
= 0;
319 return IntGdiCreateBrushIndirect(&logbrush
);
322 BOOL STDCALL
NtGdiFixBrushOrgEx(VOID
)
327 BOOL STDCALL
NtGdiPolyPatBlt(HDC hDC
,
339 rb
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATRECT
) * cRects
, TAG_PATBLT
);
342 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
345 Status
= MmCopyFromCaller(rb
, pRects
, sizeof(PATRECT
) * cRects
);
346 if(!NT_SUCCESS(Status
))
349 SetLastNtError(Status
);
354 Ret
= IntGdiPolyPatBlt(hDC
, dwRop
, pRects
, cRects
, Reserved
);
361 BOOL STDCALL
NtGdiPatBlt(HDC hDC
,
369 DC
*dc
= DC_LockDc(hDC
);
374 SetLastWin32Error(ERROR_INVALID_HANDLE
);
378 BrushObj
= BRUSHOBJ_LockBrush(dc
->w
.hBrush
);
379 if (NULL
== BrushObj
)
381 SetLastWin32Error(ERROR_INVALID_HANDLE
);
386 ret
= IntPatBlt(dc
,XLeft
,YLeft
,Width
,Height
,ROP
,BrushObj
);
388 BRUSHOBJ_UnlockBrush(dc
->w
.hBrush
);
393 BOOL STDCALL
NtGdiSetBrushOrgEx(HDC hDC
,