[Breaking change]: Graphics.GetContextInfo() is obsolete and marked as Windows only. #26785
Closed
1 of 2 tasks
Labels
breaking-change
Indicates a .NET Core breaking change
🏁 Release: .NET 6
Issues and PRs for the .NET 6 release
source incompatible
Source code may encounter a breaking change in behavior when targeting the new version.
Description
Graphics.GetContextInfo()
is a very costly API, so instead we added 2GetContextInfo()
overrides:https://docs.microsoft.com/dotnet/api/system.drawing.graphics.getcontextinfo?view=dotnet-plat-ext-6.0#System_Drawing_Graphics_GetContextInfo_System_Drawing_PointF__
https://docs.microsoft.com/dotnet/api/system.drawing.graphics.getcontextinfo?view=dotnet-plat-ext-6.0#System_Drawing_Graphics_GetContextInfo_System_Drawing_PointF__System_Drawing_Region__
These new overrides calculate just the information needed based on what was requested by the caller depending on the override used, making it lower in allocations and time. Also, instead of returning an object (that represents an array of object containing the data) we are returning the structs needed to represent this data, making it easier for the consumer to access that data.
Version
6.0.0-preview4
Version
Other (please put exact version in description textbox)
Previous behavior
No warnings when compiling.
New behavior
When compiling on Windows:
When compiling on non-Windows:
Type of breaking change
Reason for change
Graphics.GetContextInfo
exists to allow WinForms to apply cumulative Graphics transform translation and clipping to the underlying HDC so that rendering via GDI has similar output. This method currently returns anobject
array of[ Region, Matrix ]
. (Note that theMatrix
is the currentTransform
with only the cumulative offset applied.)This API is called many times during rendering of WinForms applications. Avoiding the array allocation would make a significant difference in rendering allocations. A much greater allocation reduction would be obtained if
Graphics
tracked if the.Clip
and.Transform
setters are ever accessed to allow an early out in the method logic.WinForms also don't always need both values. System.Drawing can't calculate the clipping region without the offset, but it can calculate the offset without the
Region
. Making theRegion
optional will save significant overhead.Recommended action
Use the overload that is most appropriate for the scenario from the new overloads replacing the obsolete API.
Feature area
Extensions
Affected APIs
The text was updated successfully, but these errors were encountered: