Skip to content

Commit

Permalink
Merge pull request unoplatform#15962 from Youssef1313/minor-cleanup
Browse files Browse the repository at this point in the history
refactor: Cleanup ImageSource
  • Loading branch information
Youssef1313 authored Mar 20, 2024
2 parents e522288 + 03bd727 commit 1a4200f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 142 deletions.
34 changes: 0 additions & 34 deletions src/Uno.UI/UI/Xaml/Media/ImageSource.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,40 +154,6 @@ partial void SetImageLoader()
/// </summary>
private protected virtual bool IsSourceReady => false;

/// <summary>
/// Override to provide the capability of concrete ImageSource to open synchronously.
/// </summary>
/// <param name="targetWidth">The width of the image that will render this ImageSource.</param>
/// <param name="targetHeight">The width of the image that will render this ImageSource.</param>
/// <param name="image">Returned image data.</param>
/// <returns>True if opening synchronously is possible.</returns>
/// <remarks>
/// <paramref name="targetWidth"/> and <paramref name="targetHeight"/> can be used to improve performance by fetching / decoding only the required size.
/// Depending on stretching, only one of each can be provided.
/// </remarks>
private protected virtual bool TryOpenSourceSync(int? targetWidth, int? targetHeight, out ImageData image)
{
image = default;
return false;
}

/// <summary>
/// Override to provide the capability of concrete ImageSource to open asynchronously.
/// </summary>
/// <param name="targetWidth">The width of the image that will render this ImageSource.</param>
/// <param name="targetHeight">The width of the image that will render this ImageSource.</param>
/// <param name="asyncImage">Async task for image data retrieval.</param>
/// <returns>True if opening asynchronously is possible.</returns>
/// <remarks>
/// <paramref name="targetWidth"/> and <paramref name="targetHeight"/> can be used to improve performance by fetching / decoding only the required size.
/// Depending on stretching, only one of each can be provided.
/// </remarks>
private protected virtual bool TryOpenSourceAsync(CancellationToken ct, int? targetWidth, int? targetHeight, [NotNullWhen(true)] out Task<ImageData>? asyncImage)
{
asyncImage = default;
return false;
}

internal bool TryOpenSync(out Bitmap? image, int? targetWidth = null, int? targetHeight = null)
{
if (_imageData.Bitmap is not null)
Expand Down
36 changes: 0 additions & 36 deletions src/Uno.UI/UI/Xaml/Media/ImageSource.crossruntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,41 +83,6 @@ internal IDisposable Subscribe(Action<ImageData> onSourceOpened)
/// </summary>
internal bool IsOpened => _imageData.HasData;

#region Implementers API
/// <summary>
/// Override to provide the capability of concrete ImageSource to open synchronously.
/// </summary>
/// <param name="targetWidth">The width of the image that will render this ImageSource.</param>
/// <param name="targetHeight">The width of the image that will render this ImageSource.</param>
/// <param name="image">Returned image data.</param>
/// <returns>True if opening synchronously is possible.</returns>
/// <remarks>
/// <paramref name="targetWidth"/> and <paramref name="targetHeight"/> can be used to improve performance by fetching / decoding only the required size.
/// Depending on stretching, only one of each can be provided.
/// </remarks>
private protected virtual bool TryOpenSourceSync(int? targetWidth, int? targetHeight, out ImageData image)
{
image = default;
return false;
}

/// <summary>
/// Override to provide the capability of concrete ImageSource to open asynchronously.
/// </summary>
/// <param name="targetWidth">The width of the image that will render this ImageSource.</param>
/// <param name="targetHeight">The width of the image that will render this ImageSource.</param>
/// <param name="asyncImage">Async task for image data retrieval.</param>
/// <returns>True if opening asynchronously is possible.</returns>
/// <remarks>
/// <paramref name="targetWidth"/> and <paramref name="targetHeight"/> can be used to improve performance by fetching / decoding only the required size.
/// Depending on stretching, only one of each can be provided.
/// </remarks>
private protected virtual bool TryOpenSourceAsync(CancellationToken ct, int? targetWidth, int? targetHeight, [NotNullWhen(true)] out Task<ImageData> asyncImage)
{
asyncImage = default;
return false;
}

private protected void InvalidateSource()
{
_imageData = default;
Expand All @@ -126,7 +91,6 @@ private protected void InvalidateSource()
RequestOpen();
}
}
#endregion

