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

Commit ccffd26d authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert "Finish animation callback set latest value"" into main

parents 070303ac 9d538a5b
Loading
Loading
Loading
Loading
+27 −27
Original line number Original line Diff line number Diff line
@@ -55,11 +55,10 @@ public class DimmerAnimationHelper {


        Change() {}
        Change() {}


        void copyFrom(@NonNull Change other) {
        Change(@NonNull Change other) {
            mAlpha = other.mAlpha;
            mAlpha = other.mAlpha;
            mBlurRadius = other.mBlurRadius;
            mBlurRadius = other.mBlurRadius;
            mDimmingContainer = other.mDimmingContainer;
            mDimmingContainer = other.mDimmingContainer;
            mGeometryParent = other.mGeometryParent;
            mRelativeLayer = other.mRelativeLayer;
            mRelativeLayer = other.mRelativeLayer;
        }
        }


@@ -84,8 +83,8 @@ public class DimmerAnimationHelper {
        }
        }
    }
    }


    private final Change mCurrentProperties = new Change();
    private Change mCurrentProperties = new Change();
    private final Change mRequestedProperties = new Change();
    private Change mRequestedProperties = new Change();
    private AnimationSpec mAlphaAnimationSpec;
    private AnimationSpec mAlphaAnimationSpec;


    private final AnimationAdapterFactory mAnimationAdapterFactory;
    private final AnimationAdapterFactory mAnimationAdapterFactory;
