Skip to content

Commit d5fffd2

Browse files
authored
Use GeneratedComInterface to define IGraphicsEffectD2D1Interop (#13)
Use GeneratedComInterface to define IGraphicsEffectD2D1Interop
1 parent ce5a954 commit d5fffd2

File tree

9 files changed

+107
-351
lines changed

9 files changed

+107
-351
lines changed

MileXamlControlsDemoNetCore/UI/Backdrop/BlendEffect.cs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,32 @@
22
using MileXamlControlsDemoNetCore.WindowsAPI.ComTypes;
33
using System;
44
using System.Runtime.InteropServices;
5+
using System.Runtime.InteropServices.Marshalling;
56
using Windows.Graphics.Effects;
7+
using WinRT;
68

79
namespace MileXamlControlsDemoNetCore.UI.Backdrop
810
{
9-
[Guid("81C5B77B-13F8-4CDD-AD20-C890547AC65D")]
11+
[GeneratedComClass, Guid("81C5B77B-13F8-4CDD-AD20-C890547AC65D")]
1012
public sealed partial class BlendEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop
1113
{
12-
public D2D1_BUFFER_PRECISION BufferPrecision { get; set; }
13-
14-
public bool CacheOutput { get; set; }
15-
1614
public BlendEffectMode Mode { get; set; } = BlendEffectMode.Multiply;
1715

16+
public string Name { get; set; } = string.Empty;
17+
1818
public IGraphicsEffectSource Background { get; set; }
1919

2020
public IGraphicsEffectSource Foreground { get; set; }
2121

22-
private string _name = string.Empty;
23-
24-
public string Name
25-
{
26-
get { return _name; }
27-
28-
set { _name = value; }
29-
}
30-
3122
public int GetEffectId(out Guid id)
3223
{
3324
id = typeof(BlendEffect).GUID;
3425
return 0;
3526
}
3627

37-
public int GetNamedPropertyMapping(IntPtr name, out uint index, out GRAPHICS_EFFECT_PROPERTY_MAPPING mapping)
28+
public int GetNamedPropertyMapping(string name, out uint index, out GRAPHICS_EFFECT_PROPERTY_MAPPING mapping)
3829
{
39-
switch (Marshal.PtrToStringUni(name))
30+
switch (name)
4031
{
4132
case nameof(Mode):
4233
{
@@ -51,6 +42,7 @@ public int GetNamedPropertyMapping(IntPtr name, out uint index, out GRAPHICS_EFF
5142
break;
5243
}
5344
}
45+
5446
return 0;
5547
}
5648

@@ -65,6 +57,7 @@ public int GetProperty(uint index, out IntPtr source)
6557
return 0;
6658
}
6759
}
60+
6861
source = IntPtr.Zero;
6962
return -2147483637;
7063
}
@@ -75,21 +68,21 @@ public int GetPropertyCount(out uint count)
7568
return 0;
7669
}
7770

78-
public int GetSource(uint index, out IGraphicsEffectSource source)
71+
public int GetSource(uint index, out IntPtr source)
7972
{
8073
if (index is 0)
8174
{
82-
source = Background;
75+
source = MarshalInterface<IGraphicsEffectSource>.FromManaged(Background);
8376
return 0;
8477
}
8578
else if (index is 1)
8679
{
87-
source = Foreground;
80+
source = MarshalInterface<IGraphicsEffectSource>.FromManaged(Foreground);
8881
return 0;
8982
}
9083
else
9184
{
92-
source = null;
85+
source = IntPtr.Zero;
9386
return 2147483637;
9487
}
9588
}

MileXamlControlsDemoNetCore/UI/Backdrop/BorderEffect.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,32 @@
22
using MileXamlControlsDemoNetCore.WindowsAPI.ComTypes;
33
using System;
44
using System.Runtime.InteropServices;
5+
using System.Runtime.InteropServices.Marshalling;
56
using Windows.Graphics.Effects;
7+
using WinRT;
68

