-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[WinRT] Added watchdog for ICompositor5::RequestCommitAsync #16393
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,10 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Runtime.InteropServices; | ||
using Avalonia.Win32.Interop; | ||
|
||
namespace Avalonia.Win32 | ||
{ | ||
internal class OffscreenParentWindow | ||
{ | ||
public static IntPtr Handle { get; } = CreateParentWindow(); | ||
|
||
private static UnmanagedMethods.WndProc? s_wndProcDelegate; | ||
|
||
private static IntPtr CreateParentWindow() | ||
{ | ||
s_wndProcDelegate = ParentWndProc; | ||
|
||
var wndClassEx = new UnmanagedMethods.WNDCLASSEX | ||
{ | ||
cbSize = Marshal.SizeOf<UnmanagedMethods.WNDCLASSEX>(), | ||
hInstance = UnmanagedMethods.GetModuleHandle(null), | ||
lpfnWndProc = s_wndProcDelegate, | ||
lpszClassName = "AvaloniaEmbeddedWindow-" + Guid.NewGuid(), | ||
}; | ||
|
||
var atom = UnmanagedMethods.RegisterClassEx(ref wndClassEx); | ||
|
||
if (atom == 0) | ||
{ | ||
throw new Win32Exception(); | ||
} | ||
|
||
var hwnd = UnmanagedMethods.CreateWindowEx( | ||
0, | ||
atom, | ||
null, | ||
(int)UnmanagedMethods.WindowStyles.WS_OVERLAPPEDWINDOW, | ||
UnmanagedMethods.CW_USEDEFAULT, | ||
UnmanagedMethods.CW_USEDEFAULT, | ||
UnmanagedMethods.CW_USEDEFAULT, | ||
UnmanagedMethods.CW_USEDEFAULT, | ||
IntPtr.Zero, | ||
IntPtr.Zero, | ||
IntPtr.Zero, | ||
IntPtr.Zero); | ||
|
||
if (hwnd == IntPtr.Zero) | ||
{ | ||
throw new Win32Exception(); | ||
} | ||
|
||
return hwnd; | ||
} | ||
|
||
private static IntPtr ParentWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) | ||
{ | ||
return UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam); | ||
} | ||
private static SimpleWindow s_simpleWindow = new(null); | ||
public static IntPtr Handle { get; } = s_simpleWindow.Handle; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.ComponentModel; | ||
using System.Runtime.InteropServices; | ||
using Avalonia.Win32.Interop; | ||
|
||
namespace Avalonia.Win32; | ||
|
||
internal class SimpleWindow : IDisposable | ||
{ | ||
private readonly UnmanagedMethods.WndProc? _wndProc; | ||
private static UnmanagedMethods.WndProc s_wndProcDelegate; | ||
public IntPtr Handle { get; private set; } | ||
private static string s_className; | ||
private static uint s_classAtom; | ||
private static ConcurrentDictionary<IntPtr, SimpleWindow> s_Instances = new(); | ||
|
||
static SimpleWindow() | ||
{ | ||
s_wndProcDelegate = WndProc; | ||
var wndClassEx = new UnmanagedMethods.WNDCLASSEX | ||
{ | ||
cbSize = Marshal.SizeOf<UnmanagedMethods.WNDCLASSEX>(), | ||
hInstance = UnmanagedMethods.GetModuleHandle(null), | ||
lpfnWndProc = s_wndProcDelegate, | ||
lpszClassName = s_className = "AvaloniaSimpleWindow-" + Guid.NewGuid(), | ||
}; | ||
|
||
s_classAtom = UnmanagedMethods.RegisterClassEx(ref wndClassEx); | ||
} | ||
|
||
public SimpleWindow(UnmanagedMethods.WndProc? wndProc) | ||
{ | ||
_wndProc = wndProc; | ||
var handle = GCHandle.Alloc(this); | ||
try | ||
{ | ||
var hwnd = UnmanagedMethods.CreateWindowEx( | ||
0, | ||
s_classAtom, | ||
null, | ||
(int)UnmanagedMethods.WindowStyles.WS_OVERLAPPEDWINDOW, | ||
UnmanagedMethods.CW_USEDEFAULT, | ||
UnmanagedMethods.CW_USEDEFAULT, | ||
UnmanagedMethods.CW_USEDEFAULT, | ||
UnmanagedMethods.CW_USEDEFAULT, | ||
IntPtr.Zero, | ||
IntPtr.Zero, | ||
IntPtr.Zero, | ||
GCHandle.ToIntPtr(handle)); | ||
if (hwnd == IntPtr.Zero) | ||
{ | ||
throw new Win32Exception(); | ||
} | ||
|
||
Handle = hwnd; | ||
} | ||
finally | ||
{ | ||
handle.Free(); | ||
} | ||
} | ||
|
||
private static IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) | ||
{ | ||
SimpleWindow? window; | ||
if (msg == (uint)UnmanagedMethods.WindowsMessage.WM_CREATE) | ||
{ | ||
var handle = Marshal.ReadIntPtr(lParam); | ||
window = (SimpleWindow?)GCHandle.FromIntPtr(handle).Target; | ||
if (window == null) | ||
return IntPtr.Zero; | ||
s_Instances.TryAdd(hWnd, window); | ||
} | ||
else | ||
{ | ||
s_Instances.TryGetValue(hWnd, out window); | ||
} | ||
|
||
if (msg == (uint)UnmanagedMethods.WindowsMessage.WM_DESTROY) | ||
s_Instances.TryRemove(hWnd, out _); | ||
|
||
return window?._wndProc?.Invoke(hWnd, msg, wParam, lParam) | ||
?? UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
UnmanagedMethods.DestroyWindow(Handle); | ||
Handle = IntPtr.Zero; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really descriptive. Having different classnames for offscreen and winui-hack windows might help somebody's in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The window class is now reused for all windows to avoid wasting resources for no reason. It's not possible to customize it per-window anymore