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
;
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
->lWidth
;
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
->lWidth
= 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
->lWidth
= 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
)
461 INT iMode
= (INT
)(UINT_PTR
)hDC
;
464 hrgn
= GreCreatePolyPolygonRgn(SafePoints
, SafeCounts
, Count
, iMode
);
466 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
467 return (ULONG_PTR
)hrgn
;
473 EngSetLastError(ERROR_INVALID_HANDLE
);
474 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
478 if (dc
->dctype
== DC_TYPE_INFO
)
481 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
482 /* Yes, Windows really returns TRUE in this case */
486 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
488 if (dc
->pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
489 DC_vUpdateFillBrush(dc
);
491 if (dc
->pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
492 DC_vUpdateLineBrush(dc
);
494 /* Perform the actual work */
498 Ret
= IntGdiPolyPolygon(dc
, SafePoints
, SafeCounts
, Count
);
500 case GdiPolyPolyLine
:
501 Ret
= IntGdiPolyPolyline(dc
, SafePoints
, SafeCounts
, Count
);
504 Ret
= IntGdiPolyBezier(dc
, SafePoints
, *SafeCounts
);
507 Ret
= IntGdiPolylineTo(dc
, SafePoints
, *SafeCounts
);
509 case GdiPolyBezierTo
:
510 Ret
= IntGdiPolyBezierTo(dc
, SafePoints
, *SafeCounts
);
513 EngSetLastError(ERROR_INVALID_PARAMETER
);
517 /* Cleanup and return */
518 DC_vFinishBlit(dc
, NULL
);
520 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
522 return (ULONG_PTR
)Ret
;
534 SURFACE
*psurf
= NULL
;
535 PBRUSH pbrLine
, pbrFill
;
536 BOOL ret
= FALSE
; // Default to failure
542 ASSERT ( dc
); // Caller's responsibility to set this up
544 pdcattr
= dc
->pdcattr
;
546 // Rectangle Path only.
547 if ( PATH_IsPathOpen(dc
->dclevel
) )
549 return PATH_Rectangle ( dc
, LeftRect
, TopRect
, RightRect
, BottomRect
);
552 /* Make sure rectangle is not inverted */
553 DestRect
.left
= min(LeftRect
, RightRect
);
554 DestRect
.right
= max(LeftRect
, RightRect
);
555 DestRect
.top
= min(TopRect
, BottomRect
);
556 DestRect
.bottom
= max(TopRect
, BottomRect
);
558 IntLPtoDP(dc
, (LPPOINT
)&DestRect
, 2);
560 DestRect
.left
+= dc
->ptlDCOrig
.x
;
561 DestRect
.right
+= dc
->ptlDCOrig
.x
;
562 DestRect
.top
+= dc
->ptlDCOrig
.y
;
563 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
565 /* In GM_COMPATIBLE, don't include bottom and right edges */
566 if (pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
572 DC_vPrepareDCsForBlit(dc
, &DestRect
, NULL
, NULL
);
574 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
575 DC_vUpdateFillBrush(dc
);
577 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
578 DC_vUpdateLineBrush(dc
);
580 pbrFill
= dc
->dclevel
.pbrFill
;
581 pbrLine
= dc
->dclevel
.pbrLine
;
588 psurf
= dc
->dclevel
.pSurface
;
597 if (!(pbrFill
->flAttrs
& BR_IS_NULL
))
599 BrushOrigin
= *((PPOINTL
)&pbrFill
->ptOrigin
);
600 BrushOrigin
.x
+= dc
->ptlDCOrig
.x
;
601 BrushOrigin
.y
+= dc
->ptlDCOrig
.y
;
602 ret
= IntEngBitBlt(&psurf
->SurfObj
,
610 &dc
->eboFill
.BrushObject
,
612 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
616 // Draw the rectangle with the current pen
618 ret
= TRUE
; // Change default to success
620 if (!(pbrLine
->flAttrs
& BR_IS_NULL
))
622 Mix
= ROP2_TO_MIX(pdcattr
->jROP2
);
623 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
625 &dc
->eboLine
.BrushObject
,
626 DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.top
,
627 &DestRect
, // Bounding rectangle
630 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
632 &dc
->eboLine
.BrushObject
,
633 DestRect
.right
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
,
634 &DestRect
, // Bounding rectangle
637 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
639 &dc
->eboLine
.BrushObject
,
640 DestRect
.right
, DestRect
.bottom
, DestRect
.left
, DestRect
.bottom
,
641 &DestRect
, // Bounding rectangle
644 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
646 &dc
->eboLine
.BrushObject
,
647 DestRect
.left
, DestRect
.bottom
, DestRect
.left
, DestRect
.top
,
648 &DestRect
, // Bounding rectangle
653 DC_vFinishBlit(dc
, NULL
);
655 /* Move current position in DC?
656 MSDN: The current position is neither used nor updated by Rectangle. */
663 NtGdiRectangle(HDC hDC
,
670 BOOL ret
; // Default to failure
675 EngSetLastError(ERROR_INVALID_HANDLE
);
678 if (dc
->dctype
== DC_TYPE_INFO
)
681 /* Yes, Windows really returns TRUE in this case */
685 /* Do we rotate or shear? */
686 if (!(dc
->pdcattr
->mxWorldToDevice
.flAccel
& XFORM_SCALE
))
688 POINTL DestCoords
[4];
689 ULONG PolyCounts
= 4;
691 DestCoords
[0].x
= DestCoords
[3].x
= LeftRect
;
692 DestCoords
[0].y
= DestCoords
[1].y
= TopRect
;
693 DestCoords
[1].x
= DestCoords
[2].x
= RightRect
;
694 DestCoords
[2].y
= DestCoords
[3].y
= BottomRect
;
695 // Use IntGdiPolyPolygon so to support PATH.
696 ret
= IntGdiPolyPolygon(dc
, DestCoords
, &PolyCounts
, 1);
700 ret
= IntRectangle(dc
, LeftRect
, TopRect
, RightRect
, BottomRect
);
721 PBRUSH pbrLine
, pbrFill
;
723 LONG PenWidth
, PenOrigWidth
;
724 BOOL ret
= TRUE
; // Default to success
727 ASSERT ( dc
); // Caller's responsibility to set this up
729 if ( PATH_IsPathOpen(dc
->dclevel
) )
730 return PATH_RoundRect ( dc
, Left
, Top
, Right
, Bottom
,
731 xCurveDiameter
, yCurveDiameter
);
733 if ((Left
== Right
) || (Top
== Bottom
)) return TRUE
;
735 xCurveDiameter
= max(abs( xCurveDiameter
), 1);
736 yCurveDiameter
= max(abs( yCurveDiameter
), 1);
740 INT tmp
= Right
; Right
= Left
; Left
= tmp
;
744 INT tmp
= Bottom
; Bottom
= Top
; Top
= tmp
;
747 pdcattr
= dc
->pdcattr
;
749 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
750 DC_vUpdateFillBrush(dc
);
752 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
753 DC_vUpdateLineBrush(dc
);
755 pbrLine
= PEN_ShareLockPen(pdcattr
->hpen
);
758 /* Nothing to do, as we don't have a bitmap */
759 EngSetLastError(ERROR_INTERNAL_ERROR
);
763 PenOrigWidth
= PenWidth
= pbrLine
->lWidth
;
764 if (pbrLine
->ulPenStyle
== PS_NULL
) PenWidth
= 0;
766 if (pbrLine
->ulPenStyle
== PS_INSIDEFRAME
)
768 if (2*PenWidth
> (Right
- Left
)) PenWidth
= (Right
-Left
+ 1)/2;
769 if (2*PenWidth
> (Bottom
- Top
)) PenWidth
= (Bottom
-Top
+ 1)/2;
770 Left
+= PenWidth
/ 2;
771 Right
-= (PenWidth
- 1) / 2;
773 Bottom
-= (PenWidth
- 1) / 2;
776 if (!PenWidth
) PenWidth
= 1;
777 pbrLine
->lWidth
= PenWidth
;
779 RectBounds
.left
= Left
;
780 RectBounds
.top
= Top
;
781 RectBounds
.right
= Right
;
782 RectBounds
.bottom
= Bottom
;
784 IntLPtoDP(dc
, (LPPOINT
)&RectBounds
, 2);
786 RectBounds
.left
+= dc
->ptlDCOrig
.x
;
787 RectBounds
.top
+= dc
->ptlDCOrig
.y
;
788 RectBounds
.right
+= dc
->ptlDCOrig
.x
;
789 RectBounds
.bottom
+= dc
->ptlDCOrig
.y
;
791 pbrFill
= BRUSH_ShareLockBrush(pdcattr
->hbrush
);
794 DPRINT1("FillRound Fail\n");
795 EngSetLastError(ERROR_INTERNAL_ERROR
);
801 DC_vPrepareDCsForBlit(dc
, &RectBounds
, NULL
, NULL
);
803 RtlCopyMemory(&brushTemp
, pbrFill
, sizeof(brushTemp
));
804 brushTemp
.ptOrigin
.x
+= RectBounds
.left
- Left
;
805 brushTemp
.ptOrigin
.y
+= RectBounds
.top
- Top
;
806 ret
= IntFillRoundRect( dc
,
814 BRUSH_ShareUnlockBrush(pbrFill
);
818 ret
= IntDrawRoundRect( dc
,
828 DC_vFinishBlit(dc
, NULL
);
832 pbrLine
->lWidth
= PenOrigWidth
;
833 PEN_ShareUnlockPen(pbrLine
);
848 DC
*dc
= DC_LockDc(hDC
);
849 BOOL ret
= FALSE
; /* Default to failure */
851 DPRINT("NtGdiRoundRect(0x%p,%i,%i,%i,%i,%i,%i)\n",hDC
,LeftRect
,TopRect
,RightRect
,BottomRect
,Width
,Height
);
854 DPRINT1("NtGdiRoundRect() - hDC is invalid\n");
855 EngSetLastError(ERROR_INVALID_HANDLE
);
857 else if (dc
->dctype
== DC_TYPE_INFO
)
860 /* Yes, Windows really returns TRUE in this case */
865 ret
= IntRoundRect ( dc
, LeftRect
, TopRect
, RightRect
, BottomRect
, Width
, Height
);
890 /* Check parameters */
891 if (ulMode
& GRADIENT_FILL_TRIANGLE
)
893 PGRADIENT_TRIANGLE pTriangle
= (PGRADIENT_TRIANGLE
)pMesh
;
895 for (i
= 0; i
< nMesh
; i
++, pTriangle
++)
897 if (pTriangle
->Vertex1
>= nVertex
||
898 pTriangle
->Vertex2
>= nVertex
||
899 pTriangle
->Vertex3
>= nVertex
)
901 EngSetLastError(ERROR_INVALID_PARAMETER
);
908 PGRADIENT_RECT pRect
= (PGRADIENT_RECT
)pMesh
;
909 for (i
= 0; i
< nMesh
; i
++, pRect
++)
911 if (pRect
->UpperLeft
>= nVertex
|| pRect
->LowerRight
>= nVertex
)
913 EngSetLastError(ERROR_INVALID_PARAMETER
);
919 /* Lock the output DC */
920 pdc
= DC_LockDc(hdc
);
923 EngSetLastError(ERROR_INVALID_HANDLE
);
927 if(pdc
->dctype
== DC_TYPE_INFO
)
930 /* Yes, Windows really returns TRUE in this case */
934 if (!pdc
->dclevel
.pSurface
)
936 /* Memory DC with no surface selected */
938 return TRUE
; // CHECKME
941 /* Calculate extent */
942 rclExtent
.left
= rclExtent
.right
= pVertex
->x
;
943 rclExtent
.top
= rclExtent
.bottom
= pVertex
->y
;
944 for (i
= 0; i
< nVertex
; i
++)
946 rclExtent
.left
= min(rclExtent
.left
, (pVertex
+ i
)->x
);
947 rclExtent
.right
= max(rclExtent
.right
, (pVertex
+ i
)->x
);
948 rclExtent
.top
= min(rclExtent
.top
, (pVertex
+ i
)->y
);
949 rclExtent
.bottom
= max(rclExtent
.bottom
, (pVertex
+ i
)->y
);
951 IntLPtoDP(pdc
, (LPPOINT
)&rclExtent
, 2);
953 rclExtent
.left
+= pdc
->ptlDCOrig
.x
;
954 rclExtent
.right
+= pdc
->ptlDCOrig
.x
;
955 rclExtent
.top
+= pdc
->ptlDCOrig
.y
;
956 rclExtent
.bottom
+= pdc
->ptlDCOrig
.y
;
958 ptlDitherOrg
.x
= ptlDitherOrg
.y
= 0;
959 IntLPtoDP(pdc
, (LPPOINT
)&ptlDitherOrg
, 1);
961 ptlDitherOrg
.x
+= pdc
->ptlDCOrig
.x
;
962 ptlDitherOrg
.y
+= pdc
->ptlDCOrig
.y
;
964 DC_vPrepareDCsForBlit(pdc
, &rclExtent
, NULL
, NULL
);
966 psurf
= pdc
->dclevel
.pSurface
;
968 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
970 bRet
= IntEngGradientFill(&psurf
->SurfObj
,
981 EXLATEOBJ_vCleanup(&exlo
);
982 DC_vFinishBlit(pdc
, NULL
);
999 PTRIVERTEX SafeVertex
;
1001 ULONG cbVertex
, cbMesh
;
1003 /* Validate parameters */
1004 if (!pVertex
|| !nVertex
|| !pMesh
|| !nMesh
)
1006 EngSetLastError(ERROR_INVALID_PARAMETER
);
1012 case GRADIENT_FILL_RECT_H
:
1013 case GRADIENT_FILL_RECT_V
:
1014 cbMesh
= nMesh
* sizeof(GRADIENT_RECT
);
1016 case GRADIENT_FILL_TRIANGLE
:
1017 cbMesh
= nMesh
* sizeof(GRADIENT_TRIANGLE
);
1020 EngSetLastError(ERROR_INVALID_PARAMETER
);
1024 cbVertex
= nVertex
* sizeof(TRIVERTEX
) ;
1025 if(cbVertex
+ cbMesh
<= cbVertex
)
1031 /* Allocate a kernel mode buffer */
1032 SafeVertex
= ExAllocatePoolWithTag(PagedPool
, cbVertex
+ cbMesh
, TAG_SHAPE
);
1035 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1039 SafeMesh
= (PVOID
)((ULONG_PTR
)SafeVertex
+ cbVertex
);
1041 /* Copy the parameters to kernel mode */
1044 ProbeForRead(pVertex
, cbVertex
, 1);
1045 ProbeForRead(pMesh
, cbMesh
, 1);
1046 RtlCopyMemory(SafeVertex
, pVertex
, cbVertex
);
1047 RtlCopyMemory(SafeMesh
, pMesh
, cbMesh
);
1049 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1051 ExFreePoolWithTag(SafeVertex
, TAG_SHAPE
);
1052 SetLastNtError(_SEH2_GetExceptionCode());
1053 _SEH2_YIELD(return FALSE
;)
1057 /* Call the internal function */
1058 bRet
= GreGradientFill(hdc
, SafeVertex
, nVertex
, SafeMesh
, nMesh
, ulMode
);
1060 /* Cleanup and return result */
1061 ExFreePoolWithTag(SafeVertex
, TAG_SHAPE
);
1084 dc
= DC_LockDc(hDC
);
1087 EngSetLastError(ERROR_INVALID_HANDLE
);
1090 if (dc
->dctype
== DC_TYPE_INFO
)
1093 /* Yes, Windows really returns TRUE in this case */
1097 if (!dc
->dclevel
.pSurface
)
1104 pdcattr
= dc
->pdcattr
;
1109 IntLPtoDP(dc
, (LPPOINT
)&Pt
, 1);
1111 DC_vPrepareDCsForBlit(dc
, &DestRect
, NULL
, NULL
);
1113 /// FIXME: what about prgnVIS? And what about REAL clipping?
1114 psurf
= dc
->dclevel
.pSurface
;
1117 Ret
= REGION_PtInRegion(dc
->prgnRao
, Pt
.x
, Pt
.y
);
1119 REGION_GetRgnBox(dc
->prgnRao
, (LPRECT
)&DestRect
);
1122 DC_vFinishBlit(dc
, NULL
);
1128 RECTL_vSetRect(&DestRect
, 0, 0, psurf
->SurfObj
.sizlBitmap
.cx
, psurf
->SurfObj
.sizlBitmap
.cy
);
1131 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurf
->ppal
, 0, 0xffffff, 0);
1133 /* Only solid fills supported for now
1134 * How to support pattern brushes and non standard surfaces (not offering dib functions):
1135 * Version a (most likely slow): call DrvPatBlt for every pixel
1136 * Version b: create a flood mask and let MaskBlt blit a masked brush */
1137 ConvColor
= XLATEOBJ_iXlate(&exlo
.xlo
, Color
);
1138 Ret
= DIB_XXBPP_FloodFillSolid(&psurf
->SurfObj
, &dc
->eboFill
.BrushObject
, &DestRect
, &Pt
, ConvColor
, FillType
);
1140 DC_vFinishBlit(dc
, NULL
);
1142 EXLATEOBJ_vCleanup(&exlo
);