Class WindowSurface
Represents the surface of a window
public sealed class WindowSurface : Surface, IDisposable
- Inheritance
-
WindowSurface
- Implements
- Inherited Members
Remarks
WindowSurfaces (coming from the Surface property of a Window) can be used as an alternative to using a Renderer on the window.
Do not attempt to use a WindowSurface together with a Renderer on the same Window! They are meant to be used mutually exclusively for the same Window.
For the most part WindowSurfaces are not thread-safe, and most of their properties and methods should only be accessed from the main thread!
Properties
IsValid
Gets a value indicating whether the surface is still valid
public bool IsValid { get; }
Property Value
- bool
A value indicating whether the surface is still valid
Remarks
A WindowSurface can become invalid:
In any of these cases, the Surface property of the associated Window will reference a new WindowSurface instance that is valid and can be used instead of the invalid one.
Do not attempt to use an invalid WindowSurface! You are responsible for ensuring that you only use valid WindowSurface instances.
VSync
Gets or sets the vertical synchronization (VSync) mode or interval for the surface of a window
public WindowSurfaceVSync VSync { get; set; }
Property Value
- WindowSurfaceVSync
The vertical synchronization (VSync) mode or interval for the surface of a window
Remarks
You can set the value of this property to Disabled to disable VSync,
Adaptive to enable late swap tearing (adaptive VSync) if supported,
or use the Interval(int) method to specify a custom VSync interval.
You can specify a custom interval of 1 to synchronize the surface with every vertical refresh,
2 to synchronize it with every second vertical refresh, and so on.
When a window surface is newly created, the value of this property defaults to Disabled.
This property should only be accessed from the main thread.
Exceptions
- SdlException
When setting or getting this property, SDL failed with an error (check TryGet(out string?) for more information)
Window
Gets the associated Window of the surface
public Window? Window { get; }
Property Value
- Window
The associated Window of the surface, that is the window for which this surface is the Surface instance, or
nullif this surface is not valid anymore
Methods
Dispose(bool, bool)
Dispose the surface
protected override void Dispose(bool disposing, bool forget)
Parameters
Remarks
After disposing a WindowSurface, it becomes invalid, and its associated Window will have a new WindowSurface instance as its Surface that is valid and can be used instead of the disposed one.
This method should only be called from the main thread.
TryUpdate()
Tries to copy the entirety of the window surface to the screen
public bool TryUpdate()
Returns
- bool
true, if the window surface was successfully copied to the screen; otherwise,false(call TryGet(out string?) for more information about the failure)
Remarks
This method tries to copy the present window surface's content to the screen, in order to display it as the associated Window's visible content. To reflect any changes made to the surface, you need to call this method to update the window's content on the screen.
This method should only be called from the main thread.
TryUpdateRects(ReadOnlySpan<Rect<int>>)
Tries to copy the specified areas of the window surface to the screen
public bool TryUpdateRects(ReadOnlySpan<Rect<int>> rects)
Parameters
rectsReadOnlySpan<Rect<int>>The list of areas of the window surface copy
Returns
- bool
true, if at least the specified areas of the window surface were successfully copied to the screen; otherwise,false(call TryGet(out string?) for more information about the failure)
Remarks
This method tries to copy the present window surface's content to the screen, in order to display it as the associated Window's visible content. To reflect any changes made to the surface, you need to call this method to update the window's content on the screen.
Note that this method will update at least the specified areas, but this is only intended as an optimization; in practice, this might update more of the screen (or even the entirety of all of the screen), depending on the method used by SDL to send pixels to the system.
This method should only be called from the main thread.