Skip to content

Commit

Permalink
Merge pull request #23 from dotnet-campus/t/lindexi/InternalMerge
Browse files Browse the repository at this point in the history
Pick some official PR
  • Loading branch information
kkwpsv authored Sep 9, 2022
2 parents ff4c143 + 63df3a2 commit dbda429
Show file tree
Hide file tree
Showing 56 changed files with 584 additions and 666 deletions.
10 changes: 10 additions & 0 deletions eng/WpfArcadeSdk/tools/Wpf.Cpp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ using namespace System::Runtime::Versioning;
<AdditionalNugetIds Remove="%40(AdditionalNugetIds)" />
<AdditionalNugetIds Include="%24([System.String]::Copy('%25(_AdditionalPackages.Identity)').Split('+')[0])" />
</ItemGroup>
<!--
Removing the Microsoft.NETCore.Platforms directly and then
adding it again to remove the duplicate reference.
-->
<ItemGroup>
<PackageReference Remove="Microsoft.NETCore.Platforms" />
<PackageReference Include="Microsoft.NETCore.Platforms"
Version="$(MicrosoftNETCorePlatformsVersion)" />
</ItemGroup>
</Target>
<Target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

internal static partial class Interop
{
internal static partial class zlib
internal static partial class Zlib
{
internal static readonly byte[] ZLibVersion = { (byte)'1', (byte)'.', (byte)'2', (byte)'.', (byte)'3', 0 };
[DllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_DeflateInit2_")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public ErrorCode DeflateInit2_(CompressionLevel level, int windowBits, int memLe
EnsureNotDisposed();
EnsureState(State.NotInitialized);

ErrorCode errC = Interop.zlib.DeflateInit2_(ref _zStream, level, CompressionMethod.Deflated, windowBits, memLevel, strategy);
ErrorCode errC = Interop.Zlib.DeflateInit2_(ref _zStream, level, CompressionMethod.Deflated, windowBits, memLevel, strategy);
_initializationState = State.InitializedForDeflate;

return errC;
Expand All @@ -263,7 +263,7 @@ public ErrorCode Deflate(FlushCode flush)
{
EnsureNotDisposed();
EnsureState(State.InitializedForDeflate);
return Interop.zlib.Deflate(ref _zStream, flush);
return Interop.Zlib.Deflate(ref _zStream, flush);
}


Expand All @@ -272,7 +272,7 @@ public ErrorCode DeflateEnd()
EnsureNotDisposed();
EnsureState(State.InitializedForDeflate);

ErrorCode errC = Interop.zlib.DeflateEnd(ref _zStream);
ErrorCode errC = Interop.Zlib.DeflateEnd(ref _zStream);
_initializationState = State.Disposed;

return errC;
Expand All @@ -284,7 +284,7 @@ public ErrorCode InflateInit2_(int windowBits)
EnsureNotDisposed();
EnsureState(State.NotInitialized);

ErrorCode errC = Interop.zlib.InflateInit2_(ref _zStream, windowBits);
ErrorCode errC = Interop.Zlib.InflateInit2_(ref _zStream, windowBits);
_initializationState = State.InitializedForInflate;

return errC;
Expand All @@ -295,7 +295,7 @@ public ErrorCode Inflate(FlushCode flush)
{
EnsureNotDisposed();
EnsureState(State.InitializedForInflate);
return Interop.zlib.Inflate(ref _zStream, flush);
return Interop.Zlib.Inflate(ref _zStream, flush);
}


Expand All @@ -304,7 +304,7 @@ public ErrorCode InflateEnd()
EnsureNotDisposed();
EnsureState(State.InitializedForInflate);

ErrorCode errC = Interop.zlib.InflateEnd(ref _zStream);
ErrorCode errC = Interop.Zlib.InflateEnd(ref _zStream);
_initializationState = State.Disposed;

return errC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface
// guarantee that this problem will be fixed so we will use the GetUnmanagedStream(). Note: This path will only
// be taken for embedded fonts among which XPS is a main scenario. For local fonts we use DWrite's APIs.
_fontSourceStream = fontSource->GetUnmanagedStream();
_fontSourcePointer = _fontSourceStream->PositionPointer - _fontSourceStream->Position;
try
{
_lastWriteTime = fontSource->GetLastWriteTimeUtc().ToFileTimeUtc();
}
}
catch(System::ArgumentOutOfRangeException^) //The resulting file time would represent a date and time before 12:00 midnight January 1, 1601 C.E. UTC.
{
_lastWriteTime = -1;
}

// Create lock to control access to font source stream.
_fontSourceStreamLock = gcnew Object();
}
}

