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

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

Improve default crops on tablet

The fix is pretty targeted: only for tablets (not foldable), only when
we're trying to figure out the crop on portrait.

This only applies when there are no suggested crops: on Pixel it will
mostly affect the default wallpaper.

The specs are:
 - first compute the crop on landscape (left-aligned)
 - if there is parallax, compute the crop without parallax
 - the crop on portrait is the largest crop with the same center as the
   computed crop on landscape.
 - add parallax to the portrait crop so that its virtual right-end (or
   left-end if RTL) is the same as the crop on landscape

I think this should work well on all cases (even if the full image is
not landscape).

Flag: ACONFIG com.android.window.flags.multi_crop TEAMFOOD
Bug: 266594282
Test: manual debug
Test: atest WallpaperCropperTest
Test: atest WallpaperManagerTest
Change-Id: I3a842a4dffd4e298ef364700706bd7f4682a75dc
parent 2c11e704
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -137,6 +137,27 @@ public class WallpaperCropper {
                // This will fall into "Case 4" of this function and center the folded screen
                return getCrop(displaySize, bitmapSize, newSuggestedCrops, rtl);
            }

            // The second exception is if we're on tablet and we're on portrait mode.
            // In that case, center the wallpaper relatively to landscape and put some parallax.
            boolean isTablet = mWallpaperDisplayHelper.isLargeScreen()
                    && !mWallpaperDisplayHelper.isFoldable();
            if (isTablet && displaySize.x < displaySize.y) {
                Point rotatedDisplaySize = new Point(displaySize.y, displaySize.x);
                // compute the crop on landscape (without parallax)
                Rect landscapeCrop = getCrop(rotatedDisplaySize, bitmapSize, suggestedCrops, rtl);
                landscapeCrop = noParallax(landscapeCrop, rotatedDisplaySize, bitmapSize, rtl);
                // compute the crop on portrait at the center of the landscape crop
                crop = getAdjustedCrop(landscapeCrop, bitmapSize, displaySize, false, rtl, ADD);

                // add some parallax (until the border of the landscape crop without parallax)
                if (rtl) {
                    crop.left = landscapeCrop.left;
                } else {
                    crop.right = landscapeCrop.right;
                }
            }

            return getAdjustedCrop(crop, bitmapSize, displaySize, true, rtl, ADD);
        }

+14 −1
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@ class WallpaperDisplayHelper {
    }

    private static final String TAG = WallpaperDisplayHelper.class.getSimpleName();
    private static final float LARGE_SCREEN_MIN_DP = 600f;

    private final SparseArray<DisplayData> mDisplayDatas = new SparseArray<>();
    private final DisplayManager mDisplayManager;
    private final WindowManagerInternal mWindowManagerInternal;
@@ -67,7 +69,8 @@ class WallpaperDisplayHelper {
    // related orientations pairs for foldable (folded orientation, unfolded orientation)
    private final List<Pair<Integer, Integer>> mFoldableOrientationPairs = new ArrayList<>();

    private boolean mIsFoldable;
    private final boolean mIsFoldable;
    private boolean mIsLargeScreen = false;

    WallpaperDisplayHelper(
            DisplayManager displayManager,
@@ -94,6 +97,9 @@ class WallpaperDisplayHelper {
                    mDefaultDisplaySizes.put(orientation, point);
                }
            }

            mIsLargeScreen |= (displaySize.x / metric.getDensity() >= LARGE_SCREEN_MIN_DP);

            if (populateOrientationPairs) {
                int orientation = WallpaperManager.getOrientation(displaySize);
                float newSurface = displaySize.x * displaySize.y
@@ -214,6 +220,13 @@ class WallpaperDisplayHelper {
        return mIsFoldable;
    }

    /**
     * Return true if any of the screens of the default display is considered large (DP >= 600)
     */
    boolean isLargeScreen() {
        return mIsLargeScreen;
    }

    /**
     * If a given orientation corresponds to an unfolded orientation on foldable, return the
     * corresponding folded orientation. Otherwise, return UNKNOWN. Always return UNKNOWN if the