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
;
309 ret
= IntFillEllipse( dc
,
315 BRUSH_ShareUnlockBrush(pFillBrushObj
);
319 ret
= IntDrawEllipse( dc
,
326 pbrush
->ptPenWidth
.x
= PenOrigWidth
;
327 PEN_ShareUnlockPen(pbrush
);
329 DPRINT("Ellipse Exit.\n");
335 // When the fill mode is ALTERNATE, GDI fills the area between odd-numbered and
336 // even-numbered polygon sides on each scan line. That is, GDI fills the area between the
337 // first and second side, between the third and fourth side, and so on.
339 // WINDING Selects winding mode (fills any region with a nonzero winding value).
340 // When the fill mode is WINDING, GDI fills any region that has a nonzero winding value.
341 // This value is defined as the number of times a pen used to draw the polygon would go around the region.
342 // The direction of each edge of the polygon is important.
344 extern BOOL
FillPolygon(PDC dc
,
357 NtGdiPolyPolyDraw( IN HDC hDC
,
358 IN PPOINT UnsafePoints
,
359 IN PULONG UnsafeCounts
,
367 NTSTATUS Status
= STATUS_SUCCESS
;
369 ULONG nPoints
= 0, nMaxPoints
= 0, nInvalid
= 0, i
;
371 if (!UnsafePoints
|| !UnsafeCounts
||
372 Count
== 0 || iFunc
== 0 || iFunc
> GdiPolyPolyRgn
)
374 /* Windows doesn't set last error */
380 ProbeForRead(UnsafePoints
, Count
* sizeof(POINT
), 1);
381 ProbeForRead(UnsafeCounts
, Count
* sizeof(ULONG
), 1);
383 /* Count points and validate poligons */
384 for (i
= 0; i
< Count
; i
++)
386 if (UnsafeCounts
[i
] < 2)
390 nPoints
+= UnsafeCounts
[i
];
391 nMaxPoints
= max(nMaxPoints
, UnsafeCounts
[i
]);
394 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
396 Status
= _SEH2_GetExceptionCode();
400 if (!NT_SUCCESS(Status
))
402 /* Windows doesn't set last error */
406 if (nPoints
== 0 || nPoints
< nMaxPoints
)
408 /* If all polygon counts are zero, or we have overflow,
409 return without setting a last error code. */
415 /* If at least one poly count is 0 or 1, fail */
416 EngSetLastError(ERROR_INVALID_PARAMETER
);
420 /* Allocate one buffer for both counts and points */
421 pTemp
= ExAllocatePoolWithTag(PagedPool
,
422 Count
* sizeof(ULONG
) + nPoints
* sizeof(POINT
),
426 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
431 SafePoints
= (PVOID
)(SafeCounts
+ Count
);
435 /* Pointers already probed! */
436 RtlCopyMemory(SafeCounts
, UnsafeCounts
, Count
* sizeof(ULONG
));
437 RtlCopyMemory(SafePoints
, UnsafePoints
, nPoints
* sizeof(POINT
));
439 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
441 Status
= _SEH2_GetExceptionCode();
445 if (!NT_SUCCESS(Status
))
447 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
451 /* Special handling for GdiPolyPolyRgn */
452 if (iFunc
== GdiPolyPolyRgn
)
455 hRgn
= IntCreatePolyPolygonRgn(SafePoints
, SafeCounts
, Count
, (INT_PTR
)hDC
);
456 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
457 return (ULONG_PTR
)hRgn
;
463 EngSetLastError(ERROR_INVALID_HANDLE
);
464 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
468 if (dc
->dctype
== DC_TYPE_INFO
)
471 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
472 /* Yes, Windows really returns TRUE in this case */
476 DC_vPrepareDCsForBlit(dc
, dc
->rosdc
.CombinedClip
->rclBounds
,
477 NULL
, dc
->rosdc
.CombinedClip
->rclBounds
);
479 if (dc
->pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
480 DC_vUpdateFillBrush(dc
);
482 if (dc
->pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
483 DC_vUpdateLineBrush(dc
);
485 /* Perform the actual work */
489 Ret
= IntGdiPolyPolygon(dc
, SafePoints
, SafeCounts
, Count
);
491 case GdiPolyPolyLine
:
492 Ret
= IntGdiPolyPolyline(dc
, SafePoints
, SafeCounts
, Count
);
495 Ret
= IntGdiPolyBezier(dc
, SafePoints
, *SafeCounts
);
498 Ret
= IntGdiPolylineTo(dc
, SafePoints
, *SafeCounts
);
500 case GdiPolyBezierTo
:
501 Ret
= IntGdiPolyBezierTo(dc
, SafePoints
, *SafeCounts
);
504 EngSetLastError(ERROR_INVALID_PARAMETER
);
508 /* Cleanup and return */
509 DC_vFinishBlit(dc
, NULL
);
511 ExFreePoolWithTag(pTemp
, TAG_SHAPE
);
513 return (ULONG_PTR
)Ret
;
525 SURFACE
*psurf
= NULL
;
526 PBRUSH pbrLine
, pbrFill
;
527 BOOL ret
= FALSE
; // Default to failure
533 ASSERT ( dc
); // Caller's responsibility to set this up
535 pdcattr
= dc
->pdcattr
;
537 // Rectangle Path only.
538 if ( PATH_IsPathOpen(dc
->dclevel
) )
540 return PATH_Rectangle ( dc
, LeftRect
, TopRect
, RightRect
, BottomRect
);
543 /* Make sure rectangle is not inverted */
544 DestRect
.left
= min(LeftRect
, RightRect
);
545 DestRect
.right
= max(LeftRect
, RightRect
);
546 DestRect
.top
= min(TopRect
, BottomRect
);
547 DestRect
.bottom
= max(TopRect
, BottomRect
);
549 IntLPtoDP(dc
, (LPPOINT
)&DestRect
, 2);
551 DestRect
.left
+= dc
->ptlDCOrig
.x
;
552 DestRect
.right
+= dc
->ptlDCOrig
.x
;
553 DestRect
.top
+= dc
->ptlDCOrig
.y
;
554 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
556 /* In GM_COMPATIBLE, don't include bottom and right edges */
557 if (pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
563 DC_vPrepareDCsForBlit(dc
, DestRect
, NULL
, DestRect
);
565 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
566 DC_vUpdateFillBrush(dc
);
568 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
569 DC_vUpdateLineBrush(dc
);
571 pbrFill
= dc
->dclevel
.pbrFill
;
572 pbrLine
= dc
->dclevel
.pbrLine
;
579 psurf
= dc
->dclevel
.pSurface
;
588 if (!(pbrFill
->flAttrs
& BR_IS_NULL
))
590 BrushOrigin
= *((PPOINTL
)&pbrFill
->ptOrigin
);
591 BrushOrigin
.x
+= dc
->ptlDCOrig
.x
;
592 BrushOrigin
.y
+= dc
->ptlDCOrig
.y
;
593 ret
= IntEngBitBlt(&psurf
->SurfObj
,
596 dc
->rosdc
.CombinedClip
,
601 &dc
->eboFill
.BrushObject
,
603 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
607 // Draw the rectangle with the current pen
609 ret
= TRUE
; // Change default to success
611 if (!(pbrLine
->flAttrs
& BR_IS_NULL
))
613 Mix
= ROP2_TO_MIX(pdcattr
->jROP2
);
614 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
615 dc
->rosdc
.CombinedClip
,
616 &dc
->eboLine
.BrushObject
,
617 DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.top
,
618 &DestRect
, // Bounding rectangle
621 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
622 dc
->rosdc
.CombinedClip
,
623 &dc
->eboLine
.BrushObject
,
624 DestRect
.right
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
,
625 &DestRect
, // Bounding rectangle
628 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
629 dc
->rosdc
.CombinedClip
,
630 &dc
->eboLine
.BrushObject
,
631 DestRect
.right
, DestRect
.bottom
, DestRect
.left
, DestRect
.bottom
,
632 &DestRect
, // Bounding rectangle
635 ret
= ret
&& IntEngLineTo(&psurf
->SurfObj
,
636 dc
->rosdc
.CombinedClip
,
637 &dc
->eboLine
.BrushObject
,
638 DestRect
.left
, DestRect
.bottom
, DestRect
.left
, DestRect
.top
,
639 &DestRect
, // Bounding rectangle
644 DC_vFinishBlit(dc
, NULL
);
646 /* Move current position in DC?
647 MSDN: The current position is neither used nor updated by Rectangle. */
654 NtGdiRectangle(HDC hDC
,
661 BOOL ret
; // Default to failure
666 EngSetLastError(ERROR_INVALID_HANDLE
);
669 if (dc
->dctype
== DC_TYPE_INFO
)
672 /* Yes, Windows really returns TRUE in this case */
676 /* Do we rotate or shear? */
677 if (!(dc
->pdcattr
->mxWorldToDevice
.flAccel
& XFORM_SCALE
))
679 POINTL DestCoords
[4];
680 ULONG PolyCounts
= 4;
682 DestCoords
[0].x
= DestCoords
[3].x
= LeftRect
;
683 DestCoords
[0].y
= DestCoords
[1].y
= TopRect
;
684 DestCoords
[1].x
= DestCoords
[2].x
= RightRect
;
685 DestCoords
[2].y
= DestCoords
[3].y
= BottomRect
;
686 // Use IntGdiPolyPolygon so to support PATH.
687 ret
= IntGdiPolyPolygon(dc
, DestCoords
, &PolyCounts
, 1);
691 ret
= IntRectangle(dc
, LeftRect
, TopRect
, RightRect
, BottomRect
);
712 PBRUSH pbrLine
, pbrFill
;
714 LONG PenWidth
, PenOrigWidth
;
715 BOOL ret
= TRUE
; // Default to success
718 ASSERT ( dc
); // Caller's responsibility to set this up
720 if ( PATH_IsPathOpen(dc
->dclevel
) )
721 return PATH_RoundRect ( dc
, Left
, Top
, Right
, Bottom
,
722 xCurveDiameter
, yCurveDiameter
);
724 if ((Left
== Right
) || (Top
== Bottom
)) return TRUE
;
726 xCurveDiameter
= max(abs( xCurveDiameter
), 1);
727 yCurveDiameter
= max(abs( yCurveDiameter
), 1);
731 INT tmp
= Right
; Right
= Left
; Left
= tmp
;
735 INT tmp
= Bottom
; Bottom
= Top
; Top
= tmp
;
738 pdcattr
= dc
->pdcattr
;
740 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
741 DC_vUpdateFillBrush(dc
);
743 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
744 DC_vUpdateLineBrush(dc
);
746 pbrLine
= PEN_ShareLockPen(pdcattr
->hpen
);
749 /* Nothing to do, as we don't have a bitmap */
750 EngSetLastError(ERROR_INTERNAL_ERROR
);
754 PenOrigWidth
= PenWidth
= pbrLine
->ptPenWidth
.x
;
755 if (pbrLine
->ulPenStyle
== PS_NULL
) PenWidth
= 0;
757 if (pbrLine
->ulPenStyle
== PS_INSIDEFRAME
)
759 if (2*PenWidth
> (Right
- Left
)) PenWidth
= (Right
-Left
+ 1)/2;
760 if (2*PenWidth
> (Bottom
- Top
)) PenWidth
= (Bottom
-Top
+ 1)/2;
761 Left
+= PenWidth
/ 2;
762 Right
-= (PenWidth
- 1) / 2;
764 Bottom
-= (PenWidth
- 1) / 2;
767 if (!PenWidth
) PenWidth
= 1;
768 pbrLine
->ptPenWidth
.x
= PenWidth
;
770 RectBounds
.left
= Left
;
771 RectBounds
.top
= Top
;
772 RectBounds
.right
= Right
;
773 RectBounds
.bottom
= Bottom
;
775 IntLPtoDP(dc
, (LPPOINT
)&RectBounds
, 2);
777 RectBounds
.left
+= dc
->ptlDCOrig
.x
;
778 RectBounds
.top
+= dc
->ptlDCOrig
.y
;
779 RectBounds
.right
+= dc
->ptlDCOrig
.x
;
780 RectBounds
.bottom
+= dc
->ptlDCOrig
.y
;
782 pbrFill
= BRUSH_ShareLockBrush(pdcattr
->hbrush
);
785 DPRINT1("FillRound Fail\n");
786 EngSetLastError(ERROR_INTERNAL_ERROR
);
791 RtlCopyMemory(&brushTemp
, pbrFill
, sizeof(brushTemp
));
792 brushTemp
.ptOrigin
.x
+= RectBounds
.left
- Left
;
793 brushTemp
.ptOrigin
.y
+= RectBounds
.top
- Top
;
794 ret
= IntFillRoundRect( dc
,
802 BRUSH_ShareUnlockBrush(pbrFill
);
806 ret
= IntDrawRoundRect( dc
,
815 pbrLine
->ptPenWidth
.x
= PenOrigWidth
;
816 PEN_ShareUnlockPen(pbrLine
);
831 DC
*dc
= DC_LockDc(hDC
);
832 BOOL ret
= FALSE
; /* Default to failure */
834 DPRINT("NtGdiRoundRect(0x%p,%i,%i,%i,%i,%i,%i)\n",hDC
,LeftRect
,TopRect
,RightRect
,BottomRect
,Width
,Height
);
837 DPRINT1("NtGdiRoundRect() - hDC is invalid\n");
838 EngSetLastError(ERROR_INVALID_HANDLE
);
840 else if (dc
->dctype
== DC_TYPE_INFO
)
843 /* Yes, Windows really returns TRUE in this case */
848 ret
= IntRoundRect ( dc
, LeftRect
, TopRect
, RightRect
, BottomRect
, Width
, Height
);
873 /* Check parameters */
874 if (ulMode
& GRADIENT_FILL_TRIANGLE
)
876 PGRADIENT_TRIANGLE pTriangle
= (PGRADIENT_TRIANGLE
)pMesh
;
878 for (i
= 0; i
< nMesh
; i
++, pTriangle
++)
880 if (pTriangle
->Vertex1
>= nVertex
||
881 pTriangle
->Vertex2
>= nVertex
||
882 pTriangle
->Vertex3
>= nVertex
)
884 EngSetLastError(ERROR_INVALID_PARAMETER
);
891 PGRADIENT_RECT pRect
= (PGRADIENT_RECT
)pMesh
;
892 for (i
= 0; i
< nMesh
; i
++, pRect
++)
894 if (pRect
->UpperLeft
>= nVertex
|| pRect
->LowerRight
>= nVertex
)
896 EngSetLastError(ERROR_INVALID_PARAMETER
);
902 /* Lock the output DC */
903 pdc
= DC_LockDc(hdc
);
906 EngSetLastError(ERROR_INVALID_HANDLE
);
910 if(pdc
->dctype
== DC_TYPE_INFO
)
913 /* Yes, Windows really returns TRUE in this case */
917 psurf
= pdc
->dclevel
.pSurface
;
920 /* Memory DC with no surface selected */
922 return TRUE
; // CHECKME
925 /* Calculate extent */
926 rclExtent
.left
= rclExtent
.right
= pVertex
->x
;
927 rclExtent
.top
= rclExtent
.bottom
= pVertex
->y
;
928 for (i
= 0; i
< nVertex
; i
++)
930 rclExtent
.left
= min(rclExtent
.left
, (pVertex
+ i
)->x
);
931 rclExtent
.right
= max(rclExtent
.right
, (pVertex
+ i
)->x
);
932 rclExtent
.top
= min(rclExtent
.top
, (pVertex
+ i
)->y
);
933 rclExtent
.bottom
= max(rclExtent
.bottom
, (pVertex
+ i
)->y
);
935 IntLPtoDP(pdc
, (LPPOINT
)&rclExtent
, 2);
937 rclExtent
.left
+= pdc
->ptlDCOrig
.x
;
938 rclExtent
.right
+= pdc
->ptlDCOrig
.x
;
939 rclExtent
.top
+= pdc
->ptlDCOrig
.y
;
940 rclExtent
.bottom
+= pdc
->ptlDCOrig
.y
;
942 ptlDitherOrg
.x
= ptlDitherOrg
.y
= 0;
943 IntLPtoDP(pdc
, (LPPOINT
)&ptlDitherOrg
, 1);
945 ptlDitherOrg
.x
+= pdc
->ptlDCOrig
.x
;
946 ptlDitherOrg
.y
+= pdc
->ptlDCOrig
.y
;
948 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
950 ASSERT(pdc
->rosdc
.CombinedClip
);
952 DC_vPrepareDCsForBlit(pdc
, rclExtent
, NULL
, rclExtent
);
954 bRet
= IntEngGradientFill(&psurf
->SurfObj
,
955 pdc
->rosdc
.CombinedClip
,
965 EXLATEOBJ_vCleanup(&exlo
);
966 DC_vFinishBlit(pdc
, NULL
);
983 PTRIVERTEX SafeVertex
;
985 ULONG cbVertex
, cbMesh
;
987 /* Validate parameters */
988 if (!pVertex
|| !nVertex
|| !pMesh
|| !nMesh
)
990 EngSetLastError(ERROR_INVALID_PARAMETER
);
996 case GRADIENT_FILL_RECT_H
:
997 case GRADIENT_FILL_RECT_V
:
998 cbMesh
= nMesh
* sizeof(GRADIENT_RECT
);
1000 case GRADIENT_FILL_TRIANGLE
:
1001 cbMesh
= nMesh
* sizeof(GRADIENT_TRIANGLE
);
1004 EngSetLastError(ERROR_INVALID_PARAMETER
);
1008 cbVertex
= nVertex
* sizeof(TRIVERTEX
) ;
1009 if(cbVertex
+ cbMesh
<= cbVertex
)
1015 /* Allocate a kernel mode buffer */
1016 SafeVertex
= ExAllocatePoolWithTag(PagedPool
, cbVertex
+ cbMesh
, TAG_SHAPE
);
1019 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1023 SafeMesh
= (PVOID
)((ULONG_PTR
)SafeVertex
+ cbVertex
);
1025 /* Copy the parameters to kernel mode */
1028 ProbeForRead(pVertex
, cbVertex
, 1);
1029 ProbeForRead(pMesh
, cbMesh
, 1);
1030 RtlCopyMemory(SafeVertex
, pVertex
, cbVertex
);
1031 RtlCopyMemory(SafeMesh
, pMesh
, cbMesh
);
1033 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1035 ExFreePoolWithTag(SafeVertex
, TAG_SHAPE
);
1036 SetLastNtError(_SEH2_GetExceptionCode());
1037 _SEH2_YIELD(return FALSE
;)
1041 /* Call the internal function */
1042 bRet
= GreGradientFill(hdc
, SafeVertex
, nVertex
, SafeMesh
, nMesh
, ulMode
);
1044 /* Cleanup and return result */
1045 ExFreePoolWithTag(SafeVertex
, TAG_SHAPE
);
1059 SURFACE
*psurf
= NULL
;
1066 dc
= DC_LockDc(hDC
);
1069 EngSetLastError(ERROR_INVALID_HANDLE
);
1072 if (dc
->dctype
== DC_TYPE_INFO
)
1075 /* Yes, Windows really returns TRUE in this case */
1079 pdcattr
= dc
->pdcattr
;
1081 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
1082 DC_vUpdateFillBrush(dc
);
1084 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
1085 DC_vUpdateLineBrush(dc
);
1089 IntLPtoDP(dc
, (LPPOINT
)&Pt
, 1);
1091 Ret
= NtGdiPtInRegion(dc
->rosdc
.hGCClipRgn
, Pt
.x
, Pt
.y
);
1093 IntGdiGetRgnBox(dc
->rosdc
.hGCClipRgn
,(LPRECT
)&DestRect
);
1097 psurf
= dc
->dclevel
.pSurface
;
1104 EXLATEOBJ_vInitialize(&exlo
, &gpalRGB
, psurf
->ppal
, 0, 0xffffff, 0);
1106 /* Only solid fills supported for now
1107 * How to support pattern brushes and non standard surfaces (not offering dib functions):
1108 * Version a (most likely slow): call DrvPatBlt for every pixel
1109 * Version b: create a flood mask and let MaskBlt blit a masked brush */
1110 ConvColor
= XLATEOBJ_iXlate(&exlo
.xlo
, Color
);
1111 Ret
= DIB_XXBPP_FloodFillSolid(&psurf
->SurfObj
, &dc
->eboFill
.BrushObject
, &DestRect
, &Pt
, ConvColor
, FillType
);
1113 EXLATEOBJ_vCleanup(&exlo
);