diff options
| author | 2023-06-15 16:14:39 +0200 | |
|---|---|---|
| committer | 2023-06-15 20:07:47 +0000 | |
| commit | 1f4745be4abac4224ef2a051218e4ea2a0cfa48f (patch) | |
| tree | 01283fc676307c4f048d05dd87d6cb01a38a6638 | |
| parent | f5454e3766bc7e8a0e393546961be667a663fe01 (diff) | |
Add Trace points to WallpaperColors
WallpaperColors processes Bitmaps which can be slow (and cause jank)
when called on the main thread. This adds trace points so we can debug
these calls as a source of jank.
Bug: 287209189
Test: ran a perfetto trace on device
Change-Id: If0cb5d3d6bf04c404fae2b1a6229cdb92946526b
| -rw-r--r-- | core/java/android/app/WallpaperColors.java | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/core/java/android/app/WallpaperColors.java b/core/java/android/app/WallpaperColors.java index b710644a308c..5f5a7dfe24c6 100644 --- a/core/java/android/app/WallpaperColors.java +++ b/core/java/android/app/WallpaperColors.java @@ -28,6 +28,7 @@ import android.graphics.drawable.Drawable; import android.os.Parcel; import android.os.Parcelable; import android.os.SystemProperties; +import android.os.Trace; import android.util.Log; import android.util.MathUtils; import android.util.Size; @@ -144,6 +145,7 @@ public final class WallpaperColors implements Parcelable { throw new IllegalArgumentException("Drawable cannot be null"); } + Trace.beginSection("WallpaperColors#fromDrawable"); Rect initialBounds = drawable.copyBounds(); int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); @@ -165,6 +167,7 @@ public final class WallpaperColors implements Parcelable { bitmap.recycle(); drawable.setBounds(initialBounds); + Trace.endSection(); return colors; } @@ -195,7 +198,7 @@ public final class WallpaperColors implements Parcelable { public static WallpaperColors fromBitmap(@NonNull Bitmap bitmap, @FloatRange (from = 0f, to = 1f) float dimAmount) { Objects.requireNonNull(bitmap, "Bitmap can't be null"); - + Trace.beginSection("WallpaperColors#fromBitmap"); final int bitmapArea = bitmap.getWidth() * bitmap.getHeight(); boolean shouldRecycle = false; if (bitmapArea > MAX_WALLPAPER_EXTRACTION_AREA) { @@ -247,6 +250,7 @@ public final class WallpaperColors implements Parcelable { bitmap.recycle(); } + Trace.endSection(); return new WallpaperColors(populationByColor, HINT_FROM_BITMAP | hints); } @@ -462,7 +466,7 @@ public final class WallpaperColors implements Parcelable { * Gets the most visually representative color of the wallpaper. * "Visually representative" means easily noticeable in the image, * probably happening at high frequency. - * + *fromBitmap * @return A color. */ public @NonNull Color getPrimaryColor() { @@ -545,6 +549,7 @@ public final class WallpaperColors implements Parcelable { return 0; } + Trace.beginSection("WallpaperColors#calculateDarkHints"); dimAmount = MathUtils.saturate(dimAmount); int[] pixels = new int[source.getWidth() * source.getHeight()]; double totalLuminance = 0; @@ -607,6 +612,7 @@ public final class WallpaperColors implements Parcelable { " maxD: " + maxDarkPixels + " numPixels: " + pixels.length); } + Trace.endSection(); return hints; } |