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
,
115 dc
->rosdc
.CombinedClip
,
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
,
129 dc
->rosdc
.CombinedClip
,
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
, RectBounds
);
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
)
462 hRgn
= IntCreatePolyPolygonRgn(SafePoints
, SafeCounts
, Count
, (INT_PTR
)hDC
);
463 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
464 return (ULONG_PTR
)hRgn
;
470 EngSetLastError(ERROR_INVALID_HANDLE
);
471 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
475 if (dc
->dctype
== DC_TYPE_INFO
)
478 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
479 /* Yes, Windows really returns TRUE in this case */
483 DC_vPrepareDCsForBlit(dc
, dc
->rosdc
.CombinedClip
->rclBounds
,
484 NULL
, dc
->rosdc
.CombinedClip
->rclBounds
);
486 if (dc
->pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
487 DC_vUpdateFillBrush(dc
);
489 if (dc
->pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
490 DC_vUpdateLineBrush(dc
);
492 /* Perform the actual work */
496 Ret
= IntGdiPolyPolygon(dc
, SafePoints
, SafeCounts
, Count
);
498 case GdiPolyPolyLine
:
499 Ret
= IntGdiPolyPolyline(dc
, SafePoints
, SafeCounts
, Count
);
502 Ret
= IntGdiPolyBezier(dc
, SafePoints
, *SafeCounts
);
505 Ret
= IntGdiPolylineTo(dc
, SafePoints
, *SafeCounts
);
507 case GdiPolyBezierTo
:
508 Ret
= IntGdiPolyBezierTo(dc
, SafePoints
, *SafeCounts
);
511 EngSetLastError(ERROR_INVALID_PARAMETER
);
515 /* Cleanup and return */
516 DC_vFinishBlit(dc
, NULL
);
518 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
520 return (ULONG_PTR
)Ret
;
532 SURFACE
*psurf
= NULL
;
533 PBRUSH pbrLine
, pbrFill
;
534 BOOL ret
= FALSE
; // Default to failure
540 ASSERT ( dc
); // Caller's responsibility to set this up
542 pdcattr
= dc
->pdcattr
;
544 // Rectangle Path only.
545 if ( PATH_IsPathOpen(dc
->dclevel
) )
547 return PATH_Rectangle ( dc
, LeftRect
, TopRect
, RightRect
, BottomRect
);
550 /* Make sure rectangle is not inverted */
551 DestRect
.left
= min(LeftRect
, RightRect
);
552 DestRect
.right
= max(LeftRect
, RightRect
);
553 DestRect
.top
= min(TopRect
, BottomRect
);
554 DestRect
.bottom
= max(TopRect
, BottomRect
);
556 IntLPtoDP(dc
, (LPPOINT
)&DestRect
, 2);
558 DestRect
.left
+= dc
->ptlDCOrig
.x
;
559 DestRect
.right
+= dc
->ptlDCOrig
.x
;
560 DestRect
.top
+= dc
->ptlDCOrig
.y
;
561 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
563 /* In GM_COMPATIBLE, don't include bottom and right edges */
564 if (pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
570 DC_vPrepareDCsForBlit(dc
, DestRect
, NULL
, DestRect
);
572 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
573 DC_vUpdateFillBrush(dc
);
575 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
576 DC_vUpdateLineBrush(dc
);
578 pbrFill
= dc
->dclevel
.pbrFill
;
579 pbrLine
= dc
->dclevel
.pbrLine
;
586 psurf
= dc
->dclevel
.pSurface
;
595 if (!(pbrFill
->flAttrs
& BR_IS_NULL
))
597 BrushOrigin
= *((PPOINTL
)&pbrFill
->ptOrigin
);
598 BrushOrigin
.x
+= dc
->ptlDCOrig
.x
;
599 BrushOrigin
.y
+= dc
->ptlDCOrig
.y
;
600 ret
= IntEngBitBlt(&psurf
->SurfObj
,
603 dc
->rosdc
.CombinedClip
,
608 &dc
->eboFill
.BrushObject
,
610 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
614 // Draw the rectangle with the current pen
616 ret
= TRUE
; // Change default to success
618 if (!(pbrLine
->flAttrs
& BR_IS_NULL
))
620 Mix
= ROP2_TO_MIX(pdcattr
->jROP2
);
621 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
622 dc
->rosdc
.CombinedClip
,
623 &dc
->eboLine
.BrushObject
,
624 DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.top
,
625 &DestRect
, // Bounding rectangle
628 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
629 dc
->rosdc
.CombinedClip
,
630 &dc
->eboLine
.BrushObject
,
631 DestRect
.right
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
,
632 &DestRect
, // Bounding rectangle
635 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
636 dc
->rosdc
.CombinedClip
,
637 &dc
->eboLine
.BrushObject
,
638 DestRect
.right
, DestRect
.bottom
, DestRect
.left
, DestRect
.bottom
,
639 &DestRect
, // Bounding rectangle
642 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
643 dc
->rosdc
.CombinedClip
,
644 &dc
->eboLine
.BrushObject
,
645 DestRect
.left
, DestRect
.bottom
, DestRect
.left
, DestRect
.top
,
646 &DestRect
, // Bounding rectangle
651 DC_vFinishBlit(dc
, NULL
);
653 /* Move current position in DC?
654 MSDN: The current position is neither used nor updated by Rectangle. */
661 NtGdiRectangle(HDC hDC
,
668 BOOL ret
; // Default to failure
673 EngSetLastError(ERROR_INVALID_HANDLE
);
676 if (dc
->dctype
== DC_TYPE_INFO
)
679 /* Yes, Windows really returns TRUE in this case */
683 /* Do we rotate or shear? */
684 if (!(dc
->pdcattr
->mxWorldToDevice
.flAccel
& XFORM_SCALE
))
686 POINTL DestCoords
[4];
687 ULONG PolyCounts
= 4;
689 DestCoords
[0].x
= DestCoords
[3].x
= LeftRect
;
690 DestCoords
[0].y
= DestCoords
[1].y
= TopRect
;
691 DestCoords
[1].x
= DestCoords
[2].x
= RightRect
;
692 DestCoords
[2].y
= DestCoords
[3].y
= BottomRect
;
693 // Use IntGdiPolyPolygon so to support PATH.
694 ret
= IntGdiPolyPolygon(dc
, DestCoords
, &PolyCounts
, 1);
698 ret
= IntRectangle(dc
, LeftRect
, TopRect
, RightRect
, BottomRect
);
719 PBRUSH pbrLine
, pbrFill
;
721 LONG PenWidth
, PenOrigWidth
;
722 BOOL ret
= TRUE
; // Default to success
725 ASSERT ( dc
); // Caller's responsibility to set this up
727 if ( PATH_IsPathOpen(dc
->dclevel
) )
728 return PATH_RoundRect ( dc
, Left
, Top
, Right
, Bottom
,
729 xCurveDiameter
, yCurveDiameter
);
731 if ((Left
== Right
) || (Top
== Bottom
)) return TRUE
;
733 xCurveDiameter
= max(abs( xCurveDiameter
), 1);
734 yCurveDiameter
= max(abs( yCurveDiameter
), 1);
738 INT tmp
= Right
; Right
= Left
; Left
= tmp
;
742 INT tmp
= Bottom
; Bottom
= Top
; Top
= tmp
;
745 pdcattr
= dc
->pdcattr
;
747 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
748 DC_vUpdateFillBrush(dc
);
750 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
751 DC_vUpdateLineBrush(dc
);
753 pbrLine
= PEN_ShareLockPen(pdcattr
->hpen
);
756 /* Nothing to do, as we don't have a bitmap */
757 EngSetLastError(ERROR_INTERNAL_ERROR
);
761 PenOrigWidth
= PenWidth
= pbrLine
->ptPenWidth
.x
;
762 if (pbrLine
->ulPenStyle
== PS_NULL
) PenWidth
= 0;
764 if (pbrLine
->ulPenStyle
== PS_INSIDEFRAME
)
766 if (2*PenWidth
> (Right
- Left
)) PenWidth
= (Right
-Left
+ 1)/2;
767 if (2*PenWidth
> (Bottom
- Top
)) PenWidth
= (Bottom
-Top
+ 1)/2;
768 Left
+= PenWidth
/ 2;
769 Right
-= (PenWidth
- 1) / 2;
771 Bottom
-= (PenWidth
- 1) / 2;
774 if (!PenWidth
) PenWidth
= 1;
775 pbrLine
->ptPenWidth
.x
= PenWidth
;
777 RectBounds
.left
= Left
;
778 RectBounds
.top
= Top
;
779 RectBounds
.right
= Right
;
780 RectBounds
.bottom
= Bottom
;
782 IntLPtoDP(dc
, (LPPOINT
)&RectBounds
, 2);
784 RectBounds
.left
+= dc
->ptlDCOrig
.x
;
785 RectBounds
.top
+= dc
->ptlDCOrig
.y
;
786 RectBounds
.right
+= dc
->ptlDCOrig
.x
;
787 RectBounds
.bottom
+= dc
->ptlDCOrig
.y
;
789 pbrFill
= BRUSH_ShareLockBrush(pdcattr
->hbrush
);
792 DPRINT1("FillRound Fail\n");
793 EngSetLastError(ERROR_INTERNAL_ERROR
);
799 DC_vPrepareDCsForBlit(dc
, RectBounds
, NULL
, RectBounds
);
801 RtlCopyMemory(&brushTemp
, pbrFill
, sizeof(brushTemp
));
802 brushTemp
.ptOrigin
.x
+= RectBounds
.left
- Left
;
803 brushTemp
.ptOrigin
.y
+= RectBounds
.top
- Top
;
804 ret
= IntFillRoundRect( dc
,
812 BRUSH_ShareUnlockBrush(pbrFill
);
816 ret
= IntDrawRoundRect( dc
,
826 DC_vFinishBlit(dc
, NULL
);
830 pbrLine
->ptPenWidth
.x
= PenOrigWidth
;
831 PEN_ShareUnlockPen(pbrLine
);
846 DC
*dc
= DC_LockDc(hDC
);
847 BOOL ret
= FALSE
; /* Default to failure */
849 DPRINT("NtGdiRoundRect(0x%p,%i,%i,%i,%i,%i,%i)\n",hDC
,LeftRect
,TopRect
,RightRect
,BottomRect
,Width
,Height
);
852 DPRINT1("NtGdiRoundRect() - hDC is invalid\n");
853 EngSetLastError(ERROR_INVALID_HANDLE
);
855 else if (dc
->dctype
== DC_TYPE_INFO
)
858 /* Yes, Windows really returns TRUE in this case */
863 ret
= IntRoundRect ( dc
, LeftRect
, TopRect
, RightRect
, BottomRect
, Width
, Height
);
888 /* Check parameters */
889 if (ulMode
& GRADIENT_FILL_TRIANGLE
)
891 PGRADIENT_TRIANGLE pTriangle
= (PGRADIENT_TRIANGLE
)pMesh
;
893 for (i
= 0; i
< nMesh
; i
++, pTriangle
++)
895 if (pTriangle
->Vertex1
>= nVertex
||
896 pTriangle
->Vertex2
>= nVertex
||
897 pTriangle
->Vertex3
>= nVertex
)
899 EngSetLastError(ERROR_INVALID_PARAMETER
);
906 PGRADIENT_RECT pRect
= (PGRADIENT_RECT
)pMesh
;
907 for (i
= 0; i
< nMesh
; i
++, pRect
++)
909 if (pRect
->UpperLeft
>= nVertex
|| pRect
->LowerRight
>= nVertex
)
911 EngSetLastError(ERROR_INVALID_PARAMETER
);
917 /* Lock the output DC */
918 pdc
= DC_LockDc(hdc
);
921 EngSetLastError(ERROR_INVALID_HANDLE
);
925 if(pdc
->dctype
== DC_TYPE_INFO
)
928 /* Yes, Windows really returns TRUE in this case */
932 psurf
= pdc
->dclevel
.pSurface
;
935 /* Memory DC with no surface selected */
937 return TRUE
; // CHECKME
940 /* Calculate extent */
941 rclExtent
.left
= rclExtent
.right
= pVertex
->x
;
942 rclExtent
.top
= rclExtent
.bottom
= pVertex
->y
;
943 for (i
= 0; i
< nVertex
; i
++)
945 rclExtent
.left
= min(rclExtent
.left
, (pVertex
+ i
)->x
);
946 rclExtent
.right
= max(rclExtent
.right
, (pVertex
+ i
)->x
);
947 rclExtent
.top
= min(rclExtent
.top
, (pVertex
+ i
)->y
);
948 rclExtent
.bottom
= max(rclExtent
.bottom
, (pVertex
+ i
)->y
);
950 IntLPtoDP(pdc
, (LPPOINT
)&rclExtent
, 2);
952 rclExtent
.left
+= pdc
->ptlDCOrig
.x
;
953 rclExtent
.right
+= pdc
->ptlDCOrig
.x
;
954 rclExtent
.top
+= pdc
->ptlDCOrig
.y
;
955 rclExtent
.bottom
+= pdc
->ptlDCOrig
.y
;
957 ptlDitherOrg
.x
= ptlDitherOrg
.y
= 0;
958 IntLPtoDP(pdc
, (LPPOINT
)&ptlDitherOrg
, 1);
960 ptlDitherOrg
.x
+= pdc
->ptlDCOrig
.x
;
961 ptlDitherOrg
.y
+= pdc
->ptlDCOrig
.y
;
963 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
965 ASSERT(pdc
->rosdc
.CombinedClip
);
967 DC_vPrepareDCsForBlit(pdc
, rclExtent
, NULL
, rclExtent
);
969 bRet
= IntEngGradientFill(&psurf
->SurfObj
,
970 pdc
->rosdc
.CombinedClip
,
980 EXLATEOBJ_vCleanup(&exlo
);
981 DC_vFinishBlit(pdc
, NULL
);
998 PTRIVERTEX SafeVertex
;
1000 ULONG cbVertex
, cbMesh
;
1002 /* Validate parameters */
1003 if (!pVertex
|| !nVertex
|| !pMesh
|| !nMesh
)
1005 EngSetLastError(ERROR_INVALID_PARAMETER
);
1011 case GRADIENT_FILL_RECT_H
:
1012 case GRADIENT_FILL_RECT_V
:
1013 cbMesh
= nMesh
* sizeof(GRADIENT_RECT
);
1015 case GRADIENT_FILL_TRIANGLE
:
1016 cbMesh
= nMesh
* sizeof(GRADIENT_TRIANGLE
);
1019 EngSetLastError(ERROR_INVALID_PARAMETER
);
1023 cbVertex
= nVertex
* sizeof(TRIVERTEX
) ;
1024 if(cbVertex
+ cbMesh
<= cbVertex
)
1030 /* Allocate a kernel mode buffer */
1031 SafeVertex
= ExAllocatePoolWithTag(PagedPool
, cbVertex
+ cbMesh
, TAG_SHAPE
);
1034 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1038 SafeMesh
= (PVOID
)((ULONG_PTR
)SafeVertex
+ cbVertex
);
1040 /* Copy the parameters to kernel mode */
1043 ProbeForRead(pVertex
, cbVertex
, 1);
1044 ProbeForRead(pMesh
, cbMesh
, 1);
1045 RtlCopyMemory(SafeVertex
, pVertex
, cbVertex
);
1046 RtlCopyMemory(SafeMesh
, pMesh
, cbMesh
);
1048 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1050 ExFreePoolWithTag(SafeVertex
, TAG_SHAPE
);
1051 SetLastNtError(_SEH2_GetExceptionCode());
1052 _SEH2_YIELD(return FALSE
;)
1056 /* Call the internal function */
1057 bRet
= GreGradientFill(hdc
, SafeVertex
, nVertex
, SafeMesh
, nMesh
, ulMode
);
1059 /* Cleanup and return result */
1060 ExFreePoolWithTag(SafeVertex
, TAG_SHAPE
);
1074 SURFACE
*psurf
= NULL
;
1081 dc
= DC_LockDc(hDC
);
1084 EngSetLastError(ERROR_INVALID_HANDLE
);
1087 if (dc
->dctype
== DC_TYPE_INFO
)
1090 /* Yes, Windows really returns TRUE in this case */
1094 pdcattr
= dc
->pdcattr
;
1096 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
1097 DC_vUpdateFillBrush(dc
);
1099 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
1100 DC_vUpdateLineBrush(dc
);
1104 IntLPtoDP(dc
, (LPPOINT
)&Pt
, 1);
1106 Ret
= NtGdiPtInRegion(dc
->rosdc
.hGCClipRgn
, Pt
.x
, Pt
.y
);
1108 IntGdiGetRgnBox(dc
->rosdc
.hGCClipRgn
,(LPRECT
)&DestRect
);
1112 DC_vPrepareDCsForBlit(dc
, DestRect
, NULL
, DestRect
);
1114 psurf
= dc
->dclevel
.pSurface
;
1121 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurf
->ppal
, 0, 0xffffff, 0);
1123 /* Only solid fills supported for now
1124 * How to support pattern brushes and non standard surfaces (not offering dib functions):
1125 * Version a (most likely slow): call DrvPatBlt for every pixel
1126 * Version b: create a flood mask and let MaskBlt blit a masked brush */
1127 ConvColor
= XLATEOBJ_iXlate(&exlo
.xlo
, Color
);
1128 Ret
= DIB_XXBPP_FloodFillSolid(&psurf
->SurfObj
, &dc
->eboFill
.BrushObject
, &DestRect
, &Pt
, ConvColor
, FillType
);
1130 EXLATEOBJ_vCleanup(&exlo
);
1133 DC_vFinishBlit(dc
, NULL
);