79
namespace MileXamlControlsDemoNetCore.UI.Backdrop
810
{
9-
[Guid("2A2D49C0-4ACF-43C7-8C6A-7C4A27874D27")]
10-
public partial class BorderEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop
11+
[GeneratedComClass, Guid("2A2D49C0-4ACF-43C7-8C6A-7C4A27874D27")]
12+
public sealed partial class BorderEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop
1113
{
12-
public D2D1_BUFFER_PRECISION BufferPrecision { get; set; }
13-
14-
public bool CacheOutput { get; set; }
14+
public string Name { get; set; } = string.Empty;
1515

1616
public CanvasEdgeBehavior ExtendX { get; set; } = CanvasEdgeBehavior.Clamp;
1717

1818
public CanvasEdgeBehavior ExtendY { get; set; } = CanvasEdgeBehavior.Clamp;
1919

2020
public IGraphicsEffectSource Source { get; set; }
2121

22-
private string _name = string.Empty;
23-
24-
public string Name
25-
{
26-
get { return _name; }
27-
28-
set { _name = value; }
29-
}
30-
3122
public int GetEffectId(out Guid id)
3223
{
3324
id = typeof(BorderEffect).GUID;
3425
return 0;
3526
}
3627

37-
public int GetNamedPropertyMapping(IntPtr name, out uint index, out GRAPHICS_EFFECT_PROPERTY_MAPPING mapping)
28+
public int GetNamedPropertyMapping(string name, out uint index, out GRAPHICS_EFFECT_PROPERTY_MAPPING mapping)
3829
{
39-
switch (Marshal.PtrToStringUni(name))
30+
switch (name)
4031
{
4132
case nameof(ExtendX):
4233
{
@@ -57,6 +48,7 @@ public int GetNamedPropertyMapping(IntPtr name, out uint index, out GRAPHICS_EFF
5748
break;
5849
}
5950
}
51+
6052
return 0;
6153
}
6254

@@ -82,6 +74,7 @@ public int GetProperty(uint index, out IntPtr source)
8274
return 0;
8375
}
8476
}
77+
8578
source = IntPtr.Zero;
8679
return -2147483637;
8780
}
@@ -92,16 +85,16 @@ public int GetPropertyCount(out uint count)
9285
return 0;
9386
}
9487

95-
public int GetSource(uint index, out IGraphicsEffectSource source)
88+
public int GetSource(uint index, out IntPtr source)
9689
{
9790
if (index is 0)
9891
{
99-
source = Source;
92+
source = MarshalInterface<IGraphicsEffectSource>.FromManaged(Source);
10093
return 0;
10194
}
10295
else
10396
{
104-
source = null;
97+
source = IntPtr.Zero;
10598
return 2147483637;
10699
}
107100
}

MileXamlControlsDemoNetCore/UI/Backdrop/ColorSourceEffect.cs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,29 @@
11
using MileXamlControlsDemoNetCore.Helpers;
22
using MileXamlControlsDemoNetCore.WindowsAPI.ComTypes;
33
using System;
4-
using System.Numerics;
54
using System.Runtime.InteropServices;
5+
using System.Runtime.InteropServices.Marshalling;
66
using Windows.Graphics.Effects;
77
using Windows.UI;
88

