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));
|
surface = SKSurface.Create(new SKImageInfo(w, h, SKColorType.Bgra8888, SKAlphaType.Premul));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override SKImage? Render()
|
public override SKImage? Main()
|
||||||
{
|
{
|
||||||
long now = frameTimer.ElapsedMilliseconds;
|
long now = frameTimer.ElapsedMilliseconds;
|
||||||
if (lastFrameMs > 0)
|
if (lastFrameMs > 0)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ internal class TimePlugin : SkiaPlugin
|
|||||||
|
|
||||||
public override int UpdateInterval => 1000;
|
public override int UpdateInterval => 1000;
|
||||||
|
|
||||||
public override SKImage? Render()
|
public override SKImage? Main()
|
||||||
{
|
{
|
||||||
string time = GetTime();
|
string time = GetTime();
|
||||||
|
|
||||||
|
|||||||
@@ -1136,11 +1136,11 @@ public partial class PluginWindow : Window, IPluginWindow
|
|||||||
if (plugin is SkiaAsyncPlugin skiaAsyncPlugin)
|
if (plugin is SkiaAsyncPlugin skiaAsyncPlugin)
|
||||||
{
|
{
|
||||||
CancellationToken token = pluginCancellationTokenSource?.Token ?? CancellationToken.None;
|
CancellationToken token = pluginCancellationTokenSource?.Token ?? CancellationToken.None;
|
||||||
skImage = await skiaAsyncPlugin.RenderAsync(token);
|
skImage = await skiaAsyncPlugin.MainAsync(token);
|
||||||
}
|
}
|
||||||
else if (plugin is SkiaPlugin skiaPlugin)
|
else if (plugin is SkiaPlugin skiaPlugin)
|
||||||
{
|
{
|
||||||
skImage = skiaPlugin.Render();
|
skImage = skiaPlugin.Main();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -7,29 +8,41 @@ using System.Threading.Tasks;
|
|||||||
namespace DesktopMagic.Api;
|
namespace DesktopMagic.Api;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides an abstract base class for creating asynchronous plugins using SkiaSharp rendering.
|
/// Infrastructure base class of <see cref="SkiaAsyncPlugin"/>. Derive from <see cref="SkiaAsyncPlugin"/> instead.
|
||||||
/// 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.
|
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// This method is sealed and returns null for async Skia plugins.
|
/// This method should not be called directly! Override and use <see cref="SkiaAsyncPlugin.MainAsync"/> for asynchronous Skia plugin rendering.
|
||||||
/// Override <see cref="RenderAsync(CancellationToken)"/> instead.
|
|
||||||
/// </summary>
|
/// </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)
|
public sealed override Task<Bitmap?> MainAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return Task.FromResult<Bitmap?>(null);
|
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>
|
/// <summary>
|
||||||
/// Called every <see cref="Plugin.UpdateInterval"/> milliseconds to render the plugin asynchronously.
|
/// Occurs when the <see cref="Plugin.UpdateInterval"/> elapses.
|
||||||
/// Return <see langword="null"/> to keep the previously rendered image.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cancellationToken">Token signaled when the host requests cancellation.</param>
|
/// <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>
|
/// <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 SkiaSharp;
|
||||||
|
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace DesktopMagic.Api;
|
namespace DesktopMagic.Api;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides an abstract base class for creating plugins using SkiaSharp rendering.
|
/// Infrastructure base class of <see cref="SkiaPlugin"/>. Derive from <see cref="SkiaPlugin"/> instead.
|
||||||
/// 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.
|
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// This method is sealed and returns null for Skia plugins.
|
/// This method should not be called directly! Override and use <see cref="SkiaPlugin.Main"/> for Skia plugin rendering.
|
||||||
/// Override <see cref="Render()"/> instead.
|
|
||||||
/// </summary>
|
/// </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()
|
public sealed override Bitmap? Main()
|
||||||
{
|
{
|
||||||
return null;
|
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>
|
/// <summary>
|
||||||
/// Called every <see cref="Plugin.UpdateInterval"/> milliseconds to render the plugin.
|
/// Occurs when the <see cref="Plugin.UpdateInterval"/> elapses.
|
||||||
/// Return <see langword="null"/> to keep the previously rendered image.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The rendered image, or <see langword="null"/> to keep the previous frame.</returns>
|
/// <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