Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cd0a68e5 authored by Aurélien Pomini's avatar Aurélien Pomini
Browse files

More fine-grained sampling

Flag: android.app.accurate_wallpaper_downsampling
Bug: 355665230
Test: atest WallpaperManagerTest
Change-Id: I25ff8a85d07bfd000935865a455a9198179c5a4b
parent 86b7e8d0
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -30,3 +30,13 @@ flag {
    description: "Move APIs related to bitmap and crops to @SystemApi."
    bug: "372344184"
}

flag {
  name: "accurate_wallpaper_downsampling"
  namespace: "systemui"
  description: "Accurate downsampling of wallpaper bitmap for high resolution images"
  bug: "355665230"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
+14 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.wallpaper;
import static android.app.WallpaperManager.ORIENTATION_UNKNOWN;
import static android.app.WallpaperManager.getOrientation;
import static android.app.WallpaperManager.getRotatedOrientation;
import static android.app.Flags.accurateWallpaperDownsampling;
import static android.view.Display.DEFAULT_DISPLAY;

import static com.android.server.wallpaper.WallpaperUtils.RECORD_FILE;
@@ -378,7 +379,14 @@ public class WallpaperCropper {
        for (int i = 0; i < wallpaper.mCropHints.size(); i++) {
            Rect adjustedRect = new Rect(wallpaper.mCropHints.valueAt(i));
            adjustedRect.offset(-wallpaper.cropHint.left, -wallpaper.cropHint.top);
            if (accurateWallpaperDownsampling()) {
                adjustedRect.left = (int) (0.5f + adjustedRect.left / wallpaper.mSampleSize);
                adjustedRect.top = (int) (0.5f + adjustedRect.top / wallpaper.mSampleSize);
                adjustedRect.right = (int) Math.floor(adjustedRect.right / wallpaper.mSampleSize);
                adjustedRect.bottom = (int) Math.floor(adjustedRect.bottom / wallpaper.mSampleSize);
            } else {
                adjustedRect.scale(1f / wallpaper.mSampleSize);
            }
            result.put(wallpaper.mCropHints.keyAt(i), adjustedRect);
        }
        return result;
@@ -603,6 +611,11 @@ public class WallpaperCropper {
                    float sampleSizeForThisOrientation = Math.max(1f, Math.min(
                            crop.width() / displayForThisOrientation.x,
                            crop.height() / displayForThisOrientation.y));
                    if (accurateWallpaperDownsampling()) {
                        sampleSizeForThisOrientation = Math.max(1f, Math.min(
                                (float) crop.width() / displayForThisOrientation.x,
                                (float) crop.height() / displayForThisOrientation.y));
                    }
                    sampleSize = Math.min(sampleSize, sampleSizeForThisOrientation);
                }
                // If the total crop has more width or height than either the max texture size