FontFileStream::~FontFileStream()
Expand Down Expand Up @@ -61,31 +59,9 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface
return E_INVALIDARG;
}

int fragmentSizeInt = (int)fragmentSize;
array<byte>^ buffer = gcnew array<byte>(fragmentSizeInt);

// DWrite may call this method from multiple threads. We need to ensure thread safety by making Seek and Read atomic.
System::Threading::Monitor::Enter(_fontSourceStreamLock);
try
{
_fontSourceStream->Seek(fileOffset, //long
System::IO::SeekOrigin::Begin);

_fontSourceStream->Read(buffer, //byte[]
0, //int
fragmentSizeInt //int
);
}
finally
{
System::Threading::Monitor::Exit(_fontSourceStreamLock);
}

GCHandle gcHandle = GCHandle::Alloc(buffer, GCHandleType::Pinned);

*fragmentStart = (byte*)(gcHandle.AddrOfPinnedObject().ToPointer());

*fragmentContext = GCHandle::ToIntPtr(gcHandle).ToPointer();
// Return a pointer to the font data that is already loaded in memory (because the font source resource is mmapped into the process' address space).
*fragmentStart = _fontSourcePointer + fileOffset;
*fragmentContext = nullptr;
}
catch(System::Exception^ exception)
{
Expand All @@ -102,11 +78,6 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface
void* fragmentContext
)
{
if (fragmentContext != NULL)
{
GCHandle gcHandle = GCHandle::FromIntPtr(IntPtr(fragmentContext));
gcHandle.Free();
}
}

