-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImageSource and ImageSourceServices #759
Conversation
src/Core/src/Hosting/ImageSources/ImageSourceServiceProvider.cs
Outdated
Show resolved
Hide resolved
# Conflicts: # src/Controls/samples/Controls.Sample/Controls.Sample.csproj # src/Controls/samples/Controls.Sample/Maui.Controls.Sample-net6.csproj
|
||
namespace Microsoft.Maui.Hosting | ||
{ | ||
class ImageSourceServiceProvider : MauiServiceProvider, IImageSourceServiceProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
namespace Microsoft.Maui.Hosting.Internal | ||
{ | ||
class FallbackLoggerFactory : ILoggerFactory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to indicate that the result is no longer valid and a new one should be obtained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
Looks good
I think we should add back the preserve for now because the CG needs it for AppCenter tests and it's confusing when that one crashes for that reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have also some image benckmark in the Benchmarks project?. I am thinking mostly in images from Url where things like Glide will have a huge impact but also, the metrics could help us to progress and improve (for example, with changes related with cache).
(Not necessary in this PR)
|
||
using (Stream stream = await imagesource.GetStreamAsync(cancelationToken).ConfigureAwait(false)) | ||
{ | ||
using (var decoder = new AndroidGIFImageParser(context, options.InDensity, options.InTargetDensity)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, could fix several issues like xamarin/Xamarin.Forms#13629
#if WINDOWS | ||
var config = MauiWinUIApplication.Current.Services.GetService<IImageSourceServiceConfiguration>(); | ||
config?.SetImageDirectory(newValue?.ToString()); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably in the future will have more sense in something like ApplicationHandler
if exists but looks good to me.
<PackageReference Include="Reloadify3000" Version="1.0.6" /> | ||
</ItemGroup> | ||
<ItemGroup Condition="$(TargetFramework.StartsWith('MonoAndroid'))"> | ||
<PackageReference Include="Xamarin.Android.Glide" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, what is the size of Glide library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.8MB when the aar is embedded in the dll from the nugets. About 767KB of jar files. The linker/proguard should help a bit on this.
MapSourceAsync(handler, image).FireAndForget(handler); | ||
|
||
public static async Task MapSourceAsync(ImageHandler handler, IImage image) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we include CancellationToken
here to allow cancel the loading operation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This happens inside:
var token = handler._sourceManager.BeginLoad();
The existing token is cancelled and starts a new source and returns the token to be used with UpdateSourceAsync
[InlineData("red.png", "#FF0000")] | ||
[InlineData("green.png", "#00FF00")] | ||
[InlineData("black.png", "#000000")] | ||
public async Task SourceInitializesCorrectly(string filename, string colorHex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
# Conflicts: # .nuspec/Microsoft.Maui.Controls.MultiTargeting.targets # src/Controls/src/Core/Controls.Core-net6.csproj # src/Controls/src/Core/HandlerImpl/Window.Impl.cs # src/Core/src/Core-net6.csproj # src/Core/src/TaskExtensions.cs
# Conflicts: # .nuspec/Microsoft.Maui.Controls.MultiTargeting.targets # src/Controls/src/Core/Controls.Core-net6.csproj # src/Controls/src/Core/HandlerImpl/Window.Impl.cs # src/Core/src/Core-net6.csproj # src/Core/src/TaskExtensions.cs
# Conflicts: # .nuspec/Microsoft.Maui.Controls.MultiTargeting.targets # src/Controls/src/Core/Controls.Core-net6.csproj # src/Controls/src/Core/HandlerImpl/Window.Impl.cs # src/Core/src/Core-net6.csproj # src/Core/src/TaskExtensions.cs
# Conflicts: # .nuspec/Microsoft.Maui.Controls.MultiTargeting.targets # src/Controls/src/Core/Controls.Core-net6.csproj # src/Controls/src/Core/HandlerImpl/Window.Impl.cs # src/Core/src/Core-net6.csproj # src/Core/src/TaskExtensions.cs
Hi @mattleibow , I am currently using FFImageloading with Xamarin Forms. I am checking out my dependencies in my current project for upgrade to MAUI. FFImageloading is a concern as I used it for fast image rendering on Android & iOS. As the Glide functionality is now integrated into MAUI for Android I have one less concern ;)) Looking at the FFImageloading repo it does not seem to be supported anymore by the authors. In nuget the latest download stats on the latest version is around 4.2 million downloads https://www.nuget.org/packages/Xamarin.FFImageLoading/ So alot of developers are going to trip on this library. One of the other features I used FFImageloading for was Retry Count + Retry Delay for redundancy reasons. This is a must on mobile devices that connects to unstable / intermittent internet connections to prevent for eg a listview from skipping images and displaying nothing. Any chance that the MAUI team can support Retry Count & Retry Delay within MAUI ? |
@Pinox can you open an issue proposing this feature? |
Description of Change
This PR is trying to handle the case of loading some native "image" using the
ImageSource
. Right now, this PR only contains Android.Initially, I tried returning the
Drawable
directly from the service, but this meant that there was no way to immediately release/dispose/free the bitmap. The GC would eventually get it - maybe. However, we can't rely on the GC as native bitmaps do not put enough pressure on the GC as well as sometimes we want to release them faster.My solution here is to return a "result" object that contains both the actual drawable as well as some release logic. This logic is very abstract and is just an
IDisposable
. The actual logic for this dispose is not disposing the drawable directly because this is not up to us. Rather, it wraps the logic needed to reverse the request and comes from the service that created the result.An example would be Glide that internally caches the bitmap and we have to indicate we are done with it:
target = Glide.With(context)...Submit()
Glide.With(context).Clear(target)
This logic is generic enough that it can work with any type of result since the service that caches the drawable is responsible for releasing it too.
Android:
Usage
TODO