99
namespace MileXamlControlsDemoNetCore.UI.Backdrop
1010
{
11-
[Guid("61C23C20-AE69-4D8E-94CF-50078DF638F2")]
11+
[GeneratedComClass, Guid("61C23C20-AE69-4D8E-94CF-50078DF638F2")]
1212
public sealed partial class ColorSourceEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop
1313
{
14-
public D2D1_BUFFER_PRECISION BufferPrecision { get; set; }
15-
16-
public bool CacheOutput { get; set; }
14+
public string Name { get; set; } = string.Empty;
1715

1816
public Color Color { get; set; } = Color.FromArgb(255, 255, 255, 255);
1917

20-
private string _name = string.Empty;
21-
22-
public string Name
23-
{
24-
get { return _name; }
25-
26-
set { _name = value; }
27-
}
28-
29-
public Vector4 ColorHdr
30-
{
31-
get { return new(Color.R * 255.0f, Color.G * 255.0f, Color.B * 255.0f, Color.A * 255.0f); }
32-
33-
set { Color = Color.FromArgb((byte)(value.W / 255.0f), (byte)(value.X / 255.0f), (byte)(value.Y / 255.0f), (byte)(value.Z / 255.0f)); }
34-
}
35-
3618
public int GetEffectId(out Guid id)
3719
{
3820
id = typeof(ColorSourceEffect).GUID;
3921
return 0;
4022
}
4123

42-
public int GetNamedPropertyMapping(IntPtr name, out uint index, out GRAPHICS_EFFECT_PROPERTY_MAPPING mapping)
24+
public int GetNamedPropertyMapping(string name, out uint index, out GRAPHICS_EFFECT_PROPERTY_MAPPING mapping)
4325
{
44-
switch (Marshal.PtrToStringUni(name))
26+
switch (name)
4527
{
4628
case nameof(Color):
4729
{
@@ -82,9 +64,9 @@ public int GetPropertyCount(out uint count)
8264
return 0;
8365
}
8466

85-
public int GetSource(uint index, out IGraphicsEffectSource source)
67+
public int GetSource(uint index, out IntPtr source)
8668
{
87-
source = default;
69+
source = IntPtr.Zero;
8870
return 0;
8971
}
9072

MileXamlControlsDemoNetCore/UI/Backdrop/CompositeEffect.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,19 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Runtime.InteropServices;
6+
using System.Runtime.InteropServices.Marshalling;
67
using Windows.Graphics.Effects;
8+
using WinRT;
79

810
namespace MileXamlControlsDemoNetCore.UI.Backdrop
911
{
10-
[Guid("48FC9F51-F6AC-48F1-8B58-3B28AC46F76D")]
11-
public partial class CompositeEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop
12+
[GeneratedComClass, Guid("48FC9F51-F6AC-48F1-8B58-3B28AC46F76D")]
13+
public sealed partial class CompositeEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop
1214
{
13-
public D2D1_BUFFER_PRECISION BufferPrecision { get; set; }
14-
15-
public bool CacheOutput { get; set; }
15+
public string Name { get; set; } = string.Empty;
1616

1717
public CanvasComposite Mode { get; set; } = CanvasComposite.SourceOver;
1818

19-
private string _name = string.Empty;
20-
21-
public string Name
22-
{
23-
get { return _name; }
24-
25-
set { _name = value; }
26-
}
27-
2819
public List<IGraphicsEffectSource> Sources { get; set; } = [];
2920

3021
public int GetEffectId(out Guid id)
@@ -33,9 +24,9 @@ public int GetEffectId(out Guid id)
3324
return 0;
3425
}
3526

36-
public int GetNamedPropertyMapping(IntPtr name, out uint index, out GRAPHICS_EFFECT_PROPERTY_MAPPING mapping)
27+
public int GetNamedPropertyMapping(string name, out uint index, out GRAPHICS_EFFECT_PROPERTY_MAPPING mapping)
3728
{
38-
switch (Marshal.PtrToStringUni(name))
29+
switch (name)
3930
{
4031
case nameof(Mode):
4132
{
@@ -77,16 +68,16 @@ public int GetPropertyCount(out uint count)
7768
return 0;
7869
}
7970

80-
public int GetSource(uint index, out IGraphicsEffectSource source)
71+
public int GetSource(uint index, out IntPtr source)
8172
{
8273
if (index < Sources.Count)
8374
{
84-
source = Sources[(int)index];
75+
source = MarshalInterface<IGraphicsEffectSource>.FromManaged(Sources[(int)index]);
8576
return 0;
8677
}
8778
else
8879
{
89-
source = null;
80+
source = IntPtr.Zero;
9081
return 2147483637;
9182
}
9283
}

MileXamlControlsDemoNetCore/UI/Backdrop/CrossFadeEffect.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,32 @@
22
using MileXamlControlsDemoNetCore.WindowsAPI.ComTypes;
33
using System;
44
using System.Runtime.InteropServices;
5+
using System.Runtime.InteropServices.Marshalling;
56
using Windows.Graphics.Effects;
7+
using WinRT;
68

79
namespace MileXamlControlsDemoNetCore.UI.Backdrop
810
{
9-
[Guid("12F575E8-4DB1-485F-9A84-03A07DD3829F")]
11+
[GeneratedComClass, Guid("12F575E8-4DB1-485F-9A84-03A07DD3829F")]
1012
public sealed partial class CrossFadeEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop
1113
{
12-
public D2D1_BUFFER_PRECISION BufferPrecision { get; set; }
13-
14-
public bool CacheOutput { get; set; }
14+
public string Name { get; set; } = string.Empty;
1515

1616
public float CrossFade { get; set; } = 0.5f;
1717

1818
public IGraphicsEffectSource Source1 { get; set; }
1919

2020
public IGraphicsEffectSource Source2 { get; set; }
2121

22-
private string _name = string.Empty;
23-
24-
public string Name
25-
{
26-
get { return _name; }
27-
28-
set { _name = value; }
29-
}
30-
3122
public int GetEffectId(out Guid id)
3223
{
3324
id = typeof(CrossFadeEffect).GUID;
3425
return 0;
3526
}
3627

37-
public int GetNamedPropertyMapping(IntPtr name, out uint index, out GRAPHICS_EFFECT_PROPERTY_MAPPING mapping)
28+
public int GetNamedPropertyMapping(string name, out uint index, out GRAPHICS_EFFECT_PROPERTY_MAPPING mapping)
3829
{
39-
switch (Marshal.PtrToStringUni(name))
30+
switch (name)
4031
{
4132
case nameof(CrossFade):
4233
{
@@ -77,21 +68,21 @@ public int GetPropertyCount(out uint count)
7768
return 0;
7869
}
7970

80-
public int GetSource(uint index, out IGraphicsEffectSource source)
71+
public int GetSource(uint index, out IntPtr source)
8172
{
8273
if (index is 0)
8374
{
84-
source = Source1;
75+
source = MarshalInterface<IGraphicsEffectSource>.FromManaged(Source1);
8576
return 0;
8677
}
8778
else if (index is 1)
8879
{
89-
source = Source2;
80+
source = MarshalInterface<IGraphicsEffectSource>.FromManaged(Source2);
9081
return 0;
9182
}
9283
else
9384
{
94-
source = null;
85+
source = IntPtr.Zero;
9586
return 2147483637;
9687
}
9788
}

0 commit comments

Comments
 (0)