Skip to content

Commit dbb7991

Browse files
author
Craig Mautner
committed
Separate animation steps into start, step and finish phases.
Fixes bug 6089126. Change-Id: Iafbde36ff719640335a7ecf762e1d991cf7915e4
1 parent 5bb59da commit dbb7991

File tree

4 files changed

+171
-102
lines changed

4 files changed

+171
-102
lines changed

services/java/com/android/server/wm/AppWindowToken.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Version of WindowToken that is specifically for a particular application (or
3838
* really activity) that is displaying windows.
3939
*/
40-
class AppWindowToken extends WindowToken {
40+
class AppWindowToken extends WindowToken implements WindowManagerService.StepAnimator {
4141
// Non-null only for application tokens.
4242
final IApplicationToken appToken;
4343

@@ -195,8 +195,28 @@ void showAllWindowsLocked() {
195195
}
196196
}
197197

198+
@Override
199+
public boolean stepAnimation(long currentTime) {
200+
if (animation == null) {
201+
return false;
202+
}
203+
transformation.clear();
204+
final boolean more = animation.getTransformation(currentTime, transformation);
205+
if (WindowManagerService.DEBUG_ANIM) Slog.v(
206+
WindowManagerService.TAG, "Stepped animation in " + this +
207+
": more=" + more + ", xform=" + transformation);
208+
if (!more) {
209+
animation = null;
210+
if (WindowManagerService.DEBUG_ANIM) Slog.v(
211+
WindowManagerService.TAG, "Finished animation in " + this +
212+
" @ " + currentTime);
213+
}
214+
hasTransformation = more;
215+
return more;
216+
}
217+
198218
// This must be called while inside a transaction.
199-
boolean stepAnimationLocked(long currentTime, int dw, int dh) {
219+
boolean startAndFinishAnimationLocked(long currentTime, int dw, int dh) {
200220
if (!service.mDisplayFrozen && service.mPolicy.isScreenOnFully()) {
201221
// We will run animations as long as the display isn't frozen.
202222

@@ -219,21 +239,8 @@ boolean stepAnimationLocked(long currentTime, int dw, int dh) {
219239
animation.setStartTime(currentTime);
220240
animating = true;
221241
}
222-
transformation.clear();
223-
final boolean more = animation.getTransformation(
224-
currentTime, transformation);
225-
if (WindowManagerService.DEBUG_ANIM) Slog.v(
226-
WindowManagerService.TAG, "Stepped animation in " + this +
227-
": more=" + more + ", xform=" + transformation);
228-
if (more) {
229-
// we're done!
230-
hasTransformation = true;
231-
return true;
232-
}
233-
if (WindowManagerService.DEBUG_ANIM) Slog.v(
234-
WindowManagerService.TAG, "Finished animation in " + this +
235-
" @ " + currentTime);
236-
animation = null;
242+
// we're done!
243+
return true;
237244
}
238245
} else if (animation != null) {
239246
// If the display is frozen, and there is a pending animation,
@@ -369,6 +376,7 @@ WindowState findMainWindow() {
369376
return null;
370377
}
371378

379+
@Override
372380
void dump(PrintWriter pw, String prefix) {
373381
super.dump(pw, prefix);
374382
if (appToken != null) {

services/java/com/android/server/wm/ScreenRotationAnimation.java

Lines changed: 70 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import android.view.animation.AnimationUtils;
3030
import android.view.animation.Transformation;
3131

32-
class ScreenRotationAnimation {
32+
class ScreenRotationAnimation implements WindowManagerService.StepAnimator {
3333
static final String TAG = "ScreenRotationAnimation";
3434
static final boolean DEBUG_STATE = false;
3535
static final boolean DEBUG_TRANSFORMS = false;
@@ -97,6 +97,12 @@ class ScreenRotationAnimation {
9797
final Matrix mSnapshotFinalMatrix = new Matrix();
9898
final Matrix mTmpMatrix = new Matrix();
9999
final float[] mTmpFloats = new float[9];
100+
private boolean mMoreRotateEnter;
101+
private boolean mMoreRotateExit;
102+
private boolean mMoreFinishEnter;
103+
private boolean mMoreFinishExit;
104+
private boolean mMoreStartEnter;
105+
private boolean mMoreStartExit;
100106

101107
public void printTo(String prefix, PrintWriter pw) {
102108
pw.print(prefix); pw.print("mSurface="); pw.print(mSurface);
@@ -456,34 +462,8 @@ public boolean isAnimating() {
456462
&& mRotateEnterAnimation != null || mRotateExitAnimation != null;
457463
}
458464

465+
@Override
459466
public boolean stepAnimation(long now) {
460-
if (!isAnimating()) {
461-
if (DEBUG_STATE) Slog.v(TAG, "Step: no animations running");
462-
return false;
463-
}
464-
465-
if (!mAnimRunning) {
466-
if (DEBUG_STATE) Slog.v(TAG, "Step: starting start, finish, rotate");
467-
if (mStartEnterAnimation != null) {
468-
mStartEnterAnimation.setStartTime(now);
469-
}
470-
if (mStartExitAnimation != null) {
471-
mStartExitAnimation.setStartTime(now);
472-
}
473-
if (mFinishEnterAnimation != null) {
474-
mFinishEnterAnimation.setStartTime(0);
475-
}
476-
if (mFinishExitAnimation != null) {
477-
mFinishExitAnimation.setStartTime(0);
478-
}
479-
if (mRotateEnterAnimation != null) {
480-
mRotateEnterAnimation.setStartTime(now);
481-
}
482-
if (mRotateExitAnimation != null) {
483-
mRotateExitAnimation.setStartTime(now);
484-
}
485-
mAnimRunning = true;
486-
}
487467

488468
if (mFinishAnimReady && mFinishAnimStartTime < 0) {
489469
if (DEBUG_STATE) Slog.v(TAG, "Step: finish anim now ready");
@@ -493,24 +473,24 @@ public boolean stepAnimation(long now) {
493473
// If the start animation is no longer running, we want to keep its
494474
// transformation intact until the finish animation also completes.
495475

496-
boolean moreStartExit = false;
476+
mMoreStartExit = false;
497477
if (mStartExitAnimation != null) {
498478
mStartExitTransformation.clear();
499-
moreStartExit = mStartExitAnimation.getTransformation(now, mStartExitTransformation);
479+
mMoreStartExit = mStartExitAnimation.getTransformation(now, mStartExitTransformation);
500480
if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start exit: " + mStartExitTransformation);
501-
if (!moreStartExit) {
481+
if (!mMoreStartExit) {
502482
if (DEBUG_STATE) Slog.v(TAG, "Start exit animation done!");
503483
mStartExitAnimation.cancel();
504484
mStartExitAnimation = null;
505485
}
506486
}
507487

508-
boolean moreStartEnter = false;
488+
mMoreStartEnter = false;
509489
if (mStartEnterAnimation != null) {
510490
mStartEnterTransformation.clear();
511-
moreStartEnter = mStartEnterAnimation.getTransformation(now, mStartEnterTransformation);
491+
mMoreStartEnter = mStartEnterAnimation.getTransformation(now, mStartEnterTransformation);
512492
if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start enter: " + mStartEnterTransformation);
513-
if (!moreStartEnter) {
493+
if (!mMoreStartEnter) {
514494
if (DEBUG_STATE) Slog.v(TAG, "Start enter animation done!");
515495
mStartEnterAnimation.cancel();
516496
mStartEnterAnimation = null;
@@ -521,11 +501,11 @@ public boolean stepAnimation(long now) {
521501
if (DEBUG_STATE) Slog.v(TAG, "Step: finishNow=" + finishNow);
522502

523503
mFinishExitTransformation.clear();
524-
boolean moreFinishExit = false;
504+
mMoreFinishExit = false;
525505
if (mFinishExitAnimation != null) {
526-
moreFinishExit = mFinishExitAnimation.getTransformation(finishNow, mFinishExitTransformation);
506+
mMoreFinishExit = mFinishExitAnimation.getTransformation(finishNow, mFinishExitTransformation);
527507
if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish exit: " + mFinishExitTransformation);
528-
if (!moreStartExit && !moreFinishExit) {
508+
if (!mMoreStartExit && !mMoreFinishExit) {
529509
if (DEBUG_STATE) Slog.v(TAG, "Finish exit animation done, clearing start/finish anims!");
530510
mStartExitTransformation.clear();
531511
mFinishExitAnimation.cancel();
@@ -535,11 +515,11 @@ public boolean stepAnimation(long now) {
535515
}
536516

537517
mFinishEnterTransformation.clear();
538-
boolean moreFinishEnter = false;
518+
mMoreFinishEnter = false;
539519
if (mFinishEnterAnimation != null) {
540-
moreFinishEnter = mFinishEnterAnimation.getTransformation(finishNow, mFinishEnterTransformation);
520+
mMoreFinishEnter = mFinishEnterAnimation.getTransformation(finishNow, mFinishEnterTransformation);
541521
if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish enter: " + mFinishEnterTransformation);
542-
if (!moreStartEnter && !moreFinishEnter) {
522+
if (!mMoreStartEnter && !mMoreFinishEnter) {
543523
if (DEBUG_STATE) Slog.v(TAG, "Finish enter animation done, clearing start/finish anims!");
544524
mStartEnterTransformation.clear();
545525
mFinishEnterAnimation.cancel();
@@ -549,27 +529,27 @@ public boolean stepAnimation(long now) {
549529
}
550530

551531
mRotateExitTransformation.clear();
552-
boolean moreRotateExit = false;
532+
mMoreRotateExit = false;
553533
if (mRotateExitAnimation != null) {
554-
moreRotateExit = mRotateExitAnimation.getTransformation(now, mRotateExitTransformation);
534+
mMoreRotateExit = mRotateExitAnimation.getTransformation(now, mRotateExitTransformation);
555535
if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate exit: " + mRotateExitTransformation);
556536
}
557537

558-
if (!moreFinishExit && !moreRotateExit) {
538+
if (!mMoreFinishExit && !mMoreRotateExit) {
559539
if (DEBUG_STATE) Slog.v(TAG, "Rotate exit animation done!");
560540
mRotateExitAnimation.cancel();
561541
mRotateExitAnimation = null;
562542
mRotateExitTransformation.clear();
563543
}
564544

565545
mRotateEnterTransformation.clear();
566-
boolean moreRotateEnter = false;
546+
mMoreRotateEnter = false;
567547
if (mRotateEnterAnimation != null) {
568-
moreRotateEnter = mRotateEnterAnimation.getTransformation(now, mRotateEnterTransformation);
548+
mMoreRotateEnter = mRotateEnterAnimation.getTransformation(now, mRotateEnterTransformation);
569549
if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate enter: " + mRotateEnterTransformation);
570550
}
571551

572-
if (!moreFinishEnter && !moreRotateEnter) {
552+
if (!mMoreFinishEnter && !mMoreRotateEnter) {
573553
if (DEBUG_STATE) Slog.v(TAG, "Rotate enter animation done!");
574554
mRotateEnterAnimation.cancel();
575555
mRotateEnterAnimation = null;
@@ -587,14 +567,25 @@ public boolean stepAnimation(long now) {
587567
if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final exit: " + mExitTransformation);
588568
if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final enter: " + mEnterTransformation);
589569

590-
if (!moreStartExit && !moreFinishExit && !moreRotateExit) {
570+
final boolean more = mMoreStartEnter || mMoreStartExit || mMoreFinishEnter
571+
|| mMoreFinishExit || mMoreRotateEnter || mMoreRotateExit || !mFinishAnimReady;
572+
573+
mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
574+
575+
if (DEBUG_STATE) Slog.v(TAG, "Step: more=" + more);
576+
577+
return more;
578+
}
579+
580+
void updateSurfaces() {
581+
if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
591582
if (mSurface != null) {
592583
if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
593584
mSurface.hide();
594585
}
595586
}
596587

597-
if (!moreStartEnter && !moreFinishEnter && !moreRotateEnter) {
588+
if (!mMoreStartEnter && !mMoreFinishEnter && !mMoreRotateEnter) {
598589
if (mBlackFrame != null) {
599590
if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, hiding black frame");
600591
mBlackFrame.hide();
@@ -605,15 +596,39 @@ public boolean stepAnimation(long now) {
605596
}
606597
}
607598

608-
mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
609599
setSnapshotTransform(mSnapshotFinalMatrix, mExitTransformation.getAlpha());
600+
}
601+
602+
public boolean startAndFinishAnimationLocked(long now) {
603+
if (!isAnimating()) {
604+
if (DEBUG_STATE) Slog.v(TAG, "Step: no animations running");
605+
return false;
606+
}
610607

611-
final boolean more = moreStartEnter || moreStartExit || moreFinishEnter || moreFinishExit
612-
|| moreRotateEnter || moreRotateExit || !mFinishAnimReady;
613-
614-
if (DEBUG_STATE) Slog.v(TAG, "Step: more=" + more);
615-
616-
return more;
608+
if (!mAnimRunning) {
609+
if (DEBUG_STATE) Slog.v(TAG, "Step: starting start, finish, rotate");
610+
if (mStartEnterAnimation != null) {
611+
mStartEnterAnimation.setStartTime(now);
612+
}
613+
if (mStartExitAnimation != null) {
614+
mStartExitAnimation.setStartTime(now);
615+
}
616+
if (mFinishEnterAnimation != null) {
617+
mFinishEnterAnimation.setStartTime(0);
618+
}
619+
if (mFinishExitAnimation != null) {
620+
mFinishExitAnimation.setStartTime(0);
621+
}
622+
if (mRotateEnterAnimation != null) {
623+
mRotateEnterAnimation.setStartTime(now);
624+
}
625+
if (mRotateExitAnimation != null) {
626+
mRotateExitAnimation.setStartTime(now);
627+
}
628+
mAnimRunning = true;
629+
}
630+
631+
return true;
617632
}
618633

619634
public Transformation getEnterTransformation() {

0 commit comments

Comments
 (0)