From 5326fda7ec7817ab991b07969820ece2ec47a648 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 6 Jan 2023 17:16:03 +0000 Subject: [PATCH] some hacks to test hdr --- samples/ControlCatalog/ControlCatalog.csproj | 3 +- samples/ControlCatalog/MainView.xaml | 229 +----------------- samples/ControlCatalog/MainView.xaml.cs | 92 +++---- src/Skia/Avalonia.Skia/DrawingContextImpl.cs | 1 + .../Gpu/OpenGl/GlRenderTarget.cs | 1 + .../Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs | 6 +- .../WinUiCompositedWindowSurface.cs | 4 +- 7 files changed, 41 insertions(+), 295 deletions(-) diff --git a/samples/ControlCatalog/ControlCatalog.csproj b/samples/ControlCatalog/ControlCatalog.csproj index 18f0dd16ba..29c8a51af1 100644 --- a/samples/ControlCatalog/ControlCatalog.csproj +++ b/samples/ControlCatalog/ControlCatalog.csproj @@ -1,6 +1,6 @@  - netstandard2.0;net6.0 + net6.0 true enable @@ -30,6 +30,7 @@ + diff --git a/samples/ControlCatalog/MainView.xaml b/samples/ControlCatalog/MainView.xaml index 166b98436e..bd5ec010fe 100644 --- a/samples/ControlCatalog/MainView.xaml +++ b/samples/ControlCatalog/MainView.xaml @@ -6,232 +6,5 @@ xmlns:pages="using:ControlCatalog.Pages" xmlns:viewModels="using:ControlCatalog.ViewModels" x:DataType="viewModels:MainWindowViewModel"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - None - BorderOnly - Full - - - - - FluentLight - FluentDark - SimpleLight - SimpleDark - - - - - None - Transparent - Blur - AcrylicBlur - Mica - - - - - LeftToRight - RightToLeft - - - - - - - - + diff --git a/samples/ControlCatalog/MainView.xaml.cs b/samples/ControlCatalog/MainView.xaml.cs index f3c1a68e72..604e0eba51 100644 --- a/samples/ControlCatalog/MainView.xaml.cs +++ b/samples/ControlCatalog/MainView.xaml.cs @@ -1,12 +1,17 @@ using System; using System.Collections; +using System.Runtime.InteropServices; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Controls.Documents; using Avalonia.Markup.Xaml; using Avalonia.Media; +using Avalonia.Media.Imaging; using Avalonia.Media.Immutable; +using Avalonia.Platform; using Avalonia.VisualTree; +using CommunityToolkit.HighPerformance; using ControlCatalog.Models; using ControlCatalog.Pages; @@ -18,77 +23,40 @@ namespace ControlCatalog { AvaloniaXamlLoader.Load(this); - var sideBar = this.Get("Sidebar"); + + } - if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime) - { - var tabItems = (sideBar.Items as IList); - tabItems?.Add(new TabItem() - { - Header = "Screens", - Content = new ScreenPage() - }); - } + [StructLayout(LayoutKind.Sequential)] + struct FPixel + { + public Half R { get; set; } + public Half G { get; set; } + public Half B { get; set; } + public Half A { get; set; } + } - var themes = this.Get("Themes"); - themes.SelectedItem = App.CurrentTheme; - themes.SelectionChanged += (sender, e) => + protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) + { + unsafe { - if (themes.SelectedItem is CatalogTheme theme) - { - App.SetThemeVariant(theme); - } - }; + base.OnAttachedToVisualTree(e); - var flowDirections = this.Get("FlowDirection"); - flowDirections.SelectionChanged += (sender, e) => - { - if (flowDirections.SelectedItem is FlowDirection flowDirection) - { - this.FlowDirection = flowDirection; - } - }; + var image = this.Find("PART_Image"); - var decorations = this.Get("Decorations"); - decorations.SelectionChanged += (sender, e) => - { - if (VisualRoot is Window window - && decorations.SelectedItem is SystemDecorations systemDecorations) - { - window.SystemDecorations = systemDecorations; - } - }; + var bmp = new WriteableBitmap(new PixelSize(100, 100), new Vector(96, 96), PixelFormat.RgbaF16); - var transparencyLevels = this.Get("TransparencyLevels"); - IDisposable? topLevelBackgroundSideSetter = null, sideBarBackgroundSetter = null, paneBackgroundSetter = null; - transparencyLevels.SelectionChanged += (sender, e) => - { - topLevelBackgroundSideSetter?.Dispose(); - sideBarBackgroundSetter?.Dispose(); - paneBackgroundSetter?.Dispose(); - if (transparencyLevels.SelectedItem is WindowTransparencyLevel selected) - { - var topLevel = (TopLevel)this.GetVisualRoot()!; - topLevel.TransparencyLevelHint = selected; + using var framebuffer = bmp.Lock(); - if (selected != WindowTransparencyLevel.None) - { - var transparentBrush = new ImmutableSolidColorBrush(Colors.White, 0); - var semiTransparentBrush = new ImmutableSolidColorBrush(Colors.Gray, 0.2); - topLevelBackgroundSideSetter = topLevel.SetValue(BackgroundProperty, transparentBrush, Avalonia.Data.BindingPriority.Style); - sideBarBackgroundSetter = sideBar.SetValue(BackgroundProperty, semiTransparentBrush, Avalonia.Data.BindingPriority.Style); - paneBackgroundSetter = sideBar.SetValue(SplitView.PaneBackgroundProperty, semiTransparentBrush, Avalonia.Data.BindingPriority.Style); - } + var span = new Span(framebuffer.Address.ToPointer(), 100 * 100); + + for (int i = 0; i < (100 * 100); i++) + { + span[i].R = (Half)1.0f; + span[i].A = (Half)1.0f; } - }; - } - protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) - { - base.OnAttachedToVisualTree(e); - var decorations = this.Get("Decorations"); - if (VisualRoot is Window window) - decorations.SelectedIndex = (int)window.SystemDecorations; + image.Source = bmp; + } } } } diff --git a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs index 48e8c761eb..d8609b3ffd 100644 --- a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs +++ b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs @@ -1168,6 +1168,7 @@ namespace Avalonia.Skia private SurfaceRenderTarget CreateRenderTarget(Size size, bool isLayer, PixelFormat? format = null) { var pixelSize = PixelSize.FromSizeWithDpi(size, _dpi); + format = PixelFormat.RgbaF16; var createInfo = new SurfaceRenderTarget.CreateInfo { Width = pixelSize.Width, diff --git a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs index 5bf1272c2f..72eefe171c 100644 --- a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs +++ b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs @@ -45,6 +45,7 @@ namespace Avalonia.Skia } public void Dispose() { + _surface.Canvas.Clear(new SKColorF(1,1,1,1)); _surface.Canvas.Flush(); _surface.Dispose(); _backendRenderTarget.Dispose(); diff --git a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs index cdba3b9ea2..cd2b8630dd 100644 --- a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs +++ b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs @@ -75,8 +75,10 @@ namespace Avalonia.Skia if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return null; + return null; + // Blit feature requires glBlitFramebuffer - if (!_glContext.GlInterface.IsBlitFramebufferAvailable) + /*if (!_glContext.GlInterface.IsBlitFramebufferAvailable) return null; size = new PixelSize(Math.Max(size.Width, 1), Math.Max(size.Height, 1)); @@ -95,7 +97,7 @@ namespace Avalonia.Skia ?.Log(this, "Unable to create a Skia-compatible FBO manually"); _canCreateSurfaces ??= false; return null; - } + }*/ } public bool CanCreateSharedContext => _glContext.CanCreateSharedContext; diff --git a/src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositedWindowSurface.cs b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositedWindowSurface.cs index 9ee024f9ad..0739e14710 100644 --- a/src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositedWindowSurface.cs +++ b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositedWindowSurface.cs @@ -79,7 +79,7 @@ namespace Avalonia.Win32.WinRT.Composition _compositionDevice = _interop.CreateGraphicsDevice(_d3dDevice); _compositionDevice2 = _compositionDevice.QueryInterface(); _drawingSurface = _compositionDevice2.CreateDrawingSurface2(new UnmanagedMethods.SIZE(), - DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); + DirectXPixelFormat.R16G16B16A16Float, DirectXAlphaMode.Premultiplied); _surface = _drawingSurface.QueryInterface(); _surfaceInterop = _drawingSurface.QueryInterface(); } @@ -200,4 +200,4 @@ namespace Avalonia.Win32.WinRT.Composition public double Scaling => _scaling; } } -} \ No newline at end of file +}