-
Notifications
You must be signed in to change notification settings - Fork 955
/
Effect.cs
50 lines (41 loc) · 1.23 KB
/
Effect.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#if NET9_0_OR_GREATER
namespace System.Drawing.Imaging.Effects;
/// <summary>
/// Base class for all effects.
/// </summary>
public unsafe abstract class Effect : IDisposable
{
private CGpEffect* _nativeEffect;
internal CGpEffect* NativeEffect => _nativeEffect;
private protected Effect(Guid guid)
{
CGpEffect* nativeEffect;
PInvoke.GdipCreateEffect(guid, &nativeEffect).ThrowIfFailed();
_nativeEffect = nativeEffect;
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
private protected void SetParameters<T>(ref T parameters) where T : unmanaged
{
fixed (T* p = ¶meters)
{
PInvoke.GdipSetEffectParameters(NativeEffect, p, (uint)sizeof(T)).ThrowIfFailed();
GC.KeepAlive(this);
}
}
~Effect() => Dispose(disposing: false);
public virtual void Dispose(bool disposing)
{
if (_nativeEffect is not null)
{
PInvoke.GdipDeleteEffect(_nativeEffect);
_nativeEffect = null;
}
}
}
#endif