未验证 提交 1a300bee 编写于 作者: M Martin Zikmund 提交者: GitHub

Merge pull request #12694 from unoplatform/dev/mazi/image-improvements

fix: Raise `ImageFailed` on Skia, correctly arrange empty `Image`
......@@ -82,7 +82,8 @@
</Compile>
</ItemGroup>
<Import Project="..\..\build\*.Skia.Wpf.props" />
<Import Project="..\..\build\*.Skia.Wpf.targets" />
<Import Project="..\..\..\build\*.Skia.Wpf.props" />
<Import Project="..\..\..\build\*.Skia.Wpf.targets" />
<Import Project="..\..\..\build\uno.winui.runtime-replace.targets" />
</Project>
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup>
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net6.0-windows</TargetFrameworks>
<!--
Enable implicit dotnet runtime forward rolling, as the specifed target framework
......@@ -9,6 +9,10 @@
<RollForward>Major</RollForward>
</PropertyGroup>
<PropertyGroup Condition="'$(MSBuildRuntimeType)'=='Core' or '$(BuildingInsideVisualStudio)'=='true'">
<TargetFrameworks>net7.0-windows</TargetFrameworks>
</PropertyGroup>
<Import Project="../../targetframework-override.props" />
<Import Project="../../netcore-build-windows.props" />
......@@ -34,6 +38,7 @@
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
<ItemGroup>
......@@ -46,7 +51,15 @@
<ItemGroup>
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="SkiaSharp.Views.WPF" Version="2.80.3" />
<PackageReference Include="SkiaSharp.Views.WPF" Version="2.88.3" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net6.0-windows'">
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net7.0-windows'">
<PackageReference Include="System.Drawing.Common" Version="7.0.0-rc.1.22426.10" />
</ItemGroup>
<ItemGroup>
......@@ -93,7 +106,8 @@
</None>
</ItemGroup>
<Import Project="..\..\build\*.Skia.Wpf.props" />
<Import Project="..\..\build\*.Skia.Wpf.targets" />
<Import Project="..\..\..\build\*.Skia.Wpf.props" />
<Import Project="..\..\..\build\*.Skia.Wpf.targets" />
<Import Project="..\..\..\build\uno.winui.runtime-replace.targets" />
</Project>
......@@ -452,9 +452,6 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
[RunsOnUIThread]
public async Task When_SVGImageSource()
{
#if __SKIA__
Assert.Inconclusive(); // SVGImage Load not implemented on Skia
#endif
if (!ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.Imaging.RenderTargetBitmap"))
{
Assert.Inconclusive(); // System.NotImplementedException: RenderTargetBitmap is not supported on this platform.;
......@@ -471,10 +468,6 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
[RunsOnUIThread]
public async Task When_SVGImageSource_Uri_Is_Null()
{
#if __SKIA__
Assert.Inconclusive(); // SVGImage Load not implemented on Skia
#endif
if (!ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.Imaging.RenderTargetBitmap"))
{
Assert.Inconclusive(); // System.NotImplementedException: RenderTargetBitmap is not supported on this platform.;
......@@ -490,9 +483,6 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
[RunsOnUIThread]
public async Task When_SVGImageSource_Uri_Is_Set_Null()
{
#if __SKIA__
Assert.Inconclusive(); // SVGImage Load not implemented on Skia
#endif
if (!ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.Imaging.RenderTargetBitmap"))
{
Assert.Inconclusive(); // System.NotImplementedException: RenderTargetBitmap is not supported on this platform.;
......@@ -505,6 +495,23 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
await WindowHelper.WaitForLoaded(image);
}
[TestMethod]
[RunsOnUIThread]
public async Task When_ImageFailed()
{
var image = new Image() { Width = 100, Height = 100 };
TestServices.WindowHelper.WindowContent = image;
await WindowHelper.WaitForLoaded(image);
bool imageFailedRaised = false;
image.ImageFailed += (s, e) =>
{
imageFailedRaised = true;
};
image.Source = new BitmapImage(new Uri("ms-appx:///image/definitely/does/not/exist.png"));
await WindowHelper.WaitFor(() => imageFailedRaised);
}
[TestMethod]
[RunsOnUIThread]
#if __MACOS__
......
......@@ -132,7 +132,7 @@ namespace Windows.UI.Xaml.Controls
_imageFetchDisposable.Disposable = null;
if (imageSource != null && imageSource.UseTargetSize)
if (imageSource is not null && imageSource.UseTargetSize)
{
// If the ImageSource has the UseTargetSize set, the image
// must not be loaded until the first layout has been done.
......@@ -146,6 +146,13 @@ namespace Windows.UI.Xaml.Controls
}
}
if (imageSource?.ResourceFailed == true)
{
// Currently resource-based images are evaluated immediately
// in the constructor - so we have to raise ImageFailed late.
OnImageFailed(imageSource, new InvalidOperationException("Resource could not be found"));
}
if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug))
{
this.Log().Debug(this.ToString() + " TryOpenImage - proceeding");
......
......@@ -3,11 +3,11 @@ using System.Linq;
using System.Numerics;
using Uno.Disposables;
using Uno.Foundation.Logging;
using Uno.UI.Xaml.Media;
using Windows.Foundation;
using Windows.UI.Composition;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Uno.UI.Xaml.Media;
namespace Windows.UI.Xaml.Controls
{
......@@ -124,24 +124,20 @@ namespace Windows.UI.Xaml.Controls
private void TryProcessPendingSource()
{
if (_pendingImageData.HasData)
var currentData = _pendingImageData;
_pendingImageData = new();
if (currentData.HasData)
{
_currentSurface = _pendingImageData.CompositionSurface;
_currentSurface = currentData.CompositionSurface;
_surfaceBrush = Visual.Compositor.CreateSurfaceBrush(_currentSurface);
_imageSprite.Brush = _surfaceBrush;
_pendingImageData = new();
if (_pendingImageData is not { Kind: ImageDataKind.Error })
{
ImageOpened?.Invoke(this, new RoutedEventArgs(this));
}
else
{
ImageFailed?.Invoke(this, new(
this,
_pendingImageData.Error?.Message ?? "Unknown error"));
}
ImageOpened?.Invoke(this, new RoutedEventArgs(this));
}
else if (currentData is { Kind: ImageDataKind.Error })
{
ImageFailed?.Invoke(this, new(
this,
currentData.Error?.Message ?? "Unknown error"));
}
}
......@@ -183,7 +179,7 @@ namespace Windows.UI.Xaml.Controls
else
{
_imageSprite.Size = default;
return default;
return base.ArrangeOverride(finalSize);
}
}
......
......@@ -91,6 +91,8 @@ namespace Windows.UI.Xaml.Media
|| ResourceId != null;
}
internal bool ResourceFailed => ResourceString is not null && ResourceId is null;
internal BitmapDrawable? BitmapDrawable { get; private set; }
internal int? ResourceId
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册