Skip to content

Remove all ElementUtil allocations and stop boxing in DispatcherOperation #10903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 54 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f65b08d
commit work
h3xds1nz May 20, 2025
b5e9f88
some fixes
h3xds1nz May 20, 2025
51e0e86
keep boxing prop value due to public interface
h3xds1nz May 21, 2025
9e8dacc
fix
h3xds1nz May 22, 2025
b6f4102
Polish it a bit, fix exception text
h3xds1nz May 29, 2025
2f3391d
Convert ExceptionWrapper as static class
h3xds1nz May 29, 2025
ef2247e
Remove ExceptionFilterHelper dead code
h3xds1nz May 29, 2025
6b13583
Provide specific implementation for ExceptionWrapper, remove casts
h3xds1nz May 29, 2025
85bdcbd
Wrap ExceptionWrapper inside Dispatcher
h3xds1nz May 29, 2025
d9e6373
Move ExceptionWrapper into System.Windows.Threading
h3xds1nz May 29, 2025
454db37
Move stuff around
h3xds1nz May 30, 2025
e25f0d2
Remove unused wrapper
h3xds1nz May 30, 2025
f078b64
Remove using
h3xds1nz May 30, 2025
0db154d
since I've done half the job there
h3xds1nz May 30, 2025
84aedcb
Avoid casts where we know the type
h3xds1nz May 30, 2025
f090abc
Avoid apicompat suppressions by limiting "visibility"
h3xds1nz May 30, 2025
7a029c4
Change access modifiers
h3xds1nz May 30, 2025
b66c414
Interpolation
h3xds1nz May 30, 2025
41f9af1
Fix DWriteForwarder/System.Printing dependencies in the build process
h3xds1nz May 30, 2025
9d09b65
Add a few more tests
h3xds1nz May 30, 2025
c52cf1a
Fix wrappers
h3xds1nz May 30, 2025
74a2025
ScrollProviderWrapper / ExpandCollapseProviderWrapper
h3xds1nz May 30, 2025
3abb086
RangeValueProviderWrapper
h3xds1nz May 30, 2025
473af59
GridItemProviderWrapper
h3xds1nz May 30, 2025
da104f3
Few more tests
h3xds1nz May 31, 2025
b1d7046
TextRangeProviderWrapper
h3xds1nz May 31, 2025
7ce8720
TableItemProviderWrapper
h3xds1nz May 31, 2025
8bfc0a1
SelectionProviderWrapper
h3xds1nz May 31, 2025
c668e4c
WindowProviderWrapper
h3xds1nz May 31, 2025
118ec86
ValueProviderWrapper
h3xds1nz May 31, 2025
c720586
TableProviderWrapper
h3xds1nz May 31, 2025
057b3df
SelectionItemProviderWrapper
h3xds1nz May 31, 2025
f1719ad
TransformProviderWrapper
h3xds1nz May 31, 2025
9b634d9
Finish rest of the wrapper-returns
h3xds1nz May 31, 2025
1c27ef6
Remove legacy Invoke interface in favour of new methods, add void inv…
h3xds1nz May 31, 2025
1e43057
Fix docs for ActionInfo
h3xds1nz May 31, 2025
0b64463
Add more basic ElementUtil/Dispatcher consistency tests
h3xds1nz May 31, 2025
029c0dc
Enable nullability, seal the wrappers, make fields readonly, cleanup …
h3xds1nz May 31, 2025
735a2ea
Enable nullability, seal the wrappers, make fields readonly, cleanup …
h3xds1nz May 31, 2025
1e0e0b8
Finish nullability on ITextRangeProvider
h3xds1nz May 31, 2025
cf6d0ef
Formatting changes ONLY - region cleanup, whitespaces
h3xds1nz May 31, 2025
c59ba71
Formatting changes ONLY - Flatten all namespaces on wrappers
h3xds1nz May 31, 2025
6fc0efe
Formatting changes ONLY - Add summary comments for proxies
h3xds1nz May 31, 2025
174bb73
Re-order new files in csproj
h3xds1nz May 31, 2025
e48620f
Use internals over public to avoid confusion
h3xds1nz Jun 1, 2025
59ed9ae
Add ExpandCollapse/RangeValue/ToggleProvider unit tests
h3xds1nz Jun 1, 2025
f0c0cc8
Add ValueProviderWrapper tests
h3xds1nz Jun 1, 2025
92151a5
Fix nullability on FindItemByProperty
h3xds1nz Jun 1, 2025
5db90be
Fix IGridProvider nullability
h3xds1nz Jun 1, 2025
efcdfd3
Enable nullability on IMultipleViewProvider
h3xds1nz Jun 1, 2025
e24e4a5
Add TransformProviderWrapper unit tests as well
h3xds1nz Jun 1, 2025
d380b14
Final touches
h3xds1nz Jun 2, 2025
140210e
Fix ref to include abstract keyword, revert callvirt
h3xds1nz Jun 2, 2025
3935c32
Fix baseline (again)
h3xds1nz Jun 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Microsoft.Dotnet.Wpf.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WindowsBase", "src\Microsoft.DotNet.Wpf\src\WindowsBase\WindowsBase.csproj", "{FA69991B-9696-42D0-A5C7-F5E73F0DEE9E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectWriteForwarder", "src\Microsoft.DotNet.Wpf\src\DirectWriteForwarder\DirectWriteForwarder.vcxproj", "{50A5318F-3B9A-48B9-9615-D5FA9D6D9C3E}"
ProjectSection(ProjectDependencies) = postProject
{FA69991B-9696-42D0-A5C7-F5E73F0DEE9E} = {FA69991B-9696-42D0-A5C7-F5E73F0DEE9E}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationCore", "src\Microsoft.DotNet.Wpf\src\PresentationCore\PresentationCore.csproj", "{74C63A45-EAE5-407A-9F89-E0C6BC604841}"
EndProject
Expand Down Expand Up @@ -157,6 +160,13 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationFramework.Royale-ref", "src\Microsoft.DotNet.Wpf\src\Themes\PresentationFramework.Royale\ref\PresentationFramework.Royale-ref.csproj", "{598B6188-937C-448B-8E6B-925F000BC076}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "System.Printing", "src\Microsoft.DotNet.Wpf\src\System.Printing\System.Printing.vcxproj", "{765E6BBC-772B-4808-BB72-E85615E8F237}"
ProjectSection(ProjectDependencies) = postProject
{17AA6CC2-CAE3-429C-B065-B76B8E14C632} = {17AA6CC2-CAE3-429C-B065-B76B8E14C632}
{74C63A45-EAE5-407A-9F89-E0C6BC604841} = {74C63A45-EAE5-407A-9F89-E0C6BC604841}
{9AC36357-34B7-40A1-95CA-FE9F46D089A7} = {9AC36357-34B7-40A1-95CA-FE9F46D089A7}
{B0C1157E-8664-44C4-AD8E-35CD6A78C769} = {B0C1157E-8664-44C4-AD8E-35CD6A78C769}
{FA69991B-9696-42D0-A5C7-F5E73F0DEE9E} = {FA69991B-9696-42D0-A5C7-F5E73F0DEE9E}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationUI", "src\Microsoft.DotNet.Wpf\src\PresentationUI\PresentationUI.csproj", "{B8E5B99C-D162-4DCA-9C4F-90CF2CDE942E}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ CannotRemoveBaseTypeOrInterface : Type 'System.Windows.Markup.XmlnsCompatibleWit
CannotRemoveBaseTypeOrInterface : Type 'System.Windows.Markup.XmlnsDefinitionAttribute' does not implement interface 'System.Runtime.InteropServices._Attribute' in the implementation but it does in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.Windows.Markup.XmlnsPrefixAttribute' does not implement interface 'System.Runtime.InteropServices._Attribute' in the implementation but it does in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.Windows.Media.DisableDpiAwarenessAttribute' does not implement interface 'System.Runtime.InteropServices._Attribute' in the implementation but it does in the contract.
Total Issues: 33
CannotMakeTypeAbstract : Type 'System.Windows.Threading.DispatcherOperation' is abstract in the implementation but is not abstract in the contract.
MembersMustExist : Member 'protected System.Object System.Windows.Threading.DispatcherOperation.InvokeDelegateCore()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'protected System.Object System.Windows.Threading.DispatcherOperation<TResult>.InvokeDelegateCore()' does not exist in the implementation but it does exist in the contract.
Total Issues: 36
Original file line number Diff line number Diff line change
@@ -1,124 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

//
//
//
// Description: Dock pattern provider wrapper for WCP
//
//
#nullable enable

using System.Windows.Threading;
using System.Windows.Automation;
using System.Windows.Automation.Provider;
using System.Windows.Automation.Peers;

namespace MS.Internal.Automation
{
// Automation/WCP Wrapper class: Implements that UIAutomation I...Provider
// interface, and calls through to a WCP AutomationPeer which implements the corresponding
// I...Provider inteface. Marshalls the call from the RPC thread onto the
// target AutomationPeer's context.
//
// Class has two major parts to it:
// * Implementation of the I...Provider, which uses Dispatcher.Invoke
// to call a private method (lives in second half of the class) via a delegate,
// if necessary, packages any params into an object param. Return type of Invoke
// must be cast from object to appropriate type.
// * private methods - one for each interface entry point - which get called back
// on the right context. These call through to the peer that's actually
// implenting the I...Provider version of the interface.
internal class DockProviderWrapper: MarshalByRefObject, IDockProvider
{
//------------------------------------------------------
//
// Constructors
//
//------------------------------------------------------

#region Constructors

private DockProviderWrapper( AutomationPeer peer, IDockProvider iface )
{
_peer = peer;
_iface = iface;
}

#endregion Constructors


//------------------------------------------------------
//
// Interface IDockProvider
//
//------------------------------------------------------

#region Interface IDockProvider

public void SetDockPosition(DockPosition dockPosition)
{
ElementUtil.Invoke( _peer, new DispatcherOperationCallback( SetDockPosition ), dockPosition );
}

public DockPosition DockPosition
{
get
{
return (DockPosition)ElementUtil.Invoke(_peer, new DispatcherOperationCallback( GetDockPosition ), null);
}
}

#endregion Interface IDockProvider


//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------

#region Internal Methods

internal static object Wrap( AutomationPeer peer, object iface )
{
return new DockProviderWrapper( peer, (IDockProvider) iface );
}
namespace MS.Internal.Automation;

#endregion Internal Methods

//------------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------

#region Private Methods

private object SetDockPosition( object arg )
{
_iface.SetDockPosition( (DockPosition) arg );
return null;
}

private object GetDockPosition( object unused )
{
return _iface.DockPosition;
}
/// <summary>
/// Wrapper class for the <see cref="IDockProvider"/> interface, calls through to the managed <see cref="AutomationPeer"/>
/// that implements it. The calls are made on the peer's context to ensure that the correct synchronization context is used.
/// </summary>
internal sealed class DockProviderWrapper : MarshalByRefObject, IDockProvider
{
private readonly AutomationPeer _peer;
private readonly IDockProvider _iface;

#endregion Private Methods
private DockProviderWrapper(AutomationPeer peer, IDockProvider iface)
{
Debug.Assert(peer is not null);
Debug.Assert(iface is not null);

_peer = peer;
_iface = iface;
}

//------------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------

#region Private Fields
public void SetDockPosition(DockPosition dockPosition)
{
ElementUtil.Invoke(_peer, static (state, dockPosition) => state.SetDockPosition(dockPosition), _iface, dockPosition);
}

private AutomationPeer _peer;
private IDockProvider _iface;
public DockPosition DockPosition
{
get => ElementUtil.Invoke(_peer, static (state) => state.DockPosition, _iface);
}

#endregion Private Fields
/// <summary>
/// Creates a wrapper for the given <see cref="AutomationPeer"/> and <see cref="IDockProvider"/> interface.
/// </summary>
internal static object Wrap(AutomationPeer peer, object iface)
{
return new DockProviderWrapper(peer, (IDockProvider)iface);
}
}
Loading