mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-11-02 07:08:31 +01:00
Align skia plugin API with normal plugin API
This commit is contained in:
@@ -39,7 +39,7 @@ internal class SkiaBenchmarkPlugin : SkiaPlugin
|
||||
surface = SKSurface.Create(new SKImageInfo(w, h, SKColorType.Bgra8888, SKAlphaType.Premul));
|
||||
}
|
||||
|
||||
public override SKImage? Render()
|
||||
public override SKImage? Main()
|
||||
{
|
||||
long now = frameTimer.ElapsedMilliseconds;
|
||||
if (lastFrameMs > 0)
|
||||
|
||||
@@ -17,7 +17,7 @@ internal class TimePlugin : SkiaPlugin
|
||||
|
||||
public override int UpdateInterval => 1000;
|
||||
|
||||
public override SKImage? Render()
|
||||
public override SKImage? Main()
|
||||
{
|
||||
string time = GetTime();
|
||||
|
||||
|
||||
@@ -1136,11 +1136,11 @@ public partial class PluginWindow : Window, IPluginWindow
|
||||
if (plugin is SkiaAsyncPlugin skiaAsyncPlugin)
|
||||
{
|
||||
CancellationToken token = pluginCancellationTokenSource?.Token ?? CancellationToken.None;
|
||||
skImage = await skiaAsyncPlugin.RenderAsync(token);
|
||||
skImage = await skiaAsyncPlugin.MainAsync(token);
|
||||
}
|
||||
else if (plugin is SkiaPlugin skiaPlugin)
|
||||
{
|
||||
skImage = skiaPlugin.Render();
|
||||
skImage = skiaPlugin.Main();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using SkiaSharp;
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -7,29 +8,41 @@ using System.Threading.Tasks;
|
||||
namespace DesktopMagic.Api;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an abstract base class for creating asynchronous plugins using SkiaSharp rendering.
|
||||
/// Plugins override <see cref="RenderAsync(CancellationToken)"/> and return an <see cref="SKImage"/>
|
||||
/// of their own size, just like <see cref="AsyncPlugin.MainAsync(CancellationToken)"/> returns a
|
||||
/// <see cref="Bitmap"/>. The returned image is scaled to fit the plugin window while preserving
|
||||
/// its aspect ratio.
|
||||
/// All existing <see cref="Plugin"/>, <see cref="AsyncPlugin"/>, and <see cref="SkiaPlugin"/> code is unaffected.
|
||||
/// Infrastructure base class of <see cref="SkiaAsyncPlugin"/>. Derive from <see cref="SkiaAsyncPlugin"/> instead.
|
||||
/// </summary>
|
||||
public abstract class SkiaAsyncPlugin : AsyncPlugin
|
||||
/// <remarks>This class only exists to seal the <see cref="Bitmap"/> based <see cref="AsyncPlugin.MainAsync"/> method,
|
||||
/// so that <see cref="SkiaAsyncPlugin"/> can declare its own <see cref="SkiaAsyncPlugin.MainAsync"/> method returning an <see cref="SKImage"/>.</remarks>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public abstract class SkiaAsyncPluginBase : AsyncPlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// This method is sealed and returns null for async Skia plugins.
|
||||
/// Override <see cref="RenderAsync(CancellationToken)"/> instead.
|
||||
/// This method should not be called directly! Override and use <see cref="SkiaAsyncPlugin.MainAsync"/> for asynchronous Skia plugin rendering.
|
||||
/// </summary>
|
||||
/// <remarks>This method only exists to fulfill base class requirements.</remarks>
|
||||
/// <param name="cancellationToken">Token signaled when the host requests cancellation.</param>
|
||||
/// <returns>A task that always resolves to <see langword="null"/>.</returns>
|
||||
public sealed override Task<Bitmap?> MainAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult<Bitmap?>(null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides an abstract base class for creating asynchronous plugins that render with SkiaSharp and can be integrated into the application,
|
||||
/// supporting periodic updates, rendering, and user interaction.
|
||||
/// </summary>
|
||||
/// <remarks>Derive from this class to implement custom plugin functionality. The class defines lifecycle methods
|
||||
/// such as <see cref="AsyncPlugin.StartAsync"/>, <see cref="AsyncPlugin.StopAsync"/>, and <see cref="MainAsync"/> for activation, deactivation, and periodic
|
||||
/// execution. It also provides event handlers for mouse and theme interactions, as well as access to application data
|
||||
/// and rendering configuration. Implementations should override relevant methods to respond to user input, update
|
||||
/// intervals, and configuration changes as needed. The image returned by <see cref="MainAsync"/> is scaled to fit the
|
||||
/// plugin window while preserving its aspect ratio.</remarks>
|
||||
public abstract class SkiaAsyncPlugin : SkiaAsyncPluginBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Called every <see cref="Plugin.UpdateInterval"/> milliseconds to render the plugin asynchronously.
|
||||
/// Return <see langword="null"/> to keep the previously rendered image.
|
||||
/// Occurs when the <see cref="Plugin.UpdateInterval"/> elapses.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Token signaled when the host requests cancellation.</param>
|
||||
/// <returns>The rendered image, or <see langword="null"/> to keep the previous frame.</returns>
|
||||
public abstract Task<SKImage?> RenderAsync(CancellationToken cancellationToken);
|
||||
public new abstract Task<SKImage?> MainAsync(CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
@@ -1,32 +1,44 @@
|
||||
using SkiaSharp;
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
|
||||
namespace DesktopMagic.Api;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an abstract base class for creating plugins using SkiaSharp rendering.
|
||||
/// Plugins override <see cref="Render()"/> and return an <see cref="SKImage"/> of their own size,
|
||||
/// just like <see cref="Plugin.Main()"/> returns a <see cref="Bitmap"/>. The returned image is
|
||||
/// scaled to fit the plugin window while preserving its aspect ratio.
|
||||
/// All existing <see cref="Plugin"/> and <see cref="AsyncPlugin"/> code is unaffected.
|
||||
/// Infrastructure base class of <see cref="SkiaPlugin"/>. Derive from <see cref="SkiaPlugin"/> instead.
|
||||
/// </summary>
|
||||
public abstract class SkiaPlugin : Plugin
|
||||
/// <remarks>This class only exists to seal the <see cref="Bitmap"/> based <see cref="Plugin.Main"/> method,
|
||||
/// so that <see cref="SkiaPlugin"/> can declare its own <see cref="SkiaPlugin.Main"/> method returning an <see cref="SKImage"/>.</remarks>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public abstract class SkiaPluginBase : Plugin
|
||||
{
|
||||
/// <summary>
|
||||
/// This method is sealed and returns null for Skia plugins.
|
||||
/// Override <see cref="Render()"/> instead.
|
||||
/// This method should not be called directly! Override and use <see cref="SkiaPlugin.Main"/> for Skia plugin rendering.
|
||||
/// </summary>
|
||||
/// <returns>Always null.</returns>
|
||||
/// <remarks>This method only exists to fulfill base class requirements.</remarks>
|
||||
/// <returns>Always <see langword="null"/>.</returns>
|
||||
public sealed override Bitmap? Main()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides an abstract base class for creating plugins that render with SkiaSharp and can be integrated into the application,
|
||||
/// supporting periodic updates, rendering, and user interaction.
|
||||
/// </summary>
|
||||
/// <remarks>Derive from this class to implement custom plugin functionality. The class defines lifecycle methods
|
||||
/// such as <see cref="Plugin.Start"/>, <see cref="Plugin.Stop"/>, and <see cref="Main"/> for activation, deactivation, and periodic
|
||||
/// execution. It also provides event handlers for mouse and theme interactions, as well as access to application data
|
||||
/// and rendering configuration. Implementations should override relevant methods to respond to user input, update
|
||||
/// intervals, and configuration changes as needed. The image returned by <see cref="Main"/> is scaled to fit the
|
||||
/// plugin window while preserving its aspect ratio.</remarks>
|
||||
public abstract class SkiaPlugin : SkiaPluginBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Called every <see cref="Plugin.UpdateInterval"/> milliseconds to render the plugin.
|
||||
/// Return <see langword="null"/> to keep the previously rendered image.
|
||||
/// Occurs when the <see cref="Plugin.UpdateInterval"/> elapses.
|
||||
/// </summary>
|
||||
/// <returns>The rendered image, or <see langword="null"/> to keep the previous frame.</returns>
|
||||
public abstract SKImage? Render();
|
||||
public new abstract SKImage? Main();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user