From 3dc1fc2c0849aa5d93c5cc408245cacd975078ca Mon Sep 17 00:00:00 2001 From: ahmed walid Date: Wed, 20 Sep 2023 19:51:57 +0200 Subject: [PATCH] feat(composition): Implement WhiteNoiseEffect + Sample + Win2D + Refactor --- .../EffectBrushTests.xaml | 1 + .../EffectBrushTests.xaml.cs | 2066 +---------------- .../CompositionEffectBrush.skia.cs | 55 + .../Composition/Effects/WhiteNoiseEffect.cs | 69 + .../Graphics/Canvas/CanvasComposite.cs | 19 + .../Graphics/Canvas/CanvasEdgeBehavior.cs | 10 + .../Canvas/Effects/AlphaMaskEffect.cs | 34 + .../Graphics/Canvas/Effects/BlendEffect.cs | 64 + .../Canvas/Effects/BlendEffectMode.cs | 32 + .../Graphics/Canvas/Effects/BorderEffect.cs | 70 + .../Canvas/Effects/ColorMatrixEffect.cs | 60 + .../Canvas/Effects/ColorSourceEffect.cs | 59 + .../Canvas/Effects/CompositeEffect.cs | 63 + .../Graphics/Canvas/Effects/ContrastEffect.cs | 60 + .../Canvas/Effects/CrossfadeEffect.cs | 64 + .../Canvas/Effects/DistantDiffuseEffect.cs | 91 + .../Canvas/Effects/DistantSpecularEffect.cs | 101 + .../Canvas/Effects/EffectBorderMode.cs | 8 + .../Canvas/Effects/EffectOptimization.cs | 9 + .../Graphics/Canvas/Effects/ExposureEffect.cs | 61 + .../Canvas/Effects/GammaTransferEffect.cs | 225 ++ .../Canvas/Effects/GaussianBlurEffect.cs | 80 + .../Canvas/Effects/GrayscaleEffect.cs | 32 + .../Canvas/Effects/HueRotationEffect.cs | 60 + .../Graphics/Canvas/Effects/InvertEffect.cs | 32 + .../Canvas/Effects/LinearTransferEffect.cs | 185 ++ .../Canvas/Effects/LuminanceToAlphaEffect.cs | 32 + .../Graphics/Canvas/Effects/Matrix5x4.cs | 70 + .../Graphics/Canvas/Effects/OpacityEffect.cs | 60 + .../Canvas/Effects/PointDiffuseEffect.cs | 82 + .../Canvas/Effects/PointSpecularEffect.cs | 92 + .../Canvas/Effects/SaturationEffect.cs | 60 + .../Graphics/Canvas/Effects/SepiaEffect.cs | 60 + .../Canvas/Effects/SpotDiffuseEffect.cs | 112 + .../Canvas/Effects/SpotSpecularEffect.cs | 122 + .../Effects/TemperatureAndTintEffect.cs | 70 + .../Graphics/Canvas/Effects/TintEffect.cs | 61 + .../Canvas/Effects/Transform2DEffect.cs | 61 + 38 files changed, 2465 insertions(+), 2027 deletions(-) create mode 100644 src/Uno.UI.Composition/Composition/Effects/WhiteNoiseEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/CanvasComposite.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/CanvasEdgeBehavior.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/AlphaMaskEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/BlendEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/BlendEffectMode.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/BorderEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ColorMatrixEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ColorSourceEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/CompositeEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ContrastEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/CrossfadeEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/DistantDiffuseEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/DistantSpecularEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/EffectBorderMode.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/EffectOptimization.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ExposureEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/GammaTransferEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/GaussianBlurEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/GrayscaleEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/HueRotationEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/InvertEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/LinearTransferEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/LuminanceToAlphaEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/Matrix5x4.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/OpacityEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/PointDiffuseEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/PointSpecularEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SaturationEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SepiaEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SpotDiffuseEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SpotSpecularEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/TemperatureAndTintEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/TintEffect.cs create mode 100644 src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/Transform2DEffect.cs diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Composition/EffectBrushTests.xaml b/src/SamplesApp/UITests.Shared/Windows_UI_Composition/EffectBrushTests.xaml index 493f3601847d..95878c3cc23b 100644 --- a/src/SamplesApp/UITests.Shared/Windows_UI_Composition/EffectBrushTests.xaml +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Composition/EffectBrushTests.xaml @@ -39,5 +39,6 @@ + diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Composition/EffectBrushTests.xaml.cs b/src/SamplesApp/UITests.Shared/Windows_UI_Composition/EffectBrushTests.xaml.cs index cde56b5be815..c20aba8c3735 100644 --- a/src/SamplesApp/UITests.Shared/Windows_UI_Composition/EffectBrushTests.xaml.cs +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Composition/EffectBrushTests.xaml.cs @@ -1,29 +1,19 @@ using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; using System.Numerics; -using System.Runtime.InteropServices; using Uno.Extensions; using Uno.UI.Samples.Controls; -using Windows.Foundation; -using Windows.Foundation.Collections; -using Windows.Graphics.Effects; #if !WINDOWS_UWP // Making the sample buildable on UWP -using Windows.Graphics.Effects.Interop; +using Microsoft.Graphics.Canvas.Effects; #endif using Windows.UI; using Windows.UI.Composition; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml.Hosting; -using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Navigation; +using Microsoft.Graphics.Canvas; +using Windows.UI.Composition.Effects; // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 @@ -43,25 +33,25 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) #if !WINDOWS_UWP var compositor = Windows.UI.Xaml.Window.Current.Compositor; - var effect = new SimpleBlurEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), BlurAmount = 5.0f }; + var effect = new GaussianBlurEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), BlurAmount = 5.0f }; var factory = compositor.CreateEffectFactory(effect); var effectBrush = factory.CreateBrush(); blurGrid.Background = new EffectTesterBrush(effectBrush); - var effect2 = new SimpleGrayscaleEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }; + var effect2 = new GrayscaleEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }; var factory2 = compositor.CreateEffectFactory(effect2); var effectBrush2 = factory2.CreateBrush(); grayGrid.Background = new EffectTesterBrush(effectBrush2); - var effect3 = new SimpleInvertEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }; + var effect3 = new InvertEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }; var factory3 = compositor.CreateEffectFactory(effect3); var effectBrush3 = factory3.CreateBrush(); invertGrid.Background = new EffectTesterBrush(effectBrush3); - var effect4 = new SimpleHueRotationEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Angle = (float)MathEx.ToRadians(45) }; + var effect4 = new HueRotationEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Angle = (float)MathEx.ToRadians(45) }; var factory4 = compositor.CreateEffectFactory(effect4); var effectBrush4 = factory4.CreateBrush(); @@ -69,7 +59,7 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) // BEGIN: Aggregation Test - var effect5 = new SimpleGrayscaleEffect() { Source = effect }; + var effect5 = new GrayscaleEffect() { Source = effect }; var factory5 = compositor.CreateEffectFactory(effect5); var effectBrush5 = factory5.CreateBrush(); @@ -77,13 +67,13 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) aggregationGrid.Background = new EffectTesterBrush(effectBrush5); - var effect6 = new SimpleTintEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Color = Color.FromArgb(127, 66, 135, 245) }; + var effect6 = new TintEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Color = Color.FromArgb(127, 66, 135, 245) }; var factory6 = compositor.CreateEffectFactory(effect6); var effectBrush6 = factory6.CreateBrush(); tintGrid.Background = new EffectTesterBrush(effectBrush6); - var effect7 = new SimpleBlendEffect() { Background = new CompositionEffectSourceParameter("sourceBrush"), Foreground = new CompositionEffectSourceParameter("secondaryBrush"), Mode = D2D1BlendEffectMode.Color }; + var effect7 = new BlendEffect() { Background = new CompositionEffectSourceParameter("sourceBrush"), Foreground = new CompositionEffectSourceParameter("secondaryBrush"), Mode = BlendEffectMode.Luminosity /* this is actually BlendEffectMode.Color, see comment on D2D1BlendEffectMode*/ }; var factory7 = compositor.CreateEffectFactory(effect7); var effectBrush7 = factory7.CreateBrush(); @@ -96,7 +86,7 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) { var brush = compositor.CreateSurfaceBrush(surface); - var effect8 = new SimpleCompositeEffect() { Sources = { new CompositionEffectSourceParameter("secondaryBrush"), new CompositionEffectSourceParameter("sourceBrush") }, Mode = D2D1CompositeMode.SourceOver }; + var effect8 = new CompositeEffect() { Sources = { new CompositionEffectSourceParameter("secondaryBrush"), new CompositionEffectSourceParameter("sourceBrush") }, Mode = CanvasComposite.SourceOver }; var factory8 = compositor.CreateEffectFactory(effect8); var effectBrush8 = factory8.CreateBrush(); @@ -104,25 +94,25 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) } }; - var effect9 = new SimpleColorSourceEffect() { Color = Color.FromArgb(127, 66, 135, 245) }; + var effect9 = new ColorSourceEffect() { Color = Color.FromArgb(127, 66, 135, 245) }; var factory9 = compositor.CreateEffectFactory(effect9); var effectBrush9 = factory9.CreateBrush(); colorGrid.Background = new EffectTesterBrush(effectBrush9); - var effect10 = new SimpleOpacityEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Opacity = 0.2f }; + var effect10 = new OpacityEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Opacity = 0.2f }; var factory10 = compositor.CreateEffectFactory(effect10); var effectBrush10 = factory10.CreateBrush(); opacityGrid.Background = new EffectTesterBrush(effectBrush10); - var effect11 = new SimpleContrastEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Contrast = 2.0f }; + var effect11 = new ContrastEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Contrast = 2.0f }; var factory11 = compositor.CreateEffectFactory(effect11); var effectBrush11 = factory11.CreateBrush(); contrastGrid.Background = new EffectTesterBrush(effectBrush11); - var effect12 = new SimpleExposureEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Exposure = -1.0f }; + var effect12 = new ExposureEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Exposure = -1.0f }; var factory12 = compositor.CreateEffectFactory(effect12); var effectBrush12 = factory12.CreateBrush(); @@ -135,7 +125,7 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) { var brush = compositor.CreateSurfaceBrush(surface2); - var effect13 = new SimpleCrossfadeEffect() { Source1 = new CompositionEffectSourceParameter("sourceBrush"), Source2 = new CompositionEffectSourceParameter("secondaryBrush"), CrossFade = 0.5f }; + var effect13 = new CrossFadeEffect() { Source1 = new CompositionEffectSourceParameter("sourceBrush"), Source2 = new CompositionEffectSourceParameter("secondaryBrush"), CrossFade = 0.5f }; var factory13 = compositor.CreateEffectFactory(effect13); var effectBrush13 = factory13.CreateBrush(); @@ -143,49 +133,49 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) } }; - var effect14 = new SimpleLuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }; + var effect14 = new LuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }; var factory14 = compositor.CreateEffectFactory(effect14); var effectBrush14 = factory14.CreateBrush(); lumaGrid.Background = new EffectTesterBrush(effectBrush14); - var effect15 = new SimpleLinearTransferEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), RedOffset = -1.0f, RedSlope = 2.5f, GreenOffset = -1.0f, GreenSlope = 5.0f }; + var effect15 = new LinearTransferEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), RedOffset = -1.0f, RedSlope = 2.5f, GreenOffset = -1.0f, GreenSlope = 5.0f }; var factory15 = compositor.CreateEffectFactory(effect15); var effectBrush15 = factory15.CreateBrush(); linearXferGrid.Background = new EffectTesterBrush(effectBrush15); - var effect16 = new SimpleGammaTransferEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), RedExponent = 0.25f, GreenExponent = 0.25f, BlueExponent = 0.25f }; + var effect16 = new GammaTransferEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), RedExponent = 0.25f, GreenExponent = 0.25f, BlueExponent = 0.25f }; var factory16 = compositor.CreateEffectFactory(effect16); var effectBrush16 = factory16.CreateBrush(); gammaXferGrid.Background = new EffectTesterBrush(effectBrush16); - var effect17 = new SimpleBorderEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Extend = D2D1BorderEdgeMode.Wrap }; + var effect17 = new BorderEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), ExtendX = CanvasEdgeBehavior.Wrap }; var factory17 = compositor.CreateEffectFactory(effect17); var effectBrush17 = factory17.CreateBrush(); borderGrid.Background = new EffectTesterBrush(effectBrush17, 50); - var effect18 = new SimpleTransform2DEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), TransformMatrix = Matrix3x2.CreateRotation((float)MathEx.ToRadians(45), new(100, 100)) }; + var effect18 = new Transform2DEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), TransformMatrix = Matrix3x2.CreateRotation((float)MathEx.ToRadians(45), new(100, 100)) }; var factory18 = compositor.CreateEffectFactory(effect18); var effectBrush18 = factory18.CreateBrush(); t2dGrid.Background = new EffectTesterBrush(effectBrush18); - var effect19 = new SimpleSepiaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Intensity = 1.0f }; + var effect19 = new SepiaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Intensity = 1.0f }; var factory19 = compositor.CreateEffectFactory(effect19); var effectBrush19 = factory19.CreateBrush(); sepiaGrid.Background = new EffectTesterBrush(effectBrush19); - var effect20 = new SimpleTemperatureAndTintEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Temperature = 0.5f, Tint = 0.5f }; + var effect20 = new TemperatureAndTintEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Temperature = 0.5f, Tint = 0.5f }; var factory20 = compositor.CreateEffectFactory(effect20); var effectBrush20 = factory20.CreateBrush(); tempTintGrid.Background = new EffectTesterBrush(effectBrush20); - var swapRedAndBlue = new SimpleMatrix5x4 + var swapRedAndBlue = new Matrix5x4 { M11 = 0, M12 = 0, M13 = 1, M14 = 0, M21 = 0, M22 = 1, M23 = 0, M24 = 0, @@ -194,7 +184,7 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) M51 = 0, M52 = 0, M53 = 0, M54 = 0 }; - var effect21 = new SimpleColorMatrixEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), ColorMatrix = swapRedAndBlue }; + var effect21 = new ColorMatrixEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), ColorMatrix = swapRedAndBlue }; var factory21 = compositor.CreateEffectFactory(effect21); var effectBrush21 = factory21.CreateBrush(); @@ -207,7 +197,7 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) { var brush = compositor.CreateSurfaceBrush(surface3); - var effect22 = new SimpleDistantDiffuseEffect() { Source = new SimpleLuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }, DiffuseAmount = 5.0f, Azimuth = (float)MathEx.ToRadians(180.0f) }; + var effect22 = new DistantDiffuseEffect() { Source = new LuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }, DiffuseAmount = 5.0f, Azimuth = (float)MathEx.ToRadians(180.0f) }; var factory22 = compositor.CreateEffectFactory(effect22); var effectBrush22 = factory22.CreateBrush(); @@ -215,7 +205,7 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) ddGrid.Background = new XamlCompositionBrush(effectBrush22); - var effect23 = new SimpleDistantSpecularEffect() { Source = new SimpleLuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }, Azimuth = (float)MathEx.ToRadians(180.0f) }; + var effect23 = new DistantSpecularEffect() { Source = new LuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }, Azimuth = (float)MathEx.ToRadians(180.0f) }; var factory23 = compositor.CreateEffectFactory(effect23); var effectBrush23 = factory23.CreateBrush(); @@ -223,7 +213,7 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) dsGrid.Background = new XamlCompositionBrush(effectBrush23); - var effect24 = new SimpleSpotDiffuseEffect() { Source = new SimpleLuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }, DiffuseAmount = 5.0f, LimitingConeAngle = 0.25f, LightTarget = new Vector3(surface3.DecodedSize.ToVector2(), 0) / 2 }; + var effect24 = new SpotDiffuseEffect() { Source = new LuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }, DiffuseAmount = 5.0f, LimitingConeAngle = 0.25f, LightTarget = new Vector3(surface3.DecodedSize.ToVector2(), 0) / 2 }; var factory24 = compositor.CreateEffectFactory(effect24); var effectBrush24 = factory24.CreateBrush(); @@ -231,7 +221,7 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) sdGrid.Background = new XamlCompositionBrush(effectBrush24); - var effect25 = new SimpleSpotSpecularEffect() { Source = new SimpleLuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }, SpecularAmount = 1.25f, LimitingConeAngle = 0.25f, LightTarget = new Vector3(surface3.DecodedSize.ToVector2(), 0) / 2, LightColor = Colors.WhiteSmoke }; + var effect25 = new SpotSpecularEffect() { Source = new LuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }, SpecularAmount = 1.25f, LimitingConeAngle = 0.25f, LightTarget = new Vector3(surface3.DecodedSize.ToVector2(), 0) / 2, LightColor = Colors.WhiteSmoke }; var factory25 = compositor.CreateEffectFactory(effect25); var effectBrush25 = factory25.CreateBrush(); @@ -239,7 +229,7 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) ssGrid.Background = new XamlCompositionBrush(effectBrush25); - var effect26 = new SimplePointDiffuseEffect() { Source = new SimpleLuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }, DiffuseAmount = 1.25f, LightColor = Colors.WhiteSmoke }; + var effect26 = new PointDiffuseEffect() { Source = new LuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }, DiffuseAmount = 1.25f, LightColor = Colors.WhiteSmoke }; var factory26 = compositor.CreateEffectFactory(effect26); var effectBrush26 = factory26.CreateBrush(); @@ -247,7 +237,7 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) pdGrid.Background = new XamlCompositionBrush(effectBrush26); - var effect27 = new SimplePointSpecularEffect() { Source = new SimpleLuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }, SpecularAmount = 1.25f, LightColor = Colors.WhiteSmoke }; + var effect27 = new PointSpecularEffect() { Source = new LuminanceToAlphaEffect() { Source = new CompositionEffectSourceParameter("sourceBrush") }, SpecularAmount = 1.25f, LightColor = Colors.WhiteSmoke }; var factory27 = compositor.CreateEffectFactory(effect27); var effectBrush27 = factory27.CreateBrush(); @@ -257,7 +247,7 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) } }; - var effect28 = new SimpleAlphaMaskEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), AlphaMask = new CompositionEffectSourceParameter("maskBrush") }; + var effect28 = new AlphaMaskEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), AlphaMask = new CompositionEffectSourceParameter("maskBrush") }; var factory28 = compositor.CreateEffectFactory(effect28); var effectBrush28 = factory28.CreateBrush(); @@ -271,11 +261,17 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) maskGrid.Background = new EffectTesterBrush(effectBrush28); - var effect29 = new SimpleSaturationEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Saturation = 0.3f }; + var effect29 = new SaturationEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), Saturation = 0.3f }; var factory29 = compositor.CreateEffectFactory(effect29); var effectBrush29 = factory29.CreateBrush(); saturationGrid.Background = new EffectTesterBrush(effectBrush29); + + var effect30 = new WhiteNoiseEffect() { Frequency = new(1.04f) }; + var factory30 = compositor.CreateEffectFactory(effect30); + var effectBrush30 = factory30.CreateBrush(); + + noiseGrid.Background = new XamlCompositionBrush(effectBrush30); #endif } @@ -347,1989 +343,5 @@ protected override void OnConnected() CompositionBrush = _brush; } } - -#if !WINDOWS_UWP - [Guid("1FEB6D69-2FE6-4AC9-8C58-1D7F93E7A6A5")] - private class SimpleBlurEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleBlurEffect"; - private Guid _id = new Guid("1FEB6D69-2FE6-4AC9-8C58-1D7F93E7A6A5"); - - public string Name - { - get => _name; - set => _name = value; - } - - public IGraphicsEffectSource Source { get; set; } - - public float BlurAmount { get; set; } = 3.0f; - - public uint Optimization { get; set; } // enum - - public uint BorderMode { get; set; } // enum - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "BlurAmount": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "Optimization": - { - index = 1; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "BorderMode": - { - index = 2; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return BlurAmount; - case 1: - return Optimization; - case 2: - return BorderMode; - default: - return null; - } - } - - public uint GetPropertyCount() => 3; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("36DDE0EB-3725-42E0-836D-52FB20AEE644")] - private class SimpleGrayscaleEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleGrayscaleEffect"; - private Guid _id = new Guid("36DDE0EB-3725-42E0-836D-52FB20AEE644"); - - public string Name - { - get => _name; - set => _name = value; - } - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) => throw new NotSupportedException(); - - public object GetProperty(uint index) => throw new NotSupportedException(); - - public uint GetPropertyCount() => 0; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("E0C3784D-CB39-4E84-B6FD-6B72F0810263")] - private class SimpleInvertEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleInvertEffect"; - private Guid _id = new Guid("E0C3784D-CB39-4E84-B6FD-6B72F0810263"); - - public string Name - { - get => _name; - set => _name = value; - } - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) => throw new NotSupportedException(); - - public object GetProperty(uint index) => throw new NotSupportedException(); - - public uint GetPropertyCount() => 0; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("0F4458EC-4B32-491B-9E85-BD73F44D3EB6")] - private class SimpleHueRotationEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleHueRotationEffect"; - private Guid _id = new Guid("0F4458EC-4B32-491B-9E85-BD73F44D3EB6"); - - public string Name - { - get => _name; - set => _name = value; - } - - public float Angle { get; set; } = 0.0f; // Radians - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Angle": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Angle; - default: - return null; - } - } - - public uint GetPropertyCount() => 1; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("36312B17-F7DD-4014-915D-FFCA768CF211")] - private class SimpleTintEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleTintEffect"; - private Guid _id = new Guid("36312B17-F7DD-4014-915D-FFCA768CF211"); - - public string Name - { - get => _name; - set => _name = value; - } - - public Color Color { get; set; } = Color.FromArgb(255, 255, 255, 255); - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Color": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.ColorToVector4; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Color; - default: - return null; - } - } - - public uint GetPropertyCount() => 1; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("81C5B77B-13F8-4CDD-AD20-C890547AC65D")] - private class SimpleBlendEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleBlendEffect"; - private Guid _id = new Guid("81C5B77B-13F8-4CDD-AD20-C890547AC65D"); - - public string Name - { - get => _name; - set => _name = value; - } - - public D2D1BlendEffectMode Mode { get; set; } = D2D1BlendEffectMode.Multiply; - - public IGraphicsEffectSource Background { get; set; } - - public IGraphicsEffectSource Foreground { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Mode": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Mode; - default: - return null; - } - } - - public uint GetPropertyCount() => 1; - - public IGraphicsEffectSource GetSource(uint index) => index is 0 ? Background : Foreground; - - public uint GetSourceCount() => 2; - } - - [Guid("48FC9F51-F6AC-48F1-8B58-3B28AC46F76D")] - private class SimpleCompositeEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleCompositeEffect"; - private Guid _id = new Guid("48FC9F51-F6AC-48F1-8B58-3B28AC46F76D"); - - public string Name - { - get => _name; - set => _name = value; - } - - public D2D1CompositeMode Mode { get; set; } = D2D1CompositeMode.SourceOver; - - public List Sources { get; set; } = new(); - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Mode": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Mode; - default: - return null; - } - } - - public uint GetPropertyCount() => 1; - - public IGraphicsEffectSource GetSource(uint index) => index < Sources.Count ? Sources[(int)index] : null; - - public uint GetSourceCount() => (uint)Sources.Count; - } - - [Guid("61C23C20-AE69-4D8E-94CF-50078DF638F2")] - private class SimpleColorSourceEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleColorSourceEffect"; - private Guid _id = new Guid("61C23C20-AE69-4D8E-94CF-50078DF638F2"); - - public string Name - { - get => _name; - set => _name = value; - } - - public Color Color { get; set; } = Color.FromArgb(255, 255, 255, 255); - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Color": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.ColorToVector4; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Color; - default: - return null; - } - } - - public uint GetPropertyCount() => 1; - public IGraphicsEffectSource GetSource(uint index) => throw new InvalidOperationException(); - public uint GetSourceCount() => 0; - } - - [Guid("811D79A4-DE28-4454-8094-C64685F8BD4C")] - private class SimpleOpacityEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleOpacityEffect"; - private Guid _id = new Guid("811D79A4-DE28-4454-8094-C64685F8BD4C"); - - public string Name - { - get => _name; - set => _name = value; - } - - public float Opacity { get; set; } = 1.0f; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Opacity": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Opacity; - default: - return null; - } - } - - public uint GetPropertyCount() => 1; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("B648A78A-0ED5-4F80-A94A-8E825ACA6B77")] - private class SimpleContrastEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleContrastEffect"; - private Guid _id = new Guid("B648A78A-0ED5-4F80-A94A-8E825ACA6B77"); - - public string Name - { - get => _name; - set => _name = value; - } - - public float Contrast { get; set; } = 0.0f; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Contrast": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Contrast; - default: - return null; - } - } - - public uint GetPropertyCount() => 1; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("B56C8CFA-F634-41EE-BEE0-FFA617106004")] - private class SimpleExposureEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleExposureEffect"; - private Guid _id = new Guid("B56C8CFA-F634-41EE-BEE0-FFA617106004"); - - public string Name - { - get => _name; - set => _name = value; - } - - public float Exposure { get; set; } = 0.0f; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Exposure": - case "ExposureValue": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Exposure; - default: - return null; - } - } - - public uint GetPropertyCount() => 1; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("12F575E8-4DB1-485F-9A84-03A07DD3829F")] - private class SimpleCrossfadeEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleCrossfadeEffect"; - private Guid _id = new Guid("12F575E8-4DB1-485F-9A84-03A07DD3829F"); - - public string Name - { - get => _name; - set => _name = value; - } - - public float CrossFade { get; set; } = 0.5f; - - public IGraphicsEffectSource Source1 { get; set; } - - public IGraphicsEffectSource Source2 { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Weight": - case "CrossFade": - case "Crossfade": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return CrossFade; - default: - return null; - } - } - - public uint GetPropertyCount() => 1; - public IGraphicsEffectSource GetSource(uint index) => index is 0 ? Source1 : Source2; - public uint GetSourceCount() => 2; - } - - [Guid("41251AB7-0BEB-46F8-9DA7-59E93FCCE5DE")] - private class SimpleLuminanceToAlphaEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleLuminanceToAlphaEffect"; - private Guid _id = new Guid("41251AB7-0BEB-46F8-9DA7-59E93FCCE5DE"); - - public string Name - { - get => _name; - set => _name = value; - } - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) => throw new NotSupportedException(); - - public object GetProperty(uint index) => throw new NotSupportedException(); - - public uint GetPropertyCount() => 0; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("AD47C8FD-63EF-4ACC-9B51-67979C036C06")] - private class SimpleLinearTransferEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleLinearTransferEffect"; - private Guid _id = new Guid("AD47C8FD-63EF-4ACC-9B51-67979C036C06"); - - public string Name - { - get => _name; - set => _name = value; - } - - public float RedOffset { get; set; } = 0.0f; - - public float RedSlope { get; set; } = 1.0f; - - public bool RedDisable { get; set; } = false; - - - public float GreenOffset { get; set; } = 0.0f; - - public float GreenSlope { get; set; } = 1.0f; - - public bool GreenDisable { get; set; } = false; - - - public float BlueOffset { get; set; } = 0.0f; - - public float BlueSlope { get; set; } = 1.0f; - - public bool BlueDisable { get; set; } = false; - - - public float AlphaOffset { get; set; } = 0.0f; - - public float AlphaSlope { get; set; } = 1.0f; - - public bool AlphaDisable { get; set; } = false; - - - public bool ClampOutput { get; set; } = false; - - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "RedOffset": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "RedSlope": - { - index = 1; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "RedDisable": - { - index = 2; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "GreenOffset": - { - index = 3; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "GreenSlope": - { - index = 4; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "GreenDisable": - { - index = 5; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "BlueOffset": - { - index = 6; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "BlueSlope": - { - index = 7; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "BlueDisable": - { - index = 8; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "AlphaOffset": - { - index = 9; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "AlphaSlope": - { - index = 10; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "AlphaDisable": - { - index = 11; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "ClampOutput": - { - index = 12; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return RedOffset; - case 1: - return RedSlope; - case 2: - return RedDisable; - case 3: - return GreenOffset; - case 4: - return GreenSlope; - case 5: - return GreenDisable; - case 6: - return BlueOffset; - case 7: - return BlueSlope; - case 8: - return BlueDisable; - case 9: - return AlphaOffset; - case 10: - return AlphaSlope; - case 11: - return AlphaDisable; - case 12: - return ClampOutput; - default: - return null; - } - } - - public uint GetPropertyCount() => 13; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("409444C4-C419-41A0-B0C1-8CD0C0A18E42")] - private class SimpleGammaTransferEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleGammaTransferEffect"; - private Guid _id = new Guid("409444C4-C419-41A0-B0C1-8CD0C0A18E42"); - - public string Name - { - get => _name; - set => _name = value; - } - - public float RedAmplitude { get; set; } = 1.0f; - - public float RedExponent { get; set; } = 1.0f; - - public float RedOffset { get; set; } = 0.0f; - - public bool RedDisable { get; set; } = false; - - - public float GreenAmplitude { get; set; } = 1.0f; - - public float GreenExponent { get; set; } = 1.0f; - - public float GreenOffset { get; set; } = 0.0f; - - public bool GreenDisable { get; set; } = false; - - - public float BlueAmplitude { get; set; } = 1.0f; - - public float BlueExponent { get; set; } = 1.0f; - - public float BlueOffset { get; set; } = 0.0f; - - public bool BlueDisable { get; set; } = false; - - - public float AlphaAmplitude { get; set; } = 1.0f; - - public float AlphaExponent { get; set; } = 1.0f; - - public float AlphaOffset { get; set; } = 0.0f; - - public bool AlphaDisable { get; set; } = false; - - - public bool ClampOutput { get; set; } = false; - - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "RedAmplitude": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "RedExponent": - { - index = 1; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "RedOffset": - { - index = 2; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "RedDisable": - { - index = 3; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "GreenAmplitude": - { - index = 4; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "GreenExponent": - { - index = 5; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "GreenOffset": - { - index = 6; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "GreenDisable": - { - index = 7; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "BlueAmplitude": - { - index = 8; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "BlueExponent": - { - index = 9; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "BlueOffset": - { - index = 10; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "BlueDisable": - { - index = 11; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "AlphaAmplitude": - { - index = 12; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "AlphaExponent": - { - index = 13; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "AlphaOffset": - { - index = 14; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "AlphaDisable": - { - index = 15; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "ClampOutput": - { - index = 16; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return RedAmplitude; - case 1: - return RedExponent; - case 2: - return RedOffset; - case 3: - return RedDisable; - case 4: - return GreenAmplitude; - case 5: - return GreenExponent; - case 6: - return GreenOffset; - case 7: - return GreenDisable; - case 8: - return BlueAmplitude; - case 9: - return BlueExponent; - case 10: - return BlueOffset; - case 11: - return BlueDisable; - case 12: - return AlphaAmplitude; - case 13: - return AlphaExponent; - case 14: - return AlphaOffset; - case 15: - return AlphaDisable; - case 16: - return ClampOutput; - default: - return null; - } - } - - public uint GetPropertyCount() => 17; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("2A2D49C0-4ACF-43C7-8C6A-7C4A27874D27")] - private class SimpleBorderEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleBorderEffect"; - private Guid _id = new Guid("2A2D49C0-4ACF-43C7-8C6A-7C4A27874D27"); - - public string Name - { - get => _name; - set => _name = value; - } - - public D2D1BorderEdgeMode Extend { get; set; } = D2D1BorderEdgeMode.Clamp; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "ExtendX": - case "ExtendY": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Extend; - default: - return null; - } - } - - public uint GetPropertyCount() => 2; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("6AA97485-6354-4CFC-908C-E4A74F62C96C")] - private class SimpleTransform2DEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleTransform2DEffect"; - private Guid _id = new Guid("6AA97485-6354-4CFC-908C-E4A74F62C96C"); - - public string Name - { - get => _name; - set => _name = value; - } - - public Matrix3x2 TransformMatrix { get; set; } = Matrix3x2.Identity; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "TransformMatrix": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return TransformMatrix; - default: - return null; - } - } - - public uint GetPropertyCount() => 4; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("3A1AF410-5F1D-4DBE-84DF-915DA79B7153")] - private class SimpleSepiaEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleSepiaEffect"; - private Guid _id = new Guid("3A1AF410-5F1D-4DBE-84DF-915DA79B7153"); - - public string Name - { - get => _name; - set => _name = value; - } - - public float Intensity { get; set; } = 0.5f; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Intensity": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Intensity; - default: - return null; - } - } - - public uint GetPropertyCount() => 1; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("89176087-8AF9-4A08-AEB1-895F38DB1766")] - private class SimpleTemperatureAndTintEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleTemperatureAndTintEffect"; - private Guid _id = new Guid("89176087-8AF9-4A08-AEB1-895F38DB1766"); - - public string Name - { - get => _name; - set => _name = value; - } - - public float Temperature { get; set; } = 0.0f; - - public float Tint { get; set; } = 0.0f; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Temperature": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "Tint": - { - index = 1; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Temperature; - case 1: - return Tint; - default: - return null; - } - } - - public uint GetPropertyCount() => 2; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - private struct SimpleMatrix5x4 - { - public float M11; - public float M12; - public float M13; - public float M14; - public float M21; - public float M22; - public float M23; - public float M24; - public float M31; - public float M32; - public float M33; - public float M34; - public float M41; - public float M42; - public float M43; - public float M44; - public float M51; - public float M52; - public float M53; - public float M54; - - public static SimpleMatrix5x4 Identity - { - get => new SimpleMatrix5x4() - { - M11 = 1, M12 = 0, M13 = 0, M14 = 0, - M21 = 0, M22 = 1, M23 = 0, M24 = 0, - M31 = 0, M32 = 0, M33 = 1, M34 = 0, - M41 = 0, M42 = 0, M43 = 0, M44 = 1, - M51 = 0, M52 = 0, M53 = 0, M54 = 0 - }; - } - - public float[] ToArray() - { - return new float[20] - { - M11, M12, M13, M14, - M21, M22, M23, M24, - M31, M32, M33, M34, - M41, M42, M43, M44, - M51, M52, M53, M54 - }; - } - } - - [Guid("921F03D6-641C-47DF-852D-B4BB6153AE11")] - private class SimpleColorMatrixEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleColorMatrixEffect"; - private Guid _id = new Guid("921F03D6-641C-47DF-852D-B4BB6153AE11"); - - public string Name - { - get => _name; - set => _name = value; - } - - public SimpleMatrix5x4 ColorMatrix { get; set; } = SimpleMatrix5x4.Identity; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "ColorMatrix": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return ColorMatrix.ToArray(); - default: - return null; - } - } - - public uint GetPropertyCount() => 1; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("3E7EFD62-A32D-46D4-A83C-5278889AC954")] - private class SimpleDistantDiffuseEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleDistantDiffuseEffect"; - private Guid _id = new Guid("3E7EFD62-A32D-46D4-A83C-5278889AC954"); - - public string Name - { - get => _name; - set => _name = value; - } - - public float Azimuth { get; set; } = 0.0f; - - public float Elevation { get; set; } = 0.0f; - - public float DiffuseAmount { get; set; } = 1.0f; - - public Color LightColor { get; set; } = Colors.White; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Azimuth": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; - break; - } - case "Elevation": - { - index = 1; - mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; - break; - } - case "DiffuseAmount": - { - index = 2; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "LightColor": - { - index = 3; - mapping = GraphicsEffectPropertyMapping.ColorToVector3; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Azimuth; - case 1: - return Elevation; - case 2: - return DiffuseAmount; - case 3: - return LightColor; - default: - return null; - } - } - - public uint GetPropertyCount() => 4; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("428C1EE5-77B8-4450-8AB5-72219C21ABDA")] - private class SimpleDistantSpecularEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleDistantSpecularEffect"; - private Guid _id = new Guid("428C1EE5-77B8-4450-8AB5-72219C21ABDA"); - - public string Name - { - get => _name; - set => _name = value; - } - - public float Azimuth { get; set; } = 0.0f; - - public float Elevation { get; set; } = 0.0f; - - public float SpecularExponent { get; set; } = 1.0f; - - public float SpecularAmount { get; set; } = 1.0f; - - public Color LightColor { get; set; } = Colors.White; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Azimuth": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; - break; - } - case "Elevation": - { - index = 1; - mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; - break; - } - case "SpecularExponent": - { - index = 2; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "SpecularAmount": - { - index = 3; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "LightColor": - { - index = 4; - mapping = GraphicsEffectPropertyMapping.ColorToVector3; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Azimuth; - case 1: - return Elevation; - case 2: - return SpecularExponent; - case 3: - return SpecularAmount; - case 4: - return LightColor; - default: - return null; - } - } - - public uint GetPropertyCount() => 5; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("818A1105-7932-44F4-AA86-08AE7B2F2C93")] - private class SimpleSpotDiffuseEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleSpotDiffuseEffect"; - private Guid _id = new Guid("818A1105-7932-44F4-AA86-08AE7B2F2C93"); - - public string Name - { - get => _name; - set => _name = value; - } - - public Vector3 LightPosition { get; set; } = new(); - - public Vector3 LightTarget { get; set; } = new(); - - public float Focus { get; set; } = 1.0f; - - public float LimitingConeAngle { get; set; } = MathF.PI / 2.0f; - - public float DiffuseAmount { get; set; } = 1.0f; - - public Color LightColor { get; set; } = Colors.White; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "LightPosition": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "LightTarget": - { - index = 1; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "Focus": - { - index = 2; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "LimitingConeAngle": - { - index = 3; - mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; - break; - } - case "DiffuseAmount": - { - index = 4; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "LightColor": - { - index = 5; - mapping = GraphicsEffectPropertyMapping.ColorToVector3; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return LightPosition; - case 1: - return LightTarget; - case 2: - return Focus; - case 3: - return LimitingConeAngle; - case 4: - return DiffuseAmount; - case 5: - return LightColor; - default: - return null; - } - } - - public uint GetPropertyCount() => 6; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("EDAE421E-7654-4A37-9DB8-71ACC1BEB3C1")] - private class SimpleSpotSpecularEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleSpotSpecularEffect"; - private Guid _id = new Guid("EDAE421E-7654-4A37-9DB8-71ACC1BEB3C1"); - - public string Name - { - get => _name; - set => _name = value; - } - - public Vector3 LightPosition { get; set; } = new(); - - public Vector3 LightTarget { get; set; } = new(); - - public float Focus { get; set; } = 1.0f; - - public float LimitingConeAngle { get; set; } = MathF.PI / 2.0f; - - public float SpecularExponent { get; set; } = 1.0f; - - public float SpecularAmount { get; set; } = 1.0f; - - public Color LightColor { get; set; } = Colors.White; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "LightPosition": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "LightTarget": - { - index = 1; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "Focus": - { - index = 2; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "LimitingConeAngle": - { - index = 3; - mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; - break; - } - case "SpecularExponent": - { - index = 4; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "SpecularAmount": - { - index = 5; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "LightColor": - { - index = 6; - mapping = GraphicsEffectPropertyMapping.ColorToVector3; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return LightPosition; - case 1: - return LightTarget; - case 2: - return Focus; - case 3: - return LimitingConeAngle; - case 4: - return SpecularExponent; - case 5: - return SpecularAmount; - case 6: - return LightColor; - default: - return null; - } - } - - public uint GetPropertyCount() => 7; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("B9E303C3-C08C-4F91-8B7B-38656BC48C20")] - private class SimplePointDiffuseEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimplePointDiffuseEffect"; - private Guid _id = new Guid("B9E303C3-C08C-4F91-8B7B-38656BC48C20"); - - public string Name - { - get => _name; - set => _name = value; - } - - public Vector3 LightPosition { get; set; } = new(); - - public float DiffuseAmount { get; set; } = 1.0f; - - public Color LightColor { get; set; } = Colors.White; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "LightPosition": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "DiffuseAmount": - { - index = 1; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "LightColor": - { - index = 2; - mapping = GraphicsEffectPropertyMapping.ColorToVector3; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return LightPosition; - case 1: - return DiffuseAmount; - case 2: - return LightColor; - default: - return null; - } - } - - public uint GetPropertyCount() => 3; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("09C3CA26-3AE2-4F09-9EBC-ED3865D53F22")] - private class SimplePointSpecularEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimplePointSpecularEffect"; - private Guid _id = new Guid("09C3CA26-3AE2-4F09-9EBC-ED3865D53F22"); - - public string Name - { - get => _name; - set => _name = value; - } - - public Vector3 LightPosition { get; set; } = new(); - - public float SpecularExponent { get; set; } = 1.0f; - - public float SpecularAmount { get; set; } = 1.0f; - - public Color LightColor { get; set; } = Colors.White; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "LightPosition": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "SpecularExponent": - { - index = 1; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "SpecularAmount": - { - index = 2; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - case "LightColor": - { - index = 3; - mapping = GraphicsEffectPropertyMapping.ColorToVector3; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return LightPosition; - case 1: - return SpecularExponent; - case 2: - return SpecularAmount; - case 3: - return LightColor; - default: - return null; - } - } - - public uint GetPropertyCount() => 4; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } - - [Guid("C80ECFF0-3FD5-4F05-8328-C5D1724B4F0A")] - private class SimpleAlphaMaskEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleAlphaMaskEffect"; - private Guid _id = new Guid("C80ECFF0-3FD5-4F05-8328-C5D1724B4F0A"); - - public string Name - { - get => _name; - set => _name = value; - } - - public IGraphicsEffectSource AlphaMask { get; set; } - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) => throw new NotSupportedException(); - - public object GetProperty(uint index) => throw new NotSupportedException(); - - public uint GetPropertyCount() => 0; - public IGraphicsEffectSource GetSource(uint index) => index == 0 ? Source : AlphaMask; - public uint GetSourceCount() => 2; - } - - [Guid("5CB2D9CF-327D-459F-A0CE-40C0B2086BF7")] - private class SimpleSaturationEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop - { - private string _name = "SimpleSaturationEffect"; - private Guid _id = new Guid("5CB2D9CF-327D-459F-A0CE-40C0B2086BF7"); - - public string Name - { - get => _name; - set => _name = value; - } - - public float Saturation { get; set; } = 0.5f; - - public IGraphicsEffectSource Source { get; set; } - - public Guid GetEffectId() => _id; - - public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) - { - switch (name) - { - case "Saturation": - { - index = 0; - mapping = GraphicsEffectPropertyMapping.Direct; - break; - } - default: - { - index = 0xFF; - mapping = (GraphicsEffectPropertyMapping)0xFF; - break; - } - } - } - - public object GetProperty(uint index) - { - switch (index) - { - case 0: - return Saturation; - default: - return null; - } - } - - public uint GetPropertyCount() => 1; - public IGraphicsEffectSource GetSource(uint index) => Source; - public uint GetSourceCount() => 1; - } -#endif } } diff --git a/src/Uno.UI.Composition/Composition/CompositionEffectBrush.skia.cs b/src/Uno.UI.Composition/Composition/CompositionEffectBrush.skia.cs index 617058cb4d28..64ea63ea6677 100644 --- a/src/Uno.UI.Composition/Composition/CompositionEffectBrush.skia.cs +++ b/src/Uno.UI.Composition/Composition/CompositionEffectBrush.skia.cs @@ -1481,6 +1481,61 @@ half4 main() sourceFilter, new(bounds)); } + return null; + } + case EffectType.WhiteNoiseEffect: + { + if (effectInterop.GetPropertyCount() == 2) + { + effectInterop.GetNamedPropertyMapping("Frequency", out uint frequencyProp, out _); + effectInterop.GetNamedPropertyMapping("Offset", out uint offsetProp, out _); + + Vector2 frequency = (Vector2)effectInterop.GetProperty(frequencyProp); + Vector2 offset = (Vector2)effectInterop.GetProperty(offsetProp); + + string shader = $@" + uniform half2 frequency; + uniform half2 offset; + + half Hash(half2 p) + {{ + return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); + }} + + + half4 main(float2 coords) + {{ + float2 coord = coords * 0.81 * frequency + offset; + float2 px00 = floor(coord - 0.5) + 0.5; + float2 px11 = px00 + 1; + float2 px10 = float2(px11.x, px00.y); + float2 px01 = float2(px00.x, px11.y); + float2 factor = coord - px00; + float sample00 = Hash(px00); + float sample10 = Hash(px10); + float sample01 = Hash(px01); + float sample11 = Hash(px11); + float result = mix(mix(sample00, sample10, factor.x), mix(sample01, sample11, factor.x), factor.y); + + return half4(result.xxx, 1); + }} + "; + + SKRuntimeEffect runtimeEffect = SKRuntimeEffect.Create(shader, out string errors); + if (errors is not null) + { + return null; + } + + SKRuntimeEffectUniforms uniforms = new(runtimeEffect) + { + { "frequency", new float[2] { frequency.X, frequency.Y } }, + { "offset", new float[2] { offset.X, offset.Y } } + }; + + return SKImageFilter.CreatePaint(new SKPaint() { Shader = runtimeEffect.ToShader(false, uniforms), IsAntialias = true, FilterQuality = SKFilterQuality.High }, new(bounds)); + } + return null; } case EffectType.Unsupported: diff --git a/src/Uno.UI.Composition/Composition/Effects/WhiteNoiseEffect.cs b/src/Uno.UI.Composition/Composition/Effects/WhiteNoiseEffect.cs new file mode 100644 index 000000000000..e3ac373a53dd --- /dev/null +++ b/src/Uno.UI.Composition/Composition/Effects/WhiteNoiseEffect.cs @@ -0,0 +1,69 @@ +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Windows.UI.Composition.Effects +{ + [Guid("6152DFC6-9FBA-4810-8CBA-B280AA27BFF6")] + internal class WhiteNoiseEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "WhiteNoiseEffect"; + private Guid _id = new Guid("6152DFC6-9FBA-4810-8CBA-B280AA27BFF6"); + + public string Name + { + get => _name; + set => _name = value; + } + + public Vector2 Frequency { get; set; } = new(0.01f); + + public Vector2 Offset { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Frequency": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "Offset": + { + index = 1; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Frequency; + case 1: + return Offset; + default: + return null; + } + } + + public uint GetPropertyCount() => 2; + public IGraphicsEffectSource GetSource(uint index) => throw new NotSupportedException(); + public uint GetSourceCount() => 0; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/CanvasComposite.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/CanvasComposite.cs new file mode 100644 index 000000000000..db58ad2b7ce6 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/CanvasComposite.cs @@ -0,0 +1,19 @@ +namespace Microsoft.Graphics.Canvas +{ + public enum CanvasComposite + { + SourceOver = 0, + DestinationOver = 1, + SourceIn = 2, + DestinationIn = 3, + SourceOut = 4, + DestinationOut = 5, + SourceAtop = 6, + DestinationAtop = 7, + Xor = 8, + Add = 9, + Copy = 10, + BoundedCopy = 11, + MaskInvert = 12 + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/CanvasEdgeBehavior.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/CanvasEdgeBehavior.cs new file mode 100644 index 000000000000..d36419f8b8cd --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/CanvasEdgeBehavior.cs @@ -0,0 +1,10 @@ +namespace Microsoft.Graphics.Canvas +{ + public enum CanvasEdgeBehavior + { + Clamp = 0, + Wrap = 1, + Mirror = 2 + } +} + diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/AlphaMaskEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/AlphaMaskEffect.cs new file mode 100644 index 000000000000..2e12ff05d43e --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/AlphaMaskEffect.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("C80ECFF0-3FD5-4F05-8328-C5D1724B4F0A")] + public class AlphaMaskEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "AlphaMaskEffect"; + private Guid _id = new Guid("C80ECFF0-3FD5-4F05-8328-C5D1724B4F0A"); + + public string Name + { + get => _name; + set => _name = value; + } + + public IGraphicsEffectSource AlphaMask { get; set; } + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) => throw new NotSupportedException(); + + public object GetProperty(uint index) => throw new NotSupportedException(); + + public uint GetPropertyCount() => 0; + public IGraphicsEffectSource GetSource(uint index) => index == 0 ? Source : AlphaMask; + public uint GetSourceCount() => 2; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/BlendEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/BlendEffect.cs new file mode 100644 index 000000000000..68b1cc17bc42 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/BlendEffect.cs @@ -0,0 +1,64 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("81C5B77B-13F8-4CDD-AD20-C890547AC65D")] + public class BlendEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "BlendEffect"; + private Guid _id = new Guid("81C5B77B-13F8-4CDD-AD20-C890547AC65D"); + + public string Name + { + get => _name; + set => _name = value; + } + + public BlendEffectMode Mode { get; set; } = BlendEffectMode.Multiply; + + public IGraphicsEffectSource Background { get; set; } + + public IGraphicsEffectSource Foreground { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Mode": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Mode; + default: + return null; + } + } + + public uint GetPropertyCount() => 1; + + public IGraphicsEffectSource GetSource(uint index) => index is 0 ? Background : Foreground; + + public uint GetSourceCount() => 2; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/BlendEffectMode.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/BlendEffectMode.cs new file mode 100644 index 000000000000..0d6216b0f387 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/BlendEffectMode.cs @@ -0,0 +1,32 @@ +namespace Microsoft.Graphics.Canvas.Effects +{ + public enum BlendEffectMode + { + Multiply = 0, + Screen = 1, + Darken = 2, + Lighten = 3, + Dissolve = 4, + ColorBurn = 5, + LinearBurn = 6, + DarkerColor = 7, + LighterColor = 8, + ColorDodge = 9, + LinearDodge = 10, + Overlay = 11, + SoftLight = 12, + HardLight = 13, + VividLight = 14, + LinearLight = 15, + PinLight = 16, + HardMix = 17, + Difference = 18, + Exclusion = 19, + Hue = 20, + Saturation = 21, + Color = 22, + Luminosity = 23, + Subtract = 24, + Division = 25 + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/BorderEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/BorderEffect.cs new file mode 100644 index 000000000000..1f2a1c7516fb --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/BorderEffect.cs @@ -0,0 +1,70 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("2A2D49C0-4ACF-43C7-8C6A-7C4A27874D27")] + public class BorderEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "BorderEffect"; + private Guid _id = new Guid("2A2D49C0-4ACF-43C7-8C6A-7C4A27874D27"); + + public string Name + { + get => _name; + set => _name = value; + } + + public CanvasEdgeBehavior ExtendX { get; set; } = CanvasEdgeBehavior.Clamp; + + public CanvasEdgeBehavior ExtendY { get; set; } = CanvasEdgeBehavior.Clamp; + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "ExtendX": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "ExtendY": + { + index = 1; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return ExtendX; + case 1: + return ExtendY; + default: + return null; + } + } + + public uint GetPropertyCount() => 2; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ColorMatrixEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ColorMatrixEffect.cs new file mode 100644 index 000000000000..a1f6398f5c9f --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ColorMatrixEffect.cs @@ -0,0 +1,60 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("921F03D6-641C-47DF-852D-B4BB6153AE11")] + public class ColorMatrixEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "ColorMatrixEffect"; + private Guid _id = new Guid("921F03D6-641C-47DF-852D-B4BB6153AE11"); + + public string Name + { + get => _name; + set => _name = value; + } + + public Matrix5x4 ColorMatrix { get; set; } = Matrix5x4.Identity; + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "ColorMatrix": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return ColorMatrix.ToArray(); + default: + return null; + } + } + + public uint GetPropertyCount() => 1; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ColorSourceEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ColorSourceEffect.cs new file mode 100644 index 000000000000..3933548f4969 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ColorSourceEffect.cs @@ -0,0 +1,59 @@ +using System; +using System.Runtime.InteropServices; +using Windows.UI; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("61C23C20-AE69-4D8E-94CF-50078DF638F2")] + public class ColorSourceEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "ColorSourceEffect"; + private Guid _id = new Guid("61C23C20-AE69-4D8E-94CF-50078DF638F2"); + + public string Name + { + get => _name; + set => _name = value; + } + + public Color Color { get; set; } = Color.FromArgb(255, 255, 255, 255); + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Color": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.ColorToVector4; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Color; + default: + return null; + } + } + + public uint GetPropertyCount() => 1; + public IGraphicsEffectSource GetSource(uint index) => throw new InvalidOperationException(); + public uint GetSourceCount() => 0; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/CompositeEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/CompositeEffect.cs new file mode 100644 index 000000000000..3f3deca6cd2d --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/CompositeEffect.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("48FC9F51-F6AC-48F1-8B58-3B28AC46F76D")] + public class CompositeEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "CompositeEffect"; + private Guid _id = new Guid("48FC9F51-F6AC-48F1-8B58-3B28AC46F76D"); + + public string Name + { + get => _name; + set => _name = value; + } + + public CanvasComposite Mode { get; set; } = CanvasComposite.SourceOver; + + public List Sources { get; set; } = new(); + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Mode": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Mode; + default: + return null; + } + } + + public uint GetPropertyCount() => 1; + + public IGraphicsEffectSource GetSource(uint index) => index < Sources.Count ? Sources[(int)index] : null; + + public uint GetSourceCount() => (uint)Sources.Count; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ContrastEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ContrastEffect.cs new file mode 100644 index 000000000000..2dac808b7556 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ContrastEffect.cs @@ -0,0 +1,60 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("B648A78A-0ED5-4F80-A94A-8E825ACA6B77")] + public class ContrastEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "ContrastEffect"; + private Guid _id = new Guid("B648A78A-0ED5-4F80-A94A-8E825ACA6B77"); + + public string Name + { + get => _name; + set => _name = value; + } + + public float Contrast { get; set; } + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Contrast": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Contrast; + default: + return null; + } + } + + public uint GetPropertyCount() => 1; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/CrossfadeEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/CrossfadeEffect.cs new file mode 100644 index 000000000000..fa8a4b96e367 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/CrossfadeEffect.cs @@ -0,0 +1,64 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("12F575E8-4DB1-485F-9A84-03A07DD3829F")] + public class CrossFadeEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "CrossFadeEffect"; + private Guid _id = new Guid("12F575E8-4DB1-485F-9A84-03A07DD3829F"); + + public string Name + { + get => _name; + set => _name = value; + } + + public float CrossFade { get; set; } = 0.5f; + + public IGraphicsEffectSource Source1 { get; set; } + + public IGraphicsEffectSource Source2 { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Weight": + case "CrossFade": + case "Crossfade": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return CrossFade; + default: + return null; + } + } + + public uint GetPropertyCount() => 1; + public IGraphicsEffectSource GetSource(uint index) => index is 0 ? Source1 : Source2; + public uint GetSourceCount() => 2; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/DistantDiffuseEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/DistantDiffuseEffect.cs new file mode 100644 index 000000000000..32630190567a --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/DistantDiffuseEffect.cs @@ -0,0 +1,91 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; +using Windows.UI; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("3E7EFD62-A32D-46D4-A83C-5278889AC954")] + public class DistantDiffuseEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "DistantDiffuseEffect"; + private Guid _id = new Guid("3E7EFD62-A32D-46D4-A83C-5278889AC954"); + + public string Name + { + get => _name; + set => _name = value; + } + + public float Azimuth { get; set; } + + public float Elevation { get; set; } + + public float DiffuseAmount { get; set; } = 1.0f; + + public Color LightColor { get; set; } = Colors.White; + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Azimuth": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; + break; + } + case "Elevation": + { + index = 1; + mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; + break; + } + case "DiffuseAmount": + { + index = 2; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "LightColor": + { + index = 3; + mapping = GraphicsEffectPropertyMapping.ColorToVector3; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Azimuth; + case 1: + return Elevation; + case 2: + return DiffuseAmount; + case 3: + return LightColor; + default: + return null; + } + } + + public uint GetPropertyCount() => 4; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/DistantSpecularEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/DistantSpecularEffect.cs new file mode 100644 index 000000000000..201444fd4f94 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/DistantSpecularEffect.cs @@ -0,0 +1,101 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; +using Windows.UI; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("428C1EE5-77B8-4450-8AB5-72219C21ABDA")] + public class DistantSpecularEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "DistantSpecularEffect"; + private Guid _id = new Guid("428C1EE5-77B8-4450-8AB5-72219C21ABDA"); + + public string Name + { + get => _name; + set => _name = value; + } + + public float Azimuth { get; set; } + + public float Elevation { get; set; } + + public float SpecularExponent { get; set; } = 1.0f; + + public float SpecularAmount { get; set; } = 1.0f; + + public Color LightColor { get; set; } = Colors.White; + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Azimuth": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; + break; + } + case "Elevation": + { + index = 1; + mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; + break; + } + case "SpecularExponent": + { + index = 2; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "SpecularAmount": + { + index = 3; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "LightColor": + { + index = 4; + mapping = GraphicsEffectPropertyMapping.ColorToVector3; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Azimuth; + case 1: + return Elevation; + case 2: + return SpecularExponent; + case 3: + return SpecularAmount; + case 4: + return LightColor; + default: + return null; + } + } + + public uint GetPropertyCount() => 5; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/EffectBorderMode.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/EffectBorderMode.cs new file mode 100644 index 000000000000..845f92421b27 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/EffectBorderMode.cs @@ -0,0 +1,8 @@ +namespace Microsoft.Graphics.Canvas.Effects +{ + public enum EffectBorderMode + { + Soft = 0, + Hard = 1 + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/EffectOptimization.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/EffectOptimization.cs new file mode 100644 index 000000000000..7d8b8dfe15d7 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/EffectOptimization.cs @@ -0,0 +1,9 @@ +namespace Microsoft.Graphics.Canvas.Effects +{ + public enum EffectOptimization + { + Speed = 0, + Balanced = 1, + Quality = 2 + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ExposureEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ExposureEffect.cs new file mode 100644 index 000000000000..2412aa4ed785 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/ExposureEffect.cs @@ -0,0 +1,61 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("B56C8CFA-F634-41EE-BEE0-FFA617106004")] + public class ExposureEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "ExposureEffect"; + private Guid _id = new Guid("B56C8CFA-F634-41EE-BEE0-FFA617106004"); + + public string Name + { + get => _name; + set => _name = value; + } + + public float Exposure { get; set; } + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Exposure": + case "ExposureValue": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Exposure; + default: + return null; + } + } + + public uint GetPropertyCount() => 1; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/GammaTransferEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/GammaTransferEffect.cs new file mode 100644 index 000000000000..d157ff449170 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/GammaTransferEffect.cs @@ -0,0 +1,225 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("409444C4-C419-41A0-B0C1-8CD0C0A18E42")] + public class GammaTransferEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "GammaTransferEffect"; + private Guid _id = new Guid("409444C4-C419-41A0-B0C1-8CD0C0A18E42"); + + public string Name + { + get => _name; + set => _name = value; + } + + public float RedAmplitude { get; set; } = 1.0f; + + public float RedExponent { get; set; } = 1.0f; + + public float RedOffset { get; set; } + + public bool RedDisable { get; set; } + + + public float GreenAmplitude { get; set; } = 1.0f; + + public float GreenExponent { get; set; } = 1.0f; + + public float GreenOffset { get; set; } + + public bool GreenDisable { get; set; } + + + public float BlueAmplitude { get; set; } = 1.0f; + + public float BlueExponent { get; set; } = 1.0f; + + public float BlueOffset { get; set; } + + public bool BlueDisable { get; set; } + + + public float AlphaAmplitude { get; set; } = 1.0f; + + public float AlphaExponent { get; set; } = 1.0f; + + public float AlphaOffset { get; set; } + + public bool AlphaDisable { get; set; } + + + public bool ClampOutput { get; set; } + + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "RedAmplitude": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "RedExponent": + { + index = 1; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "RedOffset": + { + index = 2; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "RedDisable": + { + index = 3; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "GreenAmplitude": + { + index = 4; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "GreenExponent": + { + index = 5; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "GreenOffset": + { + index = 6; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "GreenDisable": + { + index = 7; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "BlueAmplitude": + { + index = 8; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "BlueExponent": + { + index = 9; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "BlueOffset": + { + index = 10; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "BlueDisable": + { + index = 11; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "AlphaAmplitude": + { + index = 12; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "AlphaExponent": + { + index = 13; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "AlphaOffset": + { + index = 14; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "AlphaDisable": + { + index = 15; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "ClampOutput": + { + index = 16; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return RedAmplitude; + case 1: + return RedExponent; + case 2: + return RedOffset; + case 3: + return RedDisable; + case 4: + return GreenAmplitude; + case 5: + return GreenExponent; + case 6: + return GreenOffset; + case 7: + return GreenDisable; + case 8: + return BlueAmplitude; + case 9: + return BlueExponent; + case 10: + return BlueOffset; + case 11: + return BlueDisable; + case 12: + return AlphaAmplitude; + case 13: + return AlphaExponent; + case 14: + return AlphaOffset; + case 15: + return AlphaDisable; + case 16: + return ClampOutput; + default: + return null; + } + } + + public uint GetPropertyCount() => 17; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/GaussianBlurEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/GaussianBlurEffect.cs new file mode 100644 index 000000000000..8b52113c24a3 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/GaussianBlurEffect.cs @@ -0,0 +1,80 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("1FEB6D69-2FE6-4AC9-8C58-1D7F93E7A6A5")] + public class GaussianBlurEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "GaussianBlurEffect"; + private Guid _id = new Guid("1FEB6D69-2FE6-4AC9-8C58-1D7F93E7A6A5"); + + public string Name + { + get => _name; + set => _name = value; + } + + public IGraphicsEffectSource Source { get; set; } + + public float BlurAmount { get; set; } = 3.0f; + + public EffectOptimization Optimization { get; set; } = EffectOptimization.Balanced; + + public EffectBorderMode BorderMode { get; set; } = EffectBorderMode.Soft; + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "BlurAmount": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "Optimization": + { + index = 1; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "BorderMode": + { + index = 2; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return BlurAmount; + case 1: + return (uint)Optimization; + case 2: + return (uint)BorderMode; + default: + return null; + } + } + + public uint GetPropertyCount() => 3; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/GrayscaleEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/GrayscaleEffect.cs new file mode 100644 index 000000000000..9428065a87a0 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/GrayscaleEffect.cs @@ -0,0 +1,32 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("36DDE0EB-3725-42E0-836D-52FB20AEE644")] + public class GrayscaleEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "GrayscaleEffect"; + private Guid _id = new Guid("36DDE0EB-3725-42E0-836D-52FB20AEE644"); + + public string Name + { + get => _name; + set => _name = value; + } + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) => throw new NotSupportedException(); + + public object GetProperty(uint index) => throw new NotSupportedException(); + + public uint GetPropertyCount() => 0; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/HueRotationEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/HueRotationEffect.cs new file mode 100644 index 000000000000..09a0a6c1c04f --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/HueRotationEffect.cs @@ -0,0 +1,60 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("0F4458EC-4B32-491B-9E85-BD73F44D3EB6")] + public class HueRotationEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "HueRotationEffect"; + private Guid _id = new Guid("0F4458EC-4B32-491B-9E85-BD73F44D3EB6"); + + public string Name + { + get => _name; + set => _name = value; + } + + public float Angle { get; set; } // Radians + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Angle": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Angle; + default: + return null; + } + } + + public uint GetPropertyCount() => 1; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/InvertEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/InvertEffect.cs new file mode 100644 index 000000000000..cf7d307eb696 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/InvertEffect.cs @@ -0,0 +1,32 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("E0C3784D-CB39-4E84-B6FD-6B72F0810263")] + public class InvertEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "InvertEffect"; + private Guid _id = new Guid("E0C3784D-CB39-4E84-B6FD-6B72F0810263"); + + public string Name + { + get => _name; + set => _name = value; + } + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) => throw new NotSupportedException(); + + public object GetProperty(uint index) => throw new NotSupportedException(); + + public uint GetPropertyCount() => 0; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/LinearTransferEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/LinearTransferEffect.cs new file mode 100644 index 000000000000..d46bcb6ce492 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/LinearTransferEffect.cs @@ -0,0 +1,185 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("AD47C8FD-63EF-4ACC-9B51-67979C036C06")] + public class LinearTransferEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "LinearTransferEffect"; + private Guid _id = new Guid("AD47C8FD-63EF-4ACC-9B51-67979C036C06"); + + public string Name + { + get => _name; + set => _name = value; + } + + public float RedOffset { get; set; } + + public float RedSlope { get; set; } = 1.0f; + + public bool RedDisable { get; set; } + + + public float GreenOffset { get; set; } + + public float GreenSlope { get; set; } = 1.0f; + + public bool GreenDisable { get; set; } + + + public float BlueOffset { get; set; } + + public float BlueSlope { get; set; } = 1.0f; + + public bool BlueDisable { get; set; } + + + public float AlphaOffset { get; set; } + + public float AlphaSlope { get; set; } = 1.0f; + + public bool AlphaDisable { get; set; } + + + public bool ClampOutput { get; set; } + + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "RedOffset": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "RedSlope": + { + index = 1; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "RedDisable": + { + index = 2; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "GreenOffset": + { + index = 3; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "GreenSlope": + { + index = 4; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "GreenDisable": + { + index = 5; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "BlueOffset": + { + index = 6; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "BlueSlope": + { + index = 7; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "BlueDisable": + { + index = 8; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "AlphaOffset": + { + index = 9; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "AlphaSlope": + { + index = 10; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "AlphaDisable": + { + index = 11; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "ClampOutput": + { + index = 12; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return RedOffset; + case 1: + return RedSlope; + case 2: + return RedDisable; + case 3: + return GreenOffset; + case 4: + return GreenSlope; + case 5: + return GreenDisable; + case 6: + return BlueOffset; + case 7: + return BlueSlope; + case 8: + return BlueDisable; + case 9: + return AlphaOffset; + case 10: + return AlphaSlope; + case 11: + return AlphaDisable; + case 12: + return ClampOutput; + default: + return null; + } + } + + public uint GetPropertyCount() => 13; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/LuminanceToAlphaEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/LuminanceToAlphaEffect.cs new file mode 100644 index 000000000000..ac708d29d79c --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/LuminanceToAlphaEffect.cs @@ -0,0 +1,32 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("41251AB7-0BEB-46F8-9DA7-59E93FCCE5DE")] + public class LuminanceToAlphaEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "LuminanceToAlphaEffect"; + private Guid _id = new Guid("41251AB7-0BEB-46F8-9DA7-59E93FCCE5DE"); + + public string Name + { + get => _name; + set => _name = value; + } + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) => throw new NotSupportedException(); + + public object GetProperty(uint index) => throw new NotSupportedException(); + + public uint GetPropertyCount() => 0; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/Matrix5x4.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/Matrix5x4.cs new file mode 100644 index 000000000000..1c272101caca --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/Matrix5x4.cs @@ -0,0 +1,70 @@ +namespace Microsoft.Graphics.Canvas.Effects +{ + public struct Matrix5x4 + { + public float M11; + public float M12; + public float M13; + public float M14; + public float M21; + public float M22; + public float M23; + public float M24; + public float M31; + public float M32; + public float M33; + public float M34; + public float M41; + public float M42; + public float M43; + public float M44; + public float M51; + public float M52; + public float M53; + public float M54; + + public static Matrix5x4 Identity => new Matrix5x4() + { + M11 = 1, + M12 = 0, + M13 = 0, + M14 = 0, + M21 = 0, + M22 = 1, + M23 = 0, + M24 = 0, + M31 = 0, + M32 = 0, + M33 = 1, + M34 = 0, + M41 = 0, + M42 = 0, + M43 = 0, + M44 = 1, + M51 = 0, + M52 = 0, + M53 = 0, + M54 = 0 + }; + + internal float[] ToArray() + { + return new float[20] + { + M11, M12, M13, M14, + M21, M22, M23, M24, + M31, M32, M33, M34, + M41, M42, M43, M44, + M51, M52, M53, M54 + }; + } + + public override bool Equals(object obj) => base.Equals(obj); + + public override int GetHashCode() => base.GetHashCode(); + + public static bool operator ==(Matrix5x4 left, Matrix5x4 right) => left.Equals(right); + + public static bool operator !=(Matrix5x4 left, Matrix5x4 right) => !(left == right); + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/OpacityEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/OpacityEffect.cs new file mode 100644 index 000000000000..0a193c04dd0c --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/OpacityEffect.cs @@ -0,0 +1,60 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("811D79A4-DE28-4454-8094-C64685F8BD4C")] + public class OpacityEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "OpacityEffect"; + private Guid _id = new Guid("811D79A4-DE28-4454-8094-C64685F8BD4C"); + + public string Name + { + get => _name; + set => _name = value; + } + + public float Opacity { get; set; } = 1.0f; + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Opacity": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Opacity; + default: + return null; + } + } + + public uint GetPropertyCount() => 1; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/PointDiffuseEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/PointDiffuseEffect.cs new file mode 100644 index 000000000000..f1ec69215cae --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/PointDiffuseEffect.cs @@ -0,0 +1,82 @@ +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; +using Windows.UI; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("B9E303C3-C08C-4F91-8B7B-38656BC48C20")] + public class PointDiffuseEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "PointDiffuseEffect"; + private Guid _id = new Guid("B9E303C3-C08C-4F91-8B7B-38656BC48C20"); + + public string Name + { + get => _name; + set => _name = value; + } + + public Vector3 LightPosition { get; set; } + + public float DiffuseAmount { get; set; } = 1.0f; + + public Color LightColor { get; set; } = Colors.White; + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "LightPosition": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "DiffuseAmount": + { + index = 1; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "LightColor": + { + index = 2; + mapping = GraphicsEffectPropertyMapping.ColorToVector3; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return LightPosition; + case 1: + return DiffuseAmount; + case 2: + return LightColor; + default: + return null; + } + } + + public uint GetPropertyCount() => 3; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/PointSpecularEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/PointSpecularEffect.cs new file mode 100644 index 000000000000..26a26c2e61cd --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/PointSpecularEffect.cs @@ -0,0 +1,92 @@ +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; +using Windows.UI; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("09C3CA26-3AE2-4F09-9EBC-ED3865D53F22")] + public class PointSpecularEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "PointSpecularEffect"; + private Guid _id = new Guid("09C3CA26-3AE2-4F09-9EBC-ED3865D53F22"); + + public string Name + { + get => _name; + set => _name = value; + } + + public Vector3 LightPosition { get; set; } + + public float SpecularExponent { get; set; } = 1.0f; + + public float SpecularAmount { get; set; } = 1.0f; + + public Color LightColor { get; set; } = Colors.White; + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "LightPosition": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "SpecularExponent": + { + index = 1; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "SpecularAmount": + { + index = 2; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "LightColor": + { + index = 3; + mapping = GraphicsEffectPropertyMapping.ColorToVector3; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return LightPosition; + case 1: + return SpecularExponent; + case 2: + return SpecularAmount; + case 3: + return LightColor; + default: + return null; + } + } + + public uint GetPropertyCount() => 4; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SaturationEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SaturationEffect.cs new file mode 100644 index 000000000000..83487c3d97ea --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SaturationEffect.cs @@ -0,0 +1,60 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("5CB2D9CF-327D-459F-A0CE-40C0B2086BF7")] + public class SaturationEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "SaturationEffect"; + private Guid _id = new Guid("5CB2D9CF-327D-459F-A0CE-40C0B2086BF7"); + + public string Name + { + get => _name; + set => _name = value; + } + + public float Saturation { get; set; } = 0.5f; + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Saturation": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Saturation; + default: + return null; + } + } + + public uint GetPropertyCount() => 1; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SepiaEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SepiaEffect.cs new file mode 100644 index 000000000000..6e8e3334a36a --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SepiaEffect.cs @@ -0,0 +1,60 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("3A1AF410-5F1D-4DBE-84DF-915DA79B7153")] + public class SepiaEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "SepiaEffect"; + private Guid _id = new Guid("3A1AF410-5F1D-4DBE-84DF-915DA79B7153"); + + public string Name + { + get => _name; + set => _name = value; + } + + public float Intensity { get; set; } = 0.5f; + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Intensity": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Intensity; + default: + return null; + } + } + + public uint GetPropertyCount() => 1; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SpotDiffuseEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SpotDiffuseEffect.cs new file mode 100644 index 000000000000..a886a681f481 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SpotDiffuseEffect.cs @@ -0,0 +1,112 @@ +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; +using Windows.UI; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("818A1105-7932-44F4-AA86-08AE7B2F2C93")] + public class SpotDiffuseEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "SpotDiffuseEffect"; + private Guid _id = new Guid("818A1105-7932-44F4-AA86-08AE7B2F2C93"); + + public string Name + { + get => _name; + set => _name = value; + } + + public Vector3 LightPosition { get; set; } + + public Vector3 LightTarget { get; set; } + + public float Focus { get; set; } = 1.0f; + + public float LimitingConeAngle { get; set; } = MathF.PI / 2.0f; + + public float DiffuseAmount { get; set; } = 1.0f; + + public Color LightColor { get; set; } = Colors.White; + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "LightPosition": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "LightTarget": + { + index = 1; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "Focus": + { + index = 2; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "LimitingConeAngle": + { + index = 3; + mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; + break; + } + case "DiffuseAmount": + { + index = 4; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "LightColor": + { + index = 5; + mapping = GraphicsEffectPropertyMapping.ColorToVector3; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return LightPosition; + case 1: + return LightTarget; + case 2: + return Focus; + case 3: + return LimitingConeAngle; + case 4: + return DiffuseAmount; + case 5: + return LightColor; + default: + return null; + } + } + + public uint GetPropertyCount() => 6; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SpotSpecularEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SpotSpecularEffect.cs new file mode 100644 index 000000000000..1ac003b204a8 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/SpotSpecularEffect.cs @@ -0,0 +1,122 @@ +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; +using Windows.UI; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("EDAE421E-7654-4A37-9DB8-71ACC1BEB3C1")] + public class SpotSpecularEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "SpotSpecularEffect"; + private Guid _id = new Guid("EDAE421E-7654-4A37-9DB8-71ACC1BEB3C1"); + + public string Name + { + get => _name; + set => _name = value; + } + + public Vector3 LightPosition { get; set; } + + public Vector3 LightTarget { get; set; } + + public float Focus { get; set; } = 1.0f; + + public float LimitingConeAngle { get; set; } = MathF.PI / 2.0f; + + public float SpecularExponent { get; set; } = 1.0f; + + public float SpecularAmount { get; set; } = 1.0f; + + public Color LightColor { get; set; } = Colors.White; + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "LightPosition": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "LightTarget": + { + index = 1; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "Focus": + { + index = 2; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "LimitingConeAngle": + { + index = 3; + mapping = GraphicsEffectPropertyMapping.RadiansToDegrees; + break; + } + case "SpecularExponent": + { + index = 4; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "SpecularAmount": + { + index = 5; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "LightColor": + { + index = 6; + mapping = GraphicsEffectPropertyMapping.ColorToVector3; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return LightPosition; + case 1: + return LightTarget; + case 2: + return Focus; + case 3: + return LimitingConeAngle; + case 4: + return SpecularExponent; + case 5: + return SpecularAmount; + case 6: + return LightColor; + default: + return null; + } + } + + public uint GetPropertyCount() => 7; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/TemperatureAndTintEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/TemperatureAndTintEffect.cs new file mode 100644 index 000000000000..8e3fb5f4d5cb --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/TemperatureAndTintEffect.cs @@ -0,0 +1,70 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("89176087-8AF9-4A08-AEB1-895F38DB1766")] + public class TemperatureAndTintEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "TemperatureAndTintEffect"; + private Guid _id = new Guid("89176087-8AF9-4A08-AEB1-895F38DB1766"); + + public string Name + { + get => _name; + set => _name = value; + } + + public float Temperature { get; set; } + + public float Tint { get; set; } + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Temperature": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + case "Tint": + { + index = 1; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Temperature; + case 1: + return Tint; + default: + return null; + } + } + + public uint GetPropertyCount() => 2; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/TintEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/TintEffect.cs new file mode 100644 index 000000000000..d4dee0e4efd5 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/TintEffect.cs @@ -0,0 +1,61 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; +using Windows.UI; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("36312B17-F7DD-4014-915D-FFCA768CF211")] + public class TintEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "TintEffect"; + private Guid _id = new Guid("36312B17-F7DD-4014-915D-FFCA768CF211"); + + public string Name + { + get => _name; + set => _name = value; + } + + public Color Color { get; set; } = Color.FromArgb(255, 255, 255, 255); + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "Color": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.ColorToVector4; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return Color; + default: + return null; + } + } + + public uint GetPropertyCount() => 1; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +} diff --git a/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/Transform2DEffect.cs b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/Transform2DEffect.cs new file mode 100644 index 000000000000..6ca1ad764351 --- /dev/null +++ b/src/Uno.UI.Composition/Win2D/Microsoft/Graphics/Canvas/Effects/Transform2DEffect.cs @@ -0,0 +1,61 @@ +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using Windows.Graphics.Effects; +using Windows.Graphics.Effects.Interop; + +namespace Microsoft.Graphics.Canvas.Effects +{ + [Guid("6AA97485-6354-4CFC-908C-E4A74F62C96C")] + public class Transform2DEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop + { + private string _name = "Transform2DEffect"; + private Guid _id = new Guid("6AA97485-6354-4CFC-908C-E4A74F62C96C"); + + public string Name + { + get => _name; + set => _name = value; + } + + public Matrix3x2 TransformMatrix { get; set; } = Matrix3x2.Identity; + + public IGraphicsEffectSource Source { get; set; } + + public Guid GetEffectId() => _id; + + public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping) + { + switch (name) + { + case "TransformMatrix": + { + index = 0; + mapping = GraphicsEffectPropertyMapping.Direct; + break; + } + default: + { + index = 0xFF; + mapping = (GraphicsEffectPropertyMapping)0xFF; + break; + } + } + } + + public object GetProperty(uint index) + { + switch (index) + { + case 0: + return TransformMatrix; + default: + return null; + } + } + + public uint GetPropertyCount() => 4; + public IGraphicsEffectSource GetSource(uint index) => Source; + public uint GetSourceCount() => 1; + } +}