private protected void RequestOpen()
{
Expand Down
48 changes: 40 additions & 8 deletions src/Uno.UI/UI/Xaml/Media/ImageSource.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
#nullable enable
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.UI.Xaml.Media.Imaging;
using Uno.Diagnostics.Eventing;
using Uno.Extensions;
using Uno.Foundation.Logging;
using Uno.Helpers;
using Uno.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
using Uno.UI;
using System.Net;

#if !IS_UNO
using Uno.Web.Query;
using Uno.Web.Query.Cache;
#endif
using Uno.UI.Xaml.Media;

namespace Microsoft.UI.Xaml.Media
{
Expand Down Expand Up @@ -224,5 +220,41 @@ internal void UnloadImageData()
private protected virtual void UnloadImageSourceData()
{
}

#region Implementers API
/// <summary>
/// Override to provide the capability of concrete ImageSource to open synchronously.
/// </summary>
/// <param name="targetWidth">The width of the image that will render this ImageSource.</param>
/// <param name="targetHeight">The width of the image that will render this ImageSource.</param>
/// <param name="image">Returned image data.</param>
/// <returns>True if opening synchronously is possible.</returns>
/// <remarks>
/// <paramref name="targetWidth"/> and <paramref name="targetHeight"/> can be used to improve performance by fetching / decoding only the required size.
/// Depending on stretching, only one of each can be provided.
/// </remarks>
private protected virtual bool TryOpenSourceSync(int? targetWidth, int? targetHeight, out ImageData image)
{
image = default;
return false;
}

/// <summary>
/// Override to provide the capability of concrete ImageSource to open asynchronously.
/// </summary>
/// <param name="targetWidth">The width of the image that will render this ImageSource.</param>
/// <param name="targetHeight">The width of the image that will render this ImageSource.</param>
/// <param name="asyncImage">Async task for image data retrieval.</param>
/// <returns>True if opening asynchronously is possible.</returns>
/// <remarks>
/// <paramref name="targetWidth"/> and <paramref name="targetHeight"/> can be used to improve performance by fetching / decoding only the required size.
/// Depending on stretching, only one of each can be provided.
/// </remarks>
private protected virtual bool TryOpenSourceAsync(CancellationToken ct, int? targetWidth, int? targetHeight, [NotNullWhen(true)] out Task<ImageData>? asyncImage)
{
asyncImage = default;
return false;
}
#endregion
}
}
28 changes: 0 additions & 28 deletions src/Uno.UI/UI/Xaml/Media/ImageSource.iOSmacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,34 +118,6 @@ internal ImageData OpenBundle()
/// </summary>
private protected virtual bool IsSourceReady => false;

/// <summary>
/// Override to provide the capability of concrete ImageSource to open synchronously.
/// </summary>
/// <param name="image">Returned image data.</param>
/// <returns>True if opening synchronously is possible.</returns>
private protected virtual bool TryOpenSourceSync(int? targetWidth, int? targetHeight, out ImageData image)
{
image = default;
return false;
}

/// <summary>
/// Override to provide the capability of concrete ImageSource to open asynchronously.
/// </summary>
/// <param name="targetWidth">The width of the image that will render this ImageSource.</param>
/// <param name="targetHeight">The width of the image that will render this ImageSource.</param>
/// <param name="asyncImage">Async task for image data retrieval.</param>
/// <returns>True if opening asynchronously is possible.</returns>
/// <remarks>
/// <paramref name="targetWidth"/> and <paramref name="targetHeight"/> can be used to improve performance by fetching / decoding only the required size.
/// Depending on stretching, only one of each can be provided.
/// </remarks>
private protected virtual bool TryOpenSourceAsync(CancellationToken ct, int? targetWidth, int? targetHeight, [NotNullWhen(true)] out Task<ImageData>? asyncImage)
{
asyncImage = default;
return false;
}

/// <summary>
/// Retrieves the already loaded image, or for supported source (eg. WriteableBitmap, cf remarks),
/// create a native image from the data in memory.
Expand Down
36 changes: 0 additions & 36 deletions src/Uno.UI/UI/Xaml/Media/ImageSource.unittests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,4 @@ partial void CleanupResource()
{
AbsoluteUri = null;
}

#region Implementers API
/// <summary>
/// Override to provide the capability of concrete ImageSource to open synchronously.
/// </summary>
/// <param name="targetWidth">The width of the image that will render this ImageSource.</param>
/// <param name="targetHeight">The width of the image that will render this ImageSource.</param>
/// <param name="image">Returned image data.</param>
/// <returns>True if opening synchronously is possible.</returns>
/// <remarks>
/// <paramref name="targetWidth"/> and <paramref name="targetHeight"/> can be used to improve performance by fetching / decoding only the required size.
/// Depending on stretching, only one of each can be provided.
/// </remarks>
private protected virtual bool TryOpenSourceSync(int? targetWidth, int? targetHeight, out ImageData image)
{
image = default;
return false;
}

/// <summary>
/// Override to provide the capability of concrete ImageSource to open asynchronously.
/// </summary>
/// <param name="targetWidth">The width of the image that will render this ImageSource.</param>
/// <param name="targetHeight">The width of the image that will render this ImageSource.</param>
/// <param name="asyncImage">Async task for image data retrieval.</param>
/// <returns>True if opening asynchronously is possible.</returns>
/// <remarks>
/// <paramref name="targetWidth"/> and <paramref name="targetHeight"/> can be used to improve performance by fetching / decoding only the required size.
/// Depending on stretching, only one of each can be provided.
/// </remarks>
private protected virtual bool TryOpenSourceAsync(CancellationToken ct, int? targetWidth, int? targetHeight, [NotNullWhen(true)] out Task<ImageData> asyncImage)
{
asyncImage = default;
return false;
}
#endregion
}

0 comments on commit 1a4200f

Please sign in to comment.