Skip to content

Commit

Permalink
feat(composition): Implement AcrylicBrush!
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed605 committed Mar 2, 2024
1 parent 260ebeb commit 2ec862b
Show file tree
Hide file tree
Showing 9 changed files with 583 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid x:Name="Example3Grid" MinWidth="320" MinHeight="200">
<Grid x:Name="Example3Grid" MinWidth="320" MinHeight="200" Padding="50">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="250"/>
Expand All @@ -18,7 +18,7 @@
<Ellipse Fill="Magenta" Height="150" Width="150" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Rectangle Fill="Yellow" Height="100" Width="80" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
</Grid>
<Border x:Name="CustomAcrylicShapeInApp" Margin="12">
<Border x:Name="CustomAcrylicShapeInApp" Margin="12" CornerRadius="12">
<Border.Background>
<AcrylicBrush BackgroundSource="Backdrop" TintOpacity="0.5" TintColor="Red" FallbackColor="Green" />
</Border.Background>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public partial class CompositionEffectBrush : CompositionBrush

internal bool HasBackdropBrushInput { get; private set; }

internal bool UseBlurPadding { get; set; }

private SKImageFilter? GenerateEffectFilter(object effect, SKRect bounds)
{
// TODO: https://user-images.githubusercontent.com/34550324/264485558-d7ee5062-b0e0-4f6e-a8c7-0620ec561d3d.png
Expand Down Expand Up @@ -71,7 +73,7 @@ public partial class CompositionEffectBrush : CompositionBrush
_ = (uint)effectInterop.GetProperty(optProp); // TODO
_ = (uint)effectInterop.GetProperty(borderProp); // TODO

return SKImageFilter.CreateBlur(sigma, sigma, sourceFilter, new(bounds));
return SKImageFilter.CreateBlur(sigma, sigma, sourceFilter, new(UseBlurPadding ? bounds with { Left = -100, Top = -100, Right = bounds.Right + 100, Bottom = bounds.Bottom + 100 } : bounds));
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private static SKPaint TryCreateAndClearPaint(in DrawingSession session, ref SKP
paint.IsStroke = isStroke;
paint.IsAntialias = true;
paint.IsAutohinted = true;
paint.FilterQuality = SKFilterQuality.High;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ internal SkiaCompositionSurface(SKImage image)
this.Log().Debug($"Image load result {result}");
}

if (result == SKCodecResult.Success)
{
_image = SKImage.FromBitmap(bitmap);
}

return (result == SKCodecResult.Success || result == SKCodecResult.IncompleteInput, result);
}
else
Expand Down
Binary file added src/Uno.UI/Resources/NoiseAsset256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/Uno.UI/UI/Xaml/Media/AcrylicBrush/AcrylicBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.UI.Xaml.Media
/// Paints an area with a semi-transparent material that uses multiple
/// effects including blur and a noise texture.
/// </summary>
/// <remarks>Currently uses blurring only in Uno.</remarks>
/// <remarks>Currently uses blurring only in non-Skia Uno heads.</remarks>
public partial class AcrylicBrush : XamlCompositionBrushBase
{
/// <summary>
Expand Down Expand Up @@ -116,9 +116,9 @@ public bool AlwaysUseFallback
typeof(AcrylicBrush),
new FrameworkPropertyMetadata(
// Due to the fact that additional subviews are added to acrylic owner views
// on non-WASM platforms, we default to using fallback where not completely safe
// on platforms other than WASM and Skia, we default to using fallback where not completely safe
// When this is explicitly set to false, Acrylic will be displayed
#if __WASM__
#if __WASM__ || __SKIA__
false
#else
true
Expand Down
Loading

0 comments on commit 2ec862b

Please sign in to comment.