[ComVisible(true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface
private ref class FontFileStream : public IDWriteFontFileStreamMirror
{
private:
Stream^ _fontSourceStream;
UnmanagedMemoryStream^ _fontSourceStream;
Byte* _fontSourcePointer;
INT64 _lastWriteTime;
Object^ _fontSourceStreamLock;

public:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
<RestoreProjectStyle>Unknown</RestoreProjectStyle>
<!--
Opting out of this to ensure _WindowsBaseReference is used as
OutputItemsType in the project reference later.
-->
<LegacyNativeReferenceResolution>true</LegacyNativeReferenceResolution>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,18 @@ internal static RoutedEvent[] MapInputTypeToRoutedEvents(SynchronizedInputType i

internal static void RaiseAutomationEvents()
{
if (InputElement.IsUIElement(InputManager.ListeningElement))
if (InputManager.ListeningElement is UIElement e)
{
UIElement e = (UIElement)InputManager.ListeningElement;
//Raise InputDiscarded automation event
SynchronizedInputHelper.RaiseAutomationEvent(e.GetAutomationPeer());
}
else if (InputElement.IsContentElement(InputManager.ListeningElement))
else if (InputManager.ListeningElement is ContentElement ce)
{
ContentElement ce = (ContentElement)InputManager.ListeningElement;
//Raise InputDiscarded automation event
SynchronizedInputHelper.RaiseAutomationEvent(ce.GetAutomationPeer());
}
else if (InputElement.IsUIElement3D(InputManager.ListeningElement))
else if (InputManager.ListeningElement is UIElement3D e3D)
{
UIElement3D e3D = (UIElement3D)InputManager.ListeningElement;
//Raise InputDiscarded automation event
SynchronizedInputHelper.RaiseAutomationEvent(e3D.GetAutomationPeer());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ internal static DependencyObject GetUIParent(DependencyObject child, bool contin
[FriendAccessAllowed]
internal static bool IsUIElementOrUIElement3D(DependencyObject o)
{
return (o is UIElement || o is UIElement3D);
return (o is UIElement or UIElement3D);
}

[FriendAccessAllowed]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Markup;
using MS.Internal;
Expand Down Expand Up @@ -60,18 +61,13 @@ public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed)
/// <param name="canExecute">Handler associated with determining if the command can execute.</param>
public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute)
{
if (command == null)
{
throw new ArgumentNullException("command");
}
_command = command ?? throw new ArgumentNullException(nameof(command));

_command = command;

if (executed != null)
if (executed is not null)
{
Executed += executed;
}
if (canExecute != null)
if (canExecute is not null)
{
CanExecute += canExecute;
}
Expand All @@ -87,20 +83,8 @@ public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed, Can
[Localizability(LocalizationCategory.NeverLocalize)] // cannot be localized
public ICommand Command
{
get
{
return _command;
}

set
{
if (value == null)
{
throw new ArgumentNullException("value");
}

_command = value;
}
get => _command;
set => _command = value ?? throw new ArgumentNullException(nameof(value));
}

#endregion
Expand Down Expand Up @@ -138,49 +122,46 @@ public ICommand Command
/// <param name="e">Event arguments.</param>
internal void OnCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (!e.Handled)
if (e.Handled) return;
if (e.RoutedEvent == CommandManager.CanExecuteEvent)
{
if (e.RoutedEvent == CommandManager.CanExecuteEvent)
if (CanExecute is null)
{
if (CanExecute != null)
{
CanExecute(sender, e);
if (e.CanExecute)
{
e.Handled = true;
}
}
else if (!e.CanExecute)
{
// If there is an Executed handler, then the command can be executed.
if (Executed != null)
{
e.CanExecute = true;
e.Handled = true;
}
}
if (e.CanExecute) return;
// If there is an Executed handler, then the command can be executed.
if (Executed is null) return;
e.CanExecute = true;
e.Handled = true;
}
else // e.RoutedEvent == CommandManager.PreviewCanExecuteEvent
else
{
if (PreviewCanExecute != null)
CanExecute(sender, e);
if (e.CanExecute)
{
PreviewCanExecute(sender, e);
if (e.CanExecute)
{
e.Handled = true;
}
e.Handled = true;
}
}
}
else // e.RoutedEvent == CommandManager.PreviewCanExecuteEvent
{
if (PreviewCanExecute is null) return;
PreviewCanExecute(sender, e);
if (e.CanExecute)
{
e.Handled = true;
}
}
}

private bool CheckCanExecute(object sender, ExecutedRoutedEventArgs e)
{
CanExecuteRoutedEventArgs canExecuteArgs = new CanExecuteRoutedEventArgs(e.Command, e.Parameter);
canExecuteArgs.RoutedEvent = CommandManager.CanExecuteEvent;
CanExecuteRoutedEventArgs canExecuteArgs = new(e.Command, e.Parameter)
{
RoutedEvent = CommandManager.CanExecuteEvent,
// Since we don't actually raise this event, we have to explicitly set the source.
Source = e.OriginalSource
};

// Since we don't actually raise this event, we have to explicitly set the source.
canExecuteArgs.Source = e.OriginalSource;
canExecuteArgs.OverrideSource(e.Source);

OnCanExecute(sender, canExecuteArgs);
Expand All @@ -195,30 +176,22 @@ private bool CheckCanExecute(object sender, ExecutedRoutedEventArgs e)
/// <param name="e">Event arguments.</param>
internal void OnExecuted(object sender, ExecutedRoutedEventArgs e)
{
if (!e.Handled)
if (e.Handled) return;
if (e.RoutedEvent == CommandManager.ExecutedEvent)
{
if (e.RoutedEvent == CommandManager.ExecutedEvent)
{
if (Executed != null)
{
if (CheckCanExecute(sender, e))
{
Executed(sender, e);
e.Handled = true;
}
}
}
else // e.RoutedEvent == CommandManager.PreviewExecutedEvent
{
if (PreviewExecuted != null)
{
if (CheckCanExecute(sender, e))
{
PreviewExecuted(sender, e);
e.Handled = true;
}
}
}
if (Executed is null) return;
if (!CheckCanExecute(sender, e)) return;
Debug.Assert(Executed != null, nameof(Executed) + " != null");
Executed(sender, e);
e.Handled = true;
}
else // e.RoutedEvent == CommandManager.PreviewExecutedEvent
{
if (PreviewExecuted is null) return;
if (!CheckCanExecute(sender, e)) return;
Debug.Assert(PreviewExecuted != null, nameof(PreviewExecuted) + " != null");
PreviewExecuted(sender, e);
e.Handled = true;
}
}

Expand Down
Loading

0 comments on commit dbda429

Please sign in to comment.