Skip to content
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

Add Android LoadImageFromFont benchmark and enable verbose Glide logging #24033

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.microsoft.maui.glide;

import android.util.Log;

public class GlideLogging {
private static final String TAG = "Glide";
private static final boolean IS_VERBOSE_LOGGABLE = Log.isLoggable(TAG, Log.VERBOSE);

public static boolean isVerboseLoggable() {
return IS_VERBOSE_LOGGABLE;
}

public static void v(String message) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use this in the future to enhance our java glide-related logging.

if (IS_VERBOSE_LOGGABLE) {
Log.v(TAG, message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

import com.microsoft.maui.ImageLoaderCallback;
import com.microsoft.maui.glide.GlideLogging;
import com.microsoft.maui.glide.fallback.ImageLoaderCallbackModelLoaderFactory;
import com.microsoft.maui.glide.font.FontModel;
import com.microsoft.maui.glide.font.FontModelLoaderFactory;
Expand All @@ -33,4 +36,13 @@ public void registerComponents(Context context, Glide glide, Registry registry)
public boolean isManifestParsingEnabled() {
return false;
}
}

@Override
public void applyOptions(Context context, GlideBuilder builder) {
// Glide is checking for the log level only on some classes, so we have to do it ourselves here.
// Command: adb shell setprop log.tag.Glide VERBOSE
if (GlideLogging.isVerboseLoggable()) {
builder.setLogLevel(Log.VERBOSE);
}
}
}
2 changes: 1 addition & 1 deletion src/Core/src/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<ProjectReference Include="..\..\Graphics\src\Graphics.Win2D\Graphics.Win2D.csproj" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.Contains('-android'))">
<PackageReference Include="Xamarin.Android.Glide" Version="4.15.1.2" />
<PackageReference Include="Xamarin.Android.Glide" Version="$(_XamarinAndroidGlideVersion)" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.6.1.3" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.9.0.2" />
<PackageReference Include="Xamarin.AndroidX.SwipeRefreshLayout" Version="1.1.0.14" />
Expand Down
2 changes: 1 addition & 1 deletion src/Core/tests/Benchmarks.Droid/Benchmarks.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<Using Include="BenchmarkDotNet.Order" />
<Using Include="BenchmarkDotNet.Running" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.10" />
<PackageReference Include="Xamarin.Android.Glide" Version="4.14.2.1" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version was not in sync with the one we use on all other projects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put the entry here across the repo?

Then you could just put <PackageReference Include="Xamarin.Android.Glide" /> without the Version across the repo.

Copy link
Contributor Author

@albyrock87 albyrock87 Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I found something better which is already used in the solution $(_XamarinAndroidGlideVersion).

<_XamarinAndroidGlideVersion>4.15.1.2</_XamarinAndroidGlideVersion>

<PackageReference Include="Xamarin.Android.Glide" Version="$(_XamarinAndroidGlideVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Controls\src\Core\Controls.Core.csproj" />
Expand Down
25 changes: 23 additions & 2 deletions src/Core/tests/Benchmarks.Droid/ImageBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Android.Content;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.OS;
using Bumptech.Glide;
using Bumptech.Glide.Request.Target;
using Bumptech.Glide.Request.Transition;
using Java.Lang;
using Microsoft.Maui.Storage;
using AImageView = Android.Widget.ImageView;
using Path = System.IO.Path;

namespace Benchmarks.Droid;

Expand All @@ -20,6 +20,7 @@ public class ImageBenchmark
Handler? handler;
Context? context;
string? imageFilename;
Typeface? defaultTypeface;

[GlobalSetup]
public void GlobalSetup()
Expand All @@ -29,6 +30,7 @@ public void GlobalSetup()
imageView = new AImageView(context);
glide = Glide.Get(context);
handler = new Handler(Looper.MainLooper!);
defaultTypeface = Typeface.Default;

var imageName = "dotnet_bot.png";
var cacheDir = FileSystem.CacheDirectory;
Expand Down Expand Up @@ -70,6 +72,25 @@ public async Task ImageHelperFromFile()
await callback.SuccessTask;
}

[Benchmark]
public async Task ImageHelperFromFont()
{
var callback = new Callback();

handler!.Post(() =>
{
Microsoft.Maui.PlatformInterop.LoadImageFromFont(
context,
Color.Aquamarine,
"A",
defaultTypeface,
24,
callback);
});

await callback.SuccessTask;
}

class Callback : Java.Lang.Object, Microsoft.Maui.IImageLoaderCallback
{
readonly TaskCompletionSource<Drawable?> tcsDrawable = new TaskCompletionSource<Drawable?>();
Expand Down
Loading