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): Initial work on Composition effects
- Loading branch information
Showing
10 changed files
with
178 additions
and
130 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/Uno.UI.Composition/Composition/CompositionEffectBrush.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,31 @@ | ||
using Windows.Graphics.Effects; | ||
using System.Collections.Generic; | ||
|
||
namespace Windows.UI.Composition | ||
{ | ||
public partial class CompositionEffectBrush : CompositionBrush | ||
{ | ||
private IGraphicsEffect _effect; | ||
//private IEnumerable<string> _animatableProperties; // TODO: Uncomment and implement this when we implement Composition animations | ||
|
||
private Dictionary<string, CompositionBrush> _sourceParameters; | ||
|
||
internal CompositionEffectBrush(IGraphicsEffect graphicsEffect, IEnumerable<string> animatableProperties = null) | ||
{ | ||
_effect = graphicsEffect; | ||
//_animatableProperties = animatableProperties; // TODO (see the TODO note above) | ||
|
||
_sourceParameters = new(); | ||
} | ||
|
||
public CompositionBrush GetSourceParameter(string name) | ||
{ | ||
if (_sourceParameters.TryGetValue(name, out var result)) | ||
return result; | ||
|
||
return null; | ||
} | ||
|
||
public void SetSourceParameter(string name, CompositionBrush source) => _sourceParameters[name] = source; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Uno.UI.Composition/Composition/CompositionEffectBrush.skia.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,44 @@ | ||
using Windows.Graphics.Effects; | ||
using System; | ||
using SkiaSharp; | ||
|
||
namespace Windows.UI.Composition | ||
{ | ||
public partial class CompositionEffectBrush : CompositionBrush | ||
{ | ||
private SKImageFilter GenerateEffectFilter(object effect, SKRect bounds) | ||
{ | ||
// TODO: https://user-images.githubusercontent.com/34550324/264485558-d7ee5062-b0e0-4f6e-a8c7-0620ec561d3d.png | ||
|
||
switch (effect) | ||
{ | ||
case CompositionEffectSourceParameter effectSourceParameter: | ||
{ | ||
CompositionBrush brush = GetSourceParameter(effectSourceParameter.Name); | ||
if (brush is not null) | ||
{ | ||
SKPaint paint = new SKPaint() { IsAntialias = true, IsAutohinted = true, FilterQuality = SKFilterQuality.High }; | ||
brush.UpdatePaint(paint, bounds); | ||
|
||
return SKImageFilter.CreatePaint(paint, new SKImageFilter.CropRect(bounds)); | ||
} | ||
else | ||
return null; | ||
} | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
internal override void UpdatePaint(SKPaint paint, SKRect bounds) | ||
{ | ||
SKImageFilter filter = GenerateEffectFilter(_effect, bounds); | ||
if (filter is null) | ||
throw new NotSupportedException("The specified IGraphicsEffect is not supported"); // TODO: Replicate Windows' behavior | ||
|
||
paint.Shader = null; | ||
paint.ImageFilter = filter; | ||
paint.FilterQuality = SKFilterQuality.High; | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Uno.UI.Composition/Composition/CompositionEffectFactory.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,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Windows.Graphics.Effects; | ||
|
||
namespace Windows.UI.Composition | ||
{ | ||
public partial class CompositionEffectFactory : CompositionObject | ||
{ | ||
private IGraphicsEffect _effect; | ||
private IEnumerable<string> _animatableProperties; | ||
|
||
private CompositionEffectFactoryLoadStatus _loadStatus; | ||
private Exception _extendedError; | ||
|
||
internal CompositionEffectFactory(IGraphicsEffect effect, IEnumerable<string> animatableProperties = null) | ||
{ | ||
if (effect is null) | ||
throw new ArgumentNullException(nameof(effect)); | ||
|
||
_effect = effect; | ||
_animatableProperties = animatableProperties; | ||
} | ||
|
||
public CompositionEffectBrush CreateBrush() => new(_effect, _animatableProperties); | ||
|
||
public CompositionEffectFactoryLoadStatus LoadStatus => _loadStatus; | ||
public Exception ExtendedError => _extendedError; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Uno.UI.Composition/Composition/CompositionEffectSourceParameter.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,13 @@ | ||
using Windows.Graphics.Effects; | ||
|
||
namespace Windows.UI.Composition | ||
{ | ||
public partial class CompositionEffectSourceParameter : IGraphicsEffectSource | ||
{ | ||
private string _name; | ||
|
||
public CompositionEffectSourceParameter(string name) => _name = name; | ||
|
||
public string Name => _name; | ||
} | ||
} |
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
105 changes: 47 additions & 58 deletions
105
src/Uno.UI.Composition/Generated/3.0.0.0/Microsoft.UI.Composition/Compositor.cs
Large diffs are not rendered by default.
Oops, something went wrong.
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