blob: 72019315139b166928bf3a720419f6bd8e52b5c8 [file] [log] [blame]
Hongwei Wang85cf41f2020-01-15 15:14:47 -08001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.systemui.pip;
18
Tony Huang4b8795d2020-05-29 16:08:31 +080019import android.animation.AnimationHandler;
Hongwei Wang85cf41f2020-01-15 15:14:47 -080020import android.animation.Animator;
Winson Chung3b4d8562020-06-10 04:25:18 +000021import android.animation.RectEvaluator;
Hongwei Wang85cf41f2020-01-15 15:14:47 -080022import android.animation.ValueAnimator;
23import android.annotation.IntDef;
Hongwei Wang85cf41f2020-01-15 15:14:47 -080024import android.graphics.Rect;
Hongwei Wang85cf41f2020-01-15 15:14:47 -080025import android.view.SurfaceControl;
Hongwei Wang85cf41f2020-01-15 15:14:47 -080026
27import com.android.internal.annotations.VisibleForTesting;
Tony Huang4b8795d2020-05-29 16:08:31 +080028import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
Winson Chung3b4d8562020-06-10 04:25:18 +000029import com.android.systemui.Interpolators;
Hongwei Wang85cf41f2020-01-15 15:14:47 -080030
31import java.lang.annotation.Retention;
32import java.lang.annotation.RetentionPolicy;
33
Hongwei Wangec3cb3c2020-03-09 10:43:21 -070034import javax.inject.Inject;
35
Hongwei Wang85cf41f2020-01-15 15:14:47 -080036/**
37 * Controller class of PiP animations (both from and to PiP mode).
38 */
39public class PipAnimationController {
40 private static final float FRACTION_START = 0f;
41 private static final float FRACTION_END = 1f;
42
Hongwei Wang85cf41f2020-01-15 15:14:47 -080043 public static final int ANIM_TYPE_BOUNDS = 0;
44 public static final int ANIM_TYPE_ALPHA = 1;
45
46 @IntDef(prefix = { "ANIM_TYPE_" }, value = {
47 ANIM_TYPE_BOUNDS,
48 ANIM_TYPE_ALPHA
49 })
50 @Retention(RetentionPolicy.SOURCE)
51 public @interface AnimationType {}
52
Hongwei Wang221fe3d2020-03-26 13:13:04 -070053 public static final int TRANSITION_DIRECTION_NONE = 0;
54 public static final int TRANSITION_DIRECTION_SAME = 1;
55 public static final int TRANSITION_DIRECTION_TO_PIP = 2;
56 public static final int TRANSITION_DIRECTION_TO_FULLSCREEN = 3;
Hongwei Wang5c52ff82020-04-20 16:02:30 -070057 public static final int TRANSITION_DIRECTION_TO_SPLIT_SCREEN = 4;
Hongwei Wang925a1022020-07-14 15:26:32 -070058 public static final int TRANSITION_DIRECTION_REMOVE_STACK = 5;
Hongwei Wangdf8bb002020-03-03 17:41:02 -080059
60 @IntDef(prefix = { "TRANSITION_DIRECTION_" }, value = {
61 TRANSITION_DIRECTION_NONE,
62 TRANSITION_DIRECTION_SAME,
63 TRANSITION_DIRECTION_TO_PIP,
Hongwei Wang5c52ff82020-04-20 16:02:30 -070064 TRANSITION_DIRECTION_TO_FULLSCREEN,
Hongwei Wang925a1022020-07-14 15:26:32 -070065 TRANSITION_DIRECTION_TO_SPLIT_SCREEN,
66 TRANSITION_DIRECTION_REMOVE_STACK
Hongwei Wangdf8bb002020-03-03 17:41:02 -080067 })
68 @Retention(RetentionPolicy.SOURCE)
Hongwei Wang221fe3d2020-03-26 13:13:04 -070069 public @interface TransitionDirection {}
Hongwei Wangdf8bb002020-03-03 17:41:02 -080070
Winson Chungc4d4ee82020-05-05 12:51:06 -070071 public static boolean isInPipDirection(@TransitionDirection int direction) {
72 return direction == TRANSITION_DIRECTION_TO_PIP;
73 }
74
Hongwei Wang5c52ff82020-04-20 16:02:30 -070075 public static boolean isOutPipDirection(@TransitionDirection int direction) {
76 return direction == TRANSITION_DIRECTION_TO_FULLSCREEN
77 || direction == TRANSITION_DIRECTION_TO_SPLIT_SCREEN;
78 }
79
Hongwei Wangec3cb3c2020-03-09 10:43:21 -070080 private final PipSurfaceTransactionHelper mSurfaceTransactionHelper;
Hongwei Wang85cf41f2020-01-15 15:14:47 -080081
82 private PipTransitionAnimator mCurrentAnimator;
83
Tony Huang4b8795d2020-05-29 16:08:31 +080084 private ThreadLocal<AnimationHandler> mSfAnimationHandlerThreadLocal =
85 ThreadLocal.withInitial(() -> {
86 AnimationHandler handler = new AnimationHandler();
87 handler.setProvider(new SfVsyncFrameCallbackProvider());
88 return handler;
89 });
90
Hongwei Wangec3cb3c2020-03-09 10:43:21 -070091 @Inject
Hongwei Wang925a1022020-07-14 15:26:32 -070092 PipAnimationController(PipSurfaceTransactionHelper helper) {
Hongwei Wangec3cb3c2020-03-09 10:43:21 -070093 mSurfaceTransactionHelper = helper;
Hongwei Wang85cf41f2020-01-15 15:14:47 -080094 }
95
Hongwei Wangdf8bb002020-03-03 17:41:02 -080096 @SuppressWarnings("unchecked")
97 PipTransitionAnimator getAnimator(SurfaceControl leash,
Hongwei Wang85cf41f2020-01-15 15:14:47 -080098 Rect destinationBounds, float alphaStart, float alphaEnd) {
99 if (mCurrentAnimator == null) {
100 mCurrentAnimator = setupPipTransitionAnimator(
Hongwei Wangdf8bb002020-03-03 17:41:02 -0800101 PipTransitionAnimator.ofAlpha(leash, destinationBounds, alphaStart, alphaEnd));
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800102 } else if (mCurrentAnimator.getAnimationType() == ANIM_TYPE_ALPHA
103 && mCurrentAnimator.isRunning()) {
104 mCurrentAnimator.updateEndValue(alphaEnd);
105 } else {
106 mCurrentAnimator.cancel();
107 mCurrentAnimator = setupPipTransitionAnimator(
Hongwei Wangdf8bb002020-03-03 17:41:02 -0800108 PipTransitionAnimator.ofAlpha(leash, destinationBounds, alphaStart, alphaEnd));
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800109 }
110 return mCurrentAnimator;
111 }
112
Hongwei Wangdf8bb002020-03-03 17:41:02 -0800113 @SuppressWarnings("unchecked")
Winson Chung3b4d8562020-06-10 04:25:18 +0000114 PipTransitionAnimator getAnimator(SurfaceControl leash, Rect startBounds, Rect endBounds,
115 Rect sourceHintRect) {
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800116 if (mCurrentAnimator == null) {
117 mCurrentAnimator = setupPipTransitionAnimator(
Winson Chung3b4d8562020-06-10 04:25:18 +0000118 PipTransitionAnimator.ofBounds(leash, startBounds, endBounds, sourceHintRect));
Winson Chungc4d4ee82020-05-05 12:51:06 -0700119 } else if (mCurrentAnimator.getAnimationType() == ANIM_TYPE_ALPHA
120 && mCurrentAnimator.isRunning()) {
121 // If we are still animating the fade into pip, then just move the surface and ensure
122 // we update with the new destination bounds, but don't interrupt the existing animation
123 // with a new bounds
124 mCurrentAnimator.setDestinationBounds(endBounds);
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800125 } else if (mCurrentAnimator.getAnimationType() == ANIM_TYPE_BOUNDS
126 && mCurrentAnimator.isRunning()) {
127 mCurrentAnimator.setDestinationBounds(endBounds);
128 // construct new Rect instances in case they are recycled
129 mCurrentAnimator.updateEndValue(new Rect(endBounds));
130 } else {
131 mCurrentAnimator.cancel();
132 mCurrentAnimator = setupPipTransitionAnimator(
Winson Chung3b4d8562020-06-10 04:25:18 +0000133 PipTransitionAnimator.ofBounds(leash, startBounds, endBounds, sourceHintRect));
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800134 }
135 return mCurrentAnimator;
136 }
137
Hongwei Wang951dc022020-03-30 16:16:16 -0700138 PipTransitionAnimator getCurrentAnimator() {
139 return mCurrentAnimator;
140 }
141
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800142 private PipTransitionAnimator setupPipTransitionAnimator(PipTransitionAnimator animator) {
Hongwei Wangec3cb3c2020-03-09 10:43:21 -0700143 animator.setSurfaceTransactionHelper(mSurfaceTransactionHelper);
Winson Chung3b4d8562020-06-10 04:25:18 +0000144 animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800145 animator.setFloatValues(FRACTION_START, FRACTION_END);
Tony Huang4b8795d2020-05-29 16:08:31 +0800146 animator.setAnimationHandler(mSfAnimationHandlerThreadLocal.get());
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800147 return animator;
148 }
149
150 /**
151 * Additional callback interface for PiP animation
152 */
153 public static class PipAnimationCallback {
154 /**
155 * Called when PiP animation is started.
156 */
Winson Chung55701472020-03-04 19:30:30 -0800157 public void onPipAnimationStart(PipTransitionAnimator animator) {}
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800158
159 /**
160 * Called when PiP animation is ended.
161 */
Winson Chung55701472020-03-04 19:30:30 -0800162 public void onPipAnimationEnd(SurfaceControl.Transaction tx,
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800163 PipTransitionAnimator animator) {}
164
165 /**
166 * Called when PiP animation is cancelled.
167 */
Winson Chung55701472020-03-04 19:30:30 -0800168 public void onPipAnimationCancel(PipTransitionAnimator animator) {}
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800169 }
170
171 /**
172 * Animator for PiP transition animation which supports both alpha and bounds animation.
173 * @param <T> Type of property to animate, either alpha (float) or bounds (Rect)
174 */
175 public abstract static class PipTransitionAnimator<T> extends ValueAnimator implements
176 ValueAnimator.AnimatorUpdateListener,
177 ValueAnimator.AnimatorListener {
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800178 private final SurfaceControl mLeash;
179 private final @AnimationType int mAnimationType;
180 private final Rect mDestinationBounds = new Rect();
181
Tony Huang5ebe0192020-05-15 19:27:54 +0800182 protected T mCurrentValue;
183 protected T mStartValue;
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800184 private T mEndValue;
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800185 private PipAnimationCallback mPipAnimationCallback;
Hongwei Wangec3cb3c2020-03-09 10:43:21 -0700186 private PipSurfaceTransactionHelper.SurfaceControlTransactionFactory
187 mSurfaceControlTransactionFactory;
188 private PipSurfaceTransactionHelper mSurfaceTransactionHelper;
Hongwei Wangdf8bb002020-03-03 17:41:02 -0800189 private @TransitionDirection int mTransitionDirection;
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800190
Hongwei Wangdf8bb002020-03-03 17:41:02 -0800191 private PipTransitionAnimator(SurfaceControl leash, @AnimationType int animationType,
192 Rect destinationBounds, T startValue, T endValue) {
Winson Chung55701472020-03-04 19:30:30 -0800193 mLeash = leash;
194 mAnimationType = animationType;
195 mDestinationBounds.set(destinationBounds);
196 mStartValue = startValue;
197 mEndValue = endValue;
198 addListener(this);
199 addUpdateListener(this);
200 mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new;
Hongwei Wangdf8bb002020-03-03 17:41:02 -0800201 mTransitionDirection = TRANSITION_DIRECTION_NONE;
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800202 }
203
204 @Override
205 public void onAnimationStart(Animator animation) {
206 mCurrentValue = mStartValue;
Hongwei Wang09c1f042020-03-18 13:47:45 -0700207 onStartTransaction(mLeash, newSurfaceControlTransaction());
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800208 if (mPipAnimationCallback != null) {
Winson Chung55701472020-03-04 19:30:30 -0800209 mPipAnimationCallback.onPipAnimationStart(this);
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800210 }
211 }
212
213 @Override
214 public void onAnimationUpdate(ValueAnimator animation) {
215 applySurfaceControlTransaction(mLeash, newSurfaceControlTransaction(),
216 animation.getAnimatedFraction());
217 }
218
219 @Override
220 public void onAnimationEnd(Animator animation) {
221 mCurrentValue = mEndValue;
222 final SurfaceControl.Transaction tx = newSurfaceControlTransaction();
Hongwei Wang09c1f042020-03-18 13:47:45 -0700223 onEndTransaction(mLeash, tx);
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800224 if (mPipAnimationCallback != null) {
Winson Chung55701472020-03-04 19:30:30 -0800225 mPipAnimationCallback.onPipAnimationEnd(tx, this);
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800226 }
227 }
228
229 @Override
230 public void onAnimationCancel(Animator animation) {
231 if (mPipAnimationCallback != null) {
Winson Chung55701472020-03-04 19:30:30 -0800232 mPipAnimationCallback.onPipAnimationCancel(this);
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800233 }
234 }
235
236 @Override public void onAnimationRepeat(Animator animation) {}
237
238 @AnimationType int getAnimationType() {
239 return mAnimationType;
240 }
241
242 PipTransitionAnimator<T> setPipAnimationCallback(PipAnimationCallback callback) {
243 mPipAnimationCallback = callback;
244 return this;
245 }
246
Hongwei Wangdf8bb002020-03-03 17:41:02 -0800247 @TransitionDirection int getTransitionDirection() {
248 return mTransitionDirection;
249 }
250
251 PipTransitionAnimator<T> setTransitionDirection(@TransitionDirection int direction) {
252 if (direction != TRANSITION_DIRECTION_SAME) {
253 mTransitionDirection = direction;
254 }
255 return this;
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800256 }
257
258 T getStartValue() {
259 return mStartValue;
260 }
261
262 T getEndValue() {
263 return mEndValue;
264 }
265
266 Rect getDestinationBounds() {
267 return mDestinationBounds;
268 }
269
270 void setDestinationBounds(Rect destinationBounds) {
271 mDestinationBounds.set(destinationBounds);
Hongwei Wang951dc022020-03-30 16:16:16 -0700272 if (mAnimationType == ANIM_TYPE_ALPHA) {
273 onStartTransaction(mLeash, newSurfaceControlTransaction());
274 }
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800275 }
276
277 void setCurrentValue(T value) {
278 mCurrentValue = value;
279 }
280
Hongwei Wangdf8bb002020-03-03 17:41:02 -0800281 boolean shouldApplyCornerRadius() {
Hongwei Wang5c52ff82020-04-20 16:02:30 -0700282 return !isOutPipDirection(mTransitionDirection);
Hongwei Wangdf8bb002020-03-03 17:41:02 -0800283 }
284
Hongwei Wang09c1f042020-03-18 13:47:45 -0700285 boolean inScaleTransition() {
286 if (mAnimationType != ANIM_TYPE_BOUNDS) return false;
Winson Chungc4d4ee82020-05-05 12:51:06 -0700287 return !isInPipDirection(getTransitionDirection());
Hongwei Wang09c1f042020-03-18 13:47:45 -0700288 }
289
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800290 /**
291 * Updates the {@link #mEndValue}.
292 *
293 * NOTE: Do not forget to call {@link #setDestinationBounds(Rect)} for bounds animation.
294 * This is typically used when we receive a shelf height adjustment during the bounds
295 * animation. In which case we can update the end bounds and keep the existing animation
296 * running instead of cancelling it.
297 */
298 void updateEndValue(T endValue) {
299 mEndValue = endValue;
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800300 }
301
302 SurfaceControl.Transaction newSurfaceControlTransaction() {
303 return mSurfaceControlTransactionFactory.getTransaction();
304 }
305
306 @VisibleForTesting
Hongwei Wangec3cb3c2020-03-09 10:43:21 -0700307 void setSurfaceControlTransactionFactory(
308 PipSurfaceTransactionHelper.SurfaceControlTransactionFactory factory) {
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800309 mSurfaceControlTransactionFactory = factory;
310 }
311
Hongwei Wangec3cb3c2020-03-09 10:43:21 -0700312 PipSurfaceTransactionHelper getSurfaceTransactionHelper() {
313 return mSurfaceTransactionHelper;
314 }
315
316 void setSurfaceTransactionHelper(PipSurfaceTransactionHelper helper) {
317 mSurfaceTransactionHelper = helper;
318 }
319
Hongwei Wang09c1f042020-03-18 13:47:45 -0700320 void onStartTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {}
321
322 void onEndTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {}
323
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800324 abstract void applySurfaceControlTransaction(SurfaceControl leash,
325 SurfaceControl.Transaction tx, float fraction);
326
Hongwei Wangdf8bb002020-03-03 17:41:02 -0800327 static PipTransitionAnimator<Float> ofAlpha(SurfaceControl leash,
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800328 Rect destinationBounds, float startValue, float endValue) {
Hongwei Wangdf8bb002020-03-03 17:41:02 -0800329 return new PipTransitionAnimator<Float>(leash, ANIM_TYPE_ALPHA,
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800330 destinationBounds, startValue, endValue) {
331 @Override
332 void applySurfaceControlTransaction(SurfaceControl leash,
333 SurfaceControl.Transaction tx, float fraction) {
334 final float alpha = getStartValue() * (1 - fraction) + getEndValue() * fraction;
335 setCurrentValue(alpha);
Hongwei Wangec3cb3c2020-03-09 10:43:21 -0700336 getSurfaceTransactionHelper().alpha(tx, leash, alpha);
Hongwei Wang09c1f042020-03-18 13:47:45 -0700337 tx.apply();
338 }
339
340 @Override
341 void onStartTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {
Hongwei Wang925a1022020-07-14 15:26:32 -0700342 if (getTransitionDirection() == TRANSITION_DIRECTION_REMOVE_STACK) {
343 // while removing the pip stack, no extra work needs to be done here.
344 return;
345 }
Hongwei Wang09c1f042020-03-18 13:47:45 -0700346 getSurfaceTransactionHelper()
Winson Chung3b4d8562020-06-10 04:25:18 +0000347 .resetScale(tx, leash, getDestinationBounds())
Hongwei Wang09c1f042020-03-18 13:47:45 -0700348 .crop(tx, leash, getDestinationBounds())
349 .round(tx, leash, shouldApplyCornerRadius());
Winson Chung1b5d0552020-04-06 19:28:49 -0700350 tx.show(leash);
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800351 tx.apply();
352 }
Tony Huang5ebe0192020-05-15 19:27:54 +0800353
354 @Override
355 void updateEndValue(Float endValue) {
356 super.updateEndValue(endValue);
357 mStartValue = mCurrentValue;
358 }
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800359 };
360 }
361
Hongwei Wangdf8bb002020-03-03 17:41:02 -0800362 static PipTransitionAnimator<Rect> ofBounds(SurfaceControl leash,
Winson Chung3b4d8562020-06-10 04:25:18 +0000363 Rect startValue, Rect endValue, Rect sourceHintRect) {
364 // Just for simplicity we'll interpolate between the source rect hint insets and empty
365 // insets to calculate the window crop
366 final Rect initialStartValue = new Rect(startValue);
367 final Rect sourceHintRectInsets = sourceHintRect != null
368 ? new Rect(sourceHintRect.left - startValue.left,
369 sourceHintRect.top - startValue.top,
370 startValue.right - sourceHintRect.right,
371 startValue.bottom - sourceHintRect.bottom)
372 : null;
373 final Rect sourceInsets = new Rect(0, 0, 0, 0);
374
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800375 // construct new Rect instances in case they are recycled
Hongwei Wangdf8bb002020-03-03 17:41:02 -0800376 return new PipTransitionAnimator<Rect>(leash, ANIM_TYPE_BOUNDS,
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800377 endValue, new Rect(startValue), new Rect(endValue)) {
Winson Chung3b4d8562020-06-10 04:25:18 +0000378 private final RectEvaluator mRectEvaluator = new RectEvaluator(new Rect());
379 private final RectEvaluator mInsetsEvaluator = new RectEvaluator(new Rect());
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800380
381 @Override
382 void applySurfaceControlTransaction(SurfaceControl leash,
383 SurfaceControl.Transaction tx, float fraction) {
384 final Rect start = getStartValue();
385 final Rect end = getEndValue();
Winson Chung3b4d8562020-06-10 04:25:18 +0000386 Rect bounds = mRectEvaluator.evaluate(fraction, start, end);
387 setCurrentValue(bounds);
Hongwei Wang09c1f042020-03-18 13:47:45 -0700388 if (inScaleTransition()) {
Winson Chungc4d4ee82020-05-05 12:51:06 -0700389 if (isOutPipDirection(getTransitionDirection())) {
Winson Chung3b4d8562020-06-10 04:25:18 +0000390 getSurfaceTransactionHelper().scale(tx, leash, end, bounds);
Winson Chungc4d4ee82020-05-05 12:51:06 -0700391 } else {
Winson Chung3b4d8562020-06-10 04:25:18 +0000392 getSurfaceTransactionHelper().scale(tx, leash, start, bounds);
Winson Chungc4d4ee82020-05-05 12:51:06 -0700393 }
Hongwei Wang09c1f042020-03-18 13:47:45 -0700394 } else {
Winson Chung3b4d8562020-06-10 04:25:18 +0000395 if (sourceHintRectInsets != null) {
396 Rect insets = mInsetsEvaluator.evaluate(fraction, sourceInsets,
397 sourceHintRectInsets);
398 getSurfaceTransactionHelper().scaleAndCrop(tx, leash, initialStartValue,
399 bounds, insets);
400 } else {
401 getSurfaceTransactionHelper().scale(tx, leash, start, bounds);
402 }
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800403 }
404 tx.apply();
405 }
Hongwei Wang09c1f042020-03-18 13:47:45 -0700406
407 @Override
408 void onStartTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {
409 getSurfaceTransactionHelper()
410 .alpha(tx, leash, 1f)
411 .round(tx, leash, shouldApplyCornerRadius());
Winson Chung1b5d0552020-04-06 19:28:49 -0700412 tx.show(leash);
Hongwei Wang09c1f042020-03-18 13:47:45 -0700413 tx.apply();
414 }
415
416 @Override
417 void onEndTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {
Hongwei Wang09c1f042020-03-18 13:47:45 -0700418 // NOTE: intentionally does not apply the transaction here.
419 // this end transaction should get executed synchronously with the final
420 // WindowContainerTransaction in task organizer
Winson Chung3b4d8562020-06-10 04:25:18 +0000421 getSurfaceTransactionHelper()
422 .resetScale(tx, leash, getDestinationBounds())
Robert Carrb80a55c2020-05-05 15:17:51 -0700423 .crop(tx, leash, getDestinationBounds());
Hongwei Wang09c1f042020-03-18 13:47:45 -0700424 }
Tony Huang5ebe0192020-05-15 19:27:54 +0800425
426 @Override
427 void updateEndValue(Rect endValue) {
428 super.updateEndValue(endValue);
429 if (mStartValue != null && mCurrentValue != null) {
430 mStartValue.set(mCurrentValue);
431 }
432 }
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800433 };
434 }
435 }
Hongwei Wang85cf41f2020-01-15 15:14:47 -0800436}