@@ -129,7 +128,7 @@ public class DimmerAnimationHelper {
                    + "call adjustRelativeLayer?");
                    + "call adjustRelativeLayer?");
            return;
            return;
        }
        }
        if (mRequestedProperties.mDimmingContainer.getSurfaceControl() == null) {
        if (mRequestedProperties.mDimmingContainer.mSurfaceControl == null) {
            Log.w(TAG, "container " + mRequestedProperties.mDimmingContainer
            Log.w(TAG, "container " + mRequestedProperties.mDimmingContainer
                    + "does not have a surface");
                    + "does not have a surface");
            dim.remove(t);
            dim.remove(t);
@@ -155,35 +154,35 @@ public class DimmerAnimationHelper {
                        "%s skipping animation and directly setting alpha=%f, blur=%d",
                        "%s skipping animation and directly setting alpha=%f, blur=%d",
                        dim, mRequestedProperties.mAlpha,
                        dim, mRequestedProperties.mAlpha,
                        mRequestedProperties.mBlurRadius);
                        mRequestedProperties.mBlurRadius);
                mCurrentProperties.copyFrom(mRequestedProperties);
                setAlphaBlur(dim.mDimSurface, mRequestedProperties.mAlpha,
                setCurrentAlphaBlur(dim.mDimSurface, t);
                        mRequestedProperties.mBlurRadius, t);
                dim.mSkipAnimation = false;
                dim.mSkipAnimation = false;
            } else {
            } else {
                Change startProperties = mCurrentProperties;
                startAnimation(t, dim);
                mCurrentProperties.copyFrom(mRequestedProperties);
                startAnimation(t, dim, startProperties, mRequestedProperties);
            }
            }

        } else if (!dim.isDimming()) {
        } else if (!dim.isDimming()) {
            // We are not dimming, so we tried the exit animation but the alpha is already 0,
            // We are not dimming, so we tried the exit animation but the alpha is already 0,
            // therefore, let's just remove this surface
            // therefore, let's just remove this surface
            dim.remove(t);
            dim.remove(t);
        }
        }
        mCurrentProperties = new Change(mRequestedProperties);
    }
    }


    private void startAnimation(
    private void startAnimation(
            @NonNull SurfaceControl.Transaction t, @NonNull Dimmer.DimState dim,
            @NonNull SurfaceControl.Transaction t, @NonNull Dimmer.DimState dim) {
            @NonNull Change from, @NonNull Change to) {
        ProtoLog.v(WM_DEBUG_DIMMER, "Starting animation on %s", dim);
        ProtoLog.v(WM_DEBUG_DIMMER, "Starting animation on %s", dim);
        mAlphaAnimationSpec = getRequestedAnimationSpec(from, to);
        mAlphaAnimationSpec = getRequestedAnimationSpec();
        mLocalAnimationAdapter = mAnimationAdapterFactory.get(mAlphaAnimationSpec,
        mLocalAnimationAdapter = mAnimationAdapterFactory.get(mAlphaAnimationSpec,
                dim.mHostContainer.mWmService.mSurfaceAnimationRunner);
                dim.mHostContainer.mWmService.mSurfaceAnimationRunner);


        float targetAlpha = to.mAlpha;
        float targetAlpha = mRequestedProperties.mAlpha;
        int targetBlur = mRequestedProperties.mBlurRadius;


        mLocalAnimationAdapter.startAnimation(dim.mDimSurface, t,
        mLocalAnimationAdapter.startAnimation(dim.mDimSurface, t,
                ANIMATION_TYPE_DIMMER, /* finishCallback */ (type, animator) -> {
                ANIMATION_TYPE_DIMMER, /* finishCallback */ (type, animator) -> {
                    synchronized (dim.mHostContainer.mWmService.mGlobalLock) {
                    synchronized (dim.mHostContainer.mWmService.mGlobalLock) {
                        setCurrentAlphaBlur(dim.mDimSurface, t);
                        setAlphaBlur(dim.mDimSurface, targetAlpha, targetBlur, t);
                        if (targetAlpha == 0f && !dim.isDimming()) {
                        if (targetAlpha == 0f && !dim.isDimming()) {
                            dim.remove(t);
                            dim.remove(t);
                        }
                        }
@@ -208,15 +207,15 @@ public class DimmerAnimationHelper {
    }
    }


    @NonNull
    @NonNull
    private static AnimationSpec getRequestedAnimationSpec(Change from, Change to) {
    private AnimationSpec getRequestedAnimationSpec() {
        final float startAlpha = Math.max(from.mAlpha, 0f);
        final float startAlpha = Math.max(mCurrentProperties.mAlpha, 0f);
        final int startBlur = Math.max(from.mBlurRadius, 0);
        final int startBlur = Math.max(mCurrentProperties.mBlurRadius, 0);
        long duration = (long) (getDimDuration(to.mDimmingContainer)
        long duration = (long) (getDimDuration(mRequestedProperties.mDimmingContainer)
                * Math.abs(to.mAlpha - startAlpha));
                * Math.abs(mRequestedProperties.mAlpha - startAlpha));


        final AnimationSpec spec =  new AnimationSpec(
        final AnimationSpec spec =  new AnimationSpec(
                new AnimationSpec.AnimationExtremes<>(startAlpha, to.mAlpha),
                new AnimationSpec.AnimationExtremes<>(startAlpha, mRequestedProperties.mAlpha),
                new AnimationSpec.AnimationExtremes<>(startBlur, to.mBlurRadius),
                new AnimationSpec.AnimationExtremes<>(startBlur, mRequestedProperties.mBlurRadius),
                duration
                duration
        );
        );
        ProtoLog.v(WM_DEBUG_DIMMER, "Dim animation requested: %s", spec);
        ProtoLog.v(WM_DEBUG_DIMMER, "Dim animation requested: %s", spec);
@@ -226,7 +225,7 @@ public class DimmerAnimationHelper {
    /**
    /**
     * Change the geometry and relative parent of this dim layer
     * Change the geometry and relative parent of this dim layer
     */
     */
    static void reparent(@NonNull SurfaceControl dimLayer,
    void reparent(@NonNull SurfaceControl dimLayer,
                  @Nullable SurfaceControl newGeometryParent,
                  @Nullable SurfaceControl newGeometryParent,
                  @NonNull SurfaceControl relativeParent,
                  @NonNull SurfaceControl relativeParent,
                  int relativePosition,
                  int relativePosition,
@@ -241,16 +240,17 @@ public class DimmerAnimationHelper {
        }
        }
    }
    }


    void setCurrentAlphaBlur(@NonNull SurfaceControl sc, @NonNull SurfaceControl.Transaction t) {
    void setAlphaBlur(@NonNull SurfaceControl sc, float alpha, int blur,
                      @NonNull SurfaceControl.Transaction t) {
        try {
        try {
            t.setAlpha(sc, mCurrentProperties.mAlpha);
            t.setAlpha(sc, alpha);
            t.setBackgroundBlurRadius(sc, mCurrentProperties.mBlurRadius);
            t.setBackgroundBlurRadius(sc, blur);
        } catch (NullPointerException e) {
        } catch (NullPointerException e) {
            Log.w(TAG , "Tried to change look of dim " + sc + " after remove",  e);
            Log.w(TAG , "Tried to change look of dim " + sc + " after remove",  e);
        }
        }
    }
    }


    private static long getDimDuration(@NonNull WindowContainer<?> container) {
    private long getDimDuration(@NonNull WindowContainer<?> container) {
        // Use the same duration as the animation on the WindowContainer
        // Use the same duration as the animation on the WindowContainer
        AnimationAdapter animationAdapter = container.mSurfaceAnimator.getAnimation();
        AnimationAdapter animationAdapter = container.mSurfaceAnimator.getAnimation();
        final float durationScale = container.mWmService.getTransitionAnimationScaleLocked();
        final float durationScale = container.mWmService.getTransitionAnimationScaleLocked();