Skip to content

Commit df88e68

Browse files
committed
Lay out impl, add new APIs from proposal
1 parent 40ce1a2 commit df88e68

10 files changed

+403
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
namespace Silk.NET.Windowing;
7+
8+
/// <summary>
9+
/// Represents a surface with a user-controlled lifecycle.
10+
/// </summary>
11+
/// <remarks>
12+
/// This API is <b>not guaranteed to be supported</b> on all platforms and you should only use it if you know what
13+
/// you're doing and know you need the granular control this API provides! Please use
14+
/// <see cref="ISurfaceApplication.Run{T}" /> instead where possible. If you insist on using this API, please fall back
15+
/// to <see cref="ISurfaceApplication.Run{T}" /> if <see cref="TryCreate{T}" /> returns <c>false</c> indicating a lack
16+
/// of support.
17+
/// </remarks>
18+
public interface IDetachedSurfaceLifecycle : IDisposable
19+
{
20+
/// <summary>
21+
/// Gets the surface with which this lifecycle is associated. The destruction of this surface is handled by
22+
/// the <see cref="IDisposable.Dispose" /> method of this <see cref="IDetachedSurfaceLifecycle" /> implementation.
23+
/// </summary>
24+
Surface Surface { get; }
25+
26+
/// <summary>
27+
/// Gets a value indicating whether the surface is indicating that its lifecycle should conclude as a result of
28+
/// its current configuration e.g. an entire tick passing with <see cref="ISurfaceWindow.IsCloseRequested" /> being
29+
/// <c>true</c>.
30+
/// </summary>
31+
/// <remarks>
32+
/// It is expected that <see cref="Tick" /> shall not be called if this property is <c>true</c>.
33+
/// </remarks>
34+
bool ShouldTerminate { get; }
35+
36+
/// <summary>
37+
/// Steps the underlying implementation's surface lifecycle (i.e. event loop), running a single tick on the
38+
/// <see cref="Surface" />.
39+
/// </summary>
40+
/// <remarks>
41+
/// It is expected that implementations shall return after doing as little work as possible. For instance, if the
42+
/// underlying implementation exposes one-by-one event retrieval or otherwise allows customisation of the extent to
43+
/// which the event pump is run, it is expected that a single event shall be pumped in this case. Note that this is
44+
/// just an example and the exact details of this is implementation-defined.
45+
/// </remarks>
46+
void Tick();
47+
48+
/// <summary>
49+
/// Attempts to create a <see cref="IDetachedSurfaceLifecycle" /> using the reference implementation.
50+
/// </summary>
51+
/// <param name="lifecycle">The created surface lifecycle on success, <c>null</c> otherwise.</param>
52+
/// <typeparam name="T">
53+
/// The application that shall be associated with the surface. Note that even with this API,
54+
/// <see cref="ISurfaceApplication.Initialize{T}" /> shall still be called for consistency and portability. However,
55+
/// unlike <see cref="ISurfaceApplication.Run{T}" />, this method shall not block and will instead return an
56+
/// <see cref="IDetachedSurfaceLifecycle" /> on which <see cref="Tick" /> is expected to be continuously called to
57+
/// enact the same behaviour on the surface. The associated application is also used for any additional global
58+
/// configuration, such as <see cref="ISurfaceApplication.WindowClass" />.
59+
/// </typeparam>
60+
/// <returns>
61+
/// <c>true</c> if <paramref name="lifecycle" /> has been populated with an <see cref="IDetachedSurfaceLifecycle" />
62+
/// object containing a valid <see cref="Surface" />, <c>false</c> otherwise.
63+
/// </returns>
64+
/// <remarks>
65+
/// This is the same reference implementation that <see cref="ISurfaceApplication.Run{T}" /> would otherwise use.
66+
/// </remarks>
67+
static sealed bool TryCreate<T>([NotNullWhen(true)] out IDetachedSurfaceLifecycle? lifecycle)
68+
where T : ISurfaceApplication => throw new NotImplementedException();
69+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
using System.Numerics;
6+
7+
namespace Silk.NET.Windowing.SDL3;
8+
9+
internal class SdlSurface : Surface
10+
{
11+
private SdlSurfaceComponents _components;
12+
13+
public SdlSurface() => _components = new SdlSurfaceComponents(this);
14+
15+
public override ISurfaceOpenGL? OpenGL => _components.IsOpenGLEnabled ? _components : null;
16+
public override ISurfaceWindow? Window => _components.IsWindowEnabled ? _components : null;
17+
public override ISurfaceDisplay? Display => _components.IsDisplayEnabled ? _components : null;
18+
public override ISurfaceVulkan? Vulkan => _components.IsVulkanEnabled ? _components : null;
19+
public override ISurfaceChildren? Children =>
20+
_components.IsChildrenEnabled ? _components : null;
21+
public override ISurfaceScale? Scale => _components.IsScaleEnabled ? _components : null;
22+
public override Vector2 DrawableSize { get; }
23+
public override event Action<SurfaceResizeEvent>? DrawableSizeChanged;
24+
public override event Action<SurfaceLifecycleEvent>? Created;
25+
public override event Action<SurfaceLifecycleEvent>? Terminating;
26+
public override event Action<SurfaceLifecycleEvent>? Pausing;
27+
public override event Action<SurfaceLifecycleEvent>? Resuming;
28+
public override event Action<SurfaceLifecycleEvent>? LowMemory;
29+
public override SurfaceTickOptions TickOptions { get; set; }
30+
31+
public override void Continue() => throw new NotImplementedException();
32+
33+
public override void Terminate() => throw new NotImplementedException();
34+
35+
public override bool TryGetPlatformInfo<TPlatformInfo>(
36+
[NotNullWhen(true)] out TPlatformInfo? info
37+
)
38+
where TPlatformInfo : default => throw new NotImplementedException();
39+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Silk.NET.Windowing.SDL3;
5+
6+
internal partial class SdlSurfaceComponents : ISurfaceChildren
7+
{
8+
void ISurfaceChildren.Spawn<T>() => throw new NotImplementedException();
9+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Silk.NET.Windowing.SDL3;
5+
6+
internal partial class SdlSurfaceComponents : ISurfaceDisplay
7+
{
8+
IDisplay ISurfaceDisplay.Current
9+
{
10+
get => throw new NotImplementedException();
11+
set => throw new NotImplementedException();
12+
}
13+
14+
IReadOnlyList<IDisplay> ISurfaceDisplay.Available => throw new NotImplementedException();
15+
16+
VideoMode ISurfaceDisplay.VideoMode
17+
{
18+
get => throw new NotImplementedException();
19+
set => throw new NotImplementedException();
20+
}
21+
22+
IReadOnlyList<VideoMode> ISurfaceDisplay.AvailableVideoModes =>
23+
throw new NotImplementedException();
24+
25+
event Action<DisplayChangeEvent>? ISurfaceDisplay.CurrentDisplayChanged
26+
{
27+
add => throw new NotImplementedException();
28+
remove => throw new NotImplementedException();
29+
}
30+
31+
event Action<DisplayAvailabilityChangeEvent>? ISurfaceDisplay.AvailableChanged
32+
{
33+
add => throw new NotImplementedException();
34+
remove => throw new NotImplementedException();
35+
}
36+
37+
event Action<DisplayVideoModeAvailabilityChangeEvent>? ISurfaceDisplay.AvailableVideoModesChanged
38+
{
39+
add => throw new NotImplementedException();
40+
remove => throw new NotImplementedException();
41+
}
42+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Silk.NET.Core.Loader;
5+
using Silk.NET.Maths;
6+
7+
namespace Silk.NET.Windowing.SDL3;
8+
9+
internal partial class SdlSurfaceComponents : ISurfaceOpenGL
10+
{
11+
void IDisposable.Dispose() => throw new NotImplementedException();
12+
13+
unsafe void* INativeContext.LoadFunction(string functionName, string libraryNameHint) =>
14+
throw new NotImplementedException();
15+
16+
bool IGLContext.IsCurrent
17+
{
18+
get => throw new NotImplementedException();
19+
set => throw new NotImplementedException();
20+
}
21+
22+
int IGLContext.SwapInterval
23+
{
24+
get => throw new NotImplementedException();
25+
set => throw new NotImplementedException();
26+
}
27+
28+
void IGLContext.SwapBuffers() => throw new NotImplementedException();
29+
30+
int? ISurfaceOpenGL.PreferredDepthBufferBits
31+
{
32+
get => throw new NotImplementedException();
33+
set => throw new NotImplementedException();
34+
}
35+
36+
int? ISurfaceOpenGL.PreferredStencilBufferBits
37+
{
38+
get => throw new NotImplementedException();
39+
set => throw new NotImplementedException();
40+
}
41+
42+
Vector4D<int>? ISurfaceOpenGL.PreferredBitDepth
43+
{
44+
get => throw new NotImplementedException();
45+
set => throw new NotImplementedException();
46+
}
47+
48+
int? ISurfaceOpenGL.PreferredSampleCount
49+
{
50+
get => throw new NotImplementedException();
51+
set => throw new NotImplementedException();
52+
}
53+
54+
Version32? ISurfaceOpenGL.Version
55+
{
56+
get => throw new NotImplementedException();
57+
set => throw new NotImplementedException();
58+
}
59+
60+
OpenGLContextFlags ISurfaceOpenGL.Flags
61+
{
62+
get => throw new NotImplementedException();
63+
set => throw new NotImplementedException();
64+
}
65+
66+
OpenGLContextProfile ISurfaceOpenGL.Profile
67+
{
68+
get => throw new NotImplementedException();
69+
set => throw new NotImplementedException();
70+
}
71+
72+
bool ISurfaceOpenGL.IsSupported => throw new NotImplementedException();
73+
74+
bool ISurfaceOpenGL.ShouldSwapAutomatically
75+
{
76+
get => throw new NotImplementedException();
77+
set => throw new NotImplementedException();
78+
}
79+
80+
IGLContext? ISurfaceOpenGL.SharedContext
81+
{
82+
get => throw new NotImplementedException();
83+
set => throw new NotImplementedException();
84+
}
85+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Silk.NET.Windowing.SDL3;
5+
6+
internal partial class SdlSurfaceComponents : ISurfaceScale
7+
{
8+
float ISurfaceScale.ContentScale => throw new NotImplementedException();
9+
10+
float ISurfaceScale.DrawScale => throw new NotImplementedException();
11+
12+
float ISurfaceScale.PixelDensity => throw new NotImplementedException();
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Silk.NET.Windowing.SDL3;
5+
6+
internal partial class SdlSurfaceComponents : ISurfaceVulkan
7+
{
8+
bool ISurfaceVulkan.IsEnabled
9+
{
10+
get => throw new NotImplementedException();
11+
set => throw new NotImplementedException();
12+
}
13+
14+
ulong ISurfaceVulkan.CreateSurface(IntPtr instance, Ptr allocator) =>
15+
throw new NotImplementedException();
16+
17+
Ptr2D<sbyte> ISurfaceVulkan.GetRequiredExtensions(out uint count) =>
18+
throw new NotImplementedException();
19+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Silk.NET.Maths;
5+
6+
namespace Silk.NET.Windowing.SDL3;
7+
8+
internal partial class SdlSurfaceComponents : ISurfaceWindow
9+
{
10+
Rectangle<float> ISurfaceWindow.Bounds
11+
{
12+
get => throw new NotImplementedException();
13+
set => throw new NotImplementedException();
14+
}
15+
16+
Rectangle<float> ISurfaceWindow.ClientArea
17+
{
18+
get => throw new NotImplementedException();
19+
set => throw new NotImplementedException();
20+
}
21+
22+
event Action<WindowCoordinatesEvent>? ISurfaceWindow.CoordinatesChanged
23+
{
24+
add => throw new NotImplementedException();
25+
remove => throw new NotImplementedException();
26+
}
27+
28+
bool ISurfaceWindow.IsCloseRequested
29+
{
30+
get => throw new NotImplementedException();
31+
set => throw new NotImplementedException();
32+
}
33+
34+
bool ISurfaceWindow.IsVisible
35+
{
36+
get => throw new NotImplementedException();
37+
set => throw new NotImplementedException();
38+
}
39+
40+
event Action<WindowToggleEvent>? ISurfaceWindow.CloseRequested
41+
{
42+
add => throw new NotImplementedException();
43+
remove => throw new NotImplementedException();
44+
}
45+
46+
bool ISurfaceWindow.IsFocused
47+
{
48+
get => throw new NotImplementedException();
49+
set => throw new NotImplementedException();
50+
}
51+
52+
event Action<WindowToggleEvent>? ISurfaceWindow.FocusChanged
53+
{
54+
add => throw new NotImplementedException();
55+
remove => throw new NotImplementedException();
56+
}
57+
58+
string ISurfaceWindow.Title
59+
{
60+
get => throw new NotImplementedException();
61+
set => throw new NotImplementedException();
62+
}
63+
64+
WindowState ISurfaceWindow.State
65+
{
66+
get => throw new NotImplementedException();
67+
set => throw new NotImplementedException();
68+
}
69+
70+
event Action<WindowStateEvent>? ISurfaceWindow.StateChanged
71+
{
72+
add => throw new NotImplementedException();
73+
remove => throw new NotImplementedException();
74+
}
75+
76+
WindowBorder ISurfaceWindow.Border
77+
{
78+
get => throw new NotImplementedException();
79+
set => throw new NotImplementedException();
80+
}
81+
82+
bool ISurfaceWindow.IsTopMost
83+
{
84+
get => throw new NotImplementedException();
85+
set => throw new NotImplementedException();
86+
}
87+
88+
event Action<WindowFileEvent>? ISurfaceWindow.FileDrop
89+
{
90+
add => throw new NotImplementedException();
91+
remove => throw new NotImplementedException();
92+
}
93+
94+
bool ISurfaceWindow.TrySetIcon(WindowIconVariants icon) => throw new NotImplementedException();
95+
}

0 commit comments

Comments
 (0)