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.31 2004/01/15 21:03:05 gvg 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>
35 #include <win32k/debug1.h>
38 IntGdiCreateBrushIndirect(PLOGBRUSH lb
)
43 hBrush
= BRUSHOBJ_AllocBrush();
49 brushPtr
= BRUSHOBJ_LockBrush (hBrush
);
50 /* FIXME: Occurs! FiN */
51 /* ASSERT( brushPtr ); *///I want to know
if this ever occurs
54 brushPtr
->iSolidColor
= lb
->lbColor
;
55 brushPtr
->logbrush
.lbStyle
= lb
->lbStyle
;
56 brushPtr
->logbrush
.lbColor
= lb
->lbColor
;
57 brushPtr
->logbrush
.lbHatch
= lb
->lbHatch
;
59 BRUSHOBJ_UnlockBrush( hBrush
);
66 IntGdiCreateDIBPatternBrush(HGLOBAL hDIBPacked
,
72 PBITMAPINFO info
, newInfo
;
75 DPRINT("%04x\n", hbitmap
);
77 logbrush
.lbStyle
= BS_DIBPATTERN
;
78 logbrush
.lbColor
= coloruse
;
81 /* Make a copy of the bitmap */
82 if (!(info
= (BITMAPINFO
*)GlobalLock( hbitmap
)))
88 if (info
->bmiHeader
.biCompression
) size
= info
->bmiHeader
.biSizeImage
;
90 size
= DIB_GetDIBImageBytes(info
->bmiHeader
.biWidth
, info
->bmiHeader
.biHeight
, info
->bmiHeader
.biBitCount
);
91 size
+= DIB_BitmapInfoSize(info
, coloruse
);
93 if (!(logbrush
.lbHatch
= (INT
)GlobalAlloc16( GMEM_MOVEABLE
, size
)))
95 GlobalUnlock16( hbitmap
);
98 newInfo
= (BITMAPINFO
*) GlobalLock16((HGLOBAL16
)logbrush
.lbHatch
);
99 memcpy(newInfo
, info
, size
);
100 GlobalUnlock16((HGLOBAL16
)logbrush
.lbHatch
);
101 GlobalUnlock(hbitmap
);
102 return IntGdiCreateBrushIndirect(&logbrush
);
107 IntGdiCreateDIBPatternBrushPt(CONST VOID
*PackedDIB
,
115 info
= (BITMAPINFO
*) PackedDIB
;
120 DPRINT ("%p %ldx%ld %dbpp\n",
122 info
->bmiHeader
.biWidth
,
123 info
->bmiHeader
.biHeight
,
124 info
->bmiHeader
.biBitCount
);
126 logbrush
.lbStyle
= BS_DIBPATTERN
;
127 logbrush
.lbColor
= Usage
;
128 logbrush
.lbHatch
= 0;
130 /* Make a copy of the bitmap */
132 if (info
->bmiHeader
.biCompression
)
134 size
= info
->bmiHeader
.biSizeImage
;
138 size
= DIB_GetDIBImageBytes (info
->bmiHeader
.biWidth
, info
->bmiHeader
.biHeight
, info
->bmiHeader
.biBitCount
);
140 size
+= DIB_BitmapInfoSize (info
, Usage
);
142 logbrush
.lbHatch
= (LONG
) GDIOBJ_AllocObj(size
, GDI_OBJECT_TYPE_DONTCARE
, NULL
);
143 if (logbrush
.lbHatch
== 0)
147 newInfo
= (PBITMAPINFO
) GDIOBJ_LockObj ((HGDIOBJ
) logbrush
.lbHatch
, GDI_OBJECT_TYPE_DONTCARE
);
149 memcpy(newInfo
, info
, size
);
150 GDIOBJ_UnlockObj((HGDIOBJ
) logbrush
.lbHatch
, GDI_OBJECT_TYPE_DONTCARE
);
152 return IntGdiCreateBrushIndirect (&logbrush
);
168 SurfObj
= (SURFOBJ
*)AccessUserObject((ULONG
)dc
->Surface
);
171 SetLastWin32Error(ERROR_INVALID_HANDLE
);
176 if (BrushObj
->logbrush
.lbStyle
!= BS_NULL
)
180 DestRect
.left
= XLeft
+ dc
->w
.DCOrgX
;
181 DestRect
.right
= XLeft
+ Width
+ dc
->w
.DCOrgX
;
185 DestRect
.left
= XLeft
+ Width
+ 1 + dc
->w
.DCOrgX
;
186 DestRect
.right
= XLeft
+ dc
->w
.DCOrgX
+ 1;
190 DestRect
.top
= YLeft
+ dc
->w
.DCOrgY
;
191 DestRect
.bottom
= YLeft
+ Height
+ dc
->w
.DCOrgY
;
195 DestRect
.top
= YLeft
+ Height
+ dc
->w
.DCOrgY
+ 1;
196 DestRect
.bottom
= YLeft
+ dc
->w
.DCOrgY
+ 1;
198 ret
= IntEngBitBlt(SurfObj
,
215 IntGdiPolyPatBlt(HDC hDC
,
229 SetLastWin32Error(ERROR_INVALID_HANDLE
);
233 for (r
= pRects
, i
= 0; i
< cRects
; i
++)
235 BrushObj
= BRUSHOBJ_LockBrush(r
->hBrush
);
236 IntPatBlt(dc
,r
->r
.left
,r
->r
.top
,r
->r
.right
,r
->r
.bottom
,dwRop
,BrushObj
);
237 BRUSHOBJ_UnlockBrush(r
->hBrush
);
245 /******************************************************************************/
247 HBRUSH STDCALL
NtGdiCreateBrushIndirect(CONST LOGBRUSH
*lb
)
252 Status
= MmCopyFromCaller(&Safelb
, lb
, sizeof(LOGBRUSH
));
253 if(!NT_SUCCESS(Status
))
255 SetLastNtError(Status
);
259 return IntGdiCreateBrushIndirect(&Safelb
);
262 HBRUSH STDCALL
NtGdiCreateDIBPatternBrush(HGLOBAL hDIBPacked
,
265 /* IntGdiCreateDIBPatternBrush() */
269 HBRUSH STDCALL
NtGdiCreateDIBPatternBrushPt(CONST VOID
*PackedDIB
,
272 /* FIXME - copy PackedDIB memory first! */
273 return IntGdiCreateDIBPatternBrushPt(PackedDIB
, Usage
);
276 HBRUSH STDCALL
NtGdiCreateHatchBrush(INT Style
,
281 DPRINT("%d %06lx\n", Style
, Color
);
283 if (Style
< 0 || Style
>= NB_HATCH_STYLES
)
287 logbrush
.lbStyle
= BS_HATCHED
;
288 logbrush
.lbColor
= Color
;
289 logbrush
.lbHatch
= Style
;
291 return IntGdiCreateBrushIndirect (&logbrush
);
294 HBRUSH STDCALL
NtGdiCreatePatternBrush(HBITMAP hBitmap
)
296 LOGBRUSH logbrush
= { BS_PATTERN
, 0, 0 };
298 DPRINT ("%04x\n", hBitmap
);
299 logbrush
.lbHatch
= (INT
) BITMAPOBJ_CopyBitmap (hBitmap
);
300 if(!logbrush
.lbHatch
)
306 return IntGdiCreateBrushIndirect( &logbrush
);
310 HBRUSH STDCALL
NtGdiCreateSolidBrush(COLORREF Color
)
314 logbrush
.lbStyle
= BS_SOLID
;
315 logbrush
.lbColor
= Color
;
316 logbrush
.lbHatch
= 0;
318 return IntGdiCreateBrushIndirect(&logbrush
);
321 BOOL STDCALL
NtGdiFixBrushOrgEx(VOID
)
326 BOOL STDCALL
NtGdiPolyPatBlt(HDC hDC
,
338 rb
= ExAllocatePool(PagedPool
, sizeof(PATRECT
) * cRects
);
341 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
344 Status
= MmCopyFromCaller(rb
, pRects
, sizeof(PATRECT
) * cRects
);
345 if(!NT_SUCCESS(Status
))
348 SetLastNtError(Status
);
353 Ret
= IntGdiPolyPatBlt(hDC
, dwRop
, pRects
, cRects
, Reserved
);
360 BOOL STDCALL
NtGdiPatBlt(HDC hDC
,
368 DC
*dc
= DC_LockDc(hDC
);
373 SetLastWin32Error(ERROR_INVALID_HANDLE
);
377 BrushObj
= BRUSHOBJ_LockBrush(dc
->w
.hBrush
);
378 if (NULL
== BrushObj
)
380 SetLastWin32Error(ERROR_INVALID_HANDLE
);
385 ret
= IntPatBlt(dc
,XLeft
,YLeft
,Width
,Height
,ROP
,BrushObj
);
387 BRUSHOBJ_UnlockBrush(dc
->w
.hBrush
);
392 BOOL STDCALL
NtGdiSetBrushOrgEx(HDC hDC
,