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

Commit 13f7ae1a authored by Aurélien Pomini's avatar Aurélien Pomini Committed by Android (Google) Code Review
Browse files

Merge "More fine-grained sampling" into main

parents 2fdae165 cd0a68e5
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