2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/gdi/ntgdi/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
;
86 /* Memory DC without a bitmap selected, nothing to do. */
90 /* Now fill the polygon with the current fill brush. */
91 if (!(pbrFill
->flAttrs
& BR_IS_NULL
))
93 BrushOrigin
= *((PPOINTL
)&pbrFill
->ptOrigin
);
94 BrushOrigin
.x
+= dc
->ptlDCOrig
.x
;
95 BrushOrigin
.y
+= dc
->ptlDCOrig
.y
;
96 ret
= IntFillPolygon (dc
,
98 &dc
->eboFill
.BrushObject
,
105 // Draw the Polygon Edges with the current pen ( if not a NULL pen )
106 if (!(pbrLine
->flAttrs
& BR_IS_NULL
))
110 for (i
= 0; i
< Count
-1; i
++)
113 // DPRINT1("Polygon Making line from (%d,%d) to (%d,%d)\n",
114 // Points[0].x, Points[0].y,
115 // Points[1].x, Points[1].y );
117 ret
= IntEngLineTo(&psurf
->SurfObj
,
119 &dc
->eboLine
.BrushObject
,
120 Points
[i
].x
, /* From */
122 Points
[i
+1].x
, /* To */
125 ROP2_TO_MIX(pdcattr
->jROP2
)); /* MIX */
128 /* Close the polygon */
131 ret
= IntEngLineTo(&psurf
->SurfObj
,
133 &dc
->eboLine
.BrushObject
,
134 Points
[Count
-1].x
, /* From */
136 Points
[0].x
, /* To */
139 ROP2_TO_MIX(pdcattr
->jROP2
)); /* MIX */
148 IntGdiPolyPolygon(DC
*dc
,
153 if (PATH_IsPathOpen(dc
->dclevel
))
154 return PATH_PolyPolygon ( dc
, Points
, (PINT
)PolyCounts
, Count
);
158 if (!IntGdiPolygon ( dc
, Points
, *PolyCounts
))
160 Points
+=*PolyCounts
++;
166 IntPolygon(HDC hdc
, POINT
*Point
, int Count
)
171 pdc
= DC_LockDc(hdc
);
174 EngSetLastError(ERROR_INVALID_HANDLE
);
178 bResult
= IntGdiPolygon(pdc
, Point
, Count
);
185 /******************************************************************************/
194 * This function uses optimized Bresenham's ellipse algorithm. It draws
195 * four lines of the ellipse in one pass.
212 LONG PenWidth
, PenOrigWidth
;
213 LONG RadiusX
, RadiusY
, CenterX
, CenterY
;
214 PBRUSH pFillBrushObj
;
215 BRUSH tmpFillBrushObj
;
220 EngSetLastError(ERROR_INVALID_HANDLE
);
224 if (PATH_IsPathOpen(dc
->dclevel
))
226 ret
= PATH_Ellipse(dc
, Left
, Top
, Right
, Bottom
);
232 //// Could this use PATH_CheckCorners ?
234 if ((Left
== Right
) || (Top
== Bottom
))
242 INT tmp
= Right
; Right
= Left
; Left
= tmp
;
246 INT tmp
= Bottom
; Bottom
= Top
; Top
= tmp
;
250 pdcattr
= dc
->pdcattr
;
252 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
253 DC_vUpdateFillBrush(dc
);
255 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
256 DC_vUpdateLineBrush(dc
);
258 pbrush
= PEN_ShareLockPen(pdcattr
->hpen
);
261 DPRINT1("Ellipse Fail 1\n");
263 EngSetLastError(ERROR_INTERNAL_ERROR
);
267 PenOrigWidth
= PenWidth
= pbrush
->lWidth
;
268 if (pbrush
->ulPenStyle
== PS_NULL
) PenWidth
= 0;
270 if (pbrush
->ulPenStyle
== PS_INSIDEFRAME
)
272 if (2*PenWidth
> (Right
- Left
)) PenWidth
= (Right
-Left
+ 1)/2;
273 if (2*PenWidth
> (Bottom
- Top
)) PenWidth
= (Bottom
-Top
+ 1)/2;
274 Left
+= PenWidth
/ 2;
275 Right
-= (PenWidth
- 1) / 2;
277 Bottom
-= (PenWidth
- 1) / 2;
280 if (!PenWidth
) PenWidth
= 1;
281 pbrush
->lWidth
= PenWidth
;
283 RectBounds
.left
= Left
;
284 RectBounds
.right
= Right
;
285 RectBounds
.top
= Top
;
286 RectBounds
.bottom
= Bottom
;
288 IntLPtoDP(dc
, (LPPOINT
)&RectBounds
, 2);
290 RectBounds
.left
+= dc
->ptlDCOrig
.x
;
291 RectBounds
.right
+= dc
->ptlDCOrig
.x
;
292 RectBounds
.top
+= dc
->ptlDCOrig
.y
;
293 RectBounds
.bottom
+= dc
->ptlDCOrig
.y
;
295 // Setup for dynamic width and height.
296 RadiusX
= max((RectBounds
.right
- RectBounds
.left
) / 2, 2); // Needs room
297 RadiusY
= max((RectBounds
.bottom
- RectBounds
.top
) / 2, 2);
298 CenterX
= (RectBounds
.right
+ RectBounds
.left
) / 2;
299 CenterY
= (RectBounds
.bottom
+ RectBounds
.top
) / 2;
301 DPRINT("Ellipse 1: Left: %d, Top: %d, Right: %d, Bottom: %d\n",
302 RectBounds
.left
,RectBounds
.top
,RectBounds
.right
,RectBounds
.bottom
);
304 DPRINT("Ellipse 2: XLeft: %d, YLeft: %d, Width: %d, Height: %d\n",
305 CenterX
- RadiusX
, CenterY
+ RadiusY
, RadiusX
*2, RadiusY
*2);
307 pFillBrushObj
= BRUSH_ShareLockBrush(pdcattr
->hbrush
);
308 if (NULL
== pFillBrushObj
)
310 DPRINT1("FillEllipse Fail\n");
311 EngSetLastError(ERROR_INTERNAL_ERROR
);
316 RtlCopyMemory(&tmpFillBrushObj
, pFillBrushObj
, sizeof(tmpFillBrushObj
));
317 //tmpFillBrushObj.ptOrigin.x += RectBounds.left - Left;
318 //tmpFillBrushObj.ptOrigin.y += RectBounds.top - Top;
319 tmpFillBrushObj
.ptOrigin
.x
+= dc
->ptlDCOrig
.x
;
320 tmpFillBrushObj
.ptOrigin
.y
+= dc
->ptlDCOrig
.y
;
322 DC_vPrepareDCsForBlit(dc
, &RectBounds
, NULL
, NULL
);
324 ret
= IntFillEllipse( dc
,
330 BRUSH_ShareUnlockBrush(pFillBrushObj
);
334 ret
= IntDrawEllipse( dc
,
342 DC_vFinishBlit(dc
, NULL
);
345 pbrush
->lWidth
= PenOrigWidth
;
346 PEN_ShareUnlockPen(pbrush
);
348 DPRINT("Ellipse Exit.\n");
354 // When the fill mode is ALTERNATE, GDI fills the area between odd-numbered and
355 // even-numbered polygon sides on each scan line. That is, GDI fills the area between the
356 // first and second side, between the third and fourth side, and so on.
358 // WINDING Selects winding mode (fills any region with a nonzero winding value).
359 // When the fill mode is WINDING, GDI fills any region that has a nonzero winding value.
360 // This value is defined as the number of times a pen used to draw the polygon would go around the region.
361 // The direction of each edge of the polygon is important.
363 extern BOOL
FillPolygon(PDC dc
,
376 NtGdiPolyPolyDraw( IN HDC hDC
,
377 IN PPOINT UnsafePoints
,
378 IN PULONG UnsafeCounts
,
386 NTSTATUS Status
= STATUS_SUCCESS
;
388 ULONG nPoints
= 0, nMaxPoints
= 0, nInvalid
= 0, i
;
390 if (!UnsafePoints
|| !UnsafeCounts
||
391 Count
== 0 || iFunc
== 0 || iFunc
> GdiPolyPolyRgn
)
393 /* Windows doesn't set last error */
399 ProbeForRead(UnsafePoints
, Count
* sizeof(POINT
), 1);
400 ProbeForRead(UnsafeCounts
, Count
* sizeof(ULONG
), 1);
402 /* Count points and validate poligons */
403 for (i
= 0; i
< Count
; i
++)
405 if (UnsafeCounts
[i
] < 2)
409 nPoints
+= UnsafeCounts
[i
];
410 nMaxPoints
= max(nMaxPoints
, UnsafeCounts
[i
]);
413 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
415 Status
= _SEH2_GetExceptionCode();
419 if (!NT_SUCCESS(Status
))
421 /* Windows doesn't set last error */
425 if (nPoints
== 0 || nPoints
< nMaxPoints
)
427 /* If all polygon counts are zero, or we have overflow,
428 return without setting a last error code. */
434 /* If at least one poly count is 0 or 1, fail */
435 EngSetLastError(ERROR_INVALID_PARAMETER
);
439 /* Allocate one buffer for both counts and points */
440 pTemp
= ExAllocatePoolWithTag(PagedPool
,
441 Count
* sizeof(ULONG
) + nPoints
* sizeof(POINT
),
445 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
450 SafePoints
= (PVOID
)(SafeCounts
+ Count
);
454 /* Pointers already probed! */
455 RtlCopyMemory(SafeCounts
, UnsafeCounts
, Count
* sizeof(ULONG
));
456 RtlCopyMemory(SafePoints
, UnsafePoints
, nPoints
* sizeof(POINT
));
458 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
460 Status
= _SEH2_GetExceptionCode();
464 if (!NT_SUCCESS(Status
))
466 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
470 /* Special handling for GdiPolyPolyRgn */
471 if (iFunc
== GdiPolyPolyRgn
)
473 INT iMode
= (INT
)(UINT_PTR
)hDC
;
476 hrgn
= GreCreatePolyPolygonRgn(SafePoints
, SafeCounts
, Count
, iMode
);
478 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
479 return (ULONG_PTR
)hrgn
;
485 EngSetLastError(ERROR_INVALID_HANDLE
);
486 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
490 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
492 if (dc
->pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
493 DC_vUpdateFillBrush(dc
);
495 if (dc
->pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
496 DC_vUpdateLineBrush(dc
);
498 /* Perform the actual work */
502 Ret
= IntGdiPolyPolygon(dc
, SafePoints
, SafeCounts
, Count
);
504 case GdiPolyPolyLine
:
505 Ret
= IntGdiPolyPolyline(dc
, SafePoints
, SafeCounts
, Count
);
508 Ret
= IntGdiPolyBezier(dc
, SafePoints
, *SafeCounts
);
511 Ret
= IntGdiPolylineTo(dc
, SafePoints
, *SafeCounts
);
513 case GdiPolyBezierTo
:
514 Ret
= IntGdiPolyBezierTo(dc
, SafePoints
, *SafeCounts
);
517 EngSetLastError(ERROR_INVALID_PARAMETER
);
521 /* Cleanup and return */
522 DC_vFinishBlit(dc
, NULL
);
524 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
526 return (ULONG_PTR
)Ret
;
538 SURFACE
*psurf
= NULL
;
539 PBRUSH pbrLine
, pbrFill
;
540 BOOL ret
= FALSE
; // Default to failure
546 ASSERT ( dc
); // Caller's responsibility to set this up
548 pdcattr
= dc
->pdcattr
;
550 // Rectangle Path only.
551 if ( PATH_IsPathOpen(dc
->dclevel
) )
553 return PATH_Rectangle ( dc
, LeftRect
, TopRect
, RightRect
, BottomRect
);
556 /* Make sure rectangle is not inverted */
557 DestRect
.left
= min(LeftRect
, RightRect
);
558 DestRect
.right
= max(LeftRect
, RightRect
);
559 DestRect
.top
= min(TopRect
, BottomRect
);
560 DestRect
.bottom
= max(TopRect
, BottomRect
);
562 IntLPtoDP(dc
, (LPPOINT
)&DestRect
, 2);
564 DestRect
.left
+= dc
->ptlDCOrig
.x
;
565 DestRect
.right
+= dc
->ptlDCOrig
.x
;
566 DestRect
.top
+= dc
->ptlDCOrig
.y
;
567 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
569 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
571 IntUpdateBoundsRect(dc
, &DestRect
);
574 /* In GM_COMPATIBLE, don't include bottom and right edges */
575 if (pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
581 DC_vPrepareDCsForBlit(dc
, &DestRect
, NULL
, NULL
);
583 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
584 DC_vUpdateFillBrush(dc
);
586 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
587 DC_vUpdateLineBrush(dc
);
589 pbrFill
= dc
->dclevel
.pbrFill
;
590 pbrLine
= dc
->dclevel
.pbrLine
;
597 psurf
= dc
->dclevel
.pSurface
;
606 if (!(pbrFill
->flAttrs
& BR_IS_NULL
))
608 BrushOrigin
= *((PPOINTL
)&pbrFill
->ptOrigin
);
609 BrushOrigin
.x
+= dc
->ptlDCOrig
.x
;
610 BrushOrigin
.y
+= dc
->ptlDCOrig
.y
;
611 ret
= IntEngBitBlt(&psurf
->SurfObj
,
619 &dc
->eboFill
.BrushObject
,
621 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
625 // Draw the rectangle with the current pen
627 ret
= TRUE
; // Change default to success
629 if (!(pbrLine
->flAttrs
& BR_IS_NULL
))
631 Mix
= ROP2_TO_MIX(pdcattr
->jROP2
);
632 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
634 &dc
->eboLine
.BrushObject
,
635 DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.top
,
636 &DestRect
, // Bounding rectangle
639 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
641 &dc
->eboLine
.BrushObject
,
642 DestRect
.right
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
,
643 &DestRect
, // Bounding rectangle
646 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
648 &dc
->eboLine
.BrushObject
,
649 DestRect
.right
, DestRect
.bottom
, DestRect
.left
, DestRect
.bottom
,
650 &DestRect
, // Bounding rectangle
653 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
655 &dc
->eboLine
.BrushObject
,
656 DestRect
.left
, DestRect
.bottom
, DestRect
.left
, DestRect
.top
,
657 &DestRect
, // Bounding rectangle
662 DC_vFinishBlit(dc
, NULL
);
664 /* Move current position in DC?
665 MSDN: The current position is neither used nor updated by Rectangle. */
672 NtGdiRectangle(HDC hDC
,
679 BOOL ret
; // Default to failure
684 EngSetLastError(ERROR_INVALID_HANDLE
);
688 /* Do we rotate or shear? */
689 if (!(dc
->pdcattr
->mxWorldToDevice
.flAccel
& XFORM_SCALE
))
691 POINTL DestCoords
[4];
692 ULONG PolyCounts
= 4;
694 DestCoords
[0].x
= DestCoords
[3].x
= LeftRect
;
695 DestCoords
[0].y
= DestCoords
[1].y
= TopRect
;
696 DestCoords
[1].x
= DestCoords
[2].x
= RightRect
;
697 DestCoords
[2].y
= DestCoords
[3].y
= BottomRect
;
698 // Use IntGdiPolyPolygon so to support PATH.
699 ret
= IntGdiPolyPolygon(dc
, DestCoords
, &PolyCounts
, 1);
703 ret
= IntRectangle(dc
, LeftRect
, TopRect
, RightRect
, BottomRect
);
724 PBRUSH pbrLine
, pbrFill
;
726 LONG PenWidth
, PenOrigWidth
;
727 BOOL ret
= TRUE
; // Default to success
730 ASSERT ( dc
); // Caller's responsibility to set this up
732 if ( PATH_IsPathOpen(dc
->dclevel
) )
733 return PATH_RoundRect ( dc
, Left
, Top
, Right
, Bottom
,
734 xCurveDiameter
, yCurveDiameter
);
736 if ((Left
== Right
) || (Top
== Bottom
)) return TRUE
;
738 xCurveDiameter
= max(abs( xCurveDiameter
), 1);
739 yCurveDiameter
= max(abs( yCurveDiameter
), 1);
743 INT tmp
= Right
; Right
= Left
; Left
= tmp
;
747 INT tmp
= Bottom
; Bottom
= Top
; Top
= tmp
;
750 pdcattr
= dc
->pdcattr
;
752 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
753 DC_vUpdateFillBrush(dc
);
755 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
756 DC_vUpdateLineBrush(dc
);
758 pbrLine
= PEN_ShareLockPen(pdcattr
->hpen
);
761 /* Nothing to do, as we don't have a bitmap */
762 EngSetLastError(ERROR_INTERNAL_ERROR
);
766 PenOrigWidth
= PenWidth
= pbrLine
->lWidth
;
767 if (pbrLine
->ulPenStyle
== PS_NULL
) PenWidth
= 0;
769 if (pbrLine
->ulPenStyle
== PS_INSIDEFRAME
)
771 if (2*PenWidth
> (Right
- Left
)) PenWidth
= (Right
-Left
+ 1)/2;
772 if (2*PenWidth
> (Bottom
- Top
)) PenWidth
= (Bottom
-Top
+ 1)/2;
773 Left
+= PenWidth
/ 2;
774 Right
-= (PenWidth
- 1) / 2;
776 Bottom
-= (PenWidth
- 1) / 2;
779 if (!PenWidth
) PenWidth
= 1;
780 pbrLine
->lWidth
= PenWidth
;
782 RectBounds
.left
= Left
;
783 RectBounds
.top
= Top
;
784 RectBounds
.right
= Right
;
785 RectBounds
.bottom
= Bottom
;
787 IntLPtoDP(dc
, (LPPOINT
)&RectBounds
, 2);
789 RectBounds
.left
+= dc
->ptlDCOrig
.x
;
790 RectBounds
.top
+= dc
->ptlDCOrig
.y
;
791 RectBounds
.right
+= dc
->ptlDCOrig
.x
;
792 RectBounds
.bottom
+= dc
->ptlDCOrig
.y
;
794 pbrFill
= BRUSH_ShareLockBrush(pdcattr
->hbrush
);
797 DPRINT1("FillRound Fail\n");
798 EngSetLastError(ERROR_INTERNAL_ERROR
);
804 DC_vPrepareDCsForBlit(dc
, &RectBounds
, NULL
, NULL
);
806 RtlCopyMemory(&brushTemp
, pbrFill
, sizeof(brushTemp
));
807 brushTemp
.ptOrigin
.x
+= RectBounds
.left
- Left
;
808 brushTemp
.ptOrigin
.y
+= RectBounds
.top
- Top
;
809 ret
= IntFillRoundRect( dc
,
817 BRUSH_ShareUnlockBrush(pbrFill
);
821 ret
= IntDrawRoundRect( dc
,
831 DC_vFinishBlit(dc
, NULL
);
835 pbrLine
->lWidth
= PenOrigWidth
;
836 PEN_ShareUnlockPen(pbrLine
);
851 DC
*dc
= DC_LockDc(hDC
);
852 BOOL ret
= FALSE
; /* Default to failure */
854 DPRINT("NtGdiRoundRect(0x%p,%i,%i,%i,%i,%i,%i)\n",hDC
,LeftRect
,TopRect
,RightRect
,BottomRect
,Width
,Height
);
857 DPRINT1("NtGdiRoundRect() - hDC is invalid\n");
858 EngSetLastError(ERROR_INVALID_HANDLE
);
862 ret
= IntRoundRect ( dc
, LeftRect
, TopRect
, RightRect
, BottomRect
, Width
, Height
);
887 /* Check parameters */
888 if (ulMode
& GRADIENT_FILL_TRIANGLE
)
890 PGRADIENT_TRIANGLE pTriangle
= (PGRADIENT_TRIANGLE
)pMesh
;
892 for (i
= 0; i
< nMesh
; i
++, pTriangle
++)
894 if (pTriangle
->Vertex1
>= nVertex
||
895 pTriangle
->Vertex2
>= nVertex
||
896 pTriangle
->Vertex3
>= nVertex
)
898 EngSetLastError(ERROR_INVALID_PARAMETER
);
905 PGRADIENT_RECT pRect
= (PGRADIENT_RECT
)pMesh
;
906 for (i
= 0; i
< nMesh
; i
++, pRect
++)
908 if (pRect
->UpperLeft
>= nVertex
|| pRect
->LowerRight
>= nVertex
)
910 EngSetLastError(ERROR_INVALID_PARAMETER
);
916 /* Lock the output DC */
917 pdc
= DC_LockDc(hdc
);
920 EngSetLastError(ERROR_INVALID_HANDLE
);
924 if (!pdc
->dclevel
.pSurface
)
926 /* Memory DC with no surface selected */
928 return TRUE
; // CHECKME
931 /* Calculate extent */
932 rclExtent
.left
= rclExtent
.right
= pVertex
->x
;
933 rclExtent
.top
= rclExtent
.bottom
= pVertex
->y
;
934 for (i
= 0; i
< nVertex
; i
++)
936 rclExtent
.left
= min(rclExtent
.left
, (pVertex
+ i
)->x
);
937 rclExtent
.right
= max(rclExtent
.right
, (pVertex
+ i
)->x
);
938 rclExtent
.top
= min(rclExtent
.top
, (pVertex
+ i
)->y
);
939 rclExtent
.bottom
= max(rclExtent
.bottom
, (pVertex
+ i
)->y
);
941 IntLPtoDP(pdc
, (LPPOINT
)&rclExtent
, 2);
943 rclExtent
.left
+= pdc
->ptlDCOrig
.x
;
944 rclExtent
.right
+= pdc
->ptlDCOrig
.x
;
945 rclExtent
.top
+= pdc
->ptlDCOrig
.y
;
946 rclExtent
.bottom
+= pdc
->ptlDCOrig
.y
;
948 ptlDitherOrg
.x
= ptlDitherOrg
.y
= 0;
949 IntLPtoDP(pdc
, (LPPOINT
)&ptlDitherOrg
, 1);
951 ptlDitherOrg
.x
+= pdc
->ptlDCOrig
.x
;
952 ptlDitherOrg
.y
+= pdc
->ptlDCOrig
.y
;
954 if (pdc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
956 IntUpdateBoundsRect(pdc
, &rclExtent
);
959 DC_vPrepareDCsForBlit(pdc
, &rclExtent
, NULL
, NULL
);
961 psurf
= pdc
->dclevel
.pSurface
;
963 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
965 bRet
= IntEngGradientFill(&psurf
->SurfObj
,
976 EXLATEOBJ_vCleanup(&exlo
);
977 DC_vFinishBlit(pdc
, NULL
);
994 PTRIVERTEX SafeVertex
;
996 ULONG cbVertex
, cbMesh
;
998 /* Validate parameters */
999 if (!pVertex
|| !nVertex
|| !pMesh
|| !nMesh
)
1001 EngSetLastError(ERROR_INVALID_PARAMETER
);
1007 case GRADIENT_FILL_RECT_H
:
1008 case GRADIENT_FILL_RECT_V
:
1009 cbMesh
= nMesh
* sizeof(GRADIENT_RECT
);
1011 case GRADIENT_FILL_TRIANGLE
:
1012 cbMesh
= nMesh
* sizeof(GRADIENT_TRIANGLE
);
1015 EngSetLastError(ERROR_INVALID_PARAMETER
);
1019 cbVertex
= nVertex
* sizeof(TRIVERTEX
) ;
1020 if(cbVertex
+ cbMesh
<= cbVertex
)
1026 /* Allocate a kernel mode buffer */
1027 SafeVertex
= ExAllocatePoolWithTag(PagedPool
, cbVertex
+ cbMesh
, TAG_SHAPE
);
1030 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1034 SafeMesh
= (PVOID
)((ULONG_PTR
)SafeVertex
+ cbVertex
);
1036 /* Copy the parameters to kernel mode */
1039 ProbeForRead(pVertex
, cbVertex
, 1);
1040 ProbeForRead(pMesh
, cbMesh
, 1);
1041 RtlCopyMemory(SafeVertex
, pVertex
, cbVertex
);
1042 RtlCopyMemory(SafeMesh
, pMesh
, cbMesh
);
1044 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1046 ExFreePoolWithTag(SafeVertex
, TAG_SHAPE
);
1047 SetLastNtError(_SEH2_GetExceptionCode());
1048 _SEH2_YIELD(return FALSE
;)
1052 /* Call the internal function */
1053 bRet
= GreGradientFill(hdc
, SafeVertex
, nVertex
, SafeMesh
, nMesh
, ulMode
);
1055 /* Cleanup and return result */
1056 ExFreePoolWithTag(SafeVertex
, TAG_SHAPE
);
1079 dc
= DC_LockDc(hDC
);
1082 EngSetLastError(ERROR_INVALID_HANDLE
);
1086 if (!dc
->dclevel
.pSurface
)
1093 pdcattr
= dc
->pdcattr
;
1098 IntLPtoDP(dc
, (LPPOINT
)&Pt
, 1);
1100 DC_vPrepareDCsForBlit(dc
, &DestRect
, NULL
, NULL
);
1102 /// FIXME: what about prgnVIS? And what about REAL clipping?
1103 psurf
= dc
->dclevel
.pSurface
;
1106 Ret
= REGION_PtInRegion(dc
->prgnRao
, Pt
.x
, Pt
.y
);
1108 REGION_GetRgnBox(dc
->prgnRao
, (LPRECT
)&DestRect
);
1111 DC_vFinishBlit(dc
, NULL
);
1117 RECTL_vSetRect(&DestRect
, 0, 0, psurf
->SurfObj
.sizlBitmap
.cx
, psurf
->SurfObj
.sizlBitmap
.cy
);
1120 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
1122 IntUpdateBoundsRect(dc
, &DestRect
);
1125 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurf
->ppal
, 0, 0xffffff, 0);
1127 /* Only solid fills supported for now
1128 * How to support pattern brushes and non standard surfaces (not offering dib functions):
1129 * Version a (most likely slow): call DrvPatBlt for every pixel
1130 * Version b: create a flood mask and let MaskBlt blit a masked brush */
1131 ConvColor
= XLATEOBJ_iXlate(&exlo
.xlo
, Color
);
1132 Ret
= DIB_XXBPP_FloodFillSolid(&psurf
->SurfObj
, &dc
->eboFill
.BrushObject
, &DestRect
, &Pt
, ConvColor
, FillType
);
1134 DC_vFinishBlit(dc
, NULL
);
1136 EXLATEOBJ_vCleanup(&exlo
);