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

Commit 228a5eac authored by Todd Lee's avatar Todd Lee
Browse files

Allow fractional pixels for origin transition bounds

Bug: b/378975686
Test: presubmits
Flag: NONE exempt minor change
Change-Id: I3d8dff2694f11a82a7543cbe3684c9ea624688c6
parent b44ee2f1
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.view.WindowManager.TRANSIT_CHANGE;
import android.annotation.Nullable;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.RectF;
import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.os.IBinder;
@@ -462,10 +463,10 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub implements
            return;
        }
        // Calculate bounds.
        Rect maxClosingBounds = new Rect();
        Rect maxOpeningBounds = new Rect();
        RectF maxClosingBounds = new RectF();
        RectF maxOpeningBounds = new RectF();
        for (int i = 0; i < info.getChanges().size(); i++) {
            Rect bound = getBounds(states[i]);
            RectF bound = getBounds(states[i]);
            if (bound == null) {
                continue;
            }
@@ -489,13 +490,11 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub implements
    }

    @Nullable
    private static Rect getBounds(@Nullable WindowAnimationState state) {
    private static RectF getBounds(@Nullable WindowAnimationState state) {
        if (state == null || state.bounds == null) {
            return null;
        }
        Rect out = new Rect();
        state.bounds.roundOut(out);
        return out;
        return state.bounds;
    }

    /** A {@link Runnable} that will only run once. */
+11 −11
Original line number Diff line number Diff line
@@ -33,12 +33,12 @@ import java.util.concurrent.Executor;
 */
public class SurfaceUIComponent implements UIComponent {
    private final ArrayList<SurfaceControl> mSurfaces = new ArrayList<>();
    private final Rect mBaseBounds;
    private final RectF mBaseBounds;
    private final float[] mFloat9 = new float[9];

    private float mAlpha;
    private boolean mVisible;
    private Rect mBounds;
    private RectF mBounds;
    @Nullable
    private final SurfaceControl mBackgroundDimmingSurface;

@@ -67,8 +67,8 @@ public class SurfaceUIComponent implements UIComponent {
        mSurfaces.addAll(surfaces);
        mAlpha = alpha;
        mVisible = visible;
        mBounds = bounds;
        mBaseBounds = baseBounds;
        mBounds = new RectF(bounds);
        mBaseBounds = new RectF(baseBounds);
        if (enableBackgroundDimming) {
          mBackgroundDimmingSurface = new SurfaceControl.Builder()
                  .setName("SurfaceUIComponent-BackgroundDimming")
@@ -79,8 +79,8 @@ public class SurfaceUIComponent implements UIComponent {
          if (!bounds.equals(baseBounds)) {
              Matrix matrix = new Matrix();
              matrix.setRectToRect(
                  new RectF(baseBounds),
                  new RectF(bounds),
                      mBaseBounds,
                      mBounds,
                      Matrix.ScaleToFit.CENTER);
              new SurfaceControl.Transaction()
                  .setMatrix(mBackgroundDimmingSurface, matrix, mFloat9).apply();
@@ -103,7 +103,7 @@ public class SurfaceUIComponent implements UIComponent {
    }

    @Override
    public Rect getBounds() {
    public RectF getBounds() {
        return mBounds;
    }

@@ -166,7 +166,7 @@ public class SurfaceUIComponent implements UIComponent {
        }

        @Override
        public Transaction setBounds(SurfaceUIComponent ui, Rect bounds) {
        public Transaction setBounds(SurfaceUIComponent ui, RectF bounds) {
            mChanges.add(
                    () -> {
                        if (ui.mBounds.equals(bounds)) {
@@ -175,8 +175,8 @@ public class SurfaceUIComponent implements UIComponent {
                        ui.mBounds = bounds;
                        Matrix matrix = new Matrix();
                        matrix.setRectToRect(
                                new RectF(ui.mBaseBounds),
                                new RectF(ui.mBounds),
                                ui.mBaseBounds,
                                ui.mBounds,
                                Matrix.ScaleToFit.CENTER);
                        ui.mSurfaces.forEach(
                                s -> mTransaction.setMatrix(s, matrix, ui.mFloat9));
+2 −2
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.systemui.animation;

import android.annotation.FloatRange;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.ArrayMap;
import android.view.SurfaceControl;

@@ -61,7 +61,7 @@ public class Transactions implements UIComponent.Transaction<UIComponent> {
    }

    @Override
    public Transactions setBounds(UIComponent ui, Rect bounds) {
    public Transactions setBounds(UIComponent ui, RectF bounds) {
        getTransactionFor(ui).setBounds(ui, bounds);
        return this;
    }
+3 −3
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ package com.android.systemui.animation;
import android.annotation.FloatRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Rect;
import android.graphics.RectF;
import android.view.SurfaceControl;

import java.util.concurrent.Executor;
@@ -38,7 +38,7 @@ public interface UIComponent {

    /** Get the bounds of this UI in its display. */
    @NonNull
    Rect getBounds();
    RectF getBounds();

    /** Create a new {@link Transaction} that can update this UI. */
    @NonNull
@@ -62,7 +62,7 @@ public interface UIComponent {

        /** Update bounds of an UI. Execution will be delayed until {@link #commit()} is called. */
        @NonNull
        Transaction setBounds(@NonNull T ui, @NonNull Rect bounds);
        Transaction setBounds(@NonNull T ui, @NonNull RectF bounds);

        /**
         * Attach a ui to the transition leash. Execution will be delayed until {@link #commit()} is
+10 −10
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ public class ViewUIComponent implements UIComponent {
    private final Handler mMainHandler;
    @Nullable private SurfaceControl mSurfaceControl;
    @Nullable private Surface mSurface;
    @Nullable private Rect mViewBoundsOverride;
    @Nullable private RectF mViewBoundsOverride;
    private boolean mVisibleOverride;
    private final boolean mEnableBackgroundDimming;
    private final Paint mPaint = new Paint();
@@ -91,7 +91,7 @@ public class ViewUIComponent implements UIComponent {
    }

    @Override
    public Rect getBounds() {
    public RectF getBounds() {
        if (isAttachedToLeash() && mViewBoundsOverride != null) {
            return mViewBoundsOverride;
        }
@@ -195,7 +195,7 @@ public class ViewUIComponent implements UIComponent {
            return;
        }

        final Rect realBounds = getRealBounds();
        final RectF realBounds = getRealBounds();
        if (realBounds.width() == 0 || realBounds.height() == 0) {
            // bad bounds.
            logD("draw: skipped - zero bounds");
@@ -207,7 +207,7 @@ public class ViewUIComponent implements UIComponent {
        // Clear the canvas first.
        canvas.drawColor(0, PorterDuff.Mode.CLEAR);
        if (mVisibleOverride) {
            Rect renderBounds = getBounds();
            RectF renderBounds = getBounds();
            canvas.translate(renderBounds.left, renderBounds.top);

            float cornerRadius = (float) Math.min(renderBounds.width(), renderBounds.height()) / 2;
@@ -227,8 +227,8 @@ public class ViewUIComponent implements UIComponent {
            }

            canvas.scale(
                    (float) renderBounds.width() / realBounds.width(),
                    (float) renderBounds.height() / realBounds.height());
                    renderBounds.width() / realBounds.width(),
                    renderBounds.height() / realBounds.height());

            if (mView.getClipToOutline()) {
                mView.getOutlineProvider().getOutline(mView, mClippingOutline);
@@ -253,10 +253,10 @@ public class ViewUIComponent implements UIComponent {
        draw();
    }

    private Rect getRealBounds() {
    private RectF getRealBounds() {
        Rect output = new Rect();
        mView.getBoundsOnScreen(output);
        return output;
        return new RectF(output);
    }

    private boolean isAttachedToLeash() {
@@ -279,7 +279,7 @@ public class ViewUIComponent implements UIComponent {
        }
    }

    private void setBounds(Rect bounds) {
    private void setBounds(RectF bounds) {
        logD("setBounds: " + bounds);
        mViewBoundsOverride = bounds;
        if (isAttachedToLeash()) {
@@ -381,7 +381,7 @@ public class ViewUIComponent implements UIComponent {
        }

        @Override
        public Transaction setBounds(ViewUIComponent ui, Rect bounds) {
        public Transaction setBounds(ViewUIComponent ui, RectF bounds) {
            mChanges.add(() -> ui.post(() -> ui.setBounds(bounds)));
            return this;
        }