From: Winson Chung Date: Fri, 9 Jun 2017 19:01:20 +0000 (-0700) Subject: Boost the anim thread priority when doing a bounds animation. X-Git-Tag: android-x86-9.0-r1~1044^2~164^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=1ec3e26c087ce69134631cbcdf5c38f7ebdd63e7;p=android-x86%2Fframeworks-base.git Boost the anim thread priority when doing a bounds animation. Bug: 36371375 Bug: 36631902 Test: Start PIP, ensure anim thread priority is boosted for entire transition Change-Id: Id60ce7a2b7791de2786d683dbe148483d0ad0f04 --- diff --git a/services/core/java/com/android/server/wm/BoundsAnimationController.java b/services/core/java/com/android/server/wm/BoundsAnimationController.java index 7d13889eee35..cff2fadd7649 100644 --- a/services/core/java/com/android/server/wm/BoundsAnimationController.java +++ b/services/core/java/com/android/server/wm/BoundsAnimationController.java @@ -206,6 +206,10 @@ public class BoundsAnimationController { mTmpRect.set(mFrom.left, mFrom.top, mFrom.left + mFrozenTaskWidth, mFrom.top + mFrozenTaskHeight); + // Boost the thread priority of the animation thread while the bounds animation is + // running + updateBooster(); + // Ensure that we have prepared the target for animation before // we trigger any size changes, so it can swap surfaces // in to appropriate modes, or do as it wishes otherwise. @@ -316,6 +320,9 @@ public class BoundsAnimationController { removeListener(this); removeUpdateListener(this); mRunningAnimations.remove(mTarget); + + // Reset the thread priority of the animation thread after the bounds animation is done + updateBooster(); } @Override @@ -446,4 +453,9 @@ public class BoundsAnimationController { b.resume(); } } + + private void updateBooster() { + WindowManagerService.sThreadPriorityBooster.setBoundsAnimationRunning( + !mRunningAnimations.isEmpty()); + } } diff --git a/services/core/java/com/android/server/wm/WindowManagerThreadPriorityBooster.java b/services/core/java/com/android/server/wm/WindowManagerThreadPriorityBooster.java index 6a244a251537..1b2eb465399a 100644 --- a/services/core/java/com/android/server/wm/WindowManagerThreadPriorityBooster.java +++ b/services/core/java/com/android/server/wm/WindowManagerThreadPriorityBooster.java @@ -23,6 +23,7 @@ import static android.os.Process.setThreadPriority; import static com.android.server.LockGuard.INDEX_WINDOW; import static com.android.server.am.ActivityManagerService.TOP_APP_PRIORITY_BOOST; +import com.android.internal.annotations.GuardedBy; import com.android.server.AnimationThread; import com.android.server.ThreadPriorityBooster; @@ -32,12 +33,18 @@ import com.android.server.ThreadPriorityBooster; */ class WindowManagerThreadPriorityBooster extends ThreadPriorityBooster { - private final AnimationThread mAnimationThread; + private final Object mLock = new Object(); + + private final int mAnimationThreadId; + + @GuardedBy("mLock") private boolean mAppTransitionRunning; + @GuardedBy("mLock") + private boolean mBoundsAnimationRunning; WindowManagerThreadPriorityBooster() { super(THREAD_PRIORITY_DISPLAY, INDEX_WINDOW); - mAnimationThread = AnimationThread.get(); + mAnimationThreadId = AnimationThread.get().getThreadId(); } @Override @@ -45,7 +52,7 @@ class WindowManagerThreadPriorityBooster extends ThreadPriorityBooster { // Do not boost the animation thread. As the animation thread is changing priorities, // boosting it might mess up the priority because we reset it the the previous priority. - if (myTid() == mAnimationThread.getThreadId()) { + if (myTid() == mAnimationThreadId) { return; } super.boost(); @@ -55,24 +62,35 @@ class WindowManagerThreadPriorityBooster extends ThreadPriorityBooster { public void reset() { // See comment in boost(). - if (myTid() == mAnimationThread.getThreadId()) { + if (myTid() == mAnimationThreadId) { return; } super.reset(); } void setAppTransitionRunning(boolean running) { - if (mAppTransitionRunning == running) { - return; + synchronized (mLock) { + if (mAppTransitionRunning != running) { + mAppTransitionRunning = running; + updatePriorityLocked(); + } } + } - final int priority = calculatePriority(running); - setBoostToPriority(priority); - setThreadPriority(mAnimationThread.getThreadId(), priority); - mAppTransitionRunning = running; + void setBoundsAnimationRunning(boolean running) { + synchronized (mLock) { + if (mBoundsAnimationRunning != running) { + mBoundsAnimationRunning = running; + updatePriorityLocked(); + } + } } - private int calculatePriority(boolean appTransitionRunning) { - return appTransitionRunning ? TOP_APP_PRIORITY_BOOST : THREAD_PRIORITY_DISPLAY; + @GuardedBy("mLock") + private void updatePriorityLocked() { + int priority = (mAppTransitionRunning || mBoundsAnimationRunning) + ? TOP_APP_PRIORITY_BOOST : THREAD_PRIORITY_DISPLAY; + setBoostToPriority(priority); + setThreadPriority(mAnimationThreadId, priority); } }