2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: subsystems/win32/win32k/objects/fillshap.c
14 #define Rsin(d) ((d) == 0.0 ? 0.0 : ((d) == 90.0 ? 1.0 : sin(d*M_PI/180.0)))
15 #define Rcos(d) ((d) == 0.0 ? 1.0 : ((d) == 90.0 ? 0.0 : cos(d*M_PI/180.0)))
23 PBRUSH pbrLine
, pbrFill
;
24 BOOL ret
= FALSE
; // Default to failure
32 ASSERT(dc
); // Caller's responsibility to pass a valid dc
34 if (!Points
|| Count
< 2 )
36 EngSetLastError(ERROR_INVALID_PARAMETER
);
44 for (CurrentPoint = 1; CurrentPoint < Count; ++CurrentPoint) {
45 Left = min(Left, Points[CurrentPoint].x);
46 Top = min(Top, Points[CurrentPoint].y);
50 pdcattr
= dc
->pdcattr
;
52 /* Convert to screen coordinates */
53 IntLPtoDP(dc
, Points
, Count
);
54 for (CurrentPoint
= 0; CurrentPoint
< Count
; CurrentPoint
++)
56 Points
[CurrentPoint
].x
+= dc
->ptlDCOrig
.x
;
57 Points
[CurrentPoint
].y
+= dc
->ptlDCOrig
.y
;
59 // No need to have path here.
61 DestRect
.left
= Points
[0].x
;
62 DestRect
.right
= Points
[0].x
;
63 DestRect
.top
= Points
[0].y
;
64 DestRect
.bottom
= Points
[0].y
;
66 for (CurrentPoint
= 1; CurrentPoint
< Count
; ++CurrentPoint
)
68 DestRect
.left
= min(DestRect
.left
, Points
[CurrentPoint
].x
);
69 DestRect
.right
= max(DestRect
.right
, Points
[CurrentPoint
].x
);
70 DestRect
.top
= min(DestRect
.top
, Points
[CurrentPoint
].y
);
71 DestRect
.bottom
= max(DestRect
.bottom
, Points
[CurrentPoint
].y
);
74 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
75 DC_vUpdateFillBrush(dc
);
77 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
78 DC_vUpdateLineBrush(dc
);
80 /* Special locking order to avoid lock-ups */
81 pbrFill
= dc
->dclevel
.pbrFill
;
82 pbrLine
= dc
->dclevel
.pbrLine
;
83 psurf
= dc
->dclevel
.pSurface
;
84 /* FIXME: psurf can be NULL!!!! don't assert but handle this case gracefully! */
87 /* Now fill the polygon with the current fill brush. */
88 if (!(pbrFill
->flAttrs
& BR_IS_NULL
))
90 BrushOrigin
= *((PPOINTL
)&pbrFill
->ptOrigin
);
91 BrushOrigin
.x
+= dc
->ptlDCOrig
.x
;
92 BrushOrigin
.y
+= dc
->ptlDCOrig
.y
;
93 ret
= IntFillPolygon (dc
,
95 &dc
->eboFill
.BrushObject
,
102 // Draw the Polygon Edges with the current pen ( if not a NULL pen )
103 if (!(pbrLine
->flAttrs
& BR_IS_NULL
))
107 for (i
= 0; i
< Count
-1; i
++)
110 // DPRINT1("Polygon Making line from (%d,%d) to (%d,%d)\n",
111 // Points[0].x, Points[0].y,
112 // Points[1].x, Points[1].y );
114 ret
= IntEngLineTo(&psurf
->SurfObj
,
116 &dc
->eboLine
.BrushObject
,
117 Points
[i
].x
, /* From */
119 Points
[i
+1].x
, /* To */
122 ROP2_TO_MIX(pdcattr
->jROP2
)); /* MIX */
125 /* Close the polygon */
128 ret
= IntEngLineTo(&psurf
->SurfObj
,
130 &dc
->eboLine
.BrushObject
,
131 Points
[Count
-1].x
, /* From */
133 Points
[0].x
, /* To */
136 ROP2_TO_MIX(pdcattr
->jROP2
)); /* MIX */
145 IntGdiPolyPolygon(DC
*dc
,
150 if (PATH_IsPathOpen(dc
->dclevel
))
151 return PATH_PolyPolygon ( dc
, Points
, (PINT
)PolyCounts
, Count
);
155 if (!IntGdiPolygon ( dc
, Points
, *PolyCounts
))
157 Points
+=*PolyCounts
++;
163 IntPolygon(HDC hdc
, POINT
*Point
, int Count
)
166 if (!(dc
= DC_LockDc(hdc
)))
168 EngSetLastError(ERROR_INVALID_HANDLE
);
171 return IntGdiPolygon(dc
, Point
, Count
);
175 /******************************************************************************/
184 * This function uses optimized Bresenham's ellipse algorithm. It draws
185 * four lines of the ellipse in one pass.
202 LONG PenWidth
, PenOrigWidth
;
203 LONG RadiusX
, RadiusY
, CenterX
, CenterY
;
204 PBRUSH pFillBrushObj
;
205 BRUSH tmpFillBrushObj
;
207 if ((Left
== Right
) || (Top
== Bottom
)) return TRUE
;
212 EngSetLastError(ERROR_INVALID_HANDLE
);
215 if (dc
->dctype
== DC_TYPE_INFO
)
218 /* Yes, Windows really returns TRUE in this case */
222 if (PATH_IsPathOpen(dc
->dclevel
))
224 ret
= PATH_Ellipse(dc
, Left
, Top
, Right
, Bottom
);
231 INT tmp
= Right
; Right
= Left
; Left
= tmp
;
235 INT tmp
= Bottom
; Bottom
= Top
; Top
= tmp
;
238 pdcattr
= dc
->pdcattr
;
240 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
241 DC_vUpdateFillBrush(dc
);
243 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
244 DC_vUpdateLineBrush(dc
);
246 pbrush
= PEN_ShareLockPen(pdcattr
->hpen
);
249 DPRINT1("Ellipse Fail 1\n");
251 EngSetLastError(ERROR_INTERNAL_ERROR
);
255 PenOrigWidth
= PenWidth
= pbrush
->ptPenWidth
.x
;
256 if (pbrush
->ulPenStyle
== PS_NULL
) PenWidth
= 0;
258 if (pbrush
->ulPenStyle
== PS_INSIDEFRAME
)
260 if (2*PenWidth
> (Right
- Left
)) PenWidth
= (Right
-Left
+ 1)/2;
261 if (2*PenWidth
> (Bottom
- Top
)) PenWidth
= (Bottom
-Top
+ 1)/2;
262 Left
+= PenWidth
/ 2;
263 Right
-= (PenWidth
- 1) / 2;
265 Bottom
-= (PenWidth
- 1) / 2;
268 if (!PenWidth
) PenWidth
= 1;
269 pbrush
->ptPenWidth
.x
= PenWidth
;
271 RectBounds
.left
= Left
;
272 RectBounds
.right
= Right
;
273 RectBounds
.top
= Top
;
274 RectBounds
.bottom
= Bottom
;
276 IntLPtoDP(dc
, (LPPOINT
)&RectBounds
, 2);
278 RectBounds
.left
+= dc
->ptlDCOrig
.x
;
279 RectBounds
.right
+= dc
->ptlDCOrig
.x
;
280 RectBounds
.top
+= dc
->ptlDCOrig
.y
;
281 RectBounds
.bottom
+= dc
->ptlDCOrig
.y
;
283 // Setup for dynamic width and height.
284 RadiusX
= max((RectBounds
.right
- RectBounds
.left
) / 2, 2); // Needs room
285 RadiusY
= max((RectBounds
.bottom
- RectBounds
.top
) / 2, 2);
286 CenterX
= (RectBounds
.right
+ RectBounds
.left
) / 2;
287 CenterY
= (RectBounds
.bottom
+ RectBounds
.top
) / 2;
289 DPRINT("Ellipse 1: Left: %d, Top: %d, Right: %d, Bottom: %d\n",
290 RectBounds
.left
,RectBounds
.top
,RectBounds
.right
,RectBounds
.bottom
);
292 DPRINT("Ellipse 2: XLeft: %d, YLeft: %d, Width: %d, Height: %d\n",
293 CenterX
- RadiusX
, CenterY
+ RadiusY
, RadiusX
*2, RadiusY
*2);
295 pFillBrushObj
= BRUSH_ShareLockBrush(pdcattr
->hbrush
);
296 if (NULL
== pFillBrushObj
)
298 DPRINT1("FillEllipse Fail\n");
299 EngSetLastError(ERROR_INTERNAL_ERROR
);
304 RtlCopyMemory(&tmpFillBrushObj
, pFillBrushObj
, sizeof(tmpFillBrushObj
));
305 //tmpFillBrushObj.ptOrigin.x += RectBounds.left - Left;
306 //tmpFillBrushObj.ptOrigin.y += RectBounds.top - Top;
307 tmpFillBrushObj
.ptOrigin
.x
+= dc
->ptlDCOrig
.x
;
308 tmpFillBrushObj
.ptOrigin
.y
+= dc
->ptlDCOrig
.y
;
310 DC_vPrepareDCsForBlit(dc
, &RectBounds
, NULL
, NULL
);
312 ret
= IntFillEllipse( dc
,
318 BRUSH_ShareUnlockBrush(pFillBrushObj
);
322 ret
= IntDrawEllipse( dc
,
330 DC_vFinishBlit(dc
, NULL
);
333 pbrush
->ptPenWidth
.x
= PenOrigWidth
;
334 PEN_ShareUnlockPen(pbrush
);
336 DPRINT("Ellipse Exit.\n");
342 // When the fill mode is ALTERNATE, GDI fills the area between odd-numbered and
343 // even-numbered polygon sides on each scan line. That is, GDI fills the area between the
344 // first and second side, between the third and fourth side, and so on.
346 // WINDING Selects winding mode (fills any region with a nonzero winding value).
347 // When the fill mode is WINDING, GDI fills any region that has a nonzero winding value.
348 // This value is defined as the number of times a pen used to draw the polygon would go around the region.
349 // The direction of each edge of the polygon is important.
351 extern BOOL
FillPolygon(PDC dc
,
364 NtGdiPolyPolyDraw( IN HDC hDC
,
365 IN PPOINT UnsafePoints
,
366 IN PULONG UnsafeCounts
,
374 NTSTATUS Status
= STATUS_SUCCESS
;
376 ULONG nPoints
= 0, nMaxPoints
= 0, nInvalid
= 0, i
;
378 if (!UnsafePoints
|| !UnsafeCounts
||
379 Count
== 0 || iFunc
== 0 || iFunc
> GdiPolyPolyRgn
)
381 /* Windows doesn't set last error */
387 ProbeForRead(UnsafePoints
, Count
* sizeof(POINT
), 1);
388 ProbeForRead(UnsafeCounts
, Count
* sizeof(ULONG
), 1);
390 /* Count points and validate poligons */
391 for (i
= 0; i
< Count
; i
++)
393 if (UnsafeCounts
[i
] < 2)
397 nPoints
+= UnsafeCounts
[i
];
398 nMaxPoints
= max(nMaxPoints
, UnsafeCounts
[i
]);
401 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
403 Status
= _SEH2_GetExceptionCode();
407 if (!NT_SUCCESS(Status
))
409 /* Windows doesn't set last error */
413 if (nPoints
== 0 || nPoints
< nMaxPoints
)
415 /* If all polygon counts are zero, or we have overflow,
416 return without setting a last error code. */
422 /* If at least one poly count is 0 or 1, fail */
423 EngSetLastError(ERROR_INVALID_PARAMETER
);
427 /* Allocate one buffer for both counts and points */
428 pTemp
= ExAllocatePoolWithTag(PagedPool
,
429 Count
* sizeof(ULONG
) + nPoints
* sizeof(POINT
),
433 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
438 SafePoints
= (PVOID
)(SafeCounts
+ Count
);
442 /* Pointers already probed! */
443 RtlCopyMemory(SafeCounts
, UnsafeCounts
, Count
* sizeof(ULONG
));
444 RtlCopyMemory(SafePoints
, UnsafePoints
, nPoints
* sizeof(POINT
));
446 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
448 Status
= _SEH2_GetExceptionCode();
452 if (!NT_SUCCESS(Status
))
454 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
458 /* Special handling for GdiPolyPolyRgn */
459 if (iFunc
== GdiPolyPolyRgn
)
464 Rgn
= REGION_AllocUserRgnWithHandle(0);
467 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
468 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
471 hRgn
= Rgn
->BaseObject
.hHmgr
;
472 if (!IntSetPolyPolygonRgn(SafePoints
, SafeCounts
, Count
, hDC
? 1 : 2, Rgn
))
474 /* EngSetLastError ? */
475 GreDeleteObject(hRgn
);
478 RGNOBJAPI_Unlock(Rgn
);
479 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
480 return (ULONG_PTR
)hRgn
;
486 EngSetLastError(ERROR_INVALID_HANDLE
);
487 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
491 if (dc
->dctype
== DC_TYPE_INFO
)
494 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
495 /* Yes, Windows really returns TRUE in this case */
499 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
501 if (dc
->pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
502 DC_vUpdateFillBrush(dc
);
504 if (dc
->pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
505 DC_vUpdateLineBrush(dc
);
507 /* Perform the actual work */
511 Ret
= IntGdiPolyPolygon(dc
, SafePoints
, SafeCounts
, Count
);
513 case GdiPolyPolyLine
:
514 Ret
= IntGdiPolyPolyline(dc
, SafePoints
, SafeCounts
, Count
);
517 Ret
= IntGdiPolyBezier(dc
, SafePoints
, *SafeCounts
);
520 Ret
= IntGdiPolylineTo(dc
, SafePoints
, *SafeCounts
);
522 case GdiPolyBezierTo
:
523 Ret
= IntGdiPolyBezierTo(dc
, SafePoints
, *SafeCounts
);
526 EngSetLastError(ERROR_INVALID_PARAMETER
);
530 /* Cleanup and return */
531 DC_vFinishBlit(dc
, NULL
);
533 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
535 return (ULONG_PTR
)Ret
;
547 SURFACE
*psurf
= NULL
;
548 PBRUSH pbrLine
, pbrFill
;
549 BOOL ret
= FALSE
; // Default to failure
555 ASSERT ( dc
); // Caller's responsibility to set this up
557 pdcattr
= dc
->pdcattr
;
559 // Rectangle Path only.
560 if ( PATH_IsPathOpen(dc
->dclevel
) )
562 return PATH_Rectangle ( dc
, LeftRect
, TopRect
, RightRect
, BottomRect
);
565 /* Make sure rectangle is not inverted */
566 DestRect
.left
= min(LeftRect
, RightRect
);
567 DestRect
.right
= max(LeftRect
, RightRect
);
568 DestRect
.top
= min(TopRect
, BottomRect
);
569 DestRect
.bottom
= max(TopRect
, BottomRect
);
571 IntLPtoDP(dc
, (LPPOINT
)&DestRect
, 2);
573 DestRect
.left
+= dc
->ptlDCOrig
.x
;
574 DestRect
.right
+= dc
->ptlDCOrig
.x
;
575 DestRect
.top
+= dc
->ptlDCOrig
.y
;
576 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
578 /* In GM_COMPATIBLE, don't include bottom and right edges */
579 if (pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
585 DC_vPrepareDCsForBlit(dc
, &DestRect
, NULL
, NULL
);
587 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
588 DC_vUpdateFillBrush(dc
);
590 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
591 DC_vUpdateLineBrush(dc
);
593 pbrFill
= dc
->dclevel
.pbrFill
;
594 pbrLine
= dc
->dclevel
.pbrLine
;
601 psurf
= dc
->dclevel
.pSurface
;
610 if (!(pbrFill
->flAttrs
& BR_IS_NULL
))
612 BrushOrigin
= *((PPOINTL
)&pbrFill
->ptOrigin
);
613 BrushOrigin
.x
+= dc
->ptlDCOrig
.x
;
614 BrushOrigin
.y
+= dc
->ptlDCOrig
.y
;
615 ret
= IntEngBitBlt(&psurf
->SurfObj
,
623 &dc
->eboFill
.BrushObject
,
625 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
629 // Draw the rectangle with the current pen
631 ret
= TRUE
; // Change default to success
633 if (!(pbrLine
->flAttrs
& BR_IS_NULL
))
635 Mix
= ROP2_TO_MIX(pdcattr
->jROP2
);
636 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
638 &dc
->eboLine
.BrushObject
,
639 DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.top
,
640 &DestRect
, // Bounding rectangle
643 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
645 &dc
->eboLine
.BrushObject
,
646 DestRect
.right
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
,
647 &DestRect
, // Bounding rectangle
650 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
652 &dc
->eboLine
.BrushObject
,
653 DestRect
.right
, DestRect
.bottom
, DestRect
.left
, DestRect
.bottom
,
654 &DestRect
, // Bounding rectangle
657 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
659 &dc
->eboLine
.BrushObject
,
660 DestRect
.left
, DestRect
.bottom
, DestRect
.left
, DestRect
.top
,
661 &DestRect
, // Bounding rectangle
666 DC_vFinishBlit(dc
, NULL
);
668 /* Move current position in DC?
669 MSDN: The current position is neither used nor updated by Rectangle. */
676 NtGdiRectangle(HDC hDC
,
683 BOOL ret
; // Default to failure
688 EngSetLastError(ERROR_INVALID_HANDLE
);
691 if (dc
->dctype
== DC_TYPE_INFO
)
694 /* Yes, Windows really returns TRUE in this case */
698 /* Do we rotate or shear? */
699 if (!(dc
->pdcattr
->mxWorldToDevice
.flAccel
& XFORM_SCALE
))
701 POINTL DestCoords
[4];
702 ULONG PolyCounts
= 4;
704 DestCoords
[0].x
= DestCoords
[3].x
= LeftRect
;
705 DestCoords
[0].y
= DestCoords
[1].y
= TopRect
;
706 DestCoords
[1].x
= DestCoords
[2].x
= RightRect
;
707 DestCoords
[2].y
= DestCoords
[3].y
= BottomRect
;
708 // Use IntGdiPolyPolygon so to support PATH.
709 ret
= IntGdiPolyPolygon(dc
, DestCoords
, &PolyCounts
, 1);
713 ret
= IntRectangle(dc
, LeftRect
, TopRect
, RightRect
, BottomRect
);
734 PBRUSH pbrLine
, pbrFill
;
736 LONG PenWidth
, PenOrigWidth
;
737 BOOL ret
= TRUE
; // Default to success
740 ASSERT ( dc
); // Caller's responsibility to set this up
742 if ( PATH_IsPathOpen(dc
->dclevel
) )
743 return PATH_RoundRect ( dc
, Left
, Top
, Right
, Bottom
,
744 xCurveDiameter
, yCurveDiameter
);
746 if ((Left
== Right
) || (Top
== Bottom
)) return TRUE
;
748 xCurveDiameter
= max(abs( xCurveDiameter
), 1);
749 yCurveDiameter
= max(abs( yCurveDiameter
), 1);
753 INT tmp
= Right
; Right
= Left
; Left
= tmp
;
757 INT tmp
= Bottom
; Bottom
= Top
; Top
= tmp
;
760 pdcattr
= dc
->pdcattr
;
762 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
763 DC_vUpdateFillBrush(dc
);
765 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
766 DC_vUpdateLineBrush(dc
);
768 pbrLine
= PEN_ShareLockPen(pdcattr
->hpen
);
771 /* Nothing to do, as we don't have a bitmap */
772 EngSetLastError(ERROR_INTERNAL_ERROR
);
776 PenOrigWidth
= PenWidth
= pbrLine
->ptPenWidth
.x
;
777 if (pbrLine
->ulPenStyle
== PS_NULL
) PenWidth
= 0;
779 if (pbrLine
->ulPenStyle
== PS_INSIDEFRAME
)
781 if (2*PenWidth
> (Right
- Left
)) PenWidth
= (Right
-Left
+ 1)/2;
782 if (2*PenWidth
> (Bottom
- Top
)) PenWidth
= (Bottom
-Top
+ 1)/2;
783 Left
+= PenWidth
/ 2;
784 Right
-= (PenWidth
- 1) / 2;
786 Bottom
-= (PenWidth
- 1) / 2;
789 if (!PenWidth
) PenWidth
= 1;
790 pbrLine
->ptPenWidth
.x
= PenWidth
;
792 RectBounds
.left
= Left
;
793 RectBounds
.top
= Top
;
794 RectBounds
.right
= Right
;
795 RectBounds
.bottom
= Bottom
;
797 IntLPtoDP(dc
, (LPPOINT
)&RectBounds
, 2);
799 RectBounds
.left
+= dc
->ptlDCOrig
.x
;
800 RectBounds
.top
+= dc
->ptlDCOrig
.y
;
801 RectBounds
.right
+= dc
->ptlDCOrig
.x
;
802 RectBounds
.bottom
+= dc
->ptlDCOrig
.y
;
804 pbrFill
= BRUSH_ShareLockBrush(pdcattr
->hbrush
);
807 DPRINT1("FillRound Fail\n");
808 EngSetLastError(ERROR_INTERNAL_ERROR
);
814 DC_vPrepareDCsForBlit(dc
, &RectBounds
, NULL
, NULL
);
816 RtlCopyMemory(&brushTemp
, pbrFill
, sizeof(brushTemp
));
817 brushTemp
.ptOrigin
.x
+= RectBounds
.left
- Left
;
818 brushTemp
.ptOrigin
.y
+= RectBounds
.top
- Top
;
819 ret
= IntFillRoundRect( dc
,
827 BRUSH_ShareUnlockBrush(pbrFill
);
831 ret
= IntDrawRoundRect( dc
,
841 DC_vFinishBlit(dc
, NULL
);
845 pbrLine
->ptPenWidth
.x
= PenOrigWidth
;
846 PEN_ShareUnlockPen(pbrLine
);
861 DC
*dc
= DC_LockDc(hDC
);
862 BOOL ret
= FALSE
; /* Default to failure */
864 DPRINT("NtGdiRoundRect(0x%p,%i,%i,%i,%i,%i,%i)\n",hDC
,LeftRect
,TopRect
,RightRect
,BottomRect
,Width
,Height
);
867 DPRINT1("NtGdiRoundRect() - hDC is invalid\n");
868 EngSetLastError(ERROR_INVALID_HANDLE
);
870 else if (dc
->dctype
== DC_TYPE_INFO
)
873 /* Yes, Windows really returns TRUE in this case */
878 ret
= IntRoundRect ( dc
, LeftRect
, TopRect
, RightRect
, BottomRect
, Width
, Height
);
903 /* Check parameters */
904 if (ulMode
& GRADIENT_FILL_TRIANGLE
)
906 PGRADIENT_TRIANGLE pTriangle
= (PGRADIENT_TRIANGLE
)pMesh
;
908 for (i
= 0; i
< nMesh
; i
++, pTriangle
++)
910 if (pTriangle
->Vertex1
>= nVertex
||
911 pTriangle
->Vertex2
>= nVertex
||
912 pTriangle
->Vertex3
>= nVertex
)
914 EngSetLastError(ERROR_INVALID_PARAMETER
);
921 PGRADIENT_RECT pRect
= (PGRADIENT_RECT
)pMesh
;
922 for (i
= 0; i
< nMesh
; i
++, pRect
++)
924 if (pRect
->UpperLeft
>= nVertex
|| pRect
->LowerRight
>= nVertex
)
926 EngSetLastError(ERROR_INVALID_PARAMETER
);
932 /* Lock the output DC */
933 pdc
= DC_LockDc(hdc
);
936 EngSetLastError(ERROR_INVALID_HANDLE
);
940 if(pdc
->dctype
== DC_TYPE_INFO
)
943 /* Yes, Windows really returns TRUE in this case */
947 psurf
= pdc
->dclevel
.pSurface
;
950 /* Memory DC with no surface selected */
952 return TRUE
; // CHECKME
955 /* Calculate extent */
956 rclExtent
.left
= rclExtent
.right
= pVertex
->x
;
957 rclExtent
.top
= rclExtent
.bottom
= pVertex
->y
;
958 for (i
= 0; i
< nVertex
; i
++)
960 rclExtent
.left
= min(rclExtent
.left
, (pVertex
+ i
)->x
);
961 rclExtent
.right
= max(rclExtent
.right
, (pVertex
+ i
)->x
);
962 rclExtent
.top
= min(rclExtent
.top
, (pVertex
+ i
)->y
);
963 rclExtent
.bottom
= max(rclExtent
.bottom
, (pVertex
+ i
)->y
);
965 IntLPtoDP(pdc
, (LPPOINT
)&rclExtent
, 2);
967 rclExtent
.left
+= pdc
->ptlDCOrig
.x
;
968 rclExtent
.right
+= pdc
->ptlDCOrig
.x
;
969 rclExtent
.top
+= pdc
->ptlDCOrig
.y
;
970 rclExtent
.bottom
+= pdc
->ptlDCOrig
.y
;
972 ptlDitherOrg
.x
= ptlDitherOrg
.y
= 0;
973 IntLPtoDP(pdc
, (LPPOINT
)&ptlDitherOrg
, 1);
975 ptlDitherOrg
.x
+= pdc
->ptlDCOrig
.x
;
976 ptlDitherOrg
.y
+= pdc
->ptlDCOrig
.y
;
978 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
980 DC_vPrepareDCsForBlit(pdc
, &rclExtent
, NULL
, NULL
);
982 bRet
= IntEngGradientFill(&psurf
->SurfObj
,
993 EXLATEOBJ_vCleanup(&exlo
);
994 DC_vFinishBlit(pdc
, NULL
);
1011 PTRIVERTEX SafeVertex
;
1013 ULONG cbVertex
, cbMesh
;
1015 /* Validate parameters */
1016 if (!pVertex
|| !nVertex
|| !pMesh
|| !nMesh
)
1018 EngSetLastError(ERROR_INVALID_PARAMETER
);
1024 case GRADIENT_FILL_RECT_H
:
1025 case GRADIENT_FILL_RECT_V
:
1026 cbMesh
= nMesh
* sizeof(GRADIENT_RECT
);
1028 case GRADIENT_FILL_TRIANGLE
:
1029 cbMesh
= nMesh
* sizeof(GRADIENT_TRIANGLE
);
1032 EngSetLastError(ERROR_INVALID_PARAMETER
);
1036 cbVertex
= nVertex
* sizeof(TRIVERTEX
) ;
1037 if(cbVertex
+ cbMesh
<= cbVertex
)
1043 /* Allocate a kernel mode buffer */
1044 SafeVertex
= ExAllocatePoolWithTag(PagedPool
, cbVertex
+ cbMesh
, TAG_SHAPE
);
1047 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1051 SafeMesh
= (PVOID
)((ULONG_PTR
)SafeVertex
+ cbVertex
);
1053 /* Copy the parameters to kernel mode */
1056 ProbeForRead(pVertex
, cbVertex
, 1);
1057 ProbeForRead(pMesh
, cbMesh
, 1);
1058 RtlCopyMemory(SafeVertex
, pVertex
, cbVertex
);
1059 RtlCopyMemory(SafeMesh
, pMesh
, cbMesh
);
1061 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1063 ExFreePoolWithTag(SafeVertex
, TAG_SHAPE
);
1064 SetLastNtError(_SEH2_GetExceptionCode());
1065 _SEH2_YIELD(return FALSE
;)
1069 /* Call the internal function */
1070 bRet
= GreGradientFill(hdc
, SafeVertex
, nVertex
, SafeMesh
, nMesh
, ulMode
);
1072 /* Cleanup and return result */
1073 ExFreePoolWithTag(SafeVertex
, TAG_SHAPE
);
1087 SURFACE
*psurf
= NULL
;
1094 dc
= DC_LockDc(hDC
);
1097 EngSetLastError(ERROR_INVALID_HANDLE
);
1100 if (dc
->dctype
== DC_TYPE_INFO
)
1103 /* Yes, Windows really returns TRUE in this case */
1107 psurf
= dc
->dclevel
.pSurface
;
1114 pdcattr
= dc
->pdcattr
;
1116 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
1117 DC_vUpdateFillBrush(dc
);
1119 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
1120 DC_vUpdateLineBrush(dc
);
1124 IntLPtoDP(dc
, (LPPOINT
)&Pt
, 1);
1128 Ret
= REGION_PtInRegion(dc
->prgnRao
, Pt
.x
, Pt
.y
);
1130 REGION_GetRgnBox(dc
->prgnRao
,(LPRECT
)&DestRect
);
1135 RECTL_vSetRect(&DestRect
, 0, psurf
->SurfObj
.sizlBitmap
.cx
, 0, psurf
->SurfObj
.sizlBitmap
.cy
);
1137 DC_vPrepareDCsForBlit(dc
, &DestRect
, NULL
, NULL
);
1139 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurf
->ppal
, 0, 0xffffff, 0);
1141 /* Only solid fills supported for now
1142 * How to support pattern brushes and non standard surfaces (not offering dib functions):
1143 * Version a (most likely slow): call DrvPatBlt for every pixel
1144 * Version b: create a flood mask and let MaskBlt blit a masked brush */
1145 ConvColor
= XLATEOBJ_iXlate(&exlo
.xlo
, Color
);
1146 Ret
= DIB_XXBPP_FloodFillSolid(&psurf
->SurfObj
, &dc
->eboFill
.BrushObject
, &DestRect
, &Pt
, ConvColor
, FillType
);
1148 DC_vFinishBlit(dc
, NULL
);
1150 EXLATEOBJ_vCleanup(&exlo
);