forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(composition): More work on Composition effects + working sample
- Loading branch information
Showing
13 changed files
with
405 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/SamplesApp/UITests.Shared/Windows_UI_Composition/EffectBrushTests.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<UserControl | ||
x:Class="UITests.Windows_UI_Composition.EffectBrushTests" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:UITests.Windows_UI_Composition" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
d:DesignHeight="300" | ||
d:DesignWidth="400"> | ||
|
||
<Grid> | ||
<Grid x:Name="testGrid" Width="200" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left"/> | ||
</Grid> | ||
</UserControl> |
139 changes: 139 additions & 0 deletions
139
src/SamplesApp/UITests.Shared/Windows_UI_Composition/EffectBrushTests.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using Uno.UI.Samples.Controls; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.Graphics.Effects; | ||
using Windows.Graphics.Effects.Interop; | ||
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; | ||
|
||
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 | ||
|
||
namespace UITests.Windows_UI_Composition | ||
{ | ||
[Sample("Windows.UI.Composition", Name = "CompositionEffectBrush", Description = "", IsManualTest = true)] | ||
public sealed partial class EffectBrushTests : UserControl | ||
{ | ||
public EffectBrushTests() | ||
{ | ||
this.InitializeComponent(); | ||
this.Loaded += EffectBrushTests_Loaded; | ||
} | ||
|
||
private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
testGrid.Background = new TestBrush(); | ||
} | ||
|
||
private class TestBrush : Windows.UI.Xaml.Media.XamlCompositionBrushBase | ||
{ | ||
protected override void OnConnected() | ||
{ | ||
var compositor = Window.Current.Compositor; | ||
var surface = LoadedImageSurface.StartLoadFromUri(new Uri("https://avatars.githubusercontent.com/u/52228309?s=200&v=4")); | ||
surface.LoadCompleted += (s, o) => | ||
{ | ||
if (o.Status == LoadedImageSourceLoadStatus.Success) | ||
{ | ||
var brush = compositor.CreateSurfaceBrush(surface); | ||
var effect = new SimpleBlurEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), BlurAmount = 5.0f }; | ||
var factory = compositor.CreateEffectFactory(effect); | ||
var effectBrush = factory.CreateBrush(); | ||
|
||
effectBrush.SetSourceParameter("sourceBrush", brush); | ||
CompositionBrush = effectBrush; | ||
} | ||
}; | ||
} | ||
} | ||
|
||
#if WINDOWS_UWP | ||
private interface IGraphicsEffectD2D1Interop { } | ||
#endif | ||
|
||
[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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Windows.Graphics.Effects | ||
{ | ||
/// <summary> | ||
/// This enum specifies Direct2D blend modes supported by Composition APIs<br/> | ||
/// Note that Color and Luminosity values are switched to follow the current behavior (which is a bug) on Windows<br/><br/> | ||
/// <remarks> | ||
/// References:<br/> | ||
/// 1- <see href="https://microsoft.github.io/Win2D/WinUI2/html/T_Microsoft_Graphics_Canvas_Effects_BlendEffectMode.htm"/><br/> | ||
/// 2- wuceffects.dll!Windows::UI::Composition::g_pszModeNames | ||
/// </remarks> | ||
/// </summary> | ||
internal enum D2D1BlendEffectMode | ||
{ | ||
Multiply = 0, | ||
Screen = 1, | ||
Darken = 2, | ||
Lighten = 3, | ||
//Dissolve = 4, // Note: Composition doesn't support Dissolve yet (as of 10.0.25941.1000) | ||
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, // Note: Composition supports Hue since 19H1, docs are outdated | ||
Saturation = 21, // Note: Composition supports Saturation since 19H1, docs are outdated | ||
Luminosity = 22, // Note: Composition supports Luminosity since 19H1, docs are outdated | ||
Color = 23, // Note: Composition supports Color since 19H1, docs are outdated | ||
Subtract = 24, | ||
Division = 25 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Windows.Graphics.Effects | ||
{ | ||
/// <summary> | ||
/// This enum specifies Direct2D composite modes supported by Composition APIs<br/><br/> | ||
/// <remarks> | ||
/// References:<br/> | ||
/// 1- <see href="https://microsoft.github.io/Win2D/WinUI2/html/T_Microsoft_Graphics_Canvas_CanvasComposite.htm"/><br/> | ||
/// 2- wuceffects.dll!Windows::UI::Composition::g_pszModeNames_0 | ||
/// </remarks> | ||
/// </summary> | ||
internal enum D2D1CompositeMode | ||
{ | ||
SourceOver = 0, | ||
DestinationOver = 1, | ||
SourceIn = 2, | ||
DestinationIn = 3, | ||
SourceOut = 4, | ||
DestinationOut = 5, | ||
SourceAtop = 6, | ||
DestinationAtop = 7, | ||
Xor = 8, | ||
Add = 9, // Plus | ||
Copy = 10, // SourceCopy | ||
//BoundedCopy = 11, // Note: Composition doesn't support BoundedCopy yet (as of 10.0.25941.1000) | ||
MaskInvert = 12 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.